G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
CalorimeterSD.cc
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
27
28#include "CalorimeterSD.hh"
29
30#include "G4HCofThisEvent.hh"
31#include "G4SDManager.hh"
32#include "G4Step.hh"
33
34namespace B4c {
35
36//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37
38CalorimeterSD::CalorimeterSD(const G4String& name, const G4String& hitsCollectionName,
39 G4int nofCells)
40 : G4VSensitiveDetector(name), fNofCells(nofCells) {
41 collectionName.insert(hitsCollectionName);
42}
43
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45
46void CalorimeterSD::Initialize(G4HCofThisEvent* hce) {
47 // Create hits collection
48 fHitsCollection = new CalorHitsCollection(SensitiveDetectorName, collectionName[0]);
49
50 // Add this collection in hce
51 auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
52 hce->AddHitsCollection(hcID, fHitsCollection);
53
54 // Create hits
55 // fNofCells for cells + one more for total sums
56 for (G4int i = 0; i < fNofCells + 1; i++) {
57 fHitsCollection->insert(new CalorHit());
58 }
59}
60
61//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62
63G4bool CalorimeterSD::ProcessHits(G4Step* step, G4TouchableHistory*) {
64 // energy deposit
65 auto edep = step->GetTotalEnergyDeposit();
66
67 // step length
68 G4double stepLength = 0.;
69 if (step->GetTrack()->GetDefinition()->GetPDGCharge() != 0.) {
70 stepLength = step->GetStepLength();
71 }
72
73 if (edep == 0. && stepLength == 0.)
74 return false;
75
76 auto touchable = (step->GetPreStepPoint()->GetTouchable());
77
78 // Get calorimeter cell id
79 auto layerNumber = touchable->GetReplicaNumber(1);
80
81 // Get hit accounting data for this cell
82 auto hit = (*fHitsCollection)[layerNumber];
83 if (!hit) {
84 G4ExceptionDescription msg;
85 msg << "Cannot access hit " << layerNumber;
86 G4Exception("CalorimeterSD::ProcessHits()", "MyCode0004", FatalException, msg);
87 }
88
89 // Get hit for total accounting
90 auto hitTotal = (*fHitsCollection)[fHitsCollection->entries() - 1];
91
92 // Add values
93 hit->Add(edep, stepLength);
94 hitTotal->Add(edep, stepLength);
95
96 return true;
97}
98
99//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100
101void CalorimeterSD::EndOfEvent(G4HCofThisEvent*) {
102 if (verboseLevel > 1) {
103 auto nofHits = fHitsCollection->entries();
104 G4cout << G4endl << "-------->Hits Collection: in this event they are " << nofHits
105 << " hits in the tracker chambers: " << G4endl;
106 for (std::size_t i = 0; i < nofHits; ++i)
107 (*fHitsCollection)[i]->Print();
108 }
109}
110
111//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112
113} // namespace B4c
Definition of the B4c::CalorimeterSD class.
void Initialize(G4HCofThisEvent *hitCollection) override
void EndOfEvent(G4HCofThisEvent *hitCollection) override
CalorimeterSD(const G4String &name, const G4String &hitsCollectionName, G4int nofCells)
G4bool ProcessHits(G4Step *step, G4TouchableHistory *history) override
G4THitsCollection< CalorHit > CalorHitsCollection
Definition CalorHit.hh:77