ATLAS Offline Software
L1ThresholdBase.cxx
Go to the documentation of this file.
1 /* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */
2 
3 #include <algorithm>
4 #include <cmath>
5 #include <limits>
6 
7 
10 
17 unsigned int
18 TrigConf::energyInCounts(unsigned int energyMeV, unsigned int energyResolutionMeV)
19 {
20  if ( energyMeV % energyResolutionMeV != 0 ) {
21  throw std::runtime_error("Energy " + std::to_string(energyMeV) + " MeV is not a multiple of the energy resolution " + std::to_string(energyResolutionMeV));
22  }
23  return energyMeV / energyResolutionMeV;
24 }
25 
26 
27 std::shared_ptr<TrigConf::L1Threshold>
28 TrigConf::L1Threshold::createThreshold( const std::string & name, const std::string & type,
29  std::weak_ptr<L1ThrExtraInfoBase> extraInfo, const ptree & data )
30 {
31  if( type == "EM" )
32  return std::make_shared<L1Threshold_EM>( name, type, extraInfo, data );
33 
34  if( type == "TAU" )
35  return std::make_shared<L1Threshold_TAU>( name, type, extraInfo, data );
36 
37  if( type == "XE" )
38  return std::make_shared<L1Threshold_XE>( name, type, extraInfo, data );
39 
40  if( type == "JET" || type == "JB" || type == "JF" ) // JB and JF are Run 1 thresholds
41  return std::make_shared<L1Threshold_JET>( name, type, extraInfo, data );
42 
43  if( type == "XS" )
44  return std::make_shared<L1Threshold_XS>( name, type, extraInfo, data );
45 
46  if( type == "TE" || type == "JE" ) // JE is a Run 1 threshold
47  return std::make_shared<L1Threshold_TE>( name, type, extraInfo, data );
48 
49  if( type == "eEM" )
50  return std::make_shared<L1Threshold_eEM>( name, type, extraInfo, data );
51 
52  if( type == "jEM" )
53  return std::make_shared<L1Threshold_jEM>( name, type, extraInfo, data );
54 
55  if( type == "eTAU" )
56  return std::make_shared<L1Threshold_eTAU>( name, type, extraInfo, data );
57 
58  if( type == "jTAU" )
59  return std::make_shared<L1Threshold_jTAU>( name, type, extraInfo, data );
60 
61  if( type == "cTAU" )
62  return std::make_shared<L1Threshold_cTAU>( name, type, extraInfo, data );
63 
64  if( type == "jJ" )
65  return std::make_shared<L1Threshold_jJ>( name, type, extraInfo, data );
66 
67  if( type == "jLJ" )
68  return std::make_shared<L1Threshold_jLJ>( name, type, extraInfo, data );
69 
70  if( type == "gJ" )
71  return std::make_shared<L1Threshold_gJ>( name, type, extraInfo, data );
72 
73  if( type == "gLJ" )
74  return std::make_shared<L1Threshold_gLJ>( name, type, extraInfo, data );
75 
76  if( type == "jXE" )
77  return std::make_shared<L1Threshold_jXE>( name, type, extraInfo, data );
78 
79  if( type == "jTE" )
80  return std::make_shared<L1Threshold_jTE>( name, type, extraInfo, data );
81 
82  if( type == "gXE" )
83  return std::make_shared<L1Threshold_gXE>( name, type, extraInfo, data );
84 
85  if( type == "gTE" )
86  return std::make_shared<L1Threshold_gTE>( name, type, extraInfo, data );
87 
88  if( type == "MU" )
89  return std::make_shared<L1Threshold_MU>( name, type, extraInfo, data );
90 
91  if( type == "ZB" )
92  return std::make_shared<L1Threshold_ZB>( name, type, extraInfo, data );
93 
94  if( type == "ZBTopo" )
95  return std::make_shared<L1Threshold_ZBTopo>( name, type, extraInfo, data );
96 
97  static const std::string NIMtypes[] = { "BCM", "BCMCMB", "LUCID", "ZDC", "BPTX", "CALREQ", "MBTS", "MBTSSI", "NIM" };
98  bool isNIMtype = std::find(std::begin(NIMtypes), std::end(NIMtypes), type) != std::end(NIMtypes);
99 
100  if( isNIMtype )
101  return std::make_shared<L1Threshold_NIM>( name, type, extraInfo, data );
102 
103  if( type == "internal" )
104  return std::make_shared<L1Threshold_internal>( name, type, extraInfo, data );
105 
106  static const std::string noSpecialImp[] = { "JET", "XS", "TOPO", "MULTTOPO", "MUTOPO", "R2TOPO", "ALFA", "NSWMon", "LArSat"};
107  bool useBaseClass = std::find(std::begin(noSpecialImp), std::end(noSpecialImp),type) != std::end(noSpecialImp);
108 
109  if( useBaseClass )
110  return std::make_shared<L1Threshold>( name, type, extraInfo, data );
111 
112  throw std::runtime_error("Threshold " + name + " is not of a valid L1 threshold type: " + type);
113 
114 }
115 
116 TrigConf::L1Threshold::L1Threshold( const std::string & name, const std::string & type,
117  std::weak_ptr<L1ThrExtraInfoBase> extraInfo, const boost::property_tree::ptree & data)
118  : DataStructure(data),
119  m_extraInfo(extraInfo),
120  m_type(type)
121 {
122  m_name = name;
123  load();
124 }
125 
126 float
128  return 0;
129 }
130 
131 void
133 {
134  load();
135 }
136 
137 void
139 {
140  if( type() == "internal" ) {
141  return;
142  }
143  m_name = getAttribute("name", true, m_name);
144  m_type = getAttribute("type", true, m_type);
145  m_mapping = getAttribute<unsigned int>("mapping");
146 }
147 
148 
151 {
152  m_name = thrTypeName;
153  load();
154 }
155 
156 void
158 {
159  if(! isInitialized() || empty() )
160  return;
161 
162  // if( m_name == "internal" ) { // internal trigger have no extra info
163  // return;
164  // }
165  for( auto & content : data() ) {
166  if( content.first == "type" ||
167  content.first == "thresholds" ) {
168  continue;
169  }
170  // if there is anything else in the tree we consider it extra info fro this threshold type
171  m_extraInfo.emplace( std::piecewise_construct,
172  std::forward_as_tuple(content.first),
173  std::forward_as_tuple(content.second));
174  }
175 
176  m_resolutionMeV = getAttribute<unsigned int>("resolutionMeV", true, 1000);
177  if( hasAttribute("emscale") ) { // for previous definition of the EM resolution
178  m_resolutionMeV = 1000 / getAttribute<unsigned int>("emscale");
179  }
180 }
181 
182 
183 const std::string &
185 {
186  return m_name;
187 }
188 
189 bool
191 {
192  if( key.empty() ) {
193  return m_extraInfo.size()>0;
194  }
195  return m_extraInfo.count(key)>0;
196 }
197 
198 std::optional<std::reference_wrapper<const TrigConf::DataStructure>>
200 {
201  bool hasKey = m_extraInfo.count(key)>0;
202  return hasKey ? std::optional<std::reference_wrapper<const TrigConf::DataStructure>>{m_extraInfo.at(key)} : std::nullopt;
203 }
204 
205 
206 
213 TrigConf::L1Threshold_Calo::L1Threshold_Calo( const std::string & name, const std::string & type,
214  std::weak_ptr<L1ThrExtraInfoBase> extraInfo, const boost::property_tree::ptree & data)
215  : L1Threshold(name, type, extraInfo, data),
216  m_etaDepThrValue(name + "#" + type + "_value")
217 {
218  load();
219 }
220 
221 void
223 {
225  load();
226 }
227 
228 namespace {
229  unsigned int gev2MeVThrVal(double gevVal) {
230  unsigned int mev_i = std::lround( 1000 * gevVal );
231  if( gevVal != (mev_i / 1000.) ) {
232  std::runtime_error("Value conversion failed");
233  }
234  return mev_i;
235  }
236 
237 }
238 
239 
240 void
242 {
243  if( type() == "internal" ) {
244  return;
245  }
246  m_thrValue = gev2MeVThrVal( getAttribute<double>("value", true, 0) );
247  m_input = getAttribute("input", true, "");
248  if( const auto & thrVs = data().get_child_optional("thrValues") ) {
249  for( auto & x : thrVs.get() ) {
250  auto value = gev2MeVThrVal( x.second.get_child("value").get_value<float>() );
251  auto etamin = x.second.get_child("etamin").get_value<unsigned int>();
252  auto etamax = x.second.get_child("etamax").get_value<unsigned int>();
253  auto priority = x.second.get_child("priority").get_value<unsigned int>();
254  m_etaDepThrValue.addRangeValue(value, etamin, etamax, priority, /*symmetric=*/ false);
255  }
256  }
257  if( const auto & ranges = data().get_child_optional("ranges") ) {
258  m_etaDepThrValue.setOutsideRangeValue(getAttribute("maxValue", true, std::numeric_limits<unsigned int>::max()));
259  for( auto & x : ranges.get() ) {
260  auto etamin = x.second.get_child("etamin").get_value<unsigned int>();
261  auto etamax = x.second.get_child("etamax").get_value<unsigned int>();
262  m_etaDepThrValue.addRangeValue(m_thrValue, etamin, etamax, /*priority=*/ 1, /*symmetric=*/ false);
263  }
264  }
265 }
266 
267 /*
268  various access methods to the threshold values
269 */
270 
271 float
273 {
274  return thrValueMeV(eta) / 1000.0f;
275 }
276 
277 unsigned int
279  auto extraInfo = m_extraInfo.lock();
280  return energyInCounts( thrValueMeV(eta), extraInfo->resolutionMeV() );
281 }
282 
283 unsigned int
285  return energyInCounts( thrValueMeV(eta), 100 );
286 }
287 
288 unsigned int
290  return m_etaDepThrValue.empty() ? m_thrValue : m_etaDepThrValue.at(eta);
291 }
292 
295  auto thresholdValuesGeV = ValueWithEtaDependence<float>{ m_etaDepThrValue.name()+"GeV" };
296  for( auto & r : m_etaDepThrValue ) {
297  thresholdValuesGeV.addRangeValue(r.value() / 1000.0f, r.etaMin(), r.etaMax(), r.priority(), r.symmetric());
298  }
299  return thresholdValuesGeV;
300 }
301 
304  return m_etaDepThrValue;
305 }
306 
309  auto thrValues100MeV = ValueWithEtaDependence<unsigned int>{ m_etaDepThrValue.name()+"100MeV" };
310  for( auto & r : m_etaDepThrValue ) {
311  thrValues100MeV.addRangeValue( energyInCounts( r.value(), 100 ), r.etaMin(), r.etaMax(), r.priority(), r.symmetric());
312  }
313  return thrValues100MeV;
314 }
315 
318  auto extraInfo = m_extraInfo.lock();
319  auto thrValuesCounts = ValueWithEtaDependence<unsigned int>{ m_etaDepThrValue.name()+"Counts" };
320  for( auto & r : m_etaDepThrValue ) {
321  thrValuesCounts.addRangeValue( energyInCounts( r.value(), extraInfo->resolutionMeV() ), r.etaMin(), r.etaMax(), r.priority(), r.symmetric());
322  }
323  return thrValuesCounts;
324 }
325 
327  m_isDefined = true;
328  m_isobit = pt.get_child("isobit").get_value<int>();
329  m_offset = pt.get_child("offset").get_value<int>();
330  m_slope = pt.get_child("slope").get_value<int>();
331  m_mincut = pt.get_child("mincut").get_value<int>();
332  m_upperlimit = pt.get_child("upperlimit").get_value<int>();
333  m_etamin = pt.get_child("etamin").get_value<int>();
334  m_etamax = pt.get_child("etamax").get_value<int>();
335  m_priority = pt.get_child("priority").get_value<int>();
336 }
337 
338 std::ostream &
339 TrigConf::operator<<(std::ostream & os, const TrigConf::IsolationLegacy & iso) {
340  os << "isolation bit " << iso.isobit() << ": offset=" << iso.offset() << ", slope=" << iso.slope()
341  << ", mincut=" << iso.mincut() << ", upperlimit=" << iso.upperlimit()
342  << ", etamin=" << iso.etamin() << ", etamax=" << iso.etamax() << ", priority=" << iso.priority();
343  return os;
344 }
345 
346 std::string
348 {
349  if (wp == Selection::WP::NONE)
350  return "None";
351  if (wp == Selection::WP::LOOSE)
352  return "Loose";
353  if (wp == Selection::WP::MEDIUM)
354  return "Medium";
355  if (wp == Selection::WP::TIGHT)
356  return "Tight";
358  return "HadLoose";
360  return "HadMedium";
362  return "HadTight";
363  if (wp == Selection::WP::HAD) // Had = HadMedium for backward compatibility
364  return "HadMedium";
365  if (wp == Selection::WP::LOOSE12)
366  return "Loose12";
367  if (wp == Selection::WP::LOOSE20)
368  return "Loose20";
369  if (wp == Selection::WP::LOOSE30)
370  return "Loose30";
371  if (wp == Selection::WP::LOOSE35)
372  return "Loose35";
374  return "Medium12";
376  return "Medium20";
378  return "Medium30";
380  return "Medium35";
381  if (wp == Selection::WP::TIGHT12)
382  return "Tight12";
383  if (wp == Selection::WP::TIGHT20)
384  return "Tight20";
385  if (wp == Selection::WP::TIGHT30)
386  return "Tight30";
387  if (wp == Selection::WP::TIGHT35)
388  return "Tight35";
389  throw std::runtime_error("Unknown working point " + std::to_string(int(wp)));
390 }
391 
393 TrigConf::Selection::stringToWP(const std::string & wpStr)
394 {
395  if (wpStr == "None")
396  return Selection::WP::NONE;
397  if (wpStr == "Loose")
398  return Selection::WP::LOOSE;
399  if (wpStr == "Medium")
400  return Selection::WP::MEDIUM;
401  if (wpStr == "Tight")
402  return Selection::WP::TIGHT;
403  if (wpStr == "HadLoose")
405  if (wpStr == "HadMedium")
407  if (wpStr == "HadTight")
409  if (wpStr == "Had") // Had = HadMedium for backward compatibility
410  return Selection::WP::HADMEDIUM;
411  if (wpStr == "Loose12")
412  return Selection::WP::LOOSE12;
413  if (wpStr == "Loose20")
414  return Selection::WP::LOOSE20;
415  if (wpStr == "Loose30")
416  return Selection::WP::LOOSE30;
417  if (wpStr == "Loose35")
418  return Selection::WP::LOOSE35;
419  if (wpStr == "Medium12")
421  if (wpStr == "Medium20")
423  if (wpStr == "Medium30")
425  if (wpStr == "Medium35")
427  if (wpStr == "Tight12")
428  return Selection::WP::TIGHT12;
429  if (wpStr == "Tight20")
430  return Selection::WP::TIGHT20;
431  if (wpStr == "Tight30")
432  return Selection::WP::TIGHT30;
433  if (wpStr == "Tight35")
434  return Selection::WP::TIGHT35;
435  throw std::runtime_error("Unknown working point name " + wpStr);
436 }
TrigConf::DataStructure::data
const ptree & data() const
Access to the underlying data, if needed.
Definition: DataStructure.h:83
TrigConf::Selection::WP
WP
Definition: L1ThresholdBase.h:298
TrigConf::L1Threshold_Calo::thrValuesCounts
virtual ValueWithEtaDependence< unsigned int > thrValuesCounts() const
access to the list of ThresholdValues in energy units
Definition: L1ThresholdBase.cxx:317
beamspotman.r
def r
Definition: beamspotman.py:676
TrigConf::Selection::WP::LOOSE
@ LOOSE
trigbs_pickEvents.ranges
ranges
Definition: trigbs_pickEvents.py:60
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
TrigConf::operator<<
std::ostream & operator<<(std::ostream &os, const TrigConf::IsolationLegacy &iso)
Definition: L1ThresholdBase.cxx:339
TrigConf::Selection::WP::MEDIUM12
@ MEDIUM12
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
TrigConf::Selection::stringToWP
static WP stringToWP(const std::string &)
Definition: L1ThresholdBase.cxx:393
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
TrigConf::Selection::WP::TIGHT35
@ TIGHT35
TrigConf::Selection::wpToString
static std::string wpToString(WP)
Definition: L1ThresholdBase.cxx:347
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
test_pyathena.pt
pt
Definition: test_pyathena.py:11
athena.value
value
Definition: athena.py:124
python.selector.AtlRunQuerySelectorLhcOlc.priority
priority
Definition: AtlRunQuerySelectorLhcOlc.py:611
TrigConf::L1Threshold::type
const std::string & type() const
Accessor to the threshold type.
Definition: L1ThresholdBase.h:157
TrigConf::ValueWithEtaDependence
class to implement a L1 threshold cut that varies with eta
Definition: L1ThresholdBase.h:35
TrigConf::IsolationLegacy
Definition: L1ThresholdBase.h:264
TrigConf::L1ThrExtraInfoBase::thresholdTypeName
const std::string & thresholdTypeName() const
Definition: L1ThresholdBase.cxx:184
TrigConf::L1Threshold_Calo::load
void load()
Definition: L1ThresholdBase.cxx:241
TrigConf::DataStructure::name
virtual const std::string & name() const final
Definition: DataStructure.cxx:109
TrigConf::DataStructure::m_name
std::string m_name
Definition: DataStructure.h:259
TrigConf::IsolationLegacy::offset
int offset() const
Definition: L1ThresholdBase.h:272
x
#define x
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
L1Threshold.h
TrigConf::Selection::WP::NONE
@ NONE
TrigConf::Selection::WP::HADLOOSE
@ HADLOOSE
TrigConf::Selection::WP::TIGHT12
@ TIGHT12
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TrigConf::Selection::WP::LOOSE35
@ LOOSE35
TrigConf::IsolationLegacy::mincut
int mincut() const
Definition: L1ThresholdBase.h:274
TrigConf::Selection::WP::TIGHT30
@ TIGHT30
TrigConf::L1Threshold_Calo::thrValue100MeV
virtual unsigned int thrValue100MeV(int eta=0) const
as above above but in 100 MeV
Definition: L1ThresholdBase.cxx:284
grepfile.content
string content
Definition: grepfile.py:56
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
TrigConf::L1Threshold::createThreshold
static std::shared_ptr< L1Threshold > createThreshold(const std::string &name, const std::string &type, std::weak_ptr< L1ThrExtraInfoBase > extraInfo, const ptree &data)
static method to create type-specific L1Thresholds
Definition: L1ThresholdBase.cxx:28
TrigConf::L1Threshold::update
virtual void update() override
Update the internal data after modification of the data object.
Definition: L1ThresholdBase.cxx:132
TrigConf::L1Threshold_Calo::thrValue
virtual float thrValue(int eta=0) const override
Accessor to the threshold value for eta-dependent threholds.
Definition: L1ThresholdBase.cxx:272
TrigConf::L1Threshold_Calo::thrValueCounts
virtual unsigned int thrValueCounts(int eta=0) const
Definition: L1ThresholdBase.cxx:278
TrigConf::IsolationLegacy::etamin
int etamin() const
Definition: L1ThresholdBase.h:276
TrigConf::L1Threshold_Calo::update
virtual void update() override
Update the internal data after modification of the data object.
Definition: L1ThresholdBase.cxx:222
TrigConf::L1ThrExtraInfoBase::getExtraInfo
std::optional< std::reference_wrapper< const TrigConf::DataStructure > > getExtraInfo(const std::string &key) const
Definition: L1ThresholdBase.cxx:199
TrigConf::Selection::WP::LOOSE20
@ LOOSE20
TrigConf::L1ThrExtraInfoBase::L1ThrExtraInfoBase
L1ThrExtraInfoBase()=delete
TrigConf::IsolationLegacy::etamax
int etamax() const
Definition: L1ThresholdBase.h:277
TrigConf::L1Threshold::thrValue
virtual float thrValue(int eta=0) const
Accessor to the threshold value for eta-dependent threholds.
Definition: L1ThresholdBase.cxx:127
TrigConf::Selection::WP::MEDIUM20
@ MEDIUM20
TrigConf::IsolationLegacy::slope
int slope() const
Definition: L1ThresholdBase.h:273
PlotSFuncertainty.wp
wp
Definition: PlotSFuncertainty.py:112
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
L1ThresholdBase.h
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::Selection::WP::HADTIGHT
@ HADTIGHT
TrigConf::L1Threshold_Calo::thrValues
virtual ValueWithEtaDependence< float > thrValues() const
access to the list of ThresholdValues in GeV
Definition: L1ThresholdBase.cxx:294
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
TrigConf::energyInCounts
unsigned int energyInCounts(unsigned int energyMeV, unsigned int energyResolutionMeV)
helper funtion to translate energies into counts
Definition: L1ThresholdBase.cxx:18
TrigConf::IsolationLegacy::priority
int priority() const
Definition: L1ThresholdBase.h:278
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrigConf::DataStructure
Base class for Trigger configuration data and wrapper around underlying representation.
Definition: DataStructure.h:37
TrigConf::Selection::WP::LOOSE12
@ LOOSE12
TrigConf::Selection::WP::MEDIUM30
@ MEDIUM30
TrigConf::Selection::WP::HAD
@ HAD
TrigConf::Selection::WP::MEDIUM
@ MEDIUM
TrigConf::Selection::WP::TIGHT
@ TIGHT
TrigConf::Selection::WP::MEDIUM35
@ MEDIUM35
TrigConf::Selection::WP::HADMEDIUM
@ HADMEDIUM
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigConf::L1ThrExtraInfoBase::load
void load()
Definition: L1ThresholdBase.cxx:157
TrigConf::Selection::WP::LOOSE30
@ LOOSE30
TrigConf::L1Threshold::load
void load()
Definition: L1ThresholdBase.cxx:138
TrigConf::L1Threshold_Calo::L1Threshold_Calo
L1Threshold_Calo()=delete
Constructor.
TrigConf::Selection::WP::TIGHT20
@ TIGHT20
TrigConf::L1Threshold_Calo::thrValueMeV
virtual unsigned int thrValueMeV(int eta=0) const
Definition: L1ThresholdBase.cxx:289
TrigConf::IsolationLegacy::upperlimit
int upperlimit() const
Definition: L1ThresholdBase.h:275
python.root_pickle.load
def load(f, use_proxy=1, key=None)
Definition: root_pickle.py:476
TrigConf::L1Threshold_Calo::thrValues100MeV
virtual ValueWithEtaDependence< unsigned int > thrValues100MeV() const
access to the list of ThresholdValues in 100 MeV (for L1Topo multiplicity)
Definition: L1ThresholdBase.cxx:308
TrigConf::IsolationLegacy::IsolationLegacy
IsolationLegacy()=default
LArCellBinning.etamin
etamin
Definition: LArCellBinning.py:137
TrigConf::DataStructure::ptree
boost::property_tree::ptree ptree
Definition: DataStructure.h:40
TrigConf::IsolationLegacy::isobit
int isobit() const
Definition: L1ThresholdBase.h:271
TrigConf::L1Threshold::L1Threshold
L1Threshold()=default
Constructor.
TrigConf::L1ThrExtraInfoBase::hasExtraInfo
bool hasExtraInfo(const std::string &key="") const
Definition: L1ThresholdBase.cxx:190
TrigConf::L1Threshold
Standard L1 threshold configuration.
Definition: L1ThresholdBase.h:125
TrigConf::L1Threshold_Calo::thrValuesMeV
virtual const ValueWithEtaDependence< unsigned int > & thrValuesMeV() const
access to the list of ThresholdValues in MeV
Definition: L1ThresholdBase.cxx:303
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
TrigConf::ValueWithEtaDependence::name
const std::string & name() const
Definition: L1ThresholdBase.h:54