Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:16

0001 //
0002 //
0003 // File: Constrained_Z.cc
0004 // Purpose: Do kinematic fitting for a (Z->ll)+jets event.
0005 // Created: Apr, 2004, sss
0006 //
0007 // CMSSW File      : src/Constrained_Z.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 Constrained_Z.cc
0014 
0015     @brief Do a constrained kinematic fit of a
0016     \f$Z\to\ell^{+}\ell^{-}+\rm{jets}\f$ event.
0017     See the documentation for the header file Constrained_Z.h for details.
0018 
0019     @par Creation date:
0020     July 2000.
0021 
0022     @author
0023     Scott Stuart Snyder <snyder@bnl.gov>.
0024 
0025     @par Modification History:
0026     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0027     Imported to CMSSW.<br>
0028     Oct 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0029     Added Doxygen tags for automatic generation of documentation.
0030 
0031     @par Terms of Usage:
0032     With consent from the original author (Scott Snyder).
0033 
0034  */
0035 
0036 #include "TopQuarkAnalysis/TopHitFit/interface/Constrained_Z.h"
0037 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
0038 #include "TopQuarkAnalysis/TopHitFit/interface/Lepjets_Event.h"
0039 #include "TopQuarkAnalysis/TopHitFit/interface/Defaults.h"
0040 #include <ostream>
0041 #include <cassert>
0042 #include <cstdio>
0043 
0044 namespace hitfit {
0045 
0046   //*************************************************************************
0047   // Argument handling.
0048   //
0049 
0050   Constrained_Z_Args::Constrained_Z_Args(const Defaults& defs)
0051       //
0052       // Purpose: Constructor.
0053       //
0054       // Inputs:
0055       //   defs -        The Defaults instance from which to initialize.
0056       //
0057       : _zmass(defs.get_float("zmass")), _fourvec_constrainer_args(defs) {}
0058 
0059   double Constrained_Z_Args::zmass() const
0060   //
0061   // Purpose: Return the zmass parameter.
0062   //          See the header for documentation.
0063   //
0064   {
0065     return _zmass;
0066   }
0067 
0068   const Fourvec_Constrainer_Args& Constrained_Z_Args::fourvec_constrainer_args() const
0069   //
0070   // Purpose: Return the contained subobject parameters.
0071   //
0072   {
0073     return _fourvec_constrainer_args;
0074   }
0075 
0076   //*************************************************************************
0077 
0078   Constrained_Z::Constrained_Z(const Constrained_Z_Args& args)
0079       //
0080       // Purpose: Constructor.
0081       //
0082       // Inputs:
0083       //   args -        The parameter settings for this instance.
0084       //
0085       : _args(args), _constrainer(args.fourvec_constrainer_args()) {
0086     char buf[256];
0087     sprintf(buf, "(%d) = %f", lepton_label, _args.zmass());
0088     _constrainer.add_constraint(buf);
0089   }
0090 
0091   namespace {
0092 
0093     /**
0094 
0095     @brief Helper function to create an object to put into Fourvec_Event.
0096 
0097     @param obj The input object.
0098 
0099     @param mass The mass to which it should be constrained.
0100 
0101     @param type The type to assign to it.
0102 
0103     @par Return:
0104     The constructed <i>FE_Obj</i>.
0105 
0106  */
0107     FE_Obj make_fe_obj(const Lepjets_Event_Lep& obj, double mass, int type)
0108     //
0109     // Purpose: Helper to create an object to put into the Fourvec_Event.
0110     //
0111     // Inputs:
0112     //   obj -         The input object.
0113     //   mass -        The mass to which it should be constrained.
0114     //   type -        The type to assign it.
0115     //
0116     // Returns:
0117     //   The constructed FE_Obj.
0118     //
0119     {
0120       return FE_Obj(obj.p(), mass, type, obj.p_sigma(), obj.eta_sigma(), obj.phi_sigma(), obj.res().p_res().inverse());
0121     }
0122 
0123     /**
0124 
0125     @brief Convert from a Lepjets_Event to a Fourvec_Event.
0126 
0127     @param ev The input event.
0128 
0129     @param fe The output Fourvec_Event.
0130 
0131     @par Input:
0132     - Lepjets_Event <i>ev</i>.
0133 
0134     @par Output:
0135     - Fourvec_Event <i>fe</i>.
0136 
0137  */
0138     void do_import(const Lepjets_Event& ev, Fourvec_Event& fe)
0139     //
0140     // Purpose: Convert from a Lepjets_Event to a Fourvec_Event.
0141     //
0142     // Inputs:
0143     //   ev -          The input event.
0144     //
0145     // Outputs:
0146     //   fe -          The initialized Fourvec_Event.
0147     //
0148     {
0149       assert(ev.nleps() >= 2);
0150       fe.add(make_fe_obj(ev.lep(0), 0, lepton_label));
0151       fe.add(make_fe_obj(ev.lep(1), 0, lepton_label));
0152 
0153       for (std::vector<Lepjets_Event_Jet>::size_type j = 0; j < ev.njets(); j++)
0154         fe.add(make_fe_obj(ev.jet(j), 0, isr_label));
0155 
0156       Fourvec kt = ev.kt();
0157       fe.set_kt_error(ev.kt_res().sigma(kt.x()), ev.kt_res().sigma(kt.y()), 0);
0158       fe.set_x_p(ev.met());
0159     }
0160 
0161     /**
0162 
0163     @brief Convert from a Fourvec_Event to a Lepjets_Event.
0164 
0165     @param fe The input event.
0166 
0167     @param ev The returned Lepjets_Event.
0168 
0169     @par Input:
0170     - Fourvec_Event <i>fe</i>.
0171     - Lepjets_Event <i>ev</i>.
0172 
0173     @par Output:
0174     - Lepjets_Event <i>ev</i>
0175 
0176  */
0177     void do_export(const Fourvec_Event& fe, Lepjets_Event& ev)
0178     //
0179     // Purpose: Convert from a Fourvec_Event to a Lepjets_Event.
0180     //
0181     // Inputs:
0182     //   fe -          The input event.
0183     //   ev -          The original Lepjets_Event.
0184     //
0185     // Outputs:
0186     //   ev -          The updated Lepjets_Event.
0187     //
0188     {
0189       ev.lep(0).p() = fe.obj(0).p;
0190       ev.lep(1).p() = fe.obj(1).p;
0191 
0192       for (std::vector<Lepjets_Event_Jet>::size_type j = 0, k = 1; j < ev.njets(); j++)
0193         ev.jet(j).p() = fe.obj(k++).p;
0194 
0195       Fourvec nu;
0196       ev.met() = nu;
0197     }
0198 
0199   }  // unnamed namespace
0200 
0201   double Constrained_Z::constrain(Lepjets_Event& ev, Column_Vector& pull)
0202   //
0203   // Purpose: Do a constrained fit for EV.
0204   //          Returns the pull quantities in PULL.
0205   //          Returns the chisq; this will be < 0 if the fit failed
0206   //          to converge.
0207   //
0208   // Inputs:
0209   //   ev -          The event we're fitting.
0210   //
0211   // Outputs:
0212   //   ev -          The fitted event.
0213   //   pull -        Pull quantities for well-measured variables.
0214   //
0215   // Returns:
0216   //   The fit chisq, or < 0 if the fit didn't converge.
0217   //
0218   {
0219     Fourvec_Event fe;
0220     do_import(ev, fe);
0221     Column_Vector pully;
0222     double m, sigm;
0223     double chisq = _constrainer.constrain(fe, m, sigm, pull, pully);
0224     do_export(fe, ev);
0225 
0226     return chisq;
0227   }
0228 
0229   /**
0230      @brief Output stream operator, print the content of this Constrained_Z
0231      to an output stream.
0232 
0233      @param s The output stream to which to wrire.
0234      @param cz The instance of Constrained_Z to be printed.
0235    */
0236   std::ostream& operator<<(std::ostream& s, const Constrained_Z& cz)
0237   //
0238   // Purpose: Print the object to S.
0239   //
0240   // Inputs:
0241   //   s -           The stream to which to write.
0242   //   cz -          The object to write.
0243   //
0244   // Returns:
0245   //   The stream S.
0246   //
0247   {
0248     return s << cz._constrainer;
0249   }
0250 
0251 }  // namespace hitfit