CMS 3D CMS Logo

AlCaHcalHBHEMuonProducer.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
18 
27 
29 
39 
42 
45 
51 
55 
59 
71 
72 //#define EDM_ML_DEBUG
73 
75  struct Counters {
76  Counters() : nAll_(0), nGood_(0) {}
77  mutable std::atomic<unsigned int> nAll_, nGood_;
78  };
79 } // namespace alcaHcalHBHEMuonProducer
80 
81 class AlCaHcalHBHEMuonProducer : public edm::stream::EDProducer<edm::GlobalCache<alcaHcalHBHEMuonProducer::Counters>> {
82 public:
84  ~AlCaHcalHBHEMuonProducer() override = default;
85 
86  static std::unique_ptr<alcaHcalHBHEMuonProducer::Counters> initializeGlobalCache(edm::ParameterSet const&) {
87  return std::make_unique<alcaHcalHBHEMuonProducer::Counters>();
88  }
89 
90  void produce(edm::Event&, const edm::EventSetup&) override;
91 
92  void endStream() override;
93 
95 
96  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
97 
98 private:
99  void beginRun(edm::Run const&, edm::EventSetup const&) override;
100  void endRun(edm::Run const&, edm::EventSetup const&) override;
101  int matchId(const HcalDetId&, const HcalDetId&);
102  double activeLength(const DetId&, const HcalDDDRecConstants* hdc);
103  bool isGoodVertex(const reco::Vertex& vtx);
104  double respCorr(const DetId& id, const HcalRespCorrs* respCorrs);
105  double gainFactor(const HcalDbService* dbserv, const HcalDetId& id);
106  int depth16HE(int ieta, int iphi, const HcalTopology* theHBHETopology);
107  bool goodCell(const HcalDetId& hcid,
108  const reco::Track* pTrack,
109  const CaloGeometry* geo,
110  const MagneticField* bField,
111  const HcalDDDRecConstants* hdc);
112 
113  // ----------member data ---------------------------
115  const std::vector<std::string> trigNames_;
121  const int verbosity_;
124  const int maxDepth_;
126 
129 
136 
151 
153  static const int depthMax_ = 7;
154  std::vector<std::string> all_triggers_;
155  std::vector<int> hltresults_;
156 
157  std::vector<HcalDDDRecConstants::HcalActiveLength> actHB, actHE;
158  std::map<DetId, double> corrValue_;
160 };
161 
164  : trigNames_(iConfig.getParameter<std::vector<std::string>>("triggers")),
165  processName_(iConfig.getParameter<std::string>("processName")),
166  triggerResults_(iConfig.getParameter<edm::InputTag>("triggerResults")),
167  labelEBRecHit_(iConfig.getParameter<edm::InputTag>("labelEBRecHit")),
168  labelEERecHit_(iConfig.getParameter<edm::InputTag>("labelEERecHit")),
169  labelHBHERecHit_(iConfig.getParameter<edm::InputTag>("labelHBHERecHit")),
170  labelVtx_(iConfig.getParameter<std::string>("labelVertex")),
171  labelMuon_(iConfig.getParameter<std::string>("labelMuon")),
172  labelHBHEMuon_(iConfig.getParameter<std::string>("labelHBHEMuon")),
173  collapseDepth_(iConfig.getParameter<bool>("collapseDepth")),
174  isItPlan1_(iConfig.getParameter<bool>("isItPlan1")),
175  verbosity_(iConfig.getUntrackedParameter<int>("verbosity", 0)),
176  isItPreRecHit_(iConfig.getUntrackedParameter<bool>("isItPreRecHit", false)),
177  writeRespCorr_(iConfig.getUntrackedParameter<bool>("writeRespCorr", false)),
178  fileInCorr_(iConfig.getUntrackedParameter<std::string>("fileInCorr", "")),
179  maxDepth_(iConfig.getUntrackedParameter<int>("maxDepth", 7)),
180  mergedDepth_((!isItPreRecHit_) || (collapseDepth_)),
181  usePFThresh_(iConfig.getParameter<bool>("usePFThreshold")),
182  nRun_(0),
183  nAll_(0),
184  nGood_(0),
185  tok_trigRes_(consumes<edm::TriggerResults>(triggerResults_)),
186  tok_Vtx_(consumes<reco::VertexCollection>(labelVtx_)),
187  tok_EB_(consumes<EcalRecHitCollection>(labelEBRecHit_)),
188  tok_EE_(consumes<EcalRecHitCollection>(labelEERecHit_)),
189  tok_HBHE_(consumes<HBHERecHitCollection>(labelHBHERecHit_)),
190  tok_Muon_(consumes<reco::MuonCollection>(labelMuon_)),
193  tok_respcorr0_(esConsumes<HcalRespCorrs, HcalRespCorrsRcd, edm::Transition::BeginRun>()),
194  tok_respcorr1_(esConsumes<HcalRespCorrs, HcalRespCorrsRcd>()),
195  tok_geom0_(esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()),
197  tok_htopo0_(esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>()),
203  tok_dbservice_(esConsumes<HcalDbService, HcalDbRecord>()),
204  tok_ecalPFRecHitThresholds_(esConsumes<EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd>()) {
205  //now do what ever initialization is needed
206  edm::LogVerbatim("HBHEMuon") << "Labels used: Trig " << triggerResults_ << " Vtx " << labelVtx_ << " EB "
207  << labelEBRecHit_ << " EE " << labelEERecHit_ << " HBHE " << labelHBHERecHit_ << " MU "
208  << labelMuon_;
209 
210  if (!fileInCorr_.empty()) {
211  std::ifstream infile(fileInCorr_.c_str());
212  if (infile.is_open()) {
213  while (true) {
214  unsigned int id;
215  double cfac;
216  infile >> id >> cfac;
217  if (!infile.good())
218  break;
219  corrValue_[DetId(id)] = cfac;
220  }
221  infile.close();
222  }
223  }
224  useMyCorr_ = (!corrValue_.empty());
225  edm::LogVerbatim("HBHEMuon") << "Flags used: ollapseDepth " << collapseDepth_ << ":" << mergedDepth_ << " IsItPlan1 "
226  << isItPlan1_ << " IsItPreRecHit " << isItPreRecHit_ << " UseMyCorr " << useMyCorr_;
227 
228  //create the objects for HcalHBHEMuonVariables which has information of isolated muons
229  produces<HcalHBHEMuonVariablesCollection>(labelHBHEMuon_);
230  edm::LogVerbatim("HcalIsoTrack") << " Expected to produce the collections:\n"
231  << "HcalHBHEMuonVariablesCollection with label " << labelHBHEMuon_;
232 }
233 
234 //
235 // member functions
236 //
237 
238 // ------------ method called for each event ------------
240  ++nAll_;
241  auto outputHcalHBHEMuonColl = std::make_unique<HcalHBHEMuonVariablesCollection>();
242 
243  unsigned int runNumber = iEvent.id().run();
244  unsigned int eventNumber = iEvent.id().event();
245  unsigned int lumiNumber = iEvent.id().luminosityBlock();
246  unsigned int bxNumber = iEvent.bunchCrossing();
247 #ifdef EDM_ML_DEBUG
248  edm::LogVerbatim("HBHEMuon") << "Run " << runNumber << " Event " << eventNumber << " Lumi " << lumiNumber << " BX "
249  << bxNumber << std::endl;
250 #endif
251 
252  //Step1: Find if the event passes one of the chosen triggers
253  bool ok(false);
255  if (trigNames_.empty()) {
256  ok = true;
257  } else {
258  auto const& triggerResults = iEvent.getHandle(tok_trigRes_);
259  if (triggerResults.isValid()) {
260  std::vector<std::string> modules;
261  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
262  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
263  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
264  int hlt = triggerResults->accept(iHLT);
265  for (unsigned int i = 0; i < trigNames_.size(); ++i) {
266  if (triggerNames_[iHLT].find(trigNames_[i]) != std::string::npos) {
267  if (hlt > 0) {
268  ok = true;
269  }
270 #ifdef EDM_ML_DEBUG
271  edm::LogVerbatim("HBHEMuon") << "AlCaHcalHBHEMuonFilter::Trigger " << triggerNames_[iHLT] << " Flag " << hlt
272  << ":" << ok << std::endl;
273 #endif
274  }
275  }
276  }
277  }
278  }
279 
280  // get handles to calogeometry and calotopology
281  const HcalDDDRecConstants* hdc = &iSetup.getData(tok_ddrec1_);
282  const HcalRespCorrs* resp = &iSetup.getData(tok_respcorr1_);
283  const CaloGeometry* geo = &iSetup.getData(tok_geom1_);
284  const HcalTopology* theHBHETopology = &iSetup.getData(tok_htopo1_);
285  const MagneticField* bField = &iSetup.getData(tok_magField_);
286  const EcalChannelStatus* theEcalChStatus = &iSetup.getData(tok_chan_);
287  const EcalSeverityLevelAlgo* sevlv = &iSetup.getData(tok_sevlv_);
288  const CaloTopology* caloTopology = &iSetup.getData(tok_topo_);
290  HcalRespCorrs respCorrsObj(*resp);
291  HcalRespCorrs* respCorrs = &respCorrsObj;
292  respCorrs->setTopo(theHBHETopology);
293  const EcalPFRecHitThresholds* eThresholds = &iSetup.getData(tok_ecalPFRecHitThresholds_);
294  ;
295 
296  // Relevant blocks from iEvent
297  auto const& vtx = iEvent.getHandle(tok_Vtx_);
298  auto barrelRecHitsHandle = iEvent.getHandle(tok_EB_);
299  auto endcapRecHitsHandle = iEvent.getHandle(tok_EE_);
300  auto hbhe = iEvent.getHandle(tok_HBHE_);
301  auto const& muons = iEvent.getHandle(tok_Muon_);
302 
303  // require a good vertex
304  math::XYZPoint pvx;
305  unsigned int goodVertex = 0;
306  reco::VertexCollection::const_iterator firstGoodVertex;
307  if (!vtx.isValid()) {
308 #ifdef EDM_ML_DEBUG
309  edm::LogVerbatim("HBHEMuon") << "No Good Vertex found == Reject";
310 #endif
311  } else {
312  firstGoodVertex = vtx->end();
313  for (reco::VertexCollection::const_iterator it = vtx->begin(); it != vtx->end(); it++) {
314  if (isGoodVertex(*it)) {
315  if (firstGoodVertex == vtx->end())
316  firstGoodVertex = it;
317  ++goodVertex;
318  }
319  }
320  if (firstGoodVertex != vtx->end())
321  pvx = firstGoodVertex->position();
322  }
323 
324  if (ok && (goodVertex > 0) && muons.isValid() && barrelRecHitsHandle.isValid() && endcapRecHitsHandle.isValid() &&
325  hbhe.isValid()) {
326  for (reco::MuonCollection::const_iterator recMuon = muons->begin(); recMuon != muons->end(); ++recMuon) {
327  HcalHBHEMuonVariables hbheMuon;
328  hbheMuon.runNumber_ = runNumber;
329  hbheMuon.eventNumber_ = eventNumber;
330  hbheMuon.lumiNumber_ = lumiNumber;
331  hbheMuon.bxNumber_ = bxNumber;
332  hbheMuon.goodVertex_ = goodVertex;
333  hbheMuon.muonGood_ = (recMuon->isPFMuon());
334  hbheMuon.muonGlobal_ = (recMuon->isGlobalMuon());
335  hbheMuon.muonTracker_ = (recMuon->isTrackerMuon());
336  hbheMuon.ptGlob_ = ((recMuon)->pt());
337  hbheMuon.etaGlob_ = (recMuon->eta());
338  hbheMuon.phiGlob_ = (recMuon->phi());
339  hbheMuon.energyMuon_ = (recMuon->energy());
340  hbheMuon.pMuon_ = (recMuon->p());
341 #ifdef EDM_ML_DEBUG
342  edm::LogVerbatim("HBHEMuon") << "Energy:" << recMuon->energy() << " P:" << recMuon->p();
343 #endif
344  hbheMuon.muonTight_ = (muon::isTightMuon(*recMuon, *firstGoodVertex));
345  hbheMuon.muonMedium_ = (muon::isMediumMuon(*recMuon));
346  hbheMuon.muonTrkKink_ = (recMuon->combinedQuality().trkKink);
347  hbheMuon.muonChi2LocalPosition_ = (recMuon->combinedQuality().chi2LocalPosition);
348  hbheMuon.muonSegComp_ = (muon::segmentCompatibility(*recMuon));
349  // acessing tracker hits info
350  if (recMuon->track().isNonnull()) {
351  hbheMuon.trackerLayer_ = (recMuon->track()->hitPattern().trackerLayersWithMeasurement());
352  } else {
353  hbheMuon.trackerLayer_ = -1;
354  }
355  if (recMuon->innerTrack().isNonnull()) {
356  hbheMuon.innerTrack_ = true;
357  hbheMuon.numPixelLayers_ = (recMuon->innerTrack()->hitPattern().pixelLayersWithMeasurement());
358  hbheMuon.chiTracker_ = (recMuon->innerTrack()->normalizedChi2());
359  hbheMuon.dxyTracker_ = (fabs(recMuon->innerTrack()->dxy(pvx)));
360  hbheMuon.dzTracker_ = (fabs(recMuon->innerTrack()->dz(pvx)));
361  hbheMuon.innerTrackPt_ = (recMuon->innerTrack()->pt());
362  hbheMuon.innerTrackEta_ = (recMuon->innerTrack()->eta());
363  hbheMuon.innerTrackPhi_ = (recMuon->innerTrack()->phi());
364  hbheMuon.tightPixelHits_ = (recMuon->innerTrack()->hitPattern().numberOfValidPixelHits());
365  hbheMuon.tightValidFraction_ = (recMuon->innerTrack()->validFraction());
366  }
367  // outer track info
368  if (recMuon->outerTrack().isNonnull()) {
369  hbheMuon.outerTrack_ = true;
370  hbheMuon.outerTrackPt_ = (recMuon->outerTrack()->pt());
371  hbheMuon.outerTrackEta_ = (recMuon->outerTrack()->eta());
372  hbheMuon.outerTrackPhi_ = (recMuon->outerTrack()->phi());
373  hbheMuon.outerTrackChi_ = (recMuon->outerTrack()->normalizedChi2());
374  hbheMuon.outerTrackHits_ = (recMuon->outerTrack()->numberOfValidHits());
375  hbheMuon.outerTrackRHits_ = (recMuon->outerTrack()->recHitsSize());
376  }
377  // Tight Muon cuts
378  if (recMuon->globalTrack().isNonnull()) {
379  hbheMuon.globalTrack_ = true;
380  hbheMuon.chiGlobal_ = (recMuon->globalTrack()->normalizedChi2());
381  hbheMuon.globalMuonHits_ = (recMuon->globalTrack()->hitPattern().numberOfValidMuonHits());
382  hbheMuon.matchedStat_ = (recMuon->numberOfMatchedStations());
383  hbheMuon.globalTrackPt_ = (recMuon->globalTrack()->pt());
384  hbheMuon.globalTrackEta_ = (recMuon->globalTrack()->eta());
385  hbheMuon.globalTrackPhi_ = (recMuon->globalTrack()->phi());
386  hbheMuon.tightTransImpara_ = (fabs(recMuon->muonBestTrack()->dxy(pvx)));
387  hbheMuon.tightLongPara_ = (fabs(recMuon->muonBestTrack()->dz(pvx)));
388  }
389 
390  hbheMuon.isolationR04_ =
391  ((recMuon->pfIsolationR04().sumChargedHadronPt +
392  std::max(0.,
393  recMuon->pfIsolationR04().sumNeutralHadronEt + recMuon->pfIsolationR04().sumPhotonEt -
394  (0.5 * recMuon->pfIsolationR04().sumPUPt))) /
395  recMuon->pt());
396 
397  hbheMuon.isolationR03_ =
398  ((recMuon->pfIsolationR03().sumChargedHadronPt +
399  std::max(0.,
400  recMuon->pfIsolationR03().sumNeutralHadronEt + recMuon->pfIsolationR03().sumPhotonEt -
401  (0.5 * recMuon->pfIsolationR03().sumPUPt))) /
402  recMuon->pt());
403 
404  hbheMuon.ecalEnergy_ = (recMuon->calEnergy().emS9);
405  hbheMuon.hcalEnergy_ = (recMuon->calEnergy().hadS9);
406  hbheMuon.hoEnergy_ = (recMuon->calEnergy().hoS9);
407 
408  if (recMuon->innerTrack().isNonnull()) {
409  const reco::Track* pTrack = (recMuon->innerTrack()).get();
410  spr::propagatedTrackID trackID = spr::propagateCALO(pTrack, geo, bField, (((verbosity_ / 100) % 10 > 0)));
411 
412  double activeLengthTot(0), activeLengthHotTot(0);
413  double eHcalDepth[depthMax_], eHcalDepthHot[depthMax_];
414  double eHcalDepthC[depthMax_], eHcalDepthHotC[depthMax_];
415  double cHcalDepthHot[depthMax_], cHcalDepthHotBG[depthMax_];
416  double eHcalDepthRaw[depthMax_], eHcalDepthHotRaw[depthMax_];
417  double eHcalDepthCRaw[depthMax_], eHcalDepthHotCRaw[depthMax_];
418  double cHcalDepthHotRaw[depthMax_], cHcalDepthHotBGRaw[depthMax_];
419  double eHcalDepthAux[depthMax_], eHcalDepthHotAux[depthMax_];
420  double eHcalDepthCAux[depthMax_], eHcalDepthHotCAux[depthMax_];
421  double cHcalDepthHotAux[depthMax_], cHcalDepthHotBGAux[depthMax_];
422  double activeL[depthMax_], activeHotL[depthMax_];
423  bool matchDepth[depthMax_], matchDepthHot[depthMax_];
424  HcalDetId eHcalDetId[depthMax_];
425  unsigned int isHot(0);
426  int ieta(-1000), iphi(-1000);
427  for (int i = 0; i < depthMax_; ++i) {
428  eHcalDepth[i] = eHcalDepthHot[i] = 0;
429  eHcalDepthC[i] = eHcalDepthHotC[i] = 0;
430  cHcalDepthHot[i] = cHcalDepthHotBG[i] = 0;
431  eHcalDepthRaw[i] = eHcalDepthHotRaw[i] = 0;
432  eHcalDepthCRaw[i] = eHcalDepthHotCRaw[i] = 0;
433  cHcalDepthHotRaw[i] = cHcalDepthHotBGRaw[i] = 0;
434  eHcalDepthAux[i] = eHcalDepthHotAux[i] = 0;
435  eHcalDepthCAux[i] = eHcalDepthHotCAux[i] = 0;
436  cHcalDepthHotAux[i] = cHcalDepthHotBGAux[i] = 0;
437  activeL[i] = activeHotL[i] = 0;
438  matchDepth[i] = matchDepthHot[i] = true;
439  }
440 #ifdef EDM_ML_DEBUG
441  double eHcal(0);
442 #endif
443 
444  hbheMuon.ecalDetId_ = ((trackID.detIdECAL)());
445  hbheMuon.hcalDetId_ = ((trackID.detIdHCAL)());
446  hbheMuon.ehcalDetId_ = ((trackID.detIdEHCAL)());
447 
448  HcalDetId check(false);
449  std::pair<bool, HcalDetId> info = spr::propagateHCALBack(pTrack, geo, bField, (((verbosity_ / 100) % 10 > 0)));
450  if (info.first) {
451  check = info.second;
452  }
453 
454  bool okE = trackID.okECAL;
455  if (okE) {
456  const DetId isoCell(trackID.detIdECAL);
457  std::pair<double, bool> e3x3 = (usePFThresh_ ? spr::eECALmatrix(isoCell,
458  barrelRecHitsHandle,
459  endcapRecHitsHandle,
460  *theEcalChStatus,
461  geo,
462  caloTopology,
463  sevlv,
464  eThresholds,
465  1,
466  1,
467  false)
468  : spr::eECALmatrix(isoCell,
469  barrelRecHitsHandle,
470  endcapRecHitsHandle,
471  *theEcalChStatus,
472  geo,
473  caloTopology,
474  sevlv,
475  1,
476  1,
477  -100.0,
478  -100.0,
479  -500.0,
480  500.0,
481  false));
482  hbheMuon.ecal3x3Energy_ = e3x3.first;
483  okE = e3x3.second;
484  }
485 #ifdef EDM_ML_DEBUG
486  edm::LogVerbatim("HBHEMuon") << "Propagate Track to ECAL: " << okE << ":" << trackID.okECAL << " E "
487  << hbheMuon.ecal3x3Energy_;
488 #endif
489 
490  if (trackID.okHCAL) {
491  DetId closestCell(trackID.detIdHCAL);
492  HcalDetId hcidt(closestCell.rawId());
493  if ((hcidt.ieta() == check.ieta()) && (hcidt.iphi() == check.iphi()))
494  hbheMuon.matchedId_ = true;
495 #ifdef EDM_ML_DEBUG
496  edm::LogVerbatim("HBHEMuon") << "Front " << hcidt << " Back " << info.first << ":" << check << " Match "
497  << hbheMuon.matchedId_;
498 #endif
499  HcalSubdetector subdet = hcidt.subdet();
500  ieta = hcidt.ieta();
501  iphi = hcidt.iphi();
502  bool hborhe = (std::abs(ieta) == 16);
503 
504  hbheMuon.hcal1x1Energy_ = spr::eHCALmatrix(
505  theHBHETopology, closestCell, hbhe, 0, 0, false, true, -100.0, -100.0, -100.0, -100.0, -500., 500., 0);
507  theHBHETopology, closestCell, hbhe, 0, 0, false, true, -100.0, -100.0, -100.0, -100.0, -500., 500., 1);
509  theHBHETopology, closestCell, hbhe, 0, 0, false, true, -100.0, -100.0, -100.0, -100.0, -500., 500., 2);
510  std::vector<std::pair<double, int>> ehdepth, ehdepthAux, ehdepthRaw;
511  spr::energyHCALCell((HcalDetId)closestCell,
512  hbhe,
513  ehdepth,
514  maxDepth_,
515  -100.0,
516  -100.0,
517  -100.0,
518  -100.0,
519  -500.0,
520  500.0,
521  0,
522  depth16HE(ieta, iphi, theHBHETopology),
523  (((verbosity_ / 1000) % 10) > 0));
524  for (int i = 0; i < depthMax_; ++i)
525  eHcalDetId[i] = HcalDetId();
526  spr::energyHCALCell((HcalDetId)closestCell,
527  hbhe,
528  ehdepthAux,
529  maxDepth_,
530  -100.0,
531  -100.0,
532  -100.0,
533  -100.0,
534  -500.0,
535  500.0,
536  1,
537  depth16HE(ieta, iphi, theHBHETopology),
538  (((verbosity_ / 1000) % 10) > 0));
539  spr::energyHCALCell((HcalDetId)closestCell,
540  hbhe,
541  ehdepthRaw,
542  maxDepth_,
543  -100.0,
544  -100.0,
545  -100.0,
546  -100.0,
547  -500.0,
548  500.0,
549  2,
550  depth16HE(ieta, iphi, theHBHETopology),
551  (((verbosity_ / 1000) % 10) > 0));
552  for (unsigned int i = 0; i < ehdepth.size(); ++i) {
553  HcalSubdetector subdet0 =
554  (hborhe) ? ((ehdepth[i].second >= depth16HE(ieta, iphi, theHBHETopology)) ? HcalEndcap : HcalBarrel)
555  : subdet;
556  HcalDetId hcid0(subdet0, ieta, iphi, ehdepth[i].second);
557  double actL = activeLength(DetId(hcid0), hdc);
558  double ene = ehdepth[i].first;
559  double eneAux = ehdepthAux[i].first;
560  double eneRaw = ehdepthRaw[i].first;
561  bool tmpC(false);
562  if (ene > 0.0) {
563  if (!(theHBHETopology->validHcal(hcid0))) {
564  edm::LogWarning("HBHEMuon") << "(1) Invalid ID " << hcid0 << " with E = " << ene;
565  edm::LogWarning("HBHEMuon") << HcalDetId(closestCell) << " with " << ehdepth.size() << " depths:";
566  for (const auto& ehd : ehdepth)
567  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":" << ehd.first;
568  } else {
569  tmpC = goodCell(hcid0, pTrack, geo, bField, hdc);
570  double enec(ene);
571  double corr = respCorr(DetId(hcid0), respCorrs);
572  if (corr != 0)
573  ene /= corr;
574 #ifdef EDM_ML_DEBUG
575  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc->mergedDepthDetId(hcid0) : hcid0;
576  edm::LogVerbatim("HBHEMuon") << hcid0 << ":" << id << " Corr " << corr;
577 #endif
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  if (eneAux > 0.0) {
596  if (theHBHETopology->validHcal(hcid0)) {
597  double enecAux(eneAux);
598  double corr = respCorr(DetId(hcid0), respCorrs);
599  if (corr != 0)
600  eneAux /= corr;
601  int depth = ehdepthAux[i].second - 1;
602  if (collapseDepth_) {
603  HcalDetId id = hdc->mergedDepthDetId(hcid0);
604  depth = id.depth() - 1;
605  }
606  eHcalDepthAux[depth] += eneAux;
607  eHcalDepthCAux[depth] += enecAux;
608 #ifdef EDM_ML_DEBUG
609  if ((verbosity_ % 10) > 0)
610  edm::LogVerbatim("HBHEMuon")
611  << hcid0 << " E " << eneAux << ":" << enecAux << " L " << actL << " Match " << tmpC;
612 #endif
613  }
614  }
615  if (eneRaw > 0.0) {
616  if (theHBHETopology->validHcal(hcid0)) {
617  double enecRaw(eneRaw);
618  double corr = respCorr(DetId(hcid0), respCorrs);
619  if (corr != 0)
620  eneRaw /= corr;
621  int depth = ehdepthRaw[i].second - 1;
622  if (collapseDepth_) {
623  HcalDetId id = hdc->mergedDepthDetId(hcid0);
624  depth = id.depth() - 1;
625  }
626  eHcalDepthRaw[depth] += eneRaw;
627  eHcalDepthCRaw[depth] += enecRaw;
628 #ifdef EDM_ML_DEBUG
629  if ((verbosity_ % 10) > 0)
630  edm::LogVerbatim("HBHEMuon")
631  << hcid0 << " E " << eneRaw << ":" << enecRaw << " L " << actL << " Match " << tmpC;
632 #endif
633  }
634  }
635  }
636 #ifdef EDM_ML_DEBUG
637  if ((verbosity_ % 10) > 0) {
638  edm::LogVerbatim("HBHEMuon") << hcidt << " Match " << hbheMuon.matchedId_ << " Depths " << ehdepth.size();
639  for (unsigned int k = 0; k < ehdepth.size(); ++k)
640  edm::LogVerbatim("HBHEMuon") << " [" << k << ":" << ehdepth[k].second << "] " << matchDepth[k];
641  }
642 #endif
643  HcalDetId hotCell;
644  spr::eHCALmatrix(geo, theHBHETopology, closestCell, hbhe, 1, 1, hotCell, false, 0, false);
645  isHot = matchId(closestCell, hotCell);
646  if (hotCell != HcalDetId()) {
647  subdet = HcalDetId(hotCell).subdet();
648  ieta = HcalDetId(hotCell).ieta();
649  iphi = HcalDetId(hotCell).iphi();
650  hborhe = (std::abs(ieta) == 16);
651  std::vector<std::pair<double, int>> ehdepth, ehdepthAux, ehdepthRaw;
652  spr::energyHCALCell(hotCell,
653  hbhe,
654  ehdepth,
655  maxDepth_,
656  -100.0,
657  -100.0,
658  -100.0,
659  -100.0,
660  -500.0,
661  500.0,
662  0,
663  depth16HE(ieta, iphi, theHBHETopology),
664  false);
665  spr::energyHCALCell(hotCell,
666  hbhe,
667  ehdepthAux,
668  maxDepth_,
669  -100.0,
670  -100.0,
671  -100.0,
672  -100.0,
673  -500.0,
674  500.0,
675  1,
676  depth16HE(ieta, iphi, theHBHETopology),
677  false);
678  spr::energyHCALCell(hotCell,
679  hbhe,
680  ehdepthRaw,
681  maxDepth_,
682  -100.0,
683  -100.0,
684  -100.0,
685  -100.0,
686  -500.0,
687  500.0,
688  2,
689  depth16HE(ieta, iphi, theHBHETopology),
690  false);
691  for (int i = 0; i < depthMax_; ++i)
692  eHcalDetId[i] = HcalDetId();
693  for (unsigned int i = 0; i < ehdepth.size(); ++i) {
694  HcalSubdetector subdet0 =
695  (hborhe) ? ((ehdepth[i].second >= depth16HE(ieta, iphi, theHBHETopology)) ? HcalEndcap : HcalBarrel)
696  : subdet;
697  HcalDetId hcid0(subdet0, ieta, iphi, ehdepth[i].second);
698  double actL = activeLength(DetId(hcid0), hdc);
699  double ene = ehdepth[i].first;
700  bool tmpC(false);
701  if (ene > 0.0) {
702  if (!(theHBHETopology->validHcal(hcid0))) {
703  edm::LogWarning("HBHEMuon") << "(2) Invalid ID " << hcid0 << " with E = " << ene;
704  edm::LogWarning("HBHEMuon") << HcalDetId(hotCell) << " with " << ehdepth.size() << " depths:";
705  for (const auto& ehd : ehdepth)
706  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":" << ehd.first;
707  } else {
708  tmpC = goodCell(hcid0, pTrack, geo, bField, hdc);
709  double chg(ene), enec(ene);
710  double corr = respCorr(DetId(hcid0), respCorrs);
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") << hcid0 << ":" << id << " Corr " << corr << " E " << ene << ":" << enec;
716 #endif
717  double gain = gainFactor(conditions, hcid0);
718  if (gain != 0)
719  chg /= gain;
720 #ifdef EDM_ML_DEBUG
721  edm::LogVerbatim("HBHEMuon") << hcid0 << " Gain " << gain << " C " << chg;
722 #endif
723  int depth = ehdepth[i].second - 1;
724  if (collapseDepth_) {
725  HcalDetId id = hdc->mergedDepthDetId(hcid0);
726  depth = id.depth() - 1;
727  }
728  eHcalDepthHot[depth] += ene;
729  eHcalDepthHotC[depth] += enec;
730  cHcalDepthHot[depth] += chg;
731  activeHotL[depth] += actL;
732  activeLengthHotTot += actL;
733  matchDepthHot[depth] = (matchDepthHot[depth] && tmpC);
734 #ifdef EDM_ML_DEBUG
735  eHcal += ene;
736  if ((verbosity_ % 10) > 0)
737  edm::LogVerbatim("HBHEMuon") << hcid0 << " depth " << depth << " E " << ene << ":" << enec << " C "
738  << chg << " L " << actL << " Match " << tmpC;
739 #endif
740  }
741  }
742  double eneAux = ehdepthAux[i].first;
743  if (eneAux > 0.0) {
744  if (theHBHETopology->validHcal(hcid0)) {
745  double chgAux(eneAux), enecAux(eneAux);
746  double corr = respCorr(DetId(hcid0), respCorrs);
747  if (corr != 0)
748  eneAux /= corr;
749  double gain = gainFactor(conditions, hcid0);
750  if (gain != 0)
751  chgAux /= gain;
752  int depth = ehdepthAux[i].second - 1;
753  if (collapseDepth_) {
754  HcalDetId id = hdc->mergedDepthDetId(hcid0);
755  depth = id.depth() - 1;
756  }
757  eHcalDepthHotAux[depth] += eneAux;
758  eHcalDepthHotCAux[depth] += enecAux;
759  cHcalDepthHotAux[depth] += chgAux;
760 #ifdef EDM_ML_DEBUG
761  if ((verbosity_ % 10) > 0)
762  edm::LogVerbatim("HBHEMuon") << hcid0 << " depth " << depth << " E " << eneAux << ":" << enecAux
763  << " C " << chgAux << " L " << actL << " Match " << tmpC;
764 #endif
765  }
766  }
767  double eneRaw = ehdepthRaw[i].first;
768  if (eneRaw > 0.0) {
769  if (theHBHETopology->validHcal(hcid0)) {
770  double chgRaw(eneRaw), enecRaw(eneRaw);
771  double corr = respCorr(DetId(hcid0), respCorrs);
772  if (corr != 0)
773  eneRaw /= corr;
774  double gain = gainFactor(conditions, hcid0);
775  if (gain != 0)
776  chgRaw /= gain;
777  int depth = ehdepthRaw[i].second - 1;
778  if (collapseDepth_) {
779  HcalDetId id = hdc->mergedDepthDetId(hcid0);
780  depth = id.depth() - 1;
781  }
782  eHcalDepthHotRaw[depth] += eneRaw;
783  eHcalDepthHotCRaw[depth] += enecRaw;
784  cHcalDepthHotRaw[depth] += chgRaw;
785 #ifdef EDM_ML_DEBUG
786  if ((verbosity_ % 10) > 0)
787  edm::LogVerbatim("HBHEMuon") << hcid0 << " depth " << depth << " E " << eneRaw << ":" << enecRaw
788  << " C " << chgRaw << " L " << actL << " Match " << tmpC;
789 #endif
790  }
791  }
792  }
793 
794  HcalDetId oppCell(subdet, -ieta, iphi, HcalDetId(hotCell).depth());
795  std::vector<std::pair<double, int>> ehdeptho, ehdepthoAux, ehdepthoRaw;
796  spr::energyHCALCell(oppCell,
797  hbhe,
798  ehdeptho,
799  maxDepth_,
800  -100.0,
801  -100.0,
802  -100.0,
803  -100.0,
804  -500.0,
805  500.0,
806  0,
807  depth16HE(-ieta, iphi, theHBHETopology),
808  false);
809  spr::energyHCALCell(oppCell,
810  hbhe,
811  ehdepthoAux,
812  maxDepth_,
813  -100.0,
814  -100.0,
815  -100.0,
816  -100.0,
817  -500.0,
818  500.0,
819  1,
820  depth16HE(-ieta, iphi, theHBHETopology),
821  false);
822  spr::energyHCALCell(oppCell,
823  hbhe,
824  ehdepthoRaw,
825  maxDepth_,
826  -100.0,
827  -100.0,
828  -100.0,
829  -100.0,
830  -500.0,
831  500.0,
832  2,
833  depth16HE(-ieta, iphi, theHBHETopology),
834  false);
835  for (unsigned int i = 0; i < ehdeptho.size(); ++i) {
836  HcalSubdetector subdet0 =
837  (hborhe) ? ((ehdeptho[i].second >= depth16HE(-ieta, iphi, theHBHETopology)) ? HcalEndcap : HcalBarrel)
838  : subdet;
839  HcalDetId hcid0(subdet0, -ieta, iphi, ehdeptho[i].second);
840  double ene = ehdeptho[i].first;
841  if (ene > 0.0) {
842  if (!(theHBHETopology->validHcal(hcid0))) {
843  edm::LogWarning("HBHEMuon") << "(3) Invalid ID " << hcid0 << " with E = " << ene;
844  edm::LogWarning("HBHEMuon") << oppCell << " with " << ehdeptho.size() << " depths:";
845  for (const auto& ehd : ehdeptho)
846  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":" << ehd.first;
847  } else {
848  double chg(ene);
849  double corr = respCorr(DetId(hcid0), respCorrs);
850  if (corr != 0)
851  ene /= corr;
852 #ifdef EDM_ML_DEBUG
853  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc->mergedDepthDetId(hcid0) : hcid0;
854  edm::LogVerbatim("HBHEMuon")
855  << hcid0 << ":" << id << " Corr " << corr << " E " << ene << ":" << ehdeptho[i].first;
856 #endif
857  double gain = gainFactor(conditions, hcid0);
858  if (gain != 0)
859  chg /= gain;
860 #ifdef EDM_ML_DEBUG
861  edm::LogVerbatim("HBHEMuon") << hcid0 << " Gain " << gain << " C " << chg;
862 #endif
863  int depth = ehdeptho[i].second - 1;
864  if (collapseDepth_) {
865  HcalDetId id = hdc->mergedDepthDetId(hcid0);
866  depth = id.depth() - 1;
867  }
868  cHcalDepthHotBG[depth] += chg;
869 #ifdef EDM_ML_DEBUG
870  if ((verbosity_ % 10) > 0)
871  edm::LogVerbatim("HBHEMuon") << hcid0 << " Depth " << depth << " E " << ene << " C " << chg;
872 #endif
873  }
874  }
875  double eneAux = ehdepthoAux[i].first;
876  if (eneAux > 0.0) {
877  if (theHBHETopology->validHcal(hcid0)) {
878  double chgAux(eneAux);
879  double corr = respCorr(DetId(hcid0), respCorrs);
880  if (corr != 0)
881  eneAux /= corr;
882  double gain = gainFactor(conditions, hcid0);
883  if (gain != 0)
884  chgAux /= gain;
885  int depth = ehdepthoAux[i].second - 1;
886  if (collapseDepth_) {
887  HcalDetId id = hdc->mergedDepthDetId(hcid0);
888  depth = id.depth() - 1;
889  }
890  cHcalDepthHotBGAux[depth] += chgAux;
891 #ifdef EDM_ML_DEBUG
892  if ((verbosity_ % 10) > 0)
893  edm::LogVerbatim("HBHEMuon") << hcid0 << " Depth " << depth << " E " << eneAux << " C " << chgAux;
894 #endif
895  }
896  }
897  double eneRaw = ehdepthoRaw[i].first;
898  if (eneRaw > 0.0) {
899  if (theHBHETopology->validHcal(hcid0)) {
900  double chgRaw(eneRaw);
901  double corr = respCorr(DetId(hcid0), respCorrs);
902  if (corr != 0)
903  eneRaw /= corr;
904  double gain = gainFactor(conditions, hcid0);
905  if (gain != 0)
906  chgRaw /= gain;
907  int depth = ehdepthoRaw[i].second - 1;
908  if (collapseDepth_) {
909  HcalDetId id = hdc->mergedDepthDetId(hcid0);
910  depth = id.depth() - 1;
911  }
912  cHcalDepthHotBGRaw[depth] += chgRaw;
913 #ifdef EDM_ML_DEBUG
914  if ((verbosity_ % 10) > 0)
915  edm::LogVerbatim("HBHEMuon") << hcid0 << " Depth " << depth << " E " << eneRaw << " C " << chgRaw;
916 #endif
917  }
918  }
919  }
920  }
921  }
922 #ifdef EDM_ML_DEBUG
923  edm::LogVerbatim("HBHEMuon") << "Propagate Track to HCAL: " << trackID.okHCAL << " Match "
924  << hbheMuon.matchedId_ << " Hot " << isHot << " Energy " << eHcal;
925 #endif
926  hbheMuon.hcalIeta_ = ieta;
927  hbheMuon.hcalIphi_ = iphi;
928  for (int i = 0; i < depthMax_; ++i) {
929  hbheMuon.hcalDepthEnergy_.push_back(eHcalDepth[i]);
930  hbheMuon.hcalDepthActiveLength_.push_back(activeL[i]);
931  hbheMuon.hcalDepthEnergyHot_.push_back(eHcalDepthHot[i]);
932  hbheMuon.hcalDepthActiveLengthHot_.push_back(activeHotL[i]);
933  hbheMuon.hcalDepthEnergyCorr_.push_back(eHcalDepthC[i]);
934  hbheMuon.hcalDepthEnergyHotCorr_.push_back(eHcalDepthHotC[i]);
935  hbheMuon.hcalDepthChargeHot_.push_back(cHcalDepthHot[i]);
936  hbheMuon.hcalDepthChargeHotBG_.push_back(cHcalDepthHotBG[i]);
937  hbheMuon.hcalDepthMatch_.push_back(matchDepth[i]);
938  hbheMuon.hcalDepthMatchHot_.push_back(matchDepthHot[i]);
939  hbheMuon.hcalDepthEnergyAux_.push_back(eHcalDepthAux[i]);
940  hbheMuon.hcalDepthEnergyHotAux_.push_back(eHcalDepthHotAux[i]);
941  hbheMuon.hcalDepthEnergyCorrAux_.push_back(eHcalDepthCAux[i]);
942  hbheMuon.hcalDepthEnergyHotCorrAux_.push_back(eHcalDepthHotCAux[i]);
943  hbheMuon.hcalDepthChargeHotAux_.push_back(cHcalDepthHotAux[i]);
944  hbheMuon.hcalDepthChargeHotBGAux_.push_back(cHcalDepthHotBGAux[i]);
945  hbheMuon.hcalDepthEnergyRaw_.push_back(eHcalDepthRaw[i]);
946  hbheMuon.hcalDepthEnergyHotRaw_.push_back(eHcalDepthHotRaw[i]);
947  hbheMuon.hcalDepthEnergyCorrRaw_.push_back(eHcalDepthCRaw[i]);
948  hbheMuon.hcalDepthEnergyHotCorrRaw_.push_back(eHcalDepthHotCRaw[i]);
949  hbheMuon.hcalDepthChargeHotRaw_.push_back(cHcalDepthHotRaw[i]);
950  hbheMuon.hcalDepthChargeHotBGRaw_.push_back(cHcalDepthHotBGRaw[i]);
951  }
952  hbheMuon.hcalActiveLength_ = activeLengthTot;
953  hbheMuon.hcalHot_ = isHot;
954  hbheMuon.hcalActiveLengthHot_ = activeLengthHotTot;
955 
956  if ((recMuon->p() > 10.0) && (trackID.okHCAL))
957  outputHcalHBHEMuonColl->emplace_back(hbheMuon);
958  }
959  }
960  }
961  if (!outputHcalHBHEMuonColl->empty())
962  ++nGood_;
963  iEvent.put(std::move(outputHcalHBHEMuonColl), labelHBHEMuon_);
964 }
965 
966 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
969  std::vector<std::string> triggers = {"HLT_IsoMu", "HLT_Mu"};
970  desc.add<std::vector<std::string>>("triggers", triggers);
971  desc.add<std::string>("processName", "HLT");
972  desc.add<edm::InputTag>("triggerResults", 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  desc.add<std::string>("labelHBHEMuon", "hbheMuon");
979  desc.add<bool>("collapseDepth", false);
980  desc.add<bool>("isItPlan1", false);
981  desc.addUntracked<int>("verbosity", 0);
982  desc.addUntracked<bool>("isItPreRecHit", false);
983  desc.addUntracked<bool>("writeRespCorr", false);
984  desc.addUntracked<std::string>("fileInCorr", "");
985  desc.addUntracked<int>("maxDepth", 7);
986  desc.add<bool>("usePFThreshold", true);
987  descriptions.add("alcaHcalHBHEMuonProducer", desc);
988 }
989 
990 // ------------ method called once each job just after ending the event loop ------------
992  globalCache()->nAll_ += nAll_;
993  globalCache()->nGood_ += nGood_;
994 }
995 
997  edm::LogVerbatim("HBHEMuon") << "Selects " << count->nGood_ << " out of " << count->nAll_ << " total # of events\n";
998 }
999 
1000 // ------------ method called when starting or ending a run ------------
1002  const HcalDDDRecConstants* hdc = &iSetup.getData(tok_ddrec0_);
1003  actHB.clear();
1004  actHE.clear();
1005  actHB = hdc->getThickActive(0);
1006  actHE = hdc->getThickActive(1);
1007 #ifdef EDM_ML_DEBUG
1008  unsigned int k1(0), k2(0);
1009  edm::LogVerbatim("HBHEMuon") << actHB.size() << " Active Length for HB";
1010  for (const auto& act : actHB) {
1011  edm::LogVerbatim("HBHEMuon") << "[" << k1 << "] ieta " << act.ieta << " depth " << act.depth << " zside "
1012  << act.zside << " type " << act.stype << " phi " << act.iphis.size() << ":"
1013  << act.iphis[0] << " L " << act.thick;
1014  HcalDetId hcid1(HcalBarrel, (act.ieta) * (act.zside), act.iphis[0], act.depth);
1015  HcalDetId hcid2 = mergedDepth_ ? hdc->mergedDepthDetId(hcid1) : hcid1;
1016  edm::LogVerbatim("HBHEMuon") << hcid1 << " | " << hcid2 << " L " << activeLength(DetId(hcid2), hdc);
1017  ++k1;
1018  }
1019  edm::LogVerbatim("HBHEMuon") << actHE.size() << " Active Length for HE";
1020  for (const auto& act : actHE) {
1021  edm::LogVerbatim("HBHEMuon") << "[" << k2 << "] ieta " << act.ieta << " depth " << act.depth << " zside "
1022  << act.zside << " type " << act.stype << " phi " << act.iphis.size() << ":"
1023  << act.iphis[0] << " L " << act.thick;
1024  HcalDetId hcid1(HcalEndcap, (act.ieta) * (act.zside), act.iphis[0], act.depth);
1025  HcalDetId hcid2 = mergedDepth_ ? hdc->mergedDepthDetId(hcid1) : hcid1;
1026  edm::LogVerbatim("HBHEMuon") << hcid1 << " | " << hcid2 << " L " << activeLength(DetId(hcid2), hdc);
1027  ++k2;
1028  }
1029 #endif
1030 
1031  bool changed = true;
1032  bool flag = hltConfig_.init(iRun, iSetup, processName_, changed);
1033  edm::LogVerbatim("HBHEMuon") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init " << flag << std::endl;
1034 
1035  const HcalRespCorrs* resp = &iSetup.getData(tok_respcorr0_);
1036  const HcalTopology* theHBHETopology = &iSetup.getData(tok_htopo0_);
1037  const CaloGeometry* geo = &iSetup.getData(tok_geom0_);
1038  HcalRespCorrs respCorrsObj(*resp);
1039  HcalRespCorrs* respCorrs = &respCorrsObj;
1040  respCorrs->setTopo(theHBHETopology);
1041 
1042  // Write correction factors for all HB/HE events
1043  if (writeRespCorr_) {
1044  const HcalGeometry* gHcal = static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
1045  const std::vector<DetId>& ids = gHcal->getValidDetIds(DetId::Hcal, 0);
1046  edm::LogVerbatim("HBHEMuon") << "\nTable of Correction Factors for Run " << iRun.run() << "\n";
1047  for (auto const& id : ids) {
1048  if ((id.det() == DetId::Hcal) && ((id.subdetId() == HcalBarrel) || (id.subdetId() == HcalEndcap))) {
1049  edm::LogVerbatim("HBHEMuon") << HcalDetId(id) << " " << id.rawId() << " "
1050  << (respCorrs->getValues(id))->getValue();
1051  }
1052  }
1053  }
1054 }
1055 
1057  edm::LogVerbatim("HBHEMuon") << "endRun[" << nRun_ << "] " << iRun.run() << "\n";
1058  ++nRun_;
1059 }
1060 
1061 // ------------ methods called by produce() ------------
1062 
1064  HcalDetId kd1(id1.subdet(), id1.ieta(), id1.iphi(), 1);
1065  HcalDetId kd2(id1.subdet(), id2.ieta(), id2.iphi(), 1);
1066  int match = ((kd1 == kd2) ? 1 : 0);
1067  return match;
1068 }
1069 
1071  HcalDetId id(id0);
1072  int ieta = id.ietaAbs();
1073  int zside = id.zside();
1074  int iphi = id.iphi();
1075  std::vector<int> dpths;
1076  if (mergedDepth_) {
1077  std::vector<HcalDetId> ids;
1078  hdc->unmergeDepthDetId(id, ids);
1079  for (auto idh : ids)
1080  dpths.emplace_back(idh.depth());
1081  } else {
1082  dpths.emplace_back(id.depth());
1083  }
1084  double lx(0);
1085  if (id.subdet() == HcalBarrel) {
1086  for (unsigned int i = 0; i < actHB.size(); ++i) {
1087  if ((ieta == actHB[i].ieta) && (zside == actHB[i].zside) &&
1088  (std::find(dpths.begin(), dpths.end(), actHB[i].depth) != dpths.end()) &&
1089  (std::find(actHB[i].iphis.begin(), actHB[i].iphis.end(), iphi) != actHB[i].iphis.end())) {
1090  lx += actHB[i].thick;
1091  }
1092  }
1093  } else {
1094  for (unsigned int i = 0; i < actHE.size(); ++i) {
1095  if ((ieta == actHE[i].ieta) && (zside == actHE[i].zside) &&
1096  (std::find(dpths.begin(), dpths.end(), actHE[i].depth) != dpths.end()) &&
1097  (std::find(actHE[i].iphis.begin(), actHE[i].iphis.end(), iphi) != actHE[i].iphis.end())) {
1098  lx += actHE[i].thick;
1099  }
1100  }
1101  }
1102  return lx;
1103 }
1104 
1106  if (vtx.isFake())
1107  return false;
1108  if (vtx.ndof() < 4)
1109  return false;
1110  if (vtx.position().Rho() > 2.)
1111  return false;
1112  if (fabs(vtx.position().Z()) > 24.)
1113  return false;
1114  return true;
1115 }
1116 
1117 double AlCaHcalHBHEMuonProducer::respCorr(const DetId& id, const HcalRespCorrs* respCorrs) {
1118  double cfac(1.0);
1119  if (useMyCorr_) {
1120  auto itr = corrValue_.find(id);
1121  if (itr != corrValue_.end())
1122  cfac = itr->second;
1123  } else if (respCorrs != nullptr) {
1124  cfac = (respCorrs->getValues(id))->getValue();
1125  }
1126  return cfac;
1127 }
1128 
1130  double gain(0.0);
1131  const HcalCalibrations& calibs = conditions->getHcalCalibrations(id);
1132  for (int capid = 0; capid < 4; ++capid)
1133  gain += (0.25 * calibs.respcorrgain(capid));
1134  return gain;
1135 }
1136 
1137 int AlCaHcalHBHEMuonProducer::depth16HE(int ieta, int iphi, const HcalTopology* theHBHETopology) {
1138  // Transition between HB/HE is special
1139  // For Run 1 or for Plan1 standard reconstruction it is 3
1140  // For runs beyond 2018 or in Plan1 for HEP17 it is 4
1141  int zside = (ieta > 0) ? 1 : -1;
1142  int depth = theHBHETopology->dddConstants()->getMinDepth(1, 16, iphi, zside);
1143  if (isItPlan1_ && (!isItPreRecHit_))
1144  depth = 3;
1145 #ifdef EDM_ML_DEBUG
1146  edm::LogVerbatim("HBHEMuon") << "Plan1 " << isItPlan1_ << " PreRecHit " << isItPreRecHit_ << " phi " << iphi
1147  << " depth " << depth;
1148 #endif
1149  return depth;
1150 }
1151 
1153  const reco::Track* pTrack,
1154  const CaloGeometry* geo,
1155  const MagneticField* bField,
1156  const HcalDDDRecConstants* hdc) {
1157  std::pair<double, double> rz = hdc->getRZ(hcid);
1158  bool typeRZ = (hcid.subdet() == HcalEndcap) ? false : true;
1159  bool match = spr::propagateHCAL(pTrack, geo, bField, typeRZ, rz, (((verbosity_ / 10000) % 10) > 0));
1160  return match;
1161 }
1162 
1163 //define this as a plug-in
1165 
int getMinDepth(const int &itype, const int &ieta, const int &iphi, const int &zside) const
AlCaHcalHBHEMuonProducer(const edm::ParameterSet &, const alcaHcalHBHEMuonProducer::Counters *)
Log< level::Info, true > LogVerbatim
void beginRun(edm::Run const &, edm::EventSetup const &) override
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)
int depth16HE(int ieta, int iphi, const HcalTopology *theHBHETopology)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static const TGPicture * info(bool iBackgroundIsBlack)
const edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > tok_magField_
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
bool goodCell(const HcalDetId &hcid, const reco::Track *pTrack, const CaloGeometry *geo, const MagneticField *bField, const HcalDDDRecConstants *hdc)
const edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcd > tok_respcorr0_
HcalDetId mergedDepthDetId(const HcalDetId &id) const
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > tok_htopo0_
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
const float chg[109]
Definition: CoreSimTrack.cc:5
const edm::ESGetToken< HcalDbService, HcalDbRecord > tok_dbservice_
std::pair< math::XYZPoint, bool > propagateHCAL(const reco::Track *, const MagneticField *, bool debug=false)
std::vector< float > hcalDepthEnergyCorrRaw_
std::vector< float > hcalDepthEnergyRaw_
std::vector< float > hcalDepthEnergy_
std::vector< float > hcalDepthEnergyHotRaw_
~AlCaHcalHBHEMuonProducer() override=default
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tok_geom1_
std::vector< float > hcalDepthChargeHotRaw_
int zside(DetId const &)
std::vector< bool > hcalDepthMatchHot_
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
std::vector< float > hcalDepthChargeHotBGRaw_
std::vector< HcalDDDRecConstants::HcalActiveLength > actHE
std::vector< float > hcalDepthEnergyHotAux_
std::vector< float > hcalDepthEnergyHotCorr_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
const Item * getValues(DetId fId, bool throwOnFail=true) const
const edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > tok_sevlv_
U second(std::pair< T, U > const &p)
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
bool isGoodVertex(const reco::Vertex &vtx)
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ CellNeighborsVector< TrackerTraits > const CellTracksVector< TrackerTraits > const OuterHitOfCell< TrackerTraits > const int32_t uint32_t Counters * counters
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
double activeLength(const DetId &, const HcalDDDRecConstants *hdc)
dictionary corr
const std::vector< std::string > trigNames_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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)
double respCorr(const DetId &id, const HcalRespCorrs *respCorrs)
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
std::vector< std::string > all_triggers_
const edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > tok_chan_
const edm::ESGetToken< EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd > tok_ecalPFRecHitThresholds_
std::vector< float > hcalDepthChargeHotAux_
std::vector< float > hcalDepthEnergyHot_
const edm::ESGetToken< HcalDDDRecConstants, HcalRecNumberingRecord > tok_ddrec1_
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
void endRun(edm::Run const &, edm::EventSetup const &) override
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< float > hcalDepthEnergyCorr_
std::vector< float > hcalDepthActiveLength_
static std::string const triggerResults
Definition: EdmProvDump.cc:47
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > tok_htopo1_
constexpr double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
std::vector< float > hcalDepthEnergyAux_
std::vector< float > hcalDepthEnergyHotCorrRaw_
Definition: DetId.h:17
std::vector< float > hcalDepthChargeHotBG_
std::map< DetId, double > corrValue_
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
const edm::ESGetToken< CaloTopology, CaloTopologyRecord > tok_topo_
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< CaloGeometry, CaloGeometryRecord > tok_geom0_
bool validHcal(const HcalDetId &id) const
fixed size matrix
HLT enums.
const edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcd > tok_respcorr1_
std::vector< float > hcalDepthChargeHot_
const edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
static void globalEndJob(const alcaHcalHBHEMuonProducer::Counters *counters)
std::vector< HcalActiveLength > getThickActive(const int &type) const
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:164
std::vector< float > hcalDepthEnergyCorrAux_
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
std::vector< bool > hcalDepthMatch_
double gainFactor(const HcalDbService *dbserv, const HcalDetId &id)
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< HcalDDDRecConstants::HcalActiveLength > actHB
const edm::EDGetTokenT< reco::VertexCollection > tok_Vtx_
void unmergeDepthDetId(const HcalDetId &id, std::vector< HcalDetId > &ids) const
int matchId(const HcalDetId &, const HcalDetId &)
std::vector< float > hcalDepthEnergyHotCorrAux_
Log< level::Warning, false > LogWarning
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
std::vector< float > hcalDepthActiveLengthHot_
static std::unique_ptr< alcaHcalHBHEMuonProducer::Counters > initializeGlobalCache(edm::ParameterSet const &)
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)
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
def move(src, dest)
Definition: eostools.py:511
void setTopo(const HcalTopology *topo)
Definition: Run.h:45
void produce(edm::Event &, const edm::EventSetup &) override
const edm::ESGetToken< HcalDDDRecConstants, HcalRecNumberingRecord > tok_ddrec0_
const edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
std::vector< float > hcalDepthChargeHotBGAux_
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)
const edm::EDGetTokenT< EcalRecHitCollection > tok_EE_