6 #include "GaudiKernel/IToolSvc.h"
7 #include "GaudiKernel/TypeNameString.h"
23 #include "AthLinks/ElementLink.h"
38 #include "GaudiKernel/SystemOfUnits.h"
42 namespace TrackRetrieverHelpers {
62 if (! perigee)
return nullptr ;
65 if ((perigee->parameters())[
Trk::qOverP]==0)
pt.emplace_back(9999.);
82 const AmgSymMatrix(5)* covariance = perigee->covariance();
83 if (perigee && covariance) {
85 double measuredTheta = perigee->parameters()[
Trk::theta];
86 double measuredQoverp = perigee->parameters()[
Trk::qOverP];
88 covVert = covariance->similarity(theJac);
90 for (
int ii=0; ii<20; ii++){
97 const long scale = 10000;
98 const double thisScale(
scale/100.);
100 covMatrix.emplace_back(covVert(0)*thisScale);
101 covMatrix.emplace_back(covVert(1)*thisScale);
102 covMatrix.emplace_back(covVert(2)*thisScale);
103 covMatrix.emplace_back(covVert(3)*thisScale);
104 covMatrix.emplace_back(covVert(4)*thisScale);
107 for (
int i=0;
i<10;
i++){
122 std::vector<const Trk::TrackStateOnSurface*> TSoSVec;
126 for (; tsos!=
track->trackStateOnSurfaces()->
end(); ++tsos) {
130 TSoSVec.push_back(*tsos);
144 if (TSoSVec.size() > 2 && !is_sorted(TSoSVec.begin(), TSoSVec.end(), *
compFunc))
145 std::sort(TSoSVec.begin(), TSoSVec.end(), *
compFunc);
161 if (TSoSVec.size() > 1) {
163 std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsosIter;
164 const double onetenth(0.1);
165 for (tsosIter=TSoSVec.begin(); tsosIter!=TSoSVec.end(); ++tsosIter) {
167 if (!(*tsosIter)->trackParameters()) continue ;
169 polylineX.emplace_back(
pos.x()*onetenth);
170 polylineY.emplace_back(
pos.y()*onetenth);
171 polylineZ.emplace_back(
pos.z()*onetenth);
176 numPolyline.emplace_back(numPoly);
191 if ( ! measurement )
return nullptr ;
205 if (!rot)
return nullptr ;
217 int theDriftSign = 0;
218 if (idHelper->
is_trt(hitId)) {
226 tsosDetType.emplace_back(
"unident");
227 }
else if (idHelper->
is_pixel(hitId) ) {
228 tsosDetType.emplace_back(
"PIX");
229 }
else if (idHelper->
is_sct(hitId)) {
230 tsosDetType.emplace_back(
"SIL");
231 }
else if (idHelper->
is_trt(hitId)) {
232 tsosDetType.emplace_back(
"TRT");
233 }
else if (idHelper->
is_mdt(hitId)) {
234 tsosDetType.emplace_back(
"MDT");
235 }
else if (idHelper->
is_csc(hitId)) {
236 tsosDetType.emplace_back(
"CSC");
237 }
else if (idHelper->
is_rpc(hitId)) {
238 tsosDetType.emplace_back(
"RPC");
239 }
else if (idHelper->
is_tgc(hitId)) {
240 tsosDetType.emplace_back(
"TGC");
242 tsosDetType.emplace_back(
"unident");
254 const ToolHandle<Trk::IResidualPullCalculator> & residualPullCalculator,
258 double ResLoc1 = -99.;
259 double ResLoc2 = -99.;
260 double PullLoc1 = -99.;
261 double PullLoc2 = -99.;
275 std::optional<Trk::ResidualPull> residualPull = residualPullCalculator->residualPull(rot, tsosParameters,
Trk::ResidualPull::Biased);
279 ResLoc1 = residualPull->residual()[
Trk::loc1];
281 if (residualPull->dimension() >= 2) ResLoc2 = residualPull->residual()[
Trk::loc2];
283 if ((residualPull->isPullValid()) ) {
285 PullLoc1 = residualPull->pull()[
Trk::loc1];
287 if (residualPull->dimension() >= 2) PullLoc2 = residualPull->pull()[
Trk::loc2];
293 tsosResLoc1.emplace_back(ResLoc1 );
294 tsosResLoc2.emplace_back(ResLoc2 );
295 tsosPullLoc1.emplace_back(PullLoc1 );
296 tsosPullLoc2.emplace_back(PullLoc2 );
305 if (!truthCollection) {
317 std::map<Trk::TrackTruthKey,TrackTruth>::const_iterator tempTrackTruthItr = truthCollection->find(tracklink);
320 if (tempTrackTruthItr == truthCollection->end()){
327 barcode.emplace_back((*tempTrackTruthItr).second.particleLink().barcode());
341 m_residualPullCalculator(
"Trk::ResidualPullCalculator/ResidualPullCalculator"),
343 m_trackSumTool (
"Trk::TrackSummaryTool/InDetTrackSummaryTool")
346 declareInterface<IDataRetriever>(
this);
352 "Track collection from which to retrieve the truth associations for the priority track collection");
368 return StatusCode::FAILURE;
388 return StatusCode::SUCCESS;
403 using tracksNamePair = std::pair<TrackCollection, std::string>;
404 std::vector< tracksNamePair > requestedTrackColls;
420 ATH_MSG_WARNING(
"Unable to retrieve requested track collection " << (*CollNameItr) );
426 requestedTrackColls.emplace_back(*tracks,(*CollNameItr));
433 ATH_MSG_ERROR(
"Unable to retrieve track collection iterator" );
434 return StatusCode::RECOVERABLE;
438 for (; trackCollIter!=trackCollEnd; ++trackCollIter) {
440 if ((trackCollIter.
key().find(
"HLT",0) != std::string::npos) && (!
m_doWriteHLT)){
445 if ( (trackCollIter.
key()==
"TRTSeeds") || (trackCollIter.
key() ==
"MuonSlimmedTrackCollection")) {
455 if (
std::find(requestedTrackColls.begin(), requestedTrackColls.end(),tracksNamePair(*tracks,trackCollIter.
key())) != requestedTrackColls.end())
459 requestedTrackColls.emplace_back(*tracks,trackCollIter.
key());
470 for ( ; tracksNamePairItr != requestedTrackColls.end(); ++tracksNamePairItr){
473 std::string collectionName = (*tracksNamePairItr).second;
475 if ( trackCollection->
empty()){
476 ATH_MSG_DEBUG(
"Ignoring empty track collection " << collectionName );
478 ATH_MSG_DEBUG(
"Retrieving data for track collection " << collectionName);
494 }
else if (
evtStore()->contains<TrackTruthCollection>(collectionName+
"TruthCollection") ){
495 evtStore()->retrieve(truthCollection, collectionName+
"TruthCollection").ignore();
496 ATH_MSG_DEBUG(
"Found TrackTruthCollection with key " << collectionName <<
"TruthCollection" );
498 }
else if (
evtStore()->contains<TrackTruthCollection>(collectionName+
"Truth") ){
499 evtStore()->retrieve(truthCollection, collectionName+
"Truth").ignore();
500 ATH_MSG_DEBUG(
"Found TrackTruthCollection with key " << collectionName <<
"Truth" );
503 ATH_MSG_DEBUG(
"Could not find matching TrackTruthCollection for " << collectionName );
504 truthCollection = nullptr ;
510 DataVect numDoF; numDoF.reserve(trackCollection->
size());
511 DataVect trackAuthor; trackAuthor.reserve(trackCollection->
size());
513 DataVect numHits; numHits.reserve(trackCollection->
size());
514 DataVect numPolyline; numPolyline.reserve(trackCollection->
size());
515 DataVect nBLayerHits; nBLayerHits.reserve(trackCollection->
size());
516 DataVect nPixHits; nPixHits.reserve(trackCollection->
size());
549 id.emplace_back(
id.
size());
550 chi2.emplace_back((*track)->fitQuality()->chiSquared());
551 numDoF.emplace_back((*track)->fitQuality()->numberDoF());
552 trackAuthor.emplace_back((*track)->info().trackFitter());
567 std::unique_ptr<Trk::TrackSummary>
summary =
nullptr;
572 nBLayerHits.emplace_back(0);
573 nPixHits.emplace_back(0);
593 polylineX.reserve(polylineX.size()+TSoSVec.size());
594 polylineY.reserve(polylineY.size()+TSoSVec.size());
595 polylineZ.reserve(polylineZ.size()+TSoSVec.size());
604 isOutlier.reserve(isOutlier.size()+TSoSVec.size());
605 hits.reserve(
hits.size()+TSoSVec.size());
607 tsosResLoc1.reserve(tsosResLoc1.size()+TSoSVec.size());
608 tsosResLoc2.reserve(tsosResLoc2.size()+TSoSVec.size());
609 tsosPullLoc1.reserve(tsosPullLoc1.size()+TSoSVec.size());
610 tsosPullLoc2.reserve(tsosPullLoc2.size()+TSoSVec.size());
611 tsosDetType.reserve(tsosDetType.size()+TSoSVec.size());
614 std::vector< const Trk::TrackStateOnSurface* >::const_iterator TSoSItr = TSoSVec.begin();
618 for (; TSoSItr != TSoSVec.end(); ++TSoSItr){
625 ATH_MSG_VERBOSE(
"Could not obtain RIO for TSoS of type " << (*TSoSItr)->dumpType() );
639 numHits.emplace_back(nHits);
649 DataMap[
"trackAuthor"] = trackAuthor;
652 DataMap[
"nBLayerHits"] = nBLayerHits;
653 DataMap[
"nPixHits"] = nPixHits;
656 DataMap[
"numPolyline"] = numPolyline;
670 if ( !polylineX.empty()){
671 std::string numPolyPerTrack =
DataType(polylineX.size()/((
double)
id.size())).toString();
672 DataMap[
"polylineX multiple=\"" + numPolyPerTrack +
"\""] = polylineX;
673 DataMap[
"polylineY multiple=\"" + numPolyPerTrack +
"\""] = polylineY;
674 DataMap[
"polylineZ multiple=\"" + numPolyPerTrack +
"\""] = polylineZ;
678 std::string numHitsPerTrack =
DataType(
hits.size()/((
double)
id.size())).toString();
679 DataMap[
"hits multiple=\"" + numHitsPerTrack +
"\""] =
hits;
680 DataMap[
"isOutlier multiple=\""+numHitsPerTrack+
"\""] = isOutlier;
686 DataMap[
"tsosResLoc1 multiple=\""+numHitsPerTrack+
"\""] = tsosResLoc1;
687 DataMap[
"tsosResLoc2 multiple=\""+numHitsPerTrack+
"\""] = tsosResLoc2;
688 DataMap[
"tsosPullLoc1 multiple=\""+numHitsPerTrack+
"\""] = tsosPullLoc1;
689 DataMap[
"tsosPullLoc2 multiple=\""+numHitsPerTrack+
"\""] = tsosPullLoc2;
690 DataMap[
"tsosDetType multiple=\""+numHitsPerTrack+
"\""] = tsosDetType;
696 return StatusCode::RECOVERABLE;
707 return StatusCode::SUCCESS;