25 #include "GeoModelKernel/throwExcept.h"
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::SlewCorrection,
m_doSlew);
44 settings.setBit(Property::BackgroundCorrection,
m_doBkg);
52 case timeWindowMode::UserDefined:
56 ATH_MSG_DEBUG(
"Use 1000. & 2000. as the lower and upper time window values ");
60 case timeWindowMode::CollisionG4:
65 case timeWindowMode::CollisionData:
70 case timeWindowMode::CollisionFitT0:
71 ATH_MSG_DEBUG(
"Use collision data time window of 50 to 100 to fit T0 in the end");
77 return StatusCode::FAILURE;
89 <<
" Correct time of flight "<<(
m_doTof ?
"yay" :
"nay")<<std::endl
90 <<
" Correct propagation time "<<(
m_doProp ?
"si" :
"no")<<std::endl
91 <<
" Correct temperature "<<(
m_doTemp ?
"si" :
"no")<<std::endl
92 <<
" Correct magnetic field "<<(
m_doField ?
"si" :
"no")<<std::endl
93 <<
" Correct time slew "<<(
m_doSlew ?
"si" :
"no")<<std::endl
94 <<
" Correct background "<<(
m_doBkg ?
"si" :
"no"));
95 return StatusCode::SUCCESS;
102 if (!constantHandle.isValid()){
105 return constantHandle->getCalibData(
channelId, msgStream());
109 bool resolFromRtrack)
const {
113 if (!calibConstants) {
132 if (!singleTubeData) {
140 calibResult.
setTubeT0(singleTubeData->
t0 + rtRelation->t0Global());
141 calibResult.setMeanAdc(singleTubeData->
adcCal);
148 calibResult.setPropagationTime(singleTubeData->
inversePropSpeed * propagationDistance);
155 - calibResult.tubeT0()
156 - calibResult.signalPropagationTime();
168 if (
m_doSlew && corrections->slewing()) {
169 double slewTime=corrections->slewing()->correction(calibResult.driftTime(), calibIn.
adc());
170 corrTime -= slewTime;
171 calibResult.setSlewingTime(slewTime);
175 if (
m_doField && corrections->bField()) {
179 if (!readHandle.isValid()) {
182 readHandle->getInitializedCache(fieldCache);
188 calibResult.setLorentzTime(corrections->bField()->correction(calibResult.driftTime(),
189 locBField[
static_cast<int>(BFieldComp::alongWire)],
190 locBField[
static_cast<int>(BFieldComp::alongTrack)]));
191 corrTime -= calibResult.lorentzTime();
195 const int mL = id_helper.multilayer(
id);
197 calibResult.setTemperatureTime(tempTime);
198 corrTime-=calibResult.temperatureTime();
201 if (
m_doBkg && corrections->background()) {
203 calibResult.setBackgroundTime(corrections->background()->correction(calibResult.driftTime(), bgLevel ));
204 corrTime += calibResult.backgroundTime();
208 calibResult.setDriftTime(calibResult.driftTime() + corrTime);
211 double r{0.}, reso{0.};
212 double t = calibResult.driftTime();
213 double t_inrange =
t;
216 assert(rtRelation->rt() !=
nullptr);
217 r = rtRelation->rt()->radius(
t);
221 r = rtRelation->rt()->radius(
t * (1 + tShift) );
224 if ( t < rtRelation->rt()->tLower() ) {
225 t_inrange = rtRelation->rt()->tLower();
226 double rmin = rtRelation->rt()->radius( t_inrange );
227 double drdt = (rtRelation->rt()->radius( t_inrange + 30. ) - rmin)/30.;
234 }
else if(
t > rtRelation->rt()->tUpper() ) {
235 t_inrange = rtRelation->rt()->tUpper();
236 double rmax = rtRelation->rt()->radius( t_inrange );
237 double drdt = (rmax - rtRelation->rt()->radius( t_inrange - 30. ))/30.;
243 r = rmax + drdt*(
t-t_inrange);
246 assert(rtRelation->rtRes() !=
nullptr);
247 if (!resolFromRtrack) {
248 reso = rtRelation->rtRes()->resolution( t_inrange );
250 const std::optional<double> tFromR = rtRelation->tr()->driftTime(std::abs(calibIn.
distanceToTrack()));
251 reso = rtRelation->rtRes()->resolution(tFromR.value_or(0.));
256 assert(rtRelation->rt() !=
nullptr);
258 const double driftTimeUp =
std::min(rtRelation->rt()->tUpper(),
259 calibIn.
tdc() * tdcBinSize
262 - calibResult.tubeT0());
264 const double driftTimeDn =
std::max(rtRelation->rt()->tLower(),
265 calibIn.
tdc() * tdcBinSize
268 - calibResult.tubeT0()
271 const double radiusUp = rtRelation->rt()->radius(driftTimeUp);
272 const double radiusDn = rtRelation->rt()->radius(driftTimeDn);
274 <<
" nominal drift time "<<
driftTime<<
", down: "<<driftTimeDn<<
", up: "<<driftTimeUp
275 <<
" --> driftRadius: "<<
r<<
" pm "<<reso<<
", prop-up: "<<radiusUp<<
", prop-dn: "<<radiusDn
276 <<
" delta: "<<(radiusUp-radiusDn));
277 calibResult.setDriftUncertSigProp(0.5*std::abs(radiusUp - radiusDn));
280 calibResult.setDriftRadius(
r, reso);
281 calibResult.setStatus(timeStatus);
284 <<
" passed. "<<std::endl<<
"Input: "<<calibIn<<std::endl<<
"Extracted calib constants: "<<calibResult<<std::endl);
297 double primdriftTime = primHit.tdc()*tdcBinSize - primResult.
tubeT0();
298 double twinDriftTime = twinHit.tdc()*tdcBinSize - twinResult.
tubeT0();
300 if (primdriftTime >= twinDriftTime) {
302 <<
" primDriftTime: "<<primdriftTime<<
", secondTime: "<<twinDriftTime);
307 const Identifier& primId = primHit.identify();
308 const Identifier& twinId = twinHit.identify();
313 if (!data1st || !data2nd) {
314 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
320 if (!calibSingleTube1st || !calibSingleTube2nd) {
321 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
327 constexpr
double HVdelay = 6.;
330 double twin_timedif = twinDriftTime - primdriftTime - calibSingleTube2nd->
inversePropSpeed * twinHit.tubeLength() - HVdelay;
334 const double tubeHalfLength = 0.5*primHit.tubeLength();
335 const double zTwin = std::clamp(0.5* primHit.readOutSide()* twin_timedif / calibSingleTube1st->
inversePropSpeed,
336 -tubeHalfLength, tubeHalfLength);
340 <<
" prompthit tdc = " << primHit.tdc() <<
" twinhit tdc = " << twinHit.tdc()
341 <<
" tube driftTime = " << primResult<<
" second tube driftTime = " << twinResult<<
endmsg
342 <<
" Time difference =" << twin_timedif <<
" zTwin=" << zTwin<<
", errorZ="<<errZTwin);
346 calibResult.setLocZ(zTwin, errZTwin);
352 if (rtRelation.
rt()) {
365 ATH_MSG_WARNING(
"No valid rt relation supplied for driftTimeStatus method" );
373 if (!moduleConstants){
381 return rtRel->rtRes()->resolution(
t);