CMS 3D CMS Logo

JetCombinatorics.h
Go to the documentation of this file.
1 #ifndef JetCombinatorics_h
2 #define JetCombinatorics_h
3 
15 #include "TLorentzVector.h"
16 #include "TString.h"
17 #include "TH1F.h"
18 #include "TFile.h"
19 #include "TMath.h"
20 #include <map>
21 #include <vector>
22 #include <iostream>
23 
24 class Combo {
25 public:
26  Combo() {
27  MW = 84.2; //79.8;
28  Mtop_h = 180.7; //175.;
29  Mtop_l = 174.9;
30  sigmaHadW = 10.5; //2.*7.6;
31  sigmaHadt = 19.2; //2.*12.5;
32  sigmaLept = 24.2; //2.*15.6;
33 
34  SumEt_ = 0.;
35  usebtag_ = false;
36  useMtop_ = true;
37 
38  useFlv_ = false;
40  }
41  ~Combo(){};
42 
43  void SetWp(const TLorentzVector& Wp) { Wp_ = Wp; }
44  void SetWq(const TLorentzVector& Wq) { Wq_ = Wq; }
45  void SetHadb(const TLorentzVector& Hadb) { Hadb_ = Hadb; }
46  void SetLepW(const TLorentzVector& LepW) { LepW_ = LepW; }
47  void SetLepb(const TLorentzVector& Lepb) { Lepb_ = Lepb; }
48  // flavor corrections
49  void ApplyFlavorCorrections(bool option = true) { useFlv_ = option; }
50  void SetFlvCorrWp(double corr) { Wp_flv_ = corr; }
51  void SetFlvCorrWq(double corr) { Wq_flv_ = corr; }
52  void SetFlvCorrHadb(double corr) { Hadb_flv_ = corr; }
53  void SetFlvCorrLepb(double corr) { Lepb_flv_ = corr; }
54  // b tagging
55  void SetWp_disc(double disc) { Wp_disc_ = disc; }
56  void SetWq_disc(double disc) { Wq_disc_ = disc; }
57  void SetHadb_disc(double disc) { Hadb_disc_ = disc; }
58  void SetLepb_disc(double disc) { Lepb_disc_ = disc; }
59  void SetbDiscPdf(const TString& filename) {
60  pdffile_ = TFile::Open(filename);
61  hdisc_b_ = (TH1F*)gDirectory->Get("hdiscNorm_b");
62  hdisc_cl_ = (TH1F*)gDirectory->Get("hdiscNorm_cl");
63  }
64  void SetSigmas(int type = 0) {
65  // type == 0 take defaults
66  if (type == 1) {
67  // JES +10%
68  MW = 87.2;
69  Mtop_h = 193.2;
70  Mtop_l = 179.0;
71  sigmaHadW = 13.0;
72  sigmaHadt = 22.8;
73  sigmaLept = 26.3;
74  }
75  if (type == -1) {
76  // JES -10%
77  MW = 81.6;
78  Mtop_h = 169.3;
79  Mtop_l = 171.4;
80  sigmaHadW = 8.9;
81  sigmaHadt = 17.9;
82  sigmaLept = 22.6;
83  }
84  }
85  void Usebtagging(bool option = true) { usebtag_ = option; }
86  void SetMinMassLepW(double mass) { minMassLepW_ = mass; }
87  void SetMaxMassLepW(double mass) { maxMassLepW_ = mass; }
88  void SetMinMassHadW(double mass) { minMassHadW_ = mass; }
89  void SetMaxMassHadW(double mass) { maxMassHadW_ = mass; }
92  void UseMtopConstraint(bool option = true) { useMtop_ = option; }
93 
94  void analyze() {
95  if (useFlv_) {
96  Wp_ = Wp_flv_ * Wp_;
97  Wq_ = Wq_flv_ * Wq_;
98  Hadb_ = Hadb_flv_ * Hadb_;
99  Lepb_ = Lepb_flv_ * Lepb_;
100  }
101 
102  HadW_ = Wp_ + Wq_;
103  HadTop_ = HadW_ + Hadb_;
104  LepTop_ = LepW_ + Lepb_;
106 
107  //double sigmaHadW = 10.5;//2.*7.6;
108  //double sigmaHadt = 19.2;//2.*12.5;
109  //double sigmaLept = 24.2;//2.*15.6;
110 
111  double chiHadW = (HadW_.M() - MW) / sigmaHadW;
112  double chiHadt = (HadTop_.M() - Mtop_h) / sigmaHadt;
113  double chiLept = (LepTop_.M() - Mtop_l) / sigmaLept;
114 
115  if (useMtop_) {
116  chi2_ = chiHadW * chiHadW + chiHadt * chiHadt + chiLept * chiLept;
117  Ndof_ = 3;
118  } else {
119  chi2_ = chiHadW * chiHadW + (HadTop_.M() - LepTop_.M()) * (HadTop_.M() - LepTop_.M()) /
121  Ndof_ = 2;
122  }
123 
124  SumEt_ = HadTop_.Pt();
125 
126  if (usebtag_) {
127  double gauss_norm = (2.) * TMath::Log(sigmaHadW * TMath::Sqrt(2 * TMath::Pi())) +
128  (2.) * TMath::Log(sigmaHadt * TMath::Sqrt(2 * TMath::Pi())) +
129  (2.) * TMath::Log(sigmaLept * TMath::Sqrt(2 * TMath::Pi()));
130 
131  double LR_Wp;
132  double LR_Wq;
133  double LR_Hadb;
134  double LR_Lepb;
135 
136  double LR_den = 0;
137  LR_den = (getPdfValue("cl", Wp_disc_) + getPdfValue("b", Wp_disc_));
138  if (LR_den == 0)
139  LR_Wp = 1e-5;
140  else
141  LR_Wp = getPdfValue("cl", Wp_disc_) / LR_den;
142 
143  LR_den = (getPdfValue("cl", Wq_disc_) + getPdfValue("b", Wq_disc_));
144  if (LR_den == 0)
145  LR_Wq = 1e-5;
146  else
147  LR_Wq = getPdfValue("cl", Wq_disc_) / LR_den;
148 
149  LR_den = (getPdfValue("cl", Hadb_disc_) + getPdfValue("b", Hadb_disc_));
150  if (LR_den == 0)
151  LR_Hadb = 1e-5;
152  else
153  LR_Hadb = getPdfValue("b", Hadb_disc_) / LR_den;
154 
155  LR_den = (getPdfValue("cl", Lepb_disc_) + getPdfValue("b", Lepb_disc_));
156  if (LR_den == 0)
157  LR_Lepb = 1e-5;
158  else
159  LR_Lepb = getPdfValue("b", Lepb_disc_) / LR_den;
160 
161  double btag_norm = (-0.25 - TMath::Log(4) / 2);
162  double btag_N2LL = btag_norm * 4. *
163  (LR_Wp * TMath::Log(LR_Wp / 4) + LR_Wq * TMath::Log(LR_Wq / 4) +
164  LR_Hadb * TMath::Log(LR_Hadb / 4) + LR_Lepb * TMath::Log(LR_Lepb / 4));
165 
166  chi2_ += btag_N2LL + gauss_norm;
167  Ndof_ += 3;
168  pdffile_->Close();
169  }
170  }
171 
172  TLorentzVector GetWp() { return Wp_; }
173  TLorentzVector GetWq() { return Wq_; }
174  TLorentzVector GetHadW() { return HadW_; }
175  TLorentzVector GetLepW() { return LepW_; }
176  TLorentzVector GetHadb() { return Hadb_; }
177  TLorentzVector GetLepb() { return Lepb_; }
178  TLorentzVector GetHadTop() { return HadTop_; }
179  TLorentzVector GetLepTop() { return LepTop_; }
180  TLorentzVector GetTopPair() { return TopPair_; }
181  double GetChi2() const { return chi2_; }
182  double GetNdof() { return Ndof_; }
183  double GetSumEt() const { return SumEt_; }
184  int GetIdHadb() { return IdHadb_; }
185  int GetIdWp() { return IdWp_; }
186  int GetIdWq() { return IdWq_; }
187  int GetIdLepb() { return IdLepb_; }
188  void SetIdHadb(int id) { IdHadb_ = id; }
189  void SetIdWp(int id) { IdWp_ = id; }
190  void SetIdWq(int id) { IdWq_ = id; }
191  void SetIdLepb(int id) { IdLepb_ = id; }
192  void Print() {
193  std::cout << " jet Wp : px = " << Wp_.Px() << " py = " << Wp_.Py() << " pz = " << Wp_.Pz() << " e = " << Wp_.E()
194  << std::endl;
195  std::cout << " jet Wq : px = " << Wq_.Px() << " py = " << Wq_.Py() << " pz = " << Wq_.Pz() << " e = " << Wq_.E()
196  << std::endl;
197  std::cout << " jet Hadb: px = " << Hadb_.Px() << " py = " << Hadb_.Py() << " pz = " << Hadb_.Pz()
198  << " e = " << Hadb_.E() << std::endl;
199  std::cout << " jet Lepb: px = " << Lepb_.Px() << " py = " << Lepb_.Py() << " pz = " << Lepb_.Pz()
200  << " e = " << Lepb_.E() << std::endl;
201  std::cout << " chi-squared = " << chi2_ << " sumEt = " << SumEt_ << std::endl;
202  }
203  double getPdfValue(std::string flavor, double disc) {
204  double pdf = 0;
205  TH1F* hpdf;
206  if (flavor == "b")
207  hpdf = hdisc_b_;
208  else
209  hpdf = hdisc_cl_;
210  int bin = hpdf->GetXaxis()->FindBin(disc);
211  pdf = hpdf->GetBinContent(bin);
212  if (disc < -10 || disc > 50)
213  return 0;
214  //if ( pdf == 0 ) return 1.e-7;
215  return pdf;
216  }
217 
218 private:
219  TLorentzVector Wp_;
220  TLorentzVector Wq_;
221  TLorentzVector HadW_;
222  TLorentzVector Hadb_;
223  TLorentzVector HadTop_;
224  TLorentzVector LepW_;
225  TLorentzVector Lepb_;
226  TLorentzVector LepTop_;
227  TLorentzVector TopPair_;
228 
229  bool usebtag_;
230  bool useMtop_;
231  double Wp_disc_;
232  double Wq_disc_;
233  double Hadb_disc_;
234  double Lepb_disc_;
235  TFile* pdffile_;
236  TH1F* hdisc_b_;
237  TH1F* hdisc_cl_;
238 
240  bool useFlv_;
241  double chi2_;
242  double Ndof_;
243  double SumEt_;
244  double minMassLepW_;
245  double maxMassLepW_;
246  double minMassHadW_;
247  double maxMassHadW_;
248 
251 
252  double MW;
253  double Mtop_h;
254  double Mtop_l;
255  double sigmaHadW;
256  double sigmaHadt;
257  double sigmaLept;
258 
259  int IdHadb_;
260  int IdWp_;
261  int IdWq_;
262  int IdLepb_;
263 };
264 
265 struct minChi2 {
266  bool operator()(const Combo& s1, const Combo& s2) const { return s1.GetChi2() <= s2.GetChi2(); }
267 };
268 
269 struct maxSumEt {
270  bool operator()(const Combo& s1, const Combo& s2) const { return s1.GetSumEt() >= s2.GetSumEt(); }
271 };
272 
274 public:
276  ~JetCombinatorics();
277 
278  void Verbose() { verbosef = true; }
279 
280  std::map<int, std::string> Combinatorics(int k, int max = 6);
281  std::map<int, std::string> NestedCombinatorics();
282 
283  void FourJetsCombinations(const std::vector<TLorentzVector>& jets, const std::vector<double>& bdiscriminators);
284  void SetFlavorCorrections(const std::vector<double>& vector) { flavorCorrections_ = vector; }
285  void SetMaxNJets(int n) { maxNJets_ = n; }
286  Combo GetCombination(int n = 0);
287  Combo GetCombinationSumEt(int n = 0);
288  int GetNumberOfCombos() { return ((int)allCombos_.size()); }
289  //void SetCandidate( std::vector< TLorentzVector > JetCandidates );
290 
291  void SetSigmas(int type = 0) { SigmasTypef = type; }
292  void SetLeptonicW(const TLorentzVector& LepW) { theLepW_ = LepW; }
293 
294  void SetMinMassLepW(double mass) { minMassLepW_ = mass; }
295  void SetMaxMassLepW(double mass) { maxMassLepW_ = mass; }
296  void SetMinMassHadW(double mass) { minMassHadW_ = mass; }
297  void SetMaxMassHadW(double mass) { maxMassHadW_ = mass; }
300 
301  void UsebTagging(bool option = true) { UsebTagging_ = option; }
302  void ApplyFlavorCorrection(bool option = true) { UseFlv_ = option; }
303  void UseMtopConstraint(bool option = true) { UseMtop_ = option; }
304  void SetbTagPdf(const TString& name) { bTagPdffilename_ = name; }
305  void Clear();
306 
307  std::vector<TLorentzVector> TwoCombos();
308  std::vector<TLorentzVector> ThreeCombos();
309 
310  void RemoveDuplicates(bool option) { removeDuplicates_ = option; }
311 
312  std::vector<TLorentzVector> GetComposites();
313  void AnalyzeCombos();
314 
315 private:
316  //int kcombos_;
317  //int maxcombos_;
319  bool verbosef;
320  std::map<int, std::string> Template4jCombos_;
321  std::map<int, std::string> Template5jCombos_;
322  std::map<int, std::string> Template6jCombos_;
323  std::map<int, std::string> Template7jCombos_;
324 
325  std::vector<double> flavorCorrections_;
328  bool UseMtop_;
330  bool UseFlv_;
331 
332  TLorentzVector theLepW_;
333 
334  double minMassLepW_;
335  double maxMassLepW_;
336  double minMassHadW_;
337  double maxMassHadW_;
340 
341  std::map<Combo, int, minChi2> allCombos_;
342  std::map<Combo, int, maxSumEt> allCombosSumEt_;
343 
344  Double_t minPhi_;
345  double chi2_;
346  int ndf_;
348 
349  std::vector<TLorentzVector> cand1_;
350  std::vector<TLorentzVector> cand2_;
351  std::vector<TLorentzVector> cand3_;
352 
353  //int nLists_;
354 
355  //std::vector< TLorentzVector > composites_;
356 };
357 
358 #endif
double Wq_flv_
const double Pi
type
Definition: HCALResponse.h:21
double maxMassHadW_
void SetMinMassHadW(double mass)
void UseMtopConstraint(bool option=true)
std::map< Combo, int, maxSumEt > allCombosSumEt_
void SetIdHadb(int id)
bool operator()(const Combo &s1, const Combo &s2) const
TLorentzVector Wq_
std::vector< TLorentzVector > cand3_
void SetLeptonicW(const TLorentzVector &LepW)
double Wp_disc_
TH1F * hdisc_b_
static const std::string LepW
TFile * pdffile_
double GetSumEt() const
void UsebTagging(bool option=true)
TLorentzVector TopPair_
TLorentzVector GetHadb()
double minMassLepW_
double Wp_flv_
void SetLepb_disc(double disc)
TLorentzVector Wp_
std::map< int, std::string > Template7jCombos_
void SetMaxMassLepW(double mass)
double sigmaHadt
std::vector< TLorentzVector > cand1_
void SetbDiscPdf(const TString &filename)
void SetIdWp(int id)
void SetMinMassLepTop(double mass)
std::map< int, std::string > Template5jCombos_
double GetChi2() const
bool operator()(const Combo &s1, const Combo &s2) const
TLorentzVector GetTopPair()
void ApplyFlavorCorrections(bool option=true)
double Hadb_flv_
TLorentzVector GetWp()
void SetFlvCorrLepb(double corr)
void UseMtopConstraint(bool option=true)
std::vector< double > flavorCorrections_
void SetFlavorCorrections(const std::vector< double > &vector)
double maxMassLepW_
double minMassHadW_
void SetWp_disc(double disc)
TLorentzVector Lepb_
int GetIdHadb()
void ApplyFlavorCorrection(bool option=true)
double Ndof_
double Wq_disc_
void SetMaxMassLepW(double mass)
void SetHadb_disc(double disc)
void SetFlvCorrWq(double corr)
double minMassLepTop_
void SetLepb(const TLorentzVector &Lepb)
std::map< Combo, int, minChi2 > allCombos_
bool useFlv_
void SetWq(const TLorentzVector &Wq)
double GetNdof()
TLorentzVector HadW_
void SetMaxMassHadW(double mass)
TLorentzVector GetHadTop()
int GetIdLepb()
double Lepb_disc_
TLorentzVector LepW_
void RemoveDuplicates(bool option)
void Print()
double Mtop_h
void SetIdWq(int id)
void SetHadb(const TLorentzVector &Hadb)
void SetIdLepb(int id)
void SetMinMassLepW(double mass)
double Mtop_l
bool usebtag_
JetCorrectorParameters corr
Definition: classes.h:5
TLorentzVector theLepW_
void SetMinMassLepTop(double mass)
void SetFlvCorrWp(double corr)
std::map< int, std::string > Template4jCombos_
double Lepb_flv_
TLorentzVector GetHadW()
void SetMaxMassLepTop(double mass)
void SetMaxMassLepTop(double mass)
double sigmaHadW
TH1F * hdisc_cl_
TLorentzVector GetLepb()
void SetMaxNJets(int n)
double getPdfValue(std::string flavor, double disc)
std::map< int, std::string > Template6jCombos_
void SetWq_disc(double disc)
void SetbTagPdf(const TString &name)
int GetIdWq()
double sigmaLept
TLorentzVector HadTop_
TLorentzVector Hadb_
TLorentzVector GetWq()
TLorentzVector GetLepW()
void SetFlvCorrHadb(double corr)
void SetMinMassLepW(double mass)
void SetLepW(const TLorentzVector &LepW)
TLorentzVector GetLepTop()
void analyze()
bool useMtop_
void Usebtagging(bool option=true)
void SetMinMassHadW(double mass)
double maxMassLepTop_
double SumEt_
TLorentzVector LepTop_
double MW
std::vector< TLorentzVector > cand2_
void SetSigmas(int type=0)
int GetIdWp()
void SetSigmas(int type=0)
void SetWp(const TLorentzVector &Wp)
void SetMaxMassHadW(double mass)
double chi2_
double Hadb_disc_