CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SUSY_HLT_VBF_Mu.cc
Go to the documentation of this file.
9 #include <assert.h>
10 #include <cstdlib>
11 #include "TLorentzVector.h"
12 #include <string>
13 #include <iostream>
14 #include <fstream>
15 #include <sys/types.h>
16 #include <regex.h>
17 #include <stdio.h>
18 
20 {
21  edm::LogInfo("SUSY_HLT_VBF_Mu") << "Constructor SUSY_HLT_VBF_Mu::SUSY_HLT_VBF_Mu " << std::endl;
22  // Get parameters from configuration file
23  theTrigSummary_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("trigSummary"));
24  theMuonCollection_ = consumes<reco::MuonCollection>(ps.getParameter<edm::InputTag>("MuonCollection"));
25  thePfJetCollection_ = consumes<reco::PFJetCollection>(ps.getParameter<edm::InputTag>("pfJetCollection"));
26  thePfMETCollection_ = consumes<reco::PFMETCollection>(ps.getParameter<edm::InputTag>("pfMETCollection"));
27  theCaloJetCollection_ = consumes<reco::CaloJetCollection>(ps.getParameter<edm::InputTag>("caloJetCollection"));
28  theCaloMETCollection_ = consumes<reco::CaloMETCollection>(ps.getParameter<edm::InputTag>("caloMETCollection"));
29  triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
30  HLTProcess_ = ps.getParameter<std::string>("HLTProcess");
31  triggerPath_ = ps.getParameter<std::string>("TriggerPath");
32  triggerMuFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMuon");
33  triggerHTFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterHT");
34  triggerMetFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMET");
35  triggerDiJetFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMJJ");
36  triggerCaloMETFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterCaloMET");
37  ptThrJetTrig_ = ps.getUntrackedParameter<double>("PtThrJetTrig");
38  etaThrJetTrig_ = ps.getUntrackedParameter<double>("EtaThrJetTrig");
39  ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
40  etaThrJet_ = ps.getUntrackedParameter<double>("EtaThrJet");
41  deltaetaVBFJets = ps.getUntrackedParameter<double>("DeltaEtaVBFJets");
42  pfmetOnlinethreshold = ps.getUntrackedParameter<double>("PFMetCutOnline");
43  muonOnlinethreshold = ps.getUntrackedParameter<double>("MuonCutOnline");
44  htOnlinethreshold = ps.getUntrackedParameter<double>("HTCutOnline");
45  mjjOnlinethreshold = ps.getUntrackedParameter<double>("MJJCutOnline");
46 
47 }
48 
50 {
51  edm::LogInfo("SUSY_HLT_VBF_Mu") << "Destructor SUSY_HLT_VBF_Mu::~SUSY_HLT_VBF_Mu " << std::endl;
52 }
53 
55 {
56 
57  bool changed;
58 
59  if (!fHltConfig.init(run, e, HLTProcess_, changed)) {
60  edm::LogError("SUSY_HLT_VBF_Mu") << "Initialization of HLTConfigProvider failed!!";
61  return;
62  }
63 
64  bool pathFound = false;
65  const std::vector<std::string> allTrigNames = fHltConfig.triggerNames();
66  for(size_t j = 0; j <allTrigNames.size(); ++j) {
67  if(allTrigNames[j].find(triggerPath_) != std::string::npos) {
68  pathFound = true;
69  }
70  }
71 
72  if(!pathFound) {
73  LogDebug("SUSY_HLT_VBF_Mu") << "Path not found" << "\n";
74  return;
75  }
76 
77  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::beginRun" << std::endl;
78 }
79 
81 {
82  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::bookHistograms" << std::endl;
83  //book at beginRun
84  bookHistos(ibooker_);
85 }
86 
88  edm::EventSetup const& context)
89 {
90  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::beginLuminosityBlock" << std::endl;
91 }
92 
93 
94 
96 
97 
98  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::analyze" << std::endl;
99 
100  //-------------------------------
101  //--- Jets
102  //-------------------------------
103 
104  edm::Handle<reco::PFJetCollection> pfJetCollection;
105  e.getByToken (thePfJetCollection_,pfJetCollection);
106  if ( !pfJetCollection.isValid() ){
107  edm::LogError ("SUSY_HLT_VBF_Mu") << "invalid collection: PFJets" << "\n";
108  return;
109  }
110 
111  edm::Handle<reco::CaloJetCollection> caloJetCollection;
112  e.getByToken (theCaloJetCollection_,caloJetCollection);
113  if ( !caloJetCollection.isValid() ){
114  edm::LogError ("SUSY_HLT_VBF_Mu") << "invalid collection: CaloJets" << "\n";
115  return;
116  }
117 
118  //-------------------------------
119  //--- Muon
120  //-------------------------------
122  e.getByToken (theMuonCollection_, MuonCollection);
123  if ( !MuonCollection.isValid() ){
124  edm::LogError ("SUSY_HLT_VBF_Mu") << "invalid collection: Muons " << "\n";
125  return;
126  }
127 
128 
129  //-------------------------------
130  //--- MET
131  //-------------------------------
132 
133  edm::Handle<reco::CaloMETCollection> caloMETCollection;
134  e.getByToken(theCaloMETCollection_, caloMETCollection);
135  if ( !caloMETCollection.isValid() ){
136  edm::LogError ("SUSY_HLT_VBF_Mu") << "invalid collection: CaloMET" << "\n";
137  return;
138  }
139 
140 
141  edm::Handle<reco::PFMETCollection> pfMETCollection;
142  e.getByToken(thePfMETCollection_, pfMETCollection);
143  if ( !pfMETCollection.isValid() ){
144  edm::LogError ("SUSY_HLT_VBF_Mu") << "invalid collection: PFMET" << "\n";
145  return;
146  }
147  //
148 
149  //-------------------------------
150  //--- Trigger
151  //-------------------------------
153  e.getByToken(triggerResults_,hltresults);
154  if(!hltresults.isValid()){
155  edm::LogError ("SUSY_HLT_VBF_Mu") << "invalid collection: TriggerResults" << "\n";
156  return;
157  }
158  edm::Handle<trigger::TriggerEvent> triggerSummary;
159  e.getByToken(theTrigSummary_, triggerSummary);
160  if(!triggerSummary.isValid()) {
161  edm::LogError ("SUSY_HLT_VBF_Mu") << "invalid collection: TriggerSummary" << "\n";
162  return;
163  }
164 
165 
166 
167  //get online objects
168 
169  std::vector<float> ptMuon, etaMuon, phiMuon;
170  size_t filterIndexMu = triggerSummary->filterIndex( triggerMuFilter_ );
171  trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
172  if( !(filterIndexMu >= triggerSummary->sizeFilters()) ){
173  const trigger::Keys& keys = triggerSummary->filterKeys( filterIndexMu );
174  for( size_t j = 0; j < keys.size(); ++j ){
175  trigger::TriggerObject foundObject = triggerObjects[keys[j]];
176  if(fabs(foundObject.id()) == 13){ //It's a muon
177 
178  bool same= false;
179  for(unsigned int x=0;x<ptMuon.size();x++){
180  if(fabs(ptMuon[x] - foundObject.pt()) < 0.01)
181  same = true;
182  }
183 
184  if(!same){
185  h_triggerMuPt->Fill(foundObject.pt());
186  h_triggerMuEta->Fill(foundObject.eta());
187  h_triggerMuPhi->Fill(foundObject.phi());
188  ptMuon.push_back(foundObject.pt());
189  etaMuon.push_back(foundObject.eta());
190  phiMuon.push_back(foundObject.phi());
191  }
192  }
193  }
194  }
195 
196 
197 
198  //get online objects
199 
200  size_t filterIndexMet = triggerSummary->filterIndex( triggerMetFilter_ );
201  size_t dijetFilterIndex = triggerSummary->filterIndex( triggerDiJetFilter_ );
202 
203  if( !(filterIndexMet >= triggerSummary->sizeFilters()) ){
204  const trigger::Keys& keys = triggerSummary->filterKeys( filterIndexMet );
205  for( size_t j = 0; j < keys.size(); ++j ){
206  trigger::TriggerObject foundObject = triggerObjects[keys[j]];
207  h_triggerMet->Fill(foundObject.pt());
208  h_triggerMetPhi->Fill(foundObject.phi());
209  }
210  }
211 
212  dijet = -1;
213 
214  std::vector<float> ptJet, etaJet, phiJet;
215  if( !(dijetFilterIndex >= triggerSummary->sizeFilters()) ){
216  const trigger::Keys& KEYS(triggerSummary->filterKeys(dijetFilterIndex));
217  const size_t nK(KEYS.size());
218  const trigger::TriggerObjectCollection& TOC(triggerSummary->getObjects());
219 
220  for (size_t i=0; i < nK ; i++ ) {
221  const trigger::TriggerObject& TO1(TOC[KEYS[i]]);
222  if( TO1.pt() > ptThrJetTrig_ && fabs(TO1.eta()) < etaThrJetTrig_ ){
223 
224  // for dijet part
225  for (size_t j=i; j < nK; j++) {
226  if( i < j ){
227  const trigger::TriggerObject& TO2(TOC[KEYS[j]]);
228  if( TO2.pt() > ptThrJetTrig_ && fabs(TO2.eta()) < etaThrJetTrig_ ){
229  double tmpdeta = fabs( TO1.eta() - TO2.eta() );
230  double tmpopposite = TO1.eta() * TO2.eta() ;
231  if( tmpdeta > deltaetaVBFJets && tmpopposite < 0){
232  TLorentzVector j1 ( TO1.px(), TO1.py(), TO1.pz(), TO1.energy());
233  TLorentzVector j2 ( TO2.px(), TO2.py(), TO2.pz(), TO2.energy());
234  double tmpmass = ( j1 + j2 ).M();
235  if( dijet < tmpmass ) {
236  dijet = tmpmass ;
237  }
238  }
239  }
240  }
241  }
242  }
243  }
245  }
246 
247 
248  size_t filterIndexCaloMET = triggerSummary->filterIndex( triggerCaloMETFilter_ );
249  if( filterIndexCaloMET < triggerSummary->sizeFilters() ) {
250  const trigger::Keys& keys = triggerSummary->filterKeys( filterIndexCaloMET );
251  if(keys.size() ) {
252  float met_h = triggerObjects[ keys[0] ].pt();
253  h_triggerCaloMet->Fill(met_h);
254  }
255  }
256 
257 
258 
259 
260  size_t filterIndexHt = triggerSummary->filterIndex( triggerHTFilter_ );
261  if( filterIndexHt < triggerSummary->sizeFilters() ) {
262  const trigger::Keys& keys = triggerSummary->filterKeys( filterIndexHt );
263  if( keys.size() ) {
264  float ht = triggerObjects[ keys[0] ].pt();
265  h_ht->Fill( ht );
266  }
267  }
268 
269 
270 
271  bool hasFired = false;
272 
273  const edm::TriggerNames& trigNames = e.triggerNames(*hltresults);
274  unsigned int numTriggers = trigNames.size();
275 
276  for( unsigned int hltIndex=0; hltIndex<numTriggers; ++hltIndex ){
277  if (trigNames.triggerName(hltIndex).find(triggerPath_) != std::string::npos && hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex)) hasFired = true;
278  }
279 
280 
281 
282 
283  //Matching the muon
284  int indexOfMatchedMuon = -1;
285  int offlineCounter = 0;
286  for(reco::MuonCollection::const_iterator muon = MuonCollection->begin(); muon != MuonCollection->end() ; ++muon) {
287  for(size_t off_i = 0; off_i < ptMuon.size(); ++off_i) {
288  if(reco::deltaR(muon->eta(),muon->phi(),etaMuon[off_i],phiMuon[off_i]) < 0.5) {
289  indexOfMatchedMuon = offlineCounter;
290  break;
291  }
292  }
293  offlineCounter++;
294  }
295 
296 
297 
298  float pfHT = 0.0;
299 
300  for (reco::PFJetCollection::const_iterator i_pfjet = pfJetCollection->begin(); i_pfjet != pfJetCollection->end(); ++i_pfjet){
301  if (i_pfjet->pt() < ptThrJet_) continue;
302  if (fabs(i_pfjet->eta()) > etaThrJet_) continue;
303  pfHT += i_pfjet->pt();
304  }
305 
306  //
307 
308  dijetOff =-1;
309 
310  size_t jetCol = pfJetCollection->size();
311 
312  for (size_t i=0; i < jetCol ; i++ ) {
313 
314  if( pfJetCollection->at(i).pt() > ptThrJetTrig_ && fabs(pfJetCollection->at(i).eta()) < etaThrJetTrig_ ){
315 
316  for (size_t j=i; j <jetCol ; j++) {
317 
318  if( i < j ){
319 
320  if( pfJetCollection->at(j).pt() > ptThrJetTrig_ && fabs(pfJetCollection->at(j).eta()) < etaThrJetTrig_ ){
321 
322  double tmpdetaOff = fabs( pfJetCollection->at(i).eta() - pfJetCollection->at(j).eta() );
323  double tmpoppositeOff = pfJetCollection->at(i).eta() * pfJetCollection->at(j).eta() ;
324  if( tmpdetaOff > deltaetaVBFJets && tmpoppositeOff < 0){
325  TLorentzVector j1Off ( pfJetCollection->at(i).px(), pfJetCollection->at(i).py(), pfJetCollection->at(i).pz(), pfJetCollection->at(i).energy());
326  TLorentzVector j2Off ( pfJetCollection->at(j).px(), pfJetCollection->at(j).py(), pfJetCollection->at(j).pz(), pfJetCollection->at(j).energy());
327  double tmpmassOff = ( j1Off + j2Off ).M();
328  if( dijetOff < tmpmassOff ) dijetOff = tmpmassOff ;
329 
330  }
331  }
332  }
333  }
334  }
335  }
336 
337 
338 // For trigger turn on curves
339 
340  // for muon
341  if(indexOfMatchedMuon > -1 && (dijetOff > mjjOnlinethreshold) && (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (pfHT > htOnlinethreshold)) {
342  h_den_muonpt->Fill(MuonCollection->at(indexOfMatchedMuon).pt());
343  h_den_muoneta->Fill(MuonCollection->at(indexOfMatchedMuon).eta());
344  if(hasFired) {
345  h_num_muonpt->Fill(MuonCollection->at(indexOfMatchedMuon).pt());
346  h_num_muoneta->Fill(MuonCollection->at(indexOfMatchedMuon).eta());
347  }
348  }
349 
350 
351  // For MJJ
352  if(indexOfMatchedMuon > -1 && (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold) && (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (pfHT > htOnlinethreshold)) {
354  if(hasFired) {
356  }
357  }
358 
359  // For HT
360  //
361  if(indexOfMatchedMuon > -1 && (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold) && (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (dijetOff > mjjOnlinethreshold)) {
362 
363  h_den_ht->Fill(pfHT);
364  if(hasFired) {
365  h_num_ht->Fill(pfHT);
366  }
367  }
368 
369  if(indexOfMatchedMuon > -1 && (dijetOff > mjjOnlinethreshold) && (pfHT > htOnlinethreshold) && (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold)) {
370 
371  h_den_met->Fill(pfMETCollection->begin()->et());
372  if(hasFired) {
373  h_num_met->Fill(pfMETCollection->begin()->et());
374  }
375  }
376 
377 }
378 
380 {
381  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::endLuminosityBlock" << std::endl;
382 }
383 
384 
386 {
387  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::endRun" << std::endl;
388 }
389 
391 {
392  ibooker_.cd();
393  ibooker_.setCurrentFolder("HLT/SUSYBSM/SUSY_HLT_VBF_Mu");
394 
395  //offline quantities
396 
397  //online quantities
398  h_triggerMuPt = ibooker_.book1D("triggerMuPt", "Trigger Muon Pt; GeV", 50, 0.0, 500.0);
399  h_triggerMuEta = ibooker_.book1D("triggerMuEta", "Trigger Muon Eta", 20, -3.0, 3.0);
400  h_triggerMuPhi = ibooker_.book1D("triggerMuPhi", "Trigger Muon Phi", 20, -3.5, 3.5);
401 
402  h_triggerCaloMet = ibooker_.book1D("h_triggerCaloMet", "Trigger Calo MET; GeV", 20, 0.0, 500.0);
403 
404  h_ht = ibooker_.book1D("h_ht", "h_ht",30, 0.0, 1500.0 );
405 
406  h_triggerMet = ibooker_.book1D("triggerMet", "Trigger MET; GeV", 20, 0.0, 500.0);
407  h_triggerMetPhi = ibooker_.book1D("triggerMetPhi", "Trigger MET Phi", 20, -3.5, 3.5);
408 
409  h_DiJetMass = ibooker_.book1D("h_DiJetMass" , "h_DiJetMass", 500,0.0,5000.0);
410 
411 //num and den hists to be divided in harvesting step to make turn on curves
412 
413  h_den_muonpt = ibooker_.book1D("h_den_muonpt","h_den_muonpt", 50, 0.0, 500.0);
414  h_num_muonpt = ibooker_.book1D("h_num_muonpt","h_num_muonpt", 50, 0.0, 500.0);
415 
416 
417  h_den_muoneta = ibooker_.book1D("h_den_muoneta","h_den_muoneta", 20, -3.0, 3.0);
418  h_num_muoneta = ibooker_.book1D("h_num_muoneta","h_num_muoneta", 20, -3.0, 3.0);
419 
420  h_den_mjj = ibooker_.book1D("h_den_mjj","h_den_mjj",500,0.0,5000.0);
421  h_num_mjj = ibooker_.book1D("h_num_mjj","h_num_mjj",500,0.0,5000.0);
422 
423  h_den_met = ibooker_.book1D("h_den_met","h_den_met",20,0.0,500.0);
424  h_num_met = ibooker_.book1D("h_num_met","h_num_met",20,0.0,500.0);
425 
426  h_den_ht = ibooker_.book1D("h_den_ht","h_den_ht",30,0.0,1500.0);
427  h_num_ht = ibooker_.book1D("h_num_ht","h_num_ht",30,0.0,1500.0);
428 
429 
430  ibooker_.cd();
431 }
432 
433 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * h_triggerMuPhi
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< reco::CaloMETCollection > theCaloMETCollection_
void analyze(edm::Event const &e, edm::EventSetup const &eSetup)
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:220
MonitorElement * h_num_met
int id() const
getters
Definition: TriggerObject.h:55
MonitorElement * h_ht
MonitorElement * h_den_muonpt
MonitorElement * h_triggerCaloMet
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
float phi() const
Definition: TriggerObject.h:58
void cd(void)
Definition: DQMStore.cc:266
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag triggerMetFilter_
const std::vector< std::string > & triggerNames() const
names of trigger paths
edm::EDGetTokenT< reco::MuonCollection > theMuonCollection_
double mjjOnlinethreshold
double muonOnlinethreshold
float energy() const
Definition: TriggerObject.h:65
Strings::size_type size() const
Definition: TriggerNames.cc:39
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
float eta() const
Definition: TriggerObject.h:57
MonitorElement * h_num_muoneta
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
edm::EDGetTokenT< reco::PFMETCollection > thePfMETCollection_
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::PFJetCollection > thePfJetCollection_
HLTConfigProvider fHltConfig
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
void Fill(long long x)
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
SUSY_HLT_VBF_Mu(const edm::ParameterSet &ps)
MonitorElement * h_num_mjj
edm::InputTag triggerDiJetFilter_
edm::EDGetTokenT< edm::TriggerResults > triggerResults_
MonitorElement * h_DiJetMass
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int j
Definition: DBlmapReader.cc:9
MonitorElement * h_den_met
edm::InputTag triggerHTFilter_
bool isValid() const
Definition: HandleBase.h:75
edm::InputTag triggerMuFilter_
MonitorElement * h_triggerMuPt
double htOnlinethreshold
MonitorElement * h_den_mjj
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
virtual ~SUSY_HLT_VBF_Mu()
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
std::vector< size_type > Keys
std::string HLTProcess_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::string triggerPath_
edm::EDGetTokenT< reco::CaloJetCollection > theCaloJetCollection_
edm::EDGetTokenT< trigger::TriggerEvent > theTrigSummary_
MonitorElement * h_num_muonpt
MonitorElement * h_num_ht
double pfmetOnlinethreshold
MonitorElement * h_triggerMetPhi
MonitorElement * h_triggerMuEta
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &eSetup)
MonitorElement * h_den_ht
void bookHistos(DQMStore::IBooker &)
MonitorElement * h_triggerMet
edm::InputTag triggerCaloMETFilter_
Definition: Run.h:43
MonitorElement * h_den_muoneta
void endLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &eSetup)