Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 84372 2014-10-14 12:52:34Z gcosmo $
27 //
28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30 
31 #include "EventAction.hh"
32 
33 #include "Run.hh"
34 #include "PrimaryGeneratorAction.hh"
35 #include "HistoManager.hh"
36 
37 #include "G4RunManager.hh"
38 #include "G4SystemOfUnits.hh"
39 #include "G4Event.hh"
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
44 :detector(det), primary(prim)
45 {
46  nbOfModules = detector->GetNbModules();
47  nbOfLayers = detector->GetNbLayers();
48  kLayerMax = nbOfModules*nbOfLayers + 1;
49 
50  EtotCalor = EvisCalor = 0.;
51 }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  EtotLayer.resize(kLayerMax);
64  EvisLayer.resize(kLayerMax);
65  for (G4int k=0; k<kLayerMax; k++) {
66  EtotLayer[k] = EvisLayer[k] = 0.0;
67  }
68  EtotCalor = EvisCalor = 0.;
69  EvisFiber.clear();
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 void EventAction::SumDeStep(G4int iModule, G4int iLayer, G4int iFiber,
75  G4double deStep )
76 {
77  if (iModule > 0) EtotCalor += deStep;
78 
79  G4int kLayer = 0; G4int kFiber = 0;
80  if (iLayer > 0) {
81  kLayer = (iModule-1)*nbOfLayers + iLayer;
82  EtotLayer[kLayer] += deStep;
83  }
84 
85  if (iFiber > 0) {
86  EvisLayer[kLayer] += deStep;
87  EvisCalor += deStep;
88  kFiber = 1000*kLayer + iFiber;
89  EvisFiber[kFiber] += deStep;
90  }
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
94 
96 {
97  //pass informations to Run
98  //
99  Run* run = static_cast<Run*>(
101 
102  for (G4int k=0; k<kLayerMax; k++) {
103  run->SumEvents_1(k,EtotLayer[k],EvisLayer[k]);
104  }
105 
106  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
107  analysisManager->FillH1(1,EtotCalor);
108  analysisManager->FillH1(2,EvisCalor);
109 
110  G4double Ebeam = primary->GetParticleGun()->GetParticleEnergy();
111  G4double Eleak = Ebeam - EtotCalor;
112  run->SumEvents_2(EtotCalor,EvisCalor,Eleak);
113 
114 
115  std::map<G4int,G4double>::iterator it;
116  for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
117  G4int kFiber = it->first;
118  G4int iFiber = kFiber%1000;
119  G4double Evis = it->second;
120  analysisManager->FillH1(5,iFiber+0.5,Evis);
121  }
122 
123  //write fired fibers on a file
124  //
126 }
127 
128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
129 
130 #include <fstream>
131 
133 {
134  // event is appended on a file
135  //
136  G4String name = G4AnalysisManager::Instance()->GetFileName();
137  G4String fileName = name + ".fibers.ascii";
138 
139  std::ofstream File(fileName, std::ios::app);
140  std::ios::fmtflags mode = File.flags();
141  File.setf( std::ios::scientific, std::ios::floatfield );
142  G4int prec = File.precision(3);
143 
144  //write event number
145  //
146  File << evt->GetEventID() << G4endl;
147 
148  //gun particle informations
149  //
150  G4ParticleGun* gun = primary->GetParticleGun();
151  G4double ekin = gun->GetParticleEnergy();
152  G4ThreeVector direction = gun->GetParticleMomentumDirection();
154  File << ekin << " " << direction << " " << position << G4endl;
155 
156  //write fibers
157  //
158  File << EvisFiber.size() << G4endl;
159  //
160  std::map<G4int,G4double>::iterator it;
161  for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
162  G4int kFiber = it->first;
163  G4double Evis = it->second;
164  File << " " << std::setw(7) << kFiber << " "<< std::setw(10) << Evis
165  << G4endl;
166  }
167 
168  File << G4endl;
169 
170  // restaure default formats
171  File.setf(mode,std::ios::floatfield);
172  File.precision(prec);
173 }
174 
175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
176 
The primary generator action class with particle gun.
const XML_Char * name
Definition: expat.h:151
void BeginOfEventAction(const G4Event *)
Definition: EventAction.cc:61
void SumEvents_2(G4double, G4double, G4double)
Definition: Run.cc:95
void WriteFibers(const G4Event *)
Definition: EventAction.cc:132
void SumDeStep(G4int, G4int, G4int, G4double)
Definition: EventAction.cc:74
G4ThreeVector GetParticlePosition()
int G4int
Definition: G4Types.hh:78
G4int GetEventID() const
Definition: G4Event.hh:151
void EndOfEventAction(const G4Event *)
Definition: EventAction.cc:95
G4ParticleMomentum GetParticleMomentumDirection() const
static const double prec
Definition: RanecuEngine.cc:58
tuple app
Definition: demo.py:189
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
void SumEvents_1(G4int, G4double, G4double)
Definition: Run.cc:85
G4ParticleGun * GetParticleGun()
Detector construction class to define materials and geometry.
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
G4Run * GetNonConstCurrentRun() const
G4double GetParticleEnergy() const