source: trunk/source/processes/electromagnetic/lowenergy/test/hTest/src/hTestCalorimeterSD.cc @ 1350

Last change on this file since 1350 was 1350, checked in by garnier, 13 years ago

update to last version 4.9.4

File size: 8.6 KB
Line 
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// -------------------------------------------------------------
27//
28//
29// -------------------------------------------------------------
30//      GEANT4 hTest
31//
32//      History: based on object model of
33//      2nd December 1995, G.Cosmo
34//      ---------- hTestCalorimeterSD -------------
35//             
36//  Modified: 05.04.01 Vladimir Ivanchenko new design of hTest
37//
38// -------------------------------------------------------------
39
40//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
41//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42
43#include "hTestCalorimeterSD.hh"
44
45#include "G4RunManager.hh"
46#include "G4VPhysicalVolume.hh"
47#include "G4LogicalVolume.hh"
48#include "G4Track.hh"
49#include "G4Positron.hh"
50#include "globals.hh"
51
52//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53
54hTestCalorimeterSD::hTestCalorimeterSD(G4String name)
55 :G4VSensitiveDetector(name),
56  theHisto(hTestHisto::GetPointer()),
57  evno(0),
58  evnOld(-1),
59  trIDold(-1),
60  delta(1.0e-6*mm)
61{}
62
63//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
64
65hTestCalorimeterSD::~hTestCalorimeterSD()
66{
67  energy.clear();
68}
69
70//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
71
72void hTestCalorimeterSD::Initialize(G4HCofThisEvent*)
73{
74  evno++;
75  if(0 < theHisto->GetVerbose()) 
76    G4cout << "hTestCalorimeterSD: Begin Of Event # " << evno << G4endl;
77
78  numAbs = theHisto->GetNumberOfAbsorbers();
79  energy.resize(numAbs);
80  for(G4int i=0; i<numAbs; i++) { energy[i] = 0.0; }
81  backEnergy = 0.0;
82  leakEnergy = 0.0;
83  G4double gap = theHisto->GetGap();
84  zmax = (theHisto->GetAbsorberThickness() + gap)*numAbs - gap - delta;
85}
86
87//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
88
89G4bool hTestCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
90{
91  G4double edep = aStep->GetTotalEnergyDeposit();
92  //  if(0.0 == edep) return true;
93
94  theHisto->AddTrackLength(aStep->GetStepLength());
95
96  G4int j = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
97   
98  if(j < 0 || j >= numAbs) {
99      G4cout << "Warning!!! hTestCalorimeterSD: cannot add " << edep/MeV
100             << " MeV to the slice # " << j << G4endl;
101
102  } else {
103      energy[j] += edep;
104  }
105
106  if(1 < theHisto->GetVerbose()) {
107      G4cout << "hTestCalorimeterSD: energy = " << edep/MeV
108             << " MeV is deposited at " << j
109             << "-th absorber slice " << G4endl;
110  }
111
112  const G4Track* track = aStep->GetTrack();
113  G4int trIDnow  = track->GetTrackID();
114  G4double tkin  = track->GetKineticEnergy(); 
115  G4double theta = (track->GetMomentumDirection()).theta();
116  G4double zend  = aStep->GetPostStepPoint()->GetPosition().z();
117  //  G4double zstart= aStep->GetPreStepPoint()->GetPosition().z();
118
119  G4bool stop = false;
120  G4bool primary = false;
121  G4bool outAbs = false;
122  if(track->GetNextVolume()->GetName() == "World"
123     && (zend <= delta || zend >= zmax-delta)  ) outAbs = true;
124
125  if(tkin == 0.0) stop = true;
126  if(0 == aStep->GetTrack()->GetParentID()) primary = true;
127
128  // new particle
129  if(trIDnow != trIDold || evno != evnOld) {
130    trIDold = trIDnow;
131    evnOld  = evno;
132    part_is_out = true;
133    tkinold = aStep->GetPreStepPoint()->GetKineticEnergy();
134  }
135
136  // Primary particle stop
137   
138  if(primary && (stop || outAbs)) {
139
140      G4double xend = aStep->GetPostStepPoint()->GetPosition().x();
141      G4double yend = aStep->GetPostStepPoint()->GetPosition().y();
142      theHisto->SaveToTuple("xend",xend/mm);     
143      theHisto->SaveToTuple("yend",yend/mm);     
144      theHisto->SaveToTuple("zend",zend/mm);     
145      theHisto->SaveToTuple("ltpk",(theHisto->GetTrackLength())/mm);     
146      theHisto->SaveToTuple("tend",tkin/MeV);
147      theHisto->SaveToTuple("teta",theta);     
148      theHisto->SaveToTuple("loss",(tkinold-tkin)/MeV);     
149      theHisto->SaveToTuple("dedx",(tkinold-tkin)*mm/(zmax*MeV));     
150
151    // exclude cases when track return back
152
153      if(theHisto->GetTrackLength() < 2.0*zend) theHisto->AddEndPoint(zend);
154
155  }
156
157  // After step in absorber
158
159  if(outAbs && part_is_out) {
160    G4double e = tkin;
161    if(track->GetDefinition() == G4Positron::Positron()) 
162      e += 2.*electron_mass_c2;
163    if(zend > zmax-delta)       leakEnergy += e;
164    else if(zend < delta)       backEnergy += e;
165    part_is_out = false;
166  }
167  return true;
168}
169
170//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
171
172void hTestCalorimeterSD::EndOfEvent(G4HCofThisEvent*)
173{
174  G4int i, j;
175
176  theHisto->SaveToTuple("back",backEnergy);     
177  theHisto->SaveToTuple("leak",leakEnergy);     
178  G4double etot = 0.0;
179
180  // The histogramm on the energy deposition profile
181  if(numAbs > 0) {
182    G4double s = theHisto->GetAbsorberThickness();
183    G4double z = -0.5 * s;
184    for(i=0; i<numAbs; i++) {
185      z += s; 
186      etot += energy[i];
187      theHisto->AddEnergy(energy[i], z);
188    }
189  }
190  theHisto->SaveToTuple(G4String("edep"),etot/MeV);     
191  //theHisto->SaveToTuple(G4String("Evt"),G4double(evno));     
192
193  // Integrated energy deposition to nTuple
194  G4int nMax = 60;
195  G4double EE[60];
196  G4String eSlice[60]={
197      "S0", "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", 
198      "S10", "S11", "S12", "S13", "S14", "S15", "S16", "S17", "S18", "S19", 
199      "S20", "S21", "S22", "S23", "S24", "S25", "S26", "S27", "S28", "S29", 
200      "S30", "S31", "S32", "S33", "S34", "S35", "S36", "S37", "S38", "S39", 
201      "S40", "S41", "S42", "S43", "S44", "S45", "S46", "S47", "S48", "S49", 
202      "S50", "S51", "S52", "S53", "S54", "S55", "S56", "S57", "S58", "S59"};
203  G4String eInteg[60]={
204      "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", 
205      "E10", "E11", "E12", "E13", "E14", "E15", "E16", "E17", "E18", "E19", 
206      "E20", "E21", "E22", "E23", "E24", "E25", "E26", "E27", "E28", "E29", 
207      "E30", "E31", "E32", "E33", "E34", "E35", "E36", "E37", "E38", "E39", 
208      "E40", "E41", "E42", "E43", "E44", "E45", "E46", "E47", "E48", "E49", 
209      "E50", "E51", "E52", "E53", "E54", "E55", "E56", "E57", "E58", "E59"};
210
211  G4int k = theHisto->GetNumAbsorbersSaved();
212  if (nMax > k) nMax = k;
213
214  if(nMax > 1) {
215    for(i=0; i<nMax; i++){
216      EE[i]=0.0;
217      for(j=0; j<i+1; j++) {
218        EE[i] += energy[j];
219      } 
220      //   theHisto->SaveToTuple(eSlice[i],energy[i]);     
221      // theHisto->SaveToTuple(eInteg[i],EE[i]);     
222    }
223  }
224
225  // Dump information about this event
226  theHisto->SaveEvent();
227
228  if(0 < theHisto->GetVerbose()) { 
229    G4cout << "hTestCalorimeterSD: Event #" << evno << " ended" << G4endl;
230    G4cout << "Edep(MeV)= " << etot/MeV
231           << "; backE(MeV)= " << backEnergy/MeV
232           << "; leakE(MeV)= " << leakEnergy/MeV
233           << G4endl;
234  }
235}
236
237//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
238
239void hTestCalorimeterSD::clear()
240{} 
241
242//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
243
244
245void hTestCalorimeterSD::PrintAll()
246{} 
247
248//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
249
250
251
252
253
254
255
Note: See TracBrowser for help on using the repository browser.