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 
21 #include <map>
22 #include <cmath>
23 #include <string>
24 #include <vector>
25 #include <typeinfo>
26 
27 namespace reco {
28  namespace isodeposit {
29  struct AbsVeto {
30  virtual ~AbsVeto() { }
32  virtual bool veto(double eta, double phi, float value) const = 0;
35  virtual void centerOn(double eta, double phi) {
36  throw cms::Exception("Not Implemented") << "This AbsVeto implementation (" << typeid(this).name() << ") does not support the centerOn(eta,phi) method";
37  }
38  };
39  typedef std::vector<AbsVeto*> AbsVetos;
40  }
41 }
42 
43 namespace reco {
44 
45  class IsoDeposit {
46  public:
47 
51 
52  // old style vetos
53  struct Veto {
54  Direction vetoDir; float dR;
55  Veto() {}
56  Veto(Direction dir, double d):vetoDir(dir), dR(d) {}
57  };
58  typedef std::vector<Veto> Vetos;
59 
61  IsoDeposit(double eta=0, double phi=0);
62  IsoDeposit(const Direction & candDirection);
63 
65  virtual ~IsoDeposit(){};
66 
68  const Direction & direction() const { return theDirection; }
69  double eta() const {return theDirection.eta();}
70  double phi() const {return theDirection.phi();}
71 
73  const Veto & veto() const { return theVeto; }
75  void setVeto(const Veto & aVeto) { theVeto = aVeto; }
76 
78  void addDeposit(double dr, double deposit); // FIXME - temporary for backward compatibility
79  void addDeposit(const Direction & depDir, double deposit);
80 
82  double depositWithin(
83  double coneSize, //dR in which deposit is computed
84  const Vetos & vetos = Vetos(), //additional vetos
85  bool skipDepositVeto = false //skip exclusion of veto
86  ) const;
87 
89  double depositWithin( Direction dir,
90  double coneSize, //dR in which deposit is computed
91  const Vetos & vetos = Vetos(), //additional vetos
92  bool skipDepositVeto = false //skip exclusion of veto
93  ) const;
94 
96  std::pair<double,int>
98  double coneSize, //dR in which deposit is computed
99  const Vetos & vetos = Vetos(), //additional vetos
100  double threshold = -1e+36, //threshold on counted deposits
101  bool skipDepositVeto = false //skip exclusion of veto
102  ) const;
103 
105  std::pair<double,int>
107  Direction dir, //wrt another direction
108  double coneSize, //dR in which deposit is computed
109  const Vetos & vetos = Vetos(), //additional vetos
110  double threshold = -1e+36, //threshold on deposits
111  bool skipDepositVeto = false //skip exclusion of veto
112  ) const;
113 
115  double depositWithin(
116  double coneSize, //dR in which deposit is computed
117  const AbsVetos & vetos, //additional vetos
118  bool skipDepositVeto = false //skip exclusion of veto
119  ) const;
120 
122  std::pair<double,int>
124  double coneSize, //dR in which deposit is computed
125  const AbsVetos & vetos, //additional vetos
126  bool skipDepositVeto = false //skip exclusion of veto
127  ) const;
128 
129 
131  double candEnergy() const {return theCandTag;}
132 
134  void addCandEnergy(double et) { theCandTag += et;}
135 
136  std::string print() const;
137 
139  public:
140  const const_iterator & operator++() { ++it_; cacheReady_ = false; return *this; }
141  const const_iterator * operator->() const { return this; }
142  float dR() const { return it_->first.deltaR; }
143  float eta() const { if (!cacheReady_) doDir(); return cache_.eta(); }
144  float phi() const { if (!cacheReady_) doDir(); return cache_.phi(); }
145  float value() const { return it_->second; }
146  bool operator!=(const const_iterator &it2) { return it2.it_ != it_; }
147  friend class IsoDeposit;
148  private:
150  void doDir() const { cache_ = parent_->direction() + it_->first; cacheReady_ = true; }
151  const_iterator(const IsoDeposit* parent, std::multimap<Distance, float>::const_iterator it) :
152  parent_(parent), it_(it), cache_(), cacheReady_(false) { }
154  mutable std::multimap<Distance, float>::const_iterator it_;
155  mutable Direction cache_;
156  mutable bool cacheReady_;
157  };
158  const_iterator begin() const { return const_iterator(this, theDeposits.begin()); }
159  const_iterator end() const { return const_iterator(this, theDeposits.end()); }
160 
161  class SumAlgo {
162  public:
163  SumAlgo() : sum_(0) {}
164  void operator+=(float deposit) { sum_ += deposit; }
165  double result() const { return sum_; }
166  private:
167  double sum_;
168  };
169  class CountAlgo {
170  public:
171  CountAlgo() : count_(0) {}
172  void operator+=(double deposit) { count_++; }
173  double result() const { return count_; }
174  private:
175  size_t count_;
176  };
177  class Sum2Algo {
178  public:
179  Sum2Algo() : sum2_(0) {}
180  void operator+=(double deposit) { sum2_ += deposit*deposit; }
181  double result() const { return sum2_; }
182  private:
183  double sum2_;
184  };
185  class MaxAlgo {
186  public:
187  MaxAlgo() : max_(0) {}
188  void operator+=(double deposit) { if (deposit > max_) max_ = deposit; }
189  double result() const { return max_; }
190  private:
191  double max_;
192  };
194  template<typename Algo>
195  double algoWithin( double coneSize, //dR in which deposit is computed
196  const AbsVetos & vetos = AbsVetos(), //additional vetos
197  bool skipDepositVeto = false //skip exclusion of veto
198  ) const;
200  template<typename Algo>
201  double algoWithin(const Direction &,
202  double coneSize, //dR in which deposit is computed
203  const AbsVetos & vetos = AbsVetos(), //additional vetos
204  bool skipDepositVeto = false //skip exclusion of veto
205  ) const;
206  // count of the non-vetoed deposits in the cone
207  double countWithin( double coneSize, //dR in which deposit is computed
208  const AbsVetos & vetos = AbsVetos(), //additional vetos
209  bool skipDepositVeto = false //skip exclusion of veto
210  ) const;
211  // sum of the non-vetoed deposits in the cone
212  double sumWithin( double coneSize, //dR in which deposit is computed
213  const AbsVetos & vetos = AbsVetos(), //additional vetos
214  bool skipDepositVeto = false //skip exclusion of veto
215  ) const;
216  // sum of the non-vetoed deposits in the cone w.r.t. other direction
217  double sumWithin(const Direction & dir,
218  double coneSize, //dR in which deposit is computed
219  const AbsVetos & vetos = AbsVetos(), //additional vetos
220  bool skipDepositVeto = false //skip exclusion of veto
221  ) const; // sum of the squares of the non-vetoed deposits in the cone
222  double sum2Within( double coneSize, //dR in which deposit is computed
223  const AbsVetos & vetos = AbsVetos(), //additional vetos
224  bool skipDepositVeto = false //skip exclusion of veto
225  ) const;
226  // maximum value among the non-vetoed deposits in the cone
227  double maxWithin( double coneSize, //dR in which deposit is computed
228  const AbsVetos & vetos = AbsVetos(), //additional vetos
229  bool skipDepositVeto = false //skip exclusion of veto
230  ) const;
231  // maximum value among the non-vetoed deposits in the cone
232  double nearestDR( double coneSize, //dR in which deposit is computed
233  const AbsVetos & vetos = AbsVetos(), //additional vetos
234  bool skipDepositVeto = false //skip exclusion of veto
235  ) const;
236 
237 
238 
239 
240  private:
241 
244 
247 
249  float theCandTag;
250 
253  typedef std::multimap<Distance, float> DepositsMultimap;
254 
256  };
257 
258 }
259 
260 template<typename Algo>
261 double reco::IsoDeposit::algoWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const
262 {
263  using namespace reco::isodeposit;
264  Algo algo;
265  typedef AbsVetos::const_iterator IV;
266  IV ivEnd = vetos.end();
267 
268  Distance maxDistance = {float(coneSize),999.f};
269  typedef DepositsMultimap::const_iterator IM;
270  IM imLoc = theDeposits.upper_bound( maxDistance );
271  for (IM im = theDeposits.begin(); im != imLoc; ++im) {
272  bool vetoed = false;
273  Direction dirDep = theDirection+im->first;
274  for (IV iv = vetos.begin(); iv < ivEnd; ++iv) {
275  if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) { vetoed = true; break; }
276  }
277  if (!vetoed) {
278  if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
279  algo += im->second;
280  }
281  }
282  }
283  return algo.result();
284 }
285 
286 template<typename Algo>
287 double reco::IsoDeposit::algoWithin(const Direction& dir, double coneSize,
288  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  typedef DepositsMultimap::const_iterator IM;
295  IM imLoc = theDeposits.end();
296  for (IM im = theDeposits.begin(); im != imLoc; ++im) {
297  bool vetoed = false;
298  Direction dirDep = theDirection+im->first;
299  Distance newDist = dirDep - dir;
300  if(newDist.deltaR > coneSize) continue;
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->second;
307  }
308  }
309  }
310  return algo.result();
311 }
312 
313 #endif
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:131
const Direction & direction() const
Get direction of isolation cone.
Definition: IsoDeposit.h:68
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:35
const Veto & veto() const
Get veto area.
Definition: IsoDeposit.h:73
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 setVeto(const Veto &aVeto)
Set veto.
Definition: IsoDeposit.h:75
double eta() const
Definition: IsoDeposit.h:69
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:261
const reco::IsoDeposit * parent_
Definition: IsoDeposit.h:153
double phi() const
Definition: IsoDeposit.h:70
Direction::Distance Distance
the deposits identifed by relative position to center of cone and deposit value
Definition: IsoDeposit.h:252
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134
virtual ~IsoDeposit()
Destructor.
Definition: IsoDeposit.h:65
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:56
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:172
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:141
Veto theVeto
area to be excluded in computaion of depositWithin
Definition: IsoDeposit.h:246
DepositsMultimap theDeposits
Definition: IsoDeposit.h:255
double nearestDR(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:155
const const_iterator & operator++()
Definition: IsoDeposit.h:140
void addCandEnergy(double et)
Set energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:134
std::multimap< Distance, float > DepositsMultimap
Definition: IsoDeposit.h:253
double result() const
Definition: IsoDeposit.h:181
const_iterator begin() const
Definition: IsoDeposit.h:158
std::multimap< Distance, float >::const_iterator it_
Definition: IsoDeposit.h:154
double result() const
Definition: IsoDeposit.h:165
const_iterator(const IsoDeposit *parent, std::multimap< Distance, float >::const_iterator it)
Definition: IsoDeposit.h:151
double result() const
Definition: IsoDeposit.h:189
void operator+=(double deposit)
Definition: IsoDeposit.h:188
isodeposit::AbsVeto AbsVeto
Definition: IsoDeposit.h:49
std::vector< Veto > Vetos
Definition: IsoDeposit.h:58
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:39
isodeposit::Direction Direction
Definition: IsoDeposit.h:48
float theCandTag
float tagging cand, ment to be transverse energy or pT attached to cand,
Definition: IsoDeposit.h:249
dbl *** dir
Definition: mlp_gen.cc:35
LimitAlgo * algo
Definition: Combine.cc:60
Direction theDirection
direcion of deposit (center of isolation cone)
Definition: IsoDeposit.h:243
isodeposit::AbsVetos AbsVetos
Definition: IsoDeposit.h:50
void operator+=(float deposit)
Definition: IsoDeposit.h:164
const_iterator end() const
Definition: IsoDeposit.h:159
bool operator!=(const const_iterator &it2)
Definition: IsoDeposit.h:146
void operator+=(double deposit)
Definition: IsoDeposit.h:180
IsoDeposit(double eta=0, double phi=0)
Constructor.
Definition: IsoDeposit.cc:16
Definition: fakeMenu.h:4
Direction::Distance Distance
Definition: IsoDeposit.h:149
double deltaR(const Direction &dir2) const
double result() const
Definition: IsoDeposit.h:173
Definition: DDAxes.h:10