ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GammaRayTelEventAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GammaRayTelEventAction.cc
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 
42 #include "GammaRayTelTrackerHit.hh"
45 
46 #include "GammaRayTelAnalysis.hh"
47 
48 #include "G4SystemOfUnits.hh"
49 #include "G4Event.hh"
50 #include "G4EventManager.hh"
51 #include "G4HCofThisEvent.hh"
52 #include "G4VHitsCollection.hh"
53 #include "G4SDManager.hh"
54 #include "G4UImanager.hh"
55 #include "G4ios.hh"
56 #include "G4UnitsTable.hh"
57 #include "Randomize.hh"
58 
59 #include "GammaRayTelDigi.hh"
60 #include "GammaRayTelDigitizer.hh"
61 #include "G4DigiManager.hh"
62 
63 // This file is a global variable in which we store energy deposition per hit
64 // and other relevant information
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
67 
69  :trackerCollID(-1),calorimeterCollID(-1),
70  anticoincidenceCollID(-1), drawFlag("all"),
71  theRunAction(runAction)
72 {
73  GammaRayTelDigitizer * myDM = new GammaRayTelDigitizer( "GammaRayTelDigitizer" );
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
78 
80 {;}
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
83 
85 {
86  G4int evtNb = evt->GetEventID();
87  G4cout << "Event: " << evtNb << G4endl;
89 
90  if (trackerCollID==-1) {
91  trackerCollID = SDman->GetCollectionID("TrackerCollection");
92  }
93  if(anticoincidenceCollID==-1) {
95  SDman->GetCollectionID("AnticoincidenceCollection");
96  }
97  if(calorimeterCollID==-1) {
99  SDman->GetCollectionID("CalorimeterCollection");
100  }
101 }
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
104 
106 {
107  G4int event_id = evt->GetEventID();
108 
109 
110  if (!theRunAction)
111  {
112  G4Exception("GammaRayTelEventAction::BeginOfEventAction()",
113  "GTR0001",FatalException,"Null pointer to Run Action: this should not be");
114  }
115 #ifdef G4STORE_DATA
116  std::ofstream* outFile = theRunAction->GetOutputFile();
117 #endif
118 
119  G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
121 
122  // GammaRayTelCalorimeterHitsCollection* CHC = 0;
123  // GammaRayTelAnticoincidenceHitsCollection* AHC = 0;
124 
125 
128 
129  if (HCE)
130  {
132  // CHC = (GammaRayTelCalorimeterHitsCollection*)
133  // (HCE->GetHC(calorimeterCollID));
134  // AHC = (GammaRayTelAnticoincidenceHitsCollection*)
135  // (HCE->GetHC(anticoincidenceCollID));
136 
137  if (THC)
138  {
139  int n_hit = THC->entries();
140  G4cout << "Number of tracker hits in this event = " << n_hit << G4endl;
141  G4double ESil=0;
142  G4int NStrip, NPlane, IsX;
143 
144  // This is a cycle on all the tracker hits of this event
145 
146  for (int i=0;i<n_hit;i++)
147  {
148  // Here we put the hit data in a an ASCII file for
149  // later analysis
150  ESil = (*THC)[i]->GetEdepSil();
151  NStrip = (*THC)[i]->GetNStrip();
152  NPlane = (*THC)[i]->GetNSilPlane();
153  IsX = (*THC)[i]->GetPlaneType();
154 
155 #ifdef G4STORE_DATA
156 
157 
158  (*outFile) << std::setw(7) << event_id << " " <<
159  ESil/keV << " " << NStrip <<
160  " " << NPlane << " " << IsX << " " <<
161  (*THC)[i]->GetPos().x()/mm <<" "<<
162  (*THC)[i]->GetPos().y()/mm <<" "<<
163  (*THC)[i]->GetPos().z()/mm <<" "<<
164  G4endl;
165 #else
166  G4cout << std::setw(7) << event_id << " " <<
167  ESil/keV << " " << NStrip <<
168  " " << NPlane << " " << IsX << " " <<
169  (*THC)[i]->GetPos().x()/mm <<" "<<
170  (*THC)[i]->GetPos().y()/mm <<" "<<
171  (*THC)[i]->GetPos().z()/mm <<" "<<
172  G4endl;
173 #endif
174 
175 
176  // Here we fill the histograms of the Analysis manager
177  if(IsX)
178  {
179  if (analysis->GetHisto2DMode()=="position")
180  analysis->InsertPositionXZ((*THC)[i]->GetPos().x()/mm,(*THC)[i]->GetPos().z()/mm);
181  else
182  analysis->InsertPositionXZ(NStrip, NPlane);
183  if (NPlane == 0) analysis->InsertEnergy(ESil/keV);
184  analysis->InsertHits(NPlane);
185  }
186  else
187  {
188  if (analysis->GetHisto2DMode()=="position")
189  analysis->InsertPositionYZ((*THC)[i]->GetPos().y()/mm,(*THC)[i]->GetPos().z()/mm);
190  else
191  analysis->InsertPositionYZ(NStrip, NPlane);
192  if (NPlane == 0) analysis->InsertEnergy(ESil/keV);
193  analysis->InsertHits(NPlane);
194  }
195 
196  analysis->setNtuple( ESil/keV, NPlane, (*THC)[i]->GetPos().x()/mm,
197  (*THC)[i]->GetPos().y()/mm,
198  (*THC)[i]->GetPos().z()/mm);
199 
200  }
201  analysis->EndOfEvent(n_hit);
202  }
203 
204  GammaRayTelDigitizer * myDM =
205  (GammaRayTelDigitizer*)fDM->FindDigitizerModule( "GammaRayTelDigitizer" );
206  myDM->Digitize();
207 
208 #ifdef G4STORE_DATA
209  // the whole block is needed only when outfile is active; protect block to avoid
210  // compilations warnings from gcc4.6, Gunter Folger
211 
212  G4int myDigiCollID = fDM->GetDigiCollectionID("DigitsCollection");
213 
214  // G4cout << "digi collecion" << myDigiCollID << G4endl;
215 
217 
218  if(DC) {
219  // G4cout << "Total Digits " << DC->entries() << G4endl;
220  G4int n_digi = DC->entries();
221  G4int NStrip, NPlane, IsX;
222  for (G4int i=0;i<n_digi;i++) {
223  // Here we put the digi data in a an ASCII file for
224  // later analysis
225  NStrip = (*DC)[i]->GetStripNumber();
226  NPlane = (*DC)[i]->GetPlaneNumber();
227  IsX = (*DC)[i]->GetPlaneType();
228 
229  (*outFile) << std::setw(7) << event_id << " " << NStrip <<
230  " " << NPlane << " " << IsX << " " << G4endl;
231  }
232  }
233 #endif
234  }
235 }
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248