Geant4_10
EventAction.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: EventAction.cc 68740 2013-04-05 09:56:39Z gcosmo $
27 //
28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30 
31 #include "EventAction.hh"
32 
33 #include "RunAction.hh"
34 #include "PrimaryGeneratorAction.hh"
35 #include "EventActionMessenger.hh"
36 #include "HistoManager.hh"
37 
38 #include "G4SystemOfUnits.hh"
39 #include "G4Event.hh"
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
45 :detector(det), runAct(run), primary(prim), histoManager(hist)
46 {
47  trigger = false;
48  Eseuil = 10*keV;
49 
50  writeFile = false;
51 
52  drawFlag = "none";
53  printModulo = 1000;
54  eventMessenger = new EventActionMessenger(this);
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 {
61  delete eventMessenger;
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  G4int evtNb = evt->GetEventID();
69 
70  //survey printing
71  if (evtNb%printModulo == 0)
72  G4cout << "\n---> Begin Of Event: " << evtNb << G4endl;
73 
74  //initialize Energy per event
75  //
76  G4int nbOfPixels = detector->GetSizeVectorPixels();
77  G4int size = totalEnergy.size();
78  if (size < nbOfPixels) {
79  visibleEnergy.resize(nbOfPixels);
80  totalEnergy.resize(nbOfPixels);
81  }
82 
83  for (G4int k=0; k<nbOfPixels; k++) {
84  visibleEnergy[k] = totalEnergy[k] = 0.0;
85  }
86  nbRadLen = 0.;
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 {
93  G4int n1pxl = detector->GetN1Pixels();
94  G4int n2pxl = detector->GetN2Pixels();
95  G4int n1shift = detector->GetN1Shift();
96 
97  // code for trigger conditions :
98  // 1 and only 1 pixel fired per layer
99  //
100  if (trigger) {
101  for (G4int i1=0; i1<n1pxl; i1++) {
102  //count number of pixels fired
103  G4int count = 0;
104  for (G4int i2=0; i2<n2pxl; i2++) {
105  G4int k = i1*n1shift + i2;
106  if (visibleEnergy[k] > Eseuil) count++;
107  }
108  //if event killed --> skip EndOfEventAction
109  if (count > 1) return;
110  }
111  }
112 
113  //pass informations to RunAction and HistoManager
114  //
115  G4double calorEvis = 0.;
116  G4double calorEtot = 0.;
117  for (G4int i1=0; i1<n1pxl; i1++) {
118  //sum energy per readout layer
119  G4double layerEvis = 0.;
120  G4double layerEtot = 0.;
121  for (G4int i2=0; i2<n2pxl; i2++) {
122  G4int k = i1*n1shift + i2;
123  runAct->fillPerEvent_1(k,visibleEnergy[k],totalEnergy[k]);
124  layerEvis += visibleEnergy[k];
125  layerEtot += totalEnergy[k];
126  calorEvis += visibleEnergy[k];
127  calorEtot += totalEnergy[k];
128  }
129  runAct->fillPerEvent_2(i1,layerEvis,layerEtot);
130  if (layerEvis > 0.) histoManager->FillNtuple(1, i1, layerEvis);
131  if (layerEtot > 0.) histoManager->FillNtuple(1, n1pxl+i1, layerEtot);
132  }
133 
134  histoManager->AddRowNtuple(1);
135 
136  if (calorEvis > 0.) histoManager->FillHisto(1,calorEvis);
137  if (calorEtot > 0.) histoManager->FillHisto(2,calorEtot);
138 
139  G4double Ebeam = primary->GetParticleGun()->GetParticleEnergy();
140  G4double Eleak = Ebeam - calorEtot;
141  runAct->fillPerEvent_3(calorEvis,calorEtot,Eleak);
142 
143  //nb of radiation lenght
144  //
145  runAct->fillNbRadLen(nbRadLen);
146  if (nbRadLen > 0.) histoManager->FillHisto(5,nbRadLen);
147 
148  //write file of pixels
149  //
150  if (writeFile) WritePixels(evt);
151 }
152 
153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
154 
156 {
157  writeFile = val;
158  runAct->SetWriteFile(val);
159 }
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162 
163 #include <fstream>
164 #include "G4RunManager.hh"
165 #include "G4Run.hh"
166 
168 {
169  // event is appended onto file created at BeginOfRun
170  //
171  G4String name = histoManager->GetFileName();
172  G4String fileName = name + ".pixels.ascii";
173 
174  std::ofstream File(fileName, std::ios::app);
175  std::ios::fmtflags mode = File.flags();
176  File.setf( std::ios::scientific, std::ios::floatfield );
177  G4int prec = File.precision(3);
178 
179  //write event number
180  //
181  File << evt->GetEventID() << G4endl;
182 
183  //gun particle informations
184  //
185  G4ParticleGun* gun = primary->GetParticleGun();
186  G4double ekin = gun->GetParticleEnergy();
187  G4ThreeVector direction = gun->GetParticleMomentumDirection();
189  File << ekin << " " << direction << " " << position << G4endl;
190 
191  //count nb of fired pixels
192  //
193  G4int firedPixels = 0;
194  G4int nbOfPixels = detector->GetSizeVectorPixels();
195  for (G4int k=0; k<nbOfPixels; k++) {
196  if (totalEnergy[k] > 0.0) firedPixels++;
197  }
198  File << firedPixels << G4endl;
199 
200  //write pixels
201  //
202  for (G4int k=0; k<nbOfPixels; k++) {
203  if (totalEnergy[k] > 0.0)
204  File << k << " " << visibleEnergy[k] << " " << totalEnergy[k] << " ";
205  }
206  File << G4endl;
207 
208  // restaure default formats
209  File.setf(mode,std::ios::floatfield);
210  File.precision(prec);
211 }
212 
213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
214 
215 
void FillNtuple(G4int id, G4int column, G4double value)
tuple app
Definition: testem0.py:189
void BeginOfEventAction(const G4Event *)
Definition: EventAction.cc:66
void fillNbRadLen(G4double)
Definition: RunAction.cc:155
void AddRowNtuple(G4int id)
void FillHisto(G4int id, G4double bin, G4double weight=1.0)
const XML_Char * name
Definition: expat.h:151
void fillPerEvent_1(G4int, G4double, G4double)
Definition: RunAction.cc:113
G4ThreeVector GetParticlePosition()
void fillPerEvent_2(G4int, G4double, G4double)
Definition: RunAction.cc:123
int G4int
Definition: G4Types.hh:78
G4String GetFileName()
Definition: HistoManager.hh:76
G4int GetEventID() const
Definition: G4Event.hh:140
void EndOfEventAction(const G4Event *)
Definition: EventAction.cc:91
void SetWriteFile(G4bool)
Definition: EventAction.cc:155
G4ParticleMomentum GetParticleMomentumDirection() const
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
TH2F * hist
Definition: plot.C:136
void WritePixels(const G4Event *)
Definition: EventAction.cc:167
G4ParticleGun * GetParticleGun()
void SetWriteFile(G4bool val)
Definition: RunAction.hh:66
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void fillPerEvent_3(G4double, G4double, G4double)
Definition: RunAction.cc:133
G4double GetParticleEnergy() const