Geant4_10
exGPSHistoManager.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 //
30 // $Id: exGPSHistoManager.cc 74272 2013-10-02 14:48:50Z gcosmo $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "exGPSHistoManager.hh"
36 #include "G4UnitsTable.hh"
37 #include "G4SystemOfUnits.hh"
38 #include "exGPSHistoMessenger.hh"
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 
43 fMinpos(-10.),fMaxpos(10),fMineng(0.),fMaxeng(1000.),
44 fEnerHisto(0),fPosiXY(0),fPosiZX(0),fPosiYZ(0),fAnglCTP(0),fAnglTP(0)
45 {
46  fFileName[0] = "expGPS";
47  fFactoryOn = false;
48  fMessenger = new exGPSHistoMessenger(this);
49 }
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
54 { }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 {
60  // Create or get analysis manager
61  // The choice of analysis technology is done via selection of a namespace
62  // in exGPSHistoManager.hh
63  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
64  analysisManager->SetVerboseLevel(2);
65  G4String extension = analysisManager->GetFileType();
66  fFileName[1] = fFileName[0] + "." + extension;
67 
68  // Create directories
69  analysisManager->SetHistoDirectoryName("histo");
70  analysisManager->SetNtupleDirectoryName("ntuple");
71 
72  // Open an output file
73  //
74  G4bool fileOpen = analysisManager->OpenFile(fFileName[0]);
75  if (!fileOpen) {
76  G4cout << "\n---> exGPSHistoManager::book(): cannot open " << fFileName[1]
77  << G4endl;
78  return;
79  }
80 
81  // create selected histograms
82  //
83  analysisManager->SetFirstHistoId(1);
84  analysisManager->SetFirstNtupleId(1);
85 
86  G4int id = analysisManager->CreateH1("1","Ekin primary",100,fMineng,fMaxeng);
87  fEnerHisto= analysisManager->GetH1(id);
88 
89  id = analysisManager->CreateH2("2","Position XY",100,fMinpos,fMaxpos,
90  100,fMinpos,fMaxpos);
91  fPosiXY= analysisManager->GetH2(id);
92 
93  id = analysisManager->CreateH2("3","Position YZ",100,fMinpos,fMaxpos,
94  100,fMinpos,fMaxpos);
95  fPosiYZ= analysisManager->GetH2(id);
96 
97  id = analysisManager->CreateH2("4","Position ZX",100,fMinpos,fMaxpos,
98  100,fMinpos,fMaxpos);
99  fPosiZX= analysisManager->GetH2(id);
100 
101  id =analysisManager->CreateH2("5","Source phi-std::cos(theta) distribution",
102  360,0,360,100, -1, 1);
103  fAnglCTP =analysisManager->GetH2(id);
104 
105  id =analysisManager->CreateH2("6","Source phi-theta distribution",
106  360,0,360,180,0,180);
107  fAnglTP = analysisManager->GetH2(id);
108 
109  // Create 1st ntuple (id = 1)
110  //
111  analysisManager->CreateNtuple("MyTuple", "Primary Particle Tuple");
112  id = analysisManager->CreateNtupleIColumn("particleID");
113  id = analysisManager->CreateNtupleDColumn("Ekin");
114  id = analysisManager->CreateNtupleDColumn("posX");
115  id = analysisManager->CreateNtupleDColumn("posY");
116  id = analysisManager->CreateNtupleDColumn("posZ");
117  id = analysisManager->CreateNtupleDColumn("dirTheta");
118  id = analysisManager->CreateNtupleDColumn("dirPhi");
119  id = analysisManager->CreateNtupleDColumn("weight");
120  analysisManager->FinishNtuple();
121 
122  fFactoryOn = true;
123  G4cout << "\n----> Histogram Tree is opened in " << fFileName[1] << G4endl;
124 }
125 
126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127 
129 {
130  if (fFactoryOn) {
131  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
132  analysisManager->Write();
133  analysisManager->CloseFile();
134  G4cout << "\n----> Histogram Tree is saved in " << fFileName[1] << G4endl;
135 
136  delete G4AnalysisManager::Instance();
137  fFactoryOn = false;
138  }
139 }
140 
143  G4double t, G4double p, G4double w)
144 {
145  fEnerHisto->fill(e, w);
146  fEnerHisto->fill(e/MeV,w);
147  fPosiXY->fill(x/cm,y/cm,w);
148  fPosiZX->fill(z/cm,x/cm,w);
149  fPosiYZ->fill(y/cm,z/cm,w);
150  fAnglCTP->fill(p/deg,std::cos(t),w);
151  fAnglTP->fill(p/deg,t/deg,w);
152 
153  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
154  analysisManager->FillNtupleIColumn(1,0,PDGid);
155  analysisManager->FillNtupleDColumn(1,1,e);
156  analysisManager->FillNtupleDColumn(1,2,x);
157  analysisManager->FillNtupleDColumn(1,3,y);
158  analysisManager->FillNtupleDColumn(1,4,z);
159  analysisManager->FillNtupleDColumn(1,5,t);
160  analysisManager->FillNtupleDColumn(1,6,p);
161  analysisManager->FillNtupleDColumn(1,7,w);
162  analysisManager->AddNtupleRow(1);
163 }
164 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
166 
168 {
169  if(fFactoryOn) {
170  G4cout << "\n ----> print histograms statistic \n" << G4endl;
171 
172  /*G4cout
173  << " EAbs : mean = " << G4BestUnit(fHistPt[1]->mean(), "Energy")
174  << " rms = " << G4BestUnit(fHistPt[1]->rms(), "Energy")
175  << G4endl;
176  G4cout
177  << " EGap : mean = " << G4BestUnit(fHistPt[2]->mean(), "Energy")
178  << " rms = " << G4BestUnit(fHistPt[2]->rms(), "Energy")
179  << G4endl;
180  G4cout
181  << " LAbs : mean = " << G4BestUnit(fHistPt[3]->mean(), "Length")
182  << " rms = " << G4BestUnit(fHistPt[3]->rms(), "Length")
183  << G4endl;
184  G4cout
185  << " LGap : mean = " << G4BestUnit(fHistPt[4]->mean(), "Length")
186  << " rms = " << G4BestUnit(fHistPt[4]->rms(), "Length")
187  << G4endl;
188  */
189  }
190 }
191 
192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
193 
194 
G4bool SetHistoDirectoryName(const G4String &dirName)
Definition of the exGPSHistoMessenger class.
G4int CreateNtupleIColumn(const G4String &name)
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")
const char * p
Definition: xmltok.h:285
void SetVerboseLevel(G4int verboseLevel)
G4int CreateNtuple(const G4String &name, const G4String &title)
tuple x
Definition: test.py:50
G4bool SetNtupleDirectoryName(const G4String &dirName)
int G4int
Definition: G4Types.hh:78
Double_t y
Definition: plot.C:279
G4bool FillNtupleIColumn(G4int id, G4int value)
void Fill(G4int PDGid, G4double e, G4double x, G4double y, G4double z, G4double t, G4double p, G4double w)
G4GLOB_DLL std::ostream G4cout
G4bool FillNtupleDColumn(G4int id, G4double value)
bool G4bool
Definition: G4Types.hh:79
G4String GetFileType() const
Definition of the exGPSHistoManager class.
G4bool SetFirstNtupleId(G4int firstId)
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61
G4int CreateNtupleDColumn(const G4String &name)
double G4double
Definition: G4Types.hh:76
tools::histo::h1d * GetH1(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
tools::histo::h2d * GetH2(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
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 &xbinScheme="linear", const G4String &ybinScheme="linear")