11#include <framework/core/Module.h>
12#include <framework/gearbox/Unit.h>
19#include <G4UserSteppingAction.hh>
20#include <G4ThreeVector.hh>
37 MaterialScanBase(TFile* rootFile,
const std::string& name,
const std::string& axisLabel):
54 virtual bool createNext(G4ThreeVector& origin, G4ThreeVector& direction) = 0;
119 bool createNext(G4ThreeVector& origin, G4ThreeVector& direction)
override;
132 virtual void getRay(G4ThreeVector& origin, G4ThreeVector& direction) = 0;
143 void fillValue(
const std::string& name,
double value);
173 MaterialScan2D(rootFile,
"Spherical", doCosTheta ?
"cos(#theta);#phi [deg]" :
"#theta [deg];#phi [deg]", params),
m_origin(origin),
186 void getRay(G4ThreeVector& origin, G4ThreeVector& direction)
override;
211 MaterialScanPlanar(TFile* rootFile,
const G4ThreeVector& origin,
const G4ThreeVector& dirU,
const G4ThreeVector& dirV,
219 void getRay(G4ThreeVector& origin, G4ThreeVector& direction)
override;
242 MaterialScanRay(TFile* rootFile,
const G4ThreeVector& origin,
const G4ThreeVector& dir,
double opening,
243 int count,
double sampleDepth,
double maxDepth,
bool splitByMaterials,
244 const std::vector<std::string>& ignoredMaterials):
245 MaterialScanBase(rootFile,
"Ray",
"ray length [cm]; material budget [X_0/cm]"),
258 bool createNext(G4ThreeVector& origin, G4ThreeVector& direction)
override;
269 void fillValue(
const std::string& name,
double value,
double steplength);
328 G4ThreeVector
getAxis(
char name);
Base class to create a Material Scan of the detector geometry.
void fillValue(const std::string &name, double value)
Fill the recorded material budget into the corresponding histogram.
virtual void getRay(G4ThreeVector &origin, G4ThreeVector &direction)=0
Get the origin and direction for the next scan particle.
double m_stepU
Stepsize for the parameter u.
bool createNext(G4ThreeVector &origin, G4ThreeVector &direction) override
Get the origin and direction for the next scan particle.
TH2D * getHistogram(const std::string &name)
get histogram for a given name, create if needed.
void UserSteppingAction(const G4Step *step) override
Record the material budget for each step of the particles.
std::map< std::string, std::unique_ptr< TH2D > > m_regions
Map holding pointers to all created histograms.
double m_curDepth
Tracklength of the current Ray.
int getNRays() const override
Return the number of rays in this scan.
double m_curU
Current value of the parametetr u.
double m_curV
Current value of the parametetr v.
double m_stepV
Stepsize for the parameter v.
ScanParams m_params
Parameters for the scan.
Base class for Material Scans.
virtual bool createNext(G4ThreeVector &origin, G4ThreeVector &direction)=0
Belle2::MaterialScanBase::createNext() implemention Get the origin and direction for the next scan pa...
bool checkStep(const G4Step *step)
check for stuck tracks by looking at the step length
int m_zeroSteps
Count the number of steps with (almost) zero length.
static constexpr int c_maxZeroStepsNudge
maximum number of consecutive zero steps before nudging the track along
virtual int getNRays() const =0
Return the number of rays necessary to perform the scan.
TFile * m_rootFile
Pointer to the root file for the histograms.
std::string m_axisLabel
Labels for the coordinate axes.
MaterialScanBase(TFile *rootFile, const std::string &name, const std::string &axisLabel)
This is indeed the constructor and it creates a TDirectory in the output root file and sets all varia...
std::string getName() const
Return the name of the scan.
static constexpr int c_maxZeroStepsKill
maximum number of consecutive zero steps before killing the track
std::string m_name
Name of the scan, will be prefixed to all histogram names.
static constexpr double c_zeroTolerance
maximum Step length to be considered zero
double m_rayTheta
Theta direction of the ray if custom direction is not set.
G4ThreeVector getAxis(char name)
Return a vector along the axis with the given name.
double m_raySampleDepth
Sample depth of the ray: create one bin every x cm.
bool m_raySplitByMaterials
If true Split by materials instead of regions when doing ray scan.
double m_rayPhi
Phi direction of the ray if custom direction is not set.
void initialize() override
Initialize the output file and check the parameters.
TFile * m_rootFile
Pointer to the ROOT file for the histograms.
std::string m_planeName
Name of the plane to use for scanning.
std::vector< std::string > m_rayIgnoredMaterials
Materials ignored when ray scanning.
unsigned int m_rayCount
Number of rays to shoot (if opening angle is >0)
std::optional< std::vector< double > > m_rayDirection
Direction of the ray, cannot be set at the same time as Theta and Phi.
void beginRun() override
Do the actual scanning.
MaterialScan2D::ScanParams m_spherical
Scan parameters for the spherical scan.
bool m_doSpherical
Wether or not to do a spherical scan.
bool m_doPlanar
Wether or not to do a planar scan.
bool m_doRay
Perform a material ray scan: scan along a certain direction with a given opening angle and plot mater...
std::vector< double > m_sphericalOrigin
Origin for spherical scan.
std::string m_filename
Filename for the ROOT output.
MaterialScan2D::ScanParams m_planar
Scan parameters for the planar scan.
double m_rayOpening
Opening angle of the ray.
double m_rayMaxDepth
Max depth of the ray before stopping.
std::vector< double > m_customPlane
Custom plane definition if m_planName is "custom".
bool m_doCosTheta
Perform the spherical scan uniform in cos(theta) instead of theta.
std::vector< double > m_rayOrigin
Origin of the ray if a ray scan is performed
Specific implementaion of MaterialScan to scan parallel to a given plane.
G4ThreeVector m_origin
Origin of the scan plane.
G4ThreeVector m_dirV
v direction of the scan plane
G4ThreeVector m_dirU
u direction of the scan plane
MaterialScanPlanar(TFile *rootFile, const G4ThreeVector &origin, const G4ThreeVector &dirU, const G4ThreeVector &dirV, const ScanParams ¶ms)
Create a Planar Scan object with the given parameters.
G4ThreeVector m_dirW
direction perpendicluar to u and v
void getRay(G4ThreeVector &origin, G4ThreeVector &direction) override
Create a ray with the current parameter values according to a planar distribution.
MaterialScan implementation to shoot one ray along a defined direction and record the Material as a f...
void fillValue(const std::string &name, double value, double steplength)
Fill the recorded material budget into the corresponding histogram.
G4ThreeVector m_origin
Origin of the scan.
std::map< std::string, std::unique_ptr< TH1D > > m_regions
Map holding pointers to all created histograms.
MaterialScanRay(TFile *rootFile, const G4ThreeVector &origin, const G4ThreeVector &dir, double opening, int count, double sampleDepth, double maxDepth, bool splitByMaterials, const std::vector< std::string > &ignoredMaterials)
Construct a new instance and set all parameters.
bool m_splitByMaterials
If true Split by materials instead of regions.
double m_scanDepth
The first ray does not record any material but just checks for the maximum useful depth to not get a ...
bool createNext(G4ThreeVector &origin, G4ThreeVector &direction) override
Implement shooting along the ray.
int m_curRay
Current Ray number: 0 = scan for maximum depth, 1..N = record materials.
void UserSteppingAction(const G4Step *step) override
Record the material budget for each step of the particles.
G4ThreeVector m_dir
Direction of the ray.
double m_curDepth
Current depth of the current ray.
double m_maxDepth
Maximum depth for each ray after which it will be stopped.
int getNRays() const override
Return the number of rays.
double m_opening
Opening angle in radian.
std::set< std::string > m_ignoredMaterials
Materials ignored when scanning.
double m_sampleDepth
The ray length after which to sample.
TH1D * getHistogram(const std::string &name)
get histogram for a given name, create if needed.
int m_count
Amount of rays to shoot.
Specific implementation of MaterialScan to do Spherical scanning.
G4ThreeVector m_origin
Origin for the spherical scan.
MaterialScanSpherical(TFile *rootFile, const G4ThreeVector &origin, const ScanParams ¶ms, bool doCosTheta)
Create a Spherical Scan object with the given parameters.
void getRay(G4ThreeVector &origin, G4ThreeVector &direction) override
Create a ray with the current parameter values according to a spherical distribution.
bool m_doCosTheta
Flag to indicate if polar-angular sampling is uniform in cos(theta) rather than theta.
static const double deg
degree to radians
Abstract base class for different kinds of events.
Helper struct to Store Parameters of a Scan.
double maxU
Maximum u value to scan.
bool splitByMaterials
If true, split output by Materials (otherwise by region)
ScanParams()
Default Constructor.
double minV
Minimum v value to scan.
double maxDepth
Maximum depth of the scan.
int nU
Number of rays along u coordinate.
double minU
Minimum u value to scan.
double maxV
Maximum v value to scan.
std::vector< std::string > ignoredMaterials
Names of ignored Materials.
int nV
Number of rays along v coordinate.