Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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$
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  // Here we call the analysis manager function for visualization
205 #ifdef G4ANALYSIS_USE
206  GammaRayTelAnalysis* analysis = GammaRayTelAnalysis::getInstance();
207  analysis->EndOfEvent(n_hit);
208 #endif
209 
210  }
211 
212  GammaRayTelDigitizer * myDM =
213  (GammaRayTelDigitizer*)fDM->FindDigitizerModule( "GammaRayTelDigitizer" );
214  myDM->Digitize();
215 
216 #ifdef write_outfile
217  // the whole block is needed only when outfile is active; protect block to avoid
218  // compilations warnings from gcc4.6, Gunter Folger
219 
220  G4int myDigiCollID = fDM->GetDigiCollectionID("DigitsCollection");
221 
222  // G4cout << "digi collecion" << myDigiCollID << G4endl;
223 
225 
226  if(DC) {
227  // G4cout << "Total Digits " << DC->entries() << G4endl;
228  G4int n_digi = DC->entries();
229  G4int NStrip, NPlane, IsX;
230  for (G4int i=0;i<n_digi;i++) {
231  // Here we put the digi data in a an ASCII file for
232  // later analysis
233  NStrip = (*DC)[i]->GetStripNumber();
234  NPlane = (*DC)[i]->GetPlaneNumber();
235  IsX = (*DC)[i]->GetPlaneType();
236 
237  outFile << std::setw(7) << event_id << " " << NStrip <<
238  " " << NPlane << " " << IsX << " " << G4endl;
239  }
240  }
241 #endif
242  }
243 }
244 
245 
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
256