CMS 3D CMS Logo

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