22 #include "Identifier/Identifier.h"
34 const IInterface*
p) :
37 m_extendedListOfHoles(false),
40 declareInterface<ITrackHoleSearchTool>(
this);
54 if (
sc.isFailure())
return sc;
62 return StatusCode::SUCCESS;
73 std::vector<int>& information,
75 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
nullptr;
79 for (
const auto *listOfHole : *listOfHoles) {
83 listOfHoles =
nullptr;
90 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
new std::vector<const Trk::TrackStateOnSurface*>;
94 for (
const auto *listOfHole : *listOfHoles)
95 output->push_back(listOfHole);
98 listOfHoles =
nullptr;
105 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
new std::vector<const Trk::TrackStateOnSurface*>;
109 listOfHoles =
nullptr;
123 std::vector<int>* information,
124 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles,
139 std::map<const Identifier, const Trk::TrackStateOnSurface*> mapOfHits;
151 std::map<const Identifier, std::pair<const Trk::TrackParameters*,const bool> > mapOfPredictions;
154 Gaudi::Hive::currentContext(),
track, partHyp, mapOfHits, mapOfPredictions);
160 ATH_MSG_DEBUG(
"List of hits not properly obtained, abort hole search.");
163 for (
auto & mapOfPrediction : mapOfPredictions) {
164 delete (mapOfPrediction.second).
first;
165 (mapOfPrediction.second).
first =
nullptr;
174 std::map<const Identifier, const Trk::TrackStateOnSurface*>& mapOfHits,
175 std::map<
const Identifier, std::pair<const Trk::TrackParameters*,const bool> >& mapOfPredictions)
const {
187 for (
const auto *iterTSOS : *
track.trackStateOnSurfaces()) {
193 if (iterTSOS->measurementOnTrack() !=
nullptr
194 && iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement() !=
nullptr
195 && iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify() != 0) {
196 id = iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify();
198 }
else if (iterTSOS->trackParameters() !=
nullptr
199 && iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr
200 && iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0) {
201 id = iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement()->identify();
207 mapOfHits.insert(std::pair<const Identifier, const Trk::TrackStateOnSurface*>(
id,iterTSOS));
210 if (!iterTSOS->trackParameters() &&
m_warning<10) {
212 ATH_MSG_WARNING(
"No track parameters available for state of type measurement");
218 if (
m_cosmic && !firstsipar && iterTSOS->trackParameters()) firstsipar=iterTSOS->trackParameters();
219 if (iterTSOS->trackParameters()) {
220 ATH_MSG_VERBOSE(
"TSOS pos: " << iterTSOS->trackParameters()->position()
221 <<
" r: " << sqrt(
pow(iterTSOS->trackParameters()->position().x(),2)
222 +
pow(iterTSOS->trackParameters()->position().y(),2))
223 <<
" Si measurement");
226 if (iterTSOS->trackParameters()) {
227 ATH_MSG_VERBOSE(
"TSOS pos: " << iterTSOS->trackParameters()->position()
228 <<
" r: " << sqrt(
pow(iterTSOS->trackParameters()->position().x(),2)
229 +
pow(iterTSOS->trackParameters()->position().y(),2))
230 <<
" TRT measurement");
236 ATH_MSG_DEBUG(
"Number of Si hits + outliers on original track: " << mapOfHits.size() <<
" , hits only: " << imeas);
244 std::unique_ptr<const Trk::TrackParameters> startParameters;
261 ATH_MSG_ERROR (
"cast to CylinderSurface failed, should never happen !");
273 if (!startParameters) {
274 ATH_MSG_DEBUG(
"no start parameters on SCT cylinder, try TRT ec disc");
301 if (
track.perigeeParameters()) {
302 startParameters.reset(
track.perigeeParameters()->clone());
303 }
else if (
track.trackParameters()->front()) {
308 *(
track.trackParameters()->front()),
316 if (!startParameters) {
317 ATH_MSG_DEBUG(
"No start point obtained, hole search not performed.");
322 bool foundFirst =
false;
326 ATH_MSG_DEBUG(
"We are looking for an extended list of holes, so add eventual holes before first hits");
340 while (iterTSOS!=
track.trackStateOnSurfaces()->end()
348 <<
" r: " << sqrt(
pow(startParameters->
position().x(),2)
352 int nmeas=(
int)
track.measurementsOnTrack()->size();
353 for (; iterTSOS!=
track.trackStateOnSurfaces()->end();++iterTSOS) {
367 if ((*iterTSOS)->measurementOnTrack() !=
nullptr
368 && (*iterTSOS)->measurementOnTrack()->associatedSurface().associatedDetectorElement() !=
nullptr
369 && (*iterTSOS)->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify() != 0) {
370 id = (*iterTSOS)->measurementOnTrack()->
associatedSurface().associatedDetectorElement()->identify();
371 surf = &(*iterTSOS)->measurementOnTrack()->associatedSurface();
373 }
else if ((*iterTSOS)->trackParameters() !=
nullptr
374 && (*iterTSOS)->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr
375 && (*iterTSOS)->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0) {
377 surf = &((*iterTSOS)->trackParameters()->associatedSurface());
380 surf=&((*iterTSOS)->trackParameters()->associatedSurface());
390 std::vector<std::unique_ptr<Trk::TrackParameters> > paramList =
397 if (paramList.empty()) {
402 ATH_MSG_VERBOSE(
"Number of parameters in this step: " << paramList.size());
405 for (std::unique_ptr<Trk::TrackParameters>& thisParameters : paramList) {
406 ATH_MSG_VERBOSE(
"extrapolated pos: " << thisParameters->position() <<
" r: " <<
407 sqrt(
pow(thisParameters->position().x(),2)+
pow(thisParameters->position().y(),2)));
411 if ((thisParameters->associatedSurface()).associatedDetectorElement() !=
nullptr &&
412 (thisParameters->associatedSurface()).associatedDetectorElement()->identify() != 0) {
413 id2 = (thisParameters->associatedSurface()).associatedDetectorElement()->identify();
417 startParameters = std::move(thisParameters);
424 ATH_MSG_VERBOSE(
"Surface is not Pixel or SCT, stop loop over parameters in this step");
428 startParameters = std::move(thisParameters);
437 if (iTSOS == mapOfHits.end() && !foundFirst) {
438 ATH_MSG_VERBOSE(
"Si surface before first Si measurement, skip it and continue");
443 if (iTSOS != mapOfHits.end()) {
450 if (iTSOS->second->trackParameters()) {
452 startParameters.reset( iTSOS->second->trackParameters()->clone());
455 startParameters.reset(thisParameters->clone());
460 std::pair<const Trk::TrackParameters*,const bool> trackparampair (thisParameters.release(),
true);
461 if (mapOfPredictions.insert(std::pair<
const Identifier, std::pair<const Trk::TrackParameters*,const bool> >(
id2,trackparampair)).second) {
465 delete trackparampair.first;
466 trackparampair.first=
nullptr;
478 if (measno==nmeas)
break;
486 ATH_MSG_DEBUG(
"Search for dead modules after the last Si measurement");
494 std::vector<std::unique_ptr<Trk::TrackParameters> > paramList =
500 if (paramList.empty()) {
501 ATH_MSG_VERBOSE(
"--> Did not manage to extrapolate to another surface, break loop");
503 ATH_MSG_VERBOSE(
"Number of parameters in this step: " << paramList.size());
506 for (std::unique_ptr<Trk::TrackParameters>& thisParameter : paramList) {
509 if (thisParameter->associatedSurface().associatedDetectorElement() !=
nullptr &&
510 thisParameter->associatedSurface().associatedDetectorElement()->identify() != 0) {
511 id2 = thisParameter->associatedSurface().associatedDetectorElement()->identify();
515 ATH_MSG_VERBOSE(
"Surface is not Pixel or SCT, stop loop over parameters in this step");
521 std::pair<Trk::TrackParameters*, const bool> trackparampair(
524 .insert(std::pair<
const Identifier, std::pair<const Trk::TrackParameters*, const bool>>(
525 id2, trackparampair))
527 thisParameter.reset(trackparampair.first->clone());
530 thisParameter.reset(trackparampair.first);
538 startParameters = std::move(thisParameter);
544 boundaryVol =
nullptr;
548 ATH_MSG_DEBUG(
"Number of Predictions found: " << mapOfPredictions.size());
555 std::map<
const Identifier, std::pair<const Trk::TrackParameters*, const bool> >& mapOfPredictions,
556 std::vector<int>* information,
557 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles)
const {
569 unsigned int foundTSOS = 0;
570 int PixelHoles = 0, SctHoles = 0, SctDoubleHoles = 0, PixelDead=0, SctDead=0;
571 std::set<Identifier> SctHoleIds;
574 ATH_MSG_DEBUG(
"Number of hits+outliers: " << mapOfHits.size() <<
" and predicted parameters:" << mapOfPredictions.size());
576 for (std::map<
const Identifier,std::pair<const Trk::TrackParameters*,const bool> >::const_iterator
it = mapOfPredictions.begin();
577 it != mapOfPredictions.end(); ++
it) {
586 if (iTSOS == mapOfHits.end()) {
591 ATH_MSG_VERBOSE(
"Found element is a dead pixel module, add it to the list and continue");
595 ATH_MSG_VERBOSE(
"Found element is a dead SCT module, add it to the list and continue");
609 if (((
it->second).second)) {
611 ATH_MSG_VERBOSE(
"Found element is a Pixel hole, add it to the list and continue");
614 ATH_MSG_VERBOSE(
"Found element is a SCT hole, add it to the list and continue");
622 ATH_MSG_ERROR (
"cast to SiDetectorElement failed, should never happen !");
628 if (SctHoleIds.find(otherId) != SctHoleIds.end()) {
633 SctHoleIds.insert(
id);
637 if (listOfHoles) listOfHoles->push_back(
createHoleTSOS(nextParameters));
646 ATH_MSG_VERBOSE(
"Found TSOS is an outlier, not a hole, skip it and continue");
648 mapOfHits.erase(iTSOS);
656 mapOfHits.erase(iTSOS);
662 << PixelHoles <<
" Pixel holes, "
663 << SctHoles <<
" Sct holes, "
664 << SctDoubleHoles <<
" Double holes");
666 if (listOfHoles)
ATH_MSG_DEBUG(
"==> Size of listOfHoles: " << listOfHoles->size());
668 if (!mapOfHits.empty()) {
669 int ioutliers = 0, imeasurements = 0;
670 for (std::map<const Identifier, const Trk::TrackStateOnSurface*>::const_iterator iter = mapOfHits.begin();
671 iter != mapOfHits.end(); ++iter) {
677 if (imeasurements > 0) {
678 if (PixelHoles+SctHoles+SctDoubleHoles > 0) {
679 ATH_MSG_DEBUG(
"Not all measurements found, but holes. Left measurements: "
680 << imeasurements <<
" outliers: " << ioutliers <<
" found: " << foundTSOS
681 <<
" Pixel holes: " << PixelHoles <<
" Sct holes: " << SctHoles
682 <<
" Double holes: " << SctDoubleHoles);
684 ATH_MSG_DEBUG(
"Problem ? Not all measurements found. Left measurements: "
685 << imeasurements <<
" outliers: " << ioutliers <<
" found: " << foundTSOS);
703 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
711 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles)
const {
712 auto trackTSOS = std::make_unique<Trk::TrackStates>();
722 ATH_MSG_DEBUG(
"No holes on track, copy input track to new track");
726 std::move(trackTSOS),
732 for (
const auto *listOfHole : *listOfHoles) {
733 trackTSOS->push_back(listOfHole);
747 if (fabs(perigee->parameters()[
Trk::qOverP]) > 0.002) {
752 std::stable_sort(trackTSOS->begin(), trackTSOS->end(), CompFunc);
754 trackTSOS->sort(CompFunc);
762 std::move(trackTSOS),