Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
Par02Output.cc
이 파일의 문서화 페이지로 가기
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 G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
void CreateNtuples()
Definition: Par02Output.cc:108
SaveType
Indicates to which ntuple to save the information.
Definition: Par02Output.hh:47
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)
Definition: Par02Output.cc:162
G4bool SetH1XAxisTitle(G4int id, const G4String &title)
G4bool SetFileName(const G4String &fileName)
#define G4endl
Definition: G4ios.hh:61
void EndAnalysis()
Definition: Par02Output.cc:100
G4bool fFileNameWithRunNo
If true, a run number should be added to the file. Default: false.
Definition: Par02Output.hh:124
static G4ThreadLocal G4int fCurrentID
Definition: Par02Output.hh:129
void CreateHistograms()
Definition: Par02Output.cc:146
G4bool OpenFile(const G4String &fileName="")
double z() const
G4bool FillNtupleIColumn(G4int id, G4int value)
void StartAnalysis(G4int runID)
Definition: Par02Output.cc:87
#define G4ThreadLocal
Definition: tls.hh:69
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")
void FillHistogram(G4int HNo, G4double value) const
Definition: Par02Output.cc:219
G4bool FillNtupleDColumn(G4int id, G4double value)
double G4double
Definition: G4Types.hh:76
static Par02Output * fPar02Output
The pointer to the only Par02Output class object.
Definition: Par02Output.hh:115
bool G4bool
Definition: G4Types.hh:79
G4String fFileName
A name of the output root file.
Definition: Par02Output.hh:121
static G4ThreadLocal G4int fCurrentNtupleId
Current ntuple Id.
Definition: Par02Output.hh:118
Definition of the Par02Output class.
void AppendName(G4bool app)
Definition: Par02Output.cc:75
Par02Output()
A default, protected constructor (due to singleton pattern).
Definition: Par02Output.cc:48
void SetFileName(G4String name)
Definition: Par02Output.cc:69
const G4Event * GetCurrentEvent() const
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:374
void SetVerboseLevel(G4int verboseLevel)
G4String GetFileName()
Definition: Par02Output.cc:81
Definition of the Par02EventInformation class.
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
double x() const
static Par02Output * Instance()
Definition: Par02Output.cc:60
double y() const
G4bool FillH1(G4int id, G4double value, G4double weight=1.0)