ATLAS Offline Software
Loading...
Searching...
No Matches
NswErrorCalibData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5#include <sstream>
6#include "GeoModelKernel/throwExcept.h"
7
10namespace{
11 inline double evalPoly(const double val, const std::vector<double>& pars) {
12 double result{0.};
13 for (size_t c = 0 ; c < pars.size(); ++c) {
14 result+=pars[c] * std::pow(val, c);
15 }
16 return result;
17 }
18 inline double scaleErrorAndAddSyst(const double val, const std::vector<double>& pars) {
19 return std::hypot(pars[0], pars[1]*val);
20 }
21
22}
23
24/**********************************************************
25 **********************************************************
26 **
27 ** Resolution model table
28 **
29 ************************************************************
30 ************************************************************/
32 if (funcName == "tanThetaPolynomial") {
33 return [](const Input & input, const std::vector<double>& pars){
34 return evalPoly(std::tan(input.locTheta), pars);
35 };
36 } else if (funcName == "thetaPolynomial") {
37 return [](const Input & input, const std::vector<double>& pars){
38 return evalPoly(input.locTheta, pars);
39 };
40 } else if (funcName == "scaleErrorAndAddSyst"){
41 return [](const Input& input, const std::vector<double>& pars){
42 return scaleErrorAndAddSyst(input.clusterError, pars);
43 };
44 }
46 std::stringstream except_str;
47 except_str << "NswErrorCalibData::getParametrizer() - The function '"
48 << funcName << "' is unknown. "
49 << "Please check " << __FILE__
50 << " for the set of valid function names.";
51 THROW_EXCEPTION(except_str.str());
52}
53
54
56 if (a.author() != b.clusAlgAuthor) return a.author() < b.clusAlgAuthor;
57 return a.maxStrip() < b.strip;
58}
60 if (a.clusAlgAuthor != b.author()) return a.clusAlgAuthor < b.author();
61 return a.strip < b.minStrip();
62}
64 if (m_clusAlgAuthor != other.m_clusAlgAuthor) {
65 return m_clusAlgAuthor < other.m_clusAlgAuthor;
66 }
67 return m_stripMax < other.m_stripMin;
68}
69
70NswErrorCalibData::ErrorConstants::ErrorConstants(const std::string& funcName, uint8_t author,
71 uint16_t minStrip, uint16_t maxStrip,
72 std::vector<double>&& pars):
73 m_evalFunc{getParametrizer(funcName)},
77 m_pars (std::move(pars))
78{
79}
80
85 return m_evalFunc(clustInfo, m_pars);
86}
87/***********************************************************
88 *
89 * Implementation of the NswErrorCalibData conditions object
90 *
91 **********************************************************/
92
94 AthMessaging{"NswErrorCalibData"},
95 m_idHelperSvc{idHelperSvc} {
96
97}
98double NswErrorCalibData::clusterUncertainty(const Input& clustInfo) const {
99 ErrorMap::const_iterator nswLayerItr = m_database.find(m_idHelperSvc->gasGapId(clustInfo.stripId));
100 if (nswLayerItr == m_database.end()) {
101 ATH_MSG_WARNING("There's no error calibration available for gasGap "
102 << m_idHelperSvc->toStringGasGap(clustInfo.stripId)<<".");
103 return -1.;
104 }
105 ErrorIdentifier errorId{};
106 if (m_idHelperSvc->isMM(clustInfo.stripId)) {
107 errorId.strip = m_idHelperSvc->mmIdHelper().channel(clustInfo.stripId);
108 } else if (m_idHelperSvc->issTgc(clustInfo.stripId)) {
109 errorId.strip = m_idHelperSvc->stgcIdHelper().channel(clustInfo.stripId);
110 }
111 errorId.clusAlgAuthor = clustInfo.clusterAuthor;
112 const ErrorConstantsSet& errorsInLay{nswLayerItr->second};
113 const ErrorConstantsSet::const_iterator layConstItr = errorsInLay.find(errorId);
114 if (layConstItr != errorsInLay.end()) {
115 const double uncert = layConstItr->clusterUncertainty(clustInfo);
116 if (uncert <= 0.) {
117 ATH_MSG_WARNING("Uncertainty of channel "<<m_idHelperSvc->toString(clustInfo.stripId)
118 <<" is smaller than zero ("<<uncert<<"). theta: "<<clustInfo.locTheta
119 <<", eta: "<<(-std::log(std::tan(clustInfo.locTheta/2)))
120 <<", phi: "<<clustInfo.locPhi<<", cluster size: "<<clustInfo.clusterSize
121 << ", author " << static_cast<uint>(clustInfo.clusterAuthor)
122 << ", pars " << layConstItr->pars());
123 }
124 return uncert;
125 }
126 ATH_MSG_WARNING("No calibration constants were stored for channel "<<m_idHelperSvc->toString(clustInfo.stripId)
127 <<", cluster Author: "<<static_cast<int>(clustInfo.clusterAuthor));
128 return 0.;
129}
131 ErrorConstants&& newConstants) {
133 if (newConstants.minStrip() > newConstants.maxStrip()) {
134 ATH_MSG_ERROR("The constants for gas gap"<<m_idHelperSvc->toStringGasGap(gasGapId)
135 <<" have an invalid strip range"<<newConstants.minStrip()<<" to "<<newConstants.maxStrip());
136 return StatusCode::FAILURE;
137 }
139 if (!constants.insert(std::move(newConstants)).second) {
140 ATH_MSG_ERROR("Failed to save error calibration constants for "<<m_idHelperSvc->toStringGasGap(gasGapId));
141 return StatusCode::FAILURE;
142 }
143 return StatusCode::SUCCESS;
144}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
unsigned int uint
static Double_t a
NswErrorCalibData::Input Input
NswErrorCalibData::errorParametrizer errorParametrizer
bool operator<(const NswErrorCalibData::ErrorConstants &a, const NswErrorCalibData::ErrorIdentifier &b)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Helper struct to store different error calibrations for a certain channel range & also for seperate C...
uint8_t m_clusAlgAuthor
Author of the cluster to apply the error.
bool operator<(const ErrorConstants &other) const
const std::vector< double > & pars() const
uint16_t minStrip() const
Returns the minimal strip of validitiy.
uint16_t maxStrip() const
Returns the maximal strip of validity.
double clusterUncertainty(const Input &clustInfo) const
Calculates the cluster uncertainty.
ErrorConstants(const std::string &funcName, uint8_t author, uint16_t minStrip, uint16_t maxStrip, std::vector< double > &&parameters)
uint8_t author() const
Returns the cluster author flag.
uint16_t m_stripMin
Strip range for which the constants are valid.
static errorParametrizer getParametrizer(const std::string &funcName)
const Muon::IMuonIdHelperSvc * m_idHelperSvc
double clusterUncertainty(const Input &clustInfo) const
StatusCode storeConstants(const Identifier &gasGapId, ErrorConstants &&newConstants)
NswErrorCalibData(const Muon::IMuonIdHelperSvc *idHelperSvc)
std::set< ErrorConstants, std::less<> > ErrorConstantsSet
Share the same error constants amongst several gasGaps.
std::function< double(const Input &input, const std::vector< double > &pars)> errorParametrizer
STL namespace.
Helper struct to be parsed to the object to derive the specific error of the cluster.
unsigned int clusterSize
Cluster size.
double locTheta
Direction of the muon in the local coordinate frame.
Identifier stripId
Identifier of the strip.
uint8_t clusterAuthor
Author of the cluster.
double locPhi
Azimuthal angle in the local frame.
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10