CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/RecoPixelVertexing/PixelVertexFinding/src/JetVertexChecker.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    JetVertexChecker
00004 // Class:      JetVertexChecker
00005 // 
00013 //
00014 // Original Author:  Andrea RIZZI
00015 //         Created:  Mon Jan 16 11:19:48 CET 2012
00016 // $Id: JetVertexChecker.cc,v 1.1 2012/02/01 16:24:02 arizzi Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDFilter.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "DataFormats/TrackReco/interface/Track.h"
00033 #include "DataFormats/JetReco/interface/JetTracksAssociation.h"
00034 #include "FWCore/Utilities/interface/InputTag.h"
00035 
00036 #include "DataFormats/JetReco/interface/CaloJet.h"
00037 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00038 
00039 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00040 #include "DataFormats/VertexReco/interface/Vertex.h"
00041 
00042 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00043 
00044 //
00045 // class declaration
00046 //
00047 
00048 class JetVertexChecker : public edm::EDFilter {
00049    public:
00050       explicit JetVertexChecker(const edm::ParameterSet&);
00051       ~JetVertexChecker();
00052 
00053       static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00054 
00055    private:
00056       virtual void beginJob() ;
00057       virtual bool filter(edm::Event&, const edm::EventSetup&);
00058       virtual void endJob() ;
00059       
00060       virtual bool beginRun(edm::Run&, edm::EventSetup const&);
00061       virtual bool endRun(edm::Run&, edm::EventSetup const&);
00062       virtual bool beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
00063       virtual bool endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
00064 
00065       // ----------member data ---------------------------
00066      edm::InputTag m_associator; 
00067      edm::InputTag m_primaryVertexProducer;
00068      edm::InputTag m_beamSpot;
00069      bool m_doFilter;
00070      double m_cutMinPt;
00071      double m_cutMinPtRatio; 
00072      int32_t m_maxNjets;
00073 
00074 };
00075 
00076 //
00077 // constants, enums and typedefs
00078 //
00079 
00080 //
00081 // static data member definitions
00082 //
00083 
00084 //
00085 // constructors and destructor
00086 //
00087 JetVertexChecker::JetVertexChecker(const edm::ParameterSet& iConfig)
00088 {
00089    //now do what ever initialization is needed
00090   m_beamSpot          = iConfig.getParameter<edm::InputTag>("beamSpot");
00091   m_associator              = iConfig.getParameter<edm::InputTag>("jetTracks");
00092   m_doFilter                = iConfig.getParameter<bool>("doFilter");
00093   m_cutMinPt                = iConfig.getParameter<double>("minPt");
00094   m_cutMinPtRatio           = iConfig.getParameter<double>("minPtRatio");
00095   m_maxNjets           = iConfig.getParameter<int32_t>("maxNJetsToCheck");
00096   produces<std::vector<reco::CaloJet> >(); 
00097   produces<reco::VertexCollection >(); 
00098 }
00099 
00100 
00101 JetVertexChecker::~JetVertexChecker()
00102 {
00103  
00104    // do anything here that needs to be done at desctruction time
00105    // (e.g. close files, deallocate resources etc.)
00106 
00107 }
00108 
00109 
00110 //
00111 // member functions
00112 //
00113 
00114 // ------------ method called on each new Event  ------------
00115 bool
00116 JetVertexChecker::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00117 {
00118    using namespace edm;
00119    Handle<reco::JetTracksAssociationCollection> jetTracksAssociation;
00120    iEvent.getByLabel(m_associator, jetTracksAssociation);
00121    std::auto_ptr<std::vector<reco::CaloJet> > pOut(new std::vector<reco::CaloJet> );
00122 
00123    bool result=true;
00124    int i = 0;
00125    //limit to first two jets
00126    for(reco::JetTracksAssociationCollection::const_iterator it = jetTracksAssociation->begin();
00127        it != jetTracksAssociation->end() && i < m_maxNjets; it++, i++) {
00128      if(fabs(it->first->eta()) < 2.4)
00129      {
00130       reco::TrackRefVector tracks = it->second;
00131       math::XYZVector jetMomentum = it->first->momentum();
00132       math::XYZVector trMomentum;
00133       for(reco::TrackRefVector::const_iterator itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack) 
00134       {
00135              trMomentum += (*itTrack)->momentum();
00136       }
00137       if(trMomentum.rho()/jetMomentum.rho() < m_cutMinPtRatio || trMomentum.rho() < m_cutMinPt) 
00138       {
00139 //        std::cout << "bad jet " << it->first->pt() << std::endl;
00140         pOut->push_back(* dynamic_cast<const reco::CaloJet *>(&(*it->first)));
00141         result=false;
00142       }
00143      }
00144     } 
00145   
00146     iEvent.put(pOut);
00147 
00148    edm::Handle<reco::BeamSpot> beamSpot;
00149    iEvent.getByLabel(m_beamSpot,beamSpot);
00150  
00151    reco::Vertex::Error e;
00152    e(0, 0) = 0.0015 * 0.0015;
00153    e(1, 1) = 0.0015 * 0.0015;
00154    e(2, 2) = 1.5 * 1.5;
00155    reco::Vertex::Point p(beamSpot->x0(), beamSpot->y0(), beamSpot->z0());
00156    reco::Vertex thePV(p, e, 0, 0, 0);
00157    std::auto_ptr<reco::VertexCollection> pOut2(new reco::VertexCollection);
00158    pOut2->push_back(thePV);
00159    iEvent.put(pOut2);
00160 //   std::cout << " filter " << result << std::endl;
00161    if(m_doFilter) return result;
00162    else 
00163    return true;
00164 }
00165 
00166 // ------------ method called once each job just before starting event loop  ------------
00167 void 
00168 JetVertexChecker::beginJob()
00169 {
00170 }
00171 
00172 // ------------ method called once each job just after ending the event loop  ------------
00173 void 
00174 JetVertexChecker::endJob() {
00175 }
00176 
00177 // ------------ method called when starting to processes a run  ------------
00178 bool 
00179 JetVertexChecker::beginRun(edm::Run&, edm::EventSetup const&)
00180 { 
00181   return true;
00182 }
00183 
00184 // ------------ method called when ending the processing of a run  ------------
00185 bool 
00186 JetVertexChecker::endRun(edm::Run&, edm::EventSetup const&)
00187 {
00188   return true;
00189 }
00190 
00191 // ------------ method called when starting to processes a luminosity block  ------------
00192 bool 
00193 JetVertexChecker::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
00194 {
00195   return true;
00196 }
00197 
00198 // ------------ method called when ending the processing of a luminosity block  ------------
00199 bool 
00200 JetVertexChecker::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
00201 {
00202   return true;
00203 }
00204 
00205 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00206 void
00207 JetVertexChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00208   //The following says we do not know what parameters are allowed so do no validation
00209   // Please change this to state exactly what you do use, even if it is no parameters
00210   edm::ParameterSetDescription desc;
00211   desc.setUnknown();
00212   descriptions.addDefault(desc);
00213 }
00214 //define this as a plug-in
00215 DEFINE_FWK_MODULE(JetVertexChecker);