7#include "Acts/Utilities/Enumerate.hpp"
16 std::string whiteSpace(
int n,
const char space=
' ') {
18 spaces.assign(n, space);
21 std::string rangeString(std::vector<ushort>& numbers){
22 std::ranges::sort(numbers);
24 std::stringstream sstr{};
25 ushort low{numbers.front()}, high{numbers.front()};
26 for (
const ushort n : numbers) {
27 if (high == n || high+1 == n) {
34 }
else if (low + 1!=high){
43 if (low == numbers.back()) {
45 }
else if (low + 1 != high) {
64 return StatusCode::FAILURE;
68 return StatusCode::FAILURE;
73 return StatusCode::SUCCESS;
78 return StatusCode::SUCCESS;
86 return StatusCode::SUCCESS;
94 unsigned int rtCounter{0}, t0Counter{0};
97 const MdtFullCalibData *calibData = calibHandle->getCalibData(detId, msgStream());
108 for (
int layer = 1; layer <= idHelper.
tubeLayerMax(detId); ++layer) {
109 for (
int tube = 1; tube <= idHelper.
tubeMax(detId); ++tube) {
119 chambT0[singleCalib].insert(chId);
127 unsigned t0GrpCounter{0};
128 for (
const auto&[chId, t0Channels] : t0Groups) {
129 t0GrpCounter+=t0Channels.size();
131 if ((rtCounter == 0) or (t0Counter == 0)){
132 ATH_MSG_ERROR(
"MdtCalibJsonDumpAlg::execute: Counter is zero in numerator");
133 return StatusCode::FAILURE;
135 ATH_MSG_INFO(std::format(
"Grouped {:d} / {:d} ({:.2f}%) rt relations & {:d}/ {:d} ({:.2f}%) t0 calibration constants",
136 rtGroups.size(), rtCounter, (100.* rtGroups.size() / rtCounter),
137 t0GrpCounter, t0Counter,(100.*t0GrpCounter / t0Counter)));
138 return StatusCode::SUCCESS;
142 if (!outFileRT.good()) {
144 return StatusCode::FAILURE;
148 nlohmann::json rtDump{};
149 for (
const auto [counter, payload] : Acts::enumerate(rtRelMap)) {
151 outFileRT<<whiteSpace(
m_whiteSpace)<<
" \"chambers\": [\n";
153 const std::set<Identifier>& chambers = payload.second;
155 for (
const auto [chCounter, chambId] : Acts::enumerate(chambers)) {
157 <<std::format(
"\"station\": \"{:}\", \"eta\": {:2d}, \"phi\": {:1d}, \"ml\": {:1d}",
166 if (chCounter +1 != chambers.size()) {
173 outFileRT<<whiteSpace(
m_whiteSpace+1)<<
"\"rtRelation\": {\n";
179 if (rtRel->
tr()->
name() !=
"TrRelationLookUp") {
180 outFileRT<<whiteSpace(
m_whiteSpace+1)<<
"\"trRelation\": {\n";
187 outFileRT<<whiteSpace(
m_whiteSpace+1)<<
"\"rtReso\": {\n";
192 if (counter +1 != rtRelMap.size()) {
202 return StatusCode::SUCCESS;
205 std::stringstream sstr{};
207 for (
const auto [
count, v] : Acts::enumerate(values)) {
209 if (
count + 1 != values.size())sstr<<
", ";
215 std::stringstream sstr{};
219 sstr<<std::setprecision(
m_precision + std::max(std::floor(std::log10(std::abs(v))), 1.))<<v;
225 if (!outFileT0.good()) {
227 return StatusCode::FAILURE;
231 for (
const auto [
count, payload] : Acts::enumerate(t0Map)) {
234 const T0PerChamb& calibConstants = payload.second;
241 <<std::format(
"\"station\": \"{:}\", \"eta\": {:2d}, \"phi\": {:1d}, \"calibConstants\":[\n",
244 for (
const auto [calibCounter, calibPayload] : Acts::enumerate(calibConstants)) {
245 outFileT0<<whiteSpace(2*
m_whiteSpace)<<
"{\"t0\": "<<
dump(calibPayload.first->t0)<<
", ";
246 outFileT0<<
"\"adc\": "<<
dump(calibPayload.first->adcCal)<<
", ";
247 outFileT0<<
"\"code\": "<<
dump(calibPayload.first->statusCode)<<
", ";
248 outFileT0<<
"\"tubes\": [";
249 Identifier refId = (*calibPayload.second.begin());
251 m_t0_t0= calibPayload.first->t0;
252 m_t0_adc = calibPayload.first->adcCal;
253 m_t0_code = calibPayload.first->statusCode;
254 std::vector<u_short> tubes{};
255 auto dumpTubeLayer = [&tubes, &outFileT0, &idHelper, &refId](
const Identifier& newLayId) {
256 outFileT0<<std::format(
"{{\"ml\": {:1d}, \"tl\": {:1d}, \"no\": \"{:}\"}}",
257 idHelper.multilayer(refId), idHelper.tubeLayer(refId),
262 for (
const Identifier& tubeId : calibPayload.second){
263 const int ml = idHelper.multilayer(tubeId);
264 const int tl = idHelper.tubeLayer(tubeId);
267 m_t0_tube.push_back(idHelper.tube(tubeId));
268 if (tl != idHelper.tubeLayer(refId) || ml != idHelper.multilayer(refId)) {
269 dumpTubeLayer(tubeId);
272 tubes.push_back(idHelper.tube(tubeId));
274 dumpTubeLayer(refId);
276 if (calibCounter +1 != calibConstants.size()){
279 outFileT0<<
"}]"<<std::endl;
283 if (
count +1 != t0Map.size()){
293 return StatusCode::SUCCESS;
297 std::stringstream sstr{};
299 std::string outStr{sstr.str()};
301 [](
const unsigned char c){
302 return !std::isalnum(c) && c!=
'-' && c !=
'_';
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
Obj * get()
Get (non-const) access to the underlying object.
int multilayer(const Identifier &id) const
Access to components of the ID.
Identifier elementID(int stationName, int stationEta, int stationPhi) const
static int tubeLayerMax()
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
const ParVec & parameters() const
virtual std::string name() const =0
class which holds calibration constants per rt-region
const ITrRelation * tr() const
t(r) relationship
const IRtResolution * rtRes() const
resolution
const IRtRelation * rt() const
rt relation
const SingleTubeCalib * getCalib(const Identifier &tubeId) const
return calibration constants of a single tube
int stationEta(const Identifier &id) const
const std::string & stationNameString(const Identifier &id) const
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
int stationPhi(const Identifier &id) const
int stationName(const Identifier &id) const
const_id_iterator detectorElement_end() const
std::map< const SingleTubeCalib *, std::set< Identifier >, CalibParamSorter > T0PerChamb
MuonVal::VectorBranch< double > & m_rt_resoPars
parameters of the rt resolution function
StatusCode dumpRtRelations(const EventContext &ctx, const RtGrouper &rtRelMap, const EventIDRange &eventRange)
writes the RT relations into the JSON & output root file
Gaudi::Property< std::string > m_rtJSON
MuonVal::ScalarBranch< short > & m_t0_stEta
std::string dump(const std::vector< double > &values) const
virtual StatusCode initialize() override final
MuonVal::ScalarBranch< std::string > & m_rt_type
string defining the type of the rt function
MuonVal::VectorBranch< unsigned short > & m_rt_stPhi
Station phi of the associated chamber.
Gaudi::Property< std::string > m_t0JSON
MuonVal::VectorBranch< unsigned short > & m_t0_tubeLayer
MuonVal::ScalarBranch< float > & m_t0_adc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
std::map< Identifier, T0PerChamb > T0Grouper
MuonCalib::CalibParamSorter CalibParamSorter
MuonVal::ScalarBranch< float > & m_t0_t0
MuonVal::EventIDBranch m_rt_iov_end
Data mebmers to save the IOV range (End point).
MuonVal::VectorBranch< double > & m_rt_pars
parameters of the rt-function
MuonVal::EventIDBranch m_t0_iov_start
Data mebmers to save the IOV range (Start point).
SG::ReadCondHandleKey< MuonCalib::MdtCalibDataContainer > m_readKey
MuonVal::ScalarBranch< std::string > & m_tr_type
String defining the type of the tr function.
std::vector< EventIDRange > m_seenIDs
std::map< const MuonCalib::MdtRtRelation *, std::set< Identifier >, CalibParamSorter > RtGrouper
Gaudi::Property< bool > m_savePerIOV
MuonVal::ScalarBranch< unsigned short > & m_t0_code
std::string toString(const EventIDRange &range) const
MuonVal::ScalarBranch< unsigned short > & m_t0_stPhi
MuonVal::MuonTesterTree m_rtDumpTree
MuonVal::VectorBranch< unsigned short > & m_rt_stMl
Multi layer of the associated chamber.
StatusCode dumpTubeT0s(const EventContext &ctx, const T0Grouper &t0Map, const EventIDRange &eventRange)
virtual ~MdtCalibJsonDumpAlg()
MuonVal::EventIDBranch m_rt_iov_start
Data mebmers to save the IOV range (Start point).
virtual StatusCode finalize() override final
MuonVal::VectorBranch< unsigned short > & m_t0_multiLayer
Gaudi::Property< unsigned > m_whiteSpace
MuonVal::ScalarBranch< std::string > & m_rt_resoType
string defining the type of the rt resolution function
MuonVal::VectorBranch< unsigned short > & m_t0_tube
virtual StatusCode execute(const EventContext &ctx) override final
Execute method.
MuonVal::VectorBranch< short > & m_rt_stEta
Station eta of the associated chambers.
MuonVal::VectorBranch< double > & m_tr_pars
parameters of the tr-function
Gaudi::Property< unsigned > m_precision
MuonVal::MuonTesterTree m_t0DumpTree
MuonVal::ScalarBranch< std::string > & m_t0_stName
MuonVal::EventIDBranch m_t0_iov_end
Data mebmers to save the IOV range (End point).
MuonVal::VectorBranch< std::string > & m_rt_stName
Station name string of the associated chambers.
const EventIDRange & getRange()
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
class which holds the full set of calibration constants for a given tube
TubeContainerPtr tubeCalib