Geant4_10
exrdmAnalysisManager.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: exrdmAnalysisManager.cc 68007 2013-03-13 11:28:03Z gcosmo $
27 //
30 //
31 
32 
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
35 
36 #include "exrdmAnalysisManager.hh"
37 #include "G4UnitsTable.hh"
38 #include "exrdmHisto.hh"
39 #include "G4ProcessTable.hh"
40 #include "G4RadioactiveDecay.hh"
41 #include "G4TwoVector.hh"
42 #include "G4SystemOfUnits.hh"
43 
44 #include <fstream>
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
47 
48 exrdmAnalysisManager* exrdmAnalysisManager::fManager = 0;
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
51 
53 {
54  if(!fManager) {
55  fManager = new exrdmAnalysisManager();
56  }
57  return fManager;
58 }
60 {
61  delete fManager;
62  fManager = 0;
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
66 
67 exrdmAnalysisManager::exrdmAnalysisManager()
68 : fVerbose(0), fNEvt1(-1), fNEvt2(-2),
69  fHistEMax (15.0*MeV), fHistEMin (0.),fHistNBin(100),
70  fTargetThresE(10*keV), fDetectorThresE(10*keV),fPulseWidth(1.*microsecond)
71 {
72  fEdepo.clear();
73  fHisto = new exrdmHisto();
74  BookHisto();
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
78 
79 exrdmAnalysisManager::~exrdmAnalysisManager()
80 {
81 #ifdef G4ANALYSIS_USE
82 #define HISTDELETE
83 #endif
84 #ifdef G4ANALYSIS_USE_ROOT
85 #define HISTDELETE
86 #endif
87 #ifdef HISTDELETE
88  delete fHisto;
89 #endif
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
93 
95 {
96  fHistEMax = 15.0*MeV;
97  fHistEMin = .0*MeV;
98  fHistNBin = 100;
99 
100  fHisto->Add1D("H10",
101  "Energy deposit (MeV) in the traget",fHistNBin,fHistEMin,fHistEMax,MeV);
102  fHisto->Add1D("H11",
103  "Energy deposit (MeV) in the detector",fHistNBin,fHistEMin,fHistEMax,MeV);
104  fHisto->Add1D("H12",
105  "Total energy spectrum (MeV) of the traget and detector",fHistNBin,
106  fHistEMin,fHistEMax,MeV);
107  fHisto->Add1D("H13",
108  "Coincidence spectrum (MeV) between the traget and detector",fHistNBin,
109  fHistEMin,fHistEMax,MeV);
110  fHisto->Add1D("H14",
111  "Anti-coincidence spectrum (MeV) in the traget",fHistNBin,
112  fHistEMin,fHistEMax,MeV);
113  fHisto->Add1D("H15",
114  "Anti-coincidence spectrum (MeV) in the detector",fHistNBin,
115  fHistEMin,fHistEMax,MeV);
116  fHisto->Add1D("H16",
117  "Decay emission spectrum (MeV)",fHistNBin,fHistEMin,fHistEMax,MeV);
118  // in aida these histos are indiced from 0-6
119  //
120  fHisto->AddTuple( "T1", "Emitted Particles",
121  "double PID, Energy, Time, Weight" );
122  fHisto->AddTuple( "T2", "RadioIsotopes","double PID, Time, Weight" );
123  fHisto->AddTuple( "T3", "Energy Depositions","double Energy, Time, Weight" );
124  fHisto->AddTuple( "RDecayProducts", "All Products of RDecay",
125  "double PID, Z, A, Energy, Time, Weight" );
126 }
127 
128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
129 
131 {
132  fHisto->Book();
133  G4cout << "exrdmAnalysisManager: Histograms are booked and the run has been started" << G4endl;
136  pTable->FindProcess("RadioactiveDecay", "GenericIon");
137  if (rDecay != NULL) {
138  if (!rDecay->IsAnalogueMonteCarlo()) {
139  std::vector<G4RadioactivityTable*> theTables =
140  rDecay->GetTheRadioactivityTables();
141  for (size_t i = 0 ; i < theTables.size(); i++) {
142  theTables[i]->GetTheMap()->clear();
143  G4cout << " Clear the radioactivity map: 0, new size = "
144  << theTables[i]->GetTheMap()->size() << G4endl;
145  }
146  }
147  }
148 
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
152 
154 {
155  fHisto->Save();
156  G4cout << "exrdmAnalysisManager: Histograms have been saved!" << G4endl;
157 
158  // Output the induced radioactivities
159  // in VR mode only
160  //
163  pTable->FindProcess("RadioactiveDecay", "GenericIon");
164  if (rDecay != NULL) {
165  if (!rDecay->IsAnalogueMonteCarlo()) {
166  G4String fileName = fHisto->GetFileName() + ".activity" ;
167  std::ofstream outfile (fileName, std::ios::out );
168  std::vector<G4RadioactivityTable*> theTables =
169  rDecay->GetTheRadioactivityTables();
170  for (size_t i = 0 ; i < theTables.size(); i++) {
171  G4double rate, error;
172  outfile << "Radioactivities in decay window no. " << i << G4endl;
173  outfile <<
174  "Z \tA \tE \tActivity (decays/window) \tError (decays/window) "
175  << G4endl;
176  map<G4ThreeVector,G4TwoVector> *aMap = theTables[i]->GetTheMap();
177  map<G4ThreeVector,G4TwoVector>::iterator iter;
178  for(iter=aMap->begin(); iter != aMap->end(); iter++) {
179  rate = iter->second.x()/nevent;
180  error = std::sqrt(iter->second.y())/nevent;
181  if ( rate < 0.) rate = 0.; // statically it can be < 0. but it's unphysical
182  outfile << iter->first.x() <<"\t"<< iter->first.y() <<"\t"
183  << iter->first.z() << "\t" << rate <<"\t" << error << G4endl;
184  }
185  outfile << G4endl;
186  }
187  outfile.close();
188  }
189  }
190 }
191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
192 
194 {
195  fEdepo.clear();
196 }
197 
198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
199 
201 {
202  if (fEdepo.size()) {
203  std::sort(fEdepo.begin(),fEdepo.end());
204  G4double TarE = fEdepo[0].GetEnergy();
205  G4double Time = fEdepo[0].GetTime();
206  G4double TarW = fEdepo[0].GetEnergy()*fEdepo[0].GetWeight();
207  G4double DetE = 0.;
208  G4double DetW = 0.;
209  G4double ComW = 0.;
210  if (TarE< 0.) {
211  DetE = -TarE;
212  DetW = -TarW;
213  TarE = 0.;
214  TarW = 0.;
215  }
216  for (size_t i = 1; i < fEdepo.size(); i++) {
217  if (std::fabs((fEdepo[i].GetTime()- Time)/second) <= fPulseWidth) {
218  if ( fEdepo[i].GetEnergy() > 0. ) {
219  TarE += fEdepo[i].GetEnergy();
220  TarW += fEdepo[i].GetEnergy()*fEdepo[i].GetWeight();
221  } else {
222  DetE -= fEdepo[i].GetEnergy();
223  DetW -= fEdepo[i].GetEnergy()*fEdepo[i].GetWeight();
224  }
225  } else {
226  // tallying
227  if (TarE || DetE) ComW = (TarW+DetW)/(TarE+DetE);
228  if (TarE) TarW /= TarE;
229  if (DetE) DetW /= DetE;
230  //
231  if (TarE) fHisto->FillHisto(0,TarE,TarW); // target histogram
232  if (DetE) fHisto->FillHisto(1,DetE,DetW); // Detector histogram
233  if (TarE+DetE) fHisto->FillHisto(2,DetE+TarE,ComW); // Total histogram
234  if (DetE >= fDetectorThresE && TarE >= fTargetThresE )
235  fHisto->FillHisto(3,DetE,DetW); // coincidence histogram
236  if (TarE >= fTargetThresE && DetE < fDetectorThresE)
237  fHisto->FillHisto(4,TarE,TarW); // target anti-coincidence histogram
238  if (TarE < fTargetThresE && DetE >= fDetectorThresE)
239  fHisto->FillHisto(5,DetE,DetW); // detector anti-coincidence histogram
240  //
241  //reset
242  TarE = fEdepo[i].GetEnergy();
243  Time = fEdepo[i].GetTime();
244  TarW = fEdepo[i].GetEnergy()*fEdepo[i].GetWeight();
245  DetE = 0.;
246  DetW = 0.;
247  if (TarE < 0) {
248  DetE = -TarE;
249  DetW = -TarW;
250  TarE = 0.;
251  TarW = 0.;
252  }
253  }
254  }
255  //tally the last hit
256  if (TarE || DetE) ComW = (TarW+DetW)/(TarE+DetE);
257  if (TarE) TarW /= TarE;
258  if (DetE) DetW /= DetE;
259  //
260  if (TarE) fHisto->FillHisto(0,TarE,TarW); // target histogram
261  if (DetE) fHisto->FillHisto(1,DetE,DetW); // Detector histogram
262  if (TarE+DetE) fHisto->FillHisto(2,DetE+TarE,ComW); // Total histogram
263  if (DetE >= fDetectorThresE && TarE >= fTargetThresE )
264  fHisto->FillHisto(3,DetE,DetW); // coincidence histogram
265  if (TarE >= fTargetThresE && DetE < fDetectorThresE)
266  fHisto->FillHisto(4,TarE,TarW); // target anti-coincidence histogram
267  if (TarE < fTargetThresE && DetE >= fDetectorThresE)
268  fHisto->FillHisto(5,DetE,DetW); // detector anti-coincidence histogram
269  // now add zero energy to separat events
270  AddEnergy(0.,0.,0.);
271  }
272 }
273 
274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275 
277  G4double time)
278 {
279  if(1 < fVerbose) {
280  G4cout << "exrdmAnalysisManager::AddEnergy: e(keV)= " << edep/keV
281  << " weight = " << weight << " time (s) = " << time/second
282  << G4endl;
283  }
284  fHisto->FillTuple(2, 0, edep/MeV);
285  fHisto->FillTuple(2,1,time/second);
286  fHisto->FillTuple(2,2,weight);
287  fHisto->AddRow(2);
288  //
289  exrdmEnergyDeposition A(edep,time,weight);
290  fEdepo.push_back(A);
291 }
292 
293 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
294 
296  G4double weight, G4double time )
297 {
298  if(1 < fVerbose) {
299  G4cout << "exrdmAnalysisManager::AddParticle: " << pid
300  << G4endl;
301  }
302  fHisto->FillTuple(0,0, pid);
303  fHisto->FillTuple(0,1,energy/MeV);
304  fHisto->FillTuple(0,2,time/second);
305  fHisto->FillTuple(0,3,weight);
306  fHisto->AddRow(0);
307  // now fill th emission spectrum
308  if (energy>0.0) fHisto->FillHisto(6,energy/MeV,weight);
309 }
310 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
311 
313  G4double time )
314 {
315  if(1 < fVerbose) {
316  G4cout << "exrdmAnalysisManager::AddIsotope: " << pid
317  << G4endl;
318  }
319  fHisto->FillTuple(1,0,pid);
320  fHisto->FillTuple(1,1,time/second);
321  fHisto->FillTuple(1,2,weight);
322  fHisto->AddRow(1);
323 }
324 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
325 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
326 
328  G4double energy, G4double time,
330 {
331  fHisto->FillTuple(3,0,pid);
332  fHisto->FillTuple(3,1,double(Z));
333  fHisto->FillTuple(3,2,double(A));
334  fHisto->FillTuple(3,3,energy);
335  fHisto->FillTuple(3,4,time/s);
336  fHisto->FillTuple(3,5,weight);
337  fHisto->AddRow(3);
338 }
const G4String & GetFileName() const
Definition: exrdmHisto.cc:446
void AddEnergy(G4double, G4double, G4double)
void FillTuple(G4int, const G4String &, G4double)
Definition: exrdmHisto.cc:375
Definition of the exrdmHisto class.
const XML_Char * s
Definition: expat.h:262
void FillHisto(G4int, G4double, G4double)
Definition: exrdmHisto.cc:274
void AddTuple(const G4String &, const G4String &, const G4String &)
Definition: exrdmHisto.cc:333
subroutine sort(A, N)
Definition: dpm25nuc7.f:4670
double weight
Definition: plottest35.C:25
int G4int
Definition: G4Types.hh:78
Double_t edep
Definition: macro.C:13
void AddRow(G4int)
Definition: exrdmHisto.cc:419
G4GLOB_DLL std::ostream G4cout
double energy
Definition: plottest35.C:25
Definition of the exrdmAnalysisManager class.
Float_t Z
Definition: plot.C:39
std::vector< G4RadioactivityTable * > GetTheRadioactivityTables()
void AddDecayProduct(G4double pid, G4int Z, G4int A, G4double energy, G4double time, G4double weight)
void AddParticle(G4double, G4double, G4double, G4double)
void Book()
Definition: exrdmHisto.cc:113
static exrdmAnalysisManager * GetInstance()
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static G4ProcessTable * GetProcessTable()
G4VProcess * FindProcess(const G4String &processName, const G4String &particleName) const
void Add1D(const G4String &, const G4String &, G4int nb=100, G4double x1=0., G4double x2=1., G4double u=1.)
Definition: exrdmHisto.cc:226
int microsecond
Definition: hepunit.py:85
void Save()
Definition: exrdmHisto.cc:196
void AddIsotope(G4double, G4double, G4double)
Int_t nevent
Definition: macro.C:10