Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LXeEventAction.cc
Go to the documentation of this file.
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 //
28 //
29 //
30 #include "LXeEventAction.hh"
31 #include "LXeScintHit.hh"
32 #include "LXePMTHit.hh"
34 #include "LXeTrajectory.hh"
35 #include "LXeRecorderBase.hh"
36 
37 #include "G4EventManager.hh"
38 #include "G4SDManager.hh"
39 #include "G4RunManager.hh"
40 #include "G4Event.hh"
41 #include "G4EventManager.hh"
42 #include "G4TrajectoryContainer.hh"
43 #include "G4Trajectory.hh"
44 #include "G4VVisManager.hh"
45 #include "G4ios.hh"
46 #include "G4UImanager.hh"
47 #include "G4SystemOfUnits.hh"
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52  : fRecorder(r),fSaveThreshold(0),fScintCollID(-1),fPMTCollID(-1),fVerbose(0),
53  fPMTThreshold(1),fForcedrawphotons(false),fForcenophotons(false)
54 {
55  fEventMessenger = new LXeEventMessenger(this);
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 
66  //New event, add the user information object
69 
71  if(fScintCollID<0)
72  fScintCollID=SDman->GetCollectionID("scintCollection");
73  if(fPMTCollID<0)
74  fPMTCollID=SDman->GetCollectionID("pmtHitCollection");
75 
76  if(fRecorder)fRecorder->RecordBeginOfEvent(anEvent);
77 }
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
82 
83  LXeUserEventInformation* eventInformation
85 
86  G4TrajectoryContainer* trajectoryContainer=anEvent->GetTrajectoryContainer();
87 
88  G4int n_trajectories = 0;
89  if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
90 
91  // extract the trajectories and draw them
93  for (G4int i=0; i<n_trajectories; i++){
95  ((*(anEvent->GetTrajectoryContainer()))[i]);
96  if(trj->GetParticleName()=="opticalphoton"){
97  trj->SetForceDrawTrajectory(fForcedrawphotons);
98  trj->SetForceNoDrawTrajectory(fForcenophotons);
99  }
100  trj->DrawTrajectory(50);
101  }
102  }
103 
104  LXeScintHitsCollection* scintHC = 0;
105  LXePMTHitsCollection* pmtHC = 0;
106  G4HCofThisEvent* hitsCE = anEvent->GetHCofThisEvent();
107 
108  //Get the hit collections
109  if(hitsCE){
110  if(fScintCollID>=0)scintHC = (LXeScintHitsCollection*)(hitsCE->GetHC(fScintCollID));
111  if(fPMTCollID>=0)pmtHC = (LXePMTHitsCollection*)(hitsCE->GetHC(fPMTCollID));
112  }
113 
114  //Hits in scintillator
115  if(scintHC){
116  int n_hit = scintHC->entries();
117  G4ThreeVector eWeightPos(0.);
118  G4double edep;
119  G4double edepMax=0;
120 
121  for(int i=0;i<n_hit;i++){ //gather info on hits in scintillator
122  edep=(*scintHC)[i]->GetEdep();
123  eventInformation->IncEDep(edep); //sum up the edep
124  eWeightPos += (*scintHC)[i]->GetPos()*edep;//calculate energy weighted pos
125  if(edep>edepMax){
126  edepMax=edep;//store max energy deposit
127  G4ThreeVector posMax=(*scintHC)[i]->GetPos();
128  eventInformation->SetPosMax(posMax,edep);
129  }
130  }
131  if(eventInformation->GetEDep()==0.){
132  if(fVerbose>0)G4cout<<"No hits in the scintillator this event."<<G4endl;
133  }
134  else{
135  //Finish calculation of energy weighted position
136  eWeightPos/=eventInformation->GetEDep();
137  eventInformation->SetEWeightPos(eWeightPos);
138  if(fVerbose>0){
139  G4cout << "\tEnergy weighted position of hits in LXe : "
140  << eWeightPos/mm << G4endl;
141  }
142  }
143  if(fVerbose>0){
144  G4cout << "\tTotal energy deposition in scintillator : "
145  << eventInformation->GetEDep() / keV << " (keV)" << G4endl;
146  }
147  }
148 
149  if(pmtHC){
150  G4ThreeVector reconPos(0.,0.,0.);
151  G4int pmts=pmtHC->entries();
152  //Gather info from all PMTs
153  for(G4int i=0;i<pmts;i++){
154  eventInformation->IncHitCount((*pmtHC)[i]->GetPhotonCount());
155  reconPos+=(*pmtHC)[i]->GetPMTPos()*(*pmtHC)[i]->GetPhotonCount();
156  if((*pmtHC)[i]->GetPhotonCount()>=fPMTThreshold){
157  eventInformation->IncPMTSAboveThreshold();
158  }
159  else{//wasnt above the threshold, turn it back off
160  (*pmtHC)[i]->SetDrawit(false);
161  }
162  }
163 
164  if(eventInformation->GetHitCount()>0){//dont bother unless there were hits
165  reconPos/=eventInformation->GetHitCount();
166  if(fVerbose>0){
167  G4cout << "\tReconstructed position of hits in LXe : "
168  << reconPos/mm << G4endl;
169  }
170  eventInformation->SetReconPos(reconPos);
171  }
172  pmtHC->DrawAllHits();
173  }
174 
175  if(fVerbose>0){
176  //End of event output. later to be controlled by a verbose level
177  G4cout << "\tNumber of photons that hit PMTs in this event : "
178  << eventInformation->GetHitCount() << G4endl;
179  G4cout << "\tNumber of PMTs above threshold("<<fPMTThreshold<<") : "
180  << eventInformation->GetPMTSAboveThreshold() << G4endl;
181  G4cout << "\tNumber of photons produced by scintillation in this event : "
182  << eventInformation->GetPhotonCount_Scint() << G4endl;
183  G4cout << "\tNumber of photons produced by cerenkov in this event : "
184  << eventInformation->GetPhotonCount_Ceren() << G4endl;
185  G4cout << "\tNumber of photons absorbed (OpAbsorption) in this event : "
186  << eventInformation->GetAbsorptionCount() << G4endl;
187  G4cout << "\tNumber of photons absorbed at boundaries (OpBoundary) in "
188  << "this event : " << eventInformation->GetBoundaryAbsorptionCount()
189  << G4endl;
190  G4cout << "Unacounted for photons in this event : "
191  << (eventInformation->GetPhotonCount_Scint() +
192  eventInformation->GetPhotonCount_Ceren() -
193  eventInformation->GetAbsorptionCount() -
194  eventInformation->GetHitCount() -
195  eventInformation->GetBoundaryAbsorptionCount())
196  << G4endl;
197  }
198  //If we have set the flag to save 'special' events, save here
199  if(fSaveThreshold&&eventInformation->GetPhotonCount() <= fSaveThreshold)
201 
202  if(fRecorder)fRecorder->RecordEndOfEvent(anEvent);
203 }
204 
205 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
206 
208 /*Sets the save threshold for the random number seed. If the number of photons
209 generated in an event is lower than this, then save the seed for this event
210 in a file called run###evt###.rndm
211 */
212  fSaveThreshold=save;
215  // G4UImanager::GetUIpointer()->ApplyCommand("/random/setSavingFlag 1");
216 }