[807] | 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 | // |
---|
| 27 | // $Id: Em8EventAction.cc,v 1.10 2007/11/12 10:54:49 vnivanch Exp $ |
---|
[1230] | 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
[807] | 29 | // |
---|
| 30 | // |
---|
| 31 | |
---|
| 32 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 33 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 34 | |
---|
| 35 | #include "Em8EventAction.hh" |
---|
| 36 | |
---|
| 37 | #include "Em8RunAction.hh" |
---|
| 38 | |
---|
| 39 | #include "Em8CalorHit.hh" |
---|
| 40 | #include "Em8EventActionMessenger.hh" |
---|
| 41 | #include "G4Event.hh" |
---|
| 42 | #include "G4EventManager.hh" |
---|
| 43 | #include "G4HCofThisEvent.hh" |
---|
| 44 | #include "G4VHitsCollection.hh" |
---|
| 45 | #include "G4SDManager.hh" |
---|
| 46 | #include "G4UImanager.hh" |
---|
| 47 | #include "G4TrajectoryContainer.hh" |
---|
| 48 | #include "G4Trajectory.hh" |
---|
| 49 | #include "G4VVisManager.hh" |
---|
| 50 | #include "G4ios.hh" |
---|
| 51 | #include "G4UnitsTable.hh" |
---|
| 52 | #include "Randomize.hh" |
---|
| 53 | |
---|
| 54 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 55 | |
---|
| 56 | Em8EventAction::Em8EventAction(Em8RunAction* Em8RA) |
---|
| 57 | :calorimeterCollID(-1),eventMessenger(NULL), |
---|
| 58 | runaction(Em8RA),drawFlag("all"),printModulo(10000) |
---|
| 59 | { |
---|
| 60 | verboselevel = 0; |
---|
| 61 | eventMessenger = new Em8EventActionMessenger(this); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 65 | |
---|
| 66 | Em8EventAction::~Em8EventAction() |
---|
| 67 | { |
---|
| 68 | delete eventMessenger; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 72 | |
---|
| 73 | void Em8EventAction::BeginOfEventAction(const G4Event* evt) |
---|
| 74 | { |
---|
| 75 | G4int evtNb = evt->GetEventID(); |
---|
| 76 | if (evtNb%printModulo == 0) |
---|
| 77 | G4cout << "\n---> Begin of Event: " << evtNb << G4endl; |
---|
| 78 | |
---|
| 79 | if(verboselevel>1) |
---|
| 80 | G4cout << "<<< Event " << evtNb << " started." << G4endl; |
---|
| 81 | |
---|
| 82 | if (calorimeterCollID==-1) |
---|
| 83 | { |
---|
| 84 | G4SDManager * SDman = G4SDManager::GetSDMpointer(); |
---|
| 85 | calorimeterCollID = SDman->GetCollectionID("CalCollection"); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | nstep = 0. ; |
---|
| 89 | nstepCharged = 0. ; |
---|
| 90 | nstepNeutral = 0. ; |
---|
| 91 | Nch = 0. ; |
---|
| 92 | Nne = 0. ; |
---|
| 93 | NE=0.; |
---|
| 94 | NP=0.; |
---|
| 95 | Transmitted=0.; |
---|
| 96 | Reflected =0.; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 100 | |
---|
| 101 | void Em8EventAction::EndOfEventAction(const G4Event* evt) |
---|
| 102 | { |
---|
| 103 | G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); |
---|
| 104 | Em8CalorHitsCollection* CHC = NULL; |
---|
| 105 | if (HCE) |
---|
| 106 | CHC = (Em8CalorHitsCollection*)(HCE->GetHC(calorimeterCollID)); |
---|
| 107 | |
---|
| 108 | if (CHC) |
---|
| 109 | { |
---|
| 110 | int n_hit = CHC->entries(); |
---|
| 111 | // if(verboselevel==2) |
---|
| 112 | // G4cout << " " << n_hit |
---|
| 113 | // << " hits are stored in Em8CalorHitsCollection." << G4endl; |
---|
| 114 | |
---|
| 115 | G4double totEAbs=0, totLAbs=0; |
---|
| 116 | for (int i=0;i<n_hit;i++) |
---|
| 117 | { totEAbs += (*CHC)[i]->GetEdepAbs(); |
---|
| 118 | totLAbs += (*CHC)[i]->GetTrakAbs(); |
---|
| 119 | } |
---|
| 120 | if(verboselevel==2) |
---|
| 121 | G4cout |
---|
| 122 | << " Absorber: total energy: " << std::setw(7) << |
---|
| 123 | G4BestUnit(totEAbs,"Energy") |
---|
| 124 | << " total track length: " << std::setw(7) << |
---|
| 125 | G4BestUnit(totLAbs,"Length") |
---|
| 126 | << G4endl; |
---|
| 127 | |
---|
| 128 | // count event, add deposits to the sum ... |
---|
| 129 | runaction->CountEvent() ; |
---|
| 130 | runaction->AddTrackLength(totLAbs) ; |
---|
| 131 | runaction->AddnStepsCharged(nstepCharged) ; |
---|
| 132 | runaction->AddnStepsNeutral(nstepNeutral) ; |
---|
| 133 | if(verboselevel==2) |
---|
| 134 | G4cout << " Ncharged=" << Nch << " , Nneutral=" << Nne << G4endl; |
---|
| 135 | runaction->CountParticles(Nch,Nne); |
---|
| 136 | runaction->AddEP(NE,NP); |
---|
| 137 | runaction->AddTrRef(Transmitted,Reflected) ; |
---|
| 138 | runaction->AddEdeps(totEAbs) ; |
---|
| 139 | runaction->FillEn(totEAbs) ; |
---|
| 140 | |
---|
| 141 | nstep=nstepCharged+nstepNeutral ; |
---|
| 142 | runaction->FillNbOfSteps(nstep); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); |
---|
| 146 | |
---|
| 147 | if(pVVisManager) |
---|
| 148 | { |
---|
| 149 | G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); |
---|
| 150 | G4int n_trajectories = 0; |
---|
| 151 | if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); |
---|
| 152 | for(G4int i=0; i<n_trajectories; i++) |
---|
| 153 | { G4Trajectory* trj = (G4Trajectory *)((*(evt->GetTrajectoryContainer()))[i]); |
---|
| 154 | if (drawFlag == "all") trj->DrawTrajectory(50); |
---|
| 155 | else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.)) |
---|
| 156 | trj->DrawTrajectory(50); |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | if(verboselevel>0) |
---|
| 161 | G4cout << "<<< Event " << evt->GetEventID() << " ended." << G4endl; |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | //save rndm status |
---|
| 165 | if (runaction->GetRndmFreq() == 2) |
---|
| 166 | { |
---|
| 167 | CLHEP::HepRandom::saveEngineStatus("endOfEvent.rndm"); |
---|
| 168 | G4int evtNb = evt->GetEventID(); |
---|
| 169 | if (evtNb%printModulo == 0) |
---|
| 170 | { |
---|
| 171 | G4cout << "\n---> End of Event: " << evtNb << G4endl; |
---|
| 172 | CLHEP::HepRandom::showEngineStatus(); |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 178 | |
---|
| 179 | G4int Em8EventAction::GetEventno() |
---|
| 180 | { |
---|
| 181 | G4int evno = fpEventManager->GetConstCurrentEvent()->GetEventID() ; |
---|
| 182 | return evno ; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 186 | |
---|
| 187 | void Em8EventAction::setEventVerbose(G4int level) |
---|
| 188 | { |
---|
| 189 | verboselevel = level ; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 193 | |
---|
| 194 | void Em8EventAction::CountStepsCharged() |
---|
| 195 | { |
---|
| 196 | nstepCharged += 1. ; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 200 | |
---|
| 201 | void Em8EventAction::CountStepsNeutral() |
---|
| 202 | { |
---|
| 203 | nstepNeutral += 1. ; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 207 | |
---|
| 208 | void Em8EventAction::AddCharged() |
---|
| 209 | { |
---|
| 210 | Nch += 1.; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 214 | |
---|
| 215 | void Em8EventAction::AddNeutral() |
---|
| 216 | { |
---|
| 217 | Nne += 1.; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 221 | |
---|
| 222 | void Em8EventAction::AddE() |
---|
| 223 | { |
---|
| 224 | NE += 1.; |
---|
| 225 | Nch += 1.; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 229 | |
---|
| 230 | void Em8EventAction::AddP() |
---|
| 231 | { |
---|
| 232 | NP += 1.; |
---|
| 233 | Nch += 1.; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 237 | |
---|
| 238 | void Em8EventAction::SetTr() |
---|
| 239 | { |
---|
| 240 | Transmitted = 1.; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 244 | |
---|
| 245 | void Em8EventAction::SetRef() |
---|
| 246 | { |
---|
| 247 | Reflected = 1.; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 251 | |
---|
| 252 | |
---|