Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:34

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 #include "Par03SensitiveDetector.hh"
0027 
0028 #include "Par03Hit.hh"
0029 
0030 #include "G4HCofThisEvent.hh"
0031 #include "G4SDManager.hh"
0032 #include "G4Step.hh"
0033 #include "G4TouchableHistory.hh"
0034 #include "G4Track.hh"
0035 
0036 Par03SensitiveDetector::Par03SensitiveDetector(G4String aName) : G4VSensitiveDetector(aName)
0037 {
0038   collectionName.insert("hits");
0039 }
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 Par03SensitiveDetector::Par03SensitiveDetector(G4String aName, G4int aNumLayers, G4int aNumRho,
0043                                                G4int aNumPhi)
0044   : G4VSensitiveDetector(aName), fCellNoZ(aNumLayers), fCellNoRho(aNumRho), fCellNoPhi(aNumPhi)
0045 {
0046   collectionName.insert("hits");
0047 }
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 Par03SensitiveDetector::~Par03SensitiveDetector() = default;
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 void Par03SensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
0056 {
0057   fHitsCollection = new Par03HitsCollection(SensitiveDetectorName, collectionName[0]);
0058   if (fHitCollectionID < 0) {
0059     fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0060   }
0061   aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
0062 
0063   // fill calorimeter hits with zero energy deposition
0064   for (G4int iphi = 0; iphi < fCellNoPhi; iphi++)
0065     for (G4int irho = 0; irho < fCellNoRho; irho++)
0066       for (G4int iz = 0; iz < fCellNoZ; iz++) {
0067         auto hit = new Par03Hit();
0068         fHitsCollection->insert(hit);
0069       }
0070 }
0071 
0072 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0073 
0074 G4bool Par03SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0075 {
0076   G4double edep = aStep->GetTotalEnergyDeposit();
0077   if (edep == 0.) return true;
0078 
0079   auto aTouchable = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
0080 
0081   auto hit = RetrieveAndSetupHit(aTouchable);
0082 
0083   // Add energy deposit from G4Step
0084   hit->AddEdep(edep);
0085 
0086   // Fill time information from G4Step
0087   // If it's already filled, choose hit with earliest global time
0088   if (hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
0089     hit->SetTime(aStep->GetTrack()->GetGlobalTime());
0090 
0091   // Set hit type to full simulation (only if hit is not already marked as fast
0092   // sim)
0093   if (hit->GetType() != 1) hit->SetType(0);
0094 
0095   return true;
0096 }
0097 
0098 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0099 
0100 G4bool Par03SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTrack* aTrack,
0101                                            G4TouchableHistory* aTouchable)
0102 {
0103   G4double edep = aHit->GetEnergy();
0104   if (edep == 0.) return true;
0105 
0106   auto hit = RetrieveAndSetupHit(aTouchable);
0107 
0108   // Add energy deposit from G4FastHit
0109   hit->AddEdep(edep);
0110 
0111   // Fill time information from G4FastTrack
0112   // If it's already filled, choose hit with earliest global time
0113   if (hit->GetTime() == -1 || hit->GetTime() > aTrack->GetPrimaryTrack()->GetGlobalTime()) {
0114     hit->SetTime(aTrack->GetPrimaryTrack()->GetGlobalTime());
0115   }
0116 
0117   // Set hit type to fast simulation (even if hit was already marked as full
0118   // sim, overwrite it)
0119   hit->SetType(1);
0120 
0121   return true;
0122 }
0123 
0124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0125 
0126 Par03Hit* Par03SensitiveDetector::RetrieveAndSetupHit(G4TouchableHistory* aTouchable)
0127 {
0128   G4int rhoNo = aTouchable->GetCopyNumber(0);  // cell
0129   G4int phiNo = aTouchable->GetCopyNumber(1);  // segment
0130   G4int zNo = aTouchable->GetCopyNumber(2);  // layer
0131 
0132   std::size_t hitID = fCellNoRho * fCellNoZ * phiNo + fCellNoZ * rhoNo + zNo;
0133 
0134   if (hitID >= fHitsCollection->entries()) {
0135     G4Exception("Par03SensitiveDetector::RetrieveAndSetupHit()", "InvalidSetup", FatalException,
0136                 "Size of hit collection in Par03SensitiveDetector is smaller than the "
0137                 "number of cells created in Par03DetectorConstruction!");
0138   }
0139   Par03Hit* hit = (*fHitsCollection)[hitID];
0140 
0141   if (hit->GetRhoId() < 0) {
0142     hit->SetRhoId(rhoNo);
0143     hit->SetPhiId(phiNo);
0144     hit->SetZid(zNo);
0145     hit->SetLogV(aTouchable->GetVolume(0)->GetLogicalVolume());
0146     G4AffineTransform transform = aTouchable->GetHistory()->GetTopTransform();
0147     hit->SetRot(transform.NetRotation());
0148     transform.Invert();
0149     hit->SetPos(transform.NetTranslation());
0150   }
0151   return hit;
0152 }