Skip to content
Snippets Groups Projects
Commit 72800593 authored by Marilena Bandieramonte's avatar Marilena Bandieramonte
Browse files

Add stepping histograms generation to the Event Action

The stepping action create different histograms to track stepping quantities, such as step kinetic energy, step pseudorapidity,
step length and other quantities. The histograms are merged automatically by each worker thread at the end of the run
and saved in a ROOT file. No dependency on ROOT is introduced.
parent 833c2e54
No related branches found
No related tags found
No related merge requests found
......@@ -4,21 +4,126 @@
#include "globals.hh"
#include "G4UserSteppingAction.hh"
#include "MyRunAction.hh"
class MyEventAction;
class G4Step;
class MySteppingAction : public G4UserSteppingAction {
public:
MySteppingAction(MyEventAction* evtact);
MySteppingAction(MyEventAction* evtact, MyRunAction* run);
virtual ~MySteppingAction();
virtual void UserSteppingAction(const G4Step*);
// maps to hold info per volume/process/material per particle type
//typedef std::map<G4String, TH1*> HistoMap_t;
typedef std::map<G4String, int> HistoMap_t;
typedef std::map<G4String, HistoMap_t> HistoMapMap_t;
/// this holds all the data from individual threads that needs to be merged at EoR
struct Report
{
// distributions per volume per particle type
HistoMapMap_t histoMapMap_vol_stepSize;
HistoMapMap_t histoMapMap_vol_stepKineticEnergy;
HistoMapMap_t histoMapMap_vol_postStepKineticEnergy;
HistoMapMap_t histoMapMap_vol_stepPseudorapidity;
HistoMapMap_t histoMapMap_vol_stepEnergyDeposit;
HistoMapMap_t histoMapMap_vol_stepEnergyNonIonDeposit;
HistoMapMap_t histoMapMap_vol_stepSecondaryKinetic;
HistoMapMap_t histoMapMap_vol_numberOfSteps;
HistoMapMap_t histoMapMap_vol_numberOfStepsPerInitialE;
HistoMapMap_t histoMapMap_vol_trackLengthPerInitialE;
HistoMapMap_t histoMapMap_vol_InitialE;
// distributions per material per particle type
HistoMapMap_t histoMapMap_mat_stepSize;
HistoMapMap_t histoMapMap_mat_stepKineticEnergy;
HistoMapMap_t histoMapMap_mat_postStepKineticEnergy;
HistoMapMap_t histoMapMap_mat_stepPseudorapidity;
HistoMapMap_t histoMapMap_mat_stepEnergyDeposit;
HistoMapMap_t histoMapMap_mat_stepEnergyNonIonDeposit;
HistoMapMap_t histoMapMap_mat_stepSecondaryKinetic;
HistoMapMap_t histoMapMap_mat_numberOfSteps;
HistoMapMap_t histoMapMap_mat_numberOfStepsPerInitialE;
HistoMapMap_t histoMapMap_mat_trackLengthPerInitialE;
HistoMapMap_t histoMapMap_mat_InitialE;
// distributions per process per particle type
HistoMapMap_t histoMapMap_prc_stepSize;
HistoMapMap_t histoMapMap_prc_stepKineticEnergy;
HistoMapMap_t histoMapMap_prc_postStepKineticEnergy;
HistoMapMap_t histoMapMap_prc_stepPseudorapidity;
HistoMapMap_t histoMapMap_prc_stepEnergyDeposit;
HistoMapMap_t histoMapMap_prc_stepEnergyNonIonDeposit;
HistoMapMap_t histoMapMap_prc_stepSecondaryKinetic;
HistoMapMap_t histoMapMap_prc_numberOfSteps;
HistoMapMap_t histoMapMap_prc_numberOfStepsPerInitialE;
HistoMapMap_t histoMapMap_prc_trackLengthPerInitialE;
HistoMapMap_t histoMapMap_prc_InitialE;
// all atlas
HistoMapMap_t histoMapMap_numberOfSteps;
HistoMapMap_t histoMapMap_numberOfStepsPerInitialE;
HistoMapMap_t histoMapMap_trackLengthPerInitialE;
HistoMapMap_t histoMapMap_InitialE;
HistoMapMap_t histoMapMap_stepKinetic;
HistoMapMap_t histoMapMap_postStepKinetic;
// 2D maps
HistoMapMap_t histoMapMap2D_vol_RZ;
HistoMapMap_t histoMapMap2D_mat_RZ;
HistoMapMap_t histoMapMap2D_prc_RZ;
HistoMapMap_t histoMapMap2D_vol_RZ_E;
HistoMapMap_t histoMapMap2D_mat_RZ_E;
// rather complicated function that merges two maps
void mergeMaps(HistoMapMap_t &selfMap, const HistoMapMap_t& refMap);
// function needed by ActionToolBaseReport base class
void merge(const Report & rep);
};
/// ctor
//StepHistogram(const Config&);
const Report& getReport() const { return m_report; }
private:
//Pointer to the run action
MyRunAction* m_run;
MyEventAction* fEventAction;
// report
Report m_report;
// initialize and fill histogram in a map
void InitializeFillHistogram2D(HistoMapMap_t &hMapMap, const char* suffix,
const G4String& pdgId, const G4String& vol,
int nbinsx, double xmin, double xmax,
int nbinsy, double ymin, double ymax,
double valuex, double valuey, double weight);
void InitializeFillHistogram(HistoMapMap_t &hMapMap, const char* suffix,
const G4String& pdgId, const G4String& vol,
int nbins, double xmin, double xmax, double value, double weight);
void InitializeFillHistogram(HistoMapMap_t &hMapMap, const char* suffix,
const G4String& pdgId, const G4String& vol,
int nbins, double *edges, double value, double weight);
float m_initialKineticEnergyOfStep;
G4String m_initialVolume;
G4String m_initialMaterial;
G4String m_initialProcess;
int m_trackID;
};
#endif
......@@ -61,7 +61,7 @@ void MyActionInitialization::Build() const {
MyEventAction* evtact = new MyEventAction();
SetUserAction(evtact);
SetUserAction(new MyTrackingAction(evtact));
SetUserAction(new MySteppingAction(evtact));
SetUserAction(new MySteppingAction(evtact, runact));
}
else
......
......@@ -23,7 +23,7 @@ MyRunAction::MyRunAction(bool isGeantino, G4String geantinoMapFilename) : G4User
}
MyRunAction::~MyRunAction() {
if(fIsGeantino)
//if(fIsGeantino)
delete G4AnalysisManager::Instance();
}
......@@ -97,11 +97,40 @@ void MyRunAction::BeginOfRunAction(const G4Run* /*aRun*/){
analysisManager->SetP1YAxisTitle(fEtaInt_id,"Interaction Length #lambda");
}
}
//Create step histograms only if not geantino simulation
else
{
//here create the "DEFAULT ONES"
// Create analysis manager
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
if (isMaster) {
fMasterAnalysisManager = analysisManager;
G4cout<<"MyRunAction::BeginOfRunAction, created MASTER istance of the G4AnalysisManager: "<<fMasterAnalysisManager<<G4endl;
}
G4cout<<"MyRunAction::BeginOfRunAction, created WORKER istance of the G4AnalysisManager: "<<analysisManager<<G4endl;
G4cout << "Using G4AnalysisManager type: " << analysisManager->GetType() << G4endl;
analysisManager->SetVerboseLevel(1);
G4String histoFileName = "Histo.root"; //TO DO : customizable
// Open output root file
G4cout<<"\n\nBeginOfRunAction: \n...create a root file using the G4AnalysisManager" << G4endl;
if (!analysisManager->OpenFile(histoFileName)){
G4cout<<"\nBeginOfRunAction ERROR: File cannot be opened!"<<G4endl;
exit(-1);
} else
G4cout<<"\n...output File "<<histoFileName<<" opened!"<<G4endl;
///There are no global/default histograms to create
}
if (isMaster) {
//G4cout<<"\nBeginOfRunAction isMaster, and fMasterAnalysisManager: "<<fMasterAnalysisManager<<G4endl;
G4cout<<"\nBeginOfRunAction isMaster, and fMasterAnalysisManager: "<<fMasterAnalysisManager<<G4endl;
std::vector<G4Region*>* regionVect = G4RegionStore::GetInstance();
int numRegions = regionVect->size();
......@@ -141,7 +170,7 @@ void MyRunAction::BeginOfRunAction(const G4Run* /*aRun*/){
fTimer = new G4Timer();
fTimer->Start();
}
//else G4cout<<"BeginOfRunAction isWorker, and fMasterAnalysisManager: "<<fMasterAnalysisManager<<G4endl;
else G4cout<<"BeginOfRunAction isWorker, and fMasterAnalysisManager: "<<fMasterAnalysisManager<<G4endl;
}
......@@ -159,6 +188,20 @@ void MyRunAction::EndOfRunAction(const G4Run*) {
G4cout<<"Output File successfully saved and closed! " << G4endl;
}
}
//Histogram stepping action TO DO: remove duplication of code?
else {
auto analysisManager= G4AnalysisManager::Instance();
//Finalize analysisManager and Write out file
if (analysisManager->IsOpenFile()){
G4cout<<"\n\n EndOfRunAction, writing output file: "<<analysisManager->GetFileName() << G4endl;
analysisManager->Write();
G4cout<<"... closing histogramming step file: "<<analysisManager->GetFileName() << G4endl;
analysisManager->CloseFile();
G4cout<<"Output File successfully saved and closed! " << G4endl;
}
}
if (isMaster) {
fTimer->Stop();
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment