38bool successful(
const StatusCode& arg) {
return arg.isSuccess(); }
40#define FBT_CHECK1(x, FAIL) \
42 if(!successful(x)) { \
43 Error("fbtTestBasics", "failure encounted on l.%d", __LINE__); \
47#define FBT_CHECK(x) FBT_CHECK1(x, false)
58using Store_t = std::unique_ptr<xAOD::TStore>;
82int main(
int argc,
char* argv[])
84 for(
int i=1;i<argc;++i)
86 std::string option = argv[i];
87 if(option==
"-v" || option==
"--verbose")
verbose =
true;
93 Store_t store = std::make_unique<xAOD::TStore>();
94 StatusCode::enableFailure();
99 Store_t store =
event.evtStore().get();
102 int returnCode =
allTests(store) ? 0 : 1;
104#ifndef XAOD_STANDALONE
112 std::vector<std::string>
config;
113 Result result0, result1, result2, result3, result4, result5;
115 if(
verbose) std::cout <<
"\nWill do minimal test with CP::ApplyFakeFactor\n";
119 if(
verbose) std::cout <<
"\nWill do minimal test with CP::AsymptMatrixTool\n";
122 if(
verbose) std::cout <<
"\nWill do minimal test with CP::LhoodMM_tools\n";
125 if(
verbose) std::cout <<
"\nWill test loading efficiencies from XML\n";
131 if(
verbose) std::cout <<
"\nWill test getEventWeight()\n";
140 if(
verbose) std::cout <<
"\nWill test parallel jobs and merging\n";
144 FBT_CHECK( gSystem->Exec(
"hadd -f fbt_merged.root fbt_job*.root") == 0 );
170 std::unique_ptr<TFile> f(TFile::Open(saveAs.c_str(),
"RECREATE"));
172 FBT_CHECK( tool->saveProgress(f->mkdir(
"fakes")) );
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;
185template<
class Interface>
190 FBT_CHECK( tool.setProperty(
"EnergyUnit",
"GeV") );
191 FBT_CHECK( tool.setProperty(
"ConvertWhenMissing",
true) );
194 if(!progressFile.empty())
196 FBT_CHECK( tool.setProperty(
"ProgressFileName", progressFile) );
197 FBT_CHECK( tool.setProperty(
"ProgressFileDirectory",
"fakes") );
204template<
class Interface>
207 auto eventInfo = std::make_unique<xAOD::EventInfo>();
208 auto eventAuxInfo = std::make_unique<xAOD::EventAuxInfo>();
209 eventInfo->setStore(eventAuxInfo.get());
211 flagAcc(*eventInfo) = 1;
216 auto e = std::make_unique<xAOD::Electron>();
217 e->makePrivateStore();
221 for(
int i=eventOffset;i<
nEvents+eventOffset;++i)
223 e->setPtEtaPhi((1 + (i%3))*1e4, 0., 0.);
224 TightAcc(*e) = (i%4)? 0 : 1;
229#ifdef XAOD_STANDALONE
239 FBT_CHECK( tool->applySystematicVariation({}) );
245 for(
auto& sysvar : tool->affectingSystematics())
247 FBT_CHECK( tool->applySystematicVariation({sysvar}) );
249 result.variations[sysvar] +=
y;
259template<
class Interface>
262 result.variations.clear();
266 for(
auto& sysvar : tool->affectingSystematics())
268 FBT_CHECK( tool->applySystematicVariation({sysvar}) );
279 auto compare = [&](
auto x1,
auto x2) ->
bool
281 bool closeEnough = std::fabs(x1 - x2) < std::max(1e-5, 1e-3 * std::min(std::fabs(x1), std::fabs(x2)));;
284 std::cout <<
"ERROR: found different values for the equality test: " << x1 <<
" vs " << x2 << std::endl;
296 FBT_CHECK( compare(kv.second, itr->second) );
303 std::cout <<
"Result: total yield = " <<
value <<
" +" <<
statUp <<
" -" <<
statDown << std::endl;
306 std::cout <<
" variation " << kv.first.name() <<
" = " << kv.second << std::endl;
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"));
340 config.emplace_back(
"fbt_efficiencies.xml");
341 std::ofstream out(
config.back().c_str(), std::ios_base::out);
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";
Helper class to provide type-safe access to aux data.
A number of constexpr particle constants to avoid hardcoding them directly in various places.
constexpr int pow(int base, int exp) noexcept
void record(const T *p, const std::string &key)
Helper class to provide type-safe access to aux data.
The Athena Transient Store API.
Class providing the definition of the 4-vector interface.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
const bool readCPVariations
bool successful(bool arg)
bool fillResult(asg::AnaToolHandle< Interface > &tool, 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 eventLoop(asg::AnaToolHandle< Interface > &tool, Store_t &store, Result &result, int nEvents, int eventOffset=0)
bool readFromXML(std::vector< std::string > &config)
bool allTests(Store_t &store)
bool addEventWeight(asg::AnaToolHandle< CP::ILinearFakeBkgTool > &tool, Result &result)
const std::string selection
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
#define FBT_CHECK1(x, FAIL)
const std::string process
bool minimalTest(const std::string &type, const std::vector< std::string > &config, Store_t &store, Result &result)
bool readFromROOT(std::vector< std::string > &config)
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
std::map< CP::SystematicVariation, float > variations
bool operator==(const Result &) const