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