1 |
fgolf |
1.1 |
#include "BabyDorkIdentifier.h"
|
2 |
|
|
|
3 |
|
|
#ifndef __CINT__
|
4 |
|
|
|
5 |
fgolf |
1.2 |
#include <map>
|
6 |
fgolf |
1.1 |
#include <math.h>
|
7 |
|
|
|
8 |
|
|
struct BabyDorkIdentifier {
|
9 |
fgolf |
1.2 |
BabyDorkIdentifier (unsigned int run, unsigned int lumi, unsigned int event, float weight, float pfmet, float tcmet);
|
10 |
fgolf |
1.1 |
unsigned int run_, lumi_, event_;
|
11 |
fgolf |
1.2 |
float weight_, pfmet_, tcmet_;
|
12 |
fgolf |
1.1 |
bool operator < (const BabyDorkIdentifier &) const;
|
13 |
|
|
bool operator == (const BabyDorkIdentifier &) const;
|
14 |
|
|
};
|
15 |
|
|
|
16 |
fgolf |
1.2 |
BabyDorkIdentifier::BabyDorkIdentifier (unsigned int run, unsigned int lumi, unsigned int event, float weight, float pfmet, float tcmet)
|
17 |
|
|
: run_(run), lumi_(lumi), event_(event), weight_(weight), pfmet_(pfmet), tcmet_(tcmet)
|
18 |
fgolf |
1.1 |
{}
|
19 |
|
|
|
20 |
|
|
bool BabyDorkIdentifier::operator < (const BabyDorkIdentifier &other) const
|
21 |
|
|
{
|
22 |
|
|
if (run_ != other.run_)
|
23 |
|
|
return run_ < other.run_;
|
24 |
|
|
if (lumi_ != other.lumi_)
|
25 |
|
|
return lumi_ < other.lumi_;
|
26 |
|
|
if (event_ != other.event_)
|
27 |
|
|
return event_ < other.event_;
|
28 |
fgolf |
1.2 |
|
29 |
fgolf |
1.1 |
return false;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
bool BabyDorkIdentifier::operator == (const BabyDorkIdentifier &other) const
|
33 |
|
|
{
|
34 |
|
|
if (run_ != other.run_)
|
35 |
|
|
return false;
|
36 |
|
|
if (lumi_ != other.lumi_)
|
37 |
|
|
return false;
|
38 |
|
|
if (event_ != other.event_)
|
39 |
|
|
return false;
|
40 |
fgolf |
1.2 |
|
41 |
|
|
return true;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
struct HypIdentifier {
|
45 |
|
|
HypIdentifier (enum FakeRateType fakeRateType, enum DileptonHypType hypType, unsigned int njets, unsigned int nbtags, float ht,
|
46 |
|
|
int eormu1, bool lep1isNum, float pt1, float eta1, int eormu2=-1, bool lep2isNum=false, float pt2=-999999., float eta2=-999999.);
|
47 |
|
|
FakeRateType fakeRateType_;
|
48 |
|
|
DileptonHypType hypType_;
|
49 |
|
|
unsigned int njets_, nbtags_;
|
50 |
|
|
float ht_;
|
51 |
|
|
int eormu1_;
|
52 |
|
|
bool lep1isNum_;
|
53 |
|
|
float pt1_, eta1_;
|
54 |
|
|
int eormu2_;
|
55 |
|
|
bool lep2isNum_;
|
56 |
|
|
float pt2_, eta2_;
|
57 |
|
|
bool operator < (const HypIdentifier &) const;
|
58 |
|
|
bool operator == (const HypIdentifier &) const;
|
59 |
|
|
};
|
60 |
|
|
|
61 |
|
|
HypIdentifier::HypIdentifier (enum FakeRateType fakeRateType, enum DileptonHypType hypType, unsigned int njets, unsigned int nbtags, float ht,
|
62 |
|
|
int eormu1, bool lep1isNum, float pt1, float eta1, int eormu2, bool lep2isNum, float pt2, float eta2)
|
63 |
|
|
: fakeRateType_(fakeRateType), hypType_(hypType), njets_(njets), nbtags_(nbtags), ht_(ht), eormu1_(eormu1), lep1isNum_(lep1isNum), pt1_(pt1), eta1_(eta1), eormu2_(eormu2), lep2isNum_(lep2isNum), pt2_(pt2), eta2_(eta2)
|
64 |
|
|
{}
|
65 |
|
|
|
66 |
|
|
bool HypIdentifier::operator < (const HypIdentifier &other) const
|
67 |
|
|
{
|
68 |
|
|
if (fakeRateType_ != other.fakeRateType_)
|
69 |
|
|
return fakeRateType_ < other.fakeRateType_;
|
70 |
|
|
if (hypType_ != other.hypType_)
|
71 |
|
|
return hypType_ > other.hypType_;
|
72 |
|
|
if (fabs((pt1_+pt2_)-(other.pt1_+other.pt2_)) > 1e-6*fabs(pt1_))
|
73 |
|
|
return (pt1_+pt2_) < (other.pt1_+other.pt2_);
|
74 |
|
|
|
75 |
|
|
return false;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
bool HypIdentifier::operator == (const HypIdentifier& other) const
|
79 |
|
|
{
|
80 |
|
|
if (fakeRateType_ != other.fakeRateType_)
|
81 |
|
|
return false;
|
82 |
|
|
if (hypType_ != other.hypType_)
|
83 |
|
|
return false;
|
84 |
|
|
if (fabs((pt1_+pt2_)-(other.pt1_+other.pt2_)) > 1e-6*fabs(pt1_))
|
85 |
|
|
return false;
|
86 |
|
|
|
87 |
fgolf |
1.1 |
return true;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
fgolf |
1.2 |
static std::map<BabyDorkIdentifier, HypIdentifier> already_seen_;
|
91 |
|
|
bool is_duplicate (const BabyDorkIdentifier &id, const HypIdentifier &hyp)
|
92 |
fgolf |
1.1 |
{
|
93 |
fgolf |
1.2 |
std::pair<std::map<BabyDorkIdentifier, HypIdentifier>::iterator, bool> ret =
|
94 |
|
|
already_seen_.insert(std::pair<BabyDorkIdentifier, HypIdentifier>(id, hyp));
|
95 |
|
|
|
96 |
|
|
if (ret.second)
|
97 |
|
|
return !ret.second;
|
98 |
|
|
|
99 |
|
|
HypIdentifier tmp_hyp = ret.first->second;
|
100 |
|
|
if (hyp < tmp_hyp || hyp == tmp_hyp)
|
101 |
|
|
return true;
|
102 |
|
|
else {
|
103 |
|
|
already_seen_.erase(ret.first);
|
104 |
|
|
already_seen_.insert(std::pair<BabyDorkIdentifier, HypIdentifier>(id, hyp));
|
105 |
|
|
return false;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
return false;
|
109 |
fgolf |
1.1 |
}
|
110 |
|
|
|
111 |
fgolf |
1.2 |
bool is_duplicate(unsigned int run, unsigned int lumi, unsigned int event, enum FakeRateType fakeRateType, enum DileptonHypType hypType,
|
112 |
|
|
unsigned int njets, unsigned int nbtags, float ht, float pfmet, float tcmet, float weight, int eormu1, bool lep1isNum, float pt1, float eta1,
|
113 |
|
|
int eormu2, bool lep2isNum, float pt2, float eta2)
|
114 |
fgolf |
1.1 |
{
|
115 |
fgolf |
1.2 |
return is_duplicate(BabyDorkIdentifier(run,lumi,event, weight, pfmet, tcmet), HypIdentifier(fakeRateType, hypType, njets, nbtags, ht, eormu1, lep1isNum, pt1, eta1, eormu2, lep2isNum, pt2, eta2));
|
116 |
fgolf |
1.1 |
}
|
117 |
|
|
|
118 |
|
|
void reset_babydorkidentifier()
|
119 |
|
|
{
|
120 |
|
|
already_seen_.clear();
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
#endif
|
124 |
|
|
|