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 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/gammaray_telescope/src/GammaRayTelEventAction.cc (Version 11.3.0) and /examples/advanced/gammaray_telescope/src/GammaRayTelEventAction.cc (Version 11.2)


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