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 "g4root.hh" 39 38 40 //....oooOO0OOooo........oooOO0OOooo........oo 39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 41 40 42 Par02Output* Par02Output::fPar02Output = nullp << 41 Par02Output* Par02Output::fPar02Output = 0; 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() { >> 54 delete G4AnalysisManager::Instance(); >> 55 } 56 56 57 //....oooOO0OOooo........oooOO0OOooo........oo 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 58 59 Par02Output* Par02Output::Instance() << 59 Par02Output* Par02Output::Instance() { 60 { << 60 if ( ! fPar02Output ) { 61 if (!fPar02Output) { << 62 fPar02Output = new Par02Output(); 61 fPar02Output = new Par02Output(); 63 } 62 } 64 return fPar02Output; 63 return fPar02Output; 65 } 64 } 66 65 67 //....oooOO0OOooo........oooOO0OOooo........oo 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 68 67 69 void Par02Output::SetFileName(G4String aName) << 68 void Par02Output::SetFileName( G4String aName ) { 70 { << 71 fFileName = aName; 69 fFileName = aName; 72 } 70 } 73 71 74 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 73 76 void Par02Output::AppendName(G4bool aApp) << 74 void Par02Output::AppendName( G4bool aApp ) { 77 { << 78 fFileNameWithRunNo = aApp; 75 fFileNameWithRunNo = aApp; 79 } 76 } 80 77 81 //....oooOO0OOooo........oooOO0OOooo........oo 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 79 83 G4String Par02Output::GetFileName() << 80 G4String Par02Output::GetFileName() { 84 { << 85 return fFileName; 81 return fFileName; 86 } 82 } 87 83 88 //....oooOO0OOooo........oooOO0OOooo........oo 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 89 85 90 void Par02Output::StartAnalysis(G4int aRunID) << 86 void Par02Output::StartAnalysis( G4int aRunID ) { 91 { << 92 G4AnalysisManager* analysisManager = G4Analy 87 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 93 if (fFileNameWithRunNo) { << 88 if ( fFileNameWithRunNo ) { 94 fFileName += "_run"; << 89 fFileName += "_run"; 95 fFileName += G4UIcommand::ConvertToString( << 90 fFileName += G4UIcommand::ConvertToString( aRunID ); 96 } 91 } 97 analysisManager->SetDefaultFileType("root"); << 92 analysisManager->SetVerboseLevel( 1 ); 98 analysisManager->SetVerboseLevel(1); << 93 analysisManager->SetFileName( fFileName ); 99 analysisManager->SetFileName(fFileName); << 94 analysisManager->OpenFile( fFileName ); 100 analysisManager->OpenFile(fFileName); << 101 } 95 } 102 96 103 //....oooOO0OOooo........oooOO0OOooo........oo 97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 104 98 105 void Par02Output::EndAnalysis() << 99 void Par02Output::EndAnalysis() { 106 { << 107 G4AnalysisManager* analysisManager = G4Analy 100 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 108 analysisManager->Write(); 101 analysisManager->Write(); 109 analysisManager->CloseFile(); 102 analysisManager->CloseFile(); 110 } 103 } 111 104 112 //....oooOO0OOooo........oooOO0OOooo........oo 105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 113 106 114 void Par02Output::CreateNtuples() << 107 void Par02Output::CreateNtuples() { 115 { << 116 const G4Event* event = G4RunManager::GetRunM 108 const G4Event* event = G4RunManager::GetRunManager()->GetCurrentEvent(); 117 G4String evName = "Event_"; 109 G4String evName = "Event_"; 118 evName += G4UIcommand::ConvertToString(event << 110 evName += G4UIcommand::ConvertToString( event->GetEventID() ); 119 G4AnalysisManager* analysisManager = G4Analy 111 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 120 fCurrentNtupleId = analysisManager->CreateNt << 112 fCurrentNtupleId = analysisManager->CreateNtuple( evName, evName ); 121 113 122 analysisManager->CreateNtupleIColumn("partic << 114 analysisManager->CreateNtupleIColumn( "particleID" ); // column Id = 0 123 analysisManager->CreateNtupleIColumn("PID"); << 115 analysisManager->CreateNtupleIColumn( "PID" ); // column Id = 1 124 analysisManager->CreateNtupleDColumn("MC_pX" << 116 analysisManager->CreateNtupleDColumn( "MC_pX" ); // column Id = 2 125 analysisManager->CreateNtupleDColumn("MC_pY" << 117 analysisManager->CreateNtupleDColumn( "MC_pY" ); // column Id = 3 126 analysisManager->CreateNtupleDColumn("MC_pZ" << 118 analysisManager->CreateNtupleDColumn( "MC_pZ" ); // column Id = 4 127 << 119 128 analysisManager->CreateNtupleDColumn("tracke << 120 analysisManager->CreateNtupleDColumn( "tracker_res" ); // column Id = 5 129 analysisManager->CreateNtupleDColumn("tracke << 121 analysisManager->CreateNtupleDColumn( "tracker_eff" ); // column Id = 6 130 analysisManager->CreateNtupleDColumn("tracke << 122 analysisManager->CreateNtupleDColumn( "tracker_pX" ); // column Id = 7 131 analysisManager->CreateNtupleDColumn("tracke << 123 analysisManager->CreateNtupleDColumn( "tracker_pY" ); // column Id = 8 132 analysisManager->CreateNtupleDColumn("tracke << 124 analysisManager->CreateNtupleDColumn( "tracker_pZ" ); // column Id = 9 133 << 125 134 analysisManager->CreateNtupleDColumn("emcal_ << 126 analysisManager->CreateNtupleDColumn( "emcal_res" ); // column Id = 10 135 analysisManager->CreateNtupleDColumn("emcal_ << 127 analysisManager->CreateNtupleDColumn( "emcal_eff" ); // column Id = 11 136 analysisManager->CreateNtupleDColumn("emcal_ << 128 analysisManager->CreateNtupleDColumn( "emcal_X" ); // column Id = 12 137 analysisManager->CreateNtupleDColumn("emcal_ << 129 analysisManager->CreateNtupleDColumn( "emcal_Y" ); // column Id = 13 138 analysisManager->CreateNtupleDColumn("emcal_ << 130 analysisManager->CreateNtupleDColumn( "emcal_Z" ); // column Id = 14 139 analysisManager->CreateNtupleDColumn("emcal_ << 131 analysisManager->CreateNtupleDColumn( "emcal_E" ); // column Id = 15 140 << 132 141 analysisManager->CreateNtupleDColumn("hcal_r << 133 analysisManager->CreateNtupleDColumn( "hcal_res" ); // column Id = 16 142 analysisManager->CreateNtupleDColumn("hcal_e << 134 analysisManager->CreateNtupleDColumn( "hcal_eff" ); // column Id = 17 143 analysisManager->CreateNtupleDColumn("hcal_X << 135 analysisManager->CreateNtupleDColumn( "hcal_X" ); // column Id = 18 144 analysisManager->CreateNtupleDColumn("hcal_Y << 136 analysisManager->CreateNtupleDColumn( "hcal_Y" ); // column Id = 19 145 analysisManager->CreateNtupleDColumn("hcal_Z << 137 analysisManager->CreateNtupleDColumn( "hcal_Z" ); // column Id = 20 146 analysisManager->CreateNtupleDColumn("hcal_E << 138 analysisManager->CreateNtupleDColumn( "hcal_E" ); // column Id = 21 147 139 148 analysisManager->FinishNtuple(fCurrentNtuple << 140 analysisManager->FinishNtuple( fCurrentNtupleId ); 149 } 141 } 150 142 151 //....oooOO0OOooo........oooOO0OOooo........oo 143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 152 144 153 void Par02Output::CreateHistograms() 145 void Par02Output::CreateHistograms() 154 { 146 { 155 G4AnalysisManager* analysisManager = G4Analy 147 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 156 analysisManager->CreateH1("Pdiff", "momentum << 148 analysisManager->CreateH1( "Pdiff", "momentum smeared in tracker", 100, 0.8, 1.2 ); 157 analysisManager->SetH1XAxisTitle(0, "p_{smea << 149 analysisManager->SetH1XAxisTitle( 0, "p_{smeared}/p_{true}" ); 158 analysisManager->SetH1YAxisTitle(0, "Entries << 150 analysisManager->SetH1YAxisTitle( 0, "Entries" ); 159 analysisManager->CreateH1("EMCalEdiff", "ene << 151 analysisManager->CreateH1( "EMCalEdiff", "energy smeared in EMCal", 100, 0.8, 1.2 ); 160 analysisManager->SetH1XAxisTitle(1, "E_{smea << 152 analysisManager->SetH1XAxisTitle( 1, "E_{smeared}/E_{true}" ); 161 analysisManager->SetH1YAxisTitle(1, "Entries << 153 analysisManager->SetH1YAxisTitle( 1, "Entries" ); 162 analysisManager->CreateH1("HCalEdiff", "ener << 154 analysisManager->CreateH1( "HCalEdiff", "energy smeared in HCal", 100, 0.0, 2.0 ); 163 analysisManager->SetH1XAxisTitle(2, "E_{smea << 155 analysisManager->SetH1XAxisTitle( 2, "E_{smeared}/E_{true}" ); 164 analysisManager->SetH1YAxisTitle(2, "Entries << 156 analysisManager->SetH1YAxisTitle( 2, "Entries" ); 165 } 157 } 166 158 167 //....oooOO0OOooo........oooOO0OOooo........oo 159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 160 169 void Par02Output::SaveTrack(SaveType aWhatToSa << 161 void Par02Output::SaveTrack( SaveType aWhatToSave, G4int aPartID, G4int aPDG, 170 G4double aResoluti << 162 G4ThreeVector aVector, G4double aResolution, 171 { << 163 G4double aEfficiency, G4double aEnergy ) { 172 G4AnalysisManager* analysisManager = G4Analy 164 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 173 switch (aWhatToSave) { << 165 switch( aWhatToSave ) { 174 case Par02Output::eNoSave: << 166 case Par02Output::eNoSave : 175 break; 167 break; 176 case Par02Output::eSaveMC: { << 168 case Par02Output::eSaveMC : { 177 analysisManager->FillNtupleIColumn(fCurr << 169 analysisManager->FillNtupleIColumn( fCurrentNtupleId, 0, aPartID ); 178 analysisManager->FillNtupleIColumn(fCurr << 170 analysisManager->FillNtupleIColumn( fCurrentNtupleId, 1, aPDG ); 179 analysisManager->FillNtupleDColumn(fCurr << 171 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 2, aVector.x() ); 180 analysisManager->FillNtupleDColumn(fCurr << 172 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 3, aVector.y() ); 181 analysisManager->FillNtupleDColumn(fCurr << 173 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 4, aVector.z() ); 182 fCurrentID = aPartID; 174 fCurrentID = aPartID; 183 break; 175 break; 184 } 176 } 185 case Par02Output::eSaveTracker: { << 177 case Par02Output::eSaveTracker : { 186 if (aPartID != fCurrentID) << 178 if ( aPartID != fCurrentID ) G4cout << 187 G4cout << " Wrong particle - trying to << 179 " Wrong particle - trying to save Tracker information of different particle" 188 << G4endl; << 180 << G4endl; 189 analysisManager->FillNtupleDColumn(fCurr << 181 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 5, aResolution ); 190 analysisManager->FillNtupleDColumn(fCurr << 182 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 6, aEfficiency ); 191 analysisManager->FillNtupleDColumn(fCurr << 183 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 7, aVector.x() ); 192 analysisManager->FillNtupleDColumn(fCurr << 184 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 8, aVector.y() ); 193 analysisManager->FillNtupleDColumn(fCurr << 185 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 9, aVector.z() ); 194 break; 186 break; 195 } 187 } 196 case Par02Output::eSaveEMCal: { << 188 case Par02Output::eSaveEMCal : { 197 if (aPartID != fCurrentID) << 189 if ( aPartID != fCurrentID ) G4cout << 198 G4cout << " Wrong particle - trying to << 190 " Wrong particle - trying to save EMCal information of different particle" 199 << G4endl; << 191 << G4endl; 200 analysisManager->FillNtupleDColumn(fCurr << 192 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 10, aResolution ); 201 analysisManager->FillNtupleDColumn(fCurr << 193 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 11, aEfficiency ); 202 analysisManager->FillNtupleDColumn(fCurr << 194 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 12, aVector.x() ); 203 analysisManager->FillNtupleDColumn(fCurr << 195 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 13, aVector.y() ); 204 analysisManager->FillNtupleDColumn(fCurr << 196 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 14, aVector.z() ); 205 analysisManager->FillNtupleDColumn(fCurr << 197 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 15, aEnergy ); 206 break; 198 break; 207 } 199 } 208 case Par02Output::eSaveHCal: { << 200 case Par02Output::eSaveHCal : { 209 if (aPartID != fCurrentID) << 201 if ( aPartID != fCurrentID ) G4cout << 210 G4cout << " Wrong particle - trying to << 202 " Wrong particle - trying to save HCal information of different particle" 211 << G4endl; << 203 << G4endl; 212 analysisManager->FillNtupleDColumn(fCurr << 204 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 16, aResolution ); 213 analysisManager->FillNtupleDColumn(fCurr << 205 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 17, aEfficiency ); 214 analysisManager->FillNtupleDColumn(fCurr << 206 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 18, aVector.x() ); 215 analysisManager->FillNtupleDColumn(fCurr << 207 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 19, aVector.y() ); 216 analysisManager->FillNtupleDColumn(fCurr << 208 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 20, aVector.z() ); 217 analysisManager->FillNtupleDColumn(fCurr << 209 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 21, aEnergy ); 218 analysisManager->AddNtupleRow(fCurrentNt << 210 analysisManager->AddNtupleRow( fCurrentNtupleId ); 219 break; 211 break; 220 } 212 } 221 } 213 } 222 } 214 } 223 215 224 //....oooOO0OOooo........oooOO0OOooo........oo 216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 225 217 226 void Par02Output::FillHistogram(G4int aHistNo, << 218 void Par02Output::FillHistogram( G4int aHistNo, G4double aValue ) const { 227 { << 228 G4AnalysisManager* analysisManager = G4Analy 219 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 229 analysisManager->FillH1(aHistNo, aValue); << 220 analysisManager->FillH1( aHistNo, aValue ); 230 } 221 } 231 222 232 //....oooOO0OOooo........oooOO0OOooo........oo 223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 224 233 225