ATLAS Offline Software
Loading...
Searching...
No Matches
InDetCosmicsEventPhaseTool.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// InDetCosmicsEventPhaseTool.cxx, (c) ATLAS Detector software
8
10
12
15
17#include "TrkTrack/Track.h"
19
21#include <cmath>
22//================ Constructor =================================================
23
25 , std::string const& n
26 , IInterface const* p
27 ) : AthAlgTool(t, n, p)
28 , m_caldbtool("TRT_CalDbTool", this) {
29 declareInterface<IInDetCosmicsEventPhaseTool>(this);
30 declareProperty("TRTCalDbTool", m_caldbtool);
31 declareProperty("UseNewEP", m_useNewEP = true);
32 declareProperty("GlobalOffset", m_globalOffset = 10.);
33}
34
35//================ Destructor =================================================
36
39
40
41//================ Initialisation =================================================
42
44
45 ATH_CHECK( m_caldbtool.retrieve());
46 // Read key
47 ATH_CHECK( m_T0ReadKey.initialize() );
48
49 return StatusCode::SUCCESS;
50}
51
52//================ Finalisation =================================================
53
55 return StatusCode::SUCCESS;
56}
57
58//============================================================================================
59
61 ATH_MSG_DEBUG("Finding phase...");
62
63 double aT0=0.;
64 if (!m_useNewEP) {
65 ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
66 } else {
68 const TRTCond::AverageT0* avgT0{*rhl};
69 aT0=avgT0->get();
70 }
71
72 TRTCond::RtRelation const* rtr = nullptr;
73 double timeresidualsum = 0;
74 size_t ntrthits = 0;
75 for (Trk::TrackStateOnSurface const* state : *track->trackStateOnSurfaces()) {
76 Trk::MeasurementBase const* mesb = state->measurementOnTrack();
77 if (!mesb
79 ) continue;
80 InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
81 if (!trtcirc) continue;
82 InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
83 if (!rawhit) continue;
84
85 if (!rawhit->driftTimeValid()
86 || rawhit->firstBinHigh()
87 ) continue;
88 Identifier const& ident = trtcirc->identify();
89 double rawdrifttime = rawhit->rawDriftTime();
90 double t0 = m_caldbtool->getT0(ident);
91 ATH_MSG_DEBUG("T0 : " << t0);
92 rtr = m_caldbtool->getRtRelation(ident);
93 Trk::TrackParameters const* tparp = (state->trackParameters());
94 if (!tparp) continue;
95 double trkdistance = tparp->parameters()[Trk::driftRadius];
96 double trkdrifttime = rtr->drifttime(std::abs(trkdistance));
97
98 double timeresidual = rawdrifttime - t0 + aT0 - trkdrifttime;
99 ATH_MSG_DEBUG("trkdistance=" << trkdistance
100 << " trkdrifttime=" << trkdrifttime
101 << " timeresidual=" << timeresidual
102 << " rawdrifttime=" << rawdrifttime);
103
104 if (timeresidual < 2000 && std::abs(trkdistance) < 2.8) {
105 timeresidualsum += timeresidual;
106 ++ntrthits;
107 }
108 }
109
110 ATH_MSG_DEBUG("timeresidualsum = " << timeresidualsum);
111 ATH_MSG_DEBUG("ntrtrhits = " << ntrthits);
112
113 if (ntrthits > 1) {
114 return timeresidualsum / ntrthits + m_globalOffset;
115 }
116 return 0.;
117}
118
120
121 double sum_tr = 0.;
122 double sum_goodhits = 0.;
123
124 TRTCond::RtRelation const* rtr = nullptr;
125 int nhits = segment->numberOfMeasurementBases();
126 for (int i = 0; i < nhits; ++i) {
127 Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(segment->measurement(i));
128 InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(rio);
129 if (!trtcirc) continue;
130 InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
131 if (!rawhit) continue;
132 if (!rawhit->lastBinHigh() && !rawhit->isNoise()) {
133 Identifier const& ident = trtcirc->identify();
134 rtr = m_caldbtool->getRtRelation(ident);
135 if (not rtr) {
136 ATH_MSG_WARNING("Rt relation pointer is null!");
137 return 0.;
138 }
139 double full_drifttime = rtr->drifttime(2.0);
140 sum_tr += rawhit->trailingEdge() * 3.125 - full_drifttime;
141 ATH_MSG_VERBOSE("Hit " << sum_goodhits
142 << " : " << rawhit->trailingEdge() * 3.125
143 << " fulldrifttime=" << full_drifttime);
144 sum_goodhits += 1;
145 } else {
146 ATH_MSG_VERBOSE("Hit has lastbin high");
147 }
148 }
149
150 if (sum_goodhits > 1) return sum_tr / sum_goodhits + m_globalOffset;
151 return 0;
152}
153
155 ATH_MSG_DEBUG("Finding phase...");
156
157 double aT0=0.;
158 if (!m_useNewEP) {
159 ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
160 } else {
162 const TRTCond::AverageT0* avgT0{*rhl};
163 aT0=avgT0->get();
164 }
165
166
167 double timeresidualsum = 0;
168 size_t ntrthits = 0;
169
170 for (Trk::TrackStateOnSurface const* state : *track->trackStateOnSurfaces()) {
171 Trk::MeasurementBase const* mesb = state->measurementOnTrack();
172 if (!mesb
174 ) continue;
175 InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(mesb);
176 if (!trtcirc) continue;
177 InDet::TRT_DriftCircle const* rawhit = trtcirc->prepRawData();
178 if (!rawhit) continue;
179 Identifier const& ident = trtcirc->identify();
180 double rawtrailingedge = rawhit->trailingEdge() * 3.125;
181 double t0 = m_caldbtool->getT0(ident);
182 ATH_MSG_DEBUG("T0 : " << t0);
183
184 double timeresidual = rawtrailingedge - t0 + aT0;
185 ATH_MSG_DEBUG("timeresidual=" << timeresidual);
186 if (timeresidual < 2000) {
187 timeresidualsum += timeresidual;
188 ++ntrthits;
189 }
190 }
191
192 if (ntrthits > 1) return timeresidualsum / ntrthits + m_globalOffset;
193
194 return 0.;
195}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t t0
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)
double findPhase(const Trk::Track *track) const
finds event phase of a track from the leading edge
InDetCosmicsEventPhaseTool(const std::string &, const std::string &, const IInterface *)
ToolHandle< ITRT_CalDbTool > m_caldbtool
TRT Calibration DB tool.
double findPhaseFromTE(const Trk::Track *track) const
finds event phase of a track from the trailing edge
SG::ReadCondHandleKey< TRTCond::AverageT0 > m_T0ReadKey
virtual StatusCode finalize()
standard Athena-Algorithm method
virtual StatusCode initialize()
standard Athena-Algorithm method
virtual ~InDetCosmicsEventPhaseTool()
default destructor
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
bool driftTimeValid() const
return true if the corrected drift time is OK
bool isNoise() const
returns true if the hit is caused by noise with a high probability.
bool lastBinHigh() const
returns true if the last bin is high
bool firstBinHigh() const
returns true if the first bin is high
double rawDriftTime() const
returns the raw driftTime
int trailingEdge() const
returns the trailing edge bin
double get() const
Definition AverageT0.h:19
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.
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Identifier identify() const
return the identifier -extends MeasurementBase
Base class for all TrackSegment implementations, extends the common MeasurementBase.
const MeasurementBase * measurement(unsigned int) const
returns the Trk::MeasurementBase objects depending on the integer
unsigned int numberOfMeasurementBases() const
Return the number of contained Trk::MeasurementBase (s)
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.
@ driftRadius
trt, straws
Definition ParamDefs.h:53
ParametersBase< TrackParametersDim, Charged > TrackParameters