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