6 #include "GaudiKernel/IToolSvc.h"
7 #include "GaudiKernel/TypeNameString.h"
21 #include "AthLinks/ElementLink.h"
36 #include "GaudiKernel/SystemOfUnits.h"
40 namespace TrackRetrieverHelpers {
60 if (!perigee)
return nullptr;
63 if ((perigee->parameters())[
Trk::qOverP]==0)
pt.emplace_back(9999.);
80 const AmgSymMatrix(5)* covariance = perigee->covariance();
81 if (perigee && covariance) {
83 double measuredTheta = perigee->parameters()[
Trk::theta];
84 double measuredQoverp = perigee->parameters()[
Trk::qOverP];
86 covVert = covariance->similarity(theJac);
88 for (
int ii=0; ii<20; ii++){
95 const long scale = 10000;
96 const double thisScale(
scale/100.);
98 covMatrix.emplace_back(covVert(0)*thisScale);
99 covMatrix.emplace_back(covVert(1)*thisScale);
100 covMatrix.emplace_back(covVert(2)*thisScale);
101 covMatrix.emplace_back(covVert(3)*thisScale);
102 covMatrix.emplace_back(covVert(4)*thisScale);
105 for (
int i=0;
i<10;
i++){
120 std::vector<const Trk::TrackStateOnSurface*> TSoSVec;
124 for (; tsos!=
track->trackStateOnSurfaces()->
end(); ++tsos) {
128 TSoSVec.push_back(*tsos);
141 if (TSoSVec.size() > 2 && !is_sorted(TSoSVec.begin(), TSoSVec.end(), *
compFunc))
142 std::sort(TSoSVec.begin(), TSoSVec.end(), *
compFunc);
158 if (TSoSVec.size() > 1) {
160 std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsosIter;
161 const double onetenth(0.1);
162 for (tsosIter=TSoSVec.begin(); tsosIter!=TSoSVec.end(); ++tsosIter) {
164 if (!(*tsosIter)->trackParameters()) continue ;
166 polylineX.emplace_back(
pos.x()*onetenth);
167 polylineY.emplace_back(
pos.y()*onetenth);
168 polylineZ.emplace_back(
pos.z()*onetenth);
173 numPolyline.emplace_back(numPoly);
188 if (!measurement)
return nullptr;
202 if (!rot)
return nullptr;
214 int theDriftSign = 0;
215 if (idHelper->
is_trt(hitId)) {
223 tsosDetType.emplace_back(
"unident");
224 }
else if (idHelper->
is_pixel(hitId) ) {
225 tsosDetType.emplace_back(
"PIX");
226 }
else if (idHelper->
is_sct(hitId)) {
227 tsosDetType.emplace_back(
"SIL");
228 }
else if (idHelper->
is_trt(hitId)) {
229 tsosDetType.emplace_back(
"TRT");
230 }
else if (idHelper->
is_mdt(hitId)) {
231 tsosDetType.emplace_back(
"MDT");
232 }
else if (idHelper->
is_csc(hitId)) {
233 tsosDetType.emplace_back(
"CSC");
234 }
else if (idHelper->
is_rpc(hitId)) {
235 tsosDetType.emplace_back(
"RPC");
236 }
else if (idHelper->
is_tgc(hitId)) {
237 tsosDetType.emplace_back(
"TGC");
239 tsosDetType.emplace_back(
"unident");
251 const ToolHandle<Trk::IResidualPullCalculator> & residualPullCalculator,
255 double ResLoc1 = -99.;
256 double ResLoc2 = -99.;
257 double PullLoc1 = -99.;
258 double PullLoc2 = -99.;
272 std::optional<Trk::ResidualPull> residualPull = residualPullCalculator->residualPull(rot, tsosParameters,
Trk::ResidualPull::Biased);
276 ResLoc1 = residualPull->residual()[
Trk::loc1];
278 if (residualPull->dimension() >= 2) ResLoc2 = residualPull->residual()[
Trk::loc2];
280 if ((residualPull->isPullValid()) ) {
282 PullLoc1 = residualPull->pull()[
Trk::loc1];
284 if (residualPull->dimension() >= 2) PullLoc2 = residualPull->pull()[
Trk::loc2];
290 tsosResLoc1.emplace_back(ResLoc1 );
291 tsosResLoc2.emplace_back(ResLoc2 );
292 tsosPullLoc1.emplace_back(PullLoc1 );
293 tsosPullLoc2.emplace_back(PullLoc2 );
302 if (!truthCollection.
isValid()) {
314 std::map<Trk::TrackTruthKey,TrackTruth>::const_iterator tempTrackTruthItr = truthCollection->find(tracklink);
317 if (tempTrackTruthItr == truthCollection->end()){
324 barcode.emplace_back((*tempTrackTruthItr).second.particleLink().barcode());
355 return StatusCode::SUCCESS;
385 return StatusCode::SUCCESS;
393 if ( trackCollection->
empty()){
394 ATH_MSG_DEBUG(
"Empty track collection " << collectionName );
396 ATH_MSG_DEBUG(
"Retrieving data for track collection " << collectionName);
402 DataVect numDoF; numDoF.reserve(trackCollection->
size());
403 DataVect trackAuthor; trackAuthor.reserve(trackCollection->
size());
405 DataVect numHits; numHits.reserve(trackCollection->
size());
406 DataVect numPolyline; numPolyline.reserve(trackCollection->
size());
407 DataVect nBLayerHits; nBLayerHits.reserve(trackCollection->
size());
408 DataVect nPixHits; nPixHits.reserve(trackCollection->
size());
441 id.emplace_back(
id.
size());
442 chi2.emplace_back((*track)->fitQuality()->chiSquared());
443 numDoF.emplace_back((*track)->fitQuality()->numberDoF());
444 trackAuthor.emplace_back((*track)->info().trackFitter());
451 std::string matchingKey =
"";
453 if (
key->key().find(collectionName) != std::string::npos) {
454 matchingKey=
key->key();
458 if(!matchingKey.empty()){
460 if (truthCollection.
isValid()) {
461 ATH_MSG_DEBUG(
"Found TrackTruthCollection for \"" << collectionName <<
"\": " << matchingKey);
464 ATH_MSG_WARNING(
"TrackTruthCollection \"" << matchingKey <<
"\" is not valid");
469 ATH_MSG_DEBUG(
"No matching TrackTruthCollection key found containing \"" << collectionName <<
"\"");
486 std::unique_ptr<Trk::TrackSummary>
summary =
nullptr;
491 nBLayerHits.emplace_back(0);
492 nPixHits.emplace_back(0);
512 polylineX.reserve(polylineX.size()+TSoSVec.size());
513 polylineY.reserve(polylineY.size()+TSoSVec.size());
514 polylineZ.reserve(polylineZ.size()+TSoSVec.size());
523 isOutlier.reserve(isOutlier.size()+TSoSVec.size());
524 hits.reserve(
hits.size()+TSoSVec.size());
526 tsosResLoc1.reserve(tsosResLoc1.size()+TSoSVec.size());
527 tsosResLoc2.reserve(tsosResLoc2.size()+TSoSVec.size());
528 tsosPullLoc1.reserve(tsosPullLoc1.size()+TSoSVec.size());
529 tsosPullLoc2.reserve(tsosPullLoc2.size()+TSoSVec.size());
530 tsosDetType.reserve(tsosDetType.size()+TSoSVec.size());
533 std::vector< const Trk::TrackStateOnSurface* >::const_iterator TSoSItr = TSoSVec.begin();
537 for (; TSoSItr != TSoSVec.end(); ++TSoSItr){
544 ATH_MSG_VERBOSE(
"Could not obtain RIO for TSoS of type " << (*TSoSItr)->dumpType() );
558 numHits.emplace_back(nHits);
568 DataMap[
"trackAuthor"] = trackAuthor;
571 DataMap[
"nBLayerHits"] = nBLayerHits;
572 DataMap[
"nPixHits"] = nPixHits;
575 DataMap[
"numPolyline"] = numPolyline;
589 if ( !polylineX.empty()){
590 std::string numPolyPerTrack =
DataType(polylineX.size()/((
double)
id.size())).toString();
591 DataMap[
"polylineX multiple=\"" + numPolyPerTrack +
"\""] = polylineX;
592 DataMap[
"polylineY multiple=\"" + numPolyPerTrack +
"\""] = polylineY;
593 DataMap[
"polylineZ multiple=\"" + numPolyPerTrack +
"\""] = polylineZ;
597 std::string numHitsPerTrack =
DataType(
hits.size()/((
double)
id.size())).toString();
598 DataMap[
"hits multiple=\"" + numHitsPerTrack +
"\""] =
hits;
599 DataMap[
"isOutlier multiple=\""+numHitsPerTrack+
"\""] = isOutlier;
605 DataMap[
"tsosResLoc1 multiple=\""+numHitsPerTrack+
"\""] = tsosResLoc1;
606 DataMap[
"tsosResLoc2 multiple=\""+numHitsPerTrack+
"\""] = tsosResLoc2;
607 DataMap[
"tsosPullLoc1 multiple=\""+numHitsPerTrack+
"\""] = tsosPullLoc1;
608 DataMap[
"tsosPullLoc2 multiple=\""+numHitsPerTrack+
"\""] = tsosPullLoc2;
609 DataMap[
"tsosDetType multiple=\""+numHitsPerTrack+
"\""] = tsosDetType;