ATLAS Offline Software
Functions
CalibrationDataInterfaceROOT.cxx File Reference
#include "CalibrationDataInterface/CalibrationDataInterfaceROOT.h"
#include "CalibrationDataInterface/CalibrationDataContainer.h"
#include "CalibrationDataInterface/CalibrationDataEigenVariations.h"
#include "CalibrationDataInterface/CalibrationDataInternals.h"
#include <boost/algorithm/string.hpp>
#include "TMath.h"
#include "TEnv.h"
#include "TFile.h"
#include "TObjString.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>

Go to the source code of this file.

Functions

 ClassImp (Analysis::CalibrationDataInterfaceROOT) Analysis
 

Function Documentation

◆ ClassImp()

Definition at line 289 of file CalibrationDataInterfaceROOT.cxx.

293  :
294  m_runEigenVectorMethod(false), m_EVStrategy(SFEigen), m_useRecommendedEVExclusions(false), m_verbose(true),
295  m_absEtaStrategy(GiveUp), m_otherStrategy(Flag)
296 {
297  // Normal constructor.
298  //
299  // taggerName: this should correspond to the tagger name as used in the calibration ROOT file
300  // configname: full name of the configuration file
301  // pathname: directory specification for separate scale factor or efficiency ROOT file
302 
303  m_taggerName = taggerName;
304 
305  TEnv env;
306  env.ReadFile(configname.c_str(),kEnvGlobal);
307 
308 
309  // ROOT file containing the calibrations
310  TString filename = env.GetValue("File", "BTaggingPerformanceCalibrations.root");
311  m_filenameEff = string(env.GetValue("FileEff", "")); trim(m_filenameEff);
312  m_filenameSF = string(env.GetValue("FileSF", "")); trim(m_filenameSF);
313  if (m_filenameEff == "") {
314  m_filenameEff = pathname + filename.Data();
315  }
316  if (m_filenameSF == "") {
317  m_filenameSF = pathname + filename.Data();
318  }
319 
320  if (m_verbose) {
321  cout << "=== CalibrationDataInterfaceROOT::CalibrationDataInterfaceROOT ===" << endl;
322  cout << " Config name : " << configname << endl;
323  cout << " taggerName : " << taggerName << endl;
324  cout << " Efficiency file name : " << m_filenameEff << endl
325  << " SF file name : " << m_filenameSF << endl;
326  }
327 
328  m_fileEff = TFile::Open(m_filenameEff.c_str(), "READ");
329  if (m_filenameEff == m_filenameSF)
330  m_fileSF = m_fileEff;
331  else
332  m_fileSF = TFile::Open(m_filenameSF.c_str(), "READ");
333 
334  if (m_verbose) {
335  TObjString* s;
336  m_fileSF->GetObject("VersionInfo/BuildNumber", s);
337  if (s) cout << " CDI file build number: " << s->GetName() << endl;
338  cout << endl;
339  }
340 
341  m_flavours = { "B", "C", "T", "Light" };
342  string testPrefix(taggerName); testPrefix += ".";
343 
344  // Since TEnv doesn't allow for straight retrieval of vectors of strings, expect
345  // semicolon-separated entries (semicolon because ROOT considers this as a "special"
346  // token anyway in object names).
347  string::size_type end;
348 
349  // Calibration names for the efficiencies
350  std::map<string, std::vector<string> > effNames;
351  for (auto const& flavour : m_flavours) {
352  string test(testPrefix); test += "EfficiencyCalibration"; test += flavour; test += "Name";
353  effNames[flavour] = split(string(env.GetValue(test.c_str(), "default")));
354  }
355  setEffCalibrationNames(effNames);
356 
357  // Calibration names for the efficiency scale factors
358  std::map<string, string> SFNames;
359  for (auto const& flavour : m_flavours) {
360  string test(testPrefix); test += "ScaleFactorCalibration"; test += flavour; test += "Name";
361  SFNames[flavour] = string(env.GetValue(test.c_str(), "default")); trim(SFNames[flavour]);
362  }
363  setSFCalibrationNames(SFNames);
364 
365  // Since TEnv doesn't allow for straight retrieval of vectors of strings, expect
366  // semicolon-separated entries (semicolon because ROOT considers this as a "special"
367  // token anyway in object names).
368  // Don't prefix this since the aliases are common to all taggers (even if they are read again for each tagger).
369  string AL(env.GetValue("aliases", ""));
370  if (AL.size() > 0) {
371  do {
372  end = AL.find(";");
373  string alias = AL.substr(0, end);
374  // Each alias specification uses an arrow ("->"). Forget about entries
375  // not properly following this specification.
376  // NB: TEnv imposes a maximum string length of 1024 characters -- is this a problem?
377  string::size_type arrow = alias.find("->");
378  if (arrow == string::npos) continue;
379  string target = alias.substr(0,arrow); trim(target);
380  m_aliases[target] = alias.substr(arrow+2); trim(m_aliases[target]);
381  if (end != string::npos) AL = AL.substr(end+1);
382  } while (end != string::npos);
383  }
384 
385  //run egenvector method or not?
386  string test="runEigenVectorMethod";
387  m_runEigenVectorMethod=(bool)env.GetValue(test.c_str(),0);
388 
389  if (m_runEigenVectorMethod) {
390  // Retrieve the list of systematic uncertainties not to be considered when building up
391  // the full covariance matrix used for the eigenvector method.
392  // We do this in two steps: first, for backward compatibility reasons, a flavour-independent list is scanned.
393  // Second, flavour-specific lists are scanned.
394  test = "excludeFromCovMatrix";
395  std::vector<std::string> to_exclude = split(env.GetValue(test.c_str(), ""));
396  // Copy the resulting list to all flavours
397  for (auto const& flavour : m_flavours) {
398  m_excludeFromCovMatrix[flavour] = to_exclude;
399  }
400  for (auto const& flavour : m_flavours) {
401  test = "excludeFrom"; test += flavour; test += "CovMatrix";
402  to_exclude = split(env.GetValue(test.c_str(), ""));
403  // Append to the existing list
404  m_excludeFromCovMatrix[flavour].insert(m_excludeFromCovMatrix[flavour].end(), to_exclude.begin(), to_exclude.end());
405  }
406 
407  unsigned int n_excluded = 0;
408  for (auto const& flavour : m_flavours) {
409  n_excluded += m_excludeFromCovMatrix[flavour].size();
410  }
411  if (m_verbose) {
412  cout << " List of uncertainties to exclude:";
413  if (n_excluded == 0) cout << " none";
414  for (auto const& flavour : m_flavours) {
415  if (m_excludeFromCovMatrix[flavour].size() > 0) {
416  cout << "\n\t" << flavour << ":\t";
417  for (unsigned int i = 0; i < m_excludeFromCovMatrix[flavour].size(); ++i) {
418  cout << m_excludeFromCovMatrix[flavour].at(i);
419  if (i+1 == m_excludeFromCovMatrix[flavour].size()) cout << "; ";
420  }
421  cout << endl;
422  }
423  }
424  cout << endl;
425  }
426 
427  // The following determines whether also pre-determined (recommended) lists of uncertainties are to be excluded from EV decomposition.
428  // These lists are stored with the CalibrationDataContainers, which have not been instantiated yet (so we cannot show them at this point).
429  m_useRecommendedEVExclusions = (bool) env.GetValue("ExcludeRecommendedFromEigenVectorTreatment", false);
430 
431  // determine also the eigenvector reduction strategies
432  std::map<string, EVReductionStrategy> mappings;
433  mappings["Loose"] = Loose;
434  mappings["Medium"] = Medium;
435  mappings["Tight"] = Tight;
436  for (auto const& flavour : m_flavours) {
437  test = testPrefix; test += "EigenvectorReduction"; test += flavour;
438  std::string reduction = string(env.GetValue(test.c_str(), "Loose")); trim(reduction);
439  m_EVReductions[flavour] = mappings.find(reduction) == mappings.end() ? mappings["Loose"] : mappings.find(reduction)->second;
440  }
441  }
442 
443  // determine |eta| validity range
444  m_maxAbsEta = env.GetValue("MaxAbsEta", 2.5);
445  if (m_maxAbsEta < 0) m_maxAbsEta = 2.5;
446 
447  // set validation / protection strategy in case an out-of-bounds eta value is specified
448  string strategy = string(env.GetValue("OutOfBoundsEta", "GiveUp")); trim(strategy);
449  if (strategy == "GiveUp") m_absEtaStrategy = GiveUp;
450  else if (strategy == "Flag") m_absEtaStrategy = Flag;
451  else if (strategy == "Ignore") m_absEtaStrategy = Ignore;
452  else {
453  cerr << "unknown |eta| extrapolation strategy: " << strategy << ", setting to GiveUp" << endl;
454  m_absEtaStrategy = GiveUp;
455  }
456 
457  // set validation / protection strategy in case out-of-bounds variables are specified
458  strategy = string(env.GetValue("OutOfBoundsOther", "Flag")); trim(strategy);
459  if (strategy == "GiveUp") m_otherStrategy = GiveUp;
460  else if (strategy == "GiveUpExtrapolated") m_otherStrategy = GiveUpExtrapolated;
461  else if (strategy == "Flag") m_otherStrategy = Flag;
462  else if (strategy == "Ignore") m_otherStrategy = Ignore;
463  else {
464  cerr << "unknown general extrapolation strategy: " << strategy << ", setting to Flag" << endl;
465  m_otherStrategy = Flag;
466  }
467 
468  // maximum tag weight to accept
469  m_maxTagWeight = env.GetValue("MaxTagWeight", 10.0);
470 
471  // MC/MC (hadronisation) scale factors: making this user-steerable is intended to be *temporary* only
472  m_useMCMCSF = (bool) env.GetValue("useMCMCSF", 1);
473  // MC/MC (topology) scale factors: making this user-steerable is intended to be *temporary* only
474  m_useTopologyRescaling = (bool) env.GetValue("useTopologySF", 0);
475 
476  if (m_verbose) cout << "======= end of CalibrationDataInterfaceROOT instantiation ========" << endl;
477 }
xAOD::strategy
strategy
Definition: L2CombinedMuon_v1.cxx:107
Analysis::GiveUp
@ GiveUp
Definition: CalibrationDataInterfaceROOT.h:82
LikeEnum::Loose
@ Loose
Definition: LikelihoodEnums.h:12
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
trim
std::string trim(const std::string &str, const std::string &whitespace=" \t")
Definition: BTaggingTruthTaggingTool.cxx:1149
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:144
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Analysis::GiveUpExtrapolated
@ GiveUpExtrapolated
Definition: CalibrationDataInterfaceROOT.h:82
lumiFormat.i
int i
Definition: lumiFormat.py:92
COOLRates.alias
alias
Definition: COOLRates.py:1172
Analysis::SFEigen
@ SFEigen
Definition: CalibrationDataInterfaceROOT.h:70
LikeEnum::Tight
@ Tight
Definition: LikelihoodEnums.h:15
LikeEnum::Medium
@ Medium
Definition: LikelihoodEnums.h:14
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
Analysis::Ignore
@ Ignore
Definition: CalibrationDataInterfaceROOT.h:82
COOLRates.target
target
Definition: COOLRates.py:1106
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
Analysis::Flag
@ Flag
Definition: CalibrationDataInterfaceROOT.h:82
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
Trk::split
@ split
Definition: LayerMaterialProperties.h:38