12 #include "GaudiKernel/ITHistSvc.h"
14 #include "CLHEP/Units/SystemOfUnits.h"
15 #include "CLHEP/Geometry/Transform3D.h"
27 m_extrapolateDirectly(true),
28 m_extrapolateIncrementally(true),
29 m_parameterCache(nullptr),
31 m_validationTreeName(
"G4Follower_"+
n),
32 m_validationTreeDescription(
"Output of the G4Follower_"),
33 m_validationTreeFolder(
"/val/G4Follower_"+
n),
34 m_validationTree(nullptr)
50 m_treeData = std::make_unique<TreeData>();
52 if (m_extrapolator.retrieve().isFailure()){
53 ATH_MSG_ERROR(
"Could not retrieve Extrapolator " << m_extrapolator <<
" . Abort.");
54 return StatusCode::FAILURE;
58 m_validationTree =
new TTree(m_validationTreeName.c_str(), m_validationTreeDescription.c_str());
60 m_validationTree->Branch(
"InitX", &m_treeData->m_t_x,
"initX/F");
61 m_validationTree->Branch(
"InitY", &m_treeData->m_t_y,
"initY/F");
62 m_validationTree->Branch(
"InitZ", &m_treeData->m_t_z,
"initZ/F");
63 m_validationTree->Branch(
"InitTheta", &m_treeData->m_t_theta,
"initTheta/F");
64 m_validationTree->Branch(
"InitEta", &m_treeData->m_t_eta,
"initEta/F");
65 m_validationTree->Branch(
"InitPhi", &m_treeData->m_t_phi,
"initPhi/F");
66 m_validationTree->Branch(
"InitP", &m_treeData->m_t_p,
"initP/F");
67 m_validationTree->Branch(
"InitPdg", &m_treeData->m_t_pdg,
"initPdg/I");
68 m_validationTree->Branch(
"InitCharge", &m_treeData->m_t_charge,
"initQ/F");
70 m_validationTree->Branch(
"G4Steps", &m_treeData->m_g4_steps,
"g4steps/I");
71 m_validationTree->Branch(
"G4StepP", m_treeData->m_g4_p,
"g4stepP[g4steps]/F");
72 m_validationTree->Branch(
"G4StepEta", m_treeData->m_g4_eta,
"g4stepEta[g4steps]/F");
73 m_validationTree->Branch(
"G4StepTheta", m_treeData->m_g4_theta,
"g4stepTheta[g4steps]/F");
74 m_validationTree->Branch(
"G4StepPhi", m_treeData->m_g4_phi,
"g4stepPhi[g4steps]/F");
75 m_validationTree->Branch(
"G4StepX", m_treeData->m_g4_x,
"g4stepX[g4steps]/F");
76 m_validationTree->Branch(
"G4StepY", m_treeData->m_g4_y,
"g4stepY[g4steps]/F");
77 m_validationTree->Branch(
"G4StepZ", m_treeData->m_g4_z,
"g4stepZ[g4steps]/F");
78 m_validationTree->Branch(
"G4AccumTX0", m_treeData->m_g4_tX0,
"g4stepAccTX0[g4steps]/F");
79 m_validationTree->Branch(
"G4StepT", m_treeData->m_g4_t,
"g4stepTX[g4steps]/F");
80 m_validationTree->Branch(
"G4StepX0", m_treeData->m_g4_X0,
"g4stepX0[g4steps]/F");
82 m_validationTree->Branch(
"TrkStepStatus",m_treeData->m_trk_status,
"trkstepStatus[g4steps]/I");
83 m_validationTree->Branch(
"TrkStepP", m_treeData->m_trk_p,
"trkstepP[g4steps]/F");
84 m_validationTree->Branch(
"TrkStepEta", m_treeData->m_trk_eta,
"trkstepEta[g4steps]/F");
85 m_validationTree->Branch(
"TrkStepTheta", m_treeData->m_trk_theta,
"trkstepTheta[g4steps]/F");
86 m_validationTree->Branch(
"TrkStepPhi", m_treeData->m_trk_phi,
"trkstepPhi[g4steps]/F");
87 m_validationTree->Branch(
"TrkStepX", m_treeData->m_trk_x,
"trkstepX[g4steps]/F");
88 m_validationTree->Branch(
"TrkStepY", m_treeData->m_trk_y,
"trkstepY[g4steps]/F");
89 m_validationTree->Branch(
"TrkStepZ", m_treeData->m_trk_z,
"trkstepZ[g4steps]/F");
90 m_validationTree->Branch(
"TrkStepLocX", m_treeData->m_trk_lx,
"trkstepLX[g4steps]/F");
91 m_validationTree->Branch(
"TrkStepLocY", m_treeData->m_trk_ly,
"trkstepLY[g4steps]/F");
94 SmartIF<ITHistSvc> tHistSvc{Gaudi::svcLocator()->service(
"THistSvc")};
96 ATH_MSG_ERROR(
"Could not find Hist Service -> Switching ValidationMode Off !" );
97 delete m_validationTree; m_validationTree =
nullptr;
99 if ((tHistSvc->regTree(m_validationTreeFolder, m_validationTree)).isFailure()) {
100 ATH_MSG_ERROR(
"Could not register the validation Tree -> Switching ValidationMode Off !" );
101 delete m_validationTree; m_validationTree =
nullptr;
105 return StatusCode::SUCCESS;
110 return StatusCode::SUCCESS;
115 m_treeData->m_t_x = 0.;
116 m_treeData->m_t_y = 0.;
117 m_treeData->m_t_z = 0.;
118 m_treeData->m_t_theta = 0.;
119 m_treeData->m_t_eta = 0.;
120 m_treeData->m_t_phi = 0.;
121 m_treeData->m_t_p = 0.;
122 m_treeData->m_t_charge = 0.;
123 m_treeData->m_t_pdg = 0;
124 m_treeData->m_g4_steps = 0;
129 const G4ThreeVector&
mom,
136 if (!m_treeData->m_g4_steps){
137 ATH_MSG_INFO(
"Initial step ... preparing event cache.");
138 m_treeData->m_t_x =
pos.x();
139 m_treeData->m_t_y =
pos.y();
140 m_treeData->m_t_z =
pos.z();
141 m_treeData->m_t_theta =
mom.theta();
142 m_treeData->m_t_eta =
mom.eta();
143 m_treeData->m_t_phi =
mom.phi();
144 m_treeData->m_t_p =
mom.mag();
145 m_treeData->m_t_charge =
charge;
146 m_treeData->m_t_pdg = pdg;
147 m_treeData->m_g4_steps = -1;
154 m_treeData->m_g4_steps = (m_treeData->m_g4_steps == -1) ? 0 : m_treeData->m_g4_steps;
156 if (!m_parameterCache){
161 if ( m_treeData->m_g4_steps >=
MAXPROBES) {
170 const EventContext& ctx = Gaudi::Hive::currentContext();
172 m_extrapolator->extrapolateDirectly(ctx,
176 m_extrapolator->extrapolate(ctx,
181 m_treeData->m_g4_p[m_treeData->m_g4_steps] =
mom.mag();
182 m_treeData->m_g4_eta[m_treeData->m_g4_steps] =
mom.eta();
183 m_treeData->m_g4_theta[m_treeData->m_g4_steps] =
mom.theta();
184 m_treeData->m_g4_phi[m_treeData->m_g4_steps] =
mom.phi();
185 m_treeData->m_g4_x[m_treeData->m_g4_steps] =
pos.x();
186 m_treeData->m_g4_y[m_treeData->m_g4_steps] =
pos.y();
187 m_treeData->m_g4_z[m_treeData->m_g4_steps] =
pos.z();
188 float tX0 =
X0 > 10
e-5 ?
t/
X0 : 0.;
190 m_treeData->m_g4_tX0[m_treeData->m_g4_steps] = m_tX0Cache;
191 m_treeData->m_g4_t[m_treeData->m_g4_steps] =
t;
192 m_treeData->m_g4_X0[m_treeData->m_g4_steps] =
X0;
194 m_treeData->m_trk_status[m_treeData->m_g4_steps] = trkParameters ? 1 : 0;
195 m_treeData->m_trk_p[m_treeData->m_g4_steps] = trkParameters ? trkParameters->
momentum().mag() : 0.;
196 m_treeData->m_trk_eta[m_treeData->m_g4_steps] = trkParameters ? trkParameters->
momentum().eta() : 0.;
197 m_treeData->m_trk_theta[m_treeData->m_g4_steps] = trkParameters ? trkParameters->
momentum().theta() : 0.;
198 m_treeData->m_trk_phi[m_treeData->m_g4_steps] = trkParameters ? trkParameters->
momentum().phi() : 0.;
199 m_treeData->m_trk_x[m_treeData->m_g4_steps] = trkParameters ? trkParameters->
position().x() : 0.;
200 m_treeData->m_trk_y[m_treeData->m_g4_steps] = trkParameters ? trkParameters->
position().y() : 0.;
201 m_treeData->m_trk_z[m_treeData->m_g4_steps] = trkParameters ? trkParameters->
position().z() : 0.;
202 m_treeData->m_trk_lx[m_treeData->m_g4_steps] = trkParameters ? trkParameters->parameters()[
Trk::locX] : 0.;
203 m_treeData->m_trk_ly[m_treeData->m_g4_steps] = trkParameters ? trkParameters->parameters()[
Trk::locY] : 0.;
206 if (m_extrapolateIncrementally && trkParameters) {
207 delete m_parameterCache;
208 m_parameterCache = trkParameters;
212 ++m_treeData->m_g4_steps;
218 m_validationTree->Fill();
219 delete m_parameterCache;