CMS 3D CMS Logo

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