ATLAS Offline Software
Loading...
Searching...
No Matches
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
23namespace 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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
ICscStripFitter::Result Result
static const std::vector< std::string > regions
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::vector< std::map< int, SamplePoint > > m_rt_points
MuonCalibDefaultCalibrationSource(const std::string &t, const std::string &n, const IInterface *p)
constructor
std::vector< std::unique_ptr< RegionSelectorBase > > m_t0_regions
bool insert_calibration(bool store_t0, bool store_rt)
insert calibration
std::vector< std::unique_ptr< RegionSelectorBase > > m_rt_regions
StatusCode initialize_regions(const std::vector< std::string > &reg_str, std::vector< std::unique_ptr< RegionSelectorBase > > &reg)
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)
Implements fixed identifiers not dependent upon Athena Identifier for internal use in the calibration...
Definition MuonFixedId.h:50
static std::unique_ptr< RegionSelectorBase > GetRegion(const std::string &input)
create a region from a string
This class provides a sample point for the BaseFunctionFitter.
Definition SamplePoint.h:15
int r
Definition globals.cxx:22
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.