CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/TopQuarkAnalysis/TopHitFit/src/Pair_Table.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Pair_Table.cc,v 1.1 2011/05/26 09:47:00 mseidel Exp $
00003 //
00004 // File: src/Pair_Table.cc
00005 // Purpose: Helper for Fourvec_Constrainer.
00006 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
00007 //
00008 // CMSSW File      : src/Pair_Table.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 
00037 #include "TopQuarkAnalysis/TopHitFit/interface/Pair_Table.h"
00038 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
00039 #include <ostream>
00040 
00041 
00042 using std::vector;
00043 using std::ostream;
00044 
00045 
00046 namespace hitfit {
00047 
00048 
00049 Pair_Table::Pair_Table (const std::vector<Constraint>& cv,
00050                         const Fourvec_Event& ev)
00051 //
00052 // Purpose: Constructor.
00053 //
00054 // Inputs:
00055 //   cv -          The list of constraints for the problem.
00056 //   ev -          The event.
00057 //
00058 {
00059   // The number of objects in the event, including any neutrino.
00060   int nobjs = ev.nobjs_all();
00061 
00062   // Number of constraints.
00063   int nc = cv.size();
00064 
00065   // Loop over pairs of objects.
00066   for (int i=0; i < nobjs-1; i++)
00067     for (int j=i+1; j < nobjs; j++) {
00068       // Make an Objpair instance out of it.
00069       Objpair p (i, j, nc);
00070 
00071       // Loop over constraints.
00072       bool wanted = false;
00073       for (int k=0; k < nc; k++) {
00074         int val = cv[k].has_labels (ev.obj (i).label, ev.obj (j).label);
00075         if (val) {
00076           // This pair is used by this constraint.  Record it.
00077           p.has_constraint (k, val);
00078           wanted = true;
00079         }
00080       }
00081 
00082       // Was this pair used by any constraint?
00083       if (wanted)
00084         _pairs.push_back (p);
00085     }
00086 }
00087 
00088 
00089 int Pair_Table::npairs () const
00090 //
00091 // Purpose: Return the number of pairs in the table.
00092 //
00093 // Returns:
00094 //   The number of pairs in the table.
00095 //
00096 {
00097   return _pairs.size();
00098 }
00099 
00100 
00101 const Objpair& Pair_Table::get_pair (std::vector<Objpair>::size_type pairno) const
00102 //
00103 // Purpose: Return one pair from the table.
00104 //
00105 // Inputs:
00106 //   pairno -      The number of the pair (0-based).
00107 //
00108 // Returns:
00109 //   Pair PAIRNO.
00110 //
00111 {
00112   assert (pairno < _pairs.size());
00113   return _pairs[pairno];
00114 }
00115 
00124 std::ostream& operator<< (std::ostream& s, const Pair_Table& p)
00125 //
00126 // Purpose: Print the object to S.
00127 //
00128 // Inputs:
00129 //   s -           The stream to which to write.
00130 //   p -           The object to write.
00131 //
00132 // Returns:
00133 //   The stream S.
00134 //
00135 {
00136   for (int i=0; i < p.npairs(); i++)
00137     s << " " << p.get_pair (i) << "\n";
00138   return s;
00139 }
00140 
00141 
00142 } // namespace hitfit