Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 //
0003 // File: hitfit/Fourvec_Constrainer.h
0004 // Purpose: Do a kinematic fit for a set of 4-vectors, given a set
0005 //          of mass constraints.
0006 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
0007 //
0008 // Do a constrained fit on a set of 4-vectors.
0009 // The input is in a Fourvec_Event instance.  This consists
0010 // of a collection of objects, each of which has a 4-momentum
0011 // and an integer label.  (Also uncertainties, etc.)
0012 //
0013 // We also have a set of mass constraints, based on sums of objects
0014 // with specified labels.  A constraint can either require that the
0015 // invariant mass of a set of objects is constant, or that the masses
0016 // of two sets be equal to each other.  For example, the constraint
0017 //
0018 //    (1 2) = 80
0019 //
0020 // says that the sum of all objects with labels 1 and 2 should have
0021 // a mass of 80.  And the constraint
0022 //
0023 //    (1 2) = (3 4)
0024 //
0025 // says that the sum of all objects with labels 1 and 2 should
0026 // have an invariant mass the same as the sum of all objects with
0027 // labels 3 and 4.
0028 //
0029 // All the objects are fixed to constant masses for the fit.
0030 // (These masses are attributes of the objects in the Fourvec_Event.)
0031 // This is done by scaling either the 4-vector's 3-momentum or energy,
0032 // depending on the setting of the `use_e' parameter.
0033 //
0034 // If there is no neutrino present in the event, two additional constraints
0035 // are automatically added for total pt balance, unless the parameter
0036 // ignore_met has been set.
0037 //
0038 // When the fit completes, this object can compute an invariant mass
0039 // out of some combination of the objects, including an uncertainty.
0040 // The particular combination is specified through the method mass_contraint();
0041 // it gets a constraint string like normal; the lhs of the constraint
0042 // is the mass that will be calculated.  (The rhs should be zero.)
0043 //
0044 // CMSSW File      : interface/Fourvec_Constrainer.h
0045 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
0046 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0047 //
0048 
0049 /**
0050 
0051     @file Fourvec_Constrainer.h
0052 
0053     @brief Do a kinematic fit for a set of four-vectors, given a set
0054     of mass constraints.
0055 
0056     @author Scott Stuart Snyder <snyder@bnl.gov>
0057 
0058     @par Creation date:
0059     Jul 2000.
0060 
0061     @par Modification History:
0062     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0063     Imported to CMSSW.<br>
0064     Nov 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0065     Added doxygen tags for automatic generation of documentation.
0066 
0067     @par Terms of Usage:
0068     With consent for the original author (Scott Snyder).
0069 
0070 */
0071 
0072 #ifndef HITFIT_FOURVEC_CONSTRAINER_H
0073 #define HITFIT_FOURVEC_CONSTRAINER_H
0074 
0075 #include <string>
0076 #include <vector>
0077 #include <iosfwd>
0078 #include "TopQuarkAnalysis/TopHitFit/interface/Constraint.h"
0079 #include "TopQuarkAnalysis/TopHitFit/interface/Chisq_Constrainer.h"
0080 #include "TopQuarkAnalysis/TopHitFit/interface/matutil.h"
0081 
0082 namespace hitfit {
0083 
0084   class Defaults;
0085   class Fourvec_Event;
0086   class Pair_Table;
0087 
0088   /**
0089     @class Fourvec_Constrainer_Args
0090 
0091     @brief Hold on to parameters for the Fourvec_Constrainer class.
0092  */
0093   class Fourvec_Constrainer_Args
0094   //
0095   // Purpose: Hold on to parameters for the Fourvec_Constrainer class.
0096   //
0097   // Parameters controlling the operation of the fitter:
0098   //   bool use_e         - If true, then when rescaling the 4-vectors
0099   //                        for a given mass, keep the measured energy
0100   //                        and scale the 3-momentum.  Otherwise, keep
0101   //                        the 3-momentum and scale the energy.
0102   //   float e_com        - The center-of-mass energy.
0103   //                        (Used only to keep the fit from venturing
0104   //                        into completely unphysical regions.)
0105   //   bool ignore_met    - If this is true and the event does not
0106   //                        have a neutrino, then the fit will be done
0107   //                        without the overall transverse momentum
0108   //                        constraint (and thus the missing Et information
0109   //                        will be ignored).  If the event does have
0110   //                        a neutrino, this parameter is ignored.
0111   //
0112   {
0113   public:
0114     // Constructor.  Initialize from a Defaults object.
0115     /**
0116      @brief Constructor, initialize from a Defaults object.
0117 
0118      @param defs The set of parameters for the initialization.  The instance
0119      must contain the following variables of types and names:
0120      - bool <i>use_e</i>.
0121      - double <i>e_com</i>.
0122      - bool <i>ignore_met</i>.
0123    */
0124     Fourvec_Constrainer_Args(const Defaults& defs);
0125 
0126     // Retrieve parameter values.
0127     /**
0128      Return the <i>_use_e</i> parameter.
0129    */
0130     bool use_e() const;
0131 
0132     /**
0133      Return the <i>_e_com</i> parameter.
0134    */
0135     double e_com() const;
0136 
0137     /**
0138      Return the <i>_ignore_met</i> parameter.
0139    */
0140     bool ignore_met() const;
0141 
0142     // Arguments for subobjects.
0143     const Chisq_Constrainer_Args& chisq_constrainer_args() const;
0144 
0145   private:
0146     // Hold on to parameter values.
0147     /**
0148      If TRUE, then when rescaling a four-momentum for a given mass,
0149      keep the measured energy and scale the three-momentum.
0150      If FALSE, then keep the three-momentum and scale the energy.
0151    */
0152     bool _use_e;
0153 
0154     /**
0155      The center-of-mass energy. Used only to keep the fit from
0156      going into a completely unphysical region.
0157    */
0158     double _e_com;
0159 
0160     /**
0161      If TRUE and the event does not have a neutrino, then the fit
0162      will be done without the overall transverse momentum constraint.
0163      Thus the missing transverse energy information will be ignored.
0164      If the event does have a neutrino, this parameter is ignored.
0165      If FALSE, take into account the overall transverse momentum constraint.
0166    */
0167     bool _ignore_met;
0168 
0169     /**
0170      The internal arguments for the subobjects.
0171    */
0172     Chisq_Constrainer_Args _chisq_constrainer_args;
0173   };
0174 
0175   //*************************************************************************
0176 
0177   /**
0178     @class Fourvec_Constrainer
0179 
0180     @brief Do a kinematic fit for a set of four-momenta, given a set
0181     of mass constraints.
0182 
0183     The input is in a Fourvec_Event instance.  This consists of a collection
0184     of objects, each of which has a four-momentum, an uncertainty on the
0185     four-momentum, and an integer label.
0186 
0187     There are also a set of mass constraints, based on sums of objects
0188     with specified labels.  A constraint can either require that the invariant
0189     mass of a set of objects is constant, or that the mass of two sets of
0190     objects be equal to each other.  For example, the constraint
0191 
0192     \f[ (1~~2) = 80 \f]
0193 
0194     says that the sum of all objects with labels 1 and 2 should have a mass
0195     of 80, where the unit of mass is always in GeV.  And the constraint
0196 
0197     \f[ (1~~2) = (3~~4) \f]
0198 
0199     says that the sum of all objects with labels 1 and 2 should have an
0200     invariant mass equal as the invariant mass of the sum of all objects with
0201     label 3 and 4.
0202 
0203     All the objects are fixed to constant masses for the fit.  These masses
0204     are attributes of the objects in the Fourvec_Event.  This is done by
0205     scaling either the four-momentum's three-momentum or energy,
0206     depending on the setting of the <i>use_e</i> parameter.
0207 
0208     If there is no neutrino present in the event, two additional
0209     constraints are automatically added for total \f$p_{T}\f$ balance, unless
0210     the parameter <i>ignore_met</i> has been set to TRUE.
0211 
0212     When the fit completes, this object can  compute an invariant mass out
0213     of some combination of the objects, including and uncertainty.
0214     The particular combination is specified through the method
0215     mass_constraint((); it gets a constraint string like normal with
0216     the LHS of the constraint i s the mass which will be calculater, and
0217     the RHS of the oncstrant should be zero.
0218 
0219  */
0220   class Fourvec_Constrainer
0221   //
0222   // Purpose: Do a kinematic fit for a set of 4-vectors, given a set
0223   //          of mass constraints.
0224   //
0225   {
0226   public:
0227     // Constructor.
0228     // ARGS holds the parameter settings for this instance.
0229     /**
0230      @brief Constructor.
0231 
0232      @param args Parameter settings for this instance.
0233    */
0234     Fourvec_Constrainer(const Fourvec_Constrainer_Args& args);
0235 
0236     // Specify an additional constraint S for the problem.
0237     // The format for S is described above.
0238     /**
0239      @brief Specify an additional constraint <i>s</i> for the problem.
0240      The format for <i>s</i> is described in the class description.
0241 
0242      @param s The constraint to add.
0243    */
0244     void add_constraint(std::string s);
0245 
0246     // Specify the combination of objects that will be returned by
0247     // constrain() as the mass.  The format of S is the same as for
0248     // normal constraints.  The LHS specifies the mass to calculate;
0249     // the RHS should be zero.
0250     // This should only be called once.
0251     /**
0252      @brief Specify a combination of objects that will be returned
0253      by the constrain() method as mass.  The format of <i>s</i>
0254      is the same as for normal constraints.  The left-hand side specifies
0255      the mass to calculate, the right-hand side should be zero.
0256      This combination of objects will be called only once.
0257 
0258      @param s The constraint defining the mass.
0259    */
0260     void mass_constraint(std::string s);
0261 
0262     // Do a constrained fit for EV.  Returns the requested mass and
0263     // its error in M and SIGM, and the pull quantities in PULLX and
0264     // PULLY.  Returns the chisq; this will be < 0 if the fit failed
0265     // to converge.
0266     /**
0267      @brief Do a constrained fit for event <i>ev</i>.  Returns the requested
0268      mass and its uncertainty in <i>m</i> and <i>sigm</i>, and the pull
0269      quantities in <i>pullx</i> and <i>pully</i>.  Returns the \f$\chi^{2}\f$,
0270      the value will be negative if the fit failed to converge.
0271 
0272      @param ev The event to be fitted (input), and later after fitting
0273      (output).
0274 
0275      @param m The requested invariant mass to calculate.
0276 
0277      @param sigm The uncertainty in the requested invariant mass.
0278 
0279      @param pullx Pull quantities for well-measured variables.
0280 
0281      @param pully Pull quantities for poorly-measured variables.
0282 
0283      @par Input:
0284      - <i>ev</i> (before fit).
0285 
0286      @par Output:
0287      - <i>ev</i> (after fit).
0288      - <i>m</i>.
0289      - <i>sigm</i>.
0290      - <i>pullx</i>
0291      - <i>pully</i>.
0292      @par Returns:
0293      The fit \f$\chi^{2}\f$, this value will be negative if the fit failed
0294      to converge.
0295    */
0296     double constrain(Fourvec_Event& ev, double& m, double& sigm, Column_Vector& pullx, Column_Vector& pully);
0297 
0298     // Dump the internal state.
0299     friend std::ostream& operator<<(std::ostream& s, const Fourvec_Constrainer& c);
0300 
0301   private:
0302     // Parameter settings.
0303     /**
0304      Parameter settings for this instance.
0305    */
0306     const Fourvec_Constrainer_Args _args;
0307 
0308     // The constraints for this problem.
0309     /**
0310      The constraints for this problem.
0311    */
0312     std::vector<Constraint> _constraints;
0313 
0314     // The constraint giving the mass to be calculated.  This
0315     // should have no more than one entry.
0316     /**
0317       The constraint giving the mass to be calculated.  This should
0318       have no more than one entry.
0319    */
0320     std::vector<Constraint> _mass_constraint;
0321   };
0322 
0323 }  // namespace hitfit
0324 
0325 #endif  // not HITFIT_FOURVEC_CONSTRAINER_H