ATLAS Offline Software
Functions | Variables
SystematicStrategyComparison.cxx File Reference
#include "POOLRootAccess/TEvent.h"
#include <AsgTools/StandaloneToolHandle.h>
#include "FTagAnalysisInterfaces/IBTaggingEfficiencyTool.h"
#include "CalibrationDataInterface/CDIReader.h"
#include "xAODJet/JetAuxContainer.h"
#include "xAODJet/JetContainer.h"
#include "xAODBTagging/BTaggingAuxContainer.h"
#include "xAODBTagging/BTagging.h"
#include "xAODBTagging/BTaggingUtilities.h"
#include <string>
#include <iomanip>
#include "TFile.h"

Go to the source code of this file.

Functions

int main ()
 

Variables

POOL::TEvent event (POOL::TEvent::kClassAccess)
 

Function Documentation

◆ main()

int main ( )

getCoefficientMap(label, EigenIdxList)

input value:

  1. label: falvor label in std::string format, could be one of B, C, T, Light
  2. EigenIdxList is user defined vector containing all eigenvector index that user interested in. output: Map of format map<string, map<string, float>> containing decomposition coefficient of the list of eigenvectors defined by EigenIdxList.

getCoefficients(label, evIdx)

input value:

  1. label: falvor label in std::string format, could be one of B, C, T, Light
  2. evIdx: The index of eigenvector user interested in. output value: vector of coefficient values. The order is the same as output given by getListOfOriginalNuisanceParameters()

getListOfOriginalNuisanceParameters(label)

input value:

  1. label: falvor label in std::string format, could be one of B, C, T, Light output value: List of original nuisance parameter names.

getNumEigenVectors(label)

input value:

  1. label: falvor label in std::string format, could be one of B, C, T, Light return value: number of eigen vectors used for chosen label. Return 0 if error occured.

Definition at line 49 of file SystematicStrategyComparison.cxx.

49  {
50  bool retval = true;
51  bool perform_jet_validation = false; // flag for turning on the
52  // systematic strategies to compare
53  std::vector<std::string> strats;
54  strats.push_back("SFEigen");
55  strats.push_back("SFGlobalEigen");
56  std::cout << "Starting up the SystematicStrategyComparison . . ." << std::endl;
57  // set your CDI file path here
58  std::string CDIfile = "/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/xAODBTaggingEfficiency/13TeV/2022-22-13TeV-MC20-CDI-2022-07-28_v1.root";
59 
60  if(perform_jet_validation){
61  // set your own DAOD file (ideally a sample with many jets, like ttH), and select a suitable event below
62  std::string DAODpath = "/DAODs/Example.pool.root.1"; // path to an example DAOD file, from which we can retrieve jets to test the BTagging tools
63  //load some jets to show how to use the tool
64  TFile* m_file = TFile::Open(DAODpath.c_str(),"read");
65  if(!event.readFrom(m_file).isSuccess()){
66  std::cout << "failed to load file" << std::endl;
67  return -1;
68  }
69  event.getEntry(42);
70  }
71 
72  Analysis::CDIReader Reader(CDIfile);
73  for(const std::string& tag : Reader.getTaggers()){
74  for(const std::string& jeta : Reader.getJetCollections(tag)){
75  for(const std::string& wp : Reader.getWorkingPoints(tag, jeta)){
76  for(const std::string& strat : strats ){
77  asg::StandaloneToolHandle<IBTaggingEfficiencyTool> tool("BTaggingEfficiencyTool/SysStratTest");
78  StatusCode code1 = tool.setProperty("ScaleFactorFileName", CDIfile); // set your CDI file here
79  StatusCode code2 = tool.setProperty("TaggerName", tag );
80  StatusCode code3 = tool.setProperty("OperatingPoint", wp);
81  StatusCode code4 = tool.setProperty("JetAuthor", jeta);
82  StatusCode code5 = tool.setProperty("MinPt", 1);
83  StatusCode code6 = tool.setProperty("SystematicsStrategy", strat);//either "SFEigen" or "SFGlobalEigen"
84  StatusCode code7 = tool.setProperty("useFlexibleConfig", true);
85 
86  StatusCode code_init = tool.initialize();
87  if (code_init != StatusCode::SUCCESS || code1 != StatusCode::SUCCESS || code2 != StatusCode::SUCCESS
88  || code3 != StatusCode::SUCCESS || code4 != StatusCode::SUCCESS || code5 != StatusCode::SUCCESS
89  || code6 != StatusCode::SUCCESS || code7 != StatusCode::SUCCESS)
90  {
91  std::cout << "Initialization of tool " << tool->name() << " failed! " << std::endl;
92  return -1;
93  }
94  else {
95  std::cout << "Initialization of tool " << tool->name() << " finished." << std::endl;
96  }
97 
98  // select your efficiency map based on the DSID of your sample:
99  unsigned int sample_dsid = 410464;
100 
101  tool->setMapIndex(sample_dsid);
102 
103 
104  std::cout << "-----------------------------------------------------" << std::endl;
105  const std::map<CP::SystematicVariation, std::vector<std::string> > allowed_variations = tool->listSystematics();
106  std::cout << "Allowed systematics variations for tool " << tool->name() << ":" << std::endl;
107  for (const auto& var : allowed_variations) {
108  std::cout << std::setw(40) << std::left << var.first.name() << ":";
109  for (const auto& flv : var.second) std::cout << " " << flv;
110  std::cout << std::endl;
111  }
112  std::cout << "-----------------------------------------------------" << std::endl;
113 
114  if(perform_jet_validation){
115  // retrieve the "real jets" of the jet collection in question
116  const xAOD::JetContainer* jets = nullptr;
117  if (!event.retrieve(jets, jeta).isSuccess()){ std::cout << " error retrieving jets " << std::endl; return -1;}
118 
119  // test with the jet!
120  int jet_index = 0;
121  for(const xAOD::Jet* jet : *jets){
122  if(jet->pt() < 20000 or std::abs(jet->eta()) > 2.4) break; // any lower than this and you start seeing failed SF/Eff retrieval
123  int truthlabel = -999;
124  jet->getAttribute("HadronConeExclTruthLabelID",truthlabel);
125  std::cout << "\n- - - - - - - - - - - - - - - Jet " << jet_index << " - - - - - - - - - - - - - - - -" << std::endl;
126  std::cout << " |- Jet index " << jet_index << " px = " << jet->px() << " py = " << jet->py() << " pz = " << jet->pz() << " e " << jet->e() << std::endl;
127  std::cout << " \\_ pt = " << jet->pt() << " eta = " << jet->eta() << " phi = " << jet->phi() << " m " << jet->m() << std::endl;
128 
129  // Storage for sf/eff values
130  float sf=0;
131  float eff=0;
133  std::cout << "Testing function calls without systematics..." << std::endl;
134  result = tool->getEfficiency(*jet,eff);
135  if( result!=CorrectionCode::Ok) { std::cout << "b jet get efficiency failed"<<std::endl; retval=false;}
136  else {
137  std::cout << "b jet get efficiency succeeded: " << eff << std::endl;
138  }
139  result = tool->getScaleFactor(*jet,sf);
140  if( result!=CorrectionCode::Ok) { std::cout << "b jet get scale factor failed"<<std::endl; retval=false;}
141  else {
142  std::cout << "b jet get scale factor succeeded: " << sf << std::endl;
143  }
144 
145  std::cout << "Testing function calls with systematics..." << std::endl;
146  const CP::SystematicSet& systs = tool->affectingSystematics();
147  for(const auto& var : systs){
149  set.insert(var);
150  StatusCode sresult = tool->applySystematicVariation(set);
151  if( sresult !=StatusCode::SUCCESS) {
152  std::cout << var.name() << " apply systematic variation FAILED " << std::endl;
153  }
154  result = tool->getScaleFactor(*jet,sf);
155  if( result!=CorrectionCode::Ok) {
156  std::cout << var.name() << " getScaleFactor FAILED" << std::endl;
157  } else {
158  std::cout << var.name() << ": scale-factor = " << sf << std::endl;
159  }
160  }
161  // don't forget to switch back off the systematics...
162  CP::SystematicSet defaultSet;
163  StatusCode dummyResult = tool->applySystematicVariation(defaultSet);
164  if (dummyResult != StatusCode::SUCCESS) std::cout << "problem disabling systematics setting!" << std::endl;
165 
166  jet_index += 1;
167  }
168  }
169  } // end strats loop
170  } // end wps loop
171  } // end jets loop
172  } // end taggers loop
173  std::cout << " Great, now the SystematicStrategyComparison is finished! " << std::endl;
174 
175  return retval;
176 }

Variable Documentation

◆ event

beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
Analysis::dummyResult
const CalibResult dummyResult(dummyValue, dummyValue)
get_generator_info.result
result
Definition: get_generator_info.py:21
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
LArCellBinning_test.retval
def retval
Definition: LArCellBinning_test.py:112
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LHEF::Reader
Pythia8::Reader Reader
Definition: Prophecy4fMerger.cxx:11
PlotSFuncertainty.wp
wp
Definition: PlotSFuncertainty.py:112
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
Analysis::CDIReader
Definition: CDIReader.h:39