CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/special/src/HLTSingleVertexPixelTrackFilter.cc

Go to the documentation of this file.
00001 // $Id: HLTSingleVertexPixelTrackFilter.cc,v 1.3 2009/11/01 19:34:12 davidlw Exp $
00002 
00003 #include "HLTrigger/special/interface/HLTSingleVertexPixelTrackFilter.h"
00004 
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "DataFormats/Common/interface/RefToBase.h"
00012 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00013 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00014 #include "DataFormats/VertexReco/interface/Vertex.h"
00015 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00016 #include "DataFormats/TrackReco/interface/Track.h"
00017 #include "DataFormats/TrackReco/interface/TrackFwd.h" 
00018 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00019 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 // constructors and destructor
00024 //
00025  
00026 HLTSingleVertexPixelTrackFilter::HLTSingleVertexPixelTrackFilter(const edm::ParameterSet& iConfig) :
00027     pixelVerticesTag_ (iConfig.getParameter<edm::InputTag>("vertexCollection")),
00028     pixelTracksTag_ (iConfig.getParameter<edm::InputTag>("trackCollection")),
00029     min_Pt_  (iConfig.getParameter<double>("MinPt")),
00030     max_Pt_  (iConfig.getParameter<double>("MaxPt")),
00031     max_Eta_  (iConfig.getParameter<double>("MaxEta")),
00032     max_Vz_  (iConfig.getParameter<double>("MaxVz")),
00033     min_trks_  (iConfig.getParameter<int>("MinTrks")),
00034     min_sep_  (iConfig.getParameter<double>("MinSep"))
00035 {
00036    //register your products
00037   produces<trigger::TriggerFilterObjectWithRefs>();
00038 }
00039 
00040 HLTSingleVertexPixelTrackFilter::~HLTSingleVertexPixelTrackFilter()
00041 {
00042 }
00043 
00044 //
00045 // member functions
00046 //
00047 
00048 // ------------ method called to produce the data  ------------
00049 bool HLTSingleVertexPixelTrackFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00050 {
00051 
00052    // All HLT filters must create and fill an HLT filter object,
00053    // recording any reconstructed physics objects satisfying (or not)
00054    // this HLT filter, and place it in the Event.
00055 
00056    // The Filter object
00057    std::auto_ptr<trigger::TriggerFilterObjectWithRefs> filterproduct (new trigger::TriggerFilterObjectWithRefs(path(),module()));
00058 
00059    // Ref to Candidate object to be recorded in filter object
00060    edm::Ref<reco::RecoChargedCandidateCollection> candref;
00061 
00062    // Specific filter code
00063    bool accept = false; 
00064 
00065    int nTrackCandidate = 0;
00066 
00067    // get hold of products from Event
00068    edm::Handle<reco::VertexCollection> vertexCollection;
00069    iEvent.getByLabel( pixelVerticesTag_, vertexCollection );
00070    if(vertexCollection.isValid())
00071    {
00072      const reco::VertexCollection * vertices = vertexCollection.product();
00073      int npixelvertices = vertices->size();
00074      if (npixelvertices!=0)
00075      {
00076        double vzmax = 0;
00077        int   nmax = 0;
00078        reco::VertexCollection::const_iterator verticesItr;
00079        for (verticesItr=vertices->begin(); verticesItr!=vertices->end(); ++verticesItr)
00080        {
00081             int ntracksize = verticesItr->tracksSize();
00082             double vz = verticesItr->z();
00083             if(fabs(vz) > max_Vz_) continue;
00084             if( ntracksize > nmax) 
00085             {
00086               vzmax = vz;
00087               nmax = ntracksize;
00088             }
00089        }
00090 
00091        edm::Handle<reco::RecoChargedCandidateCollection> trackCollection;
00092        iEvent.getByLabel(pixelTracksTag_,trackCollection);
00093        if(trackCollection.isValid())
00094        {
00095           const reco::RecoChargedCandidateCollection * tracks = trackCollection.product();
00096           reco::RecoChargedCandidateCollection::const_iterator tracksItr;
00097           int icount=-1;
00098           for (tracksItr=tracks->begin(); tracksItr!=tracks->end(); ++tracksItr)
00099           {
00100             icount++;
00101             double eta = tracksItr->eta();
00102             if(fabs(eta) > max_Eta_) continue;
00103             double pt  = tracksItr->pt();
00104             if(pt < min_Pt_ || pt > max_Pt_) continue;
00105             double vz = tracksItr->vz();   
00106             if(fabs(vz-vzmax) > min_sep_) continue;
00107 
00108             candref = edm::Ref<reco::RecoChargedCandidateCollection>(trackCollection, icount);
00109             filterproduct->addObject(trigger::TriggerTrack, candref);
00110             nTrackCandidate++;
00111           }
00112        }
00113      }
00114    }
00115        
00116    accept = ( nTrackCandidate >= min_trks_ );
00117 
00118    filterproduct->addCollectionTag(pixelTracksTag_);
00119 
00120    iEvent.put(filterproduct);
00121 
00122    return accept;
00123 }
00124 
00125 DEFINE_FWK_MODULE(HLTSingleVertexPixelTrackFilter);