CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/GeneratorInterface/GenFilters/src/NJetsMCEta.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:   NJetsMC
00004 // Class:     NJetsMC
00005 // 
00013 //
00014 // Original Author:  "Nathaniel Odell"
00015 //         Created:  Thu Aug 12 09:24:46 CDT 2010
00016 // $Id: NJetsMC.cc,v 1.1 2011/03/23 14:46:46 mucib Exp $
00017 // then moved to more general N-jets purpose in GeneratorInterface/GenFilters
00018 // Modified by Qiang Li on Dec 2 2013 to add eta cuts for the leading 2 jets
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 // user include files
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDFilter.h"
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 #include "DataFormats/HepMCCandidate/interface/GenParticle.h" 
00031 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00032 #include "DataFormats/JetReco/interface/GenJet.h"
00033 
00034 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00035 
00036 #include "TROOT.h"
00037 #include "TH1F.h"
00038 #include "TFile.h"
00039 #include "TSystem.h"
00040 #include "TLorentzVector.h"
00041 #include <iostream>
00042 
00043 
00044 using namespace edm;
00045 using namespace std;
00046 using namespace reco;
00047  
00048 struct sortPt
00049 {
00050 bool operator()(TLorentzVector* s1, TLorentzVector* s2) const
00051   {
00052     return s1->Pt() >= s2->Pt();
00053   }
00054 } mysortPt;
00055 
00056 
00057 //
00058 // class declaration
00059 //
00060 
00061 class NJetsMCEta : public edm::EDFilter 
00062 {
00063 public:
00064   explicit NJetsMCEta(const edm::ParameterSet&);
00065   ~NJetsMCEta();
00066   
00067 private:
00068   virtual void beginJob() ;
00069   virtual bool filter(edm::Event&, const edm::EventSetup&);
00070   virtual void endJob() ;
00071   // ----------member data ---------------------------
00072   
00073   edm::InputTag GenHandle_;
00074   Int_t  njets_;
00075   double minpt_;
00076   double maxeta_;
00077   double mineta_;
00078 
00079   vector<TLorentzVector*> *pjet;
00080 
00081 };
00082 
00083 NJetsMCEta::NJetsMCEta(const edm::ParameterSet& iConfig):
00084   GenHandle_(iConfig.getUntrackedParameter<InputTag>("GenTag")),
00085   njets_(iConfig.getParameter<int32_t>("Njets")),
00086   minpt_(iConfig.getParameter<double>("MinPt")),
00087   maxeta_(iConfig.getParameter<double>("MaxEta")),
00088   mineta_(iConfig.getParameter<double>("MinEta"))
00089 {
00090 }
00091 
00092 
00093 NJetsMCEta::~NJetsMCEta()
00094 {
00095 }
00096 
00097 bool NJetsMCEta::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00098 {
00099    using namespace edm;
00100    
00101    Handle<reco::GenJetCollection> GenJets;
00102    iEvent.getByLabel(GenHandle_, GenJets);
00103  
00104    vector<TLorentzVector*> jet;
00105 
00106    Int_t count = 0;
00107    bool result = false;
00108 
00109  
00110 
00111    for(GenJetCollection::const_iterator iJet = GenJets->begin(); iJet != GenJets->end(); ++iJet)
00112      {
00113        const reco::Candidate* myJet = &(*iJet); 
00114        TLorentzVector *dummy = new TLorentzVector(0,0,0,0);
00115        dummy->SetPtEtaPhiE(myJet->pt(),myJet->eta(),myJet->energy(),myJet->phi());
00116        jet.push_back(dummy);
00117      }
00118 
00119    pjet = &jet ;
00120 
00121    sort (pjet->begin(), pjet->end(), mysortPt);
00122  
00123    if(pjet->size()>0 && pjet->at(0)->Pt() > minpt_ && abs(pjet->at(0)->Eta()) < maxeta_ && abs(pjet->at(0)->Eta()) > mineta_) ++count;
00124    if(pjet->size()>1 && pjet->at(1)->Pt() > minpt_ && abs(pjet->at(1)->Eta()) < maxeta_ && abs(pjet->at(1)->Eta()) > mineta_) ++count;
00125 
00126 
00127    if( count >= njets_ )
00128       result = true;
00129 
00130    return result;
00131 }
00132 
00133 void NJetsMCEta::beginJob()
00134 {
00135 }
00136 
00137 void NJetsMCEta::endJob()
00138 {
00139 }
00140  
00141 
00142 
00143 //define this as a plug-in
00144 DEFINE_FWK_MODULE(NJetsMCEta);