CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Fourvec_Event.cc
Go to the documentation of this file.
1 //
2 // $Id: Fourvec_Event.cc,v 1.2 2013/05/28 17:55:59 gartung Exp $
3 //
4 // File: src/Fourvec_Event.cc
5 // Purpose: Represent an event for kinematic fitting as a collection
6 // of 4-vectors.
7 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
8 //
9 // CMSSW File : src/Fourvec_Event.cc
10 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
11 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
12 //
13 
14 
16 #include <cassert>
17 #include <ostream>
18 
19 
43 using std::ostream;
44 
45 
46 namespace hitfit {
47 
48 
49 FE_Obj::FE_Obj (const Fourvec& the_p,
50  double the_mass,
51  int the_label,
52  double the_p_error,
53  double the_phi_error,
54  double the_eta_error,
55  bool the_muon_p)
56 //
57 // Purpose: Contructor.
58 //
59 // Inputs:
60 // the_p - 4-momentum.
61 // the_mass - The mass of the object.
62 // The constrained fit will fix the mass to this value.
63 // the_p_error - Uncertainty in p (or, if the_muon_p is set, in 1/p).
64 // the_phi_error-Uncertainty in phi.
65 // the_eta_error-Uncertainty in eta.
66 // the_muon_p - If true, the `p' uncertainty is in 1/p, and 1/p
67 // should be used as the fit variable instead of p.
68 //
69  : p (the_p),
70  mass (the_mass),
71  label (the_label),
72  p_error (the_p_error),
73  phi_error (the_phi_error),
74  eta_error (the_eta_error),
75  muon_p (the_muon_p)
76 {
77 }
78 
79 
88 std::ostream& operator<< (std::ostream& s, const FE_Obj& o)
89 //
90 // Purpose: Print the object to S.
91 //
92 // Inputs:
93 // s - The stream to which to write.
94 // o - The object to write.
95 //
96 // Returns:
97 // The stream S.
98 //
99 {
100  s << o.p << " - " << o.mass << " - " << o.label << "\n";
101  s << " errors: " << o.p_error << " " << o.phi_error << " " << o.eta_error;
102  if (o.muon_p)
103  s << " (mu)";
104  s << "\n";
105  return s;
106 }
107 
108 
109 //************************************************************************
110 
111 
113 //
114 // Purpose: Constructor.
115 //
116  : _kt_x_error (0),
117  _kt_y_error (0),
118  _kt_xy_covar (0),
119  _has_neutrino (false)
120 {
121 }
122 
123 
125 //
126 // Purpose: Return true if this event has a neutrino.
127 //
128 // Returns:
129 // True if this event has a neutrino.
130 //
131 {
132  return _has_neutrino;
133 }
134 
135 
137 //
138 // Purpose: Return the number of objects in the event, not including
139 // any neutrino.
140 //
141 // Returns:
142 // The number of objects in the event, not including any neutrino.
143 //
144 {
145  return _objs.size() - (_has_neutrino ? 1 : 0);
146 }
147 
148 
150 //
151 // Purpose: Return the number of objects in the event, including any neutrino.
152 //
153 // Returns:
154 // The number of objects in the event, including any neutrino.
155 //
156 {
157  return _objs.size();
158 }
159 
160 
162 //
163 // Purpose: Access object I.
164 //
165 // Inputs:
166 // i - The index of the desired object (0-based indexing).
167 //
168 {
169  assert (i < _objs.size ());
170  return _objs[i];
171 }
172 
173 
175 //
176 // Purpose: Access the neutrino 4-vector.
177 //
178 {
179  assert (_has_neutrino);
180  return _objs.back().p;
181 }
182 
183 
185 //
186 // Purpose: Access the kt 4-vector.
187 //
188 {
189  return _kt;
190 }
191 
192 
194 //
195 // Purpose: Access the X 4-vector.
196 //
197 {
198  return _x;
199 }
200 
201 
203 //
204 // Purpose: Return the X uncertainty in kt.
205 //
206 // Returns:
207 // The X uncertainty in kt.
208 //
209 {
210  return _kt_x_error;
211 }
212 
213 
215 //
216 // Purpose: Return the Y uncertainty in kt.
217 //
218 // Returns:
219 // The Y uncertainty in kt.
220 //
221 {
222  return _kt_y_error;
223 }
224 
225 
227 //
228 // Purpose: Return the kt XY covariance.
229 //
230 // Returns:
231 // The kt XY covariance.
232 //
233 {
234  return _kt_xy_covar;
235 }
236 
237 
246 std::ostream& operator<< (std::ostream& s, const Fourvec_Event& fe)
247 //
248 // Purpose: Print out the contents of the class.
249 //
250 // Inputs:
251 // s - The stream to which to write.
252 // fe - The object to write.
253 //
254 // Returns:
255 // The stream S.
256 //
257 {
258  s << "kt: (" << fe._kt.x() << ", " << fe._kt.y() << "); "
259  << " error: " << fe._kt_x_error << " " << fe._kt_y_error << " "
260  << fe._kt_xy_covar << "\n";
261  s << "x: " << fe._x << "\n";
262  for (unsigned i = 0; i < fe._objs.size(); i++)
263  s << i+1 << ": " << fe._objs[i];
264  return s;
265 }
266 
267 
269 //
270 // Purpose: Add an object to the event.
271 //
272 // Inputs:
273 // obj - The object to add.
274 // It should not be a neutrino.
275 //
276 {
277  assert (obj.label != nu_label);
278 
279  // Add to the end of the list, but before any neutrino.
280  if (_has_neutrino) {
281  assert (_objs.size() > 0);
282  _objs.insert (_objs.begin() + _objs.size() - 1, obj);
283  }
284  else
285  _objs.push_back (obj);
286 
287  // Maintain kt.
288  _kt += obj.p;
289 }
290 
291 
293 //
294 // Purpose: Set the neutrino 4-momentum to P.
295 // This adds a neutrino if there wasn't one there already.
296 //
297 // Inputs:
298 // p - The new 4-momentum of the neutrino.
299 //
300 {
301  if (_has_neutrino) {
302  _kt -= _objs.back().p;
303  _objs.back().p = p;
304  }
305  else {
306  _has_neutrino = true;
307  _objs.push_back (FE_Obj (p, 0, nu_label, 0, 0, 0, false));
308  }
309 
310  _kt += p;
311 }
312 
313 
315 //
316 // Purpose: Set object I's 4-momentum to P.
317 //
318 // Inputs:
319 // i - The index of the object to change (0-based indexing).
320 // p - The new 4-momentum.
321 //
322 {
323  assert (i < _objs.size ());
324  _kt -= _objs[i].p;
325  _objs[i].p = p;
326  _kt += p;
327 }
328 
329 
331 //
332 // Purpose: Set the momentum of the X object to P.
333 //
334 // Inputs:
335 // p - The new 4-momentum.
336 //
337 {
338  _kt -= _x;
339  _x = p;
340  _kt += p;
341 }
342 
343 
344 void Fourvec_Event::set_kt_error (double kt_x_error,
345  double kt_y_error,
346  double kt_xy_covar)
347 //
348 // Purpose: Set the kt uncertainties.
349 //
350 // Inputs:
351 // kt_x_error - The uncertainty in the X component of kt.
352 // kt_y_error - The uncertainty in the Y component of kt.
353 // kt_xy_covar - The covariance between the X and Y components.
354 //
355 {
359 }
360 
361 
362 } // namespace hitfit
363 
int i
Definition: DBlmapReader.cc:9
Fourvec_Event()
Default constructor.
void set_kt_error(double kt_x_error, double kt_y_error, double kt_xy_covar)
Set the uncertainties on .
Represent an event for kinematic fitting as a collection of four-momenta. Each object is represented ...
void add(const FE_Obj &obj)
Add an object to the event. The object should not be a neutrino, use the method set_nu_p for that...
const int nu_label
const FE_Obj & obj(std::vector< FE_Obj >::size_type i) const
Access object at index i, with the convention that the index starts at 0.
uint16_t size_type
int nobjs() const
Return the number of objects in the event not including any neutrinos.
std::vector< FE_Obj > _objs
double kt_y_error() const
Return the y uncertainty in .
double kt_xy_covar() const
Return the xy covariance in .
CLHEP::HepLorentzVector Fourvec
Typedef for a HepLorentzVector.
Definition: fourvec.h:58
int nobjs_all() const
Return the number of objects in the event including any neutrinos.
void set_nu_p(const Fourvec &p)
Set the neutrino four-momentum to . This method adds a neutrino if there wasn&#39;t already one...
void set_obj_p(std::vector< FE_Obj >::size_type i, const Fourvec &p)
Set the four-momentum of object at index i to .
void set_x_p(const Fourvec &p)
Set the four-momentum of the object.
const Fourvec & kt() const
Access the four-momentum.
string const
Definition: compareJSON.py:14
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream...
FE_Obj(const Fourvec &the_p, double the_mass, int the_label, double the_p_error, double the_phi_error, double the_eta_error, bool the_muon_p)
Constructor.
double kt_x_error() const
Return the x uncertainty in .
Represent a single object in a Fourvec_Event, this is just a dumb data container. Each object in a Fo...
Definition: Fourvec_Event.h:95
const Fourvec & x() const
Access the four-momentum.
const Fourvec & nu() const
Access the neutrino four-momentum.
Represent an event for kinematic fitting as a collection of four-momenta.
bool has_neutrino() const
Return TRUE is this event contains a neutrino, otherwise returns FALSE.