Geant4  10.02.p03
RMC01AnalysisManager Class Reference

#include <RMC01AnalysisManager.hh>

Collaboration diagram for RMC01AnalysisManager:

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 ()
 

Private Member Functions

 RMC01AnalysisManager ()
 
void EndOfEventForForwardSimulation (const G4Event *anEvent)
 
void EndOfEventForAdjointSimulation (const G4Event *anEvent)
 
G4double PrimDiffAndDirFluxForAdjointSim (G4double prim_energy)
 
void ComputeMeanEdepAndError (const G4Event *anEvent, G4double &mean, G4double &error)
 

Private Attributes

RMC01AnalysisManagerMessengerfMsg
 
G4AnaH1fEdep_vs_prim_ekin
 
G4AnaH1fElectron_current
 
G4AnaH1fProton_current
 
G4AnaH1fGamma_current
 
G4double fAccumulated_edep
 
G4double fAccumulated_edep2
 
G4double fNentry
 
G4double fMean_edep
 
G4double fError_mean_edep
 
G4double fRelative_error
 
G4double fElapsed_time
 
G4double fPrecision_to_reach
 
G4bool fStop_run_if_precision_reached
 
G4int fNb_evt_modulo_for_convergence_test
 
G4AnaH1fEdep_rmatrix_vs_electron_prim_energy
 
G4AnaH2fElectron_current_rmatrix_vs_electron_prim_energy
 
G4AnaH2fGamma_current_rmatrix_vs_electron_prim_energy
 
G4AnaH1fEdep_rmatrix_vs_gamma_prim_energy
 
G4AnaH2fElectron_current_rmatrix_vs_gamma_prim_energy
 
G4AnaH2fGamma_current_rmatrix_vs_gamma_prim_energy
 
G4AnaH1fEdep_rmatrix_vs_proton_prim_energy
 
G4AnaH2fElectron_current_rmatrix_vs_proton_prim_energy
 
G4AnaH2fProton_current_rmatrix_vs_proton_prim_energy
 
G4AnaH2fGamma_current_rmatrix_vs_proton_prim_energy
 
G4String fFileName [2]
 
G4bool fFactoryOn
 
PRIM_SPECTRUM_TYPE fPrimSpectrumType
 
G4int fPrimPDG_ID
 
G4double fAlpha_or_E0
 
G4double fAmplitude_prim_spectrum
 
G4double fEmin_prim_spectrum
 
G4double fEmax_prim_spectrum
 
G4bool fAdjoint_sim_mode
 
G4int fNb_evt_per_adj_evt
 
G4TimerfTimer
 
std::fstream fConvergenceFileOutput
 

Static Private Attributes

static RMC01AnalysisManagerfInstance = 0
 

Detailed Description

Definition at line 77 of file RMC01AnalysisManager.hh.

Constructor & Destructor Documentation

◆ ~RMC01AnalysisManager()

RMC01AnalysisManager::~RMC01AnalysisManager ( )

Definition at line 103 of file RMC01AnalysisManager.cc.

104 {;
105 }

◆ RMC01AnalysisManager()

RMC01AnalysisManager::RMC01AnalysisManager ( )
private

Definition at line 61 of file RMC01AnalysisManager.cc.

76  fFactoryOn(false),
81 {
82 
84 
85  //-------------
86  //Timer for convergence vector
87  //-------------
88 
89  fTimer = new G4Timer();
90 
91  //---------------------------------
92  //Primary particle ID for normalisation of adjoint results
93  //---------------------------------
94 
96 
97  fFileName[0] = "sim";
98 
99 }
G4AnaH1 * fEdep_rmatrix_vs_proton_prim_energy
static const double MeV
Definition: G4SIunits.hh:211
G4AnaH1 * fEdep_rmatrix_vs_electron_prim_energy
G4AnaH2 * fGamma_current_rmatrix_vs_proton_prim_energy
G4AnaH2 * fElectron_current_rmatrix_vs_electron_prim_energy
G4AnaH2 * fElectron_current_rmatrix_vs_gamma_prim_energy
PRIM_SPECTRUM_TYPE fPrimSpectrumType
G4AnaH2 * fProton_current_rmatrix_vs_proton_prim_energy
RMC01AnalysisManagerMessenger * fMsg
G4AnaH2 * fGamma_current_rmatrix_vs_electron_prim_energy
G4AnaH2 * fElectron_current_rmatrix_vs_proton_prim_energy
static G4Electron * Electron()
Definition: G4Electron.cc:94
static const double keV
Definition: G4SIunits.hh:213
G4AnaH2 * fGamma_current_rmatrix_vs_gamma_prim_energy
G4AnaH1 * fEdep_rmatrix_vs_gamma_prim_energy
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ BeginOfEvent()

void RMC01AnalysisManager::BeginOfEvent ( const G4Event )

Definition at line 178 of file RMC01AnalysisManager.cc.

179 { ;
180 }
Here is the caller graph for this function:

◆ BeginOfRun()

void RMC01AnalysisManager::BeginOfRun ( const G4Run aRun)

Definition at line 117 of file RMC01AnalysisManager.cc.

118 {
119 
120 
121  fAccumulated_edep =0.;
122  fAccumulated_edep2 =0.;
123  fNentry = 0.0;
124  fRelative_error=1.;
125  fMean_edep=0.;
126  fError_mean_edep=0.;
128 
129  if (fAdjoint_sim_mode){
132  fConvergenceFileOutput.open("ConvergenceOfAdjointSimulationResults.txt",
133  std::ios::out);
135  "Normalised Edep[MeV]\terror[MeV]\tcomputing_time[s]"<<std::endl;
136  }
137  else {
138  fConvergenceFileOutput.open("ConvergenceOfForwardSimulationResults.txt",
139  std::ios::out);
141  "Edep per event [MeV]\terror[MeV]\tcomputing_time[s]"
142  <<std::endl;
143  }
144  fConvergenceFileOutput.setf(std::ios::scientific);
145  fConvergenceFileOutput.precision(6);
146 
147  fTimer->Start();
148  fElapsed_time=0.;
149 
150  book();
151 }
static G4AdjointSimManager * GetInstance()
void Start()
G4int GetNumberOfEventToBeProcessed() const
Definition: G4Run.hh:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ book()

void RMC01AnalysisManager::book ( )

Definition at line 589 of file RMC01AnalysisManager.cc.

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

◆ ComputeMeanEdepAndError()

void RMC01AnalysisManager::ComputeMeanEdepAndError ( const G4Event anEvent,
G4double mean,
G4double error 
)
private

Definition at line 499 of file RMC01AnalysisManager.cc.

501 {
502  G4int nb_event=anEvent->GetEventID()+1;
503  G4double factor=1.;
504  if (fAdjoint_sim_mode) {
505  nb_event /=fNb_evt_per_adj_evt;
507  }
508 
509  // VI: error computation now is based on number of entries and not
510  // number of events
511  if (fNentry > 1.0) {
512  mean = fAccumulated_edep/fNentry;
514  /*
515  G4cout << "Nevt= " << nb_event << " mean= " << mean
516  << " mean_x2= " << mean_x2 << " x2 - x*x= "
517  << mean_x2-mean*mean << G4endl;
518  */
519  error = factor*std::sqrt(mean_x2-mean*mean)/std::sqrt(fNentry);
520  mean *=factor;
521  }
522  else {
523  mean=0;
524  error=0;
525  }
526 }
static G4AdjointSimManager * GetInstance()
int G4int
Definition: G4Types.hh:78
static const G4double factor
G4int GetEventID() const
Definition: G4Event.hh:151
static PROLOG_HANDLER error
Definition: xmlrole.cc:112
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndOfEvent()

void RMC01AnalysisManager::EndOfEvent ( const G4Event anEvent)

Definition at line 184 of file RMC01AnalysisManager.cc.

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

◆ EndOfEventForAdjointSimulation()

void RMC01AnalysisManager::EndOfEventForAdjointSimulation ( const G4Event anEvent)
private

Definition at line 292 of file RMC01AnalysisManager.cc.

294 {
295  //Output from Sensitive volume computed during the forward tracking phase
296  //-----------------------------------------------------------------------
298  G4HCofThisEvent* HCE = anEvent->GetHCofThisEvent();
299  RMC01DoubleWithWeightHitsCollection* edepCollection =
301  HCE->GetHC(SDman->GetCollectionID("edep")));
302 
303  RMC01DoubleWithWeightHitsCollection* electronCurrentCollection =
305  HCE->GetHC(SDman->GetCollectionID("current_electron")));
306 
307  RMC01DoubleWithWeightHitsCollection* protonCurrentCollection =
309  HCE->GetHC(SDman->GetCollectionID("current_proton")));
310 
311  RMC01DoubleWithWeightHitsCollection* gammaCurrentCollection =
313  HCE->GetHC(SDman->GetCollectionID("current_gamma")));
314 
315  //Output from adjoint tracking phase
316  //----------------------------------------------------------------------------
317 
318  G4AdjointSimManager* theAdjointSimManager =
320  G4int pdg_nb =theAdjointSimManager
322  G4double prim_ekin=theAdjointSimManager->GetEkinAtEndOfLastAdjointTrack();
323  G4double adj_weight=theAdjointSimManager->GetWeightAtEndOfLastAdjointTrack();
324 
325 
326  //Factor of normalisation to user defined prim spectrum (power law or exp)
327  //---------------------------------------------------------------------------
328 
329  G4double normalised_weight = 0.;
330  if (pdg_nb== fPrimPDG_ID && prim_ekin>= fEmin_prim_spectrum
331  && prim_ekin<= fEmax_prim_spectrum)
332  normalised_weight =
333  adj_weight*PrimDiffAndDirFluxForAdjointSim(prim_ekin);
334 
335  //Answer matrices
336  //-------------
337  G4AnaH1* edep_rmatrix =0;
338  G4AnaH2* electron_current_rmatrix =0;
339  G4AnaH2* gamma_current_rmatrix =0;
340  G4AnaH2* proton_current_rmatrix =0;
341 
342  if (pdg_nb == G4Electron::Electron()->GetPDGEncoding()){ //e- answer matrices
344 
345  electron_current_rmatrix =
347 
348  gamma_current_rmatrix = fGamma_current_rmatrix_vs_electron_prim_energy;
349  }
350  else if (pdg_nb == G4Gamma::Gamma()->GetPDGEncoding()){
351  //gammma answer matrices
352  edep_rmatrix = fEdep_rmatrix_vs_gamma_prim_energy;
353  electron_current_rmatrix = fElectron_current_rmatrix_vs_gamma_prim_energy;
354  gamma_current_rmatrix = fGamma_current_rmatrix_vs_gamma_prim_energy;
355  }
356  else if (pdg_nb == G4Proton::Proton()->GetPDGEncoding()){
357  //proton answer matrices
359  electron_current_rmatrix = fElectron_current_rmatrix_vs_proton_prim_energy;
360  gamma_current_rmatrix = fGamma_current_rmatrix_vs_proton_prim_energy;
361  proton_current_rmatrix = fProton_current_rmatrix_vs_proton_prim_energy;
362  }
363 
364  //Registering of total energy deposited in Event
365  //-------------------------------
366  G4double totEdep=0;
367  G4int i;
368  for (i=0;i<edepCollection->entries();i++)
369  totEdep+=(*edepCollection)[i]->GetValue()*
370  (*edepCollection)[i]->GetWeight();
371 
372  G4bool new_mean_computed=false;
373  if (totEdep>0.){
374  if (normalised_weight>0.){
375  G4double edep=totEdep* normalised_weight;
376 
377  //Check if the edep is not wrongly too high
378  //-----------------------------------------
379  G4double new_mean , new_error;
380 
382  fAccumulated_edep2 +=edep*edep;
383  fNentry += 1.0;
384  ComputeMeanEdepAndError(anEvent,new_mean,new_error);
385  G4double new_relative_error = 1.;
386  if ( new_error >0) new_relative_error = new_error/ new_mean;
387  if (fRelative_error <0.10 && new_relative_error>1.5*fRelative_error) {
388  G4cout<<"Potential wrong adjoint weight!"<<std::endl;
389  G4cout<<"The results of this event will not be registered!"
390  <<std::endl;
391  G4cout<<"previous mean edep [MeV] "<< fMean_edep<<std::endl;
392  G4cout<<"previous relative error "<< fRelative_error<<std::endl;
393  G4cout<<"new rejected mean edep [MeV] "<< new_mean<<std::endl;
394  G4cout<<"new rejected relative error "<< new_relative_error
395  <<std::endl;
397  fAccumulated_edep2 -=edep*edep;
398  fNentry -= 1.0;
399  return;
400  }
401  else { //accepted
402  fMean_edep = new_mean;
403  fError_mean_edep = new_error;
404  fRelative_error =new_relative_error;
405  new_mean_computed=true;
406  }
407  fEdep_vs_prim_ekin->fill(prim_ekin,edep);
408  }
409 
410  // Registering answer matrix
411  //---------------------------
412 
413  edep_rmatrix->fill(prim_ekin,totEdep*adj_weight/cm2);
414  }
415  if (!new_mean_computed){
417  if (fError_mean_edep>0) fRelative_error= fError_mean_edep/fMean_edep;
418  }
419 
420 
421  //Registering of current of particles on the sensitive volume
422  //------------------------------------------------------------
423 
424  for (i=0;i<electronCurrentCollection->entries();i++) {
425  G4double ekin =(*electronCurrentCollection)[i]->GetValue();
426  G4double weight=(*electronCurrentCollection)[i]->GetWeight();
427  fElectron_current->fill(ekin,weight*normalised_weight);
428  electron_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/cm2);
429  }
430 
431  for (i=0;i<protonCurrentCollection->entries();i++) {
432  G4double ekin =(*protonCurrentCollection)[i]->GetValue();
433  G4double weight=(*protonCurrentCollection)[i]->GetWeight();
434  fProton_current->fill(ekin,weight*normalised_weight);
435  proton_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/cm2);
436  }
437 
438  for (i=0;i<gammaCurrentCollection->entries();i++) {
439  G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
440  G4double weight=(*gammaCurrentCollection)[i]->GetWeight();
441  fGamma_current->fill(ekin,weight*normalised_weight);
442  gamma_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/cm2);
443  }
444 }
G4AnaH1 * fEdep_rmatrix_vs_proton_prim_energy
static G4AdjointSimManager * GetInstance()
static const double cm2
Definition: G4SIunits.hh:119
G4AnaH1 * fEdep_rmatrix_vs_electron_prim_energy
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
G4AnaH2 * fGamma_current_rmatrix_vs_proton_prim_energy
G4AnaH2 * fElectron_current_rmatrix_vs_electron_prim_energy
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack()
G4AnaH2 * fElectron_current_rmatrix_vs_gamma_prim_energy
double weight
Definition: plottest35.C:25
int G4int
Definition: G4Types.hh:78
G4AnaH2 * fProton_current_rmatrix_vs_proton_prim_energy
Double_t edep
G4double GetEkinAtEndOfLastAdjointTrack()
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
static G4Proton * Proton()
Definition: G4Proton.cc:93
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
G4double PrimDiffAndDirFluxForAdjointSim(G4double prim_energy)
void ComputeMeanEdepAndError(const G4Event *anEvent, G4double &mean, G4double &error)
G4AnaH2 * fGamma_current_rmatrix_vs_electron_prim_energy
G4AnaH2 * fElectron_current_rmatrix_vs_proton_prim_energy
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
G4double GetWeightAtEndOfLastAdjointTrack()
static G4Electron * Electron()
Definition: G4Electron.cc:94
tools::histo::h1d G4AnaH1
Definition: g4root_defs.hh:46
tools::histo::h2d G4AnaH2
Definition: g4root_defs.hh:52
double G4double
Definition: G4Types.hh:76
G4AnaH2 * fGamma_current_rmatrix_vs_gamma_prim_energy
G4AnaH1 * fEdep_rmatrix_vs_gamma_prim_energy
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndOfEventForForwardSimulation()

void RMC01AnalysisManager::EndOfEventForForwardSimulation ( const G4Event anEvent)
private

Definition at line 224 of file RMC01AnalysisManager.cc.

226 {
227 
229  G4HCofThisEvent* HCE = anEvent->GetHCofThisEvent();
230  RMC01DoubleWithWeightHitsCollection* edepCollection =
232  (HCE->GetHC(SDman->GetCollectionID("edep")));
233 
234  RMC01DoubleWithWeightHitsCollection* electronCurrentCollection =
236  (HCE->GetHC(SDman->GetCollectionID("current_electron")));
237 
238  RMC01DoubleWithWeightHitsCollection* protonCurrentCollection =
240  (HCE->GetHC(SDman->GetCollectionID("current_proton")));
241 
242  RMC01DoubleWithWeightHitsCollection* gammaCurrentCollection =
244  (HCE->GetHC(SDman->GetCollectionID("current_gamma")));
245 
246  //Total energy deposited in Event
247  //-------------------------------
248  G4double totEdep=0;
249  G4int i;
250  for (i=0;i<edepCollection->entries();i++)
251  totEdep+=(*edepCollection)[i]->GetValue()
252  *(*edepCollection)[i]->GetWeight();
253 
254  if (totEdep>0.){
255  fAccumulated_edep +=totEdep ;
256  fAccumulated_edep2 +=totEdep*totEdep;
257  fNentry += 1.0;
258  G4PrimaryParticle* thePrimary=anEvent->GetPrimaryVertex()->GetPrimary();
259  G4double E0= thePrimary->GetG4code()->GetPDGMass();
260  G4double P=thePrimary->GetMomentum().mag();
261  G4double prim_ekin =std::sqrt(E0*E0+P*P)-E0;
262  fEdep_vs_prim_ekin->fill(prim_ekin,totEdep);
263  }
266 
267  //Particle current on sensitive cylinder
268  //-------------------------------------
269 
270  for (i=0;i<electronCurrentCollection->entries();i++) {
271  G4double ekin =(*electronCurrentCollection)[i]->GetValue();
272  G4double weight=(*electronCurrentCollection)[i]->GetWeight();
273  fElectron_current->fill(ekin,weight);
274  }
275 
276  for (i=0;i<protonCurrentCollection->entries();i++) {
277  G4double ekin =(*protonCurrentCollection)[i]->GetValue();
278  G4double weight=(*protonCurrentCollection)[i]->GetWeight();
279  fProton_current->fill(ekin,weight);
280  }
281 
282  for (i=0;i<gammaCurrentCollection->entries();i++) {
283  G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
284  G4double weight=(*gammaCurrentCollection)[i]->GetWeight();
285  fGamma_current->fill(ekin,weight);
286  }
287 
288 }
G4ParticleDefinition * GetG4code() const
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
G4PrimaryParticle * GetPrimary(G4int i=0) const
double weight
Definition: plottest35.C:25
int G4int
Definition: G4Types.hh:78
static double P[]
double mag() const
void ComputeMeanEdepAndError(const G4Event *anEvent, G4double &mean, G4double &error)
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:167
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
G4ThreeVector GetMomentum() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndOfRun()

void RMC01AnalysisManager::EndOfRun ( const G4Run aRun)

Definition at line 155 of file RMC01AnalysisManager.cc.

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

◆ GetInstance()

RMC01AnalysisManager * RMC01AnalysisManager::GetInstance ( void  )
static

Definition at line 109 of file RMC01AnalysisManager.cc.

110 {
111  if (fInstance == 0) fInstance = new RMC01AnalysisManager;
112  return fInstance;
113 }
static RMC01AnalysisManager * fInstance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrimDiffAndDirFluxForAdjointSim()

G4double RMC01AnalysisManager::PrimDiffAndDirFluxForAdjointSim ( G4double  prim_energy)
private

Definition at line 448 of file RMC01AnalysisManager.cc.

450 {
452  if ( fPrimSpectrumType ==EXPO) flux*=std::exp(-prim_energy/fAlpha_or_E0);
453  else flux*=std::pow(prim_energy, -fAlpha_or_E0);
454  return flux;
455 }
PRIM_SPECTRUM_TYPE fPrimSpectrumType
double G4double
Definition: G4Types.hh:76
Here is the caller graph for this function:

◆ save()

void RMC01AnalysisManager::save ( G4double  scaling_factor)

Definition at line 757 of file RMC01AnalysisManager.cc.

758 { if (fFactoryOn) {
759  G4AnalysisManager* theHistoManager = G4AnalysisManager::Instance();
760  //scaling of results
761  //-----------------
762 
763  for (int ind=1; ind<=theHistoManager->GetNofH1s();ind++){
764  theHistoManager->SetH1Ascii(ind,true);
765  theHistoManager->ScaleH1(ind,scaling_factor);
766  }
767  for (int ind=1; ind<=theHistoManager->GetNofH2s();ind++)
768  theHistoManager->ScaleH2(ind,scaling_factor);
769 
770  theHistoManager->Write();
771  theHistoManager->CloseFile();
772  G4cout << "\n----> Histogram Tree is saved in " << fFileName[1] << G4endl;
773 
774  delete G4AnalysisManager::Instance();
775  fFactoryOn = false;
776  }
777 }
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:

◆ SetPrecision()

void RMC01AnalysisManager::SetPrecision ( G4double  precision)
inline

Definition at line 97 of file RMC01AnalysisManager.hh.

97  {
98  fPrecision_to_reach =precision/100.;};
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPrimaryExpSpectrumForAdjointSim()

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

Definition at line 530 of file RMC01AnalysisManager.cc.

535  if (particle_name == "e-" ) fPrimPDG_ID =
537  else if (particle_name == "gamma") fPrimPDG_ID =
539  else if (particle_name == "proton") fPrimPDG_ID =
541  else {
542  G4cout<<"The particle that you did select is not in the candidate "<<
543  "list for primary [e-, gamma, proton]!"<<G4endl;
544  return;
545  }
546  fAlpha_or_E0 = E0 ;
547  fAmplitude_prim_spectrum = omni_fluence/E0/
548  (std::exp(-Emin/E0)-std::exp(-Emax/E0))/4./pi;
551 }
PRIM_SPECTRUM_TYPE fPrimSpectrumType
G4GLOB_DLL std::ostream G4cout
static G4Proton * Proton()
Definition: G4Proton.cc:93
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static const double pi
Definition: G4SIunits.hh:74
static const G4double Emin
static G4Electron * Electron()
Definition: G4Electron.cc:94
static const G4double Emax
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPrimaryPowerLawSpectrumForAdjointSim()

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

Definition at line 555 of file RMC01AnalysisManager.cc.

559  if (particle_name == "e-" ) fPrimPDG_ID =
561  else if (particle_name == "gamma") fPrimPDG_ID =
563  else if (particle_name == "proton") fPrimPDG_ID =
565  else {
566  G4cout<<"The particle that you did select is not in the candidate"<<
567  " list for primary [e-, gamma, proton]!"<<G4endl;
568  return;
569  }
570 
571 
572  if (alpha ==1.) {
573  fAmplitude_prim_spectrum = omni_fluence/std::log(Emax/Emin)/4./pi;
574  }
575  else {
576  G4double p=1.-alpha;
577  fAmplitude_prim_spectrum = omni_fluence/p/(std::pow(Emax,p)
578  -std::pow(Emin,p))/4./pi;
579  }
580 
581  fAlpha_or_E0 = alpha ;
584 
585 }
PRIM_SPECTRUM_TYPE fPrimSpectrumType
G4GLOB_DLL std::ostream G4cout
static G4Proton * Proton()
Definition: G4Proton.cc:93
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static const double pi
Definition: G4SIunits.hh:74
static const G4double Emin
static G4Electron * Electron()
Definition: G4Electron.cc:94
static const G4double Emax
#define G4endl
Definition: G4ios.hh:61
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:

Member Data Documentation

◆ fAccumulated_edep

G4double RMC01AnalysisManager::fAccumulated_edep
private

Definition at line 138 of file RMC01AnalysisManager.hh.

◆ fAccumulated_edep2

G4double RMC01AnalysisManager::fAccumulated_edep2
private

Definition at line 139 of file RMC01AnalysisManager.hh.

◆ fAdjoint_sim_mode

G4bool RMC01AnalysisManager::fAdjoint_sim_mode
private

Definition at line 179 of file RMC01AnalysisManager.hh.

◆ fAlpha_or_E0

G4double RMC01AnalysisManager::fAlpha_or_E0
private

Definition at line 175 of file RMC01AnalysisManager.hh.

◆ fAmplitude_prim_spectrum

G4double RMC01AnalysisManager::fAmplitude_prim_spectrum
private

Definition at line 176 of file RMC01AnalysisManager.hh.

◆ fConvergenceFileOutput

std::fstream RMC01AnalysisManager::fConvergenceFileOutput
private

Definition at line 185 of file RMC01AnalysisManager.hh.

◆ fEdep_rmatrix_vs_electron_prim_energy

G4AnaH1* RMC01AnalysisManager::fEdep_rmatrix_vs_electron_prim_energy
private

Definition at line 152 of file RMC01AnalysisManager.hh.

◆ fEdep_rmatrix_vs_gamma_prim_energy

G4AnaH1* RMC01AnalysisManager::fEdep_rmatrix_vs_gamma_prim_energy
private

Definition at line 156 of file RMC01AnalysisManager.hh.

◆ fEdep_rmatrix_vs_proton_prim_energy

G4AnaH1* RMC01AnalysisManager::fEdep_rmatrix_vs_proton_prim_energy
private

Definition at line 160 of file RMC01AnalysisManager.hh.

◆ fEdep_vs_prim_ekin

G4AnaH1* RMC01AnalysisManager::fEdep_vs_prim_ekin
private

Definition at line 126 of file RMC01AnalysisManager.hh.

◆ fElapsed_time

G4double RMC01AnalysisManager::fElapsed_time
private

Definition at line 144 of file RMC01AnalysisManager.hh.

◆ fElectron_current

G4AnaH1* RMC01AnalysisManager::fElectron_current
private

Definition at line 127 of file RMC01AnalysisManager.hh.

◆ fElectron_current_rmatrix_vs_electron_prim_energy

G4AnaH2* RMC01AnalysisManager::fElectron_current_rmatrix_vs_electron_prim_energy
private

Definition at line 153 of file RMC01AnalysisManager.hh.

◆ fElectron_current_rmatrix_vs_gamma_prim_energy

G4AnaH2* RMC01AnalysisManager::fElectron_current_rmatrix_vs_gamma_prim_energy
private

Definition at line 157 of file RMC01AnalysisManager.hh.

◆ fElectron_current_rmatrix_vs_proton_prim_energy

G4AnaH2* RMC01AnalysisManager::fElectron_current_rmatrix_vs_proton_prim_energy
private

Definition at line 161 of file RMC01AnalysisManager.hh.

◆ fEmax_prim_spectrum

G4double RMC01AnalysisManager::fEmax_prim_spectrum
private

Definition at line 178 of file RMC01AnalysisManager.hh.

◆ fEmin_prim_spectrum

G4double RMC01AnalysisManager::fEmin_prim_spectrum
private

Definition at line 177 of file RMC01AnalysisManager.hh.

◆ fError_mean_edep

G4double RMC01AnalysisManager::fError_mean_edep
private

Definition at line 142 of file RMC01AnalysisManager.hh.

◆ fFactoryOn

G4bool RMC01AnalysisManager::fFactoryOn
private

Definition at line 166 of file RMC01AnalysisManager.hh.

◆ fFileName

G4String RMC01AnalysisManager::fFileName[2]
private

Definition at line 165 of file RMC01AnalysisManager.hh.

◆ fGamma_current

G4AnaH1* RMC01AnalysisManager::fGamma_current
private

Definition at line 129 of file RMC01AnalysisManager.hh.

◆ fGamma_current_rmatrix_vs_electron_prim_energy

G4AnaH2* RMC01AnalysisManager::fGamma_current_rmatrix_vs_electron_prim_energy
private

Definition at line 154 of file RMC01AnalysisManager.hh.

◆ fGamma_current_rmatrix_vs_gamma_prim_energy

G4AnaH2* RMC01AnalysisManager::fGamma_current_rmatrix_vs_gamma_prim_energy
private

Definition at line 158 of file RMC01AnalysisManager.hh.

◆ fGamma_current_rmatrix_vs_proton_prim_energy

G4AnaH2* RMC01AnalysisManager::fGamma_current_rmatrix_vs_proton_prim_energy
private

Definition at line 163 of file RMC01AnalysisManager.hh.

◆ fInstance

RMC01AnalysisManager * RMC01AnalysisManager::fInstance = 0
staticprivate

Definition at line 106 of file RMC01AnalysisManager.hh.

◆ fMean_edep

G4double RMC01AnalysisManager::fMean_edep
private

Definition at line 141 of file RMC01AnalysisManager.hh.

◆ fMsg

RMC01AnalysisManagerMessenger* RMC01AnalysisManager::fMsg
private

Definition at line 122 of file RMC01AnalysisManager.hh.

◆ fNb_evt_modulo_for_convergence_test

G4int RMC01AnalysisManager::fNb_evt_modulo_for_convergence_test
private

Definition at line 147 of file RMC01AnalysisManager.hh.

◆ fNb_evt_per_adj_evt

G4int RMC01AnalysisManager::fNb_evt_per_adj_evt
private

Definition at line 180 of file RMC01AnalysisManager.hh.

◆ fNentry

G4double RMC01AnalysisManager::fNentry
private

Definition at line 140 of file RMC01AnalysisManager.hh.

◆ fPrecision_to_reach

G4double RMC01AnalysisManager::fPrecision_to_reach
private

Definition at line 145 of file RMC01AnalysisManager.hh.

◆ fPrimPDG_ID

G4int RMC01AnalysisManager::fPrimPDG_ID
private

Definition at line 174 of file RMC01AnalysisManager.hh.

◆ fPrimSpectrumType

PRIM_SPECTRUM_TYPE RMC01AnalysisManager::fPrimSpectrumType
private

Definition at line 173 of file RMC01AnalysisManager.hh.

◆ fProton_current

G4AnaH1* RMC01AnalysisManager::fProton_current
private

Definition at line 128 of file RMC01AnalysisManager.hh.

◆ fProton_current_rmatrix_vs_proton_prim_energy

G4AnaH2* RMC01AnalysisManager::fProton_current_rmatrix_vs_proton_prim_energy
private

Definition at line 162 of file RMC01AnalysisManager.hh.

◆ fRelative_error

G4double RMC01AnalysisManager::fRelative_error
private

Definition at line 143 of file RMC01AnalysisManager.hh.

◆ fStop_run_if_precision_reached

G4bool RMC01AnalysisManager::fStop_run_if_precision_reached
private

Definition at line 146 of file RMC01AnalysisManager.hh.

◆ fTimer

G4Timer* RMC01AnalysisManager::fTimer
private

Definition at line 184 of file RMC01AnalysisManager.hh.


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