Geant4  9.6.p02
 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$
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
62  fHitsCollection
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++ ) {
73  fHitsCollection->insert(new B4cCalorHit());
74  }
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
81 {
82  // energy deposit
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 ) {
102  G4cerr << "Cannot access hit " << layerNumber << G4endl;
103  exit(1);
104  }
105 
106  // Get hit for total accounting
107  B4cCalorHit* 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  G4int nofHits = fHitsCollection->entries();
123  G4cout << "\n-------->Hits Collection: in this event they are " << nofHits
124  << " hits in the tracker chambers: " << G4endl;
125  for ( G4int i=0; i<nofHits; i++ ) (*fHitsCollection)[i]->Print();
126  }
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......