CMS 3D CMS Logo

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