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 
25 
27 
37 
40 
44 
48 
59 
60 //#define EDM_ML_DEBUG
61 
63 
64 public:
65  explicit HcalHBHEMuonAnalyzer(const edm::ParameterSet&);
67 
68  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
69 
70 private:
71  virtual void beginJob() ;
72  virtual void analyze(const edm::Event&, const edm::EventSetup& );
73  virtual void endJob() ;
74  virtual void beginRun(edm::Run const&, edm::EventSetup const&);
75  virtual void endRun(edm::Run const&, edm::EventSetup const&);
76  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
77  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
78  void clearVectors();
79  int matchId(const HcalDetId&, const HcalDetId&);
80  double activeLength(const DetId&);
81  bool isGoodVertex(const reco::Vertex& vtx);
82  // ----------member data ---------------------------
89  bool useRaw_;
90  const int MaxDepth=7;
91 
98 
100  std::vector<double> ptGlob_, etaGlob_, phiGlob_, chiGlobal_;
104  std::vector<double> matchedId_,numPixelLayers_;
105  std::vector<double> chiTracker_,dxyTracker_,dzTracker_;
109  std::vector<bool> innerTrack_, outerTrack_, globalTrack_;
110  std::vector<double> isolationR04_,isolationR03_;
113  std::vector<unsigned int> ecalDetId_,hcalDetId_,ehcalDetId_;
129  std::vector<HcalDDDRecConstants::HcalActiveLength> actHB, actHE;
130  std::vector<std::string> all_triggers;
132 
133  TTree *tree_;
135  std::vector<int> hltresults;
137  };
138 
140  //now do what ever initialization is needed
141  kount_ = 0;
142  HLTriggerResults_ = iConfig.getParameter<edm::InputTag>("HLTriggerResults");
143  labelVtx_ = iConfig.getParameter<std::string>("LabelVertex");
144  labelEBRecHit_ = iConfig.getParameter<std::string>("LabelEBRecHit");
145  labelEERecHit_ = iConfig.getParameter<std::string>("LabelEERecHit");
146  labelHBHERecHit_ = iConfig.getParameter<std::string>("LabelHBHERecHit");
147  labelMuon_ = iConfig.getParameter<std::string>("LabelMuon");
148  verbosity_ = iConfig.getUntrackedParameter<int>("Verbosity",0);
149  maxDepth_ = iConfig.getUntrackedParameter<int>("MaxDepth",4);
150  if (maxDepth_ > MaxDepth) maxDepth_ = MaxDepth;
151  else if (maxDepth_ < 1) maxDepth_ = 4;
152  std::string modnam = iConfig.getUntrackedParameter<std::string>("ModuleName","");
153  std::string procnm = iConfig.getUntrackedParameter<std::string>("ProcessName","");
154  useRaw_ = iConfig.getUntrackedParameter<bool>("UseRaw",false);
155 
156  tok_trigRes_ = consumes<edm::TriggerResults>(HLTriggerResults_);
157  if (modnam == "") {
158  tok_Vtx_ = consumes<reco::VertexCollection>(labelVtx_);
159  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit",labelEBRecHit_));
160  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit",labelEERecHit_));
161  tok_HBHE_ = consumes<HBHERecHitCollection>(labelHBHERecHit_);
162  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
163  edm::LogInfo("HBHEMuon") << "Labels used " << HLTriggerResults_ << " "
164  << labelVtx_ << " " << labelEBRecHit_ << " "
165  << labelEERecHit_ << " " << labelHBHERecHit_
166  << " " << labelMuon_;
167  } else {
168  tok_Vtx_ = consumes<reco::VertexCollection>(edm::InputTag(modnam,labelVtx_,procnm));
169  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag(modnam,labelEBRecHit_,procnm));
170  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag(modnam,labelEERecHit_,procnm));
171  tok_HBHE_ = consumes<HBHERecHitCollection>(edm::InputTag(modnam,labelHBHERecHit_,procnm));
172  tok_Muon_ = consumes<reco::MuonCollection>(edm::InputTag(modnam,labelMuon_,procnm));
173  edm::LogInfo("HBHEMuon") << "Labels used " << HLTriggerResults_
174  << "\n " << edm::InputTag(modnam,labelVtx_,procnm)
175  << "\n " << edm::InputTag(modnam,labelEBRecHit_,procnm)
176  << "\n " << edm::InputTag(modnam,labelEERecHit_,procnm)
177  << "\n " << edm::InputTag(modnam,labelHBHERecHit_,procnm)
178  << "\n " << edm::InputTag(modnam,labelMuon_,procnm);
179  }
180 }
181 
183  // do anything here that needs to be done at desctruction time
184  // (e.g. close files, deallocate resources etc.)
185 }
186 
187 //
188 // member functions
189 //
190 
191 // ------------ method called for each event ------------
193  ++kount_;
194  clearVectors();
195  // depthHE is the first depth index for HE for |ieta| = 16
196  // It used to be 3 for all runs preceding 2017 and 4 beyond that
197  int depthHE = (maxDepth_ <= 6) ? 3 : 4;
198  runNumber_ = iEvent.id().run();
199  eventNumber_ = iEvent.id().event();
200  lumiNumber_ = iEvent.id().luminosityBlock();
201  bxNumber_ = iEvent.bunchCrossing();
202 #ifdef EDM_ML_DEBUG
203  edm::LogInfo("HBHEMuon") << "Run " << runNumber_ << " Event " << eventNumber_
204  << " Lumi " << lumiNumber_ << " BX " << bxNumber_
205  << std::endl;
206 #endif
208  iEvent.getByToken(tok_trigRes_, _Triggers);
209 #ifdef EDM_ML_DEBUG
210  edm::LogInfo("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  edm::LogInfo("HBHEMuon") << "Size of HLT MENU: " << _Triggers->size()
216  << std::endl;
217 #endif
218  if (_Triggers.isValid()) {
219  const edm::TriggerNames &triggerNames_ = iEvent.triggerNames(*_Triggers);
220  std::vector<int> index;
221  for (int i=0; i<Ntriggers; i++) {
222  index.push_back(triggerNames_.triggerIndex(all_triggers[i]));
223  int triggerSize = int( _Triggers->size());
224 #ifdef EDM_ML_DEBUG
225  edm::LogInfo("HBHEMuon") << "outside loop " << index[i]
226  << "\ntriggerSize " << triggerSize
227  << std::endl;
228 #endif
229  if (index[i] < triggerSize) {
230  hltresults.push_back(_Triggers->accept(index[i]));
231 #ifdef EDM_ML_DEBUG
232  edm::LogInfo("HBHEMuon") << "Trigger_info " << triggerSize
233  << " triggerSize " << index[i]
234  << " trigger_index " << hltresults.at(i)
235  << " hltresult" << std::endl;
236 #endif
237  } else {
238  edm::LogInfo("HBHEMuon") << "Requested HLT path \""
239  << "\" does not exist\n";
240  }
241  }
242  }
243 
245  iSetup.get<CaloGeometryRecord>().get(pG);
246  const CaloGeometry* geo = pG.product();
247 
249  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
250  const MagneticField* bField = bFieldH.product();
251 
253  iSetup.get<EcalChannelStatusRcd>().get(ecalChStatus);
254  const EcalChannelStatus* theEcalChStatus = ecalChStatus.product();
255 
257  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
258 
259  edm::ESHandle<CaloTopology> theCaloTopology;
260  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
261  const CaloTopology *caloTopology = theCaloTopology.product();
262 
264  iSetup.get<HcalRecNumberingRecord>().get(htopo);
265  const HcalTopology* theHBHETopology = htopo.product();
266 
267  // Relevant blocks from iEvent
269  iEvent.getByToken(tok_Vtx_, vtx);
270 
271  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
272  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
273  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
274  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
275 
277  iEvent.getByToken(tok_HBHE_, hbhe);
278 
280  iEvent.getByToken(tok_Muon_, _Muon);
281 
282  // get handles to calogeometry and calotopology
283  if (!(vtx.isValid())) return;
284  reco::VertexCollection::const_iterator firstGoodVertex = vtx->end();
285  for (reco::VertexCollection::const_iterator it = vtx->begin(); it != firstGoodVertex; it++) {
286  if (isGoodVertex(*it)) {
287  firstGoodVertex = it;
288  break;
289  }
290  }
291  // require a good vertex
292  if (firstGoodVertex == vtx->end()) return;
293 
294  bool accept(false);
295  if (_Muon.isValid() && barrelRecHitsHandle.isValid() &&
296  endcapRecHitsHandle.isValid() && hbhe.isValid()) {
297  for (reco::MuonCollection::const_iterator RecMuon = _Muon->begin(); RecMuon!= _Muon->end(); ++RecMuon) {
298 
299  if (RecMuon->p() > 10.0) accept = true;
300 
301  muon_is_good_.push_back(RecMuon->isPFMuon());
302  muon_global_.push_back(RecMuon->isGlobalMuon());
303  muon_tracker_.push_back(RecMuon->isTrackerMuon());
304  ptGlob_.push_back((RecMuon)->pt());
305  etaGlob_.push_back(RecMuon->eta());
306  phiGlob_.push_back(RecMuon->phi());
307  energyMuon_.push_back(RecMuon->energy());
308  pMuon_.push_back(RecMuon->p());
309 #ifdef EDM_ML_DEBUG
310  edm::LogInfo("HBHEMuon") << "Energy:" << RecMuon->energy() << " P:"
311  << RecMuon->p() << std::endl;
312 #endif
313  // acessing tracker hits info
314  if (RecMuon->track().isNonnull()) {
315  trackerLayer_.push_back(RecMuon->track()->hitPattern().trackerLayersWithMeasurement());
316  } else {
317  trackerLayer_.push_back(-1);
318  }
319  if (RecMuon->innerTrack().isNonnull()) {
320  innerTrack_.push_back(true);
321  numPixelLayers_.push_back(RecMuon->innerTrack()->hitPattern().pixelLayersWithMeasurement());
322  chiTracker_.push_back(RecMuon->innerTrack()->normalizedChi2());
323  dxyTracker_.push_back(fabs(RecMuon->innerTrack()->dxy((*firstGoodVertex).position())));
324  dzTracker_.push_back(fabs(RecMuon->innerTrack()->dz((*firstGoodVertex).position())));
325  innerTrackpt_.push_back(RecMuon->innerTrack()->pt());
326  innerTracketa_.push_back(RecMuon->innerTrack()->eta());
327  innerTrackphi_.push_back(RecMuon->innerTrack()->phi());
328  tight_PixelHits_.push_back(RecMuon->innerTrack()->hitPattern().numberOfValidPixelHits());
329  } else {
330  innerTrack_.push_back(false);
331  numPixelLayers_.push_back(0);
332  chiTracker_.push_back(0);
333  dxyTracker_.push_back(0);
334  dzTracker_.push_back(0);
335  innerTrackpt_.push_back(0);
336  innerTracketa_.push_back(0);
337  innerTrackphi_.push_back(0);
338  tight_PixelHits_.push_back(0);
339  }
340  // outer track info
341  if (RecMuon->outerTrack().isNonnull()) {
342  outerTrack_.push_back(true);
343  outerTrackPt_.push_back(RecMuon->outerTrack()->pt());
344  outerTrackEta_.push_back(RecMuon->outerTrack()->eta());
345  outerTrackPhi_.push_back(RecMuon->outerTrack()->phi());
346  outerTrackChi_.push_back(RecMuon->outerTrack()->normalizedChi2());
347  outerTrackHits_.push_back(RecMuon->outerTrack()->numberOfValidHits());
348  outerTrackRHits_.push_back(RecMuon->outerTrack()->recHitsSize());
349  } else {
350  outerTrack_.push_back(false);
351  outerTrackPt_.push_back(0);
352  outerTrackEta_.push_back(0);
353  outerTrackPhi_.push_back(0);
354  outerTrackChi_.push_back(0);
355  outerTrackHits_.push_back(0);
356  outerTrackRHits_.push_back(0);
357  }
358  // Tight Muon cuts
359  if (RecMuon->globalTrack().isNonnull()) {
360  globalTrack_.push_back(true);
361  chiGlobal_.push_back(RecMuon->globalTrack()->normalizedChi2());
362  globalMuonHits_.push_back(RecMuon->globalTrack()->hitPattern().numberOfValidMuonHits());
363  matchedStat_.push_back(RecMuon->numberOfMatchedStations());
364  globalTrckPt_.push_back(RecMuon->globalTrack()->pt());
365  globalTrckEta_.push_back(RecMuon->globalTrack()->eta());
366  globalTrckPhi_.push_back(RecMuon->globalTrack()->phi());
367  tight_TransImpara_.push_back(fabs(RecMuon->muonBestTrack()->dxy((*firstGoodVertex).position())));
368  tight_LongPara_.push_back(fabs(RecMuon->muonBestTrack()->dz((*firstGoodVertex).position())));
369  } else {
370  globalTrack_.push_back(false);
371  chiGlobal_.push_back(0);
372  globalMuonHits_.push_back(0);
373  matchedStat_.push_back(0);
374  globalTrckPt_.push_back(0);
375  globalTrckEta_.push_back(0);
376  globalTrckPhi_.push_back(0);
377  tight_TransImpara_.push_back(0);
378  tight_LongPara_.push_back(0);
379  }
380 
381  isolationR04_.push_back(((RecMuon->pfIsolationR04().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR04().sumNeutralHadronEt + RecMuon->pfIsolationR04().sumPhotonEt - (0.5 *RecMuon->pfIsolationR04().sumPUPt))) / RecMuon->pt()) );
382 
383  isolationR03_.push_back(((RecMuon->pfIsolationR03().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR03().sumNeutralHadronEt + RecMuon->pfIsolationR03().sumPhotonEt - (0.5 * RecMuon->pfIsolationR03().sumPUPt))) / RecMuon->pt()));
384 
385  ecalEnergy_.push_back(RecMuon->calEnergy().emS9);
386  hcalEnergy_.push_back(RecMuon->calEnergy().hadS9);
387  hoEnergy_.push_back(RecMuon->calEnergy().hoS9);
388 
389  double eEcal(0), eHcal(0), activeLengthTot(0), activeLengthHotTot(0);
390  double eHcalDepth[MaxDepth], eHcalDepthHot[MaxDepth];
391  double activeL[MaxDepth], activeHotL[MaxDepth];
392  unsigned int isHot(0);
393  bool tmpmatch(false);
394  for (int i=0; i<MaxDepth; ++i)
395  eHcalDepth[i] = eHcalDepthHot[i] = activeL[i] = activeHotL[i] = -10000;
396 
397  if (RecMuon->innerTrack().isNonnull()) {
398  const reco::Track* pTrack = (RecMuon->innerTrack()).get();
399  spr::propagatedTrackID trackID = spr::propagateCALO(pTrack, geo, bField, (((verbosity_/100)%10>0)));
400 
401  ecalDetId_.push_back((trackID.detIdECAL)());
402  hcalDetId_.push_back((trackID.detIdHCAL)());
403  ehcalDetId_.push_back((trackID.detIdEHCAL)());
404 
406  std::pair<bool,HcalDetId> info = spr::propagateHCALBack(pTrack, geo, bField, (((verbosity_/100)%10>0)));
407  if (info.first) {
408  check = info.second;
409  }
410 
411  bool okE = trackID.okECAL;
412  if (okE) {
413  const DetId isoCell(trackID.detIdECAL);
414  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);
415  eEcal = e3x3.first;
416  okE = e3x3.second;
417  }
418 #ifdef EDM_ML_DEBUG
419  edm::LogInfo("HBHEMuon") << "Propagate Track to ECAL: " << okE << ":"
420  << trackID.okECAL << " E "
421  << eEcal << std::endl;
422 #endif
423 
424  if (trackID.okHCAL) {
425  const DetId closestCell(trackID.detIdHCAL);
426  HcalDetId hcidt(closestCell.rawId());
427  if ((hcidt.ieta() == check.ieta()) && (hcidt.iphi() == check.iphi()))
428  tmpmatch= true;
429 
430  HcalSubdetector subdet = HcalDetId(closestCell).subdet();
431  int ieta = HcalDetId(closestCell).ieta();
432  int iphi = HcalDetId(closestCell).iphi();
433  bool hborhe = (std::abs(ieta) == 16);
434 
435  eHcal = spr::eHCALmatrix(theHBHETopology, closestCell, hbhe,0,0, false, true, -100.0, -100.0, -100.0, -100.0, -500.,500.,useRaw_);
436  std::vector<std::pair<double,int> > ehdepth;
437  spr::energyHCALCell((HcalDetId) closestCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, useRaw_, (((verbosity_/1000)%10)>0));
438  for (unsigned int i=0; i<ehdepth.size(); ++i) {
439  eHcalDepth[ehdepth[i].second-1] = ehdepth[i].first;
440  HcalSubdetector subdet0 = (hborhe) ? ((ehdepth[i].second >= depthHE) ? HcalEndcap : HcalBarrel) : subdet;
441  HcalDetId hcid0(subdet0,ieta,iphi,ehdepth[i].second);
442  double actL = activeLength(DetId(hcid0));
443  activeL[ehdepth[i].second-1] = actL;
444  activeLengthTot += actL;
445 #ifdef EDM_ML_DEBUG
446  if ((verbosity_%10) > 0)
447  edm::LogInfo("HBHEMuon") << hcid0 << " E " << ehdepth[i].first
448  << " L " << actL << std::endl;
449 #endif
450  }
451 
452  HcalDetId hotCell;
453  spr::eHCALmatrix(geo, theHBHETopology, closestCell, hbhe, 1,1, hotCell, false, useRaw_, false);
454  isHot = matchId(closestCell,hotCell);
455  if (hotCell != HcalDetId()) {
456  subdet = HcalDetId(hotCell).subdet();
457  ieta = HcalDetId(hotCell).ieta();
458  iphi = HcalDetId(hotCell).iphi();
459  hborhe = (std::abs(ieta) == 16);
460  std::vector<std::pair<double,int> > ehdepth;
461  spr::energyHCALCell(hotCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, useRaw_, false);//(((verbosity_/1000)%10)>0 ));
462  for (unsigned int i=0; i<ehdepth.size(); ++i) {
463  eHcalDepthHot[ehdepth[i].second-1] = ehdepth[i].first;
464  HcalSubdetector subdet0 = (hborhe) ? ((ehdepth[i].second >= depthHE) ? HcalEndcap : HcalBarrel) : subdet;
465  HcalDetId hcid0(subdet0,ieta,iphi,ehdepth[i].second);
466  double actL = activeLength(DetId(hcid0));
467  activeHotL[ehdepth[i].second-1] = actL;
468  activeLengthHotTot += actL;
469 #ifdef EDM_ML_DEBUG
470  if ((verbosity_%10) > 0)
471  edm::LogInfo("HBHEMuon") << hcid0 << " E " << ehdepth[i].first
472  << " L " << actL << std::endl;
473 #endif
474  }
475  }
476  }
477 #ifdef EDM_ML_DEBUG
478  edm::LogInfo("HBHEMuon") << "Propagate Track to HCAL: "
479  << trackID.okHCAL << " Match " << tmpmatch
480  << " Hot " << isHot << " Energy "
481  << eHcal << std::endl;
482 #endif
483 
484  } else {
485  ecalDetId_.push_back(0);
486  hcalDetId_.push_back(0);
487  ehcalDetId_.push_back(0);
488  }
489 
490  matchedId_.push_back(tmpmatch);
491  ecal3x3Energy_.push_back(eEcal);
492  hcal1x1Energy_.push_back(eHcal);
493  hcalDepth1Energy_.push_back(eHcalDepth[0]);
494  hcalDepth2Energy_.push_back(eHcalDepth[1]);
495  hcalDepth3Energy_.push_back(eHcalDepth[2]);
496  hcalDepth4Energy_.push_back(eHcalDepth[3]);
497  hcalDepth5Energy_.push_back(eHcalDepth[4]);
498  hcalDepth6Energy_.push_back(eHcalDepth[5]);
499  hcalDepth7Energy_.push_back(eHcalDepth[6]);
500  hcalDepth1ActiveLength_.push_back(activeL[0]);
501  hcalDepth2ActiveLength_.push_back(activeL[1]);
502  hcalDepth3ActiveLength_.push_back(activeL[2]);
503  hcalDepth4ActiveLength_.push_back(activeL[3]);
504  hcalDepth5ActiveLength_.push_back(activeL[4]);
505  hcalDepth6ActiveLength_.push_back(activeL[5]);
506  hcalDepth7ActiveLength_.push_back(activeL[6]);
507  hcalActiveLength_.push_back(activeLengthTot);
508  hcalHot_.push_back(isHot);
509  hcalDepth1EnergyHot_.push_back(eHcalDepthHot[0]);
510  hcalDepth2EnergyHot_.push_back(eHcalDepthHot[1]);
511  hcalDepth3EnergyHot_.push_back(eHcalDepthHot[2]);
512  hcalDepth4EnergyHot_.push_back(eHcalDepthHot[3]);
513  hcalDepth5EnergyHot_.push_back(eHcalDepthHot[4]);
514  hcalDepth6EnergyHot_.push_back(eHcalDepthHot[5]);
515  hcalDepth7EnergyHot_.push_back(eHcalDepthHot[6]);
516  hcalDepth1ActiveLengthHot_.push_back(activeHotL[0]);
517  hcalDepth2ActiveLengthHot_.push_back(activeHotL[1]);
518  hcalDepth3ActiveLengthHot_.push_back(activeHotL[2]);
519  hcalDepth4ActiveLengthHot_.push_back(activeHotL[3]);
520  hcalDepth5ActiveLengthHot_.push_back(activeHotL[4]);
521  hcalDepth6ActiveLengthHot_.push_back(activeHotL[5]);
522  hcalDepth7ActiveLengthHot_.push_back(activeHotL[6]);
523  hcalActiveLengthHot_.push_back(activeLengthHotTot);
524  }
525  }
526  if (accept) tree_->Fill();
527 }
528 
529 // ------------ method called once each job just before starting event loop ------------
531 
532  tree_ = fs->make<TTree>("TREE", "TREE");
533  tree_->Branch("Event_No", &eventNumber_);
534  tree_->Branch("Run_No", &runNumber_);
535  tree_->Branch("LumiNumber", &lumiNumber_);
536  tree_->Branch("BXNumber", &bxNumber_);
537  tree_->Branch("pt_of_muon", &ptGlob_);
538  tree_->Branch("eta_of_muon", &etaGlob_);
539  tree_->Branch("phi_of_muon", &phiGlob_);
540  tree_->Branch("energy_of_muon", &energyMuon_);
541  tree_->Branch("p_of_muon", &pMuon_);
542  tree_->Branch("PF_Muon", &muon_is_good_);
543  tree_->Branch("Global_Muon", &muon_global_);
544  tree_->Branch("Tracker_muon", &muon_tracker_);
545 
546  tree_->Branch("hcal_3into3", &hcalEnergy_);
547  tree_->Branch("hcal_1x1", &hcal1x1Energy_);
548  tree_->Branch("hcal_detID", &hcalDetId_);
549  tree_->Branch("hcal_cellHot", &hcalHot_);
550  tree_->Branch("activeLength", &hcalActiveLength_);
551  tree_->Branch("hcal_edepth1", &hcalDepth1Energy_);
552  tree_->Branch("hcal_edepth2", &hcalDepth2Energy_);
553  tree_->Branch("hcal_edepth3", &hcalDepth3Energy_);
554  tree_->Branch("hcal_edepth4", &hcalDepth4Energy_);
555  tree_->Branch("hcal_activeL1", &hcalDepth1ActiveLength_);
556  tree_->Branch("hcal_activeL2", &hcalDepth2ActiveLength_);
557  tree_->Branch("hcal_activeL3", &hcalDepth3ActiveLength_);
558  tree_->Branch("hcal_activeL4", &hcalDepth4ActiveLength_);
559  tree_->Branch("activeLengthHot", &hcalActiveLengthHot_);
560  tree_->Branch("hcal_edepthHot1", &hcalDepth1EnergyHot_);
561  tree_->Branch("hcal_edepthHot2", &hcalDepth2EnergyHot_);
562  tree_->Branch("hcal_edepthHot3", &hcalDepth3EnergyHot_);
563  tree_->Branch("hcal_edepthHot4", &hcalDepth4EnergyHot_);
564  tree_->Branch("hcal_activeHotL1", &hcalDepth1ActiveLength_);
565  tree_->Branch("hcal_activeHotL2", &hcalDepth2ActiveLength_);
566  tree_->Branch("hcal_activeHotL3", &hcalDepth3ActiveLength_);
567  tree_->Branch("hcal_activeHotL4", &hcalDepth4ActiveLength_);
568 
569  if (maxDepth_ > 4) {
570  tree_->Branch("hcal_edepth5", &hcalDepth5Energy_);
571  tree_->Branch("hcal_activeL5", &hcalDepth5ActiveLength_);
572  tree_->Branch("hcal_edepthHot5", &hcalDepth5EnergyHot_);
573  tree_->Branch("hcal_activeHotL5", &hcalDepth5ActiveLength_);
574  if (maxDepth_ > 5) {
575  tree_->Branch("hcal_edepth6", &hcalDepth6Energy_);
576  tree_->Branch("hcal_activeL6", &hcalDepth6ActiveLength_);
577  tree_->Branch("hcal_edepthHot6", &hcalDepth6EnergyHot_);
578  tree_->Branch("hcal_activeHotL6", &hcalDepth6ActiveLength_);
579  if (maxDepth_ > 6) {
580  tree_->Branch("hcal_edepth7", &hcalDepth7Energy_);
581  tree_->Branch("hcal_activeL7", &hcalDepth7ActiveLength_);
582  tree_->Branch("hcal_edepthHot7", &hcalDepth7EnergyHot_);
583  tree_->Branch("hcal_activeHotL7", &hcalDepth7ActiveLength_);
584  }
585  }
586  }
587 
588 
589  tree_->Branch("TrackerLayer", &trackerLayer_);
590  tree_->Branch("matchedId", &matchedId_);
591  tree_->Branch("innerTrack", &innerTrack_);
592  tree_->Branch("innerTrackpt", &innerTrackpt_);
593  tree_->Branch("innerTracketa", &innerTracketa_);
594  tree_->Branch("innerTrackphi", &innerTrackphi_);
595  tree_->Branch("MatchedStat", &matchedStat_);
596  tree_->Branch("GlobalTrckPt", &globalTrckPt_);
597  tree_->Branch("GlobalTrckEta", &globalTrckEta_);
598  tree_->Branch("GlobalTrckPhi", &globalTrckPhi_);
599  tree_->Branch("NumPixelLayers", &numPixelLayers_);
600  tree_->Branch("chiTracker", &chiTracker_);
601  tree_->Branch("DxyTracker", &dxyTracker_);
602  tree_->Branch("DzTracker", &dzTracker_);
603  tree_->Branch("OuterTrack", &outerTrack_);
604  tree_->Branch("OuterTrackPt", &outerTrackPt_);
605  tree_->Branch("OuterTrackEta", &outerTrackEta_);
606  tree_->Branch("OuterTrackPhi", &outerTrackPhi_);
607  tree_->Branch("OuterTrackHits", &outerTrackHits_);
608  tree_->Branch("OuterTrackRHits", &outerTrackRHits_);
609  tree_->Branch("OuterTrackChi", &outerTrackChi_);
610  tree_->Branch("GlobalTrack", &globalTrack_);
611  tree_->Branch("GlobTrack_Chi", &chiGlobal_);
612  tree_->Branch("Global_Muon_Hits", &globalMuonHits_);
613  tree_->Branch("MatchedStations", &matchedStat_);
614  tree_->Branch("Global_Track_Pt", &globalTrckPt_);
615  tree_->Branch("Global_Track_Eta", &globalTrckEta_);
616  tree_->Branch("Global_Track_Phi", &globalTrckPhi_);
618  tree_->Branch("Tight_LongitudinalImpactparameter",&tight_LongPara_);
619  tree_->Branch("Tight_TransImpactparameter", &tight_TransImpara_);
620  tree_->Branch("InnerTrackPixelHits", &tight_PixelHits_);
621  tree_->Branch("IsolationR04", &isolationR04_);
622  tree_->Branch("IsolationR03", &isolationR03_);
623 
624  tree_->Branch("ecal_3into3", &ecalEnergy_);
625  tree_->Branch("ecal_3x3", &ecal3x3Energy_);
626  tree_->Branch("ecal_detID", &ecalDetId_);
627  tree_->Branch("ehcal_detID", &ehcalDetId_);
628  tree_->Branch("tracker_3into3", &hoEnergy_);
629 
631  tree_->Branch("hltresults", &hltresults);
632  tree_->Branch("all_triggers", &all_triggers);
633 
634 }
635 
636 // ------------ method called once each job just after ending the event loop ------------
638 
639 // ------------ method called when starting to processes a run ------------
640 void HcalHBHEMuonAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
641 
643  iSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
644  const HcalDDDRecConstants & hdc = (*pHRNDC);
645  actHB.clear();
646  actHE.clear();
647  actHB = hdc.getThickActive(0);
648  actHE = hdc.getThickActive(1);
649 
650  bool changed = true;
651  all_triggers.clear();
652  if (hltConfig_.init(iRun, iSetup,"HLT" , changed)) {
653  // if init returns TRUE, initialisation has succeeded!
654 #ifdef EDM_ML_DEBUG
655  edm::LogInfo("HBHEMuon") << "HLT config with process name "
656  << "HLT" << " successfully extracted"
657  << std::endl;
658 #endif
659 // std::string string_search[5]={"HLT_IsoMu_","HLT_L1SingleMu_","HLT_L2Mu","HLT_Mu","HLT_RelIso1p0Mu"};
660  std::string string_search[6]={"HLT_IsoMu17","HLT_IsoMu20","HLT_IsoMu24","HLT_IsoMu27","HLT_Mu45","HLT_Mu50"};
661 
662  unsigned int ntriggers = hltConfig_.size();
663  for (unsigned int t=0;t<ntriggers;++t) {
665  for (unsigned int ik=0; ik<6; ++ik) {
666  if (hltname.find(string_search[ik])!=std::string::npos ){
667  all_triggers.push_back(hltname);
668  break;
669  }
670  }
671  }//loop over ntriggers
672  edm::LogInfo("HBHEMuon") << "All triggers size in begin run "
673  << all_triggers.size() << std::endl;
674  } else {
675  edm::LogError("HBHEMuon") << "Error! HLT config extraction with process name "
676  << "HLT" << " failed";
677  }
678 
679 }
680 
681 
682 // ------------ method called when ending the processing of a run ------------
684 
685 // ------------ method called when starting to processes a luminosity block ------------
687 
688 // ------------ method called when ending the processing of a luminosity block ------------
690 
691 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
693  //The following says we do not know what parameters are allowed so do no validation
694  // Please change this to state exactly what you do use, even if it is no parameters
696  desc.setUnknown();
697  descriptions.addDefault(desc);
698 }
699 
702  eventNumber_ = -99999;
703  runNumber_ = -99999;
704  lumiNumber_ = -99999;
705  bxNumber_ = -99999;
706  muon_is_good_.clear();
707  muon_global_.clear();
708  muon_tracker_.clear();
709  ptGlob_.clear();
710  etaGlob_.clear();
711  phiGlob_.clear();
712  energyMuon_.clear();
713  pMuon_.clear();
714  trackerLayer_.clear();
715  matchedId_.clear();
716  innerTrack_.clear();
717  numPixelLayers_.clear();
718  chiTracker_.clear();
719  dxyTracker_.clear();
720  dzTracker_.clear();
721  innerTrackpt_.clear();
722  innerTracketa_.clear();
723  innerTrackphi_.clear();
724  tight_PixelHits_.clear();
725  outerTrack_.clear();
726  outerTrackPt_.clear();
727  outerTrackEta_.clear();
728  outerTrackPhi_.clear();
729  outerTrackHits_.clear();
730  outerTrackRHits_.clear();
731  outerTrackChi_.clear();
732  globalTrack_.clear();
733  chiGlobal_.clear();
734  globalMuonHits_.clear();
735  matchedStat_.clear();
736  globalTrckPt_.clear();
737  globalTrckEta_.clear();
738  globalTrckPhi_.clear();
739  tight_TransImpara_.clear();
740  tight_LongPara_.clear();
741 
742  isolationR04_.clear();
743  isolationR03_.clear();
744  ecalEnergy_.clear();
745  hcalEnergy_.clear();
746  hoEnergy_.clear();
747  ecalDetId_.clear();
748  hcalDetId_.clear();
749  ehcalDetId_.clear();
750  ecal3x3Energy_.clear();
751  hcal1x1Energy_.clear();
752  hcalHot_.clear();
753  hcalDepth1Energy_.clear();
754  hcalDepth2Energy_.clear();
755  hcalDepth3Energy_.clear();
756  hcalDepth4Energy_.clear();
757  hcalDepth5Energy_.clear();
758  hcalDepth6Energy_.clear();
759  hcalDepth7Energy_.clear();
760  hcalDepth1ActiveLength_.clear();
761  hcalDepth2ActiveLength_.clear();
762  hcalDepth3ActiveLength_.clear();
763  hcalDepth4ActiveLength_.clear();
764  hcalDepth5ActiveLength_.clear();
765  hcalDepth6ActiveLength_.clear();
766  hcalDepth7ActiveLength_.clear();
767  hcalActiveLengthHot_.clear();
768  hcalDepth1EnergyHot_.clear();
769  hcalDepth2EnergyHot_.clear();
770  hcalDepth3EnergyHot_.clear();
771  hcalDepth4EnergyHot_.clear();
772  hcalDepth5EnergyHot_.clear();
773  hcalDepth6EnergyHot_.clear();
774  hcalDepth7EnergyHot_.clear();
782  hltresults.clear();
783 }
784 
785 int HcalHBHEMuonAnalyzer::matchId(const HcalDetId& id1, const HcalDetId& id2) {
786 
787  HcalDetId kd1(id1.subdet(),id1.ieta(),id1.iphi(),1);
788  HcalDetId kd2(id2.subdet(),id2.ieta(),id2.iphi(),1);
789  int match = ((kd1 == kd2) ? 1 : 0);
790  return match;
791 }
792 
794  HcalDetId id(id_);
795  int ieta = id.ietaAbs();
796  int depth= id.depth();
797  double lx(0);
798  if (id.subdet() == HcalBarrel) {
799  for (unsigned int i=0; i<actHB.size(); ++i) {
800  if (ieta == actHB[i].ieta && depth == actHB[i].depth) {
801  lx = actHB[i].thick;
802  break;
803  }
804  }
805  } else {
806  for (unsigned int i=0; i<actHE.size(); ++i) {
807  if (ieta == actHE[i].ieta && depth == actHE[i].depth) {
808  lx = actHE[i].thick;
809  break;
810  }
811  }
812  }
813  return lx;
814 }
815 
817  if (vtx.isFake()) return false;
818  if (vtx.ndof() < 4) return false;
819  if (vtx.position().Rho() > 2.) return false;
820  if (fabs(vtx.position().Z()) > 24.) return false;
821  return true;
822 }
823 
824 //define this as a plug-in
826 
828 
RunNumber_t run() const
Definition: EventID.h:39
unsigned int size() const
number of trigger paths in trigger table
std::vector< double > hcalDepth1Energy_
std::vector< double > hcalDepth5EnergyHot_
std::vector< double > hcalDepth6Energy_
std::vector< double > hcalDepth7Energy_
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
std::vector< double > innerTrackphi_
std::vector< double > hcalDepth7ActiveLengthHot_
HcalHBHEMuonAnalyzer(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > hcalDepth1ActiveLength_
std::vector< double > hcalDepth1EnergyHot_
static const TGPicture * info(bool iBackgroundIsBlack)
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
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< double > hcalDepth6ActiveLengthHot_
std::vector< double > dzTracker_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
const std::string & triggerName(unsigned int triggerIndex) const
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
std::vector< double > outerTrackChi_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< double > matchedStat_
std::vector< double > tight_LongPara_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
std::vector< double > hcalDepth5ActiveLengthHot_
std::vector< HcalDDDRecConstants::HcalActiveLength > actHE
std::vector< double > isolationR03_
std::vector< double > hcalDepth2Energy_
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 > outerTrackPt_
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
std::vector< double > hcalDepth4Energy_
edm::EDGetTokenT< reco::VertexCollection > tok_Vtx_
std::vector< double > globalTrckPt_
int iEvent
Definition: GenABIO.cc:230
std::vector< double > hcalDepth2EnergyHot_
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< bool > muon_tracker_
std::vector< double > ecalEnergy_
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
std::vector< double > hcalDepth3ActiveLengthHot_
std::vector< double > hcalActiveLengthHot_
std::vector< double > innerTracketa_
std::vector< double > globalTrckEta_
std::vector< double > isolationR04_
std::vector< double > hcalDepth5ActiveLength_
std::vector< double > hcalDepth4EnergyHot_
std::vector< double > hcalDepth2ActiveLengthHot_
unsigned int size() const
Get number of paths stored.
std::vector< double > ptGlob_
std::vector< unsigned int > ehcalDetId_
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
std::pair< bool, HcalDetId > propagateHCALBack(const reco::Track *, const CaloGeometry *geo, const MagneticField *bField, bool debug=false)
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > tight_PixelHits_
std::vector< double > hcalEnergy_
std::vector< double > trackerLayer_
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_
std::vector< double > outerTrackRHits_
std::vector< double > hcal1x1Energy_
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
double ndof() const
Definition: Vertex.h:105
virtual void endRun(edm::Run const &, edm::EventSetup const &)
std::vector< HcalActiveLength > getThickActive(const int type) const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::vector< bool > muon_is_good_
std::vector< double > hcalDepth7ActiveLength_
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
Definition: DetId.h:18
std::vector< double > hcalDepth4ActiveLengthHot_
std::vector< double > hcalDepth6ActiveLength_
std::vector< double > chiGlobal_
std::vector< HcalDDDRecConstants::HcalActiveLength > actHB
std::vector< unsigned int > hcalDetId_
bool isFake() const
Definition: Vertex.h:72
std::vector< int > hltresults
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:56
std::vector< std::string > all_triggers
std::vector< double > globalMuonHits_
std::vector< double > hcalDepth3ActiveLength_
std::vector< double > hoEnergy_
std::vector< double > hcalDepth7EnergyHot_
std::vector< double > hcalDepth1ActiveLengthHot_
int matchId(const HcalDetId &, const HcalDetId &)
edm::EventID id() const
Definition: EventBase.h:60
std::vector< double > phiGlob_
std::vector< double > hcalDepth2ActiveLength_
HLTConfigProvider hltConfig_
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
std::vector< double > hcalActiveLength_
std::vector< double > hcalDepth3Energy_
std::vector< double > chiTracker_
std::vector< double > matchedId_
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
std::vector< double > hcalDepth5Energy_
std::vector< double > hcalDepth3EnergyHot_
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< double > hcalDepth6EnergyHot_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< bool > outerTrack_
def check(config)
Definition: trackerTree.py:14
std::vector< double > numPixelLayers_
edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
edm::Service< TFileService > fs
std::vector< double > hcalDepth4ActiveLength_
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_
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)