DAS  3.0
Das Analysis System
Balance.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common.h"
4 
5 #include <map>
6 #include <memory>
7 #include <vector>
8 
9 #include <TDirectory.h>
10 #include <TH3.h>
11 #include <TList.h>
12 #include <TString.h>
13 
14 #include <darwin.h>
15 
18 
19 namespace DAS::JetEnergy {
20 
21 using namespace std;
22 namespace DT = Darwin::Tools;
23 
30 vector<DAS::Uncertainties::Variation> GetScaleVariations (const DT::MetaInfo& metainfo,
31  bool applySyst)
32 {
33  vector<DAS::Uncertainties::Variation> variations;
34  variations.emplace_back("nominal","nominal");
35  if (!applySyst) return variations;
36 
37  const TList * groupContents = metainfo.List("variations", DAS::RecJet::ScaleVar);
38  if (!groupContents)
39  BOOST_THROW_EXCEPTION( invalid_argument(groupContents->GetName()) );
40 
41  size_t i = 0;
42  for (const TObject * obj: *groupContents) {
43  const auto os = dynamic_cast<const TObjString*>(obj);
44  if (!os) BOOST_THROW_EXCEPTION( invalid_argument(obj->GetName()) );
45  TString s = os->GetString();
46  s.ReplaceAll(SysUp, "");
47  s.ReplaceAll(SysDown, "");
48  if (find(begin(JES_variations), end(JES_variations), s) != end(JES_variations))
49  variations.emplace_back(DAS::RecJet::ScaleVar, os->GetString(), ++i);
50  }
51  return variations;
52 }
53 
56 class Balance {
57 
58  TDirectory * d;
59  unique_ptr<TH3D> asymmetry;
60  unique_ptr<TH2D> response;
61 
62 public:
64 
65  Balance (TDirectory * d,
67  const vector<double>& pt_edges,
68  const vector<double>& y_edges) :
69  d(d), v(v)
70  {
71  int nBins = 120;
72  auto balBins = getBinning(nBins, -1.2, 1.2);
73  assertValidBinning(balBins);
74 
75  int nPtBins = pt_edges.size()-1,
76  nYbins = y_edges.size()-1;
77 
78  TString dirname = d->GetName();
79  TString hname = dirname + '_' + v.group + '_' + v.name;
80  asymmetry = make_unique<TH3D>(hname, v.name, nBins, balBins.data(),
81  nPtBins, pt_edges.data(),
82  nYbins, y_edges.data());
83 
84  balBins = getBinning(nBins, 0, 1.2);
85  response = make_unique<TH2D>("response_" + hname, v.name, nBins, balBins.data(),
86  nYbins, y_edges.data());
87  }
88 
92  void operator() (const DAS::AbstractPhysicsObject& tag,
93  const DAS::AbstractPhysicsObject& probe,
94  const double ev_w)
95  {
96  float absy_probe = probe.AbsRap(v);
97 
98  float pt_tag = tag .CorrPt(v),
99  pt_probe = probe.CorrPt(v);
100 
101  double jw = tag .Weight(v)
102  * probe.Weight(v);
103 
104  response->Fill(pt_probe/pt_tag, absy_probe, ev_w*jw);
105 
106  // \todo does this also apply to Z+jet balance?
107  // (e.g. not in 1804.05252)
108  float pt_dif = (pt_tag - pt_probe),
109  pt_ave = (pt_tag + pt_probe) * 0.5;
110 
111  float asym = pt_dif / pt_ave;
112 
113  cout << asym << endl;
114 
115  asymmetry->Fill(asym, pt_ave, absy_probe, ev_w*jw);
116  }
117 
118  void Write ()
119  {
120  d->cd();
121  TString dirname = d->GetName();
122 
123  asymmetry->SetDirectory(d);
124  TString hname = asymmetry->GetName();
125  hname.ReplaceAll(dirname + '_', "");
126  asymmetry->Write(hname);
127 
128  response->SetDirectory(d);
129  hname = response->GetName();
130  hname.ReplaceAll(dirname + '_', "");
131  response->Write(hname);
132  }
133 };
134 
135 } // end of DAS::JetEnergy namespace
DAS::y_edges
static const std::vector< double > y_edges
Definition: binnings.h:36
DAS::AbstractPhysicsObject::CorrPt
virtual float CorrPt(const Uncertainties::Variation &) const =0
DAS::JetEnergy::Balance
Balance histogram for a given variation.
Definition: Balance.h:56
DAS::RecJet::ScaleVar
static const char *const ScaleVar
Name of jet rec scales in variations.
Definition: Jet.h:38
DAS::JetEnergy::Balance::response
unique_ptr< TH2D > response
response
Definition: Balance.h:60
DAS::SysUp
const std::string SysUp
Suffix used for "up" uncertainties. Follows the Combine convention.
Definition: Format.h:8
DAS::AbstractPhysicsObject::Weight
virtual double Weight(const Uncertainties::Variation &) const =0
DAS::Uncertainties::Variation::name
const TString name
variation name (including "Up" or "Down")
Definition: Variation.h:25
DAS::pt_edges
static const std::vector< double > pt_edges
Definition: binnings.h:33
DAS::JetEnergy::getBinning
std::vector< double > getBinning(int nBins, float first, float last)
Definition: common.h:53
Jet.h
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:68
DAS::JetEnergy::JES_variations
static const std::vector< std::string > JES_variations
Definition: common.h:49
DAS::JetEnergy::Balance::d
TDirectory * d
directory in output ROOT file
Definition: Balance.h:58
DAS::JetEnergy::assertValidBinning
void assertValidBinning(const std::vector< double > &v)
Definition: common.h:61
DAS::JetEnergy::GetScaleVariations
vector< DAS::Uncertainties::Variation > GetScaleVariations(const DT::MetaInfo &metainfo, bool applySyst)
Definition: Balance.h:30
gitlab_post_comment.response
response
Definition: gitlab_post_comment.py:23
DAS::AbstractPhysicsObject
Definition: PhysicsObject.h:22
DAS::AbstractPhysicsObject::AbsRap
virtual float AbsRap(const Uncertainties::Variation &) const =0
Darwin::Tools
Classes and functions related to the framework.
Definition: Dict_rdict.cxx:990
DAS::nPtBins
static const int nPtBins
Definition: binnings.h:39
DAS::SysDown
const std::string SysDown
Suffix used for "down" uncertainties. Follows the Combine convention.
Definition: Format.h:10
Darwin::Tools::UserInfo::List
TList * List(TList *mother, const char *key) const
Accest do daughter list from a mother list.
Definition: UserInfo.cc:33
DAS::Uncertainties::Variation::group
const TString group
e.g. event, recjet
Definition: Variation.h:24
DAS::JetEnergy::Balance::v
DAS::Uncertainties::Variation v
systematic variation
Definition: Balance.h:63
DAS::JetEnergy::Balance::Balance
Balance(TDirectory *d, const DAS::Uncertainties::Variation &v, const vector< double > &pt_edges, const vector< double > &y_edges)
Definition: Balance.h:65
DAS::Uncertainties::Variation
Definition: Variation.h:22
DAS::JetEnergy
Definition: applyJERsmearing.cc:41
DAS::JetEnergy::Balance::Write
void Write()
Definition: Balance.h:118
Variation.h
DAS::nYbins
static const int nYbins
Definition: binnings.h:38
DAS::JetEnergy::Balance::asymmetry
unique_ptr< TH3D > asymmetry
asymmetry histogram
Definition: Balance.h:59
common.h