CMS 3D CMS Logo

MuTriggerAnalyzer.cc
Go to the documentation of this file.
16 #include "TGraphAsymmErrors.h"
17 #include "TH1.h"
18 #include <numeric>
19 #include <algorithm>
20 #include <string>
21 using namespace std;
22 using namespace reco;
23 using namespace edm;
24 
25 /*
26 bool IsMuMatchedToHLTMu ( const reco::Candidate * dau, std::vector<reco::Particle> HLTMu , double DR, double DPtRel ) {
27  unsigned int dim = HLTMu.size();
28  unsigned int nPass=0;
29  if (dim==0) return false;
30  for (unsigned int k =0; k< dim; k++ ) {
31  if ( (deltaR(HLTMu[k], *dau) < DR) && (fabs(HLTMu[k].pt() - dau->pt())/ HLTMu[k].pt()<DPtRel)){ nPass++ ;
32  }
33  }
34  return (nPass>0);
35 }
36 
37 bool IsMuMatchedToHLTSingleMu ( const reco::Candidate * dau, reco::Particle HLTMu , double DR, double DPtRel ) {
38  unsigned int nPass=0;
39  if ( (deltaR(HLTMu, *dau) < DR) && (fabs(HLTMu.pt() - dau->pt())/ HLTMu.pt()<DPtRel)) {
40  nPass++;
41  }
42  return (nPass>0);
43 }
44 
45 */
46 
48 public:
50 
51 private:
52  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
53  void endJob() override;
54  bool IsMuMatchedToHLTMu(const reco::Muon&, std::vector<reco::Particle>&, double, double);
55 
60  double ptMuCut_, etaMuCut_;
66 
67  double maxDPtRel_, maxDeltaR_;
68  const int nbins_;
69  const double ptMax_;
72  TH1D* deltaR_;
74 };
75 
77  std::vector<reco::Particle>& HLTMu,
78  double DR,
79  double DPtRel) {
80  size_t dim = HLTMu.size();
81  size_t nPass = 0;
82 
83  // filling the denumerator;
84  double muRecoPt = mu.pt();
85  hTrigMuonPtDenS_->Fill(muRecoPt);
86 
87  if (dim == 0)
88  return false;
89  for (size_t k = 0; k < dim; k++) {
90  if ((deltaR(HLTMu[k], mu) < DR) && (fabs(HLTMu[k].pt() - mu.pt()) / HLTMu[k].pt() < DPtRel)) {
91  nPass++;
92  std::cout << " matching a muon " << std::endl;
93  std::cout << "muon reco pt : " << muRecoPt << std::endl;
94  std::cout << "muon reco eta " << mu.eta() << std::endl;
95  std::cout << "muon trigger pt " << HLTMu[k].pt() << std::endl;
96  // filling the numerator, at the same bin as the denum.....
97  hTrigMuonPtNumS_->Fill(muRecoPt);
98  deltaR_->Fill(deltaR(HLTMu[k], mu));
99  deltaPtOverPt_->Fill(fabs(HLTMu[k].pt() - mu.pt()) / HLTMu[k].pt());
100 
101  std::cout << "muon trigger eta : " << HLTMu[k].eta() << std::endl;
102  std::cout << "deltaR((HLTMu[k], mu)): " << deltaR(HLTMu[k], mu) << std::endl;
103  std::cout << "deltaPtOverPt: " << fabs(HLTMu[k].pt() - mu.pt()) / HLTMu[k].pt() << std::endl;
104  }
105  }
106 
107  return (nPass > 0);
108 }
109 
111  : trigToken_(consumes<TriggerResults>(cfg.getParameter<edm::InputTag>("TrigTag"))),
112  trigEvTag_(cfg.getParameter<edm::InputTag>("triggerEvent")),
113  trigEvToken_(consumes<trigger::TriggerEvent>(trigEvTag_)),
114  muonToken_(consumes<View<Muon> >(cfg.getUntrackedParameter<edm::InputTag>("muons"))),
115  ptMuCut_(cfg.getUntrackedParameter<double>("ptMuCut")),
116  etaMuCut_(cfg.getUntrackedParameter<double>("etaMuCut")),
117  hltPath_(cfg.getParameter<std::string>("hltPath")),
118  L3FilterName_(cfg.getParameter<std::string>("L3FilterName")),
119  maxDPtRel_(cfg.getParameter<double>("maxDPtRel")),
120  maxDeltaR_(cfg.getParameter<double>("maxDeltaR")),
121  nbins_(cfg.getParameter<double>("ptMax_")),
122  ptMax_(cfg.getParameter<double>("ptMax_")) {
124 
125  hTrigMuonPtNumS_ = fs->make<TH1D>("hTrigMuonPtNumS", "hTrigMuonPtNumS", nbins_ + 1, 0, ptMax_);
126  hTrigMuonPtDenS_ = fs->make<TH1D>("hTrigMuonPtDenS", "hTrigMuonPtDenS", nbins_ + 1, 0, ptMax_);
127  deltaR_ = fs->make<TH1D>("deltaR", "deltaR", nbins_ + 1, 0, maxDeltaR_);
128  deltaPtOverPt_ = fs->make<TH1D>("deltaPtOverPt", "deltaPtOverPt", nbins_ + 1, 0, maxDPtRel_);
129 }
130 
132  for (int i = 0; i < nbins_ + 1; ++i) {
133  std::cout << "number of reco muon in bin " << i << " = " << hTrigMuonPtDenS_->GetBinContent(i) << std::endl;
134  std::cout << "number of hlt muon in bin " << i << " = " << hTrigMuonPtNumS_->GetBinContent(i) << std::endl;
135  }
136 }
137 
139  // bool overlap = false;
140 
141  // Trigger
144  if (!ev.getByToken(trigToken_, triggerResults)) {
145  LogWarning("") << ">>> TRIGGER collection does not exist !!!";
146  return;
147  }
148  // trigNames.init(*triggerResults);
149  trigNames_ = &ev.triggerNames(*triggerResults);
150  //bool trigger_fired = false;
151  for (unsigned int i = 0; i < triggerResults->size(); i++) {
153  if (trigName == hltPath_ && triggerResults->accept(i)) {
154  //trigger_fired = true;
155  }
156  }
157  edm::Handle<trigger::TriggerEvent> handleTriggerEvent;
158  // LogTrace("") << ">>> Trigger bit: " << trigger_fired << " (" << hltPath_ << ")";
159  if (!ev.getByToken(trigEvToken_, handleTriggerEvent)) {
160  LogWarning("errorTriggerEventValid") << "trigger::TriggerEvent product with InputTag " << trigEvTag_.encode()
161  << " not in event";
162  return;
163  }
164  const trigger::TriggerObjectCollection& toc(handleTriggerEvent->getObjects());
165  size_t nMuHLT = 0;
166  std::vector<reco::Particle> HLTMuMatched;
167  for (size_t ia = 0; ia < handleTriggerEvent->sizeFilters(); ++ia) {
168  std::string fullname = handleTriggerEvent->filterTag(ia).encode();
170  size_t p = fullname.find_first_of(':');
171  if (p != std::string::npos) {
172  name = fullname.substr(0, p);
173  } else {
174  name = fullname;
175  }
176  if (!toc.empty()) {
177  const trigger::Keys& k = handleTriggerEvent->filterKeys(ia);
178  for (trigger::Keys::const_iterator ki = k.begin(); ki != k.end(); ++ki) {
179  if (name == L3FilterName_) {
180  HLTMuMatched.push_back(toc[*ki].particle());
181  nMuHLT++;
182  }
183  }
184  }
185  }
186 
187  // looping on muon....
189  if (!ev.getByToken(muonToken_, muons)) {
190  LogError("") << ">>> muon collection does not exist !!!";
191  return;
192  }
193  //saving only muons with pt> ptMuCut and eta<etaMuCut
194  std::vector<reco::Muon> highPtGlbMuons;
195 
196  for (unsigned int i = 0; i < muons->size(); i++) {
197  const reco::Muon& mu = muons->at(i);
198  double pt = mu.pt();
199  double eta = mu.eta();
200  if (pt > ptMuCut_ && fabs(eta) < etaMuCut_) {
201  if (mu.isGlobalMuon())
202  highPtGlbMuons.push_back(mu);
203  }
204  }
205  unsigned int nHighPtGlbMu = highPtGlbMuons.size();
206  std::cout << "I've got " << nHighPtGlbMu << " nHighPtGlbMu" << std::endl;
207  // unsigned int nHighPtStaMu = highPtStaMuons.size();
208  // stop the loop after 10 cicles....
209  if (nHighPtGlbMu > 10)
210  nHighPtGlbMu = 10;
211 
212  for (unsigned int i = 0; i < nHighPtGlbMu; i++) {
213  IsMuMatchedToHLTMu(highPtGlbMuons[i], HLTMuMatched, maxDeltaR_, maxDPtRel_);
214  }
215 }
216 
218 
MuTriggerAnalyzer::deltaR_
TH1D * deltaR_
Definition: MuTriggerAnalyzer.cc:72
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
MuTriggerAnalyzer::triggerResults_
edm::Handle< edm::TriggerResults > triggerResults_
Definition: MuTriggerAnalyzer.cc:63
Handle.h
trigger::TriggerEvent::sizeFilters
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:146
mps_fire.i
i
Definition: mps_fire.py:355
MuTriggerAnalyzer::hTrigMuonPtNumS_
TH1D * hTrigMuonPtNumS_
Definition: MuTriggerAnalyzer.cc:70
Muon.h
trigger::TriggerEvent::filterKeys
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:118
IsMuMatchedToHLTMu
bool IsMuMatchedToHLTMu(const reco::Candidate *dau, std::vector< reco::Particle > HLTMu, double DR, double DPtRel)
Definition: ZGoldenFilter.cc:22
trigNames
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:57
MuTriggerAnalyzer::ptMax_
const double ptMax_
Definition: MuTriggerAnalyzer.cc:69
MuTriggerAnalyzer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
Definition: MuTriggerAnalyzer.cc:138
TriggerResults.h
MuTriggerAnalyzer::ptMuCut_
double ptMuCut_
Definition: MuTriggerAnalyzer.cc:60
MuTriggerAnalyzer::hltPath_
std::string hltPath_
Definition: MuTriggerAnalyzer.cc:61
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
TriggerEvent.h
edm::EDGetTokenT< TriggerResults >
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
MuTriggerAnalyzer::etaMuCut_
double etaMuCut_
Definition: MuTriggerAnalyzer.cc:60
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle< edm::TriggerResults >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
Muon
Definition: Muon.py:1
reco::Muon
Definition: Muon.h:27
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
MuTriggerAnalyzer::maxDPtRel_
double maxDPtRel_
Definition: MuTriggerAnalyzer.cc:67
nJettinessAdder_cfi.nPass
nPass
Definition: nJettinessAdder_cfi.py:14
deltaR.h
MakerMacros.h
trigger::TriggerEvent::filterTag
const edm::InputTag filterTag(trigger::size_type index) const
Definition: TriggerEvent.h:108
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
MuTriggerAnalyzer::nbins_
const int nbins_
Definition: MuTriggerAnalyzer.cc:68
dqmdumpme.k
k
Definition: dqmdumpme.py:60
MuTriggerAnalyzer::trigEvToken_
edm::EDGetTokenT< trigger::TriggerEvent > trigEvToken_
Definition: MuTriggerAnalyzer.cc:58
MuTriggerAnalyzer::MuTriggerAnalyzer
MuTriggerAnalyzer(const edm::ParameterSet &pset)
Definition: MuTriggerAnalyzer.cc:110
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EgHLTOffTrigSelection_cfi.trigName
trigName
Definition: EgHLTOffTrigSelection_cfi.py:8
edm::LogWarning
Definition: MessageLogger.h:141
TFileService.h
MuTriggerAnalyzer::trigToken_
edm::EDGetTokenT< TriggerResults > trigToken_
Definition: MuTriggerAnalyzer.cc:56
edm::View
Definition: CaloClusterFwd.h:14
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
trigger::TriggerObjectCollection
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
MuTriggerAnalyzer::endJob
void endJob() override
Definition: MuTriggerAnalyzer.cc:131
MuTriggerAnalyzer::deltaPtOverPt_
TH1D * deltaPtOverPt_
Definition: MuTriggerAnalyzer.cc:73
edm::Service< TFileService >
TriggerNames.h
trigger::Keys
std::vector< size_type > Keys
Definition: TriggerTypeDefs.h:19
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:57
MuTriggerAnalyzer::L3FilterName_
std::string L3FilterName_
Definition: MuTriggerAnalyzer.cc:62
trigger::TriggerEvent::getObjects
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:101
TriggerObject.h
InputTag.h
edm::TriggerNames::triggerName
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:22
looper.cfg
cfg
Definition: looper.py:297
std
Definition: JetResolutionObject.h:76
MuTriggerAnalyzer::IsMuMatchedToHLTMu
bool IsMuMatchedToHLTMu(const reco::Muon &, std::vector< reco::Particle > &, double, double)
Definition: MuTriggerAnalyzer.cc:76
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
edm::TriggerNames
Definition: TriggerNames.h:55
MuTriggerAnalyzer::muonToken_
edm::EDGetTokenT< View< Muon > > muonToken_
Definition: MuTriggerAnalyzer.cc:59
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
trigger
Definition: HLTPrescaleTableCond.h:8
Candidate.h
MuTriggerAnalyzer::hTrigMuonPtDenS_
TH1D * hTrigMuonPtDenS_
Definition: MuTriggerAnalyzer.cc:71
ParameterSet.h
MuTriggerAnalyzer
Definition: MuTriggerAnalyzer.cc:47
MuTriggerAnalyzer::maxDeltaR_
double maxDeltaR_
Definition: MuTriggerAnalyzer.cc:67
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
MuTriggerAnalyzer::trigEvTag_
edm::InputTag trigEvTag_
Definition: MuTriggerAnalyzer.cc:57
edm::InputTag
Definition: InputTag.h:15
edm::TriggerResults
Definition: TriggerResults.h:35
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
ZCounting_cff.TriggerEvent
TriggerEvent
Definition: ZCounting_cff.py:5
MuTriggerAnalyzer::trigNames_
edm::TriggerNames const * trigNames_
Definition: MuTriggerAnalyzer.cc:64
MuTriggerAnalyzer::handleTriggerEvent_
edm::Handle< trigger::TriggerEvent > handleTriggerEvent_
Definition: MuTriggerAnalyzer.cc:65