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