CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IsoDeposit.h
Go to the documentation of this file.
1 #ifndef RecoCandidate_IsoDeposit_H
2 #define RecoCandidate_IsoDeposit_H
3 
22 #include <map>
23 #include <cmath>
24 #include <string>
25 #include <vector>
26 #include <typeinfo>
27 
28 namespace reco {
29  namespace isodeposit {
30  struct AbsVeto {
31  virtual ~AbsVeto() { }
33  virtual bool veto(double eta, double phi, float value) const = 0;
36  virtual void centerOn(double eta, double phi) {
37  throw cms::Exception("Not Implemented") << "This AbsVeto implementation (" << typeid(this).name() << ") does not support the centerOn(eta,phi) method";
38  }
39  };
40  typedef std::vector<AbsVeto*> AbsVetos;
41  }
42 }
43 
44 namespace reco {
45 
46  class IsoDeposit {
47  public:
48 
53  typedef std::multimap<Distance, float> DepositsMultimap;
54  typedef DepositsMultimap::const_iterator DepIterator;
55 
56 
57  // old style vetos
58  struct Veto {
59  Direction vetoDir; float dR;
60  Veto() {}
61  Veto(Direction dir, double d):vetoDir(dir), dR(d) {}
62  };
63  typedef std::vector<Veto> Vetos;
64 
66  IsoDeposit(double eta=0, double phi=0);
67  IsoDeposit(const Direction & candDirection);
68 
70  virtual ~IsoDeposit(){};
71 
73  const Direction & direction() const { return theDirection; }
74  double eta() const {return theDirection.eta();}
75  double phi() const {return theDirection.phi();}
76 
78  const Veto & veto() const { return theVeto; }
80  void setVeto(const Veto & aVeto) { theVeto = aVeto; }
81 
83  void addDeposit(double dr, double deposit); // FIXME - temporary for backward compatibility
84  void addDeposit(const Direction & depDir, double deposit);
85 
87  double depositWithin(
88  double coneSize, //dR in which deposit is computed
89  const Vetos & vetos = Vetos(), //additional vetos
90  bool skipDepositVeto = false //skip exclusion of veto
91  ) const;
92 
94  double depositWithin( Direction dir,
95  double coneSize, //dR in which deposit is computed
96  const Vetos & vetos = Vetos(), //additional vetos
97  bool skipDepositVeto = false //skip exclusion of veto
98  ) const;
99 
101  std::pair<double,int>
103  double coneSize, //dR in which deposit is computed
104  const Vetos & vetos = Vetos(), //additional vetos
105  double threshold = -1e+36, //threshold on counted deposits
106  bool skipDepositVeto = false //skip exclusion of veto
107  ) const;
108 
110  std::pair<double,int>
112  Direction dir, //wrt another direction
113  double coneSize, //dR in which deposit is computed
114  const Vetos & vetos = Vetos(), //additional vetos
115  double threshold = -1e+36, //threshold on deposits
116  bool skipDepositVeto = false //skip exclusion of veto
117  ) const;
118 
120  double depositWithin(
121  double coneSize, //dR in which deposit is computed
122  const AbsVetos & vetos, //additional vetos
123  bool skipDepositVeto = false //skip exclusion of veto
124  ) const;
125 
127  std::pair<double,int>
129  double coneSize, //dR in which deposit is computed
130  const AbsVetos & vetos, //additional vetos
131  bool skipDepositVeto = false //skip exclusion of veto
132  ) const;
133 
134 
136  double candEnergy() const {return theCandTag;}
137 
139  void addCandEnergy(double et) { theCandTag += et;}
140 
141  std::string print() const;
142 
144  public:
145  const const_iterator & operator++() { ++it_; cacheReady_ = false; return *this; }
146  const const_iterator * operator->() const { return this; }
147  float dR() const { return it_->first.deltaR; }
148  float eta() const { if (!cacheReady_) doDir(); return cache_.eta(); }
149  float phi() const { if (!cacheReady_) doDir(); return cache_.phi(); }
150  float value() const { return it_->second; }
151  bool operator!=(const const_iterator &it2) { return it2.it_ != it_; }
152  friend class IsoDeposit;
153  private:
155  void doDir() const { cache_ = parent_->direction() + it_->first; cacheReady_ = true; }
156  const_iterator(const IsoDeposit* parent, std::multimap<Distance, float>::const_iterator it) :
157  parent_(parent), it_(it), cache_(), cacheReady_(false) { }
159  mutable std::multimap<Distance, float>::const_iterator it_;
160  mutable Direction cache_;
161  mutable bool cacheReady_;
162  };
163  const_iterator begin() const { return const_iterator(this, theDeposits.begin()); }
164  const_iterator end() const { return const_iterator(this, theDeposits.end()); }
165 
166  class SumAlgo {
167  public:
168  SumAlgo() : sum_(0) {}
169  void operator+=(DepIterator deposit) { sum_ += deposit->second; }
170  void operator+=(double deposit) { sum_ += deposit; }
171  double result() const { return sum_; }
172  private:
173  double sum_;
174  };
175  class CountAlgo {
176  public:
177  CountAlgo() : count_(0) {}
178  void operator+=(DepIterator deposit) { count_++; }
179  void operator+=(double deposit) { count_ ++; }
180  double result() const { return count_; }
181  private:
182  size_t count_;
183  };
184  class Sum2Algo {
185  public:
186  Sum2Algo() : sum2_(0) {}
187  void operator+=(DepIterator deposit) { sum2_ += deposit->second*deposit->second; }
188  void operator+=(double deposit) { sum2_ += deposit*deposit; }
189  double result() const { return sum2_; }
190  private:
191  double sum2_;
192  };
193  class MaxAlgo {
194  public:
195  MaxAlgo() : max_(0) {}
196  void operator+=(DepIterator deposit) { if (deposit->second > max_) max_ = deposit->second; }
197  void operator+=(double deposit) { if (deposit > max_) max_ = deposit; }
198  double result() const { return max_; }
199  private:
200  double max_;
201  };
202 
203  class MeanDRAlgo {
204  public:
205  MeanDRAlgo() : sum_(0.),count_(0.) {}
206  void operator+=(DepIterator deposit) {sum_ +=deposit->first.deltaR; count_+=1.0; }
207  double result() const { return sum_/std::max(1.,count_); }
208  private:
209  double sum_;
210  double count_;
211  };
212 
213  class SumDRAlgo {
214  public:
215  SumDRAlgo() : sum_(0.){}
216  void operator+=(DepIterator deposit) {sum_ +=deposit->first.deltaR;}
217  double result() const { return sum_; }
218  private:
219  double sum_;
220  };
221 
223  template<typename Algo>
224  double algoWithin( double coneSize, //dR in which deposit is computed
225  const AbsVetos & vetos = AbsVetos(), //additional vetos
226  bool skipDepositVeto = false //skip exclusion of veto
227  ) const;
229  template<typename Algo>
230  double algoWithin(const Direction &,
231  double coneSize, //dR in which deposit is computed
232  const AbsVetos & vetos = AbsVetos(), //additional vetos
233  bool skipDepositVeto = false //skip exclusion of veto
234  ) const;
235  // count of the non-vetoed deposits in the cone
236  double countWithin( double coneSize, //dR in which deposit is computed
237  const AbsVetos & vetos = AbsVetos(), //additional vetos
238  bool skipDepositVeto = false //skip exclusion of veto
239  ) const;
240  // sum of the non-vetoed deposits in the cone
241  double sumWithin( double coneSize, //dR in which deposit is computed
242  const AbsVetos & vetos = AbsVetos(), //additional vetos
243  bool skipDepositVeto = false //skip exclusion of veto
244  ) const;
245  // sum of the non-vetoed deposits in the cone w.r.t. other direction
246  double sumWithin(const Direction & dir,
247  double coneSize, //dR in which deposit is computed
248  const AbsVetos & vetos = AbsVetos(), //additional vetos
249  bool skipDepositVeto = false //skip exclusion of veto
250  ) const; // sum of the squares of the non-vetoed deposits in the cone
251  double sum2Within( double coneSize, //dR in which deposit is computed
252  const AbsVetos & vetos = AbsVetos(), //additional vetos
253  bool skipDepositVeto = false //skip exclusion of veto
254  ) const;
255  // maximum value among the non-vetoed deposits in the cone
256  double maxWithin( double coneSize, //dR in which deposit is computed
257  const AbsVetos & vetos = AbsVetos(), //additional vetos
258  bool skipDepositVeto = false //skip exclusion of veto
259  ) const;
260  // maximum value among the non-vetoed deposits in the cone
261  double nearestDR( double coneSize, //dR in which deposit is computed
262  const AbsVetos & vetos = AbsVetos(), //additional vetos
263  bool skipDepositVeto = false //skip exclusion of veto
264  ) const;
265 
266 
267 
268 
269  private:
270 
273 
276 
278  float theCandTag;
279 
281 
283  };
284 
285 }
286 
287 template<typename Algo>
288 double reco::IsoDeposit::algoWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const
289 {
290  using namespace reco::isodeposit;
291  Algo algo;
292  typedef AbsVetos::const_iterator IV;
293  IV ivEnd = vetos.end();
294 
295  Distance maxDistance = {float(coneSize),999.f};
296  typedef DepositsMultimap::const_iterator IM;
297  IM imLoc = theDeposits.upper_bound( maxDistance );
298  for (IM im = theDeposits.begin(); im != imLoc; ++im) {
299  bool vetoed = false;
300  Direction dirDep = theDirection+im->first;
301  for (IV iv = vetos.begin(); iv < ivEnd; ++iv) {
302  if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) { vetoed = true; break; }
303  }
304  if (!vetoed) {
305  if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
306  algo += im;
307  }
308  }
309  }
310  return algo.result();
311 }
312 
313 template<typename Algo>
314 double reco::IsoDeposit::algoWithin(const Direction& dir, double coneSize,
315  const AbsVetos& vetos, bool skipDepositVeto) const
316 {
317  using namespace reco::isodeposit;
318  Algo algo;
319  typedef AbsVetos::const_iterator IV;
320  IV ivEnd = vetos.end();
321  typedef DepositsMultimap::const_iterator IM;
322  IM imLoc = theDeposits.end();
323  for (IM im = theDeposits.begin(); im != imLoc; ++im) {
324  bool vetoed = false;
325  Direction dirDep = theDirection+im->first;
326  Distance newDist = dirDep - dir;
327  if(newDist.deltaR > coneSize) continue;
328  for (IV iv = vetos.begin(); iv < ivEnd; ++iv) {
329  if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) { vetoed = true; break; }
330  }
331  if (!vetoed) {
332  if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
333  algo += im;
334  }
335  }
336  }
337  return algo.result();
338 }
339 
340 
341 
342 
343 #endif
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:136
const Direction & direction() const
Get direction of isolation cone.
Definition: IsoDeposit.h:73
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
virtual void centerOn(double eta, double phi)
Definition: IsoDeposit.h:36
const Veto & veto() const
Get veto area.
Definition: IsoDeposit.h:78
void operator+=(double deposit)
Definition: IsoDeposit.h:170
virtual bool veto(double eta, double phi, float value) const =0
Return &quot;true&quot; if a deposit at specific (eta,phi) with that value must be vetoed in the sum...
list parent
Definition: dbtoconf.py:74
void operator+=(DepIterator deposit)
Definition: IsoDeposit.h:178
DepositsMultimap::const_iterator DepIterator
Definition: IsoDeposit.h:54
void setVeto(const Veto &aVeto)
Set veto.
Definition: IsoDeposit.h:80
double eta() const
Definition: IsoDeposit.h:74
double algoWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Get some info about the deposit (e.g. sum, max, sum2, count)
Definition: IsoDeposit.h:288
const reco::IsoDeposit * parent_
Definition: IsoDeposit.h:158
double phi() const
Definition: IsoDeposit.h:75
Direction::Distance Distance
Definition: IsoDeposit.h:52
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134
void operator+=(DepIterator deposit)
Definition: IsoDeposit.h:169
virtual ~IsoDeposit()
Destructor.
Definition: IsoDeposit.h:70
T eta() const
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:150
Veto(Direction dir, double d)
Definition: IsoDeposit.h:61
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
void operator+=(double deposit)
Definition: IsoDeposit.h:179
void operator+=(DepIterator deposit)
Definition: IsoDeposit.h:216
void operator+=(DepIterator deposit)
Definition: IsoDeposit.h:206
double depositWithin(double coneSize, const Vetos &vetos=Vetos(), bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:34
const const_iterator * operator->() const
Definition: IsoDeposit.h:146
Veto theVeto
area to be excluded in computaion of depositWithin
Definition: IsoDeposit.h:275
void operator+=(DepIterator deposit)
Definition: IsoDeposit.h:196
DepositsMultimap theDeposits
the deposits identifed by relative position to center of cone and deposit value
Definition: IsoDeposit.h:282
const T & max(const T &a, const T &b)
double nearestDR(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:155
const const_iterator & operator++()
Definition: IsoDeposit.h:145
void addCandEnergy(double et)
Set energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:139
std::multimap< Distance, float > DepositsMultimap
Definition: IsoDeposit.h:53
double result() const
Definition: IsoDeposit.h:189
const_iterator begin() const
Definition: IsoDeposit.h:163
std::multimap< Distance, float >::const_iterator it_
Definition: IsoDeposit.h:159
double result() const
Definition: IsoDeposit.h:171
const_iterator(const IsoDeposit *parent, std::multimap< Distance, float >::const_iterator it)
Definition: IsoDeposit.h:156
double result() const
Definition: IsoDeposit.h:198
void operator+=(double deposit)
Definition: IsoDeposit.h:197
isodeposit::AbsVeto AbsVeto
Definition: IsoDeposit.h:50
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
std::vector< AbsVeto * > AbsVetos
Definition: IsoDeposit.h:40
void operator+=(DepIterator deposit)
Definition: IsoDeposit.h:187
isodeposit::Direction Direction
Definition: IsoDeposit.h:49
float theCandTag
float tagging cand, ment to be transverse energy or pT attached to cand,
Definition: IsoDeposit.h:278
dbl *** dir
Definition: mlp_gen.cc:35
double result() const
Definition: IsoDeposit.h:217
Direction theDirection
direcion of deposit (center of isolation cone)
Definition: IsoDeposit.h:272
isodeposit::AbsVetos AbsVetos
Definition: IsoDeposit.h:51
const_iterator end() const
Definition: IsoDeposit.h:164
bool operator!=(const const_iterator &it2)
Definition: IsoDeposit.h:151
void operator+=(double deposit)
Definition: IsoDeposit.h:188
IsoDeposit(double eta=0, double phi=0)
Constructor.
Definition: IsoDeposit.cc:16
Definition: fakeMenu.h:4
Direction::Distance Distance
Definition: IsoDeposit.h:154
double deltaR(const Direction &dir2) const
double result() const
Definition: IsoDeposit.h:180
Definition: DDAxes.h:10