CMS 3D CMS Logo

Fit_Result_Vec.cc
Go to the documentation of this file.
1 //
2 //
3 // File: src/Fit_Result_Vec.cc
4 // Purpose: Hold a set of Fit_Result structures.
5 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
6 //
7 // CMSSW File : src/Fit_Result_Vec.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 
38 #include <cassert>
39 #include <ostream>
40 #include <algorithm>
41 
42 
43 using std::ostream;
44 using std::vector;
45 using std::lower_bound;
46 
47 
48 namespace hitfit {
49 
50 
51 Fit_Result_Vec::Fit_Result_Vec (std::vector<std::shared_ptr<Fit_Result>>::size_type max_len)
52 //
53 // Purpose Constructor.
54 //
55 // Inputs:
56 // max_len - The maximum length of the vector.
57 //
58  : _max_len (max_len)
59 {
60  assert (max_len > 0);
61  _v.reserve (max_len + 1);
62 }
63 
64 
66 //
67 // Purpose: Copy constructor.
68 //
69 // Inputs:
70 // vec - The vector to copy.
71 //
72  : _v (vec._v),
73  _max_len (vec._max_len)
74 {
75 }
76 
77 
79 //
80 // Purpose: Destructor.
81 //
82 {
83 }
84 
85 
87 //
88 // Purpose: Assignment.
89 //
90 // Inputs:
91 // vec - The vector to copy.
92 //
93 // Returns:
94 // This object.
95 //
96 {
97  _v = vec._v;
98  _max_len = vec._max_len;
99  return *this;
100 }
101 
102 
103 std::vector<std::shared_ptr<Fit_Result>>::size_type Fit_Result_Vec::size () const
104 //
105 // Purpose: Get back the number of results in the vector.
106 //
107 // Returns:
108 // The number of results in the vector.
109 //
110 {
111  return _v.size ();
112 }
113 
114 
115 const Fit_Result& Fit_Result_Vec::operator[] (std::vector<std::shared_ptr<Fit_Result>>::size_type i) const
116 //
117 // Purpose: Get back the Ith result in the vector.
118 //
119 // Inputs:
120 // i - The index of the desired result.
121 //
122 // Returns:
123 // The Ith result.
124 //
125 {
126  assert (i < _v.size());
127  return *_v[i];
128 }
129 
130 
131 namespace {
132 
133 
134 struct Compare_Fitresptr
135 //
136 // Purpose: Helper for push().
137 //
138 {
139  bool operator() (std::shared_ptr<const Fit_Result> a, std::shared_ptr<const Fit_Result> b) const
140  {
141  return *a < *b;
142  }
143 };
144 
145 
146 } // unnamed namespace
147 
148 
149 void Fit_Result_Vec::push (std::shared_ptr<Fit_Result> res)
150 //
151 // Purpose: Add a new result to the vector.
152 //
153 // Inputs:
154 // res - The result to add.
155 //
156 {
157  // Find where to add it.
158  vector<std::shared_ptr<Fit_Result>>::iterator it = lower_bound (_v.begin(),
159  _v.end(),
160  res,
161  Compare_Fitresptr());
162 
163  // Insert it.
164  _v.insert (it, res);
165 
166  // Knock off the guy at the end if we've exceeded our maximum size.
167  if (_v.size() > _max_len) {
168  _v.erase (_v.end()-1);
169  }
170 }
171 
172 
181 std::ostream& operator<< (std::ostream& s, const Fit_Result_Vec& resvec)
182 //
183 // Purpose: Print the object to S.
184 //
185 // Inputs:
186 // s - The stream to which to write.
187 // resvec - The object to write.
188 //
189 // Returns:
190 // The stream S.
191 //
192 {
193  for (std::vector<std::shared_ptr<Fit_Result>>::size_type i=0; i < resvec._v.size(); i++)
194  s << "Entry " << i << "\n" << *resvec._v[i];
195  return s;
196 }
197 
198 
199 } // namespace hitfit
Hold the result of one kinematic fit.
Definition: Fit_Result.h:52
Fit_Result_Vec & operator=(const Fit_Result_Vec &vec)
Assignment operator.
~Fit_Result_Vec()
Destructor.
Hold the result of one kinematic fit.
Hold a list of pointers to a set of Fit_Result objects, resulting from different jet permutation with...
uint16_t size_type
Definition: Electron.h:6
void push(std::shared_ptr< Fit_Result > res)
Add a new Fit_Result to the list.
Fit_Result_Vec(std::vector< std::shared_ptr< Fit_Result >>::size_type max_len)
Constructor.
std::vector< std::shared_ptr< Fit_Result > > _v
double b
Definition: hdecay.h:120
Holds pointers to a set of Fit_Result objects, resulting from different jet permutation with some con...
std::vector< std::shared_ptr< Fit_Result > >::size_type size() const
Return the number of Fit_Result objects in the list.
double a
Definition: hdecay.h:121
const Fit_Result & operator[](std::vector< std::shared_ptr< Fit_Result >>::size_type i) const
Return the i-th element of the Fit_Result objects in the vector.
friend std::ostream & operator<<(std::ostream &s, const Fit_Result_Vec &resvec)
Output stream operator, print the content of this Fit_Result_Vec to an output stream.
std::vector< std::shared_ptr< Fit_Result > >::size_type _max_len