CMS 3D CMS Logo

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