ATLAS Offline Software
MdtCalibInputSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <dirent.h>
8 #include <sys/types.h>
9 
18 #include "fstream"
19 #include "iostream"
20 #include "list"
21 
22 MdtCalibInputSvc::MdtCalibInputSvc(const std::string &name, ISvcLocator *svc_locator) :
23  AthService(name, svc_locator), m_reg_sel_svc("RegionSelectionSvc", name) {
24  declareProperty("RegionSelectionSvc", m_reg_sel_svc);
25 }
26 
29  for (it1 = m_t0.begin(); it1 != m_t0.end(); ++it1) delete it1->second;
31  for (it2 = m_rt_relation.begin(); it2 != m_rt_relation.end(); ++it2) delete it2->second;
33  for (it3 = m_B_corr.begin(); it3 != m_B_corr.end(); ++it3) delete it3->second;
35  for (it4 = m_spat_res.begin(); it4 != m_spat_res.end(); ++it4) delete it4->second;
36 }
37 
39  ATH_MSG_INFO("initialize()");
40  // get region selection service
41  ATH_CHECK(m_reg_sel_svc.retrieve());
42  ATH_CHECK(m_calib_input_tool.retrieve());
44  return StatusCode::SUCCESS;
45 }
46 
48  static std::mutex warn_mutex;
49  std::map<MuonCalib::NtupleStationId, MuonCalib::MdtStationT0Container *>::const_iterator it;
50  if ((it = m_t0.find(id)) == m_t0.end()) {
52  chamber_id.SetMultilayer(0);
53  if ((it = m_t0.find(chamber_id)) == m_t0.end()) {
54  std::lock_guard<std::mutex> guard(warn_mutex);
55  if (m_t0_warned.find(chamber_id) == m_t0_warned.end()) {
56  ATH_MSG_WARNING("T0 not loaded for station " << id.regionId());
57  m_t0_warned.insert(chamber_id);
58  }
59  return nullptr;
60  }
61  }
62  return it->second;
63 }
64 
66  static std::mutex warn_mutex;
67  std::map<MuonCalib::NtupleStationId, MuonCalib::IRtRelation *>::const_iterator it;
68  if ((it = m_rt_relation.find(id)) == m_rt_relation.end()) {
70  chamber_id.SetMultilayer(0);
71  if ((it = m_rt_relation.find(chamber_id)) == m_rt_relation.end()) {
72  std::lock_guard<std::mutex> guard(warn_mutex);
73  if (m_rt_warned.find(chamber_id) == m_rt_warned.end()) {
74  ATH_MSG_WARNING("Rt relation not loaded for station" << chamber_id.regionId());
75  m_rt_warned.insert(chamber_id);
76  }
77  return nullptr;
78  }
79  }
80  return it->second;
81 }
82 
85  if ((fun = findbfieldfun(id)) != nullptr) return fun;
87  chamber_id.SetMultilayer(0);
88  return findbfieldfun(chamber_id);
89 }
90 
92  std::map<MuonCalib::NtupleStationId, MuonCalib::IRtResolution *>::const_iterator it;
93  if ((it = m_spat_res.find(id)) == m_spat_res.end()) {
95  chamber_id.SetMultilayer(0);
96  if ((it = m_spat_res.find(chamber_id)) == m_spat_res.end()) {
97  if (m_rt_warned.find(chamber_id) == m_rt_warned.end()) {
98  ATH_MSG_FATAL("Rt relation not loaded for station");
99  m_rt_warned.insert(chamber_id);
100  }
101  return nullptr;
102  }
103  }
104  return it->second;
105 }
106 
108  ATH_CHECK(m_calib_input_tool->LoadT0(m_t0, -1));
110  create_mean_rts();
111  return StatusCode::SUCCESS;
112 }
113 
115  std::map<MuonCalib::NtupleStationId, MuonCalib::IRtRelation *>::const_iterator it(m_rt_relation.find(id));
116  if (it == m_rt_relation.end()) return false;
117  ATH_MSG_INFO("Initiailizing B-Field correction for " << id.regionId());
118  const MuonCalib::IRtRelation *rt_rel(it->second);
119  // create magnetic field correction
120  std::vector<double> corr_params(2);
121  corr_params[0] = 3080.0; // high voltage
122  corr_params[1] = 0.11; // epsilon parameter
123  m_B_corr[id] = new MuonCalib::BFieldCorFunc(corr_params, rt_rel);
124  return true;
125 }
126 
128  ATH_MSG_INFO("MdtCalibInputSvc::create_mean_rts()");
129  std::list<const MuonCalib::IRtRelation *> matching_relations;
130  std::list<MuonCalib::NtupleStationId> matching_ids;
131  // loop over all rts
132  for (std::map<MuonCalib::NtupleStationId, MuonCalib::IRtRelation *>::const_iterator it = m_rt_relation.begin();
133  it != m_rt_relation.end(); ++it) {
135  // if the rt relation is stored per chamber, check both multilayers
136  if (it->first.GetMl() == 0) {
137  id.set_mdt();
138  for (int i = 1; i <= 2; i++) {
139  id.setStationName(it->first.GetStation());
140  id.setStationEta(it->first.GetEta());
141  id.setStationPhi(it->first.GetPhi());
142  id.setMdtMultilayer(i);
143  if (m_reg_sel_svc->isInRegion(id)) {
144  matching_relations.push_back(it->second);
145  matching_ids.push_back(it->first);
146  break;
147  }
148  }
149  } else {
150  id.setStationName(it->first.GetStation());
151  id.setStationEta(it->first.GetEta());
152  id.setStationPhi(it->first.GetPhi());
153  id.setMdtMultilayer(it->first.GetMl());
154  if (m_reg_sel_svc->isInRegion(id)) {
155  matching_relations.push_back(it->second);
156  matching_ids.push_back(it->first);
157  }
158  }
159  }
160 
161  ATH_MSG_INFO("Found " << matching_relations.size() << " rt-relations for calibration region");
162  if (matching_relations.empty()) return;
163  // averageing over rt relations is not yet implemented - take the first found
164  if (matching_relations.size() > 1) { ATH_MSG_WARNING("More than one rt relation for this region loaded! Taking first!"); }
165  m_sel_region_rt = *(matching_relations.begin());
166  m_mean_station_id = *(matching_ids.begin());
167  m_sel_region_res = GetResolution(*(matching_ids.begin()));
168 } // end MdtCalibInputSvc::create_mean_rts
169 
171  std::map<MuonCalib::NtupleStationId, MuonCalib::BFieldCorFunc *>::const_iterator it(m_B_corr.find(id));
172  if (it == m_B_corr.end()) {
173  if (!create_b_field_correction(id)) return nullptr;
174  return findbfieldfun(id);
175  }
176  return it->second;
177 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
MdtCalibInputSvc::read_calib_input
StatusCode read_calib_input()
Definition: MdtCalibInputSvc.cxx:107
generateReferenceFile.fun
fun
Definition: generateReferenceFile.py:18
MdtCalibInputSvc::create_mean_rts
void create_mean_rts()
create mean rt relations, and resolutions for the selected calibration region
Definition: MdtCalibInputSvc.cxx:127
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
MuonCalib::NtupleStationId
Definition: NtupleStationId.h:36
MuonCalib::MdtStationT0Container
Definition: MdtStationT0Container.h:24
MdtCalibInputSvc::MdtCalibInputSvc
MdtCalibInputSvc(const std::string &name, ISvcLocator *svc_locator)
Service constructor.
Definition: MdtCalibInputSvc.cxx:22
skel.it
it
Definition: skel.GENtoEVGEN.py:396
MdtStationT0Container.h
MdtCalibInputSvc::m_mean_station_id
MuonCalib::NtupleStationId m_mean_station_id
station id for mean rt
Definition: MdtCalibInputSvc.h:84
MdtCalibInputSvc::m_B_corr
std::map< MuonCalib::NtupleStationId, MuonCalib::BFieldCorFunc * > m_B_corr
Definition: MdtCalibInputSvc.h:69
MdtCalibInputSvc::m_sel_region_rt
const MuonCalib::IRtRelation * m_sel_region_rt
rt relation - resolution - and correction function for the selected region - is average of all matchi...
Definition: MdtCalibInputSvc.h:80
MuonCalib::BFieldCorFunc
Definition: BFieldCorFunc.h:47
MdtCalibInputSvc::m_sel_region_res
const MuonCalib::IRtResolution * m_sel_region_res
Definition: MdtCalibInputSvc.h:82
MdtCalibInputSvc::m_reg_sel_svc
ServiceHandle< RegionSelectionSvc > m_reg_sel_svc
pointer to region selection service
Definition: MdtCalibInputSvc.h:72
NtupleStationId.h
MdtCalibInputSvc.h
MdtCalibInputSvc::GetResolution
const MuonCalib::IRtResolution * GetResolution() const
Get resolution for calibration region.
Definition: MdtCalibInputSvc.h:61
MdtCalibInputSvc::GetBCorr
const MuonCalib::BFieldCorFunc * GetBCorr()
Get b-field correction for calibratino region.
Definition: MdtCalibInputSvc.h:56
MdtCalibInputSvc::findbfieldfun
const MuonCalib::BFieldCorFunc * findbfieldfun(const MuonCalib::NtupleStationId &id)
Definition: MdtCalibInputSvc.cxx:170
MdtCalibInputSvc::GetRtRelation
const MuonCalib::IRtRelation * GetRtRelation() const
Get rt-Relation for calibration region.
Definition: MdtCalibInputSvc.h:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
DetDescrDictionaryDict::it1
std::vector< HWIdentifier >::iterator it1
Definition: DetDescrDictionaryDict.h:17
RtFromPoints.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthService
Definition: AthService.h:32
MdtCalibInputSvc::~MdtCalibInputSvc
virtual ~MdtCalibInputSvc()
destructor
Definition: MdtCalibInputSvc.cxx:27
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
calibdata.chamber_id
chamber_id
Definition: calibdata.py:536
IRtResolution.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MdtCalibInputSvc::GetT0
const MuonCalib::MdtStationT0Container * GetT0(const MuonCalib::NtupleStationId &id) const
Get t0 container for Station.
Definition: MdtCalibInputSvc.cxx:47
RtResolutionFromPoints.h
MuonCalib::MuonFixedId
Definition: MuonFixedId.h:50
MdtCalibInputSvc::m_t0
std::map< MuonCalib::NtupleStationId, MuonCalib::MdtStationT0Container * > m_t0
calibration data sorted by station id
Definition: MdtCalibInputSvc.h:67
MuonCalib::IRtResolution
generic interface for a resolution function
Definition: IRtResolution.h:13
MdtCalibInputSvc::create_b_field_correction
bool create_b_field_correction(const MuonCalib::NtupleStationId &id)
create the b-field correction
Definition: MdtCalibInputSvc.cxx:114
MdtCalibInputSvc::m_calib_input_tool
ToolHandle< MuonCalib::ICalibrationIOTool > m_calib_input_tool
calibration io tool to be used
Definition: MdtCalibInputSvc.h:65
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IRtRelation.h
MdtCalibInputSvc::m_rt_relation
std::map< MuonCalib::NtupleStationId, MuonCalib::IRtRelation * > m_rt_relation
Definition: MdtCalibInputSvc.h:68
SamplePoint.h
MdtCalibInputSvc::initialize
virtual StatusCode initialize() override
service initalizer - reads files
Definition: MdtCalibInputSvc.cxx:38
MuonFixedId.h
MdtCalibInputSvc::m_spat_res
std::map< MuonCalib::NtupleStationId, MuonCalib::IRtResolution * > m_spat_res
Definition: MdtCalibInputSvc.h:70
MuonCalib::IRtRelation
generic interface for a rt-relation
Definition: IRtRelation.h:15