CMS 3D CMS Logo

HcalHBHEMuonAnalyzer.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
19 
27 
29 
39 
42 
45 
49 
53 
57 
69 
70 //#define EDM_ML_DEBUG
71 
72 class HcalHBHEMuonAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns,edm::one::SharedResources> {
73 
74 public:
75  explicit HcalHBHEMuonAnalyzer(const edm::ParameterSet&);
76 
77  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
78 
79 private:
80  void beginJob() override;
81  void analyze(edm::Event const&, edm::EventSetup const&) override;
82  void beginRun(edm::Run const&, edm::EventSetup const&) override;
83  void endRun(edm::Run const&, edm::EventSetup const&) override {}
86  void clearVectors();
87  int matchId(const HcalDetId&, const HcalDetId&);
88  double activeLength(const DetId&);
89  bool isGoodVertex(const reco::Vertex& vtx);
90  double respCorr(const DetId& id);
91  double gainFactor(const edm::ESHandle<HcalDbService>&, const HcalDetId& id);
92  int depth16HE(int ieta, int iphi);
93  bool goodCell(const HcalDetId& hcid, const reco::Track* pTrack,
94  const CaloGeometry* geo, const MagneticField* bField);
95 
96  // ----------member data ---------------------------
102  std::vector<std::string> triggers_;
107 
111 
119 
121  static const int depthMax_ = 7;
122  TTree *tree_;
124  unsigned int goodVertex_;
126  std::vector<double> ptGlob_, etaGlob_, phiGlob_, energyMuon_, pMuon_;
129  std::vector<bool> innerTrack_, outerTrack_, globalTrack_;
130  std::vector<double> chiTracker_, dxyTracker_, dzTracker_;
132  std::vector<double> tight_validFraction_, outerTrackChi_;
136  std::vector<int> globalMuonHits_, matchedStat_;
138  std::vector<double> isolationR04_, isolationR03_;
139  std::vector<double> ecalEnergy_, hcalEnergy_, hoEnergy_;
140  std::vector<bool> matchedId_, hcalHot_;
141  std::vector<double> ecal3x3Energy_, hcal1x1Energy_;
142  std::vector<unsigned int> ecalDetId_, hcalDetId_, ehcalDetId_;
143  std::vector<double> hcalDepthEnergy_[depthMax_];
144  std::vector<double> hcalDepthActiveLength_[depthMax_];
145  std::vector<double> hcalDepthEnergyHot_[depthMax_];
146  std::vector<double> hcalDepthActiveLengthHot_[depthMax_];
147  std::vector<double> hcalDepthChargeHot_[depthMax_];
148  std::vector<double> hcalDepthChargeHotBG_[depthMax_];
149  std::vector<double> hcalDepthEnergyCorr_[depthMax_];
150  std::vector<double> hcalDepthEnergyHotCorr_[depthMax_];
151  std::vector<bool> hcalDepthMatch_[depthMax_];
152  std::vector<bool> hcalDepthMatchHot_[depthMax_];
154  std::vector<std::string> all_triggers_;
155  std::vector<int> hltresults_;
156 
157  std::vector<HcalDDDRecConstants::HcalActiveLength> actHB, actHE;
158  std::map<DetId,double> corrValue_;
160 
161 };
162 
164 
165  usesResource(TFileService::kSharedResource);
166  //now do what ever initialization is needed
167  kount_ = 0;
168  HLTriggerResults_ = iConfig.getParameter<edm::InputTag>("HLTriggerResults");
169  labelBS_ = iConfig.getParameter<std::string>("LabelBeamSpot");
170  labelVtx_ = iConfig.getParameter<std::string>("LabelVertex");
171  labelEBRecHit_ = iConfig.getParameter<edm::InputTag>("LabelEBRecHit");
172  labelEERecHit_ = iConfig.getParameter<edm::InputTag>("LabelEERecHit");
173  labelHBHERecHit_ = iConfig.getParameter<edm::InputTag>("LabelHBHERecHit");
174  labelMuon_ = iConfig.getParameter<std::string>("LabelMuon");
175  triggers_ = iConfig.getParameter<std::vector<std::string>>("Triggers");
176  useRaw_ = iConfig.getParameter<bool>("UseRaw");
177  unCorrect_ = iConfig.getParameter<bool>("UnCorrect");
178  getCharge_ = iConfig.getParameter<bool>("GetCharge");
179  collapseDepth_ = iConfig.getParameter<bool>("CollapseDepth");
180  isItPlan1_ = iConfig.getParameter<bool>("IsItPlan1");
181  ignoreHECorr_ = iConfig.getUntrackedParameter<bool>("IgnoreHECorr",false);
182  isItPreRecHit_ = iConfig.getUntrackedParameter<bool>("IsItPreRecHit",false);
183  verbosity_ = iConfig.getUntrackedParameter<int>("Verbosity",0);
184  maxDepth_ = iConfig.getUntrackedParameter<int>("MaxDepth",4);
185  if (maxDepth_ > depthMax_) maxDepth_ = depthMax_;
186  else if (maxDepth_ < 1) maxDepth_ = 4;
187  std::string modnam = iConfig.getUntrackedParameter<std::string>("ModuleName","");
188  std::string procnm = iConfig.getUntrackedParameter<std::string>("ProcessName","");
189  fileInCorr_ = iConfig.getUntrackedParameter<std::string>("FileInCorr","");
190  writeRespCorr_ = iConfig.getUntrackedParameter<bool>("WriteRespCorr",false);
191 
192  mergedDepth_ = (!isItPreRecHit_) || (collapseDepth_);
193  tok_trigRes_ = consumes<edm::TriggerResults>(HLTriggerResults_);
194  tok_bs_ = consumes<reco::BeamSpot>(labelBS_);
195  tok_EB_ = consumes<EcalRecHitCollection>(labelEBRecHit_);
196  tok_EE_ = consumes<EcalRecHitCollection>(labelEERecHit_);
197  tok_HBHE_ = consumes<HBHERecHitCollection>(labelHBHERecHit_);
198  if (modnam == "") {
199  tok_Vtx_ = consumes<reco::VertexCollection>(labelVtx_);
200  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
201  edm::LogVerbatim("HBHEMuon") << "Labels used: Trig " << HLTriggerResults_
202  << " Vtx " << labelVtx_ << " EB "
203  << labelEBRecHit_ << " EE "
204  << labelEERecHit_ << " HBHE "
205  << labelHBHERecHit_ << " MU " << labelMuon_;
206  } else {
207  tok_Vtx_ = consumes<reco::VertexCollection>(edm::InputTag(modnam,labelVtx_,procnm));
208  tok_Muon_ = consumes<reco::MuonCollection>(edm::InputTag(modnam,labelMuon_,procnm));
209  edm::LogVerbatim("HBHEMuon") << "Labels used Trig " << HLTriggerResults_
210  << "\n Vtx " << edm::InputTag(modnam,labelVtx_,procnm)
211  << "\n EB " << labelEBRecHit_
212  << "\n EE " << labelEERecHit_
213  << "\n HBHE " << labelHBHERecHit_
214  << "\n MU " << edm::InputTag(modnam,labelMuon_,procnm);
215  }
216 
217  if (fileInCorr_ != "") {
218  std::ifstream infile(fileInCorr_.c_str());
219  if (infile.is_open()) {
220  while (true) {
221  unsigned int id;
222  double cfac;
223  infile >> id >> cfac;
224  if (!infile.good()) break;
225  corrValue_[DetId(id)] = cfac;
226  }
227  infile.close();
228  }
229  }
230  useMyCorr_ = (!corrValue_.empty());
231  edm::LogVerbatim("HBHEMuon") << "Flags used: UseRaw " << useRaw_
232  << " GetCharge " << getCharge_ << " UnCorrect "
233  << unCorrect_ << " IgnoreHECorr "
234  << ignoreHECorr_ << " CollapseDepth "
235  << collapseDepth_ << ":" << mergedDepth_
236  << " IsItPlan1 " << isItPlan1_
237  << " IsItPreRecHit " << isItPreRecHit_
238  << " UseMyCorr " << useMyCorr_;
239 }
240 
241 //
242 // member functions
243 //
244 
245 // ------------ method called for each event ------------
247  ++kount_;
248  clearVectors();
249  runNumber_ = iEvent.id().run();
250  eventNumber_ = iEvent.id().event();
251  lumiNumber_ = iEvent.id().luminosityBlock();
252  bxNumber_ = iEvent.bunchCrossing();
253 #ifdef EDM_ML_DEBUG
254  edm::LogVerbatim("HBHEMuon") << "Run " << runNumber_ << " Event "
255  << eventNumber_ << " Lumi " << lumiNumber_
256  << " BX " << bxNumber_ << std::endl;
257 #endif
259  iEvent.getByToken(tok_trigRes_, _Triggers);
260 #ifdef EDM_ML_DEBUG
261  if ((verbosity_/10000)%10>0)
262  edm::LogVerbatim("HBHEMuon") << "Size of all triggers "
263  << all_triggers_.size() << std::endl;
264 #endif
265  int Ntriggers = all_triggers_.size();
266 #ifdef EDM_ML_DEBUG
267  if ((verbosity_/10000)%10>0)
268  edm::LogVerbatim("HBHEMuon") << "Size of HLT MENU: " << _Triggers->size()
269  << std::endl;
270 #endif
271  if (_Triggers.isValid()) {
272  const edm::TriggerNames &triggerNames_ = iEvent.triggerNames(*_Triggers);
273  std::vector<int> index;
274  for (int i=0; i<Ntriggers; i++) {
275  index.push_back(triggerNames_.triggerIndex(all_triggers_[i]));
276  int triggerSize = int( _Triggers->size());
277 #ifdef EDM_ML_DEBUG
278  if ((verbosity_/10000)%10>0)
279  edm::LogVerbatim("HBHEMuon") << "outside loop " << index[i]
280  << "\ntriggerSize " << triggerSize
281  << std::endl;
282 #endif
283  if (index[i] < triggerSize) {
284  hltresults_.push_back(_Triggers->accept(index[i]));
285 #ifdef EDM_ML_DEBUG
286  if ((verbosity_/10000)%10>0)
287  edm::LogVerbatim("HBHEMuon") << "Trigger_info " << triggerSize
288  << " triggerSize " << index[i]
289  << " trigger_index " << hltresults_.at(i)
290  << " hltresult" << std::endl;
291 #endif
292  } else {
293  if ((verbosity_/10000)%10>0)
294  edm::LogVerbatim("HBHEMuon") << "Requested HLT path \""
295  << "\" does not exist\n";
296  }
297  }
298  }
299 
300  // get handles to calogeometry and calotopology
302  iSetup.get<CaloGeometryRecord>().get(pG);
303  const CaloGeometry* geo = pG.product();
304 
306  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
307  const MagneticField* bField = bFieldH.product();
308 
310  iSetup.get<EcalChannelStatusRcd>().get(ecalChStatus);
311  const EcalChannelStatus* theEcalChStatus = ecalChStatus.product();
312 
314  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
315 
316  edm::ESHandle<CaloTopology> theCaloTopology;
317  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
318  const CaloTopology *caloTopology = theCaloTopology.product();
319 
320  edm::ESHandle<HcalDbService> conditions;
321  iSetup.get<HcalDbRecord>().get(conditions);
322 
323  // Relevant blocks from iEvent
325  iEvent.getByToken(tok_Vtx_, vtx);
326  edm::Handle<reco::BeamSpot> beamSpotH;
327  iEvent.getByToken(tok_bs_, beamSpotH);
328 
329  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
330  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
331  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
332  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
333 
335  iEvent.getByToken(tok_HBHE_, hbhe);
336 
338  iEvent.getByToken(tok_Muon_, _Muon);
339 
340  // require a good vertex
341  math::XYZPoint pvx;
342  bool goodVtx(false);
343  goodVertex_ = 0;
344  if (vtx.isValid()) {
345  reco::VertexCollection::const_iterator firstGoodVertex = vtx->end();
346  for (reco::VertexCollection::const_iterator it = vtx->begin();
347  it != vtx->end(); it++) {
348  if (isGoodVertex(*it)) {
349  if (firstGoodVertex == vtx->end()) firstGoodVertex = it;
350  ++goodVertex_;
351  }
352  }
353  if (firstGoodVertex != vtx->end()) {
354  pvx = firstGoodVertex->position();
355  goodVtx = true;
356  }
357  }
358  if (!goodVtx) {
359  if (beamSpotH.isValid()) {
360  pvx = beamSpotH->position();
361  goodVtx = true;
362  }
363  }
364  if (!goodVtx) {
365 #ifdef EDM_ML_DEBUG
366  edm::LogVerbatim("HBHEMuon") << "No Good Vertex found == Reject\n";
367 #endif
368  return;
369  }
370 
371  bool accept(false);
372  if (_Muon.isValid() && barrelRecHitsHandle.isValid() &&
373  endcapRecHitsHandle.isValid() && hbhe.isValid()) {
374  for (reco::MuonCollection::const_iterator RecMuon = _Muon->begin(); RecMuon!= _Muon->end(); ++RecMuon) {
375 
376  muon_is_good_.push_back(RecMuon->isPFMuon());
377  muon_global_.push_back(RecMuon->isGlobalMuon());
378  muon_tracker_.push_back(RecMuon->isTrackerMuon());
379  ptGlob_.push_back((RecMuon)->pt());
380  etaGlob_.push_back(RecMuon->eta());
381  phiGlob_.push_back(RecMuon->phi());
382  energyMuon_.push_back(RecMuon->energy());
383  pMuon_.push_back(RecMuon->p());
384 #ifdef EDM_ML_DEBUG
385  edm::LogVerbatim("HBHEMuon") << "Energy:" << RecMuon->energy() << " P:"
386  << RecMuon->p() << std::endl;
387 #endif
388  muon_trkKink.push_back(RecMuon->combinedQuality().trkKink);
389  muon_chi2LocalPosition.push_back(RecMuon->combinedQuality().chi2LocalPosition);
390  muon_segComp.push_back(muon::segmentCompatibility(*RecMuon));
391  // acessing tracker hits info
392  if (RecMuon->track().isNonnull()) {
393  trackerLayer_.push_back(RecMuon->track()->hitPattern().trackerLayersWithMeasurement());
394  } else {
395  trackerLayer_.push_back(-1);
396  }
397  if (RecMuon->innerTrack().isNonnull()) {
398  innerTrack_.push_back(true);
399  numPixelLayers_.push_back(RecMuon->innerTrack()->hitPattern().pixelLayersWithMeasurement());
400  chiTracker_.push_back(RecMuon->innerTrack()->normalizedChi2());
401  dxyTracker_.push_back(fabs(RecMuon->innerTrack()->dxy(pvx)));
402  dzTracker_.push_back(fabs(RecMuon->innerTrack()->dz(pvx)));
403  innerTrackpt_.push_back(RecMuon->innerTrack()->pt());
404  innerTracketa_.push_back(RecMuon->innerTrack()->eta());
405  innerTrackphi_.push_back(RecMuon->innerTrack()->phi());
406  tight_PixelHits_.push_back(RecMuon->innerTrack()->hitPattern().numberOfValidPixelHits());
407  tight_validFraction_.push_back(RecMuon->innerTrack()->validFraction());
408  } else {
409  innerTrack_.push_back(false);
410  numPixelLayers_.push_back(0);
411  chiTracker_.push_back(0);
412  dxyTracker_.push_back(0);
413  dzTracker_.push_back(0);
414  innerTrackpt_.push_back(0);
415  innerTracketa_.push_back(0);
416  innerTrackphi_.push_back(0);
417  tight_PixelHits_.push_back(0);
418  tight_validFraction_.push_back(-99);
419  }
420  // outer track info
421  if (RecMuon->outerTrack().isNonnull()) {
422  outerTrack_.push_back(true);
423  outerTrackPt_.push_back(RecMuon->outerTrack()->pt());
424  outerTrackEta_.push_back(RecMuon->outerTrack()->eta());
425  outerTrackPhi_.push_back(RecMuon->outerTrack()->phi());
426  outerTrackChi_.push_back(RecMuon->outerTrack()->normalizedChi2());
427  outerTrackHits_.push_back(RecMuon->outerTrack()->numberOfValidHits());
428  outerTrackRHits_.push_back(RecMuon->outerTrack()->recHitsSize());
429  } else {
430  outerTrack_.push_back(false);
431  outerTrackPt_.push_back(0);
432  outerTrackEta_.push_back(0);
433  outerTrackPhi_.push_back(0);
434  outerTrackChi_.push_back(0);
435  outerTrackHits_.push_back(0);
436  outerTrackRHits_.push_back(0);
437  }
438  // Tight Muon cuts
439  if (RecMuon->globalTrack().isNonnull()) {
440  globalTrack_.push_back(true);
441  chiGlobal_.push_back(RecMuon->globalTrack()->normalizedChi2());
442  globalMuonHits_.push_back(RecMuon->globalTrack()->hitPattern().numberOfValidMuonHits());
443  matchedStat_.push_back(RecMuon->numberOfMatchedStations());
444  globalTrckPt_.push_back(RecMuon->globalTrack()->pt());
445  globalTrckEta_.push_back(RecMuon->globalTrack()->eta());
446  globalTrckPhi_.push_back(RecMuon->globalTrack()->phi());
447  tight_TransImpara_.push_back(fabs(RecMuon->muonBestTrack()->dxy(pvx)));
448  tight_LongPara_.push_back(fabs(RecMuon->muonBestTrack()->dz(pvx)));
449  } else {
450  globalTrack_.push_back(false);
451  chiGlobal_.push_back(0);
452  globalMuonHits_.push_back(0);
453  matchedStat_.push_back(0);
454  globalTrckPt_.push_back(0);
455  globalTrckEta_.push_back(0);
456  globalTrckPhi_.push_back(0);
457  tight_TransImpara_.push_back(0);
458  tight_LongPara_.push_back(0);
459  }
460 
461  isolationR04_.push_back(((RecMuon->pfIsolationR04().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR04().sumNeutralHadronEt + RecMuon->pfIsolationR04().sumPhotonEt - (0.5 *RecMuon->pfIsolationR04().sumPUPt))) / RecMuon->pt()) );
462 
463  isolationR03_.push_back(((RecMuon->pfIsolationR03().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR03().sumNeutralHadronEt + RecMuon->pfIsolationR03().sumPhotonEt - (0.5 * RecMuon->pfIsolationR03().sumPUPt))) / RecMuon->pt()));
464 
465  ecalEnergy_.push_back(RecMuon->calEnergy().emS9);
466  hcalEnergy_.push_back(RecMuon->calEnergy().hadS9);
467  hoEnergy_.push_back(RecMuon->calEnergy().hoS9);
468 
469  double eEcal(0), eHcal(0), activeLengthTot(0), activeLengthHotTot(0);
470  double eHcalDepth[depthMax_], eHcalDepthHot[depthMax_];
471  double eHcalDepthC[depthMax_], eHcalDepthHotC[depthMax_];
472  double cHcalDepthHot[depthMax_], cHcalDepthHotBG[depthMax_];
473  double activeL[depthMax_], activeHotL[depthMax_];
474  bool matchDepth[depthMax_], matchDepthHot[depthMax_];
475  HcalDetId eHcalDetId[depthMax_];
476  unsigned int isHot(0);
477  bool tmpmatch(false);
478  for (int i=0; i<depthMax_; ++i) {
479  eHcalDepth[i] = eHcalDepthHot[i] = 0;
480  eHcalDepthC[i] = eHcalDepthHotC[i] = 0;
481  cHcalDepthHot[i] = cHcalDepthHotBG[i]= 0;
482  activeL[i] = activeHotL[i] = 0;
483  matchDepth[i] = matchDepthHot[i] = true;
484  }
485  if (RecMuon->innerTrack().isNonnull()) {
486  const reco::Track* pTrack = (RecMuon->innerTrack()).get();
487  spr::propagatedTrackID trackID = spr::propagateCALO(pTrack, geo, bField, (((verbosity_/100)%10>0)));
488  if ((RecMuon->p()>10.0) && (trackID.okHCAL)) accept = true;
489 
490  ecalDetId_.push_back((trackID.detIdECAL)());
491  hcalDetId_.push_back((trackID.detIdHCAL)());
492  ehcalDetId_.push_back((trackID.detIdEHCAL)());
493 
495  std::pair<bool,HcalDetId> info = spr::propagateHCALBack(pTrack, geo, bField, (((verbosity_/100)%10>0)));
496  if (info.first) {
497  check = info.second;
498  }
499 
500  bool okE = trackID.okECAL;
501  if (okE) {
502  const DetId isoCell(trackID.detIdECAL);
503  std::pair<double,bool> e3x3 = spr::eECALmatrix(isoCell,barrelRecHitsHandle,endcapRecHitsHandle,*theEcalChStatus,geo,caloTopology,sevlv.product(),1,1,-100.0,-100.0,-500.0,500.0,false);
504  eEcal = e3x3.first;
505  okE = e3x3.second;
506  }
507 #ifdef EDM_ML_DEBUG
508  edm::LogVerbatim("HBHEMuon") << "Propagate Track to ECAL: " << okE
509  << ":" << trackID.okECAL << " E " <<eEcal;
510 #endif
511 
512  if (trackID.okHCAL) {
513  DetId closestCell(trackID.detIdHCAL);
514  HcalDetId hcidt(closestCell.rawId());
515  if ((hcidt.ieta() == check.ieta()) && (hcidt.iphi() == check.iphi()))
516  tmpmatch = true;
517 #ifdef EDM_ML_DEBUG
518  edm::LogVerbatim("HBHEMuon") << "Front " << hcidt << " Back "
519  << info.first << ":" << check
520  << " Match " << tmpmatch;
521 #endif
522 
523  HcalSubdetector subdet = hcidt.subdet();
524  int ieta = hcidt.ieta();
525  int iphi = hcidt.iphi();
526  bool hborhe = (std::abs(ieta) == 16);
527 
528  eHcal = spr::eHCALmatrix(theHBHETopology_, closestCell, hbhe,0,0, false, true, -100.0, -100.0, -100.0, -100.0, -500.,500.,useRaw_);
529  std::vector<std::pair<double,int> > ehdepth;
530  spr::energyHCALCell((HcalDetId)closestCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, useRaw_, depth16HE(ieta,iphi), (((verbosity_/1000)%10)>0));
531  for (int i=0; i<depthMax_; ++i) eHcalDetId[i] = HcalDetId();
532  for (unsigned int i=0; i<ehdepth.size(); ++i) {
533  HcalSubdetector subdet0 = (hborhe) ? ((ehdepth[i].second >= depth16HE(ieta,iphi)) ? HcalEndcap : HcalBarrel) : subdet;
534  HcalDetId hcid0(subdet0,ieta,iphi,ehdepth[i].second);
535  double actL = activeLength(DetId(hcid0));
536  double ene = ehdepth[i].first;
537  bool tmpC(false);
538  if (ene > 0.0) {
539  if (!(theHBHETopology_->validHcal(hcid0))) {
540  edm::LogWarning("HBHEMuon") << "(1) Invalid ID " << hcid0
541  << " with E = " << ene;
542  edm::LogWarning("HBHEMuon") << HcalDetId(closestCell)
543  << " with " << ehdepth.size()
544  << " depths:";
545  for (const auto& ehd : ehdepth)
546  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":"
547  << ehd.first;
548  } else {
549  tmpC = goodCell(hcid0, pTrack, geo, bField);
550  double enec(ene);
551  if (unCorrect_) {
552  double corr = (ignoreHECorr_ && (subdet0==HcalEndcap)) ? 1.0 : respCorr(DetId(hcid0));
553  if (corr != 0) ene /= corr;
554 #ifdef EDM_ML_DEBUG
555  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc_->mergedDepthDetId(hcid0) : hcid0;
556  edm::LogVerbatim("HBHEMuon") << hcid0 << ":" << id << " Corr "
557  << corr;
558 #endif
559  }
560  int depth = ehdepth[i].second - 1;
561  if (collapseDepth_) {
562  HcalDetId id = hdc_->mergedDepthDetId(hcid0);
563  depth = id.depth() - 1;
564  }
565  eHcalDepth[depth] += ene;
566  eHcalDepthC[depth]+= enec;
567  activeL[depth] += actL;
568  activeLengthTot += actL;
569  matchDepth[depth] = (matchDepth[depth] && tmpC);
570 #ifdef EDM_ML_DEBUG
571  if ((verbosity_%10) > 0)
572  edm::LogVerbatim("HBHEMuon") << hcid0 << " E " << ene << ":"
573  << enec << " L " << actL
574  << " Match " << tmpC;
575 #endif
576  }
577  }
578  }
579 #ifdef EDM_ML_DEBUG
580  if ((verbosity_%10) > 0) {
581  std::cout << hcidt << " Match " << tmpmatch << " Depths "
582  << ehdepth.size();
583  for (unsigned int k=0; k<ehdepth.size(); ++k)
584  std::cout << " [" << ehdepth[k].second << "] " << matchDepth[k];
585  std::cout << std::endl;
586  }
587 #endif
588  HcalDetId hotCell;
589  spr::eHCALmatrix(geo, theHBHETopology_, closestCell, hbhe, 1,1, hotCell, false, useRaw_, false);
590  isHot = matchId(closestCell,hotCell);
591  if (hotCell != HcalDetId()) {
592  subdet = HcalDetId(hotCell).subdet();
593  ieta = HcalDetId(hotCell).ieta();
594  iphi = HcalDetId(hotCell).iphi();
595  hborhe = (std::abs(ieta) == 16);
596  std::vector<std::pair<double,int> > ehdepth;
597  spr::energyHCALCell(hotCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, useRaw_, depth16HE(ieta,iphi), false);//(((verbosity_/1000)%10)>0 ));
598  for (int i=0; i<depthMax_; ++i) eHcalDetId[i] = HcalDetId();
599  for (unsigned int i=0; i<ehdepth.size(); ++i) {
600  HcalSubdetector subdet0 = (hborhe) ? ((ehdepth[i].second >= depth16HE(ieta,iphi)) ? HcalEndcap : HcalBarrel) : subdet;
601  HcalDetId hcid0(subdet0,ieta,iphi,ehdepth[i].second);
602  double actL = activeLength(DetId(hcid0));
603  double ene = ehdepth[i].first;
604  bool tmpC(false);
605  if (ene > 0.0) {
606  if (!(theHBHETopology_->validHcal(hcid0))) {
607  edm::LogWarning("HBHEMuon") << "(2) Invalid ID " << hcid0
608  << " with E = " << ene;
609  edm::LogWarning("HBHEMuon") << HcalDetId(hotCell)
610  << " with " << ehdepth.size()
611  << " depths:";
612  for (const auto& ehd : ehdepth)
613  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":"
614  << ehd.first;
615  } else {
616  tmpC = goodCell(hcid0, pTrack, geo, bField);
617  double chg(ene), enec(ene);
618  if (unCorrect_) {
619  double corr = (ignoreHECorr_ && (subdet0==HcalEndcap)) ? 1.0 : respCorr(DetId(hcid0));
620  if (corr != 0) {ene /= corr; chg /= corr;}
621 #ifdef EDM_ML_DEBUG
622  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc_->mergedDepthDetId(hcid0) : hcid0;
623  edm::LogVerbatim("HBHEMuon") << hcid0 << ":" << id
624  << " Corr " << corr << " E "
625  << ene << ":" << enec;
626 #endif
627  }
628  if (getCharge_) {
629  double gain = gainFactor(conditions,hcid0);
630  if (gain != 0) chg /= gain;
631 #ifdef EDM_ML_DEBUG
632  edm::LogVerbatim("HBHEMuon") << hcid0 << " Gain " << gain
633  << " C " << chg;
634 #endif
635  }
636  int depth = ehdepth[i].second - 1;
637  if (collapseDepth_) {
638  HcalDetId id = hdc_->mergedDepthDetId(hcid0);
639  depth = id.depth() - 1;
640  }
641  eHcalDepthHot[depth] += ene;
642  eHcalDepthHotC[depth] += enec;
643  cHcalDepthHot[depth] += chg;
644  activeHotL[depth] += actL;
645  activeLengthHotTot += actL;
646  matchDepthHot[depth] = (matchDepthHot[depth] && tmpC);
647 #ifdef EDM_ML_DEBUG
648  if ((verbosity_%10) > 0)
649  edm::LogVerbatim("HBHEMuon") << hcid0 << " depth " << depth
650  << " E " << ene << ":" << enec
651  << " C " << chg << " L "
652  << actL << " Match " << tmpC;
653 #endif
654  }
655  }
656  }
657 
658  HcalDetId oppCell(subdet,-ieta,iphi,HcalDetId(hotCell).depth());
659  std::vector<std::pair<double,int> > ehdeptho;
660  spr::energyHCALCell(oppCell, hbhe, ehdeptho, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, useRaw_, depth16HE(-ieta,iphi), false); //(((verbosity_/1000)%10)>0));
661  for (unsigned int i=0; i<ehdeptho.size(); ++i) {
662  HcalSubdetector subdet0 = (hborhe) ? ((ehdeptho[i].second >= depth16HE(-ieta,iphi)) ? HcalEndcap : HcalBarrel) : subdet;
663  HcalDetId hcid0(subdet0,-ieta,iphi,ehdeptho[i].second);
664  double ene = ehdeptho[i].first;
665  if (ene > 0.0) {
666  if (!(theHBHETopology_->validHcal(hcid0))) {
667  edm::LogWarning("HBHEMuon") << "(3) Invalid ID " << hcid0
668  << " with E = " << ene;
669  edm::LogWarning("HBHEMuon") << oppCell << " with "
670  << ehdeptho.size() << " depths:";
671  for (const auto& ehd : ehdeptho)
672  edm::LogWarning("HBHEMuon") << " " << ehd.second << ":"
673  << ehd.first;
674  } else {
675  double chg(ene);
676  if (unCorrect_) {
677  double corr = (ignoreHECorr_ && (subdet0==HcalEndcap)) ? 1.0 : respCorr(DetId(hcid0));
678  if (corr != 0) {ene /= corr; chg /= corr;}
679 #ifdef EDM_ML_DEBUG
680  HcalDetId id = (isItPlan1_ && isItPreRecHit_) ? hdc_->mergedDepthDetId(hcid0) : hcid0;
681  edm::LogVerbatim("HBHEMuon") << hcid0 << ":" << id
682  << " Corr " << corr << " E "
683  << ene << ":"
684  << ehdeptho[i].first;
685 #endif
686  }
687  if (getCharge_) {
688  double gain = gainFactor(conditions,hcid0);
689  if (gain != 0) chg /= gain;
690 #ifdef EDM_ML_DEBUG
691  edm::LogVerbatim("HBHEMuon") << hcid0 << " Gain " << gain
692  << " C " << chg;
693 #endif
694  }
695  int depth = ehdeptho[i].second - 1;
696  if (collapseDepth_) {
697  HcalDetId id = hdc_->mergedDepthDetId(hcid0);
698  depth = id.depth() - 1;
699  }
700  cHcalDepthHotBG[depth] += chg;
701 #ifdef EDM_ML_DEBUG
702  if ((verbosity_%10) > 0)
703  edm::LogVerbatim("HBHEMuon") << hcid0 << " Depth " << depth
704  << " E " << ene << " C "
705  << chg;
706 #endif
707  }
708  }
709  }
710  }
711  }
712 #ifdef EDM_ML_DEBUG
713  edm::LogVerbatim("HBHEMuon") << "Propagate Track to HCAL: "
714  << trackID.okHCAL << " Match " << tmpmatch
715  << " Hot " << isHot << " Energy "
716  << eHcal << std::endl;
717 #endif
718 
719  } else {
720  ecalDetId_.push_back(0);
721  hcalDetId_.push_back(0);
722  ehcalDetId_.push_back(0);
723  }
724 
725  matchedId_.push_back(tmpmatch);
726  ecal3x3Energy_.push_back(eEcal);
727  hcal1x1Energy_.push_back(eHcal);
728  for (int i=0; i<depthMax_; ++i) {
729  hcalDepthEnergy_[i].push_back(eHcalDepth[i]);
730  hcalDepthActiveLength_[i].push_back(activeL[i]);
731  hcalDepthEnergyHot_[i].push_back(eHcalDepthHot[i]);
732  hcalDepthActiveLengthHot_[i].push_back(activeHotL[i]);
733  hcalDepthEnergyCorr_[i].push_back(eHcalDepthC[i]);
734  hcalDepthEnergyHotCorr_[i].push_back(eHcalDepthHotC[i]);
735  hcalDepthChargeHot_[i].push_back(cHcalDepthHot[i]);
736  hcalDepthChargeHotBG_[i].push_back(cHcalDepthHotBG[i]);
737  hcalDepthMatch_[i].push_back(matchDepth[i]);
738  hcalDepthMatchHot_[i].push_back(matchDepthHot[i]);
739  }
740  hcalActiveLength_.push_back(activeLengthTot);
741  hcalHot_.push_back(isHot);
742  hcalActiveLengthHot_.push_back(activeLengthHotTot);
743  }
744  }
745  if (accept) tree_->Fill();
746 }
747 
748 // ------------ method called once each job just before starting event loop ------------
750 
751  tree_ = fs->make<TTree>("TREE", "TREE");
752  tree_->Branch("Event_No", &eventNumber_);
753  tree_->Branch("Run_No", &runNumber_);
754  tree_->Branch("LumiNumber", &lumiNumber_);
755  tree_->Branch("BXNumber", &bxNumber_);
756  tree_->Branch("GoodVertex", &goodVertex_);
757  tree_->Branch("PF_Muon", &muon_is_good_);
758  tree_->Branch("Global_Muon", &muon_global_);
759  tree_->Branch("Tracker_muon", &muon_tracker_);
760  tree_->Branch("pt_of_muon", &ptGlob_);
761  tree_->Branch("eta_of_muon", &etaGlob_);
762  tree_->Branch("phi_of_muon", &phiGlob_);
763  tree_->Branch("energy_of_muon", &energyMuon_);
764  tree_->Branch("p_of_muon", &pMuon_);
765  tree_->Branch("muon_trkKink", &muon_trkKink);
766  tree_->Branch("muon_chi2LocalPosition", &muon_chi2LocalPosition);
767  tree_->Branch("muon_segComp", &muon_segComp);
768 
769  tree_->Branch("TrackerLayer", &trackerLayer_);
770  tree_->Branch("NumPixelLayers", &numPixelLayers_);
771  tree_->Branch("InnerTrackPixelHits", &tight_PixelHits_);
772  tree_->Branch("innerTrack", &innerTrack_);
773  tree_->Branch("chiTracker", &chiTracker_);
774  tree_->Branch("DxyTracker", &dxyTracker_);
775  tree_->Branch("DzTracker", &dzTracker_);
776  tree_->Branch("innerTrackpt", &innerTrackpt_);
777  tree_->Branch("innerTracketa", &innerTracketa_);
778  tree_->Branch("innerTrackphi", &innerTrackphi_);
779  tree_->Branch("tight_validFraction", &tight_validFraction_);
780 
781  tree_->Branch("OuterTrack", &outerTrack_);
782  tree_->Branch("OuterTrackChi", &outerTrackChi_);
783  tree_->Branch("OuterTrackPt", &outerTrackPt_);
784  tree_->Branch("OuterTrackEta", &outerTrackEta_);
785  tree_->Branch("OuterTrackPhi", &outerTrackPhi_);
786  tree_->Branch("OuterTrackHits", &outerTrackHits_);
787  tree_->Branch("OuterTrackRHits", &outerTrackRHits_);
788 
789  tree_->Branch("GlobalTrack", &globalTrack_);
790  tree_->Branch("GlobalTrckPt", &globalTrckPt_);
791  tree_->Branch("GlobalTrckEta", &globalTrckEta_);
792  tree_->Branch("GlobalTrckPhi", &globalTrckPhi_);
793  tree_->Branch("Global_Muon_Hits", &globalMuonHits_);
794  tree_->Branch("MatchedStations", &matchedStat_);
795  tree_->Branch("GlobTrack_Chi", &chiGlobal_);
796  tree_->Branch("Tight_LongitudinalImpactparameter",&tight_LongPara_);
797  tree_->Branch("Tight_TransImpactparameter", &tight_TransImpara_);
798 
799  tree_->Branch("IsolationR04", &isolationR04_);
800  tree_->Branch("IsolationR03", &isolationR03_);
801  tree_->Branch("ecal_3into3", &ecalEnergy_);
802  tree_->Branch("hcal_3into3", &hcalEnergy_);
803  tree_->Branch("tracker_3into3", &hoEnergy_);
804 
805  tree_->Branch("matchedId", &matchedId_);
806  tree_->Branch("hcal_cellHot", &hcalHot_);
807 
808  tree_->Branch("ecal_3x3", &ecal3x3Energy_);
809  tree_->Branch("hcal_1x1", &hcal1x1Energy_);
810  tree_->Branch("ecal_detID", &ecalDetId_);
811  tree_->Branch("hcal_detID", &hcalDetId_);
812  tree_->Branch("ehcal_detID", &ehcalDetId_);
813 
814  char name[100];
815  for (int k=0; k<maxDepth_; ++k) {
816  sprintf (name, "hcal_edepth%d", (k+1));
817  tree_->Branch(name, &hcalDepthEnergy_[k]);
818  sprintf (name, "hcal_activeL%d", (k+1));
819  tree_->Branch(name, &hcalDepthActiveLength_[k]);
820  sprintf (name, "hcal_edepthHot%d", (k+1));
821  tree_->Branch(name, &hcalDepthEnergyHot_[k]);
822  sprintf (name, "hcal_activeHotL%d", (k+1));
823  tree_->Branch(name, &hcalDepthActiveLengthHot_[k]);
824  sprintf (name, "hcal_cdepthHot%d", (k+1));
825  tree_->Branch(name, &hcalDepthChargeHot_[k]);
826  sprintf (name, "hcal_cdepthHotBG%d", (k+1));
827  tree_->Branch(name, &hcalDepthChargeHotBG_[k]);
828  sprintf (name, "hcal_edepthCorrect%d", (k+1));
829  tree_->Branch(name, &hcalDepthEnergyCorr_[k]);
830  sprintf (name, "hcal_edepthHotCorrect%d", (k+1));
831  tree_->Branch(name, &hcalDepthEnergyHotCorr_[k]);
832  sprintf (name, "hcal_depthMatch%d", (k+1));
833  tree_->Branch(name, &hcalDepthMatch_[k]);
834  sprintf (name, "hcal_depthMatchHot%d", (k+1));
835  tree_->Branch(name, &hcalDepthMatchHot_[k]);
836  }
837 
838  tree_->Branch("activeLength", &hcalActiveLength_);
839  tree_->Branch("activeLengthHot", &hcalActiveLengthHot_);
840 
841  tree_->Branch("hltresults", &hltresults_);
842  tree_->Branch("all_triggers", &all_triggers_);
843 }
844 
845 // ------------ method called when starting to processes a run ------------
846 void HcalHBHEMuonAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
847 
849  iSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
850  hdc_ = pHRNDC.product();
851  actHB.clear();
852  actHE.clear();
853  actHB = hdc_->getThickActive(0);
854  actHE = hdc_->getThickActive(1);
855 #ifdef EDM_ML_DEBUG
856  unsigned int k1(0), k2(0);
857  edm::LogVerbatim("HBHEMuon") << actHB.size() << " Active Length for HB";
858  for (const auto& act : actHB) {
859  edm::LogVerbatim("HBHEMuon") << "[" << k1 << "] ieta " << act.ieta
860  << " depth " << act.depth << " zside "
861  << act.zside << " type " << act.stype
862  << " phi " << act.iphis.size() << ":"
863  << act.iphis[0] << " L " << act.thick;
864  HcalDetId hcid1(HcalBarrel,(act.ieta)*(act.zside),act.iphis[0],act.depth);
865  HcalDetId hcid2 = mergedDepth_ ? hdc_->mergedDepthDetId(hcid1) : hcid1;
866  edm::LogVerbatim("HBHEMuon") << hcid1 << " | " << hcid2 << " L "
867  << activeLength(DetId(hcid2));
868  ++k1;
869  }
870  edm::LogVerbatim("HBHEMuon") << actHE.size() << " Active Length for HE";
871  for (const auto& act : actHE) {
872  edm::LogVerbatim("HBHEMuon") << "[" << k2 << "] ieta " << act.ieta
873  << " depth " << act.depth << " zside "
874  << act.zside << " type " << act.stype
875  << " phi " << act.iphis.size() << ":"
876  << act.iphis[0] << " L " << act.thick;
877  HcalDetId hcid1(HcalEndcap,(act.ieta)*(act.zside),act.iphis[0],act.depth);
878  HcalDetId hcid2 = mergedDepth_ ? hdc_->mergedDepthDetId(hcid1) : hcid1;
879  edm::LogVerbatim("HBHEMuon") << hcid1 << " | " << hcid2 << " L "
880  << activeLength(DetId(hcid2));
881  ++k2;
882  }
883 #endif
884 
885  bool changed = true;
886  all_triggers_.clear();
887  if (hltConfig_.init(iRun, iSetup, "HLT" , changed)) {
888  // if init returns TRUE, initialisation has succeeded!
889 #ifdef EDM_ML_DEBUG
890  edm::LogVerbatim("HBHEMuon") << "HLT config with process name "
891  << "HLT" << " successfully extracted"
892  << std::endl;
893 #endif
894  unsigned int ntriggers = hltConfig_.size();
895  for (unsigned int t=0;t<ntriggers;++t) {
897  for (unsigned int ik=0; ik<6; ++ik) {
898  if (hltname.find(triggers_[ik])!=std::string::npos ){
899  all_triggers_.push_back(hltname);
900  break;
901  }
902  }
903  }//loop over ntriggers
904  edm::LogVerbatim("HBHEMuon") << "All triggers size in begin run "
905  << all_triggers_.size() << std::endl;
906  } else {
907  edm::LogError("HBHEMuon") << "Error! HLT config extraction with process "
908  << "name HLT failed";
909  }
910 
912  iSetup.get<HcalRecNumberingRecord>().get(htopo);
913  theHBHETopology_ = htopo.product();
914 
916  iSetup.get<HcalRespCorrsRcd>().get(resp);
917  respCorrs_ = new HcalRespCorrs(*resp.product());
919 
920  // Write correction factors for all HB/HE events
921  if (writeRespCorr_) {
923  iSetup.get<CaloGeometryRecord>().get(pG);
924  const CaloGeometry* geo = pG.product();
926  const std::vector<DetId>& ids = gHcal->getValidDetIds(DetId::Hcal,0);
927  edm::LogVerbatim("HBHEMuon") << "\nTable of Correction Factors for Run "
928  << iRun.run() << "\n";
929  for (auto const& id: ids) {
930  if ((id.det() == DetId::Hcal) &&
931  ((id.subdetId() == HcalBarrel) || (id.subdetId() == HcalEndcap))) {
932  edm::LogVerbatim("HBHEMuon") << HcalDetId(id) << " " << id.rawId() <<" "
933  << (respCorrs_->getValues(id))->getValue();
934  }
935  }
936  }
937 }
938 
939 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
942  desc.add<edm::InputTag>("HLTriggerResults",edm::InputTag("TriggerResults","","HLT"));
943  desc.add<std::string>("LabelBeamSpot","offlineBeamSpot");
944  desc.add<std::string>("LabelVertex","offlinePrimaryVertices");
945  desc.add<edm::InputTag>("LabelEBRecHit",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
946  desc.add<edm::InputTag>("LabelEERecHit",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
947  desc.add<edm::InputTag>("LabelHBHERecHit",edm::InputTag("hbhereco"));
948  desc.add<std::string>("LabelMuon","muons");
949 // std::vector<std::string> trig = {"HLT_IsoMu_","HLT_L1SingleMu_","HLT_L2Mu","HLT_Mu","HLT_RelIso1p0Mu"};
950  std::vector<std::string> trig = {"HLT_IsoMu17","HLT_IsoMu20",
951  "HLT_IsoMu24","HLT_IsoMu27",
952  "HLT_Mu45","HLT_Mu50"};
953  desc.add<std::vector<std::string>>("Triggers",trig);
954  desc.add<bool>("UseRaw",false);
955  desc.add<bool>("UnCorrect",false);
956  desc.add<bool>("GetCharge",false);
957  desc.add<bool>("CollapseDepth",false);
958  desc.add<bool>("IsItPlan1",false);
959  desc.addUntracked<bool>("IgnoreHECorr",false);
960  desc.addUntracked<bool>("IsItPreRecHit",false);
961  desc.addUntracked<std::string>("ModuleName","");
962  desc.addUntracked<std::string>("ProcessName","");
963  desc.addUntracked<int>("Verbosity",0);
964  desc.addUntracked<int>("MaxDepth",4);
965  desc.addUntracked<std::string>("FileInCorr","");
966  desc.addUntracked<bool>("WriteRespCorr",false);
967  descriptions.add("hcalHBHEMuon",desc);
968 }
969 
972  eventNumber_ = -99999;
973  runNumber_ = -99999;
974  lumiNumber_ = -99999;
975  bxNumber_ = -99999;
976  goodVertex_ = -99999;
977 
978  muon_is_good_.clear();
979  muon_global_.clear();
980  muon_tracker_.clear();
981  ptGlob_.clear();
982  etaGlob_.clear();
983  phiGlob_.clear();
984  energyMuon_.clear();
985  pMuon_.clear();
986  muon_trkKink.clear();
987  muon_chi2LocalPosition.clear();
988  muon_segComp.clear();
989 
990  trackerLayer_.clear();
991  numPixelLayers_.clear();
992  tight_PixelHits_.clear();
993  innerTrack_.clear();
994  chiTracker_.clear();
995  dxyTracker_.clear();
996  dzTracker_.clear();
997  innerTrackpt_.clear();
998  innerTracketa_.clear();
999  innerTrackphi_.clear();
1000  tight_validFraction_.clear();
1001 
1002  outerTrack_.clear();
1003  outerTrackPt_.clear();
1004  outerTrackEta_.clear();
1005  outerTrackPhi_.clear();
1006  outerTrackHits_.clear();
1007  outerTrackRHits_.clear();
1008  outerTrackChi_.clear();
1009 
1010  globalTrack_.clear();
1011  globalTrckPt_.clear();
1012  globalTrckEta_.clear();
1013  globalTrckPhi_.clear();
1014  globalMuonHits_.clear();
1015  matchedStat_.clear();
1016  chiGlobal_.clear();
1017  tight_LongPara_.clear();
1018  tight_TransImpara_.clear();
1019 
1020  isolationR04_.clear();
1021  isolationR03_.clear();
1022  ecalEnergy_.clear();
1023  hcalEnergy_.clear();
1024  hoEnergy_.clear();
1025  matchedId_.clear();
1026  hcalHot_.clear();
1027  ecal3x3Energy_.clear();
1028  hcal1x1Energy_.clear();
1029  ecalDetId_.clear();
1030  hcalDetId_.clear();
1031  ehcalDetId_.clear();
1032  for (int i=0; i<maxDepth_; ++i) {
1033  hcalDepthEnergy_[i].clear();
1034  hcalDepthActiveLength_[i].clear();
1035  hcalDepthEnergyHot_[i].clear();
1036  hcalDepthActiveLengthHot_[i].clear();
1037  hcalDepthChargeHot_[i].clear();
1038  hcalDepthChargeHotBG_[i].clear();
1039  hcalDepthEnergyCorr_[i].clear();
1040  hcalDepthEnergyHotCorr_[i].clear();
1041  hcalDepthMatch_[i].clear();
1042  hcalDepthMatchHot_[i].clear();
1043  }
1044  hcalActiveLength_.clear();
1045  hcalActiveLengthHot_.clear();
1046  hltresults_.clear();
1047 }
1048 
1050 
1051  HcalDetId kd1(id1.subdet(),id1.ieta(),id1.iphi(),1);
1052  HcalDetId kd2(id1.subdet(),id2.ieta(),id2.iphi(),1);
1053  int match = ((kd1 == kd2) ? 1 : 0);
1054  return match;
1055 }
1056 
1058  HcalDetId id(id_);
1059  int ieta = id.ietaAbs();
1060  int zside= id.zside();
1061  int iphi = id.iphi();
1062  std::vector<int> dpths;
1063  if (mergedDepth_) {
1064  std::vector<HcalDetId> ids;
1065  hdc_->unmergeDepthDetId(id,ids);
1066  for (auto idh : ids)
1067  dpths.emplace_back(idh.depth());
1068  } else {
1069  dpths.emplace_back(id.depth());
1070  }
1071  double lx(0);
1072  if (id.subdet() == HcalBarrel) {
1073  for (unsigned int i=0; i<actHB.size(); ++i) {
1074  if ((ieta == actHB[i].ieta) && (zside == actHB[i].zside) &&
1075  (std::find(dpths.begin(),dpths.end(),actHB[i].depth) != dpths.end())&&
1076  (std::find(actHB[i].iphis.begin(),actHB[i].iphis.end(),iphi) !=
1077  actHB[i].iphis.end())) {
1078  lx += actHB[i].thick;
1079  }
1080  }
1081  } else {
1082  for (unsigned int i=0; i<actHE.size(); ++i) {
1083  if ((ieta == actHE[i].ieta) && (zside == actHE[i].zside) &&
1084  (std::find(dpths.begin(),dpths.end(),actHE[i].depth) != dpths.end())&&
1085  (std::find(actHE[i].iphis.begin(),actHE[i].iphis.end(),iphi) !=
1086  actHE[i].iphis.end())) {
1087  lx += actHE[i].thick;
1088  }
1089  }
1090  }
1091  return lx;
1092 }
1093 
1095  if (vtx.isFake()) return false;
1096  if (vtx.ndof() < 4) return false;
1097  if (vtx.position().Rho() > 2.) return false;
1098  if (fabs(vtx.position().Z()) > 24.) return false;
1099  return true;
1100 }
1101 
1103  double cfac(1.0);
1104  if (useMyCorr_) {
1105  auto itr = corrValue_.find(id);
1106  if (itr != corrValue_.end()) cfac = itr->second;
1107  } else if (respCorrs_ != nullptr) {
1108  cfac = (respCorrs_->getValues(id))->getValue();
1109  }
1110  return cfac;
1111 }
1112 
1114  double gain(0.0);
1115  const HcalCalibrations& calibs=conditions->getHcalCalibrations(id);
1116  for (int capid=0; capid<4; ++capid)
1117  gain += (0.25*calibs.respcorrgain(capid));
1118  return gain;
1119 }
1120 
1121 int HcalHBHEMuonAnalyzer::depth16HE(int ieta, int iphi) {
1122  // Transition between HB/HE is special
1123  // For Run 1 or for Plan1 standard reconstruction it is 3
1124  // For runs beyond 2018 or in Plan1 for HEP17 it is 4
1125  int zside = (ieta > 0) ? 1 : -1;
1126  int depth = theHBHETopology_->dddConstants()->getMinDepth(1,16,iphi,zside);
1127  if (isItPlan1_ && (!isItPreRecHit_)) depth = 3;
1128 #ifdef EDM_ML_DEBUG
1129  edm::LogVerbatim("HBHEMuon") << "Plan1 " << isItPlan1_ << " PreRecHit "
1130  << isItPreRecHit_ << " phi " << iphi
1131  << " depth " << depth;
1132 #endif
1133  return depth;
1134 }
1135 
1137  const reco::Track* pTrack,
1138  const CaloGeometry* geo,
1139  const MagneticField* bField) {
1140 
1141  std::pair<double,double> rz = hdc_->getRZ(hcid);
1142  bool typeRZ = (hcid.subdet() == HcalEndcap) ? false : true;
1143  bool match = spr::propagateHCAL(pTrack, geo, bField, typeRZ, rz, (((verbosity_/10000)%10)>0));
1144  return match;
1145 }
1146 
1147 //define this as a plug-in
1149 
RunNumber_t run() const
Definition: EventID.h:39
unsigned int size() const
number of trigger paths in trigger table
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< double > tight_validFraction_
std::vector< int > hltresults_
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:44
EventNumber_t event() const
Definition: EventID.h:41
std::vector< double > innerTrackphi_
HcalHBHEMuonAnalyzer(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
const HcalTopology * theHBHETopology_
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:167
static const TGPicture * info(bool iBackgroundIsBlack)
double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
std::vector< std::string > all_triggers_
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, std::string &theTrackQuality, bool debug=false)
std::vector< std::string > triggers_
std::vector< double > dzTracker_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
RunNumber_t run() const
Definition: RunBase.h:40
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void analyze(edm::Event const &, edm::EventSetup const &) override
const std::string & triggerName(unsigned int triggerIndex) const
std::vector< double > outerTrackChi_
const float chg[109]
Definition: CoreSimTrack.cc:5
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
HcalDetId mergedDepthDetId(const HcalDetId &id) const
std::vector< double > hcalDepthChargeHotBG_[depthMax_]
std::vector< double > tight_LongPara_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::pair< math::XYZPoint, bool > propagateHCAL(const reco::Track *, const MagneticField *, bool debug=false)
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
std::vector< unsigned int > ecalDetId_
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
std::vector< double > pMuon_
bool accept() const
Has at least one path accepted the event?
std::vector< double > globalTrckPhi_
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, bool useRaw=false, bool debug=false)
int bunchCrossing() const
Definition: EventBase.h:66
double respCorr(const DetId &id)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const Item * getValues(DetId fId, bool throwOnFail=true) const
int zside(DetId const &)
std::vector< HcalDDDRecConstants::HcalActiveLength > actHE
bool validHcal(const HcalDetId &id) const
std::vector< double > isolationR03_
std::vector< int > outerTrackHits_
#define nullptr
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
const Point & position() const
position
Definition: Vertex.h:109
double gainFactor(const edm::ESHandle< HcalDbService > &, const HcalDetId &id)
std::vector< bool > muon_global_
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
std::vector< float > muon_trkKink
std::vector< double > hcalDepthEnergy_[depthMax_]
std::vector< double > outerTrackPt_
std::map< DetId, double > corrValue_
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
edm::EDGetTokenT< reco::BeamSpot > tok_bs_
edm::EDGetTokenT< reco::VertexCollection > tok_Vtx_
void beginRun(edm::Run const &, edm::EventSetup const &) override
std::vector< double > globalTrckPt_
int depth() const
get the tower depth
Definition: HcalDetId.cc:108
std::vector< int > tight_PixelHits_
int iEvent
Definition: GenABIO.cc:230
std::vector< bool > muon_tracker_
std::vector< double > ecalEnergy_
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
std::vector< int > numPixelLayers_
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
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)
std::vector< double > hcalActiveLengthHot_
std::vector< double > innerTracketa_
std::vector< double > globalTrckEta_
std::vector< double > isolationR04_
unsigned int size() const
Get number of paths stored.
std::vector< double > hcalDepthActiveLengthHot_[depthMax_]
std::vector< double > hcalDepthEnergyHotCorr_[depthMax_]
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< double > ptGlob_
std::vector< unsigned int > ehcalDetId_
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
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, bool useRaw=false, int depthHE=3, bool debug=false)
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
std::vector< double > hcalEnergy_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< double > outerTrackEta_
bool isValid() const
Definition: HandleBase.h:74
double activeLength(const DetId &)
std::vector< bool > globalTrack_
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
std::vector< double > hcal1x1Energy_
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
bool goodCell(const HcalDetId &hcid, const reco::Track *pTrack, const CaloGeometry *geo, const MagneticField *bField)
std::vector< int > outerTrackRHits_
double ndof() const
Definition: Vertex.h:105
std::vector< bool > hcalHot_
JetCorrectorParameters corr
Definition: classes.h:5
int k[5][pyjets_maxn]
std::vector< bool > muon_is_good_
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
Definition: DetId.h:18
std::vector< double > chiGlobal_
std::vector< HcalDDDRecConstants::HcalActiveLength > actHB
std::vector< float > muon_segComp
int depth16HE(int ieta, int iphi)
std::vector< unsigned int > hcalDetId_
bool isFake() const
Definition: Vertex.h:72
std::vector< double > hcalDepthEnergyHot_[depthMax_]
std::vector< int > matchedStat_
std::vector< bool > matchedId_
void endRun(edm::Run const &, edm::EventSetup const &) override
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< double > hcalDepthEnergyCorr_[depthMax_]
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const T & get() const
Definition: EventSetup.h:58
void unmergeDepthDetId(const HcalDetId &id, std::vector< HcalDetId > &ids) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< double > hcalDepthActiveLength_[depthMax_]
std::vector< double > hoEnergy_
int matchId(const HcalDetId &, const HcalDetId &)
const HcalDDDRecConstants * hdc_
edm::EventID id() const
Definition: EventBase.h:60
std::vector< double > phiGlob_
HLTConfigProvider hltConfig_
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
std::vector< int > globalMuonHits_
std::vector< double > hcalActiveLength_
std::vector< double > chiTracker_
std::vector< double > hcalDepthChargeHot_[depthMax_]
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
std::vector< bool > hcalDepthMatchHot_[depthMax_]
std::vector< HcalActiveLength > getThickActive(const int &type) const
const Point & position() const
position
Definition: BeamSpot.h:62
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< int > trackerLayer_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< bool > outerTrack_
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
def check(config)
Definition: trackerTree.py:14
edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
edm::Service< TFileService > fs
T const * product() const
Definition: ESHandle.h:86
std::vector< double > dxyTracker_
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:301
std::vector< double > ecal3x3Energy_
void setTopo(const HcalTopology *topo)
std::vector< double > tight_TransImpara_
std::vector< double > energyMuon_
std::vector< double > etaGlob_
Definition: Run.h:43
bool isGoodVertex(const reco::Vertex &vtx)
std::vector< double > outerTrackPhi_
std::vector< double > innerTrackpt_
std::vector< bool > innerTrack_
std::vector< bool > hcalDepthMatch_[depthMax_]
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)
std::vector< float > muon_chi2LocalPosition