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