24#include "GeoModelKernel/throwExcept.h"
33 using Property = ToolSettings::Property;
34 settings.setBit(Property::TofCorrection,
m_doTof);
35 settings.setBit(Property::PropCorrection,
m_doProp);
36 settings.setBit(Property::TempCorrection,
m_doTemp);
37 settings.setBit(Property::MagFieldCorrection,
m_doField);
38 settings.setBit(Property::SlewCorrection,
m_doSlew);
39 settings.setBit(Property::BackgroundCorrection,
m_doBkg);
47 case timeWindowMode::UserDefined:
50 case timeWindowMode::Default:
51 ATH_MSG_DEBUG(
"Use 1000. & 2000. as the lower and upper time window values ");
55 case timeWindowMode::CollisionG4:
60 case timeWindowMode::CollisionData:
65 case timeWindowMode::CollisionFitT0:
66 ATH_MSG_DEBUG(
"Use collision data time window of 50 to 100 to fit T0 in the end");
72 return StatusCode::FAILURE;
84 <<
" Correct time of flight "<<(
m_doTof ?
"yay" :
"nay")<<std::endl
85 <<
" Correct propagation time "<<(
m_doProp ?
"si" :
"no")<<std::endl
86 <<
" Correct temperature "<<(
m_doTemp ?
"si" :
"no")<<std::endl
87 <<
" Correct magnetic field "<<(
m_doField ?
"si" :
"no")<<std::endl
88 <<
" Correct time slew "<<(
m_doSlew ?
"si" :
"no")<<std::endl
89 <<
" Correct background "<<(
m_doBkg ?
"si" :
"no"));
90 return StatusCode::SUCCESS;
98 calibData->
getCalibData(channelId, msgStream()) :
nullptr;
102 bool resolFromRtrack)
const {
112 if (!calibConstants) {
131 if (!singleTubeData) {
147 <<(invPropSpeed * propagationDistance));
152 const double driftTime = calibIn.
tdc() * tdcBinSize
168 if (
m_doSlew && corrections->slewing()) {
169 double slewTime=corrections->slewing()->correction(calibResult.
driftTime(), calibIn.
adc());
170 corrTime -= slewTime;
175 if (
m_doField && corrections->bField()) {
188 locBField[
static_cast<int>(BFieldComp::alongWire)],
189 locBField[
static_cast<int>(BFieldComp::alongTrack)]));
200 if (
m_doBkg && corrections->background()) {
210 double r{0.}, reso{0.};
212 double t_inrange = t;
215 assert(rtRelation->rt() !=
nullptr);
216 r = rtRelation->rt()->radius(t);
220 r = rtRelation->rt()->radius( t * (1 + tShift) );
223 if ( t < rtRelation->rt()->tLower()) {
224 t_inrange = rtRelation->rt()->tLower();
225 double rmin = rtRelation->rt()->radius( t_inrange );
226 double drdt = rtRelation->rt()->driftVelocity( t_inrange);
232 r = rmin + drdt*(t-t_inrange);
233 }
else if( t > rtRelation->rt()->tUpper() ) {
234 t_inrange = rtRelation->rt()->tUpper();
235 double rmax = rtRelation->rt()->radius( t_inrange );
236 double drdt = rtRelation->rt()->driftVelocity(t_inrange);
242 r = rmax + drdt*(t-t_inrange);
245 assert(rtRelation->rtRes() !=
nullptr);
258 }
else if (!resolFromRtrack) {
259 reso = rtRelation->rtRes()->resolution( t_inrange );
261 const std::optional<double> tFromR = rtRelation->tr()->driftTime(std::abs(calibIn.
distanceToTrack()));
262 reso = rtRelation->rtRes()->resolution(tFromR.value_or(0.));
266 assert(rtRelation->rt() !=
nullptr);
267 const double driftTimeUp = std::min(rtRelation->rt()->tUpper(),
268 calibIn.
tdc() * tdcBinSize
273 const double driftTimeDn = std::max(rtRelation->rt()->tLower(),
274 calibIn.
tdc() * tdcBinSize
280 const double radiusUp = rtRelation->rt()->radius(driftTimeUp);
281 const double radiusDn = rtRelation->rt()->radius(driftTimeDn);
283 <<
" nominal drift time "<<calibResult.
driftTime()<<
", down: "<<driftTimeDn<<
", up: "<<driftTimeUp
284 <<
" --> driftRadius: "<<
r<<
" pm "<<reso<<
", prop-up: "<<radiusUp<<
", prop-dn: "<<radiusDn
285 <<
" delta: "<<(radiusUp-radiusDn));
294 <<
" passed. "<<std::endl<<
"Input: "<<calibIn<<std::endl<<
"Extracted calib constants: "<<calibResult<<std::endl);
307 double primdriftTime = primHit.tdc()*tdcBinSize - primResult.
tubeT0();
308 double twinDriftTime = twinHit.tdc()*tdcBinSize - twinResult.
tubeT0();
310 if (primdriftTime >= twinDriftTime) {
312 <<
" primDriftTime: "<<primdriftTime<<
", secondTime: "<<twinDriftTime);
317 const Identifier& primId = primHit.identify();
318 const Identifier& twinId = twinHit.identify();
329 if (!data1st || !data2nd) {
330 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
337 if (!calibSingleTube1st || !calibSingleTube2nd) {
338 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
344 constexpr double HVdelay = 6.;
347 double twin_timedif = twinDriftTime - primdriftTime - invPropSpeed * twinHit.tubeLength() - HVdelay;
351 const double tubeHalfLength = 0.5*primHit.tubeLength();
352 const double zTwin = std::clamp(0.5* primHit.readOutSide()* twin_timedif / invPropSpeed, -tubeHalfLength, tubeHalfLength);
353 const double errZTwin =
m_resTwin / invPropSpeed;
356 <<
" prompthit tdc = " << primHit.tdc() <<
" twinhit tdc = " << twinHit.tdc()
357 <<
" tube driftTime = " << primResult<<
" second tube driftTime = " << twinResult<<
endmsg
358 <<
" Time difference =" << twin_timedif <<
" zTwin=" << zTwin<<
", errorZ="<<errZTwin);
362 calibResult.
setLocZ(zTwin, errZTwin);
368 if (rtRelation.
rt()) {
371 << driftTime <<
". Mininum time = "
376 << driftTime <<
". Maximum time = "
381 ATH_MSG_WARNING(
"No valid rt relation supplied for driftTimeStatus method" );
389 if (!moduleConstants){
396 const double t = std::min(std::max(time, rtRel->rt()->tLower()), rtRel->rt()->tUpper());
397 return rtRel->rtRes()->resolution(t);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
MdtCalibOutput::MdtDriftCircleStatus MdtDriftCircleStatus
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h)
void getField(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field value at given position xyz[3] is in mm, bxyz[3] is in kT if deriv[9] is given,...
double backgroundTime() const
Return the time correction arising from background processes.
void setSlewingTime(const double slewTime)
Sets the slewing time.
void setDriftTime(const double driftTime)
Sets the drift time.
void setBackgroundTime(const double bkgTime)
Sets the background time correction.
void setStatus(const MdtDriftCircleStatus stat)
double driftTime() const
Returns the drift time inside the tube.
void setTemperatureTime(const double tempTime)
Sets the temperature time correction.
void setDriftUncertSigProp(const double uncert)
Sets the uncertainty on the drift radius arising from the unknown position along the wires.
void setTubeT0(const double T0)
Sets the tube T0.
double driftUncertSigProp() const
Returns the uncertainty on the drift radius arising from the unknown position along the wire.
void setLorentzTime(const double time)
Sets the Lorentz time.
void setDriftRadius(const double radius, const double uncert)
Sets the charge drift radius and its associated uncertainty.
Muon::MdtDriftCircleStatus MdtDriftCircleStatus
void setMeanAdc(const double adc)
Sets the mean tube adc.
double temperatureTime() const
Returns the time corrections stemming from temperature & pressure corrections.
double signalPropagationTime() const
Returns the signal propagation time.
double lorentzTime() const
Returns the time corrections from the signal propgation inside a magnetic field.
double tubeT0() const
Returns the point in time where the muon typically enters the chamber.
void setPropagationTime(const double T0)
Sets the signal propagation time in the tube wire.
void setLocZ(const double locZ, const double locZuncert)
int multilayer(const Identifier &id) const
Access to components of the ID.
generic interface for a rt-relation
virtual double tLower() const =0
Returns the lower time covered by the r-t.
virtual double tUpper() const =0
Returns the upper time covered by the r-t.
float inversePropSpeed() const
const MdtFullCalibData * getCalibData(const Identifier &measId, MsgStream &msg) const
Returns the calibration data associated with this station.
class which holds calibration constants per rt-region
const IRtRelation * rt() const
rt relation
Support class for PropertyMgr.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
float RtScaleFunction(const float t, const bool ml2, const IRtRelation &rtrelation)
MdtDriftCircleStatus
Enum to represent the 'status' of Mdt measurements e.g.
@ MdtStatusAfterSpectrum
The tube produced a hit that is inconsistent with the drift time spectrum, the drift time is larger t...
@ MdtStatusBeforeSpectrum
The tube produced a hit that is inconsistent with the drift time spectrum, the drift time is smaller ...
@ MdtStatusUnDefined
Undefined.
@ MdtStatusDriftTime
The tube produced a vaild measurement.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
class which holds the full set of calibration constants for a given tube
TubeContainerPtr tubeCalib
CorrectionPtr corrections
float adcCal
quality flag for the SingleTubeCalib constants: 0 all ok, 1 no hits found, 2 too few hits,...
float t0
< relative t0 in chamber (ns)
#define THROW_EXCEPTION(MESSAGE)