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 /// \file exoticphysics/monopole/src/RunAction.cc 27 /// \brief Implementation of the RunAction cla 27 /// \brief Implementation of the RunAction class 28 // 28 // 29 // << 29 // $Id: RunAction.cc 66994 2013-01-29 14:34:08Z 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 #include "DetectorConstruction.hh" 35 #include "DetectorConstruction.hh" 36 #include "PrimaryGeneratorAction.hh" 36 #include "PrimaryGeneratorAction.hh" 37 #include "Run.hh" << 38 #include "RunActionMessenger.hh" 37 #include "RunActionMessenger.hh" 39 38 40 #include "G4AnalysisManager.hh" << 39 #include "G4Run.hh" 41 #include "G4EmCalculator.hh" << 40 #include "G4RunManager.hh" 42 #include "G4ProductionCutsTable.hh" << 43 #include "G4SystemOfUnits.hh" << 44 #include "G4UnitsTable.hh" 41 #include "G4UnitsTable.hh" >> 42 #include "G4SystemOfUnits.hh" 45 #include "G4ios.hh" 43 #include "G4ios.hh" 46 #include "Randomize.hh" << 44 >> 45 #include "Histo.hh" >> 46 #include "G4EmCalculator.hh" 47 47 48 //....oooOO0OOooo........oooOO0OOooo........oo 48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 49 50 RunAction::RunAction(DetectorConstruction* det 50 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin) 51 : fDetector(det), fKinematic(kin) << 51 :fDetector(det), fKinematic(kin) 52 { << 52 { 53 fMessenger = new RunActionMessenger(this); << 53 fVerboseLevel = 1; 54 fBinLength = 5 * CLHEP::mm; << 54 fProjRange = fProjRange2 = fBinLength = fOffsetX = 0.; 55 G4AnalysisManager* analysisManager = G4Analy << 55 fHisto = new Histo(); 56 analysisManager->SetFileName("monopole.root" << 56 fHisto->SetFileName("monopole"); 57 analysisManager->SetVerboseLevel(1); << 57 // create commands for interactive definition of the detector 58 analysisManager->SetActivation(true); << 58 fRunActionMessenger = new RunActionMessenger(this); 59 } 59 } 60 60 61 //....oooOO0OOooo........oooOO0OOooo........oo 61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 62 62 63 RunAction::~RunAction() 63 RunAction::~RunAction() 64 { 64 { 65 if (isMaster && G4Threading::IsMultithreaded << 65 delete fHisto; 66 << 66 delete fRunActionMessenger; 67 delete fMessenger; << 68 } << 69 << 70 //....oooOO0OOooo........oooOO0OOooo........oo << 71 << 72 G4Run* RunAction::GenerateRun() << 73 { << 74 fRun = new Run(fDetector, fKinematic); << 75 return fRun; << 76 } 67 } 77 68 78 //....oooOO0OOooo........oooOO0OOooo........oo 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 70 80 void RunAction::BeginOfRunAction(const G4Run* 71 void RunAction::BeginOfRunAction(const G4Run* aRun) 81 { << 72 { 82 // Dump production cuts << 73 if(GetVerbose() > 0) { 83 G4ProductionCutsTable::GetProductionCutsTabl << 74 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; >> 75 } >> 76 >> 77 //initialize projected range, tallies, Ebeam, and book histograms >> 78 fProjRange = fProjRange2 = 0.; >> 79 >> 80 G4double length = fDetector->GetAbsorSizeX(); >> 81 if(0.0 == fBinLength) { fBinLength = 5 * mm; } >> 82 if(fBinLength > fDetector->GetMaxStepSize()) { >> 83 fBinLength = fDetector->GetMaxStepSize(); >> 84 } >> 85 fOffsetX = -0.5 * length; >> 86 >> 87 G4int nbBins = G4lrint(length / fBinLength); >> 88 84 89 85 G4cout << "### Run " << aRun->GetRunID() << << 90 // Create histograms 86 // histograms << 91 fHisto->Add1D("1","Edep (MeV/mm) along absorber (mm)", nbBins, 0, length, mm); 87 // << 92 fHisto->Add1D("2","DEDX (MeV/mm) of proton", 100, -3., 7.); 88 Book(); << 93 fHisto->Add1D("3","DEDX (MeV/mm) of monopole", 100, -3., 7.); >> 94 fHisto->Add1D("4","Range(mm) of proton", 100, -3., 7., mm); >> 95 fHisto->Add1D("5","Range(mm) of monopole", 100, -3., 7., mm); >> 96 >> 97 fHisto->Book(); 89 } 98 } 90 99 91 //....oooOO0OOooo........oooOO0OOooo........oo 100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 101 93 void RunAction::EndOfRunAction(const G4Run*) << 102 void RunAction::EndOfRunAction(const G4Run* aRun) 94 { << 103 { 95 // print Run summary << 104 G4int nEvents = aRun->GetNumberOfEvent(); 96 // << 105 if (nEvents == 0) { return; } 97 if (isMaster) fRun->EndOfRun(fBinLength); << 106 98 << 107 //run conditions 99 // save histograms << 108 // 100 G4AnalysisManager* analysisManager = G4Analy << 109 const G4Material* material = fDetector->GetAbsorMaterial(); 101 if (analysisManager->IsActive()) { << 110 G4double density = material->GetDensity(); 102 analysisManager->Write(); << 111 G4String matName = material->GetName(); 103 analysisManager->CloseFile(); << 112 const G4ParticleDefinition* part = 104 analysisManager->Clear(); << 113 fKinematic->GetParticleGun()->GetParticleDefinition(); >> 114 G4String particle = part->GetParticleName(); >> 115 G4double energy = fKinematic->GetParticleGun()->GetParticleEnergy(); >> 116 >> 117 if(GetVerbose() > 0){ >> 118 G4cout << "\n The run consists of " << nEvents << " "<< particle << " of " >> 119 << G4BestUnit(energy,"Energy") << " through " >> 120 << G4BestUnit(fDetector->GetAbsorSizeX(),"Length") << " of " >> 121 << matName << " (density: " >> 122 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 123 }; >> 124 >> 125 //compute projected range and straggling >> 126 >> 127 fProjRange /= nEvents; fProjRange2 /= nEvents; >> 128 G4double rms = fProjRange2 - fProjRange*fProjRange; >> 129 if (rms>0.) { rms = std::sqrt(rms); } >> 130 else { rms = 0.; } >> 131 >> 132 if(GetVerbose() > 0){ >> 133 G4cout.precision(5); >> 134 G4cout << "\n projected Range= " << G4BestUnit(fProjRange, "Length") >> 135 << " rms= " << G4BestUnit(rms, "Length") >> 136 << G4endl; >> 137 }; >> 138 >> 139 G4double ekin[100], dedxproton[100], dedxmp[100]; >> 140 G4EmCalculator calc; >> 141 calc.SetVerbose(0); >> 142 G4int i; >> 143 for(i = 0; i < 100; ++i) { >> 144 ekin[i] = std::pow(10., 0.1*G4double(i)) * keV; >> 145 dedxproton[i] = >> 146 calc.ComputeElectronicDEDX(ekin[i], "proton", matName); >> 147 dedxmp[i] = >> 148 calc.ComputeElectronicDEDX(ekin[i], "monopole", matName); 105 } 149 } 106 } << 107 150 108 //....oooOO0OOooo........oooOO0OOooo........oo << 151 if(GetVerbose() > 0){ >> 152 G4cout << "### Stopping Powers" << G4endl; >> 153 for(i=0; i<100; i++) { >> 154 G4cout << " E(MeV)= " << ekin[i] << " dedxp= " << dedxproton[i] >> 155 << " dedxmp= " << dedxmp[i] >> 156 << G4endl; >> 157 } >> 158 } >> 159 G4cout << "### End of stopping power table" << G4endl; 109 160 110 void RunAction::SetBinSize(G4double size) << 161 // normalize histogram 111 { << 162 G4double fac = (mm/MeV) / (nEvents * fBinLength); 112 fBinLength = size; << 163 fHisto->ScaleH1(0,fac); 113 if (fBinLength > fDetector->GetMaxStepSize() << 164 114 fBinLength = fDetector->GetMaxStepSize(); << 165 if(GetVerbose() > 0){ >> 166 G4cout << "Range table for " << matName << G4endl; >> 167 } >> 168 >> 169 for(i=0; i<100; ++i) { >> 170 G4double e = std::log10(ekin[i] / MeV) + 0.05; >> 171 fHisto->Fill(1, e, dedxproton[i]); >> 172 fHisto->Fill(2, e, dedxmp[i]); >> 173 fHisto->Fill(3, e, std::log10(calc.GetRange(ekin[i],"proton",matName)/mm)); >> 174 fHisto->Fill(4, e, std::log10(calc.GetRange(ekin[i],"monopole",matName)/mm)); 115 } 175 } >> 176 >> 177 // save and clean histo >> 178 fHisto->Save(); >> 179 >> 180 CLHEP::HepRandom::showEngineStatus(); 116 } 181 } 117 182 118 //....oooOO0OOooo........oooOO0OOooo........oo 183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 119 184 120 void RunAction::Book() << 185 void RunAction::FillHisto(G4int ih, G4double x, G4double weight) 121 { 186 { 122 G4AnalysisManager* analysisManager = G4Analy << 187 if(GetVerbose() > 1) { 123 analysisManager->SetFirstHistoId(1); << 188 G4cout << "FillHisto " << ih << " x=" << x << " weight= " << weight 124 << 189 << G4endl; 125 G4double length = fDetector->GetAbsorSizeX() << 190 } 126 G4int nbBins = G4lrint(length / fBinLength); << 191 fHisto->Fill(ih, x, weight); 127 << 128 // Create histograms << 129 analysisManager->CreateH1("h1", "Edep (MeV/m << 130 analysisManager->CreateH1("h2", "Total DEDX << 131 analysisManager->CreateH1("h3", "Total DEDX << 132 analysisManager->CreateH1("h4", "Range(mm) o << 133 analysisManager->CreateH1("h5", "Range(mm) o << 134 analysisManager->CreateH1("h6", "Restricted << 135 analysisManager->CreateH1("h7", "Restricted << 136 analysisManager->CreateH1("h8", "Delta-elect << 137 analysisManager->CreateH1("h9", "Delta-elect << 138 "mm"); << 139 analysisManager->OpenFile(); << 140 } 192 } 141 193 142 //....oooOO0OOooo........oooOO0OOooo........oo 194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 143 195