CMS 3D CMS Logo

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 
12 
38 #include <ostream>
39 
40 
41 using std::vector;
42 using std::ostream;
43 
44 
45 namespace hitfit {
46 
47 
48 Pair_Table::Pair_Table (const std::vector<Constraint>& cv,
49  const Fourvec_Event& ev)
50 //
51 // Purpose: Constructor.
52 //
53 // Inputs:
54 // cv - The list of constraints for the problem.
55 // ev - The event.
56 //
57 {
58  // The number of objects in the event, including any neutrino.
59  int nobjs = ev.nobjs_all();
60 
61  // Number of constraints.
62  int nc = cv.size();
63 
64  // Loop over pairs of objects.
65  for (int i=0; i < nobjs-1; i++)
66  for (int j=i+1; j < nobjs; j++) {
67  // Make an Objpair instance out of it.
68  Objpair p (i, j, nc);
69 
70  // Loop over constraints.
71  bool wanted = false;
72  for (int k=0; k < nc; k++) {
73  int val = cv[k].has_labels (ev.obj (i).label, ev.obj (j).label);
74  if (val) {
75  // This pair is used by this constraint. Record it.
76  p.has_constraint (k, val);
77  wanted = true;
78  }
79  }
80 
81  // Was this pair used by any constraint?
82  if (wanted)
83  _pairs.push_back (p);
84  }
85 }
86 
87 
88 int Pair_Table::npairs () const
89 //
90 // Purpose: Return the number of pairs in the table.
91 //
92 // Returns:
93 // The number of pairs in the table.
94 //
95 {
96  return _pairs.size();
97 }
98 
99 
101 //
102 // Purpose: Return one pair from the table.
103 //
104 // Inputs:
105 // pairno - The number of the pair (0-based).
106 //
107 // Returns:
108 // Pair PAIRNO.
109 //
110 {
111  assert (pairno < _pairs.size());
112  return _pairs[pairno];
113 }
114 
123 std::ostream& operator<< (std::ostream& s, const Pair_Table& p)
124 //
125 // Purpose: Print the object to S.
126 //
127 // Inputs:
128 // s - The stream to which to write.
129 // p - The object to write.
130 //
131 // Returns:
132 // The stream S.
133 //
134 {
135  for (int i=0; i < p.npairs(); i++)
136  s << " " << p.get_pair (i) << "\n";
137  return s;
138 }
139 
140 
141 } // 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:100
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:88
bool ev
cv
Definition: cuy.py:362
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:63
std::vector< Objpair > _pairs
Definition: Pair_Table.h:137
int nobjs_all() const
Return the number of objects in the event including any neutrinos.
int k[5][pyjets_maxn]
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream...
A lookup table to speed up constraint evaluation using Fourvec_Constrainer.
Definition: Pair_Table.h:99
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:48
A lookup table to speed up constraint evaluation.
Represent a pair of objects in Pair_Table.
Definition: Objpair.h:62
Represent an event for kinematic fitting as a collection of four-momenta.