46 #include "G4THitsCollection.hh"
62 :fAccumulated_edep(0.), fAccumulated_edep2(0.), fMean_edep(0.),
63 fError_mean_edep(0.), fRelative_error(0.), fElapsed_time(0.),
64 fPrecision_to_reach(0.),fStop_run_if_precision_reached(true),
65 fNb_evt_modulo_for_convergence_test(5000),
66 fEdep_rmatrix_vs_electron_prim_energy(0),
67 fElectron_current_rmatrix_vs_electron_prim_energy(0),
68 fGamma_current_rmatrix_vs_electron_prim_energy(0),
69 fEdep_rmatrix_vs_gamma_prim_energy(0),
70 fElectron_current_rmatrix_vs_gamma_prim_energy(0),
71 fGamma_current_rmatrix_vs_gamma_prim_energy(0),
72 fEdep_rmatrix_vs_proton_prim_energy(0),
73 fElectron_current_rmatrix_vs_proton_prim_energy(0),
74 fProton_current_rmatrix_vs_proton_prim_energy(0),
75 fGamma_current_rmatrix_vs_proton_prim_energy(0),
77 fPrimSpectrumType(
EXPO),
78 fAlpha_or_E0(.5*
MeV),fAmplitude_prim_spectrum (1.),
79 fEmin_prim_spectrum(1.*
keV),fEmax_prim_spectrum (20.*
MeV),
80 fAdjoint_sim_mode(true),fNb_evt_per_adj_evt(2)
134 "Normalised Edep[MeV]\terror[MeV]\tcomputing_time[s]"<<std::endl;
140 "Edep per event [MeV]\terror[MeV]\tcomputing_time[s]"
159 G4cout<<
"Results of forward simulation!"<<std::endl;
165 G4cout<<
"Results of reverse/adjoint simulation!"<<std::endl;
196 nb_event =
static_cast<G4int>(n_adj_evt);
249 for (i=0;i<edepCollection->
entries();i++)
250 totEdep+=(*edepCollection)[i]->GetValue()
251 *(*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();
270 G4double weight=(*electronCurrentCollection)[i]->GetWeight();
274 for (i=0;i<protonCurrentCollection->
entries();i++) {
275 G4double ekin =(*protonCurrentCollection)[i]->GetValue();
276 G4double weight=(*protonCurrentCollection)[i]->GetWeight();
280 for (i=0;i<gammaCurrentCollection->
entries();i++) {
281 G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
282 G4double weight=(*gammaCurrentCollection)[i]->GetWeight();
318 G4int pdg_nb =theAdjointSimManager
336 G4AnaH2* electron_current_rmatrix =0;
337 G4AnaH2* gamma_current_rmatrix =0;
338 G4AnaH2* proton_current_rmatrix =0;
343 electron_current_rmatrix =
366 for (i=0;i<edepCollection->
entries();i++)
367 totEdep+=(*edepCollection)[i]->GetValue()*
368 (*edepCollection)[i]->GetWeight();
370 G4bool new_mean_computed=
false;
372 if (normalised_weight>0.){
373 G4double edep=totEdep* normalised_weight;
384 if ( new_error >0) new_relative_error = new_error/ new_mean;
386 G4cout<<
"Potential wrong adjoint weight!"<<std::endl;
387 G4cout<<
"The results of this event will not be registered!"
390 G4cout<<
"previous relative error "<< fRelative_error<<std::endl;
391 G4cout<<
"new rejected mean edep [MeV] "<< new_mean<<std::endl;
392 G4cout<<
"new rejected relative error "<< new_relative_error
401 fRelative_error =new_relative_error;
402 new_mean_computed=
true;
410 edep_rmatrix->fill(prim_ekin,totEdep*adj_weight/
cm2);
412 if (!new_mean_computed){
421 for (i=0;i<electronCurrentCollection->
entries();i++) {
422 G4double ekin =(*electronCurrentCollection)[i]->GetValue();
423 G4double weight=(*electronCurrentCollection)[i]->GetWeight();
425 electron_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/
cm2);
428 for (i=0;i<protonCurrentCollection->
entries();i++) {
429 G4double ekin =(*protonCurrentCollection)[i]->GetValue();
430 G4double weight=(*protonCurrentCollection)[i]->GetWeight();
432 proton_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/
cm2);
435 for (i=0;i<gammaCurrentCollection->
entries();i++) {
436 G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
437 G4double weight=(*gammaCurrentCollection)[i]->GetWeight();
439 gamma_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/
cm2);
510 error = factor*std::sqrt(mean_x2-mean*mean)/std::sqrt(
G4double(nb_event));
533 G4cout<<
"The particle that you did select is not in the candidate "<<
534 "list for primary [e-, gamma, proton]!"<<
G4endl;
539 (std::exp(-Emin/E0)-std::exp(-Emax/E0))/4./
pi;
557 G4cout<<
"The particle that you did select is not in the candidate"<<
558 " list for primary [e-, gamma, proton]!"<<
G4endl;
569 -std::pow(Emin,p))/4./
pi;
603 G4cout <<
"\n---> RMC01AnalysisManager::book(): cannot open " <<
fFileName[1]
619 G4String(
"edep vs e- primary energy"),60,emin,emax,
649 G4String(
"electron RM vs e- primary energy"),60,emin,emax,
655 CreateH2(
G4String(
"Electron_current_rmatrix_vs_electron_prim_energy"),
656 G4String(
"electron current RM vs e- primary energy"),
657 60,emin,emax,60,emin,emax,
661 theHistoManager->
GetH2(idHisto);
665 CreateH2(
G4String(
"Gamma_current_rmatrix_vs_electron_prim_energy"),
666 G4String(
"gamma current RM vs e- primary energy"),
667 60,emin,emax,60,emin,emax,
672 theHistoManager->
GetH2(idHisto);
679 G4String(
"electron RM vs gamma primary energy"),60,emin,emax,
685 CreateH2(
G4String(
"Electron_current_rmatrix_vs_gamma_prim_energy"),
686 G4String(
"electron current RM vs gamma primary energy"),
687 60,emin,emax,60,emin,emax,
691 theHistoManager->
GetH2(idHisto);
695 CreateH2(
G4String(
"Gamma_current_rmatrix_vs_gamma_prim_energy"),
696 G4String(
"gamma current RM vs gamma primary energy"),
697 60,emin,emax,60,emin,emax,
701 theHistoManager->
GetH2(idHisto);
708 G4String(
"electron RM vs proton primary energy"),60,emin,emax,
714 CreateH2(
G4String(
"Electron_current_rmatrix_vs_proton_prim_energy"),
715 G4String(
"electron current RM vs proton primary energy"),
716 60,emin,emax,60,emin,emax,
720 theHistoManager->
GetH2(idHisto);
724 CreateH2(
G4String(
"Gamma_current_rmatrix_vs_proton_prim_energy"),
725 G4String(
"gamma current RM vs proton primary energy"),
726 60,emin,emax,60,emin,emax,
730 theHistoManager->
GetH2(idHisto);
734 CreateH2(
G4String(
"Proton_current_rmatrix_vs_proton_prim_energy"),
735 G4String(
"proton current RM vs proton primary energy"),
736 60,emin,emax,60,emin,emax,
740 theHistoManager->
GetH2(idHisto);
754 for (
int ind=1; ind<=theHistoManager->
GetNofH1s();ind++){
756 theHistoManager->
ScaleH1(ind,scaling_factor);
758 for (
int ind=1; ind<=theHistoManager->
GetNofH2s();ind++)
759 theHistoManager->
ScaleH2(ind,scaling_factor);
761 theHistoManager->
Write();
765 delete G4AnalysisManager::Instance();
G4AnaH1 * fEdep_rmatrix_vs_proton_prim_energy
static G4AdjointSimManager * GetInstance()
G4bool SetHistoDirectoryName(const G4String &dirName)
virtual void AbortRun(G4bool softAbort=false)
void SetPrimaryPowerLawSpectrumForAdjointSim(const G4String &particle_name, G4double fluence, G4double alpha, G4double Emin, G4double Emax)
G4ThreeVector GetMomentum() const
G4double fEmax_prim_spectrum
G4AnaH1 * fEdep_rmatrix_vs_electron_prim_energy
G4bool SetFirstHistoId(G4int firstId)
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
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")
tools::histo::h2d G4AnaH2
G4int fNb_evt_per_adj_evt
G4bool ScaleH1(G4int id, G4double factor)
G4bool ScaleH2(G4int id, G4double factor)
G4bool GetAdjointSimMode()
G4double fError_mean_edep
G4AnaH2 * fGamma_current_rmatrix_vs_proton_prim_energy
G4AnaH2 * fElectron_current_rmatrix_vs_electron_prim_energy
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack()
G4int GetPDGEncoding() const
G4AnaH2 * fElectron_current_rmatrix_vs_gamma_prim_energy
void SetPrimaryExpSpectrumForAdjointSim(const G4String &particle_name, G4double fluence, G4double E0, G4double Emin, G4double Emax)
void BeginOfEvent(const G4Event *)
PRIM_SPECTRUM_TYPE fPrimSpectrumType
G4AnaH2 * fProton_current_rmatrix_vs_proton_prim_energy
G4ParticleDefinition * GetG4code() const
G4int GetNbEvtOfLastRun()
Definition of the RMC01SD class.
void save(G4double scaling_factor)
G4AnaH1 * fElectron_current
G4bool fStop_run_if_precision_reached
G4double GetEkinAtEndOfLastAdjointTrack()
G4PrimaryParticle * GetPrimary(G4int i=0) const
G4double fPrecision_to_reach
void SetH1Ascii(G4int id, G4bool ascii)
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
G4AnaH1 * fEdep_vs_prim_ekin
G4String GetFileType() const
G4double fAmplitude_prim_spectrum
static G4Proton * Proton()
void EndOfRun(const G4Run *)
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition of the RMC01AnalysisManager class.
G4AnaH1 * fProton_current
G4double PrimDiffAndDirFluxForAdjointSim(G4double prim_energy)
RMC01AnalysisManagerMessenger * fMsg
static G4RunManager * GetRunManager()
tools::histo::h1d G4AnaH1
void ComputeMeanEdepAndError(const G4Event *anEvent, G4double &mean, G4double &error)
Definition of the RMC01AnalysisManagerMessenger class.
G4double GetPDGMass() const
G4double GetRealElapsed() const
G4double fAccumulated_edep
G4AnaH2 * fGamma_current_rmatrix_vs_electron_prim_energy
G4AnaH2 * fElectron_current_rmatrix_vs_proton_prim_energy
static RMC01AnalysisManager * GetInstance()
static G4SDManager * GetSDMpointer()
void EndOfEvent(const G4Event *)
G4double GetWeightAtEndOfLastAdjointTrack()
G4int fNb_evt_modulo_for_convergence_test
void BeginOfRun(const G4Run *)
static const G4double Emin
G4int GetNumberOfEventToBeProcessed() const
static G4Electron * Electron()
static const G4double Emax
G4double fEmin_prim_spectrum
static PROLOG_HANDLER error
G4HCofThisEvent * GetHCofThisEvent() const
static const G4double alpha
G4AnaH2 * fGamma_current_rmatrix_vs_gamma_prim_energy
tools::histo::h1d * GetH1(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
tools::histo::h2d * GetH2(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
G4double fAccumulated_edep2
std::fstream fConvergenceFileOutput
void EndOfEventForAdjointSimulation(const G4Event *anEvent)
void EndOfEventForForwardSimulation(const G4Event *anEvent)
static RMC01AnalysisManager * fInstance
G4AnaH1 * fEdep_rmatrix_vs_gamma_prim_energy