ATLAS Offline Software
TRT_TrackTimingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 // TRT_TrackTimingTool.cxx, (c) ATLAS Detector software
8 
10 
11 #include "InDetIdentifier/TRT_ID.h"
12 
13 
16 
17 
18 using CLHEP::GeV;
19 
20 //================ Constructor =================================================
21 
23  const std::string& n,
24  const IInterface* p) :
25  AthAlgTool(t, n, p), m_ITrackFitter("Trk::GlobalChi2Fitter/InDetTrackFitter"), m_eventPhaseTool(), m_caldbtool(
26  "TRT_CalDbTool", this), m_doEtaCorrection(true), m_debug(false) {
27  declareInterface<ITRT_TrackTimingTool>(this);
28  declareInterface<Trk::ITrackTimingTool>(this);
29 
30  // retrieve properties from job options
31  declareProperty("FitterTool", m_ITrackFitter);
32  declareProperty("EventPhaseTool", m_eventPhaseTool);
33  declareProperty("TRTCalDbTool", m_caldbtool);
34  declareProperty("DoEtaCorrection", m_doEtaCorrection);
35  declareProperty("DebugMissingMeasurement", m_debug);
36  declareProperty("EventInfoKey", m_EventInfoKey = "ByteStreamEventInfo");
37 }
38 
39 //================ Destructor ==================================================
40 
42 
43 
44 //================ Initialisation ==============================================
45 
48 
49  if (sc.isFailure()) return sc;
50 
51  // retrieve fitter
52  if (m_ITrackFitter.retrieve().isFailure()) {
53  msg(MSG::FATAL) << "Failed to retrieve tool " << m_ITrackFitter << endmsg;
54  return StatusCode::FAILURE;
55  } else msg(MSG::INFO) << "Retrieved tool " << m_ITrackFitter << endmsg;
56 
58 
59 
60  ATH_MSG_INFO("InDet::TRT_TrackTimingTool::initialize() successful in " << name() << ", do eta correction: " <<
61  (m_doEtaCorrection ? "true" : "false"));
62  return StatusCode::SUCCESS;
63 }
64 
65 //================ Finalisation =================================================
66 
69 
70  return sc;
71 }
72 
73 std::vector<Trk::SpaceTimePoint*> InDet::TRT_TrackTimingTool::timeMeasurements(const Trk::Track& track,
74  const Trk::SegmentCollection* sgmColl)
75 const {
76  if (sgmColl != nullptr) {
77  ATH_MSG_INFO("TRT_TrackTimingTool::timeMeasurements called with SegmentCollection != 0");
78  }
79 
80  std::vector<Trk::SpaceTimePoint*> timeMeasurementsVector;
81  // need to use constructor: SpaceTimePoint(const GlobalPosition& position, const float& t, const float& t_error, const
82  // float& weight);
83 
84  // Useless test; compiler can assume it's false and optimize it away.
85  // Tests for null must be done on pointers, not references
86  // (which by definition cannot be null).
87  //if (&track==0) return timeMeasurementsVector; // this function should not have been called in the first place
88 
89  float time = 0.;
90  Amg::Vector3D position(0., 0., 0.);
91 
92  // info about track
93  int nTRTdriftCircles(0), nMissingRDOs(0), nMissingTrackParameters(0), nUsedHits(0);
94  trackInformation(track, position, nTRTdriftCircles, nMissingRDOs, nMissingTrackParameters, nUsedHits);
95 
97  "trackInformation: " << nTRTdriftCircles << ", " << nMissingRDOs << ", " << nMissingTrackParameters << " slimmed? " <<
98  (track.info().trackProperties(Trk::TrackInfo::SlimmedTrack)));
99 
100  if (!nTRTdriftCircles) return timeMeasurementsVector; // no TRT hits for this track, can not do anything
101 
102  Trk::Track* newtrack = nullptr;
103  if (nMissingTrackParameters) { // need to re-fit the track to get the track parameters
104  newtrack = (m_ITrackFitter->fit(Gaudi::Hive::currentContext(),track,
105  false, track.info().particleHypothesis())).release();
106 
107  if (newtrack == nullptr) {
108  ATH_MSG_INFO("fit to unslim track has failed, giving up.");
109  return timeMeasurementsVector;
110  }
111  }
112 
113  const Trk::Track* track_ptr = (newtrack != nullptr) ? newtrack : &track;
114 
115  // there are TRT hits, and track parameters, use the tool to calculate the time
116  ATH_MSG_DEBUG("timeMeasurements(): diagnosed that track has all information already.");
117 
118  if (!nMissingRDOs) {
119  time = m_eventPhaseTool->findPhase(track_ptr);
120  } else {
121  time = getTrackTimeFromDriftRadius(track_ptr, nUsedHits);
122  }
123 
124 
125  if (m_doEtaCorrection && time != 0.) time -= etaCorrection(*track_ptr);
126 
127 
128 
129 // assign estimated constant conservative error for now
130  float error = 1.; // units ns
131 
132 // use default weight of 1.; 0. if the time measurement is invalid
133  float weight = (time == 0.) ? 0. : 0.02 * nUsedHits;
134 
135  ATH_MSG_DEBUG("TRT_TrackTimingTool::timeMeasurements: TRT track with " << nTRTdriftCircles << " hits, track time = "
136  << time << " ns, position: " << position << ", error: " << error << ", weight: " << weight <<
137  ".");
138 
139  if (time != 0.) { // add measurement only if valid
140  Trk::SpaceTimePoint* timeMeasurement = new Trk::SpaceTimePoint(position, time, error, weight, Trk::TrackState::TRT);
141 
142  timeMeasurementsVector.push_back(timeMeasurement);
143  } else {
144  ATH_MSG_INFO("TRT_TrackTimingTool::timeMeasurement not available");
146  }
147 
148 
149  if (newtrack) delete newtrack;
150 
151  return timeMeasurementsVector;
152 }
153 
154 //===============================================================================
155 
156 // The same functions but for TrackParticles
157 std::vector<Trk::SpaceTimePoint*> InDet::TRT_TrackTimingTool::timeMeasurements(const Trk::TrackParticleBase& tpb) const
158 {
159  if (tpb.originalTrack() == nullptr) {
160  std::vector<Trk::SpaceTimePoint*> v;
161  return v;
162  }
163  return timeMeasurements(*tpb.originalTrack());
164 }
165 
166 // a mock implementation for the segments, must be implemented for gaudi factories to work => returns empty vector
167 std::vector<Trk::SpaceTimePoint*> InDet::TRT_TrackTimingTool::timeMeasurements(std::vector<const Trk::Segment*> /*segments*/)
168 const {
169  std::vector<Trk::SpaceTimePoint*> v;
170  return v;
171 }
172 
173 //===============================================================================
174 
176  float time = 0.;
177 
178  nHits = 0;
179 
180  for (const Trk::TrackStateOnSurface* state : *track->trackStateOnSurfaces()) {
181  Trk::MeasurementBase const* mesb = state->measurementOnTrack();
182  if (!mesb || !state->type(Trk::TrackStateOnSurface::Measurement)) continue;
183 
184  InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
185  if (!trtcirc) continue;
186 
187  Trk::TrackParameters const* tparp = state->trackParameters();
188  if (!tparp) continue;
189 
190  float driftR = trtcirc->localParameters()[Trk::driftRadius];
191  if (std::abs(driftR) < 0.000001) continue; // driftR == 0 => measurement not available, could be anything
192  if (std::abs(driftR) > 2.) continue;
193 
194  float trackR = tparp->parameters()[Trk::driftRadius];
195 
196  Identifier id = trtcirc->identify();
197  const TRTCond::RtRelation* rtRelation = m_caldbtool->getRtRelation(id);
198  if (not rtRelation) {
199  ATH_MSG_WARNING("Rt relation pointer is null!");
200  continue;
201  }
202  float driftT = rtRelation->drifttime(std::abs(driftR));
203  float trackT = rtRelation->drifttime(std::abs(trackR));
204 
205 
206  time += driftT - trackT;
207  nHits++;
208  }
209 
210  if (nHits > 0) time /= (float) nHits;
211 
212  return time;
213 }
214 
215 //===============================================================================
216 
218  const float correctionLargeEta = -0.31; // ns
219 
220  const Trk::Perigee* trackPar = track.perigeeParameters();
221 
222  if (!trackPar) {
223  ATH_MSG_WARNING("missing perigee parameters, can not make eta correction");
224  return 0.;
225  }
226 
227  double eta = trackPar->eta();
228  float correction = (1.3 * eta * eta - 1.9) * eta * eta;
229  if (std::abs(eta) > 1. && correction > correctionLargeEta) correction = correctionLargeEta;
230 
231  ATH_MSG_DEBUG("eta correction: " << correction << " ns at eta = " << eta);
232 
233  return correction;
234 }
235 
236 //===============================================================================
237 
239  int& nTRTdriftCircles, int& nMissingRDOs,
240  int& nMissingTrackParameters, int& nUsedHits) const {
241  // define position as center-of-gravity for all TRT hits on track
242  Amg::Vector3D GlobalPositionSum(0., 0., 0.);
243 
244  for (const Trk::TrackStateOnSurface* state : *track.trackStateOnSurfaces()) {
245  Trk::MeasurementBase const* mesb = state->measurementOnTrack();
246  if (!mesb || !state->type(Trk::TrackStateOnSurface::Measurement)) continue;
247 
248  InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
249  if (!trtcirc) continue;
250 
251  nTRTdriftCircles++;
252 
253  GlobalPositionSum += trtcirc->globalPosition();
254 
255  if (!state->trackParameters()) nMissingTrackParameters++;
256 
257  InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
258  if (!rawhit) {
259  nMissingRDOs++;
260  continue;
261  }
262  if (!rawhit->driftTimeValid() || rawhit->firstBinHigh()) continue;
263  nUsedHits++; // this is the N of hits that will potentially be used for the track time calculation
264 
265 // if ( !(state->trackParameters()) ) continue;
266  }
267 
268  if (nTRTdriftCircles) GlobalPositionSum /= (double) nTRTdriftCircles;
269  position = GlobalPositionSum;
270 
271  return;
272 }
273 
274 //===============================================================================
275 
277  int checkNTRThits(0), missingMeasurement(0), noTRT_DriftCircle(0), missingPrepRawData(0), invalidHits(0),
278  missingTrackPar(0);
279 
280  for (Trk::TrackStateOnSurface const* state : *track.trackStateOnSurfaces()) {
281  Trk::MeasurementBase const* mesb = state->measurementOnTrack();
282  if (!mesb || !state->type(Trk::TrackStateOnSurface::Measurement)) {
283  missingMeasurement++;
284  continue;
285  }
286 
287  InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
288  if (!trtcirc) {
289  noTRT_DriftCircle++;
290  continue;
291  }
292 
293  InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
294  if (!rawhit) {
295  missingPrepRawData++;
296  continue;
297  }
298  if (!rawhit->driftTimeValid() || rawhit->firstBinHigh()) {
299  invalidHits++;
300  continue;
301  }
302  Trk::TrackParameters const* tparp = state->trackParameters();
303  if (!tparp) {
304  missingTrackPar++;
305  continue;
306  }
307 
308  checkNTRThits++;
309 
310  ATH_MSG_INFO(
311  "debugMissingMeasurements: TRT hit " << checkNTRThits << ", raw drift time: " << rawhit->rawDriftTime() << " ns, track R: " <<
312  tparp->parameters()[Trk::driftRadius] << " mm.");
313  }
314 
315  ATH_MSG_INFO("debugMissingMeasurements: N valid hits: " << checkNTRThits << ", missing MeasurementBase / Measurement: " << missingMeasurement
316  << ", missing TRT_DriftCircleOnTrack: " << noTRT_DriftCircle << ", missingPrepRawData: " << missingPrepRawData
317  << ", invalid LE or TE: " << invalidHits << ", missing track parameters: " <<
318  missingTrackPar);
319 
320  return;
321 }
Trk::SpaceTimePoint
SpaceTimePoint.
Definition: SpaceTimePoint.h:26
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
InDet::TRT_DriftCircleOnTrack::prepRawData
virtual const TRT_DriftCircle * prepRawData() const override final
returns the PrepRawData - is a TRT_DriftCircle in this scope
Definition: TRT_DriftCircleOnTrack.h:202
InDet::TRT_TrackTimingTool::m_doEtaCorrection
bool m_doEtaCorrection
Definition: TRT_TrackTimingTool.h:77
Trk::TrackState::TRT
@ TRT
Definition: TrackStateDefs.h:30
InDet::TRT_TrackTimingTool::m_eventPhaseTool
ToolHandle< InDet::IInDetCosmicsEventPhaseTool > m_eventPhaseTool
Definition: TRT_TrackTimingTool.h:73
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
InDet::TRT_TrackTimingTool::finalize
virtual StatusCode finalize()
standard Athena-Algorithm method
Definition: TRT_TrackTimingTool.cxx:67
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDet::TRT_TrackTimingTool::trackInformation
void trackInformation(const Trk::Track &track, Amg::Vector3D &position, int &nTRTdriftCircles, int &nMissingRDOs, int &nMissingTrackParameters, int &nUsedHits) const
get basic track info to know which function needs to be called, and calculate the position
Definition: TRT_TrackTimingTool.cxx:238
RtRelation.h
abstract base class for rt-relations
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
initialize
void initialize()
Definition: run_EoverP.cxx:894
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
TRT_TrackTimingTool.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
BasicRtRelation.h
InDet::TRT_DriftCircleOnTrack
Definition: TRT_DriftCircleOnTrack.h:53
InDet::TRT_DriftCircle
Definition: TRT_DriftCircle.h:32
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
InDet::TRT_TrackTimingTool::m_caldbtool
ToolHandle< ITRT_CalDbTool > m_caldbtool
TRT Calibration DB tool.
Definition: TRT_TrackTimingTool.h:75
Trk::TrackParticleBase
Definition: TrackParticleBase.h:41
tools.zlumi_mc_cf.correction
def correction(mu, runmode, campaign, run=None)
Definition: zlumi_mc_cf.py:4
Trk::TrackInfo::SlimmedTrack
@ SlimmedTrack
A slimmed track.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:87
TRTCond::RtRelation
Definition: RtRelation.h:27
InDet::TRT_TrackTimingTool::debugMissingMeasurements
void debugMissingMeasurements(const Trk::Track &trk) const
private debugging function for commissioning phase
Definition: TRT_TrackTimingTool.cxx:276
InDet::TRT_TrackTimingTool::initialize
virtual StatusCode initialize()
standard Athena-Algorithm method
Definition: TRT_TrackTimingTool.cxx:46
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
beamspotman.n
n
Definition: beamspotman.py:731
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::driftRadius
@ driftRadius
trt, straws
Definition: ParamDefs.h:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::MeasurementBase::type
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
Trk::ParametersBase
Definition: ParametersBase.h:55
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
InDet::TRT_TrackTimingTool::timeMeasurements
virtual std::vector< Trk::SpaceTimePoint * > timeMeasurements(const Trk::Track &trk, const Trk::SegmentCollection *sgmColl=0) const
returns time measurements for a given track.
Definition: TRT_TrackTimingTool.cxx:73
InDet::TRT_TrackTimingTool::m_ITrackFitter
ToolHandle< Trk::ITrackFitter > m_ITrackFitter
tools - this is the tool that actually does the work
Definition: TRT_TrackTimingTool.h:72
DataVector< Trk::Segment >
Trk::MeasurementBase
Definition: MeasurementBase.h:58
InDet::TRT_TrackTimingTool::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Current event.
Definition: TRT_TrackTimingTool.h:79
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
InDet::TRT_TrackTimingTool::etaCorrection
float etaCorrection(const Trk::Track &track) const
eta-dependent corrections, called if m_doEtaCorrection == true
Definition: TRT_TrackTimingTool.cxx:217
Trk::MeasurementBase::localParameters
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Definition: MeasurementBase.h:132
InDet::TRT_TrackTimingTool::getTrackTimeFromDriftRadius
float getTrackTimeFromDriftRadius(const Trk::Track *track, int &nHits) const
calculate the time from drift radius - when RDO hits are not available - for running on AODs
Definition: TRT_TrackTimingTool.cxx:175
python.PyAthena.v
v
Definition: PyAthena.py:154
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
InDet::TRT_TrackTimingTool::m_debug
bool m_debug
Definition: TRT_TrackTimingTool.h:78
Trk::RIO_OnTrack::identify
Identifier identify() const
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:152
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
InDet::TRT_DriftCircle::driftTimeValid
bool driftTimeValid() const
return true if the corrected drift time is OK
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
InDet::TRT_DriftCircle::rawDriftTime
double rawDriftTime() const
returns the raw driftTime
InDet::TRT_DriftCircleOnTrack::globalPosition
virtual const Amg::Vector3D & globalPosition() const override final
return the global position of this RIO_OnTrack
Definition: TRT_DriftCircleOnTrack.cxx:160
AthAlgTool
Definition: AthAlgTool.h:26
error
Definition: IImpactPoint3dEstimator.h:70
Trk::TrackParticleBase::originalTrack
const Track * originalTrack() const
Return pointer to associated track.
Definition: TrackParticleBase.h:205
InDet::TRT_DriftCircle::firstBinHigh
bool firstBinHigh() const
returns true if the first bin is high
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
InDet::TRT_TrackTimingTool::~TRT_TrackTimingTool
virtual ~TRT_TrackTimingTool()
default destructor
Definition: TRT_TrackTimingTool.cxx:41
InDet::TRT_TrackTimingTool::TRT_TrackTimingTool
TRT_TrackTimingTool(const std::string &, const std::string &, const IInterface *)
Definition: TRT_TrackTimingTool.cxx:22
Identifier
Definition: IdentifierFieldParser.cxx:14