1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
#include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
#include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <sstream>
using namespace reco;
IsoDeposit::IsoDeposit(const Direction& candDirection) : theDirection(candDirection), theCandTag(0.) {
theVeto.vetoDir = theDirection;
theVeto.dR = 0.;
}
IsoDeposit::IsoDeposit(double eta, double phi) : theDirection(Direction(eta, phi)), theCandTag(0.) {
theVeto.vetoDir = theDirection;
theVeto.dR = 0.;
}
void IsoDeposit::addDeposit(double dr, double value) {
Distance relDir = {float(dr), 0.f};
theDeposits.insert(std::make_pair(relDir, value));
}
void IsoDeposit::addDeposit(const Direction& depDir, double deposit) {
Distance relDir = depDir - theDirection;
theDeposits.insert(std::make_pair(relDir, deposit));
}
double IsoDeposit::depositWithin(double coneSize, const Vetos& vetos, bool skipDepositVeto) const {
return depositAndCountWithin(coneSize, vetos, -1e+36, skipDepositVeto).first;
}
double IsoDeposit::depositWithin(Direction dir, double coneSize, const Vetos& vetos, bool skipDepositVeto) const {
return depositAndCountWithin(dir, coneSize, vetos, -1e+36, skipDepositVeto).first;
}
std::pair<double, int> IsoDeposit::depositAndCountWithin(double coneSize,
const Vetos& vetos,
double threshold,
bool skipDepositVeto) const {
double result = 0;
int count = 0;
Vetos allVetos = vetos;
typedef Vetos::const_iterator IV;
if (!skipDepositVeto)
allVetos.push_back(theVeto);
IV ivEnd = allVetos.end();
Distance maxDistance = {float(coneSize), 999.f};
typedef DepositsMultimap::const_iterator IM;
IM imLoc = theDeposits.upper_bound(maxDistance);
for (IM im = theDeposits.begin(); im != imLoc; ++im) {
bool vetoed = false;
for (IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
Direction dirDep = theDirection + im->first;
if (dirDep.deltaR(iv->vetoDir) < iv->dR)
vetoed = true;
}
if (!vetoed && im->second > threshold) {
result += im->second;
count++;
}
}
return std::pair<double, int>(result, count);
}
std::pair<double, int> IsoDeposit::depositAndCountWithin(
Direction dir, double coneSize, const Vetos& vetos, double threshold, bool skipDepositVeto) const {
double result = 0;
int count = 0;
Vetos allVetos = vetos;
typedef Vetos::const_iterator IV;
if (!skipDepositVeto)
allVetos.push_back(theVeto);
IV ivEnd = allVetos.end();
typedef DepositsMultimap::const_iterator IM;
for (IM im = theDeposits.begin(); im != theDeposits.end(); ++im) {
bool vetoed = false;
Direction dirDep = theDirection + im->first;
Distance newDist = dirDep - dir;
if (newDist.deltaR > coneSize)
continue;
for (IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
if (dirDep.deltaR(iv->vetoDir) < iv->dR)
vetoed = true;
}
if (!vetoed && im->second > threshold) {
result += im->second;
count++;
}
}
return std::pair<double, int>(result, count);
}
std::pair<double, int> IsoDeposit::depositAndCountWithin(double coneSize,
const AbsVetos& vetos,
bool skipDepositVeto) const {
using namespace reco::isodeposit;
double result = 0;
int count = 0;
typedef AbsVetos::const_iterator IV;
IV ivEnd = vetos.end();
Distance maxDistance = {float(coneSize), 999.f};
typedef DepositsMultimap::const_iterator IM;
IM imLoc = theDeposits.upper_bound(maxDistance);
for (IM im = theDeposits.begin(); im != imLoc; ++im) {
bool vetoed = false;
Direction dirDep = theDirection + im->first;
for (IV iv = vetos.begin(); iv < ivEnd; ++iv) {
if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) {
vetoed = true;
break;
}
}
if (!vetoed) {
if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
result += im->second;
count++;
}
}
}
return std::pair<double, int>(result, count);
}
double IsoDeposit::depositWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
return depositAndCountWithin(coneSize, vetos, skipDepositVeto).first;
}
double IsoDeposit::countWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
return algoWithin<CountAlgo>(coneSize, vetos, skipDepositVeto);
}
double IsoDeposit::sumWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
return algoWithin<SumAlgo>(coneSize, vetos, skipDepositVeto);
}
double IsoDeposit::sumWithin(const Direction& dir, double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
return algoWithin<SumAlgo>(dir, coneSize, vetos, skipDepositVeto);
}
double IsoDeposit::sum2Within(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
return algoWithin<Sum2Algo>(coneSize, vetos, skipDepositVeto);
}
double IsoDeposit::maxWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
return algoWithin<MaxAlgo>(coneSize, vetos, skipDepositVeto);
}
double IsoDeposit::nearestDR(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const {
using namespace reco::isodeposit;
double result = coneSize;
typedef AbsVetos::const_iterator IV;
IV ivEnd = vetos.end();
Distance maxDistance = {float(coneSize), 999.f};
typedef DepositsMultimap::const_iterator IM;
IM imLoc = theDeposits.upper_bound(maxDistance);
for (IM im = theDeposits.begin(); im != imLoc; ++im) {
bool vetoed = false;
Direction dirDep = theDirection + im->first;
for (IV iv = vetos.begin(); iv < ivEnd; ++iv) {
if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) {
vetoed = true;
break;
}
}
if (!vetoed) {
if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
result = (dirDep.deltaR(theVeto.vetoDir) < result) ? dirDep.deltaR(theVeto.vetoDir) : result;
}
}
}
return result;
}
std::string IsoDeposit::print() const {
std::ostringstream str;
str << "Direction : " << theDirection.print() << std::endl;
str << "Veto: (" << theVeto.vetoDir.eta() << ", " << theVeto.vetoDir.phi() << " dR=" << theVeto.dR << ")"
<< std::endl;
typedef DepositsMultimap::const_iterator IM;
IM imEnd = theDeposits.end();
for (IM im = theDeposits.begin(); im != imEnd; ++im) {
str << "(dR=" << im->first.deltaR << ", alpha=" << im->first.relativeAngle << ", Pt=" << im->second << "),";
}
str << std::endl;
return str.str();
}
|