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