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