ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13
16
17
18using 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
47 StatusCode sc = AlgTool::initialize();
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
57 ATH_CHECK(m_EventInfoKey.initialize());
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
68 StatusCode sc = AlgTool::finalize();
69
70 return sc;
71}
72
73std::vector<Trk::SpaceTimePoint*> InDet::TRT_TrackTimingTool::timeMeasurements(const Trk::Track& track,
74 const Trk::SegmentCollection* sgmColl)
75const {
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
157std::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
167std::vector<Trk::SpaceTimePoint*> InDet::TRT_TrackTimingTool::timeMeasurements(std::vector<const Trk::Segment*> /*segments*/)
168const {
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
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}
Scalar eta() const
pseudorapidity method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
static const uint32_t nHits
abstract base class for rt-relations
This is an Identifier helper class for the TRT subdetector.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
MsgStream & msg() const
Represents 'corrected' measurements from the TRT (for example, corrected for wire sag).
virtual const TRT_DriftCircle * prepRawData() const override final
returns the PrepRawData - is a TRT_DriftCircle in this scope
virtual const Amg::Vector3D & globalPosition() const override final
return the global position of this RIO_OnTrack
bool driftTimeValid() const
return true if the corrected drift time is OK
bool firstBinHigh() const
returns true if the first bin is high
double rawDriftTime() const
returns the raw driftTime
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Current event.
ToolHandle< Trk::ITrackFitter > m_ITrackFitter
tools - this is the tool that actually does the work
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
virtual StatusCode initialize()
standard Athena-Algorithm method
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
ToolHandle< ITRT_CalDbTool > m_caldbtool
TRT Calibration DB tool.
virtual std::vector< Trk::SpaceTimePoint * > timeMeasurements(const Trk::Track &trk, const Trk::SegmentCollection *sgmColl=0) const
returns time measurements for a given track.
virtual ~TRT_TrackTimingTool()
default destructor
TRT_TrackTimingTool(const std::string &, const std::string &, const IInterface *)
virtual StatusCode finalize()
standard Athena-Algorithm method
ToolHandle< InDet::IInDetCosmicsEventPhaseTool > m_eventPhaseTool
float etaCorrection(const Trk::Track &track) const
eta-dependent corrections, called if m_doEtaCorrection == true
void debugMissingMeasurements(const Trk::Track &trk) const
private debugging function for commissioning phase
Base class for rt-relations in the TRT.
Definition RtRelation.h:27
virtual float drifttime(float radius) const =0
drifttime for given radius
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
double eta() const
Access method for pseudorapidity - from momentum.
Identifier identify() const
return the identifier -extends MeasurementBase
SpaceTimePoint.
const Track * originalTrack() const
Return pointer to associated track.
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Eigen::Matrix< double, 3, 1 > Vector3D
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
DataVector< Trk::Segment > SegmentCollection
@ driftRadius
trt, straws
Definition ParamDefs.h:53
ParametersBase< TrackParametersDim, Charged > TrackParameters