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;
100 return constantHandle->getCalibData(channelId, msgStream());
104 bool resolFromRtrack)
const {
109 if (!constantHandle.
isValid()){
114 if (!calibConstants) {
133 if (!singleTubeData) {
137 const float invPropSpeed = constantHandle->inversePropSpeed();
149 <<(invPropSpeed * propagationDistance));
154 const double driftTime = calibIn.
tdc() * tdcBinSize
170 if (
m_doSlew && corrections->slewing()) {
171 double slewTime=corrections->slewing()->correction(calibResult.
driftTime(), calibIn.
adc());
172 corrTime -= slewTime;
177 if (
m_doField && corrections->bField()) {
184 readHandle->getInitializedCache(fieldCache);
191 locBField[
static_cast<int>(BFieldComp::alongWire)],
192 locBField[
static_cast<int>(BFieldComp::alongTrack)]));
203 if (
m_doBkg && corrections->background()) {
213 double r{0.}, reso{0.};
215 double t_inrange = t;
218 assert(rtRelation->rt() !=
nullptr);
219 r = rtRelation->rt()->radius(t);
223 r = rtRelation->rt()->radius( t * (1 + tShift) );
226 if ( t < rtRelation->rt()->tLower()) {
227 t_inrange = rtRelation->rt()->tLower();
228 double rmin = rtRelation->rt()->radius( t_inrange );
229 double drdt = rtRelation->rt()->driftVelocity( t_inrange);
235 r = rmin + drdt*(t-t_inrange);
236 }
else if( t > rtRelation->rt()->tUpper() ) {
237 t_inrange = rtRelation->rt()->tUpper();
238 double rmax = rtRelation->rt()->radius( t_inrange );
239 double drdt = rtRelation->rt()->driftVelocity(t_inrange);
245 r = rmax + drdt*(t-t_inrange);
248 assert(rtRelation->rtRes() !=
nullptr);
261 }
else if (!resolFromRtrack) {
262 reso = rtRelation->rtRes()->resolution( t_inrange );
264 const std::optional<double> tFromR = rtRelation->tr()->driftTime(std::abs(calibIn.
distanceToTrack()));
265 reso = rtRelation->rtRes()->resolution(tFromR.value_or(0.));
269 assert(rtRelation->rt() !=
nullptr);
270 const double driftTimeUp = std::min(rtRelation->rt()->tUpper(),
271 calibIn.
tdc() * tdcBinSize
276 const double driftTimeDn = std::max(rtRelation->rt()->tLower(),
277 calibIn.
tdc() * tdcBinSize
283 const double radiusUp = rtRelation->rt()->radius(driftTimeUp);
284 const double radiusDn = rtRelation->rt()->radius(driftTimeDn);
286 <<
" nominal drift time "<<calibResult.
driftTime()<<
", down: "<<driftTimeDn<<
", up: "<<driftTimeUp
287 <<
" --> driftRadius: "<<
r<<
" pm "<<reso<<
", prop-up: "<<radiusUp<<
", prop-dn: "<<radiusDn
288 <<
" delta: "<<(radiusUp-radiusDn));
297 <<
" passed. "<<std::endl<<
"Input: "<<calibIn<<std::endl<<
"Extracted calib constants: "<<calibResult<<std::endl);
310 double primdriftTime = primHit.tdc()*tdcBinSize - primResult.
tubeT0();
311 double twinDriftTime = twinHit.tdc()*tdcBinSize - twinResult.
tubeT0();
313 if (primdriftTime >= twinDriftTime) {
315 <<
" primDriftTime: "<<primdriftTime<<
", secondTime: "<<twinDriftTime);
320 const Identifier& primId = primHit.identify();
321 const Identifier& twinId = twinHit.identify();
325 if (!constantHandle.
isValid()){
332 if (!data1st || !data2nd) {
333 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
339 const double invPropSpeed = constantHandle->inversePropSpeed();
340 if (!calibSingleTube1st || !calibSingleTube2nd) {
341 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
347 constexpr double HVdelay = 6.;
350 double twin_timedif = twinDriftTime - primdriftTime - invPropSpeed * twinHit.tubeLength() - HVdelay;
354 const double tubeHalfLength = 0.5*primHit.tubeLength();
355 const double zTwin = std::clamp(0.5* primHit.readOutSide()* twin_timedif / invPropSpeed, -tubeHalfLength, tubeHalfLength);
356 const double errZTwin =
m_resTwin / invPropSpeed;
359 <<
" prompthit tdc = " << primHit.tdc() <<
" twinhit tdc = " << twinHit.tdc()
360 <<
" tube driftTime = " << primResult<<
" second tube driftTime = " << twinResult<<
endmsg
361 <<
" Time difference =" << twin_timedif <<
" zTwin=" << zTwin<<
", errorZ="<<errZTwin);
365 calibResult.
setLocZ(zTwin, errZTwin);
371 if (rtRelation.
rt()) {
374 << driftTime <<
". Mininum time = "
379 << driftTime <<
". Maximum time = "
384 ATH_MSG_WARNING(
"No valid rt relation supplied for driftTimeStatus method" );
392 if (!moduleConstants){
399 const double t = std::min(std::max(time, rtRel->rt()->tLower()), rtRel->rt()->tUpper());
400 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
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.
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.
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)