22#include "G4Electron.hh"
24#include "G4Positron.hh"
25#include "G4ParticleDefinition.hh"
26#include "G4TouchableHistory.hh"
27#include "G4VPhysicalVolume.hh"
28#include "G4LogicalVolume.hh"
29#include "G4VProcess.hh"
36using std::stringstream;
55 G4ParticleDefinition* pDef = aTrack->GetDefinition();
56 const G4String& pName = pDef->GetParticleName();
57 const G4String& pSubType = pDef->GetParticleSubType();
58 if (pName ==
"neutron" || pName ==
"proton" ) {
m_p_tag = pName; }
59 else if (pSubType ==
"e" || pSubType ==
"pi" ) {
m_p_tag = pSubType; }
60 else {
m_p_tag = pDef->GetParticleType(); }
77 G4cout<<
m_config.name<<
" initialized, in directory "<<gDirectory->GetPath()<<G4endl;
85 G4cout<<
m_config.name<<
" saved & closed."<<G4endl;
102 for ( vector<string>::const_iterator it =
m_trajectory.begin();
133 G4VPhysicalVolume* pv = currentTree.
GetVolume();
134 string thPV =
cleanstr(pv->GetName());
135 string thNoDau =
stringify(pv->GetLogicalVolume()->GetNoDaughters());
139 string v_name = (thRep == 16969 ? std::move(thPV) : thPV+
"_"+
stringify(thRep));
147 if ( !currentTree.
Descend() )
break;
159 double xfill,
double weight,
const int nbins,
163 (TH1F*)gDirectory->FindObjectAny((part_tag+
"_"+vol_tag+
"_hist").c_str());
164 if (!hLeft && !hExists) {
return; }
166 hExists =
new TH1F((part_tag+
"_"+vol_tag+
"_hist").c_str(),
167 (part_tag+
" KE in "+vol_tag).c_str(),
168 nbins,0,nbins*binsize);
171 if (!hLeft) G4cout<<
"Last histogram reached"<<G4endl;
174 if (xfill >= 0 && weight >= 0) { hExists->Fill(xfill,weight); }
175 else if (xfill >= 0) { hExists->Fill(xfill); }
183 TDirectory* dExists = (TDirectory*)gDirectory->FindObjectAny(vol_tag.c_str());
184 if (!dLeft && !dExists) {
return enter; }
186 dExists =
new TDirectoryFile(vol_tag.c_str(),
190 if (!dLeft) G4cout<<
"Last directory created"<<G4endl;
193 if (dExists) enter = (bool)dExists->cd();
std::string cleanstr(T obj)
std::string stringify(T obj)
TestActionEHist(const Config &config)
Config m_config
holds the python configuration
void BuildHists(const std::string &vol_tag, const std::string &part_tag, int &hLeft, double xfill=-1, double yfill=-1, const int nbins=3000, const int binsize=1)
Size of bins in histogram, in MeV.
virtual void EndOfRunAction(const G4Run *) override
bool BuildDirs(const std::string &vol_tag, const std::string &dirTitle, int &dLeft)
Remaining directories to create.
virtual void PreUserTrackingAction(const G4Track *) override
std::string m_p_tag
Used to specify current particle in tracking.
bool m_firstStep
Flag indicating whether step is first in current volume.
TFile * m_world
File in which to store neutron & electron info.
std::vector< std::string > m_trajectory
Used to store volume names which the current track has entered.
virtual void UserSteppingAction(const G4Step *) override
virtual void PostUserTrackingAction(const G4Track *) override
virtual void BeginOfRunAction(const G4Run *) override
int GetStepNumber() const
bool Ascend(int levels=1)
G4VPhysicalVolume * GetVolume(int rel=0) const
int GetCopyNumber(int rel=0) const
void SetDepthCutDetail(const char *)
bool Descend(int levels=1)
void SetDepthCutSimple(const int, const int, const int, const int)
const G4StepPoint * GetPreStepPoint() const