Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 07:51:08

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