6#include "GaudiKernel/IToolSvc.h"
7#include "GaudiKernel/TypeNameString.h"
21#include "AthLinks/ElementLink.h"
36#include "GaudiKernel/SystemOfUnits.h"
57 const Trk::Perigee *perigee = track->perigeeParameters();
60 if (!perigee)
return nullptr;
63 if ((perigee->parameters())[
Trk::qOverP]==0) pt.emplace_back(9999.);
64 else pt.push_back( (perigee->
charge() > 0) ?
DataType(perigee->
pT()/Gaudi::Units::GeV) :
DataType((-perigee->
pT())/Gaudi::Units::GeV));
66 d0.emplace_back((perigee->parameters())[
Trk::d0]/Gaudi::Units::cm);
67 z0.emplace_back(perigee->parameters()[
Trk::z0]/Gaudi::Units::cm);
68 phi0.emplace_back(perigee->parameters()[
Trk::phi0]);
70 if (perigee->parameters()[
Trk::theta] == 0.) cotTheta.emplace_back(9999.);
71 else cotTheta.emplace_back(1./tan(perigee->parameters()[
Trk::theta]));
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++){
106 covMatrix.emplace_back( 0. );
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))
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 ;
165 const Amg::Vector3D& pos = (*tsosIter)->trackParameters()->position();
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)) {
219 driftSign.emplace_back(theDriftSign);
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()) {
304 barcode.emplace_back(0);
314 std::map<Trk::TrackTruthKey,TrackTruth>::const_iterator tempTrackTruthItr = truthCollection->find(tracklink);
317 if (tempTrackTruthItr == truthCollection->end()){
319 barcode.emplace_back(0);
324 barcode.emplace_back((*tempTrackTruthItr).second.particleLink().barcode());
355 return StatusCode::SUCCESS;
371 for (
const auto& key :
m_keys) {
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());
404 DataVect barcode; barcode.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());
409 DataVect nSCTHits; nSCTHits.reserve(trackCollection->
size());
410 DataVect nTRTHits; nTRTHits.reserve(trackCollection->
size());
431 DataVect cotTheta; cotTheta.reserve(trackCollection->
size());
433 DataVect covMatrix; covMatrix.reserve(trackCollection->
size() * 15 );
437 for (track=trackCollection->
begin(); track!=trackCollection->
end(); ++track) {
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");
466 barcode.emplace_back(0);
469 ATH_MSG_DEBUG(
"No matching TrackTruthCollection key found containing \"" << collectionName <<
"\"");
470 barcode.emplace_back(0);
475 barcode.emplace_back(0);
486 std::unique_ptr<Trk::TrackSummary> summary =
nullptr;
487 summary =
m_trackSumTool->summary(Gaudi::Hive::currentContext(), **track);
491 nBLayerHits.emplace_back(0);
492 nPixHits.emplace_back(0);
493 nSCTHits.emplace_back(0);
494 nTRTHits.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());
525 driftSign.reserve(driftSign.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;
573 DataMap[
"nSCTHits"] = nSCTHits;
574 DataMap[
"nTRTHits"] = nTRTHits;
575 DataMap[
"numPolyline"] = numPolyline;
584 DataMap[
"cotTheta"] = cotTheta;
585 DataMap[
"covMatrix multiple=\"15\""] = covMatrix;
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;
600 DataMap[
"driftSign multiple=\""+numHitsPerTrack+
"\""] = driftSign;
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;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
An STL vector of pointers that by default owns its pointed-to elements.
#define AmgSymMatrix(dim)
char data[hepevt_bytes_allocation_ATLAS]
bool(*)(const xAOD::Jet *, const xAOD::Jet *) compFunc
static const uint32_t nHits
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
const ServiceHandle< StoreGateSvc > & detStore() const
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
bool is_mdt(Identifier id) const
bool is_rpc(Identifier id) const
bool is_sct(Identifier id) const
bool is_tgc(Identifier id) const
bool is_pixel(Identifier id) const
bool is_csc(Identifier id) const
bool is_trt(Identifier id) const
DataModel_detail::const_iterator< DataVector > const_iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
ElementLink implementation for ROOT usage.
bool setElement(ElementType element)
Set to point to an element.
bool setStorableObject(BaseConstReference data, bool replace=false, IProxyDict *sg=0)
Set link to point to a new container (storable).
bool is_valid() const
Check if id is in a valid state.
value_type get_compact() const
Get the compact id.
Templated class to convert any object that is streamable in a ostringstream in a string.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each track collection retrieve all data.
ToolHandle< Trk::ITrackSummaryTool > m_trackSumTool
ToolHandle< Trk::IResidualPullCalculator > m_residualPullCalculator
SG::ReadHandleKeyArray< TrackCollection > m_keys
TrackRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
SG::ReadHandleKeyArray< TrackTruthCollection > m_TrackTruthCollections
const AtlasDetectorID * m_idHelper
Used to find out the corresponding sub-det from ROT->identify().
Gaudi::Property< bool > m_doHitsDetails
StatusCode initialize()
Default AthAlgTool methods.
Gaudi::Property< bool > m_doWriteResiduals
const DataMap getData(const TrackCollection *trackCollection, const std::string &collectionName)
Puts the variables into a DataMap.
Gaudi::Property< bool > m_doHitsSorting
Gaudi::Property< bool > m_isMC
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
This is the 5x5 jacobian for the transformation of track parameters and errors having the new standar...
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
double charge() const
Returns the charge.
double pT() const
Access method for transverse momentum.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Identifier identify() const
return the identifier -extends MeasurementBase
@ Biased
RP with track state including the hit.
Class providing comparison function, or relational definition, for sorting MeasurementBase objects.
represents the track state (measurement, material, fit parameters and quality) at a surface.
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
double chi2(TH1 *h0, TH1 *h1)
Eigen::Matrix< double, 3, 1 > Vector3D
Namespace for all helper functions.
const Trk::RIO_OnTrack * getBaseInfoFromHit(const Trk::TrackStateOnSurface *tsos, const AtlasDetectorID *idHelper, DataVect &isOutlier, DataVect &hits, DataVect &driftSign, DataVect &tsosDetType)
Retrieve all the basic hit information from the Trk::TrackStateOnSurface.
void getPolylineFromHits(const std::vector< const Trk::TrackStateOnSurface * > &TSoSVec, DataVect &polylineX, DataVect &polylineY, DataVect &polylineZ, DataVect &numPolyline)
Get polyline hits if available.
void getTruthFromTrack(const Trk::Track *track, const TrackCollection *trackCollection, SG::ReadHandle< TrackTruthCollection > &truthCollection, DataVect &barcode)
Get the barcode of the associated truth track.
std::vector< const Trk::TrackStateOnSurface * > getTrackStateOnSurfaces(const Trk::Track *track, const Trk::Perigee *perigee, bool doHitsSorting)
Get a list of track-State on Surfaces for measurement and outlier hits, sorted using the perigee comp...
void getResidualPullFromHit(const Trk::TrackStateOnSurface *tsos, const Trk::RIO_OnTrack *rot, const ToolHandle< Trk::IResidualPullCalculator > &residualPullCalculator, DataVect &tsosResLoc1, DataVect &tsosResLoc2, DataVect &tsosPullLoc1, DataVect &tsosPullLoc2)
Get the residual pull information from the Trk::TrackStateOnSurface hit.
const Trk::Perigee * getPerigeeParameters(const Trk::Track *track, DataVect &pt, DataVect &d0, DataVect &z0, DataVect &phi0, DataVect &cotTheta, DataVect &covMatrix)
Obtain the perigee parameters for a given track, if available, and fill them in the corresponding dat...
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ loc2
generic first and second local coordinate
ParametersBase< TrackParametersDim, Charged > TrackParameters
@ numberOfSCTHits
number of SCT holes
@ numberOfPixelHits
number of pixel layers on track with absence of hits
@ numberOfTRTHits
number of TRT outliers
@ numberOfInnermostPixelLayerHits
these are the hits in the 1st pixel layer
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.