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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/electromagnetic/TestEm7/src/RunAction.cc (Version 11.3.0) and /examples/extended/electromagnetic/TestEm7/src/RunAction.cc (Version 7.1.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 /// \file electromagnetic/TestEm7/src/RunActio <<  23 // $Id: RunAction.cc,v 1.14 2005/06/01 13:12:13 maire Exp $
 27 /// \brief Implementation of the RunAction cla <<  24 // GEANT4 tag $Name: geant4-07-01-patch-01 $
 28 //                                             <<  25 // 
 29 //                                             << 
 30 //....oooOO0OOooo........oooOO0OOooo........oo     26 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31 //....oooOO0OOooo........oooOO0OOooo........oo     27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32                                                    28 
 33 #include "RunAction.hh"                            29 #include "RunAction.hh"
 34                                                << 
 35 #include "DetectorConstruction.hh"                 30 #include "DetectorConstruction.hh"
 36 #include "PhysicsList.hh"                          31 #include "PhysicsList.hh"
 37 #include "PrimaryGeneratorAction.hh"           << 
 38 #include "StepMax.hh"                              32 #include "StepMax.hh"
                                                   >>  33 #include "PrimaryGeneratorAction.hh"
 39                                                    34 
 40 #include "G4Run.hh"                                35 #include "G4Run.hh"
 41 #include "G4RunManager.hh"                         36 #include "G4RunManager.hh"
 42 #include "G4SystemOfUnits.hh"                  << 
 43 #include "G4UnitsTable.hh"                         37 #include "G4UnitsTable.hh"
 44 #include "G4ios.hh"                                38 #include "G4ios.hh"
                                                   >>  39 
 45 #include "Randomize.hh"                            40 #include "Randomize.hh"
 46                                                    41 
                                                   >>  42 #ifdef G4ANALYSIS_USE
                                                   >>  43 #include "AIDA/AIDA.h"
                                                   >>  44 #endif
                                                   >>  45 
 47 //....oooOO0OOooo........oooOO0OOooo........oo     46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 48                                                    47 
 49 RunAction::RunAction(DetectorConstruction* det <<  48 RunAction::RunAction(DetectorConstruction* det, PhysicsList* phys,
 50   : G4UserRunAction(),                         <<  49                      PrimaryGeneratorAction* kin)
 51     fAnalysisManager(0),                       <<  50 :detector(det), physics(phys), kinematic(kin), af(0), tree(0)
 52     fDetector(det),                            <<  51 { 
 53     fPhysics(phys),                            <<  52   tallyEdep = new G4double[MaxTally];
 54     fKinematic(kin),                           <<  53   binLength = offsetX = 0.;
 55     fTallyEdep(new G4double[kMaxTally]),       <<  54   histo[0] = 0;
 56     fProjRange(0.),                            <<  55   
 57     fProjRange2(0.),                           <<  56 #ifdef G4ANALYSIS_USE
 58     fEdeptot(0.),                              <<  57  // Creating the analysis factory
 59     fEniel(0.),                                <<  58  af = AIDA_createAnalysisFactory();
 60     fNbPrimarySteps(0),                        <<  59  if(!af) {
 61     fRange(0)                                  <<  60    G4cout << "RunAction::RunAction() :" 
 62 {                                              <<  61           << " problem creating the AIDA analysis factory."
 63   // Book predefined histograms                <<  62           << G4endl;
 64   BookHisto();                                 <<  63  }     
                                                   >>  64 #endif  
 65 }                                                  65 }
 66                                                    66 
 67 //....oooOO0OOooo........oooOO0OOooo........oo     67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 68                                                    68 
 69 RunAction::~RunAction()                            69 RunAction::~RunAction()
 70 {                                                  70 {
 71   delete[] fTallyEdep;                         <<  71   delete tallyEdep;
                                                   >>  72   
                                                   >>  73 #ifdef G4ANALYSIS_USE
                                                   >>  74   delete af;  
                                                   >>  75 #endif      
 72 }                                                  76 }
 73                                                    77 
 74 //....oooOO0OOooo........oooOO0OOooo........oo     78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 75                                                    79 
 76 void RunAction::BeginOfRunAction(const G4Run*  <<  80 void RunAction::bookHisto()
 77 {                                                  81 {
 78   G4cout << "### Run " << aRun->GetRunID() <<  <<  82   G4double length  = detector->GetAbsorSizeX();
                                                   >>  83   G4double stepMax = physics->GetStepMaxProcess()->GetMaxStep();
                                                   >>  84   const G4int nbmin = 100;
                                                   >>  85   G4int nbBins = (int)(0.5 + length/stepMax);
                                                   >>  86   if (nbBins < nbmin) nbBins = nbmin;
                                                   >>  87   binLength = length/nbBins;
                                                   >>  88   offsetX   = 0.5*length;
                                                   >>  89  
                                                   >>  90 #ifdef G4ANALYSIS_USE
                                                   >>  91   if (!af) return;
                                                   >>  92 
                                                   >>  93   // Create a tree mapped to an hbook file.
                                                   >>  94   G4bool readOnly  = false;
                                                   >>  95   G4bool createNew = true;
                                                   >>  96   G4String options = "--noErrors uncompress";
                                                   >>  97   AIDA::ITreeFactory* tf  = af->createTreeFactory();  
                                                   >>  98   tree = tf->create("testem7.hbook","hbook", readOnly, createNew, options);
                                                   >>  99   //tree = tf->create("testem7.root", "root",readOnly, createNew, options);
                                                   >> 100   //tree = tf->create("testem7.XML" , "XML" ,readOnly, createNew, options);
                                                   >> 101   delete tf;
                                                   >> 102   if (!tree) {
                                                   >> 103     G4cout << "RunAction::bookHisto()" << G4endl;
                                                   >> 104     return;
                                                   >> 105   }
                                                   >> 106 
                                                   >> 107   // Create a histogram factory, whose histograms will be handled by the tree
                                                   >> 108   AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree);
                                                   >> 109   
                                                   >> 110   // Create histogram
                                                   >> 111   histo[0] = hf->createHistogram1D("1","Edep (MeV/mm) along absorber (mm)",
                                                   >> 112              nbBins, 0, length/mm);
                                                   >> 113        
                                                   >> 114   delete hf;       
                                                   >> 115   G4cout << "\n----> Histogram Tree opened" << G4endl;
                                                   >> 116 #endif
                                                   >> 117 }
 79                                                   118 
 80   if (!fAnalysisManager) {                     << 119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 81     BookHisto();                               << 
 82   }                                            << 
 83                                                   120 
 84   CLHEP::HepRandom::showEngineStatus();        << 121 void RunAction::cleanHisto()
                                                   >> 122 {
                                                   >> 123 #ifdef G4ANALYSIS_USE
                                                   >> 124   tree->commit();       // Writing the histograms to the file
                                                   >> 125   tree->close();        // and closing the tree (and the file)
                                                   >> 126   delete tree;
                                                   >> 127   tree = 0;
                                                   >> 128   
                                                   >> 129   G4cout << "\n----> Histogram Tree saved" << G4endl;  
                                                   >> 130 #endif
                                                   >> 131 }
 85                                                   132 
 86   // initialize projected range, tallies, Ebea << 133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 87   //                                           << 
 88   fNbPrimarySteps = 0;                         << 
 89   fRange = 0;                                  << 
 90   fProjRange = fProjRange2 = 0.;               << 
 91   fEdeptot = fEniel = 0.;                      << 
 92   for (G4int j = 0; j < kMaxTally; ++j) {      << 
 93     fTallyEdep[j] = 0.;                        << 
 94   }                                            << 
 95   fKinematic->ResetEbeamCumul();               << 
 96                                                   134 
 97   if (fAnalysisManager->IsActive()) {          << 135 void RunAction::FillHisto(G4int ih, G4double x, G4double weight)
 98     fAnalysisManager->OpenFile();              << 136 {
                                                   >> 137 #ifdef G4ANALYSIS_USE
                                                   >> 138   if(histo[ih]) histo[ih]->fill(x, weight);
                                                   >> 139 #endif
                                                   >> 140 }
 99                                                   141 
100     // histogram "1" is defined by the length  << 142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101     // zoomed histograms are defined by UI com << 143 
102     G4double length = fDetector->GetAbsorSizeX << 144 void RunAction::BeginOfRunAction(const G4Run* aRun)
103     G4double stepMax = fPhysics->GetStepMaxPro << 145 {  
104     G4int nbBins = 100;                        << 146   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
105     if (stepMax < DBL_MAX) {                   << 147   
106       G4int nb = (G4int)(0.5 + length / stepMa << 148   // save Rndm status
107       nbBins = std::min(std::max(nbBins, nb),  << 149   G4RunManager::GetRunManager()->SetRandomNumberStore(true);
108     }                                          << 150   HepRandom::showEngineStatus();
109     fAnalysisManager->SetH1(1, nbBins, 0., len << 151      
110   }                                            << 152   //initialize projected range, tallies, Ebeam, and book histograms
                                                   >> 153   //
                                                   >> 154   projRange = projRange2 = 0.;
                                                   >> 155   for (G4int j=0; j<MaxTally; j++) tallyEdep[j] = 0.;
                                                   >> 156   kinematic->ResetEbeamCumul();
                                                   >> 157   bookHisto();      
111 }                                                 158 }
112                                                   159 
113 //....oooOO0OOooo........oooOO0OOooo........oo    160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114                                                   161 
115 void RunAction::EndOfRunAction(const G4Run* aR    162 void RunAction::EndOfRunAction(const G4Run* aRun)
116 {                                                 163 {
117   G4int nbofEvents = aRun->GetNumberOfEvent(); << 164   G4int NbofEvents = aRun->GetNumberOfEvent();
118   if (nbofEvents == 0) return;                 << 165   if (NbofEvents == 0) return;
119                                                   166 
120   // run conditions                            << 167   //run conditions
121   //                                           << 168   //  
122   const G4Material* material = fDetector->GetA << 169   G4Material* material = detector->GetAbsorMaterial();
123   G4double density = material->GetDensity();      170   G4double density = material->GetDensity();
124                                                << 171    
125   G4String particle = fKinematic->GetParticleG << 172   G4String particle = kinematic->GetParticleGun()->GetParticleDefinition()
126   G4double energy = fKinematic->GetParticleGun << 173                       ->GetParticleName();    
127   G4cout << "\n The run consists of " << nbofE << 174   G4double energy = kinematic->GetParticleGun()->GetParticleEnergy();
128          << G4BestUnit(energy, "Energy") << "  << 175   G4cout << "\n The run consists of " << NbofEvents << " "<< particle << " of "
129          << G4BestUnit(fDetector->GetAbsorSize << 176          << G4BestUnit(energy,"Energy") << " through " 
130          << " (density: " << G4BestUnit(densit << 177    << G4BestUnit(detector->GetAbsorSizeX(),"Length") << " of "
131                                                << 178    << material->GetName() << " (density: " 
132   // compute projected range and straggling    << 179    << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
                                                   >> 180    
                                                   >> 181   //compute projected range and straggling
                                                   >> 182   //
                                                   >> 183   projRange /= NbofEvents; projRange2 /= NbofEvents;
                                                   >> 184   G4double rms = projRange2 - projRange*projRange;        
                                                   >> 185   if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
                                                   >> 186 
                                                   >> 187   G4cout.precision(5);       
                                                   >> 188   G4cout << "\n projected Range= "<< G4BestUnit(projRange,"Length")
                                                   >> 189          << "   rms= "            << G4BestUnit( rms,"Length")
                                                   >> 190          << G4endl;
                                                   >> 191      
                                                   >> 192   //print dose in tallies
133   //                                              193   //
134   if (fRange > 0) {                            << 194   G4int tallyNumber = detector->GetTallyNumber();
135     fProjRange /= fRange;                      << 
136     fProjRange2 /= fRange;                     << 
137   }                                            << 
138   G4double rms = fProjRange2 - fProjRange * fP << 
139   if (rms > 0.)                                << 
140     rms = std::sqrt(rms);                      << 
141   else                                         << 
142     rms = 0.;                                  << 
143                                                << 
144   G4double nstep = G4double(fNbPrimarySteps) / << 
145                                                << 
146   G4cout.precision(6);                         << 
147   G4cout << "\n Projected Range= " << G4BestUn << 
148          << "   rms= " << G4BestUnit(rms, "Len << 
149   G4cout << " Mean number of primary steps = " << 
150                                                << 
151   // compute energy deposition and niel        << 
152   //                                           << 
153   fEdeptot /= nbofEvents;                      << 
154   G4cout << " Total energy deposit= " << G4Bes << 
155   fEniel /= nbofEvents;                        << 
156   G4cout << " niel energy deposit = " << G4Bes << 
157                                                << 
158   // print dose in tallies                     << 
159   //                                           << 
160   G4int tallyNumber = fDetector->GetTallyNumbe << 
161   if (tallyNumber > 0) {                          195   if (tallyNumber > 0) {
162     G4double Ebeam = fKinematic->GetEbeamCumul << 196     G4double tallyMass = detector->GetTallyMass();
                                                   >> 197     G4double Ebeam = kinematic->GetEbeamCumul();
163     G4cout << "\n-----------------------------    198     G4cout << "\n---------------------------------------------------------\n";
164     G4cout << " Cumulated Doses : \tEdep          199     G4cout << " Cumulated Doses : \tEdep      \tEdep/Ebeam \tDose" << G4endl;
165     for (G4int j = 0; j < tallyNumber; ++j) {  << 200     for (G4int j=0; j<tallyNumber; j++) {
166       G4double Edep = fTallyEdep[j], ratio = 1 << 201       G4double Edep = tallyEdep[j], ratio = 100*Edep/Ebeam;
167       G4double tallyMass = fDetector->GetTally << 202       G4double Dose = Edep/tallyMass;
168       G4double Dose = Edep / tallyMass;        << 203       G4cout << "tally " << j << ": \t \t"
169       G4cout << " tally " << j << ": \t \t" << << 204              << G4BestUnit(Edep,"Energy") << "\t"
170              << " % \t" << G4BestUnit(Dose, "D << 205        << ratio << " % \t"
                                                   >> 206        << G4BestUnit(Dose,"Dose")   << G4endl;
171     }                                             207     }
172     G4cout << "\n----------------------------- << 208     G4cout << "\n---------------------------------------------------------\n"; 
173     G4cout << G4endl;                          << 
174   }                                            << 
175                                                << 
176   if (fAnalysisManager->IsActive()) {          << 
177     // normalize histograms                    << 
178     //                                         << 
179     for (G4int j = 1; j < 3; ++j) {            << 
180       G4double binWidth = fAnalysisManager->Ge << 
181       G4double fac = (mm / MeV) / (nbofEvents  << 
182       fAnalysisManager->ScaleH1(j, fac);       << 
183     }                                          << 
184     fAnalysisManager->ScaleH1(3, 1. / nbofEven << 
185                                                << 
186     // save histograms                         << 
187     fAnalysisManager->Write();                 << 
188     fAnalysisManager->CloseFile();             << 
189   }                                               209   }
190                                                   210 
                                                   >> 211 #ifdef G4ANALYSIS_USE
                                                   >> 212   // normalize histogram
                                                   >> 213   G4double fac = (mm/MeV)/(NbofEvents *  binLength);
                                                   >> 214   histo[0]->scale(fac);
                                                   >> 215 #endif
                                                   >> 216   
                                                   >> 217  
                                                   >> 218   // save and clean histo
                                                   >> 219   cleanHisto();
                                                   >> 220  
191   // show Rndm status                             221   // show Rndm status
192   //                                           << 222   HepRandom::showEngineStatus();
193   CLHEP::HepRandom::showEngineStatus();        << 
194 }                                              << 
195                                                << 
196 //....oooOO0OOooo........oooOO0OOooo........oo << 
197                                                << 
198 void RunAction::BookHisto()                    << 
199 {                                              << 
200   // Create or get analysis manager            << 
201   // The choice of analysis technology is done << 
202   // in HistoManager.hh                        << 
203   fAnalysisManager = G4AnalysisManager::Instan << 
204   fAnalysisManager->SetDefaultFileType("root") << 
205   fAnalysisManager->SetFileName("testem7");    << 
206   fAnalysisManager->SetVerboseLevel(1);        << 
207   fAnalysisManager->SetActivation(true);  // e << 
208                                                << 
209   // Define histograms start values            << 
210   const G4int kMaxHisto = 4;                   << 
211   const G4String id[] = {"h0", "h1", "h2", "h3 << 
212   const G4String title[] = {                   << 
213     "dummy",  // 0                             << 
214     "Edep (MeV/mm) along absorber ",  // 1     << 
215     "Edep (MeV/mm) along absorber zoomed",  // << 
216     "projectile range"  // 3                   << 
217   };                                           << 
218                                                << 
219   // Default values (to be reset via /analysis << 
220   G4int nbins = 100;                           << 
221   G4double vmin = 0.;                          << 
222   G4double vmax = 100.;                        << 
223                                                << 
224   // Create all histograms as inactivated      << 
225   // as we have not yet set nbins, vmin, vmax  << 
226   for (G4int k = 0; k < kMaxHisto; ++k) {      << 
227     G4int ih = fAnalysisManager->CreateH1(id[k << 
228     G4bool activ = false;                      << 
229     if (k == 1) activ = true;                  << 
230     fAnalysisManager->SetH1Activation(ih, acti << 
231   }                                            << 
232 }                                                 223 }
233                                                   224 
234 //....oooOO0OOooo........oooOO0OOooo........oo    225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
235                                                   226