CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuTriggerAnalyzer.cc
Go to the documentation of this file.
17 #include "TGraphAsymmErrors.h"
18 #include "TH1.h"
19 #include <numeric>
20 #include <algorithm>
21 #include <string>
22 using namespace std;
23 using namespace reco;
24 using namespace edm;
25 
26 /*
27 bool IsMuMatchedToHLTMu ( const reco::Candidate * dau, std::vector<reco::Particle> HLTMu , double DR, double DPtRel ) {
28  unsigned int dim = HLTMu.size();
29  unsigned int nPass=0;
30  if (dim==0) return false;
31  for (unsigned int k =0; k< dim; k++ ) {
32  if ( (deltaR(HLTMu[k], *dau) < DR) && (fabs(HLTMu[k].pt() - dau->pt())/ HLTMu[k].pt()<DPtRel)){ nPass++ ;
33  }
34  }
35  return (nPass>0);
36 }
37 
38 bool IsMuMatchedToHLTSingleMu ( const reco::Candidate * dau, reco::Particle HLTMu , double DR, double DPtRel ) {
39  unsigned int nPass=0;
40  if ( (deltaR(HLTMu, *dau) < DR) && (fabs(HLTMu.pt() - dau->pt())/ HLTMu.pt()<DPtRel)) {
41  nPass++;
42  }
43  return (nPass>0);
44 }
45 
46 */
47 
48 
50 public:
52 
53 private:
54  virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
55  virtual void endJob();
56  bool IsMuMatchedToHLTMu ( const reco::Muon & , std::vector<reco::Particle> ,double ,double );
57 
61  double ptMuCut_, etaMuCut_;
67 
68  double maxDPtRel_, maxDeltaR_ ;
69  const int nbins_;
70  const double ptMax_;
73  TH1D * deltaR_;
75 
76 
77 };
78 
79 bool MuTriggerAnalyzer::IsMuMatchedToHLTMu ( const reco::Muon & mu, std::vector<reco::Particle> HLTMu , double DR, 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) return false;
88  for (size_t k =0; k< dim; k++ ) {
89  if ( (deltaR(HLTMu[k], mu) < DR) && (fabs(HLTMu[k].pt() - mu.pt())/ HLTMu[k].pt()<DPtRel)){
90  nPass++ ;
91  std::cout<< " matching a muon " << std::endl;
92  std::cout << "muon reco pt : " << muRecoPt<< std::endl;
93  std::cout << "muon reco eta " << mu.eta() << std::endl;
94  std::cout << "muon trigger pt "<< HLTMu[k].pt() << std::endl;
95  // filling the numerator, at the same bin as the denum.....
96  hTrigMuonPtNumS_-> Fill(muRecoPt);
97  deltaR_-> Fill(deltaR(HLTMu[k], mu));
98  deltaPtOverPt_-> Fill(fabs(HLTMu[k].pt() - mu.pt())/ HLTMu[k].pt());
99 
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 
110 
111 
113  trigTag_(cfg.getParameter<edm::InputTag> ("TrigTag")),
114  trigEv_(cfg.getParameter<edm::InputTag> ("triggerEvent")),
115  muonTag_(cfg.getUntrackedParameter<edm::InputTag>("muons")),
116  ptMuCut_(cfg.getUntrackedParameter<double>("ptMuCut")),
117  etaMuCut_(cfg.getUntrackedParameter<double>("etaMuCut")),
118  hltPath_(cfg.getParameter<std::string >("hltPath")),
119  L3FilterName_(cfg.getParameter<std::string >("L3FilterName")),
120  maxDPtRel_(cfg.getParameter<double>("maxDPtRel")),
121  maxDeltaR_(cfg.getParameter<double>("maxDeltaR")),
122  nbins_(cfg.getParameter<double>("ptMax_")),
123  ptMax_(cfg.getParameter<double>("ptMax_")){
125 
126  hTrigMuonPtNumS_ = fs->make<TH1D>("hTrigMuonPtNumS", "hTrigMuonPtNumS", nbins_ + 1, 0, ptMax_);
127  hTrigMuonPtDenS_ = fs->make<TH1D>("hTrigMuonPtDenS", "hTrigMuonPtDenS", nbins_ +1 , 0, ptMax_);
128  deltaR_ = fs->make<TH1D>("deltaR", "deltaR", nbins_+1, 0, maxDeltaR_);
129  deltaPtOverPt_ = fs->make<TH1D>("deltaPtOverPt", "deltaPtOverPt", nbins_ + 1, 0, maxDPtRel_);
130 
131 }
132 
134  for (int i = 0; i < nbins_+1; ++i){
135  std::cout << "number of reco muon in bin " << i << " = " << hTrigMuonPtDenS_->GetBinContent(i) << std::endl;
136  std::cout << "number of hlt muon in bin " << i << " = " << hTrigMuonPtNumS_->GetBinContent(i) << std::endl;
137 
138 
139  }
140 }
141 
142 void MuTriggerAnalyzer::analyze (const Event & ev, const EventSetup &) {
143  // bool overlap = false;
144 
145  // Trigger
148  if (!ev.getByLabel(trigTag_, triggerResults)) {
149  LogWarning("") << ">>> TRIGGER collection does not exist !!!";
150  return;
151  }
152  ev.getByLabel(trigTag_, triggerResults);
153  // trigNames.init(*triggerResults);
154  trigNames_ = &ev.triggerNames(*triggerResults);
155  //bool trigger_fired = false;
156  for (unsigned int i=0; i<triggerResults->size(); i++) {
157 
158 
159  std::string trigName = trigNames_->triggerName(i);
160  if ( trigName == hltPath_ && triggerResults->accept(i)) {
161  //trigger_fired = true;
162  }
163  }
164  edm::Handle< trigger::TriggerEvent > handleTriggerEvent;
165  // LogTrace("") << ">>> Trigger bit: " << trigger_fired << " (" << hltPath_ << ")";
166  if ( ! ev.getByLabel( trigEv_, handleTriggerEvent )) {
167  LogWarning( "errorTriggerEventValid" ) << "trigger::TriggerEvent product with InputTag " << trigEv_.encode() << " not in event";
168  return;
169  }
170  ev.getByLabel( trigEv_, handleTriggerEvent );
171  const trigger::TriggerObjectCollection & toc(handleTriggerEvent->getObjects());
172  size_t nMuHLT =0;
173  std::vector<reco::Particle> HLTMuMatched;
174  for ( size_t ia = 0; ia < handleTriggerEvent->sizeFilters(); ++ ia) {
175  std::string fullname = handleTriggerEvent->filterTag(ia).encode();
177  size_t p = fullname.find_first_of(':');
178  if ( p != std::string::npos) {
179  name = fullname.substr(0, p);
180  }
181  else {
182  name = fullname;
183  }
184  if ( &toc !=0 ) {
185  const trigger::Keys & k = handleTriggerEvent->filterKeys(ia);
186  for (trigger::Keys::const_iterator ki = k.begin(); ki !=k.end(); ++ki ) {
187  if (name == L3FilterName_ ) {
188  HLTMuMatched.push_back(toc[*ki].particle());
189  nMuHLT++;
190  }
191  }
192  }
193  }
194 
195  // looping on muon....
197  if (!ev.getByLabel(muonTag_, muons)) {
198  LogError("") << ">>> muon collection does not exist !!!";
199  return;
200  }
201 
202  ev.getByLabel(muonTag_, muons);
203  //saving only muons with pt> ptMuCut and eta<etaMuCut
204  std::vector<reco::Muon> highPtGlbMuons;
205 
206  for (unsigned int i=0; i<muons->size(); i++ ){
207  const reco::Muon & mu = muons->at(i);
208  double pt = mu.pt();
209  double eta = mu.eta();
210  if (pt> ptMuCut_ && fabs(eta)< etaMuCut_) {
211  if (mu.isGlobalMuon()) highPtGlbMuons.push_back(mu);
212  }
213  }
214  unsigned int nHighPtGlbMu = highPtGlbMuons.size();
215  std::cout << "I've got " << nHighPtGlbMu << " nHighPtGlbMu" << std::endl;
216  // unsigned int nHighPtStaMu = highPtStaMuons.size();
217 
218  // stop the loop after 10 cicles....
219  (nHighPtGlbMu> 10)? nHighPtGlbMu=10 : 1;
220 
221  if (nHighPtGlbMu>0 ){
222 
223  for(unsigned int i =0 ; i < nHighPtGlbMu ; i++) {
224  reco::Muon muon1 = highPtGlbMuons[i];
225  math::XYZTLorentzVector mu1(muon1.p4());
226  // double pt1= muon1.pt();
227 
228  /* bool singleTrigFlag1 =*/ IsMuMatchedToHLTMu ( muon1, HLTMuMatched ,maxDeltaR_, maxDPtRel_ );
229 
230  }
231 
232  }
233 
234 }
235 
236 
238 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:207
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::Handle< trigger::TriggerEvent > handleTriggerEvent_
edm::InputTag trigEv_
bool isGlobalMuon() const
Definition: Muon.h:219
double deltaR_
edm::TriggerNames const * trigNames_
T eta() const
edm::Handle< edm::TriggerResults > triggerResults_
std::string encode() const
Definition: InputTag.cc:164
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup)
const int mu
Definition: Constants.h:23
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
int k[5][pyjets_maxn]
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:83
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:75
MuTriggerAnalyzer(const edm::ParameterSet &pset)
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
std::vector< size_type > Keys
bool IsMuMatchedToHLTMu(const reco::Muon &, std::vector< reco::Particle >, double, double)
edm::InputTag muonTag_
virtual void endJob()
tuple muons
Definition: patZpeak.py:38
T * make() const
make new ROOT object
tuple cout
Definition: gather_cfg.py:121
bool IsMuMatchedToHLTMu(const reco::Candidate *dau, std::vector< reco::Particle > HLTMu, double DR, double DPtRel)
edm::InputTag trigTag_
virtual float pt() const GCC11_FINAL
transverse momentum
std::string L3FilterName_
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")