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 /// \file electromagnetic/TestEm2/src/RunActio 26 /// \file electromagnetic/TestEm2/src/RunAction.cc 27 /// \brief Implementation of the RunAction cla 27 /// \brief Implementation of the RunAction class 28 // 28 // 29 // << 29 // $Id: RunAction.cc 76259 2013-11-08 11:37:28Z gcosmo $ >> 30 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 33 #include "RunAction.hh" 34 #include "RunAction.hh" 34 35 35 #include "DetectorConstruction.hh" 36 #include "DetectorConstruction.hh" 36 #include "EmAcceptance.hh" << 37 #include "PrimaryGeneratorAction.hh" 37 #include "PrimaryGeneratorAction.hh" 38 #include "Run.hh" << 39 #include "RunActionMessenger.hh" 38 #include "RunActionMessenger.hh" >> 39 #include "Run.hh" >> 40 #include "EmAcceptance.hh" 40 41 41 #include "G4Run.hh" 42 #include "G4Run.hh" 42 #include "G4RunManager.hh" 43 #include "G4RunManager.hh" >> 44 #include "G4UnitsTable.hh" >> 45 #include "G4Threading.hh" >> 46 43 #include "G4SystemOfUnits.hh" 47 #include "G4SystemOfUnits.hh" >> 48 #include <iomanip> >> 49 44 #include "Randomize.hh" 50 #include "Randomize.hh" 45 51 46 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 53 48 RunAction::RunAction(DetectorConstruction* det << 54 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin) >> 55 :G4UserRunAction(), >> 56 fDet(det),fKin(kin),fRunMessenger(0), fAnalysisManager(0),fRun(0), >> 57 fVerbose(0), fEdeptrue(1.), fRmstrue(1.), fLimittrue(DBL_MAX) 49 { 58 { 50 fRunMessenger = new RunActionMessenger(this) 59 fRunMessenger = new RunActionMessenger(this); 51 << 52 // Create analysis manager << 53 // The choice of analysis technology is done << 54 fAnalysisManager = G4AnalysisManager::Instan << 55 fAnalysisManager->SetDefaultFileType("root") << 56 << 57 // Set the default file name "testem2" << 58 // which can be then redefine in a macro via << 59 fAnalysisManager->SetFileName("testem2"); << 60 } 60 } 61 61 62 //....oooOO0OOooo........oooOO0OOooo........oo 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 63 64 RunAction::~RunAction() 64 RunAction::~RunAction() 65 { 65 { 66 delete fRunMessenger; 66 delete fRunMessenger; 67 } 67 } 68 68 69 //....oooOO0OOooo........oooOO0OOooo........oo 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 70 71 void RunAction::BookHisto() 71 void RunAction::BookHisto() 72 { 72 { 73 // Get analysis manager << 73 // Create analysis manager 74 fAnalysisManager = G4AnalysisManager::Instan << 74 // The choice of analysis technology is done via selection of a namespace >> 75 // 75 76 >> 77 fAnalysisManager = G4AnalysisManager::Instance(); >> 78 76 // Open an output file 79 // Open an output file 77 fAnalysisManager->OpenFile(); << 80 // >> 81 fHistoName[0] = "testem2"; >> 82 >> 83 fAnalysisManager->OpenFile(fHistoName[0]); >> 84 78 fAnalysisManager->SetVerboseLevel(1); 85 fAnalysisManager->SetVerboseLevel(1); >> 86 G4String extension = fAnalysisManager->GetFileType(); >> 87 fHistoName[1] = fHistoName[0] + "." + extension; 79 88 80 // Creating histograms 89 // Creating histograms 81 // 90 // 82 G4double Ekin = fKin->GetParticleGun()->GetP 91 G4double Ekin = fKin->GetParticleGun()->GetParticleEnergy(); 83 G4int nLbin = fDet->GetnLtot(); << 92 G4int nLbin = fDet->GetnLtot(); 84 G4int nRbin = fDet->GetnRtot(); << 93 G4int nRbin = fDet->GetnRtot(); 85 G4double dLradl = fDet->GetdLradl(); 94 G4double dLradl = fDet->GetdLradl(); 86 G4double dRradl = fDet->GetdRradl(); 95 G4double dRradl = fDet->GetdRradl(); >> 96 >> 97 fAnalysisManager->SetFirstHistoId(1); >> 98 fAnalysisManager->CreateH1( "h1","total energy deposit(percent of Einc)", >> 99 110,0.,110.); 87 100 88 fAnalysisManager->SetFirstHistoId(1); << 101 fAnalysisManager->CreateH1( "h2","total charged tracklength (radl)", 89 fAnalysisManager->CreateH1("h1", "total ener << 102 110,0.,110.*Ekin/GeV); 90 << 91 fAnalysisManager->CreateH1("h2", "total char << 92 << 93 fAnalysisManager->CreateH1("h3", "total neut << 94 << 95 fAnalysisManager->CreateH1("h4", "longit ene << 96 103 97 fAnalysisManager->CreateP1("p4", "longit ene << 104 fAnalysisManager->CreateH1( "h3","total neutral tracklength (radl)", 98 0., 1000.); << 105 110,0.,1100.*Ekin/GeV); 99 106 100 fAnalysisManager->CreateH1("h5", "rms on lon << 107 fAnalysisManager->CreateH1( "h4","longit energy profile (% of E inc)", >> 108 nLbin,0.,nLbin*dLradl); >> 109 >> 110 fAnalysisManager->CreateH1( "h5","rms on longit Edep (% of E inc)", >> 111 nLbin,0.,nLbin*dLradl); 101 112 102 G4double Zmin = 0.5 * dLradl, Zmax = Zmin + << 113 G4double Zmin=0.5*dLradl, Zmax=Zmin+nLbin*dLradl; 103 fAnalysisManager->CreateH1("h6", "cumul long << 114 fAnalysisManager->CreateH1( "h6","cumul longit energy dep (% of E inc)", >> 115 nLbin,Zmin,Zmax); >> 116 >> 117 fAnalysisManager->CreateH1( "h7","rms on cumul longit Edep (% of E inc)", >> 118 nLbin,Zmin,Zmax); 104 119 105 fAnalysisManager->CreateH1("h7", "rms on cum << 120 fAnalysisManager->CreateH1( "h8","radial energy profile (% of E inc)", >> 121 nRbin,0.,nRbin*dRradl); >> 122 >> 123 fAnalysisManager->CreateH1( "h9","rms on radial Edep (% of E inc)", >> 124 nRbin,0.,nRbin*dRradl); 106 125 107 fAnalysisManager->CreateH1("h8", "radial ene << 126 G4double Rmin=0.5*dRradl, Rmax=Rmin+nRbin*dRradl; >> 127 fAnalysisManager->CreateH1("h10","cumul radial energy dep (% of E inc)", >> 128 nRbin,Rmin,Rmax); 108 129 109 fAnalysisManager->CreateP1("p8", "radial ene << 130 fAnalysisManager->CreateH1("h11","rms on cumul radial Edep (% of E inc)", 110 0., 1000.); << 131 nRbin,Rmin,Rmax); 111 << 132 112 fAnalysisManager->CreateH1("h9", "rms on rad << 133 G4cout << "\n----> Histogram file is opened in " << fHistoName[1] << G4endl; >> 134 } 113 135 114 G4double Rmin = 0.5 * dRradl, Rmax = Rmin + << 136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 115 fAnalysisManager->CreateH1("h10", "cumul rad << 116 137 117 fAnalysisManager->CreateH1("h11", "rms on cu << 138 void RunAction::SaveHisto() >> 139 { >> 140 fAnalysisManager->Write(); >> 141 fAnalysisManager->CloseFile(); 118 142 119 G4String fileName = fAnalysisManager->GetFil << 143 delete fAnalysisManager; 120 G4String extension = fAnalysisManager->GetFi << 121 G4String fullFileName = fileName + "." + ext << 122 G4cout << "\n----> Histogram file is opened << 123 } 144 } 124 145 125 //....oooOO0OOooo........oooOO0OOooo........oo 146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 126 147 127 G4Run* RunAction::GenerateRun() 148 G4Run* RunAction::GenerateRun() 128 { << 149 { 129 fRun = new Run(fDet, fKin); << 150 fRun = new Run(fDet, fKin); 130 fRun->SetVerbose(fVerbose); 151 fRun->SetVerbose(fVerbose); 131 return fRun; 152 return fRun; 132 } 153 } 133 154 134 //....oooOO0OOooo........oooOO0OOooo........oo 155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 135 156 136 void RunAction::BeginOfRunAction(const G4Run*) 157 void RunAction::BeginOfRunAction(const G4Run*) 137 { 158 { >> 159 //fRun->Reset(); >> 160 // not needed as a new Run object is created with each run >> 161 138 // show Rndm status 162 // show Rndm status 139 if (isMaster) G4Random::showEngineStatus(); << 163 if (isMaster) { >> 164 G4Random::showEngineStatus(); >> 165 } 140 166 141 // histograms << 167 //histograms 142 // 168 // 143 BookHisto(); 169 BookHisto(); 144 } 170 } 145 171 146 //....oooOO0OOooo........oooOO0OOooo........oo 172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 147 173 148 void RunAction::EndOfRunAction(const G4Run*) 174 void RunAction::EndOfRunAction(const G4Run*) 149 { 175 { 150 // compute and print statistic << 176 //compute and print statistic 151 // 177 // 152 if (isMaster) fRun->EndOfRun(fEdeptrue, fRms << 178 if (isMaster) fRun->ComputeStatistics(fEdeptrue, fRmstrue, fLimittrue); 153 179 154 // show Rndm status 180 // show Rndm status 155 if (isMaster) G4Random::showEngineStatus(); << 181 G4Random::showEngineStatus(); 156 182 157 // save histos and close analysis 183 // save histos and close analysis 158 fAnalysisManager->Write(); << 184 SaveHisto(); 159 fAnalysisManager->CloseFile(); << 160 fAnalysisManager->Clear(); << 161 } 185 } 162 186 163 //....oooOO0OOooo........oooOO0OOooo........oo 187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 164 188 165 void RunAction::SetEdepAndRMS(G4ThreeVector Va 189 void RunAction::SetEdepAndRMS(G4ThreeVector Value) 166 { 190 { 167 fEdeptrue = Value(0); 191 fEdeptrue = Value(0); 168 fRmstrue = Value(1); << 192 fRmstrue = Value(1); 169 fLimittrue = Value(2); << 193 fLimittrue= Value(2); 170 } 194 } 171 //....oooOO0OOooo........oooOO0OOooo........oo 195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 172 196 173 void RunAction::SetVerbose(G4int val) << 197 void RunAction::SetVerbose(G4int val) 174 { 198 { 175 fVerbose = val; 199 fVerbose = val; 176 if (fRun) fRun->SetVerbose(val); << 200 if ( fRun ) fRun->SetVerbose(val); 177 } 201 } 178 << 202 179 //....oooOO0OOooo........oooOO0OOooo........oo 203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 180 204