ATLAS Offline Software
Loading...
Searching...
No Matches
PhysicsValidationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// PhysicsValidationTool.cxx, (c) ATLAS Detector software
8
9// class header
11
12// Tracking
14// ISF includes
17// CLHEP
18#include "CLHEP/Units/SystemOfUnits.h"
19#include "CLHEP/Units/PhysicalConstants.h"
20//
21// ROOT includes
22#include "TTree.h"
23
24#include <cmath>
25
26#include <iostream>
27
28/*=========================================================================
29 * DESCRIPTION OF FUNCTION:
30 * ==> see headerfile
31 *=======================================================================*/
33 const std::string& n,
34 const IInterface* p )
35 : base_class(t,n,p),
36 m_thistSvc("THistSvc",n),
37 m_validationStream("ISFFatras"),
38 m_eloss(0.),
39 m_ionloss(0.),
40 m_radloss(0.),
41 m_zOaTr(0.),
42 m_wZ(0.),
43 m_thIn(0.),
44 m_phIn(0.),
45 m_dIn(0.),
46 m_thEnd(0.),
47 m_phEnd(0.),
48 m_dEnd(0.),
49 m_X0(0.),
50 m_dt(0.),
51 m_interactions(nullptr),
52 m_process(0),
53 m_pdg_mother(0),
54 m_gen_mother(0),
55 m_nChild(0),
56 m_vtx_dist(0.),
57 m_vtx_theta(0.),
58 m_vtx_phi(0.),
59 m_vtx_e_diff(0.),
60 m_vtx_p_diff(0.),
63 m_p_mother(0.)
64{
65 // validation output section
66 declareProperty("ValidationStreamName",
67 m_validationStream = "ISFFatras",
68 "Name of the output stream" );
69 declareProperty("THistService",
71 "The THistSvc" );
72}
73
74/*=========================================================================
75 * DESCRIPTION OF FUNCTION:
76 * ==> see headerfile
77 *=======================================================================*/
83
84/*=========================================================================
85 * DESCRIPTION OF FUNCTION:
86 * ==> see headerfile
87 *=======================================================================*/
88StatusCode
90{
91
92 ATH_MSG_VERBOSE( "initialize()" );
93
94 // retrieve the histogram service
95 if ( m_thistSvc.retrieve().isSuccess() ) {
96 // Create the prefix of histogram names for the THistSvc
97 const char *treeName="particles";
98 const std::string prefix = "/" + m_validationStream + "/"+ treeName;
99 m_particles = new TTree( treeName, treeName );
100 m_particles->Branch("pdg" , &m_pdg , "pdg/I" );
101 m_particles->Branch("scIn" , &m_scIn , "scIn/I" );
102 m_particles->Branch("scOut" , &m_scEnd , "scOut/I" );
103 m_particles->Branch("gen" , &m_gen , "gen/I" );
104 m_particles->Branch("geoID" , &m_geoID , "geoID/I" );
105 m_particles->Branch("pth" , &m_pth , "pth/F" );
106 m_particles->Branch("pph" , &m_pph , "pph/F" );
107 m_particles->Branch("p" , &m_p , "p/F" );
108 m_particles->Branch("eloss" , &m_eloss , "eloss/F" );
109 m_particles->Branch("ionloss" , &m_ionloss , "ionloss/F" );
110 m_particles->Branch("radloss" , &m_radloss , "radloss/F" );
111 m_particles->Branch("zOaTr" , &m_zOaTr , "zOaTr/F" );
112 m_particles->Branch("wZ" , &m_wZ , "wZ/F" );
113 m_particles->Branch("X0" , &m_X0 , "X0/F" );
114 m_particles->Branch("dt" , &m_dt , "dt/F" );
115 m_particles->Branch("thIn" , &m_thIn , "thIn/F" );
116 m_particles->Branch("phIn" , &m_phIn , "phIn/F" );
117 m_particles->Branch("dIn" , &m_dIn , "dIn/F" );
118 m_particles->Branch("thEnd" , &m_thEnd , "thEnd/F" );
119 m_particles->Branch("phEnd" , &m_phEnd , "phEnd/F" );
120 m_particles->Branch("dEnd" , &m_dEnd , "dEnd/F" );
121
122 // register the Tree to the THistSvc and return it's StatusCode
123 ATH_CHECK(m_thistSvc->regTree( prefix, m_particles) );
124
125
126 const char *treeNameInt="interactions";
127 const std::string prefixInt = "/" + m_validationStream + "/"+ treeNameInt;
128 m_interactions = new TTree( treeNameInt, treeNameInt );
129 m_interactions->Branch("process" , &m_process , "process/I" );
130 m_interactions->Branch("pdg_mother" , &m_pdg_mother , "pdg_mother/I" );
131 m_interactions->Branch("gen_mother" , &m_gen_mother , "gen_mother/I" );
132 m_interactions->Branch("nChild" , &m_nChild , "nch/I" );
133 m_interactions->Branch("vtx_dist" , &m_vtx_dist , "vtx_dist/F" );
134 m_interactions->Branch("vtx_theta" , &m_vtx_theta , "vtx_theta/F" );
135 m_interactions->Branch("vtx_phi" , &m_vtx_phi , "vtx_phi/F" );
136 m_interactions->Branch("vtx_e_diff" , &m_vtx_e_diff , "vtx_e_diff/F" );
137 m_interactions->Branch("vtx_p_diff" , &m_vtx_p_diff , "vtx_p_diff/F" );
138 m_interactions->Branch("vtx_plong_diff" , &m_vtx_plong_diff , "vtx_plong_diff/F" );
139 m_interactions->Branch("vtx_pperp_diff" , &m_vtx_pperp_diff , "vtx_pperp_diff/F" );
140 m_interactions->Branch("p_mother" , &m_p_mother , "p_mother/F" );
141 m_interactions->Branch("pdg_child" , m_pdg_child , "pdg_child[nch]/I" );
142 m_interactions->Branch("fp_child" , m_fp_child , "fp_child[nch]/F" );
143 m_interactions->Branch("oa_child" , m_oa_child , "oa_child[nch]/F" );
144 // register the Tree to the THistSvc and return it's StatusCode
145 ATH_CHECK(m_thistSvc->regTree( prefixInt, m_interactions) );
146
147 }
148
149 return StatusCode::SUCCESS;
150}
151
152/*=========================================================================
153 * DESCRIPTION OF FUNCTION:
154 * ==> see headerfile
155 *=======================================================================*/
156
160 Trk::ExtrapolationCode ecode) const {
161
162 m_p = isp.momentum().mag();
163 m_ionloss = ec.eLoss ? ec.eLoss->meanIoni() : 0.;
164 m_radloss = ec.eLoss ? ec.eLoss->meanRad() : 0.; // average estimate
165 m_zOaTr = ec.zOaTrX;
166 m_wZ = ec.zX;
167
168 if (ecode == Trk::ExtrapolationCode::SuccessBoundaryReached) { // surviving particle
169 m_scEnd = 0;
170 m_eloss = ec.endParameters->momentum().mag()-m_p;
171 //m_dt = time - isp.timeStamp();
172 m_dt = ec.pathLength/CLHEP::c_light; // TODO get timing info from the cell
173
174 m_thEnd = ec.endParameters->position().theta();
175 m_phEnd = ec.endParameters->position().phi();
176 m_dEnd = ec.endParameters->position().mag();
177
178 } else {
179
180 m_scEnd = -1; // undefined
181 if (ecode == Trk::ExtrapolationCode::SuccessPathLimit) m_scEnd = 201; // decay
182 else if (ecode == Trk::ExtrapolationCode::SuccessMaterialLimit ) m_scEnd = ec.materialProcess; // material interaction
183
184 m_eloss = -m_p;
185 m_thEnd = -10.; // TODO : retrieve position of stopped particle
186 m_phEnd = -10.; // TODO : retrieve position of stopped particle
187 m_dEnd = -1.; // TODO : retrieve position of stopped particle
188 }
189 m_X0 = ec.materialX0;
190
191 saveInfo(isp);
192
193}
194
198 Trk::ExtrapolationCode ecode) const {
199
200 m_p = isp.momentum().mag();
201 m_ionloss = 0.;
202 m_radloss = 0.;
203 m_zOaTr = ec.zOaTrX;
204 m_wZ = ec.zX;
205
206 if (ecode == Trk::ExtrapolationCode::SuccessBoundaryReached) { // surviving particle
207 m_scEnd = 0;
208 m_eloss = ec.endParameters->momentum().mag()-m_p;
209 //m_dt = time - isp.timeStamp();
210 m_dt = ec.pathLength/CLHEP::c_light; // TODO get timing info from the cell
211
212 m_thEnd = ec.endParameters->position().theta();
213 m_phEnd = ec.endParameters->position().phi();
214 m_dEnd = ec.endParameters->position().mag();
215
216 } else {
217
218 m_scEnd = -1; // undefined
219 if (ecode == Trk::ExtrapolationCode::SuccessPathLimit) m_scEnd = 201; // decay
220 else if (ecode == Trk::ExtrapolationCode::SuccessMaterialLimit ) m_scEnd = ec.materialProcess; // material interaction
221
222 m_eloss = -m_p;
223 m_thEnd = -10.; // TODO : retrieve position of stopped particle
224 m_phEnd = -10.; // TODO : retrieve position of stopped particle
225 m_dEnd = -1.; // TODO : retrieve position of stopped particle
226 }
227 m_X0 = ec.materialX0;
228
229 saveInfo(isp);
230
231}
232
235 int endProcess,
236 const Trk::TrackParameters* ePar,
237 double time, double dX0 ) const {
238
239 m_pdg = isp.pdgCode();
240 m_scIn = isp.getUserInformation()? isp.getUserInformation()->process() : 0; // assume primary track
241 m_gen = isp.getUserInformation()? isp.getUserInformation()->generation() : 0; // assume primary track
242 m_pth=isp.momentum().theta();
243 m_pph=isp.momentum().phi();
244 m_geoID = isp.nextGeoID();
245 m_dIn = isp.position().mag();
246 m_thIn = isp.position().theta();
247 m_phIn = isp.position().phi();
248 m_p = isp.momentum().mag();
249 m_scEnd = endProcess;
250 m_eloss = ePar? ePar->momentum().mag()-m_p : -m_p;
251 m_dt = time - isp.timeStamp();
252
253 m_ionloss = 0.; // n.a.
254 m_radloss = 0.; // n.a.
255 m_zOaTr = 0.; // n.a.
256
257 if (ePar) {
258
259 //error propagation
260 //const Trk::MeasuredTrackParameters* mPar = dynamic_cast<const Trk::MeasuredTrackParameters*> (ePar);
261 //if (mPar) std::cout << "error propagation :"<< mPar->localErrorMatrix().error(Trk::qOverP) << std::endl;
262
263 m_thEnd = ePar->position().theta();
264 m_phEnd = ePar->position().phi();
265 m_dEnd = ePar->position().mag();
266 } else {
267 m_thEnd = m_thIn;
268 m_phEnd = m_phIn;
269 m_dEnd = -1.; // particle stopped and position unknown
270 }
271 m_X0 = dX0;
272
273 m_particles->Fill();
274
275}
276
278
279 // ISF particle info ( common )
280
281 m_pdg = isp.pdgCode();
282 m_scIn = isp.getUserInformation()? isp.getUserInformation()->process() : 0; // assume primary track
283 m_gen = isp.getUserInformation()? isp.getUserInformation()->generation() : 0; // assume primary track
284 m_pth=isp.momentum().theta();
285 m_pph=isp.momentum().phi();
286 m_geoID = isp.nextGeoID();
287 m_dIn = isp.position().mag();
288 m_thIn = isp.position().theta();
289 m_phIn = isp.position().phi();
290
291 m_particles->Fill();
292
293}
294
296 Amg::Vector3D* primOut, const ISF::ISFParticleVector& children) const {
297
299 unsigned int nSec = children.size();
300
301 int iPrimSurv = primOut ? 1 : 0;
302
303 m_pdg_mother = parent.pdgCode();
304 m_gen_mother = parent.getUserInformation()? parent.getUserInformation()->generation() : 0; // assume primary track
305
306 m_p_mother = primIn.mag();
307
308 m_vtx_dist = vertex.mag();
309 m_vtx_theta = vertex.theta();
310 m_vtx_phi = vertex.phi();
311
312 m_nChild = nSec+iPrimSurv;
313
314 Amg::Vector3D pbal(primIn);
315
316 if (iPrimSurv>0) {
318 m_fp_child[0] = primOut->mag()/m_p_mother;
319 m_oa_child[0] = primOut->unit().dot( primIn.unit() );
320 pbal -= *primOut;
321 }
322
323 unsigned int nSecMax = nSec+iPrimSurv> MAXCHILDREN ? MAXCHILDREN-iPrimSurv : nSec;
324 for (unsigned int isec=0; isec< nSec; isec++) {
325 if (isec<nSecMax) {
326 m_pdg_child[isec+iPrimSurv] = children[isec]->pdgCode();
327 m_fp_child[isec+iPrimSurv] = children[isec]->momentum().mag()/m_p_mother;
328 m_oa_child[isec+iPrimSurv] = children[isec]->momentum().unit().dot( primIn.unit() );
329 }
330 pbal -= children[isec]->momentum();
331 }
332
333 m_vtx_p_diff = pbal.mag();
334 m_vtx_plong_diff = pbal.dot(primIn)/m_p_mother;
336
337 m_interactions->Fill();
338}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define MAXCHILDREN
The generic ISF particle definition,.
Definition ISFParticle.h:42
const ParticleUserInformation * getUserInformation() const
get/set ParticleUserInformation
const Amg::Vector3D & momentum() const
The current momentum vector of the ISFParticle.
double timeStamp() const
Timestamp of the ISFParticle.
const Amg::Vector3D & position() const
The current position of the ISFParticle.
int pdgCode() const
PDG value.
AtlasDetDescr::AtlasRegion nextGeoID() const
next geoID the particle will be simulated in
double meanRad() const
double meanIoni() const
templated class as an input-output object of the extrapolation, only public members,...
int materialProcess
the material process to be generated
float zOaTrX
z/A*rho*dInX0 (for average calculations)
float zX
z*dInX0 (for average calculations)
double materialX0
collected material so far in units of X0
T * endParameters
by pointer - are newly created and can be optionally 0
EnergyLoss * eLoss
cumulated energy loss
double pathLength
the path length accumulated
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
virtual void saveISFParticleInfo(const ISF::ISFParticle &isp, int endProcess, const Trk::TrackParameters *ePar, double time, double dX0) const override
ISFParticle info: old transport tool.
virtual void saveISFVertexInfo(int process, Amg::Vector3D vertex, const ISF::ISFParticle &isp, Amg::Vector3D primIn, Amg::Vector3D *primOut, const ISF::ISFParticleVector &children) const override
void saveInfo(const ISF::ISFParticle &isp) const
TTree * m_interactions
ROOT tree containing vertex info.
PhysicsValidationTool(const std::string &, const std::string &, const IInterface *)
Constructor.
std::string m_validationStream
validation THist stream name
TTree * m_particles
Validation output TTree (+variables)
virtual StatusCode initialize() override
AlgTool initialize method.
ServiceHandle< ITHistSvc > m_thistSvc
the histogram service
const std::string process
Eigen::Matrix< double, 3, 1 > Vector3D
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
ParametersBase< TrackParametersDim, Charged > TrackParameters