CMS 3D CMS Logo

HcalNoiseAlgo.cc
Go to the documentation of this file.
2 
4  double minRecHitE,
5  double minLowHitE,
6  double minHighHitE,
7  double TS4TS5EnergyThreshold,
8  std::vector<std::pair<double, double> > const& TS4TS5UpperCut,
9  std::vector<std::pair<double, double> > const& TS4TS5LowerCut,
10  double minRBXRechitR45E)
11  : r45Count_(0), r45Fraction_(0), r45EnergyFraction_(0) {
12  // energy
13  energy_ = rbx.recHitEnergy(minRecHitE);
14 
15  // ratio
16  e2ts_ = rbx.allChargeHighest2TS();
17  e10ts_ = rbx.allChargeTotal();
18 
19  // TS4TS5
20  TS4TS5Decision_ = true;
21  if (energy_ > TS4TS5EnergyThreshold) // check filter
22  {
23  std::vector<float> AllCharge = rbx.allCharge();
24  double BaseCharge = AllCharge[4] + AllCharge[5];
25  if (BaseCharge < 1)
26  BaseCharge = 1;
27  double TS4TS5 = (AllCharge[4] - AllCharge[5]) / BaseCharge;
28 
29  if (CheckPassFilter(BaseCharge, TS4TS5, TS4TS5UpperCut, 1) == false)
30  TS4TS5Decision_ = false;
31  if (CheckPassFilter(BaseCharge, TS4TS5, TS4TS5LowerCut, -1) == false)
32  TS4TS5Decision_ = false;
33  } else
34  TS4TS5Decision_ = true;
35 
36  // Rechit-wide R45
37  int rbxHitCount = rbx.numRecHits(minRBXRechitR45E);
38  r45Count_ = 0;
39  r45Fraction_ = 0;
41  if (rbxHitCount > 0) {
42  r45Count_ = rbx.numRecHitsFailR45(minRBXRechitR45E);
43  r45Fraction_ = (double)(r45Count_) / (double)(rbxHitCount);
44  r45EnergyFraction_ = rbx.recHitEnergyFailR45(minRBXRechitR45E) / rbx.recHitEnergy(minRBXRechitR45E);
45  }
46 
47  // # of hits
48  numHPDHits_ = 0;
49  for (std::vector<reco::HcalNoiseHPD>::const_iterator it1 = rbx.HPDsBegin(); it1 != rbx.HPDsEnd(); ++it1) {
50  int nhpdhits = it1->numRecHits(minRecHitE);
51  if (numHPDHits_ < nhpdhits)
52  numHPDHits_ = nhpdhits;
53  }
54  numRBXHits_ = rbx.numRecHits(minRecHitE);
56 
57  // # of ADC zeros
58  numZeros_ = rbx.totalZeros();
59 
60  // timing
65  for (std::vector<reco::HcalNoiseHPD>::const_iterator it1 = rbx.HPDsBegin(); it1 != rbx.HPDsEnd(); ++it1) {
67  for (edm::RefVector<HBHERecHitCollection>::const_iterator it2 = rechits.begin(); it2 != rechits.end(); ++it2) {
68  float energy = (*it2)->energy();
69  float time = (*it2)->time();
70  if (energy >= minLowHitE) {
71  if (minLowEHitTime_ > time)
73  if (maxLowEHitTime_ < time)
76  ++numLowEHits_;
77  }
78  if (energy >= minHighHitE) {
79  if (minHighEHitTime_ > time)
81  if (maxHighEHitTime_ < time)
84  ++numHighEHits_;
85  }
86  }
87  }
88 
89  // emf (get the one with minimum value)
90  HPDEMF_ = 999.;
91  for (std::vector<reco::HcalNoiseHPD>::const_iterator it1 = rbx.HPDsBegin(); it1 != rbx.HPDsEnd(); ++it1) {
92  double eme = it1->caloTowerEmE();
93  double hade = it1->recHitEnergy(minRecHitE);
94  double emf = (eme + hade) == 0 ? 999 : eme / (eme + hade);
95  if (HPDEMF_ > emf)
96  HPDEMF_ = emf;
97  }
98  double eme = rbx.caloTowerEmE();
99  RBXEMF_ = (eme + energy_) == 0 ? 999 : eme / (eme + energy_);
100 
101  // calotowers
102  rbxtowers_.clear();
104  for (std::vector<reco::HcalNoiseHPD>::const_iterator it1 = rbx.HPDsBegin(); it1 != rbx.HPDsEnd(); ++it1) {
105  join(rbxtowers_, it1->caloTowers());
106  }
107 
108  return;
109 }
110 
112  pMinERatio_ = iConfig.getParameter<double>("pMinERatio");
113  pMinEZeros_ = iConfig.getParameter<double>("pMinEZeros");
114  pMinEEMF_ = iConfig.getParameter<double>("pMinEEMF");
115 
116  minERatio_ = iConfig.getParameter<double>("minERatio");
117  minEZeros_ = iConfig.getParameter<double>("minEZeros");
118  minEEMF_ = iConfig.getParameter<double>("minEEMF");
119 
120  pMinE_ = iConfig.getParameter<double>("pMinE");
121  pMinRatio_ = iConfig.getParameter<double>("pMinRatio");
122  pMaxRatio_ = iConfig.getParameter<double>("pMaxRatio");
123  pMinHPDHits_ = iConfig.getParameter<int>("pMinHPDHits");
124  pMinRBXHits_ = iConfig.getParameter<int>("pMinRBXHits");
125  pMinHPDNoOtherHits_ = iConfig.getParameter<int>("pMinHPDNoOtherHits");
126  pMinZeros_ = iConfig.getParameter<int>("pMinZeros");
127  pMinLowEHitTime_ = iConfig.getParameter<double>("pMinLowEHitTime");
128  pMaxLowEHitTime_ = iConfig.getParameter<double>("pMaxLowEHitTime");
129  pMinHighEHitTime_ = iConfig.getParameter<double>("pMinHighEHitTime");
130  pMaxHighEHitTime_ = iConfig.getParameter<double>("pMaxHighEHitTime");
131  pMaxHPDEMF_ = iConfig.getParameter<double>("pMaxHPDEMF");
132  pMaxRBXEMF_ = iConfig.getParameter<double>("pMaxRBXEMF");
133 
134  if (iConfig.existsAs<int>("pMinRBXRechitR45Count"))
135  pMinRBXRechitR45Count_ = iConfig.getParameter<int>("pMinRBXRechitR45Count");
136  else
138  if (iConfig.existsAs<double>("pMinRBXRechitR45Fraction"))
139  pMinRBXRechitR45Fraction_ = iConfig.getParameter<double>("pMinRBXRechitR45Fraction");
140  else
142  if (iConfig.existsAs<double>("pMinRBXRechitR45EnergyFraction"))
143  pMinRBXRechitR45EnergyFraction_ = iConfig.getParameter<double>("pMinRBXRechitR45EnergyFraction");
144  else
146 
147  lMinRatio_ = iConfig.getParameter<double>("lMinRatio");
148  lMaxRatio_ = iConfig.getParameter<double>("lMaxRatio");
149  lMinHPDHits_ = iConfig.getParameter<int>("lMinHPDHits");
150  lMinRBXHits_ = iConfig.getParameter<int>("lMinRBXHits");
151  lMinHPDNoOtherHits_ = iConfig.getParameter<int>("lMinHPDNoOtherHits");
152  lMinZeros_ = iConfig.getParameter<int>("lMinZeros");
153  lMinLowEHitTime_ = iConfig.getParameter<double>("lMinLowEHitTime");
154  lMaxLowEHitTime_ = iConfig.getParameter<double>("lMaxLowEHitTime");
155  lMinHighEHitTime_ = iConfig.getParameter<double>("lMinHighEHitTime");
156  lMaxHighEHitTime_ = iConfig.getParameter<double>("lMaxHighEHitTime");
157 
158  if (iConfig.existsAs<std::vector<double> >("lRBXRecHitR45Cuts"))
159  lMinRBXRechitR45Cuts_ = iConfig.getParameter<std::vector<double> >("lRBXRecHitR45Cuts");
160  else {
161  double defaultCut[4] = {-999, -999, -999, -999};
162  lMinRBXRechitR45Cuts_ = std::vector<double>(defaultCut, defaultCut + 4);
163  }
164 
165  tMinRatio_ = iConfig.getParameter<double>("tMinRatio");
166  tMaxRatio_ = iConfig.getParameter<double>("tMaxRatio");
167  tMinHPDHits_ = iConfig.getParameter<int>("tMinHPDHits");
168  tMinRBXHits_ = iConfig.getParameter<int>("tMinRBXHits");
169  tMinHPDNoOtherHits_ = iConfig.getParameter<int>("tMinHPDNoOtherHits");
170  tMinZeros_ = iConfig.getParameter<int>("tMinZeros");
171  tMinLowEHitTime_ = iConfig.getParameter<double>("tMinLowEHitTime");
172  tMaxLowEHitTime_ = iConfig.getParameter<double>("tMaxLowEHitTime");
173  tMinHighEHitTime_ = iConfig.getParameter<double>("tMinHighEHitTime");
174  tMaxHighEHitTime_ = iConfig.getParameter<double>("tMaxHighEHitTime");
175 
176  if (iConfig.existsAs<std::vector<double> >("tRBXRecHitR45Cuts"))
177  tMinRBXRechitR45Cuts_ = iConfig.getParameter<std::vector<double> >("tRBXRecHitR45Cuts");
178  else {
179  double defaultCut[4] = {-999, -999, -999, -999};
180  tMinRBXRechitR45Cuts_ = std::vector<double>(defaultCut, defaultCut + 4);
181  }
182 
183  hlMaxHPDEMF_ = iConfig.getParameter<double>("hlMaxHPDEMF");
184  hlMaxRBXEMF_ = iConfig.getParameter<double>("hlMaxRBXEMF");
185 }
186 
188  if (data.energy() > pMinE_)
189  return true;
190  if (data.validRatio() && data.energy() > pMinERatio_ && data.ratio() < pMinRatio_)
191  return true;
192  if (data.validRatio() && data.energy() > pMinERatio_ && data.ratio() > pMaxRatio_)
193  return true;
194  if (data.numHPDHits() >= pMinHPDHits_)
195  return true;
196  if (data.numRBXHits() >= pMinRBXHits_)
197  return true;
198  if (data.numHPDNoOtherHits() >= pMinHPDNoOtherHits_)
199  return true;
200  if (data.numZeros() >= pMinZeros_ && data.energy() > pMinEZeros_)
201  return true;
202  if (data.minLowEHitTime() < pMinLowEHitTime_)
203  return true;
204  if (data.maxLowEHitTime() > pMaxLowEHitTime_)
205  return true;
206  if (data.minHighEHitTime() < pMinHighEHitTime_)
207  return true;
208  if (data.maxHighEHitTime() > pMaxHighEHitTime_)
209  return true;
210  if (data.HPDEMF() < pMaxHPDEMF_ && data.energy() > pMinEEMF_)
211  return true;
212  if (data.RBXEMF() < pMaxRBXEMF_ && data.energy() > pMinEEMF_)
213  return true;
214  if (data.r45Count() >= pMinRBXRechitR45Count_)
215  return true;
216  if (data.r45Fraction() >= pMinRBXRechitR45Fraction_)
217  return true;
218  if (data.r45EnergyFraction() >= pMinRBXRechitR45EnergyFraction_)
219  return true;
220 
221  return false;
222 }
223 
227 }
228 
232 }
233 
235  if (passEMFThreshold(data)) {
236  if (data.HPDEMF() < hlMaxHPDEMF_)
237  return false;
238  if (data.RBXEMF() < hlMaxRBXEMF_)
239  return false;
240  }
241  return true;
242 }
243 
245  if (passRatioThreshold(data)) {
246  if (data.validRatio() && data.ratio() < lMinRatio_)
247  return false;
248  if (data.validRatio() && data.ratio() > lMaxRatio_)
249  return false;
250  }
251  return true;
252 }
253 
255  if (data.numHPDHits() >= lMinHPDHits_)
256  return false;
257  if (data.numRBXHits() >= lMinRBXHits_)
258  return false;
259  if (data.numHPDNoOtherHits() >= lMinHPDNoOtherHits_)
260  return false;
261  return true;
262 }
263 
265  if (passZerosThreshold(data)) {
266  if (data.numZeros() >= lMinZeros_)
267  return false;
268  }
269  return true;
270 }
271 
273  if (data.minLowEHitTime() < lMinLowEHitTime_)
274  return false;
275  if (data.maxLowEHitTime() > lMaxLowEHitTime_)
276  return false;
277  if (data.minHighEHitTime() < lMinHighEHitTime_)
278  return false;
279  if (data.maxHighEHitTime() > lMaxHighEHitTime_)
280  return false;
281  return true;
282 }
283 
285  int Count = data.r45Count();
286  double Fraction = data.r45Fraction();
287  double EnergyFraction = data.r45EnergyFraction();
288 
289  for (int i = 0; i + 3 < (int)lMinRBXRechitR45Cuts_.size(); i = i + 4) {
290  double Value = Count * lMinRBXRechitR45Cuts_[i] + Fraction * lMinRBXRechitR45Cuts_[i + 1] +
291  EnergyFraction * lMinRBXRechitR45Cuts_[i + 2] + lMinRBXRechitR45Cuts_[i + 3];
292  if (Value > 0)
293  return false;
294  }
295 
296  return true;
297 }
298 
300  if (passRatioThreshold(data)) {
301  if (data.validRatio() && data.ratio() < tMinRatio_)
302  return false;
303  if (data.validRatio() && data.ratio() > tMaxRatio_)
304  return false;
305  }
306  return true;
307 }
308 
310  if (data.numHPDHits() >= tMinHPDHits_)
311  return false;
312  if (data.numRBXHits() >= tMinRBXHits_)
313  return false;
314  if (data.numHPDNoOtherHits() >= tMinHPDNoOtherHits_)
315  return false;
316  return true;
317 }
318 
320  if (passZerosThreshold(data)) {
321  if (data.numZeros() >= tMinZeros_)
322  return false;
323  }
324  return true;
325 }
326 
328  if (data.minLowEHitTime() < tMinLowEHitTime_)
329  return false;
330  if (data.maxLowEHitTime() > tMaxLowEHitTime_)
331  return false;
332  if (data.minHighEHitTime() < tMinHighEHitTime_)
333  return false;
334  if (data.maxHighEHitTime() > tMaxHighEHitTime_)
335  return false;
336  return true;
337 }
338 
340  int Count = data.r45Count();
341  double Fraction = data.r45Fraction();
342  double EnergyFraction = data.r45EnergyFraction();
343 
344  for (int i = 0; i + 3 < (int)tMinRBXRechitR45Cuts_.size(); i = i + 4) {
345  double Value = Count * tMinRBXRechitR45Cuts_[i] + Fraction * tMinRBXRechitR45Cuts_[i + 1] +
346  EnergyFraction * tMinRBXRechitR45Cuts_[i + 2] + tMinRBXRechitR45Cuts_[i + 3];
347  if (Value > 0)
348  return false;
349  }
350 
351  return true;
352 }
353 
355  return (data.energy() > minERatio_);
356 }
357 
359  return (data.energy() > minEZeros_);
360 }
361 
362 bool HcalNoiseAlgo::passEMFThreshold(const CommonHcalNoiseRBXData& data) const { return (data.energy() > minEEMF_); }
363 
365  const edm::RefVector<CaloTowerCollection>& v2) const {
366  // combines them first into a set to get rid of duplicates and then puts them into the first vector
367 
368  // sorts them first to get rid of duplicates, then puts them into another RefVector
369  twrrefset_t twrrefset;
370  for (edm::RefVector<CaloTowerCollection>::const_iterator it = v1.begin(); it != v1.end(); ++it)
371  twrrefset.insert(*it);
372  for (edm::RefVector<CaloTowerCollection>::const_iterator it = v2.begin(); it != v2.end(); ++it)
373  twrrefset.insert(*it);
374 
375  // clear the original refvector and put them back in
376  v1.clear();
377  for (twrrefset_t::const_iterator it = twrrefset.begin(); it != twrrefset.end(); ++it) {
378  v1.push_back(*it);
379  }
380  return;
381 }
382 
384  double Discriminant,
385  std::vector<std::pair<double, double> > const& Cuts,
386  int Side) {
387  //
388  // Checks whether Discriminant value passes Cuts for the specified Charge. True if pulse is good.
389  //
390  // The "Cuts" pairs are assumed to be sorted in terms of size from small to large,
391  // where each "pair" = (Charge, Discriminant)
392  // "Side" is either positive or negative, which determines whether to discard the pulse if discriminant
393  // is greater or smaller than the cut value
394  //
395 
396  if (Cuts.empty()) // safety check that there are some cuts defined
397  return true;
398 
399  if (Charge <= Cuts[0].first) // too small to cut on
400  return true;
401 
402  int IndexLargerThanCharge = -1; // find the range it is falling in
403  for (int i = 1; i < (int)Cuts.size(); i++) {
404  if (Cuts[i].first > Charge) {
405  IndexLargerThanCharge = i;
406  break;
407  }
408  }
409 
410  double limit = 1000000;
411 
412  if (IndexLargerThanCharge == -1) // if charge is greater than the last entry, assume flat line
413  limit = Cuts[Cuts.size() - 1].second;
414  else // otherwise, do a linear interpolation to find the cut position
415  {
416  double C1 = Cuts[IndexLargerThanCharge].first;
417  double C2 = Cuts[IndexLargerThanCharge - 1].first;
418  double L1 = Cuts[IndexLargerThanCharge].second;
419  double L2 = Cuts[IndexLargerThanCharge - 1].second;
420 
421  limit = (Charge - C1) / (C2 - C1) * (L2 - L1) + L1;
422  }
423 
424  if (Side > 0 && Discriminant > limit)
425  return false;
426  if (Side < 0 && Discriminant < limit)
427  return false;
428 
429  return true;
430 }
std::vector< HcalNoiseHPD >::const_iterator HPDsBegin(void) const
Definition: HcalNoiseRBX.h:57
bool CheckPassFilter(double Charge, double Discriminant, std::vector< std::pair< double, double > > const &Cuts, int Side)
std::set< edm::Ref< CaloTowerCollection >, twrrefcomp > twrrefset_t
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
bool passTightRatio(const CommonHcalNoiseRBXData &) const
double pMaxHPDEMF_
bool passLooseTiming(const CommonHcalNoiseRBXData &) const
double hlMaxRBXEMF_
double pMinERatio_
bool passLooseZeros(const CommonHcalNoiseRBXData &) const
double recHitEnergy(double theshold=1.5) const
Definition: HcalNoiseRBX.cc:76
bool passLooseRatio(const CommonHcalNoiseRBXData &) const
int pMinRBXRechitR45Count_
int totalZeros(void) const
Definition: HcalNoiseRBX.cc:61
double pMinHighEHitTime_
std::vector< double > lMinRBXRechitR45Cuts_
bool passRatioThreshold(const CommonHcalNoiseRBXData &) const
bool passTightNoiseFilter(const CommonHcalNoiseRBXData &) const
bool passTightZeros(const CommonHcalNoiseRBXData &) const
int numRecHits(double threshold=1.5) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
edm::RefVector< CaloTowerCollection > rbxtowers_
Definition: HcalNoiseAlgo.h:74
float allChargeTotal(void) const
Definition: HcalNoiseRBX.cc:40
double tMaxHighEHitTime_
double lMaxHighEHitTime_
bool passLooseHits(const CommonHcalNoiseRBXData &) const
bool passLooseRBXRechitR45(const CommonHcalNoiseRBXData &) const
double pMinEZeros_
double energy(void) const
Definition: HcalNoiseAlgo.h:24
double pMinRBXRechitR45EnergyFraction_
double tMinHighEHitTime_
double pMaxHighEHitTime_
std::vector< double > tMinRBXRechitR45Cuts_
double lMinLowEHitTime_
bool passZerosThreshold(const CommonHcalNoiseRBXData &) const
float allChargeHighest2TS(unsigned int firstts=4) const
Definition: HcalNoiseRBX.cc:47
double pMinRBXRechitR45Fraction_
double tMinLowEHitTime_
reco::JetExtendedAssociation::JetExtendedData Value
double pMaxLowEHitTime_
double pMinLowEHitTime_
bool passTightRBXRechitR45(const CommonHcalNoiseRBXData &) const
bool passEMFThreshold(const CommonHcalNoiseRBXData &) const
HcalNoiseAlgo(const edm::ParameterSet &iConfig)
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
double caloTowerEmE(void) const
bool passLooseNoiseFilter(const CommonHcalNoiseRBXData &) const
bool passHighLevelNoiseFilter(const CommonHcalNoiseRBXData &) const
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
std::vector< HcalNoiseHPD >::const_iterator HPDsEnd(void) const
Definition: HcalNoiseRBX.h:58
double pMaxRBXEMF_
int numRecHitsFailR45(double threshold=1.5) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
double lMaxLowEHitTime_
bool passTightTiming(const CommonHcalNoiseRBXData &) const
double lMinHighEHitTime_
CommonHcalNoiseRBXData(const reco::HcalNoiseRBX &rbx, double minRecHitE, double minLowHitE, double minHighHitE, double TS4TS5EnergyThreshold, std::vector< std::pair< double, double > > const &TS4TS5UpperCut, std::vector< std::pair< double, double > > const &TS4TS5LowerCut, double MinRBXRechitR45E)
Definition: HcalNoiseAlgo.cc:3
bool passTightHits(const CommonHcalNoiseRBXData &) const
void operator()(edm::RefVector< CaloTowerCollection > &v1, const edm::RefVector< CaloTowerCollection > &v2) const
const std::vector< float > allCharge(void) const
Definition: HcalNoiseRBX.cc:38
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
double recHitEnergyFailR45(double threshold=1.5) const
Definition: HcalNoiseRBX.cc:83
double tMaxLowEHitTime_
bool isProblematic(const CommonHcalNoiseRBXData &) const
double hlMaxHPDEMF_