21 #include "Identifier/Identifier.h"
35 const IInterface*
p) :
39 declareInterface<ITrackHoleSearchTool>(
this);
49 if (
sc.isFailure())
return sc;
57 return StatusCode::SUCCESS;
68 std::vector<int>& information,
70 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
nullptr;
74 for (
const auto *listOfHole : *listOfHoles) {
78 listOfHoles =
nullptr;
85 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
new std::vector<const Trk::TrackStateOnSurface*>;
89 for (
const auto *listOfHole : *listOfHoles)
90 output->push_back(listOfHole);
93 listOfHoles =
nullptr;
100 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles =
new std::vector<const Trk::TrackStateOnSurface*>;
104 listOfHoles =
nullptr;
118 std::vector<int>* information,
119 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles,
134 std::map<const Identifier, const Trk::TrackStateOnSurface*> mapOfHits;
146 std::map<const Identifier, std::pair<const Trk::TrackParameters*,const bool> > mapOfPredictions;
149 Gaudi::Hive::currentContext(),
track, partHyp, mapOfHits, mapOfPredictions);
155 ATH_MSG_DEBUG(
"List of hits not properly obtained, abort hole search.");
158 for (
auto & mapOfPrediction : mapOfPredictions) {
159 delete (mapOfPrediction.second).
first;
160 (mapOfPrediction.second).
first =
nullptr;
169 std::map<const Identifier, const Trk::TrackStateOnSurface*>& mapOfHits,
170 std::map<
const Identifier, std::pair<const Trk::TrackParameters*,const bool> >& mapOfPredictions)
const {
182 for (
const auto *iterTSOS : *
track.trackStateOnSurfaces()) {
188 if (iterTSOS->measurementOnTrack() !=
nullptr
189 && iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement() !=
nullptr
190 && iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify() != 0) {
191 id = iterTSOS->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify();
193 }
else if (iterTSOS->trackParameters() !=
nullptr
194 && iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr
195 && iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0) {
196 id = iterTSOS->trackParameters()->associatedSurface().associatedDetectorElement()->identify();
202 mapOfHits.insert(std::pair<const Identifier, const Trk::TrackStateOnSurface*>(
id,iterTSOS));
205 if (!iterTSOS->trackParameters() &&
m_warning<10) {
207 ATH_MSG_WARNING(
"No track parameters available for state of type measurement");
213 if (
m_cosmic && !firstsipar && iterTSOS->trackParameters()) firstsipar=iterTSOS->trackParameters();
214 if (iterTSOS->trackParameters()) {
215 ATH_MSG_VERBOSE(
"TSOS pos: " << iterTSOS->trackParameters()->position()
216 <<
" r: " << sqrt(
pow(iterTSOS->trackParameters()->position().x(),2)
217 +
pow(iterTSOS->trackParameters()->position().y(),2))
218 <<
" Si measurement");
221 if (iterTSOS->trackParameters()) {
222 ATH_MSG_VERBOSE(
"TSOS pos: " << iterTSOS->trackParameters()->position()
223 <<
" r: " << sqrt(
pow(iterTSOS->trackParameters()->position().x(),2)
224 +
pow(iterTSOS->trackParameters()->position().y(),2))
225 <<
" TRT measurement");
231 ATH_MSG_DEBUG(
"Number of Si hits + outliers on original track: " << mapOfHits.size() <<
" , hits only: " << imeas);
239 std::unique_ptr<const Trk::TrackParameters> startParameters;
256 ATH_MSG_ERROR (
"cast to CylinderSurface failed, should never happen !");
268 if (!startParameters) {
269 ATH_MSG_DEBUG(
"no start parameters on SCT cylinder, try TRT ec disc");
296 if (
track.perigeeParameters()) {
297 startParameters.reset(
track.perigeeParameters()->clone());
298 }
else if (
track.trackParameters()->front()) {
303 *(
track.trackParameters()->front()),
311 if (!startParameters) {
312 ATH_MSG_DEBUG(
"No start point obtained, hole search not performed.");
317 bool foundFirst =
false;
321 ATH_MSG_DEBUG(
"We are looking for an extended list of holes, so add eventual holes before first hits");
335 while (iterTSOS!=
track.trackStateOnSurfaces()->end()
343 <<
" r: " << sqrt(
pow(startParameters->
position().x(),2)
347 int nmeas=(
int)
track.measurementsOnTrack()->size();
348 for (; iterTSOS!=
track.trackStateOnSurfaces()->end();++iterTSOS) {
362 if ((*iterTSOS)->measurementOnTrack() !=
nullptr
363 && (*iterTSOS)->measurementOnTrack()->associatedSurface().associatedDetectorElement() !=
nullptr
364 && (*iterTSOS)->measurementOnTrack()->associatedSurface().associatedDetectorElement()->identify() != 0) {
365 id = (*iterTSOS)->measurementOnTrack()->
associatedSurface().associatedDetectorElement()->identify();
366 surf = &(*iterTSOS)->measurementOnTrack()->associatedSurface();
368 }
else if ((*iterTSOS)->trackParameters() !=
nullptr
369 && (*iterTSOS)->trackParameters()->associatedSurface().associatedDetectorElement() !=
nullptr
370 && (*iterTSOS)->trackParameters()->associatedSurface().associatedDetectorElement()->identify() != 0) {
372 surf = &((*iterTSOS)->trackParameters()->associatedSurface());
375 surf=&((*iterTSOS)->trackParameters()->associatedSurface());
385 if(std::abs(startParameters->
position().z())>5000.){
386 ATH_MSG_DEBUG(
"Pathological track parameter well outside of tracking detector");
387 ATH_MSG_DEBUG(
"Propagator might have issue with this, discarding");
392 std::vector<std::unique_ptr<Trk::TrackParameters> > paramList =
399 if (paramList.empty()) {
404 ATH_MSG_VERBOSE(
"Number of parameters in this step: " << paramList.size());
407 for (std::unique_ptr<Trk::TrackParameters>& thisParameters : paramList) {
408 ATH_MSG_VERBOSE(
"extrapolated pos: " << thisParameters->position() <<
" r: " <<
409 sqrt(
pow(thisParameters->position().x(),2)+
pow(thisParameters->position().y(),2)));
413 if ((thisParameters->associatedSurface()).associatedDetectorElement() !=
nullptr &&
414 (thisParameters->associatedSurface()).associatedDetectorElement()->identify() != 0) {
415 id2 = (thisParameters->associatedSurface()).associatedDetectorElement()->identify();
419 startParameters = std::move(thisParameters);
426 ATH_MSG_VERBOSE(
"Surface is not Pixel or SCT, stop loop over parameters in this step");
430 startParameters = std::move(thisParameters);
439 if (iTSOS == mapOfHits.end() && !foundFirst) {
440 ATH_MSG_VERBOSE(
"Si surface before first Si measurement, skip it and continue");
445 if (iTSOS != mapOfHits.end()) {
452 if (iTSOS->second->trackParameters()) {
454 startParameters.reset( iTSOS->second->trackParameters()->clone());
457 startParameters.reset(thisParameters->clone());
462 std::pair<const Trk::TrackParameters*,const bool> trackparampair (thisParameters.release(),
true);
463 if (mapOfPredictions.insert(std::pair<
const Identifier, std::pair<const Trk::TrackParameters*,const bool> >(
id2,trackparampair)).second) {
467 delete trackparampair.first;
468 trackparampair.first=
nullptr;
480 if (measno==nmeas)
break;
488 ATH_MSG_DEBUG(
"Search for dead modules after the last Si measurement");
491 auto cylinderBounds = std::make_shared<Trk::CylinderVolumeBounds>(560, 2750);
496 std::vector<std::unique_ptr<Trk::TrackParameters> > paramList =
502 if (paramList.empty()) {
503 ATH_MSG_VERBOSE(
"--> Did not manage to extrapolate to another surface, break loop");
505 ATH_MSG_VERBOSE(
"Number of parameters in this step: " << paramList.size());
508 for (std::unique_ptr<Trk::TrackParameters>& thisParameter : paramList) {
511 if (thisParameter->associatedSurface().associatedDetectorElement() !=
nullptr &&
512 thisParameter->associatedSurface().associatedDetectorElement()->identify() != 0) {
513 id2 = thisParameter->associatedSurface().associatedDetectorElement()->identify();
517 ATH_MSG_VERBOSE(
"Surface is not Pixel or SCT, stop loop over parameters in this step");
523 std::pair<Trk::TrackParameters*, const bool> trackparampair(
526 .insert(std::pair<
const Identifier, std::pair<const Trk::TrackParameters*, const bool>>(
527 id2, trackparampair))
529 thisParameter.reset(trackparampair.first->clone());
532 thisParameter.reset(trackparampair.first);
540 startParameters = std::move(thisParameter);
546 boundaryVol =
nullptr;
550 ATH_MSG_DEBUG(
"Number of Predictions found: " << mapOfPredictions.size());
557 std::map<
const Identifier, std::pair<const Trk::TrackParameters*, const bool> >& mapOfPredictions,
558 std::vector<int>* information,
559 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles)
const {
571 unsigned int foundTSOS = 0;
572 int PixelHoles = 0, SctHoles = 0, SctDoubleHoles = 0, PixelDead=0, SctDead=0;
573 std::set<Identifier> SctHoleIds;
576 ATH_MSG_DEBUG(
"Number of hits+outliers: " << mapOfHits.size() <<
" and predicted parameters:" << mapOfPredictions.size());
578 for (std::map<
const Identifier,std::pair<const Trk::TrackParameters*,const bool> >::const_iterator
it = mapOfPredictions.begin();
579 it != mapOfPredictions.end(); ++
it) {
588 if (iTSOS == mapOfHits.end()) {
593 ATH_MSG_VERBOSE(
"Found element is a dead pixel module, add it to the list and continue");
597 ATH_MSG_VERBOSE(
"Found element is a dead SCT module, add it to the list and continue");
611 if (((
it->second).second)) {
613 ATH_MSG_VERBOSE(
"Found element is a Pixel hole, add it to the list and continue");
616 ATH_MSG_VERBOSE(
"Found element is a SCT hole, add it to the list and continue");
624 ATH_MSG_ERROR (
"cast to SiDetectorElement failed, should never happen !");
630 if (SctHoleIds.find(otherId) != SctHoleIds.end()) {
635 SctHoleIds.insert(
id);
639 if (listOfHoles) listOfHoles->push_back(
createHoleTSOS(nextParameters));
648 ATH_MSG_VERBOSE(
"Found TSOS is an outlier, not a hole, skip it and continue");
650 mapOfHits.erase(iTSOS);
658 mapOfHits.erase(iTSOS);
664 << PixelHoles <<
" Pixel holes, "
665 << SctHoles <<
" Sct holes, "
666 << SctDoubleHoles <<
" Double holes");
668 if (listOfHoles)
ATH_MSG_DEBUG(
"==> Size of listOfHoles: " << listOfHoles->size());
670 if (!mapOfHits.empty()) {
671 int ioutliers = 0, imeasurements = 0;
672 for (std::map<const Identifier, const Trk::TrackStateOnSurface*>::const_iterator
iter = mapOfHits.begin();
679 if (imeasurements > 0) {
680 if (PixelHoles+SctHoles+SctDoubleHoles > 0) {
681 ATH_MSG_DEBUG(
"Not all measurements found, but holes. Left measurements: "
682 << imeasurements <<
" outliers: " << ioutliers <<
" found: " << foundTSOS
683 <<
" Pixel holes: " << PixelHoles <<
" Sct holes: " << SctHoles
684 <<
" Double holes: " << SctDoubleHoles);
686 ATH_MSG_DEBUG(
"Problem ? Not all measurements found. Left measurements: "
687 << imeasurements <<
" outliers: " << ioutliers <<
" found: " << foundTSOS);
705 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
713 std::vector<const Trk::TrackStateOnSurface*>* listOfHoles)
const {
714 auto trackTSOS = std::make_unique<Trk::TrackStates>();
724 ATH_MSG_DEBUG(
"No holes on track, copy input track to new track");
728 std::move(trackTSOS),
734 for (
const auto *listOfHole : *listOfHoles) {
735 trackTSOS->push_back(listOfHole);
749 if (fabs(perigee->parameters()[
Trk::qOverP]) > 0.002) {
754 std::stable_sort(trackTSOS->begin(), trackTSOS->end(), CompFunc);
756 trackTSOS->sort(CompFunc);
764 std::move(trackTSOS),