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,v 1.8 2009/09/18 17:34:54 maire Exp $ >> 27 // GEANT4 tag $Name: geant4-09-03 $ 26 // 28 // 27 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 28 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 29 31 30 #include "EventAction.hh" 32 #include "EventAction.hh" 31 33 32 #include "Run.hh" << 34 #include "RunAction.hh" 33 #include "PrimaryGeneratorAction.hh" 35 #include "PrimaryGeneratorAction.hh" >> 36 #include "EventActionMessenger.hh" 34 #include "HistoManager.hh" 37 #include "HistoManager.hh" 35 38 36 #include "G4RunManager.hh" << 37 #include "G4SystemOfUnits.hh" << 38 #include "G4Event.hh" 39 #include "G4Event.hh" >> 40 #include "G4TrajectoryContainer.hh" >> 41 #include "G4Trajectory.hh" >> 42 #include "G4VVisManager.hh" 39 43 40 //....oooOO0OOooo........oooOO0OOooo........oo 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 41 45 42 EventAction::EventAction(DetectorConstruction* << 46 EventAction::EventAction(DetectorConstruction* det, RunAction* run, 43 :detector(det), primary(prim) << 47 PrimaryGeneratorAction* prim, HistoManager* hist) 44 { << 48 :detector(det), runAct(run), primary(prim), histoManager(hist) 45 nbOfModules = detector->GetNbModules(); << 49 { 46 nbOfLayers = detector->GetNbLayers(); << 50 trigger = false; 47 kLayerMax = nbOfModules*nbOfLayers + 1; << 51 Eseuil = 10*keV; 48 52 49 EtotCalor = EvisCalor = 0.; << 53 writeFile = false; >> 54 >> 55 drawFlag = "none"; >> 56 printModulo = 1000; >> 57 eventMessenger = new EventActionMessenger(this); 50 } 58 } 51 59 52 //....oooOO0OOooo........oooOO0OOooo........oo 60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 61 54 EventAction::~EventAction() 62 EventAction::~EventAction() 55 { 63 { >> 64 delete eventMessenger; 56 } 65 } 57 66 58 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 68 60 void EventAction::BeginOfEventAction(const G4E << 69 void EventAction::BeginOfEventAction(const G4Event* evt) 61 { << 70 { 62 EtotLayer.resize(kLayerMax); << 71 G4int evtNb = evt->GetEventID(); 63 EvisLayer.resize(kLayerMax); << 72 64 for (G4int k=0; k<kLayerMax; k++) { << 73 //survey printing 65 EtotLayer[k] = EvisLayer[k] = 0.0; << 74 if (evtNb%printModulo == 0) >> 75 G4cout << "\n---> Begin Of Event: " << evtNb << G4endl; >> 76 >> 77 //initialize Energy per event >> 78 // >> 79 G4int nbOfPixels = detector->GetSizeVectorPixels(); >> 80 G4int size = totalEnergy.size(); >> 81 if (size < nbOfPixels) { >> 82 visibleEnergy.resize(nbOfPixels); >> 83 totalEnergy.resize(nbOfPixels); 66 } 84 } 67 EtotCalor = EvisCalor = 0.; << 85 68 EvisFiber.clear(); << 86 for (G4int k=0; k<nbOfPixels; k++) { >> 87 visibleEnergy[k] = totalEnergy[k] = 0.0; >> 88 } >> 89 nbRadLen = 0.; 69 } 90 } 70 91 71 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 93 73 void EventAction::SumDeStep(G4int iModule, G4i << 94 void EventAction::EndOfEventAction(const G4Event* evt) 74 G4double deStep ) << 75 { 95 { 76 if (iModule > 0) EtotCalor += deStep; << 96 G4int n1pxl = detector->GetN1Pixels(); 77 << 97 G4int n2pxl = detector->GetN2Pixels(); 78 G4int kLayer = 0; G4int kFiber = 0; << 98 G4int n1shift = detector->GetN1Shift(); 79 if (iLayer > 0) { << 99 80 kLayer = (iModule-1)*nbOfLayers + iLayer; << 100 // code for trigger conditions : 81 EtotLayer[kLayer] += deStep; << 101 // 1 and only 1 pixel fired per layer >> 102 // >> 103 if (trigger) { >> 104 for (G4int i1=0; i1<n1pxl; i1++) { >> 105 //count number of pixels fired >> 106 G4int count = 0; >> 107 for (G4int i2=0; i2<n2pxl; i2++) { >> 108 G4int k = i1*n1shift + i2; >> 109 if (visibleEnergy[k] > Eseuil) count++; >> 110 } >> 111 //if event killed --> skip EndOfEventAction >> 112 if (count > 1) return; >> 113 } 82 } 114 } 83 115 84 if (iFiber > 0) { << 116 //pass informations to RunAction and HistoManager 85 EvisLayer[kLayer] += deStep; << 86 EvisCalor += deStep; << 87 kFiber = 1000*kLayer + iFiber; << 88 EvisFiber[kFiber] += deStep; << 89 } << 90 } << 91 << 92 //....oooOO0OOooo........oooOO0OOooo........oo << 93 << 94 void EventAction::EndOfEventAction(const G4Eve << 95 { << 96 //pass informations to Run << 97 // 117 // 98 Run* run = static_cast<Run*>( << 118 G4double calorEvis = 0.; 99 G4RunManager::GetRunManager()->Ge << 119 G4double calorEtot = 0.; 100 << 120 for (G4int i1=0; i1<n1pxl; i1++) { 101 for (G4int k=0; k<kLayerMax; k++) { << 121 //sum energy per readout layer 102 run->SumEvents_1(k,EtotLayer[k],EvisLayer << 122 G4double layerEvis = 0.; >> 123 G4double layerEtot = 0.; >> 124 for (G4int i2=0; i2<n2pxl; i2++) { >> 125 G4int k = i1*n1shift + i2; >> 126 runAct->fillPerEvent_1(k,visibleEnergy[k],totalEnergy[k]); >> 127 layerEvis += visibleEnergy[k]; >> 128 layerEtot += totalEnergy[k]; >> 129 calorEvis += visibleEnergy[k]; >> 130 calorEtot += totalEnergy[k]; >> 131 } >> 132 runAct->fillPerEvent_2(i1,layerEvis,layerEtot); >> 133 if (layerEvis > 0.) histoManager->FillNtuple(1, i1, layerEvis); >> 134 if (layerEtot > 0.) histoManager->FillNtuple(1, n1pxl+i1, layerEtot); 103 } 135 } 104 136 105 G4AnalysisManager* analysisManager = G4Analy << 137 histoManager->AddRowNtuple(1); 106 analysisManager->FillH1(1,EtotCalor); << 138 107 analysisManager->FillH1(2,EvisCalor); << 139 if (calorEvis > 0.) histoManager->FillHisto(1,calorEvis); >> 140 if (calorEtot > 0.) histoManager->FillHisto(2,calorEtot); 108 141 109 G4double Ebeam = primary->GetParticleGun()-> 142 G4double Ebeam = primary->GetParticleGun()->GetParticleEnergy(); 110 G4double Eleak = Ebeam - EtotCalor; << 143 G4double Eleak = Ebeam - calorEtot; 111 run->SumEvents_2(EtotCalor,EvisCalor,Eleak); << 144 runAct->fillPerEvent_3(calorEvis,calorEtot,Eleak); 112 145 >> 146 //nb of radiation lenght >> 147 // >> 148 runAct->fillNbRadLen(nbRadLen); >> 149 if (nbRadLen > 0.) histoManager->FillHisto(5,nbRadLen); 113 150 114 std::map<G4int,G4double>::iterator it; << 151 //write file of pixels 115 for (it = EvisFiber.begin(); it != EvisFiber << 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 // 152 // 124 //// WriteFibers(evt); << 153 if (writeFile) WritePixels(evt); >> 154 >> 155 //parameters for trajectory visualisation >> 156 // >> 157 if (G4VVisManager::GetConcreteInstance()) >> 158 { >> 159 G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); >> 160 G4int n_trajectories = 0; >> 161 if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); >> 162 for (G4int i=0; i<n_trajectories; i++) >> 163 { G4Trajectory* trj = (G4Trajectory*) >> 164 ((*(evt->GetTrajectoryContainer()))[i]); >> 165 if (drawFlag == "all") trj->DrawTrajectory(100); >> 166 else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.)) >> 167 trj->DrawTrajectory(100); >> 168 } >> 169 } >> 170 } >> 171 >> 172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 173 >> 174 void EventAction::SetWriteFile(G4bool val) >> 175 { >> 176 writeFile = val; >> 177 runAct->SetWriteFile(val); 125 } 178 } 126 179 127 //....oooOO0OOooo........oooOO0OOooo........oo 180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 128 181 129 #include <fstream> 182 #include <fstream> >> 183 #include "G4RunManager.hh" >> 184 #include "G4Run.hh" 130 185 131 void EventAction::WriteFibers(const G4Event* e << 186 void EventAction::WritePixels(const G4Event* evt) 132 { 187 { 133 // event is appended on a file << 188 // event is appended onto file created at BeginOfRun 134 // 189 // 135 G4String name = G4AnalysisManager::Instance( << 190 G4String name = histoManager->GetFileName(); 136 G4String fileName = name + ".fibers.ascii"; << 191 G4String fileName = name + ".pixels.ascii"; 137 << 192 138 std::ofstream File(fileName, std::ios::app); 193 std::ofstream File(fileName, std::ios::app); 139 std::ios::fmtflags mode = File.flags(); 194 std::ios::fmtflags mode = File.flags(); 140 File.setf( std::ios::scientific, std::ios::f 195 File.setf( std::ios::scientific, std::ios::floatfield ); 141 G4int prec = File.precision(3); 196 G4int prec = File.precision(3); 142 197 143 //write event number 198 //write event number 144 // 199 // 145 File << evt->GetEventID() << G4endl; 200 File << evt->GetEventID() << G4endl; 146 201 147 //gun particle informations 202 //gun particle informations 148 // 203 // 149 G4ParticleGun* gun = primary->GetParticleGun 204 G4ParticleGun* gun = primary->GetParticleGun(); 150 G4double ekin = gun->GetParticleEnergy(); 205 G4double ekin = gun->GetParticleEnergy(); 151 G4ThreeVector direction = gun->GetParticleMo 206 G4ThreeVector direction = gun->GetParticleMomentumDirection(); 152 G4ThreeVector position = gun->GetParticlePo 207 G4ThreeVector position = gun->GetParticlePosition(); 153 File << ekin << " " << direction << " " << p 208 File << ekin << " " << direction << " " << position << G4endl; 154 << 209 155 //write fibers << 210 //count nb of fired pixels 156 // << 157 File << EvisFiber.size() << G4endl; << 158 // 211 // 159 std::map<G4int,G4double>::iterator it; << 212 G4int firedPixels = 0; 160 for (it = EvisFiber.begin(); it != EvisFiber << 213 G4int nbOfPixels = detector->GetSizeVectorPixels(); 161 G4int kFiber = it->first; << 214 for (G4int k=0; k<nbOfPixels; k++) { 162 G4double Evis = it->second; << 215 if (totalEnergy[k] > 0.0) firedPixels++; 163 File << " " << std::setw(7) << kFiber << << 216 } 164 << G4endl; << 217 File << firedPixels << G4endl; 165 } << 218 166 << 219 //write pixels >> 220 // >> 221 for (G4int k=0; k<nbOfPixels; k++) { >> 222 if (totalEnergy[k] > 0.0) >> 223 File << k << " " << visibleEnergy[k] << " " << totalEnergy[k] << " "; >> 224 } 167 File << G4endl; 225 File << G4endl; 168 226 169 // restaure default formats 227 // restaure default formats 170 File.setf(mode,std::ios::floatfield); 228 File.setf(mode,std::ios::floatfield); 171 File.precision(prec); 229 File.precision(prec); 172 } 230 } 173 231 174 //....oooOO0OOooo........oooOO0OOooo........oo 232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 233 175 234 176 235