Geant4  10.02.p01
Par02Output.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: $
27 //
30 
31 #include "Par02Output.hh"
32 #include "Par02EventInformation.hh"
33 
34 #include "G4Event.hh"
35 #include "G4RunManager.hh"
36 #include "G4UnitsTable.hh"
37 #include "G4SystemOfUnits.hh"
38 #include "g4root.hh"
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
48 Par02Output::Par02Output() : fFileNameWithRunNo( false ) {
49  fFileName = "DefaultOutput.root";
50 }
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55  delete G4AnalysisManager::Instance();
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61  if ( ! fPar02Output ) {
62  fPar02Output = new Par02Output();
63  }
64  return fPar02Output;
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
70  fFileName = aName;
71 }
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
76  fFileNameWithRunNo = aApp;
77 }
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
82  return fFileName;
83 }
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
88  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
89  if ( fFileNameWithRunNo ) {
90  fFileName += "_run";
92  }
93  analysisManager->SetVerboseLevel( 1 );
94  analysisManager->SetFileName( fFileName );
95  analysisManager->OpenFile( fFileName );
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
101  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
102  analysisManager->Write();
103  analysisManager->CloseFile();
104 }
105 
106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107 
110  G4String evName = "Event_";
111  evName += G4UIcommand::ConvertToString( event->GetEventID() );
112  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
113  fCurrentNtupleId = analysisManager->CreateNtuple( evName, evName );
114 
115  analysisManager->CreateNtupleIColumn( "particleID" ); // column Id = 0
116  analysisManager->CreateNtupleIColumn( "PID" ); // column Id = 1
117  analysisManager->CreateNtupleDColumn( "MC_pX" ); // column Id = 2
118  analysisManager->CreateNtupleDColumn( "MC_pY" ); // column Id = 3
119  analysisManager->CreateNtupleDColumn( "MC_pZ" ); // column Id = 4
120 
121  analysisManager->CreateNtupleDColumn( "tracker_res" ); // column Id = 5
122  analysisManager->CreateNtupleDColumn( "tracker_eff" ); // column Id = 6
123  analysisManager->CreateNtupleDColumn( "tracker_pX" ); // column Id = 7
124  analysisManager->CreateNtupleDColumn( "tracker_pY" ); // column Id = 8
125  analysisManager->CreateNtupleDColumn( "tracker_pZ" ); // column Id = 9
126 
127  analysisManager->CreateNtupleDColumn( "emcal_res" ); // column Id = 10
128  analysisManager->CreateNtupleDColumn( "emcal_eff" ); // column Id = 11
129  analysisManager->CreateNtupleDColumn( "emcal_X" ); // column Id = 12
130  analysisManager->CreateNtupleDColumn( "emcal_Y" ); // column Id = 13
131  analysisManager->CreateNtupleDColumn( "emcal_Z" ); // column Id = 14
132  analysisManager->CreateNtupleDColumn( "emcal_E" ); // column Id = 15
133 
134  analysisManager->CreateNtupleDColumn( "hcal_res" ); // column Id = 16
135  analysisManager->CreateNtupleDColumn( "hcal_eff" ); // column Id = 17
136  analysisManager->CreateNtupleDColumn( "hcal_X" ); // column Id = 18
137  analysisManager->CreateNtupleDColumn( "hcal_Y" ); // column Id = 19
138  analysisManager->CreateNtupleDColumn( "hcal_Z" ); // column Id = 20
139  analysisManager->CreateNtupleDColumn( "hcal_E" ); // column Id = 21
140 
141  analysisManager->FinishNtuple( fCurrentNtupleId );
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145 
147 {
148  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
149  analysisManager->CreateH1( "Pdiff", "momentum smeared in tracker", 100, 0.8, 1.2 );
150  analysisManager->SetH1XAxisTitle( 0, "p_{smeared}/p_{true}" );
151  analysisManager->SetH1YAxisTitle( 0, "Entries" );
152  analysisManager->CreateH1( "EMCalEdiff", "energy smeared in EMCal", 100, 0.8, 1.2 );
153  analysisManager->SetH1XAxisTitle( 1, "E_{smeared}/E_{true}" );
154  analysisManager->SetH1YAxisTitle( 1, "Entries" );
155  analysisManager->CreateH1( "HCalEdiff", "energy smeared in HCal", 100, 0.0, 2.0 );
156  analysisManager->SetH1XAxisTitle( 2, "E_{smeared}/E_{true}" );
157  analysisManager->SetH1YAxisTitle( 2, "Entries" );
158 }
159 
160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161 
162 void Par02Output::SaveTrack( SaveType aWhatToSave, G4int aPartID, G4int aPDG,
163  G4ThreeVector aVector, G4double aResolution,
164  G4double aEfficiency, G4double aEnergy ) {
165  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
166  switch( aWhatToSave ) {
167  case Par02Output::eNoSave :
168  break;
169  case Par02Output::eSaveMC : {
170  analysisManager->FillNtupleIColumn( fCurrentNtupleId, 0, aPartID );
171  analysisManager->FillNtupleIColumn( fCurrentNtupleId, 1, aPDG );
172  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 2, aVector.x() );
173  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 3, aVector.y() );
174  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 4, aVector.z() );
175  fCurrentID = aPartID;
176  break;
177  }
179  if ( aPartID != fCurrentID ) G4cout <<
180  " Wrong particle - trying to save Tracker information of different particle"
181  << G4endl;
182  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 5, aResolution );
183  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 6, aEfficiency );
184  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 7, aVector.x() );
185  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 8, aVector.y() );
186  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 9, aVector.z() );
187  break;
188  }
189  case Par02Output::eSaveEMCal : {
190  if ( aPartID != fCurrentID ) G4cout <<
191  " Wrong particle - trying to save EMCal information of different particle"
192  << G4endl;
193  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 10, aResolution );
194  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 11, aEfficiency );
195  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 12, aVector.x() );
196  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 13, aVector.y() );
197  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 14, aVector.z() );
198  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 15, aEnergy );
199  break;
200  }
201  case Par02Output::eSaveHCal : {
202  if ( aPartID != fCurrentID ) G4cout <<
203  " Wrong particle - trying to save HCal information of different particle"
204  << G4endl;
205  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 16, aResolution );
206  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 17, aEfficiency );
207  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 18, aVector.x() );
208  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 19, aVector.y() );
209  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 20, aVector.z() );
210  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 21, aEnergy );
211  analysisManager->AddNtupleRow( fCurrentNtupleId );
212  break;
213  }
214  }
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218 
219 void Par02Output::FillHistogram( G4int aHistNo, G4double aValue ) const {
220  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
221  analysisManager->FillH1( aHistNo, aValue );
222 }
223 
224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
225 
static G4ThreadLocal G4int fCurrentNtupleId
Current ntuple Id.
Definition: Par02Output.hh:118
void AppendName(G4bool app)
Sets fFileNameWithRunNo that indicates whether to add the run number to the file name.
Definition: Par02Output.cc:75
Definition of the Par02EventInformation class.
G4String fFileName
A name of the output root file.
Definition: Par02Output.hh:121
void EndAnalysis()
Calls the G4AnalysisManager::Instance(). It writes to the output file and close it.
Definition: Par02Output.cc:100
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")
CLHEP::Hep3Vector G4ThreeVector
static G4ThreadLocal G4int fCurrentID
A control value of particle ID to ensure that data saved to various ntuples match the same particle...
Definition: Par02Output.hh:129
void CreateNtuples()
Creates Ntuples used to store information about particle (its ID, PDG code, energy deposits...
Definition: Par02Output.cc:108
void SetVerboseLevel(G4int verboseLevel)
void CreateHistograms()
Creates histograms to combine information from all the events in the run. To be called for each run i...
Definition: Par02Output.cc:146
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:371
#define G4ThreadLocal
Definition: tls.hh:89
G4bool SetFileName(const G4String &fileName)
int G4int
Definition: G4Types.hh:78
G4bool OpenFile(const G4String &fileName="")
void FillHistogram(G4int HNo, G4double value) const
Fills the histogram.
Definition: Par02Output.cc:219
Par02Output()
A default, protected constructor (due to singleton pattern).
Definition: Par02Output.cc:48
G4bool FillNtupleIColumn(G4int id, G4int value)
G4GLOB_DLL std::ostream G4cout
Handling the saving to the file.
Definition: Par02Output.hh:43
G4bool FillNtupleDColumn(G4int id, G4double value)
bool G4bool
Definition: G4Types.hh:79
G4String GetFileName()
Gets the file name of the output root file.
Definition: Par02Output.cc:81
Definition of the Par02Output class.
SaveType
Indicates to which ntuple to save the information.
Definition: Par02Output.hh:47
static Par02Output * Instance()
Allows the access to the unique Par02Output object.
Definition: Par02Output.cc:60
G4bool SetH1YAxisTitle(G4int id, const G4String &title)
void SaveTrack(SaveType aWhatToSave, G4int aPartID, G4int aPDG, G4ThreeVector aVector, G4double aResolution=0, G4double aEfficiency=1, G4double aEnergy=0)
Saves the information about the particle (track).
Definition: Par02Output.cc:162
void StartAnalysis(G4int runID)
Calls the G4AnalysisManager::Instance(). It sets the file name of the output file based on fFileName ...
Definition: Par02Output.cc:87
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4bool FillH1(G4int id, G4double value, G4double weight=1.0)
static Par02Output * fPar02Output
The pointer to the only Par02Output class object.
Definition: Par02Output.hh:115
#define G4endl
Definition: G4ios.hh:61
G4bool fFileNameWithRunNo
If true, a run number should be added to the file. Default: false.
Definition: Par02Output.hh:124
void SetFileName(G4String name)
Sets the file name of the output root file.
Definition: Par02Output.cc:69
double G4double
Definition: G4Types.hh:76
const G4Event * GetCurrentEvent() const
G4bool SetH1XAxisTitle(G4int id, const G4String &title)