Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RMC01AnalysisManager Class Reference

#include <RMC01AnalysisManager.hh>

Public Member Functions

 ~RMC01AnalysisManager ()
 
void BeginOfRun (const G4Run *)
 
void EndOfRun (const G4Run *)
 
void BeginOfEvent (const G4Event *)
 
void EndOfEvent (const G4Event *)
 
void SetPrimaryExpSpectrumForAdjointSim (const G4String &particle_name, G4double fluence, G4double E0, G4double Emin, G4double Emax)
 
void SetPrimaryPowerLawSpectrumForAdjointSim (const G4String &particle_name, G4double fluence, G4double alpha, G4double Emin, G4double Emax)
 
void SetPrecision (G4double precision)
 
void Book ()
 
void Save (G4double scaling_factor)
 

Static Public Member Functions

static RMC01AnalysisManagerGetInstance ()
 

Detailed Description

Definition at line 77 of file RMC01AnalysisManager.hh.

Constructor & Destructor Documentation

RMC01AnalysisManager::~RMC01AnalysisManager ( )

Definition at line 102 of file RMC01AnalysisManager.cc.

103 {;
104 }

Member Function Documentation

void RMC01AnalysisManager::BeginOfEvent ( const G4Event )

Definition at line 176 of file RMC01AnalysisManager.cc.

177 { ;
178 }

Here is the caller graph for this function:

void RMC01AnalysisManager::BeginOfRun ( const G4Run aRun)

Definition at line 116 of file RMC01AnalysisManager.cc.

117 {
118 
119  fAccumulated_edep =0.;
120  fAccumulated_edep2 =0.;
121  fNentry = 0.0;
122  fRelative_error=1.;
123  fMean_edep=0.;
124  fError_mean_edep=0.;
125  fAdjoint_sim_mode =G4AdjointSimManager::GetInstance()->GetAdjointSimMode();
126 
127  if (fAdjoint_sim_mode){
128  fNb_evt_per_adj_evt=aRun->GetNumberOfEventToBeProcessed()/
130  fConvergenceFileOutput.open("ConvergenceOfAdjointSimulationResults.txt",
131  std::ios::out);
132  fConvergenceFileOutput<<
133  "Normalised Edep[MeV]\terror[MeV]\tcomputing_time[s]"<<std::endl;
134  }
135  else {
136  fConvergenceFileOutput.open("ConvergenceOfForwardSimulationResults.txt",
137  std::ios::out);
138  fConvergenceFileOutput<<
139  "Edep per event [MeV]\terror[MeV]\tcomputing_time[s]"
140  <<std::endl;
141  }
142  fConvergenceFileOutput.setf(std::ios::scientific);
143  fConvergenceFileOutput.precision(6);
144 
145  fTimer->Start();
146  fElapsed_time=0.;
147 
148  Book();
149 }
static G4AdjointSimManager * GetInstance()
G4int GetNumberOfEventToBeProcessed() const
Definition: G4Run.hh:83
void Start()

Here is the call graph for this function:

Here is the caller graph for this function:

void RMC01AnalysisManager::Book ( )

Definition at line 601 of file RMC01AnalysisManager.cc.

602 {
603  //----------------------
604  //Creation of histograms
605  //----------------------
606 
607  //Energy binning of the histograms : 60 log bins over [1keV-1GeV]
608 
609  G4double emin=1.*keV;
610  G4double emax=1.*GeV;
611 
612  //file_name
613  fFileName[0]="forward_sim";
614  if (fAdjoint_sim_mode) fFileName[0]="adjoint_sim";
615 
616  //Histo manager
617  G4AnalysisManager* theHistoManager = G4AnalysisManager::Instance();
618  G4String extension = theHistoManager->GetFileType();
619  fFileName[1] = fFileName[0] + "." + extension;
620  theHistoManager->SetFirstHistoId(1);
621 
622  G4bool fileOpen = theHistoManager->OpenFile(fFileName[0]);
623  if (!fileOpen) {
624  G4cout << "\n---> RMC01AnalysisManager::Book(): cannot open "
625  << fFileName[1]
626  << G4endl;
627  return;
628  }
629 
630  // Create directories
631  theHistoManager->SetHistoDirectoryName("histo");
632 
633  //Histograms for :
634  // 1)the forward simulation results
635  // 2)the Reverse MC simulation results normalised to a user spectrum
636  //------------------------------------------------------------------------
637 
638  G4int idHisto =
639  theHistoManager->CreateH1(G4String("Edep_vs_prim_ekin"),
640  G4String("edep vs e- primary energy"),60,emin,emax,
641  "none","none",G4String("log"));
642  fEdep_vs_prim_ekin = theHistoManager->GetH1(idHisto);
643 
644  idHisto = theHistoManager->CreateH1(G4String("elecron_current"),
645  G4String("electron"),60,emin,emax,
646  "none","none",G4String("log"));
647 
648  fElectron_current = theHistoManager->GetH1(idHisto);
649 
650  idHisto= theHistoManager->CreateH1(G4String("proton_current"),
651  G4String("proton"),60,emin,emax,
652  "none","none",G4String("log"));
653  fProton_current=theHistoManager->GetH1(idHisto);
654 
655  idHisto= theHistoManager->CreateH1(G4String("gamma_current"),
656  G4String("gamma"),60,emin,emax,
657  "none","none",G4String("log"));
658  fGamma_current=theHistoManager->GetH1(idHisto);
659 
660  //Response matrices for the adjoint simulation only
661  //-----------------------------------------------
662  if (fAdjoint_sim_mode){
663  //Response matrices for external isotropic e- source
664  //--------------------------------------------------
665 
666  idHisto =
667  theHistoManager->CreateH1(G4String("Edep_rmatrix_vs_electron_prim_energy"),
668  G4String("electron RM vs e- primary energy"),60,emin,emax,
669  "none","none",G4String("log"));
670  fEdep_rmatrix_vs_electron_prim_energy = theHistoManager->GetH1(idHisto);
671 
672  idHisto =
673  theHistoManager->
674  CreateH2(G4String("Electron_current_rmatrix_vs_electron_prim_energy"),
675  G4String("electron current RM vs e- primary energy"),
676  60,emin,emax,60,emin,emax,
677  "none","none","none","none",G4String("log"),G4String("log"));
678 
679  fElectron_current_rmatrix_vs_electron_prim_energy =
680  theHistoManager->GetH2(idHisto);
681 
682  idHisto =
683  theHistoManager->
684  CreateH2(G4String("Gamma_current_rmatrix_vs_electron_prim_energy"),
685  G4String("gamma current RM vs e- primary energy"),
686  60,emin,emax,60,emin,emax,
687  "none","none","none","none",G4String("log"),G4String("log"));
688 
689  fGamma_current_rmatrix_vs_electron_prim_energy =
690  theHistoManager->GetH2(idHisto);
691 
692  //Response matrices for external isotropic gamma source
693 
694  idHisto =
695  theHistoManager->CreateH1(G4String("Edep_rmatrix_vs_gamma_prim_energy"),
696  G4String("electron RM vs gamma primary energy"),60,emin,emax,
697  "none","none",G4String("log"));
698  fEdep_rmatrix_vs_gamma_prim_energy = theHistoManager->GetH1(idHisto);
699 
700  idHisto =
701  theHistoManager->
702  CreateH2(G4String("Electron_current_rmatrix_vs_gamma_prim_energy"),
703  G4String("electron current RM vs gamma primary energy"),
704  60,emin,emax,60,emin,emax,
705  "none","none","none","none",G4String("log"),G4String("log"));
706 
707  fElectron_current_rmatrix_vs_gamma_prim_energy =
708  theHistoManager->GetH2(idHisto);
709 
710  idHisto =
711  theHistoManager->
712  CreateH2(G4String("Gamma_current_rmatrix_vs_gamma_prim_energy"),
713  G4String("gamma current RM vs gamma primary energy"),
714  60,emin,emax,60,emin,emax,
715  "none","none","none","none",G4String("log"),G4String("log"));
716 
717  fGamma_current_rmatrix_vs_gamma_prim_energy =
718  theHistoManager->GetH2(idHisto);
719 
720  //Response matrices for external isotropic proton source
721  idHisto =
722  theHistoManager->CreateH1(G4String("Edep_rmatrix_vs_proton_prim_energy"),
723  G4String("electron RM vs proton primary energy"),60,emin,emax,
724  "none","none",G4String("log"));
725  fEdep_rmatrix_vs_proton_prim_energy = theHistoManager->GetH1(idHisto);
726 
727  idHisto =
728  theHistoManager->
729  CreateH2(G4String("Electron_current_rmatrix_vs_proton_prim_energy"),
730  G4String("electron current RM vs proton primary energy"),
731  60,emin,emax,60,emin,emax,
732  "none","none","none","none",G4String("log"),G4String("log"));
733 
734  fElectron_current_rmatrix_vs_proton_prim_energy =
735  theHistoManager->GetH2(idHisto);
736 
737  idHisto =
738  theHistoManager->
739  CreateH2(G4String("Gamma_current_rmatrix_vs_proton_prim_energy"),
740  G4String("gamma current RM vs proton primary energy"),
741  60,emin,emax,60,emin,emax,
742  "none","none","none","none",G4String("log"),G4String("log"));
743 
744  fGamma_current_rmatrix_vs_proton_prim_energy =
745  theHistoManager->GetH2(idHisto);
746 
747  idHisto =
748  theHistoManager->
749  CreateH2(G4String("Proton_current_rmatrix_vs_proton_prim_energy"),
750  G4String("proton current RM vs proton primary energy"),
751  60,emin,emax,60,emin,emax,
752  "none","none","none","none",G4String("log"),G4String("log"));
753 
754  fProton_current_rmatrix_vs_proton_prim_energy =
755  theHistoManager->GetH2(idHisto);
756  }
757  fFactoryOn = true;
758  G4cout << "\n----> Histogram Tree is opened in " << fFileName[1] << G4endl;
759 }
G4bool SetHistoDirectoryName(const G4String &dirName)
G4bool SetFirstHistoId(G4int firstId)
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
int G4int
Definition: G4Types.hh:78
G4bool OpenFile(const G4String &fileName="")
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4String GetFileType() const
static const G4double emax
tools::histo::h2d * GetH2(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
static constexpr double GeV
Definition: G4SIunits.hh:217
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
tools::histo::h1d * GetH1(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
static constexpr double keV
Definition: G4SIunits.hh:216

Here is the call graph for this function:

Here is the caller graph for this function:

void RMC01AnalysisManager::EndOfEvent ( const G4Event anEvent)

Definition at line 182 of file RMC01AnalysisManager.cc.

183 {
184  if (fAdjoint_sim_mode) EndOfEventForAdjointSimulation(anEvent);
185  else EndOfEventForForwardSimulation(anEvent);
186 
187  //Test convergence. The error is already computed
188  //--------------------------------------
189  G4int nb_event=anEvent->GetEventID()+1;
190  //G4double factor=1.;
191  if (fAdjoint_sim_mode) {
192  G4double n_adj_evt= nb_event/fNb_evt_per_adj_evt;
193  // nb_event/fNb_evt_per_adj_evt;
194  if (n_adj_evt*fNb_evt_per_adj_evt == nb_event) {
195  nb_event =static_cast<G4int>(n_adj_evt);
196  }
197  else nb_event=0;
198  }
199 
200  if (nb_event>100 && fStop_run_if_precision_reached &&
201  fPrecision_to_reach >fRelative_error) {
202  G4cout<<fPrecision_to_reach*100.<<"% Precision reached!"<<std::endl;
203  fTimer->Stop();
204  fElapsed_time+=fTimer->GetRealElapsed();
205  fConvergenceFileOutput<<fMean_edep<<'\t'<<fError_mean_edep
206  <<'\t'<<fElapsed_time<<std::endl;
208  }
209 
210  if (nb_event>0 && nb_event % fNb_evt_modulo_for_convergence_test == 0) {
211  fTimer->Stop();
212  fElapsed_time+=fTimer->GetRealElapsed();
213  fTimer->Start();
214  fConvergenceFileOutput<<fMean_edep<<'\t'<<fError_mean_edep<<'\t'
215  <<fElapsed_time<<std::endl;
216  }
217 }
virtual void AbortRun(G4bool softAbort=false)
int G4int
Definition: G4Types.hh:78
G4int GetEventID() const
Definition: G4Event.hh:151
G4GLOB_DLL std::ostream G4cout
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4double GetRealElapsed() const
Definition: G4Timer.cc:107
void Stop()
void Start()
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

void RMC01AnalysisManager::EndOfRun ( const G4Run aRun)

Definition at line 153 of file RMC01AnalysisManager.cc.

154 { fTimer->Stop();
155  G4int nb_evt=aRun->GetNumberOfEvent();
156  G4double factor =1./ nb_evt;
157  if (!fAdjoint_sim_mode){
158  G4cout<<"Results of forward simulation!"<<std::endl;
159  G4cout<<"edep per event [MeV] = "<<fMean_edep<<std::endl;
160  G4cout<<"error[MeV] = "<<fError_mean_edep<<std::endl;
161  }
162 
163  else {
164  G4cout<<"Results of reverse/adjoint simulation!"<<std::endl;
165  G4cout<<"normalised edep [MeV] = "<<fMean_edep<<std::endl;
166  G4cout<<"error[MeV] = "<<fError_mean_edep<<std::endl;
168  *fNb_evt_per_adj_evt/aRun->GetNumberOfEvent();
169  }
170  Save(factor);
171  fConvergenceFileOutput.close();
172 }
static G4AdjointSimManager * GetInstance()
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
void Save(G4double scaling_factor)
void Stop()
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

RMC01AnalysisManager * RMC01AnalysisManager::GetInstance ( void  )
static

Definition at line 108 of file RMC01AnalysisManager.cc.

109 {
110  if (fInstance == 0) fInstance = new RMC01AnalysisManager;
111  return fInstance;
112 }

Here is the caller graph for this function:

void RMC01AnalysisManager::Save ( G4double  scaling_factor)

Definition at line 763 of file RMC01AnalysisManager.cc.

764 { if (fFactoryOn) {
765  G4AnalysisManager* theHistoManager = G4AnalysisManager::Instance();
766  //scaling of results
767  //-----------------
768 
769  for (int ind=1; ind<=theHistoManager->GetNofH1s();ind++){
770  theHistoManager->SetH1Ascii(ind,true);
771  theHistoManager->ScaleH1(ind,scaling_factor);
772  }
773  for (int ind=1; ind<=theHistoManager->GetNofH2s();ind++)
774  theHistoManager->ScaleH2(ind,scaling_factor);
775 
776  theHistoManager->Write();
777  theHistoManager->CloseFile();
778  G4cout << "\n----> Histogram Tree is saved in " << fFileName[1] << G4endl;
779 
780  delete G4AnalysisManager::Instance();
781  fFactoryOn = false;
782  }
783 }
G4bool ScaleH1(G4int id, G4double factor)
G4bool ScaleH2(G4int id, G4double factor)
void SetH1Ascii(G4int id, G4bool ascii)
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

void RMC01AnalysisManager::SetPrecision ( G4double  precision)
inline

Definition at line 97 of file RMC01AnalysisManager.hh.

97  {
98  fPrecision_to_reach =precision/100.;};

Here is the caller graph for this function:

void RMC01AnalysisManager::SetPrimaryExpSpectrumForAdjointSim ( const G4String particle_name,
G4double  fluence,
G4double  E0,
G4double  Emin,
G4double  Emax 
)

Definition at line 542 of file RMC01AnalysisManager.cc.

546 { fPrimSpectrumType = EXPO;
547  if (particle_name == "e-" ) fPrimPDG_ID =
549  else if (particle_name == "gamma") fPrimPDG_ID =
551  else if (particle_name == "proton") fPrimPDG_ID =
553  else {
554  G4cout<<"The particle that you did select is not in the candidate "<<
555  "list for primary [e-, gamma, proton]!"<<G4endl;
556  return;
557  }
558  fAlpha_or_E0 = E0 ;
559  fAmplitude_prim_spectrum = omni_fluence/E0/
560  (std::exp(-Emin/E0)-std::exp(-Emax/E0))/4./pi;
561  fEmin_prim_spectrum = Emin ;
562  fEmax_prim_spectrum = Emax;
563 }
G4GLOB_DLL std::ostream G4cout
static G4Proton * Proton()
Definition: G4Proton.cc:93
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static const G4double Emin
static G4Electron * Electron()
Definition: G4Electron.cc:94
static const G4double Emax
#define G4endl
Definition: G4ios.hh:61
static constexpr double pi
Definition: G4SIunits.hh:75

Here is the call graph for this function:

Here is the caller graph for this function:

void RMC01AnalysisManager::SetPrimaryPowerLawSpectrumForAdjointSim ( const G4String particle_name,
G4double  fluence,
G4double  alpha,
G4double  Emin,
G4double  Emax 
)

Definition at line 567 of file RMC01AnalysisManager.cc.

570 { fPrimSpectrumType =POWER;
571  if (particle_name == "e-" ) fPrimPDG_ID =
573  else if (particle_name == "gamma") fPrimPDG_ID =
575  else if (particle_name == "proton") fPrimPDG_ID =
577  else {
578  G4cout<<"The particle that you did select is not in the candidate"<<
579  " list for primary [e-, gamma, proton]!"<<G4endl;
580  return;
581  }
582 
583 
584  if (alpha ==1.) {
585  fAmplitude_prim_spectrum = omni_fluence/std::log(Emax/Emin)/4./pi;
586  }
587  else {
588  G4double p=1.-alpha;
589  fAmplitude_prim_spectrum = omni_fluence/p/(std::pow(Emax,p)
590  -std::pow(Emin,p))/4./pi;
591  }
592 
593  fAlpha_or_E0 = alpha ;
594  fEmin_prim_spectrum = Emin ;
595  fEmax_prim_spectrum = Emax;
596 
597 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
static G4Proton * Proton()
Definition: G4Proton.cc:93
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static const G4double Emin
static G4Electron * Electron()
Definition: G4Electron.cc:94
static const G4double Emax
#define G4endl
Definition: G4ios.hh:61
static constexpr double pi
Definition: G4SIunits.hh:75
double G4double
Definition: G4Types.hh:76
static const G4double alpha

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: