CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Configuration/Skimming/src/HSCPTrackSelectorModule.cc

Go to the documentation of this file.
00001 
00002 // -*- C++ -*-
00003 //
00004 // Package:    HSCPTrackSelector
00005 // Class:      HSCPTrackSelector
00006 // 
00007 // Original Author:  Loic Quertenmont
00008 //         Created:  Mon Apr 23 CDT 2012
00009 //
00010 
00011 
00012 #include "FWCore/Framework/interface/MakerMacros.h"
00013 #include "CommonTools/UtilAlgos/interface/ObjectSelector.h"
00014 
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00017 #include <DataFormats/MuonReco/interface/Muon.h>
00018 #include <DataFormats/MuonReco/interface/MuonFwd.h>
00019 #include "DataFormats/TrackReco/interface/DeDxData.h"
00020 #include "DataFormats/Common/interface/ValueMap.h"
00021 
00022 // the following include is necessary to clone all track branches
00023 // including recoTrackExtras and TrackingRecHitsOwned (in future also "owned clusters"?).
00024 // if you remove it the code will compile, but the cloned
00025 // tracks have only the recoTracks branch!
00026 #include "CommonTools/RecoAlgos/interface/TrackSelector.h"
00027 
00028 struct HSCPTrackSelector {
00029   typedef std::vector<const reco::Track*> container;
00030   typedef container::const_iterator const_iterator;
00031   typedef reco::TrackCollection collection; 
00032 
00033  HSCPTrackSelector( const edm::ParameterSet & cfg ){
00034     trackerTrackPtCut = cfg.getParameter<double>( "trackerTrackPtMin" );
00035     dedxTag_          = cfg.getParameter<edm::InputTag>("InputDedx");
00036     theMuonSource     = cfg.getParameter<edm::InputTag>("muonSource");
00037 
00038     thedEdxSwitch         = cfg.getParameter<bool>("usededx");
00039     minInnerTrackdEdx     = cfg.getParameter<double>( "InnerTrackdEdxRightMin" );
00040     maxInnerTrackdEdx     = cfg.getParameter<double>( "InnerTrackdEdxLeftMax" );
00041     minMuonTrackdEdx      = cfg.getParameter<double>( "InnerMuondEdxRightMin" );
00042     maxMuonTrackdEdx      = cfg.getParameter<double>( "InnerMuondEdxLeftMax" );
00043     mindEdxHitsInnerTrack = cfg.getParameter<unsigned int>( "dEdxMeasurementsMinForInnerTrack" );
00044     mindEdxHitsMuonTrack  = cfg.getParameter<unsigned int>( "dEdxMeasurementsMinForMuonTrack" );
00045   }
00046   
00047   const_iterator begin() const { return theSelectedTracks.begin(); }
00048   const_iterator end() const { return theSelectedTracks.end(); }
00049   size_t size() const { return theSelectedTracks.size(); }
00050 
00051   bool matchingMuon(const reco::Track* track, const edm::Handle<reco::MuonCollection>& muons){
00052     for(reco::MuonCollection::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon){
00053       const reco::Track* muonTrack = (*itMuon).get<reco::TrackRef>().get();
00054       if (!muonTrack)continue;
00055 
00056       //matching is needed because input track collection (made for dE/dx) has been refitted w.r.t track collection used for muon reco (we should do a tight maching to find equivalent track in the other collection)
00057       if(fabs(track->pt()-muonTrack->pt())<0.5 && fabs(track->eta()-muonTrack->eta())<0.02 && fabs(track->phi()-muonTrack->phi())<0.02)return true;
00058     }
00059     return false;
00060   }
00061 
00062 
00063 
00064   void select( const edm::Handle<reco::TrackCollection> & c,  const edm::Event & evt,  const edm::EventSetup &){
00065     edm::Handle<edm::ValueMap<reco::DeDxData> > dEdxTrackHandle;
00066     if(thedEdxSwitch){evt.getByLabel(dedxTag_, dEdxTrackHandle); }
00067 
00068     edm::Handle<reco::MuonCollection> muons;
00069     evt.getByLabel(theMuonSource, muons);
00070 
00071     //Loop on all Tracks
00072     theSelectedTracks.clear();
00073     for(size_t i=0; i<c->size(); i++){
00074       reco::TrackRef trkRef = reco::TrackRef(c, i);
00075       
00076       double dedx=0; unsigned int dedxHit=0; if(thedEdxSwitch){dedx=dEdxTrackHandle->get(i).dEdx(); dedxHit=dEdxTrackHandle->get(i).numberOfMeasurements();}  //DIRTY WAY OF ACCESSING DEDX
00077       bool isMuon=muons.isValid() && matchingMuon(& *trkRef, muons);
00078       //printf("muon tracks %i --> pt=%6.2f  eta=%+6.2f phi=%+6.2f dEdx=%f\n", (int)isMuon,  trkRef->pt(), trkRef->eta(), trkRef->phi(), dedx);
00079       
00080       if(isMuon){
00081          if(thedEdxSwitch && (dedxHit<mindEdxHitsMuonTrack || (dedx>minMuonTrackdEdx && dedx<maxMuonTrackdEdx)) ){continue;}     
00082          theSelectedTracks.push_back(& * trkRef );
00083       }else{
00084          if(trkRef->pt()<trackerTrackPtCut)continue;
00085          if(thedEdxSwitch && (dedxHit<mindEdxHitsInnerTrack || (dedx>minInnerTrackdEdx && dedx<maxInnerTrackdEdx)) )continue;
00086          theSelectedTracks.push_back(& * trkRef );
00087       }
00088     }
00089 
00090     //debug printout
00091 //    for (container::const_iterator it=theSelectedTracks.begin(); it != theSelectedTracks.end(); ++it) {
00092 //       printf("Selected tracks %i --> pt=%6.2f  eta=%+6.2f phi=%+6.2f - isMuon=%i\n", (int)(it-theSelectedTracks.begin()),  (*it)->pt(), (*it)->eta(), (*it)->phi(), matchingMuon(*it, theSelectedMuonTracks));
00093 //    }
00094   }
00095 
00096 private:
00097   container theSelectedTracks;
00098   double trackerTrackPtCut;
00099   double minInnerTrackdEdx;
00100   double maxInnerTrackdEdx;
00101   double minMuonTrackdEdx;
00102   double maxMuonTrackdEdx;
00103   unsigned int    mindEdxHitsInnerTrack;
00104   unsigned int    mindEdxHitsMuonTrack;
00105   edm::InputTag dedxTag_;
00106   edm::InputTag theMuonSource;
00107   bool thedEdxSwitch;
00108 };
00109 
00110 typedef ObjectSelector<HSCPTrackSelector>  HSCPTrackSelectorModule;
00111 
00112 DEFINE_FWK_MODULE( HSCPTrackSelectorModule );