CMS 3D CMS Logo

Constraint_Intermed.cc
Go to the documentation of this file.
1 //
2 //
3 // File: src/Constraint_Intermed.cc
4 // Purpose: Represent one side of a mass constraint equation.
5 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
6 //
7 // CMSSW File : src/Constraint_Intermed.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 
37 #include <iostream>
38 #include <cmath>
39 #include <algorithm>
40 #include <cstdlib>
41 
42 using std::find;
43 using std::ostream;
44 using std::sqrt;
45 using std::stable_sort;
46 using std::string;
47 using std::swap;
48 using std::unique_ptr;
49 using std::vector;
50 #ifndef __GNUC__
51 using std::atof;
52 using std::atoi;
53 #endif
54 
55 namespace hitfit {
56 
57  //************************************************************************
58 
60  //
61  // Purpose: Constructor.
62  //
63  // Inputs:
64  // constant - The constant in the mass constraint half.
65  //
66  : _c2(constant * constant / 2) {}
67 
69  //
70  // Purpose: Copy constructor.
71  //
72  // Inputs:
73  // c - The instance to copy.
74  //
75  : _c2(c._c2) {}
76 
77  bool Constraint_Intermed_Constant::has_labels(int ilabel, int jlabel) const
78  //
79  // Purpose: Return true if this guy references both labels ILABEL and JLABEL.
80  //
81  // This version always returns false.
82  //
83  // Inputs:
84  // ilabel - The first label to test.
85  // jlabel - The second label to test.
86  //
87  // Returns:
88  // True if this guy references both labels ILABEL and JLABEL.
89  //
90  {
91  return false;
92  }
93 
95  //
96  // Purpose: Evaluate this half of the mass constraint, using the data in EV.
97  // Return m^2/2.
98  //
99  // Inputs:
100  // ev - The event for which the constraint should be evaluated.
101  //
102  // Returns:
103  // m^2/2.
104  //
105  {
106  return _c2;
107  }
108 
109  void Constraint_Intermed_Constant::print(std::ostream& s) const
110  //
111  // Purpose: Print out this object.
112  //
113  // Inputs:
114  // s - The stream to which we should write.
115  //
116  {
117  s << sqrt(2 * _c2);
118  }
119 
120  unique_ptr<Constraint_Intermed> Constraint_Intermed_Constant::clone() const
121  //
122  // Purpose: Copy this object.
123  //
124  // Returns:
125  // A new copy of this object.
126  //
127  {
128  return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Constant(*this));
129  }
130 
131  //************************************************************************
132 
134  //
135  // Purpose: Constructor.
136  //
137  // Inputs:
138  // labels - The labels used by this half-constraint.
139  //
140  : _labels(labels) {
141  // Sort them.
142  stable_sort(_labels.begin(), _labels.end());
143  }
144 
146  //
147  // Purpose: Copy constructor.
148  //
149  // Inputs:
150  // c - The instance to copy.
151  //
152  : _labels(c._labels) {}
153 
154  bool Constraint_Intermed_Labels::has_labels(int ilabel, int jlabel) const
155  //
156  // Purpose: Return true if this guy references both labels ILABEL and JLABEL.
157  //
158  // Inputs:
159  // ilabel - The first label to test.
160  // jlabel - The second label to test.
161  //
162  // Returns:
163  // True if this guy references both labels ILABEL and JLABEL.
164  //
165  {
166  if (ilabel > jlabel)
167  swap(ilabel, jlabel);
168 
169  unsigned sz = _labels.size();
170  unsigned i;
171  for (i = 0; i < sz; i++) {
172  if (_labels[i] == ilabel)
173  break;
174  }
175 
176  if (i == sz)
177  return false;
178 
179  for (; i < sz; i++) {
180  if (_labels[i] == jlabel)
181  break;
182  }
183 
184  if (i == sz)
185  return false;
186 
187  return true;
188  }
189 
191  //
192  // Purpose: Evaluate this half of the mass constraint, using the data in EV.
193  // Return m^2/2.
194  //
195  // Inputs:
196  // ev - The event for which the constraint should be evaluated.
197  //
198  // Returns:
199  // m^2/2.
200  //
201  {
202  int nobjs = ev.nobjs();
203  double sum = 0;
204  for (int i = 0; i < nobjs; i++) {
205  const FE_Obj& o = ev.obj(i);
206  if (has_label(o.label))
207  sum += o.mass * o.mass / 2;
208  }
209 
210  return sum;
211  }
212 
213  void Constraint_Intermed_Labels::print(std::ostream& s) const
214  //
215  // Purpose: Print out this object.
216  //
217  // Inputs:
218  // s - The stream to which we should write.
219  //
220  {
221  s << "(";
222  for (unsigned i = 0; i < _labels.size(); i++) {
223  if (i > 0)
224  s << "+";
225  s << _labels[i];
226  }
227  s << ")";
228  }
229 
231  //
232  // Purpose: Helper function: Test to see if we use label LABEL.
233  //
234  // Inputs:
235  // label - THe label for which to search.
236  //
237  // Returns:
238  // True if we use label LABEL.
239  //
240  {
241  return find(_labels.begin(), _labels.end(), label) != _labels.end();
242  }
243 
244  unique_ptr<Constraint_Intermed> Constraint_Intermed_Labels::clone() const
245  //
246  // Purpose: Copy this object.
247  //
248  // Returns:
249  // A new copy of this object.
250  //
251  {
252  return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Labels(*this));
253  }
254 
255  //************************************************************************
256 
268  std::ostream& operator<<(std::ostream& s, const hitfit::Constraint_Intermed& ci)
269  //
270  // Purpose: Print the object to S.
271  //
272  // Inputs:
273  // s - The stream to which to write.
274  // ci - The object to write.
275  //
276  // Returns:
277  // The stream S.
278  //
279  {
280  ci.print(s);
281  return s;
282  }
283 
284  unique_ptr<Constraint_Intermed> make_constraint_intermed(string s)
285  //
286  // Purpose: Parse the string S and return an appropriate
287  // Constraint_Intermed instance.
288  // Returns null if we can't interpret the string.
289  //
290  // The string should either be a numeric constant like
291  //
292  // 80.2
293  //
294  // or a list of integers in parens, like
295  //
296  // (1 4 2)
297  //
298  // Leading spaces are ignored, as is text in a leading < >
299  // construction.
300  //
301  // Inputs:
302  // s - The string to parse.
303  //
304  // Returns:
305  // A new Constraint_Intermed instance, or null if we couldn't
306  // interpret the string.
307  //
308  {
309  // Skip leading spaces, `=', '< ... >'.
310  string::size_type i = 0;
311  while (i < s.size() && s[i] == ' ')
312  ++i;
313  if (s[i] == '=')
314  ++i;
315  while (i < s.size() && s[i] == ' ')
316  ++i;
317  if (i < s.size() && s[i] == '<') {
318  i = s.find('>', i);
319  if (i == string::npos)
320  return unique_ptr<Constraint_Intermed>();
321  ++i;
322  }
323  while (i < s.size() && s[i] == ' ')
324  ++i;
325 
326  // Fail if there's nothing left.
327  if (i == s.size())
328  return unique_ptr<Constraint_Intermed>();
329 
330  if (s[i] == '(') {
331  // List of labels.
332  // Make a Constraint_Intermed_Labels instance.
333  vector<int> labels;
334  ++i;
335  while (i < s.size()) {
336  while (i < s.size() && s[i] == ' ')
337  ++i;
338  if (i < s.size() && s[i] == ')')
339  break;
340  if (i < s.size())
341  labels.push_back(atoi(s.c_str() + i));
342  while (i < s.size() && s[i] != ' ' && s[i] != ')')
343  ++i;
344  }
345  return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Labels(labels));
346  } else {
347  // Make a Constraint_Intermed_Constant instance.
348  return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Constant(atof(s.c_str() + i)));
349  }
350  }
351 
352 } // namespace hitfit
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
mps_fire.i
i
Definition: mps_fire.py:355
hitfit
Definition: Base_Constrainer.h:43
Fourvec_Event.h
Represent an event for kinematic fitting as a collection of four-momenta.
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
hitfit::Constraint_Intermed_Labels::Constraint_Intermed_Labels
Constraint_Intermed_Labels(const std::vector< int > &labels)
Definition: Constraint_Intermed.cc:133
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
watchdog.const
const
Definition: watchdog.py:83
hitfit::Constraint_Intermed_Labels::has_label
bool has_label(int label) const
Definition: Constraint_Intermed.cc:230
hitfit::Constraint_Intermed_Constant::print
void print(std::ostream &s) const override
Definition: Constraint_Intermed.cc:109
hitfit::Fourvec_Event
Represent an event for kinematic fitting as a collection of four-momenta. Each object is represented ...
Definition: Fourvec_Event.h:193
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
hitfit::FE_Obj
Represent a single object in a Fourvec_Event, this is just a dumb data container. Each object in a Fo...
Definition: Fourvec_Event.h:90
hitfit::Constraint_Intermed_Constant::sum_mass_terms
double sum_mass_terms(const Fourvec_Event &ev) const override
Definition: Constraint_Intermed.cc:94
alignCSCRings.s
s
Definition: alignCSCRings.py:92
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
hitfit::Constraint_Intermed_Constant::Constraint_Intermed_Constant
Constraint_Intermed_Constant(double constant)
Definition: Constraint_Intermed.cc:59
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
hitfit::make_constraint_intermed
std::unique_ptr< Constraint_Intermed > make_constraint_intermed(std::string s)
hitfit::Constraint_Intermed_Constant::has_labels
bool has_labels(int ilabel, int jlabel) const override
Definition: Constraint_Intermed.cc:77
hitfit::operator<<
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream.
Definition: Constraint_Intermed.cc:268
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
hitfit::Constraint_Intermed_Labels::sum_mass_terms
double sum_mass_terms(const Fourvec_Event &ev) const override
Definition: Constraint_Intermed.cc:190
hitfit::Constraint_Intermed_Labels::clone
std::unique_ptr< Constraint_Intermed > clone() const override
Definition: Constraint_Intermed.cc:244
hitfit::Constraint_Intermed_Labels::print
void print(std::ostream &s) const override
Definition: Constraint_Intermed.cc:213
hitfit::Constraint_Intermed_Labels
Concrete class for one side of mass constraint equation of the type: .
Definition: Constraint_Intermed.h:245
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
Constraint_Intermed.h
Represent one side of a mass constraint equation. Contains the abstract base class Constraint_Interme...
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
hitfit::Constraint_Intermed_Constant::clone
std::unique_ptr< Constraint_Intermed > clone() const override
Definition: Constraint_Intermed.cc:120
hitfit::Constraint_Intermed_Constant
Concrete class for one side of mass constraint equation of the type: .
Definition: Constraint_Intermed.h:158
hitfit::Constraint_Intermed
Abstract base classes for describing one side of a mass constraint.
Definition: Constraint_Intermed.h:89
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
hitfit::Constraint_Intermed::print
virtual void print(std::ostream &s) const =0
hitfit::Constraint_Intermed_Labels::has_labels
bool has_labels(int ilabel, int jlabel) const override
Definition: Constraint_Intermed.cc:154
hitfit::Constraint_Intermed_Labels::_labels
std::vector< int > _labels
Definition: Constraint_Intermed.h:321
label
const char * label
Definition: PFTauDecayModeTools.cc:11