60 :fAccumulated_edep(0.), fAccumulated_edep2(0.), fMean_edep(0.),
61 fError_mean_edep(0.), fRelative_error(0.), fElapsed_time(0.),
62 fPrecision_to_reach(0.),fStop_run_if_precision_reached(true),
63 fNb_evt_modulo_for_convergence_test(5000),
64 fEdep_rmatrix_vs_electron_prim_energy(0),
65 fElectron_current_rmatrix_vs_electron_prim_energy(0),
66 fGamma_current_rmatrix_vs_electron_prim_energy(0),
67 fEdep_rmatrix_vs_gamma_prim_energy(0),
68 fElectron_current_rmatrix_vs_gamma_prim_energy(0),
69 fGamma_current_rmatrix_vs_gamma_prim_energy(0),
70 fEdep_rmatrix_vs_proton_prim_energy(0),
71 fElectron_current_rmatrix_vs_proton_prim_energy(0),
72 fProton_current_rmatrix_vs_proton_prim_energy(0),
73 fGamma_current_rmatrix_vs_proton_prim_energy(0),
75 fPrimSpectrumType(
EXPO),
76 fAlpha_or_E0(.5*MeV),fAmplitude_prim_spectrum (1.),
77 fEmin_prim_spectrum(1.*keV),fEmax_prim_spectrum (20.*MeV),
78 fAdjoint_sim_mode(true),fNb_evt_per_adj_evt(2)
93 fPrimPDG_ID = G4Electron::Electron()->GetPDGEncoding();
228 (HCE->GetHC(SDman->GetCollectionID(
"edep")));
232 (HCE->GetHC(SDman->GetCollectionID(
"current_electron")));
236 (HCE->GetHC(SDman->GetCollectionID(
"current_proton")));
240 (HCE->GetHC(SDman->GetCollectionID(
"current_gamma")));
246 for (i=0;i<edepCollection->entries();++i)
247 totEdep+=(*edepCollection)[i]->GetValue()
248 *(*edepCollection)[i]->GetWeight();
255 anEvent->GetPrimaryVertex()->GetPrimary();
256 G4double E0= thePrimary->GetG4code()->GetPDGMass();
257 G4double P=thePrimary->GetMomentum().mag();
258 G4double prim_ekin =std::sqrt(E0*E0+P*P)-E0;
267 for (i=0;i<electronCurrentCollection->entries();++i) {
268 G4double ekin =(*electronCurrentCollection)[i]->GetValue();
269 G4double weight=(*electronCurrentCollection)[i]->GetWeight();
273 for (i=0;i<protonCurrentCollection->entries();++i) {
274 G4double ekin =(*protonCurrentCollection)[i]->GetValue();
275 G4double weight=(*protonCurrentCollection)[i]->GetWeight();
279 for (i=0;i<gammaCurrentCollection->entries();++i) {
280 G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
281 G4double weight=(*gammaCurrentCollection)[i]->GetWeight();
298 HCE->GetHC(SDman->GetCollectionID(
"edep")));
302 HCE->GetHC(SDman->GetCollectionID(
"current_electron")));
306 HCE->GetHC(SDman->GetCollectionID(
"current_proton")));
310 HCE->GetHC(SDman->GetCollectionID(
"current_gamma")));
316 for (i=0;i<edepCollection->entries();++i)
317 totEdep+=(*edepCollection)[i]->GetValue()*
318 (*edepCollection)[i]->GetWeight();
324 G4AdjointSimManager::GetInstance();
326 size_t nb_adj_track =
327 theAdjointSimManager->GetNbOfAdointTracksReachingTheExternalSurface();
328 G4double total_normalised_weight = 0.;
332 for (std::size_t j=0;j<nb_adj_track;++j) {
334 G4int pdg_nb =theAdjointSimManager
335 ->GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(j);
336 G4double prim_ekin=theAdjointSimManager
337 ->GetEkinAtEndOfLastAdjointTrack(j);
338 G4double adj_weight=theAdjointSimManager
339 ->GetWeightAtEndOfLastAdjointTrack(j);
344 G4double normalised_weight = 0.;
349 total_normalised_weight += normalised_weight;
353 G4H1* edep_rmatrix =0;
354 G4H2* electron_current_rmatrix =0;
355 G4H2* gamma_current_rmatrix =0;
356 G4H2* proton_current_rmatrix =0;
358 if (pdg_nb == G4Electron::Electron()->GetPDGEncoding()){
360 electron_current_rmatrix =
364 else if (pdg_nb == G4Gamma::Gamma()->GetPDGEncoding()){
370 else if (pdg_nb == G4Proton::Proton()->GetPDGEncoding()){
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();
391 G4double weight=(*electronCurrentCollection)[i]->GetWeight();
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();
397 G4double weight=(*protonCurrentCollection)[i]->GetWeight();
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();
403 G4double weight=(*gammaCurrentCollection)[i]->GetWeight();
405 gamma_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/cm2);
411 G4bool new_mean_computed=
false;
413 if (total_normalised_weight>0.){
414 G4double edep=totEdep* total_normalised_weight;
418 G4double new_mean(0.0), new_error(0.0);
423 G4double new_relative_error = 1.;
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!"
429 G4cout<<
"previous mean edep [MeV] "<<
fMean_edep<<std::endl;
431 G4cout<<
"new rejected mean edep [MeV] "<< new_mean<<std::endl;
432 G4cout<<
"new rejected relative error "<< new_relative_error
443 new_mean_computed=
true;
448 if (!new_mean_computed){
571 const G4String& particle_name, G4double omni_fluence,
572 G4double alpha, G4double Emin,G4double Emax)
575 G4Electron::Electron()->GetPDGEncoding();
577 G4Gamma::Gamma()->GetPDGEncoding();
579 G4Proton::Proton()->GetPDGEncoding();
581 G4cout<<
"The particle that you did select is not in the candidate"<<
582 " list for primary [e-, gamma, proton]!"<<G4endl;
593 -std::pow(Emin,p))/4./pi;
612 G4double emin=1.*keV;
613 G4double emax=1.*GeV;
620 G4AnalysisManager* theHistoManager = G4AnalysisManager::Instance();
621 theHistoManager->SetDefaultFileType(
"root");
622 G4String extension = theHistoManager->GetFileType();
624 theHistoManager->SetFirstHistoId(1);
626 G4bool fileOpen = theHistoManager->OpenFile(
fFileName[0]);
628 G4cout <<
"\n---> RMC01AnalysisManager::Book(): cannot open "
635 theHistoManager->SetHistoDirectoryName(
"histo");
643 theHistoManager->CreateH1(
G4String(
"Edep_vs_prim_ekin"),
644 G4String(
"edep vs e- primary energy"),60,emin,emax,
648 idHisto = theHistoManager->CreateH1(
G4String(
"elecron_current"),
654 idHisto= theHistoManager->CreateH1(
G4String(
"proton_current"),
659 idHisto= theHistoManager->CreateH1(
G4String(
"gamma_current"),
671 theHistoManager->CreateH1(
G4String(
"Edep_rmatrix_vs_electron_prim_energy"),
672 G4String(
"electron RM vs e- primary energy"),60,emin,emax,
678 CreateH2(
G4String(
"Electron_current_rmatrix_vs_electron_prim_energy"),
679 G4String(
"electron current RM vs e- primary energy"),
680 60,emin,emax,60,emin,emax,
684 theHistoManager->GetH2(idHisto);
688 CreateH2(
G4String(
"Gamma_current_rmatrix_vs_electron_prim_energy"),
689 G4String(
"gamma current RM vs e- primary energy"),
690 60,emin,emax,60,emin,emax,
694 theHistoManager->GetH2(idHisto);
699 theHistoManager->CreateH1(
G4String(
"Edep_rmatrix_vs_gamma_prim_energy"),
700 G4String(
"electron RM vs gamma primary energy"),60,emin,emax,
706 CreateH2(
G4String(
"Electron_current_rmatrix_vs_gamma_prim_energy"),
707 G4String(
"electron current RM vs gamma primary energy"),
708 60,emin,emax,60,emin,emax,
712 theHistoManager->GetH2(idHisto);
716 CreateH2(
G4String(
"Gamma_current_rmatrix_vs_gamma_prim_energy"),
717 G4String(
"gamma current RM vs gamma primary energy"),
718 60,emin,emax,60,emin,emax,
722 theHistoManager->GetH2(idHisto);
726 theHistoManager->CreateH1(
G4String(
"Edep_rmatrix_vs_proton_prim_energy"),
727 G4String(
"electron RM vs proton primary energy"),60,emin,emax,
733 CreateH2(
G4String(
"Electron_current_rmatrix_vs_proton_prim_energy"),
734 G4String(
"electron current RM vs proton primary energy"),
735 60,emin,emax,60,emin,emax,
739 theHistoManager->GetH2(idHisto);
743 CreateH2(
G4String(
"Gamma_current_rmatrix_vs_proton_prim_energy"),
744 G4String(
"gamma current RM vs proton primary energy"),
745 60,emin,emax,60,emin,emax,
749 theHistoManager->GetH2(idHisto);
753 CreateH2(
G4String(
"Proton_current_rmatrix_vs_proton_prim_energy"),
754 G4String(
"proton current RM vs proton primary energy"),
755 60,emin,emax,60,emin,emax,
759 theHistoManager->GetH2(idHisto);
762 G4cout <<
"\n----> Histogram Tree is opened in " <<
fFileName[1] << G4endl;
769 G4AnalysisManager* theHistoManager = G4AnalysisManager::Instance();
773 for (G4int ind=1; ind<=theHistoManager->GetNofH1s();++ind){
774 theHistoManager->SetH1Ascii(ind,
true);
775 theHistoManager->ScaleH1(ind,scaling_factor);
777 for (G4int ind=1; ind<=theHistoManager->GetNofH2s();++ind)
778 theHistoManager->ScaleH2(ind,scaling_factor);
780 theHistoManager->Write();
781 theHistoManager->CloseFile();
782 G4cout <<
"\n----> Histogram Tree is saved in " <<
fFileName[1] << G4endl;
784 theHistoManager->Clear();