ATLAS Offline Software
NswErrorCalibData.cxx
Go to the documentation of this file.
2 #include <sstream>
3 #include "GeoModelKernel/throwExcept.h"
4 
7 namespace{
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 
70  std::vector<double>&& pars):
71  m_evalFunc{getParametrizer(funcName)},
72  m_clusAlgAuthor (author),
73  m_stripMin (minStrip),
74  m_stripMax (maxStrip),
75  m_pars (std::move(pars))
76 {
77 }
78 
81 uint8_t NswErrorCalibData::ErrorConstants::author() const { return m_clusAlgAuthor; }
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 }
96 double 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 }
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
errorParametrizer
NswErrorCalibData::errorParametrizer errorParametrizer
Definition: NswErrorCalibData.cxx:5
Muon::IMuonIdHelperSvc::stgcIdHelper
virtual const sTgcIdHelper & stgcIdHelper() const =0
access to TgcIdHelper
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
NswErrorCalibData::ErrorConstants::clusterUncertainty
double clusterUncertainty(const Input &clustInfo) const
Calculates the cluster uncertainty.
Definition: NswErrorCalibData.cxx:82
NswErrorCalibData::Input::locPhi
double locPhi
Azimuthal angle in the local frame.
Definition: NswErrorCalibData.h:33
NswErrorCalibData::errorParametrizer
std::function< double(const Input &input, const std::vector< double > &pars)> errorParametrizer
Definition: NswErrorCalibData.h:43
NswErrorCalibData::ErrorConstants
Helper struct to store different error calibrations for a certain channel range & also for seperate C...
Definition: NswErrorCalibData.h:50
NswErrorCalibData::m_idHelperSvc
const Muon::IMuonIdHelperSvc * m_idHelperSvc
Definition: NswErrorCalibData.h:95
operator<
bool operator<(const NswErrorCalibData::ErrorConstants &a, const NswErrorCalibData::ErrorIdentifier &b)
Definition: NswErrorCalibData.cxx:53
NswErrorCalibData::Input::clusterSize
unsigned int clusterSize
Cluster size.
Definition: NswErrorCalibData.h:37
THROW_EXCEPTION
#define THROW_EXCEPTION(MSG)
Definition: MMReadoutElement.cxx:48
NswErrorCalibData::ErrorIdentifier
Definition: NswErrorCalibData.h:78
Muon::IMuonIdHelperSvc::mmIdHelper
virtual const MmIdHelper & mmIdHelper() const =0
access to CscIdHelper
NswErrorCalibData::Input::locTheta
double locTheta
Direction of the muon in the local coordinate frame.
Definition: NswErrorCalibData.h:31
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
NswErrorCalibData::getParametrizer
static errorParametrizer getParametrizer(const std::string &funcName)
Definition: NswErrorCalibData.cxx:28
NswErrorCalibData::ErrorConstants::ErrorConstants
ErrorConstants(const std::string &funcName, uint8_t author, uint16_t minStrip, uint16_t maxStrip, std::vector< double > &&parameters)
Definition: NswErrorCalibData.cxx:68
sTgcIdHelper::channel
int channel(const Identifier &id) const override
Definition: sTgcIdHelper.cxx:1027
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
NswErrorCalibData::NswErrorCalibData
NswErrorCalibData(const Muon::IMuonIdHelperSvc *idHelperSvc)
Definition: NswErrorCalibData.cxx:91
NswErrorCalibData::ErrorConstants::m_clusAlgAuthor
uint8_t m_clusAlgAuthor
Author of the cluster to apply the error.
Definition: NswErrorCalibData.h:71
NswErrorCalibData::ErrorConstants::maxStrip
uint16_t maxStrip() const
Returns the maximal strip of validity.
Definition: NswErrorCalibData.cxx:80
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
NswErrorCalibData::ErrorConstants::operator<
bool operator<(const ErrorConstants &other) const
Definition: NswErrorCalibData.cxx:61
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
Muon::IMuonIdHelperSvc::toStringGasGap
virtual std::string toStringGasGap(const Identifier &id) const =0
print all fields up to gas gap to string
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
NswErrorCalibData.h
NswErrorCalibData::clusterUncertainty
double clusterUncertainty(const Input &clustInfo) const
Definition: NswErrorCalibData.cxx:96
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
NswErrorCalibData::ErrorConstantsSet
std::set< ErrorConstants, std::less<> > ErrorConstantsSet
Share the same error constants amongst several gasGaps.
Definition: NswErrorCalibData.h:83
NswErrorCalibData::ErrorConstants::author
uint8_t author() const
Returns the cluster author flag.
Definition: NswErrorCalibData.cxx:81
NswErrorCalibData::ErrorConstants::m_stripMax
uint16_t m_stripMax
Definition: NswErrorCalibData.h:74
NswErrorCalibData::Input::stripId
Identifier stripId
Identifier of the strip.
Definition: NswErrorCalibData.h:27
NswErrorCalibData::storeConstants
StatusCode storeConstants(const Identifier &gasGapId, ErrorConstants &&newConstants)
Definition: NswErrorCalibData.cxx:128
Muon::IMuonIdHelperSvc::isMM
virtual bool isMM(const Identifier &id) const =0
returns whether this is a MM Identifier or not
NswErrorCalibData::ErrorIdentifier::strip
uint16_t strip
Definition: NswErrorCalibData.h:79
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
dumpNswErrorDb.maxStrip
tuple maxStrip
Definition: dumpNswErrorDb.py:27
Muon::IMuonIdHelperSvc::gasGapId
virtual Identifier gasGapId(const Identifier &id) const =0
create a gasGap ID (will return layer Id for MDTs)
NswErrorCalibData::ErrorConstants::minStrip
uint16_t minStrip() const
Returns the minimal strip of validitiy.
Definition: NswErrorCalibData.cxx:79
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
MmIdHelper::channel
int channel(const Identifier &id) const override
Definition: MmIdHelper.cxx:800
Muon::IMuonIdHelperSvc::toString
virtual std::string toString(const Identifier &id) const =0
print all fields to string
constants
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:1
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
NswErrorCalibData::m_database
ErrorMap m_database
Definition: NswErrorCalibData.h:97
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:26
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
dumpNswErrorDb.minStrip
int minStrip
Definition: dumpNswErrorDb.py:26
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:27
NswErrorCalibData::Input
Helper struct to be parsed to the object to derive the specific error of the cluster.
Definition: NswErrorCalibData.h:25
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
python.compressB64.c
def c
Definition: compressB64.py:93
Input
NswErrorCalibData::Input Input
Definition: NswErrorCalibData.cxx:6
Muon::IMuonIdHelperSvc::issTgc
virtual bool issTgc(const Identifier &id) const =0
returns whether this is a sTGC Identifier or not
NswErrorCalibData::Input::clusterAuthor
uint8_t clusterAuthor
Author of the cluster.
Definition: NswErrorCalibData.h:29
Identifier
Definition: IdentifierFieldParser.cxx:14