CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalNoiseMonitor.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <fstream>
3 #include <algorithm>
4 
6 
11 
16 
21 
25 
27 
29 {
30  Online_ = ps.getUntrackedParameter<bool>("online",false);
31  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
32  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
33  debug_ = ps.getUntrackedParameter<int>("debug",0);
34  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
35  if(prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
36  prefixME_.append("/");
37  subdir_ = ps.getUntrackedParameter<std::string>("TaskFolder","NoiseMonitor_Hcal");
38  if(subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
39  subdir_.append("/");
40  subdir_=prefixME_+subdir_;
41  AllowedCalibTypes_ = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
42  skipOutOfOrderLS_ = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",false);
43  NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
44  makeDiagnostics_ = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
45 
46  triggers_=ps.getUntrackedParameter<std::vector<std::string> >("nzsHLTnames");
47  //["HLT_HcalPhiSym","HLT_HcalNoise_8E29]
48  period_=ps.getUntrackedParameter<int>("NoiseeventPeriod",4096); //4096
50  hltresultsLabel_ = ps.getUntrackedParameter<edm::InputTag>("HLTResultsLabel");
51  hbheDigiLabel_ = ps.getUntrackedParameter<edm::InputTag>("hbheDigiLabel");
52  hbheRechitLabel_ = ps.getUntrackedParameter<edm::InputTag>("hbheRechitLabel");
54 
55  mTrianglePeakTS = 4; // for now...
56 
57  mE2E10MinEnergy = ps.getUntrackedParameter<double>("E2E10MinEnergy");
58  mMinE2E10 = ps.getUntrackedParameter<double>("MinE2E10");
59  mMaxE2E10 = ps.getUntrackedParameter<double>("MaxE2E10");
60  mMaxHPDHitCount = ps.getUntrackedParameter<int>("MaxHPDHitCount");
61  mMaxHPDNoOtherHitCount = ps.getUntrackedParameter<int>("MaxHPDNoOtherHitCount");
62  mMaxADCZeros = ps.getUntrackedParameter<int>("MaxADCZeros");
63  mTotalZeroMinEnergy = ps.getUntrackedParameter<double>("TotalZeroMinEnergy");
64 }
65 
67 
69 {
70 }
71 
73 {
74  if(dbe_)
75  {
78  }
79 }
80 
82 {
83  if(debug_ > 1)
84  std::cout <<"HcalNoiseMonitor::beginRun"<< std::endl;
85 
87 
88  if(tevt_ == 0)
89  setup();
90 
91  if(mergeRuns_ == false)
92  reset();
93 
94  return;
95 }
96 
97 
99 {
101 
102  if(debug_ > 1)
103  std::cout << "<HcalNoiseMonitor::setup> Creating histograms" << std::endl;
104 
105  if(dbe_)
106  {
108 
109  // Fit-based
110  dbe_->setCurrentFolder(subdir_ + "DoubleChi2/");
111 
112  hNominalChi2 = dbe_->book1D("Nominal_fit_chi2", "Nominal fit chi2, total charge > 20 fC", 100, 0, 200);
113  hNominalChi2->setAxisTitle("Nominal fit #chi^{2}", 1);
114 
115  hLinearChi2 = dbe_->book1D("Linear_fit_chi2", "Linear fit chi2, total charge > 20 fC", 100, 0, 200);
116  hLinearChi2->setAxisTitle("Linear fit #chi^{2}", 1);
117 
118  hLinearTestStatistics = dbe_->book1D("Lambda_linear", "#Lambda_{linear}, total charge > 20 fC", 100, -10, 10);
119  hLinearTestStatistics->setAxisTitle("#Lambda_{linear}", 1);
120 
121  hRMS8OverMax = dbe_->book1D("RMS8_over_Max", "RMS8/max, total charge > 20 fC", 100, 0, 2);
122  hRMS8OverMax->setAxisTitle("RMS8/max", 1);
123 
124  hRMS8OverMaxTestStatistics = dbe_->book1D("Lambda_RMS8_over_max", "#Lambda_{RMS8/Max}, total charge > 20 fC",
125  100, -30, 10);
126  hRMS8OverMaxTestStatistics->setAxisTitle("#Lambda_{RMS8/Max}", 1);
127 
128  hLambdaLinearVsTotalCharge = dbe_->book2D("Lambda_linear_vs_total_charge", "#Lambda_{Linear}",
129  50, -5, 5, 25, 0, 500);
130  hLambdaLinearVsTotalCharge->setAxisTitle("#Lambda_{linear}", 1);
131  hLambdaLinearVsTotalCharge->setAxisTitle("Total charge", 2);
132 
133  hLambdaRMS8MaxVsTotalCharge = dbe_->book2D("Lambda_RMS8Max_vs_total_charge", "#Lambda_{RMS8/Max}",
134  50, -15, 5, 25, 0, 500);
135  hLambdaRMS8MaxVsTotalCharge->setAxisTitle("#Lambda_{RMS8/Max}", 1);
136  hLambdaRMS8MaxVsTotalCharge->setAxisTitle("Total charge", 2);
137 
138  hTriangleLeftSlopeVsTS4 = dbe_->book2D("Triangle_fit_left_slope",
139  "Triangle fit left distance vs. TS4", 50, 0, 10, 25, 0, 500);
140  hTriangleLeftSlopeVsTS4->setAxisTitle("Left slope", 1);
141  hTriangleLeftSlopeVsTS4->setAxisTitle("Peak time slice", 2);
142 
143  hTriangleRightSlopeVsTS4 = dbe_->book2D("Triangle_fit_right_slope",
144  "Triangle fit right distance vs. peak time slice", 50, 0, 10, 25, 0, 500);
145  hTriangleRightSlopeVsTS4->setAxisTitle("Left slope", 1);
146  hTriangleRightSlopeVsTS4->setAxisTitle("Peak time slice", 2);
147 
148  SetupEtaPhiHists(hFailLinearEtaPhi, "Fail_linear_Eta_Phi_Map", "");
149  SetupEtaPhiHists(hFailRMSMaxEtaPhi, "Fail_RMS8Max_Eta_Phi_Map", "");
150  SetupEtaPhiHists(hFailTriangleEtaPhi, "Fail_triangle_Eta_Phi_Map", "");
151 
152  // High-level isolation filter
153  dbe_->setCurrentFolder(subdir_ + "IsolationVariable/");
154 
155  SetupEtaPhiHists(hFailIsolationEtaPhi, "Fail_isolation_Eta_Phi_Map", "");
156 
157  // TS4 vs. TS5 variable
158  dbe_->setCurrentFolder(subdir_ + "TS4TS5Variable/");
159 
160  hTS4TS5RelativeDifference = dbe_->book1D("TS4_TS5_relative_difference",
161  "(TS4-TS5)/(TS4+TS5), total charge > 20 fC", 100, -1, 1);
162  hTS4TS5RelativeDifference->setAxisTitle("(TS4 - TS5) / (TS4 + TS5)", 1);
163 
164  hTS4TS5RelativeDifferenceVsCharge = dbe_->book2D("TS4_TS5_relative_difference_charge",
165  "(TS4-TS5)/(TS4+TS5) vs. Charge", 25, 0, 400, 75, -1, 1);
167  hTS4TS5RelativeDifferenceVsCharge->setAxisTitle("(TS4 - TS5) / (TS4 + TS5)", 2);
168 
169  // Noise summary object
170  dbe_->setCurrentFolder(subdir_ + "NoiseMonitoring/");
171 
172  hMaxZeros = dbe_->book1D("Max_Zeros", "Max zeros", 15, -0.5, 14.5);
173 
174  hTotalZeros = dbe_->book1D("Total_Zeros", "Total zeros", 15, -0.5, 14.5);
175 
176  hE2OverE10Digi = dbe_->book1D("E2OverE10Digi", "E2/E10 of the highest digi in an HPD", 100, 0, 2);
177 
178  hE2OverE10Digi5 = dbe_->book1D("E2OverE10Digi5", "E2/E10 of the highest 5 digi in an HPD", 100, 0, 2);
179 
180  hE2OverE10RBX = dbe_->book1D("E2OverE10RBX", "E2/E10 of RBX", 100, 0, 2);
181 
182  hHPDHitCount = dbe_->book1D("HPDHitCount", "HPD hit count (1.5 GeV)", 19, -0.5, 18.5);
183 
184  hRBXHitCount = dbe_->book1D("RBXHitCount", "Number of hits in RBX", 74, -0.5, 73.5);
185 
186  hHcalNoiseCategory = dbe_->book1D("Hcal_noise_category", "Hcal noise category", 10, 0.5, 10.5);
187  hHcalNoiseCategory->setBinLabel(1, "RBX noise", 1);
188  hHcalNoiseCategory->setBinLabel(2, "RBX pedestal flatter", 1);
189  hHcalNoiseCategory->setBinLabel(3, "RBX pedestal sharper", 1);
190  hHcalNoiseCategory->setBinLabel(4, "RBX flash large hit count", 1);
191  hHcalNoiseCategory->setBinLabel(5, "RBX flash small hit count", 1);
192  hHcalNoiseCategory->setBinLabel(7, "HPD discharge", 1);
193  hHcalNoiseCategory->setBinLabel(8, "HPD ion feedback", 1);
194 
195  hBadZeroRBX = dbe_->book1D("BadZeroRBX", "RBX with bad ADC zero counts", 72, 0.5, 72.5);
196  hBadCountHPD = dbe_->book1D("BadCountHPD", "HPD with bad hit counts", 72 * 4, 0.5, 72 * 4 + 0.5);
197  hBadNoOtherCountHPD = dbe_->book1D("BadNoOtherCountHPD", "HPD with bad \"no other\" hit counts", 72 * 4, 0.5, 72 * 4 + 0.5);
198  hBadE2E10RBX = dbe_->book1D("BadE2E10RBX", "RBX with bad E2/E10 value", 72, 0.5, 72.5);
199  }
200 
201  ReadHcalPulse();
202 
203  return;
204 }
205 
206 
208 {
210  iEvent.getByLabel(edm::InputTag(hbheDigiLabel_),hHBHEDigis);
211 
212  edm::ESHandle<HcalDbService> hConditions;
213  iSetup.get<HcalDbRecord>().get(hConditions);
214 
216  iEvent.getByLabel(edm::InputTag(hbheRechitLabel_), hRecHits);
217 
219  iEvent.getByLabel(edm::InputTag(noiseLabel_),hRBXCollection);
220 
221  HcalBaseDQMonitor::analyze(iEvent, iSetup);
222 
223  if(dbe_ == NULL)
224  {
225  if(debug_ > 0)
226  std::cout << "HcalNoiseMonitor::processEvent DQMStore not instantiated!!!"<< std::endl;
227  return;
228  }
229 
230  // loop over digis
231  for(HBHEDigiCollection::const_iterator iter = hHBHEDigis->begin(); iter != hHBHEDigis->end(); iter++)
232  {
233  HcalDetId id = iter->id();
234  const HcalCalibrations &Calibrations = hConditions->getHcalCalibrations(id);
235  const HcalQIECoder *ChannelCoder = hConditions->getHcalCoder(id);
236  const HcalQIEShape *Shape = hConditions->getHcalShape();
237  HcalCoderDb Coder(*ChannelCoder, *Shape);
238  CaloSamples Tool;
239  Coder.adc2fC(*iter, Tool);
240 
241  // int ieta = id.ieta();
242  // int iphi = id.iphi();
243  // int depth = id.depth();
244 
245  double Charge[10] = {0};
246  for(int i = 0; i < iter->size(); i++)
247  Charge[i] = Tool[i] - Calibrations.pedestal(iter->sample(i).capid());
248 
249  double TotalCharge = 0;
250  for(int i = 0; i < 10; i++)
251  TotalCharge = TotalCharge + Charge[i];
252 
253  if(TotalCharge > 20)
254  {
255  double NominalChi2 = 10000000;
256  NominalChi2 = PerformNominalFit(Charge);
257 
258  double LinearChi2 = PerformLinearFit(Charge);
259  double RMS8Max = CalculateRMS8Max(Charge);
260  TriangleFitResult TriangleResult = PerformTriangleFit(Charge);
261 
262  double TS4LeftSlope = 100000;
263  double TS4RightSlope = 100000;
264 
265  if(TriangleResult.LeftSlope > 1e-5)
266  TS4LeftSlope = Charge[4] / fabs(TriangleResult.LeftSlope);
267  if(TriangleResult.RightSlope < -1e-5)
268  TS4RightSlope = Charge[4] / fabs(TriangleResult.RightSlope);
269 
270  if(TS4LeftSlope < -1000 || TS4LeftSlope > 1000)
271  TS4LeftSlope = 1000;
272  if(TS4RightSlope < -1000 || TS4RightSlope > 1000)
273  TS4RightSlope = 1000;
274 
275  hNominalChi2->Fill(NominalChi2);
276  hLinearChi2->Fill(LinearChi2);
277  hLinearTestStatistics->Fill(log(LinearChi2) - log(NominalChi2));
278  hRMS8OverMax->Fill(RMS8Max);
279  hRMS8OverMaxTestStatistics->Fill(log(RMS8Max) - log(NominalChi2));
280 
281  hLambdaLinearVsTotalCharge->Fill(log(LinearChi2) - log(NominalChi2), TotalCharge);
282  hLambdaRMS8MaxVsTotalCharge->Fill(log(RMS8Max) - log(NominalChi2), TotalCharge);
283  hTriangleLeftSlopeVsTS4->Fill(TS4LeftSlope, Charge[4]);
284  hTriangleRightSlopeVsTS4->Fill(TS4RightSlope, Charge[4]);
285  }
286 
287  if(Charge[4] + Charge[5] > 1e-5)
288  {
289  hTS4TS5RelativeDifference->Fill((Charge[4] - Charge[5]) / (Charge[4] + Charge[5]));
290  hTS4TS5RelativeDifferenceVsCharge->Fill(TotalCharge, (Charge[4] - Charge[5]) / (Charge[4] + Charge[5]));
291  }
292  }
293 
294  // loop over rechits - noise bits (fit-based, isolation)
295  for(HBHERecHitCollection::const_iterator iter = hRecHits->begin(); iter != hRecHits->end(); iter++)
296  {
297  HcalDetId id = iter->id();
298 
299  int ieta = id.ieta();
300  int iphi = id.iphi();
301  int depth = id.depth();
302 
303  if(iter->flagField(HcalCaloFlagLabels::HBHEFlatNoise) == 1)
304  hFailLinearEtaPhi.depth[depth-1]->Fill(ieta, iphi);
305 
306  if(iter->flagField(HcalCaloFlagLabels::HBHESpikeNoise) == 1)
307  hFailRMSMaxEtaPhi.depth[depth-1]->Fill(ieta, iphi);
308 
309  if(iter->flagField(HcalCaloFlagLabels::HBHETriangleNoise) == 1)
310  hFailTriangleEtaPhi.depth[depth-1]->Fill(ieta, iphi);
311 
312  if(iter->flagField(HcalCaloFlagLabels::HBHEIsolatedNoise) == 1)
313  hFailIsolationEtaPhi.depth[depth-1]->Fill(ieta, iphi);
314  }
315 
316  // Code analagous to Yifei's
317  for(reco::HcalNoiseRBXCollection::const_iterator rbx = hRBXCollection->begin();
318  rbx != hRBXCollection->end(); rbx++)
319  {
320  const reco::HcalNoiseRBX RBX = *rbx;
321 
322  int NumberRBXHits = RBX.numRecHits(1.5);
323  double RBXEnergy = RBX.recHitEnergy(1.5);
324  double RBXE2 = RBX.allChargeHighest2TS();
325  double RBXE10 = RBX.allChargeTotal();
326 
327  std::vector<reco::HcalNoiseHPD> HPDs = RBX.HPDs();
328 
329  int RBXID = RBX.idnumber();
330 
331  if(RBXEnergy > mTotalZeroMinEnergy && RBX.totalZeros() >= mMaxADCZeros)
332  hBadZeroRBX->Fill(RBXID);
333  if(RBXEnergy > mE2E10MinEnergy && RBXE10 > 1e-5 && (RBXE2 / RBXE10 > mMaxE2E10 || RBXE2 / RBXE10 < mMinE2E10))
334  hBadE2E10RBX->Fill(RBXID);
335  for(std::vector<reco::HcalNoiseHPD>::const_iterator hpd = HPDs.begin(); hpd != HPDs.end(); hpd++)
336  {
337  reco::HcalNoiseHPD HPD = *hpd;
338  int HPDHitCount = HPD.numRecHits(1.5);
339  if(HPDHitCount >= mMaxHPDHitCount)
340  hBadCountHPD->Fill(HPD.idnumber());
341  if(HPDHitCount == NumberRBXHits && HPDHitCount >= mMaxHPDNoOtherHitCount)
343  }
344 
345  if(NumberRBXHits == 0 || RBXEnergy <= 10)
346  continue;
347 
348  hRBXHitCount->Fill(NumberRBXHits);
349 
350  hMaxZeros->Fill(RBX.maxZeros());
351  hTotalZeros->Fill(RBX.totalZeros());
352 
353  double HighestHPDEnergy = 0;
354  int HighestHPDHits = 0;
355 
356  for(std::vector<reco::HcalNoiseHPD>::const_iterator hpd = HPDs.begin(); hpd != HPDs.end(); hpd++)
357  {
358  reco::HcalNoiseHPD HPD = *hpd;
359 
360  if(HPD.recHitEnergy(1.5) > HighestHPDEnergy)
361  {
362  HighestHPDEnergy = HPD.recHitEnergy(1.5);
363  HighestHPDHits = HPD.numRecHits(1.5);
364  }
365 
366  if(HPD.numRecHits(5) < 1)
367  continue;
368 
369  if(HPD.bigChargeTotal() > 1e-5)
371  if(HPD.big5ChargeTotal() > 1e-5)
373 
374  hHPDHitCount->Fill(HPD.numRecHits(1.5));
375  }
376 
377  int NoiseCategory = 0;
378  bool IsRBXNoise = false;
379  // bool IsHPDNoise = false;
380  // bool IsHPDIonFeedback = false;
381  // bool IsHPDDischarge = false;
382 
383  if(RBXEnergy > 1e-5 && HighestHPDEnergy / RBXEnergy > 0.98)
384  {
385  // IsHPDNoise = true;
386 
387  if(HighestHPDHits >= 9)
388  {
389  // IsHPDDischarge = true;
390  NoiseCategory = 7;
391  }
392  else
393  {
394  // IsHPDIonFeedback = true;
395  NoiseCategory = 8;
396  }
397  }
398  else
399  {
400  IsRBXNoise = true;
401  NoiseCategory = 1;
402 
403  if(RBXE10 > 1e-5)
404  {
405  if(RBXE2 / RBXE10 < 0.33)
406  NoiseCategory = 2;
407  else if(RBXE2 / RBXE10 < 0.8)
408  NoiseCategory = 3;
409  else if(RBXE2 / RBXE10 > 0.8 && NumberRBXHits > 10)
410  NoiseCategory = 4;
411  else if(RBXE2 / RBXE10 > 0.8 && NumberRBXHits < 10) // [hic]
412  NoiseCategory = 5;
413  }
414  }
415 
416  hHcalNoiseCategory->Fill(NoiseCategory);
417 
418  if(IsRBXNoise == true && RBXE10 > 1e-5)
419  hE2OverE10RBX->Fill(RBXE2 / RBXE10);
420  }
421 
422  return;
423 }
424 
425 double HcalNoiseMonitor::PerformNominalFit(double Charge[10])
426 {
427  //
428  // Performs a fit to the ideal pulse shape. Returns best chi2
429  //
430  // A scan over different timing offset (for the ideal pulse) is carried out,
431  // and for each offset setting a one-parameter fit is performed
432  //
433 
434  int DigiSize = 10;
435 
436  double MinimumChi2 = 100000;
437 
438  double F = 0;
439 
440  double SumF2 = 0;
441  double SumTF = 0;
442  double SumT2 = 0;
443 
444  for(int i = 0; i + 250 < (int)CumulativeIdealPulse.size(); i++)
445  {
447  continue;
448 
449  SumF2 = 0;
450  SumTF = 0;
451  SumT2 = 0;
452 
453  for(int j = 0; j < DigiSize; j++)
454  {
455  // get ideal pulse component for this time slice....
456  F = CumulativeIdealPulse[i+j*25+25] - CumulativeIdealPulse[i+j*25];
457 
458  double Error2 = Charge[j];
459  if(Error2 < 1)
460  Error2 = 1;
461 
462  // ...and increment various summations
463  SumF2 += F * F / Error2;
464  SumTF += F * Charge[j] / Error2;
465  SumT2 += Charge[j] * Charge[j] / Error2;
466  }
467 
468  /* chi2= sum((Charge[j]-aF)^2/|Charge[j]|
469  ( |Charge[j]| = assumed sigma^2 for Charge[j]; a bit wonky for Charge[j]<1 )
470  chi2 = sum(|Charge[j]|) - 2*sum(aF*Charge[j]/|Charge[j]|) +sum( a^2*F^2/|Charge[j]|)
471  chi2 minimimized when d(chi2)/da = 0:
472  a = sum(F*Charge[j])/sum(F^2)
473  ...
474  chi2= sum(|Q[j]|) - sum(Q[j]/|Q[j]|*F)*sum(Q[j]/|Q[j]|*F)/sum(F^2/|Q[j]|), where Q = Charge
475  chi2 = SumT2 - SumTF*SumTF/SumF2
476  */
477 
478  double Chi2 = SumT2 - SumTF * SumTF / SumF2;
479 
480  if(Chi2 < MinimumChi2)
481  MinimumChi2 = Chi2;
482  }
483 
484  // safety protection in case of perfect fit - don't want the log(...) to explode
485  if(MinimumChi2 < 1e-5)
486  MinimumChi2 = 1e-5;
487 
488  return MinimumChi2;
489 }
490 
492 {
493  //
494  // Perform dual nominal fit and returns the chi2
495  //
496  // In this function we do a scan over possible "distance" (number of time slices between two components)
497  // and overall offset for the two components; first coarse, then finer
498  // All the fitting is done in the DualNominalFitSingleTry function
499  //
500 
501  double OverallMinimumChi2 = 1000000;
502 
503  int AvailableDistance[] = {-100, -75, -50, 50, 75, 100};
504 
505  // loop over possible pulse distances between two components
506  for(int k = 0; k < 6; k++)
507  {
508  double SingleMinimumChi2 = 1000000;
509  int MinOffset = 0;
510 
511  // scan coarsely through different offsets and find the minimum
512  for(int i = 0; i + 250 < (int)CumulativeIdealPulse.size(); i += 10)
513  {
514  double Chi2 = DualNominalFitSingleTry(Charge, i, AvailableDistance[k]);
515 
516  if(Chi2 < SingleMinimumChi2)
517  {
518  SingleMinimumChi2 = Chi2;
519  MinOffset = i;
520  }
521  }
522 
523  // around the minimum, scan finer for better a better minimum
524  for(int i = MinOffset - 15; i + 250 < (int)CumulativeIdealPulse.size() && i < MinOffset + 15; i++)
525  {
526  double Chi2 = DualNominalFitSingleTry(Charge, i, AvailableDistance[k]);
527  if(Chi2 < SingleMinimumChi2)
528  SingleMinimumChi2 = Chi2;
529  }
530 
531  // update overall minimum chi2
532  if(SingleMinimumChi2 < OverallMinimumChi2)
533  OverallMinimumChi2 = SingleMinimumChi2;
534  }
535 
536  return OverallMinimumChi2;
537 }
538 
539 double HcalNoiseMonitor::DualNominalFitSingleTry(double Charge[10], int Offset, int Distance)
540 {
541  //
542  // Does a fit to dual signal pulse hypothesis given offset and distance of the two target pulses
543  //
544  // The only parameters to fit here are the two pulse heights of in-time and out-of-time components
545  // since offset is given
546  // The calculation here is based from writing down the Chi2 formula and minimize against the two parameters,
547  // ie., Chi2 = Sum{((T[i] - a1 * F1[i] - a2 * F2[i]) / (Sigma[i]))^2}, where T[i] is the input pulse shape,
548  // and F1[i], F2[i] are the two ideal pulse components
549  //
550 
551  int DigiSize = 10;
552 
553  if(Offset < 0 || Offset + 250 >= (int)CumulativeIdealPulse.size())
554  return 1000000;
555  if(CumulativeIdealPulse[Offset+250] - CumulativeIdealPulse[Offset] < 1e-5)
556  return 1000000;
557 
558  static std::vector<double> F1;
559  static std::vector<double> F2;
560 
561  F1.resize(DigiSize);
562  F2.resize(DigiSize);
563 
564  double SumF1F1 = 0;
565  double SumF1F2 = 0;
566  double SumF2F2 = 0;
567  double SumTF1 = 0;
568  double SumTF2 = 0;
569 
570  double Error = 0;
571 
572  for(int j = 0; j < DigiSize; j++)
573  {
574  // this is the TS value for in-time component - no problem we can do a subtraction directly
575  F1[j] = CumulativeIdealPulse[Offset+j*25+25] - CumulativeIdealPulse[Offset+j*25];
576 
577  // However for the out-of-time component the index might go out-of-bound.
578  // Let's protect against this.
579 
580  int OffsetTemp = Offset + j * 25 + Distance;
581 
582  double C1 = 0; // lower-indexed value in the cumulative pulse shape
583  double C2 = 0; // higher-indexed value in the cumulative pulse shape
584 
585  if(OffsetTemp + 25 < (int)CumulativeIdealPulse.size() && OffsetTemp + 25 >= 0)
586  C1 = CumulativeIdealPulse[OffsetTemp+25];
587  if(OffsetTemp + 25 >= (int)CumulativeIdealPulse.size())
588  C1 = CumulativeIdealPulse[CumulativeIdealPulse.size()-1];
589  if(OffsetTemp < (int)CumulativeIdealPulse.size() && OffsetTemp >= 0)
590  C2 = CumulativeIdealPulse[OffsetTemp];
591  if(OffsetTemp >= (int)CumulativeIdealPulse.size())
592  C2 = CumulativeIdealPulse[CumulativeIdealPulse.size()-1];
593  F2[j] = C1 - C2;
594 
595  Error = Charge[j];
596  if(Error < 1)
597  Error = 1;
598 
599  SumF1F1 += F1[j] * F1[j] / Error;
600  SumF1F2 += F1[j] * F2[j] / Error;
601  SumF2F2 += F2[j] * F2[j] / Error;
602  SumTF1 += F1[j] * Charge[j] / Error;
603  SumTF2 += F2[j] * Charge[j] / Error;
604  }
605 
606  double Height = (SumF1F2 * SumTF2 - SumF2F2 * SumTF1) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
607  double Height2 = (SumF1F2 * SumTF1 - SumF1F1 * SumTF2) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
608 
609  double Chi2 = 0;
610  for(int j = 0; j < DigiSize; j++)
611  {
612  double Error = Charge[j];
613  if(Error < 1)
614  Error = 1;
615 
616  double Residual = Height * F1[j] + Height2 * F2[j] - Charge[j];
617  Chi2 += Residual * Residual / Error;
618  }
619 
620  // Safety protection in case of zero
621  if(Chi2 < 1e-5)
622  Chi2 = 1e-5;
623 
624  return Chi2;
625 }
626 
627 double HcalNoiseMonitor::PerformLinearFit(double Charge[10])
628 {
629  //
630  // Performs a straight-line fit over all time slices, and returns the chi2 value
631  //
632  // The calculation here is based from writing down the formula for chi2 and minimize
633  // with respect to the parameters in the fit, ie., slope and intercept of the straight line
634  // By doing two differentiation, we will get two equations, and the best parameters are determined by these
635  //
636 
637  int DigiSize = 10;
638 
639  double SumTS2OverTi = 0;
640  double SumTSOverTi = 0;
641  double SumOverTi = 0;
642  double SumTiTS = 0;
643  double SumTi = 0;
644 
645  double Error2 = 0;
646  for(int i = 0; i < DigiSize; i++)
647  {
648  Error2 = Charge[i];
649  if(Charge[i] < 1)
650  Error2 = 1;
651 
652  SumTS2OverTi += 1.* i * i / Error2;
653  SumTSOverTi += 1.* i / Error2;
654  SumOverTi += 1. / Error2;
655  SumTiTS += Charge[i] * i / Error2;
656  SumTi += Charge[i] / Error2;
657  }
658 
659  double CM1 = SumTS2OverTi; // Coefficient in front of slope in equation 1
660  double CM2 = SumTSOverTi; // Coefficient in front of slope in equation 2
661  double CD1 = SumTSOverTi; // Coefficient in front of intercept in equation 1
662  double CD2 = SumOverTi; // Coefficient in front of intercept in equation 2
663  double C1 = SumTiTS; // Constant coefficient in equation 1
664  double C2 = SumTi; // Constant coefficient in equation 2
665 
666  double Slope = (C1 * CD2 - C2 * CD1) / (CM1 * CD2 - CM2 * CD1);
667  double Intercept = (C1 * CM2 - C2 * CM1) / (CD1 * CM2 - CD2 * CM1);
668 
669  // now that the best parameters are found, calculate chi2 from those
670  double Chi2 = 0;
671  for(int i = 0; i < DigiSize; i++)
672  {
673  double Deviation = Slope * i + Intercept - Charge[i];
674  double Error2 = Charge[i];
675  if(Charge[i] < 1)
676  Error2 = 1;
677  Chi2 += Deviation * Deviation / Error2;
678  }
679 
680  // safety protection in case of perfect fit
681  if(Chi2 < 1e-5)
682  Chi2 = 1e-5;
683 
684  return Chi2;
685 }
686 
687 double HcalNoiseMonitor::CalculateRMS8Max(double Charge[10])
688 {
689  //
690  // CalculateRMS8Max
691  //
692  // returns "RMS" divided by the largest charge in the time slices
693  // "RMS" is calculated using all but the two largest time slices.
694  // The "RMS" is not quite the actual RMS (see note below), but the value is only
695  // used for determining max values, and is not quoted as the actual RMS anywhere.
696  //
697 
698  int DigiSize = 10;
699 
700  // Copy Charge vector again, since we are passing references around
701  std::vector<double> TempCharge(Charge, Charge + 10);
702 
703  // Sort TempCharge vector from smallest to largest charge
704  sort(TempCharge.begin(), TempCharge.end());
705 
706  double Total = 0;
707  double Total2 = 0;
708  for(int i = 0; i < DigiSize - 2; i++)
709  {
710  Total = Total + TempCharge[i];
711  Total2 = Total2 + TempCharge[i] * TempCharge[i];
712  }
713 
714  // This isn't quite the RMS (both Total2 and Total*Total need to be
715  // divided by an extra (DigiSize-2) within the sqrt to get the RMS.)
716  // We're only using this value for relative comparisons, though; we
717  // aren't explicitly interpreting it as the RMS. It might be nice
718  // to either change the calculation or rename the variable in the future, though.
719 
720  double RMS = sqrt(Total2 - Total * Total / (DigiSize - 2));
721 
722  double RMS8Max = 99999;
723  if(TempCharge[DigiSize-1] > 1e-5)
724  RMS8Max = RMS / TempCharge[DigiSize-1];
725  if(RMS8Max < 1e-5) // protection against zero
726  RMS8Max = 1e-5;
727 
728  return RMS8Max;
729 }
730 
732 {
733  //
734  // Perform a "triangle fit", and extract the slopes
735  //
736  // Left-hand side and right-hand side are not correlated to each other - do them separately
737  //
738 
740  result.Chi2 = 0;
741  result.LeftSlope = 0;
742  result.RightSlope = 0;
743 
744  int DigiSize = 10;
745 
746  // right side, starting from TS4
747  double MinimumRightChi2 = 1000000;
748  double Numerator = 0;
749  double Denominator = 0;
750 
751  for(int iTS = mTrianglePeakTS + 2; iTS <= DigiSize; iTS++) // the place where first TS center in flat line
752  {
753  // fit a straight line to the triangle part
754  Numerator = 0;
755  Denominator = 0;
756 
757  for(int i = mTrianglePeakTS + 1; i < iTS; i++)
758  {
759  Numerator += (i - mTrianglePeakTS) * (Charge[i] - Charge[mTrianglePeakTS]);
760  Denominator += (i - mTrianglePeakTS) * (i - mTrianglePeakTS);
761  }
762 
763  double BestSlope = Numerator / Denominator;
764  if(BestSlope > 0)
765  BestSlope = 0;
766 
767  // check if the slope is reasonable
768  if(iTS != DigiSize)
769  {
770  if(BestSlope > -1 * Charge[mTrianglePeakTS] / (iTS - mTrianglePeakTS))
771  BestSlope = -1 * Charge[mTrianglePeakTS] / (iTS - mTrianglePeakTS);
772  if(BestSlope < -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS))
773  BestSlope = -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS);
774  }
775  else
776  {
777  if(BestSlope < -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS))
778  BestSlope = -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS);
779  }
780 
781  // calculate partial chi2
782 
783  // The shape I'm fitting is more like a tent than a triangle.
784  // After the end of triangle edge assume a flat line
785 
786  double Chi2 = 0;
787  for(int i = mTrianglePeakTS + 1; i < iTS; i++)
788  Chi2 += (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope)
789  * (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope);
790  for(int i = iTS; i < DigiSize; i++) // Assumes fit line = 0 for iTS > fit
791  Chi2 += Charge[i] * Charge[i];
792 
793  if(Chi2 < MinimumRightChi2)
794  {
795  MinimumRightChi2 = Chi2;
796  result.RightSlope = BestSlope;
797  }
798  } // end of right-hand side loop
799 
800  // left side
801  double MinimumLeftChi2 = 1000000;
802 
803  for(int iTS = 0; iTS < (int)mTrianglePeakTS; iTS++) // the first time after linear fit ends
804  {
805  // fit a straight line to the triangle part
806  Numerator = 0;
807  Denominator = 0;
808  for(int i = iTS; i < (int)mTrianglePeakTS; i++)
809  {
810  Numerator = Numerator + (i - mTrianglePeakTS) * (Charge[i] - Charge[mTrianglePeakTS]);
811  Denominator = Denominator + (i - mTrianglePeakTS) * (i - mTrianglePeakTS);
812  }
813 
814  double BestSlope = Numerator / Denominator;
815  if(BestSlope < 0)
816  BestSlope = 0;
817 
818  // check slope
819  if(iTS != 0)
820  {
821  if(BestSlope > Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS))
822  BestSlope = Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS);
823  if(BestSlope < Charge[mTrianglePeakTS] / (mTrianglePeakTS + 1 - iTS))
824  BestSlope = Charge[mTrianglePeakTS] / (mTrianglePeakTS + 1 - iTS);
825  }
826  else
827  {
828  if(BestSlope > Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS))
829  BestSlope = Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS);
830  }
831 
832  // calculate minimum chi2
833  double Chi2 = 0;
834  for(int i = 0; i < iTS; i++)
835  Chi2 += Charge[i] * Charge[i];
836  for(int i = iTS; i < (int)mTrianglePeakTS; i++)
837  Chi2 += (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope)
838  * (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope);
839 
840  if(MinimumLeftChi2 > Chi2)
841  {
842  MinimumLeftChi2 = Chi2;
843  result.LeftSlope = BestSlope;
844  }
845  } // end of left-hand side loop
846 
847  result.Chi2 = MinimumLeftChi2 + MinimumRightChi2;
848 
849  return result;
850 }
851 
853 {
854  std::vector<double> PulseShape;
855 
856  HcalPulseShapes Shapes;
857  HcalPulseShapes::Shape HPDShape = Shapes.hbShape();
858 
859  PulseShape.reserve(350);
860  for(int i = 0; i < 200; i++)
861  PulseShape.push_back(HPDShape.at(i));
862  PulseShape.insert(PulseShape.begin(), 150, 0); // Safety margin of a lot of zeros in the beginning
863 
864  CumulativeIdealPulse.reserve(350);
865  CumulativeIdealPulse.clear();
866  CumulativeIdealPulse.push_back(0);
867  for(unsigned int i = 1; i < PulseShape.size(); i++)
868  CumulativeIdealPulse.push_back(CumulativeIdealPulse[i-1] + PulseShape[i]);
869 }
870 
872 
MonitorElement * hBadCountHPD
MonitorElement * hE2OverE10Digi
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * hBadNoOtherCountHPD
MonitorElement * hTS4TS5RelativeDifferenceVsCharge
int i
Definition: DBlmapReader.cc:9
double PerformNominalFit(double Charge[10])
MonitorElement * hE2OverE10RBX
edm::InputTag noiseLabel_
float allChargeHighest2TS(unsigned int firstts=4) const
Definition: HcalNoiseRBX.cc:65
int idnumber(void) const
Definition: HcalNoiseHPD.cc:32
MonitorElement * hMaxZeros
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
int maxZeros(void) const
Definition: HcalNoiseRBX.cc:90
float at(double time) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< int > AllowedCalibTypes_
TriangleFitResult PerformTriangleFit(double Charge[10])
MonitorElement * hLambdaRMS8MaxVsTotalCharge
std::vector< T >::const_iterator const_iterator
double CalculateRMS8Max(double Charge[10])
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
int numRecHits(double threshold=1.5) const
MonitorElement * hHcalNoiseCategory
#define NULL
Definition: scimark2.h:8
double pedestal(int fCapId) const
get pedestal for capid=0..3
MonitorElement * hNominalChi2
EtaPhiHists hFailRMSMaxEtaPhi
void Fill(long long x)
MonitorElement * hTotalZeros
edm::InputTag hbheDigiLabel_
MonitorElement * hLinearChi2
MonitorElement * hLinearTestStatistics
edm::InputTag hltresultsLabel_
int iEvent
Definition: GenABIO.cc:243
std::vector< MonitorElement * > depth
MonitorElement * hBadE2E10RBX
virtual void beginRun(const edm::Run &run, const edm::EventSetup &c)
void removeContents(void)
erase all monitoring elements in current directory (not including subfolders);
Definition: DQMStore.cc:2564
double recHitEnergy(double theshold=1.5) const
Definition: HcalNoiseRBX.cc:99
float allChargeTotal(void) const
Definition: HcalNoiseRBX.cc:57
EtaPhiHists hFailTriangleEtaPhi
float big5ChargeHighest2TS(unsigned int firstts=4) const
Definition: HcalNoiseHPD.cc:81
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const
Definition: HcalCoderDb.cc:37
T sqrt(T t)
Definition: SSEVec.h:46
int numRecHits(float threshold=1.5) const
MonitorElement * hBadZeroRBX
void beginRun(const edm::Run &run, const edm::EventSetup &c)
tuple result
Definition: query.py:137
MonitorElement * hTriangleRightSlopeVsTS4
float bigChargeHighest2TS(unsigned int firstts=4) const
Definition: HcalNoiseHPD.cc:51
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
MonitorElement * hRMS8OverMaxTestStatistics
int j
Definition: DBlmapReader.cc:9
MonitorElement * hTS4TS5RelativeDifference
double PerformDualNominalFit(double Charge[10])
float big5ChargeTotal(void) const
Definition: HcalNoiseHPD.cc:72
double DualNominalFitSingleTry(double Charge[10], int Offset, int Distance)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
int k[5][pyjets_maxn]
MonitorElement * hRBXHitCount
MonitorElement * hE2OverE10Digi5
int totalZeros(void) const
Definition: HcalNoiseRBX.cc:82
const T & get() const
Definition: EventSetup.h:55
MonitorElement * hRMS8OverMax
MonitorElement * hTriangleLeftSlopeVsTS4
const std::vector< HcalNoiseHPD > HPDs(void) const
Definition: HcalNoiseRBX.cc:33
void SetupEtaPhiHists(EtaPhiHists &hh, std::string Name, std::string Units)
std::vector< double > CumulativeIdealPulse
const Shape & hbShape() const
float recHitEnergy(float threshold=1.5) const
void analyze(edm::Event const &e, edm::EventSetup const &s)
int idnumber(void) const
Definition: HcalNoiseRBX.cc:28
tuple cout
Definition: gather_cfg.py:121
MonitorElement * hHPDHitCount
EtaPhiHists hFailIsolationEtaPhi
std::vector< std::string > triggers_
edm::InputTag hbheRechitLabel_
edm::InputTag rawdataLabel_
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
Definition: Chi2.h:17
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
virtual void setup(void)
HcalNoiseMonitor(const edm::ParameterSet &ps)
MonitorElement * hLambdaLinearVsTotalCharge
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
float bigChargeTotal(void) const
Definition: HcalNoiseHPD.cc:42
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33
double PerformLinearFit(double Charge[10])
EtaPhiHists hFailLinearEtaPhi
Abstract Class of shape.
Definition: Shape.h:16