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