Warning, file /geant4/examples/advanced/amsEcal/src/EventAction.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include "EventAction.hh"
0031
0032 #include "Run.hh"
0033 #include "PrimaryGeneratorAction.hh"
0034 #include "HistoManager.hh"
0035
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Event.hh"
0039
0040
0041
0042 EventAction::EventAction(DetectorConstruction* det,PrimaryGeneratorAction* prim)
0043 :detector(det), primary(prim)
0044 {
0045 nbOfModules = detector->GetNbModules();
0046 nbOfLayers = detector->GetNbLayers();
0047 kLayerMax = nbOfModules*nbOfLayers + 1;
0048
0049 EtotCalor = EvisCalor = 0.;
0050 }
0051
0052
0053
0054 EventAction::~EventAction()
0055 {
0056 }
0057
0058
0059
0060 void EventAction::BeginOfEventAction(const G4Event*)
0061 {
0062 EtotLayer.resize(kLayerMax);
0063 EvisLayer.resize(kLayerMax);
0064 for (G4int k=0; k<kLayerMax; k++) {
0065 EtotLayer[k] = EvisLayer[k] = 0.0;
0066 }
0067 EtotCalor = EvisCalor = 0.;
0068 EvisFiber.clear();
0069 }
0070
0071
0072
0073 void EventAction::SumDeStep(G4int iModule, G4int iLayer, G4int iFiber,
0074 G4double deStep )
0075 {
0076 if (iModule > 0) EtotCalor += deStep;
0077
0078 G4int kLayer = 0; G4int kFiber = 0;
0079 if (iLayer > 0) {
0080 kLayer = (iModule-1)*nbOfLayers + iLayer;
0081 EtotLayer[kLayer] += deStep;
0082 }
0083
0084 if (iFiber > 0) {
0085 EvisLayer[kLayer] += deStep;
0086 EvisCalor += deStep;
0087 kFiber = 1000*kLayer + iFiber;
0088 EvisFiber[kFiber] += deStep;
0089 }
0090 }
0091
0092
0093
0094 void EventAction::EndOfEventAction(const G4Event*)
0095 {
0096
0097
0098 Run* run = static_cast<Run*>(
0099 G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0100
0101 for (G4int k=0; k<kLayerMax; k++) {
0102 run->SumEvents_1(k,EtotLayer[k],EvisLayer[k]);
0103 }
0104
0105 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0106 analysisManager->FillH1(1,EtotCalor);
0107 analysisManager->FillH1(2,EvisCalor);
0108
0109 G4double Ebeam = primary->GetParticleGun()->GetParticleEnergy();
0110 G4double Eleak = Ebeam - EtotCalor;
0111 run->SumEvents_2(EtotCalor,EvisCalor,Eleak);
0112
0113
0114 std::map<G4int,G4double>::iterator it;
0115 for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
0116 G4int kFiber = it->first;
0117 G4int iFiber = kFiber%1000;
0118 G4double Evis = it->second;
0119 analysisManager->FillH1(5,iFiber+0.5,Evis);
0120 }
0121
0122
0123
0124
0125 }
0126
0127
0128
0129 #include <fstream>
0130
0131 void EventAction::WriteFibers(const G4Event* evt)
0132 {
0133
0134
0135 G4String name = G4AnalysisManager::Instance()->GetFileName();
0136 G4String fileName = name + ".fibers.ascii";
0137
0138 std::ofstream File(fileName, std::ios::app);
0139 std::ios::fmtflags mode = File.flags();
0140 File.setf( std::ios::scientific, std::ios::floatfield );
0141 G4int prec = File.precision(3);
0142
0143
0144
0145 File << evt->GetEventID() << G4endl;
0146
0147
0148
0149 G4ParticleGun* gun = primary->GetParticleGun();
0150 G4double ekin = gun->GetParticleEnergy();
0151 G4ThreeVector direction = gun->GetParticleMomentumDirection();
0152 G4ThreeVector position = gun->GetParticlePosition();
0153 File << ekin << " " << direction << " " << position << G4endl;
0154
0155
0156
0157 File << EvisFiber.size() << G4endl;
0158
0159 std::map<G4int,G4double>::iterator it;
0160 for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
0161 G4int kFiber = it->first;
0162 G4double Evis = it->second;
0163 File << " " << std::setw(7) << kFiber << " "<< std::setw(10) << Evis
0164 << G4endl;
0165 }
0166
0167 File << G4endl;
0168
0169
0170 File.setf(mode,std::ios::floatfield);
0171 File.precision(prec);
0172 }
0173
0174
0175