CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/TopQuarkAnalysis/TopHitFit/src/Fourvec_Event.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Fourvec_Event.cc,v 1.2 2013/05/28 17:55:59 gartung Exp $
00003 //
00004 // File: src/Fourvec_Event.cc
00005 // Purpose: Represent an event for kinematic fitting as a collection
00006 //          of 4-vectors.
00007 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
00008 //
00009 // CMSSW File      : src/Fourvec_Event.cc
00010 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
00011 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
00012 //
00013 
00014 
00015 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
00016 #include <cassert>
00017 #include <ostream>
00018 
00019 
00043 using std::ostream;
00044 
00045 
00046 namespace hitfit {
00047 
00048 
00049 FE_Obj::FE_Obj (const Fourvec& the_p,
00050                 double the_mass,
00051                 int the_label,
00052                 double the_p_error,
00053                 double the_phi_error,
00054                 double the_eta_error,
00055                 bool the_muon_p)
00056 //
00057 // Purpose: Contructor.
00058 //
00059 // Inputs:
00060 //   the_p -       4-momentum.
00061 //   the_mass -    The mass of the object.
00062 //                 The constrained fit will fix the mass to this value.
00063 //   the_p_error - Uncertainty in p (or, if the_muon_p is set, in 1/p).
00064 //   the_phi_error-Uncertainty in phi.
00065 //   the_eta_error-Uncertainty in eta.
00066 //   the_muon_p -  If true, the `p' uncertainty is in 1/p, and 1/p
00067 //                 should be used as the fit variable instead of p.
00068 //
00069   : p (the_p),
00070     mass (the_mass),
00071     label (the_label),
00072     p_error (the_p_error),
00073     phi_error (the_phi_error),
00074     eta_error (the_eta_error),
00075     muon_p (the_muon_p)
00076 {
00077 }
00078 
00079 
00088 std::ostream& operator<< (std::ostream& s, const FE_Obj& o)
00089 //
00090 // Purpose: Print the object to S.
00091 //
00092 // Inputs:
00093 //   s -           The stream to which to write.
00094 //   o -           The object to write.
00095 //
00096 // Returns:
00097 //   The stream S.
00098 //
00099 {
00100   s << o.p << " - " << o.mass << " - " << o.label << "\n";
00101   s << "    errors: " << o.p_error << " " << o.phi_error << " " << o.eta_error;
00102   if (o.muon_p)
00103     s << " (mu)";
00104   s << "\n";
00105   return s;
00106 }
00107 
00108 
00109 //************************************************************************
00110 
00111 
00112 Fourvec_Event::Fourvec_Event ()
00113 //
00114 // Purpose: Constructor.
00115 //
00116   : _kt_x_error (0),
00117     _kt_y_error (0),
00118     _kt_xy_covar (0),
00119     _has_neutrino (false)
00120 {
00121 }
00122 
00123 
00124 bool Fourvec_Event::has_neutrino () const
00125 //
00126 // Purpose: Return true if this event has a neutrino.
00127 //
00128 // Returns:
00129 //   True if this event has a neutrino.
00130 //
00131 {
00132   return _has_neutrino;
00133 }
00134 
00135 
00136 int Fourvec_Event::nobjs () const
00137 //
00138 // Purpose: Return the number of objects in the event, not including
00139 //          any neutrino.
00140 //
00141 // Returns:
00142 //   The number of objects in the event, not including any neutrino.
00143 //
00144 {
00145   return _objs.size() - (_has_neutrino ? 1 : 0);
00146 }
00147 
00148 
00149 int Fourvec_Event::nobjs_all () const
00150 //
00151 // Purpose: Return the number of objects in the event, including any neutrino.
00152 //
00153 // Returns:
00154 //   The number of objects in the event, including any neutrino.
00155 //
00156 {
00157   return _objs.size();
00158 }
00159 
00160 
00161 const FE_Obj& Fourvec_Event::obj (std::vector<FE_Obj>::size_type i) const
00162 //
00163 // Purpose: Access object I.
00164 //
00165 // Inputs:
00166 //   i -           The index of the desired object (0-based indexing).
00167 //
00168 {
00169   assert (i < _objs.size ());
00170   return _objs[i];
00171 }
00172 
00173 
00174 const Fourvec& Fourvec_Event::nu () const
00175 //
00176 // Purpose: Access the neutrino 4-vector.
00177 //
00178 {
00179   assert (_has_neutrino);
00180   return _objs.back().p;
00181 }
00182 
00183 
00184 const Fourvec& Fourvec_Event::kt () const
00185 //
00186 // Purpose: Access the kt 4-vector.
00187 //
00188 {
00189   return _kt;
00190 }
00191 
00192 
00193 const Fourvec& Fourvec_Event::x () const
00194 //
00195 // Purpose: Access the X 4-vector.
00196 //
00197 {
00198   return _x;
00199 }
00200 
00201 
00202 double Fourvec_Event::kt_x_error () const
00203 //
00204 // Purpose: Return the X uncertainty in kt.
00205 //
00206 // Returns:
00207 //   The X uncertainty in kt.
00208 //
00209 {
00210   return _kt_x_error;
00211 }
00212 
00213 
00214 double Fourvec_Event::kt_y_error () const
00215 //
00216 // Purpose: Return the Y uncertainty in kt.
00217 //
00218 // Returns:
00219 //   The Y uncertainty in kt.
00220 //
00221 {
00222   return _kt_y_error;
00223 }
00224 
00225 
00226 double Fourvec_Event::kt_xy_covar () const
00227 //
00228 // Purpose: Return the kt XY covariance.
00229 //
00230 // Returns:
00231 //   The kt XY covariance.
00232 //
00233 {
00234   return _kt_xy_covar;
00235 }
00236 
00237 
00246 std::ostream& operator<< (std::ostream& s, const Fourvec_Event& fe)
00247 //
00248 // Purpose: Print out the contents of the class.
00249 //
00250 // Inputs:
00251 //   s -           The stream to which to write.
00252 //   fe -          The object to write.
00253 //
00254 // Returns:
00255 //   The stream S.
00256 //
00257 {
00258   s << "kt: (" << fe._kt.x() << ", " << fe._kt.y() << "); "
00259     << " error: " << fe._kt_x_error << " " << fe._kt_y_error << " "
00260     << fe._kt_xy_covar << "\n";
00261   s << "x: " << fe._x << "\n";
00262   for (unsigned i = 0; i < fe._objs.size(); i++)
00263     s << i+1 << ": " << fe._objs[i];
00264   return s;
00265 }
00266 
00267 
00268 void Fourvec_Event::add (const FE_Obj& obj)
00269 //
00270 // Purpose: Add an object to the event.
00271 //
00272 // Inputs:
00273 //   obj -         The object to add.
00274 //                 It should not be a neutrino.
00275 //
00276 {
00277   assert (obj.label != nu_label);
00278 
00279   // Add to the end of the list, but before any neutrino.
00280   if (_has_neutrino) {
00281     assert (_objs.size() > 0);
00282     _objs.insert (_objs.begin() + _objs.size() - 1, obj);
00283   }
00284   else
00285     _objs.push_back (obj);
00286 
00287   // Maintain kt.
00288   _kt += obj.p;
00289 }
00290 
00291 
00292 void Fourvec_Event::set_nu_p (const Fourvec& p)
00293 //
00294 // Purpose: Set the neutrino 4-momentum to P.
00295 //          This adds a neutrino if there wasn't one there already.
00296 //
00297 // Inputs:
00298 //   p -           The new 4-momentum of the neutrino.
00299 //
00300 {
00301   if (_has_neutrino) {
00302     _kt -= _objs.back().p;
00303     _objs.back().p = p;
00304   }
00305   else {
00306     _has_neutrino = true;
00307     _objs.push_back (FE_Obj (p, 0, nu_label, 0, 0, 0, false));
00308   }
00309 
00310   _kt += p;
00311 }
00312 
00313 
00314 void Fourvec_Event::set_obj_p (std::vector<FE_Obj>::size_type i, const Fourvec& p)
00315 //
00316 // Purpose: Set object I's 4-momentum to P.
00317 //
00318 // Inputs:
00319 //   i -           The index of the object to change (0-based indexing).
00320 //   p -           The new 4-momentum.
00321 //
00322 {
00323   assert (i < _objs.size ());
00324   _kt -= _objs[i].p;
00325   _objs[i].p = p;
00326   _kt += p;
00327 }
00328 
00329 
00330 void Fourvec_Event::set_x_p (const Fourvec& p)
00331 //
00332 // Purpose: Set the momentum of the X object to P.
00333 //
00334 // Inputs:
00335 //   p -           The new 4-momentum.
00336 //
00337 {
00338   _kt -= _x;
00339   _x = p;
00340   _kt += p;
00341 }
00342 
00343 
00344 void Fourvec_Event::set_kt_error (double kt_x_error,
00345                                   double kt_y_error,
00346                                   double kt_xy_covar)
00347 //
00348 // Purpose: Set the kt uncertainties.
00349 //
00350 // Inputs:
00351 //   kt_x_error -  The uncertainty in the X component of kt.
00352 //   kt_y_error -  The uncertainty in the Y component of kt.
00353 //   kt_xy_covar - The covariance between the X and Y components.
00354 //
00355 {
00356   _kt_x_error = kt_x_error;
00357   _kt_y_error = kt_y_error;
00358   _kt_xy_covar = kt_xy_covar;
00359 }
00360 
00361 
00362 } // namespace hitfit
00363