ATLAS Offline Software
MuonTriggerScaleFactors.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include <sstream>
6 #include <TRandom3.h>
7 #include "TROOT.h"
8 #include "TH1.h"
9 #include "TH2.h"
10 #include "TFile.h"
11 #include "TKey.h"
12 
13 #include "xAODMuon/MuonContainer.h"
17 
24 
25 #include <iostream>
26 #include <functional>
27 #include <string>
28 #include <cmath>
29 
30 namespace CP {
31  static const double muon_barrel_endcap_boundary = 1.05;
32 
33  const std::map<unsigned int,int> MuonTriggerScaleFactors::m_runNumber_year = {
34  {284484,2015},
35  {311481,2016},
36  {340453,2017},
37  {364292,2018},
38  {440613,2022},
39  {456749,2023}
40  };
41 
43  asg::AsgTool(name),
44  m_systFilter(),
45  m_appliedSystematics(nullptr),
46  m_fileName(),
47  m_efficiencyMap(),
48  m_efficiencyMapReplicaArray(),
49  m_muonquality("Medium"),
50  m_calibration_version("240717_mc23ad"),
51  m_custom_dir(),
52  m_binning("fine"),
53  m_allowZeroSF(false),
54  m_experimental(false),
55  m_forceYear(-1),
56  m_forcePeriod(""),
57  m_replicaTriggerList(),
58  m_replicaSet(),
59  m_nReplicas(100),
60  m_ReplicaRandomSeed(12345) {
61 
62  declareProperty("MuonQuality", m_muonquality); // HighPt,Tight,Medium,Loose,LowPt
63  declareProperty("CalibrationRelease", m_calibration_version);
64  // these are for debugging / testing, *not* for general use!
65  declareProperty("filename", m_fileName);
66  declareProperty("CustomInputFolder", m_custom_dir);
67  declareProperty("Binning", m_binning); // fine or coarse
68  declareProperty("UseExperimental", m_experimental); // enable experimental features like single muon SF
69  //Properties needed for TOY setup for a given trigger: No replicas if m_replicaTriggerList is empty
70  declareProperty("ReplicaTriggerList", m_replicaTriggerList, "List of triggers on which we want to generate stat. uncertainty toy replicas.");
71  declareProperty("NReplicas", m_nReplicas, "Number of generated toy replicas, if replicas are required.");
72  declareProperty("ReplicaRandomSeed", m_ReplicaRandomSeed, "Random seed for toy replica generation.");
73  declareProperty("AllowZeroSF", m_allowZeroSF, "If a trigger is not available will return 0 instead of throwing an error. More difficult to spot configuration issues. Use at own risk");
74  declareProperty("forceYear", m_forceYear, "Only for developers. Never use this in any analysis!!!!!!");
75  declareProperty("forcePeriod", m_forcePeriod, "Only for developers. Never use this in any analysis!!!!!!");
76  }
77 
79 
81  std::string fileName = m_fileName;
82  if (fileName.empty()) {
83  if (year == 2015) fileName = "muontrigger_sf_2015_mc20a_v1.root";
84  else if (year == 2016) fileName = "muontrigger_sf_2016_mc20a_v1.root";
85  else if (year == 2017) fileName = "muontrigger_sf_2017_mc20d_v1.root";
86  else if (year == 2018) fileName = "muontrigger_sf_2018_mc20e_v2.root";
87  else if (year == 2022) fileName = "muontrigger_sf_2022_mc23a_v02.root";
88  else if (year == 2023) fileName = "muontrigger_sf_2023_mc23d_v02.root";
89  else{
90  ATH_MSG_WARNING("There is no SF file for year " << year << " yet");
91  return StatusCode::SUCCESS;
92  }
93  }
94 
95  TDirectory* origDir = gDirectory;
96 
97  std::string filePath;
98 
99  if (m_custom_dir.empty()) {
100  filePath = PathResolverFindCalibFile(Form("MuonEfficiencyCorrections/%s/%s", m_calibration_version.c_str(), fileName.c_str()));
101  if (filePath.empty()) {
102  ATH_MSG_ERROR("Unable to resolve the input file " << fileName << " via PathResolver.");
103  }
104  }
105  else {
106  ATH_MSG_INFO("Note: setting up with user specified input file location " << m_custom_dir << " - this is not encouraged!");
107  filePath = PathResolverFindCalibFile(Form("%s/%s", m_custom_dir.c_str(), fileName.c_str()));
108  }
109 
110  TFile* file = TFile::Open(filePath.c_str());
111 
112  if (file == nullptr || !file->IsOpen()) {
113  ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize Couldn't open file " << filePath);
114  return StatusCode::FAILURE;
115  }
116  TDirectory* tempDir = getTemporaryDirectory();
117  tempDir->cd();
118 
119  static const std::vector<std::string> type { "data", "mc" };
120  static const std::vector<std::string> region { "barrel", "endcap" };
121  static const std::vector<std::string> systematic { "nominal", "stat_up", "stat_down", "syst_up", "syst_down" };
122  if(m_muonquality.compare("LowPt") == 0)
123  m_muonquality = "Medium";
124  const std::string quality = m_muonquality;
125  TDirectory* qualityDirectory = file->GetDirectory(m_muonquality.c_str());
126  if (qualityDirectory == nullptr) {
127  ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize cannot find directory with selected quality");
128  return StatusCode::FAILURE;
129  }
130  TKey* periodKey;
131  TIter nextPeriod(qualityDirectory->GetListOfKeys());
132  while ((periodKey = (TKey*) nextPeriod())) {
133  if (not periodKey->IsFolder()) continue;
134  TDirectory* periodDirectory = qualityDirectory->GetDirectory(periodKey->GetName());
135  std::string periodName = std::string(periodKey->GetName());
136  std::string periodName_InMap = periodName.substr(std::string("Period").size(), periodName.size());
137  YearPeriod period = YearPeriod(year, periodName_InMap);
138  TKey* triggerKey;
139  TIter nextTrigger(periodDirectory->GetListOfKeys());
140  while ((triggerKey = (TKey*) nextTrigger())) {
141  if (not triggerKey->IsFolder()) continue;
142  TDirectory* triggerDirectory = periodDirectory->GetDirectory(triggerKey->GetName());
143  std::string triggerName = std::string(triggerKey->GetName());
144  if(!std::set<std::string>{"HLT_mu26_ivarmedium", "HLT_mu50", "HLT_mu26_ivarmedium_OR_HLT_mu50"}.count(triggerName) && m_binning == "coarse"){
145  ATH_MSG_DEBUG("Coarse binning not supported for di-muon trigger legs at the moment");
146  continue;
147  }
148  for (const auto& iregion : region) {
149  bool isBarrel = iregion.find("barrel") != std::string::npos;
150  for (const auto& itype : type) {
151  bool isData = itype.find("data") != std::string::npos;
152  std::string histname = ("_MuonTrigEff_" + periodName + "_" + triggerName + "_" + quality + "_" + "_EtaPhi_" + m_binning + "_" + iregion + "_" + itype);
153  for (const auto& isys : systematic) {
154  if (itype.find("data") != std::string::npos && isys.find("syst") != std::string::npos) continue;
155  std::string path = "eff_etaphi_" + m_binning + "_" + iregion + "_" + itype + "_" + isys;
156  TH2* hist = dynamic_cast<TH2*>(triggerDirectory->Get(path.c_str()));
157  if (not hist) {
158 
159  ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize " << path << " not found under trigger " << triggerName << " and period " << periodName << " for year: " << year);
160  continue;
161  }
162  hist->SetDirectory(0);
163 
164  EffiHistoIdent HistoId = EffiHistoIdent(period, encodeHistoName(periodName_InMap, triggerName, isData, isys, isBarrel));
165  if (m_efficiencyMap.find(HistoId) != m_efficiencyMap.end()) {
166  ATH_MSG_FATAL("MuonTriggerScaleFactors::initialize(): histogram " << path << " is duplicated for year" << year << " in period " << periodName);
167  return StatusCode::FAILURE;
168  }
169  m_efficiencyMap.insert(std::pair<EffiHistoIdent, TH1_Ptr>(HistoId, std::shared_ptr < TH1 > (hist)));
170 
171  }
172  //If the trigger is chosen for toy evaluation, generate all the replicas from
173  // NOMINAL with STAT variations stored in the data hist, load them in corresponding vector
174  if (m_replicaSet.find(triggerName) != m_replicaSet.end() && itype.find("data") != std::string::npos) {
175 
176  TH1_Ptr Nominal_H = getEfficiencyHistogram(year, periodName, triggerName, isData, "nominal", isBarrel);
177  TH1_Ptr StatUp_H = getEfficiencyHistogram(year, periodName, triggerName, isData, "stat_up", isBarrel);
178 
179  TH1_Ptr tmp_h2 = TH1_Ptr(dynamic_cast<TH2F*>(Nominal_H->Clone(Form("tmp_h2_%s", Nominal_H->GetName()))));
180  const int xbins = tmp_h2->GetNbinsX(), ybins = tmp_h2->GetNbinsY();
181  for (int x_i = 0; x_i <= xbins; ++x_i) {
182  for (int y_i = 0; y_i <= ybins; ++y_i) {
183  double statErr = std::abs(tmp_h2->GetBinContent(x_i, y_i) - StatUp_H->GetBinContent(x_i, y_i));
184  tmp_h2->SetBinError(x_i, y_i, statErr);
185  }
186  }
188  }
189  }
190  }
191  }
192  }
193  file->Close();
194  delete file;
195  origDir->cd();
196  return StatusCode::SUCCESS;
197  }
198  // ==================================================================================
199  // == MuonTriggerScaleFactors::initialize()
200  // ==================================================================================
202 
203  ATH_MSG_INFO("MuonQuality = '" << m_muonquality << "'");
204  ATH_MSG_INFO("Binning = '" << m_binning << "'");
205  ATH_MSG_INFO("CalibrationRelease = '" << m_calibration_version << "'");
206  ATH_MSG_INFO("CustomInputFolder = '" << m_custom_dir << "'");
207  ATH_MSG_INFO("AllowZeroSF = " << m_allowZeroSF);
208  ATH_MSG_INFO("experimental = " << m_experimental);
209 
211 
212  if (registerSystematics() != StatusCode::SUCCESS) {
213  return StatusCode::FAILURE;
214  }
215 
216  if (applySystematicVariation(CP::SystematicSet()) != StatusCode::SUCCESS) {
217  ATH_MSG_ERROR("Could not configure for nominal settings");
218  return StatusCode::FAILURE;
219  }
220  // Initialize indexes of replicas for trigges which are asked
221  for (auto trigToy : m_replicaTriggerList)
222  m_replicaSet.insert(trigToy);
223 
224  ATH_MSG_INFO("MuonTriggerScaleFactors::initialize");
225  constexpr auto years_to_run = std::to_array<int>({2015, 2016, 2017, 2018, 2022, 2023});
226  for (const int &year: years_to_run) {
228  }
229  return StatusCode::SUCCESS;
230  }
231 
232  CorrectionCode MuonTriggerScaleFactors::getTriggerScaleFactor(const xAOD::Muon& muon, Double_t& triggersf, const std::string& trigger) const {
233  if(!m_experimental){
234  ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor This is an experimental function. If you really know what you are doing set UseExperimental property.");
235  return CorrectionCode::Error;
236  }
237 
238  if (trigger.empty()) {
239  ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor Trigger must have value.");
240  return CorrectionCode::Error;
241  }
242 
243  TrigMuonEff::Configuration configuration;
244 
245  if (trigger == "HLT_mu8noL1")
246  ATH_MSG_WARNING("What you are trying to do is not correct. For di-muon triggers you should get the efficiency with getTriggerEfficiency and compute the SF by yourself.");
247  else if (trigger.find("HLT_2mu10") != std::string::npos || trigger.find("HLT_2mu14") != std::string::npos)
248  ATH_MSG_WARNING("Di-muon trigger scale factors for single reco muons are not supported!");
249  else
250  return GetTriggerSF(triggersf, configuration, muon, trigger);
251  return CorrectionCode::Ok;
252  }
253 
254  CorrectionCode MuonTriggerScaleFactors::getTriggerScaleFactor(const xAOD::MuonContainer& mucont, Double_t& triggersf, const std::string& trigger) const{
255  if (trigger.empty()) {
256  ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor Trigger must have value.");
257  return CorrectionCode::Error;
258  }
259 
260  TrigMuonEff::Configuration configuration;
261 
262  if (trigger == "HLT_mu8noL1") {
263  ATH_MSG_WARNING("What you are trying to do is not correct. For di-muon triggers you should get the efficiency with getTriggerEfficiency and compute the SF by yourself.");
264  }
265  else if (trigger.find("HLT_2mu10") != std::string::npos || trigger.find("HLT_2mu14") != std::string::npos) {
266  CorrectionCode cc = GetTriggerSF_dimu(triggersf, configuration, mucont, trigger);
267  return cc;
268  } else {
269  CorrectionCode cc = GetTriggerSF(triggersf, configuration, mucont, trigger);
270  return cc;
271  }
272  return CorrectionCode::Ok;
273  }
274 
275  // ==================================================================================
276  // == MuonTriggerScaleFactors::getReplica_index
277  // ==================================================================================
278  // Gets replica index correponding to the toy.
279  // Also checks if the sys_name contains "MCTOY" and if the trigger has replicas generated.
280  // Returns -1 if conditions are note satisfied
281  int MuonTriggerScaleFactors::getReplica_index(const std::string& sysBaseName, const std::string& trigStr) const{
282  if (m_replicaSet.find(trigStr) == m_replicaSet.end()) return -1; //No toys for this trigger
283  std::size_t pos = sysBaseName.find("MCTOY");
284  if (pos == std::string::npos) return -1; //sys variation not affected by TOYS
285  return atoi(sysBaseName.substr(pos + 5, pos + 8).c_str()); //toys for this trigger are around get the 3-digit number
286  }
287 
288  CorrectionCode MuonTriggerScaleFactors::getTriggerEfficiency(const xAOD::Muon& mu, Double_t& efficiency, const std::string& trigger, Bool_t dataType) const{
289  if (trigger.empty()) {
290  ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerEfficiency Trigger must have value.");
291  return CorrectionCode::Error;
292  }
293  TrigMuonEff::Configuration configuration;
294  configuration.isData = dataType;
295  configuration.replicaIndex = -1;
296  Int_t threshold;
298  if (result != CorrectionCode::Ok) return result;
299  if (mu.pt() < threshold) {
300  efficiency = 0;
301  return CorrectionCode::Ok;
302  }
303 
304  // Pre-define uncertainty variations
305  static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
306  static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
307  static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
308  static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
309 
310  std::string systype = "";
311  if (appliedSystematics().matchSystematic(syst_down) && !dataType) {
312  systype = "syst_down";
313  } else if (appliedSystematics().matchSystematic(syst_up) && !dataType) {
314  systype = "syst_up";
315  } else if (appliedSystematics().matchSystematic(stat_down)) {
316  systype = "stat_down";
317  } else if (appliedSystematics().matchSystematic(stat_up)) {
318  systype = "stat_up";
319  } else {
320  systype = "nominal";
321  }
322 
323  // Toys, if found, will overwrite the data hists stat with the generated toy
324  //+++++++++++++
325  // The best way is the use of filterByName with the 000MCTOY at the end. See:
326  // if( !(appliedSystematics().filterByBaseName("MUON_EFF_Trig_MCTOY000")).empty()){//The following is a hack!!!
327  //++++++++++THE FOLLOWING IS A PARTIAL HACK!!!
328  if (!appliedSystematics().empty() && configuration.isData == true) {
329  configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
330  if (configuration.replicaIndex != -1) systype = "replicas";
331  }
332  CorrectionCode cc = getMuonEfficiency(efficiency, configuration, mu, trigger, systype);
333  return cc;
334  }
335 
337  // Private functions //
339 
340  // ==================================================================================
341  // == MuonTriggerScaleFactors::generateReplicas
342  // ==================================================================================
343  // Generate replicas of h for Toys with each bin of h varied with Gaussian distribution
344  // with mean from bin content and sigma from bin error
345  std::vector<TH1_Ptr> MuonTriggerScaleFactors::generateReplicas(TH1_Ptr h, int nrep, int seed) const {
346  TRandom3 Rndm(seed);
347  std::vector<TH1_Ptr> replica_v;
348  const int xbins = h->GetNbinsX(), ybins = h->GetNbinsY();
349 
350  for (int t = 0; t < nrep; ++t) {
351  TH2* replica = dynamic_cast<TH2*>(h->Clone(Form("rep%d_%s", t, h->GetName())));
352 
353  for (int x_i = 0; x_i <= xbins; ++x_i) {
354  for (int y_i = 0; y_i <= ybins; ++y_i) {
355  replica->SetBinContent(x_i, y_i, Rndm.Gaus(h->GetBinContent(x_i, y_i), h->GetBinError(x_i, y_i)));
356  }
357  }
358  replica_v.push_back(TH1_Ptr(replica));
359  }
360  return replica_v;
361  }
362 
363  bool MuonTriggerScaleFactors::isTriggerSupported(const std::string& trigger) const{
364  TH1_Ptr H1 = getEfficiencyHistogram(trigger, true, "nominal");
365  return H1.get() != nullptr;
366  }
367 
368  int MuonTriggerScaleFactors::getBinNumber(const xAOD::Muon& muon, const std::string& trigger) const{
369  if(!m_experimental){
370  ATH_MSG_ERROR("MuonTriggerScaleFactors::getTriggerScaleFactor This is an experimental function. If you really know what you are doing set UseExperimental property.");
371  return CorrectionCode::Error;
372  }
373 
374  const double mu_eta = muon.eta();
375  const double mu_phi = muon.phi();
376  bool isBarrel = std::abs(mu_eta) < muon_barrel_endcap_boundary;
377  TH1_Ptr cit = getEfficiencyHistogram(trigger, true, "nominal", isBarrel);
378  if(!cit.get()){
379  if(!m_allowZeroSF)
380  ATH_MSG_ERROR("Could not find efficiency map for muon with eta: " << mu_eta << " and phi: " << mu_phi << ". Something is inconsistent. Please check your settings for year, mc and trigger." );
381  return -1;
382  }
383  auto eff_h2 = cit;
384  double mu_phi_corr = mu_phi;
385  if (mu_phi_corr < eff_h2->GetYaxis()->GetXmin()) mu_phi_corr += 2.0 * M_PI;
386  if (mu_phi_corr > eff_h2->GetYaxis()->GetXmax()) mu_phi_corr -= 2.0 * M_PI;
387  return eff_h2->FindFixBin(mu_eta, mu_phi_corr);
388  }
389 
390  unsigned int MuonTriggerScaleFactors::encodeHistoName(const std::string& period, const std::string& Trigger, bool isData, const std::string& Systematic, bool isBarrel) const {
391  //keep the string as short as possible
392  const std::string histName = period + "_" + Trigger + "_" + (isBarrel ? "b" : "e") + "_" + (isData ? "data" : "mc") + Systematic;
393  return std::hash<std::string>()(histName);
394  }
395 
396  unsigned int MuonTriggerScaleFactors::encodeHistoName(const std::string& Trigger, const TrigMuonEff::Configuration& configuration, const std::string& Systematic, bool isBarrel) const {
397  //keep the string as short as possible
398  return encodeHistoName(getDataPeriod(), Trigger, configuration.isData, Systematic, isBarrel);
399 
400  }
401  TH1_Ptr MuonTriggerScaleFactors::getEfficiencyHistogram(unsigned int year, const std::string& period, const std::string& trigger, bool isData, const std::string& Systematic, bool isBarrel) const {
403  EfficiencyMap::const_iterator Itr = m_efficiencyMap.find(Ident);
404 
405  if (Itr == m_efficiencyMap.end()) {
406  return TH1_Ptr();
407  }
408  return Itr->second;
409  }
410  TH1_Ptr MuonTriggerScaleFactors::getEfficiencyHistogram(const std::string& trigger, bool isData, const std::string& Systematic, bool isBarrel) const {
411  unsigned int run = getRunNumber();
412  return getEfficiencyHistogram(getYear(run), getDataPeriod(run), trigger, isData, Systematic, isBarrel);
413  }
414 
415  CorrectionCode MuonTriggerScaleFactors::getMuonEfficiency(Double_t& eff, const TrigMuonEff::Configuration& configuration, const xAOD::Muon& muon, const std::string& trigger, const std::string& systematic) const{
416  const double mu_eta = muon.eta();
417  const double mu_phi = muon.phi();
418  bool isBarrel = std::abs(mu_eta) < muon_barrel_endcap_boundary;
419 
420  TH1_Ptr eff_h2 = nullptr;
421  if (configuration.replicaIndex >= 0) { //Only look into the replicas if asking for them
422 
423  unsigned int run = getRunNumber();
425  std::map<EffiHistoIdent, std::vector<TH1_Ptr> >::const_iterator cit = m_efficiencyMapReplicaArray.find(Ident);
426  if (cit == m_efficiencyMapReplicaArray.end()) {
427  if (m_allowZeroSF) {
428  ATH_MSG_WARNING("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Returning efficiency = 0.");
429  eff = 0.;
430  return CorrectionCode::Ok;
431  }
432 
433  else {
434  ATH_MSG_ERROR("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Please check how you set up the tool.");
436  }
437  }
438 
439  if (configuration.replicaIndex >= (int) cit->second.size()) {
440  ATH_MSG_ERROR("MuonTriggerScaleFactors::getMuonEfficiency ; index for replicated histograms is out of range.");
442  }
443 
444  eff_h2 = cit->second[configuration.replicaIndex];
445  } else { //Standard case, look into the usual eff map
446  TH1_Ptr cit = getEfficiencyHistogram(trigger, configuration.isData, systematic, isBarrel);
447  if (cit.get() == nullptr) {
448  if (m_allowZeroSF) {
449  ATH_MSG_WARNING("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Returning efficiency = 0.");
450  eff = 0.;
451  return CorrectionCode::Ok;
452  } else {
453  ATH_MSG_ERROR("Could not find what you are looking for in the efficiency map. The trigger you are looking for, year and mc are not consistent, or the trigger is unavailable in this data period. Please check how you set up the tool.");
455  }
456  }
457  eff_h2 = cit;
458  }
459 
460  double mu_phi_corr = mu_phi;
461  if (mu_phi_corr < eff_h2->GetYaxis()->GetXmin()) mu_phi_corr += 2.0 * M_PI;
462  if (mu_phi_corr > eff_h2->GetYaxis()->GetXmax()) mu_phi_corr -= 2.0 * M_PI;
463 
464  const int bin = eff_h2->FindFixBin(mu_eta, mu_phi_corr);
465  const double efficiency = eff_h2->GetBinContent(bin);
466 
467  eff = efficiency;
468 
469  ATH_MSG_DEBUG("getMuonEfficiency [eta,phi,phi_corr]=[" << mu_eta << "," << mu_phi << "," << mu_phi_corr << "], ibin=" << bin << " eff=" << eff);
470 
471  return CorrectionCode::Ok;
472 
473  }
474 
475  CorrectionCode MuonTriggerScaleFactors::GetTriggerSF_dimu(Double_t& TriggerSF, TrigMuonEff::Configuration& configuration, const xAOD::MuonContainer& mucont, const std::string& trigger) const{
476 
477  if (mucont.size() != 2) {
478  ATH_MSG_FATAL("MuonTriggerScaleFactors::GetTriggerSF;Currently dimuon trigger chains only implemented for events with exactly 2 muons.");
479  }
480  ATH_MSG_DEBUG("The trigger that you choose : " << trigger);
481 
482  Double_t eff_data = 0;
483  Double_t eff_mc = 0;
484 
485  std::string data_err = "";
486  std::string mc_err = "";
487 
488  if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", -1))) {
489  data_err = "nominal";
490  mc_err = "syst_up";
491  } else if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", 1))) {
492  data_err = "nominal";
493  mc_err = "syst_down";
494  } else if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", -1))) {
495  data_err = "stat_down";
496  mc_err = "nominal";
497  } else if (appliedSystematics().matchSystematic(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", 1))) {
498  data_err = "stat_up";
499  mc_err = "nominal";
500  } else {
501  data_err = "nominal";
502  mc_err = "nominal";
503  }
504 
505  //Toys, if found, will overwrite the data hists with the sys generated with one toy
506  //+++++++++++++
507  //The best way is the use of filterByName with the 000MCTOY at the end. See:
508  // if( !(appliedSystematics().filterByBaseName("MUON_EFF_Trig_MCTOY000")).empty()){//The following is a hack!!!
509  //++++++++++THE FOLLOWING IS A PARTIAL HACK!!!
510  if (!appliedSystematics().empty()) {
511  configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
512  if (configuration.replicaIndex != -1) data_err = "replicas";
513  }
514 
515  configuration.isData = true;
516  CorrectionCode result = getDimuonEfficiency(eff_data, configuration, mucont, trigger, data_err);
517  if (result != CorrectionCode::Ok) return result;
518 
519  configuration.isData = false;
520  configuration.replicaIndex = -1;
521  result = getDimuonEfficiency(eff_mc, configuration, mucont, trigger, mc_err);
522  if (result != CorrectionCode::Ok) return result;
523 
524  double event_SF = 1.;
525 
526  if (std::abs(1. - eff_mc) > 0.0001) {
527  event_SF = eff_data / eff_mc;
528  }
529 
530  TriggerSF = event_SF;
531  return CorrectionCode::Ok;
532  }
533 
534  CorrectionCode MuonTriggerScaleFactors::GetTriggerSF(Double_t& TriggerSF, TrigMuonEff::Configuration& configuration, const xAOD::MuonContainer& mucont, const std::string& trigger) const{
535  Int_t threshold;
537  if (result != CorrectionCode::Ok) return result;
538 
539  double rate_not_fired_data = 1.;
540  double rate_not_fired_mc = 1.;
541 
542  for (const auto mu : mucont) {
543 
544  double eff_data = 0., eff_mc = 0.;
545 
546  if (mu->pt() < threshold) {
547 
548  eff_data = 0.;
549  eff_mc = 0.;
550 
551  } else {
552 
553  std::string muon_trigger_name = trigger;
554  std::string data_err = "";
555  std::string mc_err = "";
556 
557  // Pre-define uncertainty variations
558  static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
559  static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
560  static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
561  static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
562 
563  if (appliedSystematics().matchSystematic(syst_down)) {
564  data_err = "nominal";
565  mc_err = "syst_up";
566  } else if (appliedSystematics().matchSystematic(syst_up)) {
567  data_err = "nominal";
568  mc_err = "syst_down";
569  } else if (appliedSystematics().matchSystematic(stat_down)) {
570  data_err = "stat_down";
571  mc_err = "nominal";
572  } else if (appliedSystematics().matchSystematic(stat_up)) {
573  data_err = "stat_up";
574  mc_err = "nominal";
575  } else {
576  data_err = "nominal";
577  mc_err = "nominal";
578  }
579 
580  //Toys, if found, will overwrite the data hists, on which toys for stat uncertainty have been generated
581  //+++++++++++++
582  //The best way is the use of filterByName with the 000MCTOY at the end. See:
583  // if( !(appliedSystematics().filterByBaseName("MUON_EFF_Trig_MCTOY000")).empty()){//The following is a hack!!!
584  //++++++++++The following is a hack!!!
585  if (!appliedSystematics().empty()) {
586  configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
587  if (configuration.replicaIndex != -1) data_err = "replicas";
588  }
589 
590  configuration.isData = true;
591  CorrectionCode result_data = getMuonEfficiency(eff_data, configuration, *mu, muon_trigger_name, data_err);
592  if (result_data != CorrectionCode::Ok) return result_data;
593  configuration.isData = false;
594  configuration.replicaIndex = -1;
595  CorrectionCode result_mc = getMuonEfficiency(eff_mc, configuration, *mu, muon_trigger_name, mc_err);
596  if (result_mc != CorrectionCode::Ok) return result_mc;
597  }
598  rate_not_fired_data *= (1. - eff_data);
599  rate_not_fired_mc *= (1. - eff_mc);
600  }
601 
602  double event_SF = 1.;
603  if (1 - rate_not_fired_data == 0) event_SF = 0;
604  if ((mucont.size()) and (std::abs(1. - rate_not_fired_mc) > 0.0001)) {
605 
606  event_SF = (1. - rate_not_fired_data) / (1. - rate_not_fired_mc);
607  }
608  TriggerSF = event_SF;
609 
610  return CorrectionCode::Ok;
611  }
612 
613  CorrectionCode MuonTriggerScaleFactors::GetTriggerSF(Double_t& TriggerSF, TrigMuonEff::Configuration& configuration, const xAOD::Muon& mu, const std::string& trigger) const{
614  Int_t threshold;
616  if (result != CorrectionCode::Ok)
617  return result;
618 
619  double eff_data = 0., eff_mc = 0.;
620 
621  if (mu.pt() < threshold) {
622  eff_data = 0.;
623  eff_mc = 0.;
624  TriggerSF = 1.;
625  return CorrectionCode::Ok;
626  }
627 
628  std::string muon_trigger_name = trigger;
629  std::string data_err = "";
630  std::string mc_err = "";
631 
632  // Pre-define uncertainty variations
633  static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
634  static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
635  static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
636  static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
637 
638  if (appliedSystematics().matchSystematic(syst_down)) {
639  data_err = "nominal";
640  mc_err = "syst_up";
641  } else if (appliedSystematics().matchSystematic(syst_up)) {
642  data_err = "nominal";
643  mc_err = "syst_down";
644  } else if (appliedSystematics().matchSystematic(stat_down)) {
645  data_err = "stat_down";
646  mc_err = "nominal";
647  } else if (appliedSystematics().matchSystematic(stat_up)) {
648  data_err = "stat_up";
649  mc_err = "nominal";
650  } else {
651  data_err = "nominal";
652  mc_err = "nominal";
653  }
654 
655  if (!appliedSystematics().empty()) {
656  configuration.replicaIndex = getReplica_index(appliedSystematics().begin()->basename(), trigger);
657  if (configuration.replicaIndex != -1) data_err = "replicas";
658  }
659 
660  configuration.isData = true;
661  CorrectionCode result_data = getMuonEfficiency(eff_data, configuration, mu, muon_trigger_name, data_err);
662  if (result_data != CorrectionCode::Ok)
663  return result_data;
664  configuration.isData = false;
665  configuration.replicaIndex = -1;
666  CorrectionCode result_mc = getMuonEfficiency(eff_mc, configuration, mu, muon_trigger_name, mc_err);
667  if (result_mc != CorrectionCode::Ok)
668  return result_mc;
669  if (eff_data == 0)
670  TriggerSF = 0;
671  if (std::abs(eff_mc) > 0.0001)
672  TriggerSF = eff_data / eff_mc;
673  return CorrectionCode::Ok;
674  }
675 
676  CorrectionCode MuonTriggerScaleFactors::getDimuonEfficiency(Double_t& eff, const TrigMuonEff::Configuration& configuration, const xAOD::MuonContainer& mucont, const std::string& chain, const std::string& systematic) const{
677 
678  std::string trigger = getTriggerCorrespondingToDimuonTrigger(chain);
679  Int_t threshold;
681  if (result != CorrectionCode::Ok) return result;
682 
684  xAOD::MuonContainer::const_iterator mu2 = mucont.begin() + 1;
685 
686  Double_t eff1 = 0;
687  if ((**mu1).pt() > threshold) {
688  CorrectionCode result1 = getMuonEfficiency(eff1, configuration, (**mu1), trigger, systematic);
689  if (result1 != CorrectionCode::Ok) return result1;
690  }
691  Double_t eff2 = 0;
692  if ((**mu2).pt() > threshold) {
693  CorrectionCode result2 = getMuonEfficiency(eff2, configuration, (**mu2), trigger, systematic);
694  if (result2 != CorrectionCode::Ok) return result2;
695  }
696 
697  eff = eff1 * eff2;
698  return CorrectionCode::Ok;
699  }
700 
701  std::string MuonTriggerScaleFactors::getTriggerCorrespondingToDimuonTrigger(const std::string& trigger) const {
702  if (trigger.find("2mu10") != std::string::npos) return "HLT_mu10";
703  if (trigger.find("2mu14") != std::string::npos) return "HLT_mu14";
704  throw std::runtime_error("Unknown dimuon trigger");
705  }
706 
707  CorrectionCode MuonTriggerScaleFactors::getThreshold(Int_t& threshold, const std::string& trigger) const{
708  std::size_t index = trigger.find("HLT_mu");
709  if (index != std::string::npos) {
710  std::string rawNumber = trigger.substr(index + 6);
711  if (!rawNumber.empty() && isdigit(rawNumber[0])) {
712  std::stringstream(rawNumber) >> threshold;
713  if (threshold < 10) threshold = 10000;
714  else threshold = (threshold + 1) * 1000;
715  return CorrectionCode::Ok;
716  }
717  }
718  ATH_MSG_ERROR("MuonTriggerScaleFactors::getThreshold Could not extract threshold for trigger " << trigger);
719  return CorrectionCode::Error;
720  }
721 
722  unsigned int MuonTriggerScaleFactors::getYear(unsigned int run) const {
723  if(m_forceYear != -1){
724  return m_forceYear;
725  }
726 
727  int year=2050;
728  auto lower = m_runNumber_year.lower_bound(run);
729  if (lower != m_runNumber_year.end()){
730  year=lower->second;
731  }
732  return year;
733  }
734 
736  return getDataPeriod(getRunNumber());
737  }
738 
739  std::string MuonTriggerScaleFactors::getDataPeriod(unsigned int run) const {
740  return getDataPeriod(run, getYear(run));
741  }
742 
743  std::string MuonTriggerScaleFactors::getDataPeriod(unsigned int runNumber, unsigned year) const {
744  if(!m_forcePeriod.empty())
745  return m_forcePeriod;
746  if (year == 2015) {
747  if (runNumber >= 266904 && runNumber <= 272531) return "AC";
748  else if (runNumber >= 276073 && runNumber <= 276954) return "D";
749  else if (runNumber >= 278727 && runNumber <= 279928) return "E";
750  else if (runNumber >= 279932 && runNumber <= 280422) return "F";
751  else if (runNumber >= 280423 && runNumber <= 281075) return "G";
752  else if (runNumber >= 281130 && runNumber <= 281411) return "H";
753  else if (runNumber >= 281662 && runNumber <= 282482) return "I"; // special ALFA run
754  else if (runNumber >= 282625 && runNumber <= 284484) return "J";
755  }
756  else if (year == 2016) {
757  if (runNumber >= 296939 && runNumber <= 300287) return "A";
758  else if (runNumber >= 300345 && runNumber <= 300908) return "B";
759  else if (runNumber >= 301912 && runNumber <= 302393) return "C";
760  else if (runNumber >= 302737 && runNumber <= 302872) return "D1D3";
761  else if (runNumber >= 302919 && runNumber <= 303560) return "D4D8";
762  else if (runNumber >= 303638 && runNumber <= 303892) return "E";
763  else if (runNumber >= 303943 && runNumber <= 304494) return "F";
764  else if (runNumber >= 305291 && runNumber <= 306714) return "G";
765  else if (runNumber >= 307124 && runNumber <= 308084) return "I";
766  else if (runNumber >= 309311 && runNumber <= 309759) return "K";
767  else if (runNumber >= 310015 && runNumber <= 311481) return "L";
768  }
769  else if (year == 2017) {
770  if (runNumber >= 324320 && runNumber <= 325558) return "A";
771  else if (runNumber >= 325713 && runNumber <= 328393) return "B";
772  else if (runNumber >= 329385 && runNumber <= 330470) return "C";
773  else if (runNumber >= 330857 && runNumber <= 332304) return "D";
774  else if (runNumber >= 332720 && runNumber <= 334779) return "E";
775  else if (runNumber >= 334842 && runNumber <= 335290) return "F";
776  else if (runNumber >= 336497 && runNumber <= 336782) return "H";
777  else if (runNumber >= 336832 && runNumber <= 337833) return "I";
778  else if (runNumber >= 338183 && runNumber <= 340453) return "K";
779  }
780  else if (year == 2018) {
781  if (runNumber >= 348197 && runNumber <= 348836) return "A";
782  else if (runNumber >= 348885 && runNumber <= 349533) return "B";
783  else if (runNumber >= 349534 && runNumber <= 350220) return "C";
784  else if (runNumber >= 350310 && runNumber <= 352107) return "D";
785  else if (runNumber >= 352123 && runNumber <= 352137) return "E";
786  else if (runNumber >= 352274 && runNumber <= 352514) return "F";
787  else if (runNumber >= 354107 && runNumber <= 354494) return "G";
788  else if (runNumber >= 354826 && runNumber <= 355224) return "H";
789  else if (runNumber >= 355261 && runNumber <= 355273) return "I";
790  else if (runNumber >= 355331 && runNumber <= 355468) return "J";
791  else if (runNumber >= 355529 && runNumber <= 356259) return "K";
792  else if (runNumber >= 357050 && runNumber <= 359171) return "L";
793  else if (runNumber >= 359191 && runNumber <= 360414) return "M";
794  else if (runNumber >= 361635 && runNumber <= 361696) return "N";
795  else if (runNumber >= 361738 && runNumber <= 363400) return "O";
796  else if (runNumber >= 363664 && runNumber <= 364292) return "Q";
797  }
798  else if (year == 2022) {
799  if(runNumber >= 430536 && runNumber <= 432180) return "F";
800  else if (runNumber >= 435816 && runNumber <= 439927) return "H";
801  else if (runNumber >= 440407 && runNumber <= 440613) return "J";
802  }
803  else if (year == 2023) {
804  if(runNumber >= 451094 && runNumber <= 455924) return "F";
805  else if (runNumber >= 455975 && runNumber <= 456749) return "G";
806  }
807 
808  ATH_MSG_FATAL("RunNumber: " << runNumber << " not known! Will stop the code to prevent using wrong SFs.");
809  throw std::invalid_argument{""};
810  }
811 
813  static const SG::AuxElement::ConstAccessor<unsigned int> acc_rnd("RandomRunNumber");
815  if (info.operator->()==nullptr) {
816  ATH_MSG_FATAL("Could not retrieve the xAOD::EventInfo with name: " << m_eventInfo.key() << ". Exiting the code.");
817  throw std::invalid_argument{""};
818  }
819  if (!info->eventType(xAOD::EventInfo::IS_SIMULATION)) {
820  ATH_MSG_DEBUG("The current event is a data event. Return runNumber instead.");
821  return info->runNumber();
822  }
823  if (!acc_rnd.isAvailable(*info)) {
824  if(m_forceYear == -1 && m_forcePeriod == "")
825  ATH_MSG_FATAL("Failed to find the RandomRunNumber decoration. Please call the apply() method from the PileupReweightingTool beforehand in order to get period dependent SFs");
826  throw std::invalid_argument{""};
827  } else if (acc_rnd(*info) == 0) {
828  ATH_MSG_FATAL("Pile up tool has given runNumber 0. Exiting the code.");
829  throw std::invalid_argument{""};
830  }
831 
832  // standard behaviour for MC, get the random RunNumber
833  return acc_rnd(*info);
834  }
835 
837  gROOT->cd();
838  TDirectory* tempDir = 0;
839  int counter = 0;
840  while (not tempDir) {
841  std::stringstream dirname;
842  dirname << "MuonTriggerScaleFactorsTempDir_%i" << counter;
843  if (gROOT->GetDirectory((dirname.str()).c_str())) {
844  ++counter;
845  continue;
846  }
847  tempDir = gROOT->mkdir((dirname.str()).c_str());
848  if (not tempDir) {
849  ATH_MSG_ERROR("getTemporaryDirectory::Temporary directory could not be created");
850  }
851  }
852  return tempDir;
853  }
854 
855  //=======================================================================
856  // Systematics Interface
857  //=======================================================================
859  if (!systematic.empty()) {
861  return sys.find(systematic) != sys.end();
862  }
863  return true;
864  }
865 
868  CP::SystematicSet mySysSet;
869 
870  mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", 1));
871  mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigSystUncertainty", -1));
872 
873  //Consider full statUncertainty if TOY replicas are not used
874  if (m_replicaTriggerList.size() == 0) {
875  mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", 1));
876  mySysSet.insert(CP::SystematicVariation("MUON_EFF_TrigStatUncertainty", -1));
877  } else {
878  for (int i = 0; i < m_nReplicas; ++i) { //TOFIX Hack with just up variations! needs ASG reserved words for a clean handling//+++++++
879  mySysSet.insert(CP::SystematicVariation(Form("MUON_EFF_Trig_MCTOY%03d", i), 1));
880  }
881  }
882 
883  return mySysSet;
884  }
885 
886  // Register the systematics with the registry and add them to the recommended list
889  if (registry.registerSystematics(*this) != StatusCode::SUCCESS) {
890  ATH_MSG_ERROR("Failed to add systematic to list of recommended systematics.");
891  return StatusCode::FAILURE;
892  }
893  return StatusCode::SUCCESS;
894  }
895 
898  return affectingSystematics();
899  }
900 
902  // First, check if we already know this systematic configuration
903  auto itr = m_systFilter.find(systConfig);
904 
905  // If it's a new input set, we need to filter it
906  if (itr == m_systFilter.end()) {
907 
908  // New systematic. We need to parse it.
909  static const CP::SystematicSet affectingSys = affectingSystematics();
910  CP::SystematicSet filteredSys;
911  if (!CP::SystematicSet::filterForAffectingSystematics(systConfig, affectingSys, filteredSys)) {
912  ATH_MSG_ERROR("Unsupported combination of systematics passed to the tool!");
913  return StatusCode::FAILURE;
914  }
915 
916  // Insert filtered set into the map
917  itr = m_systFilter.insert(std::make_pair(systConfig, filteredSys)).first;
918  }
919 
920  CP::SystematicSet& mySysConf = itr->second;
921 
922  // Check to see if the set of variations tries to add in the uncertainty up and down. Since the errors
923  // are symetric this would result in 0 and so should not be done.
924  static const CP::SystematicVariation stat_up("MUON_EFF_TrigStatUncertainty", 1);
925  static const CP::SystematicVariation stat_down("MUON_EFF_TrigStatUncertainty", -1);
926  static const CP::SystematicVariation syst_up("MUON_EFF_TrigSystUncertainty", 1);
927  static const CP::SystematicVariation syst_down("MUON_EFF_TrigSystUncertainty", -1);
928 
929  if ((mySysConf.matchSystematic(stat_up) && mySysConf.matchSystematic(stat_down)) || (mySysConf.matchSystematic(syst_up) && mySysConf.matchSystematic(syst_down))) {
930  return StatusCode::FAILURE;
931  }
932 
933  m_appliedSystematics = &mySysConf;
934  return StatusCode::SUCCESS;
935  }
936 
937 } /* namespace CP */
grepfile.info
info
Definition: grepfile.py:38
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
CP::MuonTriggerScaleFactors::affectingSystematics
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by
Definition: MuonTriggerScaleFactors.cxx:867
python.AtlRunQueryAMI.period
period
Definition: AtlRunQueryAMI.py:225
CP::MuonTriggerScaleFactors::m_replicaSet
std::set< std::string > m_replicaSet
Definition: MuonTriggerScaleFactors.h:132
CP::MuonTriggerScaleFactors::getTriggerCorrespondingToDimuonTrigger
std::string getTriggerCorrespondingToDimuonTrigger(const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:701
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
CP::MuonTriggerScaleFactors::getReplica_index
virtual int getReplica_index(const std::string &sysBaseName, const std::string &trigStr) const
Definition: MuonTriggerScaleFactors.cxx:281
CP::TH1_Ptr
std::shared_ptr< TH1 > TH1_Ptr
Definition: MuonTriggerScaleFactors.h:28
CP::MuonTriggerScaleFactors::m_ReplicaRandomSeed
int m_ReplicaRandomSeed
Definition: MuonTriggerScaleFactors.h:134
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
CP::MuonTriggerScaleFactors::initialize
virtual StatusCode initialize(void)
Dummy implementation of the initialisation function.
Definition: MuonTriggerScaleFactors.cxx:201
MuonTriggerScaleFactors.h
get_generator_info.result
result
Definition: get_generator_info.py:21
CP::MuonTriggerScaleFactors::getYear
unsigned int getYear(unsigned int run) const
Definition: MuonTriggerScaleFactors.cxx:722
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
CP::MuonTriggerScaleFactors::appliedSystematics
const CP::SystematicSet & appliedSystematics() const
Definition: MuonTriggerScaleFactors.h:74
AddEmptyComponent.histName
string histName
Definition: AddEmptyComponent.py:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::MuonTriggerScaleFactors::m_muonquality
std::string m_muonquality
Definition: MuonTriggerScaleFactors.h:120
CP::MuonTriggerScaleFactors::m_binning
std::string m_binning
Definition: MuonTriggerScaleFactors.h:125
TrigMuonEff::Configuration::isData
bool isData
Definition: IMuonTriggerScaleFactors.h:24
CP::MuonTriggerScaleFactors::getDimuonEfficiency
virtual CorrectionCode getDimuonEfficiency(Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &chain, const std::string &systematic) const
Definition: MuonTriggerScaleFactors.cxx:676
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
xAODP4Helpers.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
MuonRoIContainer.h
CP::MuonTriggerScaleFactors::m_appliedSystematics
CP::SystematicSet * m_appliedSystematics
Definition: MuonTriggerScaleFactors.h:115
plotmaker.hist
hist
Definition: plotmaker.py:148
CP::MuonTriggerScaleFactors::m_forcePeriod
std::string m_forcePeriod
Definition: MuonTriggerScaleFactors.h:129
CP::MuonTriggerScaleFactors::m_nReplicas
int m_nReplicas
Definition: MuonTriggerScaleFactors.h:133
CP::MuonTriggerScaleFactors::EffiHistoIdent
std::pair< YearPeriod, unsigned int > EffiHistoIdent
Definition: MuonTriggerScaleFactors.h:91
CP::MuonTriggerScaleFactors::generateReplicas
std::vector< TH1_Ptr > generateReplicas(TH1_Ptr h, int nrep, int seed) const
Definition: MuonTriggerScaleFactors.cxx:345
CP::MuonTriggerScaleFactors::m_allowZeroSF
bool m_allowZeroSF
Definition: MuonTriggerScaleFactors.h:126
CP::MuonTriggerScaleFactors::getTemporaryDirectory
TDirectory * getTemporaryDirectory(void) const
Definition: MuonTriggerScaleFactors.cxx:836
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
dirname
std::string dirname(std::string name)
Definition: utils.cxx:200
asg
Definition: DataHandleTestTool.h:28
PixelAthClusterMonAlgCfg.ybins
ybins
Definition: PixelAthClusterMonAlgCfg.py:169
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
M_PI
#define M_PI
Definition: ActiveFraction.h:11
bin
Definition: BinsDiffFromStripMedian.h:43
CP::MuonTriggerScaleFactors::getTriggerScaleFactor
virtual CorrectionCode getTriggerScaleFactor(const xAOD::MuonContainer &mucont, Double_t &triggersf, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:254
downloadSingle.dataType
string dataType
Definition: downloadSingle.py:18
CP::MuonTriggerScaleFactors::m_replicaTriggerList
std::vector< std::string > m_replicaTriggerList
Definition: MuonTriggerScaleFactors.h:131
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CP::SystematicVariation
Definition: SystematicVariation.h:47
python.AtlRunQueryAMI.year
year
Definition: AtlRunQueryAMI.py:226
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::MuonTriggerScaleFactors::~MuonTriggerScaleFactors
virtual ~MuonTriggerScaleFactors()
Definition: MuonTriggerScaleFactors.cxx:78
DeMoAtlasDataLoss.periodName
list periodName
Definition: DeMoAtlasDataLoss.py:129
CP::MuonTriggerScaleFactors::applySystematicVariation
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
effects: configure this tool for the given list of systematic variations.
Definition: MuonTriggerScaleFactors.cxx:901
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::MuonTriggerScaleFactors::getBinNumber
virtual int getBinNumber(const xAOD::Muon &muon, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:368
CP::MuonTriggerScaleFactors::GetTriggerSF_dimu
virtual CorrectionCode GetTriggerSF_dimu(Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:475
MuonAuxContainer.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TrigMuonEff::Configuration
structure to hold variables to configure behaviour of the tool
Definition: IMuonTriggerScaleFactors.h:23
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
efficiency
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:128
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PixelAthClusterMonAlgCfg.histname
histname
Definition: PixelAthClusterMonAlgCfg.py:106
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:85
SystematicRegistry.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CP::MuonTriggerScaleFactors::m_runNumber_year
static const std::map< unsigned int, int > m_runNumber_year
Definition: MuonTriggerScaleFactors.h:137
CP::MuonTriggerScaleFactors::LoadTriggerMap
StatusCode LoadTriggerMap(unsigned int year)
Definition: MuonTriggerScaleFactors.cxx:80
mergePhysValFiles.origDir
origDir
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:24
CP::MuonTriggerScaleFactors::m_calibration_version
std::string m_calibration_version
Definition: MuonTriggerScaleFactors.h:123
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
run
Definition: run.py:1
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
TrigMuonEff::Configuration::replicaIndex
int replicaIndex
index of replicated histograms to access
Definition: IMuonTriggerScaleFactors.h:25
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
plotIsoValidation.mu_phi
mu_phi
Definition: plotIsoValidation.py:152
CP::MuonTriggerScaleFactors::isAffectedBySystematic
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
Declare the interface that this class provides.
Definition: MuonTriggerScaleFactors.cxx:858
StatusCode.h
CP::MuonTriggerScaleFactors::getDataPeriod
std::string getDataPeriod() const
Definition: MuonTriggerScaleFactors.cxx:735
PathResolver.h
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
hancool.filePath
string filePath
Definition: hancool.py:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ReadHandle.h
Handle class for reading from StoreGate.
threshold
Definition: chainparser.cxx:74
CP::MuonTriggerScaleFactors::getMuonEfficiency
virtual CorrectionCode getMuonEfficiency(Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::Muon &muon, const std::string &trigger, const std::string &systematic) const
Definition: MuonTriggerScaleFactors.cxx:415
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
MuonContainer.h
LArCellBinning.xbins
int xbins
Definition: LArCellBinning.py:163
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
CP::MuonTriggerScaleFactors::m_eventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Definition: MuonTriggerScaleFactors.h:105
CP::MuonTriggerScaleFactors::m_fileName
std::string m_fileName
Definition: MuonTriggerScaleFactors.h:116
CP::MuonTriggerScaleFactors::m_custom_dir
std::string m_custom_dir
Definition: MuonTriggerScaleFactors.h:124
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
CP::MuonTriggerScaleFactors::MuonTriggerScaleFactors
MuonTriggerScaleFactors(const std::string &name)
Definition: MuonTriggerScaleFactors.cxx:42
CP::MuonTriggerScaleFactors::m_systFilter
std::unordered_map< CP::SystematicSet, CP::SystematicSet > m_systFilter
Definition: MuonTriggerScaleFactors.h:113
CP::MuonTriggerScaleFactors::YearPeriod
std::pair< unsigned int, std::string > YearPeriod
Definition: MuonTriggerScaleFactors.h:90
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
CP::MuonTriggerScaleFactors::recommendedSystematics
virtual CP::SystematicSet recommendedSystematics() const
returns: the list of all systematics this tool recommends to use
Definition: MuonTriggerScaleFactors.cxx:897
CP::MuonTriggerScaleFactors::getRunNumber
unsigned int getRunNumber() const
Definition: MuonTriggerScaleFactors.cxx:812
CP::MuonTriggerScaleFactors::m_efficiencyMap
EfficiencyMap m_efficiencyMap
Definition: MuonTriggerScaleFactors.h:117
h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CP::SystematicVariation::empty
bool empty() const
returns: whether this is an empty systematic, i.e.
Definition: SystematicVariation.cxx:294
CP::MuonTriggerScaleFactors::encodeHistoName
unsigned int encodeHistoName(const std::string &period, const std::string &Trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
Definition: MuonTriggerScaleFactors.cxx:390
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CP::SystematicSet::matchSystematic
bool matchSystematic(const SystematicVariation &systematic, MATCHTYPE type=FULL) const
Definition: SystematicSet.cxx:128
CP::MuonTriggerScaleFactors::getTriggerEfficiency
virtual CorrectionCode getTriggerEfficiency(const xAOD::Muon &mu, Double_t &efficiency, const std::string &trigger, Bool_t dataType) const
Definition: MuonTriggerScaleFactors.cxx:288
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
CP::MuonTriggerScaleFactors::registerSystematics
StatusCode registerSystematics()
Definition: MuonTriggerScaleFactors.cxx:887
CP::MuonTriggerScaleFactors::isTriggerSupported
virtual bool isTriggerSupported(const std::string &trigger) const
Returns whether the trigger is supported by the tool or not. The decision depends on the present (ran...
Definition: MuonTriggerScaleFactors.cxx:363
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
plotIsoValidation.mu_eta
mu_eta
Definition: plotIsoValidation.py:151
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
CP::MuonTriggerScaleFactors::getThreshold
CorrectionCode getThreshold(Int_t &threshold, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:707
CP::MuonTriggerScaleFactors::m_experimental
bool m_experimental
Definition: MuonTriggerScaleFactors.h:127
test_pyathena.counter
counter
Definition: test_pyathena.py:15
Analysis::Systematic
@ Systematic
Definition: CalibrationDataInterfaceROOT.h:70
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
CP::MuonTriggerScaleFactors::getEfficiencyHistogram
virtual std::shared_ptr< TH1 > getEfficiencyHistogram(unsigned int year, const std::string &period, const std::string &trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
Definition: MuonTriggerScaleFactors.cxx:401
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
dumpTgcDigiThreshold.threshold
list threshold
Definition: dumpTgcDigiThreshold.py:34
CP::MuonTriggerScaleFactors::m_efficiencyMapReplicaArray
std::map< EffiHistoIdent, std::vector< TH1_Ptr > > m_efficiencyMapReplicaArray
Definition: MuonTriggerScaleFactors.h:118
SystematicVariation.h
CP::SystematicSet::filterForAffectingSystematics
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
Definition: SystematicSet.cxx:213
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
python.handimod.cc
int cc
Definition: handimod.py:523
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25
CP::MuonTriggerScaleFactors::GetTriggerSF
virtual CorrectionCode GetTriggerSF(Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:534
CP::MuonTriggerScaleFactors::m_forceYear
int m_forceYear
Definition: MuonTriggerScaleFactors.h:128
beamspotman.basename
basename
Definition: beamspotman.py:640