ATLAS Offline Software
InDetSlidingWindowTrackTimeTool.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 // InDetSlidingWindowTrackTimeTool.cxx, (c) ATLAS Detector software
8 
10 
12 
15 
16 #include "InDetIdentifier/TRT_ID.h"
17 #include "TrkTrack/Track.h"
19 
21 #include <cmath>
22 
23 //================ Constructor =================================================
24 
26  , std::string const& n
27  , IInterface const* p
28  ) : AthAlgTool(t, n, p)
29  , m_caldbtool("TRT_CalDbTool", this) {
30  declareInterface<IInDetCosmicsEventPhaseTool>(this);
31  declareProperty("TRTCalDbTool", m_caldbtool);
32  declareProperty("GlobalOffset", m_globalOffset = 10.);
33  declareProperty("UseNewEP", m_useNewEP = true);
34  declareProperty("NumberIterations", m_nIterations = 5);
35  declareProperty("WindowSize", m_windowSize = 7.);
36 }
37 
38 //================ Destructor =================================================
39 
41 {}
42 
43 
44 //================ Initialisation =================================================
45 
47  ATH_CHECK( m_caldbtool.retrieve());
48  // Read key
50 
51  return StatusCode::SUCCESS;
52 }
53 
54 //================ Finalisation =================================================
55 
57  //
58  return StatusCode::SUCCESS;
59 }
60 
61 
63  ATH_MSG_DEBUG("Finding phase...");
64 
65  double aT0=0.;
66  if (!m_useNewEP) {
67  ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
68  } else {
70  const TRTCond::AverageT0* avgT0{*rhl};
71  aT0=avgT0->get();
72  }
73 
74 
75  TRTCond::RtRelation const* rtr = nullptr;
76 
77  double timeresidualsum = 0;
78  size_t ntrthits = 0;
79  double windowCenter = 0;
80  for (int itr = 0; itr != m_nIterations; ++itr) {
81  timeresidualsum = 0;
82  ntrthits = 0;
83  for (Trk::TrackStateOnSurface const* state : *track->trackStateOnSurfaces()) {
84  Trk::MeasurementBase const* mesb = state->measurementOnTrack();
85  if (!mesb
87  ) continue;
88  InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
89  if (!trtcirc) continue;
90  InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
91  if (!rawhit) continue;
92  if (!rawhit->driftTimeValid()
93  || rawhit->firstBinHigh()
94  ) continue;
95  Identifier const& ident = trtcirc->identify();
96  double rawdrifttime = rawhit->rawDriftTime();
97  double t0 = m_caldbtool->getT0(ident);
98 
99  ATH_MSG_DEBUG("T0 : " << t0);
100  rtr = m_caldbtool->getRtRelation(ident);
101 
102  Trk::TrackParameters const* tparp = state->trackParameters();
103  if (!tparp) continue;
104  double trkdistance = tparp->parameters()[Trk::driftRadius];
105  double trkdrifttime = rtr->drifttime(std::abs(trkdistance));
106  double timeresidual = rawdrifttime - t0 + aT0 - trkdrifttime;
107  ATH_MSG_DEBUG("trkdistance=" << trkdistance
108  << " trkdrifttime=" << trkdrifttime
109  << " timeresidual=" << timeresidual
110  << " rawdrifttime=" << rawdrifttime);
111  if (timeresidual < 2000
112  && std::abs(trkdistance) < 2.8) {
113  if (itr == 0
114  || std::abs(timeresidual - windowCenter) < m_windowSize) {
115  timeresidualsum += timeresidual;
116  ++ntrthits;
117  }
118  }
119  }
120  if (ntrthits > 1) {
121  windowCenter = timeresidualsum / ntrthits;
122  } else break;
123  }
124 
125  ATH_MSG_DEBUG("timeresidualsum = " << timeresidualsum);
126  ATH_MSG_DEBUG("ntrtrhits = " << ntrthits);
127 
128  if (ntrthits > 1)
129  return windowCenter + m_globalOffset;
130  return 0.;
131 }
132 
134 
135  double sum_tr = 0.;
136  double sum_goodhits = 0.;
137  int nhits = segment->numberOfMeasurementBases();
138 
139  std::vector<double> data{0., 0.1, -0.00087,0.};
140  TRTCond::RtRelation const* rtr = nullptr;
141 
142  for (int i = 0; i < nhits; ++i) {
143  Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(segment->measurement(i));
144  InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(rio);
145  if (!trtcirc) continue;
146  InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
147  if (!rawhit) continue;
148  if (!rawhit->lastBinHigh() && !rawhit->isNoise()) {
149  Identifier const& ident = trtcirc->identify();
150  rtr = m_caldbtool->getRtRelation(ident);
151  if (not rtr) {
152  ATH_MSG_WARNING("Rt relation pointer is null!");
153  return 0.;
154  }
155  double full_drifttime = rtr->drifttime(2.0);
156  sum_tr += rawhit->trailingEdge() * 3.125 - full_drifttime;
157  ATH_MSG_VERBOSE("Hit " << sum_goodhits
158  << " : " << rawhit->trailingEdge() * 3.125
159  << " fulldrifttime=" << full_drifttime);
160  sum_goodhits += 1;
161  } else {
162  ATH_MSG_VERBOSE("Hit has lastbin high");
163  }
164  }
165  if (sum_goodhits > 1) return sum_tr / sum_goodhits + m_globalOffset;
166  return 0;
167 }
168 
170 
171  ATH_MSG_DEBUG("Finding phase...");
172 
173  double aT0=0.;
174  if (!m_useNewEP) {
175  ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
176  } else {
178  const TRTCond::AverageT0* avgT0{*rhl};
179  aT0=avgT0->get();
180  }
181 
182  double timeresidualsum = 0;
183  size_t ntrthits = 0;
184  for (Trk::TrackStateOnSurface const* state : *track->trackStateOnSurfaces()) {
185  Trk::MeasurementBase const* mesb = state->measurementOnTrack();
186  if (!mesb
188  ) continue;
189  InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
190  if (!trtcirc) continue;
191  InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
192  if (!rawhit) continue;
193  Identifier const& ident = trtcirc->identify();
194  double rawtrailingedge = rawhit->trailingEdge() * 3.125;
195  double t0 = m_caldbtool->getT0(ident);
196  ATH_MSG_DEBUG("T0 : " << t0);
197  double timeresidual = rawtrailingedge - t0 + aT0;
198  ATH_MSG_DEBUG("timeresidual=" << timeresidual);
199  if (timeresidual < 2000) {
200  timeresidualsum += timeresidual;
201  ++ntrthits;
202  }
203  }
204  if (ntrthits > 1) return timeresidualsum / ntrthits + m_globalOffset;
205  return 0.;
206 }
InDet::InDetSlidingWindowTrackTimeTool::m_nIterations
int m_nIterations
Definition: InDetSlidingWindowTrackTimeTool.h:67
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
TRTCond::AverageT0::get
double get() const
Definition: AverageT0.h:19
InDet::InDetSlidingWindowTrackTimeTool::findPhase
double findPhase(const Trk::Track *track) const
finds event phase of a track from the leading edge
Definition: InDetSlidingWindowTrackTimeTool.cxx:62
InDetSlidingWindowTrackTimeTool.h
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
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDet::InDetSlidingWindowTrackTimeTool::initialize
virtual StatusCode initialize()
standard Athena-Algorithm method
Definition: InDetSlidingWindowTrackTimeTool.cxx:46
RtRelation.h
abstract base class for rt-relations
InDet::InDetSlidingWindowTrackTimeTool::finalize
virtual StatusCode finalize()
standard Athena-Algorithm method
Definition: InDetSlidingWindowTrackTimeTool.cxx:56
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
InDet::InDetSlidingWindowTrackTimeTool::m_caldbtool
ToolHandle< ITRT_CalDbTool > m_caldbtool
TRT Calibration DB tool.
Definition: InDetSlidingWindowTrackTimeTool.h:63
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
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
ReadCondHandle.h
TrackSegment.h
Track.h
TRTCond::RtRelation
Definition: RtRelation.h:27
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
InDet::TRT_DriftCircle::isNoise
bool isNoise() const
returns true if the hit is caused by noise with a high probability.
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
TRTCond::RtRelation::drifttime
virtual float drifttime(float radius) const =0
drifttime for given radius
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
InDet::InDetSlidingWindowTrackTimeTool::m_globalOffset
double m_globalOffset
Definition: InDetSlidingWindowTrackTimeTool.h:65
Trk::driftRadius
@ driftRadius
trt, straws
Definition: ParamDefs.h:53
Trk::Segment
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:56
InDet::InDetSlidingWindowTrackTimeTool::InDetSlidingWindowTrackTimeTool
InDetSlidingWindowTrackTimeTool(const std::string &, const std::string &, const IInterface *)
Definition: InDetSlidingWindowTrackTimeTool.cxx:25
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
TRT_DriftCircleOnTrack.h
InDet::TRT_DriftCircle::trailingEdge
int trailingEdge() const
returns the trailing edge bin
InDet::InDetSlidingWindowTrackTimeTool::findPhaseFromTE
double findPhaseFromTE(const Trk::Track *track) const
finds event phase of a track from the trailing edge
Definition: InDetSlidingWindowTrackTimeTool.cxx:169
InDet::InDetSlidingWindowTrackTimeTool::~InDetSlidingWindowTrackTimeTool
virtual ~InDetSlidingWindowTrackTimeTool()
default destructor
Definition: InDetSlidingWindowTrackTimeTool.cxx:40
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
InDet::TRT_DriftCircle::lastBinHigh
bool lastBinHigh() const
returns true if the last bin is high
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
InDet::InDetSlidingWindowTrackTimeTool::m_windowSize
double m_windowSize
Definition: InDetSlidingWindowTrackTimeTool.h:68
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::RIO_OnTrack::identify
Identifier identify() const
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:152
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
AthAlgTool
Definition: AthAlgTool.h:26
TRTCond::AverageT0
Definition: AverageT0.h:10
InDet::InDetSlidingWindowTrackTimeTool::m_T0ReadKey
SG::ReadCondHandleKey< TRTCond::AverageT0 > m_T0ReadKey
Definition: InDetSlidingWindowTrackTimeTool.h:64
InDet::TRT_DriftCircle::firstBinHigh
bool firstBinHigh() const
returns true if the first bin is high
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
InDet::InDetSlidingWindowTrackTimeTool::m_useNewEP
bool m_useNewEP
Definition: InDetSlidingWindowTrackTimeTool.h:66
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
Identifier
Definition: IdentifierFieldParser.cxx:14