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