CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Pair_Table.cc
Go to the documentation of this file.
1 //
2 //
3 // File: src/Pair_Table.cc
4 // Purpose: Helper for Fourvec_Constrainer.
5 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
6 //
7 // CMSSW File : src/Pair_Table.cc
8 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
9 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
10 //
11 
36 #include <ostream>
37 
38 using std::ostream;
39 using std::vector;
40 
41 namespace hitfit {
42 
43  Pair_Table::Pair_Table(const std::vector<Constraint>& cv, const Fourvec_Event& ev)
44  //
45  // Purpose: Constructor.
46  //
47  // Inputs:
48  // cv - The list of constraints for the problem.
49  // ev - The event.
50  //
51  {
52  // The number of objects in the event, including any neutrino.
53  int nobjs = ev.nobjs_all();
54 
55  // Number of constraints.
56  int nc = cv.size();
57 
58  // Loop over pairs of objects.
59  for (int i = 0; i < nobjs - 1; i++)
60  for (int j = i + 1; j < nobjs; j++) {
61  // Make an Objpair instance out of it.
62  Objpair p(i, j, nc);
63 
64  // Loop over constraints.
65  bool wanted = false;
66  for (int k = 0; k < nc; k++) {
67  int val = cv[k].has_labels(ev.obj(i).label, ev.obj(j).label);
68  if (val) {
69  // This pair is used by this constraint. Record it.
70  p.has_constraint(k, val);
71  wanted = true;
72  }
73  }
74 
75  // Was this pair used by any constraint?
76  if (wanted)
77  _pairs.push_back(p);
78  }
79  }
80 
82  //
83  // Purpose: Return the number of pairs in the table.
84  //
85  // Returns:
86  // The number of pairs in the table.
87  //
88  {
89  return _pairs.size();
90  }
91 
93  //
94  // Purpose: Return one pair from the table.
95  //
96  // Inputs:
97  // pairno - The number of the pair (0-based).
98  //
99  // Returns:
100  // Pair PAIRNO.
101  //
102  {
103  assert(pairno < _pairs.size());
104  return _pairs[pairno];
105  }
106 
115  std::ostream& operator<<(std::ostream& s, const Pair_Table& p)
116  //
117  // Purpose: Print the object to S.
118  //
119  // Inputs:
120  // s - The stream to which to write.
121  // p - The object to write.
122  //
123  // Returns:
124  // The stream S.
125  //
126  {
127  for (int i = 0; i < p.npairs(); i++)
128  s << " " << p.get_pair(i) << "\n";
129  return s;
130  }
131 
132 } // namespace hitfit
const Objpair & get_pair(std::vector< Objpair >::size_type pairno) const
Get one of the pairs from the table, index starts from 0.
Definition: Pair_Table.cc:92
Represent an event for kinematic fitting as a collection of four-momenta. Each object is represented ...
int npairs() const
Return the number of pairs in the table.
Definition: Pair_Table.cc:81
bool ev
assert(be >=bs)
const FE_Obj & obj(std::vector< FE_Obj >::size_type i) const
Access object at index i, with the convention that the index starts at 0.
uint16_t size_type
void has_constraint(std::vector< signed char >::size_type k, int val)
Set the value for a constraint to a value.
Definition: Objpair.cc:53
std::vector< Objpair > _pairs
Definition: Pair_Table.h:131
int nobjs_all() const
Return the number of objects in the event including any neutrinos.
dictionary cv
Definition: cuy.py:363
A lookup table to speed up constraint evaluation using Fourvec_Constrainer.
Definition: Pair_Table.h:95
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream...
Pair_Table(const std::vector< Constraint > &cv, const Fourvec_Event &ev)
Constructor, give it the event and the list of constraints.
Definition: Pair_Table.cc:43
A lookup table to speed up constraint evaluation.
Represent a pair of objects in Pair_Table.
Definition: Objpair.h:58
Represent an event for kinematic fitting as a collection of four-momenta.