CMS 3D CMS Logo

EgammaTowerIsolation.h
Go to the documentation of this file.
1 #ifndef EgammaTowerIsolation_h
2 #define EgammaTowerIsolation_h
3 
4 //*****************************************************************************
5 // File: EgammaTowerIsolation.h
6 // ----------------------------------------------------------------------------
7 // OrigAuth: Matthias Mozer
8 // Institute: IIHE-VUB
9 // Adding feature to exclude towers used by H/E
10 //
11 // 11/11/12 Hack by VI to make it 100 times faster
12 //=============================================================================
13 //*****************************************************************************
14 
15 #include <vector>
16 
17 //CMSSW includes
22 
23 #include <cmath>
24 #include <algorithm>
25 #include <cstdint>
26 #include <atomic>
27 
29 
30 /*
31  for each set of cuts it will compute Et for all, depth1 and depth2 twice:
32  one between inner and outer and once inside outer vetoid the tower to excude
33 
34  */
35 template <unsigned int NC>
37 public:
38  struct Sum {
39  Sum() : he{0}, h2{0}, heBC{0}, h2BC{0} {}
40  float he[NC];
41  float h2[NC];
42  float heBC[NC];
43  float h2BC[NC];
44  };
45 
46  // number of cuts
47  constexpr static unsigned int NCuts = NC;
48 
49  //constructors
50 
53 
54  ~EgammaTowerIsolationNew() { delete[] mem; }
55 
56  template <typename I>
57  void compute(bool et, Sum& sum, reco::Candidate const& cand, I first, I last) const {
58  reco::SuperCluster const* sc = cand.get<reco::SuperClusterRef>().get();
59  if (sc) {
60  compute(et, sum, *sc, first, last);
61  }
62  }
63  template <typename I>
64  void compute(bool et, Sum& sum, reco::SuperCluster const& sc, I first, I last) const;
65 
66  void setRadius(float const extRadius[NC], float const intRadius[NC]) {
67  for (std::size_t i = 0; i != NCuts; ++i) {
70  }
71  maxEta = *std::max_element(extRadius, extRadius + NC);
72  }
73 
74 public:
77 
78  float maxEta;
79  //SOA
80  const uint32_t nt;
81  float* eta;
82  float* phi;
83  float* he;
84  float* h2;
85  float* st;
86  uint32_t* id;
87  uint32_t* mem = nullptr;
88  void initSoa() {
89  mem = new uint32_t[nt * 6];
90  eta = (float*)(mem);
91  phi = eta + nt;
92  he = phi + nt;
93  h2 = he + nt;
94  st = h2 + nt;
95  id = (uint32_t*)(st) + nt;
96  }
97 };
98 
99 /*#define ETISTATDEBUG*/
100 #ifdef ETISTATDEBUG
101 namespace etiStat {
102 
103  struct Count {
104  std::atomic<uint32_t> create = 0;
105  std::atomic<uint32_t> comp = 0;
106  std::atomic<uint32_t> span = 0;
107  static Count count;
108  ~Count();
109  };
110 
111 } // namespace etiStat
112 #endif
113 
114 template <unsigned int NC>
116  float intRadius[NC],
118  : maxEta(*std::max_element(extRadius, extRadius + NC)), nt(towers.size()) {
119  if (nt == 0)
120  return;
121  initSoa();
122 
123 #ifdef ETISTATDEBUG
124  etiStat::Count::count.create++;
125 #endif
126 
127  for (std::size_t i = 0; i != NCuts; ++i) {
130  }
131 
132  // sort in eta (kd-tree anoverkill,does not vectorize...)
133  uint32_t index[nt];
134 #ifdef __clang__
135  std::vector<float> e(nt);
136 #else
137  float e[nt];
138 #endif
139  for (std::size_t k = 0; k != nt; ++k) {
140  e[k] = towers[k].eta();
141  index[k] = k;
142  std::push_heap(index, index + k + 1, [&e](uint32_t i, uint32_t j) { return e[i] < e[j]; });
143  }
144  std::sort_heap(index, index + nt, [&e](uint32_t i, uint32_t j) { return e[i] < e[j]; });
145 
146  for (std::size_t i = 0; i != nt; ++i) {
147  auto j = index[i];
148  eta[i] = towers[j].eta();
149  phi[i] = towers[j].phi();
150  id[i] = towers[j].id();
151  st[i] = 1.f / std::cosh(eta[i]); // std::sin(towers[j].theta()); //;
152  he[i] = towers[j].hadEnergy();
153  h2[i] = towers[j].hadEnergyHeOuterLayer();
154  }
155 }
156 
157 template <unsigned int NC>
158 template <typename I>
160  bool et, Sum& sum, reco::SuperCluster const& sc, I first, I last) const {
161  if (nt == 0)
162  return;
163 
164 #ifdef ETISTATDEBUG
165  etiStat::Count::count.comp++;
166 #endif
167 
168  float candEta = sc.eta();
169  float candPhi = sc.phi();
170 
171  auto lb = std::lower_bound(eta, eta + nt, candEta - maxEta);
172  auto ub = std::upper_bound(lb, eta + nt, candEta + maxEta);
173  uint32_t il = lb - eta;
174  uint32_t iu = std::min(nt, uint32_t(ub - eta + 1));
175 
176 #ifdef ETISTATDEBUG
177  etiStat::Count::count.span += (iu - il);
178 #endif
179 
180  // should be restricted in eta....
181  for (std::size_t i = il; i != iu; ++i) {
182  float dr2 = reco::deltaR2(candEta, candPhi, eta[i], phi[i]);
183  float tt = et ? st[i] : 1.f;
184  for (std::size_t j = 0; j != NCuts; ++j) {
185  if (dr2 < extRadius2_[j]) {
186  if (dr2 >= intRadius2_[j]) {
187  sum.he[j] += he[i] * tt;
188  sum.h2[j] += h2[i] * tt;
189  }
190  if (std::find(first, last, id[i]) == last) {
191  sum.heBC[j] += he[i] * tt;
192  sum.h2BC[j] += h2[i] * tt;
193  }
194  }
195  }
196  }
197 }
198 
200 public:
201  enum HcalDepth { AllDepths = -1, Undefined = 0, Depth1 = 1, Depth2 = 2 };
202 
203  //constructors
205  float extRadiusI, float intRadiusI, float etLow, signed int depth, const CaloTowerCollection* towers);
206 
207  double getTowerEtSum(const reco::Candidate* cand, const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
208  reco::SuperCluster const& sc = *cand->get<reco::SuperClusterRef>().get();
209  return getSum(true, sc, detIdToExclude);
210  }
211  double getTowerESum(const reco::Candidate* cand, const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
212  reco::SuperCluster const& sc = *cand->get<reco::SuperClusterRef>().get();
213  return getSum(false, sc, detIdToExclude);
214  }
216  const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
217  return getSum(true, *sc, detIdToExclude);
218  }
219  double getTowerESum(reco::SuperCluster const* sc, const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
220  return getSum(false, *sc, detIdToExclude);
221  }
222 
223 private:
224  double getSum(bool et, reco::SuperCluster const& sc, const std::vector<CaloTowerDetId>* detIdToExclude) const;
225 
226 private:
227  signed int depth_;
228  float extRadius;
229  float intRadius;
230 };
231 
232 #endif
size
Write out results.
def create(alignables, pedeDump, additionalData, outputFile, config)
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
static constexpr unsigned int NCuts
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:184
Definition: TTTypes.h:54
void setRadius(float const extRadius[NC], float const intRadius[NC])
const std::complex< double > I
Definition: I.h:8
void compute(bool et, Sum &sum, reco::Candidate const &cand, I first, I last) const
int nt
Definition: AMPTWrapper.h:42
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
double getTowerESum(reco::SuperCluster const *sc, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
double getTowerEtSum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
EgammaTowerIsolation(float extRadiusI, float intRadiusI, float etLow, signed int depth, const CaloTowerCollection *towers)
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181
double getTowerEtSum(reco::SuperCluster const *sc, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
double getSum(bool et, reco::SuperCluster const &sc, const std::vector< CaloTowerDetId > *detIdToExclude) const