ATLAS Offline Software
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
TrigGlobEffCorr::Calculator::Helper Class Reference
Collaboration diagram for TrigGlobEffCorr::Calculator::Helper:

Classes

struct  BindPackedParam
 to decorate the parameters of the findAndBind() function(s) More...
 
struct  NoSuchTrigger
 
struct  Optional
 

Public Member Functions

 Helper (const std::vector< TrigDef > &defs)
 
 Helper (Helper &&)=default
 
bool duplicates () const
 
bool findAndBindFunction ()
 top-level function More...
 

Public Attributes

std::function< bool(Calculator *, const LeptonList &, unsigned, Efficiencies &)> m_formula
 

Protected Member Functions

template<TriggerType object_flag>
bool findAndBindFunction ()
 for combinations with a single flavour present More...
 
template<TriggerType object1_flag, TriggerType object2_flag>
bool findAndBindFunction ()
 for combinations with two flavours present More...
 
template<typename... Trigs>
bool bindFunction ()
 
template<typename Param >
auto extract ()
 

Protected Attributes

std::vector< TrigDefm_defs
 
unsigned m_n1L = 0
 
unsigned m_n2L = 0
 
unsigned m_n3L = 0
 
unsigned m_n4L = 0
 

Detailed Description

Definition at line 211 of file Calculator.h.

Constructor & Destructor Documentation

◆ Helper() [1/2]

Calculator::Helper::Helper ( const std::vector< TrigDef > &  defs)

Definition at line 1226 of file Calculator.cxx.

1226  :
1227  m_formula(nullptr), m_defs(defs)
1228 {
1229 }

◆ Helper() [2/2]

Member Function Documentation

◆ bindFunction()

template<typename... Trigs>
bool Calculator::Helper::bindFunction ( )
protected

Definition at line 1291 of file Calculator.cxx.

1292 {
1293  for(auto& def : m_defs) def.used = false;
1294  using fnptr = bool(Calculator::*)(const LeptonList&, unsigned, typename BindPackedParam<Trigs>::ArgType..., Efficiencies&);
1295  try
1296  {
1297  m_formula = std::bind<fnptr>(&Calculator::globalEfficiency, ::_1, ::_2, ::_3, extract<BindPackedParam<Trigs>>()..., ::_4);
1298  if(std::all_of(m_defs.cbegin(), m_defs.cend(), [](auto& def){return def.used;})) return true;
1299  }
1300  catch(NoSuchTrigger){}
1301  m_formula = nullptr;
1302  return false;
1303 }

◆ duplicates()

bool Calculator::Helper::duplicates ( ) const

Definition at line 1231 of file Calculator.cxx.

1232 {
1233  for(auto itr1=m_defs.cbegin(); itr1!=m_defs.cend(); ++itr1)
1234  for(auto itr2=itr1+1; itr2!=m_defs.cend(); ++itr2)
1235  if(itr1->type==itr2->type && itr1->leg==itr2->leg) return true;
1236  return false;
1237 }

◆ extract()

template<typename Param >
auto Calculator::Helper::extract ( )
protected

Definition at line 1276 of file Calculator.cxx.

1277 {
1278  std::remove_cv_t<std::remove_reference_t<typename Param::ArgType>> trigs;
1279  for(auto& def : m_defs)
1280  {
1281  if(def.used || def.type!=Param::TrigType::type()) continue;
1282  def.used = true;
1283  Param::add(trigs, def);
1284  if(!Param::multiple()) break;
1285  }
1286  if(!Param::optional() && !Param::valid(trigs)) throw NoSuchTrigger();
1287  return trigs;
1288 }

◆ findAndBindFunction() [1/3]

bool Calculator::Helper::findAndBindFunction ( )

top-level function

First check if the trigger combination refers to a single object type

Then try to rely on available formulas for combinations with two object types

As a last resort, maybe factorizing helps

check there's no mixed-flavour trigger involving 'obj_flag'

Definition at line 1394 of file Calculator.cxx.

1395 {
1396  auto countTriggers = [&](auto nlep_flag) { return std::count_if(m_defs.cbegin(), m_defs.cend(), [=](auto& def){return def.type&nlep_flag;}); };
1397  m_n1L = countTriggers(TT_SINGLELEPTON_FLAG);
1398  m_n2L = countTriggers(TT_DILEPTON_FLAG);
1399  m_n3L = countTriggers(TT_TRILEPTON_FLAG);
1400  m_n4L = countTriggers(TT_TETRALEPTON_FLAG);
1401  auto exclusively = [&](auto obj_flags) { return std::none_of(m_defs.cbegin(), m_defs.cend(), [=](auto& def){return def.type&TT_MASK_FLAVOUR&~obj_flags;}); };
1402 
1404  if(exclusively(TT_ELECTRON_FLAG)) return findAndBindFunction<TT_ELECTRON_FLAG>();
1405  if(exclusively(TT_MUON_FLAG)) return findAndBindFunction<TT_MUON_FLAG>();
1406  if(exclusively(TT_PHOTON_FLAG)) return findAndBindFunction<TT_PHOTON_FLAG>();
1407 
1409  bool success = false;
1410  if(exclusively(TT_ELECTRON_FLAG|TT_MUON_FLAG)) success = findAndBindFunction<TT_ELECTRON_FLAG,TT_MUON_FLAG>();
1411  else if(exclusively(TT_ELECTRON_FLAG|TT_PHOTON_FLAG)) success = findAndBindFunction<TT_ELECTRON_FLAG,TT_PHOTON_FLAG>();
1412  else if(exclusively(TT_MUON_FLAG|TT_PHOTON_FLAG)) success = findAndBindFunction<TT_MUON_FLAG,TT_PHOTON_FLAG>();
1413  if(success) return true;
1414 
1416  std::vector<Helper> helpers;
1417  for(auto obj_flag : {TT_ELECTRON_FLAG, TT_MUON_FLAG, TT_PHOTON_FLAG})
1418  {
1419  if(std::any_of(m_defs.cbegin(), m_defs.cend(),
1420  [&](auto& def){ return (def.type&obj_flag) && TriggerProperties(def.type).mixed();})) continue;
1421  std::vector<ImportData::TrigDef> trigs1, trigs2;
1422  std::partition_copy(m_defs.begin(), m_defs.end(), std::back_inserter(trigs1), std::back_inserter(trigs2), [&](auto& def){ return (def.type&obj_flag); });
1423  m_defs.swap(trigs2);
1424  if(!trigs1.size()) continue;
1425  helpers.emplace_back(trigs1);
1426  if(!helpers.back().findAndBindFunction()) return false;
1427  }
1428  if(helpers.size())
1429  {
1430  if(m_defs.size())
1431  {
1432  if(!findAndBindFunction()) return false;
1433  if(helpers.size() == 1) m_formula = std::bind(&Calculator::globalEfficiency_Factorized2, ::_1, ::_2, ::_3,
1434  std::move(m_formula), std::move(helpers[0].m_formula), ::_4);
1435  else if(helpers.size()==2) m_formula = std::bind(&Calculator::globalEfficiency_Factorized3, ::_1, ::_2, ::_3,
1436  std::move(m_formula), std::move(helpers[0].m_formula), std::move(helpers[1].m_formula), ::_4);
1437  else
1438  {
1439  m_formula = nullptr;
1440  return false;
1441  }
1442  }
1443  else
1444  {
1445  if(helpers.size() == 2) m_formula = std::bind(&Calculator::globalEfficiency_Factorized2, ::_1, ::_2, ::_3,
1446  std::move(helpers[0].m_formula), std::move(helpers[1].m_formula), ::_4);
1447  else if(helpers.size() == 3) m_formula = std::bind(&Calculator::globalEfficiency_Factorized3, ::_1, ::_2, ::_3,
1448  std::move(helpers[0].m_formula), std::move(helpers[1].m_formula), std::move(helpers[2].m_formula), ::_4);
1449  else return false;
1450  }
1451  return true;
1452  }
1453 
1454  return false;
1455 }

◆ findAndBindFunction() [2/3]

template<TriggerType object_flag>
bool Calculator::Helper::findAndBindFunction ( )
protected

for combinations with a single flavour present

Definition at line 1306 of file Calculator.cxx.

1307 {
1308  using A = TriggerClass<object_flag>;
1309  using A1L = flat_set<typename A::T_1>;
1310  using A_2sym = typename A::T_2sym;
1311  using A_2asym = typename A::T_2asym;
1312  if(m_n2L + m_n3L + m_n4L == 0)
1313  {
1314  return bindFunction<typename A::T_1>() || bindFunction<A1L>();
1315  }
1316  else if(m_n2L==1 && m_n3L + m_n4L == 0)
1317  {
1318  return bindFunction<A_2sym>() || bindFunction<A_2asym>()
1319  || bindFunction<A_2sym, A1L>() || bindFunction<A_2asym, A1L>();
1320  }
1321  else if(m_n2L==2 && m_n3L + m_n4L == 0)
1322  {
1323  return bindFunction<A_2sym, A_2sym, Optional<A1L>>() || bindFunction<A_2asym, A_2sym, Optional<A1L>>();
1324  }
1325  else if(m_n3L==1 && m_n1L + m_n2L + m_n4L == 0)
1326  {
1327  return bindFunction<typename A::T_3sym>() || bindFunction<typename A::T_3halfsym>();
1328  }
1329  else if(m_n4L==1 && m_n1L + m_n2L + m_n3L == 0)
1330  {
1331  return bindFunction<typename A::T_4sym>();
1332  }
1333  return false;
1334 }

◆ findAndBindFunction() [3/3]

template<TriggerType object1_flag, TriggerType object2_flag>
bool Calculator::Helper::findAndBindFunction ( )
protected

for combinations with two flavours present

this only deals with the presence of mixed triggers

checked if triggers can be factorized = no mixed trigger in the combination.

2 dilepton triggers

3 dilepton triggers

6 dilepton triggers

Definition at line 1337 of file Calculator.cxx.

1338 {
1340  using A = TriggerClass<object_flag1>;
1341  using B = TriggerClass<object_flag2>;
1343  using A_1 = typename A::T_1;
1344  using B_1 = typename B::T_1;
1345  using OA1L = Optional<flat_set<A_1>>;
1346  using OB1L = Optional<flat_set<B_1>>;
1347  using A_2sym = typename A::T_2sym;
1348  using B_2sym = typename B::T_2sym;
1349  using A_2asym = typename A::T_2asym;
1350  using B_2asym = typename B::T_2asym;
1351  using AB_1_1 = typename AB::T_1_1;
1352 
1354  if(m_n1L>0 && m_n2L + m_n3L + m_n4L == 0)
1355  {
1356  return bindFunction<A_1, B_1>() || bindFunction<flat_set<A_1>, flat_set<B_1>>();
1357  }
1358  else if(m_n2L==1 && m_n3L + m_n4L == 0)
1359  { // one dilepton trigger (+ single-lepton triggers)
1360  return bindFunction<AB_1_1>() || bindFunction<AB_1_1, flat_set<A_1>, flat_set<B_1>>();
1361  }
1362  else if(m_n2L>=2 && m_n2L<=6 && m_n3L + m_n4L == 0)
1363  { // several dilepton triggers (+ single-lepton triggers)
1364  return
1366  bindFunction<A_2sym, AB_1_1>() || bindFunction<A_2asym, AB_1_1>()
1367  || bindFunction<B_2sym, AB_1_1>() || bindFunction<B_2asym, AB_1_1>()
1369  || bindFunction<Optional<A_2sym>, Optional<B_2sym>, Optional<AB_1_1>, OA1L, OB1L>()
1370  || bindFunction<Optional<A_2asym>, Optional<B_2sym>, Optional<AB_1_1>, OA1L, OB1L>()
1371  || bindFunction<Optional<A_2sym>, Optional<B_2asym>, Optional<AB_1_1>, OA1L, OB1L>()
1372  || bindFunction<Optional<A_2asym>, Optional<B_2asym>, Optional<AB_1_1>, OA1L, OB1L>()
1374  || bindFunction<Optional<A_2sym>, Optional<A_2sym>, Optional<B_2sym>, Optional<B_2sym>, Optional<AB_1_1>, Optional<AB_1_1>, OA1L, OB1L>()
1375  || bindFunction<Optional<A_2asym>, Optional<A_2sym>, Optional<B_2sym>, Optional<B_2sym>, Optional<AB_1_1>, Optional<AB_1_1>, OA1L, OB1L>()
1376  || bindFunction<Optional<A_2sym>, Optional<A_2sym>, Optional<B_2asym>, Optional<B_2sym>, Optional<AB_1_1>, Optional<AB_1_1>, OA1L, OB1L>()
1377  || bindFunction<Optional<A_2asym>, Optional<A_2sym>, Optional<B_2asym>, Optional<B_2sym>, Optional<AB_1_1>, Optional<AB_1_1>, OA1L, OB1L>();
1378  }
1379  else if(m_n3L==1 && m_n1L + m_n2L + m_n4L == 0)
1380  { // one mixed trilepton trigger
1381  return bindFunction<typename AB::T_2sym_1>() || bindFunction<typename AB::T_1_2sym>()
1382  || bindFunction<typename AB::T_2asym_1>() || bindFunction<typename AB::T_1_2asym>();
1383  }
1384  else if(m_n3L==2 && m_n1L + m_n2L + m_n4L == 0)
1385  { // two mixed trilepton triggers
1386  return bindFunction<typename AB::T_2sym_1, typename AB::T_1_2sym>()
1387  || bindFunction<typename AB::T_2asym_1, typename AB::T_1_2sym>()
1388  || bindFunction<typename AB::T_2sym_1, typename AB::T_1_2asym>()
1389  || bindFunction<typename AB::T_2asym_1, typename AB::T_1_2asym>();
1390  }
1391  return false;
1392 }

Member Data Documentation

◆ m_defs

std::vector<TrigDef> TrigGlobEffCorr::Calculator::Helper::m_defs
protected

Definition at line 223 of file Calculator.h.

◆ m_formula

std::function<bool(Calculator*,const LeptonList&,unsigned,Efficiencies&)> TrigGlobEffCorr::Calculator::Helper::m_formula

Definition at line 218 of file Calculator.h.

◆ m_n1L

unsigned TrigGlobEffCorr::Calculator::Helper::m_n1L = 0
protected

Definition at line 224 of file Calculator.h.

◆ m_n2L

unsigned TrigGlobEffCorr::Calculator::Helper::m_n2L = 0
protected

Definition at line 224 of file Calculator.h.

◆ m_n3L

unsigned TrigGlobEffCorr::Calculator::Helper::m_n3L = 0
protected

Definition at line 224 of file Calculator.h.

◆ m_n4L

unsigned TrigGlobEffCorr::Calculator::Helper::m_n4L = 0
protected

Definition at line 224 of file Calculator.h.


The documentation for this class was generated from the following files:
TrigGlobEffCorr::TT_SINGLELEPTON_FLAG
@ TT_SINGLELEPTON_FLAG
Definition: ImportData.h:36
TrigGlobEffCorr::Efficiencies
Definition: Efficiencies.h:16
TrigGlobEffCorr::TT_MUON_FLAG
@ TT_MUON_FLAG
Definition: ImportData.h:27
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
flat_set
boost::container::flat_set< Key > flat_set
Definition: CheckConfig.cxx:11
TrigGlobEffCorr::TT_ELECTRON_FLAG
@ TT_ELECTRON_FLAG
Definition: ImportData.h:26
dqt_zlumi_alleff_HIST.A
A
Definition: dqt_zlumi_alleff_HIST.py:110
calibdata.valid
list valid
Definition: calibdata.py:45
TrigGlobEffCorr::Calculator::Helper::extract
auto extract()
Definition: Calculator.cxx:1276
TrigGlobEffCorr::Calculator::globalEfficiency_Factorized2
bool globalEfficiency_Factorized2(const LeptonList &leptons, unsigned runNumber, GlobEffFunc func1, GlobEffFunc func2, Efficiencies &globalEfficiencies)
Definition: Calculator.cxx:1065
TrigGlobEffCorr::Calculator::Helper::bindFunction
bool bindFunction()
Definition: Calculator.cxx:1291
TrigGlobEffCorr::TT_PHOTON_FLAG
@ TT_PHOTON_FLAG
Definition: ImportData.h:28
TrigGlobEffCorr::Calculator
Definition: Calculator.h:27
TrigGlobEffCorr::Calculator::Helper::m_n1L
unsigned m_n1L
Definition: Calculator.h:224
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
TrigGlobEffCorr::TT_TETRALEPTON_FLAG
@ TT_TETRALEPTON_FLAG
Definition: ImportData.h:80
TrigGlobEffCorr::TT_TRILEPTON_FLAG
@ TT_TRILEPTON_FLAG
Definition: ImportData.h:54
TrigGlobEffCorr::Calculator::Helper::m_defs
std::vector< TrigDef > m_defs
Definition: Calculator.h:223
TrigGlobEffCorr::Calculator::LeptonList
TrigGlobalEfficiencyCorrectionTool::LeptonList LeptonList
Definition: Calculator.h:28
TrigGlobEffCorr::Calculator::Helper::m_formula
std::function< bool(Calculator *, const LeptonList &, unsigned, Efficiencies &)> m_formula
Definition: Calculator.h:218
dqt_zlumi_alleff_HIST.B
B
Definition: dqt_zlumi_alleff_HIST.py:110
TrigGlobEffCorr::Calculator::globalEfficiency_Factorized3
bool globalEfficiency_Factorized3(const LeptonList &leptons, unsigned runNumber, GlobEffFunc func1, GlobEffFunc func2, GlobEffFunc func3, Efficiencies &globalEfficiencies)
Definition: Calculator.cxx:1074
TrigGlobEffCorr::Calculator::Helper::m_n3L
unsigned m_n3L
Definition: Calculator.h:224
TrigGlobEffCorr::Calculator::Helper::m_n4L
unsigned m_n4L
Definition: Calculator.h:224
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigGlobEffCorr::TT_DILEPTON_FLAG
@ TT_DILEPTON_FLAG
Definition: ImportData.h:41
TrigGlobEffCorr::Calculator::Helper::findAndBindFunction
bool findAndBindFunction()
top-level function
Definition: Calculator.cxx:1394
TrigGlobEffCorr::Calculator::globalEfficiency
auto globalEfficiency(const LeptonList &, unsigned, const Trig1L, Efficiencies &) -> std::enable_if_t< Trig1L::is1L(), bool >
One single-lepton trigger.
Definition: Calculator.cxx:284
TrigGlobEffCorr::TriggerClass
Definition: Trigger.h:307
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
TrigGlobEffCorr::Calculator::Helper::m_n2L
unsigned m_n2L
Definition: Calculator.h:224