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