Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 //
0003 // File: hitfit/private/Constraint_Intermed.h
0004 // Purpose: Represent one side of a mass constraint equation.
0005 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
0006 //
0007 // Mass constraints come in two varieties, either saying that the sum
0008 // of a set of labels should equal a constant:
0009 //
0010 //     (1 + 2) = 80
0011 //
0012 // or that two such sums should equal each other:
0013 //
0014 //     (1 + 2) = (3 + 4)
0015 //
0016 // These classes represent one side of such an equation.
0017 // There is an abstract base class Constraint_Intermed, and then concrete
0018 // implementations for the two cases, Constraint_Intermed_Constant
0019 // and Constraint_Intermed_Labels.  There is also a free function
0020 // make_constraint_intermed() to parse a string representing one
0021 // side of a constraint and return the appropriate Constraint_Intermed
0022 // instance.
0023 //
0024 // CMSSW File      : interface/Constraint_Intermed.h
0025 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
0026 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0027 //
0028 
0029 /**
0030     @file Constraint_Intermed.h
0031 
0032     @brief Represent one side of a mass constraint equation.
0033     Contains the abstract base class <i>Constraint_Intermed</i> and concrete
0034     implementations <i>Constraint_Intermed_Constant</i> and
0035     <i>Constraint_Intermed_Labels</i>.
0036 
0037     Mass constraints come in two varieties, either saying that the sum
0038     of a set of labels should equal a constant:<br>
0039 
0040     \f$(1 + 2) = 80\f$.<br>
0041 
0042     or that two such sums should equal each other:<br>
0043 
0044     \f$(1 + 2) = (3 + 4)\f$.<br>
0045 
0046     These classes represent one side of such an equation.
0047     There is an abstract base class <i>Constraint_Intermed</i>, and then the
0048     concrete implementations of the two cases, <i>Constraint_Intermed_Constant</i>
0049     and <i>Constraint_Intermed_Labels</i>.  There is also a free function
0050     make_constant_intermed() to parse a string representation one
0051     side of the constraint and return the appropriate <i>Constraint_Intermed</i>
0052     instance.
0053 
0054     @par Creation date:
0055     July 2000.
0056 
0057     @author
0058     Scott Stuart Snyder <snyder@bnl.gov>.
0059 
0060     @par Modification History:
0061     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0062     Imported to CMSSW.<br>
0063     Oct 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0064     Added Doxygen tags for automatic generation of documentation.
0065 
0066     @par Terms of Usage:
0067     With consent from the original author (Scott Snyder).
0068  */
0069 
0070 #ifndef HITFIT_CONSTRAINT_INTERMED_H
0071 #define HITFIT_CONSTRAINT_INTERMED_H
0072 
0073 #include <iosfwd>
0074 #include <vector>
0075 #include <string>
0076 #include <memory>
0077 
0078 namespace hitfit {
0079 
0080   class Fourvec_Event;
0081 
0082   //************************************************************************
0083 
0084   /**
0085    @class Constraint_Intermed.
0086 
0087    @brief Abstract base classes for describing one side of a mass constraint.
0088  */
0089   class Constraint_Intermed
0090   //
0091   // Purpose: Abstract base class for describing one side of a mass constraint.
0092   //
0093   {
0094   public:
0095     // Constructor, destructor.
0096 
0097     /**
0098      Constructor.
0099    */
0100     Constraint_Intermed() {}
0101 
0102     /**
0103      Destructor.
0104    */
0105     virtual ~Constraint_Intermed() {}
0106 
0107     // Return true if this guy references both labels ILABEL and JLABEL.
0108     /**
0109 
0110      Check the instance for reference of <i>ilabel</i> and <i>jlabel</i>.
0111 
0112      @param ilabel The first label to test.
0113      @param jlabel The second label to test.
0114 
0115      @par Return:
0116      <b>true</b> if this instance references both labels <i>ilabel</i>
0117      and <i>jlabel</i>.<br>
0118      <b>false</b> if this instance doesn't reference both labels.
0119 
0120    */
0121     virtual bool has_labels(int ilabel, int jlabel) const = 0;
0122 
0123     // Evaluate this half of the mass constraint, using the data in EV.
0124     // Return m^2/2.
0125     /**
0126      Evaluate this half of the mass constraint, using the data in <i>ev</i>.
0127 
0128      @param ev The event for which the mass constraint is to be evaluated.
0129 
0130      @par Return:
0131      \f$\frac{m^{2}}{2}\f$.
0132    */
0133     virtual double sum_mass_terms(const Fourvec_Event& ev) const = 0;
0134 
0135     // Print out this object.
0136     /**
0137      Print out the instance to the output stream.
0138 
0139      @param s The output stream to which the instance is printed.
0140    */
0141     virtual void print(std::ostream& s) const = 0;
0142 
0143     // Copy this object.
0144     /**
0145      Clone function to copy the instance.
0146    */
0147     virtual std::unique_ptr<Constraint_Intermed> clone() const = 0;
0148   };
0149 
0150   //************************************************************************
0151 
0152   /**
0153    @class Constraint_Intermed_Constant
0154    @brief Concrete class for one side of mass constraint
0155    equation of the type:<br>
0156    \f$(1 + 2) = C\f$.
0157  */
0158   class Constraint_Intermed_Constant : public Constraint_Intermed
0159   //
0160   // Purpose: Concrete base class for a constant mass constraint half.
0161   //
0162   {
0163   public:
0164     // Constructor, destructor.
0165     /**
0166      Constructor.
0167 
0168      @param constant The mass constraint of the constraint equation.
0169    */
0170     Constraint_Intermed_Constant(double constant);
0171 
0172     /**
0173      Destructor.
0174    */
0175     ~Constraint_Intermed_Constant() override{};
0176 
0177     // Copy constructor.
0178     /**
0179      Copy constructor.
0180      @param c The instance to be copied.
0181    */
0182     Constraint_Intermed_Constant(const Constraint_Intermed_Constant& c);
0183 
0184     // Return true if this guy references both labels ILABEL and JLABEL.
0185     /**
0186 
0187      Check the instance for reference of <i>ilabel</i> and <i>jlabel</i>.
0188 
0189      @param ilabel The first label to test.
0190      @param jlabel The second label to test.
0191 
0192      @par Return:
0193      <b>true</b> if this instance references both labels <i>ilabel</i>
0194      and <i>jlabel</i>.<br>
0195      <b>false</b> if this instance doesn't reference both labels.
0196 
0197    */
0198     bool has_labels(int ilabel, int jlabel) const override;
0199 
0200     // Evaluate this half of the mass constraint, using the data in EV.
0201     // Return m^2/2.
0202     /**
0203      Evaluate this half of the mass constraint, using the data in <i>ev</i>.
0204 
0205      @param ev The event for which the mass constraint is to be evaluated.
0206 
0207      @par Return:
0208      \f$\frac{m^{2}}{2}\f$.
0209    */
0210     double sum_mass_terms(const Fourvec_Event& ev) const override;
0211 
0212     // Print out this object.
0213     /**
0214      Print out the instance to the output stream.
0215 
0216      @param s The output stream to which the instance is printed.
0217    */
0218     void print(std::ostream& s) const override;
0219 
0220     // Copy this object.
0221     /**
0222      Clone function to copy the instance.
0223    */
0224     std::unique_ptr<Constraint_Intermed> clone() const override;
0225 
0226   private:
0227     // Store c^2 / 2.
0228     /**
0229      The mass constraint value.
0230    */
0231     double _c2;
0232   };
0233 
0234   //************************************************************************
0235 
0236   /**
0237 
0238    @class Constraint_Intermed_Labels
0239 
0240    @brief Concrete class for one side of mass constraint
0241    equation of the type:<br>
0242    \f$(1 + 2) =  (3 + 4)\f$.
0243 
0244  */
0245   class Constraint_Intermed_Labels : public Constraint_Intermed {
0246   public:
0247     /**
0248      Constructor.
0249      @param labels The labels used by this side of mass constraint.
0250    */
0251     Constraint_Intermed_Labels(const std::vector<int>& labels);
0252 
0253     /**
0254      Copy constructor.
0255      @param c The instance of Constraint_Intermed_Labels to be copied.
0256    */
0257     Constraint_Intermed_Labels(const Constraint_Intermed_Labels& c);
0258     /**
0259      Destructor.
0260    */
0261     ~Constraint_Intermed_Labels() override{};
0262 
0263     // Return true if this guy references both labels ILABEL and JLABEL.
0264     /**
0265 
0266      Check the instance for reference of <i>ilabel</i> and <i>jlabel</i>.
0267 
0268      @param ilabel The first label to test.
0269      @param jlabel The second label to test.
0270 
0271      @par Return:
0272      <b>true</b> if this instance references both labels <i>ilabel</i>
0273      and <i>jlabel</i>.<br>
0274      <b>false</b> if this instance doesn't reference both labels.
0275 
0276    */
0277     bool has_labels(int ilabel, int jlabel) const override;
0278 
0279     // Evaluate this half of the mass constraint, using the data in EV.
0280     // Return m^2/2.
0281     /**
0282      Evaluate this half of the mass constraint, using the data in <i>ev</i>.
0283 
0284      @param ev The event for which the mass constraint is to be evaluated.
0285 
0286      @par Return:
0287      \f$\frac{m^{2}}{2}\f$.
0288    */
0289     double sum_mass_terms(const Fourvec_Event& ev) const override;
0290 
0291     // Print out this object.
0292     /**
0293      Print out the instance to the output stream.
0294 
0295      @param s The output stream to which the instance is printed.
0296    */
0297     void print(std::ostream& s) const override;
0298 
0299     // Copy this object.
0300     /**
0301      Clone function to copy the instance.
0302    */
0303     std::unique_ptr<Constraint_Intermed> clone() const override;
0304 
0305   private:
0306     // Test to see if LABEL is used by this constraint half.
0307     /**
0308      Test to see if <i>label</i> is used by this side of the mass constraint.
0309      @param label The label for which to search.
0310      @par Return:
0311      <b>true</b> is this constraint use the label.
0312      <b>false</b> if this constraint doesn't use the label.
0313    */
0314     bool has_label(int label) const;
0315 
0316     // List of the labels for this constraint half, kept in sorted order.
0317     /**
0318      List of the labels for this side of mass constraint, kept in sorted
0319      order.
0320    */
0321     std::vector<int> _labels;
0322 
0323     // Disallow assignment
0324     /**
0325      Disallow assignment by NOT defining the assignment operation.
0326    */
0327     Constraint_Intermed& operator=(const Constraint_Intermed&);
0328   };
0329 
0330   //************************************************************************
0331 
0332   // Print out a Constraint_Intermed object.
0333   std::ostream& operator<<(std::ostream& s, const Constraint_Intermed& ci);
0334 
0335   // Parse the string S and construct the appropriate Constraint_Intermed
0336   // instance.
0337   /**
0338    Helper function to parse input string <i>s</i> and construct the
0339    appropriate Constraint_Intermed instance.  Returns null if the input
0340    string cannot be interpreted as a mass constraint.
0341 
0342    The string should be either a numeric constant like
0343 
0344    80.4
0345 
0346    or a list of integers in parenthesis like
0347 
0348    (1 2 4)
0349 
0350    Leading spaces are ignored, as is text in a leading <>
0351    construction.
0352 
0353    @param s The string to parse which contains information about the mass
0354    constraint.
0355    @par Return:
0356    <b>Valid pointer</b> to the appropriate type of constraint object,
0357    i.e. a Constraint_Intermed_Constant or a
0358    Constraint_Intermed_Labels.<br>
0359    <b>NULL pointer</b> if the input string cannot be interpreted as
0360    a mass constraint.
0361  */
0362   std::unique_ptr<Constraint_Intermed> make_constraint_intermed(std::string s);
0363 
0364 }  // namespace hitfit
0365 
0366 #endif  // not HITFIT_CONSTRAINT_INTERMED_H