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 exoticphysics/monopole/src/RunAction << 26 // $Id: RunAction.cc,v 1.2 2008/06/11 14:34:19 vnivanch Exp $ 27 /// \brief Implementation of the RunAction cla << 27 // GEANT4 tag $Name: geant4-09-02-patch-04 $ 28 // << 28 // 29 // << 30 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 31 33 #include "RunAction.hh" 32 #include "RunAction.hh" 34 << 35 #include "DetectorConstruction.hh" 33 #include "DetectorConstruction.hh" >> 34 #include "QGSP.hh" 36 #include "PrimaryGeneratorAction.hh" 35 #include "PrimaryGeneratorAction.hh" 37 #include "Run.hh" << 38 #include "RunActionMessenger.hh" 36 #include "RunActionMessenger.hh" 39 37 40 #include "G4AnalysisManager.hh" << 38 #include "G4Run.hh" 41 #include "G4EmCalculator.hh" << 39 #include "G4RunManager.hh" 42 #include "G4ProductionCutsTable.hh" << 43 #include "G4SystemOfUnits.hh" << 44 #include "G4UnitsTable.hh" 40 #include "G4UnitsTable.hh" 45 #include "G4ios.hh" 41 #include "G4ios.hh" >> 42 46 #include "Randomize.hh" 43 #include "Randomize.hh" >> 44 #include "G4EmCalculator.hh" >> 45 >> 46 #ifdef G4ANALYSIS_USE >> 47 #include "AIDA/AIDA.h" >> 48 #endif 47 49 48 //....oooOO0OOooo........oooOO0OOooo........oo 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 51 50 RunAction::RunAction(DetectorConstruction* det << 52 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin):detector(det), kinematic(kin), af(0), tree(0) 51 : fDetector(det), fKinematic(kin) << 53 { 52 { << 54 verboseLevel = 0; 53 fMessenger = new RunActionMessenger(this); << 55 binLength = offsetX = 0.; 54 fBinLength = 5 * CLHEP::mm; << 56 histo[0] = 0; 55 G4AnalysisManager* analysisManager = G4Analy << 57 tree = 0; 56 analysisManager->SetFileName("monopole.root" << 58 af = 0; 57 analysisManager->SetVerboseLevel(1); << 59 #ifdef G4ANALYSIS_USE 58 analysisManager->SetActivation(true); << 60 // Creating the analysis factory >> 61 af = AIDA_createAnalysisFactory(); >> 62 ftype = "hbook"; >> 63 fname = "monopole"; >> 64 #endif >> 65 >> 66 // create commands for interactive definition of the detector >> 67 runActionMessenger = new RunActionMessenger(this); 59 } 68 } 60 69 61 //....oooOO0OOooo........oooOO0OOooo........oo << 62 70 >> 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 RunAction::~RunAction() 72 RunAction::~RunAction() 64 { 73 { 65 if (isMaster && G4Threading::IsMultithreaded << 74 #ifdef G4ANALYSIS_USE 66 << 75 delete af; 67 delete fMessenger; << 76 #endif 68 } 77 } 69 78 70 //....oooOO0OOooo........oooOO0OOooo........oo << 71 79 72 G4Run* RunAction::GenerateRun() << 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 81 void RunAction::bookHisto() 73 { 82 { 74 fRun = new Run(fDetector, fKinematic); << 83 G4double length = detector->GetAbsorSizeX(); 75 return fRun; << 84 if(!binLength) binLength = 5 * mm; 76 } << 85 if(binLength > detector->GetMaxStepSize()) binLength = detector->GetMaxStepSize(); >> 86 offsetX = 0.5 * length; >> 87 >> 88 #ifdef G4ANALYSIS_USE >> 89 if(GetVerbose() > 0) G4cout << "\n----> Histogram Tree opened" << G4endl; 77 90 78 //....oooOO0OOooo........oooOO0OOooo........oo << 91 G4int nbBins = (int)(0.5 + length / binLength); 79 92 80 void RunAction::BeginOfRunAction(const G4Run* << 93 // Create the tree factory 81 { << 94 AIDA::ITreeFactory* tf = af->createTreeFactory(); 82 // Dump production cuts << 95 83 G4ProductionCutsTable::GetProductionCutsTabl << 96 // Create a tree mapped to an hbook file. >> 97 G4bool readOnly = false; >> 98 G4bool createNew = true; >> 99 //G4String ftype = "hbook"; >> 100 //G4String fname = "monopole"; >> 101 G4String fName = fname; >> 102 fName += "."; >> 103 fName += ftype; >> 104 G4String option = "--noErrors uncompress"; >> 105 tree = tf->create(fName,ftype, readOnly, createNew, option); 84 106 85 G4cout << "### Run " << aRun->GetRunID() << << 107 // Create a histogram factory, whose histograms will be handled by the tree 86 // histograms << 108 AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree); 87 // << 109 88 Book(); << 110 // Create histograms >> 111 histo[0] = hf->createHistogram1D("1","Edep (MeV/mm) along absorber (mm)", nbBins, 0, length); >> 112 histo[1] = hf->createHistogram1D("2","DEDX (MeV/mm) of proton", 100, -3., 7.); >> 113 histo[2] = hf->createHistogram1D("3","DEDX (MeV/mm) of monopole", 100, -3., 7.); >> 114 histo[3] = hf->createHistogram1D("4","Range(mm) of proton", 100, -3., 7.); >> 115 histo[4] = hf->createHistogram1D("5","Range(mm) of monopole", 100, -3., 7.); >> 116 >> 117 delete tf; >> 118 delete hf; >> 119 #endif 89 } 120 } 90 121 91 //....oooOO0OOooo........oooOO0OOooo........oo << 92 122 93 void RunAction::EndOfRunAction(const G4Run*) << 123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 124 void RunAction::saveHisto() 94 { 125 { 95 // print Run summary << 126 #ifdef G4ANALYSIS_USE 96 // << 127 tree->commit(); // Writing the histograms to the file 97 if (isMaster) fRun->EndOfRun(fBinLength); << 128 tree->close(); // and closing the tree (and the file) >> 129 delete tree; >> 130 tree = 0; >> 131 if(GetVerbose() > 0) G4cout << "\n----> Histogram Tree saved" << G4endl; >> 132 #endif >> 133 } 98 134 99 // save histograms << 135 100 G4AnalysisManager* analysisManager = G4Analy << 136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 101 if (analysisManager->IsActive()) { << 137 void RunAction::SetBinSize(G4double size) 102 analysisManager->Write(); << 138 { 103 analysisManager->CloseFile(); << 139 binLength = size; 104 analysisManager->Clear(); << 105 } << 106 } 140 } 107 141 108 //....oooOO0OOooo........oooOO0OOooo........oo 142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 109 143 110 void RunAction::SetBinSize(G4double size) << 144 void RunAction::FillHisto(G4int ih, G4double x, G4double weight) 111 { 145 { 112 fBinLength = size; << 146 if(GetVerbose() > 1) { 113 if (fBinLength > fDetector->GetMaxStepSize() << 147 G4cout << "FillHisto " << ih << " x=" << x << " weight= " << weight 114 fBinLength = fDetector->GetMaxStepSize(); << 148 << G4endl; 115 } 149 } >> 150 #ifdef G4ANALYSIS_USE >> 151 if(histo[ih]) histo[ih]->fill(x, weight); >> 152 #endif 116 } 153 } 117 154 118 //....oooOO0OOooo........oooOO0OOooo........oo 155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 119 156 120 void RunAction::Book() << 157 void RunAction::BeginOfRunAction(const G4Run* aRun) 121 { << 158 { 122 G4AnalysisManager* analysisManager = G4Analy << 159 if(GetVerbose() > 0) G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 123 analysisManager->SetFirstHistoId(1); << 160 >> 161 // save Rndm status >> 162 G4RunManager::GetRunManager()->SetRandomNumberStore(true); >> 163 CLHEP::HepRandom::showEngineStatus(); >> 164 >> 165 //initialize projected range, tallies, Ebeam, and book histograms >> 166 projRange = projRange2 = 0.; >> 167 kinematic->ResetEbeamCumul(); >> 168 bookHisto(); >> 169 } 124 170 125 G4double length = fDetector->GetAbsorSizeX() << 171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 126 G4int nbBins = G4lrint(length / fBinLength); << 127 172 128 // Create histograms << 173 void RunAction::EndOfRunAction(const G4Run* aRun) 129 analysisManager->CreateH1("h1", "Edep (MeV/m << 174 { 130 analysisManager->CreateH1("h2", "Total DEDX << 175 G4int NbofEvents = aRun->GetNumberOfEvent(); 131 analysisManager->CreateH1("h3", "Total DEDX << 176 if (NbofEvents == 0) return; 132 analysisManager->CreateH1("h4", "Range(mm) o << 177 133 analysisManager->CreateH1("h5", "Range(mm) o << 178 //run conditions 134 analysisManager->CreateH1("h6", "Restricted << 179 // 135 analysisManager->CreateH1("h7", "Restricted << 180 G4Material* material = detector->GetAbsorMaterial(); 136 analysisManager->CreateH1("h8", "Delta-elect << 181 G4double density = material->GetDensity(); 137 analysisManager->CreateH1("h9", "Delta-elect << 182 138 "mm"); << 183 G4String particle = kinematic->GetParticleGun()->GetParticleDefinition()->GetParticleName(); 139 analysisManager->OpenFile(); << 184 G4double energy = kinematic->GetParticleGun()->GetParticleEnergy(); >> 185 >> 186 if(GetVerbose() > 0){ >> 187 G4cout << "\n The run consists of " << NbofEvents << " "<< particle << " of " >> 188 << G4BestUnit(energy,"Energy") << " through " >> 189 << G4BestUnit(detector->GetAbsorSizeX(),"Length") << " of " >> 190 << material->GetName() << " (density: " >> 191 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 192 }; >> 193 >> 194 //compute projected range and straggling >> 195 >> 196 projRange /= NbofEvents; projRange2 /= NbofEvents; >> 197 G4double rms = projRange2 - projRange*projRange; >> 198 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 199 >> 200 if(GetVerbose() > 0){ >> 201 G4cout.precision(5); >> 202 G4cout << "\n projected Range= " << G4BestUnit(projRange, "Length") >> 203 << " rms= " << G4BestUnit(rms, "Length") >> 204 << G4endl; >> 205 }; >> 206 >> 207 G4double ekin[100], dedxproton[100], dedxmp[100]; >> 208 G4EmCalculator calc; >> 209 calc.SetVerbose(0); >> 210 G4int i; >> 211 for(i = 0; i < 100; i++) { >> 212 ekin[i] = std::pow(10., 0.1*G4double(i)) * keV; >> 213 dedxproton[i] = calc.ComputeElectronicDEDX(ekin[i], "proton", material->GetName()); >> 214 dedxmp[i] = calc.ComputeElectronicDEDX(ekin[i], "monopole", material->GetName()); >> 215 } >> 216 >> 217 if(GetVerbose() > 1){ >> 218 G4cout << "### Stopping Powers" << G4endl; >> 219 for(i=0; i<100; i++) { >> 220 G4cout << " E(MeV)= " << ekin[i] << " dedxp= " << dedxproton[i] >> 221 << " dedxmp= " << dedxmp[i] >> 222 << G4endl; >> 223 } >> 224 }; >> 225 >> 226 #ifdef G4ANALYSIS_USE >> 227 // normalize histogram >> 228 G4double fac = (mm/MeV) / (NbofEvents * binLength); >> 229 histo[0]->scale(fac); >> 230 >> 231 G4String matName = detector->GetAbsorMaterial()->GetName(); >> 232 if(GetVerbose() > 0){ >> 233 G4cout << "Range table for " << matName << G4endl; >> 234 }; >> 235 >> 236 >> 237 for(i=0; i<100; i++) { >> 238 G4double e = std::log10(ekin[i] / MeV) + 0.05; >> 239 histo[1]->fill(e, dedxproton[i]); >> 240 histo[2]->fill(e, dedxmp[i]); >> 241 histo[3]->fill(e, std::log10(calc.GetRange(ekin[i], "proton", matName) / mm)); >> 242 histo[4]->fill(e, std::log10(calc.GetRange(ekin[i], "monopole", matName) / mm)); >> 243 } >> 244 >> 245 #endif >> 246 >> 247 // save and clean histo >> 248 saveHisto(); >> 249 >> 250 // show Rndm status >> 251 CLHEP::HepRandom::showEngineStatus(); 140 } 252 } 141 253 142 //....oooOO0OOooo........oooOO0OOooo........oo 254 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 143 255