CMS 3D CMS Logo

HcalHBHEMuonAnalyzer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <iostream>
3 #include <vector>
4 #include <TFile.h>
5 #include <TTree.h>
6 #include "TPRegexp.h"
7 
8 // user include files
18 
21 
29 
31 
41 
44 
48 
52 
63 
64 #define EDM_ML_DEBUG
65 
66 class HcalHBHEMuonAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns,edm::one::SharedResources> {
67 
68 public:
69  explicit HcalHBHEMuonAnalyzer(const edm::ParameterSet&);
70 
71  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
72 
73 private:
74  void beginJob() override;
75  void analyze(edm::Event const&, edm::EventSetup const&) override;
76  void beginRun(edm::Run const&, edm::EventSetup const&) override;
77  void endRun(edm::Run const&, edm::EventSetup const&) override {}
80  void clearVectors();
81  int matchId(const HcalDetId&, const HcalDetId&);
82  double activeLength(const DetId&);
83  bool isGoodVertex(const reco::Vertex& vtx);
84 
85  // ----------member data ---------------------------
91  std::vector<std::string> triggers_;
94  static const int depthMax_=7;
96 
104 
107  std::vector<double> ptGlob_, etaGlob_, phiGlob_, chiGlobal_;
111  std::vector<double> matchedId_,numPixelLayers_;
112  std::vector<double> chiTracker_,dxyTracker_,dzTracker_;
116  std::vector<bool> innerTrack_, outerTrack_, globalTrack_;
117  std::vector<double> isolationR04_,isolationR03_;
120  std::vector<unsigned int> ecalDetId_,hcalDetId_,ehcalDetId_;
121  std::vector<double> hcalDepthEnergy_[depthMax_];
122  std::vector<double> hcalDepthActiveLength_[depthMax_];
123  std::vector<double> hcalDepthEnergyHot_[depthMax_];
124  std::vector<double> hcalDepthActiveLengthHot_[depthMax_];
125  std::vector<double> hcalDepthEnergyCorr_[depthMax_];
126  std::vector<double> hcalDepthEnergyHotCorr_[depthMax_];
128  std::vector<HcalDDDRecConstants::HcalActiveLength> actHB, actHE;
129  std::vector<std::string> all_triggers;
131 
132  TTree *tree_;
134  std::vector<int> hltresults;
136 };
137 
139 
140  usesResource(TFileService::kSharedResource);
141  //now do what ever initialization is needed
142  kount_ = 0;
143  HLTriggerResults_ = iConfig.getParameter<edm::InputTag>("HLTriggerResults");
144  labelBS_ = iConfig.getParameter<std::string>("LabelBeamSpot");
145  labelVtx_ = iConfig.getParameter<std::string>("LabelVertex");
146  labelEBRecHit_ = iConfig.getParameter<edm::InputTag>("LabelEBRecHit");
147  labelEERecHit_ = iConfig.getParameter<edm::InputTag>("LabelEERecHit");
148  labelHBHERecHit_ = iConfig.getParameter<edm::InputTag>("LabelHBHERecHit");
149  labelMuon_ = iConfig.getParameter<std::string>("LabelMuon");
150  triggers_ = iConfig.getParameter<std::vector<std::string>>("Triggers");
151  useRaw_ = iConfig.getParameter<bool>("UseRaw");
152  unCorrect_ = iConfig.getParameter<bool>("UnCorrect");
153  collapseDepth_ = iConfig.getParameter<bool>("CollapseDepth");
154  saveCorrect_ = iConfig.getParameter<bool>("SaveCorrect");
155  verbosity_ = iConfig.getUntrackedParameter<int>("Verbosity",0);
156  maxDepth_ = iConfig.getUntrackedParameter<int>("MaxDepth",4);
157  if (maxDepth_ > depthMax_) maxDepth_ = depthMax_;
158  else if (maxDepth_ < 1) maxDepth_ = 4;
159  std::string modnam = iConfig.getUntrackedParameter<std::string>("ModuleName","");
160  std::string procnm = iConfig.getUntrackedParameter<std::string>("ProcessName","");
161 
162  tok_trigRes_ = consumes<edm::TriggerResults>(HLTriggerResults_);
163  tok_bs_ = consumes<reco::BeamSpot>(labelBS_);
164  tok_EB_ = consumes<EcalRecHitCollection>(labelEBRecHit_);
165  tok_EE_ = consumes<EcalRecHitCollection>(labelEERecHit_);
166  tok_HBHE_ = consumes<HBHERecHitCollection>(labelHBHERecHit_);
167  if (modnam == "") {
168  tok_Vtx_ = consumes<reco::VertexCollection>(labelVtx_);
169  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
170  edm::LogVerbatim("HBHEMuon") << "Labels used " << HLTriggerResults_ << " "
171  << labelVtx_ << " " << labelEBRecHit_ << " "
172  << labelEERecHit_ << " " << labelHBHERecHit_
173  << " " << labelMuon_;
174  } else {
175  tok_Vtx_ = consumes<reco::VertexCollection>(edm::InputTag(modnam,labelVtx_,procnm));
176  tok_Muon_ = consumes<reco::MuonCollection>(edm::InputTag(modnam,labelMuon_,procnm));
177  edm::LogVerbatim("HBHEMuon") << "Labels used " << HLTriggerResults_
178  << "\n " << edm::InputTag(modnam,labelVtx_,procnm)
179  << "\n " << labelEBRecHit_
180  << "\n " << labelEERecHit_
181  << "\n " << labelHBHERecHit_
182  << "\n " << edm::InputTag(modnam,labelMuon_,procnm);
183  }
184 }
185 
186 //
187 // member functions
188 //
189 
190 // ------------ method called for each event ------------
192  ++kount_;
193  clearVectors();
194  // depthHE is the first depth index for HE for |ieta| = 16
195  // It used to be 3 for all runs preceding 2017 and 4 beyond that
196  int depthHE = (maxDepth_ <= 6) ? 3 : 4;
197  runNumber_ = iEvent.id().run();
198  eventNumber_ = iEvent.id().event();
199  lumiNumber_ = iEvent.id().luminosityBlock();
200  bxNumber_ = iEvent.bunchCrossing();
201 #ifdef EDM_ML_DEBUG
202  edm::LogVerbatim("HBHEMuon") << "Run " << runNumber_ << " Event "
203  << eventNumber_ << " Lumi " << lumiNumber_
204  << " BX " << bxNumber_ << std::endl;
205 #endif
207  iEvent.getByToken(tok_trigRes_, _Triggers);
208 #ifdef EDM_ML_DEBUG
209  if ((verbosity_/10000)%10>0)
210  edm::LogVerbatim("HBHEMuon") << "Size of all triggers "
211  << all_triggers.size() << std::endl;
212 #endif
213  int Ntriggers = all_triggers.size();
214 #ifdef EDM_ML_DEBUG
215  if ((verbosity_/10000)%10>0)
216  edm::LogVerbatim("HBHEMuon") << "Size of HLT MENU: " << _Triggers->size()
217  << std::endl;
218 #endif
219  if (_Triggers.isValid()) {
220  const edm::TriggerNames &triggerNames_ = iEvent.triggerNames(*_Triggers);
221  std::vector<int> index;
222  for (int i=0; i<Ntriggers; i++) {
223  index.push_back(triggerNames_.triggerIndex(all_triggers[i]));
224  int triggerSize = int( _Triggers->size());
225 #ifdef EDM_ML_DEBUG
226  if ((verbosity_/10000)%10>0)
227  edm::LogVerbatim("HBHEMuon") << "outside loop " << index[i]
228  << "\ntriggerSize " << triggerSize
229  << std::endl;
230 #endif
231  if (index[i] < triggerSize) {
232  hltresults.push_back(_Triggers->accept(index[i]));
233 #ifdef EDM_ML_DEBUG
234  if ((verbosity_/10000)%10>0)
235  edm::LogVerbatim("HBHEMuon") << "Trigger_info " << triggerSize
236  << " triggerSize " << index[i]
237  << " trigger_index " << hltresults.at(i)
238  << " hltresult" << std::endl;
239 #endif
240  } else {
241  if ((verbosity_/10000)%10>0)
242  edm::LogVerbatim("HBHEMuon") << "Requested HLT path \""
243  << "\" does not exist\n";
244  }
245  }
246  }
247 
248  // get handles to calogeometry and calotopology
250  iSetup.get<CaloGeometryRecord>().get(pG);
251  const CaloGeometry* geo = pG.product();
252 
254  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
255  const MagneticField* bField = bFieldH.product();
256 
258  iSetup.get<EcalChannelStatusRcd>().get(ecalChStatus);
259  const EcalChannelStatus* theEcalChStatus = ecalChStatus.product();
260 
262  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
263 
264  edm::ESHandle<CaloTopology> theCaloTopology;
265  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
266  const CaloTopology *caloTopology = theCaloTopology.product();
267 
269  iSetup.get<HcalRecNumberingRecord>().get(htopo);
270  const HcalTopology* theHBHETopology = htopo.product();
271 
273  iSetup.get<HcalRespCorrsRcd>().get(resp);
274  HcalRespCorrs* respCorrs = new HcalRespCorrs(*resp.product());
275  respCorrs->setTopo(theHBHETopology);
276 
277  // Relevant blocks from iEvent
279  iEvent.getByToken(tok_Vtx_, vtx);
280  edm::Handle<reco::BeamSpot> beamSpotH;
281  iEvent.getByToken(tok_bs_, beamSpotH);
282 
283  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
284  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
285  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
286  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
287 
289  iEvent.getByToken(tok_HBHE_, hbhe);
290 
292  iEvent.getByToken(tok_Muon_, _Muon);
293 
294  // require a good vertex
295  math::XYZPoint pvx;
296  bool goodVtx(false);
297  if (vtx.isValid()) {
298  reco::VertexCollection::const_iterator firstGoodVertex = vtx->end();
299  for (reco::VertexCollection::const_iterator it = vtx->begin();
300  it != firstGoodVertex; it++) {
301  if (isGoodVertex(*it)) {
302  firstGoodVertex = it;
303  break;
304  }
305  }
306  if (firstGoodVertex != vtx->end()) {
307  pvx = firstGoodVertex->position();
308  goodVtx = true;
309  }
310  }
311  if (!goodVtx) {
312  if (beamSpotH.isValid()) {
313  pvx = beamSpotH->position();
314  goodVtx = true;
315  }
316  }
317  if (!goodVtx) {
318 #ifdef EDM_ML_DEBUG
319  edm::LogVerbatim("HBHEMuon") << "No Good Vertex found == Reject\n";
320 #endif
321  return;
322  }
323 
324  bool accept(false);
325  if (_Muon.isValid() && barrelRecHitsHandle.isValid() &&
326  endcapRecHitsHandle.isValid() && hbhe.isValid()) {
327  for (reco::MuonCollection::const_iterator RecMuon = _Muon->begin(); RecMuon!= _Muon->end(); ++RecMuon) {
328 
329  if ((RecMuon->p()>10.0) && (RecMuon->track().isNonnull())) accept = true;
330 
331  muon_is_good_.push_back(RecMuon->isPFMuon());
332  muon_global_.push_back(RecMuon->isGlobalMuon());
333  muon_tracker_.push_back(RecMuon->isTrackerMuon());
334  ptGlob_.push_back((RecMuon)->pt());
335  etaGlob_.push_back(RecMuon->eta());
336  phiGlob_.push_back(RecMuon->phi());
337  energyMuon_.push_back(RecMuon->energy());
338  pMuon_.push_back(RecMuon->p());
339 #ifdef EDM_ML_DEBUG
340  edm::LogVerbatim("HBHEMuon") << "Energy:" << RecMuon->energy() << " P:"
341  << RecMuon->p() << std::endl;
342 #endif
343  muon_trkKink.push_back(RecMuon->combinedQuality().trkKink);
344  muon_chi2LocalPosition.push_back(RecMuon->combinedQuality().chi2LocalPosition);
345  muon_segComp.push_back(muon::segmentCompatibility(*RecMuon));
346  // acessing tracker hits info
347  if (RecMuon->track().isNonnull()) {
348  trackerLayer_.push_back(RecMuon->track()->hitPattern().trackerLayersWithMeasurement());
349  } else {
350  trackerLayer_.push_back(-1);
351  }
352  if (RecMuon->innerTrack().isNonnull()) {
353  innerTrack_.push_back(true);
354  numPixelLayers_.push_back(RecMuon->innerTrack()->hitPattern().pixelLayersWithMeasurement());
355  chiTracker_.push_back(RecMuon->innerTrack()->normalizedChi2());
356  dxyTracker_.push_back(fabs(RecMuon->innerTrack()->dxy(pvx)));
357  dzTracker_.push_back(fabs(RecMuon->innerTrack()->dz(pvx)));
358  innerTrackpt_.push_back(RecMuon->innerTrack()->pt());
359  innerTracketa_.push_back(RecMuon->innerTrack()->eta());
360  innerTrackphi_.push_back(RecMuon->innerTrack()->phi());
361  tight_PixelHits_.push_back(RecMuon->innerTrack()->hitPattern().numberOfValidPixelHits());
362  tight_validFraction_.push_back(RecMuon->innerTrack()->validFraction());
363  } else {
364  innerTrack_.push_back(false);
365  numPixelLayers_.push_back(0);
366  chiTracker_.push_back(0);
367  dxyTracker_.push_back(0);
368  dzTracker_.push_back(0);
369  innerTrackpt_.push_back(0);
370  innerTracketa_.push_back(0);
371  innerTrackphi_.push_back(0);
372  tight_PixelHits_.push_back(0);
373  tight_validFraction_.push_back(-99);
374  }
375  // outer track info
376  if (RecMuon->outerTrack().isNonnull()) {
377  outerTrack_.push_back(true);
378  outerTrackPt_.push_back(RecMuon->outerTrack()->pt());
379  outerTrackEta_.push_back(RecMuon->outerTrack()->eta());
380  outerTrackPhi_.push_back(RecMuon->outerTrack()->phi());
381  outerTrackChi_.push_back(RecMuon->outerTrack()->normalizedChi2());
382  outerTrackHits_.push_back(RecMuon->outerTrack()->numberOfValidHits());
383  outerTrackRHits_.push_back(RecMuon->outerTrack()->recHitsSize());
384  } else {
385  outerTrack_.push_back(false);
386  outerTrackPt_.push_back(0);
387  outerTrackEta_.push_back(0);
388  outerTrackPhi_.push_back(0);
389  outerTrackChi_.push_back(0);
390  outerTrackHits_.push_back(0);
391  outerTrackRHits_.push_back(0);
392  }
393  // Tight Muon cuts
394  if (RecMuon->globalTrack().isNonnull()) {
395  globalTrack_.push_back(true);
396  chiGlobal_.push_back(RecMuon->globalTrack()->normalizedChi2());
397  globalMuonHits_.push_back(RecMuon->globalTrack()->hitPattern().numberOfValidMuonHits());
398  matchedStat_.push_back(RecMuon->numberOfMatchedStations());
399  globalTrckPt_.push_back(RecMuon->globalTrack()->pt());
400  globalTrckEta_.push_back(RecMuon->globalTrack()->eta());
401  globalTrckPhi_.push_back(RecMuon->globalTrack()->phi());
402  tight_TransImpara_.push_back(fabs(RecMuon->muonBestTrack()->dxy(pvx)));
403  tight_LongPara_.push_back(fabs(RecMuon->muonBestTrack()->dz(pvx)));
404  } else {
405  globalTrack_.push_back(false);
406  chiGlobal_.push_back(0);
407  globalMuonHits_.push_back(0);
408  matchedStat_.push_back(0);
409  globalTrckPt_.push_back(0);
410  globalTrckEta_.push_back(0);
411  globalTrckPhi_.push_back(0);
412  tight_TransImpara_.push_back(0);
413  tight_LongPara_.push_back(0);
414  }
415 
416  isolationR04_.push_back(((RecMuon->pfIsolationR04().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR04().sumNeutralHadronEt + RecMuon->pfIsolationR04().sumPhotonEt - (0.5 *RecMuon->pfIsolationR04().sumPUPt))) / RecMuon->pt()) );
417 
418  isolationR03_.push_back(((RecMuon->pfIsolationR03().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR03().sumNeutralHadronEt + RecMuon->pfIsolationR03().sumPhotonEt - (0.5 * RecMuon->pfIsolationR03().sumPUPt))) / RecMuon->pt()));
419 
420  ecalEnergy_.push_back(RecMuon->calEnergy().emS9);
421  hcalEnergy_.push_back(RecMuon->calEnergy().hadS9);
422  hoEnergy_.push_back(RecMuon->calEnergy().hoS9);
423 
424  double eEcal(0), eHcal(0), activeLengthTot(0), activeLengthHotTot(0);
425  double eHcalDepth[depthMax_], eHcalDepthHot[depthMax_];
426  double eHcalDepthC[depthMax_], eHcalDepthHotC[depthMax_];
427  double activeL[depthMax_], activeHotL[depthMax_];
428  HcalDetId eHcalDetId[depthMax_];
429  unsigned int isHot(0);
430  bool tmpmatch(false);
431  for (int i=0; i<depthMax_; ++i) {
432  eHcalDepth[i] = eHcalDepthHot[i] = 0;
433  eHcalDepthC[i] = eHcalDepthHotC[i] = 0;
434  activeL[i] = activeHotL[i] = 0;
435  }
436  if (RecMuon->innerTrack().isNonnull()) {
437  const reco::Track* pTrack = (RecMuon->innerTrack()).get();
438  spr::propagatedTrackID trackID = spr::propagateCALO(pTrack, geo, bField, (((verbosity_/100)%10>0)));
439 
440  ecalDetId_.push_back((trackID.detIdECAL)());
441  hcalDetId_.push_back((trackID.detIdHCAL)());
442  ehcalDetId_.push_back((trackID.detIdEHCAL)());
443 
445  std::pair<bool,HcalDetId> info = spr::propagateHCALBack(pTrack, geo, bField, (((verbosity_/100)%10>0)));
446  if (info.first) {
447  check = info.second;
448  }
449 
450  bool okE = trackID.okECAL;
451  if (okE) {
452  const DetId isoCell(trackID.detIdECAL);
453  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);
454  eEcal = e3x3.first;
455  okE = e3x3.second;
456  }
457 #ifdef EDM_ML_DEBUG
458  edm::LogVerbatim("HBHEMuon") << "Propagate Track to ECAL: " << okE
459  << ":" << trackID.okECAL << " E "
460  << eEcal << std::endl;
461 #endif
462 
463  if (trackID.okHCAL) {
464  const DetId closestCell(trackID.detIdHCAL);
465  HcalDetId hcidt(closestCell.rawId());
466  if ((hcidt.ieta() == check.ieta()) && (hcidt.iphi() == check.iphi()))
467  tmpmatch= true;
468 
469  HcalSubdetector subdet = HcalDetId(closestCell).subdet();
470  int ieta = HcalDetId(closestCell).ieta();
471  int iphi = HcalDetId(closestCell).iphi();
472  bool hborhe = (std::abs(ieta) == 16);
473 
474  eHcal = spr::eHCALmatrix(theHBHETopology, closestCell, hbhe,0,0, false, true, -100.0, -100.0, -100.0, -100.0, -500.,500.,useRaw_);
475  std::vector<std::pair<double,int> > ehdepth;
476  spr::energyHCALCell((HcalDetId) closestCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, useRaw_, (((verbosity_/1000)%10)>0));
477  for (int i=0; i<depthMax_; ++i) eHcalDetId[i] = HcalDetId();
478  for (unsigned int i=0; i<ehdepth.size(); ++i) {
479  HcalSubdetector subdet0 = (hborhe) ? ((ehdepth[i].second >= depthHE) ? HcalEndcap : HcalBarrel) : subdet;
480  HcalDetId hcid0(subdet0,ieta,iphi,ehdepth[i].second);
481  double actL = activeLength(DetId(hcid0));
482  double ene = ehdepth[i].first;
483  double enec(ene);
484  if (unCorrect_) {
485  double corr = (respCorrs->getValues(DetId(hcid0)))->getValue();
486  if (corr != 0) ene /= corr;
487 #ifdef EDM_ML_DEBUG
488  edm::LogVerbatim("HBHEMuon") << hcid0 << " corr " << corr;
489 #endif
490  }
491  int depth = ehdepth[i].second - 1;
492  if (collapseDepth_) {
493  HcalDetId id = hdc->mergedDepthDetId(hcid0);
494  depth = id.depth() - 1;
495  }
496  eHcalDepth[depth] += ene;
497  eHcalDepthC[depth]+= enec;
498  activeL[depth] += actL;
499  activeLengthTot += actL;
500 #ifdef EDM_ML_DEBUG
501  if ((verbosity_%10) > 0)
502  edm::LogVerbatim("HBHEMuon") << hcid0 << " E " << ene << " L "
503  << actL << std::endl;
504 #endif
505  }
506 
507  HcalDetId hotCell;
508  spr::eHCALmatrix(geo, theHBHETopology, closestCell, hbhe, 1,1, hotCell, false, useRaw_, false);
509  isHot = matchId(closestCell,hotCell);
510  if (hotCell != HcalDetId()) {
511  subdet = HcalDetId(hotCell).subdet();
512  ieta = HcalDetId(hotCell).ieta();
513  iphi = HcalDetId(hotCell).iphi();
514  hborhe = (std::abs(ieta) == 16);
515  std::vector<std::pair<double,int> > ehdepth;
516  spr::energyHCALCell(hotCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, useRaw_, false);//(((verbosity_/1000)%10)>0 ));
517  for (int i=0; i<depthMax_; ++i) eHcalDetId[i] = HcalDetId();
518  for (unsigned int i=0; i<ehdepth.size(); ++i) {
519  HcalSubdetector subdet0 = (hborhe) ? ((ehdepth[i].second >= depthHE) ? HcalEndcap : HcalBarrel) : subdet;
520  HcalDetId hcid0(subdet0,ieta,iphi,ehdepth[i].second);
521  double actL = activeLength(DetId(hcid0));
522  double ene = ehdepth[i].first;
523  double enec(ene);
524  if (unCorrect_) {
525  double corr = (respCorrs->getValues(DetId(hcid0)))->getValue();
526  if (corr != 0) ene /= corr;
527 #ifdef EDM_ML_DEBUG
528  edm::LogVerbatim("HBHEMuon") << hcid0 << " corr " << corr;
529 #endif
530  }
531  int depth = ehdepth[i].second - 1;
532  if (collapseDepth_) {
533  HcalDetId id = hdc->mergedDepthDetId(hcid0);
534  depth = id.depth() - 1;
535  }
536  eHcalDepthHot[depth] += ene;
537  eHcalDepthHotC[depth]+= enec;
538  activeHotL[depth] += actL;
539  activeLengthHotTot += actL;
540 #ifdef EDM_ML_DEBUG
541  if ((verbosity_%10) > 0)
542  edm::LogVerbatim("HBHEMuon") << hcid0 << " E " << ene
543  << " L " << actL << std::endl;
544 #endif
545  }
546  }
547  }
548 #ifdef EDM_ML_DEBUG
549  edm::LogVerbatim("HBHEMuon") << "Propagate Track to HCAL: "
550  << trackID.okHCAL << " Match " << tmpmatch
551  << " Hot " << isHot << " Energy "
552  << eHcal << std::endl;
553 #endif
554 
555  } else {
556  ecalDetId_.push_back(0);
557  hcalDetId_.push_back(0);
558  ehcalDetId_.push_back(0);
559  }
560 
561  matchedId_.push_back(tmpmatch);
562  ecal3x3Energy_.push_back(eEcal);
563  hcal1x1Energy_.push_back(eHcal);
564  for (int i=0; i<depthMax_; ++i) {
565  hcalDepthEnergy_[i].push_back(eHcalDepth[i]);
566  hcalDepthActiveLength_[i].push_back(activeL[i]);
567  hcalDepthEnergyHot_[i].push_back(eHcalDepthHot[i]);
568  hcalDepthActiveLengthHot_[i].push_back(activeHotL[i]);
569  hcalDepthEnergyCorr_[i].push_back(eHcalDepthC[i]);
570  hcalDepthEnergyHotCorr_[i].push_back(eHcalDepthHotC[i]);
571  }
572  hcalActiveLength_.push_back(activeLengthTot);
573  hcalHot_.push_back(isHot);
574  hcalActiveLengthHot_.push_back(activeLengthHotTot);
575  }
576  }
577  if (accept) tree_->Fill();
578 }
579 
580 // ------------ method called once each job just before starting event loop ------------
582 
583  tree_ = fs->make<TTree>("TREE", "TREE");
584  tree_->Branch("Event_No", &eventNumber_);
585  tree_->Branch("Run_No", &runNumber_);
586  tree_->Branch("LumiNumber", &lumiNumber_);
587  tree_->Branch("BXNumber", &bxNumber_);
588  tree_->Branch("pt_of_muon", &ptGlob_);
589  tree_->Branch("eta_of_muon", &etaGlob_);
590  tree_->Branch("phi_of_muon", &phiGlob_);
591  tree_->Branch("energy_of_muon", &energyMuon_);
592  tree_->Branch("p_of_muon", &pMuon_);
593  tree_->Branch("PF_Muon", &muon_is_good_);
594  tree_->Branch("Global_Muon", &muon_global_);
595  tree_->Branch("Tracker_muon", &muon_tracker_);
596 
597  tree_->Branch("hcal_3into3", &hcalEnergy_);
598  tree_->Branch("hcal_1x1", &hcal1x1Energy_);
599  tree_->Branch("hcal_detID", &hcalDetId_);
600  tree_->Branch("hcal_cellHot", &hcalHot_);
601  tree_->Branch("activeLength", &hcalActiveLength_);
602  tree_->Branch("activeLengthHot", &hcalActiveLengthHot_);
603  char name[100];
604  for (int k=0; k<maxDepth_; ++k) {
605  sprintf (name, "hcal_edepth%d", (k+1));
606  tree_->Branch(name, &hcalDepthEnergy_[k]);
607  sprintf (name, "hcal_activeL%d", (k+1));
608  tree_->Branch(name, &hcalDepthActiveLength_[k]);
609  sprintf (name, "hcal_edepthHot%d", (k+1));
610  tree_->Branch(name, &hcalDepthEnergyHot_[k]);
611  sprintf (name, "hcal_activeHotL%d", (k+1));
612  tree_->Branch(name, &hcalDepthActiveLength_[k]);
613  if (saveCorrect_) {
614  sprintf (name, "hcal_edepthCorrect%d", (k+1));
615  tree_->Branch(name, &hcalDepthEnergyCorr_[k]);
616  sprintf (name, "hcal_edepthHotCorrect%d", (k+1));
617  tree_->Branch(name, &hcalDepthEnergyHotCorr_[k]);
618  }
619  }
620 
621  tree_->Branch("TrackerLayer", &trackerLayer_);
622  tree_->Branch("matchedId", &matchedId_);
623  tree_->Branch("innerTrack", &innerTrack_);
624  tree_->Branch("innerTrackpt", &innerTrackpt_);
625  tree_->Branch("innerTracketa", &innerTracketa_);
626  tree_->Branch("innerTrackphi", &innerTrackphi_);
627  tree_->Branch("MatchedStat", &matchedStat_);
628  tree_->Branch("GlobalTrckPt", &globalTrckPt_);
629  tree_->Branch("GlobalTrckEta", &globalTrckEta_);
630  tree_->Branch("GlobalTrckPhi", &globalTrckPhi_);
631  tree_->Branch("NumPixelLayers", &numPixelLayers_);
632  tree_->Branch("chiTracker", &chiTracker_);
633  tree_->Branch("DxyTracker", &dxyTracker_);
634  tree_->Branch("DzTracker", &dzTracker_);
635  tree_->Branch("OuterTrack", &outerTrack_);
636  tree_->Branch("OuterTrackPt", &outerTrackPt_);
637  tree_->Branch("OuterTrackEta", &outerTrackEta_);
638  tree_->Branch("OuterTrackPhi", &outerTrackPhi_);
639  tree_->Branch("OuterTrackHits", &outerTrackHits_);
640  tree_->Branch("OuterTrackRHits", &outerTrackRHits_);
641  tree_->Branch("OuterTrackChi", &outerTrackChi_);
642  tree_->Branch("GlobalTrack", &globalTrack_);
643  tree_->Branch("GlobTrack_Chi", &chiGlobal_);
644  tree_->Branch("Global_Muon_Hits", &globalMuonHits_);
645  tree_->Branch("MatchedStations", &matchedStat_);
646  tree_->Branch("Global_Track_Pt", &globalTrckPt_);
647  tree_->Branch("Global_Track_Eta", &globalTrckEta_);
648  tree_->Branch("Global_Track_Phi", &globalTrckPhi_);
650  tree_->Branch("Tight_LongitudinalImpactparameter",&tight_LongPara_);
651  tree_->Branch("Tight_TransImpactparameter", &tight_TransImpara_);
652  tree_->Branch("InnerTrackPixelHits", &tight_PixelHits_);
653  tree_->Branch("IsolationR04", &isolationR04_);
654  tree_->Branch("IsolationR03", &isolationR03_);
655 
656  tree_->Branch("ecal_3into3", &ecalEnergy_);
657  tree_->Branch("ecal_3x3", &ecal3x3Energy_);
658  tree_->Branch("ecal_detID", &ecalDetId_);
659  tree_->Branch("ehcal_detID", &ehcalDetId_);
660  tree_->Branch("tracker_3into3", &hoEnergy_);
661 
663  tree_->Branch("hltresults", &hltresults);
664  tree_->Branch("all_triggers", &all_triggers);
665 
666  tree_->Branch("muon_trkKink", &muon_trkKink);
667  tree_->Branch("muon_chi2LocalPosition", &muon_chi2LocalPosition);
668  tree_->Branch("muon_segComp", &muon_segComp);
669  tree_->Branch("tight_validFraction", &tight_validFraction_);
670 }
671 
672 // ------------ method called when starting to processes a run ------------
673 void HcalHBHEMuonAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
674 
676  iSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
677  hdc = pHRNDC.product();
678  actHB.clear();
679  actHE.clear();
680  actHB = hdc->getThickActive(0);
681  actHE = hdc->getThickActive(1);
682 
683  bool changed = true;
684  all_triggers.clear();
685  if (hltConfig_.init(iRun, iSetup,"HLT" , changed)) {
686  // if init returns TRUE, initialisation has succeeded!
687 #ifdef EDM_ML_DEBUG
688  edm::LogVerbatim("HBHEMuon") << "HLT config with process name "
689  << "HLT" << " successfully extracted"
690  << std::endl;
691 #endif
692  unsigned int ntriggers = hltConfig_.size();
693  for (unsigned int t=0;t<ntriggers;++t) {
695  for (unsigned int ik=0; ik<6; ++ik) {
696  if (hltname.find(triggers_[ik])!=std::string::npos ){
697  all_triggers.push_back(hltname);
698  break;
699  }
700  }
701  }//loop over ntriggers
702  edm::LogVerbatim("HBHEMuon") << "All triggers size in begin run "
703  << all_triggers.size() << std::endl;
704  } else {
705  edm::LogError("HBHEMuon") << "Error! HLT config extraction with process name "
706  << "HLT" << " failed";
707  }
708 
709 }
710 
711 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
714  desc.add<edm::InputTag>("HLTriggerResults",edm::InputTag("TriggerResults","","HLT"));
715  desc.add<std::string>("LabelBeamSpot","offlineBeamSpot");
716  desc.add<std::string>("LabelVertex","offlinePrimaryVertices");
717  desc.add<edm::InputTag>("LabelEBRecHit",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
718  desc.add<edm::InputTag>("LabelEERecHit",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
719  desc.add<edm::InputTag>("LabelHBHERecHit",edm::InputTag("hbhereco"));
720  desc.add<std::string>("LabelMuon","muons");
721 // std::vector<std::string> trig = {"HLT_IsoMu_","HLT_L1SingleMu_","HLT_L2Mu","HLT_Mu","HLT_RelIso1p0Mu"};
722  std::vector<std::string> trig = {"HLT_IsoMu17","HLT_IsoMu20",
723  "HLT_IsoMu24","HLT_IsoMu27",
724  "HLT_Mu45","HLT_Mu50"};
725  desc.add<std::vector<std::string>>("Triggers",trig);
726  desc.add<bool>("UseRaw",false);
727  desc.add<bool>("UnCorrect",false);
728  desc.add<bool>("CollapseDepth",false);
729  desc.add<bool>("SaveCorrect",false);
730  desc.addUntracked<std::string>("ModuleName","");
731  desc.addUntracked<std::string>("ProcessName","");
732  desc.addUntracked<int>("Verbosity",0);
733  desc.addUntracked<int>("MaxDepth",4);
734  descriptions.add("hcalHBHEMuon",desc);
735 }
736 
739  eventNumber_ = -99999;
740  runNumber_ = -99999;
741  lumiNumber_ = -99999;
742  bxNumber_ = -99999;
743  muon_is_good_.clear();
744  muon_global_.clear();
745  muon_tracker_.clear();
746  ptGlob_.clear();
747  etaGlob_.clear();
748  phiGlob_.clear();
749  energyMuon_.clear();
750  pMuon_.clear();
751  trackerLayer_.clear();
752  matchedId_.clear();
753  innerTrack_.clear();
754  numPixelLayers_.clear();
755  chiTracker_.clear();
756  dxyTracker_.clear();
757  dzTracker_.clear();
758  innerTrackpt_.clear();
759  innerTracketa_.clear();
760  innerTrackphi_.clear();
761  tight_PixelHits_.clear();
762  outerTrack_.clear();
763  outerTrackPt_.clear();
764  outerTrackEta_.clear();
765  outerTrackPhi_.clear();
766  outerTrackHits_.clear();
767  outerTrackRHits_.clear();
768  outerTrackChi_.clear();
769  globalTrack_.clear();
770  chiGlobal_.clear();
771  globalMuonHits_.clear();
772  matchedStat_.clear();
773  globalTrckPt_.clear();
774  globalTrckEta_.clear();
775  globalTrckPhi_.clear();
776  tight_TransImpara_.clear();
777  tight_LongPara_.clear();
778 
779  isolationR04_.clear();
780  isolationR03_.clear();
781  ecalEnergy_.clear();
782  hcalEnergy_.clear();
783  hoEnergy_.clear();
784  ecalDetId_.clear();
785  hcalDetId_.clear();
786  ehcalDetId_.clear();
787  ecal3x3Energy_.clear();
788  hcal1x1Energy_.clear();
789  hcalHot_.clear();
790  hcalActiveLengthHot_.clear();
791  for (int i=0; i<maxDepth_; ++i) {
792  hcalDepthEnergy_[i].clear();
793  hcalDepthActiveLength_[i].clear();
794  hcalDepthEnergyHot_[i].clear();
795  hcalDepthActiveLengthHot_[i].clear();
796  hcalDepthEnergyCorr_[i].clear();
797  hcalDepthEnergyHotCorr_[i].clear();
798  }
799  hltresults.clear();
800  muon_trkKink.clear();
801  muon_chi2LocalPosition.clear();
802  muon_segComp.clear();
803  tight_validFraction_.clear();
804 }
805 
806 int HcalHBHEMuonAnalyzer::matchId(const HcalDetId& id1, const HcalDetId& id2) {
807 
808  HcalDetId kd1(id1.subdet(),id1.ieta(),id1.iphi(),1);
809  HcalDetId kd2(id2.subdet(),id2.ieta(),id2.iphi(),1);
810  int match = ((kd1 == kd2) ? 1 : 0);
811  return match;
812 }
813 
815  HcalDetId id(id_);
816  int ieta = id.ietaAbs();
817  int depth= id.depth();
818  int zside= id.zside();
819  int iphi = id.iphi();
820  double lx(0);
821  if (id.subdet() == HcalBarrel) {
822  for (unsigned int i=0; i<actHB.size(); ++i) {
823  if ((ieta == actHB[i].ieta) && (depth == actHB[i].depth) &&
824  (zside == actHB[i].zside) &&
825  (std::find(actHB[i].iphis.begin(),actHB[i].iphis.end(),iphi) !=
826  actHB[i].iphis.end())) {
827  lx = actHB[i].thick;
828  break;
829  }
830  }
831  } else {
832  for (unsigned int i=0; i<actHE.size(); ++i) {
833  if ((ieta == actHE[i].ieta) && (depth == actHE[i].depth) &&
834  (zside == actHE[i].zside) &&
835  (std::find(actHE[i].iphis.begin(),actHE[i].iphis.end(),iphi) !=
836  actHE[i].iphis.end())) {
837  lx = actHE[i].thick;
838  break;
839  }
840  }
841  }
842  return lx;
843 }
844 
846  if (vtx.isFake()) return false;
847  if (vtx.ndof() < 4) return false;
848  if (vtx.position().Rho() > 2.) return false;
849  if (fabs(vtx.position().Z()) > 24.) return false;
850  return true;
851 }
852 
853 //define this as a plug-in
855 
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_
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
std::vector< double > innerTrackphi_
HcalHBHEMuonAnalyzer(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< double > hcalHot_
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_
static const int depthMax_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
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 > muon_chi2LocalPosition
std::vector< double > outerTrackChi_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< double > matchedStat_
HcalDetId mergedDepthDetId(const HcalDetId &id) const
std::vector< double > tight_LongPara_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< double > muon_trkKink
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
std::vector< unsigned int > ecalDetId_
std::vector< double > pMuon_
bool accept() const
Has at least one path accepted the event?
std::vector< double > globalTrckPhi_
std::vector< double > outerTrackHits_
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
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const Item * getValues(DetId fId, bool throwOnFail=true) const
std::vector< HcalDDDRecConstants::HcalActiveLength > actHE
std::vector< double > isolationR03_
#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
std::vector< bool > muon_global_
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
std::vector< double > hcalDepthEnergy_[depthMax_]
std::vector< double > outerTrackPt_
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
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
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_]
std::vector< double > ptGlob_
std::vector< unsigned int > ehcalDetId_
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > tight_PixelHits_
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
std::vector< double > hcalEnergy_
std::vector< double > trackerLayer_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< double > outerTrackEta_
bool isValid() const
Definition: HandleBase.h:74
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, bool debug=false)
double activeLength(const DetId &)
std::vector< bool > globalTrack_
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
std::vector< double > outerTrackRHits_
std::vector< double > hcal1x1Energy_
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
double ndof() const
Definition: Vertex.h:105
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< unsigned int > hcalDetId_
bool isFake() const
Definition: Vertex.h:72
std::vector< double > hcalDepthEnergyHot_[depthMax_]
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< int > hltresults
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:55
std::vector< std::string > all_triggers
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< double > globalMuonHits_
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< double > hcalActiveLength_
std::vector< double > chiTracker_
std::vector< double > matchedId_
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< bool > outerTrack_
std::vector< double > muon_segComp
def check(config)
Definition: trackerTree.py:14
std::vector< double > numPixelLayers_
edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
edm::Service< TFileService > fs
T const * product() const
Definition: ESHandle.h:86
std::vector< double > dxyTracker_
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:239
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:42
bool isGoodVertex(const reco::Vertex &vtx)
std::vector< double > outerTrackPhi_
std::vector< double > innerTrackpt_
std::vector< bool > innerTrack_
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)