Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: EventAction.cc 84372 2014-10-14 12:52:34Z gcosmo $ 26 // 27 // 27 //....oooOO0OOooo........oooOO0OOooo........oo 28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 28 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 29 30 30 #include "EventAction.hh" 31 #include "EventAction.hh" 31 32 32 #include "Run.hh" 33 #include "Run.hh" 33 #include "PrimaryGeneratorAction.hh" 34 #include "PrimaryGeneratorAction.hh" 34 #include "HistoManager.hh" 35 #include "HistoManager.hh" 35 36 36 #include "G4RunManager.hh" 37 #include "G4RunManager.hh" 37 #include "G4SystemOfUnits.hh" 38 #include "G4SystemOfUnits.hh" 38 #include "G4Event.hh" 39 #include "G4Event.hh" 39 40 40 //....oooOO0OOooo........oooOO0OOooo........oo 41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 41 42 42 EventAction::EventAction(DetectorConstruction* 43 EventAction::EventAction(DetectorConstruction* det,PrimaryGeneratorAction* prim) 43 :detector(det), primary(prim) 44 :detector(det), primary(prim) 44 { 45 { 45 nbOfModules = detector->GetNbModules(); 46 nbOfModules = detector->GetNbModules(); 46 nbOfLayers = detector->GetNbLayers(); 47 nbOfLayers = detector->GetNbLayers(); 47 kLayerMax = nbOfModules*nbOfLayers + 1; 48 kLayerMax = nbOfModules*nbOfLayers + 1; 48 49 49 EtotCalor = EvisCalor = 0.; 50 EtotCalor = EvisCalor = 0.; 50 } 51 } 51 52 52 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 54 54 EventAction::~EventAction() 55 EventAction::~EventAction() 55 { 56 { 56 } 57 } 57 58 58 //....oooOO0OOooo........oooOO0OOooo........oo 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 60 60 void EventAction::BeginOfEventAction(const G4E 61 void EventAction::BeginOfEventAction(const G4Event*) 61 { 62 { 62 EtotLayer.resize(kLayerMax); 63 EtotLayer.resize(kLayerMax); 63 EvisLayer.resize(kLayerMax); 64 EvisLayer.resize(kLayerMax); 64 for (G4int k=0; k<kLayerMax; k++) { 65 for (G4int k=0; k<kLayerMax; k++) { 65 EtotLayer[k] = EvisLayer[k] = 0.0; 66 EtotLayer[k] = EvisLayer[k] = 0.0; 66 } 67 } 67 EtotCalor = EvisCalor = 0.; 68 EtotCalor = EvisCalor = 0.; 68 EvisFiber.clear(); 69 EvisFiber.clear(); 69 } 70 } 70 71 71 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 73 73 void EventAction::SumDeStep(G4int iModule, G4i 74 void EventAction::SumDeStep(G4int iModule, G4int iLayer, G4int iFiber, 74 G4double deStep ) 75 G4double deStep ) 75 { 76 { 76 if (iModule > 0) EtotCalor += deStep; 77 if (iModule > 0) EtotCalor += deStep; 77 78 78 G4int kLayer = 0; G4int kFiber = 0; 79 G4int kLayer = 0; G4int kFiber = 0; 79 if (iLayer > 0) { 80 if (iLayer > 0) { 80 kLayer = (iModule-1)*nbOfLayers + iLayer; 81 kLayer = (iModule-1)*nbOfLayers + iLayer; 81 EtotLayer[kLayer] += deStep; 82 EtotLayer[kLayer] += deStep; 82 } 83 } 83 84 84 if (iFiber > 0) { 85 if (iFiber > 0) { 85 EvisLayer[kLayer] += deStep; 86 EvisLayer[kLayer] += deStep; 86 EvisCalor += deStep; 87 EvisCalor += deStep; 87 kFiber = 1000*kLayer + iFiber; 88 kFiber = 1000*kLayer + iFiber; 88 EvisFiber[kFiber] += deStep; 89 EvisFiber[kFiber] += deStep; 89 } 90 } 90 } 91 } 91 92 92 //....oooOO0OOooo........oooOO0OOooo........oo 93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 93 94 94 void EventAction::EndOfEventAction(const G4Eve 95 void EventAction::EndOfEventAction(const G4Event*) 95 { 96 { 96 //pass informations to Run 97 //pass informations to Run 97 // 98 // 98 Run* run = static_cast<Run*>( 99 Run* run = static_cast<Run*>( 99 G4RunManager::GetRunManager()->Ge 100 G4RunManager::GetRunManager()->GetNonConstCurrentRun()); 100 101 101 for (G4int k=0; k<kLayerMax; k++) { 102 for (G4int k=0; k<kLayerMax; k++) { 102 run->SumEvents_1(k,EtotLayer[k],EvisLayer 103 run->SumEvents_1(k,EtotLayer[k],EvisLayer[k]); 103 } 104 } 104 105 105 G4AnalysisManager* analysisManager = G4Analy 106 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 106 analysisManager->FillH1(1,EtotCalor); 107 analysisManager->FillH1(1,EtotCalor); 107 analysisManager->FillH1(2,EvisCalor); 108 analysisManager->FillH1(2,EvisCalor); 108 109 109 G4double Ebeam = primary->GetParticleGun()-> 110 G4double Ebeam = primary->GetParticleGun()->GetParticleEnergy(); 110 G4double Eleak = Ebeam - EtotCalor; 111 G4double Eleak = Ebeam - EtotCalor; 111 run->SumEvents_2(EtotCalor,EvisCalor,Eleak); 112 run->SumEvents_2(EtotCalor,EvisCalor,Eleak); 112 113 113 114 114 std::map<G4int,G4double>::iterator it; 115 std::map<G4int,G4double>::iterator it; 115 for (it = EvisFiber.begin(); it != EvisFiber 116 for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) { 116 G4int kFiber = it->first; 117 G4int kFiber = it->first; 117 G4int iFiber = kFiber%1000; 118 G4int iFiber = kFiber%1000; 118 G4double Evis = it->second; 119 G4double Evis = it->second; 119 analysisManager->FillH1(5,iFiber+0.5,Evis); 120 analysisManager->FillH1(5,iFiber+0.5,Evis); 120 } 121 } 121 122 122 //write fired fibers on a file 123 //write fired fibers on a file 123 // 124 // 124 //// WriteFibers(evt); 125 //// WriteFibers(evt); 125 } 126 } 126 127 127 //....oooOO0OOooo........oooOO0OOooo........oo 128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 128 129 129 #include <fstream> 130 #include <fstream> 130 131 131 void EventAction::WriteFibers(const G4Event* e 132 void EventAction::WriteFibers(const G4Event* evt) 132 { 133 { 133 // event is appended on a file 134 // event is appended on a file 134 // 135 // 135 G4String name = G4AnalysisManager::Instance( 136 G4String name = G4AnalysisManager::Instance()->GetFileName(); 136 G4String fileName = name + ".fibers.ascii"; 137 G4String fileName = name + ".fibers.ascii"; 137 138 138 std::ofstream File(fileName, std::ios::app); 139 std::ofstream File(fileName, std::ios::app); 139 std::ios::fmtflags mode = File.flags(); 140 std::ios::fmtflags mode = File.flags(); 140 File.setf( std::ios::scientific, std::ios::f 141 File.setf( std::ios::scientific, std::ios::floatfield ); 141 G4int prec = File.precision(3); 142 G4int prec = File.precision(3); 142 143 143 //write event number 144 //write event number 144 // 145 // 145 File << evt->GetEventID() << G4endl; 146 File << evt->GetEventID() << G4endl; 146 147 147 //gun particle informations 148 //gun particle informations 148 // 149 // 149 G4ParticleGun* gun = primary->GetParticleGun 150 G4ParticleGun* gun = primary->GetParticleGun(); 150 G4double ekin = gun->GetParticleEnergy(); 151 G4double ekin = gun->GetParticleEnergy(); 151 G4ThreeVector direction = gun->GetParticleMo 152 G4ThreeVector direction = gun->GetParticleMomentumDirection(); 152 G4ThreeVector position = gun->GetParticlePo 153 G4ThreeVector position = gun->GetParticlePosition(); 153 File << ekin << " " << direction << " " << p 154 File << ekin << " " << direction << " " << position << G4endl; 154 155 155 //write fibers 156 //write fibers 156 // 157 // 157 File << EvisFiber.size() << G4endl; 158 File << EvisFiber.size() << G4endl; 158 // 159 // 159 std::map<G4int,G4double>::iterator it; 160 std::map<G4int,G4double>::iterator it; 160 for (it = EvisFiber.begin(); it != EvisFiber 161 for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) { 161 G4int kFiber = it->first; 162 G4int kFiber = it->first; 162 G4double Evis = it->second; 163 G4double Evis = it->second; 163 File << " " << std::setw(7) << kFiber << 164 File << " " << std::setw(7) << kFiber << " "<< std::setw(10) << Evis 164 << G4endl; 165 << G4endl; 165 } 166 } 166 167 167 File << G4endl; 168 File << G4endl; 168 169 169 // restaure default formats 170 // restaure default formats 170 File.setf(mode,std::ios::floatfield); 171 File.setf(mode,std::ios::floatfield); 171 File.precision(prec); 172 File.precision(prec); 172 } 173 } 173 174 174 //....oooOO0OOooo........oooOO0OOooo........oo 175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 175 176 176 177