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 // $Id: GammaRayTelEventAction.cc 82334 2014-06-16 09:59:16Z gcosmo $ 27 // ------------------------------------------- 28 // ------------------------------------------------------------ 28 // GEANT 4 class implementation file 29 // GEANT 4 class implementation file 29 // CERN Geneva Switzerland 30 // CERN Geneva Switzerland 30 // 31 // 31 // 32 // 32 // ------------ GammaRayTelEventAction - 33 // ------------ GammaRayTelEventAction ------ 33 // by R.Giannitrapani, F.Longo & G. 34 // by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000) 34 // 35 // 35 // - inclusion of Digits by F.Longo & R.Gianni 36 // - inclusion of Digits by F.Longo & R.Giannitrapani (24 oct 2001) 36 // 37 // 37 // - Modification of analysis management by G. 38 // - Modification of analysis management by G.Santin (18 Nov 2001) 38 // 39 // 39 // ******************************************* 40 // ************************************************************ 40 41 41 #include "GammaRayTelEventAction.hh" 42 #include "GammaRayTelEventAction.hh" 42 #include "GammaRayTelTrackerHit.hh" 43 #include "GammaRayTelTrackerHit.hh" 43 #include "GammaRayTelAnticoincidenceHit.hh" 44 #include "GammaRayTelAnticoincidenceHit.hh" 44 #include "GammaRayTelCalorimeterHit.hh" 45 #include "GammaRayTelCalorimeterHit.hh" >> 46 45 #include "GammaRayTelAnalysis.hh" 47 #include "GammaRayTelAnalysis.hh" 46 #include "GammaRayTelDigi.hh" << 47 #include "GammaRayTelDigitizer.hh" << 48 48 49 #include "G4DigiManager.hh" << 49 #include "G4SystemOfUnits.hh" 50 #include "G4Event.hh" 50 #include "G4Event.hh" 51 #include "G4EventManager.hh" 51 #include "G4EventManager.hh" 52 #include "G4HCofThisEvent.hh" 52 #include "G4HCofThisEvent.hh" 53 #include "G4ios.hh" << 53 #include "G4VHitsCollection.hh" 54 #include "G4SDManager.hh" 54 #include "G4SDManager.hh" 55 #include "G4SystemOfUnits.hh" << 56 #include "G4UImanager.hh" 55 #include "G4UImanager.hh" >> 56 #include "G4ios.hh" 57 #include "G4UnitsTable.hh" 57 #include "G4UnitsTable.hh" 58 #include "G4VHitsCollection.hh" << 59 #include "Randomize.hh" 58 #include "Randomize.hh" 60 59 61 //....oooOO0OOooo........oooOO0OOooo........oo << 60 #include "GammaRayTelDigi.hh" >> 61 #include "GammaRayTelDigitizer.hh" >> 62 #include "G4DigiManager.hh" 62 63 63 // This file is a global variable in which we 64 // This file is a global variable in which we store energy deposition per hit 64 // and other relevant information 65 // and other relevant information 65 66 66 GammaRayTelEventAction::GammaRayTelEventAction << 67 auto *digitizer = new GammaRayTelDigitizer << 68 G4DigiManager::GetDMpointer()->AddNewModul << 69 } << 70 << 71 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 72 68 73 GammaRayTelEventAction::~GammaRayTelEventActio << 69 GammaRayTelEventAction::GammaRayTelEventAction(GammaRayTelRunAction* runAction) >> 70 :trackerCollID(-1),calorimeterCollID(-1), >> 71 anticoincidenceCollID(-1), drawFlag("all"), >> 72 theRunAction(runAction) >> 73 { >> 74 GammaRayTelDigitizer * myDM = new GammaRayTelDigitizer( "GammaRayTelDigitizer" ); >> 75 G4DigiManager::GetDMpointer()->AddNewModule(myDM); 74 } 76 } 75 77 76 //....oooOO0OOooo........oooOO0OOooo........oo 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 77 79 78 void GammaRayTelEventAction::BeginOfEventActio << 80 GammaRayTelEventAction::~GammaRayTelEventAction() 79 G4int eventIdentifer = event->GetEventID() << 81 {;} 80 G4cout << "Event: " << eventIdentifer << G << 81 auto *sensitiveDetectorManager = G4SDManag << 82 82 83 if (trackerCollectionID == -1) { << 83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 84 trackerCollectionID = sensitiveDetecto << 84 85 } << 85 void GammaRayTelEventAction::BeginOfEventAction(const G4Event* evt) 86 if (anticoincidenceCollectionID == -1) { << 86 { 87 anticoincidenceCollectionID = sensitiv << 87 G4int evtNb = evt->GetEventID(); 88 } << 88 G4cout << "Event: " << evtNb << G4endl; 89 if (calorimeterCollectionID == -1) { << 89 G4SDManager * SDman = G4SDManager::GetSDMpointer(); 90 calorimeterCollectionID = sensitiveDet << 90 91 } << 91 if (trackerCollID==-1) { >> 92 trackerCollID = SDman->GetCollectionID("TrackerCollection"); >> 93 } >> 94 if(anticoincidenceCollID==-1) { >> 95 anticoincidenceCollID = >> 96 SDman->GetCollectionID("AnticoincidenceCollection"); >> 97 } >> 98 if(calorimeterCollID==-1) { >> 99 calorimeterCollID = >> 100 SDman->GetCollectionID("CalorimeterCollection"); >> 101 } 92 } 102 } 93 103 94 //....oooOO0OOooo........oooOO0OOooo........oo 104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 95 105 96 void GammaRayTelEventAction::EndOfEventAction( << 106 void GammaRayTelEventAction::EndOfEventAction(const G4Event* evt) 97 G4int eventIdentifier = event->GetEventID( << 107 { >> 108 G4int event_id = evt->GetEventID(); 98 109 99 if (theRunAction == nullptr) { << 100 G4Exception("GammaRayTelEventAction::B << 101 } << 102 110 >> 111 if (!theRunAction) >> 112 { >> 113 G4Exception("GammaRayTelEventAction::BeginOfEventAction()", >> 114 "GTR0001",FatalException,"Null pointer to Run Action: this should not be"); >> 115 } 103 #ifdef G4STORE_DATA 116 #ifdef G4STORE_DATA 104 auto *outputFile = theRunAction->GetOutput << 117 std::ofstream* outFile = theRunAction->GetOutputFile(); 105 #endif 118 #endif 106 119 107 auto *collection = event->GetHCofThisEvent << 120 G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); 108 GammaRayTelTrackerHitsCollection *trackerC << 121 GammaRayTelTrackerHitsCollection* THC = 0; 109 // GammaRayTelCalorimeterHitsCollection* c << 110 // GammaRayTelAnticoincidenceHitsCollectio << 111 << 112 auto *fDM = G4DigiManager::GetDMpointer(); << 113 GammaRayTelAnalysis *analysis = GammaRayTe << 114 << 115 if (collection != nullptr) { << 116 trackerCollection = (GammaRayTelTracke << 117 // calorimeterCollection = (GammaRayTe << 118 // anticoincidenceCollection = (GammaR << 119 << 120 if (trackerCollection != nullptr) { << 121 G4int numberOfHits = trackerCollec << 122 G4cout << "Number of tracker hits << 123 << 124 G4double depositedEnergy{0}; << 125 G4int stripNumber; << 126 G4int planeNumber; << 127 G4int isXPlane; << 128 << 129 // This is a cycle on all the trac << 130 << 131 for (auto i = 0; i < numberOfHits; << 132 // Here we put the hit data in << 133 depositedEnergy = (*trackerCol << 134 stripNumber = (*trackerCollect << 135 planeNumber = (*trackerCollect << 136 isXPlane = (*trackerCollection << 137 122 138 #ifdef G4STORE_DATA << 123 // GammaRayTelCalorimeterHitsCollection* CHC = 0; 139 (*outputFile) << std::setw(7) << 124 // GammaRayTelAnticoincidenceHitsCollection* AHC = 0; 140 << " " << depositedEnergy/ << 141 << " " << stripNumber << 142 << " " << planeNumber << 143 << " " << isXPlane << 144 << " " << (*trackerCollect << 145 << " " << (*trackerCollect << 146 << " " << (*trackerCollect << 147 << " " << G4endl; << 148 #else << 149 G4cout << std::setw(7) << even << 150 << " " << depositedEnergy << 151 << " " << stripNumber << 152 << " " << planeNumber << 153 << " " << isXPlane << 154 << " " << (*trackerCollect << 155 << " " << (*trackerCollect << 156 << " " << (*trackerCollect << 157 << " " << G4endl; << 158 #endif << 159 125 160 // Here we fill the histograms << 161 if (isXPlane != 0) { << 162 if (analysis->GetHisto2DMo << 163 analysis->InsertPositi << 164 } else { << 165 analysis->InsertPositi << 166 } << 167 << 168 if (planeNumber == 0) { << 169 analysis->InsertEnergy << 170 } << 171 analysis->InsertHits(plane << 172 } else { << 173 if (analysis->GetHisto2DMo << 174 analysis->InsertPositi << 175 } else { << 176 analysis->InsertPositi << 177 } << 178 if (planeNumber == 0) { << 179 analysis->InsertEnergy << 180 } << 181 analysis->InsertHits(plane << 182 } << 183 analysis->setNtuple(depositedE << 184 (*trackerCollection)[i]->G << 185 (*trackerCollection)[i]->G << 186 (*trackerCollection)[i]->G << 187 ); << 188 } << 189 analysis->EndOfEvent(numberOfHits) << 190 } << 191 126 192 auto *myDM = (GammaRayTelDigitizer*) f << 127 G4DigiManager * fDM = G4DigiManager::GetDMpointer(); 193 myDM->Digitize(); << 128 GammaRayTelAnalysis* analysis = GammaRayTelAnalysis::getInstance(); >> 129 >> 130 if (HCE) >> 131 { >> 132 THC = (GammaRayTelTrackerHitsCollection*)(HCE->GetHC(trackerCollID)); >> 133 // CHC = (GammaRayTelCalorimeterHitsCollection*) >> 134 // (HCE->GetHC(calorimeterCollID)); >> 135 // AHC = (GammaRayTelAnticoincidenceHitsCollection*) >> 136 // (HCE->GetHC(anticoincidenceCollID)); >> 137 >> 138 if (THC) >> 139 { >> 140 int n_hit = THC->entries(); >> 141 G4cout << "Number of tracker hits in this event = " << n_hit << G4endl; >> 142 G4double ESil=0; >> 143 G4int NStrip, NPlane, IsX; >> 144 >> 145 // This is a cycle on all the tracker hits of this event >> 146 >> 147 for (int i=0;i<n_hit;i++) >> 148 { >> 149 // Here we put the hit data in a an ASCII file for >> 150 // later analysis >> 151 ESil = (*THC)[i]->GetEdepSil(); >> 152 NStrip = (*THC)[i]->GetNStrip(); >> 153 NPlane = (*THC)[i]->GetNSilPlane(); >> 154 IsX = (*THC)[i]->GetPlaneType(); >> 155 >> 156 #ifdef G4STORE_DATA >> 157 194 158 >> 159 (*outFile) << std::setw(7) << event_id << " " << >> 160 ESil/keV << " " << NStrip << >> 161 " " << NPlane << " " << IsX << " " << >> 162 (*THC)[i]->GetPos().x()/mm <<" "<< >> 163 (*THC)[i]->GetPos().y()/mm <<" "<< >> 164 (*THC)[i]->GetPos().z()/mm <<" "<< >> 165 G4endl; >> 166 #else >> 167 G4cout << std::setw(7) << event_id << " " << >> 168 ESil/keV << " " << NStrip << >> 169 " " << NPlane << " " << IsX << " " << >> 170 (*THC)[i]->GetPos().x()/mm <<" "<< >> 171 (*THC)[i]->GetPos().y()/mm <<" "<< >> 172 (*THC)[i]->GetPos().z()/mm <<" "<< >> 173 G4endl; >> 174 #endif >> 175 >> 176 >> 177 // Here we fill the histograms of the Analysis manager >> 178 if(IsX) >> 179 { >> 180 if (analysis->GetHisto2DMode()=="position") >> 181 analysis->InsertPositionXZ((*THC)[i]->GetPos().x()/mm,(*THC)[i]->GetPos().z()/mm); >> 182 else >> 183 analysis->InsertPositionXZ(NStrip, NPlane); >> 184 if (NPlane == 0) analysis->InsertEnergy(ESil/keV); >> 185 analysis->InsertHits(NPlane); >> 186 } >> 187 else >> 188 { >> 189 if (analysis->GetHisto2DMode()=="position") >> 190 analysis->InsertPositionYZ((*THC)[i]->GetPos().y()/mm,(*THC)[i]->GetPos().z()/mm); >> 191 else >> 192 analysis->InsertPositionYZ(NStrip, NPlane); >> 193 if (NPlane == 0) analysis->InsertEnergy(ESil/keV); >> 194 analysis->InsertHits(NPlane); >> 195 } >> 196 >> 197 analysis->setNtuple( ESil/keV, NPlane, (*THC)[i]->GetPos().x()/mm, >> 198 (*THC)[i]->GetPos().y()/mm, >> 199 (*THC)[i]->GetPos().z()/mm); >> 200 >> 201 } >> 202 analysis->EndOfEvent(n_hit); >> 203 } >> 204 >> 205 GammaRayTelDigitizer * myDM = >> 206 (GammaRayTelDigitizer*)fDM->FindDigitizerModule( "GammaRayTelDigitizer" ); >> 207 myDM->Digitize(); >> 208 195 #ifdef G4STORE_DATA 209 #ifdef G4STORE_DATA 196 // The whole block is needed only when << 210 // the whole block is needed only when outfile is active; protect block to avoid 197 // protect block to avoid compilations << 211 // compilations warnings from gcc4.6, Gunter Folger 198 212 199 auto digitsCollectionIdentifier = fDM->Get << 213 G4int myDigiCollID = fDM->GetDigiCollectionID("DigitsCollection"); 200 // G4cout << "Digits collection: " << << 201 214 202 auto *digitsCollection = (GammaRayTelDigit << 215 // G4cout << "digi collecion" << myDigiCollID << G4endl; 203 216 204 if (digitsCollection != nullptr) { << 217 GammaRayTelDigitsCollection * DC = (GammaRayTelDigitsCollection*)fDM->GetDigiCollection( myDigiCollID ); 205 auto numberOfDigits = digitsCollec << 218 206 // G4cout << "Total number of digi << 219 if(DC) { 207 << 220 // G4cout << "Total Digits " << DC->entries() << G4endl; 208 G4int stripNumber; << 221 G4int n_digi = DC->entries(); 209 G4int planeNumber; << 222 G4int NStrip, NPlane, IsX; 210 G4int isXPlane; << 223 for (G4int i=0;i<n_digi;i++) { 211 << 224 // Here we put the digi data in a an ASCII file for 212 for (auto i = 0; i < numberOfDigit << 225 // later analysis 213 // Here we put the digi data i << 226 NStrip = (*DC)[i]->GetStripNumber(); 214 stripNumber = (*digitsCollecti << 227 NPlane = (*DC)[i]->GetPlaneNumber(); 215 planeNumber = (*digitsCollecti << 228 IsX = (*DC)[i]->GetPlaneType(); 216 isXPlane = (*digitsCollection) << 229 217 << 230 (*outFile) << std::setw(7) << event_id << " " << NStrip << 218 (*outputFile) << std::setw(7) << 231 " " << NPlane << " " << IsX << " " << G4endl; 219 << eventIdentifier << 232 } 220 << " " << stripNumber << 233 } 221 << " " << planeNumber << 222 << " " << isXPlane << 223 << " " << G4endl; << 224 } << 225 } << 226 #endif 234 #endif 227 } 235 } 228 } 236 } >> 237 >> 238 >> 239 >> 240 >> 241 >> 242 >> 243 >> 244 >> 245 >> 246 >> 247 >> 248 >> 249 229 250