ATLAS Offline Software
Classes | Macros | Typedefs | Functions | Variables
fbtTestBasics.cxx File Reference
#include <fstream>
#include <map>
#include <memory>
#include <getopt.h>
#include <TSystem.h>
#include <TError.h>
#include <TFile.h>
#include <TH1F.h>
#include "POOLRootAccess/TEvent.h"
#include "AsgTools/AnaToolHandle.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODEventInfo/EventAuxInfo.h"
#include "xAODEgamma/Electron.h"
#include "xAODMuon/Muon.h"
#include "AthContainers/Accessor.h"
#include "AsgMessaging/MessageCheck.h"
#include "AsgAnalysisInterfaces/IFakeBkgTool.h"
#include "AsgAnalysisInterfaces/ILinearFakeBkgTool.h"
#include "TruthUtils/ParticleConstants.h"

Go to the source code of this file.

Classes

struct  Result
 

Macros

#define FBT_CHECK1(x, FAIL)
 
#define FBT_CHECK(x)   FBT_CHECK1(x, false)
 

Typedefs

using Store_t = StoreGateSvc *
 

Functions

bool successful (bool arg)
 
bool successful (const StatusCode &arg)
 
bool allTests (Store_t &store)
 
bool minimalTest (const std::string &type, const std::vector< std::string > &config, Store_t &store, Result &result)
 
bool parallelJob (const std::string &type, const std::vector< std::string > &config, Store_t &store, const std::string &saveAs, int nEvents, int eventOffset)
 
bool readFromROOT (std::vector< std::string > &config)
 
bool readFromXML (std::vector< std::string > &config)
 
template<class Interface = CP::IFakeBkgTool>
bool setup (asg::AnaToolHandle< Interface > &tool, const std::string &type, const std::vector< std::string > &config, const std::string &progressFile)
 mostly useful for athena, which will otherwise re-use the previous tool More...
 
template<class Interface = CP::IFakeBkgTool>
bool eventLoop (asg::AnaToolHandle< Interface > &tool, Store_t &store, Result &result, int nEvents, int eventOffset=0)
 
bool addEventWeight (asg::AnaToolHandle< CP::ILinearFakeBkgTool > &tool, Result &result)
 
bool addEventWeight (asg::AnaToolHandle< CP::IFakeBkgTool > &tool, Result &result)
 
template<class Interface = CP::IFakeBkgTool>
bool fillResult (asg::AnaToolHandle< Interface > &tool, Result &result)
 
int main (int argc, char *argv[])
 

Variables

const std::string selection = ">=1T"
 
const std::string process = ">=1F[T]"
 
const bool readCPVariations = true
 
const int nEvents = 48
 
std::atomic< bool > verbose = false
 

Macro Definition Documentation

◆ FBT_CHECK

#define FBT_CHECK (   x)    FBT_CHECK1(x, false)

Definition at line 48 of file fbtTestBasics.cxx.

◆ FBT_CHECK1

#define FBT_CHECK1 (   x,
  FAIL 
)
Value:
do { \
if(!successful(x)) { \
Error("fbtTestBasics", "failure encounted on l.%d", __LINE__); \
return FAIL; \
} \
} while(false)

Definition at line 41 of file fbtTestBasics.cxx.

Typedef Documentation

◆ Store_t

Definition at line 60 of file fbtTestBasics.cxx.

Function Documentation

◆ addEventWeight() [1/2]

bool addEventWeight ( asg::AnaToolHandle< CP::IFakeBkgTool > &  tool,
Result result 
)

Definition at line 254 of file fbtTestBasics.cxx.

255 {
256  return true;
257 }

◆ addEventWeight() [2/2]

bool addEventWeight ( asg::AnaToolHandle< CP::ILinearFakeBkgTool > &  tool,
Result result 
)

Definition at line 237 of file fbtTestBasics.cxx.

238 {
239  FBT_CHECK( tool->applySystematicVariation({}) );
240  float y;
241  FBT_CHECK( tool->getEventWeight(y, selection, process) );
242  result.value += y;
243  result.statUp = sqrt(pow(result.statUp, 2) + y*y);
244  result.statDown = sqrt(pow(result.statDown, 2) + y*y);
245  for(auto& sysvar : tool->affectingSystematics())
246  {
247  FBT_CHECK( tool->applySystematicVariation({sysvar}) );
248  FBT_CHECK( tool->getEventWeight(y, selection, process) );
249  result.variations[sysvar] += y;
250  }
251  return true;
252 }

◆ allTests()

bool allTests ( Store_t store)

Definition at line 110 of file fbtTestBasics.cxx.

111 {
112  std::vector<std::string> config;
113  Result result0, result1, result2, result3, result4, result5;
114 
115  if(verbose) std::cout <<"\nWill do minimal test with CP::ApplyFakeFactor\n";
117  FBT_CHECK( minimalTest("CP::ApplyFakeFactor", config, store, result0) );
118 
119  if(verbose) std::cout <<"\nWill do minimal test with CP::AsymptMatrixTool\n";
120  FBT_CHECK( minimalTest("CP::AsymptMatrixTool", config, store, result1) );
121 
122  if(verbose) std::cout <<"\nWill do minimal test with CP::LhoodMM_tools\n";
123  FBT_CHECK( minimalTest("CP::LhoodMM_tools", config, store, result2) );
124 
125  if(verbose) std::cout <<"\nWill test loading efficiencies from XML\n";
127  FBT_CHECK( minimalTest("CP::AsymptMatrixTool", config, store, result3) );
129  FBT_CHECK( result1 == result3 );
130 
131  if(verbose) std::cout <<"\nWill test getEventWeight()\n";
132  {
134  FBT_CHECK( setup(tool, "CP::AsymptMatrixTool", config) );
135  FBT_CHECK( eventLoop(tool, store, result4, nEvents) );
136  if(verbose) result3.Print();
137  }
138  FBT_CHECK( result1 == result4 );
139 
140  if(verbose) std::cout <<"\nWill test parallel jobs and merging\n";
141  FBT_CHECK( parallelJob("CP::LhoodMM_tools", config, store, "fbt_job1.root", 16, 0) );
142  FBT_CHECK( parallelJob("CP::LhoodMM_tools", config, store, "fbt_job2.root", 16, 16) );
143  FBT_CHECK( parallelJob("CP::LhoodMM_tools", config, store, "fbt_job3.root", 16, 32) );
144  FBT_CHECK( gSystem->Exec("hadd -f fbt_merged.root fbt_job*.root") == 0 );
145  {
147  FBT_CHECK( setup(tool, "CP::LhoodMM_tools", config, "fbt_merged.root") );
148  FBT_CHECK( fillResult(tool, result5) );
149  }
150  FBT_CHECK(result2 == result5 );
151 
152  return true;
153 }

◆ eventLoop()

template<class Interface = CP::IFakeBkgTool>
bool eventLoop ( asg::AnaToolHandle< Interface > &  tool,
Store_t store,
Result result,
int  nEvents,
int  eventOffset = 0 
)

Definition at line 205 of file fbtTestBasics.cxx.

206 {
207  auto eventInfo = std::make_unique<xAOD::EventInfo>();
208  auto eventAuxInfo = std::make_unique<xAOD::EventAuxInfo>();
209  eventInfo->setStore(eventAuxInfo.get());
210  static const SG::Accessor<int> flagAcc("flag");
211  flagAcc(*eventInfo) = 1;
212  FBT_CHECK( store->record(std::move(eventInfo), "EventInfo") );
213  FBT_CHECK( store->record(std::move(eventAuxInfo), "EventInfoAux.") );
214 
216  auto e = std::make_unique<xAOD::Electron>();
217  e->makePrivateStore();
218  e->setCharge(1);
219  particles.push_back(static_cast<xAOD::IParticle*>(&*e));
220  static const SG::Accessor<char> TightAcc("Tight");
221  for(int i=eventOffset;i<nEvents+eventOffset;++i)
222  {
223  e->setP4((1 + (i%3))*1e4, 0., 0. ,ParticleConstants::electronMassInMeV);
224  TightAcc(*e) = (i%4)? 0 : 1;
225  FBT_CHECK( tool->addEvent(particles) );
227  }
228 
229 #ifdef XAOD_STANDALONE
230  store->clear();
231 #else
232  FBT_CHECK( store->clearStore(true) );
233 #endif
234  return true;
235 }

◆ fillResult()

template<class Interface = CP::IFakeBkgTool>
bool fillResult ( asg::AnaToolHandle< Interface > &  tool,
Result result 
)

Definition at line 260 of file fbtTestBasics.cxx.

261 {
262  result.variations.clear();
263  FBT_CHECK( tool->getTotalYield(result.value, result.statUp, result.statDown) );
264  if(readCPVariations)
265  {
266  for(auto& sysvar : tool->affectingSystematics())
267  {
268  FBT_CHECK( tool->applySystematicVariation({sysvar}) );
269  float unused;
270  FBT_CHECK( tool->getTotalYield(result.variations[sysvar], unused, unused) );
271  }
272  }
273  if(verbose) result.Print();
274  return true;
275 }

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 82 of file fbtTestBasics.cxx.

83 {
84  for(int i=1;i<argc;++i)
85  {
86  std::string option = argv[i];
87  if(option=="-v" || option=="--verbose") verbose = true;
88  }
89 
90 #ifdef XAOD_STANDALONE
91  xAOD::Init("fbtTestBasics").ignore();
93  Store_t store = std::make_unique<xAOD::TStore>();
94  StatusCode::enableFailure();
95 #else
96  IAppMgrUI* app = POOL::Init();
98  FBT_CHECK1( event.evtStore().retrieve(), 1 );
99  Store_t store = event.evtStore().get();
100 #endif
101 
102  int returnCode = allTests(store) ? 0 : 1;
103 
104 #ifndef XAOD_STANDALONE
105  FBT_CHECK1( app->finalize(), 1 );
106 #endif
107  return returnCode;
108 }

◆ minimalTest()

bool minimalTest ( const std::string &  type,
const std::vector< std::string > &  config,
Store_t store,
Result result 
)

Definition at line 155 of file fbtTestBasics.cxx.

156 {
161  return true;
162 }

◆ parallelJob()

bool parallelJob ( const std::string &  type,
const std::vector< std::string > &  config,
Store_t store,
const std::string &  saveAs,
int  nEvents,
int  eventOffset 
)

Definition at line 164 of file fbtTestBasics.cxx.

165 {
168  Result result;
169  FBT_CHECK( eventLoop(tool, store, result, nEvents, eventOffset) );
170  std::unique_ptr<TFile> f(TFile::Open(saveAs.c_str(), "RECREATE"));
171  FBT_CHECK( !!f );
172  FBT_CHECK( tool->saveProgress(f->mkdir("fakes")) );
173  f->Close();
174  if(verbose)
175  {
176  float value, up, down;
177  FBT_CHECK( tool->getTotalYield(value, up, down) );
178  std::cout << "Parallel job stored intermediate yield " << value << " +" << up << " -" << down << std::endl;
179  }
180  return true;
181 }

◆ readFromROOT()

bool readFromROOT ( std::vector< std::string > &  config)

Definition at line 310 of file fbtTestBasics.cxx.

311 {
312  config.clear();
313  config.emplace_back("fbt_efficiencies.root");
314  TH1D hElFake("FakeEfficiency_el_pt","FakeEfficiency", 1, 10., 100.);
315  hElFake.SetBinContent(1, 0.05);
316  hElFake.SetBinError(1, 0.01);
317  TH1D hMuFake("FakeEfficiency_mu_pt","FakeEfficiency", 1, 10., 100.);
318  hMuFake.SetBinContent(1, 0.15);
319  hMuFake.SetBinError(1, 0.032);
320  TH1D hElReal("RealEfficiency_el_pt","RealEfficiency", 1, 10., 100.);
321  hElReal.SetBinContent(1, 0.90);
322  hElReal.SetBinError(1, 0.01);
323  TH1D hMuReal("RealEfficiency_mu_pt","RealEfficiency", 1, 10., 100.);
324  hMuReal.SetBinContent(1, 0.95);
325  hMuReal.SetBinError(1, 0.01);
326  std::unique_ptr<TFile> f(TFile::Open(config.back().c_str(), "RECREATE"));
327  FBT_CHECK( !!f );
328  f->cd();
329  hElFake.Write();
330  hElReal.Write();
331  hMuFake.Write();
332  hMuReal.Write();
333  f->Close();
334  return true;
335 }

◆ readFromXML()

bool readFromXML ( std::vector< std::string > &  config)

note: the declarations must be placed in the "good" order, otherwise the definitions of the SystematicVariations will be different than those obtained with readFromROOT()

Definition at line 337 of file fbtTestBasics.cxx.

338 {
339  config.clear();
340  config.emplace_back("fbt_efficiencies.xml");
341  std::ofstream out(config.back().c_str(), std::ios_base::out);
342  FBT_CHECK( out.is_open() );
345  out << "<efficiencies>\n";
346  out << "<param type=\"int\" level=\"event\"> flag </param>\n";
347  out << "<electron type=\"fake-efficiency\" input=\"central-value\" stat=\"per-bin\" >\n\t<bin flag=\"1\">\n 0.05 +- 0.01 (stat) </bin>\n</electron>\n";
348  out << "<electron type=\"real-efficiency\" input=\"central-value\" stat=\"global\" >\n\t<bin flag=\"1\">\n 0.90 +- 0.01 (stat) </bin>\n</electron>\n";
349  out << "<muon type=\"fake-efficiency\" input=\"central-value\" stat=\"per-bin\" >\n\t<bin flag=\"1\">\n 0.15 +- 0.032 (stat) </bin>\n</muon>\n";
350  out << "<muon type=\"real-efficiency\" input=\"central-value\" stat=\"global\" >\n\t<bin flag=\"1\">\n 0.95 +- 0.01 (stat) </bin>\n</muon>\n";
351  out << "</efficiencies>\n";
352  out.close();
353  return true;
354 }

◆ setup()

template<class Interface = CP::IFakeBkgTool>
bool setup ( asg::AnaToolHandle< Interface > &  tool,
const std::string &  type,
const std::vector< std::string > &  config,
const std::string &  progressFile = "" 
)

mostly useful for athena, which will otherwise re-use the previous tool

Definition at line 186 of file fbtTestBasics.cxx.

187 {
189  FBT_CHECK( tool.setProperty("InputFiles", config) );
190  FBT_CHECK( tool.setProperty("EnergyUnit", "GeV") );
191  FBT_CHECK( tool.setProperty("ConvertWhenMissing", true) );
192  FBT_CHECK( tool.setProperty("Selection", selection) );
193  FBT_CHECK( tool.setProperty("Process", process) );
194  if(!progressFile.empty())
195  {
196  FBT_CHECK( tool.setProperty("ProgressFileName", progressFile) );
197  FBT_CHECK( tool.setProperty("ProgressFileDirectory", "fakes") );
198  }
199  FBT_CHECK( tool.initialize() );
200  return true;
201 
202 }

◆ successful() [1/2]

bool successful ( bool  arg)

Definition at line 37 of file fbtTestBasics.cxx.

37 { return arg; }

◆ successful() [2/2]

bool successful ( const StatusCode &  arg)

Definition at line 38 of file fbtTestBasics.cxx.

38 { return arg.isSuccess(); }

Variable Documentation

◆ nEvents

const int nEvents = 48

Definition at line 78 of file fbtTestBasics.cxx.

◆ process

const std::string process = ">=1F[T]"

Definition at line 76 of file fbtTestBasics.cxx.

◆ readCPVariations

const bool readCPVariations = true

Definition at line 77 of file fbtTestBasics.cxx.

◆ selection

const std::string selection = ">=1T"

Definition at line 75 of file fbtTestBasics.cxx.

◆ verbose

std::atomic<bool> verbose = false

Definition at line 80 of file fbtTestBasics.cxx.

nEvents
const int nEvents
Definition: fbtTestBasics.cxx:78
verbose
std::atomic< bool > verbose
Definition: fbtTestBasics.cxx:80
readCPVariations
const bool readCPVariations
Definition: fbtTestBasics.cxx:77
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
SGTest::store
TestStore store
Definition: TestStore.cxx:23
asg::AnaToolHandle
a modified tool handle that allows its owner to configure new tools from the C++ side
Definition: AnaToolHandle.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
Result::Print
void Print() const
Definition: fbtTestBasics.cxx:301
SG::Accessor< int >
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
setup
bool setup(asg::AnaToolHandle< Interface > &tool, const std::string &type, const std::vector< std::string > &config, const std::string &progressFile="")
mostly useful for athena, which will otherwise re-use the previous tool
Definition: fbtTestBasics.cxx:186
python.base_data.config
config
Definition: base_data.py:20
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
athena.value
value
Definition: athena.py:124
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:101
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
x
#define x
eventLoop
bool eventLoop(asg::AnaToolHandle< Interface > &tool, Store_t &store, Result &result, int nEvents, int eventOffset=0)
Definition: fbtTestBasics.cxx:205
minimalTest
bool minimalTest(const std::string &type, const std::vector< std::string > &config, Store_t &store, Result &result)
Definition: fbtTestBasics.cxx:155
FBT_CHECK1
#define FBT_CHECK1(x, FAIL)
Definition: fbtTestBasics.cxx:40
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
successful
bool successful(bool arg)
Definition: fbtTestBasics.cxx:37
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
POOL::Init
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:29
FBT_CHECK
#define FBT_CHECK(x)
Definition: fbtTestBasics.cxx:47
POOL::TEvent::kClassAccess
@ kClassAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:46
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:120
allTests
bool allTests(Store_t &store)
Definition: fbtTestBasics.cxx:110
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
PixelAthClusterMonAlgCfg.e4
e4
Definition: PixelAthClusterMonAlgCfg.py:332
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
readFromXML
bool readFromXML(std::vector< std::string > &config)
Definition: fbtTestBasics.cxx:337
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:108
hist_file_dump.f
f
Definition: hist_file_dump.py:140
fillResult
bool fillResult(asg::AnaToolHandle< Interface > &tool, Result &result)
Definition: fbtTestBasics.cxx:260
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:19
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
selection
const std::string selection
Definition: fbtTestBasics.cxx:75
POOL::TEvent
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:40
Result
Definition: fbtTestBasics.cxx:50
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
POOL::TEvent::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:60
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
SGTest::TestStore::record
void record(const T *p, const std::string &key)
Definition: TestStore.h:81
readFromROOT
bool readFromROOT(std::vector< std::string > &config)
Definition: fbtTestBasics.cxx:310
addEventWeight
bool addEventWeight(asg::AnaToolHandle< CP::ILinearFakeBkgTool > &tool, Result &result)
Definition: fbtTestBasics.cxx:237
unused
void unused(Args &&...)
Definition: VP1ExpertSettings.cxx:39
process
const std::string process
Definition: fbtTestBasics.cxx:76
y
#define y
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
parallelJob
bool parallelJob(const std::string &type, const std::vector< std::string > &config, Store_t &store, const std::string &saveAs, int nEvents, int eventOffset)
Definition: fbtTestBasics.cxx:164
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:85
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31
ParticleConstants::PDG2011::electronMassInMeV
constexpr double electronMassInMeV
the mass of the electron (in MeV)
Definition: ParticleConstants.h:26