Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GammaRayTelAnalysis.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 #ifdef G4ANALYSIS_USE
27 //
28 // $Id$
29 // ------------------------------------------------------------
30 // GEANT 4 class implementation file
31 // CERN Geneva Switzerland
32 //
33 //
34 // ------------ GammaRayAnalysisManager ------
35 // by R.Giannitrapani, F.Longo & G.Santin (03 dic 2000)
36 //
37 // 29.05.2003 F.Longo
38 // - anaphe 5.0.5 compliant
39 //
40 // 18.06.2002 R.Giannitrapani, F.Longo & G.Santin
41 // - new release for Anaphe 4.0.3
42 //
43 // 07.12.2001 A.Pfeiffer
44 // - integrated Guy's addition of the ntuple
45 //
46 // 06.12.2001 A.Pfeiffer
47 // - updating to new design (singleton)
48 //
49 // 22.11.2001 G.Barrand
50 // - Adaptation to AIDA
51 //
52 // ************************************************************
53 #include <fstream>
54 
55 #include "G4RunManager.hh"
56 
57 #include "GammaRayTelAnalysis.hh"
60 
61 GammaRayTelAnalysis* GammaRayTelAnalysis::instance = 0;
62 
63 //--------------------------------------------------------------------------------
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
65 
66 GammaRayTelAnalysis::GammaRayTelAnalysis()
67  :GammaRayTelDetector(0),analysisFactory(0), tree(0)//, plotter(0),
68  ,tuple(0)
69  ,energy(0), hits(0), posXZ(0), posYZ(0)
70  ,histo1DDraw("enable"),histo1DSave("enable"),histo2DDraw("enable")
71  ,histo2DSave("enable"),histo2DMode("strip")
72 {
74  GammaRayTelDetector =
76 
77 #ifdef G4ANALYSIS_USE
78  // Define the messenger and the analysis system
79 
80  analysisMessenger = new GammaRayTelAnalysisMessenger(this);
81 
82  analysisFactory = AIDA_createAnalysisFactory(); // create the Analysis Factory
83  if(analysisFactory) {
84  AIDA::ITreeFactory* treeFactory = analysisFactory->createTreeFactory();
85  // create Tree Factory
86 
87  if(treeFactory) {
88  // Tree in memory :
89  // Create a "tree" associated to an xml file
90 
91  // tree = treeFactory->create("gammaraytel.hbook", "hbook", false, false);
92  // (hbook implementation)
93  tree = treeFactory->create("gammaraytel.aida","xml",false,true,"");
94  if(tree) {
95  // Get a tuple factory :
96  ITupleFactory* tupleFactory = analysisFactory->createTupleFactory(*tree);
97  if(tupleFactory) {
98  // Create a tuple :
99  tuple = tupleFactory->create("1","1", "float energy, plane, x, y, z");
100  assert(tuple);
101 
102  delete tupleFactory;
103  }
104 
105  IHistogramFactory* histoFactory = analysisFactory->createHistogramFactory(*tree);
106 
107  if(histoFactory) {
108  // Create histos :
109 
110  int Nplane = GammaRayTelDetector->GetNbOfTKRLayers();
111  int Nstrip = GammaRayTelDetector->GetNbOfTKRStrips();
112  int Ntile = GammaRayTelDetector->GetNbOfTKRTiles();
113  double sizexy = GammaRayTelDetector->GetTKRSizeXY();
114  double sizez = GammaRayTelDetector->GetTKRSizeZ();
115  int N = Nstrip*Ntile;
116 
117  // 1D histogram that store the energy deposition of the
118  // particle in the last (number 0) TKR X-plane
119 
120  energy = histoFactory->createHistogram1D("10","Edep in the last X plane (keV)", 100, 50, 200);
121 
122  // 1D histogram that store the hits distribution along the TKR X-planes
123 
124  hits = histoFactory->createHistogram1D("20","Hits dist in TKR X planes",Nplane, 0, Nplane-1);
125  // 2D histogram that store the position (mm) of the hits (XZ projection)
126 
127  if (histo2DMode == "strip"){
128  posXZ = histoFactory->createHistogram2D("30","Tracker Hits XZ (strip,plane)",
129  N, 0, N-1,
130  2*Nplane, 0, Nplane-1);
131  }
132  else
133  {
134  posXZ = histoFactory->createHistogram2D("30","Tracker Hits XZ (x,z) in mm",
135  int(sizexy/5), -sizexy/2, sizexy/2,
136  int(sizez/5), -sizez/2, sizez/2);
137  }
138  // 2D histogram that store the position (mm) of the hits (YZ projection)
139 
140  if(histo2DMode=="strip")
141  posYZ = histoFactory->createHistogram2D("40","Tracker Hits YZ (strip,plane)",
142  N, 0, N-1,
143  2*Nplane, 0, Nplane-1);
144  else
145  posYZ = histoFactory->createHistogram2D("40","Tracker Hits YZ (y,z) in mm",
146  int(sizexy/5), -sizexy/2, sizexy/2,
147  int(sizez/5), -sizez/2, sizez/2);
148 
149  delete histoFactory;
150  }
151 
152  }
153  }
154  delete treeFactory; // Will not delete the ITree.
155 
156  }
157 
158  // IPlotterFactory* plotterFactory = analysisFactory->createPlotterFactory(0,0);
159 // if(plotterFactory) {
160 // plotter = plotterFactory->create();
161 // if(plotter) {
162 // plotter->show();
163 // plotter->setParameter("pageTitle","Gamma Ray Tel");
164 
165 // }
166 // delete plotterFactory;
167 // }
168 
169 #endif
170 }
171 
172 
173 GammaRayTelAnalysis::~GammaRayTelAnalysis() {
174  Finish();
175 }
176 
177 
178 void GammaRayTelAnalysis::Init()
179 {
180 }
181 
182 void GammaRayTelAnalysis::Finish()
183 {
184 #ifdef G4ANALYSIS_USE
185  delete tree;
186  //delete plotter;
187  // delete analysisFactory; // Will delete tree and histos.
188  delete analysisMessenger;
189 
190  analysisMessenger = 0;
191 #endif
192 }
193 
194 GammaRayTelAnalysis* GammaRayTelAnalysis::getInstance()
195 {
196  if (instance == 0) instance = new GammaRayTelAnalysis();
197  return instance;
198 }
199 
200 // This function fill the 2d histogram of the XZ positions
201 void GammaRayTelAnalysis::InsertPositionXZ(double x, double z)
202 {
203 #ifdef G4ANALYSIS_USE
204  if(posXZ) posXZ->fill(x, z);
205 #endif
206 }
207 
208 // This function fill the 2d histogram of the YZ positions
209 void GammaRayTelAnalysis::InsertPositionYZ(double y, double z)
210 {
211 #ifdef G4ANALYSIS_USE
212  if(posYZ) posYZ->fill(y, z);
213 #endif
214 }
215 
216 // This function fill the 1d histogram of the energy released in the last Si plane
217 void GammaRayTelAnalysis::InsertEnergy(double en)
218 {
219 #ifdef G4ANALYSIS_USE
220  if(energy) energy->fill(en);
221 #endif
222 }
223 
224 // This function fill the 1d histogram of the hits distribution along the TKR planes
225 void GammaRayTelAnalysis::InsertHits(int nplane)
226 {
227 #ifdef G4ANALYSIS_USE
228  if(hits) hits->fill(nplane);
229 #endif
230 }
231 
232 void GammaRayTelAnalysis::setNtuple(float E, float p, float x, float y, float z)
233 {
234 #ifdef G4ANALYSIS_USE
235  tuple->fill(tuple->findColumn("energy"),E);
236  tuple->fill(tuple->findColumn("plane"),p);
237  tuple->fill(tuple->findColumn("x"),x);
238  tuple->fill(tuple->findColumn("y"),y);
239  tuple->fill(tuple->findColumn("z"),z);
240  tuple->addRow();
241 #endif
242 }
243 
244 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
245 /*
246  This member reset the histograms and it is called at the begin
247  of each run; here we put the inizialization so that the histograms have
248  always the right dimensions depending from the detector geometry
249 */
250 
251 //void GammaRayTelAnalysis::BeginOfRun(G4int n) // to be reintroduced
252 void GammaRayTelAnalysis::BeginOfRun()
253 {
254 #ifdef G4ANALYSIS_USE
255 
256  if(energy) energy->reset();
257  if(hits) hits->reset();
258  if(posXZ) posXZ->reset();
259  if(posYZ) posYZ->reset();
260 
261 #endif
262 }
263 
264 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
265 
266 /*
267  This member is called at the end of each run
268 */
269 void GammaRayTelAnalysis::EndOfRun(G4int)
270 {
271 #ifdef G4ANALYSIS_USE
272  if(tree) {
273  tree->commit();
274  tree->close();
275  }
276 
277 // if(plotter) {
278 
279 // // We set one single region for the plotter
280 // // We now print the histograms, each one in a separate file
281 
282 // if(histo2DSave == "enable") {
283 // char name[15];
284 // plotter->createRegions(1,1);
285 // sprintf(name,"posxz_%d.ps", n);
286 // plotter->currentRegion().plot(*posXZ);
287 // plotter->refresh();
288 // // plotter->write(name,"ps"); // temporary unavailable
289 
290 // plotter->createRegions(1,1);
291 // sprintf(name,"posyz_%d.ps", n);
292 // plotter->currentRegion().plot(*posYZ);
293 // plotter->next().plot(*posYZ);
294 // plotter->refresh();
295 // // plotter->write(name,"ps"); // temporary unavailable
296 // }
297 
298 // if(histo1DSave == "enable") {
299 // plotter->createRegions(1,1);
300 // char name[15];
301 // sprintf(name,"energy_%d.ps", n);
302 // plotter->currentRegion().plot(*energy);
303 // plotter->refresh();
304 // // plotter->write(name,"ps"); // temporary unavailable
305 // plotter->createRegions(1,1);
306 // sprintf(name,"hits_%d.ps", n);
307 // plotter->currentRegion().plot(*hits);
308 // plotter->refresh();
309 // // plotter->write(name,"ps"); // temporary unavailable
310 // plotter->createRegions(1,2);
311 // plotter->currentRegion().plot(*energy);
312 // plotter->next().plot(*hits);
313 // plotter->refresh();
314  // }
315 #endif
316 }
317 
318 /* This member is called at the end of every event */
319 void GammaRayTelAnalysis::EndOfEvent(G4int flag)
320 {
321  // The plotter is updated only if there is some
322  // hits in the event
323  if(!flag) return;
324 #ifdef G4ANALYSIS_USE
325  // Set the plotter ; set the number of regions and attach histograms
326  // to plot for each region.
327  // It is done here, since then EndOfRun set regions
328  // for paper output.
329  // if(plotter) {
330 // if((histo2DDraw == "enable") && (histo1DDraw == "enable")) {
331 // plotter->createRegions(1,2);
332 // //plotter->currentRegion().plot(*posXZ); //temporary unavailable
333 // plotter->currentRegion().plot(*hits);
334 // // plotter->next().plot(*posYZ); //temporary unavailable
335 // plotter->next().plot(*energy);
336 // //plotter->next().plot(*energy);
337 // // plotter->currentRegion().plot(*hits);
338 // //plotter->next().plot(*hits);
339 // } else if((histo1DDraw == "enable") && (histo2DDraw != "enable")) {
340 // plotter->createRegions(1,2);
341 // plotter->currentRegion().plot(*energy);
342 // plotter->next().plot(*hits);
343 // } else if((histo1DDraw != "enable") && (histo2DDraw == "enable")) {
344 // /* plotter->createRegions(1,2);
345 // plotter->currentRegion().plot(*posXZ);
346 // plotter->next().plot(*posYZ);*/
347 // G4cout << "Temporary Unavailable " << G4endl;
348 // } else { // Nothing to plot.
349 // plotter->createRegions(1,1);
350 // }
351 // plotter->refresh();
352 // }
353 
354 #endif
355 }
356 #endif
357 
358 
359 
360 
361 
362 
363