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;
81 const EventContext &ctx{Gaudi::Hive::currentContext()};
87 return StatusCode::SUCCESS;
95 unsigned int rtCounter{0}, t0Counter{0};
98 const MdtFullCalibData *calibData = calibHandle->getCalibData(detId, msgStream());
109 for (
int layer = 1; layer <= idHelper.
tubeLayerMax(detId); ++layer) {
110 for (
int tube = 1; tube <= idHelper.
tubeMax(detId); ++tube) {
120 chambT0[singleCalib].insert(chId);
128 unsigned t0GrpCounter{0};
129 for (
const auto&[chId, t0Channels] : t0Groups) {
130 t0GrpCounter+=t0Channels.size();
132 if ((rtCounter == 0) or (t0Counter == 0)){
133 ATH_MSG_ERROR(
"MdtCalibJsonDumpAlg::execute: Counter is zero in numerator");
134 return StatusCode::FAILURE;
136 ATH_MSG_INFO(std::format(
"Grouped {:d} / {:d} ({:.2f}%) rt relations & {:d}/ {:d} ({:.2f}%) t0 calibration constants",
137 rtGroups.size(), rtCounter, (100.* rtGroups.size() / rtCounter),
138 t0GrpCounter, t0Counter,(100.*t0GrpCounter / t0Counter)));
139 return StatusCode::SUCCESS;
143 if (!outFileRT.good()) {
145 return StatusCode::FAILURE;
149 nlohmann::json rtDump{};
150 for (
const auto [counter, payload] : Acts::enumerate(rtRelMap)) {
152 outFileRT<<whiteSpace(
m_whiteSpace)<<
" \"chambers\": [\n";
154 const std::set<Identifier>& chambers = payload.second;
156 for (
const auto [chCounter, chambId] : Acts::enumerate(chambers)) {
158 <<std::format(
"\"station\": \"{:}\", \"eta\": {:2d}, \"phi\": {:1d}, \"ml\": {:1d}",
167 if (chCounter +1 != chambers.size()) {
174 outFileRT<<whiteSpace(
m_whiteSpace+1)<<
"\"rtRelation\": {\n";
180 if (rtRel->
tr()->
name() !=
"TrRelationLookUp") {
181 outFileRT<<whiteSpace(
m_whiteSpace+1)<<
"\"trRelation\": {\n";
188 outFileRT<<whiteSpace(
m_whiteSpace+1)<<
"\"rtReso\": {\n";
193 if (counter +1 != rtRelMap.size()) {
203 return StatusCode::SUCCESS;
206 std::stringstream sstr{};
208 for (
const auto [
count, v] : Acts::enumerate(values)) {
210 if (
count + 1 != values.size())sstr<<
", ";
216 std::stringstream sstr{};
220 sstr<<std::setprecision(
m_precision + std::max(std::floor(std::log10(std::abs(v))), 1.))<<v;
226 if (!outFileT0.good()) {
228 return StatusCode::FAILURE;
232 for (
const auto [
count, payload] : Acts::enumerate(t0Map)) {
235 const T0PerChamb& calibConstants = payload.second;
242 <<std::format(
"\"station\": \"{:}\", \"eta\": {:2d}, \"phi\": {:1d}, \"calibConstants\":[\n",
245 for (
const auto [calibCounter, calibPayload] : Acts::enumerate(calibConstants)) {
246 outFileT0<<whiteSpace(2*
m_whiteSpace)<<
"{\"t0\": "<<
dump(calibPayload.first->t0)<<
", ";
247 outFileT0<<
"\"adc\": "<<
dump(calibPayload.first->adcCal)<<
", ";
248 outFileT0<<
"\"code\": "<<
dump(calibPayload.first->statusCode)<<
", ";
249 outFileT0<<
"\"tubes\": [";
250 Identifier refId = (*calibPayload.second.begin());
252 m_t0_t0= calibPayload.first->t0;
253 m_t0_adc = calibPayload.first->adcCal;
254 m_t0_code = calibPayload.first->statusCode;
255 std::vector<u_short> tubes{};
256 auto dumpTubeLayer = [&tubes, &outFileT0, &idHelper, &refId](
const Identifier& newLayId) {
257 outFileT0<<std::format(
"{{\"ml\": {:1d}, \"tl\": {:1d}, \"no\": \"{:}\"}}",
258 idHelper.multilayer(refId), idHelper.tubeLayer(refId),
263 for (
const Identifier& tubeId : calibPayload.second){
264 const int ml = idHelper.multilayer(tubeId);
265 const int tl = idHelper.tubeLayer(tubeId);
268 m_t0_tube.push_back(idHelper.tube(tubeId));
269 if (tl != idHelper.tubeLayer(refId) || ml != idHelper.multilayer(refId)) {
270 dumpTubeLayer(tubeId);
273 tubes.push_back(idHelper.tube(tubeId));
275 dumpTubeLayer(refId);
277 if (calibCounter +1 != calibConstants.size()){
280 outFileT0<<
"}]"<<std::endl;
284 if (
count +1 != t0Map.size()){
294 return StatusCode::SUCCESS;
298 std::stringstream sstr{};
300 std::string outStr{sstr.str()};
302 [](
const unsigned char c){
303 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_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
const std::string & stationNameString(const int &index) const
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::map< const SingleTubeCalib *, std::set< Identifier >, CalibParamSorter > T0PerChamb
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
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.
virtual StatusCode execute() override final
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