CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/TopQuarkAnalysis/TopHitFit/src/Constraint.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Constraint.cc,v 1.1 2011/05/26 09:46:59 mseidel Exp $
00003 //
00004 // File: src/Constraint.cc
00005 // Purpose: Represent a mass constraint equation.
00006 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
00007 //
00008 // CMSSW File      : src/Constraint.cc
00009 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
00010 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
00011 //
00012 
00013 
00036 #include "TopQuarkAnalysis/TopHitFit/interface/Constraint.h"
00037 #include "TopQuarkAnalysis/TopHitFit/interface/Constraint_Intermed.h"
00038 #include <iostream>
00039 #include <cassert>
00040 
00041 
00042 using std::auto_ptr;
00043 using std::ostream;
00044 using std::string;
00045 
00046 namespace hitfit {
00047 
00048 
00049 Constraint::Constraint (const Constraint& c)
00050 //
00051 // Purpose: Copy constructor.
00052 //
00053 // Inputs:
00054 //   c -           The instance to copy.
00055 //
00056   : _lhs (c._lhs->clone ()),
00057     _rhs (c._rhs->clone ())
00058 {
00059 }
00060 
00061 
00062 Constraint& Constraint::operator= (const Constraint& c)
00063 //
00064 // Purpose: Assignment.
00065 //
00066 // Inputs:
00067 //   c -           The instance to copy.
00068 //
00069 // Returns:
00070 //   This instance.
00071 //
00072 {
00073   {
00074     auto_ptr<Constraint_Intermed> ci = c._lhs->clone ();
00075     _lhs = ci;
00076   }
00077   {
00078     auto_ptr<Constraint_Intermed> ci = c._rhs->clone ();
00079     _rhs = ci;
00080   }
00081 
00082   return *this;
00083 }
00084 
00085 
00086 Constraint::Constraint (std::string s)
00087 //
00088 // Purpose: Constructor.
00089 //          Build a constraint from the string describing it.
00090 //
00091 // Inputs:
00092 //   s -           The string describing the constraint.
00093 //
00094 {
00095   // Split it at the equals sign.
00096   string::size_type i = s.find ('=');
00097   assert (i != string::npos);
00098 
00099   // And then build the two halves.
00100   {
00101     auto_ptr<Constraint_Intermed> ci =
00102       make_constraint_intermed (s.substr (0, i));
00103     _lhs = ci;
00104   }
00105   {
00106     auto_ptr<Constraint_Intermed> ci =
00107       make_constraint_intermed (s.substr (i+1));
00108     _rhs = ci;
00109   }
00110 }
00111 
00112 
00113 int Constraint::has_labels (int ilabel, int jlabel) const
00114 //
00115 // Purpose: See if this guy references both labels ILABEL and JLABEL
00116 //          on a single side of the constraint equation.
00117 //
00118 // Inputs:
00119 //   ilabel -      The first label to test.
00120 //   jlabel -      The second label to test.
00121 //
00122 // Returns:
00123 //   +1 if the LHS references both.
00124 //   -1 if the RHS references both.
00125 //    0 if neither reference both.
00126 //
00127 {
00128   if (_lhs->has_labels (ilabel, jlabel))
00129     return 1;
00130   else if (_rhs->has_labels (ilabel, jlabel))
00131     return -1;
00132   else
00133     return 0;
00134 }
00135 
00136 
00137 double Constraint::sum_mass_terms (const Fourvec_Event& ev) const
00138 //
00139 // Purpose: Evaluate the mass constraint, using the data in EV.
00140 //          Return m(lhs)^2/2 - m(rhs)^2/2.
00141 //
00142 // Inputs:
00143 //   ev -          The event for which the constraint should be evaluated.
00144 //
00145 // Returns:
00146 //   m(lhs)^2/2 - m(rhs)^2/2.
00147 //
00148 {
00149   return _lhs->sum_mass_terms (ev) - _rhs->sum_mass_terms (ev);
00150 }
00151 
00152 
00163 std::ostream& operator<< (std::ostream& s, const Constraint& c)
00164 //
00165 // Purpose: Print the object to S.
00166 //
00167 // Inputs:
00168 //   s -           The stream to which to write.
00169 //   c -           The object to write.
00170 //
00171 // Returns:
00172 //   The stream S.
00173 //
00174 {
00175   s << *c._lhs.get() << " = " << *c._rhs.get();
00176   return s;
00177 }
00178 
00179 
00180 } // namespace hitfit