CMS 3D CMS Logo

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