Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:18

0001 //
0002 //
0003 // File: src/Fourvec_Event.cc
0004 // Purpose: Represent an event for kinematic fitting as a collection
0005 //          of 4-vectors.
0006 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
0007 //
0008 // CMSSW File      : src/Fourvec_Event.cc
0009 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
0010 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0011 //
0012 
0013 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
0014 #include <cassert>
0015 #include <ostream>
0016 
0017 /**
0018     @file Fourvec_Event.cc
0019 
0020     @brief Represent an event for kinematic fitting as a collection of
0021     four-momenta.  See the documentation the for header file
0022     Fourvec_Event.h for details.
0023 
0024     @author Scott Stuart Snyder <snyder@bnl.gov>
0025 
0026     @par Creation date:
0027     Jul 2000.
0028 
0029     @par Modification History:
0030     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0031     Imported to CMSSW.<br>
0032     Nov 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0033     Added doxygen tags for automatic generation of documentation.
0034 
0035     @par Terms of Usage:
0036     With consent for the original author (Scott Snyder).
0037 
0038  */
0039 
0040 using std::ostream;
0041 
0042 namespace hitfit {
0043 
0044   FE_Obj::FE_Obj(const Fourvec& the_p,
0045                  double the_mass,
0046                  int the_label,
0047                  double the_p_error,
0048                  double the_phi_error,
0049                  double the_eta_error,
0050                  bool the_muon_p)
0051       //
0052       // Purpose: Contructor.
0053       //
0054       // Inputs:
0055       //   the_p -       4-momentum.
0056       //   the_mass -    The mass of the object.
0057       //                 The constrained fit will fix the mass to this value.
0058       //   the_p_error - Uncertainty in p (or, if the_muon_p is set, in 1/p).
0059       //   the_phi_error-Uncertainty in phi.
0060       //   the_eta_error-Uncertainty in eta.
0061       //   the_muon_p -  If true, the `p' uncertainty is in 1/p, and 1/p
0062       //                 should be used as the fit variable instead of p.
0063       //
0064       : p(the_p),
0065         mass(the_mass),
0066         label(the_label),
0067         p_error(the_p_error),
0068         phi_error(the_phi_error),
0069         eta_error(the_eta_error),
0070         muon_p(the_muon_p) {}
0071 
0072   /**
0073     @brief Output stream operator, print the content of this FE_Obj object
0074     to an output stream.
0075 
0076     @param s The output stream to which to write.
0077 
0078     @param o The instance of FE_Obj to be printed.
0079  */
0080   std::ostream& operator<<(std::ostream& s, const FE_Obj& o)
0081   //
0082   // Purpose: Print the object to S.
0083   //
0084   // Inputs:
0085   //   s -           The stream to which to write.
0086   //   o -           The object to write.
0087   //
0088   // Returns:
0089   //   The stream S.
0090   //
0091   {
0092     s << o.p << " - " << o.mass << " - " << o.label << "\n";
0093     s << "    errors: " << o.p_error << " " << o.phi_error << " " << o.eta_error;
0094     if (o.muon_p)
0095       s << " (mu)";
0096     s << "\n";
0097     return s;
0098   }
0099 
0100   //************************************************************************
0101 
0102   Fourvec_Event::Fourvec_Event()
0103       //
0104       // Purpose: Constructor.
0105       //
0106       : _kt_x_error(0), _kt_y_error(0), _kt_xy_covar(0), _has_neutrino(false) {}
0107 
0108   bool Fourvec_Event::has_neutrino() const
0109   //
0110   // Purpose: Return true if this event has a neutrino.
0111   //
0112   // Returns:
0113   //   True if this event has a neutrino.
0114   //
0115   {
0116     return _has_neutrino;
0117   }
0118 
0119   int Fourvec_Event::nobjs() const
0120   //
0121   // Purpose: Return the number of objects in the event, not including
0122   //          any neutrino.
0123   //
0124   // Returns:
0125   //   The number of objects in the event, not including any neutrino.
0126   //
0127   {
0128     return _objs.size() - (_has_neutrino ? 1 : 0);
0129   }
0130 
0131   int Fourvec_Event::nobjs_all() const
0132   //
0133   // Purpose: Return the number of objects in the event, including any neutrino.
0134   //
0135   // Returns:
0136   //   The number of objects in the event, including any neutrino.
0137   //
0138   {
0139     return _objs.size();
0140   }
0141 
0142   const FE_Obj& Fourvec_Event::obj(std::vector<FE_Obj>::size_type i) const
0143   //
0144   // Purpose: Access object I.
0145   //
0146   // Inputs:
0147   //   i -           The index of the desired object (0-based indexing).
0148   //
0149   {
0150     assert(i < _objs.size());
0151     return _objs[i];
0152   }
0153 
0154   const Fourvec& Fourvec_Event::nu() const
0155   //
0156   // Purpose: Access the neutrino 4-vector.
0157   //
0158   {
0159     assert(_has_neutrino);
0160     return _objs.back().p;
0161   }
0162 
0163   const Fourvec& Fourvec_Event::kt() const
0164   //
0165   // Purpose: Access the kt 4-vector.
0166   //
0167   {
0168     return _kt;
0169   }
0170 
0171   const Fourvec& Fourvec_Event::x() const
0172   //
0173   // Purpose: Access the X 4-vector.
0174   //
0175   {
0176     return _x;
0177   }
0178 
0179   double Fourvec_Event::kt_x_error() const
0180   //
0181   // Purpose: Return the X uncertainty in kt.
0182   //
0183   // Returns:
0184   //   The X uncertainty in kt.
0185   //
0186   {
0187     return _kt_x_error;
0188   }
0189 
0190   double Fourvec_Event::kt_y_error() const
0191   //
0192   // Purpose: Return the Y uncertainty in kt.
0193   //
0194   // Returns:
0195   //   The Y uncertainty in kt.
0196   //
0197   {
0198     return _kt_y_error;
0199   }
0200 
0201   double Fourvec_Event::kt_xy_covar() const
0202   //
0203   // Purpose: Return the kt XY covariance.
0204   //
0205   // Returns:
0206   //   The kt XY covariance.
0207   //
0208   {
0209     return _kt_xy_covar;
0210   }
0211 
0212   /**
0213     @brief Output stream operator, print the content of this Fourvec_Event
0214     object to an output stream.
0215 
0216     @param s The stream to which to write.
0217 
0218     @param fe The instance of Fourvec_Event to be printed.
0219 */
0220   std::ostream& operator<<(std::ostream& s, const Fourvec_Event& fe)
0221   //
0222   // Purpose: Print out the contents of the class.
0223   //
0224   // Inputs:
0225   //   s -           The stream to which to write.
0226   //   fe -          The object to write.
0227   //
0228   // Returns:
0229   //   The stream S.
0230   //
0231   {
0232     s << "kt: (" << fe._kt.x() << ", " << fe._kt.y() << "); "
0233       << " error: " << fe._kt_x_error << " " << fe._kt_y_error << " " << fe._kt_xy_covar << "\n";
0234     s << "x: " << fe._x << "\n";
0235     for (unsigned i = 0; i < fe._objs.size(); i++)
0236       s << i + 1 << ": " << fe._objs[i];
0237     return s;
0238   }
0239 
0240   void Fourvec_Event::add(const FE_Obj& obj)
0241   //
0242   // Purpose: Add an object to the event.
0243   //
0244   // Inputs:
0245   //   obj -         The object to add.
0246   //                 It should not be a neutrino.
0247   //
0248   {
0249     assert(obj.label != nu_label);
0250 
0251     // Add to the end of the list, but before any neutrino.
0252     if (_has_neutrino) {
0253       assert(!_objs.empty());
0254       _objs.insert(_objs.begin() + _objs.size() - 1, obj);
0255     } else
0256       _objs.push_back(obj);
0257 
0258     // Maintain kt.
0259     _kt += obj.p;
0260   }
0261 
0262   void Fourvec_Event::set_nu_p(const Fourvec& p)
0263   //
0264   // Purpose: Set the neutrino 4-momentum to P.
0265   //          This adds a neutrino if there wasn't one there already.
0266   //
0267   // Inputs:
0268   //   p -           The new 4-momentum of the neutrino.
0269   //
0270   {
0271     if (_has_neutrino) {
0272       _kt -= _objs.back().p;
0273       _objs.back().p = p;
0274     } else {
0275       _has_neutrino = true;
0276       _objs.push_back(FE_Obj(p, 0, nu_label, 0, 0, 0, false));
0277     }
0278 
0279     _kt += p;
0280   }
0281 
0282   void Fourvec_Event::set_obj_p(std::vector<FE_Obj>::size_type i, const Fourvec& p)
0283   //
0284   // Purpose: Set object I's 4-momentum to P.
0285   //
0286   // Inputs:
0287   //   i -           The index of the object to change (0-based indexing).
0288   //   p -           The new 4-momentum.
0289   //
0290   {
0291     assert(i < _objs.size());
0292     _kt -= _objs[i].p;
0293     _objs[i].p = p;
0294     _kt += p;
0295   }
0296 
0297   void Fourvec_Event::set_x_p(const Fourvec& p)
0298   //
0299   // Purpose: Set the momentum of the X object to P.
0300   //
0301   // Inputs:
0302   //   p -           The new 4-momentum.
0303   //
0304   {
0305     _kt -= _x;
0306     _x = p;
0307     _kt += p;
0308   }
0309 
0310   void Fourvec_Event::set_kt_error(double kt_x_error, double kt_y_error, double kt_xy_covar)
0311   //
0312   // Purpose: Set the kt uncertainties.
0313   //
0314   // Inputs:
0315   //   kt_x_error -  The uncertainty in the X component of kt.
0316   //   kt_y_error -  The uncertainty in the Y component of kt.
0317   //   kt_xy_covar - The covariance between the X and Y components.
0318   //
0319   {
0320     _kt_x_error = kt_x_error;
0321     _kt_y_error = kt_y_error;
0322     _kt_xy_covar = kt_xy_covar;
0323   }
0324 
0325 }  // namespace hitfit