CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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 AlignmentGlobalTrackSelector::AlignmentGlobalTrackSelector(const edm::ParameterSet & cfg) :
00029   theGMFilterSwitch(cfg.getParameter<bool>("applyGlobalMuonFilter")),
00030   theIsoFilterSwitch(cfg.getParameter<bool>("applyIsolationtest")),
00031   theJetCountFilterSwitch(cfg.getParameter<bool>("applyJetCountFilter")),
00032   theMuonSource("muons"),
00033   theJetIsoSource("fastjet6CaloJets"),
00034   theJetCountSource("fastjet6CaloJets")
00035 {
00036   if (theGMFilterSwitch || theIsoFilterSwitch || theJetCountFilterSwitch)
00037     LogDebug("Alignment") << "> applying global Trackfilter ...";
00038  
00039   if (theGMFilterSwitch) {
00040     theMuonSource = cfg.getParameter<InputTag>("muonSource");
00041     theMaxTrackDeltaR =cfg.getParameter<double>("maxTrackDeltaR");
00042     theMinGlobalMuonCount = cfg.getParameter<int>("minGlobalMuonCount");
00043     LogDebug("Alignment") << ">  GlobalMuonFilter : source, maxTrackDeltaR, min. Count       : "
00044                           << theMuonSource << " , "
00045                           << theMaxTrackDeltaR << " , "
00046                           << theMinIsolatedCount;
00047   }
00048   
00049   if (theIsoFilterSwitch) {
00050     theJetIsoSource = cfg.getParameter<InputTag>("jetIsoSource");
00051     theMaxJetPt = cfg.getParameter<double>("maxJetPt");
00052     theMinJetDeltaR = cfg.getParameter<double>("minJetDeltaR");
00053     theMinIsolatedCount = cfg.getParameter<int>("minIsolatedCount");
00054     LogDebug("Alignment") << ">  Isolationtest    : source, maxJetPt, minJetDeltaR, min. Count: "
00055                           << theJetIsoSource << " , "
00056                           << theMaxJetPt << " ,"
00057                           << theMinJetDeltaR << " ,"
00058                           << theMinGlobalMuonCount;
00059   }
00060   
00061   if (theJetCountFilterSwitch) {
00062     theJetCountSource = cfg.getParameter<InputTag>("jetCountSource");
00063     theMinJetPt = cfg.getParameter<double>("minJetPt");
00064     theMaxJetCount = cfg.getParameter<int>("maxJetCount");
00065     LogDebug("Alignment") << ">  JetCountFilter   : source, minJetPt, maxJetCount             : "
00066                           << theJetCountSource << " , "
00067                           << theMinJetPt << " ,"
00068                           << theMaxJetCount;  
00069   }
00070 }
00071 
00072 // destructor -----------------------------------------------------------------
00073 AlignmentGlobalTrackSelector::~AlignmentGlobalTrackSelector()
00074 {}
00075 
00077 bool AlignmentGlobalTrackSelector::useThisFilter()
00078 {
00079   return theGMFilterSwitch || theIsoFilterSwitch|| theJetCountFilterSwitch;
00080 }
00081 
00082 // do selection ---------------------------------------------------------------
00083 AlignmentGlobalTrackSelector::Tracks 
00084 AlignmentGlobalTrackSelector::select(const Tracks& tracks, const edm::Event& iEvent) 
00085 {
00086   Tracks result = tracks;
00087 
00088   if (theGMFilterSwitch) result = findMuons(result, iEvent);
00089   if (theIsoFilterSwitch) result = checkIsolation(result, iEvent);
00090   if (theJetCountFilterSwitch) result = checkJetCount(result, iEvent);
00091   LogDebug("Alignment") << ">  Global: tracks all, kept: " << tracks.size() << ", " << result.size();
00092 //  LogDebug("Alignment")<<">  o kept:";
00093 //  printTracks(result);
00094   
00095   return result;
00096 }
00097 
00099 AlignmentGlobalTrackSelector::Tracks 
00100 AlignmentGlobalTrackSelector::findMuons(const Tracks& tracks, const edm::Event& iEvent) const
00101 {
00102   Tracks result;
00103   Tracks globalMuons;
00104 
00105   //fill globalMuons with muons
00106   Handle<reco::MuonCollection> muons;
00107   iEvent.getByLabel(theMuonSource, muons);
00108 
00109   if (muons.isValid()) {
00110     for (reco::MuonCollection::const_iterator itMuon = muons->begin(); 
00111          itMuon != muons->end();
00112          ++itMuon) {
00113       const reco::Track* muonTrack = (*itMuon).get<reco::TrackRef>().get();
00114       if (!muonTrack) {
00115         LogDebug("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
00116                               << "Found muon without track: Standalone Muon!";
00117       } else {
00118         globalMuons.push_back(muonTrack);
00119       }
00120     }
00121   } else {
00122     LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
00123                           <<">  could not optain mounCollection!";
00124   }
00125 
00126   result = this->matchTracks(tracks, globalMuons);
00127   
00128   if (static_cast<int>(result.size()) < theMinGlobalMuonCount) result.clear();
00129 
00130   return result;
00131 }
00132 
00134 AlignmentGlobalTrackSelector::Tracks 
00135 AlignmentGlobalTrackSelector::checkIsolation(const Tracks& cands,const edm::Event& iEvent) const
00136 {
00137   Tracks result; result.clear();
00138 
00139   Handle<reco::CaloJetCollection> jets;
00140   iEvent.getByLabel(theJetIsoSource, jets);
00141 
00142   if (jets.isValid()) {
00143     for (Tracks::const_iterator it = cands.begin();
00144          it!=cands.end();
00145          ++it) {
00146       bool isolated = true;
00147       for (reco::CaloJetCollection::const_iterator itJet = jets->begin();
00148            itJet!=jets->end();
00149            ++itJet) 
00150         isolated &= !((*itJet).pt() > theMaxJetPt && deltaR(*(*it),(*itJet)) < theMinJetDeltaR);
00151       
00152       if (isolated)
00153         result.push_back(*it);
00154     }
00155     //    LogDebug("Alignment") << "D  Found "<<result.size()<<" isolated of "<< cands.size()<<" Tracks!";   
00156     
00157   } else
00158     LogError("Alignment")<< "@SUB=AlignmentGlobalTrackSelector::checkIsolation"
00159                          << "> could not optain jetCollection!";
00160 
00161   if (static_cast<int>(result.size()) < theMinIsolatedCount) result.clear();
00162 
00163   return result;
00164 }
00165 
00167 AlignmentGlobalTrackSelector::Tracks 
00168 AlignmentGlobalTrackSelector::checkJetCount(const Tracks& tracks, const edm::Event& iEvent) const
00169 {
00170   Tracks result; result.clear();
00171 
00172   Handle<reco::CaloJetCollection> jets;
00173   iEvent.getByLabel(theJetCountSource, jets);
00174 
00175   if (jets.isValid()) {
00176     int jetCount = 0;
00177     for (reco::CaloJetCollection::const_iterator itJet = jets->begin();
00178          itJet!=jets->end();
00179          ++itJet) {
00180       if ((*itJet).pt() > theMinJetPt)
00181         jetCount++;
00182     }
00183 
00184     if (jetCount <= theMaxJetCount)
00185       result = tracks;
00186 
00187     LogDebug("Alignment") << "> found " << jetCount << " Jets";
00188   } else
00189     LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::checkJetCount"
00190                           << ">  could not optain jetCollection!";
00191 
00192   return result;
00193 }
00194 
00195 //===================HELPERS===================
00196 
00198 AlignmentGlobalTrackSelector::Tracks
00199 AlignmentGlobalTrackSelector::matchTracks(const Tracks& src, const Tracks& comp) const
00200 {
00201   Tracks result;
00202   for (Tracks::const_iterator itComp = comp.begin();
00203        itComp!=comp.end();
00204        ++itComp) {
00205     int match = -1;
00206     double min = theMaxTrackDeltaR;
00207     for (unsigned int i=0;i<src.size();i++) {
00208       // LogDebug("Alignment") << "> Trackmatch dist: "<<deltaR(src.at(i),*itComp);
00209       if(min > deltaR(*(src.at(i)),*(*itComp))){
00210         min = deltaR(*(src.at(i)),*(*itComp));
00211         match = static_cast<int>(i);
00212       }
00213     }
00214     if (match > -1)
00215       result.push_back(src.at(match)); 
00216   }
00217   return result;
00218 }
00219 
00221 void AlignmentGlobalTrackSelector::printTracks(const Tracks& col) const
00222 {
00223   int count = 0;
00224   LogDebug("Alignment") << ">......................................";
00225   for (Tracks::const_iterator it = col.begin();
00226        it < col.end();
00227        ++it,++count) {
00228     LogDebug("Alignment") 
00229       << ">  Track No. " << count << ": p = (" 
00230       << (*it)->px() << "," 
00231       << (*it)->py() << ","
00232       << (*it)->pz() << ")\n"
00233       << ">                        pT = "
00234       << (*it)->pt() << " eta = "
00235       << (*it)->eta() << " charge = "
00236       << (*it)->charge();    
00237   }
00238   LogDebug("Alignment") << ">......................................";
00239 }