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,v 1.20 2010/06/06 06:18:54 perl Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-cand-00 $ |
---|
29 | // ------------------------------------------------------------ |
---|
30 | // GEANT 4 class implementation file |
---|
31 | // CERN Geneva Switzerland |
---|
32 | // |
---|
33 | // |
---|
34 | // ------------ GammaRayTelEventAction ------ |
---|
35 | // by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000) |
---|
36 | // |
---|
37 | // - inclusion of Digits by F.Longo & R.Giannitrapani (24 oct 2001) |
---|
38 | // |
---|
39 | // - Modification of analysis management by G.Santin (18 Nov 2001) |
---|
40 | // |
---|
41 | // ************************************************************ |
---|
42 | |
---|
43 | #include "GammaRayTelEventAction.hh" |
---|
44 | #include "GammaRayTelTrackerHit.hh" |
---|
45 | #include "GammaRayTelAnticoincidenceHit.hh" |
---|
46 | #include "GammaRayTelCalorimeterHit.hh" |
---|
47 | |
---|
48 | #ifdef G4ANALYSIS_USE |
---|
49 | #include "GammaRayTelAnalysis.hh" |
---|
50 | #endif |
---|
51 | |
---|
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 | |
---|
75 | GammaRayTelEventAction::GammaRayTelEventAction() |
---|
76 | :trackerCollID(-1),calorimeterCollID(-1), |
---|
77 | anticoincidenceCollID(-1), drawFlag("all") |
---|
78 | { |
---|
79 | G4DigiManager * fDM = G4DigiManager::GetDMpointer(); |
---|
80 | GammaRayTelDigitizer * myDM = new GammaRayTelDigitizer( "GammaRayTelDigitizer" ); |
---|
81 | fDM->AddNewModule(myDM); |
---|
82 | } |
---|
83 | |
---|
84 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
85 | |
---|
86 | GammaRayTelEventAction::~GammaRayTelEventAction() |
---|
87 | { |
---|
88 | } |
---|
89 | |
---|
90 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
91 | |
---|
92 | void GammaRayTelEventAction::BeginOfEventAction(const G4Event* evt) |
---|
93 | { |
---|
94 | |
---|
95 | G4int evtNb = evt->GetEventID(); |
---|
96 | G4cout << "Event: " << evtNb << G4endl; |
---|
97 | G4SDManager * SDman = G4SDManager::GetSDMpointer(); |
---|
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 | |
---|
114 | void GammaRayTelEventAction::EndOfEventAction(const G4Event* evt) |
---|
115 | { |
---|
116 | G4int event_id = evt->GetEventID(); |
---|
117 | |
---|
118 | G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer(); |
---|
119 | G4int n_trajectories = 0; |
---|
120 | if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); |
---|
121 | |
---|
122 | |
---|
123 | G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); |
---|
124 | GammaRayTelTrackerHitsCollection* THC = 0; |
---|
125 | GammaRayTelCalorimeterHitsCollection* CHC = 0; |
---|
126 | GammaRayTelAnticoincidenceHitsCollection* AHC = 0; |
---|
127 | |
---|
128 | |
---|
129 | G4DigiManager * fDM = G4DigiManager::GetDMpointer(); |
---|
130 | |
---|
131 | if (HCE) |
---|
132 | { |
---|
133 | THC = (GammaRayTelTrackerHitsCollection*)(HCE->GetHC(trackerCollID)); |
---|
134 | CHC = (GammaRayTelCalorimeterHitsCollection*) |
---|
135 | (HCE->GetHC(calorimeterCollID)); |
---|
136 | AHC = (GammaRayTelAnticoincidenceHitsCollection*) |
---|
137 | (HCE->GetHC(anticoincidenceCollID)); |
---|
138 | |
---|
139 | if (THC) |
---|
140 | { |
---|
141 | int n_hit = THC->entries(); |
---|
142 | G4cout << "Number of tracker hits in this event = " << n_hit << G4endl; |
---|
143 | G4double ESil=0; |
---|
144 | G4int NStrip, NPlane, IsX; |
---|
145 | |
---|
146 | // This is a cycle on all the tracker hits of this event |
---|
147 | |
---|
148 | for (int i=0;i<n_hit;i++) |
---|
149 | { |
---|
150 | // Here we put the hit data in a an ASCII file for |
---|
151 | // later analysis |
---|
152 | ESil = (*THC)[i]->GetEdepSil(); |
---|
153 | NStrip = (*THC)[i]->GetNStrip(); |
---|
154 | NPlane = (*THC)[i]->GetNSilPlane(); |
---|
155 | IsX = (*THC)[i]->GetPlaneType(); |
---|
156 | |
---|
157 | #ifdef G4STORE_DATA |
---|
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 | #ifdef G4ANALYSIS_USE |
---|
176 | |
---|
177 | // Here we fill the histograms of the Analysis manager |
---|
178 | GammaRayTelAnalysis* analysis = GammaRayTelAnalysis::getInstance(); |
---|
179 | |
---|
180 | if(IsX) |
---|
181 | { |
---|
182 | if (analysis->GetHisto2DMode()=="position") |
---|
183 | analysis->InsertPositionXZ((*THC)[i]->GetPos().x()/mm,(*THC)[i]->GetPos().z()/mm); |
---|
184 | else |
---|
185 | analysis->InsertPositionXZ(NStrip, NPlane); |
---|
186 | if (NPlane == 0) analysis->InsertEnergy(ESil/keV); |
---|
187 | analysis->InsertHits(NPlane); |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | if (analysis->GetHisto2DMode()=="position") |
---|
192 | analysis->InsertPositionYZ((*THC)[i]->GetPos().y()/mm,(*THC)[i]->GetPos().z()/mm); |
---|
193 | else |
---|
194 | analysis->InsertPositionYZ(NStrip, NPlane); |
---|
195 | if (NPlane == 0) analysis->InsertEnergy(ESil/keV); |
---|
196 | analysis->InsertHits(NPlane); |
---|
197 | } |
---|
198 | |
---|
199 | #ifdef G4ANALYSIS_USE |
---|
200 | analysis->setNtuple( ESil/keV, NPlane, (*THC)[i]->GetPos().x()/mm, |
---|
201 | (*THC)[i]->GetPos().y()/mm, |
---|
202 | (*THC)[i]->GetPos().z()/mm); |
---|
203 | #endif |
---|
204 | |
---|
205 | #endif |
---|
206 | |
---|
207 | } |
---|
208 | // Here we call the analysis manager function for visualization |
---|
209 | #ifdef G4ANALYSIS_USE |
---|
210 | GammaRayTelAnalysis* analysis = GammaRayTelAnalysis::getInstance(); |
---|
211 | analysis->EndOfEvent(n_hit); |
---|
212 | #endif |
---|
213 | |
---|
214 | } |
---|
215 | |
---|
216 | GammaRayTelDigitizer * myDM = |
---|
217 | (GammaRayTelDigitizer*)fDM->FindDigitizerModule( "GammaRayTelDigitizer" ); |
---|
218 | myDM->Digitize(); |
---|
219 | |
---|
220 | G4int myDigiCollID = fDM->GetDigiCollectionID("DigitsCollection"); |
---|
221 | |
---|
222 | // G4cout << "digi collecion" << myDigiCollID << G4endl; |
---|
223 | |
---|
224 | GammaRayTelDigitsCollection * DC = (GammaRayTelDigitsCollection*)fDM->GetDigiCollection( myDigiCollID ); |
---|
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 | } |
---|
242 | } |
---|
243 | |
---|
244 | |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | |
---|