File indexing completed on 2026-09-19 08:36:58
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 #include "CalorimeterSD.hh"
0030
0031 #include "G4HCofThisEvent.hh"
0032 #include "G4SDManager.hh"
0033 #include "G4Step.hh"
0034
0035 namespace B4c
0036 {
0037
0038
0039
0040 CalorimeterSD::CalorimeterSD(const G4String& name, const G4String& hitsCollectionName,
0041 G4int nofCells)
0042 : G4VSensitiveDetector(name), fNofCells(nofCells)
0043 {
0044 collectionName.insert(hitsCollectionName);
0045 }
0046
0047
0048
0049 void CalorimeterSD::Initialize(G4HCofThisEvent* hce)
0050 {
0051
0052 fHitsCollection = new CalorHitsCollection(SensitiveDetectorName, collectionName[0]);
0053
0054
0055 auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0056 hce->AddHitsCollection(hcID, fHitsCollection);
0057
0058
0059
0060 for (G4int i = 0; i < fNofCells + 1; i++) {
0061 fHitsCollection->insert(new CalorHit());
0062 }
0063 }
0064
0065
0066
0067 G4bool CalorimeterSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0068 {
0069
0070 auto edep = step->GetTotalEnergyDeposit();
0071
0072
0073 G4double stepLength = 0.;
0074 if (step->GetTrack()->GetDefinition()->GetPDGCharge() != 0.) {
0075 stepLength = step->GetStepLength();
0076 }
0077
0078 if (edep == 0. && stepLength == 0.) return false;
0079
0080 auto touchable = (step->GetPreStepPoint()->GetTouchable());
0081
0082
0083 auto layerNumber = touchable->GetReplicaNumber(1);
0084
0085
0086 auto hit = (*fHitsCollection)[layerNumber];
0087 if (!hit) {
0088 G4ExceptionDescription msg;
0089 msg << "Cannot access hit " << layerNumber;
0090 G4Exception("CalorimeterSD::ProcessHits()", "MyCode0004", FatalException, msg);
0091 }
0092
0093
0094 auto hitTotal = (*fHitsCollection)[fHitsCollection->entries() - 1];
0095
0096
0097 hit->Add(edep, stepLength);
0098 hitTotal->Add(edep, stepLength);
0099
0100 return true;
0101 }
0102
0103
0104
0105 void CalorimeterSD::EndOfEvent(G4HCofThisEvent*)
0106 {
0107 if (verboseLevel > 1) {
0108 auto nofHits = fHitsCollection->entries();
0109 G4cout << G4endl << "-------->Hits Collection: in this event they are " << nofHits
0110 << " hits in the tracker chambers: " << G4endl;
0111 for (std::size_t i = 0; i < nofHits; ++i)
0112 (*fHitsCollection)[i]->Print();
0113 }
0114 }
0115
0116
0117
0118 }