ATLAS Offline Software
MdtCalibDbAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
12 #include "CLHEP/Random/RandGaussZiggurat.h"
13 #include "CoralBase/Attribute.h"
14 #include "CoralBase/AttributeListSpecification.h"
15 #include "GaudiKernel/PhysicalConstants.h"
17 #include "MdtCalibData/CalibFunc.h"
30 #include "MuonCalibStl/ToString.h"
36 
37 #include "CxxUtils/StringUtils.h"
38 
39 
40 #include <fstream>
41 
42 #include "TFile.h"
43 #include "TSpline.h"
44 
45 using namespace MuonCalib;
46 using namespace CxxUtils;
50 
51 MdtCalibDbAlg::MdtCalibDbAlg(const std::string &name, ISvcLocator *pSvcLocator) :
52  AthReentrantAlgorithm(name, pSvcLocator) {}
53 
55  ATH_MSG_DEBUG("initialize " << name());
56 
57  // if timeslew correction vector m_MeanCorrectionVsR has non-zero size then set
58  // m_TsCorrectionT0=m_MeanCorrectionVsR[0] and subtract this each value in the vector.
59  if (m_MeanCorrectionVsR.size()) {
61  for (float & it : m_MeanCorrectionVsR) {
63  }
64  }
65 
66  ATH_CHECK(m_idHelperSvc.retrieve());
67  ATH_CHECK(m_idToFixedIdTool.retrieve());
68  // initiallize random number generator if doing t0 smearing (for robustness studies)
69  if (m_t0Spread != 0.) {
70  ATH_CHECK(m_AthRNGSvc.retrieve());
71  ATH_MSG_DEBUG(" initialize Random Number Service: running with t0 shift "
72  << m_t0Shift << " spread " << m_t0Spread << " rt shift " << m_rtShift);
73  // getting our random numbers stream
74  m_RNGWrapper = m_AthRNGSvc->getEngine(this, m_randomStream);
75  if (!m_RNGWrapper) {
76  ATH_MSG_ERROR("Could not get random number engine from AthRNGSvc. Abort.");
77  return StatusCode::FAILURE;
78  }
79  }
80 
81  if (m_rtShift != 0. || m_rtScale != 1. || m_t0Shift != 0. || m_t0Spread != 0.) {
82  ATH_MSG_INFO("************************************" << std::endl
83  << " Running with Calibration Deformations! " << std::endl
84  << " For performance studies only!" << std::endl
85  << " **************************************");
86  ATH_MSG_DEBUG(" rt scale " << m_rtScale << " t0 shift " << m_t0Shift << " spread " << m_t0Spread << " rt shift " << m_rtShift);
87  }
88 
93 
96  return StatusCode::SUCCESS;
97 }
98  StatusCode MdtCalibDbAlg::declareDependency(const EventContext& ctx,
100 
101  writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteTime()));
103  if (key.empty()) continue;
105  if (!readHandle.isValid()) {
106  ATH_MSG_FATAL("Failed to retrieve conditions object "<<readHandle.fullKey());
107  return StatusCode::FAILURE;
108  }
109  writeHandle.addDependency(readHandle);
110  ATH_MSG_INFO("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdoRt->size()= " << readHandle->size());
111  ATH_MSG_INFO("Range of input is " << readHandle.getRange());
112  }
113  if (m_readKeyDCS.empty()) return StatusCode::SUCCESS;
115  if (!readHandle.isValid()) {
116  ATH_MSG_FATAL("Failed to retrieve conditions object "<<m_readKeyDCS.fullKey());
117  return StatusCode::FAILURE;
118  }
119  writeHandle.addDependency(readHandle);
120  return StatusCode::SUCCESS;
121 }
122 StatusCode MdtCalibDbAlg::execute(const EventContext& ctx) const {
123  ATH_MSG_DEBUG("execute " << name());
125  if (writeHandle.isValid()) {
126  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
127  << ". In theory this should not be called, but may happen"
128  << " if multiple concurrent events are being processed out of order.");
129  return StatusCode::SUCCESS;
130  }
131  ATH_CHECK(declareDependency(ctx, writeHandle));
132 
133  RegionGranularity gran{RegionGranularity::OnePerChamber};
134  if (m_readKeyRt.key() == "/MDT/RTUNIQUE") {
135  ATH_MSG_DEBUG("Save one set of Rt constants per chamber");
136  gran = RegionGranularity::OneRt;
137  } else if (m_UseMLRt) {
138  ATH_MSG_DEBUG("Save one set of calibration constants per multi layer");
139  gran = RegionGranularity::OnePerMultiLayer;
140  } else ATH_MSG_DEBUG("Save one set of calibration constants per chamber");
141  std::unique_ptr<MuonCalib::MdtCalibDataContainer> writeCdo = std::make_unique<MuonCalib::MdtCalibDataContainer>(m_idHelperSvc.get(), gran);
142 
143  ATH_CHECK(loadRt(ctx, *writeCdo));
144  ATH_CHECK(loadTube(ctx, *writeCdo));
145  ATH_CHECK(writeHandle.record(std::move(writeCdo)));
146  return StatusCode::SUCCESS;
147 }
148 
150  ATH_MSG_DEBUG("defaultRt " << name());
152  std::ifstream inputFile(fileName);
153  if (!inputFile) {
154  ATH_MSG_ERROR("Unable to open RT Ascii file: " << fileName);
155  return StatusCode::FAILURE;
156  }
157  ATH_MSG_DEBUG("Opened RT Ascii file: " << fileName);
158 
159 
160  // Read the RTs from the text file
162  rts.read(inputFile);
163  ATH_MSG_VERBOSE("File contains " << rts.nRts() << " RT relations ");
164 
165  // Loop over all RTs in the file (but the default file only has 1 RT)
166  // Use the first valid RT found in the file as the default for all chambers.
167  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
168  for (unsigned int n = 0; n < rts.nRts(); ++n) {
169  std::unique_ptr<MuonCalib::RtDataFromFile::RtRelation> rt(rts.getRt(n));
170 
174 
175  // check if rt contains data, at least two points on the rt are required
176  if (times.size() < 2) {
177  ATH_MSG_ERROR(" defaultRt rt table has too few entries");
178  return StatusCode::FAILURE;
179  }
180  // check if all tables have same size
181  if (times.size() != radii.size() || times.size() != reso.size()) {
182  ATH_MSG_ERROR("defaultRt rt table size mismatch ");
183  return StatusCode::FAILURE;
184  }
185  // check for negative time bins, i.e. decreasing time value with radius
186  double t_min = times[0];
187  double bin_size = times[1] - t_min;
188  if (bin_size <= 0) {
189  ATH_MSG_ERROR("defaultRt rt table negative binsize ");
190  return StatusCode::FAILURE;
191  }
192 
193  // create a vector to hold the r values,
194  // we need two extra fields to store t_min and bin_size
196  rtPars.push_back(t_min);
197  rtPars.push_back(bin_size);
198 
199  // copy r values into vector
200  rtPars.insert(rtPars.end(), radii.begin(), radii.end());
201 
202  ATH_MSG_DEBUG("defaultRt new MuonCalib::IRtRelation");
203 
204  MuonCalib::CalibFunc::ParVec resoPars{t_min, bin_size};
205  // copy r values into vector
206  resoPars.insert(resoPars.end(), reso.begin(), reso.end());
207 
208  ATH_MSG_DEBUG("defaultRt new MuonCalib::IRtResolution");
209 
210  // create RT and resolution "I" objects
211  std::unique_ptr<MuonCalib::IRtRelation> rtRel {MuonCalib::MdtCalibrationFactory::createRtRelation("RtRelationLookUp", rtPars)};
212  if (!rtRel) ATH_MSG_WARNING("ERROR creating RtRelationLookUp ");
213 
214  std::unique_ptr<MuonCalib::IRtResolution> resoRel{MuonCalib::MdtCalibrationFactory::createRtResolution("RtResolutionLookUp", resoPars)};
215  if (!resoRel) ATH_MSG_WARNING("ERROR creating RtResolutionLookUp ");
216 
217  // if either RT and resolution are not OK then delete both and try next RT in file
218  if (!resoRel || !rtRel) {
219  continue;
220  }
221 
222  // Since the same RT is loaded for all chambers you might be tempted to create it once
223  // and simply store the same pointer in writeCdoRt for all regions.
224  // However it seems that when StoreGate clears writeCdoRt (which will happen in LoadRt
225  // by detStore()->removeDataAndProxy) it will crash unless there are unique pointers/objects
226  // for rtRel, resoRel, and MdtRtRelation
227 
228  // Loop over RT regions and store the default RT in each
229  std::unique_ptr<MuonCalib::IRtRelation> rtRelRegion{MuonCalib::MdtCalibrationFactory::createRtRelation("RtRelationLookUp", rtPars)};
230  std::unique_ptr<MuonCalib::IRtResolution> resoRelRegion{MuonCalib::MdtCalibrationFactory::createRtResolution("RtResolutionLookUp", resoPars)};
231  RtRelationPtr MdtRt = std::make_unique<MuonCalib::MdtRtRelation>(std::move(rtRelRegion), std::move(resoRelRegion), 0.);
232 
233  for(auto itr = idHelper.detectorElement_begin();
234  itr!= idHelper.detectorElement_end();++itr){
235  const Identifier detElId{*itr};
236  if (writeCdo.hasDataForChannel(detElId, msgStream())) {
237  const MdtFullCalibData* dataObj = writeCdo.getCalibData(detElId, msgStream());
238  if (dataObj->rtRelation) {
239  ATH_MSG_DEBUG("Rt relation constants for "<<m_idHelperSvc->toString(detElId)<<" already exists");
240  continue;
241  }
242  }
244  RtRelationPtr storeMe = MdtRt;
245  if (idHelper.multilayer(detElId) == 2) {
246  if (writeCdo.granularity() != RegionGranularity::OnePerMultiLayer) continue;
247  const Identifier firstML = idHelper.multilayerID(detElId, 1);
248  if (writeCdo.hasDataForChannel(firstML, msgStream())) {
249  const MdtFullCalibData* dataObj = writeCdo.getCalibData(firstML, msgStream());
250  if (dataObj->rtRelation) {
251  ATH_MSG_DEBUG("Copy Rt constanst from the first multi layer for "<<m_idHelperSvc->toString(detElId));
252  storeMe = dataObj->rtRelation;
253  }
254  }
255  }
256  ATH_MSG_DEBUG("Add default rt constants for "<<m_idHelperSvc->toString(detElId));
257  if (!writeCdo.storeData(detElId, storeMe, msgStream())) {
258  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" Failed to save default rts for "<<m_idHelperSvc->toString(detElId));
259  return StatusCode::FAILURE;
260  }
261 
263  loadedRts[detElId] = MdtRt;
264 
265  }
266 
267  // if VERBOSE enabled print out RT function
268  if (msgLvl(MSG::VERBOSE)) {
269  int npoints = rtRel->nPar() - 2;
270  ATH_MSG_VERBOSE("defaultRt npoints from rtRel=" << npoints);
271  for (int ipt = 0; ipt < npoints; ++ipt) {
272  double t = t_min + ipt * bin_size;
273  ATH_MSG_VERBOSE(" " << ipt << " " << t << " " << rtRel->radius(t) << " " << resoRel->resolution(t));
274  }
275  }
276  break; // only need the first good RT from the text file
277 
278  } // end loop over RTs in file
279 
280  return StatusCode::SUCCESS;
281 }
282 std::optional<double> MdtCalibDbAlg::getInnerTubeRadius(const Identifier& id) const {
283  static std::atomic<bool> rtWarningPrinted = false;
284 
285  if (m_detMgr) {
287  if (detEl) { return std::make_optional<double>(detEl->innerTubeRadius()); }
288 
289  } else if (m_r4detMgr) {
290  const MuonGMR4::MdtReadoutElement* detEl = m_r4detMgr->getMdtReadoutElement(id);
291  if (detEl) { return std::make_optional<double>(detEl->innerTubeRadius()); }
292  }
293  if (!rtWarningPrinted) {
294  ATH_MSG_WARNING("getInnerTubeRadius() - no Muon station known under the name "
295  << m_idHelperSvc->toString(id));
296  rtWarningPrinted = true;
297  }
298  return std::nullopt;
299 }
300 
302  std::string data{}, delim{};
303  if (attr["data"].specification().type() == typeid(coral::Blob)) {
304  ATH_MSG_VERBOSE("Loading data as a BLOB, uncompressing...");
305  if (!CoralUtilities::readBlobAsString(attr["data"].data<coral::Blob>(), data)) {
306  ATH_MSG_FATAL("Cannot uncompress BLOB! Aborting...");
307  return StatusCode::FAILURE;
308  }
309  delim = "\n";
310  } else {
311  data = *(static_cast<const std::string *>((attr["data"]).addressOfData()));
312  delim = " ";
313  }
314  const std::vector<std::string> tokens = tokenize(data, delim);
315  if (tokens.size() < 2) {
316  ATH_MSG_FATAL("The line "<<data<<" cannot be resolved into header & payload");
317  return StatusCode::FAILURE;
318  }
319  const std::string& header = tokens[0];
320  const std::string& payload = tokens[1];
321  ATH_MSG_DEBUG("Header: '"<<header<<"' payload: '"<<payload<<"'");
323  unsigned int numPoints{0};
325  const bool rt_ts_applied = (attr["tech"].data<int>() & MuonCalib::TIME_SLEWING_CORRECTION_APPLIED);
326  channel["appliedRT"] = rt_ts_applied;
327  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
328  {
329 
330  std::vector<int> tokensHeader = tokenizeInt(header, ",");
331  if(tokensHeader.size()< 2){
332  ATH_MSG_FATAL("Failed to deduce extract number of points & calib Identifier from "<<header);
333  return StatusCode::FAILURE;
334  }
335  unsigned int calibId = tokensHeader[0];
336  numPoints = tokensHeader[1];
337  MuonCalib::MuonFixedId id(calibId);
338  if (!id.is_mdt()) {
339  ATH_MSG_FATAL("Found non-MDT MuonFixedId, continuing...");
340  return StatusCode::FAILURE;
341  }
342  const Identifier athenaId = m_idToFixedIdTool->fixedIdToId(id);
343  if (!m_idHelperSvc->isMuon(athenaId)) {
344  ATH_MSG_WARNING("The translation from the calibration ID with station: "
345  <<id.stationNameString()<<"("<<id.stationName()<<") "
346  <<" eta:"<<id.eta()<<" phi: "<<id.phi());
347  }
348  channel["station"] = m_idHelperSvc->stationNameString(athenaId);
349  channel["eta"] = m_idHelperSvc->stationEta(athenaId);
350  channel["phi"] = m_idHelperSvc->stationPhi(athenaId);
351  channel["ml"] = idHelper.multilayer(athenaId);
352  channel["layer"] = idHelper.tubeLayer(athenaId);
353  channel["tube"] = idHelper.tube(athenaId);
354  }
356  const std::vector<double> dataPoints = tokenizeDouble(payload, ",");
357  std::vector<double> radii{}, times{}, resos{};
358  radii.reserve(numPoints);
359  times.reserve(numPoints);
360  resos.reserve(numPoints);
364  for (unsigned int k = 0 ; k < dataPoints.size(); ++k) {
365  const double value = dataPoints[k];
366  switch (k%3) {
367  case 0:
368  radii.push_back(value);
369  break;
370  case 1:
371  times.push_back(value);
372  break;
373  case 2:
374  resos.push_back(value);
375  break;
376  default:
377  break;
378  }
379  }
381  if (radii.size() != numPoints ||
382  times.size() != numPoints ||
383  resos.size() != numPoints) {
384  ATH_MSG_FATAL("Payload "<<payload<<" does not lead to the expected number of points "<<numPoints<<" vs. "<<dataPoints.size());
385  return StatusCode::FAILURE;
386  }
387  channel["radii"] = std::move(radii);
388  channel["times"] = std::move(times);
389  channel["resolutions"] = std::move(resos);
390  json.push_back(channel);
391  return StatusCode::SUCCESS;
392 }
393 
394 StatusCode MdtCalibDbAlg::loadRt(const EventContext& ctx, MuonCalib::MdtCalibDataContainer& writeCdo) const {
395  ATH_MSG_DEBUG("loadRt " << name());
396 
397  // Read Cond Handle
399  if (!readHandleRt.isValid()) {
400  ATH_MSG_ERROR("readCdoRt==nullptr");
401  return StatusCode::FAILURE;
402  }
403  // read new-style format 2020
404 
405  nlohmann::json rtCalibJson = nlohmann::json::array();
406  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
407  if (m_newFormat2020) {
408  for (CondAttrListCollection::const_iterator itr = readHandleRt->begin();
409  itr != readHandleRt->end(); ++itr) {
410  const coral::AttributeList &atr = itr->second;
411  std::string data{};
412  if (atr["data"].specification().type() == typeid(coral::Blob)) {
413  ATH_MSG_VERBOSE("Loading data as a BLOB, uncompressing...");
414  if (!CoralUtilities::readBlobAsString(atr["data"].data<coral::Blob>(), data)) {
415  ATH_MSG_FATAL("Cannot uncompress BLOB! Aborting...");
416  return StatusCode::FAILURE;
417  }
418  } else {
419  ATH_MSG_VERBOSE("Loading data as a STRING");
420  data = *(static_cast<const std::string *>((atr["data"]).addressOfData()));
421  }
422  // unwrap the json and build the data vector
424  for (auto &it : yy.items()) {
425  nlohmann::json yx = it.value();
426  rtCalibJson.push_back(yx);
427  }
428  }
429  }
430  // read old-style format
431  else {
432  for (CondAttrListCollection::const_iterator itr = readHandleRt->begin();
433  itr != readHandleRt->end(); ++itr) {
434  ATH_CHECK(legacyRtPayloadToJSON(itr->second, rtCalibJson));
435  }
436  }
438  LoadedRtMap loadedRtRel{};
439  // unpack the strings in the collection and update the writeCdoRt
440  for (const auto& payload : rtCalibJson) {
441  const bool rt_ts_applied = payload["appliedRT"];
443  const std::string stName = payload["station"];
444  const Identifier athenaId = idHelper.channelID(stName, payload["eta"], payload["phi"],
445  payload["ml"], payload["layer"], payload["tube"]);
446 
447  std::optional<double> innerTubeRadius = getInnerTubeRadius(idHelper.multilayerID(athenaId, 1));
448  if (!innerTubeRadius) continue;
449 
450 
451  const std::vector<double> radii = payload["radii"];
452  const std::vector<double> times = payload["times"];
453  const std::vector<double> resolutions = payload["resolutions"];
454 
455  if (writeCdo.hasDataForChannel(athenaId, msgStream())) {
456  const MdtFullCalibData* dataObj = writeCdo.getCalibData(athenaId, msgStream());
457  if (dataObj->rtRelation) {
458  ATH_MSG_DEBUG("Rt relation constants for "<<m_idHelperSvc->toString(athenaId)<<" already exists");
459  continue;
460  }
461  }
462 
463  MuonCalib::CalibFunc::ParVec rtPars{}, resoPars{};
464 
465  MuonCalib::SamplePoint tr_point, ts_point; // pairs of numbers; tr = (time,radius); ts = (time,sigma) [sigma=resolution]
466  std::vector<MuonCalib::SamplePoint> tr_points{}, ts_points{};
468  float multilayer_tmax_diff{-std::numeric_limits<float>::max()};
469 
470  // loop over RT function payload (triplets of radius,time,sigma(=resolution) )
471  for (unsigned int k = 0; k < radii.size(); ++k) {
472  float radius = radii[k];
473  if (m_rtShift != 0.) {
474  float oldradius = radius;
475  // TODO: What is this magic number
476  float rshift = m_rtShift * 1.87652e-2 * radius * (radius - *innerTubeRadius);
477  radius = oldradius + rshift;
478  ATH_MSG_DEBUG("DEFORM RT: old radius " << oldradius << " new radius " << radius << " shift " << rshift
479  << " max shift " << m_rtShift);
480  }
481 
482  if (m_rtScale != 1.) {
483  float oldradius = radius;
484  radius = radius * m_rtScale;
485  ATH_MSG_DEBUG("DEFORM RT: old radius " << oldradius << " new radius " << radius << " scale factor " << m_rtScale);
486  }
487  tr_point.set_x2(radius);
488 
489  float time = times[k];
490  tr_point.set_x1(time);
491  ts_point.set_x1(time);
492 
493  float sigma = resolutions[k];
494  ts_point.set_x2(sigma);
495  ts_point.set_error(1.0);
496  tr_point.set_error(1.0);
497  if (tr_point.x2() < -99) { // if radius is < -99 then treat time as ML Tmax difference
498  multilayer_tmax_diff = tr_point.x1();
499  } else if (k == 0 || (tr_points[k - 1].x1() < tr_point.x1() && tr_points[k - 1].x2() < tr_point.x2())) {
500  tr_points.push_back(tr_point);
501  ts_points.push_back(ts_point);
502  }
503  } // end loop over RT function payload (triplets of radius,time,resolution)
504 
506  if (ts_points.size() < 3) {
507  ATH_MSG_FATAL("Rt relation broken!");
508  return StatusCode::FAILURE;
509  }
510 
511  if (rt_ts_applied != m_TimeSlewingCorrection) {
512  float sign(rt_ts_applied ? -1.0 : 1.0);
513  float slice_width = (*innerTubeRadius) / static_cast<float>(m_MeanCorrectionVsR.size());
514  for (auto & tr_point : tr_points) {
515  int slice_number = static_cast<int>(std::floor(tr_point.x2() / slice_width));
516  if (slice_number < 0) slice_number = 0;
517  if (slice_number >= static_cast<int>(m_MeanCorrectionVsR.size()))
518  slice_number = static_cast<int>(m_MeanCorrectionVsR.size()) - 1;
519  tr_point.set_x1(tr_point.x1() + sign * m_MeanCorrectionVsR[slice_number]);
520  }
521  }
522 
523  // Create resolution function from ts_points
524  std::unique_ptr<MuonCalib::IRtResolution> reso = getRtResolutionInterpolation(ts_points);
525  if (msgLvl(MSG::VERBOSE)) {
526  ATH_MSG_VERBOSE("Resolution points :");
527  for (const MuonCalib::SamplePoint& point : tr_points) {
528  ATH_MSG_VERBOSE(point.x1() << "|" << point.x2() << "|" << point.error());
529  }
530  ATH_MSG_DEBUG("Resolution parameters :");
531  for (unsigned int i = 0; i < reso->nPar(); i++) { ATH_MSG_VERBOSE(i << " " << reso->par(i)); }
532  }
533 
534  // Create RT function from tr_points and load RT and resolution functions
535  std::unique_ptr<MuonCalib::IRtRelation> rt = std::make_unique<MuonCalib::RtRelationLookUp>(MuonCalib::RtFromPoints::getRtRelationLookUp(tr_points));
536  if (!reso || !rt) { continue; }
537 
538  if (rt->par(1) == 0.) {
539  ATH_MSG_FATAL("Bin size is 0");
540  for (const MuonCalib::SamplePoint& it: tr_points)
541  ATH_MSG_WARNING(it.x1() << " " << it.x2() << " " << it.error());
542  return StatusCode::FAILURE;
543  }
544  // Save ML difference if it is available
545  if (multilayer_tmax_diff > -8e8) { rt->SetTmaxDiff(multilayer_tmax_diff); }
546  // Store RT and resolution functions for this region
547  RtRelationPtr rt_rel = std::make_unique<MuonCalib::MdtRtRelation>(std::move(rt), std::move(reso), 0.);
548 
549  if (!writeCdo.storeData(athenaId ,rt_rel, msgStream())) return StatusCode::FAILURE;
551  loadedRtRel[athenaId] = rt_rel;
552 
553  } // end loop over itr (strings read from COOL)
554  ATH_CHECK(defaultRt(writeCdo, loadedRtRel));
555 
556  if (loadedRtRel.empty()) {
557  return StatusCode::SUCCESS;
558  }
559 
560  ATH_MSG_DEBUG("Initializing " << loadedRtRel.size()<< " b-field functions");
561  const MdtCondDbData* condDbData{nullptr};
562  if (!m_readKeyDCS.empty()) {
563  SG::ReadCondHandle<MdtCondDbData> readCondHandleDb{m_readKeyDCS, ctx};
565  if (readCondHandleDb->hasDCS()) {
566  condDbData = readCondHandleDb.cptr();
567  } else {
568  ATH_MSG_INFO("Do not retrieve the HV from DCS. Fall back to 2730 & 3080");
569  }
570  }
571 
572 
573  for (const auto& [athenaId, rtRelation] : loadedRtRel) {
574  CorrectionPtr corrFuncSet = std::make_unique<MuonCalib::MdtCorFuncSet>();
575 
577  std::vector<double> corr_params(2);
578  bool loadDefault{false};
579  if (condDbData){
580  const MuonCond::DcsConstants& dcs{condDbData->getHvState(athenaId)};
581  corr_params[0] = dcs.readyVolt;
583  if (corr_params[0] < std::numeric_limits<float>::epsilon()) {
584  ATH_MSG_DEBUG("Chamber "<<m_idHelperSvc->toString(athenaId)<<" is switched off "<<dcs);
585  loadDefault = true;
586  }
587  } else loadDefault = true;
588  if (loadDefault) {
589  if (m_idHelperSvc->issMdt(athenaId)) {
590  corr_params[0] = 2730.0;
591  } else {
592  corr_params[0] = 3080.0;
593  }
594  }
595  corr_params[1] = 0.11; // epsilon parameter
596  corrFuncSet->setBField(std::make_unique<MuonCalib::BFieldCorFunc>("medium", corr_params, rtRelation->rt()));
597  }
600  corrFuncSet->setSlewing(std::make_unique<MuonCalib::MdtSlewCorFuncHardcoded>(MuonCalib::CalibFunc::ParVec()));
601  }
602  if (!writeCdo.storeData(athenaId, corrFuncSet, msgStream())) return StatusCode::FAILURE;
603  }
604 
605  return StatusCode::SUCCESS;
606 }
607 
608 // build the transient structure and load some defaults for T0s
610  const MdtIdHelper& id_helper{m_idHelperSvc->mdtIdHelper()};
611 
612  // Inverse of wire propagation speed
613  const float inversePropSpeed = 1. / (Gaudi::Units::c_light * m_prop_beta);
614 
615  // loop over modules (MDT chambers) and create an MdtTubeContainer for each
616  MdtIdHelper::const_id_iterator it = id_helper.module_begin();
617  MdtIdHelper::const_id_iterator it_end = id_helper.module_end();
618  for (; it != it_end; ++it) {
619 
620  if (writeCdo.hasDataForChannel(*it, msgStream())) {
621  const MdtFullCalibData* dataObj = writeCdo.getCalibData(*it, msgStream());
622  if (dataObj->tubeCalib) {
623  ATH_MSG_DEBUG("Rt relation constants for "<<m_idHelperSvc->toString(*it)<<" already exists");
624  continue;
625  }
626  }
627  // create an MdtTubeContainer
628  TubeContainerPtr tubes = std::make_unique<MuonCalib::MdtTubeCalibContainer>(m_idHelperSvc.get(), *it);
629  if (!writeCdo.storeData(*it, tubes, msgStream())) return StatusCode::FAILURE;
630 
631  // is tubes ever 0? how could that happen?
632  double t0 = m_defaultT0;
633 
634  unsigned int nml = tubes->numMultilayers();
635  unsigned int nlayers = tubes->numLayers();
636  unsigned int ntubes = tubes->numTubes();
637  int size = nml * nlayers * ntubes;
638 
639  ATH_MSG_VERBOSE("Adding chamber " << m_idHelperSvc->toString(*it)
640  <<" size " << size << " ml " << nml << " l " << nlayers << " t " << ntubes);
641  for (unsigned int ml = 1; ml <= nml; ++ml) {
642  for (unsigned int l = 1; l <= nlayers; ++l) {
643  for (unsigned int t = 1; t <= ntubes; ++t) {
645  const Identifier tubeId = id_helper.channelID(*it, ml, l, t);
646  data.t0 = t0;
647  data.adcCal = 1.;
648  data.inversePropSpeed = inversePropSpeed;
649  tubes->setCalib(std::move(data), tubeId, msgStream());
650  }
651  }
652  }
653  }
654  return StatusCode::SUCCESS;
655 }
656 
657 
659  std::string data{};
660  if (attr["data"].specification().type() == typeid(coral::Blob)) {
661  ATH_MSG_VERBOSE("Loading data as a BLOB, uncompressing...");
662  if (!CoralUtilities::readBlobAsString(attr["data"].data<coral::Blob>(), data)) {
663  ATH_MSG_FATAL("Cannot uncompress BLOB! Aborting...");
664  return StatusCode::FAILURE;
665  }
666 
667  } else {
668  data = *(static_cast<const std::string *>((attr["data"]).addressOfData()));
669  }
670  std::vector<std::string> tokens = tokenize(data, "\n");
671  if (tokens.size() < 2) {
672  ATH_MSG_FATAL("The line "<<data<<" cannot be resolved into header & payload");
673  return StatusCode::FAILURE;
674  }
675  std::string& header = tokens[0];
676  const std::string& payload = tokens[1];
677 
682  const std::string stName = header.substr(2,3);
683  int eta{0}, phi{0}, nTubes{0};
684  {
685  std::replace(header.begin(), header.end(),'_', ',');
686  const std::vector<std::string> headerTokens = tokenize(header, ",");
687  phi = atoi(headerTokens[1]);
688  eta = atoi(headerTokens[2]);
689  nTubes = atoi(headerTokens[5]);
690  }
691  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
692  bool isValid{false};
693  const Identifier chamID = idHelper.elementID(stName, eta, phi, isValid);
694  if (!isValid) {
695  static std::atomic<bool> idWarningPrinted = false;
696  if (!idWarningPrinted) {
697  ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<" Identifier: "<<stName<<","<<eta<<","<<phi
698  <<" is invalid. Skipping");
699  idWarningPrinted.store(true, std::memory_order_relaxed);
700  }
701  return StatusCode::SUCCESS;
702  }
704  const bool t0_ts_applied = (attr["tech"].data<int>() & MuonCalib::TIME_SLEWING_CORRECTION_APPLIED);
705  channel["appliedT0"] = t0_ts_applied;
706  channel["station"] = stName;
707  channel["eta"] = eta;
708  channel["phi"] = phi;
709 
710  const std::vector<double> payLoadData = tokenizeDouble(payload, ",");
711  std::vector<double> tzeros{}, meanAdcs{};
712  std::vector<int> statusCodes{};
715  for (unsigned int k = 0; k < payLoadData.size(); ++k){
716  const double value = payLoadData[k];
717  switch (k%3) {
718  case 0:
719  tzeros.push_back(value);
720  break;
721  case 1:
722  statusCodes.push_back(value);
723  break;
724  case 2:
725  meanAdcs.push_back(value);
726  break;
727  default:
728  break;
729  }
730  }
731  if (statusCodes.size() != tzeros.size() ||
732  statusCodes.size() != meanAdcs.size() ||
733  statusCodes.empty()) {
734  ATH_MSG_FATAL("Failed to properly readt t0 calibrations for chamber "<<m_idHelperSvc->toStringChamber(chamID));
735  return StatusCode::FAILURE;
736  }
738  int ml{1}, layer{1}, tube{1};
739 
740  const int numMl = idHelper.numberOfMultilayers(chamID);
741  const Identifier secondMlID = idHelper.multilayerID(chamID, numMl);
742  const int tubesPerLay = std::max(idHelper.tubeMax(chamID), idHelper.tubeMax(secondMlID));
743  const int numLayers = std::max(idHelper.tubeLayerMax(chamID), idHelper.tubeLayerMax(secondMlID));
744  if (m_checkTubes && (numMl * numLayers * tubesPerLay) != nTubes) {
745  ATH_MSG_FATAL("Calibration database differs in terms of number of tubes for chamber "
746  <<m_idHelperSvc->toStringChamber(chamID)<<". Expected "<<(numMl * numLayers * tubesPerLay)
747  <<" vs. observed "<<nTubes);
748  return StatusCode::FAILURE;
749  }
751  for (unsigned int k = 0; k < tzeros.size(); ++k) {
752  nlohmann::json channelData{};
753  channelData["ml"] = ml;
754  channelData["layer"] =layer;
755  channelData["tube"] = tube;
756  channelData["t0"] = tzeros[k];
757  channelData["meanAdc"] = meanAdcs[k];
758  channelData["status"] = statusCodes[k];
759  ++tube;
760  if (tube > tubesPerLay){
761  tube = 1;
762  ++layer;
763  }
764  if (layer > numLayers){
765  layer = 1;
766  ++ml;
767  }
768  calibData.push_back(std::move(channelData));
769  }
770  channel["calibConstants"] = std::move(calibData);
771  json.push_back(std::move(channel));
772  return StatusCode::SUCCESS;
773 }
774 StatusCode MdtCalibDbAlg::loadTube(const EventContext& ctx, MuonCalib::MdtCalibDataContainer& writeCdo) const {
775  ATH_MSG_DEBUG("loadTube " << name());
776  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
777 
778  // Read Cond Handle
780  // read new-style format 2020
781  nlohmann::json t0CalibJson = nlohmann::json::array();
782  if (m_newFormat2020) {
783  for (CondAttrListCollection::const_iterator itr = readHandleTube->begin();
784  itr != readHandleTube->end(); ++itr) {
785  const coral::AttributeList &atr = itr->second;
786  std::string data{};
787  if (atr["data"].specification().type() == typeid(coral::Blob)) {
788  ATH_MSG_VERBOSE("Loading data as a BLOB, uncompressing...");
789  if (!CoralUtilities::readBlobAsString(atr["data"].data<coral::Blob>(), data)) {
790  ATH_MSG_FATAL("Cannot uncompress BLOB! Aborting...");
791  return StatusCode::FAILURE;
792  }
793  } else {
794  ATH_MSG_VERBOSE("Loading data as a STRING");
795  data = *(static_cast<const std::string *>((atr["data"]).addressOfData()));
796  }
797  // unwrap the json and build the data vector
799  for (auto &it : yy.items()) {
800  nlohmann::json yx = it.value();
801  t0CalibJson.push_back(yx);
802  }
803  }
804  }
805  // read old-style format
806  else {
807  for (CondAttrListCollection::const_iterator itr = readHandleTube->begin();
808  itr != readHandleTube->end(); ++itr) {
809  ATH_CHECK(legacyTubePayloadToJSON(itr->second, t0CalibJson));
810  }
811  }
812 
813  // Inverse of wire propagation speed
814  const float inversePropSpeed = 1. / (Gaudi::Units::c_light * m_prop_beta);
815 
816  // unpack the strings in the collection and update the
817  // MdtTubeCalibContainers in TDS
818  for (const auto& chambChannel : t0CalibJson) {
819  const std::string stName = chambChannel["station"];
820  const int ieta = chambChannel["eta"];
821  const int iphi = chambChannel["phi"];
822  const bool t0_ts_applied = chambChannel["appliedT0"];
823  // need to check validity of Identifier since database contains all Run 2 MDT chambers, e.g. also EI chambers which are
824  // potentially replaced by NSW
825  bool isValid{false}; // the elementID takes a bool pointer to check the validity of the Identifier
826  const Identifier chId = idHelper.elementID(stName, ieta, iphi, isValid);
827  if (!isValid) {
828  static std::atomic<bool> idWarningPrinted = false;
829  if (!idWarningPrinted) {
830  ATH_MSG_WARNING("Element Identifier " << chId.get_compact() << " retrieved for station name " << stName
831  << " is not valid, skipping");
832  idWarningPrinted.store(true, std::memory_order_relaxed);
833  }
834  continue;
835  }
836 
837  if (writeCdo.hasDataForChannel(chId, msgStream())) {
838  const MdtFullCalibData* dataObj = writeCdo.getCalibData(chId, msgStream());
839  if (dataObj->tubeCalib) {
840  ATH_MSG_DEBUG("Rt relation constants for "<<m_idHelperSvc->toString(chId)<<" already exists");
841  continue;
842  }
843  }
844 
845  TubeContainerPtr tubes = std::make_unique<MdtTubeCalibContainer>(m_idHelperSvc.get(), chId);
846  if (!writeCdo.storeData(chId, tubes, msgStream())) {
847  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" Failed to add chamber "<<m_idHelperSvc->toString(chId)
848  <<" ID fields: "<<stName<<","<<ieta<<","<<iphi);
849  return StatusCode::FAILURE;
850  }
851  //const ref. No copy
852  const nlohmann::json& tubeConstants = chambChannel["calibConstants"];
853  for (const auto& tubeChannel : tubeConstants) {
854  const int ml = tubeChannel["ml"];
855  const int l = tubeChannel["layer"];
856  const int t = tubeChannel["tube"];
857  double tzero = tubeChannel["t0"];
858  if (m_t0Shift != 0.) {
859  tzero += m_t0Shift;
860  ATH_MSG_VERBOSE("T0 shift " << m_t0Shift << " t0 " << tzero << " id " << ml << " " << l << " " << t);
861  }
862  if (m_t0Spread != 0.) {
863  CLHEP::HepRandomEngine *engine = m_RNGWrapper->getEngine(ctx);
864  double sh = CLHEP::RandGaussZiggurat::shoot(engine, 0., m_t0Spread);
865  tzero += sh;
866  ATH_MSG_VERBOSE("T0 spread " << sh << " t0 " << tzero << " id " << ml << " " << l << " " << t);
867  }
868  if (!t0_ts_applied && m_TimeSlewingCorrection) { tzero += m_TsCorrectionT0; }
869  if (t0_ts_applied && !m_TimeSlewingCorrection) { tzero -= m_TsCorrectionT0; }
870 
871  const int statusCode = tubeChannel["status"];
872  const double meanAdc = tubeChannel["meanAdc"];
874  datatube.statusCode = statusCode;
875  datatube.inversePropSpeed = inversePropSpeed;
876  datatube.t0 = tzero;
877  datatube.adcCal = meanAdc;
878  const Identifier tubeId = idHelper.channelID(chId, ml, l, t);
879  tubes->setCalib(std::move(datatube), tubeId, msgStream());
880  }
881  } // end loop over readCdoTube
882 
883  ATH_CHECK(defaultT0s(writeCdo));
884  // finally record writeCdo
885  return StatusCode::SUCCESS;
886 }
887 
888 std::unique_ptr<MuonCalib::RtResolutionLookUp> MdtCalibDbAlg::getRtResolutionInterpolation(const std::vector<MuonCalib::SamplePoint> &sample_points) {
890  // VARIABLES //
892  std::vector<Double_t> x(sample_points.size(),0);
893  std::vector<Double_t> y(sample_points.size(),0);
894 
895  for (unsigned int i = 0; i < sample_points.size(); i++) {
896  x[i] = sample_points[i].x1();
897  y[i] = sample_points[i].x2();
898  }
899  TSpline3 sp("Rt Res Tmp", x.data(), y.data(), sample_points.size());
901  // CREATE AN RtRelationLookUp OBJECT WITH THE CORRECT PARAMETERS //
903  unsigned int nb_points(100);
904  std::vector<double> res_param(nb_points + 2); // r-t parameters
905  Double_t bin_width = (x[sample_points.size() - 1] - x[0]) / static_cast<Double_t>(nb_points);
906 
907  res_param[0] = x[0];
908  res_param[1] = bin_width;
909  for (unsigned int k = 0; k < nb_points; k++) {
910  Double_t xx = x[0] + k * bin_width;
911  res_param[k + 2] = sp.Eval(xx);
912  if (std::isnan(res_param[k + 2])) {
913  TFile outf("kacke.root", "RECREATE");
914  sp.Write("kacke");
915  throw std::runtime_error("MdtCalibDbAlg::getRtResolutionInterpolation "
916  "encountered nan element");
917  }
918  }
919  return std::make_unique<MuonCalib::RtResolutionLookUp>(std::move(res_param));
920 }
921 
923  ATH_MSG_VERBOSE("initializeSagCorrection...");
924  std::vector<double> corr_params(0);
925  funcSet.wireSag(std::make_unique<MuonCalib::WireSagCorFunc>(corr_params));
926 }
MdtCalibDbAlg::m_create_b_field_function
Gaudi::Property< bool > m_create_b_field_function
Definition: MdtCalibDbAlg.h:80
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MuonCalib::MdtCalibrationFactory::createRtResolution
static IRtResolution * createRtResolution(const std::string &name, const ParVec &pars)
Definition: MdtCalibrationFactory.cxx:81
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib::t0
float t0
< relative t0 in chamber (ns)
Definition: MdtTubeCalibContainer.h:20
PathResolver::find_calib_file
static std::string find_calib_file(const std::string &logical_file_name)
Definition: PathResolver.cxx:384
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
MdtReadoutElement.h
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
GeoModel::TransientConstSharedPtr< MdtCorFuncSet >
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CxxUtils::tokenizeDouble
std::vector< double > tokenizeDouble(const std::string &the_str, std::string_view delimiter)
Definition: Control/CxxUtils/Root/StringUtils.cxx:34
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
header
Definition: hcg.cxx:526
max
#define max(a, b)
Definition: cfImp.cxx:41
MdtCalibDbAlg::m_rtScale
Gaudi::Property< double > m_rtScale
Definition: MdtCalibDbAlg.h:110
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
MdtCalibDbAlg::m_useNewGeo
Gaudi::Property< bool > m_useNewGeo
Definition: MdtCalibDbAlg.h:69
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PlotCalibFromCool.yy
yy
Definition: PlotCalibFromCool.py:714
MuonCalib::MdtCorFuncSet::wireSag
const IMdtWireSagCorFunc * wireSag() const
Definition: MdtCorFuncSet.h:34
MdtCalibDbAlg::m_rtShift
Gaudi::Property< double > m_rtShift
Definition: MdtCalibDbAlg.h:109
MuonGM::MdtReadoutElement::innerTubeRadius
double innerTubeRadius() const
Returns the inner tube radius excluding the aluminium walls.
json
nlohmann::json json
Definition: HistogramDef.cxx:9
MuonCalib::MdtCalibDataContainer::RegionGranularity
RegionGranularity
Definition: MdtCalibDataContainer.h:26
MuonCalib::MdtCorFuncSet::setBField
void setBField(std::unique_ptr< IMdtBFieldCorFunc > &&bField)
Definition: MdtCorFuncSet.cxx:24
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
MdtCalibDbAlg::m_defaultT0
Gaudi::Property< double > m_defaultT0
Definition: MdtCalibDbAlg.h:105
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
CxxUtils::tokenizeInt
std::vector< int > tokenizeInt(const std::string &the_str, std::string_view delimiter)
Definition: Control/CxxUtils/Root/StringUtils.cxx:55
MuonCalib::MdtCalibDataContainer::storeData
bool storeData(const Identifier &mlID, CorrectionPtr corrFuncSet, MsgStream &msg)
Definition: MdtCalibDataContainer.cxx:49
MuonCalib::MdtFullCalibData::CorrectionPtr
GeoModel::TransientConstSharedPtr< MdtCorFuncSet > CorrectionPtr
Definition: MdtFullCalibData.h:16
CxxUtils::tokenize
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition: Control/CxxUtils/Root/StringUtils.cxx:15
CheckAppliedSFs.bin_width
bin_width
Definition: CheckAppliedSFs.py:242
MuonCalib::SamplePoint::set_x2
void set_x2(const double &mx2)
set the x2 coordinate of the sample point to mx2
MdtCalibDbAlg::m_createSlewingFunction
Gaudi::Property< bool > m_createSlewingFunction
Definition: MdtCalibDbAlg.h:85
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:983
MuonCalib::RtDataFromFile
Manages the I/O of the Rt realtions from/to file.
Definition: RtDataFromFile.h:21
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
MdtCalibDbAlg::m_detMgr
const MuonGM::MuonDetectorManager * m_detMgr
Definition: MdtCalibDbAlg.h:66
MuonCalib::MdtFullCalibData::rtRelation
RtRelationPtr rtRelation
Definition: MdtFullCalibData.h:21
skel.it
it
Definition: skel.GENtoEVGEN.py:423
StringUtils.h
ToString.h
MdtCalibDbAlg::m_randomStream
StringProperty m_randomStream
Definition: MdtCalibDbAlg.h:114
MdtCalibDbAlg::loadTube
StatusCode loadTube(const EventContext &ctx, MuonCalib::MdtCalibDataContainer &writeCdo) const
Definition: MdtCalibDbAlg.cxx:774
MuonCalib::MdtTubeCalibContainer::numMultilayers
unsigned int numMultilayers() const
Definition: MdtTubeCalibContainer.h:49
yodamerge_tmp.npoints
npoints
Definition: yodamerge_tmp.py:250
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
MdtCondDbData
Definition: MdtCondDbData.h:21
athena.value
value
Definition: athena.py:122
MdtCalibDbAlg::m_AthRNGSvc
ServiceHandle< IAthRNGSvc > m_AthRNGSvc
Definition: MdtCalibDbAlg.h:113
IdToFixedIdTool.h
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
MdtCalibDbAlg::getRtResolutionInterpolation
static std::unique_ptr< MuonCalib::RtResolutionLookUp > getRtResolutionInterpolation(const std::vector< MuonCalib::SamplePoint > &sample_points)
Definition: MdtCalibDbAlg.cxx:888
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
MdtCalibDbAlg::legacyTubePayloadToJSON
StatusCode legacyTubePayloadToJSON(const coral::AttributeList &attr, nlohmann::json &json) const
Definition: MdtCalibDbAlg.cxx:658
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
dumpTruth.statusCode
statusCode
Definition: dumpTruth.py:89
IIOVDbSvc.h
Abstract interface to IOVDbSvc to access IOVRange and tag information.
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
MdtCalibDbAlg::m_TsCorrectionT0
Gaudi::Property< double > m_TsCorrectionT0
Definition: MdtCalibDbAlg.h:103
BFieldCorFunc.h
MuonCalib::MdtTubeCalibContainer::setCalib
bool setCalib(SingleTubeCalib &&val, const Identifier &tubeId, MsgStream &msg)
set the calibration constants of a single tube
Definition: MdtTubeCalibContainer.cxx:19
x
#define x
AthenaAttributeList.h
MdtCalibDbAlg::loadRt
StatusCode loadRt(const EventContext &ctx, MuonCalib::MdtCalibDataContainer &writeCdo) const
Definition: MdtCalibDbAlg.cxx:394
MuonCalib::MdtFullCalibData
class which holds the full set of calibration constants for a given tube
Definition: MdtFullCalibData.h:15
MdtCalibDbAlg::m_TimeSlewingCorrection
Gaudi::Property< bool > m_TimeSlewingCorrection
Definition: MdtCalibDbAlg.h:98
MdtCalibDbAlg::getInnerTubeRadius
std::optional< double > getInnerTubeRadius(const Identifier &id) const
Definition: MdtCalibDbAlg.cxx:282
WireSagCorFunc.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
MuonCalib::RtData_t_r_reso::times
const DataVec & times() const
Definition: RtData_t_r_reso.h:28
MuonCalib::CalibFunc::par
double par(unsigned int index) const
Definition: CalibFunc.h:41
MdtCalibDbAlg::initializeSagCorrection
void initializeSagCorrection(MuonCalib::MdtCorFuncSet &funcSet) const
Definition: MdtCalibDbAlg.cxx:922
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MdtCalibDbAlg::m_writeKey
SG::WriteCondHandleKey< MuonCalib::MdtCalibDataContainer > m_writeKey
Definition: MdtCalibDbAlg.h:124
MuonCalib::MdtTubeCalibContainer::numLayers
unsigned int numLayers() const
Definition: MdtTubeCalibContainer.h:50
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib::statusCode
unsigned int statusCode
Definition: MdtTubeCalibContainer.h:26
MdtSlewCorFuncHardcoded.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
MdtCalibDbAlg::m_prop_beta
Gaudi::Property< double > m_prop_beta
Definition: MdtCalibDbAlg.h:111
MuonCalib::RtFromPoints::getRtRelationLookUp
static RtRelationLookUp getRtRelationLookUp(const std::vector< SamplePoint > &sample_points)
Definition: RtFromPoints.cxx:78
MuonCalib::CalibFunc::ParVec
std::vector< double > ParVec
Definition: CalibFunc.h:36
MuonCalib::MdtFullCalibData::tubeCalib
TubeContainerPtr tubeCalib
Definition: MdtFullCalibData.h:22
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
MuonCalib::MdtCalibDataContainer::granularity
RegionGranularity granularity() const
Definition: MdtCalibDataContainer.cxx:13
MdtCalibDbAlg::m_RTfileName
StringProperty m_RTfileName
Definition: MdtCalibDbAlg.h:117
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MdtCalibDbAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MdtCalibDbAlg.h:63
MuonGM::MuonDetectorManager::getMdtReadoutElement
const MdtReadoutElement * getMdtReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:204
FullCPAlgorithmsTest_eljob.sh
sh
Definition: FullCPAlgorithmsTest_eljob.py:98
MuonCalib::MdtCorFuncSet
Class which holds all correction functions for a given region.
Definition: MdtCorFuncSet.h:18
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:50
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
lumiFormat.i
int i
Definition: lumiFormat.py:92
MdtCalibDbAlg::m_UseMLRt
Gaudi::Property< bool > m_UseMLRt
Definition: MdtCalibDbAlg.h:99
CoralUtilities::readBlobAsString
bool readBlobAsString(const coral::Blob &, std::string &)
Definition: blobaccess.cxx:85
beamspotman.n
n
Definition: beamspotman.py:731
MdtCalibDbAlg::initialize
virtual StatusCode initialize() override
Definition: MdtCalibDbAlg.cxx:54
RtFromPoints.h
RCU::Shell
Definition: ShellExec.cxx:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
MuonCalib::SamplePoint::x1
double x1(void) const
get the x1 coordinate of the sample point
CxxUtils
Definition: aligned_vector.h:29
MuonCond::DcsConstants
Helper struct to cache all dcs constants in a common place of the memory.
Definition: MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/Defs.h:31
MdtIdHelper
Definition: MdtIdHelper.h:61
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:127
MuonCalib::RtData_t_r_reso::radii
const DataVec & radii() const
Definition: RtData_t_r_reso.h:29
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MdtCalibDbAlg::m_readKeyDCS
SG::ReadCondHandleKey< MdtCondDbData > m_readKeyDCS
Definition: MdtCalibDbAlg.h:127
MdtCalibDbAlg::legacyRtPayloadToJSON
StatusCode legacyRtPayloadToJSON(const coral::AttributeList &attr, nlohmann::json &json) const
Parses the legacy payload for the RT functions to a json format.
Definition: MdtCalibDbAlg.cxx:301
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonCalib::MdtTubeCalibContainer::numTubes
unsigned int numTubes() const
Definition: MdtTubeCalibContainer.h:51
IRtResolution.h
MdtCalibDbAlg::m_newFormat2020
Gaudi::Property< bool > m_newFormat2020
Definition: MdtCalibDbAlg.h:76
MuonCalib::SamplePoint::set_error
void set_error(const double &merror)
set the error of the x2 coordinate sample point to merror
MdtCalibDbAlg.h
MdtCalibDbAlg::m_createWireSagFunction
Gaudi::Property< bool > m_createWireSagFunction
Definition: MdtCalibDbAlg.h:83
MdtCalibDbAlg::m_t0Spread
Gaudi::Property< double > m_t0Spread
Definition: MdtCalibDbAlg.h:107
MuonGMR4::MdtReadoutElement::innerTubeRadius
double innerTubeRadius() const
Returns the inner tube radius.
MuonCalib::IRtRelation::SetTmaxDiff
void SetTmaxDiff(const float &d)
set the difference in total drift time betwene the two multilayers (ML1 - ML2)
Definition: IRtRelation.h:32
MuonCalib::MdtCalibrationFactory::createRtRelation
static IRtRelation * createRtRelation(const std::string &name, const ParVec &pars)
Definition: MdtCalibrationFactory.cxx:71
lumiFormat.array
array
Definition: lumiFormat.py:98
MdtCalibDbAlg::m_r4detMgr
const MuonGMR4::MuonDetectorManager * m_r4detMgr
Definition: MdtCalibDbAlg.h:67
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib::adcCal
float adcCal
quality flag for the SingleTubeCalib constants: 0 all ok, 1 no hits found, 2 too few hits,...
Definition: MdtTubeCalibContainer.h:24
MuonCalib::TIME_SLEWING_CORRECTION_APPLIED
@ TIME_SLEWING_CORRECTION_APPLIED
Definition: MdtCalibCreationFlags.h:10
IOVInfiniteRange.h
MdtCalibDbAlg::m_readKeyRt
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyRt
Definition: MdtCalibDbAlg.h:122
PathResolver.h
MuonGMR4::MdtReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:15
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuonCalib::SamplePoint::set_x1
void set_x1(const double &mx1)
set the x1 coordinate of the sample point to mx1
RtResolutionFromPoints.h
MuonCalib::SamplePoint
Definition: SamplePoint.h:17
MuonCalib::MuonFixedId
Definition: MuonFixedId.h:50
MdtCalibDbAlg::declareDependency
StatusCode declareDependency(const EventContext &ctx, SG::WriteCondHandle< MuonCalib::MdtCalibDataContainer > &writeHandle) const
Definition: MdtCalibDbAlg.cxx:98
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib::inversePropSpeed
float inversePropSpeed
multiplicative correction factor for ADC measurement w.r.t.
Definition: MdtTubeCalibContainer.h:22
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
HI::TowerBins::numLayers
constexpr unsigned int numLayers()
Definition: HIEventDefs.h:23
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
MuonCalib::MdtCalibDataContainer::getCalibData
const MdtFullCalibData * getCalibData(const Identifier &measId, MsgStream &msg) const
Returns the calibration data associated with this station
Definition: MdtCalibDataContainer.cxx:38
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
MuonCalib::RtData_t_r_reso::resolution
const DataVec & resolution() const
Definition: RtData_t_r_reso.h:30
SG::ReadCondHandleKey< CondAttrListCollection >
MdtCalibDbAlg::m_readKeyTube
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyTube
Definition: MdtCalibDbAlg.h:123
MdtCalibDbAlg::MdtCalibDbAlg
MdtCalibDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdtCalibDbAlg.cxx:51
y
#define y
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
MuonCalib::SamplePoint::x2
double x2(void) const
get the x2 coordinate of the sample point
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
MdtCalibDbAlg::m_MeanCorrectionVsR
Gaudi::Property< std::vector< float > > m_MeanCorrectionVsR
Definition: MdtCalibDbAlg.h:101
MdtReadoutElement.h
MdtCalibDbAlg::m_checkTubes
Gaudi::Property< bool > m_checkTubes
only needed to retrieve information on number of tubes etc. (no alignment needed)
Definition: MdtCalibDbAlg.h:74
MdtCalibDbAlg::defaultT0s
StatusCode defaultT0s(MuonCalib::MdtCalibDataContainer &writeCdoTube) const
Definition: MdtCalibDbAlg.cxx:609
MuonCalib::MdtCalibDataContainer
Definition: MdtCalibDataContainer.h:20
IRtRelation.h
TransientAddress.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MdtFullCalibData.h
MdtCalibDbAlg::m_RNGWrapper
ATHRNG::RNGWrapper * m_RNGWrapper
Definition: MdtCalibDbAlg.h:115
MuonCalib::MdtFullCalibData::TubeContainerPtr
GeoModel::TransientConstSharedPtr< MdtTubeCalibContainer > TubeContainerPtr
Definition: MdtFullCalibData.h:18
calibdata.rts
rts
Definition: calibdata.py:414
MdtCalibDbAlg::m_t0Shift
Gaudi::Property< double > m_t0Shift
Definition: MdtCalibDbAlg.h:106
MdtCalibDbAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MdtCalibDbAlg.cxx:122
MuonCalib::CalibFunc::nPar
unsigned int nPar() const
Definition: CalibFunc.h:39
MuonIdHelper::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: MuonIdHelper.h:143
MdtCalibCreationFlags.h
MdtCalibDbAlg::defaultRt
StatusCode defaultRt(MuonCalib::MdtCalibDataContainer &writeCdoRt, LoadedRtMap &loadedRts) const
Definition: MdtCalibDbAlg.cxx:149
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
MuonCalib::MdtCalibDataContainer::hasDataForChannel
bool hasDataForChannel(const Identifier &measId, MsgStream &msg) const
Checks whether a calibration data object is already present.
Definition: MdtCalibDataContainer.cxx:33
MuonCalib::MdtCorFuncSet::setSlewing
void setSlewing(std::unique_ptr< IMdtSlewCorFunc > &&slew)
Definition: MdtCorFuncSet.cxx:21
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib
Definition: MdtTubeCalibContainer.h:18
SamplePoint.h
MdtCalibrationFactory.h
IOVInfiniteRange::infiniteTime
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Definition: IOVInfiniteRange.h:47
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
MdtCalibDbAlg::m_idToFixedIdTool
ToolHandle< MuonCalib::IIdToFixedIdTool > m_idToFixedIdTool
Definition: MdtCalibDbAlg.h:64
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
MuonCalib::RtData_t_r_reso::DataVec
std::vector< double > DataVec
Definition: RtData_t_r_reso.h:18
MuonFixedId.h
calibdata.tube
tube
Definition: calibdata.py:31
MdtCalibDbAlg::LoadedRtMap
std::map< Identifier, RtRelationPtr > LoadedRtMap
Definition: MdtCalibDbAlg.h:50
plot_times.times
def times(fn)
Definition: plot_times.py:11
CalibFunc.h
fitman.k
k
Definition: fitman.py:528
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:275
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
RtDataFromFile.h