CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Alignment/CommonAlignmentProducer/src/AlignmentGlobalTrackSelector.cc

Go to the documentation of this file.
00001 //Framework
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Utilities/interface/EDMException.h"
00005 
00006 //DataFormats
00007 #include <DataFormats/Candidate/interface/Particle.h>
00008 #include <DataFormats/Candidate/interface/Candidate.h>
00009 #include <DataFormats/TrackReco/interface/Track.h>
00010 #include <DataFormats/JetReco/interface/CaloJet.h>
00011 #include <DataFormats/MuonReco/interface/MuonFwd.h>
00012 #include <DataFormats/MuonReco/interface/Muon.h>
00013 
00014 #include <DataFormats/RecoCandidate/interface/RecoCandidate.h> //for the get<TrackRef>() Call
00015 
00016 #include <DataFormats/Math/interface/deltaR.h>
00017 
00018 //STL
00019 #include <math.h>
00020 
00021 #include "Alignment/CommonAlignmentProducer/interface/AlignmentGlobalTrackSelector.h"
00022 
00023 
00024 using namespace std;
00025 using namespace edm;   
00026 
00027 // constructor ----------------------------------------------------------------
00028 
00029 AlignmentGlobalTrackSelector::AlignmentGlobalTrackSelector(const edm::ParameterSet & cfg) :
00030   theMuonSource("muons"),
00031   theJetIsoSource("fastjet6CaloJets"),
00032   theJetCountSource("fastjet6CaloJets")
00033 {
00034   theIsoFilterSwitch = cfg.getParameter<bool>( "applyIsolationtest" );
00035   theGMFilterSwitch = cfg.getParameter<bool>( "applyGlobalMuonFilter" );
00036   theJetCountFilterSwitch = cfg.getParameter<bool>( "applyJetCountFilter" );
00037   if (theIsoFilterSwitch ||  theGMFilterSwitch || theJetCountFilterSwitch)
00038     LogDebug("Alignment") << "> applying global Trackfilter ...";
00039  
00040   if (theGMFilterSwitch){
00041     theMuonSource = cfg.getParameter<InputTag>( "muonSource" );
00042     theMaxTrackDeltaR =cfg.getParameter<double>("maxTrackDeltaR");
00043     theMinIsolatedCount = cfg.getParameter<int>("minIsolatedCount");
00044     LogDebug("Alignment") << ">  GlobalMuonFilter : source, maxTrackDeltaR, min. Count       : " << theMuonSource<<" , "<<theMaxTrackDeltaR<<" , "<<theMinIsolatedCount;
00045   }else{
00046     theMaxTrackDeltaR = 0;
00047     theMinIsolatedCount = 0;
00048   }
00049   
00050   if (theIsoFilterSwitch ){
00051     theJetIsoSource = cfg.getParameter<InputTag>( "jetIsoSource" );
00052     theMaxJetPt = cfg.getParameter<double>( "maxJetPt" );
00053     theMinJetDeltaR = cfg.getParameter<double>( "minJetDeltaR" );
00054     theMinGlobalMuonCount = cfg.getParameter<int>( "minGlobalMuonCount" );
00055     LogDebug("Alignment") << ">  Isolationtest    : source, maxJetPt, minJetDeltaR, min. Count: " << theJetIsoSource   << " , " << theMaxJetPt<<" ," <<theMinJetDeltaR<<" ," <<theMinGlobalMuonCount;
00056   }else{
00057     theMaxJetPt = 0;
00058     theMinJetDeltaR = 0;
00059     theMinGlobalMuonCount = 0;
00060   }
00061   
00062   if(theJetCountFilterSwitch){
00063     theJetCountSource = cfg.getParameter<InputTag>( "jetCountSource" );
00064     theMinJetPt = cfg.getParameter<double>( "minJetPt" );
00065     theMaxJetCount = cfg.getParameter<int>( "maxJetCount" );
00066     LogDebug("Alignment") << ">  JetCountFilter   : source, minJetPt, maxJetCount             : " << theJetCountSource   << " , " << theMinJetPt<<" ," <<theMaxJetCount;  
00067   }
00068 
00069   
00070 }
00071 
00072 
00073 // destructor -----------------------------------------------------------------
00074 
00075 AlignmentGlobalTrackSelector::~AlignmentGlobalTrackSelector()
00076 {}
00077 
00078 
00080 bool AlignmentGlobalTrackSelector::useThisFilter()
00081 {
00082   return theGMFilterSwitch || theIsoFilterSwitch|| theJetCountFilterSwitch;
00083 }
00084 
00085 // do selection ---------------------------------------------------------------
00086 AlignmentGlobalTrackSelector::Tracks 
00087 AlignmentGlobalTrackSelector::select(const Tracks& tracks, const edm::Event& iEvent) 
00088 {
00089   Tracks result=tracks;
00090 
00091   if(theGMFilterSwitch)  result = findMuons(result,iEvent);
00092   if(theIsoFilterSwitch)  result = checkIsolation(result,iEvent);
00093   if(theJetCountFilterSwitch)  result = checkJetCount(result,iEvent);
00094   LogDebug("Alignment") << ">  Global: tracks all,kept: " << tracks.size() << "," << result.size();
00095 //  LogDebug("Alignment")<<">  o kept:";
00096 //  printTracks(result);
00097   
00098   return result;
00099 }
00100 
00102 AlignmentGlobalTrackSelector::Tracks 
00103 AlignmentGlobalTrackSelector::checkIsolation(const Tracks& cands,const edm::Event& iEvent) const
00104 {
00105   Tracks result;  result.clear();
00106 
00107   Handle<reco::CaloJetCollection> jets;
00108   iEvent.getByLabel(theJetIsoSource  ,jets);
00109   if(jets.isValid()){
00110     for(Tracks::const_iterator it = cands.begin();it < cands.end();++it){
00111       bool isolated = true;
00112       for(reco::CaloJetCollection::const_iterator itJet = jets->begin(); itJet != jets->end() ; ++itJet) 
00113         isolated &= !((*itJet).pt() > theMaxJetPt && deltaR(*(*it),(*itJet)) < theMinJetDeltaR);
00114       
00115       if(isolated)
00116         result.push_back(*it);
00117     }
00118     //    LogDebug("Alignment") << "D  Found "<<result.size()<<" isolated of "<< cands.size()<<" Tracks!";   
00119     
00120   }else  LogError("Alignment")<<"@SUB=AlignmentGlobalTrackSelector::checkIsolation"
00121                                                  <<">  could not optain jetCollection!";
00122 
00123   if(static_cast<int>(result.size()) < theMinIsolatedCount) result.clear();
00124   return result;
00125 }
00126 
00128 AlignmentGlobalTrackSelector::Tracks 
00129 AlignmentGlobalTrackSelector::checkJetCount(const Tracks& tracks, const edm::Event& iEvent) const
00130 {
00131   Tracks result;  result.clear();
00132   Handle<reco::CaloJetCollection> jets;
00133   iEvent.getByLabel(theJetCountSource  ,jets);
00134   if(jets.isValid()){
00135     int jetCount = 0;
00136     for(reco::CaloJetCollection::const_iterator itJet = jets->begin(); itJet != jets->end() ; ++itJet){
00137       if((*itJet).pt() > theMinJetPt)
00138         jetCount++;
00139     }
00140     if(jetCount <= theMaxJetCount)
00141       result = tracks;
00142     LogDebug("Alignment")<<">  found "<<jetCount<<" Jets";
00143   }else  LogError("Alignment")<<"@SUB=AlignmentGlobalTrackSelector::checkJetCount"
00144                               <<">  could not optain jetCollection!";
00145   return result;
00146 }
00147 
00149 AlignmentGlobalTrackSelector::Tracks 
00150 AlignmentGlobalTrackSelector::findMuons(const Tracks& tracks, const edm::Event& iEvent) const
00151 {
00152   Tracks result;
00153   Tracks globalMuons;
00154 
00155   //fill globalMuons with muons
00156   Handle<reco::MuonCollection> muons;
00157   iEvent.getByLabel(theMuonSource, muons);
00158   if (muons.isValid()) {
00159     for(reco::MuonCollection::const_iterator itMuon = muons->begin(); itMuon != muons->end();
00160         ++itMuon) {
00161       const reco::Track* muonTrack = (*itMuon).get<reco::TrackRef>().get();
00162       if (!muonTrack) {
00163         LogDebug("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
00164                               << "Found muon without track: Standalone Muon!";
00165       } else {
00166         globalMuons.push_back(muonTrack);
00167       }
00168     }
00169   } else {
00170     LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
00171                           <<">  could not optain mounCollection!";
00172   }
00173 
00174   result = this->matchTracks(tracks, globalMuons);
00175   
00176   if (static_cast<int>(result.size()) < theMinGlobalMuonCount) result.clear();
00177 
00178   return result;
00179 }
00180 
00181 //===================HELPERS===================
00182 
00184 AlignmentGlobalTrackSelector::Tracks
00185 AlignmentGlobalTrackSelector::matchTracks(const Tracks& src, const Tracks& comp) const
00186 {
00187   Tracks result;
00188   for(Tracks::const_iterator itComp = comp.begin(); itComp < comp.end();++itComp){
00189       int match = -1;
00190       double min = theMaxTrackDeltaR;
00191       for(unsigned int i =0; i < src.size();i++){
00192         //      LogDebug("Alignment") << "> Trackmatch dist: "<<deltaR(src.at(i),*itComp);
00193         if(min > deltaR(*(src.at(i)),*(*itComp))){
00194           min = deltaR(*(src.at(i)),*(*itComp));
00195           match = static_cast<int>(i);
00196         }
00197       }
00198       if(match > -1)
00199         result.push_back(src.at(match)); 
00200     }
00201   return result;
00202 }
00203 
00205 void AlignmentGlobalTrackSelector::printTracks(const Tracks& col) const
00206 {
00207   int count = 0;
00208   LogDebug("Alignment") << ">......................................";
00209   for(Tracks::const_iterator it = col.begin();it < col.end();++it,++count){
00210     LogDebug("Alignment") 
00211       <<">  Track No. "<< count <<": p = ("<<(*it)->px()<<","<<(*it)->py()<<","<<(*it)->pz()<<")\n"
00212       <<">                        pT = "<<(*it)->pt()<<" eta = "<<(*it)->eta()<<" charge = "<<(*it)->charge();    
00213   }
00214   LogDebug("Alignment") << ">......................................";
00215 }