Geant4  10.01.p01
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 82268 2014-06-13 13:47:30Z 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 
64 
65 //--------------------------------------------------------------------------------
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
67 
69  :GammaRayTelDetector(0),histo2DMode("strip")
70 {
72  static_cast<const GammaRayTelDetectorConstruction*>
74 
75  // Define the messenger and the analysis system
77  histoFileName = "gammaraytel";
78 }
79 
80 
82  Finish();
83  // Complete clean-up
84  delete G4AnalysisManager::Instance();
85 }
86 
87 
89 {;}
90 
92 {
93  delete analysisMessenger;
95 }
96 
98 {
99  if (instance == 0) instance = new GammaRayTelAnalysis();
100  return instance;
101 }
102 
103 // This function fill the 2d histogram of the XZ positions
105 {
106  G4AnalysisManager* man = G4AnalysisManager::Instance();
107  man->FillH2(1,x,z);
108 }
109 
110 // This function fill the 2d histogram of the YZ positions
112 {
113  G4AnalysisManager* man = G4AnalysisManager::Instance();
114  man->FillH2(2,y,z);
115 }
116 
117 // This function fill the 1d histogram of the energy released in the last Si plane
119 {
120  G4AnalysisManager* man = G4AnalysisManager::Instance();
121  man->FillH1(1,en);
122 }
123 
124 // This function fill the 1d histogram of the hits distribution along the TKR planes
126 {
127  G4AnalysisManager* man = G4AnalysisManager::Instance();
128  man->FillH1(2,nplane);
129 }
130 
131 void GammaRayTelAnalysis::setNtuple(float E, float p, float x,
132  float y, float z)
133 {
134  G4AnalysisManager* man = G4AnalysisManager::Instance();
135  man->FillNtupleDColumn(0,E);
136  man->FillNtupleDColumn(1,p);
137  man->FillNtupleDColumn(2,x);
138  man->FillNtupleDColumn(3,y);
139  man->FillNtupleDColumn(4,z);
140  man->AddNtupleRow();
141 }
142 
143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
144 /*
145  This member reset the histograms and it is called at the begin
146  of each run; here we put the inizialization so that the histograms have
147  always the right dimensions depending from the detector geometry
148 */
149 
151 {
152  G4AnalysisManager* man = G4AnalysisManager::Instance();
153 
154  // Open an output file
155 
156  G4cout << "Opening output file " << histoFileName << " ... ";
157  man->OpenFile(histoFileName);
158  man->SetFirstHistoId(1);
159  G4cout << " done" << G4endl;
160 
161 
162  int Nplane = GammaRayTelDetector->GetNbOfTKRLayers();
163  int Nstrip = GammaRayTelDetector->GetNbOfTKRStrips();
164  int Ntile = GammaRayTelDetector->GetNbOfTKRTiles();
165  double sizexy = GammaRayTelDetector->GetTKRSizeXY();
166  double sizez = GammaRayTelDetector->GetTKRSizeZ();
167  int N = Nstrip*Ntile;
168 
169  // Book1D histograms
170  //------------------
171 
172  // 1D histogram that store the energy deposition of the
173  // particle in the last (number 0) TKR X-plane
174  man->CreateH1("1","Edep in the last X plane (keV)", 100, 50, 200);
175 
176  // 1D histogram that store the hits distribution along the TKR X-planes
177  man->CreateH1("2","Hits dist in TKR X planes",Nplane, 0, Nplane-1);
178 
179  // Book 2D histograms
180  //-------------------
181 
182  // 2D histogram that store the position (mm) of the hits (XZ projection)
183 
184  if (histo2DMode == "strip")
185  {
186  man->CreateH2("1","Tracker Hits XZ (strip,plane)",
187  N, 0, N-1,
188  2*Nplane, 0, Nplane-1);
189  }
190  else
191  {
192  man->CreateH2("1","Tracker Hits XZ (x,z) in mm",
193  int(sizexy/5), -sizexy/2, sizexy/2,
194  int(sizez/5), -sizez/2, sizez/2);
195  }
196 
197  // 2D histogram that store the position (mm) of the hits (YZ projection)
198  if (histo2DMode == "strip")
199  {
200  man->CreateH2("2","Tracker Hits YZ (strip,plane)",
201  N, 0, N-1,
202  2*Nplane, 0, Nplane-1);
203  }
204  else
205  {
206  man->CreateH2("2","Tracker Hits YZ (x,z) in mm",
207  int(sizexy/5), -sizexy/2, sizexy/2,
208  int(sizez/5), -sizez/2, sizez/2);
209  }
210 
211 
212  // Book Ntuples (energy / plane/ x / y / z)
213  //------------------------------------------
214  man->CreateNtuple("1","Track ntuple");
215  man->CreateNtupleDColumn("energy");
216  man->CreateNtupleDColumn("plane"); // can I use Int values?
217  man->CreateNtupleDColumn("x"); // can I use Int values?
218  man->CreateNtupleDColumn("y"); // can I use Int values?
219  man->CreateNtupleDColumn("z"); // can I use Int values?
220  man->FinishNtuple();
221 
222 }
223 
224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
225 
226 /*
227  This member is called at the end of each run
228 */
230 {
231  //Save histograms
232  G4AnalysisManager* man = G4AnalysisManager::Instance();
233  man->Write();
234  man->CloseFile();
235 }
236 
237 /* This member is called at the end of every event */
238 
240 {;}
241 
242 
243 
244 
245 
246 
247 
void setNtuple(float E, float p, float x, float y, float z)
G4bool SetFirstHistoId(G4int firstId)
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
G4double z
Definition: TRTMaterials.hh:39
static GammaRayTelAnalysis * getInstance()
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
void InsertPositionXZ(double x, double z)
G4int CreateNtuple(const G4String &name, const G4String &title)
int G4int
Definition: G4Types.hh:78
G4bool OpenFile(const G4String &fileName="")
G4GLOB_DLL std::ostream G4cout
const GammaRayTelDetectorConstruction * GammaRayTelDetector
G4bool FillNtupleDColumn(G4int id, G4double value)
void InsertPositionYZ(double y, double z)
void EndOfEvent(G4int flag)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
void InsertHits(int nplane)
G4bool FillH2(G4int id, G4double xvalue, G4double yvalue, G4double weight=1.0)
G4bool FillH1(G4int id, G4double value, G4double weight=1.0)
GammaRayTelAnalysisMessenger * analysisMessenger
#define G4endl
Definition: G4ios.hh:61
G4int CreateNtupleDColumn(const G4String &name)
static GammaRayTelAnalysis * instance
void InsertEnergy(double en)
G4int CreateH2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinSchemeName="linear", const G4String &ybinSchemeName="linear")