Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4cCalorimeterSD.cc
Go to the documentation of this file.
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 // $Id: B4cCalorimeterSD.cc 100946 2016-11-03 11:28:08Z gcosmo $
27 //
30 
31 #include "B4cCalorimeterSD.hh"
32 #include "G4HCofThisEvent.hh"
33 #include "G4Step.hh"
34 #include "G4ThreeVector.hh"
35 #include "G4SDManager.hh"
36 #include "G4ios.hh"
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
41  const G4String& name,
42  const G4String& hitsCollectionName,
43  G4int nofCells)
44  : G4VSensitiveDetector(name),
45  fHitsCollection(nullptr),
46  fNofCells(nofCells)
47 {
48  collectionName.insert(hitsCollectionName);
49 }
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
54 {
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 {
61  // Create hits collection
62  fHitsCollection
64 
65  // Add this collection in hce
66  auto hcID
68  hce->AddHitsCollection( hcID, fHitsCollection );
69 
70  // Create hits
71  // fNofCells for cells + one more for total sums
72  for (G4int i=0; i<fNofCells+1; i++ ) {
73  fHitsCollection->insert(new B4cCalorHit());
74  }
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
81 {
82  // energy deposit
83  auto edep = step->GetTotalEnergyDeposit();
84 
85  // step length
86  G4double stepLength = 0.;
87  if ( step->GetTrack()->GetDefinition()->GetPDGCharge() != 0. ) {
88  stepLength = step->GetStepLength();
89  }
90 
91  if ( edep==0. && stepLength == 0. ) return false;
92 
93  auto touchable = (step->GetPreStepPoint()->GetTouchable());
94 
95  // Get calorimeter cell id
96  auto layerNumber = touchable->GetReplicaNumber(1);
97 
98  // Get hit accounting data for this cell
99  auto hit = (*fHitsCollection)[layerNumber];
100  if ( ! hit ) {
102  msg << "Cannot access hit " << layerNumber;
103  G4Exception("B4cCalorimeterSD::ProcessHits()",
104  "MyCode0004", FatalException, msg);
105  }
106 
107  // Get hit for total accounting
108  auto hitTotal
109  = (*fHitsCollection)[fHitsCollection->entries()-1];
110 
111  // Add values
112  hit->Add(edep, stepLength);
113  hitTotal->Add(edep, stepLength);
114 
115  return true;
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
121 {
122  if ( verboseLevel>1 ) {
123  auto nofHits = fHitsCollection->entries();
124  G4cout
125  << G4endl
126  << "-------->Hits Collection: in this event they are " << nofHits
127  << " hits in the tracker chambers: " << G4endl;
128  for ( G4int i=0; i<nofHits; i++ ) (*fHitsCollection)[i]->Print();
129  }
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ParticleDefinition * GetDefinition() const
const XML_Char * name
Definition: expat.h:151
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double GetStepLength() const
G4int entries() const
G4THitsCollection< B4cCalorHit > B4cCalorHitsCollection
Definition: B4cCalorHit.hh:78
G4int insert(T *aHit)
const G4VTouchable * GetTouchable() const
int G4int
Definition: G4Types.hh:78
G4StepPoint * GetPreStepPoint() const
Definition of the B4cCalorimeterSD class.
B4cCalorimeterSD(const G4String &name, const G4String &hitsCollectionName, G4int nofCells)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
virtual G4bool ProcessHits(G4Step *step, G4TouchableHistory *history)
Definition: G4Step.hh:76
G4double GetTotalEnergyDeposit() const
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
virtual ~B4cCalorimeterSD()
#define G4endl
Definition: G4ios.hh:61
G4CollectionNameVector collectionName
double G4double
Definition: G4Types.hh:76
G4Track * GetTrack() const
G4double GetPDGCharge() const
virtual void Initialize(G4HCofThisEvent *hitCollection)
virtual void EndOfEvent(G4HCofThisEvent *hitCollection)