ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_TrackExtensionToolCosmics.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// Implementation file for class InDet::TRT_TrackExtensionToolCosmics
8// (c) ATLAS Detector software
11
12
13
14
20//
23#include <iostream>
24#include <utility>
25#include <cmath>
26
28// Constructor
30
32(const std::string& t,const std::string& n,const IInterface* p)
33 : AthAlgTool(t,n,p)
34{
35 declareInterface<ITRT_TrackExtensionTool>(this);
36}
37
39// Destructor
41
43= default;
44
46// Initialisation
48
50{
51 StatusCode sc = AlgTool::initialize();
52
53 // Get RIO_OnTrack creator without drift time information
54 //
55 if(m_riontrackN.retrieve().isFailure()) {
56 ATH_MSG_FATAL("Failed to retrieve tool "<< m_riontrackN);
57 return StatusCode::FAILURE;
58 }
59 ATH_MSG_DEBUG("Retrieved tool " << m_riontrackN);
60
61 ATH_CHECK( m_extrapolator.retrieve() );
62
63 if ((detStore()->retrieve(m_trtid)).isFailure()) {
64 ATH_MSG_FATAL("Problem retrieving TRTID helper");
65 return StatusCode::FAILURE;
66 }
67
68 // Get output print level
69 //
70 m_outputlevel = msg().level()-MSG::DEBUG;
71 if(m_outputlevel<=0) {
72 m_nprint=0; msg(MSG::DEBUG)<<(*this)<<endmsg;
73 }
74
75
76 //Initialize container
77 ATH_CHECK(m_trtname.initialize());
78
79 return sc;
80
81
82
83
84}
85
87// Finalize
89
91{
92 StatusCode sc = AlgTool::finalize();
93
94 return sc;
95}
96
98// Dumps relevant information into the MsgStream
100
101MsgStream& InDet::TRT_TrackExtensionToolCosmics::dump( MsgStream& out ) const
102{
103 out<<std::endl;
104 if(m_nprint) return dumpEvent(out);
105 return dumpConditions(out);
106}
107
108
110// Dumps conditions information into the MsgStream
112
114{
115
116 return out;
117}
118
120// Dumps event information into the ostream
122
124{
125 return out;
126}
127
129// Dumps relevant information into the ostream
131
132std::ostream& InDet::TRT_TrackExtensionToolCosmics::dump( std::ostream& out ) const
133{
134 return out;
135}
136
138// Overload of << operator MsgStream
140
141MsgStream& InDet::operator <<
142 (MsgStream& sl,const InDet::TRT_TrackExtensionToolCosmics& se)
143{
144 return se.dump(sl);
145}
146
148// Overload of << operator std::ostream
150
151std::ostream& InDet::operator <<
152 (std::ostream& sl,const InDet::TRT_TrackExtensionToolCosmics& se)
153{
154 return se.dump(sl);
155}
156
158// Track extension initiation
160
161std::unique_ptr<InDet::ITRT_TrackExtensionTool::IEventData>
163{
164 //create the boundary surfaces
165 //
167 if(not trtcontainer.isValid() && m_outputlevel<=0) {
168 std::stringstream msg;
169 msg << "Missing TRT_DriftCircleContainer " << m_trtname.key();
170 throw std::runtime_error( msg.str() );
171 }
172
173 std::unique_ptr<EventData> event_data(new EventData(trtcontainer.cptr()));
174
175 Amg::RotationMatrix3D r; r.setIdentity();
176 Amg::Transform3D t = Amg::Transform3D(r * Amg::Translation3D(Amg::Vector3D::Zero()));
177 event_data->m_trtcylinder= new Trk::CylinderSurface(t,1150.,3000.);
179 event_data->m_trtdiscA = new Trk::DiscSurface (transf,1.,1200.);
180 transf = Amg::Transform3D(r * Amg::Translation3D(Amg::Vector3D(0.,0.,-3000)));
181 event_data->m_trtdiscC = new Trk::DiscSurface (transf,1.,1200.);
182
183 return std::unique_ptr<InDet::ITRT_TrackExtensionTool::IEventData>(event_data.release());
184
185}
186
188// Main methods for track extension to TRT
190
191std::vector<const Trk::MeasurementBase*>&
193 const Trk::Track& Tr,
196{
199
200 event_data.m_measurement.clear();
201
202 if(not event_data.m_trtcontainer) return event_data.m_measurement;
203
204 const Trk::TrackStates*
205 tsos = Tr.trackStateOnSurfaces();
206
208 par = (*(tsos->rbegin()))->trackParameters(); if(!par ) return event_data.m_measurement;
210 parb = (*(tsos->begin()))->trackParameters();
211
212
213 if(parb && par!=parb) {
214
215 const Amg::Vector3D& g1 = par ->position();
216 const Amg::Vector3D& g2 = parb->position();
217 if((g2.x()*g2.x()+g2.y()*g2.y()) > (g1.x()*g1.x()+g1.y()*g1.y())) par=parb;
218 }
219
220 if(Tr.perigeeParameters()) {
221 return extendTrack(ctx, Tr.perigeeParameters(),event_data, used);
222 }
223 event_data.m_measurement.clear();
224 return event_data.m_measurement;
225}
226
228// Main methods for track extension to TRT
230void InDet::TRT_TrackExtensionToolCosmics::analyze_tpars(const std::vector<const Trk::TrackParameters* >* tpars,
232{
233 msg(MSG::DEBUG)<<"Number of tpars: "<<tpars->size()<<endmsg;
234
235 double lastz=-99999;
236 std::vector< const Trk::TrackParameters* >::const_iterator parameterIter = tpars->begin();
237 for ( ; parameterIter != tpars->end(); ++parameterIter) {
238 msg(MSG::DEBUG)<< "par pos: " << (**parameterIter).position() <<endmsg;
239
240 if ( (*parameterIter)->associatedSurface().associatedDetectorElementIdentifier()==0 ) {
241 msg(MSG::DEBUG)<<"No DE identifier!!!"<<endmsg;
242 continue;
243 }
244
245 const Identifier& DCId = (*parameterIter)->associatedSurface().associatedDetectorElementIdentifier();
246 if ( m_trtid->is_trt( DCId ) ) {
247
248 IdentifierHash detElements[3];
249 detElements[1]=(*parameterIter)->associatedSurface().associatedDetectorElement()->identifyHash();
251 //fill entry 0 and 2 with the neighbours (different in phi but identical in layer)
252 int bec=m_trtid->barrel_ec(DCId);
253 int phi_mod=m_trtid->phi_module(DCId);
254 int layer_or_wheel=m_trtid->layer_or_wheel(DCId);
255 int slay=m_trtid->straw_layer(DCId);
256
257 phi_mod-=1;
258 if(phi_mod<0) phi_mod=31;
259
260 Identifier temp=m_trtid->straw_id(bec,phi_mod,layer_or_wheel,slay,0);
261 detElements[0]=m_trtid->straw_layer_hash(temp);
262
263 phi_mod+=2;
264 if(phi_mod>31) phi_mod=0;
265 temp=m_trtid->straw_id(bec,phi_mod,layer_or_wheel,slay,0);
266 detElements[2]=m_trtid->straw_layer_hash(temp);
267 }
268 double maxdist=m_roadwidth;
269 const InDet::TRT_DriftCircle *circ=nullptr;
270
271 for(int i=-1;i<2;i++) {
272 if(m_searchNeighbour || i==0){
273
274 //check if this PRD exists
275 // get the driftCircleCollection belonging to this id
276 const InDet::TRT_DriftCircleCollection *container = event_data.m_trtcontainer->indexFindPtr(detElements[i+1]);
277
278 if(container==nullptr) {
279 msg(MSG::DEBUG)<<"for the current detectorElement no DriftCircleContainer seems to exist: "<<m_trtid->show_to_string(m_trtid->layer_id(detElements[i+1]))<<endmsg;
280 continue;
281 }
282
283 msg(MSG::DEBUG)<< "There are " << container->size() << " entries in the TRT_DriftCircleCollection "<<m_trtid->show_to_string(m_trtid->layer_id(detElements[i+1])) <<endmsg;
284
285 //take the closest one in case it satisfies some default cuts
286 InDet::TRT_DriftCircleCollection::const_iterator driftCircleIterator = container->begin();
287 for (; driftCircleIterator != container->end(); ++driftCircleIterator) {
288
289 //get the associated surface of the driftcircle
290 const Trk::Surface &dc_surface=(*driftCircleIterator)->detectorElement()->surface((*driftCircleIterator)->identify());
291
292 //get the local position of the track prediction in the frame of the driftcircle
293 std::optional<Amg::Vector2D> lpos=dc_surface.globalToLocal((*parameterIter)->position());
294
295 double distance=m_roadwidth+1;
296 if(lpos){
297 distance = std::abs(lpos->x());
298 msg(MSG::DEBUG)<<"Hit "<<m_trtid->show_to_string((*driftCircleIterator)->identify())<<" has a distance of "<<distance<<endmsg;
299
300 double dist_locz=std::abs(lpos->y());
301 if(distance<m_roadwidth+1){
302 if(!dc_surface.insideBounds(*lpos,m_roadwidth,m_roadwidth_locz)){
303 msg(MSG::DEBUG)<<"Hit not inside surface bounds! "<<distance<<" , "<<dist_locz<<endmsg;
304 msg(MSG::DEBUG)<<"\trejecting hit"<<endmsg;
305 distance=m_roadwidth+1;
306 }
307 }
308
309 }
310
311 if(distance<maxdist){
312 maxdist=distance;
313 circ=(*driftCircleIterator);
314 }
315 }
316 }
317 }
318 msg(MSG::DEBUG)<<"Maximal distance: "<<maxdist<<endmsg;
319 if(circ){
320 msg(MSG::DEBUG)<<"Found Driftcircle! Adding it to list ..."<<m_trtid->show_to_string(circ->identify())<<endmsg;
321 if (lastz<-9999) lastz=(**parameterIter).position().z();
322 if (std::abs(lastz-(**parameterIter).position().z())>500.) return;
323 lastz=(**parameterIter).position().z();
324 const Trk::StraightLineSurface *slsurf=dynamic_cast<const Trk::StraightLineSurface *>(&circ->detectorElement()->surface(circ->identify())); if(!slsurf) continue;
325 Trk::AtaStraightLine atasl((**parameterIter).position(),(**parameterIter).parameters()[Trk::phi],(**parameterIter).parameters()[Trk::theta],(**parameterIter).parameters()[Trk::qOverP],*slsurf);
326 const Trk::MeasurementBase *newmeas=m_riontrackN->correct(*circ,atasl,Gaudi::Hive::currentContext());
327 event_data.m_measurement.push_back(newmeas);
328
329 }
330 }
331 }
332}
333
334namespace InDet{
336 public:
338 bool operator()(const Trk::TrackParameters *par1,const Trk::TrackParameters *par2) const{
339 if (m_theta>M_PI_2) return (par1->position().z()>par2->position().z());
340 else return (par1->position().z()<par2->position().z());
341 }
342 private:
343 double m_theta;
344 };
345}
346
348// Main methods for track extension to TRT
350
351std::vector<const Trk::MeasurementBase*>&
353 const Trk::TrackParameters * par,
356{
359
360 event_data.m_measurement.clear();
361
362 std::vector<Identifier> vecID;
363 std::vector<const Trk::TrackParameters*> vecTP;
364
365
366
367 std::vector<const Trk::TrackParameters* >* tpars_down=nullptr;
368 std::vector<const Trk::TrackParameters* >* tpars_up=nullptr;
369 const Trk::Perigee *per=dynamic_cast<const Trk::Perigee *>(par);
370 if (!per) {
371 msg(MSG::FATAL)<<"Track perigee not found!"<<endmsg;
372 return event_data.m_measurement;
373 }
374
375 if (!event_data.m_trtcontainer) {
376 return event_data.m_measurement;
377 }
378
379 InDet::TRT_DriftCircleContainer::const_iterator
380 w = event_data.m_trtcontainer->begin(),we = event_data.m_trtcontainer->end();
381 for(; w!=we; ++w) {
382 if ((**w).empty()) continue;
383 const Trk::Surface &surf=(**(**w).begin()).detectorElement()->surface();
384 Amg::Vector3D pos=intersect(&surf,per);
385 Amg::Vector3D locintersec = (surf.transform().inverse())*pos;
386 Amg::Vector2D locpos(locintersec.x(), locintersec.y());
387 if (pos.perp()<500. || !surf.insideBounds(locpos,50.,50.)) continue;
388
389 Amg::Vector3D pos2=surf.transform()*Amg::Vector3D(locintersec.x(),locintersec.y(),0);
390
391 const Trk::PlaneSurface *plsurf=dynamic_cast<const Trk::PlaneSurface *>(&surf);
392 const Trk::DiscSurface *discsurf=dynamic_cast<const Trk::DiscSurface *>(&surf);
393 Trk::TrackParameters *newpar=nullptr;
394 if (plsurf) newpar=new Trk::AtaPlane(pos2,per->parameters()[Trk::phi],per->parameters()[Trk::theta],per->parameters()[Trk::qOverP],*plsurf);
395 else newpar=new Trk::AtaDisc(pos2,per->parameters()[Trk::phi],per->parameters()[Trk::theta],per->parameters()[Trk::qOverP],*discsurf);
396 vecTP.push_back(newpar);
397 }
398 tpars_down=new std::vector<const Trk::TrackParameters* >;
399 tpars_up=new std::vector<const Trk::TrackParameters* >;
400
401 if(!tpars_down || !tpars_up) return event_data.m_measurement;
402
403 tp_sort_cosmics sorter(per->parameters()[Trk::theta]);
404 std::sort(vecTP.begin(),vecTP.end(),sorter);
405 for (const auto *tmppar : vecTP){
406 if ((per->parameters()[Trk::theta]>M_PI/2 && per->position().z()<tmppar->position().z()) || (per->parameters()[Trk::theta]<M_PI/2 && per->position().z()>tmppar->position().z())) tpars_up->push_back(tmppar);
407 else tpars_down->push_back(tmppar);
408
409 }
410 if (!tpars_up->empty()) std::reverse(tpars_up->begin(),tpars_up->end());
411
412
413 if(tpars_down){
414 analyze_tpars(tpars_down,event_data);
415 }
416 if(tpars_up){
417 analyze_tpars(tpars_up, event_data);
418 }
419
420 //clean up
421 if(tpars_up){
422 std::vector< const Trk::TrackParameters* >::const_iterator parameterIter= tpars_up->begin();
423 for ( ; parameterIter != tpars_up->end(); ++parameterIter) {
424 delete *parameterIter;
425 }
426 delete tpars_up;
427 }
428
429 if(tpars_down){
430 std::vector< const Trk::TrackParameters* >::const_iterator parameterIter = tpars_down->begin();
431 for ( ; parameterIter != tpars_down->end(); ++parameterIter) {
432 delete *parameterIter;
433 }
434 delete tpars_down;
435 }
436
437 msg(MSG::DEBUG)<<"Found "<<event_data.m_measurement.size()<<" driftcircles"<<endmsg;
438
439 return event_data.m_measurement;
440}
441
443// Main methods for segment findinf in TRT
445
454
455
458 par, Trk::PropDirection dir,
460{
461
462 const EventContext& ctx = Gaudi::Hive::currentContext();
463 const Trk::TrackParameters* test=m_extrapolator->extrapolateDirectly(ctx,
464 par,
465 *event_data.m_trtcylinder,
466 dir,true,Trk::muon).release();
467 if(test){
468 delete test;
469 return event_data.m_trtcylinder;
470 }
471
472 test=m_extrapolator->extrapolateDirectly(ctx,
473 par,
474 *event_data.m_trtdiscA,dir,true,Trk::muon).release();
475 if(test){
476 delete test;
477 return event_data.m_trtdiscA;
478 }
479
480 test=m_extrapolator->extrapolateDirectly(ctx,
481 par,
482 *event_data.m_trtdiscC,dir,true,Trk::muon).release();
483 if(test){
484 delete test;
485 return event_data.m_trtdiscC;
486 }
487
488 return nullptr;
489}
490
492 // Calculate intersection of helix with silicon module. Assume barrel modules parallel to z-axis, endcap modules perpendicular to z-axis
493
494 double sinTheta = std::sin(per->parameters()[3]);
495 double r= (std::abs(per->parameters()[Trk::qOverP]) > 1e-10) ? -sinTheta/(per->parameters()[Trk::qOverP]*0.6) : 1e6;
496 double xc=per->position().x()-r*std::sin(per->parameters()[2]);
497 double yc=per->position().y()+r*std::cos(per->parameters()[2]);
498 double phi0=std::atan2(per->position().y()-yc,per->position().x()-xc);
499 double theta=per->parameters()[Trk::theta];
500 double z0=per->position().z();
501
502 if (std::abs(surf->normal().z())>0.5){ // endcap module
503 double delta_s=(surf->center().z()-z0)/cos(theta);
504 double delta_phi=delta_s*std::sin(theta)/r;
505 double x=xc+std::abs(r)*std::cos(phi0+delta_phi);
506 double y=yc+std::abs(r)*std::sin(phi0+delta_phi);
507 return Amg::Vector3D(x,y,surf->center().z());
508
509
510
511 }
512 else { // barrel module
513 double x1=surf->center().x();
514 double y1=surf->center().y();
515 double x2=x1+surf->transform()(0,0);
516 double y2=y1+surf->transform()(1,0);
517 double a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
518 double b=2*( (x2 - x1)*(x1 - xc) + (y2 - y1)*(y1 - yc));
519 double c=xc*xc + yc*yc + x1*x1 + y1*y1 - 2*(xc*x1 + yc*y1) - r*r;
520 double discr=b*b-4*a*c;
521 if (discr<0) return Amg::Vector3D(0,0,0);
522 double u1=(-b-std::sqrt(discr))/(2*a);
523 double u2=(-b+std::sqrt(discr))/(2*a);
524 double u=(std::abs(u1)<std::abs(u2)) ? u1 : u2;
525 double x=x1+u*(x2-x1);
526 double y=y1+u*(y2-y1);
527 double phi=std::atan2(y-yc,x-xc);
528 double delta_phi=phi-phi0;
529 if (std::abs(std::abs(delta_phi)-2*M_PI)<std::abs(delta_phi)){
530 if (delta_phi<0) delta_phi+=2*M_PI;
531 else delta_phi-=2*M_PI;
532
533 }
534 double delta_z=r*delta_phi/std::tan(theta);
535
536 double z=z0+delta_z;
537 return Amg::Vector3D(x,y,z);
538 }
539}
540
542// Methods for track extension to TRT for pixles+sct tracks
543// and new track production
545
554
#define M_PI
Scalar phi() const
phi method
Scalar theta() const
theta method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
static Double_t a
static Double_t sc
This is an Identifier helper class for the TRT subdetector.
#define y
#define x
#define z
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
This is a "hash" representation of an Identifier.
virtual const InDetDD::TRT_BaseElement * detectorElement() const override final
return the detector element corresponding to this PRD
std::vector< const Trk::MeasurementBase * > m_measurement
ToolHandle< Trk::IRIO_OnTrackCreator > m_riontrackN
Trk::Surface * findBoundarySurface(const Trk::TrackParameters &par, Trk::PropDirection dir, InDet::TRT_TrackExtensionToolCosmics::EventData &event_data) const
SG::ReadHandleKey< TRT_DriftCircleContainer > m_trtname
static MsgStream & dumpConditions(MsgStream &out)
void analyze_tpars(const std::vector< const Trk::TrackParameters * > *tpars, InDet::TRT_TrackExtensionToolCosmics::EventData &event_data) const
ToolHandle< Trk::IExtrapolator > m_extrapolator
virtual Trk::TrackSegment * findSegment(const EventContext &ctx, const Trk::TrackParameters *, InDet::ITRT_TrackExtensionTool::IEventData &virt_event_data, InDet::TRT_DetElementLink_xk::TRT_DetElemUsedMap &used) const override
virtual Trk::Track * newTrack(const EventContext &ctx, const Trk::Track &, InDet::ITRT_TrackExtensionTool::IEventData &virt_event_data, InDet::TRT_DetElementLink_xk::TRT_DetElemUsedMap &used) const override
virtual std::vector< const Trk::MeasurementBase * > & extendTrack(const EventContext &ctx, const Trk::Track &, InDet::ITRT_TrackExtensionTool::IEventData &virt_event_data, InDet::TRT_DetElementLink_xk::TRT_DetElemUsedMap &used) const override
static Amg::Vector3D intersect(const Trk::Surface *surf, const Trk::Perigee *per)
virtual MsgStream & dump(MsgStream &out) const override
TRT_TrackExtensionToolCosmics(const std::string &, const std::string &, const IInterface *)
virtual std::unique_ptr< InDet::ITRT_TrackExtensionTool::IEventData > newEvent(const EventContext &ctx) const override
bool operator()(const Trk::TrackParameters *par1, const Trk::TrackParameters *par2) const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Class for a CylinderSurface in the ATLAS detector.
Class for a DiscSurface in the ATLAS detector.
Definition DiscSurface.h:54
static EventData & getPrivateEventData(InDet::ITRT_TrackExtensionTool::IEventData &virt_event_data)
This class is the pure abstract base class for all fittable tracking measurements.
const Amg::Vector3D & position() const
Access method for the position.
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
Identifier identify() const
return the identifier
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
Abstract Base Class for tracking surfaces.
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const =0
Specified by each surface type: GlobalToLocal method without dynamic memory allocation - boolean chec...
virtual bool insideBounds(const Amg::Vector2D &locpos, double tol1=0., double tol2=0.) const =0
virtual methods to be overwritten by the inherited surfaces
virtual const Amg::Vector3D & normal() const
Returns the normal vector of the Surface (i.e.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
Class for a generic track segment that holdes polymorphic Trk::MeasurementBase objects,...
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const Perigee * perigeeParameters() const
return Perigee.
holding In fact this class is here in order to allow STL container for all features This class is sho...
int r
Definition globals.cxx:22
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
Primary Vertex Finder.
ParametersT< TrackParametersDim, Charged, DiscSurface > AtaDisc
PropDirection
PropDirection, enum for direction of the propagation.
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ phi
Definition ParamDefs.h:75
ParametersBase< TrackParametersDim, Charged > TrackParameters
ParametersT< TrackParametersDim, Charged, PlaneSurface > AtaPlane
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
void reverse(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of reverse for DataVector/List.