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 B5/src/RunAction.cc << 27 /// \file RunAction.cc 28 /// \brief Implementation of the B5::RunAction 28 /// \brief Implementation of the B5::RunAction class 29 29 30 #include "RunAction.hh" 30 #include "RunAction.hh" 31 << 32 #include "EventAction.hh" 31 #include "EventAction.hh" 33 32 >> 33 #include "G4Run.hh" >> 34 #include "G4UnitsTable.hh" >> 35 #include "G4SystemOfUnits.hh" 34 #include "G4AnalysisManager.hh" 36 #include "G4AnalysisManager.hh" 35 37 36 namespace B5 38 namespace B5 37 { 39 { 38 40 39 //....oooOO0OOooo........oooOO0OOooo........oo 41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 40 42 41 RunAction::RunAction(EventAction* eventAction) << 43 RunAction::RunAction(EventAction* eventAction) >> 44 : fEventAction(eventAction) 42 { 45 { 43 // Create the generic analysis manager 46 // Create the generic analysis manager 44 auto analysisManager = G4AnalysisManager::In 47 auto analysisManager = G4AnalysisManager::Instance(); 45 analysisManager->SetDefaultFileType("root"); 48 analysisManager->SetDefaultFileType("root"); 46 // If the filename extension is not provided << 49 // If the filename extension is not provided, the default file type (root) 47 // will be used for all files specified with << 50 // will be used for all files specified without extension. 48 analysisManager->SetVerboseLevel(1); 51 analysisManager->SetVerboseLevel(1); 49 52 50 // Default settings 53 // Default settings 51 analysisManager->SetNtupleMerging(true); 54 analysisManager->SetNtupleMerging(true); 52 // Note: merging ntuples is available only w << 55 // Note: merging ntuples is available only with Root output 53 analysisManager->SetFileName("B5"); 56 analysisManager->SetFileName("B5"); 54 57 55 // Book histograms, ntuple 58 // Book histograms, ntuple 56 59 57 // Creating 1D histograms 60 // Creating 1D histograms 58 analysisManager->CreateH1("Chamber1", "Drift << 61 analysisManager 59 analysisManager->CreateH1("Chamber2", "Drift << 62 ->CreateH1("Chamber1","Drift Chamber 1 # Hits", 50, 0., 50); // h1 Id = 0 >> 63 analysisManager >> 64 ->CreateH1("Chamber2","Drift Chamber 2 # Hits", 50, 0., 50); // h1 Id = 1 60 65 61 // Creating 2D histograms 66 // Creating 2D histograms 62 analysisManager->CreateH2("Chamber1 XY", "Dr << 67 analysisManager 63 50, -1000., 1000, << 68 ->CreateH2("Chamber1 XY","Drift Chamber 1 X vs Y", // h2 Id = 0 64 analysisManager->CreateH2("Chamber2 XY", "Dr << 69 50, -1000., 1000, 50, -300., 300.); 65 50, -1500., 1500, << 70 analysisManager >> 71 ->CreateH2("Chamber2 XY","Drift Chamber 2 X vs Y", // h2 Id = 1 >> 72 50, -1500., 1500, 50, -300., 300.); 66 73 67 // Creating ntuple 74 // Creating ntuple 68 if (fEventAction) { << 75 if ( fEventAction ) { 69 analysisManager->CreateNtuple("B5", "Hits" 76 analysisManager->CreateNtuple("B5", "Hits"); 70 analysisManager->CreateNtupleIColumn("Dc1H 77 analysisManager->CreateNtupleIColumn("Dc1Hits"); // column Id = 0 71 analysisManager->CreateNtupleIColumn("Dc2H 78 analysisManager->CreateNtupleIColumn("Dc2Hits"); // column Id = 1 72 analysisManager->CreateNtupleDColumn("ECEn << 79 analysisManager->CreateNtupleDColumn("ECEnergy"); // column Id = 2 73 analysisManager->CreateNtupleDColumn("HCEn << 80 analysisManager->CreateNtupleDColumn("HCEnergy"); // column Id = 3 74 analysisManager->CreateNtupleDColumn("Time << 81 analysisManager->CreateNtupleDColumn("Time1"); // column Id = 4 75 analysisManager->CreateNtupleDColumn("Time << 82 analysisManager->CreateNtupleDColumn("Time2"); // column Id = 5 76 analysisManager // column Id = 6 << 83 analysisManager // column Id = 6 77 ->CreateNtupleDColumn("ECEnergyVector", 84 ->CreateNtupleDColumn("ECEnergyVector", fEventAction->GetEmCalEdep()); 78 analysisManager // column Id = 7 << 85 analysisManager // column Id = 7 79 ->CreateNtupleDColumn("HCEnergyVector", 86 ->CreateNtupleDColumn("HCEnergyVector", fEventAction->GetHadCalEdep()); 80 analysisManager->FinishNtuple(); 87 analysisManager->FinishNtuple(); 81 } 88 } 82 89 83 // Set ntuple output file 90 // Set ntuple output file 84 analysisManager->SetNtupleFileName(0, "B5ntu 91 analysisManager->SetNtupleFileName(0, "B5ntuple"); 85 } 92 } 86 93 87 //....oooOO0OOooo........oooOO0OOooo........oo 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 88 95 >> 96 RunAction::~RunAction() >> 97 { >> 98 } >> 99 >> 100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 101 89 void RunAction::BeginOfRunAction(const G4Run* 102 void RunAction::BeginOfRunAction(const G4Run* /*run*/) 90 { 103 { 91 // inform the runManager to save random numb << 104 //inform the runManager to save random number seed 92 // G4RunManager::GetRunManager()->SetRandomN << 105 //G4RunManager::GetRunManager()->SetRandomNumberStore(true); 93 106 94 // Get analysis manager 107 // Get analysis manager 95 auto analysisManager = G4AnalysisManager::In 108 auto analysisManager = G4AnalysisManager::Instance(); 96 109 97 // Reset histograms from previous run 110 // Reset histograms from previous run 98 analysisManager->Reset(); 111 analysisManager->Reset(); 99 112 100 // Open an output file 113 // Open an output file 101 // The default file name is set in RunAction 114 // The default file name is set in RunAction::RunAction(), 102 // it can be overwritten in a macro 115 // it can be overwritten in a macro 103 analysisManager->OpenFile(); 116 analysisManager->OpenFile(); 104 } 117 } 105 118 106 //....oooOO0OOooo........oooOO0OOooo........oo 119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 107 120 108 void RunAction::EndOfRunAction(const G4Run* /* 121 void RunAction::EndOfRunAction(const G4Run* /*run*/) 109 { 122 { 110 // save histograms & ntuple 123 // save histograms & ntuple 111 // 124 // 112 auto analysisManager = G4AnalysisManager::In 125 auto analysisManager = G4AnalysisManager::Instance(); 113 analysisManager->Write(); 126 analysisManager->Write(); 114 analysisManager->CloseFile(false); 127 analysisManager->CloseFile(false); 115 // Keep content of histos so that they are p << 128 // Keep content of histos so that they are plotted. 116 // The content will be reset at start of the << 129 // The content will be reset at start of the next run. 117 } 130 } 118 131 119 //....oooOO0OOooo........oooOO0OOooo........oo 132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 120 133 121 } // namespace B5 << 134 } 122 135