ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_DriftFunctionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// TRT_DriftFunctionTool.cxx
7// Implementation file for class TRT_DriftFunctionTool
9// (c) ATLAS Detector software
11// AlgTool used to go from drift time to drift distance
13
14
16
22
23#include <cmath>
24#include <string>
25//
26// Constructor
28 const std::string& name,
29 const IInterface* parent)
30 : base_class(type, name, parent)
31{
32 // make sure all arrays are initialized - use DC3version2 as default
33 for (int i=0; i<3; i++) m_t0_barrel[i] = 15.625;
34 for (int i=0; i<14; i++) m_t0_endcap[i] = 14.2;
35 m_t0_shift=0.;
36
37 for(size_t i=0; i<s_size_default; ++i){
40 }
41 for(size_t i=s_size_default; i<MaxTimeBin; ++i) {
42 m_radius[i]=2.;
44 }
45}
46
47//
48// Destructor--------------------------------------------------
50
51//
52// Initialize--------------------------------------------------
54{
55 ATH_MSG_DEBUG( "initialize()");
56
57 StatusCode sc = AthAlgTool::initialize();
58 if (sc.isFailure())
59 {
60 ATH_MSG_FATAL("Cannot initialize AthAlgTool!");
61 return StatusCode::FAILURE;
62 }
63
64 if(m_dummy){
65 ATH_MSG_INFO(" Drift time information ignored ");
66 }
67
68 // Retrieve TRT_DetectorManager and helper
70 if (sc.isFailure() || !m_manager)
71 {
72 ATH_MSG_FATAL("Could not find the Manager: "
73 << m_trt_mgr_location << " !");
74 return sc;
75 }
76
77 // Get TRT ID helper
78 sc = detStore()->retrieve(m_trtid,"TRT_ID");
79 if ( sc.isFailure() ) {
80 ATH_MSG_FATAL( "Could not retrieve TRT ID helper." );
81 return sc;
82 }
83
84 // Check that ToT corrections have the correct length
85 if (m_tot_corrections_barrel_Xe.size() != 20) {
86 ATH_MSG_FATAL( "Length of ToTCorrectionsBarrelXe is not 20." );
87 return sc;
88 }
89 if (m_tot_corrections_endcap_Xe.size() != 20) {
90 ATH_MSG_FATAL( "Length of ToTCorrectionsEndcapXe is not 20." );
91 return sc;
92 }
93 if (m_tot_corrections_barrel_Ar.size() != 20) {
94 ATH_MSG_FATAL( "Length of ToTCorrectionsBarrelAr is not 20." );
95 return sc;
96 }
97 if (m_tot_corrections_endcap_Ar.size() != 20) {
98 ATH_MSG_FATAL( "Length of ToTCorrectionsEndcapAr is not 20." );
99 return sc;
100 }
101
102 //
103 // Get GeoModel version key
104 SmartIF<IGeoModelSvc> geomodel{service("GeoModelSvc")};
105 ATH_CHECK( geomodel.isValid() );
106
107 DecodeVersionKey versionKey(geomodel,"TRT");
108 m_key=versionKey.tag();
109
110 int numB = m_manager->getNumerology()->getNBarrelPhi();
111 ATH_MSG_DEBUG(" Number of Barrel elements "<< numB);
112 m_istestbeam = numB==2;
113
115
116 return sc;
117}
118
119//
120// Finalize-----------------------------------------------------------------
122{
123 StatusCode sc = AlgTool::finalize();
124 return sc;
125}
126
127// Drift time in ns for any non negative drift radius; Not calibrated for
128// individual straws and run range, but otherwise adapted to any
129// setup.
130double TRT_DriftFunctionTool::approxDriftTime(double driftradius) const
131{
132 double t = 0.;
133 int i=0;
134 if(driftradius<0.100) {
135 t = 2.5*s_drifttimeperbin*driftradius/0.1;
136 } else if(driftradius<1.99) {
137 while(driftradius>=m_radius[i]) ++i;
138 if(i>0) i--;
139 t=(i+0.5+(driftradius-m_radius[i])/(m_radius[i+1]-m_radius[i]))*s_drifttimeperbin;
140 } else {
141 t = s_drifttimeperbin*( 19. + (driftradius-1.99)/0.08 );
142 }
143
144 return t;
145}
146
147// Drift radius in mm for valid drift time in MC; zero otherwise.----------
148double TRT_DriftFunctionTool::driftRadius(double drifttime) const
149{
150 if( !isValidTime(drifttime) ) return 0;
151 int drifttimebin = std::max(int(drifttime/s_drifttimeperbin),0);
152
153 // Interpolate linearly
154 if(drifttime < (drifttimebin+0.5)*s_drifttimeperbin) {
155 if (drifttimebin-1 > -1)
156 return m_radius[drifttimebin-1]+
157 (m_radius[drifttimebin]-m_radius[drifttimebin-1])*
158 (drifttime - (drifttimebin-0.5)*s_drifttimeperbin)/s_drifttimeperbin;
159 } else if (drifttimebin+1 < 20) {
160 return m_radius[drifttimebin]+
161 (m_radius[drifttimebin+1]-m_radius[drifttimebin])*
162 (drifttime - (drifttimebin+0.5)*s_drifttimeperbin)/s_drifttimeperbin;
163 }
164
165 return m_radius[drifttimebin];
166}
167
168//
169// Drift radius in mm for valid drift time (rawtime-t0) in data; --------------
170// zero otherwise; truncated to at most 2mm.
171double TRT_DriftFunctionTool::driftRadius(double rawtime, Identifier id, double& t0, bool& isOK, unsigned int word) const
172{
173 isOK = true;
174 const double crawtime=rawtime - m_t0_shift; // const cast
175 const Identifier cid=id; // const cast
176 t0 = 0.;
177 float ft0=t0; //float cast
178
179 //case of no drifttime information wanted
180 if (m_dummy) return 0.;
181
182 double radius = 0.;
183 if (!m_isDataOverlay){ //standard case
184 radius = m_TRTCalDbTool->driftRadius(crawtime,ft0,cid,isOK);
185 t0 = ft0 + m_t0_shift;
186 }
187 else{ //overlay case
188 // no m_t0_shift in rawtime, and use data TRTCalDbSvc
189 radius = m_TRTCalDbTool->driftRadius(rawtime,ft0,cid,isOK);
190 t0 = ft0;
191 bool mcdigit = word & (1u<<31);
192 if (mcdigit){
193 //check if it's a MC digit, and if so apply other calibration
194 ATH_MSG_DEBUG ("Overlay TRTCalDbTool gave radius: "<<radius<<", t0: "<<t0);
195 //t0_shift in crawtime, and use MC TRTCalDbSvc(2)
196 radius = m_TRTCalDbTool2->driftRadius(crawtime,ft0,cid,isOK);
197 t0 = ft0 + m_t0_shift;
198 ATH_MSG_DEBUG ("Overlay TRTCalDbTool2 gives radius: "<<radius<<", t0: "<<t0);
199 }
200 }
201 double drifttime = rawtime-t0;
202 if( !isValidTime(drifttime) ) isOK=false;
203 return radius;
204
205}
206
207// Error of drift radius in mm -----------------------------------------------
208double TRT_DriftFunctionTool::errorOfDriftRadius(double drifttime, Identifier id, float mu, unsigned int word) const
209{
210 if(m_dummy) return 4./std::sqrt(12.);
212 bool founderr=true;
213 bool foundslope=true;
214 double error = m_TRTCalDbTool->driftError(drifttime,id,founderr);
215 double slope = m_TRTCalDbTool->driftSlope(drifttime,id,foundslope);
216 bool mcdigit = word & (1u<<31);
217 if(m_isDataOverlay && mcdigit){
218 //check if it's a MC digit, and if so apply other calibration
219 ATH_MSG_DEBUG ("Overlay TRTCalDbTool gave error: "<<error<<", found="<<founderr);
220 error = m_TRTCalDbTool2->driftError(drifttime,id,founderr);
221 ATH_MSG_DEBUG ("Overlay TRTCalDbTool2 gives error: "<<error<<", found="<<founderr);
222 ATH_MSG_DEBUG ("Overlay TRTCalDbTool gave slope: "<<slope<<", found="<<foundslope);
223 slope = m_TRTCalDbTool2->driftSlope(drifttime,id,foundslope);
224 ATH_MSG_DEBUG ("Overlay TRTCalDbTool2 gives slope: "<<slope<<", found="<<foundslope);
225 }
226
227 if(founderr && foundslope) {
228 return error+mu*slope;
229//to add condition for old setup
230 }
231 else if ((founderr && !foundslope) || (mu<0)) {
232 return error; }
233 else { //interpolate
234 if(drifttime<=0.) {
235 return m_errors[0];
236 } else if(drifttime >= 18.*s_drifttimeperbin) {
237 return m_errors[18];
238 } else {
239 float drifttimeinbins = drifttime/s_drifttimeperbin;
240 int drifttimebin = (int)drifttimeinbins;
241 float fracbin = drifttimeinbins-drifttimebin;
242 return (1-fracbin)*m_errors[drifttimebin]+fracbin*m_errors[drifttimebin+1];
243 }
244 }
245}
246
247//
248// returns the time over threshold correction in ns
249double TRT_DriftFunctionTool::driftTimeToTCorrection(double tot, Identifier id, bool isArgonStraw) const
250{
251 int tot_index = tot/s_drifttimeperbin;
252 if (tot_index < 0) tot_index = 0;
253 if (tot_index > 19) tot_index = 19;
254
255 int bec_index = std::abs(m_trtid->barrel_ec(id)) - 1;
256
257 if (isArgonStraw) {
258 return (bec_index) ? m_tot_corrections_endcap_Ar[tot_index] : m_tot_corrections_barrel_Ar[tot_index];
259 }
260 return (bec_index) ? m_tot_corrections_endcap_Xe[tot_index] : m_tot_corrections_barrel_Xe[tot_index];
261}
262
263// Returns high threshold correction to the drift time (ns)
265{
266 int bec_index = std::abs(m_trtid->barrel_ec(id)) - 1;
267
268 if (isArgonStraw) {
270 }
272}
273
274//
275// Initialise R-t relation ------------------------------------------
277{
278
279 ATH_MSG_DEBUG(" Using TRTCalDbTool ");
280 if ( m_TRTCalDbTool.retrieve().isFailure() ) {
281 ATH_MSG_FATAL(m_TRTCalDbTool.propertyName() <<
282 ": Failed to retrieve service " << m_TRTCalDbTool.type());
283 return;
284
285 } else {
286 ATH_MSG_DEBUG(m_TRTCalDbTool.propertyName() <<
287 ": Retrieved service " << m_TRTCalDbTool.type());
288 }
289
290 if (m_isDataOverlay){
291 ATH_MSG_DEBUG("Using TRTCalDbTool2 for overlay ! ");
292 if ( m_TRTCalDbTool2.retrieve().isFailure() ) {
293 ATH_MSG_FATAL(m_TRTCalDbTool2.propertyName() <<": Failed to retrieveservice " << m_TRTCalDbTool2.type());
294 return;
295 }
296 }
297 //temporary: we need some way to automatically link digi version with db tag
298 //for now we make a hack in order always to get the right t0 after having centered the
299 //drifttime spectrum better in the allowed time-window with digi version 12 in release 14.
300
301 if(m_isMC || m_isDataOverlay){
302
304 m_t0_shift=-8.;
305 ATH_MSG_DEBUG(" T0 for barrel is shifted by "
306 << m_t0_shift);
307 }
308
309 }
310 //temporary: we need to think about how to store the uncertainties in the db!!!
311
312 if(m_key.compare(6,4,"Comm")==0) {
313 for(size_t i=0; i<s_size_Comm; ++i){
314 m_radius[i] = s_radius_Comm[i];
315 m_errors[i] = s_errors_Comm[i];
316 }
317 } else {
318 for(size_t i=0; i<s_size_default; ++i){
320 }
321 }
322
323}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
static Double_t t0
This is an Identifier helper class for the TRT subdetector.
const ServiceHandle< StoreGateSvc > & detStore() const
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
const std::string & tag() const
Return version tag.
static constexpr double s_errors_default[s_size_default]
std::string m_key
GeoModel version key.
virtual StatusCode finalize() override
Finalize.
DoubleArrayProperty m_tot_corrections_barrel_Xe
virtual bool isValidTime(double drifttime) const override
Returns True for drifttimes between -10 and 75ns.
double m_errors[MaxTimeBin]
width of radius dist in each bin
static constexpr double s_radius_Comm[s_size_Comm]
virtual double errorOfDriftRadius(double drifttime, Identifier id, float mu=-10, unsigned int word=0) const override
Time-dependent error of drift radius in mm.
DoubleProperty m_ht_correction_barrel_Ar
double m_radius[MaxTimeBin]
most probable radius in each bin
virtual ~TRT_DriftFunctionTool()
Destructor.
DoubleProperty m_ht_correction_endcap_Ar
static constexpr double s_errors_Comm[s_size_Comm]
DoubleArrayProperty m_tot_corrections_endcap_Ar
DoubleProperty m_ht_correction_barrel_Xe
const InDetDD::TRT_DetectorManager * m_manager
DetectorManager and helper.
virtual double approxDriftTime(double driftradius) const override
Returns approximate drift time (t0 subtracted)
double m_t0_shift
digiversion dependent t0 shift
void setupRtRelation()
Initialise Rt relation.
DoubleArrayProperty m_tot_corrections_endcap_Xe
static const size_t s_size_default
BooleanProperty m_force_universal_errors
use one universal error
TRT_DriftFunctionTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
static const size_t s_size_Comm
DoubleProperty m_ht_correction_endcap_Xe
virtual StatusCode initialize() override
Retrieves needed services.
virtual double driftRadius(double rawtime, Identifier id, double &t0, bool &isOK, unsigned int word=0) const override
Returns drift radius in mm and t0 in ns The radius is truncated so it belongs to [0,...
ToolHandle< ITRT_CalDbTool > m_TRTCalDbTool
Tool to fetch data from database.
static constexpr double s_drifttimeperbin
double m_t0_endcap[18]
t0 for the 14(18) endcap wheels
BooleanProperty m_enable_t0_barrel_shift
enable T0 barrel shift
virtual double driftTimeHTCorrection(Identifier id, bool isArgonStraw=false) const override
Returns high threshold correction to the drift time (ns)
ToolHandle< ITRT_CalDbTool > m_TRTCalDbTool2
virtual double driftTimeToTCorrection(double tot, Identifier id, bool isArgonStraw=false) const override
Returns time over threshold correction to the drift time (ns)
DoubleArrayProperty m_tot_corrections_barrel_Ar
static constexpr double s_radius_default[s_size_default]
DoubleProperty m_uni_error
namely this one
double m_t0_barrel[3]
t0 for the 3 barrel rings