ATLAS Offline Software
Loading...
Searching...
No Matches
SingleTrackDiffAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// SingleTrackDiffAlg.cxx, (c) ATLAS Detector Software
9
11// Gaudi
12#include "GaudiKernel/MsgStream.h"
13#include "GaudiKernel/SmartDataPtr.h"
14// Trk
16#include "TrkTrack/Track.h"
17//#include "TrkParameters/Perigee.h"
18//#include "TrkParameters/MeasuredPerigee.h"
19//#include "TrkEventPrimitives/ErrorMatrix.h"
20
22
23Trk::SingleTrackDiffAlg::SingleTrackDiffAlg(const std::string& name, ISvcLocator* pSvcLocator):
24 AthAlgorithm(name,pSvcLocator),
25 m_trackDiffTool("Trk::TrackDiff/TrackDiff"),
26 m_referenceTrackCollection("simulatedTracks"),
28
29{
30 declareProperty("ReferenceTrackCollection", m_referenceTrackCollection, "Name of the reference track collection");
31 declareProperty("ComparedTrackCollection", m_comparedTrackCollection, "Name of the track collection, which tracks will be compared");
32 declareProperty("TrackDiffTool", m_trackDiffTool, "Tool to compare two tracks");
33
34}
35
37
39 msg(MSG::INFO) <<"SingleTrackDiffAlg initialize()" << endmsg;
40
41
42 // Get TrackDiff Tool
43 StatusCode sc = m_trackDiffTool.retrieve();
44 if (sc.isFailure()) {
45 msg(MSG::FATAL) << "Could not retrieve "<< m_trackDiffTool <<" (to compare tracks) "<< endmsg;
46 return sc;
47 }
48
49 return StatusCode::SUCCESS;
50}
51
53 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "SingleTrackDiffAlg execute() start" << endmsg;
54
55 StatusCode sc = StatusCode::SUCCESS;
56
57 const TrackCollection* referenceTracks = nullptr;
58 const TrackCollection* comparedTracks = nullptr;
59 // get reference collection
60 if (!m_referenceTrackCollection.empty()) {
61 sc = evtStore()->retrieve(referenceTracks, m_referenceTrackCollection);
62 if (sc.isFailure()) {
63 msg(MSG::ERROR) <<"Reference tracks not found: " << m_referenceTrackCollection << endmsg;
64 return StatusCode::FAILURE;
65 } else {
66 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) <<"Reference tracks found: " << m_referenceTrackCollection <<endmsg;
67 }
68 }else{
69 msg(MSG::ERROR) <<"No reference Track collection given!" <<endmsg;
70 return StatusCode::FAILURE;
71 }
72 // get collection for comparison
73 if (!m_comparedTrackCollection.empty()) {
74 sc = evtStore()->retrieve(comparedTracks, m_comparedTrackCollection);
75 if (sc.isFailure()) {
76 msg(MSG::ERROR) <<"Tracks for comparison not found: " << m_comparedTrackCollection << endmsg;
77 return StatusCode::FAILURE;
78 } else {
79 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) <<"Tracks for comparison found: " << m_comparedTrackCollection <<endmsg;
80 }
81 }else{
82 msg(MSG::ERROR) <<"No Track collection for comparison given!" <<endmsg;
83 return StatusCode::FAILURE;
84 }
85 // just compare the first tracks of both collections
86 TrackCollection::const_iterator refTrackIterator = referenceTracks->begin();
87 TrackCollection::const_iterator compTrackIterator = comparedTracks->begin();
88 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << referenceTracks->size() <<" reference track(s) and " << comparedTracks->size() <<" comparison track(s)" <<endmsg;
89 if ( refTrackIterator == referenceTracks->end() ) {
90 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) <<"reference collection containes no tracks." <<endmsg;
91 return StatusCode::SUCCESS;
92 }
93 if ( compTrackIterator == comparedTracks->end() ) {
94 msg(MSG::INFO) <<"collection for comparison containes no tracks in contrast to the reference collection" <<endmsg;
95 return StatusCode::SUCCESS;
96 }
97 if (!(*refTrackIterator)) {
98 msg(MSG::WARNING) <<"reference track collection containes a NULL pointer" <<endmsg;
99 return StatusCode::SUCCESS;
100 }
101 // find track in compared collection which fits best to track in reference collection
102 const Perigee* refPerigee = (*refTrackIterator)->perigeeParameters();
103 const Track* compTrack = nullptr; // later for-loop with large min chi2 will assign a sane track
104 if (refPerigee) {
105 //double minDeltaqOverP = 1.e20;
106 double minChi2 = 1.e30;
107 for (; compTrackIterator != comparedTracks->end(); ++compTrackIterator) {
108 if (!(*compTrackIterator)) {
109 msg(MSG::WARNING) <<"track collection for comparison containes a NULL pointer" <<endmsg;
110 continue;
111 }
112 const Perigee* compPerigee = (*compTrackIterator)->perigeeParameters();
113 if (compPerigee) {
114 double chi2 = -1.;
115 if (compPerigee->covariance()) {
116 AmgSymMatrix(5) weight = compPerigee->covariance()->inverse();
117 AmgVector(5) paramdiff = refPerigee->parameters() - compPerigee->parameters();
118 chi2 = paramdiff.transpose() * weight * paramdiff;
119 if (chi2 < minChi2) {
120 minChi2 = chi2;
121 compTrack = (*compTrackIterator);
122 }
123 } /* else {
124 double deltaqOverP = fabs(refPerigee->pT() - compPerigee->pT());
125 if (deltaqOverP < minDeltaqOverP) {
126 minDeltaqOverP = deltaqOverP;
127 compTrack = (*compTrackIterator);
128 }
129 }*/
130 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) <<"pTRef: " << refPerigee->pT() << " pT: " << compPerigee->pT() <<" ThetaRef: " << refPerigee->parameters()[Trk::theta] << " Theta: " << compPerigee->parameters()[Trk::theta]<<" PhiRef: " << refPerigee->parameters()[Trk::phi0] << " Phi: " << compPerigee->parameters()[Trk::phi0]<<" chi2: " << chi2 <<endmsg;
131
132 }
133 }
134 //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) <<"minimum Delta pT: " << minDeltaqOverP <<endmsg;
135 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) <<"minimum chi2: " << minChi2 <<endmsg;
136 }
137 if (compTrack) {
138 sc = m_trackDiffTool->diff( *(*refTrackIterator), *(compTrack) );
139 } else {
140 return StatusCode::SUCCESS;
141 }
142// refTrackIterator = (*referenceTracks).end();
143// compTrackIterator = (*comparedTracks).end();
144 return sc;
145 //return StatusCode::SUCCESS;
146}
147
149 msg(MSG::INFO) << "SingleTrackDiffAlg finalize()" << endmsg;
150
151 return StatusCode::SUCCESS;
152}
153
154
#define endmsg
#define AmgSymMatrix(dim)
#define AmgVector(rows)
static Double_t sc
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
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.
double pT() const
Access method for transverse momentum.
std::string m_comparedTrackCollection
jobOption: name of the compared TrackCollection
StatusCode finalize()
standard Athena-Algorithm method
SingleTrackDiffAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
~SingleTrackDiffAlg()
Default Destructor.
StatusCode execute()
standard Athena-Algorithm method
StatusCode initialize()
standard Athena-Algorithm method
ToolHandle< Trk::ITrackDiff > m_trackDiffTool
std::string m_referenceTrackCollection
jobOption: name of the reference TrackCollection
double chi2(TH1 *h0, TH1 *h1)
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ phi0
Definition ParamDefs.h:65
@ theta
Definition ParamDefs.h:66
MsgStream & msg
Definition testRead.cxx:32