CMS 3D CMS Logo

METplusTrackMonitor.cc
Go to the documentation of this file.
2 
4 
6 
8 
11 
12 // -----------------------------
13 // constructors and destructor
14 // -----------------------------
15 
17  folderName_ ( iConfig.getParameter<std::string>("FolderName") )
18  , metToken_ ( consumes<reco::CaloMETCollection> (iConfig.getParameter<edm::InputTag>("met") ) )
19  , muonToken_ ( consumes<reco::MuonCollection> (iConfig.getParameter<edm::InputTag>("muons") ) )
20  , jetToken_ ( consumes<reco::PFJetCollection> (iConfig.getParameter<edm::InputTag>("jets") ) )
21  , vtxToken_ ( consumes<reco::VertexCollection> (iConfig.getParameter<edm::InputTag>("vertices") ) )
22  , theTrigSummary_ ( consumes<trigger::TriggerEvent> (iConfig.getParameter<edm::InputTag>("trigSummary") ) )
23  , hltMetTag_ ( iConfig.getParameter<edm::InputTag>("hltMetFilter") )
24  , hltMetCleanTag_ ( iConfig.getParameter<edm::InputTag>("hltMetCleanFilter") )
25  , trackLegFilterTag_ ( iConfig.getParameter<edm::InputTag>("trackLegFilter") )
26  , met_variable_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("metBinning") )
27  , muonPt_variable_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("ptBinning") )
28  , met_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("metPSet") ) )
29  , ls_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet") ) )
30  , pt_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("ptPSet") ) )
31  , eta_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("etaPSet") ) )
32  , phi_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("phiPSet") ) )
33  , num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this))
34  , den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this))
35  , metSelection_ ( iConfig.getParameter<std::string>("metSelection") )
36  , muonSelection_ ( iConfig.getParameter<std::string>("muonSelection") )
37  , jetSelection_ ( iConfig.getParameter<std::string>("jetSelection") )
38  , vtxSelection_ ( iConfig.getParameter<std::string>("vtxSelection") )
39  , nmuons_ ( iConfig.getParameter<unsigned>("nmuons") )
40  , njets_ ( iConfig.getParameter<unsigned>("njets") )
41  , leadJetEtaCut_ ( iConfig.getParameter<double>("leadJetEtaCut") )
42  , requireLeadMatched_ ( iConfig.getParameter<bool>("requireLeadMatched") )
43  , maxMatchDeltaR_ ( iConfig.getParameter<double>("maxMatchDeltaR") )
44 {
45 
48  metVsLS_.numerator = nullptr;
49  metVsLS_.denominator = nullptr;
50  metPhiME_.numerator = nullptr;
51  metPhiME_.denominator = nullptr;
52  deltaphimetj1ME_.numerator = nullptr;
53  deltaphimetj1ME_.denominator = nullptr;
54  metVsHltMet_.numerator = nullptr; // numerator only, only available from passed filter
55  metVsHltMetClean_.numerator = nullptr; // numerator only, only available from passed filter
56 
59  muonPtVsLS_.numerator = nullptr;
60  muonPtVsLS_.denominator = nullptr;
61  deltaphimetmuonME_.numerator = nullptr;
63  muonEtaVsPhi_.numerator = nullptr;
64  muonEtaVsPhi_.denominator = nullptr;
65 
66 }
67 
69  edm::Run const &iRun,
70  edm::EventSetup const &iSetup)
71  {
72  std::string histname, histtitle;
73 
74  std::string currentFolder = folderName_;
75  ibooker.setCurrentFolder(currentFolder);
76 
77  // MET leg histograms
78 
79  histname = "met_variable"; histtitle = "CaloMET";
80  bookME(ibooker, metME_variableBinning_, histname, histtitle, met_variable_binning_);
81  setMETitle(metME_variableBinning_, "CaloMET [GeV]", "events / [GeV]");
82 
83  histname = "metVsLS"; histtitle = "CaloMET vs LS";
85  setMETitle(metVsLS_, "LS", "CaloMET [GeV]");
86 
87  histname = "metPhi"; histtitle = "CaloMET phi";
88  bookME(ibooker, metPhiME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
89  setMETitle(metPhiME_, "CaloMET #phi","events / 0.2 rad");
90 
91  histname = "deltaphi_metjet1"; histtitle = "dPhi(CaloMET, jet1)";
92  bookME(ibooker, deltaphimetj1ME_, histname, histtitle, phi_binning_.nbins, 0, phi_binning_.xmax);
93  setMETitle(deltaphimetj1ME_, "#Delta#phi (CaloMET, j1)", "events / 0.1 rad");
94 
95  histname = "metVsHltMet"; histtitle = "CaloMET vs hltMet";
97  setMETitle(metVsHltMet_, "hltMet (online) [GeV]", "CaloMET (offline) [GeV]");
98 
99  histname = "metVsHltMetClean"; histtitle = "CaloMET vs hltMetClean";
101  setMETitle(metVsHltMetClean_, "hltMetClean (online) [GeV]", "CaloMET (offline) [GeV]");
102 
103  // Track leg histograms
104 
105  histname = "muonPt_variable"; histtitle = "Muon PT";
106  bookME(ibooker, muonPtME_variableBinning_, histname, histtitle, muonPt_variable_binning_);
107  setMETitle(muonPtME_variableBinning_, "Muon p_{T} [GeV]", "events / [GeV]");
108 
109  histname = "muonEta"; histtitle = "Muon eta";
110  bookME(ibooker, muonEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
111  setMETitle(muonEtaME_, "Muon #eta", "events / 0.2");
112 
113  histname = "deltaphi_muonmet"; histtitle = "dPhi(Muon, CaloMET)";
114  bookME(ibooker, deltaphimetmuonME_, histname, histtitle, phi_binning_.nbins, 0, phi_binning_.xmax);
115  setMETitle(deltaphimetmuonME_, "#Delta#phi (Muon, CaloMET)", "events / 0.1 rad");
116 
117  histname = "muonEtaVsPhi"; histtitle = "Muon eta vs phi";
119  setMETitle(muonEtaVsPhi_, "Muon #phi", "Muon #eta");
120 
121  histname = "muonPtVsLS"; histtitle = "Muon PT vs LS";
123  setMETitle(muonPtVsLS_, "LS", "Muon p_{T} [GeV]");
124 
125  // Initialize the GenericTriggerEventFlag
128 
129  }
130 
132  {
133 
134  // Filter out events if Trigger Filtering is requested
135  if(den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup)) return;
136 
138  iEvent.getByToken(metToken_, metHandle);
139  reco::CaloMET caloMet = metHandle->front();
140  if(!metSelection_(caloMet)) return;
141 
142  float met = caloMet.pt();
143  float metPhi = caloMet.phi();
144 
146  iEvent.getByToken(jetToken_, jetsHandle);
147  if(jetsHandle->size() < njets_) return;
148  std::vector<reco::PFJet> jets;
149  for(auto const & j : *jetsHandle) {
150  if(jetSelection_(j)) jets.push_back(j);
151  }
152  if(jets.size() < njets_) return;
153  if(njets_ > 0 && !(jets.empty()) && fabs(jets[0].eta()) > leadJetEtaCut_) return;
154  float deltaphi_metjet1 = !(jets.empty()) ? fabs(deltaPhi(caloMet.phi(), jets[0].phi())) : 10.0;
155 
157  iEvent.getByToken(vtxToken_, primaryVertices);
158  if(primaryVertices->empty()) return;
159  const reco::Vertex* pv = nullptr;
160  for(auto const& v: *primaryVertices) {
161  if (!vtxSelection_(v)) continue;
162  pv = &v;
163  break;
164  }
165  if(pv == nullptr) return;
166 
168  iEvent.getByToken(muonToken_, muonHandle);
169  if(muonHandle->size() < nmuons_) return;
170  std::vector<reco::Muon> muons;
171  for(auto const & m : *muonHandle) {
172  bool passTightID = muon::isTightMuon(m, *pv) &&
173  m.innerTrack()->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_INNER_HITS) == 0 &&
174  m.innerTrack()->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS) == 0;
175  if(muonSelection_(m) && passTightID) muons.push_back(m);
176  }
177  if(muons.size() < nmuons_) return;
178 
179  // Filling MET leg histograms (denominator)
181  metPhiME_.denominator->Fill(metPhi);
182  deltaphimetj1ME_.denominator->Fill(deltaphi_metjet1);
183 
184  int ls = iEvent.id().luminosityBlock();
185  metVsLS_.denominator->Fill(ls, met);
186 
187  // Apply the selection for the MET leg numerator
188  edm::Handle<trigger::TriggerEvent> triggerSummary;
189  iEvent.getByToken(theTrigSummary_, triggerSummary);
190  if(!triggerSummary.isValid()) {
191  edm::LogError("METplusTrackMonitor") << "Invalid collection: TriggerSummary" << "\n";
192  return;
193  }
194 
195  trigger::TriggerObject hltMet, hltMetClean;
196  bool passesHltMetFilter = getHLTObj(triggerSummary, hltMetTag_, hltMet);
197  bool passesHltMetCleanFilter = getHLTObj(triggerSummary, hltMetCleanTag_, hltMetClean);
198 
199  if(!passesHltMetFilter || !passesHltMetCleanFilter) return;
200 
201  // Filling MET leg histograms (numerator)
203  metPhiME_.numerator->Fill(metPhi);
204  deltaphimetj1ME_.numerator->Fill(deltaphi_metjet1);
205  metVsLS_.numerator->Fill(ls, met);
206  metVsHltMet_.numerator->Fill(hltMet.pt(), met);
207  metVsHltMetClean_.numerator->Fill(hltMetClean.pt(), met);
208 
209  // Filling track leg histograms (denominator)
210  double leadMuonPt = !(muons.empty()) ? muons[0].pt() : -1.0;
211  double leadMuonEta = !(muons.empty()) ? muons[0].eta() : 10.0;
212  double leadMuonPhi = !(muons.empty()) ? muons[0].phi() : 10.0;
213  float deltaphi_metmuon = !(muons.empty()) ? fabs(deltaPhi(caloMet.phi(), muons[0].phi())) : 10.0;
214 
216  muonPtVsLS_.denominator->Fill(ls, leadMuonPt);
217  muonEtaME_.denominator->Fill(leadMuonEta);
218  deltaphimetmuonME_.denominator->Fill(deltaphi_metmuon);
219  muonEtaVsPhi_.denominator->Fill(leadMuonPhi, leadMuonEta);
220 
221  // Apply the selection for the track leg numerator
222  trigger::TriggerObject isoTrk;
223  bool passesTrackLegFilter = getHLTObj(triggerSummary, trackLegFilterTag_, isoTrk);
224 
225  // require track leg filter
226  if(!passesTrackLegFilter) return;
227 
228  // if requested, require lead selected muon is matched to the track leg filter object
229  if(requireLeadMatched_ && !(muons.empty()) && deltaR(muons[0], isoTrk) < maxMatchDeltaR_) return;
230 
231  // require the full HLT path is fired
232  if(num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup)) return;
233 
234  // Filling track leg histograms (denominator)
236  muonPtVsLS_.numerator->Fill(ls, leadMuonPt);
237  muonEtaME_.numerator->Fill(leadMuonEta);
238  deltaphimetmuonME_.numerator->Fill(deltaphi_metmuon);
239  muonEtaVsPhi_.numerator->Fill(leadMuonPhi, leadMuonEta);
240 
241 }
242 
244 {
246  desc.add<std::string> ( "FolderName", "HLT/MET" );
247 
248  desc.add<edm::InputTag>( "met", edm::InputTag("caloMet") );
249  desc.add<edm::InputTag>( "jets", edm::InputTag("ak4PFJetsCHS") );
250  desc.add<edm::InputTag>( "electrons", edm::InputTag("gedGsfElectrons") );
251  desc.add<edm::InputTag>( "muons", edm::InputTag("muons") );
252  desc.add<edm::InputTag>( "vertices", edm::InputTag("offlinePrimaryVertices") );
253  desc.add<edm::InputTag>( "trigSummary", edm::InputTag("hltTriggerSummaryAOD") );
254  desc.add<edm::InputTag>( "hltMetFilter", edm::InputTag("hltMET105", "", "HLT") );
255  desc.add<edm::InputTag>( "hltMetCleanFilter", edm::InputTag("hltMETClean65", "", "HLT") );
256  desc.add<edm::InputTag>( "trackLegFilter", edm::InputTag("hltTrk50Filter", "", "HLT") );
257 
258  desc.add<std::string>("metSelection", "pt > 0");
259  desc.add<std::string>("jetSelection", "pt > 0");
260  desc.add<std::string>("muonSelection", "pt > 0");
261  desc.add<std::string>("vtxSelection", "!isFake");
262  desc.add<unsigned>("njets", 0);
263  desc.add<unsigned>("nmuons", 0);
264  desc.add<double>("leadJetEtaCut", 2.4);
265  desc.add<bool>("requireLeadMatched", true);
266  desc.add<double>("maxMatchDeltaR", 0.1);
267 
268  edm::ParameterSetDescription genericTriggerEventPSet;
269  genericTriggerEventPSet.add<bool>("andOr");
270  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
271  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions", {});
272  genericTriggerEventPSet.add<bool>("andOrDcs", false);
273  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
274  genericTriggerEventPSet.add<std::string>("dbLabel", "");
275  genericTriggerEventPSet.add<bool>("andOrHlt", true);
276  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
277  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths", {});
278  genericTriggerEventPSet.add<std::string>("hltDBKey", "");
279  genericTriggerEventPSet.add<bool>("errorReplyHlt", false);
280  genericTriggerEventPSet.add<unsigned int>("verbosityLevel", 1);
281 
282  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
283  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
284 
290 
291  fillHistoPSetDescription(metPSet);
292  fillHistoPSetDescription(phiPSet);
293  fillHistoPSetDescription(ptPSet);
294  fillHistoPSetDescription(etaPSet);
295 
296  histoPSet.add<edm::ParameterSetDescription>("metPSet", metPSet);
297  histoPSet.add<edm::ParameterSetDescription>("phiPSet", phiPSet);
298  histoPSet.add<edm::ParameterSetDescription>("ptPSet", ptPSet);
299  histoPSet.add<edm::ParameterSetDescription>("etaPSet", etaPSet);
300 
301  std::vector<double> bins = {0.,20.,40.,60.,80.,90.,100.,110.,120.,130.,140.,150.,160.,170.,180.,190.,200.,220.,240.,260.,280.,300.,350.,400.,450.,1000.};
302 
303  histoPSet.add<std::vector<double> >("metBinning", bins);
304  histoPSet.add<std::vector<double> >("ptBinning", bins);
305 
308  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
309 
310  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
311 
312  descriptions.add("metPlusTrackMonitoring", desc);
313 }
314 
316 {
317 
318  double leadingPt = -1.0;
319 
320  size_t filterIndex = trigSummary->filterIndex( filterTag );
322 
323  if( !(filterIndex >= trigSummary->sizeFilters()) ) {
324  const trigger::Keys& keys = trigSummary->filterKeys( filterIndex );
325  for(unsigned short key : keys) {
326  trigger::TriggerObject foundObject = triggerObjects[key];
327  if(foundObject.pt() > leadingPt) {
328  obj = foundObject;
329  leadingPt = obj.pt();
330  }
331  }
332  }
333 
334  return (leadingPt > 0.0);
335 }
336 
337 // Define this as a plug-in
340 
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
MonitorElement * numerator
edm::InputTag hltMetCleanTag_
METplusTrackMonitor(const edm::ParameterSet &)
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
bool getHLTObj(const edm::Handle< trigger::TriggerEvent > &trigSummary, const edm::InputTag &filterTag, trigger::TriggerObject &obj) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:123
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
edm::InputTag trackLegFilterTag_
void setMETitle(ObjME &me, const std::string &titleX, const std::string &titleY)
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::vector< double > muonPt_variable_binning_
edm::EDGetTokenT< reco::MuonCollection > muonToken_
void Fill(long long x)
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Collection of Calo MET.
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
MonitorElement * denominator
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
std::vector< double > met_variable_binning_
vector< PseudoJet > jets
def pv(vc)
Definition: MetAnalyzer.py:6
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
caloMet
____________________________________________________________________________||
Definition: CaloMET_cfi.py:4
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
StringCutObjectSelector< reco::CaloMET, true > metSelection_
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:81
StringCutObjectSelector< reco::PFJet, true > jetSelection_
def ls(path, rec=False)
Definition: eostools.py:348
StringCutObjectSelector< reco::Muon, true > muonSelection_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
primaryVertices
Definition: jets_cff.py:27
met
===> hadronic RAZOR
std::vector< size_type > Keys
StringCutObjectSelector< reco::Vertex, true > vtxSelection_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::CaloMETCollection > metToken_
edm::EventID id() const
Definition: EventBase.h:60
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
double phi() const final
momentum azimuthal angle
void bookME(DQMStore::IBooker &, ObjME &me, const std::string &histname, const std::string &histtitle, unsigned nbins, double xmin, double xmax)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< trigger::TriggerEvent > theTrigSummary_
Definition: Run.h:44