ATLAS Offline Software
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 
23 Trk::SingleTrackDiffAlg::SingleTrackDiffAlg(const std::string& name, ISvcLocator* pSvcLocator):
24  AthAlgorithm(name,pSvcLocator),
25  m_trackDiffTool("Trk::TrackDiff/TrackDiff"),
26  m_referenceTrackCollection("simulatedTracks"),
27  m_comparedTrackCollection("Tracks")
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 
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
Trk::SingleTrackDiffAlg::execute
StatusCode execute()
standard Athena-Algorithm method
Definition: SingleTrackDiffAlg.cxx:52
SingleTrackDiffAlg.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Trk::SingleTrackDiffAlg::SingleTrackDiffAlg
SingleTrackDiffAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: SingleTrackDiffAlg.cxx:23
ITrackDiff.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
Track.h
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::SingleTrackDiffAlg::m_comparedTrackCollection
std::string m_comparedTrackCollection
jobOption: name of the compared TrackCollection
Definition: SingleTrackDiffAlg.h:49
Trk::theta
@ theta
Definition: ParamDefs.h:72
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
TrackCollection.h
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
Trk::SingleTrackDiffAlg::finalize
StatusCode finalize()
standard Athena-Algorithm method
Definition: SingleTrackDiffAlg.cxx:148
DataVector< Trk::Track >
AthAlgorithm
Definition: AthAlgorithm.h:47
Trk::SingleTrackDiffAlg::m_trackDiffTool
ToolHandle< Trk::ITrackDiff > m_trackDiffTool
Definition: SingleTrackDiffAlg.h:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DEBUG
#define DEBUG
Definition: page_access.h:11
Trk::SingleTrackDiffAlg::m_referenceTrackCollection
std::string m_referenceTrackCollection
jobOption: name of the reference TrackCollection
Definition: SingleTrackDiffAlg.h:48
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
Trk::SingleTrackDiffAlg::~SingleTrackDiffAlg
~SingleTrackDiffAlg()
Default Destructor.
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::SingleTrackDiffAlg::initialize
StatusCode initialize()
standard Athena-Algorithm method
Definition: SingleTrackDiffAlg.cxx:38
Trk::phi0
@ phi0
Definition: ParamDefs.h:71
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.