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