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