ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EventAction.cc
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29 
30 #include "EventAction.hh"
31 
32 #include "Run.hh"
33 #include "PrimaryGeneratorAction.hh"
34 #include "HistoManager.hh"
35 
36 #include "G4RunManager.hh"
37 #include "G4SystemOfUnits.hh"
38 #include "G4Event.hh"
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 
43 :detector(det), primary(prim)
44 {
48 
49  EtotCalor = EvisCalor = 0.;
50 }
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55 {
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
62  EtotLayer.resize(kLayerMax);
63  EvisLayer.resize(kLayerMax);
64  for (G4int k=0; k<kLayerMax; k++) {
65  EtotLayer[k] = EvisLayer[k] = 0.0;
66  }
67  EtotCalor = EvisCalor = 0.;
68  EvisFiber.clear();
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
73 void EventAction::SumDeStep(G4int iModule, G4int iLayer, G4int iFiber,
74  G4double deStep )
75 {
76  if (iModule > 0) EtotCalor += deStep;
77 
78  G4int kLayer = 0; G4int kFiber = 0;
79  if (iLayer > 0) {
80  kLayer = (iModule-1)*nbOfLayers + iLayer;
81  EtotLayer[kLayer] += deStep;
82  }
83 
84  if (iFiber > 0) {
85  EvisLayer[kLayer] += deStep;
86  EvisCalor += deStep;
87  kFiber = 1000*kLayer + iFiber;
88  EvisFiber[kFiber] += deStep;
89  }
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
95 {
96  //pass informations to Run
97  //
98  Run* run = static_cast<Run*>(
100 
101  for (G4int k=0; k<kLayerMax; k++) {
102  run->SumEvents_1(k,EtotLayer[k],EvisLayer[k]);
103  }
104 
105  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
106  analysisManager->FillH1(1,EtotCalor);
107  analysisManager->FillH1(2,EvisCalor);
108 
110  G4double Eleak = Ebeam - EtotCalor;
111  run->SumEvents_2(EtotCalor,EvisCalor,Eleak);
112 
113 
114  std::map<G4int,G4double>::iterator it;
115  for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
116  G4int kFiber = it->first;
117  G4int iFiber = kFiber%1000;
118  G4double Evis = it->second;
119  analysisManager->FillH1(5,iFiber+0.5,Evis);
120  }
121 
122  //write fired fibers on a file
123  //
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
129 #include <fstream>
130 
132 {
133  // event is appended on a file
134  //
136  G4String fileName = name + ".fibers.ascii";
137 
138  std::ofstream File(fileName, std::ios::app);
139  std::ios::fmtflags mode = File.flags();
140  File.setf( std::ios::scientific, std::ios::floatfield );
141  G4int prec = File.precision(3);
142 
143  //write event number
144  //
145  File << evt->GetEventID() << G4endl;
146 
147  //gun particle informations
148  //
150  G4double ekin = gun->GetParticleEnergy();
151  G4ThreeVector direction = gun->GetParticleMomentumDirection();
153  File << ekin << " " << direction << " " << position << G4endl;
154 
155  //write fibers
156  //
157  File << EvisFiber.size() << G4endl;
158  //
159  std::map<G4int,G4double>::iterator it;
160  for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
161  G4int kFiber = it->first;
162  G4double Evis = it->second;
163  File << " " << std::setw(7) << kFiber << " "<< std::setw(10) << Evis
164  << G4endl;
165  }
166 
167  File << G4endl;
168 
169  // restaure default formats
170  File.setf(mode,std::ios::floatfield);
171  File.precision(prec);
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175