DAS  3.0
Das Analysis System
Di.cc File Reference
#include "Core/Objects/interface/Di.h"
#include <boost/test/included/unit_test.hpp>
#include <iostream>
#include <map>
#include <TTree.h>
#include <TFile.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

GenDijet 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  )
46 {
47  vector<GenJet> * genjets = new vector<GenJet>;
48  auto gendijet = new GenDijet;
49  bool valid = static_cast<bool>(*gendijet);
50  //cout << __LINE__ << ' ' << valid << endl;
51  BOOST_TEST(!valid);
52 
54  cout << *gendijet << endl;
55  *gendijet = genjets->at(0) + genjets->at(1);
56  valid = static_cast<bool>(*gendijet);
57  //cout << *valid << endl;
58  BOOST_TEST(valid);
59 
60  auto f = make_unique<TFile>("di.root", "RECREATE");
61 
62  cout << "Creating tree" << endl;
63  {
64  auto t = make_unique<TTree>("tree", "tree");
65  t->Branch("genJets", &genjets);
66  t->Branch("genDijet", &gendijet);
67  t->Fill();
68  t->Write();
69  // NOTE: calling `TTree:Scan()` at this stage leads to a seg
70  }
71 
72  delete genjets;
73  delete gendijet;
74  genjets = nullptr;
75  gendijet = nullptr;
76 
77  cout << "Reading tree" << endl;
78  {
79  auto t = unique_ptr<TTree>(f->Get<TTree>("tree"));
80  t->Show(0);
81  cout << "Checking genJets" << endl;
82  t->Scan("genJets.CorrPt()");
83  cout << "Checking genDijet" << endl;
84  t->Scan("genDijet.first.CorrPt():genDijet.second.CorrPt():genDijet.HT()");
85  cout << "Setting branch addresses" << endl;
86  t->SetBranchAddress("genJets", &genjets);
87  t->SetBranchAddress("genDijet", &gendijet);
88  t->GetEntry(0);
89  BOOST_TEST( genjets->at(0).CorrPt() == 1. );
90  BOOST_TEST( genjets->at(1).CorrPt() == 2. );
91  BOOST_TEST( gendijet->HT() == 1.5 );
92  }
93 }

◆ BOOST_AUTO_TEST_CASE() [2/2]

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

◆ BOOST_TEST()

BOOST_TEST ( gendijet.  Rapidity() = =1.3573785791881385)

◆ GetDummyGenJets()

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

Variable Documentation

◆ gendijet

GenDijet gendijet = genjets.at(0) + genjets.at(1)
DAS::Di::Weight
double Weight(const Uncertainties::Variation &v=Uncertainties::nominal) const override
Definition: Di.h:73
gendijet
GenDijet gendijet
Definition: Di.cc:98
DAS::PhysicsObject::p4
FourVector p4
raw four-momentum directly after reconstruction
Definition: PhysicsObject.h:47
GetDummyGenJets
vector< GenJet > GetDummyGenJets()
Definition: Di.cc:18
DAS::GenDijet
Di< GenJet, GenJet > GenDijet
Definition: Di.h:77
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:252
DAS::PhysicsObject::scales
std::vector< float > scales
energy scale corrections and variations
Definition: PhysicsObject.h:48
DAS::Di::HT
float HT(const Uncertainties::Variation &v=Uncertainties::nominal) const
Definition: Di.h:70
DAS::Di::CorrPt
float CorrPt(const Uncertainties::Variation &v=Uncertainties::nominal) const override
Definition: Di.h:48
DAS::GenJet::ScaleVar
static const char *const ScaleVar
Name of jet gen scales in variations.
Definition: Jet.h:10
Ntupliser_cfg.genjets
genjets
Definition: Ntupliser_cfg.py:268
DAS::GenJet
class GenJet
Definition: Jet.h:9
DAS::Di
Definition: Di.h:33
DAS::Uncertainties::nominal
const Variation nominal
Definition: Variation.h:109
DAS::Uncertainties
Definition: Variation.h:16
DAS::GenJet::WeightVar
static const char *const *const WeightVar
Name of jet gen weights in variations.
Definition: Jet.h:11
DAS::PhysicsObject::weights
Weights weights
object weights
Definition: PhysicsObject.h:49
DAS::Uncertainties::Variation
Definition: Variation.h:22