Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunAction.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 //
28 //
29 // $Id: RunAction.cc 66994 2013-01-29 14:34:08Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 #include "DetectorConstruction.hh"
36 #include "PrimaryGeneratorAction.hh"
37 #include "RunActionMessenger.hh"
38 
39 #include "G4Run.hh"
40 #include "G4RunManager.hh"
41 #include "G4UnitsTable.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "G4ios.hh"
44 
45 #include "Histo.hh"
46 #include "G4EmCalculator.hh"
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
51  :fDetector(det), fKinematic(kin)
52 {
53  fVerboseLevel = 1;
54  fProjRange = fProjRange2 = fBinLength = fOffsetX = 0.;
55  fHisto = new Histo();
56  fHisto->SetFileName("monopole");
57  // create commands for interactive definition of the detector
58  fRunActionMessenger = new RunActionMessenger(this);
59 }
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {
65  delete fHisto;
66  delete fRunActionMessenger;
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
71 void RunAction::BeginOfRunAction(const G4Run* aRun)
72 {
73  if(GetVerbose() > 0) {
74  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
75  }
76 
77  //initialize projected range, tallies, Ebeam, and book histograms
78  fProjRange = fProjRange2 = 0.;
79 
80  G4double length = fDetector->GetAbsorSizeX();
81  if(0.0 == fBinLength) { fBinLength = 5 * mm; }
82  if(fBinLength > fDetector->GetMaxStepSize()) {
83  fBinLength = fDetector->GetMaxStepSize();
84  }
85  fOffsetX = -0.5 * length;
86 
87  G4int nbBins = G4lrint(length / fBinLength);
88 
89 
90  // Create histograms
91  fHisto->Add1D("1","Edep (MeV/mm) along absorber (mm)", nbBins, 0, length, mm);
92  fHisto->Add1D("2","DEDX (MeV/mm) of proton", 100, -3., 7.);
93  fHisto->Add1D("3","DEDX (MeV/mm) of monopole", 100, -3., 7.);
94  fHisto->Add1D("4","Range(mm) of proton", 100, -3., 7., mm);
95  fHisto->Add1D("5","Range(mm) of monopole", 100, -3., 7., mm);
96 
97  fHisto->Book();
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101 
102 void RunAction::EndOfRunAction(const G4Run* aRun)
103 {
104  G4int nEvents = aRun->GetNumberOfEvent();
105  if (nEvents == 0) { return; }
106 
107  //run conditions
108  //
109  const G4Material* material = fDetector->GetAbsorMaterial();
110  G4double density = material->GetDensity();
111  G4String matName = material->GetName();
112  const G4ParticleDefinition* part =
113  fKinematic->GetParticleGun()->GetParticleDefinition();
114  G4String particle = part->GetParticleName();
115  G4double energy = fKinematic->GetParticleGun()->GetParticleEnergy();
116 
117  if(GetVerbose() > 0){
118  G4cout << "\n The run consists of " << nEvents << " "<< particle << " of "
119  << G4BestUnit(energy,"Energy") << " through "
120  << G4BestUnit(fDetector->GetAbsorSizeX(),"Length") << " of "
121  << matName << " (density: "
122  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
123  };
124 
125  //compute projected range and straggling
126 
127  fProjRange /= nEvents; fProjRange2 /= nEvents;
128  G4double rms = fProjRange2 - fProjRange*fProjRange;
129  if (rms>0.) { rms = std::sqrt(rms); }
130  else { rms = 0.; }
131 
132  if(GetVerbose() > 0){
133  G4cout.precision(5);
134  G4cout << "\n projected Range= " << G4BestUnit(fProjRange, "Length")
135  << " rms= " << G4BestUnit(rms, "Length")
136  << G4endl;
137  };
138 
139  G4double ekin[100], dedxproton[100], dedxmp[100];
140  G4EmCalculator calc;
141  calc.SetVerbose(0);
142  G4int i;
143  for(i = 0; i < 100; ++i) {
144  ekin[i] = std::pow(10., 0.1*G4double(i)) * keV;
145  dedxproton[i] =
146  calc.ComputeElectronicDEDX(ekin[i], "proton", matName);
147  dedxmp[i] =
148  calc.ComputeElectronicDEDX(ekin[i], "monopole", matName);
149  }
150 
151  if(GetVerbose() > 0){
152  G4cout << "### Stopping Powers" << G4endl;
153  for(i=0; i<100; i++) {
154  G4cout << " E(MeV)= " << ekin[i] << " dedxp= " << dedxproton[i]
155  << " dedxmp= " << dedxmp[i]
156  << G4endl;
157  }
158  }
159  G4cout << "### End of stopping power table" << G4endl;
160 
161  // normalize histogram
162  G4double fac = (mm/MeV) / (nEvents * fBinLength);
163  fHisto->ScaleH1(0,fac);
164 
165  if(GetVerbose() > 0){
166  G4cout << "Range table for " << matName << G4endl;
167  }
168 
169  for(i=0; i<100; ++i) {
170  G4double e = std::log10(ekin[i] / MeV) + 0.05;
171  fHisto->Fill(1, e, dedxproton[i]);
172  fHisto->Fill(2, e, dedxmp[i]);
173  fHisto->Fill(3, e, std::log10(calc.GetRange(ekin[i],"proton",matName)/mm));
174  fHisto->Fill(4, e, std::log10(calc.GetRange(ekin[i],"monopole",matName)/mm));
175  }
176 
177  // save and clean histo
178  fHisto->Save();
179 
181 }
182 
183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
184 
186 {
187  if(GetVerbose() > 1) {
188  G4cout << "FillHisto " << ih << " x=" << x << " weight= " << weight
189  << G4endl;
190  }
191  fHisto->Fill(ih, x, weight);
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......