CMS 3D CMS Logo

AlignmentMuonSelector.cc
Go to the documentation of this file.
2 
5 
6 #include "TLorentzVector.h"
7 
8 // constructor ----------------------------------------------------------------
9 
11  applyBasicCuts( cfg.getParameter<bool>( "applyBasicCuts" ) ),
12  applyNHighestPt( cfg.getParameter<bool>( "applyNHighestPt" ) ),
13  applyMultiplicityFilter( cfg.getParameter<bool>( "applyMultiplicityFilter" ) ),
14  applyMassPairFilter( cfg.getParameter<bool>( "applyMassPairFilter" ) ),
15  nHighestPt( cfg.getParameter<int>( "nHighestPt" ) ),
16  minMultiplicity ( cfg.getParameter<int>( "minMultiplicity" ) ),
17  pMin( cfg.getParameter<double>( "pMin" ) ),
18  pMax( cfg.getParameter<double>( "pMax" ) ),
19  ptMin( cfg.getParameter<double>( "ptMin" ) ),
20  ptMax( cfg.getParameter<double>( "ptMax" ) ),
21  etaMin( cfg.getParameter<double>( "etaMin" ) ),
22  etaMax( cfg.getParameter<double>( "etaMax" ) ),
23  phiMin( cfg.getParameter<double>( "phiMin" ) ),
24  phiMax( cfg.getParameter<double>( "phiMax" ) ),
25  nHitMinSA( cfg.getParameter<double>( "nHitMinSA" ) ),
26  nHitMaxSA( cfg.getParameter<double>( "nHitMaxSA" ) ),
27  chi2nMaxSA( cfg.getParameter<double>( "chi2nMaxSA") ),
28  nHitMinGB( cfg.getParameter<double>( "nHitMinGB" ) ),
29  nHitMaxGB( cfg.getParameter<double>( "nHitMaxGB" ) ),
30  chi2nMaxGB( cfg.getParameter<double>( "chi2nMaxGB") ),
31  nHitMinTO( cfg.getParameter<double>( "nHitMinTO" ) ),
32  nHitMaxTO( cfg.getParameter<double>( "nHitMaxTO" ) ),
33  chi2nMaxTO( cfg.getParameter<double>( "chi2nMaxTO" ) ),
34  minMassPair( cfg.getParameter<double>( "minMassPair" ) ),
35  maxMassPair( cfg.getParameter<double>( "maxMassPair" ) )
36 {
37 
38  if (applyBasicCuts)
39  edm::LogInfo("AlignmentMuonSelector")
40  << "applying basic muon cuts ..."
41  << "\npmin,pmax: " << pMin << "," << pMax
42  << "\nptmin,ptmax: " << ptMin << "," << ptMax
43  << "\netamin,etamax: " << etaMin << "," << etaMax
44  << "\nphimin,phimax: " << phiMin << "," << phiMax
45  << "\nnhitminSA,nhitmaxSA: " << nHitMinSA << "," << nHitMaxSA
46  << "\nchi2nmaxSA: " << chi2nMaxSA<< ","
47  << "\nnhitminGB,nhitmaxGB: " << nHitMinGB << "," << nHitMaxGB
48  << "\nchi2nmaxGB: " << chi2nMaxGB<< ","
49  << "\nnhitminTO,nhitmaxTO: " << nHitMinTO << "," << nHitMaxTO
50  << "\nchi2nmaxTO: " << chi2nMaxTO;
51 
52  if (applyNHighestPt)
53  edm::LogInfo("AlignmentMuonSelector")
54  << "filter N muons with highest Pt N=" << nHighestPt;
55 
57  edm::LogInfo("AlignmentMuonSelector")
58  << "apply multiplicity filter N>=" << minMultiplicity;
59 
61  edm::LogInfo("AlignmentMuonSelector")
62  << "apply Mass Pair filter minMassPair=" << minMassPair << " maxMassPair=" << maxMassPair;
63 
64 }
65 
66 // destructor -----------------------------------------------------------------
67 
69 {}
70 
71 
72 // do selection ---------------------------------------------------------------
73 
76 {
78 
79  // apply basic muon cuts (if selected)
80  if (applyBasicCuts) result= this->basicCuts(result);
81 
82  // filter N muons with highest Pt (if selected)
83  if (applyNHighestPt) result= this->theNHighestPtMuons(result);
84 
85  // apply minimum multiplicity requirement (if selected)
87  if (result.size()<(unsigned int)minMultiplicity) result.clear();
88  }
89 
90  // apply mass pair requirement (if selected)
91  if (applyMassPairFilter) {
92  if (result.size()<2) result.clear(); // at least 2 muons are require for a mass pair...
93  else result = this->theBestMassPairCombinationMuons(result);
94  }
95 
96  edm::LogInfo("AlignmentMuonSelector") << "muons all,kept: " << muons.size() << "," << result.size();
97 
98  return result;
99 
100 }
101 
102 // make basic cuts ------------------------------------------------------------
103 
106 {
107  Muons result;
108 
109  for(Muons::const_iterator it=muons.begin();
110  it!=muons.end();++it) {
111  const reco::Muon* muonp=*it;
112  float p=muonp->p();
113  float pt=muonp->pt();
114  float eta=muonp->eta();
115  float phi=muonp->phi();
116 
117  int nhitSA=0;float chi2nSA=9999.;
118  if(muonp->isStandAloneMuon()){
119  nhitSA = muonp->standAloneMuon()->numberOfValidHits();// standAlone Muon
120  chi2nSA = muonp->standAloneMuon()->normalizedChi2(); // standAlone Muon
121  }
122  int nhitGB=0;float chi2nGB=9999.;
123  if(muonp->isGlobalMuon()){
124  nhitGB = muonp->combinedMuon()->numberOfValidHits();// global Muon
125  chi2nGB = muonp->combinedMuon()->normalizedChi2(); // global Muon
126  }
127  int nhitTO=0;float chi2nTO=9999.;
128  if(muonp->isTrackerMuon()){
129  nhitTO = muonp->track()->numberOfValidHits(); // Tracker Only
130  chi2nTO = muonp->track()->normalizedChi2(); // Tracker Only
131  }
132  edm::LogInfo("AlignmentMuonSelector") << " pt,eta,phi,nhitSA,chi2nSA,nhitGB,chi2nGB,nhitTO,chi2nTO: "
133  <<pt<<","<<eta<<","<<phi<<","<<nhitSA<< ","<<chi2nSA<<","<<nhitGB<< ","<<chi2nGB<<","<<nhitTO<< ","<<chi2nTO;
134 
135  if (p>pMin && p<pMax
136  && pt>ptMin && pt<ptMax
137  && eta>etaMin && eta<etaMax
138  && phi>phiMin && phi<phiMax
139  && nhitSA>=nHitMinSA && nhitSA<=nHitMaxSA
140  && chi2nSA<chi2nMaxSA
141  && nhitGB>=nHitMinGB && nhitGB<=nHitMaxGB
142  && chi2nGB<chi2nMaxGB
143  && nhitTO>=nHitMinTO && nhitTO<=nHitMaxTO
144  && chi2nTO<chi2nMaxTO) {
145  result.push_back(muonp);
146  }
147  }
148 
149  return result;
150 }
151 
152 //-----------------------------------------------------------------------------
153 
156 {
157  Muons sortedMuons=muons;
158  Muons result;
159 
160  // sort in pt
161  std::sort(sortedMuons.begin(),sortedMuons.end(),ptComparator);
162 
163  // copy theMuonMult highest pt muons to result vector
164  int n=0;
165  for (Muons::const_iterator it=sortedMuons.begin();
166  it!=sortedMuons.end(); ++it) {
167  if (n<nHighestPt) { result.push_back(*it); n++; }
168  }
169 
170  return result;
171 }
172 
173 //-----------------------------------------------------------------------------
174 
177 {
178  Muons sortedMuons=muons;
179  Muons result;
180  TLorentzVector mu1,mu2,pair;
181  double mass=0, minDiff=999999.;
182 
183  // sort in pt
184  std::sort(sortedMuons.begin(),sortedMuons.end(),ptComparator);
185 
186  // copy best mass pair combination muons to result vector
187  // Criteria:
188  // a) maxMassPair != minMassPair: the two highest pt muons with mass pair inside the given mass window
189  // b) maxMassPair == minMassPair: the muon pair with massPair closest to given mass value
190  for (Muons::const_iterator it1=sortedMuons.begin();
191  it1!=sortedMuons.end(); ++it1) {
192  for (Muons::const_iterator it2=it1+1;
193  it2!=sortedMuons.end(); ++it2) {
194  mu1 = TLorentzVector((*it1)->momentum().x(),(*it1)->momentum().y(),(*it1)->momentum().z(),(*it1)->p());
195  mu2 = TLorentzVector((*it2)->momentum().x(),(*it2)->momentum().y(),(*it2)->momentum().z(),(*it2)->p());
196  pair=mu1+mu2;
197  mass = pair.M();
198 
199  if( maxMassPair != minMassPair){
200  if(mass<maxMassPair && mass>minMassPair) { result.push_back(*it1); result.push_back(*it2); break;}
201  }
202  else{
203  if(fabs(mass-maxMassPair)< minDiff) { minDiff=fabs(mass-maxMassPair); result.clear(); result.push_back(*it1); result.push_back(*it2);}
204  }
205  }
206  }
207 
208  return result;
209 }
210 
Muons theNHighestPtMuons(const Muons &muons) const
filter the n highest pt muons
std::vector< const reco::Muon * > Muons
TrackRef track() const override
reference to a Track
Definition: Muon.h:49
double eta() const final
momentum pseudorapidity
bool isStandAloneMuon() const override
Definition: Muon.h:274
double pt() const final
transverse momentum
bool isTrackerMuon() const override
Definition: Muon.h:273
AlignmentMuonSelector(const edm::ParameterSet &cfg)
constructor
bool isGlobalMuon() const override
Definition: Muon.h:272
Muons theBestMassPairCombinationMuons(const Muons &muons) const
filter only those muons giving best mass pair combination
bool applyBasicCuts
private data members
TrackRef standAloneMuon() const override
reference to a stand-alone muon Track
Definition: Muon.h:52
applyBasicCuts
do not store empty events
double p() const final
magnitude of momentum vector
TrackRef combinedMuon() const override
reference to a stand-alone muon Track
Definition: Muon.h:55
Muons basicCuts(const Muons &muons) const
apply basic cuts on pt,eta,phi,nhit
Muons select(const Muons &muons, const edm::Event &evt) const
select muons
double phi() const final
momentum azimuthal angle