00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002
00003 #include "Alignment/CommonAlignmentProducer/interface/AlignmentMuonSelector.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005
00006 #include "TLorentzVector.h"
00007
00008
00009
00010 AlignmentMuonSelector::AlignmentMuonSelector(const edm::ParameterSet & cfg) :
00011 applyBasicCuts( cfg.getParameter<bool>( "applyBasicCuts" ) ),
00012 applyNHighestPt( cfg.getParameter<bool>( "applyNHighestPt" ) ),
00013 applyMultiplicityFilter( cfg.getParameter<bool>( "applyMultiplicityFilter" ) ),
00014 applyMassPairFilter( cfg.getParameter<bool>( "applyMassPairFilter" ) ),
00015 nHighestPt( cfg.getParameter<int>( "nHighestPt" ) ),
00016 minMultiplicity ( cfg.getParameter<int>( "minMultiplicity" ) ),
00017 ptMin( cfg.getParameter<double>( "ptMin" ) ),
00018 ptMax( cfg.getParameter<double>( "ptMax" ) ),
00019 etaMin( cfg.getParameter<double>( "etaMin" ) ),
00020 etaMax( cfg.getParameter<double>( "etaMax" ) ),
00021 phiMin( cfg.getParameter<double>( "phiMin" ) ),
00022 phiMax( cfg.getParameter<double>( "phiMax" ) ),
00023 nHitMinSA( cfg.getParameter<double>( "nHitMinSA" ) ),
00024 nHitMaxSA( cfg.getParameter<double>( "nHitMaxSA" ) ),
00025 chi2nMaxSA( cfg.getParameter<double>( "chi2nMaxSA") ),
00026 nHitMinGB( cfg.getParameter<double>( "nHitMinGB" ) ),
00027 nHitMaxGB( cfg.getParameter<double>( "nHitMaxGB" ) ),
00028 chi2nMaxGB( cfg.getParameter<double>( "chi2nMaxGB") ),
00029 nHitMinTO( cfg.getParameter<double>( "nHitMinTO" ) ),
00030 nHitMaxTO( cfg.getParameter<double>( "nHitMaxTO" ) ),
00031 chi2nMaxTO( cfg.getParameter<double>( "chi2nMaxTO" ) ),
00032 minMassPair( cfg.getParameter<double>( "minMassPair" ) ),
00033 maxMassPair( cfg.getParameter<double>( "maxMassPair" ) )
00034 {
00035
00036 if (applyBasicCuts)
00037 edm::LogInfo("AlignmentMuonSelector")
00038 << "applying basic muon cuts ..."
00039 << "\nptmin,ptmax: " << ptMin << "," << ptMax
00040 << "\netamin,etamax: " << etaMin << "," << etaMax
00041 << "\nphimin,phimax: " << phiMin << "," << phiMax
00042 << "\nnhitminSA,nhitmaxSA: " << nHitMinSA << "," << nHitMaxSA
00043 << "\nchi2nmaxSA: " << chi2nMaxSA<< ","
00044 << "\nnhitminGB,nhitmaxGB: " << nHitMinGB << "," << nHitMaxGB
00045 << "\nchi2nmaxGB: " << chi2nMaxGB<< ","
00046 << "\nnhitminTO,nhitmaxTO: " << nHitMinTO << "," << nHitMaxTO
00047 << "\nchi2nmaxTO: " << chi2nMaxTO;
00048
00049 if (applyNHighestPt)
00050 edm::LogInfo("AlignmentMuonSelector")
00051 << "filter N muons with highest Pt N=" << nHighestPt;
00052
00053 if (applyMultiplicityFilter)
00054 edm::LogInfo("AlignmentMuonSelector")
00055 << "apply multiplicity filter N>=" << minMultiplicity;
00056
00057 if (applyMassPairFilter)
00058 edm::LogInfo("AlignmentMuonSelector")
00059 << "apply Mass Pair filter minMassPair=" << minMassPair << " maxMassPair=" << maxMassPair;
00060
00061 }
00062
00063
00064
00065 AlignmentMuonSelector::~AlignmentMuonSelector()
00066 {}
00067
00068
00069
00070
00071 AlignmentMuonSelector::Muons
00072 AlignmentMuonSelector::select(const Muons& muons, const edm::Event& evt) const
00073 {
00074 Muons result=muons;
00075
00076
00077 if (applyBasicCuts) result= this->basicCuts(result);
00078
00079
00080 if (applyNHighestPt) result= this->theNHighestPtMuons(result);
00081
00082
00083 if (applyMultiplicityFilter) {
00084 if (result.size()<(unsigned int)minMultiplicity) result.clear();
00085 }
00086
00087
00088 if (applyMassPairFilter) {
00089 if (result.size()<2) result.clear();
00090 else result = this->theBestMassPairCombinationMuons(result);
00091 }
00092
00093 edm::LogInfo("AlignmentMuonSelector") << "muons all,kept: " << muons.size() << "," << result.size();
00094
00095 return result;
00096
00097 }
00098
00099
00100
00101 AlignmentMuonSelector::Muons
00102 AlignmentMuonSelector::basicCuts(const Muons& muons) const
00103 {
00104 Muons result;
00105
00106 for(Muons::const_iterator it=muons.begin();
00107 it!=muons.end();it++) {
00108 const reco::Muon* muonp=*it;
00109 float pt=muonp->pt();
00110 float eta=muonp->eta();
00111 float phi=muonp->phi();
00112
00113 int nhitSA=0;float chi2nSA=9999.;
00114 if(muonp->isStandAloneMuon()){
00115 nhitSA = muonp->standAloneMuon()->numberOfValidHits();
00116 chi2nSA = muonp->standAloneMuon()->normalizedChi2();
00117 }
00118 int nhitGB=0;float chi2nGB=9999.;
00119 if(muonp->isGlobalMuon()){
00120 nhitGB = muonp->combinedMuon()->numberOfValidHits();
00121 chi2nGB = muonp->combinedMuon()->normalizedChi2();
00122 }
00123 int nhitTO=0;float chi2nTO=9999.;
00124 if(muonp->isTrackerMuon()){
00125 nhitTO = muonp->track()->numberOfValidHits();
00126 chi2nTO = muonp->track()->normalizedChi2();
00127 }
00128 edm::LogInfo("AlignmentMuonSelector") << " pt,eta,phi,nhitSA,chi2nSA,nhitGB,chi2nGB,nhitTO,chi2nTO: "
00129 <<pt<<","<<eta<<","<<phi<<","<<nhitSA<< ","<<chi2nSA<<","<<nhitGB<< ","<<chi2nGB<<","<<nhitTO<< ","<<chi2nTO;
00130
00131 if (pt>ptMin && pt<ptMax
00132 && eta>etaMin && eta<etaMax
00133 && phi>phiMin && phi<phiMax
00134 && nhitSA>=nHitMinSA && nhitSA<=nHitMaxSA
00135 && chi2nSA<chi2nMaxSA
00136 && nhitGB>=nHitMinGB && nhitGB<=nHitMaxGB
00137 && chi2nGB<chi2nMaxGB
00138 && nhitTO>=nHitMinTO && nhitTO<=nHitMaxTO
00139 && chi2nTO<chi2nMaxTO) {
00140 result.push_back(muonp);
00141 }
00142 }
00143
00144 return result;
00145 }
00146
00147
00148
00149 AlignmentMuonSelector::Muons
00150 AlignmentMuonSelector::theNHighestPtMuons(const Muons& muons) const
00151 {
00152 Muons sortedMuons=muons;
00153 Muons result;
00154
00155
00156 std::sort(sortedMuons.begin(),sortedMuons.end(),ptComparator);
00157
00158
00159 int n=0;
00160 for (Muons::const_iterator it=sortedMuons.begin();
00161 it!=sortedMuons.end(); it++) {
00162 if (n<nHighestPt) { result.push_back(*it); n++; }
00163 }
00164
00165 return result;
00166 }
00167
00168
00169
00170 AlignmentMuonSelector::Muons
00171 AlignmentMuonSelector::theBestMassPairCombinationMuons(const Muons& muons) const
00172 {
00173 Muons sortedMuons=muons;
00174 Muons result;
00175 TLorentzVector mu1,mu2,pair;
00176 double mass=0, minDiff=999999.;
00177
00178
00179 std::sort(sortedMuons.begin(),sortedMuons.end(),ptComparator);
00180
00181
00182
00183
00184
00185 for (Muons::const_iterator it1=sortedMuons.begin();
00186 it1!=sortedMuons.end(); it1++) {
00187 for (Muons::const_iterator it2=it1+1;
00188 it2!=sortedMuons.end(); it2++) {
00189 mu1 = TLorentzVector((*it1)->momentum().x(),(*it1)->momentum().y(),(*it1)->momentum().z(),(*it1)->p());
00190 mu2 = TLorentzVector((*it2)->momentum().x(),(*it2)->momentum().y(),(*it2)->momentum().z(),(*it2)->p());
00191 pair=mu1+mu2;
00192 mass = pair.M();
00193
00194 if( maxMassPair != minMassPair){
00195 if(mass<maxMassPair && mass>minMassPair) { result.push_back(*it1); result.push_back(*it2); break;}
00196 }
00197 else{
00198 if(fabs(mass-maxMassPair)< minDiff) { minDiff=fabs(mass-maxMassPair); result.clear(); result.push_back(*it1); result.push_back(*it2);}
00199 }
00200 }
00201 }
00202
00203 return result;
00204 }
00205