27 static double const twoBySqrt12 = 2/std::sqrt(12);
38 using Property = ToolSettings::Property;
39 settings.setBit(Property::TofCorrection,
m_doTof);
40 settings.setBit(Property::PropCorrection,
m_doProp);
41 settings.setBit(Property::TempCorrection,
m_doTemp);
42 settings.setBit(Property::MagFieldCorrection,
m_doField);
43 settings.setBit(Property::WireSagTimeCorrection,
m_doWireSag);
44 settings.setBit(Property::SlewCorrection,
m_doSlew);
45 settings.setBit(Property::BackgroundCorrection,
m_doBkg);
53 case timeWindowMode::UserDefined:
57 ATH_MSG_DEBUG(
"Use 1000. & 2000. as the lower and upper time window values ");
61 case timeWindowMode::CollisionG4:
66 case timeWindowMode::CollisionData:
71 case timeWindowMode::CollisionFitT0:
72 ATH_MSG_DEBUG(
"Use collision data time window of 50 to 100 to fit T0 in the end");
78 return StatusCode::FAILURE;
90 <<
" Correct time of flight "<<(
m_doTof ?
"yay" :
"nay")<<std::endl
91 <<
" Correct propagation time "<<(
m_doProp ?
"si" :
"no")<<std::endl
92 <<
" Correct temperature "<<(
m_doTemp ?
"si" :
"no")<<std::endl
93 <<
" Correct magnetic field "<<(
m_doField ?
"si" :
"no")<<std::endl
94 <<
" Correct wire sagging "<<(
m_doWireSag ?
"si" :
"no")<<std::endl
95 <<
" Correct time slew "<<(
m_doSlew ?
"si" :
"no")<<std::endl
96 <<
" Correct background "<<(
m_doBkg ?
"si" :
"no"));
97 return StatusCode::SUCCESS;
104 bool resolFromRtrack)
const {
109 if (!readCondHandle.isValid()){
111 throw std::runtime_error(
"No calibration constants could be retrieved");
117 if (!calibConstants) {
136 if (!singleTubeData) {
144 calibResult.
setTubeT0(singleTubeData->
t0 + rtRelation->t0Global());
145 calibResult.setMeanAdc(singleTubeData->
adcCal);
150 calibResult.setPropagationTime(singleTubeData->
inversePropSpeed * propagationDistance);
157 - calibResult.tubeT0()
158 - calibResult.signalPropagationTime();
170 if (
m_doSlew && corrections->slewing()) {
171 double slewTime=corrections->slewing()->correction(calibResult.driftTime(), calibIn.
adc());
172 corrTime -= slewTime;
173 calibResult.setSlewingTime(slewTime);
177 if (
m_doField && corrections->bField()) {
181 if (!readHandle.isValid()) {
183 throw std::runtime_error(
"No magnetic field could be retrieved");
185 readHandle->getInitializedCache(fieldCache);
191 calibResult.setLorentzTime(corrections->bField()->correction(calibResult.driftTime(),
192 locBField[BFieldComp::alongWire],
193 locBField[BFieldComp::alongTrack]));
194 corrTime -= calibResult.lorentzTime();
197 const int mL = id_helper.multilayer(
id);
201 calibResult.setTemperatureTime(tempTime);
202 corrTime-=calibResult.temperatureTime();
205 if (
m_doBkg && corrections->background()) {
207 calibResult.setBackgroundTime(corrections->background()->correction(calibResult.driftTime(), bgLevel ));
208 corrTime += calibResult.backgroundTime();
224 double effectiveSag = nominalSurfPos.y()
227 calibResult.setSaggingTime(corrections->wireSag()->correction(
signedDriftRadius, effectiveSag));
229 corrTime += calibResult.saggingTime();
233 calibResult.setDriftTime(calibResult.driftTime() + corrTime);
236 double r{0.}, reso{0.};
237 double t = calibResult.driftTime();
238 double t_inrange =
t;
240 if(rtRelation->rt()) {
241 r = rtRelation->rt()->radius(
t);
245 r = rtRelation->rt()->radius(
t * (1 + tShift) );
248 if ( t < rtRelation->rt()->tLower() ) {
249 t_inrange = rtRelation->rt()->tLower();
250 double rmin = rtRelation->rt()->radius( t_inrange );
251 double drdt = (rtRelation->rt()->radius( t_inrange + 30. ) - rmin)/30.;
259 }
else if(
t > rtRelation->rt()->tUpper() ) {
260 t_inrange = rtRelation->rt()->tUpper();
261 double rmax = rtRelation->rt()->radius( t_inrange );
262 double drdt = (rmax - rtRelation->rt()->radius( t_inrange - 30. ))/30.;
269 r = rmax + drdt*(
t-t_inrange);
276 if (rtRelation->rtRes()) {
277 if (!resolFromRtrack) {
278 reso = rtRelation->rtRes()->resolution( t_inrange );
280 bool boundFlag{
false};
281 const double tFromR = rtRelation->tr()->tFromR(std::abs(calibIn.
distanceToTrack()),
283 reso = rtRelation->rtRes()->resolution(tFromR);
289 calibResult.setDriftRadius(
r, reso);
290 calibResult.setStatus(timeStatus);
293 <<
" passed. "<<std::endl<<
"Input: "<<calibIn<<std::endl<<
"Extracted calib constants: "<<calibResult<<std::endl);
308 double primdriftTime = primHit.
tdc()*tdcBinSize - primResult.
tubeT0();
309 double twinDriftTime = twinHit.
tdc()*tdcBinSize - twinResult.
tubeT0();
313 if (!calibDataContainer.isValid()){
315 throw std::runtime_error(
"No calibration constants could be retrieved");
320 if (!data1st || !data2nd) {
321 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
327 if (!calibSingleTube1st || !calibSingleTube2nd) {
328 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
337 double zTwin{0.}, errZTwin{0.}, twin_timedif{0.};
342 int prompthit_tdc{0}, twinhit_tdc{0};
343 bool firstIsPrompt{
true};
344 if ( primdriftTime < twinDriftTime) {
345 twin_timedif = twinDriftTime - primdriftTime;
347 twin_timedif = primdriftTime - twinDriftTime;
348 firstIsPrompt =
false;
352 const MdtCalibInput& primaryHit{(firstIsPrompt ? primHit : twinHit)};
353 const double tubelength = primaryHit.
tubeLength();
354 constexpr
double HVdelay = 6.;
359 if ( twin_timedif < (HVdelay - 5.*
m_resTwin) ||
360 twin_timedif > (tubelength*(invPropSpeed1st + invPropSpeed2nd)
364 << (tubelength*(invPropSpeed1st + invPropSpeed2nd) + HVdelay + 5.*
m_resTwin)
365 <<
") time difference = " << twin_timedif );
370 if (twin_timedif < (tubelength* (invPropSpeed1st + invPropSpeed2nd)
374 double z_hit_sign_from_twin = ( 1 / (invPropSpeed2nd *2.)) *
375 (tubelength*invPropSpeed2nd -
376 twin_timedif + HVdelay) ;
378 if (z_hit_sign_from_twin < -tubelength/2.) {
379 ATH_MSG_DEBUG(
" TWIN HIT outside acceptance with time difference "
381 <<
" Z local hit " << z_hit_sign_from_twin
382 <<
" Z local minimum " << -tubelength/2 );
383 z_hit_sign_from_twin = - tubelength/2.;
386 const double z_hit_geo_from_twin = primaryHit.readOutSide() *z_hit_sign_from_twin;
388 zTwin = z_hit_geo_from_twin;
394 <<
" prompthit tdc = " << prompthit_tdc
395 <<
" twinhit tdc = " << twinhit_tdc
396 <<
" tube driftTime = " << primResult
397 <<
" second tube driftTime = " << twinResult
398 <<
" TWIN PAIR time difference = " << twin_timedif <<
endmsg
399 <<
" z_hit_sign_from_twin = " << z_hit_sign_from_twin
400 <<
" z_hit_geo_from_twin = " << z_hit_geo_from_twin);
404 ATH_MSG_VERBOSE(
" TIME DIFFERENCE OF TWIN PAIR UNPHYSICAL OUT OF RANGE("
406 << (2*tubelength*invPropSpeed1st + HVdelay + 5*
m_resTwin)
407 <<
") time difference = "
410 errZTwin = tubelength/2.;
414 (firstIsPrompt ? twinHit : primHit),
415 (firstIsPrompt ? primResult : twinResult),
416 (firstIsPrompt ? twinResult : primResult)};
419 calibResult.
setLocZ(zTwin, errZTwin);
425 if (rtRelation.
rt()) {
438 ATH_MSG_WARNING(
"No valid rt relation supplied for driftTimeStatus method" );
446 if (!calibConstants.isValid()) {
448 throw std::runtime_error(
"Where are my Mdt calibration constants");
451 if (!moduleConstants){
453 throw std::runtime_error(
"No constants for calib container");
458 throw std::runtime_error(
"No rt relation ");
461 return rtRel->rtRes()->resolution(
t);