Geant4  10.00.p03
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 // $Id: GammaRayTelAnalysis.cc 68794 2013-04-05 13:23:26Z gcosmo $
27 // ------------------------------------------------------------
28 // GEANT 4 class implementation file
29 // CERN Geneva Switzerland
30 //
31 //
32 // ------------ GammaRayAnalysisManager ------
33 // by R.Giannitrapani, F.Longo & G.Santin (03 dic 2000)
34 //
35 // 03.04.2013 F.Longo/L.Pandola
36 // - migrated to G4tools
37 //
38 // 29.05.2003 F.Longo
39 // - anaphe 5.0.5 compliant
40 //
41 // 18.06.2002 R.Giannitrapani, F.Longo & G.Santin
42 // - new release for Anaphe 4.0.3
43 //
44 // 07.12.2001 A.Pfeiffer
45 // - integrated Guy's addition of the ntuple
46 //
47 // 06.12.2001 A.Pfeiffer
48 // - updating to new design (singleton)
49 //
50 // 22.11.2001 G.Barrand
51 // - Adaptation to AIDA
52 //
53 // ************************************************************
54 #include <fstream>
55 #include <iomanip>
56 
57 #include "G4RunManager.hh"
58 
59 #include "GammaRayTelAnalysis.hh"
62 
63 GammaRayTelAnalysis* GammaRayTelAnalysis::instance = 0;
64 
65 //--------------------------------------------------------------------------------
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
67 
68 GammaRayTelAnalysis::GammaRayTelAnalysis()
69  :GammaRayTelDetector(0),histo2DMode("strip")
70 {
72  GammaRayTelDetector =
74 
75 #ifdef G4ANALYSIS_USE
76  // Define the messenger and the analysis system
77 
78  analysisMessenger = new GammaRayTelAnalysisMessenger(this);
79  histoFileName = "gammaraytel";
80 
81 
82 
83 #endif
84 }
85 
86 
87 GammaRayTelAnalysis::~GammaRayTelAnalysis() {
88  Finish();
89 }
90 
91 
93 {;}
94 
95 void GammaRayTelAnalysis::Finish()
96 {
97 #ifdef G4ANALYSIS_USE
98  delete analysisMessenger;
99  analysisMessenger = 0;
100 #endif
101 }
102 
103 GammaRayTelAnalysis* GammaRayTelAnalysis::getInstance()
104 {
105  if (instance == 0) instance = new GammaRayTelAnalysis();
106  return instance;
107 }
108 
109 // This function fill the 2d histogram of the XZ positions
110 void GammaRayTelAnalysis::InsertPositionXZ(double x, double z)
111 {
112 #ifdef G4ANALYSIS_USE
113  G4AnalysisManager* man = G4AnalysisManager::Instance();
114  man->FillH2(1,x,z);
115 #endif
116 }
117 
118 // This function fill the 2d histogram of the YZ positions
119 void GammaRayTelAnalysis::InsertPositionYZ(double y, double z)
120 {
121 #ifdef G4ANALYSIS_USE
122  G4AnalysisManager* man = G4AnalysisManager::Instance();
123  man->FillH2(2,y,z);
124 #endif
125 }
126 
127 // This function fill the 1d histogram of the energy released in the last Si plane
128 void GammaRayTelAnalysis::InsertEnergy(double en)
129 {
130 #ifdef G4ANALYSIS_USE
131  G4AnalysisManager* man = G4AnalysisManager::Instance();
132  man->FillH1(1,en);
133 #endif
134 }
135 
136 // This function fill the 1d histogram of the hits distribution along the TKR planes
137 void GammaRayTelAnalysis::InsertHits(int nplane)
138 {
139 #ifdef G4ANALYSIS_USE
140  G4AnalysisManager* man = G4AnalysisManager::Instance();
141  man->FillH1(2,nplane);
142 #endif
143 }
144 
145 void GammaRayTelAnalysis::setNtuple(float E, float p, float x, float y, float z)
146 {
147 #ifdef G4ANALYSIS_USE
148 
149  G4AnalysisManager* man = G4AnalysisManager::Instance();
150  man->FillNtupleDColumn(0,E);
151  man->FillNtupleDColumn(1,p);
152  man->FillNtupleDColumn(2,x);
153  man->FillNtupleDColumn(3,y);
154  man->FillNtupleDColumn(4,z);
155  man->AddNtupleRow();
156 
157 #endif
158 }
159 
160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
161 /*
162  This member reset the histograms and it is called at the begin
163  of each run; here we put the inizialization so that the histograms have
164  always the right dimensions depending from the detector geometry
165 */
166 
167 //void GammaRayTelAnalysis::BeginOfRun(G4int n) // to be reintroduced
168 void GammaRayTelAnalysis::BeginOfRun()
169 {
170 #ifdef G4ANALYSIS_USE
171  G4AnalysisManager* man = G4AnalysisManager::Instance();
172 
173  // Open an output file
174 
175  G4cout << "Opening output file " << histoFileName << " ... ";
176  man->OpenFile(histoFileName);
177  man->SetFirstHistoId(1);
178  G4cout << " done" << G4endl;
179 
180 
181  int Nplane = GammaRayTelDetector->GetNbOfTKRLayers();
182  int Nstrip = GammaRayTelDetector->GetNbOfTKRStrips();
183  int Ntile = GammaRayTelDetector->GetNbOfTKRTiles();
184  double sizexy = GammaRayTelDetector->GetTKRSizeXY();
185  double sizez = GammaRayTelDetector->GetTKRSizeZ();
186  int N = Nstrip*Ntile;
187 
188  // Book1D histograms
189  //------------------
190 
191  // 1D histogram that store the energy deposition of the
192  // particle in the last (number 0) TKR X-plane
193 
194  man->CreateH1("1","Edep in the last X plane (keV)", 100, 50, 200);
195 
196  // 1D histogram that store the hits distribution along the TKR X-planes
197 
198  man->CreateH1("2","Hits dist in TKR X planes",Nplane, 0, Nplane-1);
199 
200  // Book 2D histograms
201  //-------------------
202 
203  // 2D histogram that store the position (mm) of the hits (XZ projection)
204 
205  if (histo2DMode == "strip")
206  {
207  man->CreateH2("1","Tracker Hits XZ (strip,plane)",
208  N, 0, N-1,
209  2*Nplane, 0, Nplane-1);
210  }
211  else
212  {
213  man->CreateH2("1","Tracker Hits XZ (x,z) in mm",
214  int(sizexy/5), -sizexy/2, sizexy/2,
215  int(sizez/5), -sizez/2, sizez/2);
216  }
217 
218  // 2D histogram that store the position (mm) of the hits (YZ projection)
219 
220  if (histo2DMode == "strip")
221  {
222  man->CreateH2("2","Tracker Hits YZ (strip,plane)",
223  N, 0, N-1,
224  2*Nplane, 0, Nplane-1);
225  }
226  else
227  {
228  man->CreateH2("2","Tracker Hits YZ (x,z) in mm",
229  int(sizexy/5), -sizexy/2, sizexy/2,
230  int(sizez/5), -sizez/2, sizez/2);
231  }
232 
233 
234  // Book Ntuples (energy / plane/ x / y / z)
235  //------------------------------------------
236 
237  man->CreateNtuple("1","Track ntuple");
238  man->CreateNtupleDColumn("energy");
239  man->CreateNtupleDColumn("plane"); // can I use Int values?
240  man->CreateNtupleDColumn("x"); // can I use Int values?
241  man->CreateNtupleDColumn("y"); // can I use Int values?
242  man->CreateNtupleDColumn("z"); // can I use Int values?
243  man->FinishNtuple();
244 
245 #endif
246 }
247 
248 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
249 
250 /*
251  This member is called at the end of each run
252 */
253 void GammaRayTelAnalysis::EndOfRun()
254 {
255 #ifdef G4ANALYSIS_USE
256 
257  //Save histograms
258  G4AnalysisManager* man = G4AnalysisManager::Instance();
259  man->Write();
260  man->CloseFile();
261  // Complete clean-up
262  delete G4AnalysisManager::Instance();
263 
264 #endif
265 }
266 
267 /* This member is called at the end of every event */
268 
269 void GammaRayTelAnalysis::EndOfEvent(G4int /* flag */ )
270 {
271 
272 #ifdef G4ANALYSIS_USE
273 
274 #endif
275 }
276 
277 
278 
279 
280 
281 
282 
void Init()
Definition: G4IonTable.cc:89
G4double z
Definition: TRTMaterials.hh:39
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
#define G4endl
Definition: G4ios.hh:61
static MCTruthManager * instance