ATLAS Offline Software
SteppingValidation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "SteppingValidation.h"
6 
7 #include <cmath>
8 
9 #include "TH1.h"
10 #include "TH2.h"
11 
12 #include "G4StepPoint.hh"
13 #include "G4Step.hh"
14 #include "G4VProcess.hh"
15 #include "G4Track.hh"
16 
17 #include "MCTruth/TrackHelper.h"
18 
19 namespace G4UA
20 {
21 
22  //----------------------------------------------------------------------------
24  : m_stepL(nullptr), m_stepProc(nullptr), m_mscAngle(nullptr),
25  m_stepELoss(nullptr), m_secE(nullptr),
26  m_latPhi(nullptr), m_latEta(nullptr), m_EvsR(nullptr),
27  m_prim(nullptr), m_sec(nullptr),
28  m_primH(0), m_primF(0), m_dh(0), m_dh2(0), m_dp(0), m_dp2(0), m_nsec(0)
29  {}
30 
31  //----------------------------------------------------------------------------
33  {
34  m_path += "Stepping/";
35 
36  // Set up all the histograms...
37  _TH1D_NOCHECK( m_stepL , "stepL" , 100 , -9 , 3 );
38  _TH1D_NOCHECK( m_stepProc , "stepProc" , 15 , -0.5 , 14.5 );
39  _TH1D_NOCHECK( m_mscAngle , "mscAngle" , 100 , 0. , M_PI );
40  _TH1D_NOCHECK( m_stepELoss , "stepELoss" , 100 , -10 , 2 );
41  _TH1D_NOCHECK( m_secE , "secE" , 100 , -3.5 , 5 );
42  _TH2D_NOCHECK( m_EvsR , "EvsR" , 100 , 0 , 1.2 , 100 , 1000. , 20000.);
43  _TH1D_NOCHECK( m_latPhi , "latPhi" , 100 , 0. , 1.2 );
44  _TH1D_NOCHECK( m_latEta , "latEta" , 100 , 0. , 0.6 );
45 
46  _SET_TITLE(m_stepL, "Step length distribution", "Step length [log(mm)]", "Steps");
47  _SET_TITLE(m_stepProc, "Step process distribution", "Step process", "Steps");
48  _SET_TITLE(m_mscAngle, "Multiple scattering angle distribution", "Angle", "Steps");
49  _SET_TITLE(m_stepELoss, "Energy loss distribution", "Energy Loss [log(MeV)]", "Steps");
50  _SET_TITLE(m_secE, "Secondary energy distribution", "Energy [log(MeV)]", "Secondaries");
51  _SET_TITLE(m_EvsR, "Primary Energy vs Radius", "Radius [m]", "Primary Energy [MeV]");
52  _SET_TITLE(m_latPhi, "Phi energy distribution", "Energy-weighted #phi RMS", "Primaries");
53  _SET_TITLE(m_latEta, "Eta energy distribution", "Energy-weighted #eta RMS", "Primaries");
54  }
55 
56  //----------------------------------------------------------------------------
58  {
59  // Fill lateral energy spread
60  if (m_nsec>0){
61  m_latPhi->Fill( std::sqrt( m_dp2/m_nsec - std::pow(m_dp/m_nsec,2) ) );
62  m_latEta->Fill( std::sqrt( m_dh2/m_nsec - std::pow(m_dh/m_nsec,2) ) );
63  }
64  }
65 
66  //----------------------------------------------------------------------------
68  {
69  m_prim = m_sec = 0;
70  m_primH = m_primF = 0;
71  m_dh = m_dh2 = m_dp = m_dp2 = 0;
72  m_nsec = 0;
73  }
74 
75  //----------------------------------------------------------------------------
76  void SteppingValidation::UserSteppingAction(const G4Step* aStep)
77  {
78  // Fill process type
79  m_stepProc->Fill( aStep->GetPostStepPoint()->GetProcessDefinedStep()->
80  GetProcessType() );
81 
82  // Fill energy deposit
83  m_stepELoss->Fill( log10(aStep->GetTotalEnergyDeposit()) );
84 
85  // Fill step length
86  m_stepL->Fill( log10( aStep->GetStepLength() ) );
87 
88  // Fill secondary energies
89  auto* preStepPoint = aStep->GetPreStepPoint();
90  auto* postStepPoint = aStep->GetPostStepPoint();
91  if (m_prim == 0){
92  m_prim = aStep->GetTrack();
93  }
94  // New secondary
95  else if (aStep->GetTrack()!=m_prim && aStep->GetTrack()!=m_sec){
96  m_secE->Fill( log10(preStepPoint->GetTotalEnergy()) );
97  m_sec = aStep->GetTrack();
98  }
99 
100  // Defined by transport --> MSC
101  if (postStepPoint->GetProcessDefinedStep()->GetProcessType()==1){
102  if (m_prim==aStep->GetTrack()){
103  double angle = std::acos(
104  preStepPoint->GetMomentumDirection().dot(
105  postStepPoint->GetMomentumDirection() ) );
106  m_mscAngle->Fill(angle);
107  m_EvsR->Fill( postStepPoint->GetPosition().perp()*0.001,
108  aStep->GetTrack()->GetTotalEnergy() );
109  }
110  }
111 
112  if (aStep->GetTrack()->GetNextVolume()==0){
113  // Leaving world! Use this for RMS calculations
114  if (m_prim==aStep->GetTrack()){
115  m_primH = postStepPoint->GetPosition().eta();
116  m_primF = postStepPoint->GetPosition().phi();
117  } else {
118  m_dh += (postStepPoint->GetPosition().eta() - m_primH )*aStep->GetTrack()->GetTotalEnergy();
119  m_dh2 += std::pow(postStepPoint->GetPosition().eta() - m_primH,2)*aStep->GetTrack()->GetTotalEnergy();
120  m_dp += (postStepPoint->GetPosition().phi() - m_primF )*aStep->GetTrack()->GetTotalEnergy();
121  m_dp2 += std::pow(postStepPoint->GetPosition().phi() - m_primF,2)*aStep->GetTrack()->GetTotalEnergy();
122  m_nsec += aStep->GetTrack()->GetTotalEnergy();
123  }
124  }
125 
126  }
127 
128 } // namespace G4UA
G4UA::SteppingValidation::m_nsec
double m_nsec
Definition: SteppingValidation.h:48
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
TrackHelper.h
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
M_PI
#define M_PI
Definition: ActiveFraction.h:11
_TH1D_NOCHECK
#define _TH1D_NOCHECK(var, name, nbin, xmin, xmax)
Definition: SimTestHisto.h:56
G4UA::SteppingValidation::m_primF
double m_primF
Definition: SteppingValidation.h:48
G4UA::SteppingValidation::m_dh2
double m_dh2
Definition: SteppingValidation.h:48
_SET_TITLE
#define _SET_TITLE(var, title, xaxis, yaxis)
Definition: SimTestHisto.h:93
G4UA::SteppingValidation::m_secE
TH1 * m_secE
Definition: SteppingValidation.h:45
G4UA::SteppingValidation::m_primH
double m_primH
Definition: SteppingValidation.h:48
G4UA::SteppingValidation::m_prim
G4Track * m_prim
Definition: SteppingValidation.h:47
G4UA::SteppingValidation::m_dp2
double m_dp2
Definition: SteppingValidation.h:48
G4UA::SteppingValidation::m_dh
double m_dh
Definition: SteppingValidation.h:48
angle
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
Definition: TRTDetectorFactory_Full.cxx:73
G4UA::SteppingValidation::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: SteppingValidation.cxx:76
G4UA::SteppingValidation::m_latEta
TH1 * m_latEta
Definition: SteppingValidation.h:45
G4UA::SteppingValidation::m_sec
G4Track * m_sec
Definition: SteppingValidation.h:47
G4UA::SteppingValidation::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: SteppingValidation.cxx:57
G4UA::SteppingValidation::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *) override
Definition: SteppingValidation.cxx:32
G4UA::SteppingValidation::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *) override
Definition: SteppingValidation.cxx:67
G4UA::SteppingValidation::m_stepL
TH1 * m_stepL
Definition: SteppingValidation.h:45
G4UA::SteppingValidation::m_latPhi
TH1 * m_latPhi
Definition: SteppingValidation.h:45
G4UA::SteppingValidation::m_mscAngle
TH1 * m_mscAngle
Definition: SteppingValidation.h:45
SimTestHisto::m_path
std::string m_path
Definition: SimTestHisto.h:34
G4UA::SteppingValidation::SteppingValidation
SteppingValidation()
Definition: SteppingValidation.cxx:23
G4UA::SteppingValidation::m_EvsR
TH2 * m_EvsR
Definition: SteppingValidation.h:46
G4UA::SteppingValidation::m_stepELoss
TH1 * m_stepELoss
Definition: SteppingValidation.h:45
G4UA::SteppingValidation::m_dp
double m_dp
Definition: SteppingValidation.h:48
G4UA::SteppingValidation::m_stepProc
TH1 * m_stepProc
Definition: SteppingValidation.h:45
_TH2D_NOCHECK
#define _TH2D_NOCHECK(var, name, nbinx, xmin, xmax, nbiny, ymin, ymax)
Definition: SimTestHisto.h:71
SteppingValidation.h