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