Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
A01EventAction.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 //
28 //
29 // $Id$
30 // --------------------------------------------------------------
31 //
32 
33 #include "A01EventAction.hh"
35 #ifdef G4ANALYSIS_USE
36 #include "A01AnalysisManager.hh"
37 #endif // G4ANALYSIS_USE
38 
39 #include "G4Event.hh"
40 #include "G4EventManager.hh"
41 #include "G4HCofThisEvent.hh"
42 #include "G4VHitsCollection.hh"
43 #include "G4TrajectoryContainer.hh"
44 #include "G4Trajectory.hh"
45 #include "G4VVisManager.hh"
46 #include "G4SDManager.hh"
47 #include "G4UImanager.hh"
48 #include "G4ios.hh"
49 #include "G4SystemOfUnits.hh"
50 
51 #include "A01HodoscopeHit.hh"
52 #include "A01DriftChamberHit.hh"
53 #include "A01EmCalorimeterHit.hh"
54 
55 #include "A01HadCalorimeterHit.hh"
56 
58 {
59  G4String colName;
61  fHHC1ID = SDman->GetCollectionID(colName="hodoscope1/hodoscopeColl");
62  fHHC2ID = SDman->GetCollectionID(colName="hodoscope2/hodoscopeColl");
63  fDHC1ID = SDman->GetCollectionID(colName="chamber1/driftChamberColl");
64  fDHC2ID = SDman->GetCollectionID(colName="chamber2/driftChamberColl");
65  fECHCID = SDman->GetCollectionID(colName="EMcalorimeter/EMcalorimeterColl");
66  fHCHCID = SDman->GetCollectionID(colName="HadCalorimeter/HadCalorimeterColl");
67  fVerboseLevel = 1;
68  fMessenger = new A01EventActionMessenger(this);
69 
70 #ifdef G4ANALYSIS_USE
71  fPlotter = 0;
72  fTuple = 0;
73  fDc1Hits = fDc2Hits = 0;
74  fDc1XY = fDc2XY = fEvstof = 0;
75 
76  // Do some analysis
77 
79  IHistogramFactory* hFactory = analysisManager->getHistogramFactory();
80 
81  if (hFactory)
82  {
83  // Create some histograms
84  fDc1Hits = hFactory->createHistogram1D("Drift Chamber 1 # Hits",50,0,50);
85  fDc2Hits = hFactory->createHistogram1D("Drift Chamber 2 # Hits",50,0,50);
86 
87  // Create some clouds (Scatter Plots)
88  fDc1XY = hFactory->createCloud2D("Drift Chamber 1 X vs Y");
89  fDc2XY = hFactory->createCloud2D("Drift Chamber 2 X vs Y");
90  fEvstof = hFactory->createCloud2D("EDep vs Time-of-flight");
91 
92  fPlotter = analysisManager->getPlotter();
93  if (fPlotter)
94  {
95  fPlotter->createRegions(3,2);
96  fPlotter->region(0)->plot(*fDc1Hits);
97  fPlotter->region(1)->plot(*fDc2Hits);
98  fPlotter->region(2)->plot(*fDc1XY);
99  fPlotter->region(3)->plot(*fDc2XY);
100  fPlotter->region(4)->plot(*fEvstof);
101  fPlotter->show();
102  }
103  }
104 
105  // Create a Tuple
106 
107  ITupleFactory* tFactory = analysisManager->getTupleFactory();
108  if (tFactory)
109  {
110  fTuple = tFactory->create("MyTuple","MyTuple","int fDc1Hits, fDc2Hits, double ECEnergy, HCEnergy, time1, time2","");
111  }
112 #endif // G4ANALYSIS_USE
113 }
114 
116 {
117 #ifdef G4ANALYSIS_USE
119 #endif // G4ANALYSIS_USE
120  delete fMessenger;
121 }
122 
124 {
125 }
126 
128 {
129  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
130  A01HodoscopeHitsCollection* fHHC1 = 0;
131  A01HodoscopeHitsCollection* fHHC2 = 0;
136  if(HCE)
137  {
138  fHHC1 = (A01HodoscopeHitsCollection*)(HCE->GetHC(fHHC1ID));
139  fHHC2 = (A01HodoscopeHitsCollection*)(HCE->GetHC(fHHC2ID));
140  fDHC1 = (A01DriftChamberHitsCollection*)(HCE->GetHC(fDHC1ID));
141  fDHC2 = (A01DriftChamberHitsCollection*)(HCE->GetHC(fDHC2ID));
142  ECHC = (A01EmCalorimeterHitsCollection*)(HCE->GetHC(fECHCID));
143  HCHC = (A01HadCalorimeterHitsCollection*)(HCE->GetHC(fHCHCID));
144  }
145 
146 #ifdef G4ANALYSIS_USE
147  // Fill some histograms
148 
149  if (fDHC1 && fDc1Hits)
150  {
151  int n_hit = fDHC1->entries();
152  fDc1Hits->fill(n_hit);
153  for(int i1=0;i1<n_hit;i1++)
154  {
155  A01DriftChamberHit* aHit = (*fDHC1)[i1];
156  G4ThreeVector localPos = aHit->GetLocalPos();
157  if (fDc1XY) fDc1XY->fill(localPos.y(), localPos.x());
158  }
159  }
160  if (fDHC2 && fDc2Hits)
161  {
162  int n_hit = fDHC2->entries();
163  fDc2Hits->fill(n_hit);
164  for(int i1=0;i1<n_hit;i1++)
165  {
166  A01DriftChamberHit* aHit = (*fDHC2)[i1];
167  G4ThreeVector localPos = aHit->GetLocalPos();
168  if (fDc2XY) fDc2XY->fill(localPos.y(), localPos.x());
169  }
170  }
171 
172  // Fill the tuple
173 
174  if (fTuple)
175  {
176  if (fDHC1) fTuple->fill(0,fDHC1->entries());
177  if (fDHC2) fTuple->fill(1,fDHC2->entries());
178  if(ECHC)
179  {
180  int iHit = 0;
181  double totalE = 0.;
182  for(int i1=0;i1<80;i1++)
183  {
184  A01EmCalorimeterHit* aHit = (*ECHC)[i1];
185  double eDep = aHit->GetEdep();
186  if(eDep>0.)
187  {
188  iHit++;
189  totalE += eDep;
190  }
191  }
192  fTuple->fill(2,totalE);
193 
194  if (fHHC1 && fHHC2 && fHHC1->entries()==1 && fHHC2->entries()==1)
195  {
196  double tof = (*fHHC2)[0]->GetTime() - (*fHHC1)[0]->GetTime();
197  if (fEvstof) fEvstof->fill(tof,totalE);
198  }
199  }
200  if(HCHC)
201  {
202  int iHit = 0;
203  double totalE = 0.;
204  for(int i1=0;i1<20;i1++)
205  {
206  A01HadCalorimeterHit* aHit = (*HCHC)[i1];
207  double eDep = aHit->GetEdep();
208  if(eDep>0.)
209  {
210  iHit++;
211  totalE += eDep;
212  }
213  }
214  fTuple->fill(3,totalE);
215  }
216  if (fHHC1 && fHHC1->entries()==1) fTuple->fill(4,(*fHHC1)[0]->GetTime());
217  if (fHHC2 && fHHC2->entries()==1) fTuple->fill(5,(*fHHC2)[0]->GetTime());
218  fTuple->addRow();
219  }
220  if (fPlotter) fPlotter->refresh();
221 #endif // G4ANALYSIS_USE
222 
223 
224  // Diagnostics
225 
226  if (fVerboseLevel==0 || evt->GetEventID() % fVerboseLevel != 0) return;
227 
228  G4PrimaryParticle* primary = evt->GetPrimaryVertex(0)->GetPrimary(0);
229  G4cout << G4endl
230  << ">>> Event " << evt->GetEventID() << " >>> Simulation truth : "
231  << primary->GetG4code()->GetParticleName()
232  << " " << primary->GetMomentum() << G4endl;
233 
234  if(fHHC1)
235  {
236  int n_hit = fHHC1->entries();
237  G4cout << "Hodoscope 1 has " << n_hit << " hits." << G4endl;
238  for(int i1=0;i1<n_hit;i1++)
239  {
240  A01HodoscopeHit* aHit = (*fHHC1)[i1];
241  aHit->Print();
242  }
243  }
244  if(fHHC2)
245  {
246  int n_hit = fHHC2->entries();
247  G4cout << "Hodoscope 2 has " << n_hit << " hits." << G4endl;
248  for(int i1=0;i1<n_hit;i1++)
249  {
250  A01HodoscopeHit* aHit = (*fHHC2)[i1];
251  aHit->Print();
252  }
253  }
254  if(fDHC1)
255  {
256  int n_hit = fDHC1->entries();
257  G4cout << "Drift Chamber 1 has " << n_hit << " hits." << G4endl;
258  for(int i2=0;i2<5;i2++)
259  {
260  for(int i1=0;i1<n_hit;i1++)
261  {
262  A01DriftChamberHit* aHit = (*fDHC1)[i1];
263  if(aHit->GetLayerID()==i2) aHit->Print();
264  }
265  }
266  }
267  if(fDHC2)
268  {
269  int n_hit = fDHC2->entries();
270  G4cout << "Drift Chamber 2 has " << n_hit << " hits." << G4endl;
271  for(int i2=0;i2<5;i2++)
272  {
273  for(int i1=0;i1<n_hit;i1++)
274  {
275  A01DriftChamberHit* aHit = (*fDHC2)[i1];
276  if(aHit->GetLayerID()==i2) aHit->Print();
277  }
278  }
279  }
280  if(ECHC)
281  {
282  int iHit = 0;
283  double totalE = 0.;
284  for(int i1=0;i1<80;i1++)
285  {
286  A01EmCalorimeterHit* aHit = (*ECHC)[i1];
287  double eDep = aHit->GetEdep();
288  if(eDep>0.)
289  {
290  iHit++;
291  totalE += eDep;
292  }
293  }
294  G4cout << "EM Calorimeter has " << iHit << " hits. Total Edep is "
295  << totalE/MeV << " (MeV)" << G4endl;
296  }
297  if(HCHC)
298  {
299  int iHit = 0;
300  double totalE = 0.;
301  for(int i1=0;i1<20;i1++)
302  {
303  A01HadCalorimeterHit* aHit = (*HCHC)[i1];
304  double eDep = aHit->GetEdep();
305  if(eDep>0.)
306  {
307  iHit++;
308  totalE += eDep;
309  }
310  }
311  G4cout << "Hadron Calorimeter has " << iHit << " hits. Total Edep is "
312  << totalE/MeV << " (MeV)" << G4endl;
313  }
314 }
315 
316