25 #include "GeoModelHelpers/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 bool boundFlag{
false};
251 const double tFromR = rtRelation->tr()->tFromR(std::abs(calibIn.
distanceToTrack()),
253 reso = rtRelation->rtRes()->resolution(tFromR);
258 assert(rtRelation->rt() !=
nullptr);
260 const double driftTimeUp =
std::min(rtRelation->rt()->tUpper(),
261 calibIn.
tdc() * tdcBinSize
264 - calibResult.tubeT0());
266 const double driftTimeDn =
std::max(rtRelation->rt()->tLower(),
267 calibIn.
tdc() * tdcBinSize
270 - calibResult.tubeT0()
273 const double radiusUp = rtRelation->rt()->radius(driftTimeUp);
274 const double radiusDn = rtRelation->rt()->radius(driftTimeDn);
276 <<
" nominal drift time "<<
driftTime<<
", down: "<<driftTimeDn<<
", up: "<<driftTimeUp
277 <<
" --> driftRadius: "<<
r<<
" pm "<<reso<<
", prop-up: "<<radiusUp<<
", prop-dn: "<<radiusDn
278 <<
" delta: "<<(radiusUp-radiusDn));
279 calibResult.setDriftUncertSigProp(0.5*std::abs(radiusUp - radiusDn));
282 calibResult.setDriftRadius(
r, reso);
283 calibResult.setStatus(timeStatus);
286 <<
" passed. "<<std::endl<<
"Input: "<<calibIn<<std::endl<<
"Extracted calib constants: "<<calibResult<<std::endl);
299 double primdriftTime = primHit.tdc()*tdcBinSize - primResult.
tubeT0();
300 double twinDriftTime = twinHit.tdc()*tdcBinSize - twinResult.
tubeT0();
302 if (primdriftTime >= twinDriftTime) {
304 <<
" primDriftTime: "<<primdriftTime<<
", secondTime: "<<twinDriftTime);
309 const Identifier& primId = primHit.identify();
310 const Identifier& twinId = twinHit.identify();
315 if (!data1st || !data2nd) {
316 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
322 if (!calibSingleTube1st || !calibSingleTube2nd) {
323 ATH_MSG_WARNING(__FILE__<<
":"<<__LINE__<<
" Failed to access calibration constants for tubes "<<
329 constexpr
double HVdelay = 6.;
332 double twin_timedif = twinDriftTime - primdriftTime - calibSingleTube2nd->
inversePropSpeed * twinHit.tubeLength() - HVdelay;
336 const double tubeHalfLength = 0.5*primHit.tubeLength();
337 const double zTwin = std::clamp(0.5* primHit.readOutSide()* twin_timedif / calibSingleTube1st->
inversePropSpeed,
338 -tubeHalfLength, tubeHalfLength);
342 <<
" prompthit tdc = " << primHit.tdc() <<
" twinhit tdc = " << twinHit.tdc()
343 <<
" tube driftTime = " << primResult<<
" second tube driftTime = " << twinResult<<
endmsg
344 <<
" Time difference =" << twin_timedif <<
" zTwin=" << zTwin<<
", errorZ="<<errZTwin);
348 calibResult.setLocZ(zTwin, errZTwin);
354 if (rtRelation.
rt()) {
367 ATH_MSG_WARNING(
"No valid rt relation supplied for driftTimeStatus method" );
375 if (!moduleConstants){
383 return rtRel->rtRes()->resolution(
t);