ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4cCalorimeterSD.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B4cCalorimeterSD.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
29 
30 #include "B4cCalorimeterSD.hh"
31 #include "G4HCofThisEvent.hh"
32 #include "G4Step.hh"
33 #include "G4ThreeVector.hh"
34 #include "G4SDManager.hh"
35 #include "G4ios.hh"
36 
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38 
40  const G4String& name,
41  const G4String& hitsCollectionName,
42  G4int nofCells)
43  : G4VSensitiveDetector(name),
44  fHitsCollection(nullptr),
45  fNofCells(nofCells)
46 {
47  collectionName.insert(hitsCollectionName);
48 }
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 
53 {
54 }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 {
60  // Create hits collection
63 
64  // Add this collection in hce
65  auto hcID
67  hce->AddHitsCollection( hcID, fHitsCollection );
68 
69  // Create hits
70  // fNofCells for cells + one more for total sums
71  for (G4int i=0; i<fNofCells+1; i++ ) {
73  }
74 }
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
80 {
81  // energy deposit
82  auto edep = step->GetTotalEnergyDeposit();
83 
84  // step length
85  G4double stepLength = 0.;
86  if ( step->GetTrack()->GetDefinition()->GetPDGCharge() != 0. ) {
87  stepLength = step->GetStepLength();
88  }
89 
90  if ( edep==0. && stepLength == 0. ) return false;
91 
92  auto touchable = (step->GetPreStepPoint()->GetTouchable());
93 
94  // Get calorimeter cell id
95  auto layerNumber = touchable->GetReplicaNumber(1);
96 
97  // Get hit accounting data for this cell
98  auto hit = (*fHitsCollection)[layerNumber];
99  if ( ! hit ) {
101  msg << "Cannot access hit " << layerNumber;
102  G4Exception("B4cCalorimeterSD::ProcessHits()",
103  "MyCode0004", FatalException, msg);
104  }
105 
106  // Get hit for total accounting
107  auto hitTotal
108  = (*fHitsCollection)[fHitsCollection->entries()-1];
109 
110  // Add values
111  hit->Add(edep, stepLength);
112  hitTotal->Add(edep, stepLength);
113 
114  return true;
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 
120 {
121  if ( verboseLevel>1 ) {
122  auto nofHits = fHitsCollection->entries();
123  G4cout
124  << G4endl
125  << "-------->Hits Collection: in this event they are " << nofHits
126  << " hits in the tracker chambers: " << G4endl;
127  for ( std::size_t i=0; i<nofHits; ++i ) (*fHitsCollection)[i]->Print();
128  }
129 }
130 
131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......