ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Par02Output.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
29 
30 #include "Par02Output.hh"
31 #include "Par02EventInformation.hh"
32 
33 #include "G4Event.hh"
34 #include "G4RunManager.hh"
35 #include "G4UnitsTable.hh"
36 #include "G4SystemOfUnits.hh"
37 #include "g4root.hh"
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40 
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 
47 Par02Output::Par02Output() : fFileNameWithRunNo( false ) {
48  fFileName = "DefaultOutput.root";
49 }
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60  if ( ! fPar02Output ) {
61  fPar02Output = new Par02Output();
62  }
63  return fPar02Output;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69  fFileName = aName;
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75  fFileNameWithRunNo = aApp;
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81  return fFileName;
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
85 
88  if ( fFileNameWithRunNo ) {
89  fFileName += "_run";
91  }
92  analysisManager->SetVerboseLevel( 1 );
93  analysisManager->SetFileName( fFileName );
94  analysisManager->OpenFile( fFileName );
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
100  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
101  analysisManager->Write();
102  analysisManager->CloseFile();
103 }
104 
105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
106 
109  G4String evName = "Event_";
110  evName += G4UIcommand::ConvertToString( event->GetEventID() );
111  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
112  fCurrentNtupleId = analysisManager->CreateNtuple( evName, evName );
113 
114  analysisManager->CreateNtupleIColumn( "particleID" ); // column Id = 0
115  analysisManager->CreateNtupleIColumn( "PID" ); // column Id = 1
116  analysisManager->CreateNtupleDColumn( "MC_pX" ); // column Id = 2
117  analysisManager->CreateNtupleDColumn( "MC_pY" ); // column Id = 3
118  analysisManager->CreateNtupleDColumn( "MC_pZ" ); // column Id = 4
119 
120  analysisManager->CreateNtupleDColumn( "tracker_res" ); // column Id = 5
121  analysisManager->CreateNtupleDColumn( "tracker_eff" ); // column Id = 6
122  analysisManager->CreateNtupleDColumn( "tracker_pX" ); // column Id = 7
123  analysisManager->CreateNtupleDColumn( "tracker_pY" ); // column Id = 8
124  analysisManager->CreateNtupleDColumn( "tracker_pZ" ); // column Id = 9
125 
126  analysisManager->CreateNtupleDColumn( "emcal_res" ); // column Id = 10
127  analysisManager->CreateNtupleDColumn( "emcal_eff" ); // column Id = 11
128  analysisManager->CreateNtupleDColumn( "emcal_X" ); // column Id = 12
129  analysisManager->CreateNtupleDColumn( "emcal_Y" ); // column Id = 13
130  analysisManager->CreateNtupleDColumn( "emcal_Z" ); // column Id = 14
131  analysisManager->CreateNtupleDColumn( "emcal_E" ); // column Id = 15
132 
133  analysisManager->CreateNtupleDColumn( "hcal_res" ); // column Id = 16
134  analysisManager->CreateNtupleDColumn( "hcal_eff" ); // column Id = 17
135  analysisManager->CreateNtupleDColumn( "hcal_X" ); // column Id = 18
136  analysisManager->CreateNtupleDColumn( "hcal_Y" ); // column Id = 19
137  analysisManager->CreateNtupleDColumn( "hcal_Z" ); // column Id = 20
138  analysisManager->CreateNtupleDColumn( "hcal_E" ); // column Id = 21
139 
140  analysisManager->FinishNtuple( fCurrentNtupleId );
141 }
142 
143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
144 
146 {
147  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
148  analysisManager->CreateH1( "Pdiff", "momentum smeared in tracker", 100, 0.8, 1.2 );
149  analysisManager->SetH1XAxisTitle( 0, "p_{smeared}/p_{true}" );
150  analysisManager->SetH1YAxisTitle( 0, "Entries" );
151  analysisManager->CreateH1( "EMCalEdiff", "energy smeared in EMCal", 100, 0.8, 1.2 );
152  analysisManager->SetH1XAxisTitle( 1, "E_{smeared}/E_{true}" );
153  analysisManager->SetH1YAxisTitle( 1, "Entries" );
154  analysisManager->CreateH1( "HCalEdiff", "energy smeared in HCal", 100, 0.0, 2.0 );
155  analysisManager->SetH1XAxisTitle( 2, "E_{smeared}/E_{true}" );
156  analysisManager->SetH1YAxisTitle( 2, "Entries" );
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160 
161 void Par02Output::SaveTrack( SaveType aWhatToSave, G4int aPartID, G4int aPDG,
162  G4ThreeVector aVector, G4double aResolution,
163  G4double aEfficiency, G4double aEnergy ) {
164  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
165  switch( aWhatToSave ) {
166  case Par02Output::eNoSave :
167  break;
168  case Par02Output::eSaveMC : {
169  analysisManager->FillNtupleIColumn( fCurrentNtupleId, 0, aPartID );
170  analysisManager->FillNtupleIColumn( fCurrentNtupleId, 1, aPDG );
171  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 2, aVector.x() );
172  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 3, aVector.y() );
173  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 4, aVector.z() );
174  fCurrentID = aPartID;
175  break;
176  }
178  if ( aPartID != fCurrentID ) G4cout <<
179  " Wrong particle - trying to save Tracker information of different particle"
180  << G4endl;
181  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 5, aResolution );
182  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 6, aEfficiency );
183  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 7, aVector.x() );
184  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 8, aVector.y() );
185  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 9, aVector.z() );
186  break;
187  }
188  case Par02Output::eSaveEMCal : {
189  if ( aPartID != fCurrentID ) G4cout <<
190  " Wrong particle - trying to save EMCal information of different particle"
191  << G4endl;
192  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 10, aResolution );
193  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 11, aEfficiency );
194  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 12, aVector.x() );
195  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 13, aVector.y() );
196  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 14, aVector.z() );
197  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 15, aEnergy );
198  break;
199  }
200  case Par02Output::eSaveHCal : {
201  if ( aPartID != fCurrentID ) G4cout <<
202  " Wrong particle - trying to save HCal information of different particle"
203  << G4endl;
204  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 16, aResolution );
205  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 17, aEfficiency );
206  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 18, aVector.x() );
207  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 19, aVector.y() );
208  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 20, aVector.z() );
209  analysisManager->FillNtupleDColumn( fCurrentNtupleId, 21, aEnergy );
210  analysisManager->AddNtupleRow( fCurrentNtupleId );
211  break;
212  }
213  }
214 }
215 
216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217 
218 void Par02Output::FillHistogram( G4int aHistNo, G4double aValue ) const {
219  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
220  analysisManager->FillH1( aHistNo, aValue );
221 }
222 
223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
224