CMS 3D CMS Logo

RecAnalyzerMinbias.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalCalibAlgos
4 // Class: RecAnalyzerMinbias
5 //
13 //
14 // Original Author: Sunanda Banerjee
15 // Created: Thu Mar 4 18:52:02 CST 2012
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <string>
22 #include <iostream>
23 #include <fstream>
24 #include <sstream>
25 #include <vector>
26 #include <map>
27 
28 // user include files
56 
58 
59 #include "TH1D.h"
60 #include "TH2D.h"
61 #include "TMath.h"
62 #include "TProfile.h"
63 #include "TTree.h"
64 
65 //#define EDM_ML_DEBUG
66 
67 // class declaration
68 class RecAnalyzerMinbias : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
69 public:
70  explicit RecAnalyzerMinbias(const edm::ParameterSet&);
71  ~RecAnalyzerMinbias() override;
72 
73  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
74 
75 private:
76  void analyze(edm::Event const&, edm::EventSetup const&) override;
77  void beginJob() override;
78  void endJob() override;
79  void beginRun(edm::Run const&, edm::EventSetup const&) override;
80  void endRun(edm::Run const&, edm::EventSetup const&) override {}
81 
82 private:
83  void analyzeHcal(const HBHERecHitCollection&, const HFRecHitCollection&, int, bool, double);
84 
85  // ----------member data ---------------------------
92  std::map<DetId, double> corrFactor_;
93  std::vector<unsigned int> hcalID_;
94  TTree *myTree_, *myTree1_;
95  TH1D* h_[4];
96  TH2D *hbhe_, *hb_, *he_, *hf_;
100  TProfile *hbherun_, *hbrun_, *herun_, *hfrun_;
101  std::vector<TH1D*> histo_;
102  std::map<HcalDetId, TH1D*> histHC_;
103  std::vector<int> trigbit_;
104  double rnnum_;
105  struct myInfo {
107  myInfo() { theMB0 = theMB1 = theMB2 = theMB3 = theMB4 = runcheck = 0; }
108  };
109  // Root tree members
110  double rnnumber;
114  std::map<std::pair<int, HcalDetId>, myInfo> myMap_;
125 };
126 
127 // constructors and destructor
129  usesResource("TFileService");
130 
131  // get name of output file with histogramms
132  runNZS_ = iConfig.getParameter<bool>("runNZS");
133  Noise_ = iConfig.getParameter<bool>("noise");
134  eLowHB_ = iConfig.getParameter<double>("eLowHB");
135  eHighHB_ = iConfig.getParameter<double>("eHighHB");
136  eLowHE_ = iConfig.getParameter<double>("eLowHE");
137  eHighHE_ = iConfig.getParameter<double>("eHighHE");
138  eLowHF_ = iConfig.getParameter<double>("eLowHF");
139  eHighHF_ = iConfig.getParameter<double>("eHighHF");
140  eMin_ = iConfig.getUntrackedParameter<double>("eMin", 2.0);
141  // The following run range is suited to study 2017 commissioning period
142  runMin_ = iConfig.getUntrackedParameter<int>("RunMin", 308327);
143  runMax_ = iConfig.getUntrackedParameter<int>("RunMax", 315250);
144  trigbit_ = iConfig.getUntrackedParameter<std::vector<int>>("triggerBits");
145  ignoreL1_ = iConfig.getUntrackedParameter<bool>("ignoreL1", false);
146  std::string cfile = iConfig.getUntrackedParameter<std::string>("corrFile");
147  fillHist_ = iConfig.getUntrackedParameter<bool>("fillHisto", false);
148  extraHist_ = iConfig.getUntrackedParameter<bool>("extraHisto", false);
149  std::vector<int> ieta = iConfig.getUntrackedParameter<std::vector<int>>("hcalIeta");
150  std::vector<int> iphi = iConfig.getUntrackedParameter<std::vector<int>>("hcalIphi");
151  std::vector<int> depth = iConfig.getUntrackedParameter<std::vector<int>>("hcalDepth");
152 
153  // get token names of modules, producing object collections
154  tok_hbherecoMB_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInputMB"));
155  tok_hfrecoMB_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInputMB"));
156  tok_hltL1GtMap_ = consumes<L1GlobalTriggerObjectMapRecord>(edm::InputTag("hltL1GtObjectMap"));
157  tok_ew_ = consumes<GenEventInfoProduct>(edm::InputTag("generator"));
158  tok_hbhedigi_ = consumes<HBHEDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalDigiCollectionTag"));
159  tok_qie11digi_ = consumes<QIE11DigiCollection>(iConfig.getParameter<edm::InputTag>("hcalDigiCollectionTag"));
160  tok_hodigi_ = consumes<HODigiCollection>(iConfig.getParameter<edm::InputTag>("hcalDigiCollectionTag"));
161  tok_hfdigi_ = consumes<HFDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalDigiCollectionTag"));
162  tok_qie10digi_ = consumes<QIE10DigiCollection>(iConfig.getParameter<edm::InputTag>("hcalDigiCollectionTag"));
163  tok_gtRec_ = consumes<L1GlobalTriggerReadoutRecord>(edm::InputTag("gtDigisAlCaMB"));
164 
165  // Read correction factors
166  std::ifstream infile(cfile.c_str());
167  if (!infile.is_open()) {
168  theRecalib_ = false;
169  edm::LogWarning("RecAnalyzer") << "Cannot open '" << cfile << "' for the correction file";
170  } else {
171  unsigned int ndets(0), nrec(0);
172  while (true) {
173  unsigned int id;
174  double cfac;
175  infile >> id >> cfac;
176  if (!infile.good())
177  break;
178  HcalDetId detId(id);
179  nrec++;
180  std::map<DetId, double>::iterator itr = corrFactor_.find(detId);
181  if (itr == corrFactor_.end()) {
182  corrFactor_[detId] = cfac;
183  ndets++;
184  }
185  }
186  infile.close();
187  edm::LogInfo("RecAnalyzer") << "Reads " << nrec << " correction factors for " << ndets << " detIds";
188  theRecalib_ = (ndets > 0);
189  }
190 
191  edm::LogInfo("RecAnalyzer") << " Flags (ReCalib): " << theRecalib_ << " (IgnoreL1): " << ignoreL1_ << " (NZS) "
192  << runNZS_ << " and with " << ieta.size() << " detId for full histogram";
193  edm::LogInfo("RecAnalyzer") << "Thresholds for HB " << eLowHB_ << ":" << eHighHB_ << " for HE " << eLowHE_ << ":"
194  << eHighHE_ << " for HF " << eLowHF_ << ":" << eHighHF_;
195  for (unsigned int k = 0; k < ieta.size(); ++k) {
196  HcalSubdetector subd =
197  ((std::abs(ieta[k]) > 29) ? HcalForward
198  : (std::abs(ieta[k]) > 16) ? HcalEndcap
199  : ((std::abs(ieta[k]) == 16) && (depth[k] == 3))
200  ? HcalEndcap
201  : (depth[k] == 4) ? HcalOuter : HcalBarrel);
202  unsigned int id = (HcalDetId(subd, ieta[k], iphi[k], depth[k])).rawId();
203  hcalID_.push_back(id);
204  edm::LogInfo("RecAnalyzer") << "DetId[" << k << "] " << HcalDetId(id);
205  }
206  edm::LogInfo("RecAnalyzer") << "Select on " << trigbit_.size() << " L1 Trigger selection";
207  for (unsigned int k = 0; k < trigbit_.size(); ++k)
208  edm::LogInfo("RecAnalyzer") << "Bit[" << k << "] " << trigbit_[k];
209 }
210 
212 
214  std::vector<int> iarray;
216  desc.add<bool>("runNZS", true);
217  desc.add<bool>("noise", false);
218  desc.add<double>("eLowHB", 4);
219  desc.add<double>("eHighHB", 100);
220  desc.add<double>("eLowHE", 4);
221  desc.add<double>("eHighHE", 150);
222  desc.add<double>("eLowHF", 10);
223  desc.add<double>("eHighHF", 150);
224  // Suitable cutoff to remove fluctuation of pedestal
225  desc.addUntracked<double>("eMin", 2.0);
226  // The following run range is suited to study 2017 commissioning period
227  desc.addUntracked<int>("runMin", 308327);
228  desc.addUntracked<int>("runMax", 308347);
229  desc.addUntracked<std::vector<int>>("triggerBits", iarray);
230  desc.addUntracked<bool>("ignoreL1", false);
231  desc.addUntracked<std::string>("corrFile", "CorFactor.txt");
232  desc.addUntracked<bool>("fillHisto", false);
233  desc.addUntracked<bool>("extraHisto", false);
234  desc.addUntracked<std::vector<int>>("hcalIeta", iarray);
235  desc.addUntracked<std::vector<int>>("hcalIphi", iarray);
236  desc.addUntracked<std::vector<int>>("hcalDepth", iarray);
237  desc.add<edm::InputTag>("hbheInputMB", edm::InputTag("hbherecoMB"));
238  desc.add<edm::InputTag>("hfInputMB", edm::InputTag("hfrecoMB"));
239  desc.add<edm::InputTag>("gtDigisAlCaMB", edm::InputTag("gtDigisAlCaMB"));
240  desc.add<edm::InputTag>("hcalDigiCollectionTag", edm::InputTag("hcalDigis"));
241  descriptions.add("recAnalyzerMinbias", desc);
242 }
243 
245  std::string hc[5] = {"Empty", "HB", "HE", "HO", "HF"};
246  char name[700], title[700];
247  hbhe_ = fs_->make<TH2D>("hbhe", "Noise in HB/HE", 61, -30.5, 30.5, 72, 0.5, 72.5);
248  hb_ = fs_->make<TH2D>("hb", "Noise in HB", 61, -16.5, 16.5, 72, 0.5, 72.5);
249  he_ = fs_->make<TH2D>("he", "Noise in HE", 61, -30.5, 30.5, 72, 0.5, 72.5);
250  hf_ = fs_->make<TH2D>("hf", "Noise in HF", 82, -41.5, 41.5, 72, 0.5, 72.5);
251  int nbin = (runMax_ - runMin_ + 1);
252  sprintf(title, "Fraction of channels in HB/HE with E > %4.1f GeV vs Run number", eMin_);
253  hbherun_ = fs_->make<TProfile>("hbherun", title, nbin, runMin_ - 0.5, runMax_ + 0.5, 0.0, 1.0);
254  sprintf(title, "Fraction of channels in HB with E > %4.1f GeV vs Run number", eMin_);
255  hbrun_ = fs_->make<TProfile>("hbrun", title, nbin, runMin_ - 0.5, runMax_ + 0.5, 0.0, 1.0);
256  sprintf(title, "Fraction of channels in HE with E > %4.1f GeV vs Run number", eMin_);
257  herun_ = fs_->make<TProfile>("herun", title, nbin, runMin_ - 0.5, runMax_ + 0.5, 0.0, 1.0);
258  sprintf(title, "Fraction of channels in HF with E > %4.1f GeV vs Run number", eMin_);
259  hfrun_ = fs_->make<TProfile>("hfrun", title, nbin, runMin_ - 0.5, runMax_ + 0.5, 0.0, 1.0);
260  for (int idet = 1; idet <= 4; idet++) {
261  sprintf(name, "%s", hc[idet].c_str());
262  sprintf(title, "Noise distribution for %s", hc[idet].c_str());
263  h_[idet - 1] = fs_->make<TH1D>(name, title, 48, -6., 6.);
264  }
265 
266  for (const auto& hcalid : hcalID_) {
267  HcalDetId id = HcalDetId(hcalid);
268  int subdet = id.subdetId();
269  sprintf(name, "%s%d_%d_%d", hc[subdet].c_str(), id.ieta(), id.iphi(), id.depth());
270  sprintf(title,
271  "Energy Distribution for %s ieta %d iphi %d depth %d",
272  hc[subdet].c_str(),
273  id.ieta(),
274  id.iphi(),
275  id.depth());
276  double xmin = (subdet == 4) ? -10 : -1;
277  double xmax = (subdet == 4) ? 90 : 9;
278  TH1D* hh = fs_->make<TH1D>(name, title, 50, xmin, xmax);
279  histo_.push_back(hh);
280  };
281 
282  if (extraHist_) {
283  h_AmplitudeHBtest_ = fs_->make<TH1D>("h_AmplitudeHBtest", "", 5000, 0., 5000.);
284  h_AmplitudeHEtest_ = fs_->make<TH1D>("h_AmplitudeHEtest", "", 3000, 0., 3000.);
285  h_AmplitudeHFtest_ = fs_->make<TH1D>("h_AmplitudeHFtest", "", 10000, 0., 10000.);
286  h_AmplitudeHB_ = fs_->make<TH1D>("h_AmplitudeHB", "", 100000, 0., 100000.);
287  h_AmplitudeHE_ = fs_->make<TH1D>("h_AmplitudeHE", "", 300000, 0., 300000.);
288  h_AmplitudeHF_ = fs_->make<TH1D>("h_AmplitudeHF", "", 100000, 0., 1000000.);
289  }
290 
291  if (!fillHist_) {
292  myTree_ = fs_->make<TTree>("RecJet", "RecJet Tree");
293  myTree_->Branch("cells", &cells, "cells/I");
294  myTree_->Branch("mysubd", &mysubd, "mysubd/I");
295  myTree_->Branch("depth", &depth, "depth/I");
296  myTree_->Branch("ieta", &ieta, "ieta/I");
297  myTree_->Branch("iphi", &iphi, "iphi/I");
298  myTree_->Branch("mom0_MB", &mom0_MB, "mom0_MB/F");
299  myTree_->Branch("mom1_MB", &mom1_MB, "mom1_MB/F");
300  myTree_->Branch("mom2_MB", &mom2_MB, "mom2_MB/F");
301  myTree_->Branch("mom3_MB", &mom3_MB, "mom3_MB/F");
302  myTree_->Branch("mom4_MB", &mom4_MB, "mom4_MB/F");
303  myTree_->Branch("trigbit", &trigbit, "trigbit/I");
304  myTree_->Branch("rnnumber", &rnnumber, "rnnumber/D");
305  }
306  myTree1_ = fs_->make<TTree>("RecJet1", "RecJet1 Tree");
307  myTree1_->Branch("rnnum_", &rnnum_, "rnnum_/D");
308  myTree1_->Branch("HBHEsize", &HBHEsize, "HBHEsize/I");
309  myTree1_->Branch("HFsize", &HFsize, "HFsize/I");
310 
311  myMap_.clear();
312 }
313 
314 // EndJob
315 //
317  if (!fillHist_) {
318  cells = 0;
319  for (const auto& itr : myMap_) {
320  edm::LogVerbatim("RecAnalyzer") << "Fired trigger bit number " << itr.first.first;
321  myInfo info = itr.second;
322  if (info.theMB0 > 0) {
323  mom0_MB = info.theMB0;
324  mom1_MB = info.theMB1;
325  mom2_MB = info.theMB2;
326  mom3_MB = info.theMB3;
327  mom4_MB = info.theMB4;
328  rnnumber = info.runcheck;
329  trigbit = itr.first.first;
330  mysubd = itr.first.second.subdet();
331  depth = itr.first.second.depth();
332  iphi = itr.first.second.iphi();
333  ieta = itr.first.second.ieta();
334  edm::LogVerbatim("RecAnalyzer") << " Result= " << trigbit << " " << mysubd << " " << ieta << " " << iphi
335  << " mom0 " << mom0_MB << " mom1 " << mom1_MB << " mom2 " << mom2_MB
336  << " mom3 " << mom3_MB << " mom4 " << mom4_MB;
337  myTree_->Fill();
338  cells++;
339  }
340  }
341  edm::LogVerbatim("RecAnalyzer") << "cells"
342  << " " << cells;
343  }
344 #ifdef EDM_ML_DEBUG
345  edm::LogVerbatim("RecAnalyzer") << "Exiting from RecAnalyzerMinbias::endjob";
346 #endif
347 }
348 
350  if (!init_) {
351  init_ = true;
352  if (fillHist_) {
354  iS.get<IdealGeometryRecord>().get(htopo);
355  if (htopo.isValid()) {
356  const HcalTopology* hcaltopology = htopo.product();
357 
358  char name[700], title[700];
359  // For HB
360  int maxDepthHB = hcaltopology->maxDepthHB();
361  int nbinHB = (Noise_) ? 18 : int(2000 * eHighHB_);
362  double x_min = (Noise_) ? -3. : 0.;
363  double x_max = (Noise_) ? 3. : 2. * eHighHB_;
364  for (int eta = -50; eta < 50; eta++) {
365  for (int phi = 0; phi < 100; phi++) {
366  for (int depth = 1; depth <= maxDepthHB; depth++) {
367  HcalDetId cell(HcalBarrel, eta, phi, depth);
368  if (hcaltopology->valid(cell)) {
369  sprintf(name, "HBeta%dphi%ddep%d", eta, phi, depth);
370  sprintf(title, "HB #eta %d #phi %d depth %d", eta, phi, depth);
371  TH1D* h = fs_->make<TH1D>(name, title, nbinHB, x_min, x_max);
372  histHC_[cell] = h;
373  }
374  }
375  }
376  }
377  // For HE
378  int maxDepthHE = hcaltopology->maxDepthHE();
379  int nbinHE = (Noise_) ? 18 : int(2000 * eHighHE_);
380  x_min = (Noise_) ? -3. : 0.;
381  x_max = (Noise_) ? 3. : 2. * eHighHE_;
382  for (int eta = -50; eta < 50; eta++) {
383  for (int phi = 0; phi < 100; phi++) {
384  for (int depth = 1; depth <= maxDepthHE; depth++) {
385  HcalDetId cell(HcalEndcap, eta, phi, depth);
386  if (hcaltopology->valid(cell)) {
387  sprintf(name, "HEeta%dphi%ddep%d", eta, phi, depth);
388  sprintf(title, "HE #eta %d #phi %d depth %d", eta, phi, depth);
389  TH1D* h = fs_->make<TH1D>(name, title, nbinHE, x_min, x_max);
390  histHC_[cell] = h;
391  }
392  }
393  }
394  }
395  // For HF
396  int maxDepthHF = 4;
397  int nbinHF = (Noise_) ? 200 : int(2000 * eHighHF_);
398  x_min = (Noise_) ? -10. : 0.;
399  x_max = (Noise_) ? 10. : 2. * eHighHF_;
400  for (int eta = -50; eta < 50; eta++) {
401  for (int phi = 0; phi < 100; phi++) {
402  for (int depth = 1; depth <= maxDepthHF; depth++) {
403  HcalDetId cell(HcalForward, eta, phi, depth);
404  if (hcaltopology->valid(cell)) {
405  sprintf(name, "HFeta%dphi%ddep%d", eta, phi, depth);
406  sprintf(title, "Energy (HF #eta %d #phi %d depth %d)", eta, phi, depth);
407  TH1D* h = fs_->make<TH1D>(name, title, nbinHF, x_min, x_max);
408  histHC_[cell] = h;
409  }
410  }
411  }
412  }
413  }
414  }
415  }
416 }
417 
418 //
419 // member functions
420 //
421 // ------------ method called to produce the data ------------
422 
424  rnnum_ = (double)iEvent.run();
425 
426  if (extraHist_) {
427  double amplitudefullHB(0), amplitudefullHE(0), amplitudefullHF(0);
429  iEvent.getByToken(tok_hbhedigi_, hbhedigi);
430  if (hbhedigi.isValid()) {
431  for (auto const& digi : *(hbhedigi.product())) {
432  int nTS = digi.size();
433  double amplitudefullTSs = 0.;
434  if (digi.id().subdet() == HcalBarrel) {
435  if (nTS <= 10) {
436  for (int i = 0; i < nTS; i++)
437  amplitudefullTSs += digi.sample(i).adc();
438  h_AmplitudeHBtest_->Fill(amplitudefullTSs);
439  amplitudefullHB += amplitudefullTSs;
440  }
441  }
442  if (digi.id().subdet() == HcalEndcap) {
443  if (nTS <= 10) {
444  for (int i = 0; i < nTS; i++)
445  amplitudefullTSs += digi.sample(i).adc();
446  h_AmplitudeHEtest_->Fill(amplitudefullTSs);
447  amplitudefullHE += amplitudefullTSs;
448  }
449  }
450  }
451  }
452 
454  iEvent.getByToken(tok_qie11digi_, qie11digi);
455  if (qie11digi.isValid()) {
456  for (QIE11DataFrame const& digi : *(qie11digi.product())) {
457  double amplitudefullTSs = 0.;
458  if (HcalDetId(digi.id()).subdet() == HcalBarrel) {
459  for (int i = 0; i < digi.samples(); i++)
460  amplitudefullTSs += digi[i].adc();
461  h_AmplitudeHBtest_->Fill(amplitudefullTSs);
462  amplitudefullHB += amplitudefullTSs;
463  }
464  if (HcalDetId(digi.id()).subdet() == HcalEndcap) {
465  for (int i = 0; i < digi.samples(); i++)
466  amplitudefullTSs += digi[i].adc();
467  h_AmplitudeHEtest_->Fill(amplitudefullTSs);
468  amplitudefullHE += amplitudefullTSs;
469  }
470  }
471  }
472 
474  iEvent.getByToken(tok_hfdigi_, hfdigi);
475  if (hfdigi.isValid()) {
476  for (auto const& digi : *(hfdigi.product())) {
477  int nTS = digi.size();
478  double amplitudefullTSs = 0.;
479  if (digi.id().subdet() == HcalForward) {
480  if (nTS <= 10) {
481  for (int i = 0; i < nTS; i++)
482  amplitudefullTSs += digi.sample(i).adc();
483  h_AmplitudeHFtest_->Fill(amplitudefullTSs);
484  amplitudefullHF += amplitudefullTSs;
485  }
486  }
487  }
488  }
489 
491  iEvent.getByToken(tok_qie10digi_, qie10digi);
492  if (qie10digi.isValid()) {
493  for (QIE10DataFrame const& digi : *(qie10digi.product())) {
494  double amplitudefullTSs = 0.;
495  if (HcalDetId(digi.id()).subdet() == HcalForward) {
496  for (int i = 0; i < digi.samples(); i++)
497  amplitudefullTSs += digi[i].adc();
498  h_AmplitudeHFtest_->Fill(amplitudefullTSs);
499  amplitudefullHF += amplitudefullTSs;
500  }
501  }
502  }
503 
504  h_AmplitudeHB_->Fill(amplitudefullHB);
505  h_AmplitudeHE_->Fill(amplitudefullHE);
506  h_AmplitudeHF_->Fill(amplitudefullHF);
507  }
508 
510  iEvent.getByToken(tok_hbherecoMB_, hbheMB);
511  if (!hbheMB.isValid()) {
512  edm::LogWarning("RecAnalyzer") << "HcalCalibAlgos: Error! can't get hbhe product!";
513  return;
514  }
515  const HBHERecHitCollection HithbheMB = *(hbheMB.product());
516  HBHEsize = HithbheMB.size();
517  edm::LogVerbatim("RecAnalyzer") << "HBHE MB size of collection " << HithbheMB.size();
518  if (HithbheMB.size() < 5100 && runNZS_) {
519  edm::LogWarning("RecAnalyzer") << "HBHE problem " << rnnum_ << " size " << HBHEsize;
520  }
521 
523  iEvent.getByToken(tok_hfrecoMB_, hfMB);
524  if (!hfMB.isValid()) {
525  edm::LogWarning("RecAnalyzer") << "HcalCalibAlgos: Error! can't get hf product!";
526  return;
527  }
528  const HFRecHitCollection HithfMB = *(hfMB.product());
529  edm::LogVerbatim("RecAnalyzer") << "HF MB size of collection " << HithfMB.size();
530  HFsize = HithfMB.size();
531  if (HithfMB.size() < 1700 && runNZS_) {
532  edm::LogWarning("RecAnalyzer") << "HF problem " << rnnum_ << " size " << HFsize;
533  }
534 
535  bool select(false);
536  if (!trigbit_.empty()) {
538  iEvent.getByToken(tok_hltL1GtMap_, gtObjectMapRecord);
539  if (gtObjectMapRecord.isValid()) {
540  const std::vector<L1GlobalTriggerObjectMap>& objMapVec = gtObjectMapRecord->gtObjectMap();
541  for (std::vector<L1GlobalTriggerObjectMap>::const_iterator itMap = objMapVec.begin(); itMap != objMapVec.end();
542  ++itMap) {
543  bool resultGt = (*itMap).algoGtlResult();
544  if (resultGt) {
545  int algoBit = (*itMap).algoBitNumber();
546  if (std::find(trigbit_.begin(), trigbit_.end(), algoBit) != trigbit_.end()) {
547  select = true;
548  break;
549  }
550  }
551  }
552  }
553  }
554 
555  if (!trigbit_.empty() || select)
556  myTree1_->Fill();
557 
558  //event weight for FLAT sample and PU information
559  double eventWeight = 1.0;
561  iEvent.getByToken(tok_ew_, genEventInfo);
562  if (genEventInfo.isValid())
563  eventWeight = genEventInfo->weight();
564 #ifdef EDM_ML_DEBUG
565  edm::LogVerbatim("RecAnalyzer") << "Test HB " << HBHEsize << " HF " << HFsize << " Trigger " << trigbit_.size() << ":"
566  << select << ":" << ignoreL1_ << " Wt " << eventWeight;
567 #endif
568  if (ignoreL1_ || (!trigbit_.empty() && select)) {
569  analyzeHcal(HithbheMB, HithfMB, 1, true, eventWeight);
570  } else if ((!ignoreL1_) && (trigbit_.empty())) {
572  iEvent.getByToken(tok_hltL1GtMap_, gtObjectMapRecord);
573  if (gtObjectMapRecord.isValid()) {
574  const std::vector<L1GlobalTriggerObjectMap>& objMapVec = gtObjectMapRecord->gtObjectMap();
575  bool ok(false);
576  for (std::vector<L1GlobalTriggerObjectMap>::const_iterator itMap = objMapVec.begin(); itMap != objMapVec.end();
577  ++itMap) {
578  bool resultGt = (*itMap).algoGtlResult();
579  if (resultGt) {
580  int algoBit = (*itMap).algoBitNumber();
581  analyzeHcal(HithbheMB, HithfMB, algoBit, (!ok), eventWeight);
582  ok = true;
583  }
584  }
585  if (!ok) {
586  edm::LogInfo("RecAnalyzer") << "No passed L1 Trigger found";
587  }
588  }
589  }
590 }
591 
593  const HBHERecHitCollection& HithbheMB, const HFRecHitCollection& HithfMB, int algoBit, bool fill, double weight) {
594  // Signal part for HB HE
595  int count(0), countHB(0), countHE(0), count2(0), count2HB(0), count2HE(0);
596  for (HBHERecHitCollection::const_iterator hbheItr = HithbheMB.begin(); hbheItr != HithbheMB.end(); hbheItr++) {
597  // Recalibration of energy
598  DetId mydetid = hbheItr->id().rawId();
599  double icalconst(1.);
600  if (theRecalib_) {
601  std::map<DetId, double>::iterator itr = corrFactor_.find(mydetid);
602  if (itr != corrFactor_.end())
603  icalconst = itr->second;
604  }
605  HBHERecHit aHit(hbheItr->id(), hbheItr->energy() * icalconst, hbheItr->time());
606  double energyhit = aHit.energy();
607  DetId id = (*hbheItr).detid();
608  HcalDetId hid = HcalDetId(id);
609  double eLow = (hid.subdet() == HcalEndcap) ? eLowHE_ : eLowHB_;
610  double eHigh = (hid.subdet() == HcalEndcap) ? eHighHE_ : eHighHB_;
611  ++count;
612  if (id.subdetId() == HcalBarrel)
613  ++countHB;
614  else
615  ++countHE;
616  if (fill) {
617  for (unsigned int i = 0; i < hcalID_.size(); i++) {
618  if (hcalID_[i] == id.rawId()) {
619  histo_[i]->Fill(energyhit);
620  break;
621  }
622  }
623  if (fillHist_) {
624  std::map<HcalDetId, TH1D*>::iterator itr1 = histHC_.find(hid);
625  if (itr1 != histHC_.end())
626  itr1->second->Fill(energyhit);
627  }
628  h_[hid.subdet() - 1]->Fill(energyhit);
629  if (energyhit > eMin_) {
630  hbhe_->Fill(hid.ieta(), hid.iphi());
631  ++count2;
632  if (id.subdetId() == HcalBarrel) {
633  ++count2HB;
634  hb_->Fill(hid.ieta(), hid.iphi());
635  } else {
636  ++count2HE;
637  he_->Fill(hid.ieta(), hid.iphi());
638  }
639  }
640  }
641  if (!fillHist_) {
642  if (Noise_ || runNZS_ || (energyhit >= eLow && energyhit <= eHigh)) {
643  std::map<std::pair<int, HcalDetId>, myInfo>::iterator itr1 =
644  myMap_.find(std::pair<int, HcalDetId>(algoBit, hid));
645  if (itr1 == myMap_.end()) {
646  myInfo info;
647  myMap_[std::pair<int, HcalDetId>(algoBit, hid)] = info;
648  itr1 = myMap_.find(std::pair<int, HcalDetId>(algoBit, hid));
649  }
650  itr1->second.theMB0 += weight;
651  itr1->second.theMB1 += (weight * energyhit);
652  itr1->second.theMB2 += (weight * energyhit * energyhit);
653  itr1->second.theMB3 += (weight * energyhit * energyhit * energyhit);
654  itr1->second.theMB4 += (weight * energyhit * energyhit * energyhit * energyhit);
655  itr1->second.runcheck = rnnum_;
656  }
657  }
658  } // HBHE_MB
659  if (fill) {
660  if (count > 0)
661  hbherun_->Fill(rnnum_, (double)(count2) / count);
662  if (countHB > 0)
663  hbrun_->Fill(rnnum_, (double)(count2HB) / countHB);
664  if (countHE > 0)
665  herun_->Fill(rnnum_, (double)(count2HE) / countHE);
666  }
667 #ifdef EDM_ML_DEBUG
668  edm::LogVerbatim("RecAnalyzer") << "HBHE " << count2 << ":" << count << ":" << (double)(count2) / count << "\t HB "
669  << count2HB << ":" << countHB << ":" << (double)(count2HB) / countHB << "\t HE "
670  << count2HE << ":" << countHE << ":" << (double)(count2HE) / countHE;
671 #endif
672  int countHF(0), count2HF(0);
673  // Signal part for HF
674  for (HFRecHitCollection::const_iterator hfItr = HithfMB.begin(); hfItr != HithfMB.end(); hfItr++) {
675  // Recalibration of energy
676  DetId mydetid = hfItr->id().rawId();
677  double icalconst(1.);
678  if (theRecalib_) {
679  std::map<DetId, double>::iterator itr = corrFactor_.find(mydetid);
680  if (itr != corrFactor_.end())
681  icalconst = itr->second;
682  }
683  HFRecHit aHit(hfItr->id(), hfItr->energy() * icalconst, hfItr->time());
684 
685  double energyhit = aHit.energy();
686  DetId id = (*hfItr).detid();
687  HcalDetId hid = HcalDetId(id);
688  ++countHF;
689  if (fill) {
690  for (unsigned int i = 0; i < hcalID_.size(); i++) {
691  if (hcalID_[i] == id.rawId()) {
692  histo_[i]->Fill(energyhit);
693  break;
694  }
695  }
696  if (fillHist_) {
697  std::map<HcalDetId, TH1D*>::iterator itr1 = histHC_.find(hid);
698  if (itr1 != histHC_.end())
699  itr1->second->Fill(energyhit);
700  }
701  h_[hid.subdet() - 1]->Fill(energyhit);
702  if (energyhit > eMin_) {
703  hf_->Fill(hid.ieta(), hid.iphi());
704  ++count2HF;
705  }
706  }
707 
708  //
709  // Remove PMT hits
710  //
711  if (!fillHist_) {
712  if (((Noise_ || runNZS_) && fabs(energyhit) <= 40.) || (energyhit >= eLowHF_ && energyhit <= eHighHF_)) {
713  std::map<std::pair<int, HcalDetId>, myInfo>::iterator itr1 =
714  myMap_.find(std::pair<int, HcalDetId>(algoBit, hid));
715  if (itr1 == myMap_.end()) {
716  myInfo info;
717  myMap_[std::pair<int, HcalDetId>(algoBit, hid)] = info;
718  itr1 = myMap_.find(std::pair<int, HcalDetId>(algoBit, hid));
719  }
720  itr1->second.theMB0 += weight;
721  itr1->second.theMB1 += (weight * energyhit);
722  itr1->second.theMB2 += (weight * energyhit * energyhit);
723  itr1->second.theMB3 += (weight * energyhit * energyhit * energyhit);
724  itr1->second.theMB4 += (weight * energyhit * energyhit * energyhit * energyhit);
725  itr1->second.runcheck = rnnum_;
726  }
727  }
728  }
729  if (fill && countHF > 0)
730  hfrun_->Fill(rnnum_, (double)(count2HF) / countHF);
731 #ifdef EDM_ML_DEBUG
732  if (count)
733  edm::LogVerbatim("RecAnalyzer") << "HF " << count2HF << ":" << countHF << ":" << (double)(count2HF) / countHF;
734 #endif
735 }
736 
737 //define this as a plug-in
constexpr float energy() const
Definition: CaloRecHit.h:31
void endJob() override
T getParameter(std::string const &) const
RecAnalyzerMinbias(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< int > trigbit_
static const TGPicture * info(bool iBackgroundIsBlack)
edm::EDGetTokenT< HFDigiCollection > tok_hfdigi_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:146
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool valid(const DetId &id) const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
int maxDepthHE() const
Definition: HcalTopology.h:146
edm::EDGetTokenT< GenEventInfoProduct > tok_ew_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< T >::const_iterator const_iterator
Definition: weight.py:1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< QIE11DigiCollection > tok_qie11digi_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void beginJob() override
double weight() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::map< HcalDetId, TH1D * > histHC_
const std::vector< L1GlobalTriggerObjectMap > & gtObjectMap() const
get / set the vector of object maps
std::vector< TH1D * > histo_
edm::EDGetTokenT< QIE10DigiCollection > tok_qie10digi_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< HBHEDigiCollection > tok_hbhedigi_
int ieta() const
get the cell ieta
Definition: HcalDetId.h:159
edm::EDGetTokenT< HFRecHitCollection > tok_hfrecoMB_
RunNumber_t run() const
Definition: Event.h:101
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void analyze(edm::Event const &, edm::EventSetup const &) override
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
int k[5][pyjets_maxn]
const_iterator end() const
void analyzeHcal(const HBHERecHitCollection &, const HFRecHitCollection &, int, bool, double)
edm::EDGetTokenT< HODigiCollection > tok_hodigi_
int iphi() const
get the cell iphi
Definition: HcalDetId.h:161
Definition: DetId.h:18
void endRun(edm::Run const &, edm::EventSetup const &) override
edm::Service< TFileService > fs_
T const * product() const
Definition: Handle.h:74
std::vector< unsigned int > hcalID_
edm::EDGetTokenT< HBHERecHitCollection > tok_hbherecoMB_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::map< std::pair< int, HcalDetId >, myInfo > myMap_
int maxDepthHB() const
Definition: HcalTopology.h:145
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > tok_gtRec_
size_type size() const
T get() const
Definition: EventSetup.h:71
susybsm::HSCParticleCollection hc
Definition: classes.h:25
bool isValid() const
Definition: ESHandle.h:44
edm::EDGetTokenT< L1GlobalTriggerObjectMapRecord > tok_hltL1GtMap_
T const * product() const
Definition: ESHandle.h:86
void beginRun(edm::Run const &, edm::EventSetup const &) override
const_iterator begin() const
std::map< DetId, double > corrFactor_
Definition: Run.h:45