Geant4  10.01
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 87359 2014-12-01 16:04:27Z 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(0),
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
64 
65  // Add this collection in hce
66  G4int 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++ ) {
74  }
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
81 {
82  // energy deposit
83  G4double 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  G4TouchableHistory* touchable
95 
96  // Get calorimeter cell id
97  G4int layerNumber = touchable->GetReplicaNumber(1);
98 
99  // Get hit accounting data for this cell
100  B4cCalorHit* hit = (*fHitsCollection)[layerNumber];
101  if ( ! hit ) {
103  msg << "Cannot access hit " << layerNumber;
104  G4Exception("B4cCalorimeterSD::ProcessHits()",
105  "MyCode0004", FatalException, msg);
106  }
107 
108  // Get hit for total accounting
109  B4cCalorHit* hitTotal
110  = (*fHitsCollection)[fHitsCollection->entries()-1];
111 
112  // Add values
113  hit->Add(edep, stepLength);
114  hitTotal->Add(edep, stepLength);
115 
116  return true;
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
120 
122 {
123  if ( verboseLevel>1 ) {
124  G4int nofHits = fHitsCollection->entries();
125  G4cout
126  << G4endl
127  << "-------->Hits Collection: in this event they are " << nofHits
128  << " hits in the tracker chambers: " << G4endl;
129  for ( G4int i=0; i<nofHits; i++ ) (*fHitsCollection)[i]->Print();
130  }
131 }
132 
133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ParticleDefinition * GetDefinition() const
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double GetStepLength() const
void Add(G4double de, G4double dl)
Definition: B4cCalorHit.hh:100
G4String name
Definition: TRTMaterials.hh:40
G4THitsCollection< B4cCalorHit > B4cCalorHitsCollection
Definition: B4cCalorHit.hh:78
G4int entries() const
G4int insert(T *aHit)
const G4VTouchable * GetTouchable() const
int G4int
Definition: G4Types.hh:78
Calorimeter hit class.
Definition: B4cCalorHit.hh:46
G4StepPoint * GetPreStepPoint() const
B4cCalorHitsCollection * fHitsCollection
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)
G4int GetReplicaNumber(G4int depth=0) const
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)