CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/TopQuarkAnalysis/TopHitFit/src/Constrained_Top.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Constrained_Top.cc,v 1.1 2011/05/26 09:46:59 mseidel Exp $
00003 //
00004 // File: src/Constrained_Top.cc
00005 // Purpose: Do kinematic fitting for a ttbar -> ljets event.
00006 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
00007 //
00008 // CMSSW File      : src/Constrained_Top.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 
00013 
00039 #include "TopQuarkAnalysis/TopHitFit/interface/Constrained_Top.h"
00040 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
00041 #include "TopQuarkAnalysis/TopHitFit/interface/Lepjets_Event.h"
00042 #include "TopQuarkAnalysis/TopHitFit/interface/Defaults.h"
00043 #include <ostream>
00044 #include <cassert>
00045 #include <stdio.h>
00046 
00047 
00048 using std::ostream;
00049 
00050 
00051 namespace hitfit {
00052 
00053 
00054 //*************************************************************************
00055 // Argument handling.
00056 //
00057 
00058 
00059 Constrained_Top_Args::Constrained_Top_Args (const Defaults& defs)
00060 //
00061 // Purpose: Constructor.
00062 //
00063 // Inputs:
00064 //   defs -        The Defaults instance from which to initialize.
00065 //
00066   : _bmass (defs.get_float ("bmass")),
00067     _fourvec_constrainer_args (defs),
00068     _equal_side(defs.get_bool("equal_side"))
00069 
00070 {
00071 }
00072 
00073 
00074 double Constrained_Top_Args::bmass () const
00075 //
00076 // Purpose: Return the bmass parameter.
00077 //          See the header for documentation.
00078 //
00079 {
00080   return _bmass;
00081 }
00082 
00083 
00084 const Fourvec_Constrainer_Args&
00085 Constrained_Top_Args::fourvec_constrainer_args () const
00086 //
00087 // Purpose: Return the contained subobject parameters.
00088 //
00089 {
00090   return _fourvec_constrainer_args;
00091 }
00092 
00093 
00094 bool Constrained_Top_Args::equal_side () const
00095 //
00096 // Purpose: Return the equal_side parameter
00097 //          See the header for documentation.
00098 //
00099 {
00100   return _equal_side;
00101 }
00102 
00103 
00104 //*************************************************************************
00105 
00106 
00107 Constrained_Top::Constrained_Top (const Constrained_Top_Args& args,
00108                                   double lepw_mass,
00109                                   double hadw_mass,
00110                                   double top_mass)
00111 //
00112 // Purpose: Constructor.
00113 //
00114 // Inputs:
00115 //   args -        The parameter settings for this instance.
00116 //   lepw_mass -   The mass to which the leptonic W should be constrained,
00117 //                 or 0 to skip this constraint.
00118 //   hadw_mass -   The mass to which the hadronic W should be constrained,
00119 //                 or 0 to skip this constraint.
00120 //   top_mass -    The mass to which the top quarks should be constrained,
00121 //                 or 0 to skip this constraint.
00122 //
00123   : _args (args),
00124     _constrainer (args.fourvec_constrainer_args())
00125 {
00126   char buf[256];
00127   if (lepw_mass > 0) {
00128     sprintf (buf, "(%d %d) = %f", nu_label, lepton_label, lepw_mass);
00129     _constrainer.add_constraint (buf);
00130   }
00131 
00132   if (hadw_mass > 0) {
00133     sprintf (buf, "(%d %d) = %f", hadw1_label, hadw2_label, hadw_mass);
00134     _constrainer.add_constraint (buf);
00135   }
00136 
00137   if (args.equal_side()) {
00138       sprintf (buf, "(%d %d %d) = (%d %d %d)",
00139                nu_label, lepton_label, lepb_label,
00140                hadw1_label, hadw2_label, hadb_label);
00141       _constrainer.add_constraint (buf);
00142   }
00143 
00144   if (top_mass > 0) {
00145     sprintf (buf, "(%d %d %d) = %f",
00146              hadw1_label, hadw2_label, hadb_label, top_mass);
00147     _constrainer.add_constraint (buf);
00148   }
00149   else {
00150     sprintf (buf, "(%d %d %d) = 0", hadw1_label, hadw2_label, hadb_label);
00151     _constrainer.mass_constraint (buf);
00152   }
00153 }
00154 
00155 namespace {
00156 
00157 
00172 FE_Obj make_fe_obj (const Lepjets_Event_Lep& obj, double mass, int type)
00173 //
00174 // Purpose: Helper to create an object to put into the Fourvec_Event.
00175 //
00176 // Inputs:
00177 //   obj -         The input object.
00178 //   mass -        The mass to which it should be constrained.
00179 //   type -        The type to assign it.
00180 //
00181 // Returns:
00182 //   The constructed FE_Obj.
00183 //
00184 {
00185   return FE_Obj (obj.p(), mass, type,
00186                  obj.p_sigma(), obj.eta_sigma(), obj.phi_sigma(),
00187                  obj.res().p_res().inverse());
00188 }
00189 
00190 
00209 void do_import (const Lepjets_Event& ev, double bmass, Fourvec_Event& fe)
00210 //
00211 // Purpose: Convert from a Lepjets_Event to a Fourvec_Event.
00212 //
00213 // Inputs:
00214 //   ev -          The input event.
00215 //   bmass -       The mass to which b-jets should be fixed.
00216 //
00217 // Outputs:
00218 //   fe -          The initialized Fourvec_Event.
00219 //
00220 {
00221   assert (ev.nleps() == 1);
00222   fe.add (make_fe_obj (ev.lep(0), 0, lepton_label));
00223 
00224   bool saw_lepb = false;
00225   bool saw_hadb = false;
00226   for (std::vector<Lepjets_Event_Jet>::size_type j=0; j < ev.njets(); j++) {
00227     if (ev.jet(j).type() == isr_label || ev.jet(j).type() == higgs_label)
00228       continue;
00229     double mass = 0;
00230     if (ev.jet(j).type() == lepb_label && !saw_lepb) {
00231       mass = bmass;
00232       saw_lepb = true;
00233     }
00234     else if (ev.jet(j).type() == hadb_label && !saw_hadb) {
00235       mass = bmass;
00236       saw_hadb = true;
00237     }
00238     fe.add (make_fe_obj (ev.jet(j), mass, ev.jet(j).type()));
00239   }
00240 
00241   fe.set_nu_p (ev.met());
00242   Fourvec kt = ev.kt ();
00243   fe.set_kt_error (ev.kt_res().sigma (kt.x()),
00244                    ev.kt_res().sigma (kt.y()),
00245                    0);
00246 }
00247 
00248 
00265 void do_export (const Fourvec_Event& fe, Lepjets_Event& ev)
00266 //
00267 // Purpose: Convert from a Fourvec_Event to a Lepjets_Event.
00268 //
00269 // Inputs:
00270 //   fe -          The input event.
00271 //   ev -          The original Lepjets_Event.
00272 //
00273 // Outputs:
00274 //   ev -          The updated Lepjets_Event.
00275 //
00276 {
00277   ev.lep(0).p() = fe.obj(0).p;
00278   for (std::vector<Lepjets_Event_Jet>::size_type j=0, k=1; j < ev.njets(); j++) {
00279     if (ev.jet(j).type() == isr_label || ev.jet(j).type() == higgs_label)
00280       continue;
00281     ev.jet(j).p() = fe.obj(k++).p;
00282   }
00283 
00284   ev.met() = fe.nu();
00285 }
00286 
00287 
00288 } // unnamed namespace
00289 
00290 
00291 double Constrained_Top::constrain (Lepjets_Event& ev,
00292                                    double& mt,
00293                                    double& sigmt,
00294                                    Column_Vector& pullx,
00295                                    Column_Vector& pully)
00296 //
00297 // Purpose: Do a constrained fit for EV.  Returns the top mass and
00298 //          its error in MT and SIGMT, and the pull quantities in PULLX and
00299 //          PULLY.  Returns the chisq; this will be < 0 if the fit failed
00300 //          to converge.
00301 //
00302 // Inputs:
00303 //   ev -          The event we're fitting.
00304 //
00305 // Outputs:
00306 //   ev -          The fitted event.
00307 //   mt -          Requested invariant mass.
00308 //   sigmt -       Uncertainty on mt.
00309 //   pullx -       Pull quantities for well-measured variables.
00310 //   pully -       Pull quantities for poorly-measured variables.
00311 //
00312 // Returns:
00313 //   The fit chisq, or < 0 if the fit didn't converge.
00314 //
00315 {
00316   Fourvec_Event fe;
00317   do_import (ev, _args.bmass (), fe);
00318   double chisq = _constrainer.constrain (fe, mt, sigmt, pullx, pully);
00319   do_export (fe, ev);
00320 
00321   return chisq;
00322 }
00323 
00324 
00334 std::ostream& operator<< (std::ostream& s, const Constrained_Top& ct)
00335 //
00336 // Purpose: Print the object to S.
00337 //
00338 // Inputs:
00339 //   s -           The stream to which to write.
00340 //   ct -          The object to write.
00341 //
00342 // Returns:
00343 //   The stream S.
00344 //
00345 {
00346   return s << ct._constrainer;
00347 }
00348 
00349 
00350 } // namespace hitfit