CMS 3D CMS Logo

BPHDecayToTkpTknSymChargeBuilder.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Paolo Ronchese INFN Padova
5  *
6  */
7 
8 //-----------------------
9 // This Class' Header --
10 //-----------------------
12 
13 //-------------------------------
14 // Collaborating Class Headers --
15 //-------------------------------
27 
28 //---------------
29 // C++ Headers --
30 //---------------
31 using namespace std;
32 
33 //-------------------
34 // Initializations --
35 //-------------------
36 
37 //----------------
38 // Constructors --
39 //----------------
41  const BPHEventSetupWrapper& es,
42  const string& daug1Name,
43  double daug1Mass,
44  double daug1Sigma,
45  const string& daug2Name,
46  double daug2Mass,
47  double daug2Sigma,
48  const BPHRecoBuilder::BPHGenericCollection* posCollection,
49  const BPHRecoBuilder::BPHGenericCollection* negCollection,
50  double expectedMass)
52  d1Name(daug1Name),
53  d1Mass(daug1Mass),
54  d1Sigma(daug1Sigma),
55  d2Name(daug2Name),
56  d2Mass(daug2Mass),
57  d2Sigma(daug2Sigma),
58  eMass(expectedMass),
59  pCollection(posCollection),
60  nCollection(negCollection),
61  pt1Min(-1.0),
62  pt2Min(-1.0),
63  eta1Max(10.0),
64  eta2Max(10.0),
65  dzMax(1.0) {}
66 
67 //--------------
68 // Operations --
69 //--------------
71  // extract basic informations from input collections
72 
73  vector<Particle*> pList;
74  vector<Particle*> nList;
75 
76  addParticle(pCollection, +1, pList);
77  addParticle(nCollection, -1, nList);
78  int iPos;
79  int iNeg;
80  int nPos = pList.size();
81  int nNeg = nList.size();
82  double massMin = getMassMin();
83  double massMax = getMassMax();
84  double mSqMin = massMin * massMin * 0.9;
85  double mSqMax = massMax * massMax * 1.1;
86  if (mSqMin < 0.0)
87  mSqMin = 0.0;
88 
89  for (iPos = 0; iPos < nPos; ++iPos) {
90  Particle* pc = pList[iPos];
91  const reco::Track* pt = pc->track;
92  double px = pc->px;
93  double py = pc->py;
94  double pz = pc->pz;
95  double p1 = pc->e1;
96  double p2 = pc->e2;
97  for (iNeg = 0; iNeg < nNeg; ++iNeg) {
98  Particle* nc = nList[iNeg];
99  const reco::Track* nt = nc->track;
100  if (fabs(nt->dz() - pt->dz()) > dzMax)
101  continue;
102  double nx = nc->px;
103  double ny = nc->py;
104  double nz = nc->pz;
105  double n1 = nc->e1;
106  double n2 = nc->e2;
107  const float tx = px + nx;
108  const float ty = py + ny;
109  const float tz = pz + nz;
110  const float ta = ((p1 > 0.0) && (n2 > 0.0) ? p1 + n2 : -1.0);
111  const float tb = ((p2 > 0.0) && (n1 > 0.0) ? p2 + n1 : -1.0);
112  float ma = (ta > 0 ? (ta * ta) - ((tx * tx) + (ty * ty) + (tz * tz)) : -1.0);
113  float mb = (tb > 0 ? (tb * tb) - ((tx * tx) + (ty * ty) + (tz * tz)) : -1.0);
114  if (((ma < mSqMin) || (ma > mSqMax)) && ((mb < mSqMin) || (mb > mSqMax)))
115  continue;
116  BPHPlusMinusCandidatePtr rc(nullptr);
117  float rcMass = -1.0;
118  if (ma > 0.0) {
120  rc->add(d1Name, pc->cand, d1Mass, d1Sigma);
121  rc->add(d2Name, nc->cand, d2Mass, d2Sigma);
122  rcMass = rc->composite().mass();
123  }
124  BPHPlusMinusCandidatePtr rb(nullptr);
125  float rbMass = -1.0;
126  if (mb > 0.0) {
128  rb->add(d1Name, nc->cand, d1Mass, d1Sigma);
129  rb->add(d2Name, pc->cand, d2Mass, d2Sigma);
130  rbMass = rb->composite().mass();
131  }
132  BPHPlusMinusCandidatePtr* rp(nullptr);
133  double mass = -1.0;
134  if ((rc.get() != nullptr) && ((rb.get() == nullptr) || (fabs(rcMass - eMass) < fabs(rbMass - eMass)))) {
135  mass = rcMass;
136  rp = &rc;
137  } else {
138  mass = rbMass;
139  rp = &rb;
140  }
141  BPHPlusMinusCandidate* rr = rp->get();
142  if (mass < massMin)
143  continue;
144  if (mass > massMax)
145  continue;
146  if (!chi2Sel->accept(*rr))
147  continue;
148  recList.push_back(*rp);
149  }
150  }
151 
152  for (iPos = 0; iPos < nPos; ++iPos)
153  delete pList[iPos];
154  for (iNeg = 0; iNeg < nNeg; ++iNeg)
155  delete nList[iNeg];
156 
157  return;
158 }
159 
162  outdated = true;
163  pt1Min = pt;
164  return;
165 }
166 
168  outdated = true;
169  pt2Min = pt;
170  return;
171 }
172 
174  outdated = true;
175  eta1Max = eta;
176  return;
177 }
178 
180  outdated = true;
181  eta2Max = eta;
182  return;
183 }
184 
186  outdated = true;
187  dzMax = dz;
188  return;
189 }
190 
192  int charge,
193  vector<Particle*>& list) {
194  int i;
195  int n = collection->size();
196  list.reserve(n);
197  for (i = 0; i < n; ++i) {
198  const reco::Candidate& cand = collection->get(i);
199  int q = cand.charge();
200  if ((charge > 0) && (q <= 0))
201  continue;
202  if ((charge < 0) && (q >= 0))
203  continue;
204  const reco::Candidate::LorentzVector p4 = cand.p4();
205  const reco::Track* tk = BPHTrackReference::getTrack(cand, "cfhp");
206  if (tk == nullptr)
207  continue;
208  double px = p4.px();
209  double py = p4.py();
210  double pz = p4.pz();
211  double p2 = (px * px) + (py * py) + (pz * pz);
212  double e1 = ((p4.pt() >= pt1Min) && (p4.eta() <= eta1Max) ? sqrt(p2 + (d1Mass * d1Mass)) : -1.0);
213  double e2 = ((p4.pt() >= pt2Min) && (p4.eta() <= eta2Max) ? sqrt(p2 + (d2Mass * d2Mass)) : -1.0);
214  if ((e1 > 0.0) || (e2 > 0.0))
215  list.push_back(new Particle(&cand, tk, px, py, pz, e1, e2));
216  }
217  return;
218 }
bool accept(const BPHDecayVertex &cand) const override
select vertex
Definition: BPHChi2Select.h:48
static double constexpr eMass
Electron mass[GeV].
Definition: Constants.h:13
constexpr float dzMax
const BPHEventSetupWrapper * evSetup
const BPHRecoBuilder::BPHGenericCollection * nCollection
double getMassMin() const
get current cuts
T sqrt(T t)
Definition: SSEVec.h:19
BPHGenericPtr< BPHPlusMinusCandidate >::type BPHPlusMinusCandidatePtr
static const reco::Track * getTrack(const reco::Candidate &rc, const char *modeList="cfhbpmnigset", char *modeFlag=nullptr)
const BPHRecoBuilder::BPHGenericCollection * pCollection
int nt
Definition: AMPTWrapper.h:42
BPHDecayToTkpTknSymChargeBuilder(const BPHEventSetupWrapper &es, const std::string &daug1Name, double daug1Mass, double daug1Sigma, const std::string &daug2Name, double daug2Mass, double daug2Sigma, const BPHRecoBuilder::BPHGenericCollection *posCollection, const BPHRecoBuilder::BPHGenericCollection *negCollection, double expectedMass)
static type create(Args &&... args)
Definition: BPHGenericPtr.h:10
void addParticle(const BPHRecoBuilder::BPHGenericCollection *collection, int charge, std::vector< Particle *> &list)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
common object to interface with edm collections
void fillRecList() override
build candidates