File indexing completed on 2026-03-28 07:51:05
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 "Par01CalorimeterSD.hh"
0030
0031 #include "Par01CalorimeterHit.hh"
0032
0033 #include "G4LogicalVolume.hh"
0034 #include "G4ParticleDefinition.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Track.hh"
0037 #include "G4VPhysicalVolume.hh"
0038 #include "G4ios.hh"
0039
0040
0041
0042 Par01CalorimeterSD::Par01CalorimeterSD(G4String name, G4int nCells, G4String colName)
0043 : G4VSensitiveDetector(name), fNumberOfCells(nCells), fHCID(-1)
0044 {
0045 G4String HCname;
0046 collectionName.insert(HCname = colName);
0047 fCellID = new G4int[fNumberOfCells];
0048 }
0049
0050
0051
0052 Par01CalorimeterSD::~Par01CalorimeterSD()
0053 {
0054 delete[] fCellID;
0055 }
0056
0057
0058
0059 void Par01CalorimeterSD::Initialize(G4HCofThisEvent*)
0060 {
0061 fCalCollection = new Par01CalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]);
0062 for (G4int j = 0; j < fNumberOfCells; j++) {
0063 fCellID[j] = -1;
0064 }
0065 }
0066
0067
0068
0069 G4bool Par01CalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0070 {
0071 G4double edep = aStep->GetTotalEnergyDeposit();
0072 if (edep <= 0.) return false;
0073
0074 auto hist = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
0075 const G4VPhysicalVolume* physVol = hist->GetVolume();
0076 G4int copyID = hist->GetReplicaNumber();
0077
0078 if (fCellID[copyID] == -1) {
0079 Par01CalorimeterHit* calHit = new Par01CalorimeterHit(physVol->GetLogicalVolume());
0080 calHit->SetEdep(edep);
0081 G4AffineTransform aTrans = hist->GetHistory()->GetTopTransform();
0082 aTrans.Invert();
0083 calHit->SetPos(aTrans.NetTranslation());
0084 calHit->SetRot(aTrans.NetRotation());
0085 G4int icell = fCalCollection->insert(calHit);
0086 fCellID[copyID] = icell - 1;
0087 if (verboseLevel > 0) {
0088 G4cout << " New Calorimeter Hit on CellID " << copyID << G4endl;
0089 }
0090 }
0091 else {
0092 (*fCalCollection)[fCellID[copyID]]->AddEdep(edep);
0093 if (verboseLevel > 0) {
0094 G4cout << " Energy added to CellID " << copyID << G4endl;
0095 }
0096 }
0097
0098 return true;
0099 }
0100
0101
0102
0103 void Par01CalorimeterSD::EndOfEvent(G4HCofThisEvent* HCE)
0104 {
0105 if (fHCID < 0) {
0106 fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0107 }
0108 HCE->AddHitsCollection(fHCID, fCalCollection);
0109 }
0110
0111
0112
0113 void Par01CalorimeterSD::clear() {}
0114
0115
0116
0117 void Par01CalorimeterSD::DrawAll() {}
0118
0119
0120
0121 void Par01CalorimeterSD::PrintAll() {}