ATLAS Offline Software
Loading...
Searching...
No Matches
TBExtrapolTrackToCaloTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ***************************************************************************
6// Liquid Argon detector description package
7// -----------------------------------------
8//
9//****************************************************************************
10
12#include <vector>
13
14// Stuff needed for the extrapolation :
18#include "TrkTrack/Track.h"
22#include "xAODTracking/Vertex.h"
23// CLHEP
24#include "CLHEP/Units/SystemOfUnits.h"
25#include "CLHEP/Vector/Rotation.h"
26#include "CLHEP/Vector/ThreeVector.h"
27
28// Calo specific stuff :
32
33#include <cmath>
34#include <iostream>
35#include <iomanip>
36
37
38
40 const std::string& name,
41 const IInterface* parent) :
42 AthAlgTool(type, name, parent),
43 m_calosurf("CaloSurfaceBuilder"),
44 m_extrapolator("Trk::Extrapolator/AtlasExtrapolator")
45{
46
47 declareProperty ("CaloSurfaceBuilder",m_calosurf,"Extrapolation ToolHandle");
48 declareProperty ("Extrapolator",m_extrapolator,"CaloSurfaceBuilder ToolHandle");
49
50}
51
54
55StatusCode
57{
58
59 // at this point the joboption should have been read
60 ATH_CHECK(m_caloMgrKey.initialize());
61 ATH_CHECK(detStore()->retrieve(m_calo_id,"CaloCell_ID"));
62
63
64
65 ATH_MSG_DEBUG ( " getting started ");
66
67
68
69 // Get TrkExtrapolator from ToolService
70 StatusCode s=m_extrapolator.retrieve();
71
72 if (s.isFailure())
73 {
74 ATH_MSG_FATAL ( "Could not find Tool "
75 << m_extrapolator.name() << " with parent " << m_extrapolator.parentName() );
76 return s;
77 } else
78 {
79 ATH_MSG_INFO ( "Successfully retrieved tool " << m_extrapolator.typeAndName() << " with parent " << m_extrapolator.parentName() ) ;
80 }
81
82
83 IAlgTool* tool;
84 s = toolSvc()->retrieveTool("TBCaloCoordinate",tool);
85 if (s.isFailure())
86 {
87 ATH_MSG_FATAL ("Could not find Tool TBCaloCoordinate" );
88
89 return s;
90 }
91 m_calo_tb_coord = dynamic_cast<ICaloCoordinateTool*>(tool);
92
93
94
95 // Get the CaloSurface tool and sets the depthtool it should use:
96 s=m_calosurf.retrieve();
97
98 if (s.isFailure())
99 {
100 ATH_MSG_FATAL ("Could not find Tool CaloSurfaceBuilder"
101 << m_calosurf.typeAndName());
102 return s;
103 } else {
104 ATH_MSG_INFO ("Successfully retrieved Tool CaloSurfaceBuilder "
105 << m_calosurf.typeAndName());
106
107 }
108
109
110 StatusCode sc = StatusCode::SUCCESS;
111 return sc;
112}
113
114StatusCode
116{
117 StatusCode sc = StatusCode::SUCCESS;
118 return sc;
119}
120
121void
123 double& etaCaloLocal, double& phiCaloLocal)
124{
125
126
127 Amg::Vector3D pt_ctb,pt_local;
128 etaCaloLocal = 0.;
129 phiCaloLocal = 0.;
130
131 if (!parm) {
132 ATH_MSG_WARNING ("CaloVariables called with null Trk::TrackParameters*" ) ;
133 return;
134 }
135
136 pt_ctb = parm->position();
137
138 m_calo_tb_coord->ctb_to_local(pt_ctb, pt_local);
139
140 if ( msgLvl(MSG::DEBUG) ){
141
142 ATH_MSG_DEBUG ("Impact point in ctb coord : x,y,z= "
143 << pt_ctb.x() << " "
144 << pt_ctb.y() << " " << pt_ctb.z() << " R="
145 << std::sqrt( pt_ctb.x()*pt_ctb.x() + pt_ctb.y()*pt_ctb.y()
146 + pt_ctb.z()*pt_ctb.z())
147 << " eta=" << pt_ctb.eta() << " phi=" << pt_ctb.phi() );
148
149
150
151 ATH_MSG_DEBUG ("Impact point in local coord : x,y,z= "
152 << pt_local.x() << " "
153 << pt_local.y() << " " << pt_local.z() << " R="
154 << std::sqrt( pt_local.x()*pt_local.x() + pt_local.y()*pt_local.y()
155 + pt_local.z()*pt_local.z())
156 << " eta=" << pt_local.eta() << " phi=" << pt_local.phi());
157 }
158
159 etaCaloLocal = pt_local.eta();
160 phiCaloLocal = pt_local.phi();
161
162}
163
164void
166 Amg::Vector3D* pt_ctb,
167 Amg::Vector3D* pt_local)
168{
169
170 if (!parm) {
171 ATH_MSG_WARNING ("CaloLocalPoint TrkParam called with null Trk::TrackParameters*" );
172 return;
173 }
174
175 if (!pt_local) {
176 ATH_MSG_WARNING ("CaloLocalPoint TrkParam called with null Amg::Vector3D* pt_local" );
177 return;
178 }
179
180 if (!pt_ctb) {
181 ATH_MSG_WARNING ("CaloLocalPoint TrkParam called with null Amg::Vector3D* pt_ctb" );
182 return;
183 }
184
185
186 *pt_ctb = parm->position();
187
188 ATH_MSG_DEBUG ("Impact point in ctb coord : x,y,z= "
189 << pt_ctb->x() << " "
190 << pt_ctb->y() << " " << pt_ctb->z() << " R="
191 << std::sqrt( pt_ctb->x()*pt_ctb->x() + pt_ctb->y()*pt_ctb->y()
192 + pt_ctb->z()*pt_ctb->z())
193 << " eta=" << pt_ctb->eta() << " phi=" << pt_ctb->phi() );
194
195 m_calo_tb_coord->ctb_to_local(*pt_ctb, *pt_local);
196
197 ATH_MSG_DEBUG ("Impact point in local coord : x,y,z= "
198 << pt_local->x() << " "
199 << pt_local->y() << " " << pt_local->z() << " R="
200 << std::sqrt( pt_local->x()*pt_local->x()
201 + pt_local->y()*pt_local->y()
202 + pt_local->z()*pt_local->z())
203 << " eta=" << pt_local->eta() << " phi=" << pt_local->phi());
204}
205
206bool
208 const CaloCell_ID::CaloSample sample,
209 const double offset,
210 Amg::Vector3D* pt_ctb,
211 Amg::Vector3D* pt_local)
212{
213
214 if (!trk) {
215 ATH_MSG_WARNING ("TrackSeenByCalo Trk called with null Trk::TrackParameters*" );
216 return false;
217 }
218
219 if (!pt_local) {
220 ATH_MSG_WARNING ("TrackSeenByCalo Trk called with null Amg::Vector3D* pt_local");
221
222 return false;
223 }
224
225 if (!pt_ctb) {
226 ATH_MSG_WARNING ("TrackSeenByCalo Trk called with null Amg::Vector3D* pt_ctb");
227
228 return false;
229 }
230
231
232 Trk::Surface* surf = 0;
233 bool success = false;
234 double trketa = 0.;
236 const CaloDetDescrManager* caloDDMgr = *caloMgrHandle;
237 // Take eta of the last measured hit as best guess and create surface :
239 trk->trackParameters();
240 if (paramvec) {
241 for (const Trk::TrackParameters* params : *paramvec)
242 trketa = params->eta();
243 surf = m_calosurf->CreateUserSurface(sample, offset, trketa, caloDDMgr);
244 }
245 if (!surf)
246 return success;
247
248 //std::cout << " here we go : " << std::endl;
249 const Trk::TrackParameters* param = extrapolate(trk,surf);
250
251
252
253 if(param) {
254 CaloLocalPoint (param,pt_ctb, pt_local);
255 success = true;
256 delete param;
257 }
258 delete surf;
259
260 return success;
261}
262
263bool
265 const CaloCell_ID::CaloSample sample,
266 const double offset,
267 Amg::Vector3D* pt_ctb,
268 Amg::Vector3D* pt_local)
269{
270 bool success = false;
271
272
273 if (!parm) {
274 ATH_MSG_WARNING ("TrackSeenByCalo TrkParam called with null Trk::TrackParameters*" );
275 return false;
276 }
277
278 if (!pt_local) {
279
280 ATH_MSG_WARNING("TrackSeenByCalo TrkParam called with null Amg::Vector3D* pt_local" );
281 return false;
282 }
283
284 if (!pt_ctb) {
285 ATH_MSG_WARNING ("TrackSeenByCalo TrkParam called with null Amg::Vector3D* pt_ctb" );
286 return false;
287 }
288
289
290 // Take eta as best guess of track direction and create surface :
291 double trketa = parm->eta();
293 const CaloDetDescrManager* caloDDMgr = *caloMgrHandle;
294 Trk::Surface* surf = m_calosurf->CreateUserSurface (sample,offset,trketa,caloDDMgr);
295 if (!surf) return success;
296
297 const Trk::TrackParameters* resparam = extrapolate(parm,surf);
298
299
300
301 if(resparam) {
302 CaloLocalPoint (resparam,pt_ctb, pt_local);
303 success = true;
304 delete resparam;
305 }
306 delete surf;
307
308 return success;
309}
310
311bool
313 const bool barrel,
314 const CaloCell_ID::SUBCALO subcalo,
315 const int sampling_or_module,
316 const double offset,
317 Amg::Vector3D* pt_ctb,
318 Amg::Vector3D* pt_local)
319{
320
321
323 CaloDetDescrManager::build_sample ( subcalo, barrel ,sampling_or_module, sample);
324 return TrackSeenByCalo(trk,sample,offset,pt_ctb,pt_local);
325}
326
327bool
329 const bool barrel,
330 const CaloCell_ID::SUBCALO subcalo,
331 const int sampling_or_module,
332 const double offset,
333 Amg::Vector3D* pt_ctb,
334 Amg::Vector3D* pt_local)
335{
337 CaloDetDescrManager::build_sample ( subcalo, barrel ,sampling_or_module, sample);
338 return TrackSeenByCalo(parm,sample,offset,pt_ctb,pt_local);
339}
340
341bool
343 const CaloCell_ID::CaloSample sample,
344 const double offset,
345 Amg::Vector3D* pt_ctb,
346 Amg::Vector3D* pt_local,
347 double& trketa_atcalo, double& trkphi_atcalo)
348{
349
350
351 if (!trk) {
352 ATH_MSG_WARNING ("TrackSeenByCalo Trk called with null Trk::TrackParameters*" );
353 return false;
354 }
355
356 if (!pt_local) {
357 ATH_MSG_WARNING ("TrackSeenByCalo Trk called with null Amg::Vector3D* pt_local" ) ;
358 return false;
359 }
360
361 if (!pt_ctb) {
362 ATH_MSG_WARNING ("TrackSeenByCalo Trk called with null Amg::Vector3D* pt_ctb" );
363 return false;
364 }
365
366 Trk::Surface* surf = 0;
367 bool success = false;
368 double trketa = 0.;
369
370 // Take eta of the last measured hit as best guess and create surface :
372 trk->trackParameters();
373 if (paramvec) {
375 if ((*caloMgrHandle)->lar_geometry() == "H8") {
376 trketa = m_calo_tb_coord->beam_local_eta();
377 } else {
378 for (const Trk::TrackParameters* params : *paramvec)
379 trketa = params->eta();
380 }
381
382 surf = m_calosurf->CreateUserSurface(sample, offset, trketa, (*caloMgrHandle));
383 }
384 if (!surf)
385 return success;
386
387 const Trk::TrackParameters* param = extrapolate(trk,surf);
388
389
390
391 if(param) {
392 CaloLocalPoint (param,pt_ctb, pt_local);
393 trketa_atcalo = param->eta();
394 if ( sin(param->parameters()[Trk::phi]) > 0.)
395 trkphi_atcalo = std::acos(cos(param->parameters()[Trk::phi]));
396 else
397 trkphi_atcalo = -1. * std::acos(cos(param->parameters()[Trk::phi]));
398 trkphi_atcalo = m_range.fix(trkphi_atcalo);
399 success = true;
400 delete param;
401 }
402 else {
403 trketa_atcalo = 999999.;
404 trkphi_atcalo = 999999.;
405 }
406 delete surf;
407
408 return success;
409}
410
413{
414 if (m_calosurf==0) return nullptr;
415
416 // getCaloDepth from the surface builder
417 return m_calosurf->getCaloDepth();
418}
419
422 const Trk::Surface* surf)
423{
424
425
426 const Trk::TrackParameters* param=0;
427
428 if (!parm) {
429 ATH_MSG_WARNING ("extrapolate TrkParam called with null Trk::TrackParameters*" ) ;
430 return param;
431 }
432
433 if (!surf) {
434 ATH_MSG_WARNING ("extrapolate TrkParam called with null Trk::Surface*" << endmsg );
435 return param;
436 }
437
438
439
440
441 ATH_MSG_DEBUG ( "Trying to propagate TrackParameters to Surface ... "
442 << (*surf));
443
444 // for the moment use nonInteracting to avoid the navigation
445 param = m_extrapolator->extrapolate(
446 Gaudi::Hive::currentContext(),
447 *parm, *surf,
449 true, Trk::nonInteracting).release();
450
451 if (param)
452 ATH_MSG_DEBUG ("Propagation successful ");
453 else
454 ATH_MSG_DEBUG ("Propagation failed ");
455
456 return param;
457}
458
461 const Trk::Surface* surf)
462{
463
464 const Trk::TrackParameters* param=0;
465 if (!trk) {
466 ATH_MSG_WARNING ("extrapolate Trk called with null Trk::Track*");
467 return param;
468 }
469
470 if (!surf) {
471 ATH_MSG_WARNING ("extrapolate Trk called with null Trk::Surface*" );
472 return param;
473 }
474
475
476
477
478 ATH_MSG_DEBUG ("Trying to propagate to Surface ... " << (*surf) );
479
480 param = m_extrapolator->extrapolateTrack(
481 Gaudi::Hive::currentContext(),
482 *trk, *surf,
484 true, Trk::nonInteracting).release();
485
486 // the other way to do it:
487 //
488 // const TrackParameters* extrapolate(const Trk::Propagator& prop,
489 // const Trk::Track& trk,
490 // const Trk::Surface& sf,
491 // Trk::PropDirectiondir=anyDirection,Trk::BoundaryCheck bcheck = true)
492 // const;
493
494 if (param)
495 ATH_MSG_DEBUG ("Propagation successful " );
496 else
497 ATH_MSG_DEBUG ("Propagation failed ");
498
499 return param;
500}
501
502
504{
505 const EventContext& ctx = Gaudi::Hive::currentContext();
506 Amg::Vector3D momentum(0., 0., 0.);
507 if (vertex.vxTrackAtVertexAvailable())
508 {
509 // Use the parameters at the vertex
510 // (the tracks should be parallel but we will do the sum anyway)
511 for (const auto& trkAtVertex : vertex.vxTrackAtVertex())
512 {
513 const Trk::TrackParameters* paramAtVertex = trkAtVertex.perigeeAtVertex();
514 if (!paramAtVertex)
515 ATH_MSG_WARNING("VxTrackAtVertex does not have perigee at vertex");
516 else
517 momentum += paramAtVertex->momentum();
518 }
519 }
520 else if (vertex.nTrackParticles() == 1)
521 {
522 // Use the first measurement
523 const xAOD::TrackParticle *tp = vertex.trackParticle(0);
524 unsigned int index(0);
525 if (!tp || !tp->indexOfParameterAtPosition(index, xAOD::FirstMeasurement))
526 {
527 ATH_MSG_WARNING("No TrackParticle or no have first measurement");
528 }
529 else
530 momentum += tp->curvilinearParameters(index).momentum();
531 // OR last 3 values of trackParameters(index)
532 }
533 else
534 {
535 // Extrapolate track particles to vertex
536 // (the tracks should be parallel but we will do the sum anyway)
537 const Trk::PerigeeSurface *surface = new Trk::PerigeeSurface(vertex.position());
538 for (unsigned int i = 0; i < vertex.nTrackParticles(); ++i)
539 {
540 const xAOD::TrackParticle* tp = vertex.trackParticle( i );
541 if (!tp)
542 {
543 ATH_MSG_WARNING("NULL pointer to TrackParticle in vertex");
544 continue;
545 }
546 const Trk::TrackParameters* params = m_extrapolator->extrapolate(ctx,
547 tp->perigeeParameters(),
548 *surface,
549 Trk::alongMomentum).release();
550 if (!params)
551 ATH_MSG_DEBUG("Extrapolation to vertex (perigee) failed");
552 else
553 {
554 momentum += params->momentum();
555 delete params;
556 }
557 }
558 delete surface;
559 }
560
561 return momentum;
562}
563
564
565#if 0
566Trk::Intersection TBExtrapolTrackToCaloTool::getIntersectionInCalo(const Amg::Vector3D& position, const Amg::Vector3D& momentum, const CaloCell_ID::CaloSample sample) const
567{
568 Trk::Intersection result{Amg::Vector3D(0., 0., 0.), 0., false};
569
570 // get the destination Surface
571 const Trk::Surface* surface = m_calosurf->CreateUserSurface (sample, 0. /* offset */, momentum.eta());
572 if (!surface)
573 return result;
574
575 // intersect with calorimeter surface
576 result = surface->straightLineIntersection(position, momentum);
577 delete surface;
578 return result;
579}
580#endif
581
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Declaration of CaloDepthTool.
ICaloCoordinateTool interface declaration 30.9.2004 Creation of the class TBCalocoordinate by claire....
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
Implementation of the ICaloDepthTool interface.Given a Track direction, checks if it is in the Calori...
static void build_sample(CaloCell_ID::SUBCALO subCalo, bool barrel, int sampling_or_module, CaloCell_ID::CaloSample &sample)
translate between the 2 ways to label a sub-detector:
This class provides the client interface for accessing the detector description information common to...
Derived DataVector<T>.
Definition DataVector.h:795
This (clean) interface is implemented in the (rather dirty) ICaloCoordinateTool class,...
virtual Amg::Vector3D getMomentumAtVertex(const xAOD::Vertex &vertex, bool) const
TBExtrapolTrackToCaloTool(const std::string &type, const std::string &name, const IInterface *parent)
void CaloLocalPoint(const Trk::TrackParameters *parm, Amg::Vector3D *pt_ctb, Amg::Vector3D *pt_local)
virtual StatusCode finalize() override
void CaloVariables(const Trk::TrackParameters *parm, double &etaCaloLocal, double &phiCaloLocal)
now return the variables needed to compare with CaloClusters:
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
virtual StatusCode initialize() override
ToolHandle< Trk::IExtrapolator > m_extrapolator
CaloDepthTool * getCaloDepth()
access to the private tool used to define the extrapolation depth, needed to play with delta-eta
const Trk::TrackParameters * extrapolate(const Trk::Track &, const CaloCell_ID::CaloSample, const double, const Trk::PropDirection=Trk::alongMomentum, const Trk::ParticleHypothesis=Trk::undefined) const
ToolHandle< ICaloSurfaceBuilder > m_calosurf
bool TrackSeenByCalo(const Trk::Track *trk, const CaloCell_ID::CaloSample sample, const double offset, Amg::Vector3D *pt_ctb, Amg::Vector3D *pt_local)
The "do-it-all" method which combines the 3 steps.
double eta() const
Access method for pseudorapidity - from momentum.
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
Class describing the Line to which the Perigee refers to.
Abstract Base Class for tracking surfaces.
Intersection straightLineIntersection(const T &pars, bool forceDir=false, const Trk::BoundaryCheck &bchk=false) const
fst straight line intersection schema - templated for charged and neutral parameters
const DataVector< const TrackParameters > * trackParameters() const
Return a pointer to a vector of TrackParameters.
Eigen::Matrix< double, 3, 1 > Vector3D
@ alongMomentum
@ phi
Definition ParamDefs.h:75
ParametersBase< TrackParametersDim, Charged > TrackParameters
Definition index.py:1
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
@ FirstMeasurement
Parameter defined at the position of the 1st measurement.