CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 edm::EventSetup& es,
42  const std::string& daug1Name,
43  double daug1Mass,
44  double daug1Sigma,
45  const std::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 // Destructor --
69 //--------------
71 
72 //--------------
73 // Operations --
74 //--------------
75 vector<BPHPlusMinusConstCandPtr> BPHDecayToTkpTknSymChargeBuilder::build() {
76  if (updated)
77  return recList;
78 
79  recList.clear();
80 
81  // extract basic informations from input collections
82 
83  vector<Particle*> pList;
84  vector<Particle*> nList;
85 
86  addParticle(pCollection, +1, pList);
87  addParticle(nCollection, -1, nList);
88  int iPos;
89  int iNeg;
90  int nPos = pList.size();
91  int nNeg = nList.size();
92  double massMin = getMassMin();
93  double massMax = getMassMax();
94  double mSqMin = massMin * massMin * 0.9;
95  double mSqMax = massMax * massMax * 1.1;
96  if (mSqMin < 0.0)
97  mSqMin = 0.0;
98 
99  for (iPos = 0; iPos < nPos; ++iPos) {
100  Particle* pc = pList[iPos];
101  const reco::Track* pt = pc->track;
102  double px = pc->px;
103  double py = pc->py;
104  double pz = pc->pz;
105  double p1 = pc->e1;
106  double p2 = pc->e2;
107  for (iNeg = 0; iNeg < nNeg; ++iNeg) {
108  Particle* nc = nList[iNeg];
109  const reco::Track* nt = nc->track;
110  if (fabs(nt->dz() - pt->dz()) > dzMax)
111  continue;
112  double nx = nc->px;
113  double ny = nc->py;
114  double nz = nc->pz;
115  double n1 = nc->e1;
116  double n2 = nc->e2;
117  const float tx = px + nx;
118  const float ty = py + ny;
119  const float tz = pz + nz;
120  const float ta = ((p1 > 0.0) && (n2 > 0.0) ? p1 + n2 : -1.0);
121  const float tb = ((p2 > 0.0) && (n1 > 0.0) ? p2 + n1 : -1.0);
122  float ma = (ta > 0 ? (ta * ta) - ((tx * tx) + (ty * ty) + (tz * tz)) : -1.0);
123  float mb = (tb > 0 ? (tb * tb) - ((tx * tx) + (ty * ty) + (tz * tz)) : -1.0);
124  // if ( ma > 0.0 ) ma = sqrt( ma );
125  // else ma = -1.0;
126  // if ( mb > 0.0 ) mb = sqrt( mb );
127  // else mb = -1.0;
128  if (((ma < mSqMin) || (ma > mSqMax)) && ((mb < mSqMin) || (mb > mSqMax)))
129  continue;
130  BPHPlusMinusCandidatePtr rc(nullptr);
131  float rcMass = -1.0;
132  if (ma > 0.0) {
134  rc->add(d1Name, pc->cand, d1Mass, d1Sigma);
135  rc->add(d2Name, nc->cand, d2Mass, d2Sigma);
136  rcMass = rc->composite().mass();
137  }
138  BPHPlusMinusCandidatePtr rb(nullptr);
139  float rbMass = -1.0;
140  if (mb > 0.0) {
142  rb->add(d1Name, nc->cand, d1Mass, d1Sigma);
143  rb->add(d2Name, pc->cand, d2Mass, d2Sigma);
144  rbMass = rb->composite().mass();
145  }
146  BPHPlusMinusCandidatePtr* rp(nullptr);
147  double mass = -1.0;
148  if ((rc.get() != nullptr) && ((rb.get() == nullptr) || (fabs(rcMass - eMass) < fabs(rbMass - eMass)))) {
149  mass = rcMass;
150  rp = &rc;
151  } else {
152  mass = rbMass;
153  rp = &rb;
154  }
155  BPHPlusMinusCandidate* rr = rp->get();
156  if (mass < massMin)
157  continue;
158  if (mass > massMax)
159  continue;
160  if (!chi2Sel->accept(*rr))
161  continue;
162  recList.push_back(*rp);
163  }
164  }
165 
166  for (iPos = 0; iPos < nPos; ++iPos)
167  delete pList[iPos];
168  for (iNeg = 0; iNeg < nNeg; ++iNeg)
169  delete nList[iNeg];
170 
171  updated = true;
172  return recList;
173 }
174 
177  updated = false;
178  pt1Min = pt;
179  return;
180 }
181 
183  updated = false;
184  pt2Min = pt;
185  return;
186 }
187 
189  updated = false;
190  eta1Max = eta;
191  return;
192 }
193 
195  updated = false;
196  eta2Max = eta;
197  return;
198 }
199 
201  updated = false;
202  dzMax = dz;
203  return;
204 }
205 
207  int charge,
208  vector<Particle*>& list) {
209  int i;
210  int n = collection->size();
211  list.reserve(n);
212  for (i = 0; i < n; ++i) {
213  const reco::Candidate& cand = collection->get(i);
214  int q = cand.charge();
215  if ((charge > 0) && (q <= 0))
216  continue;
217  if ((charge < 0) && (q >= 0))
218  continue;
219  const reco::Candidate::LorentzVector p4 = cand.p4();
220  const reco::Track* tk = BPHTrackReference::getTrack(cand, "cfhp");
221  if (tk == nullptr)
222  continue;
223  double px = p4.px();
224  double py = p4.py();
225  double pz = p4.pz();
226  double p2 = (px * px) + (py * py) + (pz * pz);
227  double e1 = ((p4.pt() >= pt1Min) && (p4.eta() <= eta1Max) ? sqrt(p2 + (d1Mass * d1Mass)) : -1.0);
228  double e2 = ((p4.pt() >= pt2Min) && (p4.eta() <= eta2Max) ? sqrt(p2 + (d2Mass * d2Mass)) : -1.0);
229  if ((e1 > 0.0) || (e2 > 0.0))
230  list.push_back(new Particle(&cand, tk, px, py, pz, e1, e2));
231  }
232  return;
233 }
void addParticle(const BPHRecoBuilder::BPHGenericCollection *collection, int charge, std::vector< Particle * > &list)
const TString p2
Definition: fwPaths.cc:13
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 BPHRecoBuilder::BPHGenericCollection * nCollection
std::vector< BPHPlusMinusConstCandPtr > recList
T sqrt(T t)
Definition: SSEVec.h:19
BPHDecayToTkpTknSymChargeBuilder(const edm::EventSetup &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)
BPHGenericPtr< BPHPlusMinusCandidate >::type BPHPlusMinusCandidatePtr
static const reco::Track * getTrack(const reco::Candidate &rc, const char *modeList="cfhbpmnigset", char *modeFlag=nullptr)
const TString p1
Definition: fwPaths.cc:12
virtual const reco::Candidate & get(int i) const =0
const BPHRecoBuilder::BPHGenericCollection * pCollection
virtual int charge() const =0
electric charge
double getMassMin() const
get current cuts
int nt
Definition: AMPTWrapper.h:42
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:622
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
static type create(Args &&...args)
Definition: BPHGenericPtr.h:10
std::vector< BPHPlusMinusConstCandPtr > build()
build candidates
const edm::EventSetup * evSetup
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector