Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
advanced/amsEcal/src/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 // $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 {
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 
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  //
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 
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
void EndOfEventAction(const G4Event *)
const XML_Char * name
Definition: expat.h:151
static const double prec
Definition: RanecuEngine.cc:58
G4int GetEventID() const
Definition: G4Event.hh:151
DetectorConstruction * detector
std::map< G4int, G4double > EvisFiber
#define G4endl
Definition: G4ios.hh:61
void BeginOfEventAction(const G4Event *)
void SumDeStep(G4int, G4int, G4int, G4double)
double G4double
Definition: G4Types.hh:76
void SumEvents_2(G4double, G4double, G4double)
void SumEvents_1(G4int, G4double, G4double)
The primary generator action class with particle gun.
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
G4Run * GetNonConstCurrentRun() const
int G4int
Definition: G4Types.hh:78
G4ThreeVector GetParticlePosition()
G4double GetParticleEnergy() const
void WriteFibers(const G4Event *)
PrimaryGeneratorAction * primary
G4ParticleMomentum GetParticleMomentumDirection() const
std::vector< G4double > EtotLayer
Simple detector construction with a box volume placed in a world.
std::vector< G4double > EvisLayer