21 class G4LogicalVolume;
27 namespace Simulation {
55 typedef std::vector<StepInfo*>
Steps;
68 virtual void operator()(
const G4Step* step, G4SteppingManager* mgr);
70 virtual void begin(
const G4Track* track);
72 virtual void end(
const G4Track* track);
95 #include "CLHEP/Units/SystemOfUnits.h"
96 #include "G4LogicalVolume.hh"
97 #include "G4Material.hh"
100 using namespace DD4hep::Simulation;
107 : pre(prePos), post(postPos), volume(vol)
112 Geant4MaterialScanner::StepInfo::StepInfo(
const StepInfo& c)
113 : pre(c.pre), post(c.post), volume(c.volume)
146 string prePath = pre_handler.
path();
148 string postPath = post_handler.
path();
150 G4LogicalVolume* logVol = h.
logvol(h.
pre);
165 printP2(
"Starting tracking action for track ID=%d",track->GetTrackID());
175 using namespace CLHEP;
177 const char* line =
" +--------------------------------------------------------------------------------------------------------------------------------------------------\n";
178 const char* fmt1 =
" | %5d %-20s %3.0f %8.3f %8.4f %11.4f %11.4f %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n";
179 const char* fmt2 =
" | %5d %-20s %3.0f %8.3f %8.4f %11.6g %11.6g %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n";
183 ::printf(
"%s + Material scan between: x_0 = (%7.2f,%7.2f,%7.2f) [cm] and x_1 = (%7.2f,%7.2f,%7.2f) [cm] TrackID:%d: \n%s",
184 line,pre.X()/
cm,pre.Y()/
cm,pre.Z()/
cm,post.X()/
cm,post.Y()/
cm,post.Z()/
cm,track->GetTrackID(),line);
185 ::printf(
" | \\ %-11s Atomic Radiation Interaction Path Integrated Integrated Material\n",
"Material");
186 ::printf(
" | Num. \\ %-11s Number/Z Mass/A Density Length Length Thickness Length X0 Lambda Endpoint \n",
"Name");
187 ::printf(
" | Layer \\ %-11s [g/mole] [g/cm3] [cm] [cm] [cm] [cm] [cm] [cm] ( cm, cm, cm)\n",
"");
190 for(Steps::const_iterator i=
m_steps.begin(); i!=
m_steps.end(); ++i, ++count) {
191 const G4LogicalVolume* logVol = (*i)->volume;
192 G4Material* material = logVol->GetMaterial();
194 const Position& postPos = (*i)->post;
195 Position direction = postPos - prePos;
196 double length = direction.R()/
cm;
197 double intLen = material->GetNuclearInterLength()/
cm;
198 double radLen = material->GetRadlen()/
cm;
199 double density = material->GetDensity()/(
gram/
cm3);
200 double nLambda = length / intLen;
201 double nx0 = length / radLen;
204 const char* fmt = radLen >= 1e5 ? fmt2 : fmt1;
205 const double* fractions = material->GetFractionVector();
206 for(
size_t j=0; j<material->GetNumberOfElements(); ++j) {
207 Zeff += fractions[j]*(material->GetElement(j)->GetZ());
208 Aeff += fractions[j]*(material->GetElement(j)->GetA())/
gram;
213 ::printf(fmt,count,material->GetName().c_str(),
214 Zeff, Aeff, density, radLen, intLen, length,
216 postPos.X()/
cm,postPos.Y()/
cm,postPos.Z()/
cm);
void callAtEnd(Q *p, void(T::*f)(const G4Track *), CallbackSequence::Location where=CallbackSequence::END)
Register Post-track action callback.
Class to perform directional material scans using Geantinos.
void beginEvent(const G4Event *event)
Registered callback on Begin-event.
Geant4TrackingActionSequence & trackingAction() const
Access to the main tracking action sequence from the kernel object.
std::string path() const
Helper: Access the placement path of a Geant4 touchable object as a string.
~StepInfo()
Default destructor.
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
const G4LogicalVolume * volume
Reference to the logical volue.
void callAtBegin(Q *p, void(T::*f)(const G4Track *), CallbackSequence::Location where=CallbackSequence::END)
Register Pre-track action callback.
static void decrement(T *)
Decrement count according to type information.
Position postPos() const
Returns the post-step position.
virtual ~Geant4MaterialScanner()
Default destructor.
Position pre
Pre-step and Post-step position.
Helper class to ease the extraction of information from a G4Step object.
virtual void begin(const G4Track *track)
Begin-of-tracking callback.
Geant4Context * context() const
Access the context.
void printP2(const char *fmt,...) const
Support for messages with variable output level using output level+2.
const std::string & name() const
Access name of the action.
void callAtBegin(Q *p, void(T::*f)(const G4Event *))
Register begin-of-event callback.
Concrete implementation of the Geant4 stepping action sequence.
Functor to delete objects from heap and reset the pointer.
virtual void end(const G4Track *track)
End-of-tracking callback.
Position prePos() const
Returns the pre-step position.
virtual void operator()(const G4Step *step, G4SteppingManager *mgr)
User stepping callback.
Helper class to ease the extraction of information from a G4Touchable object.
ROOT::Math::XYZVector Position
bool m_needsControl
Default property: Flag to create control instance.
static void increment(T *)
Increment count according to type information.
Generic context to extend user, run and event information.
G4LogicalVolume * logvol(const G4StepPoint *p) const
std::vector< StepInfo * > Steps
Geant4EventActionSequence & eventAction() const
Access to the main event action sequence from the kernel object.
Geant4MaterialScanner(Geant4Context *context, const std::string &name)
Standard constructor.
Structure to hold the information of one simulation step.
StepInfo & operator=(const StepInfo &c)
Assignment operator.
StepInfo(const Position &pre, const Position &post, const G4LogicalVolume *volume)
Initializing constructor.