ATLAS Offline Software
Loading...
Searching...
No Matches
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
16
17unsigned int
18TrigConf::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
27std::shared_ptr<TrigConf::L1Threshold>
28TrigConf::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
116TrigConf::L1Threshold::L1Threshold( const std::string & name, const std::string & type,
117 std::weak_ptr<L1ThrExtraInfoBase> extraInfo, const boost::property_tree::ptree & data)
119 m_extraInfo(extraInfo),
120 m_type(type)
121{
122 m_name = name;
123 load();
124}
125
126float
128 return 0;
129}
130
131void
136
137void
139{
140 if( type() == "internal" ) {
141 return;
142 }
143 m_name = getAttribute("name", true, m_name);
144 m_type = getAttribute("type", true, m_type);
146}
147
148
149TrigConf::L1ThrExtraInfoBase::L1ThrExtraInfoBase(const std::string & thrTypeName, const boost::property_tree::ptree & data)
151{
152 m_name = thrTypeName;
153 load();
154}
155
156void
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
179 }
180}
181
182
183const std::string &
188
189bool
190TrigConf::L1ThrExtraInfoBase::hasExtraInfo(const std::string & key) const
191{
192 if( key.empty() ) {
193 return m_extraInfo.size()>0;
194 }
195 return m_extraInfo.count(key)>0;
196}
197
198std::optional<std::reference_wrapper<const TrigConf::DataStructure>>
199TrigConf::L1ThrExtraInfoBase::getExtraInfo( const std::string & key) const
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
212
213TrigConf::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
221void
227
228namespace {
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
240void
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
271float
273{
274 return thrValueMeV(eta) / 1000.0f;
275}
276
277unsigned int
279 auto extraInfo = m_extraInfo.lock();
280 return energyInCounts( thrValueMeV(eta), extraInfo->resolutionMeV() );
281}
282
283unsigned int
287
288unsigned int
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
306
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();
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
326TrigConf::IsolationLegacy::IsolationLegacy( const boost::property_tree::ptree & pt ) {
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
338std::ostream &
339TrigConf::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
346std::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";
357 if (wp == Selection::WP::HADLOOSE)
358 return "HadLoose";
359 if (wp == Selection::WP::HADMEDIUM)
360 return "HadMedium";
361 if (wp == Selection::WP::HADTIGHT)
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";
373 if (wp == Selection::WP::LOOSE50)
374 return "Loose50";
375 if (wp == Selection::WP::LOOSE55)
376 return "Loose55";
377 if (wp == Selection::WP::MEDIUM12)
378 return "Medium12";
379 if (wp == Selection::WP::MEDIUM20)
380 return "Medium20";
381 if (wp == Selection::WP::MEDIUM30)
382 return "Medium30";
383 if (wp == Selection::WP::MEDIUM35)
384 return "Medium35";
385 if (wp == Selection::WP::MEDIUM50)
386 return "Medium50";
387 if (wp == Selection::WP::MEDIUM55)
388 return "Medium55";
389 if (wp == Selection::WP::TIGHT12)
390 return "Tight12";
391 if (wp == Selection::WP::TIGHT20)
392 return "Tight20";
393 if (wp == Selection::WP::TIGHT30)
394 return "Tight30";
395 if (wp == Selection::WP::TIGHT35)
396 return "Tight35";
397 if (wp == Selection::WP::TIGHT50)
398 return "Tight50";
399 if (wp == Selection::WP::TIGHT55)
400 return "Tight55";
401 throw std::runtime_error("Unknown working point " + std::to_string(int(wp)));
402}
403
405TrigConf::Selection::stringToWP(const std::string & wpStr)
406{
407 if (wpStr == "None")
408 return Selection::WP::NONE;
409 if (wpStr == "Loose")
411 if (wpStr == "Medium")
413 if (wpStr == "Tight")
415 if (wpStr == "HadLoose")
417 if (wpStr == "HadMedium")
419 if (wpStr == "HadTight")
421 if (wpStr == "Had") // Had = HadMedium for backward compatibility
423 if (wpStr == "Loose12")
425 if (wpStr == "Loose20")
427 if (wpStr == "Loose30")
429 if (wpStr == "Loose35")
431 if (wpStr == "Loose50")
433 if (wpStr == "Loose55")
435 if (wpStr == "Medium12")
437 if (wpStr == "Medium20")
439 if (wpStr == "Medium30")
441 if (wpStr == "Medium35")
443 if (wpStr == "Medium50")
445 if (wpStr == "Medium55")
447 if (wpStr == "Tight12")
449 if (wpStr == "Tight20")
451 if (wpStr == "Tight30")
453 if (wpStr == "Tight35")
455 if (wpStr == "Tight50")
457 if (wpStr == "Tight55")
459 throw std::runtime_error("Unknown working point name " + wpStr);
460}
Scalar eta() const
pseudorapidity method
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#define x
static const Attributes_t empty
virtual const std::string & name() const final
const ptree & data() const
Access to the underlying data, if needed.
bool hasAttribute(const std::string &key) const
Check for attribute.
DataStructure()
Default constructor, leading to an uninitialized configuration object.
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
boost::property_tree::ptree ptree
const std::string & thresholdTypeName() const
std::map< std::string, DataStructure > m_extraInfo
std::optional< std::reference_wrapper< const TrigConf::DataStructure > > getExtraInfo(const std::string &key) const
bool hasExtraInfo(const std::string &key="") const
virtual void update() override
Update the internal data after modification of the data object.
L1Threshold_Calo()=delete
Constructor.
virtual const ValueWithEtaDependence< unsigned int > & thrValuesMeV() const
access to the list of ThresholdValues in MeV
virtual float thrValue(int eta=0) const override
Accessor to the threshold value for eta-dependent threholds.
virtual ValueWithEtaDependence< unsigned int > thrValues100MeV() const
access to the list of ThresholdValues in 100 MeV (for L1Topo multiplicity)
virtual ValueWithEtaDependence< float > thrValues() const
access to the list of ThresholdValues in GeV
ValueWithEtaDependence< unsigned int > m_etaDepThrValue
eta-dependent threshold value in MeV
virtual unsigned int thrValueMeV(int eta=0) const
virtual unsigned int thrValueCounts(int eta=0) const
unsigned int m_thrValue
threshold value in MeV
virtual ValueWithEtaDependence< unsigned int > thrValuesCounts() const
access to the list of ThresholdValues in energy units
virtual unsigned int thrValue100MeV(int eta=0) const
as above above but in 100 MeV
virtual void update() override
Update the internal data after modification of the data object.
std::string m_type
threshold type
L1Threshold()=default
Constructor.
virtual float thrValue(int eta=0) const
Accessor to the threshold value for eta-dependent threholds.
const std::string & type() const
Accessor to the threshold type.
unsigned int m_mapping
unique identifier amongst thresholds of the same type
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
std::weak_ptr< L1ThrExtraInfoBase > m_extraInfo
static std::string wpToString(WP)
static WP stringToWP(const std::string &)
class to implement a L1 threshold cut that varies with eta
int r
Definition globals.cxx:22
unsigned int energyInCounts(unsigned int energyMeV, unsigned int energyResolutionMeV)
helper funtion to translate energies into counts
std::ostream & operator<<(std::ostream &os, const TrigConf::IsolationLegacy &iso)