Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:47

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // ********************************************************************
0027 //
0028 //  CaTS (Calorimetry and Tracking Simulation)
0029 //
0030 //  Authors : Hans Wenzel
0031 //            Soon Yung Jun
0032 //            (Fermi National Accelerator Laboratory)
0033 //
0034 // History
0035 //   October 18th, 2021 : first implementation
0036 //
0037 // ********************************************************************
0038 //
0039 /// \file DRCalorimeterSD.cc
0040 /// \brief Implementation of the CaTS::DRCalorimeterSD class
0041 
0042 // Geant4 headers
0043 #include "G4HCofThisEvent.hh"
0044 #include "G4Step.hh"
0045 #include "G4ThreeVector.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4ios.hh"
0048 #include "G4SteppingManager.hh"
0049 #include "G4EventManager.hh"
0050 #include "G4Cerenkov.hh"
0051 // project headers
0052 #include "DRCalorimeterSD.hh"
0053 #include "ConfigurationManager.hh"
0054 
0055 DRCalorimeterSD::DRCalorimeterSD(G4String name)
0056   : G4VSensitiveDetector(name)
0057   , fDRCalorimeterHitsCollection(0)
0058   , fHCID(0)
0059 {
0060   G4String HCname = name + "_HC";
0061   collectionName.insert(HCname);
0062   G4cout << collectionName.size() << "   DRCalorimeterSD name:  " << name
0063          << " collection Name: " << HCname << G4endl;
0064   fHCID   = -1;
0065   verbose = ConfigurationManager::getInstance()->isEnable_verbose();
0066 }
0067 
0068 DRCalorimeterSD::~DRCalorimeterSD() {}
0069 
0070 void DRCalorimeterSD::Initialize(G4HCofThisEvent* hce)
0071 {
0072   fDRCalorimeterHitsCollection =
0073     new DRCalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]);
0074   if(fHCID < 0)
0075   {
0076     if(verbose)
0077       G4cout << "DRCalorimeterSD::Initialize:  " << SensitiveDetectorName
0078              << "   " << collectionName[0] << G4endl;
0079     fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0080   }
0081   hce->AddHitsCollection(fHCID, fDRCalorimeterHitsCollection);
0082 }
0083 
0084 G4bool DRCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0085 {
0086   G4double edep = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
0087   if(edep == 0.)
0088     return false;
0089   G4double time = aStep->GetPreStepPoint()->GetGlobalTime() / CLHEP::ns;
0090   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0091   G4ThreeVector cellpos     = touch->GetTranslation();
0092   unsigned int ID = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
0093   G4Track* theTrack          = aStep->GetTrack();
0094   G4String particleType      = theTrack->GetDefinition()->GetParticleName();
0095   unsigned int NCerenPhotons = 0;
0096   G4SteppingManager* fpSteppingManager = G4EventManager::GetEventManager()
0097                                            ->GetTrackingManager()
0098                                            ->GetSteppingManager();
0099   G4StepStatus stepStatus = fpSteppingManager->GetfStepStatus();
0100   if(stepStatus != fAtRestDoItProc)
0101   {
0102     G4ProcessVector* procPost = fpSteppingManager->GetfPostStepDoItVector();
0103     size_t MAXofPostStepLoops = fpSteppingManager->GetMAXofPostStepLoops();
0104     for(size_t i3 = 0; i3 < MAXofPostStepLoops; i3++)
0105     {
0106       if((*procPost)[i3]->GetProcessName() == "Cerenkov")
0107       {
0108         G4Cerenkov* proc = (G4Cerenkov*) (*procPost)[i3];
0109         NCerenPhotons += proc->GetNumPhotons();
0110       }
0111     }
0112   }
0113   //
0114   //  check if this cell has been hit before
0115   // fDRCalorimeterHitsCollection
0116   for(unsigned int j = 0; j < fDRCalorimeterHitsCollection->entries(); j++)
0117   {
0118     DRCalorimeterHit* aPreviousHit = (*fDRCalorimeterHitsCollection)[j];
0119     if(ID == aPreviousHit->GetId())
0120     {
0121       aPreviousHit->SetEdep(aStep->GetTotalEnergyDeposit() +
0122                             aPreviousHit->GetEdep());
0123       aPreviousHit->SetNceren(aPreviousHit->GetNceren() + NCerenPhotons);
0124       if((particleType == "e+") || (particleType == "gamma") ||
0125          (particleType == "e-"))
0126       {
0127         aPreviousHit->SetEm_Edep(edep + aPreviousHit->GetEm_Edep());
0128       }
0129       return true;
0130     }
0131   }
0132   //
0133   // otherwise create a new hit:
0134   //
0135   DRCalorimeterHit* newHit;
0136   if((particleType == "e+") || (particleType == "gamma") ||
0137      (particleType == "e-"))
0138   {
0139     newHit = new DRCalorimeterHit(ID, edep, edep, NCerenPhotons, time, cellpos);
0140   }
0141   else
0142   {
0143     newHit = new DRCalorimeterHit(ID, edep, 0.0, time, NCerenPhotons, cellpos);
0144   }
0145   fDRCalorimeterHitsCollection->insert(newHit);
0146   return true;
0147 }
0148 
0149 void DRCalorimeterSD::EndOfEvent(G4HCofThisEvent*)
0150 {
0151   G4int NbHits = fDRCalorimeterHitsCollection->entries();
0152   if(verbose)
0153     G4cout << " Number of DRCalorimeterHits:  " << NbHits << G4endl;
0154 }