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