Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 //
0003 // File: src/Pair_Table.cc
0004 // Purpose: Helper for Fourvec_Constrainer.
0005 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
0006 //
0007 // CMSSW File      : src/Pair_Table.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 Pair_Table.cc
0014 
0015     @brief A lookup table to speed up constraint evaluation.
0016     See the documentation for the header file Pair_Table.h for details.
0017 
0018     @author Scott Stuart Snyder <snyder@bnl.gov>
0019 
0020     @par Creation date:
0021     Jul 2000.
0022 
0023     @par Modification History:
0024     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0025     Imported to CMSSW.<br>
0026     Nov 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0027     Added doxygen tags for automatic generation of documentation.
0028 
0029     @par Terms of Usage:
0030     With consent for the original author (Scott Snyder).
0031 
0032  */
0033 
0034 #include "TopQuarkAnalysis/TopHitFit/interface/Pair_Table.h"
0035 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
0036 #include <ostream>
0037 
0038 using std::ostream;
0039 using std::vector;
0040 
0041 namespace hitfit {
0042 
0043   Pair_Table::Pair_Table(const std::vector<Constraint>& cv, const Fourvec_Event& ev)
0044   //
0045   // Purpose: Constructor.
0046   //
0047   // Inputs:
0048   //   cv -          The list of constraints for the problem.
0049   //   ev -          The event.
0050   //
0051   {
0052     // The number of objects in the event, including any neutrino.
0053     int nobjs = ev.nobjs_all();
0054 
0055     // Number of constraints.
0056     int nc = cv.size();
0057 
0058     // Loop over pairs of objects.
0059     for (int i = 0; i < nobjs - 1; i++)
0060       for (int j = i + 1; j < nobjs; j++) {
0061         // Make an Objpair instance out of it.
0062         Objpair p(i, j, nc);
0063 
0064         // Loop over constraints.
0065         bool wanted = false;
0066         for (int k = 0; k < nc; k++) {
0067           int val = cv[k].has_labels(ev.obj(i).label, ev.obj(j).label);
0068           if (val) {
0069             // This pair is used by this constraint.  Record it.
0070             p.has_constraint(k, val);
0071             wanted = true;
0072           }
0073         }
0074 
0075         // Was this pair used by any constraint?
0076         if (wanted)
0077           _pairs.push_back(p);
0078       }
0079   }
0080 
0081   int Pair_Table::npairs() const
0082   //
0083   // Purpose: Return the number of pairs in the table.
0084   //
0085   // Returns:
0086   //   The number of pairs in the table.
0087   //
0088   {
0089     return _pairs.size();
0090   }
0091 
0092   const Objpair& Pair_Table::get_pair(std::vector<Objpair>::size_type pairno) const
0093   //
0094   // Purpose: Return one pair from the table.
0095   //
0096   // Inputs:
0097   //   pairno -      The number of the pair (0-based).
0098   //
0099   // Returns:
0100   //   Pair PAIRNO.
0101   //
0102   {
0103     assert(pairno < _pairs.size());
0104     return _pairs[pairno];
0105   }
0106 
0107   /**
0108     @brief Output stream operator, print the content of this Pair_Table
0109     to an output stream.
0110 
0111     @param s The stream to which to write.
0112 
0113     @param p The instance of Pair_Table to be printed.
0114  */
0115   std::ostream& operator<<(std::ostream& s, const Pair_Table& p)
0116   //
0117   // Purpose: Print the object to S.
0118   //
0119   // Inputs:
0120   //   s -           The stream to which to write.
0121   //   p -           The object to write.
0122   //
0123   // Returns:
0124   //   The stream S.
0125   //
0126   {
0127     for (int i = 0; i < p.npairs(); i++)
0128       s << " " << p.get_pair(i) << "\n";
0129     return s;
0130   }
0131 
0132 }  // namespace hitfit