Geant4  10.03.p03
 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: GammaRayTelEventAction.cc 82334 2014-06-16 09:59:16Z 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 #include "GammaRayTelAnalysis.hh"
48 
49 #include "G4SystemOfUnits.hh"
50 #include "G4Event.hh"
51 #include "G4EventManager.hh"
52 #include "G4HCofThisEvent.hh"
53 #include "G4VHitsCollection.hh"
54 #include "G4SDManager.hh"
55 #include "G4UImanager.hh"
56 #include "G4ios.hh"
57 #include "G4UnitsTable.hh"
58 #include "Randomize.hh"
59 
60 #include "GammaRayTelDigi.hh"
61 #include "GammaRayTelDigitizer.hh"
62 #include "G4DigiManager.hh"
63 
64 // This file is a global variable in which we store energy deposition per hit
65 // and other relevant information
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
68 
70  :trackerCollID(-1),calorimeterCollID(-1),
71  anticoincidenceCollID(-1), drawFlag("all"),
72  theRunAction(runAction)
73 {
74  GammaRayTelDigitizer * myDM = new GammaRayTelDigitizer( "GammaRayTelDigitizer" );
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
79 
81 {;}
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
84 
86 {
87  G4int evtNb = evt->GetEventID();
88  G4cout << "Event: " << evtNb << G4endl;
90 
91  if (trackerCollID==-1) {
92  trackerCollID = SDman->GetCollectionID("TrackerCollection");
93  }
94  if(anticoincidenceCollID==-1) {
95  anticoincidenceCollID =
96  SDman->GetCollectionID("AnticoincidenceCollection");
97  }
98  if(calorimeterCollID==-1) {
99  calorimeterCollID =
100  SDman->GetCollectionID("CalorimeterCollection");
101  }
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
105 
107 {
108  G4int event_id = evt->GetEventID();
109 
110 
111  if (!theRunAction)
112  {
113  G4Exception("GammaRayTelEventAction::BeginOfEventAction()",
114  "GTR0001",FatalException,"Null pointer to Run Action: this should not be");
115  }
116 #ifdef G4STORE_DATA
117  std::ofstream* outFile = theRunAction->GetOutputFile();
118 #endif
119 
120  G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
122 
123  // GammaRayTelCalorimeterHitsCollection* CHC = 0;
124  // GammaRayTelAnticoincidenceHitsCollection* AHC = 0;
125 
126 
129 
130  if (HCE)
131  {
132  THC = (GammaRayTelTrackerHitsCollection*)(HCE->GetHC(trackerCollID));
133  // CHC = (GammaRayTelCalorimeterHitsCollection*)
134  // (HCE->GetHC(calorimeterCollID));
135  // AHC = (GammaRayTelAnticoincidenceHitsCollection*)
136  // (HCE->GetHC(anticoincidenceCollID));
137 
138  if (THC)
139  {
140  int n_hit = THC->entries();
141  G4cout << "Number of tracker hits in this event = " << n_hit << G4endl;
142  G4double ESil=0;
143  G4int NStrip, NPlane, IsX;
144 
145  // This is a cycle on all the tracker hits of this event
146 
147  for (int i=0;i<n_hit;i++)
148  {
149  // Here we put the hit data in a an ASCII file for
150  // later analysis
151  ESil = (*THC)[i]->GetEdepSil();
152  NStrip = (*THC)[i]->GetNStrip();
153  NPlane = (*THC)[i]->GetNSilPlane();
154  IsX = (*THC)[i]->GetPlaneType();
155 
156 #ifdef G4STORE_DATA
157 
158 
159  (*outFile) << std::setw(7) << event_id << " " <<
160  ESil/keV << " " << NStrip <<
161  " " << NPlane << " " << IsX << " " <<
162  (*THC)[i]->GetPos().x()/mm <<" "<<
163  (*THC)[i]->GetPos().y()/mm <<" "<<
164  (*THC)[i]->GetPos().z()/mm <<" "<<
165  G4endl;
166 #else
167  G4cout << std::setw(7) << event_id << " " <<
168  ESil/keV << " " << NStrip <<
169  " " << NPlane << " " << IsX << " " <<
170  (*THC)[i]->GetPos().x()/mm <<" "<<
171  (*THC)[i]->GetPos().y()/mm <<" "<<
172  (*THC)[i]->GetPos().z()/mm <<" "<<
173  G4endl;
174 #endif
175 
176 
177  // Here we fill the histograms of the Analysis manager
178  if(IsX)
179  {
180  if (analysis->GetHisto2DMode()=="position")
181  analysis->InsertPositionXZ((*THC)[i]->GetPos().x()/mm,(*THC)[i]->GetPos().z()/mm);
182  else
183  analysis->InsertPositionXZ(NStrip, NPlane);
184  if (NPlane == 0) analysis->InsertEnergy(ESil/keV);
185  analysis->InsertHits(NPlane);
186  }
187  else
188  {
189  if (analysis->GetHisto2DMode()=="position")
190  analysis->InsertPositionYZ((*THC)[i]->GetPos().y()/mm,(*THC)[i]->GetPos().z()/mm);
191  else
192  analysis->InsertPositionYZ(NStrip, NPlane);
193  if (NPlane == 0) analysis->InsertEnergy(ESil/keV);
194  analysis->InsertHits(NPlane);
195  }
196 
197  analysis->setNtuple( ESil/keV, NPlane, (*THC)[i]->GetPos().x()/mm,
198  (*THC)[i]->GetPos().y()/mm,
199  (*THC)[i]->GetPos().z()/mm);
200 
201  }
202  analysis->EndOfEvent(n_hit);
203  }
204 
205  GammaRayTelDigitizer * myDM =
206  (GammaRayTelDigitizer*)fDM->FindDigitizerModule( "GammaRayTelDigitizer" );
207  myDM->Digitize();
208 
209 #ifdef G4STORE_DATA
210  // the whole block is needed only when outfile is active; protect block to avoid
211  // compilations warnings from gcc4.6, Gunter Folger
212 
213  G4int myDigiCollID = fDM->GetDigiCollectionID("DigitsCollection");
214 
215  // G4cout << "digi collecion" << myDigiCollID << G4endl;
216 
218 
219  if(DC) {
220  // G4cout << "Total Digits " << DC->entries() << G4endl;
221  G4int n_digi = DC->entries();
222  G4int NStrip, NPlane, IsX;
223  for (G4int i=0;i<n_digi;i++) {
224  // Here we put the digi data in a an ASCII file for
225  // later analysis
226  NStrip = (*DC)[i]->GetStripNumber();
227  NPlane = (*DC)[i]->GetPlaneNumber();
228  IsX = (*DC)[i]->GetPlaneType();
229 
230  (*outFile) << std::setw(7) << event_id << " " << NStrip <<
231  " " << NPlane << " " << IsX << " " << G4endl;
232  }
233  }
234 #endif
235  }
236 }
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
void setNtuple(float E, float p, float x, float y, float z)
std::ofstream * GetOutputFile()
static constexpr double mm
Definition: G4SIunits.hh:115
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
static GammaRayTelAnalysis * getInstance()
void InsertPositionXZ(double x, double z)
static G4DigiManager * GetDMpointer()
G4int entries() const
tuple x
Definition: test.py:50
int G4int
Definition: G4Types.hh:78
GammaRayTelEventAction(GammaRayTelRunAction *runAction=0)
G4int GetEventID() const
Definition: G4Event.hh:151
G4GLOB_DLL std::ostream G4cout
G4int entries() const
void InsertPositionYZ(double y, double z)
virtual void BeginOfEventAction(const G4Event *)
void EndOfEvent(G4int flag)
void AddNewModule(G4VDigitizerModule *DM)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int GetDigiCollectionID(G4String DCname)
void InsertHits(int nplane)
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:185
double G4double
Definition: G4Types.hh:76
void InsertEnergy(double en)
G4VDigitizerModule * FindDigitizerModule(G4String mName)
static constexpr double keV
Definition: G4SIunits.hh:216