46 #include "G4THitsCollection.hh"
61 :fAccumulated_edep(0.), fAccumulated_edep2(0.), fMean_edep(0.),
62 fError_mean_edep(0.), fRelative_error(0.), fElapsed_time(0.),
63 fPrecision_to_reach(0.),fStop_run_if_precision_reached(true),
64 fNb_evt_modulo_for_convergence_test(5000),
65 fEdep_rmatrix_vs_electron_prim_energy(0),
66 fElectron_current_rmatrix_vs_electron_prim_energy(0),
67 fGamma_current_rmatrix_vs_electron_prim_energy(0),
68 fEdep_rmatrix_vs_gamma_prim_energy(0),
69 fElectron_current_rmatrix_vs_gamma_prim_energy(0),
70 fGamma_current_rmatrix_vs_gamma_prim_energy(0),
71 fEdep_rmatrix_vs_proton_prim_energy(0),
72 fElectron_current_rmatrix_vs_proton_prim_energy(0),
73 fProton_current_rmatrix_vs_proton_prim_energy(0),
74 fGamma_current_rmatrix_vs_proton_prim_energy(0),
76 fPrimSpectrumType(
EXPO),
77 fAlpha_or_E0(.5*
MeV),fAmplitude_prim_spectrum (1.),
78 fEmin_prim_spectrum(1.*
keV),fEmax_prim_spectrum (20.*
MeV),
79 fAdjoint_sim_mode(true),fNb_evt_per_adj_evt(2)
133 "Normalised Edep[MeV]\terror[MeV]\tcomputing_time[s]"<<std::endl;
139 "Edep per event [MeV]\terror[MeV]\tcomputing_time[s]"
158 G4cout<<
"Results of forward simulation!"<<std::endl;
164 G4cout<<
"Results of reverse/adjoint simulation!"<<std::endl;
195 nb_event =
static_cast<G4int>(n_adj_evt);
247 for (i=0;i<edepCollection->
entries();i++)
248 totEdep+=(*edepCollection)[i]->GetValue()
249 *(*edepCollection)[i]->GetWeight();
259 G4double prim_ekin =std::sqrt(E0*E0+P*P)-E0;
268 for (i=0;i<electronCurrentCollection->
entries();i++) {
269 G4double ekin =(*electronCurrentCollection)[i]->GetValue();
274 for (i=0;i<protonCurrentCollection->
entries();i++) {
275 G4double ekin =(*protonCurrentCollection)[i]->GetValue();
280 for (i=0;i<gammaCurrentCollection->
entries();i++) {
281 G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
317 for (i=0;i<edepCollection->
entries();i++)
318 totEdep+=(*edepCollection)[i]->GetValue()*
319 (*edepCollection)[i]->GetWeight();
327 size_t nb_adj_track =
329 G4double total_normalised_weight = 0.;
333 for (
size_t j=0;j<nb_adj_track;j++) {
334 G4int pdg_nb =theAdjointSimManager
336 G4double prim_ekin=theAdjointSimManager
338 G4double adj_weight=theAdjointSimManager
349 total_normalised_weight += normalised_weight;
354 G4AnaH2* electron_current_rmatrix =0;
355 G4AnaH2* gamma_current_rmatrix =0;
356 G4AnaH2* proton_current_rmatrix =0;
360 electron_current_rmatrix =
373 electron_current_rmatrix =
381 ->fill(prim_ekin,totEdep*normalised_weight);
384 edep_rmatrix->fill(prim_ekin,totEdep*adj_weight/
cm2);
389 for (i=0;i<electronCurrentCollection->
entries();i++) {
390 G4double ekin =(*electronCurrentCollection)[i]->GetValue();
393 electron_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/
cm2);
395 for (i=0;i<protonCurrentCollection->
entries();i++) {
396 G4double ekin =(*protonCurrentCollection)[i]->GetValue();
399 proton_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/
cm2);
401 for (i=0;i<gammaCurrentCollection->
entries();i++) {
402 G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
405 gamma_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/
cm2);
411 G4bool new_mean_computed=
false;
413 if (total_normalised_weight>0.){
424 if ( new_error >0) new_relative_error = new_error/ new_mean;
426 G4cout<<
"Potential wrong adjoint weight!"<<std::endl;
427 G4cout<<
"The results of this event will not be registered!"
430 G4cout<<
"previous relative error "<< fRelative_error<<std::endl;
431 G4cout<<
"new rejected mean edep [MeV] "<< new_mean<<std::endl;
432 G4cout<<
"new rejected relative error "<< new_relative_error
442 fRelative_error =new_relative_error;
443 new_mean_computed=
true;
447 if (!new_mean_computed){
523 if (nb_event_float >1.) {
531 error = factor*std::sqrt(mean_x2-mean*mean)/std::sqrt(nb_event_float);
554 G4cout<<
"The particle that you did select is not in the candidate "<<
555 "list for primary [e-, gamma, proton]!"<<
G4endl;
560 (std::exp(-Emin/E0)-std::exp(-Emax/E0))/4./
pi;
578 G4cout<<
"The particle that you did select is not in the candidate"<<
579 " list for primary [e-, gamma, proton]!"<<
G4endl;
590 -std::pow(Emin,p))/4./
pi;
624 G4cout <<
"\n---> RMC01AnalysisManager::Book(): cannot open "
640 G4String(
"edep vs e- primary energy"),60,emin,emax,
668 G4String(
"electron RM vs e- primary energy"),60,emin,emax,
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,
680 theHistoManager->
GetH2(idHisto);
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,
690 theHistoManager->
GetH2(idHisto);
696 G4String(
"electron RM vs gamma primary energy"),60,emin,emax,
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,
708 theHistoManager->
GetH2(idHisto);
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,
718 theHistoManager->
GetH2(idHisto);
723 G4String(
"electron RM vs proton primary energy"),60,emin,emax,
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,
735 theHistoManager->
GetH2(idHisto);
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,
745 theHistoManager->
GetH2(idHisto);
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,
755 theHistoManager->
GetH2(idHisto);
769 for (
int ind=1; ind<=theHistoManager->
GetNofH1s();ind++){
771 theHistoManager->
ScaleH1(ind,scaling_factor);
773 for (
int ind=1; ind<=theHistoManager->
GetNofH2s();ind++)
774 theHistoManager->
ScaleH2(ind,scaling_factor);
776 theHistoManager->
Write();
780 delete G4AnalysisManager::Instance();
virtual void AbortRun(G4bool softAbort=false)
G4double GetRealElapsed() const
G4int GetCollectionID(G4String colName)
static G4RunManager * GetRunManager()
G4ThreeVector GetMomentum() const
G4PrimaryParticle * GetPrimary(G4int i=0) const
static const G4double Emin
G4AnaH1 * fEdep_rmatrix_vs_proton_prim_energy
G4int fNb_evt_modulo_for_convergence_test
std::fstream fConvergenceFileOutput
G4bool SetHistoDirectoryName(const G4String &dirName)
G4AnaH2 * fGamma_current_rmatrix_vs_proton_prim_energy
G4AnaH1 * fElectron_current
static constexpr double MeV
static constexpr double keV
G4AnaH2 * fGamma_current_rmatrix_vs_electron_prim_energy
G4double PrimDiffAndDirFluxForAdjointSim(G4double prim_energy)
G4bool ScaleH1(G4int id, G4double factor)
G4AnaH1 * fProton_current
size_t GetNbOfAdointTracksReachingTheExternalSurface()
G4int GetNbEvtOfLastRun()
G4String GetFileType() const
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(size_t i=0)
G4bool SetFirstHistoId(G4int firstId)
G4bool OpenFile(const G4String &fileName="")
static const G4double emax
static G4Proton * Proton()
tools::histo::h2d G4AnaH2
G4double fAccumulated_edep2
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")
G4double GetPDGMass() const
G4AnaH1 * fEdep_vs_prim_ekin
G4HCofThisEvent * GetHCofThisEvent() const
G4double fAmplitude_prim_spectrum
G4int GetNumberOfEvent() const
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
RMC01AnalysisManagerMessenger * fMsg
void EndOfEvent(const G4Event *)
G4AnaH1 * fEdep_rmatrix_vs_electron_prim_energy
G4double fError_mean_edep
G4AnaH1 * fEdep_rmatrix_vs_gamma_prim_energy
G4double fPrecision_to_reach
G4bool fStop_run_if_precision_reached
static constexpr double cm2
G4AnaH2 * fProton_current_rmatrix_vs_proton_prim_energy
G4ParticleDefinition * GetG4code() const
G4AnaH2 * fElectron_current_rmatrix_vs_gamma_prim_energy
static RMC01AnalysisManager * fInstance
static const G4double alpha
void ComputeMeanEdepAndError(const G4Event *anEvent, G4double &mean, G4double &error)
G4int fNb_evt_per_adj_evt
void BeginOfEvent(const G4Event *)
void SetPrimaryExpSpectrumForAdjointSim(const G4String &particle_name, G4double fluence, G4double E0, G4double Emin, G4double Emax)
PRIM_SPECTRUM_TYPE fPrimSpectrumType
tools::histo::h1d G4AnaH1
void SetPrimaryPowerLawSpectrumForAdjointSim(const G4String &particle_name, G4double fluence, G4double alpha, G4double Emin, G4double Emax)
static G4Electron * Electron()
G4AnaH2 * fGamma_current_rmatrix_vs_gamma_prim_energy
G4int GetNumberOfEventToBeProcessed() const
G4VHitsCollection * GetHC(G4int i)
G4double fAccumulated_edep
void EndOfEventForAdjointSimulation(const G4Event *anEvent)
Definition of the RMC01SD class.
G4bool ScaleH2(G4int id, G4double factor)
G4AnaH2 * fElectron_current_rmatrix_vs_electron_prim_energy
static G4SDManager * GetSDMpointer()
void SetH1Ascii(G4int id, G4bool ascii)
void EndOfRun(const G4Run *)
G4double fEmin_prim_spectrum
Definition of the RMC01AnalysisManager class.
G4AnaH2 * fElectron_current_rmatrix_vs_proton_prim_energy
static const G4double Emax
G4bool GetAdjointSimMode()
G4int GetPDGEncoding() const
G4GLOB_DLL std::ostream G4cout
G4double GetWeightAtEndOfLastAdjointTrack(size_t i=0)
static PROLOG_HANDLER error
static RMC01AnalysisManager * GetInstance()
static constexpr double pi
static G4AdjointSimManager * GetInstance()
void EndOfEventForForwardSimulation(const G4Event *anEvent)
Definition of the RMC01AnalysisManagerMessenger class.
void Save(G4double scaling_factor)
G4double fEmax_prim_spectrum
void BeginOfRun(const G4Run *)
static constexpr double GeV
G4double GetEkinAtEndOfLastAdjointTrack(size_t i=0)