File indexing completed on 2025-02-23 09:22:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include "RE01CalorimeterSD.hh"
0032
0033 #include "RE01CalorimeterHit.hh"
0034
0035 #include "G4LogicalVolume.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4Step.hh"
0038 #include "G4TouchableHistory.hh"
0039 #include "G4Track.hh"
0040 #include "G4VPhysicalVolume.hh"
0041 #include "G4VTouchable.hh"
0042 #include "G4ios.hh"
0043
0044
0045 RE01CalorimeterSD::RE01CalorimeterSD(G4String name)
0046 : G4VSensitiveDetector(name), fCalCollection(0), fNumberOfCellsInZ(20), fNumberOfCellsInPhi(48)
0047 {
0048
0049 for (G4int j = 0; j < fNumberOfCellsInZ; j++)
0050 for (G4int k = 0; k < fNumberOfCellsInPhi; k++) {
0051 fCellID[j][k] = -1;
0052 }
0053
0054 G4String HCname;
0055 collectionName.insert(HCname = "calCollection");
0056 }
0057
0058
0059 RE01CalorimeterSD::~RE01CalorimeterSD()
0060 {
0061 ;
0062 }
0063
0064
0065 void RE01CalorimeterSD::Initialize(G4HCofThisEvent* HCE)
0066 {
0067 fCalCollection = new RE01CalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]);
0068 for (G4int j = 0; j < fNumberOfCellsInZ; j++)
0069 for (G4int k = 0; k < fNumberOfCellsInPhi; k++) {
0070 fCellID[j][k] = -1;
0071 }
0072
0073 static G4int HCID = -1;
0074 if (HCID < 0) {
0075 HCID = GetCollectionID(0);
0076 }
0077 HCE->AddHitsCollection(HCID, fCalCollection);
0078 }
0079
0080
0081 G4bool RE01CalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0082 {
0083
0084
0085
0086
0087
0088 G4double edep = aStep->GetTotalEnergyDeposit();
0089 if (edep == 0.) return false;
0090
0091 const G4VTouchable* ROhist = aStep->GetPreStepPoint()->GetTouchable();
0092 G4int copyIDinZ = ROhist->GetReplicaNumber();
0093 G4int copyIDinPhi = ROhist->GetReplicaNumber(1);
0094
0095 if (fCellID[copyIDinZ][copyIDinPhi] == -1) {
0096 RE01CalorimeterHit* calHit =
0097 new RE01CalorimeterHit(ROhist->GetVolume()->GetLogicalVolume(), copyIDinZ, copyIDinPhi);
0098 calHit->SetEdep(edep);
0099 G4AffineTransform aTrans = ROhist->GetHistory()->GetTopTransform();
0100 aTrans.Invert();
0101 calHit->SetPos(aTrans.NetTranslation());
0102 calHit->SetRot(aTrans.NetRotation());
0103 calHit->SetTrackInformation(aStep->GetTrack());
0104 G4int icell = fCalCollection->insert(calHit);
0105 fCellID[copyIDinZ][copyIDinPhi] = icell - 1;
0106 if (verboseLevel > 0) {
0107 G4cout << " New Calorimeter Hit on CellID " << copyIDinZ << " " << copyIDinPhi << G4endl;
0108 }
0109 }
0110 else {
0111 (*fCalCollection)[fCellID[copyIDinZ][copyIDinPhi]]->AddEdep(edep);
0112 (*fCalCollection)[fCellID[copyIDinZ][copyIDinPhi]]->SetTrackInformation(aStep->GetTrack());
0113 if (verboseLevel > 0) {
0114 G4cout << " Energy added to CellID " << copyIDinZ << " " << copyIDinPhi << G4endl;
0115 }
0116 }
0117
0118 return true;
0119 }