ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackSplitterTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
16//#include "TrkFitterUtils/FitterTypes.h"
17#include "GaudiKernel/MsgStream.h"
20//#include "TrkParameters/MeasuredPerigee.h" //use perigee
25
28#include "GaudiKernel/ThreadLocalContext.h"
29
70
71//namespace InDetTrackSplitterHelpers{
72// /** A method to determine which half track the hit belongs to
73// */
74// bool inline CompareYPosition(Trk::MeasurementBase const* mb1, Trk::MeasurementBase const* mb2){
75// return mb1->globalPosition().y() > mb2->globalPosition().y();
76// }
77//}
78
79
80InDet::InDetTrackSplitterTool::InDetTrackSplitterTool( std::string const & type, std::string const & name, IInterface const* parent ) :
81 AthAlgTool( type, name, parent )
82{
83 declareInterface<IInDetTrackSplitterTool>(this);
84}
85
86//=========================================================
88
89
90//=========================================================
92{
93
94 msg(MSG::DEBUG) << "In initialize()" << endmsg;
95
98 if ((detStore()->retrieve(m_trtid)).isFailure()) {
99 msg(MSG::WARNING) << "Problem retrieving TRTID helper" << endmsg;
100 return StatusCode::SUCCESS;
101 }
102
105 if ((detStore()->retrieve(m_sctid)).isFailure()) {
106 msg(MSG::WARNING) << "Problem retrieving SCT ID helper" << endmsg;
107 return StatusCode::SUCCESS;
108 }
109
112 if(m_trkfitter.retrieve().isFailure()) {
113 msg(MSG::WARNING) << "Could not find refit tool " << m_trkfitter << endmsg;
114 return StatusCode::SUCCESS;
115 }
116
117 ATH_CHECK( m_outputUpperTracksName.initialize() );
118 ATH_CHECK( m_outputLowerTracksName.initialize() );
119
120 msg(MSG::DEBUG) << "InDetTrackSplitterTool initialized" << endmsg;
121 return StatusCode::SUCCESS;
122
123}
124
125//=========================================================
127{
128 msg(MSG::DEBUG) << "In finalize() "<< endmsg;
129 return StatusCode::SUCCESS;
130}
131
135std::pair<Trk::Track*, Trk::Track*> InDet::InDetTrackSplitterTool::splitInUpperLowerTrack(Trk::Track const& input,
136 bool siliconHitsOnly) const {
137 //std::cout << "input: " << input << std::endl;
138 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " In splitInUpperLowerTrack" <<endmsg;
139
140 //**The returned tracks */
141 Trk::Track* upperTrack(nullptr);
142 Trk::Track* lowerTrack(nullptr);
143
145 Trk::Perigee const* originalPerigee = input.perigeeParameters();
146
148 Trk::ParticleHypothesis hypo = input.info().particleHypothesis();
149
151 auto uppertraj = std::make_unique<Trk::TrackStates>();
152 auto lowertraj = std::make_unique<Trk::TrackStates>();
153
154 unsigned int totalNumberHits = 0;
155
156 unsigned int totalNumberPixelHits = 0;
157 unsigned int totalNumberSCTHits = 0;
158 unsigned int totalNumberTRTHits = 0;
159
160 unsigned int numberUpperPixelHits = 0;
161 unsigned int numberUpperSCTHits = 0;
162 unsigned int numberUpperTRTHits = 0;
163 unsigned int numberUpperPseudoMeas = 0;
164
165 unsigned int numberLowerPixelHits = 0;
166 unsigned int numberLowerSCTHits = 0;
167 unsigned int numberLowerTRTHits = 0;
168 unsigned int numberLowerPseudoMeas = 0;
169
170 //DataVector<Trk::MeasurementBase const>::const_iterator meas = input.measurementsOnTrack()->begin();
171 //DataVector<Trk::MeasurementBase const>::const_iterator measEnd = input.measurementsOnTrack()->end();
172 //for(;meas != measEnd; ++meas){
173 //Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(*meas);
174 Trk::TrackStates::const_iterator tsosit = input.trackStateOnSurfaces()->begin();
175 Trk::TrackStates::const_iterator tsosEnd = input.trackStateOnSurfaces()->end();
176 bool perigeeseen=false;
177 for(;tsosit != tsosEnd; ++tsosit){
178 if ((**tsosit).type(Trk::TrackStateOnSurface::Outlier)) continue;
179 if (originalPerigee==(**tsosit).trackParameters()){
180 perigeeseen=true;
181 uppertraj->push_back((**tsosit).clone());
182 lowertraj->push_back((**tsosit).clone());
183 continue;
184 }
185
186 if (m_keepmaterial &&
187 ((**tsosit).type(Trk::TrackStateOnSurface::Scatterer) ||
188 (**tsosit).type(Trk::TrackStateOnSurface::BremPoint) ||
189 (**tsosit).type(Trk::TrackStateOnSurface::CaloDeposit))) {
190 if (!perigeeseen)
191 uppertraj->push_back((**tsosit).clone());
192 else
193 lowertraj->push_back((**tsosit).clone());
194 continue;
195 }
196 const Trk::RIO_OnTrack *rio = nullptr;
197 const Trk::MeasurementBase *measb=(**tsosit).measurementOnTrack();
198 if (measb) rio=dynamic_cast<const Trk::RIO_OnTrack*>(measb);
199
200 if(rio){
201 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "an rio..." <<endmsg;
202
203 totalNumberHits++;
204
205 Identifier const& surfaceid = (rio->identify());
206
207 if (m_trtid->is_pixel(surfaceid))
208 ++totalNumberPixelHits;
209 if (m_trtid->is_sct(surfaceid))
210 ++totalNumberSCTHits;
211 if (m_trtid->is_trt(surfaceid))
212 ++totalNumberTRTHits;
213
214 //if( (*meas)->globalPosition().y() > 0){
215 if( !perigeeseen){
216
217 if (m_trtid->is_pixel(surfaceid))
218 ++numberUpperPixelHits;
219 if (m_trtid->is_sct(surfaceid))
220 ++numberUpperSCTHits;
221 if (m_trtid->is_trt(surfaceid))
222 ++numberUpperTRTHits;
223
224 if (!siliconHitsOnly || m_trtid->is_sct(surfaceid) ||
225 m_trtid->is_pixel(surfaceid))
226 uppertraj->push_back((**tsosit).clone());
227 }
228
229 // if( (*meas)->globalPosition().y() < 0){
230 if (perigeeseen) {
231
232 if (m_trtid->is_pixel(surfaceid))
233 ++numberLowerPixelHits;
234 if (m_trtid->is_sct(surfaceid))
235 ++numberLowerSCTHits;
236 if (m_trtid->is_trt(surfaceid))
237 ++numberLowerTRTHits;
238
239 if (!siliconHitsOnly || m_trtid->is_sct(surfaceid) ||
240 m_trtid->is_pixel(surfaceid))
241 // m_lowerHits.push_back( *meas);
242 lowertraj->push_back((**tsosit).clone());
243 }
244 } else {
245 if (msgLvl(MSG::VERBOSE))
246 msg(MSG::VERBOSE) << "Not an rio" << endmsg;
247 // Trk::PseudoMeasurementOnTrack const* ps =
248 // dynamic_cast<Trk::PseudoMeasurementOnTrack const*>(*measb);
250 dynamic_cast<const Trk::PseudoMeasurementOnTrack*>(measb);
251
252 if (ps) {
253 if (!perigeeseen || totalNumberHits == totalNumberTRTHits) {
254 if (msgLvl(MSG::DEBUG))
255 msg(MSG::DEBUG) << "Adding an upper pseudoMeasurement" << endmsg;
256 ++numberUpperPseudoMeas;
257 uppertraj->push_back((**tsosit).clone());
258 }
259 if (perigeeseen || totalNumberHits == totalNumberTRTHits) {
260 if (msgLvl(MSG::DEBUG))
261 msg(MSG::DEBUG) << "Adding a lower pseudoMeasurement" << endmsg;
262 ++numberLowerPseudoMeas;
263 lowertraj->push_back((**tsosit).clone());
264 }
265 }
266
267 const Trk::CompetingRIOsOnTrack* crot =
268 dynamic_cast<const Trk::CompetingRIOsOnTrack*>(measb);
269 if (crot) {
270 if (!perigeeseen)
271 uppertraj->push_back((**tsosit).clone());
272 else
273 lowertraj->push_back((**tsosit).clone());
274 }
275 }
276 }
277
278 Trk::Track upperorigtrack(input.info(),std::move(uppertraj),nullptr);
279 Trk::Track lowerorigtrack(input.info(),std::move(lowertraj),nullptr);
280
282 if(isConstrained(numberUpperPixelHits,numberUpperSCTHits,numberUpperTRTHits,numberUpperPseudoMeas)){
283
284 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "before calling upper fit" << endmsg;
285 //m_upperTrack = m_trkfitter->fit(m_upperHits, *originalPerigee, true, hypo);
286 upperTrack = (m_trkfitter->fit(Gaudi::Hive::currentContext(),upperorigtrack, false, hypo)).release();
287 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "after calling upper fit" << endmsg;
288
289 if(!upperTrack){
290 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Upper Fit Failed!" << endmsg ;
291 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
292 << numberUpperPixelHits << " upper Pixel hits, "
293 << numberUpperSCTHits << " upper SCT hits, "
294 << numberUpperTRTHits << "upper TRT hits"
295 << numberUpperPseudoMeas << "upper Pseudomeasurements"
296 << endmsg;
297
298 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
299 << totalNumberPixelHits << " total Pixel hits, "
300 << totalNumberSCTHits << " total SCT hits, "
301 << totalNumberTRTHits << "total TRT hits"
302 << endmsg;
303
304 }
305
306 }else{
307 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Not enough measurements on upper track. Fit fails." << endmsg ;
308 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
309 << numberUpperPixelHits << " upper Pixel hits, "
310 << numberUpperSCTHits << " upper SCT hits, "
311 << numberUpperTRTHits << "upper TRT hits"
312 << numberUpperPseudoMeas << "upper Pseudomeasurements"
313 << endmsg;
314 }
315
317 if(isConstrained(numberLowerPixelHits,numberLowerSCTHits,numberLowerTRTHits,numberLowerPseudoMeas)){
318
319 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "before calling lower fit" << endmsg;
320 lowerTrack = (m_trkfitter->fit(Gaudi::Hive::currentContext(),lowerorigtrack, false, hypo)).release();
321 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "after calling lower fit" << endmsg;
322
323 if(!lowerTrack){
324 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Lower Fit Failed!" << endmsg ;
325 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
326 << numberLowerPixelHits << " upper Pixel hits, "
327 << numberLowerSCTHits << " upper SCT hits, "
328 << numberLowerTRTHits << "upper TRT hits"
329 << numberLowerPseudoMeas << "upper Pseudomeasurements"
330 << endmsg;
331
332 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
333 << totalNumberPixelHits << " total Pixel hits, "
334 << totalNumberSCTHits << " total SCT hits, "
335 << totalNumberTRTHits << "total TRT hits"
336 << endmsg;
337 }
338
339 }else{
340 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Not enough measurements on lower track. Fit fails." << endmsg ;
341 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
342 << numberLowerPixelHits << " upper Pixel hits, "
343 << numberLowerSCTHits << " upper SCT hits, "
344 << numberLowerTRTHits << "upper TRT hits"
345 << numberLowerPseudoMeas << "upper Pseudomeasurements"
346 << endmsg;
347 }
348
349 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Leaving splitInUpperLowerTrack" <<endmsg;
350 return std::make_pair(upperTrack, lowerTrack);
351}
352
356 bool removeSilicon, bool applyConstraint ) const {
357 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " In stripTrack" <<endmsg;
358
360 Trk::Track* outputTrack(nullptr);
361
363 if(removeSilicon){
364 outputTrack = stripSiFromTrack(input);
365 }
367 else{
368 outputTrack = stripTRTFromTrack(input, applyConstraint);
369 }
370
371 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Leaving stripTrack" <<endmsg;
372 return outputTrack;
373}
374
378 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "In stripSiFromTrack" <<endmsg;
379
381 Trk::Track* outputTrack(nullptr);
382
384 Trk::MeasurementSet TRTHits;
385
387 Trk::Perigee const* originalPerigee = input.perigeeParameters();
388
390 Trk::ParticleHypothesis hypo = input.info().particleHypothesis();
391
393 Trk::PseudoMeasurementOnTrack const* constraint = makeThetaZ0Constraint(originalPerigee);
394
396 TRTHits.push_back(constraint);
397
398 unsigned int totalNumberTRTHits = 0;
399
400 DataVector<Trk::MeasurementBase const>::const_iterator meas = input.measurementsOnTrack()->begin();
401 DataVector<Trk::MeasurementBase const>::const_iterator measEnd = input.measurementsOnTrack()->end();
402 for(;meas != measEnd; ++meas){
403 Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(*meas);
404
405 if(!rio){
406 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "No ROT skipping measurement." <<endmsg;
407 continue;
408 }
409
410 Identifier const& surfaceid = (rio->identify());
411
412 if(!m_trtid->is_trt(surfaceid)){
413 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Removing Non-TRT hit." <<endmsg;
414 continue;
415 }
416
417 ++totalNumberTRTHits;
418 TRTHits.push_back(*meas);
419
420 }
421
423 // Should be Constrained !!!
424 //if(isConstrained(numberUpperPixelHits,numberUpperSCTHits,numberUpperTRTHits,numberUpperPseudoMeas)){
425
426 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "before calling fit" << endmsg;
427 outputTrack = (m_trkfitter->fit(Gaudi::Hive::currentContext(),TRTHits, *originalPerigee, true, hypo)).release();
428 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "after calling fit" << endmsg;
429
430 if(!outputTrack){
431 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Fit Failed!" << endmsg ;
432 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There were: "
433 << totalNumberTRTHits << "TRT hits"
434 << endmsg;
435 }
436
437 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Leaving stripSiFromTrack" <<endmsg;
438 return outputTrack;
439}
440
441
445 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "In stripTRTFromTrack" <<endmsg;
446
448 Trk::Track* outputTrack(nullptr);
449
451 Trk::MeasurementSet SiHits;
452
454 Trk::Perigee const* originalPerigee = input.perigeeParameters();
455
457 Trk::ParticleHypothesis hypo = input.info().particleHypothesis();
458
460 bool addedConstraint = false;
461
462 unsigned int totalNumberSiHits = 0;
463
464 DataVector<Trk::MeasurementBase const>::const_iterator meas = input.measurementsOnTrack()->begin();
465 DataVector<Trk::MeasurementBase const>::const_iterator measEnd = input.measurementsOnTrack()->end();
466 for(;meas != measEnd; ++meas){
467 Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(*meas);
468
469 if(!rio){
470 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "No ROT skipping measurement." <<endmsg;
471 continue;
472 }
473
474 Identifier const& surfaceid = (rio->identify());
475
476 if(applyConstraint && !addedConstraint && m_trtid->is_trt(surfaceid)){
477
482 Trk::StraightLineSurface const* trtSurf = dynamic_cast<Trk::StraightLineSurface const*>(&(rio->associatedSurface()));
483 if (not trtSurf){
484 ATH_MSG_DEBUG("Cast of rio associated surface to StraightLineSurface failed.");
485 continue;
486 }
488 Trk::PseudoMeasurementOnTrack const* constraint = makePConstraint(originalPerigee,trtSurf);
489
491 SiHits.push_back(constraint);
492
494 addedConstraint = true;
495 }
496
497 if(!m_trtid->is_sct(surfaceid) && !m_trtid->is_pixel(surfaceid)){
498 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Removing Non-Si hit." <<endmsg;
499 continue;
500 }
501
502 ++totalNumberSiHits;
503 SiHits.push_back(*meas);
504
505 }
506
508 // Should be Constrained !!!
509 //if(isConstrained(numberUpperPixelHits,numberUpperSCTHits,numberUpperTRTHits,numberUpperPseudoMeas)){
510
511 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "before calling fit" << endmsg;
512 outputTrack = (m_trkfitter->fit(Gaudi::Hive::currentContext(),SiHits, *originalPerigee, false, hypo)).release();
513 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "after calling fit" << endmsg;
514
515 if(!outputTrack){
516 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Fit Failed!" << endmsg ;
517 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There were: " << totalNumberSiHits << "TRT hits" << endmsg;
518 }
519
520 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Leaving stripTRTFromTrack" <<endmsg;
521 return outputTrack;
522}
523
527
528 if( !perigee->covariance() ) return nullptr;
529
532 Trk::DefinedParameter inputPMeasurement(perigee->parameters()[Trk::qOverP],Trk::qOverP);
533 std::array<Trk::DefinedParameter,1> constraints = {inputPMeasurement};
534
536 Amg::MatrixX constraintErrMatrix(1,1);
537 constraintErrMatrix(0,0)=(*perigee->covariance())(Trk::qOverP,Trk::qOverP);
538
541 std::move(constraintErrMatrix) ,*trtSurf);
542
543 return psmom;
544}
545
549 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "In makeThetaZ0Constraint" <<endmsg;
550
551 if( !perigee->covariance() ) return nullptr;
552
555 Trk::DefinedParameter inputTheta0Measurement(perigee->parameters()[Trk::theta],Trk::theta);
556 Trk::DefinedParameter inputZ0Measurement(perigee->parameters()[Trk::z0],Trk::z0);
557 std::array<Trk::DefinedParameter,2> constraints = {inputZ0Measurement, inputTheta0Measurement};
558
561 Amg::MatrixX constraintErrMatrix(2,2);
562 constraintErrMatrix(0,0) = (*perigee->covariance())(Trk::z0,Trk::z0);
563 constraintErrMatrix(0,1) = (*perigee->covariance())(Trk::z0,Trk::theta);
564 constraintErrMatrix(1,0) = (*perigee->covariance())(Trk::theta, Trk::z0);
565 constraintErrMatrix(1,1) = (*perigee->covariance())(Trk::theta, Trk::theta);
566
570 const Trk::PerigeeSurface & surface = perigee->associatedSurface();
571
575 std::move(constraintErrMatrix) ,
576 surface);
577
580 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Leaving makeThetaZ0Constraint" <<endmsg;
581 return psmom;
582}
583
588std::pair<Trk::Track*, Trk::Track*> InDet::InDetTrackSplitterTool::splitInOddEvenHitsTrack(Trk::Track const& input) const {
589 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " In splitInOddEvenHitsTrack" <<endmsg;
590
592 Trk::Track* oddTrack(nullptr);
593 Trk::Track* evenTrack(nullptr);
594
596 Trk::Perigee const* originalPerigee = input.perigeeParameters();
597
599 Trk::ParticleHypothesis hypo = input.info().particleHypothesis();
600
602 Trk::MeasurementSet oddHits;
603 Trk::MeasurementSet evenHits;
604
605 unsigned int totalNumberPixelHits = 0;
606 unsigned int totalNumberSCTHits = 0;
607 unsigned int totalNumberTRTHits = 0;
608 unsigned int totalNumberHits = 0;
609
610 unsigned int numberOddSCTHits = 0;
611 unsigned int numberOddPixelHits = 0;
612 unsigned int numberOddTRTHits = 0;
613 unsigned int numberOddPseudoMeas = 0;
614
615 unsigned int numberEvenPixelHits = 0;
616 unsigned int numberEvenSCTHits = 0;
617 unsigned int numberEvenTRTHits = 0;
618 unsigned int numberEvenPseudoMeas = 0;
619
621 std::vector<Trk::MeasurementBase const*> unusedSCTHits = getSCTHits(input);
622
623 DataVector<Trk::MeasurementBase const>::const_iterator meas = input.measurementsOnTrack()->begin();
624 DataVector<Trk::MeasurementBase const>::const_iterator measEnd = input.measurementsOnTrack()->end();
625 for(;meas != measEnd; ++meas){
626 Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(*meas);
627 if(rio){
628 Identifier const& surfaceid = (rio->identify());
629 if(m_trtid->is_pixel(surfaceid)) ++totalNumberPixelHits;
630 if(m_trtid->is_sct(surfaceid)) ++totalNumberSCTHits;
631 if(m_trtid->is_trt(surfaceid)) ++totalNumberTRTHits;
632
634 if( totalNumberHits % 2 == 1){
635
636 if(m_trtid->is_pixel(surfaceid)) ++numberOddPixelHits;
637 if(m_trtid->is_sct(surfaceid)) ++numberOddSCTHits;
638 if(m_trtid->is_trt(surfaceid)) ++numberOddTRTHits;
639
640 if(!m_trtid->is_sct(surfaceid)){
641 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "adding odd hit" <<endmsg;
642 oddHits.push_back( *meas);
643 ++totalNumberHits;
644 }else{
645
648 std::vector<Trk::MeasurementBase const* >::iterator result = find(unusedSCTHits.begin(), unusedSCTHits.end(), *meas);
649
651 if(result != unusedSCTHits.end()){
652
653 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "add the (odd) SCT hit" <<endmsg;
654 oddHits.push_back( *meas);
655 ++totalNumberHits;
656
658 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "removing the SCT hit from unused list" <<endmsg;
659 unusedSCTHits.erase(result);
660
662 result = findSCTHitsFromSameSpacePoint( *meas, unusedSCTHits);
663 if(result != unusedSCTHits.end()){
664 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "adding the other (odd) SCT hit in the spacepoint" <<endmsg;
665 oddHits.push_back( *result);
666 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "removing the SCT hit from unused list" <<endmsg;
667 unusedSCTHits.erase(result);
668 }
669 }
670 }
671 }else{
672 if(m_trtid->is_pixel(surfaceid))
673 ++numberEvenPixelHits;
674 if(m_trtid->is_sct(surfaceid))
675 ++numberEvenSCTHits;
676 if(m_trtid->is_trt(surfaceid))
677 ++numberEvenTRTHits;
678
679 if(!m_trtid->is_sct(surfaceid)){
680 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "add the (even) hit" <<endmsg;
681 evenHits.push_back( *meas);
682 ++totalNumberHits;
683 }else{
686 std::vector<Trk::MeasurementBase const* >::iterator result = find(unusedSCTHits.begin(), unusedSCTHits.end(), *meas);
687
689 if(result != unusedSCTHits.end()){
690
691 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "add the (even) SCT hit" <<endmsg;
692 evenHits.push_back( *meas);
693 ++totalNumberHits;
694
696 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "removing the SCT hit from unused list" <<endmsg;
697 unusedSCTHits.erase(result);
698
700 result = findSCTHitsFromSameSpacePoint( *meas, unusedSCTHits);
701 if(result != unusedSCTHits.end()){
702 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "adding the other (even) SCT hit in the spacepoint" <<endmsg;
703 evenHits.push_back( *result);
704 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "removing the SCT hit from unused list" <<endmsg;
705 unusedSCTHits.erase(result);
706 }
707 }
708 }
709 }
710 }else{
711 Trk::PseudoMeasurementOnTrack const* ps = dynamic_cast<Trk::PseudoMeasurementOnTrack const*>(*meas);
712
713 if(ps){
714 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Adding an odd pseudoMeasurement" <<endmsg;
715 ++numberOddPseudoMeas;
716 oddHits.push_back( ps);
717
718 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Adding an even pseudoMeasurement" <<endmsg;
719 ++numberEvenPseudoMeas;
720 evenHits.push_back( ps);
721 }
722 }
723 }
724
726 //std::sort(oddHits.begin(), oddHits.end(), InDetTrackSplitterHelpers::CompareYPosition );
727 //std::sort(evenHits.begin(), evenHits.end(), InDetTrackSplitterHelpers::CompareYPosition );
728
731 if(isConstrained(numberOddPixelHits,numberOddSCTHits,numberOddTRTHits,numberOddPseudoMeas)){
732
733 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "before calling odd fit" << endmsg;
734 oddTrack = (m_trkfitter->fit(Gaudi::Hive::currentContext(),oddHits, *originalPerigee, false, hypo)).release();
735 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "after calling odd fit" << endmsg;
736
737 if(!oddTrack){
738 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Odd Fit Failed!" << endmsg ;
739 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
740 << numberOddPixelHits << " odd Pixel hits, "
741 << numberOddSCTHits << " odd SCT hits, "
742 << numberOddTRTHits << " odd TRT hits"
743 << numberOddPseudoMeas << "odd Pseudomeasurements"
744 << endmsg;
745
746 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: "
747 << totalNumberPixelHits << " total Pixel hits, "
748 << totalNumberSCTHits << " total SCT hits, "
749 << totalNumberTRTHits << "total TRT hits"
750 << endmsg;
751 }
752
753 }else
754 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Not enough measurements on odd track. Fit fails." << endmsg ;
755
757 if(isConstrained(numberEvenPixelHits,numberEvenSCTHits,numberEvenTRTHits,numberEvenPseudoMeas)){
758
759 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "before calling even fit" << endmsg;
760 evenTrack = (m_trkfitter->fit(Gaudi::Hive::currentContext(),evenHits, *originalPerigee, false, hypo)).release();
761 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "after calling even fit" << endmsg;
762
763 if(!evenTrack){
764 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Even Fit Failed!" << endmsg ;
765 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There was: " << numberEvenSCTHits << " even si hits and "
766 << numberEvenTRTHits << "even TRT hits"<< endmsg;
767
768 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "There were: " << totalNumberSCTHits << " total Si hits and "
769 << totalNumberTRTHits << "total TRT hits"<< endmsg;
770 }
771
772 }else
773 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Not enough measurements on even track. Fit fails." << endmsg ;
774
775 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Leaving splitInOddEvenHitsTrack" <<endmsg;
776 return std::make_pair(oddTrack, evenTrack);
777}
778
788 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " In splitTracks" <<endmsg;
789
790 // const EventContext& ctx = Gaudi::Hive::currentContext();
792 if ( upperTracks.record( std::make_unique<TrackCollection>() ).isFailure() ) {
793 ATH_MSG_FATAL( "Failed to record upper tracks collection " << m_outputUpperTracksName.key() );
794 }
795
797 if ( lowerTracks.record( std::make_unique<TrackCollection>() ).isFailure() ) {
798 ATH_MSG_FATAL( "Failed to record upper tracks collection " << m_outputLowerTracksName.key() );
799 }
800
801 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "There are: " << inputTracks->size() << " input tracks."<< endmsg;
802
803 TrackCollection::const_iterator it = inputTracks->begin();
804 TrackCollection::const_iterator itE = inputTracks->end();
805 for (; it != itE; ++it){
806
808 if(trackIsCandidate( **it) ){
809 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Track is a candidate."<< endmsg;
810
811 std::pair<Trk::Track*, Trk::Track*> splitTracks = this->splitInUpperLowerTrack(**it);
812 //For debugging
813 //std::pair<Trk::Track*, Trk::Track*> splitTracks = this->splitInOddEvenHitsTrack(**it);
814
815 Trk::Track* upperTrack = splitTracks.first;
816 if(upperTrack){
817 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Upper track fit suceeded"<< endmsg;
818 upperTracks->push_back( upperTrack);
819 }else
820 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Upper track fit failed!"<< endmsg;
821
822 Trk::Track* lowerTrack = splitTracks.second;
823 if(lowerTrack){
824 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Lower track fit suceeded"<< endmsg;
825 lowerTracks->push_back( lowerTrack);
826 }else
827 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Lower track fit failed!"<< endmsg;
828
829 } else
830 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Track is NOT a candidate."<< endmsg;
831 }
832
833 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Leaving splitTracks" <<endmsg;
834}
835
841 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "In trackIsCandidate."<< endmsg;
842 Trk::Perigee const* trackPerigee = inputTrack.perigeeParameters();
843
844 if (!trackPerigee)
845 {
846 msg(MSG::WARNING) << "Found track with invalid perigee parameters. Not splitting." << endmsg;
847 return false;
848 }
849
850 //Trk::Perigee const* measuredperigee = dynamic_cast<Trk::Perigee const*>( trackPerigee );
851 double const d0 = trackPerigee->parameters()[Trk::d0];
852
853 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "do is: "<< d0 << endmsg;
854
856
857 //width of the cavity in the TRT
858 if( fabs(d0) < 600){
859 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "is a candidate" << endmsg;
860 return true;
861 }
862
863 if(msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "is NOT a candidate" << endmsg;
864 return false;
865}
866
870std::vector<Trk::MeasurementBase const*> InDet::InDetTrackSplitterTool::getSCTHits(Trk::Track const& input) const {
871 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "In getSCTHits " << endmsg;
872 std::vector<Trk::MeasurementBase const*> SCTHits;
873
874 DataVector<Trk::MeasurementBase const>::const_iterator meas = input.measurementsOnTrack()->begin();
875 DataVector<Trk::MeasurementBase const>::const_iterator measEnd = input.measurementsOnTrack()->end();
876 for(;meas != measEnd; ++meas){
877
878 Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(*meas);
879
880 if(rio){
881 Identifier const& surfaceid = (rio->identify());
882 if(m_trtid->is_sct(surfaceid)){
883 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "we've found an SCT hit " << endmsg;
884 SCTHits.push_back(*meas);
885 }
886 }
887 }
888
889 //if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "sorting the hits " << endmsg;
891 //std::sort(SCTHits.begin(), SCTHits.end(), InDetTrackSplitterHelpers::CompareYPosition );
892
893 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Leaving getSCTHits " << endmsg;
894 return SCTHits;
895}
896
901std::vector<Trk::MeasurementBase const*>::iterator InDet::InDetTrackSplitterTool::findSCTHitsFromSameSpacePoint(Trk::MeasurementBase const* sctHit, std::vector<Trk::MeasurementBase const*>& listOfSCTHits) const {
902 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in findSCTHitsFromSameSpacePoint " << endmsg;
903 std::vector<Trk::MeasurementBase const*>::iterator result = listOfSCTHits.end();
904
905 Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(sctHit);
906 if(rio){
907 Identifier const& surfaceid = (rio->identify());
908
909 int targetEta = m_sctid->eta_module(surfaceid);
910 int targetPhi = m_sctid->phi_module(surfaceid);
911
912 std::vector<Trk::MeasurementBase const*>::const_iterator meas = listOfSCTHits.begin();
913 std::vector<Trk::MeasurementBase const*>::const_iterator measEnd = listOfSCTHits.end();
914 for(;meas != measEnd; ++meas){
915 Trk::RIO_OnTrack const* candidateRio = dynamic_cast<Trk::RIO_OnTrack const*>(*meas);
916 if(candidateRio){
917 Identifier const& candidateSurfaceid = (candidateRio->identify());
918 if(m_sctid->eta_module(candidateSurfaceid) == targetEta && m_sctid->phi_module(candidateSurfaceid) == targetPhi){
919 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Found another hit in the SpacePoint " << endmsg;
920 result = find(listOfSCTHits.begin(), listOfSCTHits.end(), *meas);
921 }
922 }
923 }
924 }
925
926 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Leaving findSCTHitsFromSameSpacePoint " << endmsg;
927 return result;
928}
929
933bool InDet::InDetTrackSplitterTool::isConstrained(unsigned int nPixelHits, unsigned int nSCTHits, unsigned int nTRTHits, unsigned int nPseudomeasurements) const{
934 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "In isConstrained " << endmsg;
935
938 if( (( nPixelHits + nSCTHits) > 1 && (2*nPixelHits + nSCTHits + nTRTHits) > 5) ||
939 (nPseudomeasurements >= 1 && nTRTHits > 10)){
940 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Leaving isConstrained (true)" << endmsg;
941 return true;
942 }
943
944 if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Leaving isConstrained (false)" << endmsg;
945 return false;
946}
947
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_FATAL(x,...)
This is an Identifier helper class for the SCT subdetector.
This is an Identifier helper class for the TRT subdetector.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
BooleanProperty m_keepmaterial
Do we use the material on the input track.
Trk::PseudoMeasurementOnTrack const * makePConstraint(Trk::Perigee const *originialPerigee, Trk::StraightLineSurface const *trtSurf) const
Make the qOverP constraint.
SG::WriteHandleKey< TrackCollection > m_outputUpperTracksName
Output track collection names recorded in storgate.
virtual std::pair< Trk::Track *, Trk::Track * > splitInUpperLowerTrack(Trk::Track const &input, bool siliconHitsOnly=false) const
Splits a single input track into upper and lower parts (based on global y) returns a pair of track th...
bool trackIsCandidate(Trk::Track const &inputTrack) const
Track selection applied in the splitTracks method (for the moment this is just a d0 cut requiring the...
Trk::Track * stripSiFromTrack(Trk::Track const &input) const
Strip the Si hits, fit the remaining with a theta, z0 constraint.
std::vector< Trk::MeasurementBase const * > getSCTHits(Trk::Track const &input) const
Return a vector of the SCT hits on track.
virtual Trk::Track * stripTrack(Trk::Track const &input, bool removeSilicon=true, bool applyConstraint=true) const
Takes a combined ID track and either 1) if removeSilicon = true Strips off the Si hits.
virtual StatusCode initialize()
standard Athena-Algorithm methods
std::vector< Trk::MeasurementBaseconst * >::iterator findSCTHitsFromSameSpacePoint(Trk::MeasurementBase const *sctHit, std::vector< Trk::MeasurementBase const * > &listOfSCTHits) const
Logic to check if there is another SCT hit associated with the input hit, which forms a space point.
InDetTrackSplitterTool(std::string const &, std::string const &, IInterface const *)
default constructor
PublicToolHandle< Trk::ITrackFitter > m_trkfitter
Helper Functions.
Trk::Track * stripTRTFromTrack(Trk::Track const &input, bool applyConstraint=true) const
Strip the TRT hits, fit the remaining with a qOverP constraint.
virtual void splitTracks(TrackCollection const *inputTracks) const
Takes a trackCollection, splits them according to upper and lower parts and fills two track collectio...
bool isConstrained(unsigned int nPixelHits, unsigned int nSCTHits, unsigned int nTRTHits, unsigned int nPseudomeasurements) const
Logic to check if the track is constrained given the number of various types of hits.
SG::WriteHandleKey< TrackCollection > m_outputLowerTracksName
Trk::PseudoMeasurementOnTrack const * makeThetaZ0Constraint(Trk::Perigee const *originialPerigee) const
Make the theta and z0 constraint.
virtual ~InDetTrackSplitterTool()
default destructor
virtual std::pair< Trk::Track *, Trk::Track * > splitInOddEvenHitsTrack(Trk::Track const &input) const
Splits a single input track into odd and even parts (with logic to aviod splitting SCT space points).
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
This class is the pure abstract base class for all fittable tracking measurements.
virtual const S & associatedSurface() const override final
Access to the Surface method.
Class describing the Line to which the Perigee refers to.
Class to handle pseudo-measurements in fitters and on track objects.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
virtual const Surface & associatedSurface() const override=0
returns the surface for the local to global transformation
Identifier identify() const
return the identifier -extends MeasurementBase
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
@ BremPoint
This represents a brem point on the track, and so will contain TrackParameters and MaterialEffectsBas...
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
@ CaloDeposit
This TSOS contains a CaloEnergy object.
const Perigee * perigeeParameters() const
return Perigee.
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
std::vector< const MeasurementBase * > MeasurementSet
vector of fittable measurements
Definition FitterTypes.h:30
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ d0
Definition ParamDefs.h:63
@ z0
Definition ParamDefs.h:64
std::pair< double, ParamDefs > DefinedParameter
Typedef to of a std::pair<double, ParamDefs> to identify a passed-through double as a specific type o...
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.