Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 /// \file Par02Output.cc 27 /// \file Par02Output.cc 28 /// \brief Implementation of the Par02Output c 28 /// \brief Implementation of the Par02Output class 29 29 30 #include "Par02Output.hh" 30 #include "Par02Output.hh" 31 << 32 #include "Par02EventInformation.hh" 31 #include "Par02EventInformation.hh" 33 32 34 #include "G4AnalysisManager.hh" << 35 #include "G4Event.hh" 33 #include "G4Event.hh" 36 #include "G4RunManager.hh" 34 #include "G4RunManager.hh" 37 #include "G4SystemOfUnits.hh" << 38 #include "G4UnitsTable.hh" 35 #include "G4UnitsTable.hh" >> 36 #include "G4SystemOfUnits.hh" >> 37 #include "G4AnalysisManager.hh" 39 38 40 //....oooOO0OOooo........oooOO0OOooo........oo 39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 41 40 42 Par02Output* Par02Output::fPar02Output = nullp 41 Par02Output* Par02Output::fPar02Output = nullptr; 43 G4ThreadLocal G4int Par02Output::fCurrentNtupl 42 G4ThreadLocal G4int Par02Output::fCurrentNtupleId = 0; 44 G4ThreadLocal G4int Par02Output::fCurrentID = 43 G4ThreadLocal G4int Par02Output::fCurrentID = 0; 45 44 46 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 46 48 Par02Output::Par02Output() : fFileNameWithRunN << 47 Par02Output::Par02Output() : fFileNameWithRunNo( false ) { 49 { << 50 fFileName = "DefaultOutput.root"; 48 fFileName = "DefaultOutput.root"; 51 } 49 } 52 50 53 //....oooOO0OOooo........oooOO0OOooo........oo 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 54 52 55 Par02Output::~Par02Output() = default; 53 Par02Output::~Par02Output() = default; 56 54 57 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 56 59 Par02Output* Par02Output::Instance() << 57 Par02Output* Par02Output::Instance() { 60 { << 58 if ( ! fPar02Output ) { 61 if (!fPar02Output) { << 62 fPar02Output = new Par02Output(); 59 fPar02Output = new Par02Output(); 63 } 60 } 64 return fPar02Output; 61 return fPar02Output; 65 } 62 } 66 63 67 //....oooOO0OOooo........oooOO0OOooo........oo 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 68 65 69 void Par02Output::SetFileName(G4String aName) << 66 void Par02Output::SetFileName( G4String aName ) { 70 { << 71 fFileName = aName; 67 fFileName = aName; 72 } 68 } 73 69 74 //....oooOO0OOooo........oooOO0OOooo........oo 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 71 76 void Par02Output::AppendName(G4bool aApp) << 72 void Par02Output::AppendName( G4bool aApp ) { 77 { << 78 fFileNameWithRunNo = aApp; 73 fFileNameWithRunNo = aApp; 79 } 74 } 80 75 81 //....oooOO0OOooo........oooOO0OOooo........oo 76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 77 83 G4String Par02Output::GetFileName() << 78 G4String Par02Output::GetFileName() { 84 { << 85 return fFileName; 79 return fFileName; 86 } 80 } 87 81 88 //....oooOO0OOooo........oooOO0OOooo........oo 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 89 83 90 void Par02Output::StartAnalysis(G4int aRunID) << 84 void Par02Output::StartAnalysis( G4int aRunID ) { 91 { << 92 G4AnalysisManager* analysisManager = G4Analy 85 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 93 if (fFileNameWithRunNo) { << 86 if ( fFileNameWithRunNo ) { 94 fFileName += "_run"; << 87 fFileName += "_run"; 95 fFileName += G4UIcommand::ConvertToString( << 88 fFileName += G4UIcommand::ConvertToString( aRunID ); 96 } 89 } 97 analysisManager->SetDefaultFileType("root"); 90 analysisManager->SetDefaultFileType("root"); 98 analysisManager->SetVerboseLevel(1); << 91 analysisManager->SetVerboseLevel( 1 ); 99 analysisManager->SetFileName(fFileName); << 92 analysisManager->SetFileName( fFileName ); 100 analysisManager->OpenFile(fFileName); << 93 analysisManager->OpenFile( fFileName ); 101 } 94 } 102 95 103 //....oooOO0OOooo........oooOO0OOooo........oo 96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 104 97 105 void Par02Output::EndAnalysis() << 98 void Par02Output::EndAnalysis() { 106 { << 107 G4AnalysisManager* analysisManager = G4Analy 99 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 108 analysisManager->Write(); 100 analysisManager->Write(); 109 analysisManager->CloseFile(); 101 analysisManager->CloseFile(); 110 } 102 } 111 103 112 //....oooOO0OOooo........oooOO0OOooo........oo 104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 113 105 114 void Par02Output::CreateNtuples() << 106 void Par02Output::CreateNtuples() { 115 { << 116 const G4Event* event = G4RunManager::GetRunM 107 const G4Event* event = G4RunManager::GetRunManager()->GetCurrentEvent(); 117 G4String evName = "Event_"; 108 G4String evName = "Event_"; 118 evName += G4UIcommand::ConvertToString(event << 109 evName += G4UIcommand::ConvertToString( event->GetEventID() ); 119 G4AnalysisManager* analysisManager = G4Analy 110 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 120 fCurrentNtupleId = analysisManager->CreateNt << 111 fCurrentNtupleId = analysisManager->CreateNtuple( evName, evName ); 121 112 122 analysisManager->CreateNtupleIColumn("partic << 113 analysisManager->CreateNtupleIColumn( "particleID" ); // column Id = 0 123 analysisManager->CreateNtupleIColumn("PID"); << 114 analysisManager->CreateNtupleIColumn( "PID" ); // column Id = 1 124 analysisManager->CreateNtupleDColumn("MC_pX" << 115 analysisManager->CreateNtupleDColumn( "MC_pX" ); // column Id = 2 125 analysisManager->CreateNtupleDColumn("MC_pY" << 116 analysisManager->CreateNtupleDColumn( "MC_pY" ); // column Id = 3 126 analysisManager->CreateNtupleDColumn("MC_pZ" << 117 analysisManager->CreateNtupleDColumn( "MC_pZ" ); // column Id = 4 127 << 118 128 analysisManager->CreateNtupleDColumn("tracke << 119 analysisManager->CreateNtupleDColumn( "tracker_res" ); // column Id = 5 129 analysisManager->CreateNtupleDColumn("tracke << 120 analysisManager->CreateNtupleDColumn( "tracker_eff" ); // column Id = 6 130 analysisManager->CreateNtupleDColumn("tracke << 121 analysisManager->CreateNtupleDColumn( "tracker_pX" ); // column Id = 7 131 analysisManager->CreateNtupleDColumn("tracke << 122 analysisManager->CreateNtupleDColumn( "tracker_pY" ); // column Id = 8 132 analysisManager->CreateNtupleDColumn("tracke << 123 analysisManager->CreateNtupleDColumn( "tracker_pZ" ); // column Id = 9 133 << 124 134 analysisManager->CreateNtupleDColumn("emcal_ << 125 analysisManager->CreateNtupleDColumn( "emcal_res" ); // column Id = 10 135 analysisManager->CreateNtupleDColumn("emcal_ << 126 analysisManager->CreateNtupleDColumn( "emcal_eff" ); // column Id = 11 136 analysisManager->CreateNtupleDColumn("emcal_ << 127 analysisManager->CreateNtupleDColumn( "emcal_X" ); // column Id = 12 137 analysisManager->CreateNtupleDColumn("emcal_ << 128 analysisManager->CreateNtupleDColumn( "emcal_Y" ); // column Id = 13 138 analysisManager->CreateNtupleDColumn("emcal_ << 129 analysisManager->CreateNtupleDColumn( "emcal_Z" ); // column Id = 14 139 analysisManager->CreateNtupleDColumn("emcal_ << 130 analysisManager->CreateNtupleDColumn( "emcal_E" ); // column Id = 15 140 << 131 141 analysisManager->CreateNtupleDColumn("hcal_r << 132 analysisManager->CreateNtupleDColumn( "hcal_res" ); // column Id = 16 142 analysisManager->CreateNtupleDColumn("hcal_e << 133 analysisManager->CreateNtupleDColumn( "hcal_eff" ); // column Id = 17 143 analysisManager->CreateNtupleDColumn("hcal_X << 134 analysisManager->CreateNtupleDColumn( "hcal_X" ); // column Id = 18 144 analysisManager->CreateNtupleDColumn("hcal_Y << 135 analysisManager->CreateNtupleDColumn( "hcal_Y" ); // column Id = 19 145 analysisManager->CreateNtupleDColumn("hcal_Z << 136 analysisManager->CreateNtupleDColumn( "hcal_Z" ); // column Id = 20 146 analysisManager->CreateNtupleDColumn("hcal_E << 137 analysisManager->CreateNtupleDColumn( "hcal_E" ); // column Id = 21 147 138 148 analysisManager->FinishNtuple(fCurrentNtuple << 139 analysisManager->FinishNtuple( fCurrentNtupleId ); 149 } 140 } 150 141 151 //....oooOO0OOooo........oooOO0OOooo........oo 142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 152 143 153 void Par02Output::CreateHistograms() 144 void Par02Output::CreateHistograms() 154 { 145 { 155 G4AnalysisManager* analysisManager = G4Analy 146 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 156 analysisManager->CreateH1("Pdiff", "momentum << 147 analysisManager->CreateH1( "Pdiff", "momentum smeared in tracker", 100, 0.8, 1.2 ); 157 analysisManager->SetH1XAxisTitle(0, "p_{smea << 148 analysisManager->SetH1XAxisTitle( 0, "p_{smeared}/p_{true}" ); 158 analysisManager->SetH1YAxisTitle(0, "Entries << 149 analysisManager->SetH1YAxisTitle( 0, "Entries" ); 159 analysisManager->CreateH1("EMCalEdiff", "ene << 150 analysisManager->CreateH1( "EMCalEdiff", "energy smeared in EMCal", 100, 0.8, 1.2 ); 160 analysisManager->SetH1XAxisTitle(1, "E_{smea << 151 analysisManager->SetH1XAxisTitle( 1, "E_{smeared}/E_{true}" ); 161 analysisManager->SetH1YAxisTitle(1, "Entries << 152 analysisManager->SetH1YAxisTitle( 1, "Entries" ); 162 analysisManager->CreateH1("HCalEdiff", "ener << 153 analysisManager->CreateH1( "HCalEdiff", "energy smeared in HCal", 100, 0.0, 2.0 ); 163 analysisManager->SetH1XAxisTitle(2, "E_{smea << 154 analysisManager->SetH1XAxisTitle( 2, "E_{smeared}/E_{true}" ); 164 analysisManager->SetH1YAxisTitle(2, "Entries << 155 analysisManager->SetH1YAxisTitle( 2, "Entries" ); 165 } 156 } 166 157 167 //....oooOO0OOooo........oooOO0OOooo........oo 158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 159 169 void Par02Output::SaveTrack(SaveType aWhatToSa << 160 void Par02Output::SaveTrack( SaveType aWhatToSave, G4int aPartID, G4int aPDG, 170 G4double aResoluti << 161 G4ThreeVector aVector, G4double aResolution, 171 { << 162 G4double aEfficiency, G4double aEnergy ) { 172 G4AnalysisManager* analysisManager = G4Analy 163 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 173 switch (aWhatToSave) { << 164 switch( aWhatToSave ) { 174 case Par02Output::eNoSave: << 165 case Par02Output::eNoSave : 175 break; 166 break; 176 case Par02Output::eSaveMC: { << 167 case Par02Output::eSaveMC : { 177 analysisManager->FillNtupleIColumn(fCurr << 168 analysisManager->FillNtupleIColumn( fCurrentNtupleId, 0, aPartID ); 178 analysisManager->FillNtupleIColumn(fCurr << 169 analysisManager->FillNtupleIColumn( fCurrentNtupleId, 1, aPDG ); 179 analysisManager->FillNtupleDColumn(fCurr << 170 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 2, aVector.x() ); 180 analysisManager->FillNtupleDColumn(fCurr << 171 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 3, aVector.y() ); 181 analysisManager->FillNtupleDColumn(fCurr << 172 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 4, aVector.z() ); 182 fCurrentID = aPartID; 173 fCurrentID = aPartID; 183 break; 174 break; 184 } 175 } 185 case Par02Output::eSaveTracker: { << 176 case Par02Output::eSaveTracker : { 186 if (aPartID != fCurrentID) << 177 if ( aPartID != fCurrentID ) G4cout << 187 G4cout << " Wrong particle - trying to << 178 " Wrong particle - trying to save Tracker information of different particle" 188 << G4endl; << 179 << G4endl; 189 analysisManager->FillNtupleDColumn(fCurr << 180 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 5, aResolution ); 190 analysisManager->FillNtupleDColumn(fCurr << 181 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 6, aEfficiency ); 191 analysisManager->FillNtupleDColumn(fCurr << 182 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 7, aVector.x() ); 192 analysisManager->FillNtupleDColumn(fCurr << 183 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 8, aVector.y() ); 193 analysisManager->FillNtupleDColumn(fCurr << 184 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 9, aVector.z() ); 194 break; 185 break; 195 } 186 } 196 case Par02Output::eSaveEMCal: { << 187 case Par02Output::eSaveEMCal : { 197 if (aPartID != fCurrentID) << 188 if ( aPartID != fCurrentID ) G4cout << 198 G4cout << " Wrong particle - trying to << 189 " Wrong particle - trying to save EMCal information of different particle" 199 << G4endl; << 190 << G4endl; 200 analysisManager->FillNtupleDColumn(fCurr << 191 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 10, aResolution ); 201 analysisManager->FillNtupleDColumn(fCurr << 192 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 11, aEfficiency ); 202 analysisManager->FillNtupleDColumn(fCurr << 193 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 12, aVector.x() ); 203 analysisManager->FillNtupleDColumn(fCurr << 194 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 13, aVector.y() ); 204 analysisManager->FillNtupleDColumn(fCurr << 195 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 14, aVector.z() ); 205 analysisManager->FillNtupleDColumn(fCurr << 196 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 15, aEnergy ); 206 break; 197 break; 207 } 198 } 208 case Par02Output::eSaveHCal: { << 199 case Par02Output::eSaveHCal : { 209 if (aPartID != fCurrentID) << 200 if ( aPartID != fCurrentID ) G4cout << 210 G4cout << " Wrong particle - trying to << 201 " Wrong particle - trying to save HCal information of different particle" 211 << G4endl; << 202 << G4endl; 212 analysisManager->FillNtupleDColumn(fCurr << 203 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 16, aResolution ); 213 analysisManager->FillNtupleDColumn(fCurr << 204 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 17, aEfficiency ); 214 analysisManager->FillNtupleDColumn(fCurr << 205 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 18, aVector.x() ); 215 analysisManager->FillNtupleDColumn(fCurr << 206 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 19, aVector.y() ); 216 analysisManager->FillNtupleDColumn(fCurr << 207 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 20, aVector.z() ); 217 analysisManager->FillNtupleDColumn(fCurr << 208 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 21, aEnergy ); 218 analysisManager->AddNtupleRow(fCurrentNt << 209 analysisManager->AddNtupleRow( fCurrentNtupleId ); 219 break; 210 break; 220 } 211 } 221 } 212 } 222 } 213 } 223 214 224 //....oooOO0OOooo........oooOO0OOooo........oo 215 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 225 216 226 void Par02Output::FillHistogram(G4int aHistNo, << 217 void Par02Output::FillHistogram( G4int aHistNo, G4double aValue ) const { 227 { << 228 G4AnalysisManager* analysisManager = G4Analy 218 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 229 analysisManager->FillH1(aHistNo, aValue); << 219 analysisManager->FillH1( aHistNo, aValue ); 230 } 220 } 231 221 232 //....oooOO0OOooo........oooOO0OOooo........oo 222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 223 233 224