CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 //
00002 // $Id: Constrained_Z.cc,v 1.1 2011/05/26 09:46:59 mseidel Exp $
00003 //
00004 // File: Constrained_Z.cc
00005 // Purpose: Do kinematic fitting for a (Z->ll)+jets event.
00006 // Created: Apr, 2004, sss
00007 //
00008 // CMSSW File      : src/Constrained_Z.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 
00038 #include "TopQuarkAnalysis/TopHitFit/interface/Constrained_Z.h"
00039 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
00040 #include "TopQuarkAnalysis/TopHitFit/interface/Lepjets_Event.h"
00041 #include "TopQuarkAnalysis/TopHitFit/interface/Defaults.h"
00042 #include <ostream>
00043 #include <cassert>
00044 #include <stdio.h>
00045 
00046 
00047 namespace hitfit {
00048 
00049 
00050 //*************************************************************************
00051 // Argument handling.
00052 //
00053 
00054 
00055 Constrained_Z_Args::Constrained_Z_Args (const Defaults& defs)
00056 //
00057 // Purpose: Constructor.
00058 //
00059 // Inputs:
00060 //   defs -        The Defaults instance from which to initialize.
00061 //
00062   : _zmass (defs.get_float ("zmass")),
00063     _fourvec_constrainer_args (defs)
00064 {
00065 }
00066 
00067 
00068 double Constrained_Z_Args::zmass () const
00069 //
00070 // Purpose: Return the zmass parameter.
00071 //          See the header for documentation.
00072 //
00073 {
00074   return _zmass;
00075 }
00076 
00077 
00078 const Fourvec_Constrainer_Args&
00079 Constrained_Z_Args::fourvec_constrainer_args () const
00080 //
00081 // Purpose: Return the contained subobject parameters.
00082 //
00083 {
00084   return _fourvec_constrainer_args;
00085 }
00086 
00087 
00088 //*************************************************************************
00089 
00090 
00091 Constrained_Z::Constrained_Z (const Constrained_Z_Args& args)
00092 //
00093 // Purpose: Constructor.
00094 //
00095 // Inputs:
00096 //   args -        The parameter settings for this instance.
00097 //   
00098   : _args (args),
00099     _constrainer (args.fourvec_constrainer_args())
00100 {
00101   char buf[256];
00102   sprintf (buf, "(%d) = %f", lepton_label, _args.zmass());
00103   _constrainer.add_constraint (buf);
00104 }
00105 
00106 
00107 namespace {
00108 
00109 
00124 FE_Obj make_fe_obj (const Lepjets_Event_Lep& obj, double mass, int type)
00125 //
00126 // Purpose: Helper to create an object to put into the Fourvec_Event.
00127 //
00128 // Inputs:
00129 //   obj -         The input object.
00130 //   mass -        The mass to which it should be constrained.
00131 //   type -        The type to assign it.
00132 //
00133 // Returns:
00134 //   The constructed FE_Obj.
00135 //
00136 {
00137   return FE_Obj (obj.p(), mass, type,
00138                  obj.p_sigma(), obj.eta_sigma(), obj.phi_sigma(),
00139                  obj.res().p_res().inverse());
00140 }
00141 
00142 
00158 void do_import (const Lepjets_Event& ev, Fourvec_Event& fe)
00159 //
00160 // Purpose: Convert from a Lepjets_Event to a Fourvec_Event.
00161 //
00162 // Inputs:
00163 //   ev -          The input event.
00164 //
00165 // Outputs:
00166 //   fe -          The initialized Fourvec_Event.
00167 //
00168 {
00169   assert (ev.nleps() >= 2);
00170   fe.add (make_fe_obj (ev.lep(0), 0, lepton_label));
00171   fe.add (make_fe_obj (ev.lep(1), 0, lepton_label));
00172 
00173   for (std::vector<Lepjets_Event_Jet>::size_type j=0; j < ev.njets(); j++)
00174     fe.add (make_fe_obj (ev.jet(j), 0, isr_label));
00175 
00176   Fourvec kt = ev.kt ();
00177   fe.set_kt_error (ev.kt_res().sigma (kt.x()),
00178                    ev.kt_res().sigma (kt.y()),
00179                    0);
00180   fe.set_x_p (ev.met());
00181 }
00182 
00183 
00200 void do_export (const Fourvec_Event& fe, Lepjets_Event& ev)
00201 //
00202 // Purpose: Convert from a Fourvec_Event to a Lepjets_Event.
00203 //
00204 // Inputs:
00205 //   fe -          The input event.
00206 //   ev -          The original Lepjets_Event.
00207 //
00208 // Outputs:
00209 //   ev -          The updated Lepjets_Event.
00210 //
00211 {
00212   ev.lep(0).p() = fe.obj(0).p;
00213   ev.lep(1).p() = fe.obj(1).p;
00214 
00215   for (std::vector<Lepjets_Event_Jet>::size_type j=0, k=1; j < ev.njets(); j++)
00216     ev.jet(j).p() = fe.obj(k++).p;
00217 
00218   Fourvec nu;
00219   ev.met() = nu;
00220 }
00221 
00222 
00223 } // unnamed namespace
00224 
00225 
00226 double Constrained_Z::constrain (Lepjets_Event& ev, Column_Vector& pull)
00227 //
00228 // Purpose: Do a constrained fit for EV.
00229 //          Returns the pull quantities in PULL.
00230 //          Returns the chisq; this will be < 0 if the fit failed
00231 //          to converge.
00232 //
00233 // Inputs:
00234 //   ev -          The event we're fitting.
00235 //
00236 // Outputs:
00237 //   ev -          The fitted event.
00238 //   pull -        Pull quantities for well-measured variables.
00239 //
00240 // Returns:
00241 //   The fit chisq, or < 0 if the fit didn't converge.
00242 //
00243 {
00244   Fourvec_Event fe;
00245   do_import (ev, fe);
00246   Column_Vector pully;
00247   double m, sigm;
00248   double chisq = _constrainer.constrain (fe, m, sigm, pull, pully);
00249   do_export (fe, ev);
00250 
00251   return chisq;
00252 }
00253 
00254 
00262 std::ostream& operator<< (std::ostream& s, const Constrained_Z& cz)
00263 //
00264 // Purpose: Print the object to S.
00265 //
00266 // Inputs:
00267 //   s -           The stream to which to write.
00268 //   cz -          The object to write.
00269 //
00270 // Returns:
00271 //   The stream S.
00272 //
00273 {
00274   return s << cz._constrainer;
00275 }
00276 
00277 
00278 } // namespace hitfit