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