ATLAS Offline Software
Loading...
Searching...
No Matches
NswErrorCalibData.cxx
Go to the documentation of this file.
2#include <sstream>
3#include "GeoModelKernel/throwExcept.h"
4
7namespace{
8 inline double evalPoly(const double val, const std::vector<double>& pars) {
9 double result{0.};
10 for (size_t c = 0 ; c < pars.size(); ++c) {
11 result+=pars[c] * std::pow(val, c);
12 }
13 return result;
14 }
15 inline double scaleErrorAndAddSyst(const double val, const std::vector<double>& pars) {
16 return std::hypot(pars[0], pars[1]*val);
17 }
18
19}
20
21/**********************************************************
22 **********************************************************
23 **
24 ** Resolution model table
25 **
26 ************************************************************
27 ************************************************************/
29 if (funcName == "tanThetaPolynomial") {
30 return [](const Input & input, const std::vector<double>& pars){
31 return evalPoly(std::tan(input.locTheta), pars);
32 };
33 } else if (funcName == "thetaPolynomial") {
34 return [](const Input & input, const std::vector<double>& pars){
35 return evalPoly(input.locTheta, pars);
36 };
37 } else if (funcName == "scaleErrorAndAddSyst"){
38 return [](const Input& input, const std::vector<double>& pars){
39 return scaleErrorAndAddSyst(input.clusterError, pars);
40 };
41 }
43 return [funcName](const Input&, const std::vector<double>& ) {
44 std::stringstream except_str{};
45 except_str<<"NswErrorCalibData::parametrizer() - The function '"<<funcName<<"' is unknown.";
46 except_str<<"Please check"<<__FILE__<<" for the set of valid function names. ";
47 THROW_EXCEPTION(except_str.str());
48 return 0.;
49 };
50}
51
52
54 if (a.author() != b.clusAlgAuthor) return a.author() < b.clusAlgAuthor;
55 return a.maxStrip() < b.strip;
56}
58 if (a.clusAlgAuthor != b.author()) return a.clusAlgAuthor < b.author();
59 return a.strip < b.minStrip();
60}
62 if (m_clusAlgAuthor != other.m_clusAlgAuthor) {
63 return m_clusAlgAuthor < other.m_clusAlgAuthor;
64 }
65 return m_stripMax < other.m_stripMin;
66}
67
68NswErrorCalibData::ErrorConstants::ErrorConstants(const std::string& funcName, uint8_t author,
69 uint16_t minStrip, uint16_t maxStrip,
70 std::vector<double>&& pars):
71 m_evalFunc{getParametrizer(funcName)},
75 m_pars (std::move(pars))
76{
77}
78
83 return m_evalFunc(clustInfo, m_pars);
84}
85/***********************************************************
86 *
87 * Implementation of the NswErrorCalibData conditions object
88 *
89 **********************************************************/
90
92 AthMessaging{"NswErrorCalibData"},
93 m_idHelperSvc{idHelperSvc} {
94
95}
96double NswErrorCalibData::clusterUncertainty(const Input& clustInfo) const {
97 ErrorMap::const_iterator nswLayerItr = m_database.find(m_idHelperSvc->gasGapId(clustInfo.stripId));
98 if (nswLayerItr == m_database.end()) {
99 ATH_MSG_WARNING("There's no error calibration available for gasGap "
100 << m_idHelperSvc->toStringGasGap(clustInfo.stripId)<<".");
101 return -1.;
102 }
103 ErrorIdentifier errorId{};
104 if (m_idHelperSvc->isMM(clustInfo.stripId)) {
105 errorId.strip = m_idHelperSvc->mmIdHelper().channel(clustInfo.stripId);
106 } else if (m_idHelperSvc->issTgc(clustInfo.stripId)) {
107 errorId.strip = m_idHelperSvc->stgcIdHelper().channel(clustInfo.stripId);
108 }
109 errorId.clusAlgAuthor = clustInfo.clusterAuthor;
110 const ErrorConstantsSet& errorsInLay{nswLayerItr->second};
111 const ErrorConstantsSet::const_iterator layConstItr = errorsInLay.find(errorId);
112 if (layConstItr != errorsInLay.end()) {
113 const double uncert = layConstItr->clusterUncertainty(clustInfo);
114 if (uncert <= 0.) {
115 ATH_MSG_WARNING("Uncertainty of channel "<<m_idHelperSvc->toString(clustInfo.stripId)
116 <<" is smaller than zero ("<<uncert<<"). theta: "<<clustInfo.locTheta
117 <<", eta: "<<(-std::log(std::tan(clustInfo.locTheta/2)))
118 <<", phi: "<<clustInfo.locPhi<<", cluster size: "<<clustInfo.clusterSize
119 << ", author " << static_cast<uint>(clustInfo.clusterAuthor)
120 << ", pars " << layConstItr->pars());
121 }
122 return uncert;
123 }
124 ATH_MSG_WARNING("No calibration constants were stored for channel "<<m_idHelperSvc->toString(clustInfo.stripId)
125 <<", cluster Author: "<<static_cast<int>(clustInfo.clusterAuthor));
126 return 0.;
127}
129 ErrorConstants&& newConstants) {
131 if (newConstants.minStrip() > newConstants.maxStrip()) {
132 ATH_MSG_ERROR("The constants for gas gap"<<m_idHelperSvc->toStringGasGap(gasGapId)
133 <<" have an invalid strip range"<<newConstants.minStrip()<<" to "<<newConstants.maxStrip());
134 return StatusCode::FAILURE;
135 }
137 if (!constants.insert(std::move(newConstants)).second) {
138 ATH_MSG_ERROR("Failed to save error calibration constants for "<<m_idHelperSvc->toStringGasGap(gasGapId));
139 return StatusCode::FAILURE;
140 }
141 return StatusCode::SUCCESS;
142}
#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