|
DAS
3.0
Das Analysis System
|
#include <boost/test/included/unit_test.hpp>
#include <boost/exception/all.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include "test.h"
#include "exceptions.h"
#include "Options.h"
#include "UserInfo.h"
#include "MetaInfo.h"
#include "example01.cc"
#include "example02.cc"
#include "example03.cc"
#include "example04.cc"
#include "../bin/getMetaInfo.cc"
#include "../bin/printMetaInfo.cc"
#include "../bin/printEntries.cc"
#include "../bin/printBranches.cc"
#include "../bin/forceMetaInfo.cc"
|
template<bool DARWIN_TEST_EXCEPTIONS = false> |
void | example02 (const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0}) |
|
template<bool DARWIN_TEST_EXCEPTIONS = false> |
void | example03 (const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0}) |
|
void | example04 (const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0}) |
|
| BOOST_AUTO_TEST_CASE (output) |
|
| BOOST_AUTO_TEST_CASE (getters) |
|
| BOOST_AUTO_TEST_CASE (ntuple_producer) |
|
| BOOST_AUTO_TEST_CASE (ntuple_weight_modifier) |
|
| BOOST_AUTO_TEST_CASE (ntuple_JEC_modifier) |
|
| BOOST_AUTO_TEST_CASE (projection) |
|
| BOOST_AUTO_TEST_CASE (all_steps) |
|
| BOOST_AUTO_TEST_CASE (getBool) |
|
| BOOST_AUTO_TEST_CASE (forceMetaInfo) |
|
| BOOST_AUTO_TEST_CASE (GetFirstTreeLocation) |
|
| BOOST_AUTO_TEST_CASE (printEntries) |
|
| BOOST_AUTO_TEST_CASE (printBranches) |
|
| BOOST_AUTO_TEST_CASE (printMetaInfo) |
|
| BOOST_AUTO_TEST_CASE (closure) |
|
| BOOST_AUTO_TEST_CASE (exceptions) |
|
◆ BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test |
◆ DARWIN_GIT_REPO
#define DARWIN_GIT_REPO DARWIN |
◆ DOXYGEN_SHOULD_SKIP_THIS
#define DOXYGEN_SHOULD_SKIP_THIS |
◆ BOOST_AUTO_TEST_CASE() [1/15]
BOOST_AUTO_TEST_CASE |
( |
all_steps |
| ) |
|
257 BOOST_REQUIRE_NO_THROW( pt::read_info(
"example.info",
config) );
260 BOOST_REQUIRE_NO_THROW( DP::example01(
"ntuple01.root",
config, steering) );
261 BOOST_REQUIRE_NO_THROW(
DP::example02(
"ntuple01.root",
"ntuple02.root",
config, steering) );
262 BOOST_REQUIRE_NO_THROW(
DP::example03(
"ntuple02.root",
"ntuple03.root",
config, steering) );
263 BOOST_REQUIRE_NO_THROW(
DP::example04(
"ntuple03.root",
"hists04.root",
config, steering) );
◆ BOOST_AUTO_TEST_CASE() [2/15]
BOOST_AUTO_TEST_CASE |
( |
closure |
| ) |
|
330 unique_ptr<TFile>
f(TFile::Open(
"ntuple02.root"));
334 vector<string> exts {
"info",
"xml",
"json"};
335 for (
string ext: exts) {
336 fs::path file =
"out1." + ext;
337 vector<fs::path>
inputs = {
"ntuple02.root"};
341 auto getHash = [](
const fs::path& ntuple) {
342 auto rootfile = unique_ptr<TFile>(TFile::Open(ntuple.c_str(),
"READ"));
343 auto events = unique_ptr<TTree>(rootfile->Get<TTree>(
"events"));
348 size_t Hash = getHash(
"ntuple02.root");
351 auto chain = [&
config,&getHash](
const fs::path& fOut,
bool isMC) {
352 fs::remove(
"ntuple02.root");
353 fs::remove(
"ntuple03.root");
357 DP::example01(
"ntuple01.root",
config, steering);
361 vector<fs::path>
inputs = {
"hists04.root"};
363 size_t Hash = getHash(
"ntuple02.root");
364 fs::remove(
"ntuple01.root");
365 fs::rename(
"hists04.root", Form(
"hists04_%s_%s.root", &(fOut.extension().c_str()[1]),
isMC ?
"true" :
"false"));
369 pt::read_info(
"out1.info",
config);
370 int oldseed =
config.get<
int>(
"preseed");
371 config.put<
int>(
"preseed", 2*oldseed);
372 BOOST_TEST( Hash != chain(
"out2.info",
true ) );
373 config.put<
int>(
"preseed", oldseed);
374 BOOST_TEST( Hash == chain(
"out2.info",
true ) );
375 BOOST_TEST( Hash != chain(
"out2.info",
false) );
377 pt::read_json(
"out1.json",
config);
378 BOOST_TEST( Hash == chain(
"out2.json",
true ) );
379 BOOST_TEST( Hash != chain(
"out2.json",
false) );
381 pt::read_xml(
"out1.xml",
config);
383 BOOST_TEST( Hash == chain(
"out2.xml",
true ) );
384 BOOST_TEST( Hash != chain(
"out2.xml",
false) );
386 vector<fs::path>
inputs = {
"hists04_info_true.root" ,
"hists04_json_true.root" ,
"hists04_xml_true.root" };
388 inputs = {
"hists04_info_false.root",
"hists04_json_false.root",
"hists04_xml_false.root"};
390 inputs = {
"hists04_info_true.root" ,
"hists04_info_false.root"};
393 for (
string name: {
"true",
"false",
"failure"})
394 fs::remove(
name +
".info");
396 for (
string ext: exts) {
397 fs::remove(
"out1." + ext);
398 fs::remove(
"out2." + ext);
399 for (
string b: {
"true",
"false"})
400 fs::remove(
"hists04_" + ext +
"_" + b +
".root");
◆ BOOST_AUTO_TEST_CASE() [3/15]
BOOST_AUTO_TEST_CASE |
( |
exceptions |
| ) |
|
407 auto f = unique_ptr<TFile>(TFile::Open(
"ntuple02.root",
"READ"));
408 auto t = unique_ptr<TTree>(
f->Get<TTree>(
"events"));
410 cout <<
DE::BadInput(
"Here is a bad input", metainfo).what() << endl;
412 cout <<
DE::AnomalousEvent(
"Here is an anomally (just for the example)", t).what() << endl;
416 BOOST_REQUIRE_NO_THROW( pt::read_info(DARWIN
"/test/example.info",
config) );
419 DP::example01(
"ntuple01.root",
config, steering);
420 BOOST_REQUIRE_THROW( DP::example02<true>(
"ntuple01.root",
"ntuple02.root",
config, steering), boost::wrapexcept<DE::AnomalousEvent> );
421 BOOST_REQUIRE_THROW( DP::example01<true>(
"ntuple01.root",
config, steering), boost::wrapexcept<DE::BadInput > );
423 fs::remove(
"inexistent.out");
424 fs::remove(
"ntuple01.root");
◆ BOOST_AUTO_TEST_CASE() [4/15]
BOOST_AUTO_TEST_CASE |
( |
forceMetaInfo |
| ) |
|
278 vector<fs::path>
input = {
"ntuple02.root"};
281 input = {
"ntuple01.root"};
283 unique_ptr<TFile>
f(TFile::Open(
"ntuple01.root",
"READ"));
284 auto events = unique_ptr<TTree>(
f->Get<TTree>(
"events"));
287 BOOST_TEST( !metainfo.Get<
bool>(
"git",
"reproducible") );
◆ BOOST_AUTO_TEST_CASE() [5/15]
BOOST_AUTO_TEST_CASE |
( |
getBool |
| ) |
|
◆ BOOST_AUTO_TEST_CASE() [6/15]
BOOST_AUTO_TEST_CASE |
( |
GetFirstTreeLocation |
| ) |
|
295 TFile::Open(
"GetFirstTreeLocation.root",
"RECREATE")->Close();
◆ BOOST_AUTO_TEST_CASE() [7/15]
BOOST_AUTO_TEST_CASE |
( |
getters |
| ) |
|
78 vector<fs::path>
files;
79 BOOST_REQUIRE_THROW( DT::GetHist<TH1>(
files,
"h"), boost::wrapexcept<fs::filesystem_error> );
81 BOOST_REQUIRE_THROW( flow.GetInputTree(
files, {0, 1},
"t"), boost::wrapexcept<invalid_argument> );
83 for (
int i = 1; i < 4; ++i) {
84 fs::path
name = Form(
"getters_%d.root", i);
87 unique_ptr<TFile>
f(TFile::Open(
name.c_str(),
"RECREATE"));
88 auto h = make_unique<TH1F>(
"h",
"h", 1, 0., 1.);
89 auto t = make_unique<TTree>(
"t",
"t");
90 h->SetDirectory(
f.get());
91 t->SetDirectory(
f.get());
96 BOOST_REQUIRE_THROW( DT::GetHist<TH1> (
files,
"thisHistDoesNotExist"), boost::wrapexcept<DE::BadInput> );
97 BOOST_REQUIRE_THROW( flow.GetInputTree(
files, {1, 0},
"t" ), boost::wrapexcept<invalid_argument> );
98 BOOST_REQUIRE_THROW( flow.GetInputTree(
files, {1, 0},
"thisTreeDoesNotExist"), boost::wrapexcept<DE::BadInput> );
100 BOOST_REQUIRE_NO_THROW( DT::GetHist<TH1>(
files,
"h") );
◆ BOOST_AUTO_TEST_CASE() [8/15]
BOOST_AUTO_TEST_CASE |
( |
ntuple_JEC_modifier |
| ) |
|
176 fs::path
input, output;
181 .output(
"output", &output,
"output ROOT file");
183 for (
string mode: {
"f",
"F"}) {
184 string cmd =
"example03 ntuple02_" + mode +
".root ntuple03_" + mode +
".root -j 3 -k 1 -" + mode +
" -s";
190 const auto& slice =
options.slice();
191 const int steering =
options.steering();
196 vector<DP::RecJet> * recs_f =
nullptr,
200 flow_f.GetInputTree(vector<fs::path>{
"ntuple03_f.root"});
201 flow_F.GetInputTree(vector<fs::path>{
"ntuple03_F.root"});
202 BOOST_REQUIRE_NO_THROW( recs_f = flow_f.GetBranchReadOnly<vector<DP::RecJet>>(
"recJets") );
203 BOOST_REQUIRE_NO_THROW( recs_F = flow_F.GetBranchReadOnly<vector<DP::RecJet>>(
"recJets") );
205 string active_branches_f = flow_f.DumpActiveBranches(),
206 active_branches_F = flow_F.DumpActiveBranches();
207 cout <<
"Without friends: " << active_branches_f << endl;
208 cout <<
"With friends: " << active_branches_F << endl;
209 BOOST_TEST( active_branches_f == active_branches_F );
211 auto tIn_f = flow_f.GetInputTree(),
212 tIn_F = flow_F.GetInputTree();
213 BOOST_TEST( tIn_f->GetEntries() == tIn_F->GetEntries() );
215 for (
long long i = 0; i < tIn_f->GetEntries(); ++i) {
218 BOOST_TEST( recs_f->size() == recs_F->size() );
219 for (
size_t j = 0; j < recs_f->size(); ++j)
220 BOOST_TEST( recs_f->at(j).CorrPt() == recs_F->at(j).CorrPt() );
223 fs::remove(
"ntuple02_f.root");
224 fs::remove(
"ntuple03_f.root");
◆ BOOST_AUTO_TEST_CASE() [9/15]
BOOST_AUTO_TEST_CASE |
( |
ntuple_producer |
| ) |
|
112 options.output(
"output" , &output,
"output ROOT file")
113 .arg<
bool> (
"isMC" ,
"flags.isMC" ,
"flag" )
114 .arg<float> (
"R" ,
"flags.R" ,
"R parameter in jet clustering algorithm")
115 .arg<
int > (
"year" ,
"flags.year" ,
"year (20xx)" );
117 auto const args =
tokenize(
"example01 ntuple01.root -c example.info -f");
121 const int steering =
options.steering();
123 BOOST_REQUIRE_NO_THROW( DP::example01(output,
config, steering) );
◆ BOOST_AUTO_TEST_CASE() [10/15]
BOOST_AUTO_TEST_CASE |
( |
ntuple_weight_modifier |
| ) |
|
128 fs::path
input, output;
133 .output(
"output", &output,
"output ROOT file")
134 .arg<fs::path>(
"filters",
"corrections.filters",
"location of list of event filters to apply");
136 for (
string mode: {
"f",
"F"}) {
137 string cmd =
"example02 ntuple01.root ntuple02_" + mode +
".root -c example.info -v -j 2 -k 1 -" + mode;
143 const auto& slice =
options.slice();
144 const int steering =
options.steering();
155 auto tIn_f = flow_f.GetInputTree({
"ntuple02_f.root"}),
156 tIn_F = flow_F.GetInputTree({
"ntuple02_F.root"});
157 BOOST_TEST( tIn_f->GetEntries() == tIn_F->GetEntries() );
159 BOOST_TEST_MESSAGE(
"Trying to load an inexistant branch" );
163 BOOST_TEST_MESSAGE(
"Loading the analog branch in the friend and no-friend n-tuples." );
164 BOOST_REQUIRE_NO_THROW( event_f = flow_f.GetBranchReadOnly<
DP::RecEvent>(
"recEvent") );
165 BOOST_REQUIRE_NO_THROW( event_F = flow_F.GetBranchReadOnly<
DP::RecEvent>(
"recEvent") );
167 for (
long long i = 0; i < tIn_f->GetEntries(); ++i) {
◆ BOOST_AUTO_TEST_CASE() [11/15]
BOOST_AUTO_TEST_CASE |
( |
output |
| ) |
|
72 BOOST_REQUIRE_THROW(
DT::GetOutputFile(
"/this/file/does/not/exists.root"), boost::wrapexcept<fs::filesystem_error> );
◆ BOOST_AUTO_TEST_CASE() [12/15]
BOOST_AUTO_TEST_CASE |
( |
printBranches |
| ) |
|
315 vector<fs::path>
inputs {
"ntuple01.root"};
◆ BOOST_AUTO_TEST_CASE() [13/15]
BOOST_AUTO_TEST_CASE |
( |
printEntries |
| ) |
|
301 auto f = TFile::Open(
"printEntries.root",
"RECREATE");
303 auto d =
f->mkdir(
"dir2"); d->cd();
304 auto dd = d->mkdir(
"subdir"); dd->cd();
305 auto t =
new TTree(
"one_tree",
"");
310 fs::remove(
"printEntries.root");
◆ BOOST_AUTO_TEST_CASE() [14/15]
BOOST_AUTO_TEST_CASE |
( |
printMetaInfo |
| ) |
|
321 vector<fs::path>
inputs {
"ntuple01.root"};
323 tree.put<
string>(
"path",
"preseed");
◆ BOOST_AUTO_TEST_CASE() [15/15]
BOOST_AUTO_TEST_CASE |
( |
projection |
| ) |
|
229 fs::path
input, output;
233 .output(
"output", &output,
"output ROOT file");
235 auto const args =
tokenize(
"example04 ntuple03_F.root hists04.root");
239 const auto& slice =
options.slice();
240 const int steering =
options.steering();
244 fs::remove(
"ntuple01.root");
245 fs::remove(
"ntuple02_F.root");
246 fs::remove(
"ntuple03_F.root");
247 fs::remove(
"hists04.root");
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
options
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:41
void example03(const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
Definition: main.cc:49
static bool verbose
Definition: Step.h:40
args
Definition: Ntupliser_cfg.py:11
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Hash from TTree obtained by combination of different elements.
Definition: UserInfo.h:286
f
Definition: Ntupliser_cfg.py:256
void example02(const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
Definition: main.cc:41
void example04(const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
Definition: main.cc:56
files
Definition: compareFiles.py:125
cmd
Definition: Core-cfgcmd.txt:1
config
Definition: Ntupliser_cfg.py:264
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35
Generic detector-level event.
Definition: Event.h:64
string isMC
Definition: Ntupliser_cfg.py:59
def inputs
Definition: jercExample.py:118
Generic exception for problematic event (during event loop).
Definition: exceptions.h:63
Weights weights
e.g. cross section normalisation
Definition: Event.h:26