22 #include "Identifier/Identifier.h"
34 const IInterface*
p) :
38 declareInterface<ITrackHoleSearchTool>(
this);
48 if (
sc.isFailure())
return sc;
56 return StatusCode::SUCCESS;
67 std::vector<int>& information,
69 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
nullptr;
73 for (
const auto *listOfHole : *listOfHoles) {
77 listOfHoles =
nullptr;
84 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
new std::vector<const Trk::TrackStateOnSurface*>;
88 for (
const auto *listOfHole : *listOfHoles)
89 output->push_back(listOfHole);
92 listOfHoles =
nullptr;
99 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
new std::vector<const Trk::TrackStateOnSurface*>;
103 listOfHoles =
nullptr;
117 std::vector<int>* information,
118 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles,
133 std::map<const Identifier, const Trk::TrackStateOnSurface*> mapOfHits;
145 std::map<const Identifier, std::pair<const Trk::TrackParameters*,const bool> > mapOfPredictions;
148 Gaudi::Hive::currentContext(),
track, partHyp, mapOfHits, mapOfPredictions);
154 ATH_MSG_DEBUG(
"List of hits not properly obtained, abort hole search.");
157 for (
auto & mapOfPrediction : mapOfPredictions) {
158 delete (mapOfPrediction.second).
first;
159 (mapOfPrediction.second).
first =
nullptr;
168 std::map<const Identifier, const Trk::TrackStateOnSurface*>& mapOfHits,
169 std::map<
const Identifier, std::pair<const Trk::TrackParameters*,const bool> >& mapOfPredictions)
const {
181 for (
const auto *iterTSOS : *
track.trackStateOnSurfaces()) {
187 if (iterTSOS->measurementOnTrack() !=
nullptr
188 && iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement() !=
nullptr
189 && iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify() != 0) {
190 id = iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify();
192 }
else if (iterTSOS->trackParameters() !=
nullptr
193 && iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr
194 && iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0) {
195 id = iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement()->identify();
201 mapOfHits.insert(std::pair<const Identifier, const Trk::TrackStateOnSurface*>(
id,iterTSOS));
204 if (!iterTSOS->trackParameters() &&
m_warning<10) {
206 ATH_MSG_WARNING(
"No track parameters available for state of type measurement");
212 if (
m_cosmic && !firstsipar && iterTSOS->trackParameters()) firstsipar=iterTSOS->trackParameters();
213 if (iterTSOS->trackParameters()) {
214 ATH_MSG_VERBOSE(
"TSOS pos: " << iterTSOS->trackParameters()->position()
215 <<
" r: " << sqrt(
pow(iterTSOS->trackParameters()->position().x(),2)
216 +
pow(iterTSOS->trackParameters()->position().y(),2))
217 <<
" Si measurement");
220 if (iterTSOS->trackParameters()) {
221 ATH_MSG_VERBOSE(
"TSOS pos: " << iterTSOS->trackParameters()->position()
222 <<
" r: " << sqrt(
pow(iterTSOS->trackParameters()->position().x(),2)
223 +
pow(iterTSOS->trackParameters()->position().y(),2))
224 <<
" TRT measurement");
230 ATH_MSG_DEBUG(
"Number of Si hits + outliers on original track: " << mapOfHits.size() <<
" , hits only: " << imeas);
238 std::unique_ptr<const Trk::TrackParameters> startParameters;
255 ATH_MSG_ERROR (
"cast to CylinderSurface failed, should never happen !");
267 if (!startParameters) {
268 ATH_MSG_DEBUG(
"no start parameters on SCT cylinder, try TRT ec disc");
295 if (
track.perigeeParameters()) {
296 startParameters.reset(
track.perigeeParameters()->clone());
297 }
else if (
track.trackParameters()->front()) {
302 *(
track.trackParameters()->front()),
310 if (!startParameters) {
311 ATH_MSG_DEBUG(
"No start point obtained, hole search not performed.");
316 bool foundFirst =
false;
320 ATH_MSG_DEBUG(
"We are looking for an extended list of holes, so add eventual holes before first hits");
334 while (iterTSOS!=
track.trackStateOnSurfaces()->end()
342 <<
" r: " << sqrt(
pow(startParameters->
position().x(),2)
346 int nmeas=(
int)
track.measurementsOnTrack()->size();
347 for (; iterTSOS!=
track.trackStateOnSurfaces()->end();++iterTSOS) {
361 if ((*iterTSOS)->measurementOnTrack() !=
nullptr
362 && (*iterTSOS)->measurementOnTrack()->associatedSurface().associatedDetectorElement() !=
nullptr
363 && (*iterTSOS)->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify() != 0) {
364 id = (*iterTSOS)->measurementOnTrack()->
associatedSurface().associatedDetectorElement()->identify();
365 surf = &(*iterTSOS)->measurementOnTrack()->associatedSurface();
367 }
else if ((*iterTSOS)->trackParameters() !=
nullptr
368 && (*iterTSOS)->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr
369 && (*iterTSOS)->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0) {
371 surf = &((*iterTSOS)->trackParameters()->associatedSurface());
374 surf=&((*iterTSOS)->trackParameters()->associatedSurface());
384 if(std::abs(startParameters->
position().z())>5000.){
385 ATH_MSG_DEBUG(
"Pathological track parameter well outside of tracking detector");
386 ATH_MSG_DEBUG(
"Propagator might have issue with this, discarding");
391 std::vector<std::unique_ptr<Trk::TrackParameters> > paramList =
398 if (paramList.empty()) {
403 ATH_MSG_VERBOSE(
"Number of parameters in this step: " << paramList.size());
406 for (std::unique_ptr<Trk::TrackParameters>& thisParameters : paramList) {
407 ATH_MSG_VERBOSE(
"extrapolated pos: " << thisParameters->position() <<
" r: " <<
408 sqrt(
pow(thisParameters->position().x(),2)+
pow(thisParameters->position().y(),2)));
412 if ((thisParameters->associatedSurface()).associatedDetectorElement() !=
nullptr &&
413 (thisParameters->associatedSurface()).associatedDetectorElement()->identify() != 0) {
414 id2 = (thisParameters->associatedSurface()).associatedDetectorElement()->identify();
418 startParameters = std::move(thisParameters);
425 ATH_MSG_VERBOSE(
"Surface is not Pixel or SCT, stop loop over parameters in this step");
429 startParameters = std::move(thisParameters);
438 if (iTSOS == mapOfHits.end() && !foundFirst) {
439 ATH_MSG_VERBOSE(
"Si surface before first Si measurement, skip it and continue");
444 if (iTSOS != mapOfHits.end()) {
451 if (iTSOS->second->trackParameters()) {
453 startParameters.reset( iTSOS->second->trackParameters()->clone());
456 startParameters.reset(thisParameters->clone());
461 std::pair<const Trk::TrackParameters*,const bool> trackparampair (thisParameters.release(),
true);
462 if (mapOfPredictions.insert(std::pair<
const Identifier, std::pair<const Trk::TrackParameters*,const bool> >(
id2,trackparampair)).second) {
466 delete trackparampair.first;
467 trackparampair.first=
nullptr;
479 if (measno==nmeas)
break;
487 ATH_MSG_DEBUG(
"Search for dead modules after the last Si measurement");
495 std::vector<std::unique_ptr<Trk::TrackParameters> > paramList =
501 if (paramList.empty()) {
502 ATH_MSG_VERBOSE(
"--> Did not manage to extrapolate to another surface, break loop");
504 ATH_MSG_VERBOSE(
"Number of parameters in this step: " << paramList.size());
507 for (std::unique_ptr<Trk::TrackParameters>& thisParameter : paramList) {
510 if (thisParameter->associatedSurface().associatedDetectorElement() !=
nullptr &&
511 thisParameter->associatedSurface().associatedDetectorElement()->identify() != 0) {
512 id2 = thisParameter->associatedSurface().associatedDetectorElement()->identify();
516 ATH_MSG_VERBOSE(
"Surface is not Pixel or SCT, stop loop over parameters in this step");
522 std::pair<Trk::TrackParameters*, const bool> trackparampair(
525 .insert(std::pair<
const Identifier, std::pair<const Trk::TrackParameters*, const bool>>(
526 id2, trackparampair))
528 thisParameter.reset(trackparampair.first->clone());
531 thisParameter.reset(trackparampair.first);
539 startParameters = std::move(thisParameter);
545 boundaryVol =
nullptr;
549 ATH_MSG_DEBUG(
"Number of Predictions found: " << mapOfPredictions.size());
556 std::map<
const Identifier, std::pair<const Trk::TrackParameters*, const bool> >& mapOfPredictions,
557 std::vector<int>* information,
558 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles)
const {
570 unsigned int foundTSOS = 0;
571 int PixelHoles = 0, SctHoles = 0, SctDoubleHoles = 0, PixelDead=0, SctDead=0;
572 std::set<Identifier> SctHoleIds;
575 ATH_MSG_DEBUG(
"Number of hits+outliers: " << mapOfHits.size() <<
" and predicted parameters:" << mapOfPredictions.size());
577 for (std::map<
const Identifier,std::pair<const Trk::TrackParameters*,const bool> >::const_iterator
it = mapOfPredictions.begin();
578 it != mapOfPredictions.end(); ++
it) {
587 if (iTSOS == mapOfHits.end()) {
592 ATH_MSG_VERBOSE(
"Found element is a dead pixel module, add it to the list and continue");
596 ATH_MSG_VERBOSE(
"Found element is a dead SCT module, add it to the list and continue");
610 if (((
it->second).second)) {
612 ATH_MSG_VERBOSE(
"Found element is a Pixel hole, add it to the list and continue");
615 ATH_MSG_VERBOSE(
"Found element is a SCT hole, add it to the list and continue");
623 ATH_MSG_ERROR (
"cast to SiDetectorElement failed, should never happen !");
629 if (SctHoleIds.find(otherId) != SctHoleIds.end()) {
634 SctHoleIds.insert(
id);
638 if (listOfHoles) listOfHoles->push_back(
createHoleTSOS(nextParameters));
647 ATH_MSG_VERBOSE(
"Found TSOS is an outlier, not a hole, skip it and continue");
649 mapOfHits.erase(iTSOS);
657 mapOfHits.erase(iTSOS);
663 << PixelHoles <<
" Pixel holes, "
664 << SctHoles <<
" Sct holes, "
665 << SctDoubleHoles <<
" Double holes");
667 if (listOfHoles)
ATH_MSG_DEBUG(
"==> Size of listOfHoles: " << listOfHoles->size());
669 if (!mapOfHits.empty()) {
670 int ioutliers = 0, imeasurements = 0;
671 for (std::map<const Identifier, const Trk::TrackStateOnSurface*>::const_iterator iter = mapOfHits.begin();
672 iter != mapOfHits.end(); ++iter) {
678 if (imeasurements > 0) {
679 if (PixelHoles+SctHoles+SctDoubleHoles > 0) {
680 ATH_MSG_DEBUG(
"Not all measurements found, but holes. Left measurements: "
681 << imeasurements <<
" outliers: " << ioutliers <<
" found: " << foundTSOS
682 <<
" Pixel holes: " << PixelHoles <<
" Sct holes: " << SctHoles
683 <<
" Double holes: " << SctDoubleHoles);
685 ATH_MSG_DEBUG(
"Problem ? Not all measurements found. Left measurements: "
686 << imeasurements <<
" outliers: " << ioutliers <<
" found: " << foundTSOS);
704 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
712 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles)
const {
713 auto trackTSOS = std::make_unique<Trk::TrackStates>();
723 ATH_MSG_DEBUG(
"No holes on track, copy input track to new track");
727 std::move(trackTSOS),
733 for (
const auto *listOfHole : *listOfHoles) {
734 trackTSOS->push_back(listOfHole);
748 if (fabs(perigee->parameters()[
Trk::qOverP]) > 0.002) {
753 std::stable_sort(trackTSOS->begin(), trackTSOS->end(), CompFunc);
755 trackTSOS->sort(CompFunc);
763 std::move(trackTSOS),