ATLAS Offline Software
MuonCalibDefaultCalibrationSource.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // this
7 
9 
10 // MuonCalibStandAloneBase
12 
13 // MuonCalibMath
15 
16 // MuonCalibIdentifier//MuonCalibIdentifier
18 
19 // c-c++
20 #include <fstream>
21 #include <sstream>
22 
23 namespace MuonCalib {
25  MuonCalibDefaultCalibrationSource::MuonCalibDefaultCalibrationSource(const std::string &t, const std::string &n, const IInterface *p) :
26  AthAlgTool(t, n, p) {
27  declareInterface<IMuonCalibConditionsSource>(this);
28  declareProperty("T0Regions", m_t0_region_str);
29  declareProperty("T0", m_t0);
30  declareProperty("TimeSlewingAppliedT0", m_time_slewing_applied_t0);
31  declareProperty("BFieldCorrectionAppliedT0", m_bfield_applied_t0);
32  declareProperty("RtRegions", m_rt_region_str);
33  declareProperty("RtFiles", m_rt_files);
34  declareProperty("TimeSlewingAppliedRt", m_time_slewing_applied_rt);
35  declareProperty("BFieldCorrectionAppliedRt", m_bfield_applied_rt);
36  }
37 
39  // get region selection service
40  ATH_CHECK(m_reg_sel_svc.retrieve());
41  // check matching lengths
42  if (m_t0_region_str.size() != m_t0.size()) {
43  ATH_MSG_FATAL("Configuration error: T0Regions and T0 have different size!");
44  return StatusCode::FAILURE;
45  }
46  if (m_rt_region_str.size() != m_rt_files.size()) {
47  ATH_MSG_FATAL("Configuration error: RtRegions and RtFiles have different size!");
48  return StatusCode::FAILURE;
49  }
50  // initialize regions
55  // load rt files
57  return StatusCode::SUCCESS;
58  }
59 
60  bool MuonCalibDefaultCalibrationSource::insert_calibration(bool store_t0, bool store_rt) {
61  if (store_t0 && !store_t0_fun()) { return false; }
62  if (store_rt && !store_rt_fun()) { return false; }
63  return true;
64  }
65 
66  StatusCode MuonCalibDefaultCalibrationSource::initialize_regions(const std::vector<std::string> &reg_str,
67  std::vector<std::unique_ptr<RegionSelectorBase> > &reg_vec) {
68  for (const std::string &reg : reg_str) {
69  std::unique_ptr<RegionSelectorBase> r = RegionSelectorBase::GetRegion(reg);
70  if (!r) {
71  ATH_MSG_FATAL("Error in region " << reg);
72  return StatusCode::FAILURE;
73  }
74  reg_vec.emplace_back(std::move(r));
75  }
76  return StatusCode::SUCCESS;
77  }
78 
79  void MuonCalibDefaultCalibrationSource::initialize_creation_flags(const std::vector<bool> &ts_applied,
80  const std::vector<bool> &bf_applied, unsigned int n_regions,
81  std::vector<unsigned int> &flags) {
82  for (unsigned int i = 0; i < n_regions; i++) {
83  unsigned int flag(0);
84  if (i < ts_applied.size() && ts_applied[i]) { flag |= MuonCalib::TIME_SLEWING_CORRECTION_APPLIED; }
85  if (i < bf_applied.size() && bf_applied[i]) { flag |= MuonCalib::B_FIELD_CORRECTIONS_APPLIED; }
86  flags.push_back(flag);
87  }
88  }
89 
91  for (const auto & fname : m_rt_files) {
92  std::string line;
93  std::ifstream rtf(fname.c_str());
94  if (!rtf.good()) {
95  ATH_MSG_FATAL("Cannot open rt file '" << fname << "'!");
96  return StatusCode::FAILURE;
97  }
98  std::map<int, SamplePoint> pts;
99  // read dummy line
100  std::getline(rtf, line);
101  int i(0);
102  while (!rtf.eof()) {
103  std::getline(rtf, line);
104  std::istringstream ln_str(line);
105  double r, t, s;
106  ln_str >> r;
107  ln_str >> t;
108  ln_str >> s;
109  if (rtf.eof()) break;
110  SamplePoint pt(t, r, s);
111  pts[i] = pt;
112  i++;
113  }
114  m_rt_points.push_back(pts);
115  }
116  return StatusCode::SUCCESS;
117  }
118 
120  const std::vector<NtupleStationId> &regions(m_reg_sel_svc->GetStationsInRegions());
121  for (const auto & region : regions) {
122  MuonFixedId fid(region.FixedId());
123  for (unsigned int i = 0; i < m_t0_regions.size(); i++) {
124  if (m_t0_regions[i]->Result(fid)) {
125  m_inserter->StartT0Chamber(region);
126  while (m_inserter->AppendT0(m_t0[i], 5, 0.0)) {}
127  m_inserter->StoreT0Chamber(region, std::string("default"), m_creation_flags_t0[i]);
128  // break;
129  }
130  }
131  }
132  return true;
133  }
134 
136  const std::vector<NtupleStationId> &regions(m_reg_sel_svc->GetStationsInRegions());
137  for (const auto & region : regions) {
138  MuonFixedId fid(region.FixedId());
139  for (unsigned int i = 0; i < m_rt_regions.size(); i++) {
140  if (m_rt_regions[i]->Result(fid)) {
141  m_inserter->StoreRtChamber(region, m_rt_points[i], std::string("default"), m_creation_flags_rt[i]);
142  break;
143  }
144  }
145  }
146  return true;
147  }
148 
149 } // namespace MuonCalib
MuonCalib::MuonCalibDefaultCalibrationSource::m_creation_flags_t0
std::vector< unsigned int > m_creation_flags_t0
Definition: MuonCalibDefaultCalibrationSource.h:47
MuonCalib::MuonCalibDefaultCalibrationSource::m_time_slewing_applied_rt
std::vector< bool > m_time_slewing_applied_rt
Definition: MuonCalibDefaultCalibrationSource.h:43
beamspotman.r
def r
Definition: beamspotman.py:676
MuonCalib::MuonCalibDefaultCalibrationSource::~MuonCalibDefaultCalibrationSource
virtual ~MuonCalibDefaultCalibrationSource()
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
MuonCalib::MuonCalibDefaultCalibrationSource::initialize
StatusCode initialize()
initialize
Definition: MuonCalibDefaultCalibrationSource.cxx:38
EgEfficiencyCorr_testFixedInput.pts
list pts
Definition: EgEfficiencyCorr_testFixedInput.py:10
MuonCalib::RegionSelectorBase::GetRegion
static std::unique_ptr< RegionSelectorBase > GetRegion(const std::string &input)
create a region from a string
Definition: RegionSelectorBase.cxx:13
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
MuonCalib::IMuonCalibConditionsSource::m_inserter
CoolInserter * m_inserter
Definition: IMuonCalibConditionsSource.h:31
MuonCalib::MuonCalibDefaultCalibrationSource::load_rt_files
StatusCode load_rt_files()
Definition: MuonCalibDefaultCalibrationSource.cxx:90
test_pyathena.pt
pt
Definition: test_pyathena.py:11
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
MuonCalib::MuonCalibDefaultCalibrationSource::m_t0_regions
std::vector< std::unique_ptr< RegionSelectorBase > > m_t0_regions
Definition: MuonCalibDefaultCalibrationSource.h:50
MuonCalib::CoolInserter::StoreT0Chamber
bool StoreT0Chamber(const NtupleStationId &id, const std::string &file, unsigned int creation_flags=0)
Definition: CoolInserter.cxx:193
MuonCalib::MuonCalibDefaultCalibrationSource::m_creation_flags_rt
std::vector< unsigned int > m_creation_flags_rt
Definition: MuonCalibDefaultCalibrationSource.h:48
MuonCalib::MuonCalibDefaultCalibrationSource::m_rt_points
std::vector< std::map< int, SamplePoint > > m_rt_points
Definition: MuonCalibDefaultCalibrationSource.h:52
MuonCalib::CoolInserter::AppendT0
bool AppendT0(float t0, int validflag, float adc0)
Definition: CoolInserter.cxx:184
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
MuonCalib::MuonCalibDefaultCalibrationSource::m_bfield_applied_rt
std::vector< bool > m_bfield_applied_rt
Definition: MuonCalibDefaultCalibrationSource.h:44
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
MuonCalib::MuonCalibDefaultCalibrationSource::initialize_creation_flags
void initialize_creation_flags(const std::vector< bool > &ts_applied, const std::vector< bool > &bf_applied, unsigned int n_regions, std::vector< unsigned int > &flags)
Definition: MuonCalibDefaultCalibrationSource.cxx:79
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
master.flag
bool flag
Definition: master.py:29
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::MuonCalibDefaultCalibrationSource::m_time_slewing_applied_t0
std::vector< bool > m_time_slewing_applied_t0
Definition: MuonCalibDefaultCalibrationSource.h:38
MuonCalib::MuonCalibDefaultCalibrationSource::m_reg_sel_svc
ServiceHandle< RegionSelectionSvc > m_reg_sel_svc
Definition: MuonCalibDefaultCalibrationSource.h:54
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CoolInserter.h
MuonCalib::B_FIELD_CORRECTIONS_APPLIED
@ B_FIELD_CORRECTIONS_APPLIED
Definition: MdtCalibCreationFlags.h:10
MuonCalib::MuonCalibDefaultCalibrationSource::m_bfield_applied_t0
std::vector< bool > m_bfield_applied_t0
Definition: MuonCalibDefaultCalibrationSource.h:39
MuonCalib::MuonCalibDefaultCalibrationSource::m_rt_files
std::vector< std::string > m_rt_files
Definition: MuonCalibDefaultCalibrationSource.h:42
MuonCalib::TIME_SLEWING_CORRECTION_APPLIED
@ TIME_SLEWING_CORRECTION_APPLIED
Definition: MdtCalibCreationFlags.h:10
MuonCalib::SamplePoint
Definition: SamplePoint.h:16
MuonCalib::MuonCalibDefaultCalibrationSource::insert_calibration
bool insert_calibration(bool store_t0, bool store_rt)
insert calibration
Definition: MuonCalibDefaultCalibrationSource.cxx:60
MuonCalib::MuonFixedId
Definition: MuonFixedId.h:50
MuonCalib::MuonCalibDefaultCalibrationSource::m_rt_region_str
std::vector< std::string > m_rt_region_str
Definition: MuonCalibDefaultCalibrationSource.h:41
MuonCalib::MuonCalibDefaultCalibrationSource::initialize_regions
StatusCode initialize_regions(const std::vector< std::string > &reg_str, std::vector< std::unique_ptr< RegionSelectorBase > > &reg)
Definition: MuonCalibDefaultCalibrationSource.cxx:66
MuonCalib::MuonCalibDefaultCalibrationSource::m_t0_region_str
std::vector< std::string > m_t0_region_str
Definition: MuonCalibDefaultCalibrationSource.h:36
MuonCalib::MuonCalibDefaultCalibrationSource::m_t0
std::vector< float > m_t0
Definition: MuonCalibDefaultCalibrationSource.h:37
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
MuonCalib::MuonCalibDefaultCalibrationSource::store_rt_fun
bool store_rt_fun()
Definition: MuonCalibDefaultCalibrationSource.cxx:135
MuonCalib::MuonCalibDefaultCalibrationSource::MuonCalibDefaultCalibrationSource
MuonCalibDefaultCalibrationSource(const std::string &t, const std::string &n, const IInterface *p)
constructor
Definition: MuonCalibDefaultCalibrationSource.cxx:25
RegionSelectorBase.h
MuonCalibDefaultCalibrationSource.h
MdtCalibCreationFlags.h
SamplePoint.h
AthAlgTool
Definition: AthAlgTool.h:26
MuonCalib::MuonCalibDefaultCalibrationSource::store_t0_fun
bool store_t0_fun()
Definition: MuonCalibDefaultCalibrationSource.cxx:119
MuonCalib::CoolInserter::StoreRtChamber
bool StoreRtChamber(const NtupleStationId &id, const std::map< int, SamplePoint > &points, const std::string &file, unsigned int creation_flags=0)
Definition: CoolInserter.cxx:250
MuonCalib::MuonCalibDefaultCalibrationSource::m_rt_regions
std::vector< std::unique_ptr< RegionSelectorBase > > m_rt_regions
Definition: MuonCalibDefaultCalibrationSource.h:50
MuonCalib::CoolInserter::StartT0Chamber
bool StartT0Chamber(const NtupleStationId &sid)
Definition: CoolInserter.cxx:155