CMS 3D CMS Logo

HcalHBHEMuonAnalyzer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 #include <TFile.h>
6 #include <TTree.h>
7 #include "TPRegexp.h"
8 
9 // user include files
19 
27 
29 
39 
42 
45 
49 
53 
57 
69 
70 //#define EDM_ML_DEBUG
71 
72 class HcalHBHEMuonAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
73 public:
74  explicit HcalHBHEMuonAnalyzer(const edm::ParameterSet&);
75 
76  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
77 
78 private:
79  void beginJob() override;
80  void analyze(edm::Event const&, edm::EventSetup const&) override;
81  void beginRun(edm::Run const&, edm::EventSetup const&) override;
82  void endRun(edm::Run const&, edm::EventSetup const&) override {}
83  void clearVectors();
84  int matchId(const HcalDetId&, const HcalDetId&);
85  double activeLength(const DetId&);
86  bool isGoodVertex(const reco::Vertex& vtx);
87  double respCorr(const DetId& id);
88  double gainFactor(const HcalDbService* dbserv, const HcalDetId& id);
89  int depth16HE(int ieta, int iphi);
90  bool goodCell(const HcalDetId& hcid, const reco::Track* pTrack, const CaloGeometry* geo, const MagneticField* bField);
91 
92  // ----------member data ---------------------------
97  const std::vector<std::string> triggers_;
98  const double pMinMuon_;
99  const int verbosity_, useRaw_;
103  const int maxDepth_;
105 
112 
122 
127 
129  int kount_;
130 
132  static const int depthMax_ = 7;
133  TTree* tree_;
135  unsigned int goodVertex_;
167  std::vector<std::string> all_triggers_;
168  std::vector<int> hltresults_;
169 
170  std::vector<HcalDDDRecConstants::HcalActiveLength> actHB, actHE;
171  std::map<DetId, double> corrValue_;
173 };
174 
176  : hlTriggerResults_(iConfig.getParameter<edm::InputTag>("hlTriggerResults")),
177  labelEBRecHit_(iConfig.getParameter<edm::InputTag>("labelEBRecHit")),
178  labelEERecHit_(iConfig.getParameter<edm::InputTag>("labelEERecHit")),
179  labelHBHERecHit_(iConfig.getParameter<edm::InputTag>("labelHBHERecHit")),
180  labelVtx_(iConfig.getParameter<std::string>("labelVertex")),
181  labelMuon_(iConfig.getParameter<std::string>("labelMuon")),
182  fileInCorr_(iConfig.getUntrackedParameter<std::string>("fileInCorr", "")),
183  triggers_(iConfig.getParameter<std::vector<std::string>>("triggers")),
184  pMinMuon_(iConfig.getParameter<double>("pMinMuon")),
185  verbosity_(iConfig.getUntrackedParameter<int>("verbosity", 0)),
186  useRaw_(iConfig.getParameter<int>("useRaw")),
187  unCorrect_(iConfig.getParameter<bool>("unCorrect")),
188  collapseDepth_(iConfig.getParameter<bool>("collapseDepth")),
189  isItPlan1_(iConfig.getParameter<bool>("isItPlan1")),
190  ignoreHECorr_(iConfig.getUntrackedParameter<bool>("ignoreHECorr", false)),
191  isItPreRecHit_(iConfig.getUntrackedParameter<bool>("isItPreRecHit", false)),
192  getCharge_(iConfig.getParameter<bool>("getCharge")),
193  writeRespCorr_(iConfig.getUntrackedParameter<bool>("writeRespCorr", false)),
194  maxDepth_(iConfig.getUntrackedParameter<int>("maxDepth", 7)),
195  modnam_(iConfig.getUntrackedParameter<std::string>("moduleName", "")),
196  procnm_(iConfig.getUntrackedParameter<std::string>("processName", "")),
197  tok_trigRes_(consumes<edm::TriggerResults>(hlTriggerResults_)),
198  tok_Vtx_((modnam_.empty()) ? consumes<reco::VertexCollection>(labelVtx_)
199  : consumes<reco::VertexCollection>(edm::InputTag(modnam_, labelVtx_, procnm_))),
200  tok_EB_(consumes<EcalRecHitCollection>(labelEBRecHit_)),
201  tok_EE_(consumes<EcalRecHitCollection>(labelEERecHit_)),
202  tok_HBHE_(consumes<HBHERecHitCollection>(labelHBHERecHit_)),
203  tok_Muon_((modnam_.empty()) ? consumes<reco::MuonCollection>(labelMuon_)
204  : consumes<reco::MuonCollection>(edm::InputTag(modnam_, labelMuon_, procnm_))),
206  tok_htopo_(esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>()),
207  tok_respcorr_(esConsumes<HcalRespCorrs, HcalRespCorrsRcd, edm::Transition::BeginRun>()),
208  tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()),
213  tok_dbservice_(esConsumes<HcalDbService, HcalDbRecord>()),
214  hdc_(nullptr),
215  theHBHETopology_(nullptr),
216  respCorrs_(nullptr) {
217  usesResource(TFileService::kSharedResource);
218  //now do what ever initialization is needed
219  kount_ = 0;
221 
222  if (modnam_.empty()) {
223  edm::LogVerbatim("HBHEMuon") << "Labels used: Trig " << hlTriggerResults_ << " Vtx " << labelVtx_ << " EB "
224  << labelEBRecHit_ << " EE " << labelEERecHit_ << " HBHE " << labelHBHERecHit_ << " MU "
225  << labelMuon_;
226  } else {
227  edm::LogVerbatim("HBHEMuon") << "Labels used Trig " << hlTriggerResults_ << "\n Vtx "
229  << "\n EE " << labelEERecHit_ << "\n HBHE " << labelHBHERecHit_ << "\n MU "
231  }
232 
233  if (!fileInCorr_.empty()) {
234  std::ifstream infile(fileInCorr_.c_str());
235  if (infile.is_open()) {
236  while (true) {
237  unsigned int id;
238  double cfac;
239  infile >> id >> cfac;
240  if (!infile.good())
241  break;
242  corrValue_[DetId(id)] = cfac;
243  }
244  infile.close();
245  }
246  }
247  useMyCorr_ = (!corrValue_.empty());
248  edm::LogVerbatim("HBHEMuon") << "Flags used: UseRaw " << useRaw_ << " GetCharge " << getCharge_ << " UnCorrect "
249  << unCorrect_ << " IgnoreHECorr " << ignoreHECorr_ << " CollapseDepth " << collapseDepth_
250  << ":" << mergedDepth_ << " IsItPlan1 " << isItPlan1_ << " IsItPreRecHit "
251  << isItPreRecHit_ << " UseMyCorr " << useMyCorr_ << " pMinMuon " << pMinMuon_;
252 }
253 
254 //
255 // member functions
256 //
257 
258 // ------------ method called for each event ------------
260  ++kount_;
261  clearVectors();
262  std::vector<bool> muon_is_good, muon_global, muon_tracker;
263  std::vector<bool> muon_is_tight, muon_is_medium;
264  std::vector<double> ptGlob, etaGlob, phiGlob, energyMuon, pMuon;
265  std::vector<float> muon_trkKink, muon_chi2LocalPosition, muon_segComp;
266  std::vector<int> trackerLayer, numPixelLayers, tight_PixelHits;
267  std::vector<bool> innerTrack, outerTrack, globalTrack;
268  std::vector<double> chiTracker, dxyTracker, dzTracker;
269  std::vector<double> innerTrackpt, innerTracketa, innerTrackphi;
270  std::vector<double> tight_validFraction, outerTrackChi;
271  std::vector<double> outerTrackPt, outerTrackEta, outerTrackPhi;
272  std::vector<int> outerTrackHits, outerTrackRHits;
273  std::vector<double> globalTrckPt, globalTrckEta, globalTrckPhi;
274  std::vector<int> globalMuonHits, matchedStat;
275  std::vector<double> chiGlobal, tight_LongPara, tight_TransImpara;
276  std::vector<double> isolationR04, isolationR03;
277  std::vector<double> ecalEnergy, hcalEnergy, hoEnergy;
278  std::vector<bool> matchedId, hcalHot;
279  std::vector<double> ecal3x3Energy, hcal1x1Energy;
280  std::vector<unsigned int> ecalDetId, hcalDetId, ehcalDetId;
281  std::vector<int> hcal_ieta, hcal_iphi;
282  std::vector<double> hcalDepthEnergy[depthMax_];
283  std::vector<double> hcalDepthActiveLength[depthMax_];
284  std::vector<double> hcalDepthEnergyHot[depthMax_];
285  std::vector<double> hcalDepthActiveLengthHot[depthMax_];
286  std::vector<double> hcalDepthChargeHot[depthMax_];
287  std::vector<double> hcalDepthChargeHotBG[depthMax_];
288  std::vector<double> hcalDepthEnergyCorr[depthMax_];
289  std::vector<double> hcalDepthEnergyHotCorr[depthMax_];
290  std::vector<bool> hcalDepthMatch[depthMax_];
291  std::vector<bool> hcalDepthMatchHot[depthMax_];
292  std::vector<double> hcalActiveLength, hcalActiveLengthHot;
293  runNumber_ = iEvent.id().run();
294  eventNumber_ = iEvent.id().event();
295  lumiNumber_ = iEvent.id().luminosityBlock();
296  bxNumber_ = iEvent.bunchCrossing();
297 #ifdef EDM_ML_DEBUG
298  edm::LogVerbatim("HBHEMuon") << "Run " << runNumber_ << " Event " << eventNumber_ << " Lumi " << lumiNumber_ << " BX "
299  << bxNumber_ << std::endl;
300 #endif
301  const edm::Handle<edm::TriggerResults>& _Triggers = iEvent.getHandle(tok_trigRes_);
302 #ifdef EDM_ML_DEBUG
303  if ((verbosity_ / 10000) % 10 > 0)
304  edm::LogVerbatim("HBHEMuon") << "Size of all triggers " << all_triggers_.size();
305 #endif
306  int Ntriggers = static_cast<int>(all_triggers_.size());
307 #ifdef EDM_ML_DEBUG
308  if ((verbosity_ / 10000) % 10 > 0)
309  edm::LogVerbatim("HBHEMuon") << "Size of HLT MENU: " << _Triggers->size();
310 #endif
311  if (_Triggers.isValid()) {
312  const edm::TriggerNames& triggerNames_ = iEvent.triggerNames(*_Triggers);
313  std::vector<int> index;
314  for (int i = 0; i < Ntriggers; i++) {
315  index.push_back(triggerNames_.triggerIndex(all_triggers_[i]));
316  int triggerSize = static_cast<int>(_Triggers->size());
317 #ifdef EDM_ML_DEBUG
318  if ((verbosity_ / 10000) % 10 > 0)
319  edm::LogVerbatim("HBHEMuon") << "outside loop " << index[i] << "\ntriggerSize " << triggerSize;
320 #endif
321  if (index[i] < triggerSize) {
322  hltresults_.push_back(_Triggers->accept(index[i]));
323 #ifdef EDM_ML_DEBUG
324  if ((verbosity_ / 10000) % 10 > 0)
325  edm::LogVerbatim("HBHEMuon") << "Trigger_info " << triggerSize << " triggerSize " << index[i]
326  << " trigger_index " << hltresults_.at(i) << " hltresult";
327 #endif
328  } else {
329  if ((verbosity_ / 10000) % 10 > 0)
330  edm::LogVerbatim("HBHEMuon") << "Requested HLT path \""
331  << "\" does not exist";
332  }
333  }
334  }
335 
336  // get handles to calogeometry and calotopology
337  const MagneticField* bField = &iSetup.getData(tok_magField_);
338  const EcalChannelStatus* theEcalChStatus = &iSetup.getData(tok_chan_);
339  const EcalSeverityLevelAlgo* sevlv = &iSetup.getData(tok_sevlv_);
340  const CaloTopology* caloTopology = &iSetup.getData(tok_topo_);
342 
343  // Relevant blocks from iEvent
345 
346  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle = iEvent.getHandle(tok_EB_);
347  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle = iEvent.getHandle(tok_EE_);
348 
350 
351  const edm::Handle<reco::MuonCollection>& _Muon = iEvent.getHandle(tok_Muon_);
352 
353  // require a good vertex
354  math::XYZPoint pvx;
355  goodVertex_ = 0;
356  if (!vtx.isValid()) {
357 #ifdef EDM_ML_DEBUG
358  edm::LogVerbatim("HBHEMuon") << "No Good Vertex found == Reject";
359 #endif
360  return;
361  }
362  reco::VertexCollection::const_iterator firstGoodVertex = vtx->end();
363  for (reco::VertexCollection::const_iterator it = vtx->begin(); it != vtx->end(); it++) {
364  if (isGoodVertex(*it)) {
365  if (firstGoodVertex == vtx->end())
366  firstGoodVertex = it;
367  ++goodVertex_;
368  }
369  }
370  if (firstGoodVertex != vtx->end())
371  pvx = firstGoodVertex->position();
372 
373  bool accept(false);
374  if (_Muon.isValid() && barrelRecHitsHandle.isValid() && endcapRecHitsHandle.isValid() && hbhe.isValid()) {
375  for (const auto& RecMuon : (*(_Muon.product()))) {
376  muon_is_good.push_back(RecMuon.isPFMuon());
377  muon_global.push_back(RecMuon.isGlobalMuon());
378  muon_tracker.push_back(RecMuon.isTrackerMuon());
379  ptGlob.push_back(RecMuon.pt());
380  etaGlob.push_back(RecMuon.eta());
381  phiGlob.push_back(RecMuon.phi());
382  energyMuon.push_back(RecMuon.energy());
383  pMuon.push_back(RecMuon.p());
384 #ifdef EDM_ML_DEBUG
385  edm::LogVerbatim("HBHEMuon") << "Energy:" << RecMuon.energy() << " P:" << RecMuon.p();
386 #endif
387  muon_is_tight.push_back(muon::isTightMuon(RecMuon, *firstGoodVertex));
388  muon_is_medium.push_back(muon::isMediumMuon(RecMuon));
389  muon_trkKink.push_back(RecMuon.combinedQuality().trkKink);
390  muon_chi2LocalPosition.push_back(RecMuon.combinedQuality().chi2LocalPosition);
391  muon_segComp.push_back(muon::segmentCompatibility(RecMuon));
392  // acessing tracker hits info
393  if (RecMuon.track().isNonnull()) {
394  trackerLayer.push_back(RecMuon.track()->hitPattern().trackerLayersWithMeasurement());
395  } else {
396  trackerLayer.push_back(-1);
397  }
398  if (RecMuon.innerTrack().isNonnull()) {
399  innerTrack.push_back(true);
400  numPixelLayers.push_back(RecMuon.innerTrack()->hitPattern().pixelLayersWithMeasurement());
401  chiTracker.push_back(RecMuon.innerTrack()->normalizedChi2());
402  dxyTracker.push_back(fabs(RecMuon.innerTrack()->dxy(pvx)));
403  dzTracker.push_back(fabs(RecMuon.innerTrack()->dz(pvx)));
404  innerTrackpt.push_back(RecMuon.innerTrack()->pt());
405  innerTracketa.push_back(RecMuon.innerTrack()->eta());
406  innerTrackphi.push_back(RecMuon.innerTrack()->phi());
407  tight_PixelHits.push_back(RecMuon.innerTrack()->hitPattern().numberOfValidPixelHits());
408  tight_validFraction.push_back(RecMuon.innerTrack()->validFraction());
409  } else {
410  innerTrack.push_back(false);
411  numPixelLayers.push_back(0);
412  chiTracker.push_back(0);
413  dxyTracker.push_back(0);
414  dzTracker.push_back(0);
415  innerTrackpt.push_back(0);
416  innerTracketa.push_back(0);
417  innerTrackphi.push_back(0);
418  tight_PixelHits.push_back(0);
419  tight_validFraction.push_back(-99);
420  }
421  // outer track info
422  if (RecMuon.outerTrack().isNonnull()) {
423  outerTrack.push_back(true);
424  outerTrackPt.push_back(RecMuon.outerTrack()->pt());
425  outerTrackEta.push_back(RecMuon.outerTrack()->eta());
426  outerTrackPhi.push_back(RecMuon.outerTrack()->phi());
427  outerTrackChi.push_back(RecMuon.outerTrack()->normalizedChi2());
428  outerTrackHits.push_back(RecMuon.outerTrack()->numberOfValidHits());
429  outerTrackRHits.push_back(RecMuon.outerTrack()->recHitsSize());
430  } else {
431  outerTrack.push_back(false);
432  outerTrackPt.push_back(0);
433  outerTrackEta.push_back(0);
434  outerTrackPhi.push_back(0);
435  outerTrackChi.push_back(0);
436  outerTrackHits.push_back(0);
437  outerTrackRHits.push_back(0);
438  }
439  // Tight Muon cuts
440  if (RecMuon.globalTrack().isNonnull()) {
441  globalTrack.push_back(true);
442  chiGlobal.push_back(RecMuon.globalTrack()->normalizedChi2());
443  globalMuonHits.push_back(RecMuon.globalTrack()->hitPattern().numberOfValidMuonHits());
444  matchedStat.push_back(RecMuon.numberOfMatchedStations());
445  globalTrckPt.push_back(RecMuon.globalTrack()->pt());
446  globalTrckEta.push_back(RecMuon.globalTrack()->eta());
447  globalTrckPhi.push_back(RecMuon.globalTrack()->phi());
448  tight_TransImpara.push_back(fabs(RecMuon.muonBestTrack()->dxy(pvx)));
449  tight_LongPara.push_back(fabs(RecMuon.muonBestTrack()->dz(pvx)));
450  } else {
451  globalTrack.push_back(false);
452  chiGlobal.push_back(0);
453  globalMuonHits.push_back(0);
454  matchedStat.push_back(0);
455  globalTrckPt.push_back(0);
456  globalTrckEta.push_back(0);
457  globalTrckPhi.push_back(0);
458  tight_TransImpara.push_back(0);
459  tight_LongPara.push_back(0);
460  }
461 
462  isolationR04.push_back(
463  ((RecMuon.pfIsolationR04().sumChargedHadronPt +
464  std::max(0.,
465  RecMuon.pfIsolationR04().sumNeutralHadronEt + RecMuon.pfIsolationR04().sumPhotonEt -
466  (0.5 * RecMuon.pfIsolationR04().sumPUPt))) /
467  RecMuon.pt()));
468 
469  isolationR03.push_back(
470  ((RecMuon.pfIsolationR03().sumChargedHadronPt +
471  std::max(0.,
472  RecMuon.pfIsolationR03().sumNeutralHadronEt + RecMuon.pfIsolationR03().sumPhotonEt -
473  (0.5 * RecMuon.pfIsolationR03().sumPUPt))) /
474  RecMuon.pt()));
475 
476  ecalEnergy.push_back(RecMuon.calEnergy().emS9);
477  hcalEnergy.push_back(RecMuon.calEnergy().hadS9);
478  hoEnergy.push_back(RecMuon.calEnergy().hoS9);
479 
480  double eEcal(0), eHcal(0), activeLengthTot(0), activeLengthHotTot(0);
481  double eHcalDepth[depthMax_], eHcalDepthHot[depthMax_];
482  double eHcalDepthC[depthMax_], eHcalDepthHotC[depthMax_];
483  double cHcalDepthHot[depthMax_], cHcalDepthHotBG[depthMax_];
484  double activeL[depthMax_], activeHotL[depthMax_];
485  bool matchDepth[depthMax_], matchDepthHot[depthMax_];
486  HcalDetId eHcalDetId[depthMax_];
487  unsigned int isHot(0);
488  bool tmpmatch(false);
489  int ieta(-1000), iphi(-1000);
490  for (int i = 0; i < depthMax_; ++i) {
491  eHcalDepth[i] = eHcalDepthHot[i] = 0;
492  eHcalDepthC[i] = eHcalDepthHotC[i] = 0;
493  cHcalDepthHot[i] = cHcalDepthHotBG[i] = 0;
494  activeL[i] = activeHotL[i] = 0;
495  matchDepth[i] = matchDepthHot[i] = true;
496  }
497  if (RecMuon.innerTrack().isNonnull()) {
498  const reco::Track* pTrack = (RecMuon.innerTrack()).get();
499  spr::propagatedTrackID trackID = spr::propagateCALO(pTrack, geo_, bField, (((verbosity_ / 100) % 10 > 0)));
500  if ((RecMuon.p() > pMinMuon_) && (trackID.okHCAL))
501  accept = true;
502 
503  ecalDetId.push_back((trackID.detIdECAL)());
504  hcalDetId.push_back((trackID.detIdHCAL)());
505  ehcalDetId.push_back((trackID.detIdEHCAL)());
506 
508  std::pair<bool, HcalDetId> info = spr::propagateHCALBack(pTrack, geo_, bField, (((verbosity_ / 100) % 10 > 0)));
509  if (info.first) {
510  check = info.second;
511  }
512 
513  bool okE = trackID.okECAL;
514  if (okE) {
515  const DetId isoCell(trackID.detIdECAL);
516  std::pair<double, bool> e3x3 = spr::eECALmatrix(isoCell,
517  barrelRecHitsHandle,
518  endcapRecHitsHandle,
519  *theEcalChStatus,
520  geo_,
521  caloTopology,
522  sevlv,
523  1,
524  1,
525  -100.0,
526  -100.0,
527  -500.0,
528  500.0,
529  false);
530  eEcal = e3x3.first;
531  okE = e3x3.second;
532  }
533 #ifdef EDM_ML_DEBUG
534  edm::LogVerbatim("HBHEMuon") << "Propagate Track to ECAL: " << okE << ":" << trackID.okECAL << " E " << eEcal;
535 #endif
536 
537  if (trackID.okHCAL) {
538  DetId closestCell(trackID.detIdHCAL);
539  HcalDetId hcidt(closestCell.rawId());
540  if ((hcidt.ieta() == check.ieta()) && (hcidt.iphi() == check.iphi()))
541  tmpmatch = true;
542 #ifdef EDM_ML_DEBUG
543  edm::LogVerbatim("HBHEMuon") << "Front " << hcidt << " Back " << info.first << ":" << check << " Match "
544  << tmpmatch;
545 #endif
546 
547  HcalSubdetector subdet = hcidt.subdet();
548  ieta = hcidt.ieta();
549  iphi = hcidt.iphi();
550  bool hborhe = (std::abs(ieta) == 16);
551 
553  closestCell,
554  hbhe,
555  0,
556  0,
557  false,
558  true,
559  -100.0,
560  -100.0,
561  -100.0,
562  -100.0,
563  -500.,
564  500.,
565  useRaw_);
566  std::vector<std::pair<double, int>> ehdepth;
567  spr::energyHCALCell((HcalDetId)closestCell,
568  hbhe,
569  ehdepth,
570  maxDepth_,
571  -100.0,
572  -100.0,
573  -100.0,
574  -100.0,
575  -500.0,
576  500.0,
577  useRaw_,
578  depth16HE(ieta, iphi),
579  (((verbosity_ / 1000) % 10) > 0));
580  for (int i = 0; i < depthMax_; ++i)
581  eHcalDetId[i] = HcalDetId();
582  for (unsigned int i = 0; i < ehdepth.size(); ++i) {
583  HcalSubdetector subdet0 =
584  (hborhe) ? ((ehdepth[i].second >= depth16HE(ieta, iphi)) ? HcalEndcap : HcalBarrel) : subdet;
585  HcalDetId hcid0(subdet0, ieta, iphi, ehdepth[i].second);
586  double actL = activeLength(DetId(hcid0));
587  double ene = ehdepth[i].first;
588  bool tmpC(false);
589  if (ene > 0.0) {
590  if (!(theHBHETopology_->validHcal(hcid0))) {
591  edm::LogWarning("HBHEMuon") << "(1) Invalid ID " << hcid0 << " with E = " << ene;
592  edm::LogWarning("HBHEMuon") << HcalDetId(closestCell) << " with " << ehdepth.size() << " depths:";
593  for (const auto& ehd : ehdepth)
594  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":" << ehd.first;
595  } else {
596  tmpC = goodCell(hcid0, pTrack, geo_, bField);
597  double enec(ene);
598  if (unCorrect_) {
599  double corr = (ignoreHECorr_ && (subdet0 == HcalEndcap)) ? 1.0 : respCorr(DetId(hcid0));
600  if (corr != 0)
601  ene /= corr;
602 #ifdef EDM_ML_DEBUG
603  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc_->mergedDepthDetId(hcid0) : hcid0;
604  edm::LogVerbatim("HBHEMuon") << hcid0 << ":" << id << " Corr " << corr;
605 #endif
606  }
607  int depth = ehdepth[i].second - 1;
608  if (collapseDepth_) {
609  HcalDetId id = hdc_->mergedDepthDetId(hcid0);
610  depth = id.depth() - 1;
611  }
612  eHcalDepth[depth] += ene;
613  eHcalDepthC[depth] += enec;
614  activeL[depth] += actL;
615  activeLengthTot += actL;
616  matchDepth[depth] = (matchDepth[depth] && tmpC);
617 #ifdef EDM_ML_DEBUG
618  if ((verbosity_ % 10) > 0)
619  edm::LogVerbatim("HBHEMuon")
620  << hcid0 << " E " << ene << ":" << enec << " L " << actL << " Match " << tmpC;
621 #endif
622  }
623  }
624  }
625 #ifdef EDM_ML_DEBUG
626  if ((verbosity_ % 10) > 0) {
627  edm::LogVerbatim("HBHEMuon") << hcidt << " Match " << tmpmatch << " Depths " << ehdepth.size();
628  for (unsigned int k = 0; k < ehdepth.size(); ++k)
629  edm::LogVerbatim("HBHEMuon") << " [" << k << ":" << ehdepth[k].second << "] " << matchDepth[k];
630  }
631 #endif
632  HcalDetId hotCell;
633  spr::eHCALmatrix(geo_, theHBHETopology_, closestCell, hbhe, 1, 1, hotCell, false, useRaw_, false);
634  isHot = matchId(closestCell, hotCell);
635  if (hotCell != HcalDetId()) {
636  subdet = HcalDetId(hotCell).subdet();
637  ieta = HcalDetId(hotCell).ieta();
638  iphi = HcalDetId(hotCell).iphi();
639  hborhe = (std::abs(ieta) == 16);
640  std::vector<std::pair<double, int>> ehdepth;
641  spr::energyHCALCell(hotCell,
642  hbhe,
643  ehdepth,
644  maxDepth_,
645  -100.0,
646  -100.0,
647  -100.0,
648  -100.0,
649  -500.0,
650  500.0,
651  useRaw_,
652  depth16HE(ieta, iphi),
653  false); //(((verbosity_/1000)%10)>0 ));
654  for (int i = 0; i < depthMax_; ++i)
655  eHcalDetId[i] = HcalDetId();
656  for (unsigned int i = 0; i < ehdepth.size(); ++i) {
657  HcalSubdetector subdet0 =
658  (hborhe) ? ((ehdepth[i].second >= depth16HE(ieta, iphi)) ? HcalEndcap : HcalBarrel) : subdet;
659  HcalDetId hcid0(subdet0, ieta, iphi, ehdepth[i].second);
660  double actL = activeLength(DetId(hcid0));
661  double ene = ehdepth[i].first;
662  bool tmpC(false);
663  if (ene > 0.0) {
664  if (!(theHBHETopology_->validHcal(hcid0))) {
665  edm::LogWarning("HBHEMuon") << "(2) Invalid ID " << hcid0 << " with E = " << ene;
666  edm::LogWarning("HBHEMuon") << HcalDetId(hotCell) << " with " << ehdepth.size() << " depths:";
667  for (const auto& ehd : ehdepth)
668  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":" << ehd.first;
669  } else {
670  tmpC = goodCell(hcid0, pTrack, geo_, bField);
671  double chg(ene), enec(ene);
672  if (unCorrect_) {
673  double corr = (ignoreHECorr_ && (subdet0 == HcalEndcap)) ? 1.0 : respCorr(DetId(hcid0));
674  if (corr != 0)
675  ene /= corr;
676 #ifdef EDM_ML_DEBUG
677  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc_->mergedDepthDetId(hcid0) : hcid0;
678  edm::LogVerbatim("HBHEMuon")
679  << hcid0 << ":" << id << " Corr " << corr << " E " << ene << ":" << enec;
680 #endif
681  }
682  if (getCharge_) {
683  double gain = gainFactor(conditions, hcid0);
684  if (gain != 0)
685  chg /= gain;
686 #ifdef EDM_ML_DEBUG
687  edm::LogVerbatim("HBHEMuon") << hcid0 << " Gain " << gain << " C " << chg;
688 #endif
689  }
690  int depth = ehdepth[i].second - 1;
691  if (collapseDepth_) {
692  HcalDetId id = hdc_->mergedDepthDetId(hcid0);
693  depth = id.depth() - 1;
694  }
695  eHcalDepthHot[depth] += ene;
696  eHcalDepthHotC[depth] += enec;
697  cHcalDepthHot[depth] += chg;
698  activeHotL[depth] += actL;
699  activeLengthHotTot += actL;
700  matchDepthHot[depth] = (matchDepthHot[depth] && tmpC);
701 #ifdef EDM_ML_DEBUG
702  if ((verbosity_ % 10) > 0)
703  edm::LogVerbatim("HBHEMuon") << hcid0 << " depth " << depth << " E " << ene << ":" << enec << " C "
704  << chg << " L " << actL << " Match " << tmpC;
705 #endif
706  }
707  }
708  }
709 
710  HcalDetId oppCell(subdet, -ieta, iphi, HcalDetId(hotCell).depth());
711  std::vector<std::pair<double, int>> ehdeptho;
712  spr::energyHCALCell(oppCell,
713  hbhe,
714  ehdeptho,
715  maxDepth_,
716  -100.0,
717  -100.0,
718  -100.0,
719  -100.0,
720  -500.0,
721  500.0,
722  useRaw_,
723  depth16HE(-ieta, iphi),
724  false); //(((verbosity_/1000)%10)>0));
725  for (unsigned int i = 0; i < ehdeptho.size(); ++i) {
726  HcalSubdetector subdet0 =
727  (hborhe) ? ((ehdeptho[i].second >= depth16HE(-ieta, iphi)) ? HcalEndcap : HcalBarrel) : subdet;
728  HcalDetId hcid0(subdet0, -ieta, iphi, ehdeptho[i].second);
729  double ene = ehdeptho[i].first;
730  if (ene > 0.0) {
731  if (!(theHBHETopology_->validHcal(hcid0))) {
732  edm::LogWarning("HBHEMuon") << "(3) Invalid ID " << hcid0 << " with E = " << ene;
733  edm::LogWarning("HBHEMuon") << oppCell << " with " << ehdeptho.size() << " depths:";
734  for (const auto& ehd : ehdeptho)
735  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":" << ehd.first;
736  } else {
737  double chg(ene);
738  if (unCorrect_) {
739  double corr = (ignoreHECorr_ && (subdet0 == HcalEndcap)) ? 1.0 : respCorr(DetId(hcid0));
740  if (corr != 0)
741  ene /= corr;
742 #ifdef EDM_ML_DEBUG
743  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc_->mergedDepthDetId(hcid0) : hcid0;
744  edm::LogVerbatim("HBHEMuon")
745  << hcid0 << ":" << id << " Corr " << corr << " E " << ene << ":" << ehdeptho[i].first;
746 #endif
747  }
748  if (getCharge_) {
749  double gain = gainFactor(conditions, hcid0);
750  if (gain != 0)
751  chg /= gain;
752 #ifdef EDM_ML_DEBUG
753  edm::LogVerbatim("HBHEMuon") << hcid0 << " Gain " << gain << " C " << chg;
754 #endif
755  }
756  int depth = ehdeptho[i].second - 1;
757  if (collapseDepth_) {
758  HcalDetId id = hdc_->mergedDepthDetId(hcid0);
759  depth = id.depth() - 1;
760  }
761  cHcalDepthHotBG[depth] += chg;
762 #ifdef EDM_ML_DEBUG
763  if ((verbosity_ % 10) > 0)
764  edm::LogVerbatim("HBHEMuon") << hcid0 << " Depth " << depth << " E " << ene << " C " << chg;
765 #endif
766  }
767  }
768  }
769  }
770  }
771 #ifdef EDM_ML_DEBUG
772  edm::LogVerbatim("HBHEMuon") << "Propagate Track to HCAL: " << trackID.okHCAL << " Match " << tmpmatch
773  << " Hot " << isHot << " Energy " << eHcal << std::endl;
774 #endif
775 
776  } else {
777  ecalDetId.push_back(0);
778  hcalDetId.push_back(0);
779  ehcalDetId.push_back(0);
780  }
781 
782  matchedId.push_back(tmpmatch);
783  ecal3x3Energy.push_back(eEcal);
784  hcal1x1Energy.push_back(eHcal);
785  hcal_ieta.push_back(ieta);
786  hcal_iphi.push_back(iphi);
787  for (int i = 0; i < depthMax_; ++i) {
788  hcalDepthEnergy[i].push_back(eHcalDepth[i]);
789  hcalDepthActiveLength[i].push_back(activeL[i]);
790  hcalDepthEnergyHot[i].push_back(eHcalDepthHot[i]);
791  hcalDepthActiveLengthHot[i].push_back(activeHotL[i]);
792  hcalDepthEnergyCorr[i].push_back(eHcalDepthC[i]);
793  hcalDepthEnergyHotCorr[i].push_back(eHcalDepthHotC[i]);
794  hcalDepthChargeHot[i].push_back(cHcalDepthHot[i]);
795  hcalDepthChargeHotBG[i].push_back(cHcalDepthHotBG[i]);
796  hcalDepthMatch[i].push_back(matchDepth[i]);
797  hcalDepthMatchHot[i].push_back(matchDepthHot[i]);
798  }
799  hcalActiveLength.push_back(activeLengthTot);
800  hcalHot.push_back(isHot);
801  hcalActiveLengthHot.push_back(activeLengthHotTot);
802  }
803  }
804  if (accept) {
805 #ifdef EDM_ML_DEBUG
806  for (unsigned int i = 0; i < hcal_ieta.size(); ++i)
807  edm::LogVerbatim("HBHEMuon") << "[" << i << "] ieta/iphi for entry to "
808  << "HCAL has value of " << hcal_ieta[i] << ":" << hcal_iphi[i];
809 #endif
810  for (unsigned int k = 0; k < muon_is_good.size(); ++k) {
811  muon_is_good_ = muon_is_good[k];
812  muon_global_ = muon_global[k];
813  muon_tracker_ = muon_tracker[k];
814  muon_is_tight_ = muon_is_tight[k];
815  muon_is_medium_ = muon_is_medium[k];
816  ptGlob_ = ptGlob[k];
817  etaGlob_ = etaGlob[k];
818  phiGlob_ = phiGlob[k];
819  energyMuon_ = energyMuon[k];
820  pMuon_ = pMuon[k];
821  muon_trkKink_ = muon_trkKink[k];
822  muon_chi2LocalPosition_ = muon_chi2LocalPosition[k];
823  muon_segComp_ = muon_segComp[k];
824  trackerLayer_ = trackerLayer[k];
825  numPixelLayers_ = numPixelLayers[k];
826  tight_PixelHits_ = tight_PixelHits[k];
828  outerTrack_ = outerTrack[k];
830  chiTracker_ = chiTracker[k];
831  dxyTracker_ = dxyTracker[k];
832  dzTracker_ = dzTracker[k];
833  innerTrackpt_ = innerTrackpt[k];
834  innerTracketa_ = innerTracketa[k];
835  innerTrackphi_ = innerTrackphi[k];
836  tight_validFraction_ = tight_validFraction[k];
837  outerTrackChi_ = outerTrackChi[k];
838  outerTrackPt_ = outerTrackPt[k];
839  outerTrackEta_ = outerTrackEta[k];
840  outerTrackPhi_ = outerTrackPhi[k];
841  outerTrackHits_ = outerTrackHits[k];
842  outerTrackRHits_ = outerTrackRHits[k];
843  globalTrckPt_ = globalTrckPt[k];
844  globalTrckEta_ = globalTrckEta[k];
845  globalTrckPhi_ = globalTrckPhi[k];
846  globalMuonHits_ = globalMuonHits[k];
847  matchedStat_ = matchedStat[k];
848  chiGlobal_ = chiGlobal[k];
849  tight_LongPara_ = tight_LongPara[k];
850  tight_TransImpara_ = tight_TransImpara[k];
853  ecalEnergy_ = ecalEnergy[k];
854  hcalEnergy_ = hcalEnergy[k];
855  hoEnergy_ = hoEnergy[k];
856  matchedId_ = matchedId[k];
857  hcalHot_ = hcalHot[k];
858  ecal3x3Energy_ = ecal3x3Energy[k];
859  hcal1x1Energy_ = hcal1x1Energy[k];
860  ecalDetId_ = ecalDetId[k];
861  hcalDetId_ = hcalDetId[k];
862  ehcalDetId_ = ehcalDetId[k];
863  hcal_ieta_ = hcal_ieta[k];
864  hcal_iphi_ = hcal_iphi[k];
865  for (int i = 0; i < depthMax_; ++i) {
866  hcalDepthEnergy_[i] = hcalDepthEnergy[i][k];
867  hcalDepthActiveLength_[i] = hcalDepthActiveLength[i][k];
868  hcalDepthEnergyHot_[i] = hcalDepthEnergyHot[i][k];
869  hcalDepthActiveLengthHot_[i] = hcalDepthActiveLengthHot[i][k];
870  hcalDepthChargeHot_[i] = hcalDepthChargeHot[i][k];
871  hcalDepthChargeHotBG_[i] = hcalDepthChargeHotBG[i][k];
872  hcalDepthEnergyCorr_[i] = hcalDepthEnergyCorr[i][k];
873  hcalDepthEnergyHotCorr_[i] = hcalDepthEnergyHotCorr[i][k];
874  hcalDepthMatch_[i] = hcalDepthMatch[i][k];
875  hcalDepthMatchHot_[i] = hcalDepthMatchHot[i][k];
876  }
877  hcalActiveLength_ = hcalActiveLength[k];
878  hcalActiveLengthHot_ = hcalActiveLengthHot[k];
879  tree_->Fill();
880  }
881  }
882 }
883 
884 // ------------ method called once each job just before starting event loop ------------
887  tree_ = fs->make<TTree>("TREE", "TREE");
888  tree_->Branch("Event_No", &eventNumber_);
889  tree_->Branch("Run_No", &runNumber_);
890  tree_->Branch("LumiNumber", &lumiNumber_);
891  tree_->Branch("BXNumber", &bxNumber_);
892  tree_->Branch("GoodVertex", &goodVertex_);
893  tree_->Branch("PF_Muon", &muon_is_good_);
894  tree_->Branch("Global_Muon", &muon_global_);
895  tree_->Branch("Tracker_muon", &muon_tracker_);
896  tree_->Branch("MuonIsTight", &muon_is_tight_);
897  tree_->Branch("MuonIsMedium", &muon_is_medium_);
898  tree_->Branch("pt_of_muon", &ptGlob_);
899  tree_->Branch("eta_of_muon", &etaGlob_);
900  tree_->Branch("phi_of_muon", &phiGlob_);
901  tree_->Branch("energy_of_muon", &energyMuon_);
902  tree_->Branch("p_of_muon", &pMuon_);
903  tree_->Branch("muon_trkKink", &muon_trkKink_);
904  tree_->Branch("muon_chi2LocalPosition", &muon_chi2LocalPosition_);
905  tree_->Branch("muon_segComp", &muon_segComp_);
906 
907  tree_->Branch("TrackerLayer", &trackerLayer_);
908  tree_->Branch("NumPixelLayers", &numPixelLayers_);
909  tree_->Branch("InnerTrackPixelHits", &tight_PixelHits_);
910  tree_->Branch("innerTrack", &innerTrack_);
911  tree_->Branch("chiTracker", &chiTracker_);
912  tree_->Branch("DxyTracker", &dxyTracker_);
913  tree_->Branch("DzTracker", &dzTracker_);
914  tree_->Branch("innerTrackpt", &innerTrackpt_);
915  tree_->Branch("innerTracketa", &innerTracketa_);
916  tree_->Branch("innerTrackphi", &innerTrackphi_);
917  tree_->Branch("tight_validFraction", &tight_validFraction_);
918 
919  tree_->Branch("OuterTrack", &outerTrack_);
920  tree_->Branch("OuterTrackChi", &outerTrackChi_);
921  tree_->Branch("OuterTrackPt", &outerTrackPt_);
922  tree_->Branch("OuterTrackEta", &outerTrackEta_);
923  tree_->Branch("OuterTrackPhi", &outerTrackPhi_);
924  tree_->Branch("OuterTrackHits", &outerTrackHits_);
925  tree_->Branch("OuterTrackRHits", &outerTrackRHits_);
926 
927  tree_->Branch("GlobalTrack", &globalTrack_);
928  tree_->Branch("GlobalTrckPt", &globalTrckPt_);
929  tree_->Branch("GlobalTrckEta", &globalTrckEta_);
930  tree_->Branch("GlobalTrckPhi", &globalTrckPhi_);
931  tree_->Branch("Global_Muon_Hits", &globalMuonHits_);
932  tree_->Branch("MatchedStations", &matchedStat_);
933  tree_->Branch("GlobTrack_Chi", &chiGlobal_);
934  tree_->Branch("Tight_LongitudinalImpactparameter", &tight_LongPara_);
935  tree_->Branch("Tight_TransImpactparameter", &tight_TransImpara_);
936 
937  tree_->Branch("IsolationR04", &isolationR04_);
938  tree_->Branch("IsolationR03", &isolationR03_);
939  tree_->Branch("ecal_3into3", &ecalEnergy_);
940  tree_->Branch("hcal_3into3", &hcalEnergy_);
941  tree_->Branch("tracker_3into3", &hoEnergy_);
942 
943  tree_->Branch("matchedId", &matchedId_);
944  tree_->Branch("hcal_cellHot", &hcalHot_);
945 
946  tree_->Branch("ecal_3x3", &ecal3x3Energy_);
947  tree_->Branch("hcal_1x1", &hcal1x1Energy_);
948  tree_->Branch("ecal_detID", &ecalDetId_);
949  tree_->Branch("hcal_detID", &hcalDetId_);
950  tree_->Branch("ehcal_detID", &ehcalDetId_);
951  tree_->Branch("hcal_ieta", &hcal_ieta_);
952  tree_->Branch("hcal_iphi", &hcal_iphi_);
953 
954  char name[100];
955  for (int k = 0; k < maxDepth_; ++k) {
956  sprintf(name, "hcal_edepth%d", (k + 1));
957  tree_->Branch(name, &hcalDepthEnergy_[k]);
958  sprintf(name, "hcal_activeL%d", (k + 1));
959  tree_->Branch(name, &hcalDepthActiveLength_[k]);
960  sprintf(name, "hcal_edepthHot%d", (k + 1));
961  tree_->Branch(name, &hcalDepthEnergyHot_[k]);
962  sprintf(name, "hcal_activeHotL%d", (k + 1));
964  sprintf(name, "hcal_cdepthHot%d", (k + 1));
965  tree_->Branch(name, &hcalDepthChargeHot_[k]);
966  sprintf(name, "hcal_cdepthHotBG%d", (k + 1));
967  tree_->Branch(name, &hcalDepthChargeHotBG_[k]);
968  sprintf(name, "hcal_edepthCorrect%d", (k + 1));
969  tree_->Branch(name, &hcalDepthEnergyCorr_[k]);
970  sprintf(name, "hcal_edepthHotCorrect%d", (k + 1));
971  tree_->Branch(name, &hcalDepthEnergyHotCorr_[k]);
972  sprintf(name, "hcal_depthMatch%d", (k + 1));
973  tree_->Branch(name, &hcalDepthMatch_[k]);
974  sprintf(name, "hcal_depthMatchHot%d", (k + 1));
975  tree_->Branch(name, &hcalDepthMatchHot_[k]);
976  }
977 
978  tree_->Branch("activeLength", &hcalActiveLength_);
979  tree_->Branch("activeLengthHot", &hcalActiveLengthHot_);
980 
981  tree_->Branch("hltresults", &hltresults_);
982  tree_->Branch("all_triggers", &all_triggers_);
983 }
984 
985 // ------------ method called when starting to processes a run ------------
986 void HcalHBHEMuonAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
987  hdc_ = &iSetup.getData(tok_ddrec_);
988  actHB.clear();
989  actHE.clear();
990  actHB = hdc_->getThickActive(0);
991  actHE = hdc_->getThickActive(1);
992 #ifdef EDM_ML_DEBUG
993  unsigned int k1(0), k2(0);
994  edm::LogVerbatim("HBHEMuon") << actHB.size() << " Active Length for HB";
995  for (const auto& act : actHB) {
996  edm::LogVerbatim("HBHEMuon") << "[" << k1 << "] ieta " << act.ieta << " depth " << act.depth << " zside "
997  << act.zside << " type " << act.stype << " phi " << act.iphis.size() << ":"
998  << act.iphis[0] << " L " << act.thick;
999  HcalDetId hcid1(HcalBarrel, (act.ieta) * (act.zside), act.iphis[0], act.depth);
1000  HcalDetId hcid2 = mergedDepth_ ? hdc_->mergedDepthDetId(hcid1) : hcid1;
1001  edm::LogVerbatim("HBHEMuon") << hcid1 << " | " << hcid2 << " L " << activeLength(DetId(hcid2));
1002  ++k1;
1003  }
1004  edm::LogVerbatim("HBHEMuon") << actHE.size() << " Active Length for HE";
1005  for (const auto& act : actHE) {
1006  edm::LogVerbatim("HBHEMuon") << "[" << k2 << "] ieta " << act.ieta << " depth " << act.depth << " zside "
1007  << act.zside << " type " << act.stype << " phi " << act.iphis.size() << ":"
1008  << act.iphis[0] << " L " << act.thick;
1009  HcalDetId hcid1(HcalEndcap, (act.ieta) * (act.zside), act.iphis[0], act.depth);
1010  HcalDetId hcid2 = mergedDepth_ ? hdc_->mergedDepthDetId(hcid1) : hcid1;
1011  edm::LogVerbatim("HBHEMuon") << hcid1 << " | " << hcid2 << " L " << activeLength(DetId(hcid2));
1012  ++k2;
1013  }
1014 #endif
1015 
1016  bool changed = true;
1017  all_triggers_.clear();
1018  if (hltConfig_.init(iRun, iSetup, "HLT", changed)) {
1019  // if init returns TRUE, initialisation has succeeded!
1020 #ifdef EDM_ML_DEBUG
1021  edm::LogVerbatim("HBHEMuon") << "HLT config with process name HLT successfully extracted";
1022 #endif
1023  unsigned int ntriggers = hltConfig_.size();
1024  for (unsigned int t = 0; t < ntriggers; ++t) {
1025  std::string hltname(hltConfig_.triggerName(t));
1026  for (unsigned int ik = 0; ik < triggers_.size(); ++ik) {
1027  if (hltname.find(triggers_[ik]) != std::string::npos) {
1028  all_triggers_.push_back(hltname);
1029  break;
1030  }
1031  }
1032  } //loop over ntriggers
1033  edm::LogVerbatim("HBHEMuon") << "All triggers size in begin run " << all_triggers_.size();
1034  } else {
1035  edm::LogError("HBHEMuon") << "Error! HLT config extraction with process name HLT failed";
1036  }
1037 
1038  theHBHETopology_ = &iSetup.getData(tok_htopo_);
1039  const HcalRespCorrs* resp = &iSetup.getData(tok_respcorr_);
1040  respCorrs_ = new HcalRespCorrs(*resp);
1042  geo_ = &iSetup.getData(tok_geom_);
1043 
1044  // Write correction factors for all HB/HE events
1045  if (writeRespCorr_) {
1046  const HcalGeometry* gHcal = static_cast<const HcalGeometry*>(geo_->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
1047  const std::vector<DetId>& ids = gHcal->getValidDetIds(DetId::Hcal, 0);
1048  edm::LogVerbatim("HBHEMuon") << "\nTable of Correction Factors for Run " << iRun.run() << "\n";
1049  for (auto const& id : ids) {
1050  if ((id.det() == DetId::Hcal) && ((id.subdetId() == HcalBarrel) || (id.subdetId() == HcalEndcap))) {
1051  edm::LogVerbatim("HBHEMuon") << HcalDetId(id) << " " << id.rawId() << " "
1052  << (respCorrs_->getValues(id))->getValue();
1053  }
1054  }
1055  }
1056 }
1057 
1058 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
1061  desc.add<edm::InputTag>("hlTriggerResults", edm::InputTag("TriggerResults", "", "HLT"));
1062  desc.add<edm::InputTag>("labelEBRecHit", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
1063  desc.add<edm::InputTag>("labelEERecHit", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
1064  desc.add<edm::InputTag>("labelHBHERecHit", edm::InputTag("hbhereco"));
1065  desc.add<std::string>("labelVertex", "offlinePrimaryVertices");
1066  desc.add<std::string>("labelMuon", "muons");
1067  std::vector<std::string> trig = {"HLT_IsoMu17", "HLT_IsoMu20", "HLT_IsoMu24", "HLT_IsoMu27", "HLT_Mu45", "HLT_Mu50"};
1068  desc.add<std::vector<std::string>>("triggers", trig);
1069  desc.add<double>("pMinMuon", 10.0);
1070  desc.addUntracked<int>("verbosity", 0);
1071  desc.add<int>("useRaw", 0);
1072  desc.add<bool>("unCorrect", true);
1073  desc.add<bool>("getCharge", true);
1074  desc.add<bool>("collapseDepth", false);
1075  desc.add<bool>("isItPlan1", false);
1076  desc.addUntracked<bool>("ignoreHECorr", false);
1077  desc.addUntracked<bool>("isItPreRecHit", false);
1078  desc.addUntracked<std::string>("moduleName", "");
1079  desc.addUntracked<std::string>("processName", "");
1080  desc.addUntracked<int>("maxDepth", 7);
1081  desc.addUntracked<std::string>("fileInCorr", "");
1082  desc.addUntracked<bool>("writeRespCorr", false);
1083  descriptions.add("hcalHBHEMuon", desc);
1084 }
1085 
1088  eventNumber_ = -99999;
1089  runNumber_ = -99999;
1090  lumiNumber_ = -99999;
1091  bxNumber_ = -99999;
1092  goodVertex_ = -99999;
1093 
1094  muon_is_good_ = false;
1095  muon_global_ = false;
1096  muon_tracker_ = false;
1097  ptGlob_ = 0;
1098  etaGlob_ = 0;
1099  phiGlob_ = 0;
1100  energyMuon_ = 0;
1101  pMuon_ = 0;
1102  muon_trkKink_ = 0;
1104  muon_segComp_ = 0;
1105  muon_is_tight_ = false;
1106  muon_is_medium_ = false;
1107 
1108  trackerLayer_ = 0;
1109  numPixelLayers_ = 0;
1110  tight_PixelHits_ = 0;
1111  innerTrack_ = false;
1112  chiTracker_ = 0;
1113  dxyTracker_ = 0;
1114  dzTracker_ = 0;
1115  innerTrackpt_ = 0;
1116  innerTracketa_ = 0;
1117  innerTrackphi_ = 0;
1119 
1120  outerTrack_ = false;
1121  outerTrackPt_ = 0;
1122  outerTrackEta_ = 0;
1123  outerTrackPhi_ = 0;
1124  outerTrackHits_ = 0;
1125  outerTrackRHits_ = 0;
1126  outerTrackChi_ = 0;
1127 
1128  globalTrack_ = false;
1129  globalTrckPt_ = 0;
1130  globalTrckEta_ = 0;
1131  globalTrckPhi_ = 0;
1132  globalMuonHits_ = 0;
1133  matchedStat_ = 0;
1134  chiGlobal_ = 0;
1135  tight_LongPara_ = 0;
1136  tight_TransImpara_ = 0;
1137 
1138  isolationR04_ = 0;
1139  isolationR03_ = 0;
1140  ecalEnergy_ = 0;
1141  hcalEnergy_ = 0;
1142  hoEnergy_ = 0;
1143  matchedId_ = false;
1144  hcalHot_ = false;
1145  ecal3x3Energy_ = 0;
1146  hcal1x1Energy_ = 0;
1147  ecalDetId_ = 0;
1148  hcalDetId_ = 0;
1149  ehcalDetId_ = 0;
1150  hcal_ieta_ = 0;
1151  hcal_iphi_ = 0;
1152  for (int i = 0; i < maxDepth_; ++i) {
1153  hcalDepthEnergy_[i] = 0;
1155  hcalDepthEnergyHot_[i] = 0;
1157  hcalDepthChargeHot_[i] = 0;
1158  hcalDepthChargeHotBG_[i] = 0;
1159  hcalDepthEnergyCorr_[i] = 0;
1161  hcalDepthMatch_[i] = false;
1162  hcalDepthMatchHot_[i] = false;
1163  }
1164  hcalActiveLength_ = 0;
1166  hltresults_.clear();
1167 }
1168 
1170  HcalDetId kd1(id1.subdet(), id1.ieta(), id1.iphi(), 1);
1171  HcalDetId kd2(id1.subdet(), id2.ieta(), id2.iphi(), 1);
1172  int match = ((kd1 == kd2) ? 1 : 0);
1173  return match;
1174 }
1175 
1177  HcalDetId id(id_);
1178  int ieta = id.ietaAbs();
1179  int zside = id.zside();
1180  int iphi = id.iphi();
1181  std::vector<int> dpths;
1182  if (mergedDepth_) {
1183  std::vector<HcalDetId> ids;
1184  hdc_->unmergeDepthDetId(id, ids);
1185  for (auto idh : ids)
1186  dpths.emplace_back(idh.depth());
1187  } else {
1188  dpths.emplace_back(id.depth());
1189  }
1190  double lx(0);
1191  if (id.subdet() == HcalBarrel) {
1192  for (unsigned int i = 0; i < actHB.size(); ++i) {
1193  if ((ieta == actHB[i].ieta) && (zside == actHB[i].zside) &&
1194  (std::find(dpths.begin(), dpths.end(), actHB[i].depth) != dpths.end()) &&
1195  (std::find(actHB[i].iphis.begin(), actHB[i].iphis.end(), iphi) != actHB[i].iphis.end())) {
1196  lx += actHB[i].thick;
1197  }
1198  }
1199  } else {
1200  for (unsigned int i = 0; i < actHE.size(); ++i) {
1201  if ((ieta == actHE[i].ieta) && (zside == actHE[i].zside) &&
1202  (std::find(dpths.begin(), dpths.end(), actHE[i].depth) != dpths.end()) &&
1203  (std::find(actHE[i].iphis.begin(), actHE[i].iphis.end(), iphi) != actHE[i].iphis.end())) {
1204  lx += actHE[i].thick;
1205  }
1206  }
1207  }
1208  return lx;
1209 }
1210 
1212  if (vtx.isFake())
1213  return false;
1214  if (vtx.ndof() < 4)
1215  return false;
1216  if (vtx.position().Rho() > 2.)
1217  return false;
1218  if (fabs(vtx.position().Z()) > 24.)
1219  return false;
1220  return true;
1221 }
1222 
1224  double cfac(1.0);
1225  if (useMyCorr_) {
1226  auto itr = corrValue_.find(id);
1227  if (itr != corrValue_.end())
1228  cfac = itr->second;
1229  } else if (respCorrs_ != nullptr) {
1230  cfac = (respCorrs_->getValues(id))->getValue();
1231  }
1232  return cfac;
1233 }
1234 
1236  double gain(0.0);
1237  const HcalCalibrations& calibs = conditions->getHcalCalibrations(id);
1238  for (int capid = 0; capid < 4; ++capid)
1239  gain += (0.25 * calibs.respcorrgain(capid));
1240  return gain;
1241 }
1242 
1244  // Transition between HB/HE is special
1245  // For Run 1 or for Plan1 standard reconstruction it is 3
1246  // For runs beyond 2018 or in Plan1 for HEP17 it is 4
1247  int zside = (ieta > 0) ? 1 : -1;
1249  if (isItPlan1_ && (!isItPreRecHit_))
1250  depth = 3;
1251 #ifdef EDM_ML_DEBUG
1252  edm::LogVerbatim("HBHEMuon") << "Plan1 " << isItPlan1_ << " PreRecHit " << isItPreRecHit_ << " phi " << iphi
1253  << " depth " << depth;
1254 #endif
1255  return depth;
1256 }
1257 
1259  const reco::Track* pTrack,
1260  const CaloGeometry* geo,
1261  const MagneticField* bField) {
1262  std::pair<double, double> rz = hdc_->getRZ(hcid);
1263  bool typeRZ = (hcid.subdet() == HcalEndcap) ? false : true;
1264  bool match = spr::propagateHCAL(pTrack, geo, bField, typeRZ, rz, (((verbosity_ / 10000) % 10) > 0));
1265  return match;
1266 }
1267 
1268 //define this as a plug-in
1270 
double gainFactor(const HcalDbService *dbserv, const HcalDetId &id)
int getMinDepth(const int &itype, const int &ieta, const int &iphi, const int &zside) const
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< int > hltresults_
bool accept() const
Has at least one path accepted the event?
Log< level::Info, true > LogVerbatim
const std::string & triggerName(unsigned int triggerIndex) const
HcalHBHEMuonAnalyzer(const edm::ParameterSet &)
const std::string labelMuon_
double getRZ(const int &subdet, const int &ieta, const int &depth) const
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, const std::string &theTrackQuality, bool debug=false)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const HcalTopology * theHBHETopology_
double hcalDepthEnergyHot_[depthMax_]
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< std::string > all_triggers_
const edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcd > tok_respcorr_
const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const override
Get a list of valid detector ids (for the given subdetector)
Definition: HcalGeometry.cc:76
void analyze(edm::Event const &, edm::EventSetup const &) override
HcalDetId mergedDepthDetId(const HcalDetId &id) const
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
const float chg[109]
Definition: CoreSimTrack.cc:5
std::pair< math::XYZPoint, bool > propagateHCAL(const reco::Track *, const MagneticField *, bool debug=false)
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > tok_htopo_
const edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
T const * product() const
Definition: Handle.h:70
const edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > tok_sevlv_
double respCorr(const DetId &id)
double hcalDepthChargeHot_[depthMax_]
int zside(DetId const &)
std::vector< HcalDDDRecConstants::HcalActiveLength > actHE
const edm::InputTag hlTriggerResults_
const edm::ESGetToken< CaloTopology, CaloTopologyRecord > tok_topo_
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
double hcalDepthActiveLengthHot_[depthMax_]
double hcalDepthEnergyCorr_[depthMax_]
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const Item * getValues(DetId fId, bool throwOnFail=true) const
const edm::InputTag labelEERecHit_
unsigned int triggerIndex(std::string_view name) const
Definition: TriggerNames.cc:52
double hcalDepthActiveLength_[depthMax_]
U second(std::pair< T, U > const &p)
const edm::InputTag labelEBRecHit_
const edm::ESGetToken< HcalDbService, HcalDbRecord > tok_dbservice_
void beginRun(edm::Run const &, edm::EventSetup const &) override
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
double hcalDepthEnergyHotCorr_[depthMax_]
bool hcalDepthMatchHot_[depthMax_]
unsigned int size() const
Get number of paths stored.
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
dictionary corr
spr::propagatedTrackDirection propagateHCALBack(unsigned int thisTrk, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, const CaloGeometry *geo, const MagneticField *bField, bool debug=false)
unsigned int size() const
number of trigger paths in trigger table
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
Transition
Definition: Transition.h:12
const CaloGeometry * geo_
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const std::string labelVtx_
double activeLength(const DetId &)
bool goodCell(const HcalDetId &hcid, const reco::Track *pTrack, const CaloGeometry *geo, const MagneticField *bField)
constexpr double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
const edm::InputTag labelHBHERecHit_
double hcalDepthChargeHotBG_[depthMax_]
Definition: DetId.h:17
const edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
std::map< DetId, double > corrValue_
std::vector< HcalDDDRecConstants::HcalActiveLength > actHB
double hcalDepthEnergy_[depthMax_]
int depth16HE(int ieta, int iphi)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tok_geom_
void endRun(edm::Run const &, edm::EventSetup const &) override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool hcalDepthMatch_[depthMax_]
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
bool isValid() const
Definition: HandleBase.h:70
bool validHcal(const HcalDetId &id) const
int matchId(const HcalDetId &, const HcalDetId &)
const edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
const HcalDDDRecConstants * hdc_
fixed size matrix
HLT enums.
HLTConfigProvider hltConfig_
const edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > tok_chan_
std::vector< HcalActiveLength > getThickActive(const int &type) const
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:164
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
const edm::EDGetTokenT< reco::VertexCollection > tok_Vtx_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
void unmergeDepthDetId(const HcalDetId &id, std::vector< HcalDetId > &ids) const
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > tok_magField_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Log< level::Warning, false > LogWarning
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
const std::string fileInCorr_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
void energyHCALCell(HcalDetId detId, edm::Handle< T > &hits, std::vector< std::pair< double, int > > &energyCell, int maxDepth=1, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100, double tMin=-500, double tMax=500, int useRaw=0, int depthHE=3, bool debug=false)
const edm::ESGetToken< HcalDDDRecConstants, HcalRecNumberingRecord > tok_ddrec_
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
void setTopo(const HcalTopology *topo)
const std::vector< std::string > triggers_
Definition: Run.h:45
bool isGoodVertex(const reco::Vertex &vtx)
double eECALmatrix(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const CaloGeometry *geo, const CaloTopology *caloTopology, int ieta, int iphi, double ebThr=-100, double eeThr=-100, double tMin=-500, double tMax=500, bool debug=false)
double eHCALmatrix(const HcalTopology *topology, const DetId &det, edm::Handle< T > &hits, int ieta, int iphi, bool includeHO=false, bool algoNew=true, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100, double tMin=-500, double tMax=500, int useRaw=0, bool debug=false)