Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 //
0003 // File: src/Constraint.cc
0004 // Purpose: Represent a mass constraint equation.
0005 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
0006 //
0007 // CMSSW File      : src/Constraint.cc
0008 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
0009 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0010 //
0011 
0012 /**
0013     @file Constraint.cc
0014 
0015     @brief Represent a mass constraint equation.
0016     See the documentation for the header file Constraint.h for details.
0017 
0018     @par Creation date:
0019     July 2000.
0020 
0021     @author
0022     Scott Stuart Snyder <snyder@bnl.gov>.
0023 
0024     @par Modification History:
0025     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0026     Imported to CMSSW.<br>
0027     Oct 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0028     Added Doxygen tags for automatic generation of documentation.
0029 
0030     @par Terms of Usage:
0031     With consent from the original author (Scott Snyder).
0032  */
0033 
0034 #include "TopQuarkAnalysis/TopHitFit/interface/Constraint.h"
0035 #include "TopQuarkAnalysis/TopHitFit/interface/Constraint_Intermed.h"
0036 #include <iostream>
0037 #include <cassert>
0038 
0039 using std::ostream;
0040 using std::string;
0041 using std::unique_ptr;
0042 
0043 namespace hitfit {
0044 
0045   Constraint::Constraint(const Constraint& c)
0046       //
0047       // Purpose: Copy constructor.
0048       //
0049       // Inputs:
0050       //   c -           The instance to copy.
0051       //
0052       : _lhs(c._lhs->clone()), _rhs(c._rhs->clone()) {}
0053 
0054   Constraint& Constraint::operator=(const Constraint& c)
0055   //
0056   // Purpose: Assignment.
0057   //
0058   // Inputs:
0059   //   c -           The instance to copy.
0060   //
0061   // Returns:
0062   //   This instance.
0063   //
0064   {
0065     {
0066       unique_ptr<Constraint_Intermed> ci = c._lhs->clone();
0067       _lhs = std::move(ci);
0068     }
0069     {
0070       unique_ptr<Constraint_Intermed> ci = c._rhs->clone();
0071       _rhs = std::move(ci);
0072     }
0073 
0074     return *this;
0075   }
0076 
0077   Constraint::Constraint(std::string s)
0078   //
0079   // Purpose: Constructor.
0080   //          Build a constraint from the string describing it.
0081   //
0082   // Inputs:
0083   //   s -           The string describing the constraint.
0084   //
0085   {
0086     // Split it at the equals sign.
0087     string::size_type i = s.find('=');
0088     assert(i != string::npos);
0089 
0090     // And then build the two halves.
0091     {
0092       unique_ptr<Constraint_Intermed> ci = make_constraint_intermed(s.substr(0, i));
0093       _lhs = std::move(ci);
0094     }
0095     {
0096       unique_ptr<Constraint_Intermed> ci = make_constraint_intermed(s.substr(i + 1));
0097       _rhs = std::move(ci);
0098     }
0099   }
0100 
0101   int Constraint::has_labels(int ilabel, int jlabel) const
0102   //
0103   // Purpose: See if this guy references both labels ILABEL and JLABEL
0104   //          on a single side of the constraint equation.
0105   //
0106   // Inputs:
0107   //   ilabel -      The first label to test.
0108   //   jlabel -      The second label to test.
0109   //
0110   // Returns:
0111   //   +1 if the LHS references both.
0112   //   -1 if the RHS references both.
0113   //    0 if neither reference both.
0114   //
0115   {
0116     if (_lhs->has_labels(ilabel, jlabel))
0117       return 1;
0118     else if (_rhs->has_labels(ilabel, jlabel))
0119       return -1;
0120     else
0121       return 0;
0122   }
0123 
0124   double Constraint::sum_mass_terms(const Fourvec_Event& ev) const
0125   //
0126   // Purpose: Evaluate the mass constraint, using the data in EV.
0127   //          Return m(lhs)^2/2 - m(rhs)^2/2.
0128   //
0129   // Inputs:
0130   //   ev -          The event for which the constraint should be evaluated.
0131   //
0132   // Returns:
0133   //   m(lhs)^2/2 - m(rhs)^2/2.
0134   //
0135   {
0136     return _lhs->sum_mass_terms(ev) - _rhs->sum_mass_terms(ev);
0137   }
0138 
0139   /**
0140 
0141     @brief Output stream operator, print the content of this Constraint to
0142     an output stream.
0143 
0144     @param s The stream to which to write.
0145 
0146     @param c The instance of Constraint to be printed.
0147 
0148 */
0149   std::ostream& operator<<(std::ostream& s, const Constraint& c)
0150   //
0151   // Purpose: Print the object to S.
0152   //
0153   // Inputs:
0154   //   s -           The stream to which to write.
0155   //   c -           The object to write.
0156   //
0157   // Returns:
0158   //   The stream S.
0159   //
0160   {
0161     s << *c._lhs.get() << " = " << *c._rhs.get();
0162     return s;
0163   }
0164 
0165 }  // namespace hitfit