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  void compute(
57  bool et, Sum& sum, reco::Candidate const& cand, CaloTowerDetId const* first, CaloTowerDetId const* last) const {
58  reco::SuperCluster const& sc = *cand.get<reco::SuperClusterRef>().get();
59  return compute(et, sum, sc, first, last);
60  }
61  void compute(
62  bool et, Sum& sum, reco::SuperCluster const& sc, CaloTowerDetId const* first, CaloTowerDetId const* last) const;
63 
64  void setRadius(float const extRadius[NC], float const intRadius[NC]) {
65  for (std::size_t i = 0; i != NCuts; ++i) {
68  }
69  maxEta = *std::max_element(extRadius, extRadius + NC);
70  }
71 
72 public:
75 
76  float maxEta;
77  //SOA
78  const uint32_t nt;
79  float* eta;
80  float* phi;
81  float* he;
82  float* h2;
83  float* st;
84  uint32_t* id;
85  uint32_t* mem = nullptr;
86  void initSoa() {
87  mem = new uint32_t[nt * 6];
88  eta = (float*)(mem);
89  phi = eta + nt;
90  he = phi + nt;
91  h2 = he + nt;
92  st = h2 + nt;
93  id = (uint32_t*)(st) + nt;
94  }
95 };
96 
97 /*#define ETISTATDEBUG*/
98 #ifdef ETISTATDEBUG
99 namespace etiStat {
100 
101  struct Count {
102  std::atomic<uint32_t> create = 0;
103  std::atomic<uint32_t> comp = 0;
104  std::atomic<uint32_t> span = 0;
105  static Count count;
106  ~Count();
107  };
108 
109 } // namespace etiStat
110 #endif
111 
112 template <unsigned int NC>
114  float intRadius[NC],
116  : maxEta(*std::max_element(extRadius, extRadius + NC)), nt(towers.size()) {
117  if (nt == 0)
118  return;
119  initSoa();
120 
121 #ifdef ETISTATDEBUG
122  etiStat::Count::count.create++;
123 #endif
124 
125  for (std::size_t i = 0; i != NCuts; ++i) {
128  }
129 
130  // sort in eta (kd-tree anoverkill,does not vectorize...)
131  uint32_t index[nt];
132 #ifdef __clang__
133  std::vector<float> e(nt);
134 #else
135  float e[nt];
136 #endif
137  for (std::size_t k = 0; k != nt; ++k) {
138  e[k] = towers[k].eta();
139  index[k] = k;
140  std::push_heap(index, index + k + 1, [&e](uint32_t i, uint32_t j) { return e[i] < e[j]; });
141  }
142  std::sort_heap(index, index + nt, [&e](uint32_t i, uint32_t j) { return e[i] < e[j]; });
143 
144  for (std::size_t i = 0; i != nt; ++i) {
145  auto j = index[i];
146  eta[i] = towers[j].eta();
147  phi[i] = towers[j].phi();
148  id[i] = towers[j].id();
149  st[i] = 1.f / std::cosh(eta[i]); // std::sin(towers[j].theta()); //;
150  he[i] = towers[j].hadEnergy();
151  h2[i] = towers[j].hadEnergyHeOuterLayer();
152  }
153 }
154 
155 template <unsigned int NC>
157  bool et, Sum& sum, reco::SuperCluster const& sc, CaloTowerDetId const* first, CaloTowerDetId const* last) const {
158  if (nt == 0)
159  return;
160 
161 #ifdef ETISTATDEBUG
162  etiStat::Count::count.comp++;
163 #endif
164 
165  float candEta = sc.eta();
166  float candPhi = sc.phi();
167 
168  auto lb = std::lower_bound(eta, eta + nt, candEta - maxEta);
169  auto ub = std::upper_bound(lb, eta + nt, candEta + maxEta);
170  uint32_t il = lb - eta;
171  uint32_t iu = std::min(nt, uint32_t(ub - eta + 1));
172 
173 #ifdef ETISTATDEBUG
174  etiStat::Count::count.span += (iu - il);
175 #endif
176 
177  // should be restricted in eta....
178  for (std::size_t i = il; i != iu; ++i) {
179  float dr2 = reco::deltaR2(candEta, candPhi, eta[i], phi[i]);
180  float tt = et ? st[i] : 1.f;
181  for (std::size_t j = 0; j != NCuts; ++j) {
182  if (dr2 < extRadius2_[j]) {
183  if (dr2 >= intRadius2_[j]) {
184  sum.he[j] += he[i] * tt;
185  sum.h2[j] += h2[i] * tt;
186  }
187  if (std::find(first, last, id[i]) == last) {
188  sum.heBC[j] += he[i] * tt;
189  sum.h2BC[j] += h2[i] * tt;
190  }
191  }
192  }
193  }
194 }
195 
197 public:
198  enum HcalDepth { AllDepths = -1, Undefined = 0, Depth1 = 1, Depth2 = 2 };
199 
200  //constructors
202  float extRadiusI, float intRadiusI, float etLow, signed int depth, const CaloTowerCollection* towers);
203 
204  double getTowerEtSum(const reco::Candidate* cand, const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
205  reco::SuperCluster const& sc = *cand->get<reco::SuperClusterRef>().get();
206  return getSum(true, sc, detIdToExclude);
207  }
208  double getTowerESum(const reco::Candidate* cand, const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
209  reco::SuperCluster const& sc = *cand->get<reco::SuperClusterRef>().get();
210  return getSum(false, sc, detIdToExclude);
211  }
213  const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
214  return getSum(true, *sc, detIdToExclude);
215  }
216  double getTowerESum(reco::SuperCluster const* sc, const std::vector<CaloTowerDetId>* detIdToExclude = nullptr) const {
217  return getSum(false, *sc, detIdToExclude);
218  }
219 
220 private:
221  double getSum(bool et, reco::SuperCluster const& sc, const std::vector<CaloTowerDetId>* detIdToExclude) const;
222 
223 private:
224  signed int depth_;
225  float extRadius;
226  float intRadius;
227 };
228 
229 #endif
reco::CaloCluster::phi
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:184
EgammaTowerIsolationNew::he
float * he
Definition: EgammaTowerIsolation.h:81
EgammaTowerIsolationNew::Sum::h2
float h2[NC]
Definition: EgammaTowerIsolation.h:41
mps_fire.i
i
Definition: mps_fire.py:355
EgammaTowerIsolationNew::nt
const uint32_t nt
Definition: EgammaTowerIsolation.h:78
EgammaTowerIsolation::depth_
signed int depth_
Definition: EgammaTowerIsolation.h:224
EgammaTowerIsolationNew::id
uint32_t * id
Definition: EgammaTowerIsolation.h:84
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
nt
int nt
Definition: AMPTWrapper.h:42
reco::SuperCluster
Definition: SuperCluster.h:18
EgammaTowerIsolationNew::Sum::he
float he[NC]
Definition: EgammaTowerIsolation.h:40
min
T min(T a, T b)
Definition: MathUtil.h:58
electronEcalRecHitIsolationLcone_cfi.extRadius
extRadius
Definition: electronEcalRecHitIsolationLcone_cfi.py:18
EgammaTowerIsolationNew::Sum::heBC
float heBC[NC]
Definition: EgammaTowerIsolation.h:42
edm::SortedCollection< CaloTower >
EgammaTowerIsolationNew::EgammaTowerIsolationNew
EgammaTowerIsolationNew()
Definition: EgammaTowerIsolation.h:51
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
RecoCandidate.h
EgammaTowerIsolationNew::Sum
Definition: EgammaTowerIsolation.h:38
dqmdumpme.first
first
Definition: dqmdumpme.py:55
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
edm::Ref< SuperClusterCollection >
deltaR.h
dqmdumpme.last
last
Definition: dqmdumpme.py:56
EgammaTowerIsolation::getTowerESum
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
Definition: EgammaTowerIsolation.h:208
EgammaTowerIsolation::Depth2
Definition: EgammaTowerIsolation.h:198
EgammaTowerIsolationNew::maxEta
float maxEta
Definition: EgammaTowerIsolation.h:76
cuda_std::upper_bound
__host__ constexpr __device__ RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:45
PVValHelper::eta
Definition: PVValidationHelpers.h:69
EgammaTowerIsolation::HcalDepth
HcalDepth
Definition: EgammaTowerIsolation.h:198
maxEta
double maxEta
Definition: PFJetBenchmarkAnalyzer.cc:76
EgammaTowerIsolationNew::extRadius2_
float extRadius2_[NCuts]
Definition: EgammaTowerIsolation.h:73
EgammaTowerIsolationNew::setRadius
void setRadius(float const extRadius[NC], float const intRadius[NC])
Definition: EgammaTowerIsolation.h:64
Sum
Definition: SiPixelActionExecutor.h:21
dqmdumpme.k
k
Definition: dqmdumpme.py:60
EgammaTowerIsolationNew::mem
uint32_t * mem
Definition: EgammaTowerIsolation.h:85
EgammaTowerIsolation::AllDepths
Definition: EgammaTowerIsolation.h:198
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
EgammaTowerIsolationNew::~EgammaTowerIsolationNew
~EgammaTowerIsolationNew()
Definition: EgammaTowerIsolation.h:54
EgammaTowerIsolationNew::intRadius2_
float intRadius2_[NCuts]
Definition: EgammaTowerIsolation.h:74
reco::CaloCluster::eta
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181
EgammaTowerIsolationNew
Definition: EgammaTowerIsolation.h:36
PVValHelper::phi
Definition: PVValidationHelpers.h:68
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
cand
Definition: decayParser.h:34
EgammaTowerIsolationNew::NCuts
constexpr static unsigned int NCuts
Definition: EgammaTowerIsolation.h:47
EgammaTowerIsolation
Definition: EgammaTowerIsolation.h:196
EgammaTowerIsolation::Undefined
Definition: EgammaTowerIsolation.h:198
EgammaTowerIsolationNew::Sum::h2BC
float h2BC[NC]
Definition: EgammaTowerIsolation.h:43
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
EgammaTowerIsolationNew::st
float * st
Definition: EgammaTowerIsolation.h:83
CaloTowerDetId.h
get
#define get
es_hardcode_cfi.he
he
Definition: es_hardcode_cfi.py:123
reco::Candidate
Definition: Candidate.h:27
CaloTowerCollection.h
EgammaTowerIsolation::extRadius
float extRadius
Definition: EgammaTowerIsolation.h:225
EgammaTowerIsolationNew::phi
float * phi
Definition: EgammaTowerIsolation.h:80
HLT_2018_cff.towers
towers
Definition: HLT_2018_cff.py:35030
EgammaTowerIsolation::getSum
double getSum(bool et, reco::SuperCluster const &sc, const std::vector< CaloTowerDetId > *detIdToExclude) const
Definition: EgammaTowerIsolation.cc:51
EgammaTowerIsolationNew::h2
float * h2
Definition: EgammaTowerIsolation.h:82
std
Definition: JetResolutionObject.h:76
EgammaTowerIsolation::getTowerEtSum
double getTowerEtSum(reco::SuperCluster const *sc, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
Definition: EgammaTowerIsolation.h:212
EgammaTowerIsolationNew::Sum::Sum
Sum()
Definition: EgammaTowerIsolation.h:39
electronHcalTowerIsolationLcone_cfi.intRadius
intRadius
Definition: electronHcalTowerIsolationLcone_cfi.py:5
SuperCluster.h
EgammaTowerIsolation::getTowerESum
double getTowerESum(reco::SuperCluster const *sc, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
Definition: EgammaTowerIsolation.h:216
EgammaTowerIsolation::getTowerEtSum
double getTowerEtSum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
Definition: EgammaTowerIsolation.h:204
EgammaTowerIsolation::Depth1
Definition: EgammaTowerIsolation.h:198
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
EgammaTowerIsolation::intRadius
float intRadius
Definition: EgammaTowerIsolation.h:226
EgammaTowerIsolationNew::initSoa
void initSoa()
Definition: EgammaTowerIsolation.h:86
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
EgammaTowerIsolationNew::eta
float * eta
Definition: EgammaTowerIsolation.h:79
EgammaTowerIsolation::EgammaTowerIsolation
EgammaTowerIsolation(float extRadiusI, float intRadiusI, float etLow, signed int depth, const CaloTowerCollection *towers)
Definition: EgammaTowerIsolation.cc:37
CaloTowerDetId
Definition: CaloTowerDetId.h:12
EgammaTowerIsolationNew::compute
void compute(bool et, Sum &sum, reco::Candidate const &cand, CaloTowerDetId const *first, CaloTowerDetId const *last) const
Definition: EgammaTowerIsolation.h:56