CMS 3D CMS Logo

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