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