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 code8 = tool.setProperty("doXbbTagging", false);
87 
88  StatusCode code_init = tool.initialize();
89  if (code_init != StatusCode::SUCCESS || code1 != StatusCode::SUCCESS || code2 != StatusCode::SUCCESS
90  || code3 != StatusCode::SUCCESS || code4 != StatusCode::SUCCESS || code5 != StatusCode::SUCCESS
91  || code6 != StatusCode::SUCCESS || code7 != StatusCode::SUCCESS || code8 != StatusCode::SUCCESS)
92  {
93  std::cout << "Initialization of tool " << tool->name() << " failed! " << std::endl;
94  return -1;
95  }
96  else {
97  std::cout << "Initialization of tool " << tool->name() << " finished." << std::endl;
98  }
99 
100  // select your efficiency map based on the DSID of your sample:
101  unsigned int sample_dsid = 410464;
102 
103  tool->setMapIndex(sample_dsid);
104 
105 
106  std::cout << "-----------------------------------------------------" << std::endl;
107  const std::map<CP::SystematicVariation, std::vector<std::string> > allowed_variations = tool->listSystematics();
108  std::cout << "Allowed systematics variations for tool " << tool->name() << ":" << std::endl;
109  for (const auto& var : allowed_variations) {
110  std::cout << std::setw(40) << std::left << var.first.name() << ":";
111  for (const auto& flv : var.second) std::cout << " " << flv;
112  std::cout << std::endl;
113  }
114  std::cout << "-----------------------------------------------------" << std::endl;
115 
116  if(perform_jet_validation){
117  // retrieve the "real jets" of the jet collection in question
118  const xAOD::JetContainer* jets = nullptr;
119  if (!event.retrieve(jets, jeta).isSuccess()){ std::cout << " error retrieving jets " << std::endl; return -1;}
120 
121  // test with the jet!
122  int jet_index = 0;
123  for(const xAOD::Jet* jet : *jets){
124  if(jet->pt() < 20000 or std::abs(jet->eta()) > 2.4) break; // any lower than this and you start seeing failed SF/Eff retrieval
125  int truthlabel = -999;
126  jet->getAttribute("HadronConeExclTruthLabelID",truthlabel);
127  std::cout << "\n- - - - - - - - - - - - - - - Jet " << jet_index << " - - - - - - - - - - - - - - - -" << std::endl;
128  std::cout << " |- Jet index " << jet_index << " px = " << jet->px() << " py = " << jet->py() << " pz = " << jet->pz() << " e " << jet->e() << std::endl;
129  std::cout << " \\_ pt = " << jet->pt() << " eta = " << jet->eta() << " phi = " << jet->phi() << " m " << jet->m() << std::endl;
130 
131  // Storage for sf/eff values
132  float sf=0;
133  float eff=0;
135  std::cout << "Testing function calls without systematics..." << std::endl;
136  result = tool->getEfficiency(*jet,eff);
137  if( result!=CorrectionCode::Ok) { std::cout << "b jet get efficiency failed"<<std::endl; retval=false;}
138  else {
139  std::cout << "b jet get efficiency succeeded: " << eff << std::endl;
140  }
141  result = tool->getScaleFactor(*jet,sf);
142  if( result!=CorrectionCode::Ok) { std::cout << "b jet get scale factor failed"<<std::endl; retval=false;}
143  else {
144  std::cout << "b jet get scale factor succeeded: " << sf << std::endl;
145  }
146 
147  std::cout << "Testing function calls with systematics..." << std::endl;
148  const CP::SystematicSet& systs = tool->affectingSystematics();
149  for(const auto& var : systs){
151  set.insert(var);
152  StatusCode sresult = tool->applySystematicVariation(set);
153  if( sresult !=StatusCode::SUCCESS) {
154  std::cout << var.name() << " apply systematic variation FAILED " << std::endl;
155  }
156  result = tool->getScaleFactor(*jet,sf);
157  if( result!=CorrectionCode::Ok) {
158  std::cout << var.name() << " getScaleFactor FAILED" << std::endl;
159  } else {
160  std::cout << var.name() << ": scale-factor = " << sf << std::endl;
161  }
162  }
163  // don't forget to switch back off the systematics...
164  CP::SystematicSet defaultSet;
165  StatusCode dummyResult = tool->applySystematicVariation(defaultSet);
166  if (dummyResult != StatusCode::SUCCESS) std::cout << "problem disabling systematics setting!" << std::endl;
167 
168  jet_index += 1;
169  }
170  }
171  } // end strats loop
172  } // end wps loop
173  } // end jets loop
174  } // end taggers loop
175  std::cout << " Great, now the SystematicStrategyComparison is finished! " << std::endl;
176 
177  return retval;
178 }

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:111
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
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
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:224
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:73
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