DAS  3.0
Das Analysis System
Di.cc File Reference
#include <boost/test/included/unit_test.hpp>
#include <iostream>
#include <map>
#include <TFile.h>
#include <TTree.h>
#include <Di.h>
#include <Jet.h>
+ Include dependency graph for Di.cc:

Macros

#define BOOST_TEST_MODULE   Di
 

Functions

vector< GenJetGetDummyGenJets ()
 
 BOOST_AUTO_TEST_CASE (dijet)
 
 BOOST_TEST (gendijet.Rapidity()==1.3573785791881385)
 
 BOOST_AUTO_TEST_CASE (variations)
 

Variables

auto gendijet = genjets.at(0) + genjets.at(1)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   Di

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( dijet  )
52 {
53  vector<GenJet> * genjets = new vector<GenJet>;
54  auto gendijet = new Di<GenJet,GenJet>;
55  bool valid = static_cast<bool>(*gendijet);
56  BOOST_TEST(!valid);
57 
59  cout << *gendijet << endl;
60  *gendijet = genjets->at(0) + genjets->at(1);
61  valid = static_cast<bool>(*gendijet);
62  BOOST_TEST(valid);
63 
64  auto f = make_unique<TFile>("di.root", "RECREATE");
65 
66  cout << "Creating tree" << endl;
67  {
68  auto t = make_unique<TTree>("tree", "tree");
69  t->Branch("genJets", &genjets);
70  t->Branch("genDijet", &gendijet);
71  t->Fill();
72  t->Write();
73  // Note: calling `TTree:Scan()` at this stage leads to a seg
74  }
75 
76  delete genjets;
77  delete gendijet;
78  genjets = nullptr;
79  gendijet = nullptr;
80 
81  cout << "Reading tree" << endl;
82  {
83  auto t = unique_ptr<TTree>(f->Get<TTree>("tree"));
84  t->Show(0);
85  cout << "Checking genJets" << endl;
86  t->Scan("genJets.CorrPt()");
87  cout << "Checking genDijet" << endl;
88  t->Scan("genDijet.first.CorrPt():genDijet.second.CorrPt():genDijet.HT()");
89  cout << "Setting branch addresses" << endl;
90  t->SetBranchAddress("genJets", &genjets);
91  t->SetBranchAddress("genDijet", &gendijet);
92  t->GetEntry(0);
93  BOOST_TEST( genjets->at(0).CorrPt() == 1. );
94  BOOST_TEST( genjets->at(1).CorrPt() == 2. );
95  BOOST_TEST( gendijet->HT() == 1.5 );
96  gendijet->clear();
97  BOOST_TEST( gendijet->first == nullptr );
98  BOOST_TEST( gendijet->second == nullptr );
99  }
100 }

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( variations  )
121 {
122  auto genjets = GetDummyGenJets();
123  auto gendijet = genjets.at(0) + genjets.at(1);
124 
125  using namespace Darwin::Physics;
126  cout << genjets.at(0).Weight(nominal) << ' ' << genjets.at(1).Weight(nominal) << ' ' << gendijet.Weight(nominal) << endl;
127 
128  map<int, double> bits_results {{1,1.5}, {2,1.5}, {3,1.0}};
129  for (auto bit_result: bits_results) {
130  int bit = bit_result.first;
131  double result = bit_result.second;
132  Variation v(GenJet::WeightVar, "wgtUp_stat" + to_string(bit), 1, bit);
133  cout << "1st-jet weight: " << genjets.at(0).Weight(v) << '\n'
134  << "2nd-jet weight: " << genjets.at(1).Weight(v) << '\n'
135  << "dijet weight: " << gendijet.Weight(v) << endl;
136  BOOST_TEST( gendijet.Weight(v) == result );
137  }
138 
139  for (int i = 1; i <= 2; ++i) {
140  Variation v(GenJet::ScaleVar, "scale", i);
141  cout << "1st-jet corrected pt: " << genjets.at(0).CorrPt(v) << '\n'
142  << "2nd-jet corrected pt: " << genjets.at(1).CorrPt(v) << '\n'
143  << "dijet corrected pt: " << gendijet.CorrPt(v) << '\n'
144  << "dijet corrected HT: " << gendijet.HT(v) << endl;
145  BOOST_TEST( genjets.at(0).CorrPt(i) == genjets.at(0).CorrPt(v) );
146  BOOST_TEST( genjets.at(1).CorrPt(i) == genjets.at(1).CorrPt(v) );
147  BOOST_TEST( 2*gendijet.HT(v) == genjets.at(0).CorrPt(i) + genjets.at(1).CorrPt(i) );
148  }
149 }

◆ BOOST_TEST()

BOOST_TEST ( gendijet.  Rapidity() = =1.3573785791881385)

◆ GetDummyGenJets()

vector<GenJet> GetDummyGenJets ( )
25 {
26  GenJet genjet1, genjet2;
27 
28  // 4-vectors
29  genjet1.p4 = {1,1,1,1};
30  genjet2.p4 = {2,2,2,2};
31 
32  // JES
33  genjet1.scales.push_back(1.5);
34  genjet1.scales.push_back(0.5);
35  genjet2.scales.push_back(1.5);
36  genjet2.scales.push_back(0.5);
37 
38  // weights
39  genjet1.weights.push_back({1.5,1});
40  genjet1.weights.push_back({0.5,1});
41  genjet2.weights.push_back({1.5,2});
42  genjet2.weights.push_back({0.5,2});
43 
44  // collection
45  vector<GenJet> genjets;
46  genjets.push_back(genjet1);
47  genjets.push_back(genjet2);
48  return genjets;
49 }

Variable Documentation

◆ gendijet

auto gendijet = genjets.at(0) + genjets.at(1)
gendijet
GenDijet gendijet
Definition: Di.cc:98
GetDummyGenJets
vector< GenJet > GetDummyGenJets()
Definition: Di.cc:18
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:252
Darwin::Physics::GenJet
Generic generator-level jet.
Definition: Jet.h:14
Darwin::Physics::Variation
Definition: Variation.h:20
Ntupliser_cfg.genjets
genjets
Definition: Ntupliser_cfg.py:268
Darwin::Physics::GenericObject::weights
Weights weights
object weights
Definition: GenericObject.h:55
Darwin::Physics::GenJet::WeightVar
static const char *const *const WeightVar
Definition: Jet.h:21
Darwin::Physics::nominal
const Variation nominal("", "nominal")
Darwin::Physics::GenericObject::scales
std::vector< float > scales
energy scale corrections and variations
Definition: GenericObject.h:54
Darwin::Physics::Di
Definition: Di.h:37
Darwin::Physics::GenJet::ScaleVar
static const char *const ScaleVar
Definition: Jet.h:20
Darwin::Physics::GenericObject::p4
FourVector p4
raw four-momentum directly after reconstruction
Definition: GenericObject.h:53
Darwin::Physics
Everything what concerns physics analysis directly.
Definition: darwin.h:23