ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
G4UA::TestActionEHist Class Reference

#include <TestActionEHist.h>

Inheritance diagram for G4UA::TestActionEHist:
Collaboration diagram for G4UA::TestActionEHist:

Classes

struct  Config
 

Public Member Functions

 TestActionEHist (const Config &config)
 
virtual void PreUserTrackingAction (const G4Track *) override
 
virtual void PostUserTrackingAction (const G4Track *) override
 
virtual void BeginOfRunAction (const G4Run *) override
 
virtual void EndOfRunAction (const G4Run *) override
 
virtual void UserSteppingAction (const G4Step *) override
 

Private Member Functions

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. More...
 
bool BuildDirs (const std::string &vol_tag, const std::string &dirTitle, int &dLeft)
 Remaining directories to create. More...
 

Private Attributes

Config m_config
 holds the python configuration More...
 
TFile * m_world
 File in which to store neutron & electron info. More...
 
bool m_firstStep
 Flag indicating whether step is first in current volume. More...
 
std::string m_p_tag
 Used to specify current particle in tracking. More...
 
std::vector< std::string > m_trajectory
 Used to store volume names which the current track has entered. More...
 

Detailed Description

Definition at line 46 of file TestActionEHist.h.

Constructor & Destructor Documentation

◆ TestActionEHist()

G4UA::TestActionEHist::TestActionEHist ( const Config config)

Definition at line 44 of file TestActionEHist.cxx.

45  : m_config(config), m_world(0), m_firstStep(false), m_p_tag("")
46  {
47  }

Member Function Documentation

◆ BeginOfRunAction()

void G4UA::TestActionEHist::BeginOfRunAction ( const G4Run *  )
overridevirtual

Definition at line 72 of file TestActionEHist.cxx.

73  {
74  // initialize histogramming file (DON'T USE GAUDI) & directories
75  delete m_world;
76  m_world = new TFile(m_config.name.c_str(), "RECREATE");
77  G4cout<<m_config.name<<" initialized, in directory "<<gDirectory->GetPath()<<G4endl;
78  }

◆ BuildDirs()

bool G4UA::TestActionEHist::BuildDirs ( const std::string &  vol_tag,
const std::string &  dirTitle,
int &  dLeft 
)
private

Remaining directories to create.

Parameters
vol_tagFunction to generate TDirectory objects Tag to identify object by volume
dirTitleDirectory title

Definition at line 180 of file TestActionEHist.cxx.

181  {
182  bool enter = false;
183  TDirectory* dExists = (TDirectory*)gDirectory->FindObjectAny(vol_tag.c_str());
184  if (!dLeft && !dExists) { return enter; }
185  if (!dExists) {
186  dExists = new TDirectoryFile(vol_tag.c_str(),
187  dirTitle.c_str());
188  dLeft--;
189 
190  if (!dLeft) G4cout<<"Last directory created"<<G4endl;
191  }
192 
193  if (dExists) enter = (bool)dExists->cd();
194  // if (enter) ATH_MSG_DEBUG("Current directory: "<<gDirectory->GetPath());
195  return enter;
196  }

◆ BuildHists()

void G4UA::TestActionEHist::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 
)
private

Size of bins in histogram, in MeV.

Parameters
vol_tagFunction to generate TH1-type histograms Tag to identify object by volume
part_tagTag to identify object by particle
hLeftAmount of histogram space remaining, set by maxhists
xfillParameter to fill histogram along x
yfillParamteter to fill histogram along y
nbinsNumber of bins in histogram

Definition at line 158 of file TestActionEHist.cxx.

161  {
162  TH1F* hExists =
163  (TH1F*)gDirectory->FindObjectAny((part_tag+"_"+vol_tag+"_hist").c_str());
164  if (!hLeft && !hExists) { return; }
165  else if (!hExists) {
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);
169  hLeft--;
170  //G4cout<<"Histogram "<<gDirectory->GetPath()<<"/"<<hExists->GetName()<<" created"<<G4endl;
171  if (!hLeft) G4cout<<"Last histogram reached"<<G4endl;
172  }
173 
174  if (xfill >= 0 && weight >= 0) { hExists->Fill(xfill,weight); }
175  else if (xfill >= 0) { hExists->Fill(xfill); }
176  else { return; }
177  }

◆ EndOfRunAction()

void G4UA::TestActionEHist::EndOfRunAction ( const G4Run *  )
overridevirtual

Definition at line 80 of file TestActionEHist.cxx.

81  {
82  m_world->Write();
83  m_world->Close();
84  delete m_world;
85  G4cout<<m_config.name<<" saved & closed."<<G4endl;
86  }

◆ PostUserTrackingAction()

void G4UA::TestActionEHist::PostUserTrackingAction ( const G4Track *  aTrack)
overridevirtual

Definition at line 65 of file TestActionEHist.cxx.

66  {
67  if (aTrack) {
68  m_trajectory.clear();
69  }
70  }

◆ PreUserTrackingAction()

void G4UA::TestActionEHist::PreUserTrackingAction ( const G4Track *  aTrack)
overridevirtual

Definition at line 50 of file TestActionEHist.cxx.

51  {
52  if (aTrack) {
53 
54  // Set Particle label and empty trajectory
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(); }
61  if (!m_trajectory.empty()) m_trajectory.clear();
62  }
63  }

◆ UserSteppingAction()

void G4UA::TestActionEHist::UserSteppingAction ( const G4Step *  aStep)
overridevirtual

Definition at line 88 of file TestActionEHist.cxx.

89  {
90  if (aStep) {
91 
92  // Create tree structure for current step
93  VolumeTreeNavigator currentTree( aStep );
94 
95  // check for processes which don't need to be histogrammed
96  //if ( currentTree.KillProcesses( 2, "nKiller", "G4FastSimulationManagerProcess" ) ) return;
97 
98  // Stores a list of the names of leaf-node volumes which the track has entered
99  // and checks it for earlier occurences of the same volume
100  m_firstStep = true;
101  if (currentTree.GetStepNumber() > 1) {
102  for ( vector<string>::const_iterator it = m_trajectory.begin();
103  it != m_trajectory.end(); ++it ) {
104  if ( *it == stringify( currentTree.GetVolume()->GetName() ) ) {
105  m_firstStep = false;
106  break;
107  }
108  }
109  }
110 
111  // For particles' first step in the current volume
112  if (m_firstStep) {
113  // push_back trajectory element
114  m_trajectory.push_back( stringify( currentTree.GetVolume()->GetName() ) );
115 
116  // set depth cut (MUST implement Simple if Detail is used)
117  currentTree.SetDepthCutSimple(m_config.dCALO, m_config.dBeam, m_config.dIDET, m_config.dMUON);
118  // Detailed depth cut format: /Atlas::Atlas/[level 1]/[level 2]/.../[last directory level]
119  if ( !m_config.dDetail.empty() ) {
120  currentTree.SetDepthCutDetail( m_config.dDetail.c_str() );
121  }
122 
123  //for( auto histelement : currentTree.GetHistory())
124  // std::cout<<histelement.first->GetName()<< std::endl;
125  //std::cout<<"end dump tree "<<std::endl;
126  //std::cout<<"before ascending "<<currentTree.GetVolume()->GetName()<<std::endl;
127 
128  // go to ATLAS::ATLAS
129  currentTree.Ascend( currentTree.GetCurrentDepth() );
130 
131  while ( true ) {
132  // collect naming info for histogram
133  G4VPhysicalVolume* pv = currentTree.GetVolume();
134  string thPV = cleanstr(pv->GetName());
135  string thNoDau = stringify(pv->GetLogicalVolume()->GetNoDaughters());
136  int thRep = currentTree.GetCopyNumber();
137 
138  // construct keyname & directory title
139  string v_name = (thRep == 16969 ? thPV : thPV+"_"+stringify(thRep));
140  string p_name = m_p_tag + ( currentTree.GetStepNumber() != 1 ? "_entred" : "_madein" );
141  string title = thNoDau+" daughters, "+stringify(currentTree.GetCurrentDepth())+" from base";
142 
143  // Build and fill histogram at bottom of tree, then build dir and cd to it
144  if ( currentTree.GetStepNumber() == 1 || currentTree.GetCurrentDepth() == currentTree.GetFullDepth() ) {
145  BuildHists(v_name, p_name, m_config.maxhists, currentTree.GetPreStepPoint()->GetKineticEnergy());
146  }
147  if ( !currentTree.Descend() ) break;
148  if ( !BuildDirs(v_name, title, m_config.maxdirs) ) break;
149  }
150 
151  // Return to world to get ready for next step... FINALLY
152  m_world->cd();
153  }
154  }
155  }

Member Data Documentation

◆ m_config

Config G4UA::TestActionEHist::m_config
private

holds the python configuration

Definition at line 71 of file TestActionEHist.h.

◆ m_firstStep

bool G4UA::TestActionEHist::m_firstStep
private

Flag indicating whether step is first in current volume.

Definition at line 75 of file TestActionEHist.h.

◆ m_p_tag

std::string G4UA::TestActionEHist::m_p_tag
private

Used to specify current particle in tracking.

Definition at line 77 of file TestActionEHist.h.

◆ m_trajectory

std::vector<std::string> G4UA::TestActionEHist::m_trajectory
private

Used to store volume names which the current track has entered.

Definition at line 79 of file TestActionEHist.h.

◆ m_world

TFile* G4UA::TestActionEHist::m_world
private

File in which to store neutron & electron info.

Definition at line 73 of file TestActionEHist.h.


The documentation for this class was generated from the following files:
G4UA::TestActionEHist::BuildHists
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.
Definition: TestActionEHist.cxx:158
VolumeTreeNavigator
Definition: VolumeTreeNavigator.h:39
skel.it
it
Definition: skel.GENtoEVGEN.py:423
G4UA::TestActionEHist::BuildDirs
bool BuildDirs(const std::string &vol_tag, const std::string &dirTitle, int &dLeft)
Remaining directories to create.
Definition: TestActionEHist.cxx:180
cleanstr
std::string cleanstr(T obj)
Definition: VolumeTreeNavigator.h:81
G4UA::TestActionEHist::m_trajectory
std::vector< std::string > m_trajectory
Used to store volume names which the current track has entered.
Definition: TestActionEHist.h:79
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
G4UA::TestActionEHist::Config::dMUON
int dMUON
Used for depth limits applied in jobOptions.
Definition: TestActionEHist.h:57
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
G4UA::TestActionEHist::Config::dIDET
int dIDET
Definition: TestActionEHist.h:56
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
stringify
std::string stringify(T obj)
Definition: VolumeTreeNavigator.h:73
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
G4UA::TestActionEHist::Config::dBeam
int dBeam
Definition: TestActionEHist.h:55
G4UA::TestActionEHist::m_firstStep
bool m_firstStep
Flag indicating whether step is first in current volume.
Definition: TestActionEHist.h:75
G4UA::TestActionEHist::Config::maxdirs
int maxdirs
Used to set maximum number of histograms/directories from jobOptions.
Definition: TestActionEHist.h:59
covarianceTool.title
title
Definition: covarianceTool.py:542
G4UA::TestActionEHist::m_world
TFile * m_world
File in which to store neutron & electron info.
Definition: TestActionEHist.h:73
G4UA::TestActionEHist::Config::dDetail
std::string dDetail
Path used to set detailed depth cuts.
Definition: TestActionEHist.h:60
G4UA::TestActionEHist::m_config
Config m_config
holds the python configuration
Definition: TestActionEHist.h:71
G4UA::TestActionEHist::m_p_tag
std::string m_p_tag
Used to specify current particle in tracking.
Definition: TestActionEHist.h:77
TH1F
Definition: rootspy.cxx:320
G4UA::TestActionEHist::Config::maxhists
int maxhists
Definition: TestActionEHist.h:58
python.changerun.pv
pv
Definition: changerun.py:81
G4UA::TestActionEHist::Config::name
std::string name
Name of root output file.
Definition: TestActionEHist.h:61
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
G4UA::TestActionEHist::Config::dCALO
int dCALO
Definition: TestActionEHist.h:54
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60