Geant4_10
GammaRayTelEventAction.cc
Go to the documentation of this file.
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 // $Id: GammaRayTelEventAction.cc 68794 2013-04-05 13:23:26Z gcosmo $
28 // ------------------------------------------------------------
29 // GEANT 4 class implementation file
30 // CERN Geneva Switzerland
31 //
32 //
33 // ------------ GammaRayTelEventAction ------
34 // by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
35 //
36 // - inclusion of Digits by F.Longo & R.Giannitrapani (24 oct 2001)
37 //
38 // - Modification of analysis management by G.Santin (18 Nov 2001)
39 //
40 // ************************************************************
41 
43 #include "GammaRayTelTrackerHit.hh"
46 
47 #ifdef G4ANALYSIS_USE
48 #include "GammaRayTelAnalysis.hh"
49 #endif
50 
51 #include "G4SystemOfUnits.hh"
52 #include "G4Event.hh"
53 #include "G4EventManager.hh"
54 #include "G4HCofThisEvent.hh"
55 #include "G4VHitsCollection.hh"
56 #include "G4SDManager.hh"
57 #include "G4UImanager.hh"
58 #include "G4ios.hh"
59 #include "G4UnitsTable.hh"
60 #include "Randomize.hh"
61 
62 #include "GammaRayTelDigi.hh"
63 #include "GammaRayTelDigitizer.hh"
64 #include "G4DigiManager.hh"
65 
66 // This file is a global variable in which we store energy deposition per hit
67 // and other relevant information
68 
69 #ifdef G4STORE_DATA
70 extern std::ofstream outFile;
71 #endif
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
74 
76  :trackerCollID(-1),calorimeterCollID(-1),
77  anticoincidenceCollID(-1), drawFlag("all")
78 {
80  GammaRayTelDigitizer * myDM = new GammaRayTelDigitizer( "GammaRayTelDigitizer" );
81  fDM->AddNewModule(myDM);
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
85 
87 {
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
91 
93 {
94 
95  G4int evtNb = evt->GetEventID();
96  G4cout << "Event: " << evtNb << G4endl;
98 
99  if (trackerCollID==-1) {
100  trackerCollID = SDman->GetCollectionID("TrackerCollection");
101  }
102  if(anticoincidenceCollID==-1) {
103  anticoincidenceCollID =
104  SDman->GetCollectionID("AnticoincidenceCollection");
105  }
106  if(calorimeterCollID==-1) {
107  calorimeterCollID =
108  SDman->GetCollectionID("CalorimeterCollection");
109  }
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
113 
115 {
116  G4int event_id = evt->GetEventID();
117 
118 
119  G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
121 // GammaRayTelCalorimeterHitsCollection* CHC = 0;
122 // GammaRayTelAnticoincidenceHitsCollection* AHC = 0;
123 
124 
126 
127  if (HCE)
128  {
129  THC = (GammaRayTelTrackerHitsCollection*)(HCE->GetHC(trackerCollID));
130 // CHC = (GammaRayTelCalorimeterHitsCollection*)
131 // (HCE->GetHC(calorimeterCollID));
132 // AHC = (GammaRayTelAnticoincidenceHitsCollection*)
133 // (HCE->GetHC(anticoincidenceCollID));
134 
135  if (THC)
136  {
137  int n_hit = THC->entries();
138  G4cout << "Number of tracker hits in this event = " << n_hit << G4endl;
139  G4double ESil=0;
140  G4int NStrip, NPlane, IsX;
141 
142  // This is a cycle on all the tracker hits of this event
143 
144  for (int i=0;i<n_hit;i++)
145  {
146  // Here we put the hit data in a an ASCII file for
147  // later analysis
148  ESil = (*THC)[i]->GetEdepSil();
149  NStrip = (*THC)[i]->GetNStrip();
150  NPlane = (*THC)[i]->GetNSilPlane();
151  IsX = (*THC)[i]->GetPlaneType();
152 
153 #ifdef G4STORE_DATA
154  outFile << std::setw(7) << event_id << " " <<
155  ESil/keV << " " << NStrip <<
156  " " << NPlane << " " << IsX << " " <<
157  (*THC)[i]->GetPos().x()/mm <<" "<<
158  (*THC)[i]->GetPos().y()/mm <<" "<<
159  (*THC)[i]->GetPos().z()/mm <<" "<<
160  G4endl;
161 #else
162  G4cout << std::setw(7) << event_id << " " <<
163  ESil/keV << " " << NStrip <<
164  " " << NPlane << " " << IsX << " " <<
165  (*THC)[i]->GetPos().x()/mm <<" "<<
166  (*THC)[i]->GetPos().y()/mm <<" "<<
167  (*THC)[i]->GetPos().z()/mm <<" "<<
168  G4endl;
169 #endif
170 
171 #ifdef G4ANALYSIS_USE
172 
173  // Here we fill the histograms of the Analysis manager
174  GammaRayTelAnalysis* analysis = GammaRayTelAnalysis::getInstance();
175 
176  if(IsX)
177  {
178  if (analysis->GetHisto2DMode()=="position")
179  analysis->InsertPositionXZ((*THC)[i]->GetPos().x()/mm,(*THC)[i]->GetPos().z()/mm);
180  else
181  analysis->InsertPositionXZ(NStrip, NPlane);
182  if (NPlane == 0) analysis->InsertEnergy(ESil/keV);
183  analysis->InsertHits(NPlane);
184  }
185  else
186  {
187  if (analysis->GetHisto2DMode()=="position")
188  analysis->InsertPositionYZ((*THC)[i]->GetPos().y()/mm,(*THC)[i]->GetPos().z()/mm);
189  else
190  analysis->InsertPositionYZ(NStrip, NPlane);
191  if (NPlane == 0) analysis->InsertEnergy(ESil/keV);
192  analysis->InsertHits(NPlane);
193  }
194 
195 #ifdef G4ANALYSIS_USE
196  analysis->setNtuple( ESil/keV, NPlane, (*THC)[i]->GetPos().x()/mm,
197  (*THC)[i]->GetPos().y()/mm,
198  (*THC)[i]->GetPos().z()/mm);
199 #endif
200 
201 #endif
202 
203  }
204 #ifdef G4ANALYSIS_USE
205  GammaRayTelAnalysis* analysis = GammaRayTelAnalysis::getInstance();
206  analysis->EndOfEvent(n_hit);
207 #endif
208 
209  }
210 
211  GammaRayTelDigitizer * myDM =
212  (GammaRayTelDigitizer*)fDM->FindDigitizerModule( "GammaRayTelDigitizer" );
213  myDM->Digitize();
214 
215 #ifdef write_outfile
216  // the whole block is needed only when outfile is active; protect block to avoid
217  // compilations warnings from gcc4.6, Gunter Folger
218 
219  G4int myDigiCollID = fDM->GetDigiCollectionID("DigitsCollection");
220 
221  // G4cout << "digi collecion" << myDigiCollID << G4endl;
222 
224 
225  if(DC) {
226  // G4cout << "Total Digits " << DC->entries() << G4endl;
227  G4int n_digi = DC->entries();
228  G4int NStrip, NPlane, IsX;
229  for (G4int i=0;i<n_digi;i++) {
230  // Here we put the digi data in a an ASCII file for
231  // later analysis
232  NStrip = (*DC)[i]->GetStripNumber();
233  NPlane = (*DC)[i]->GetPlaneNumber();
234  IsX = (*DC)[i]->GetPlaneType();
235 
236  outFile << std::setw(7) << event_id << " " << NStrip <<
237  " " << NPlane << " " << IsX << " " << G4endl;
238  }
239  }
240 #endif
241  }
242 }
243 
244 
245 
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
std::ofstream outFile
Definition: GammaRayTel.cc:68
static G4DigiManager * GetDMpointer()
G4int entries() const
tuple x
Definition: test.py:50
int G4int
Definition: G4Types.hh:78
G4int GetEventID() const
Definition: G4Event.hh:140
Double_t y
Definition: plot.C:279
G4GLOB_DLL std::ostream G4cout
G4int entries() const
virtual void BeginOfEventAction(const G4Event *)
void AddNewModule(G4VDigitizerModule *DM)
G4int GetDigiCollectionID(G4String DCname)
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
tuple z
Definition: test.py:28
virtual void EndOfEventAction(const G4Event *)
#define G4endl
Definition: G4ios.hh:61
const G4VDigiCollection * GetDigiCollection(G4int DCID, G4int eventID=0)
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:174
double G4double
Definition: G4Types.hh:76
G4VDigitizerModule * FindDigitizerModule(G4String mName)