CMS 3D CMS Logo

Constraint.cc
Go to the documentation of this file.
1 //
2 //
3 // File: src/Constraint.cc
4 // Purpose: Represent a mass constraint equation.
5 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
6 //
7 // CMSSW File : src/Constraint.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 <iostream>
37 #include <cassert>
38 
39 using std::ostream;
40 using std::string;
41 using std::unique_ptr;
42 
43 namespace hitfit {
44 
46  //
47  // Purpose: Copy constructor.
48  //
49  // Inputs:
50  // c - The instance to copy.
51  //
52  : _lhs(c._lhs->clone()), _rhs(c._rhs->clone()) {}
53 
55  //
56  // Purpose: Assignment.
57  //
58  // Inputs:
59  // c - The instance to copy.
60  //
61  // Returns:
62  // This instance.
63  //
64  {
65  {
66  unique_ptr<Constraint_Intermed> ci = c._lhs->clone();
67  _lhs = std::move(ci);
68  }
69  {
70  unique_ptr<Constraint_Intermed> ci = c._rhs->clone();
71  _rhs = std::move(ci);
72  }
73 
74  return *this;
75  }
76 
78  //
79  // Purpose: Constructor.
80  // Build a constraint from the string describing it.
81  //
82  // Inputs:
83  // s - The string describing the constraint.
84  //
85  {
86  // Split it at the equals sign.
87  string::size_type i = s.find('=');
88  assert(i != string::npos);
89 
90  // And then build the two halves.
91  {
92  unique_ptr<Constraint_Intermed> ci = make_constraint_intermed(s.substr(0, i));
93  _lhs = std::move(ci);
94  }
95  {
96  unique_ptr<Constraint_Intermed> ci = make_constraint_intermed(s.substr(i + 1));
97  _rhs = std::move(ci);
98  }
99  }
100 
101  int Constraint::has_labels(int ilabel, int jlabel) const
102  //
103  // Purpose: See if this guy references both labels ILABEL and JLABEL
104  // on a single side of the constraint equation.
105  //
106  // Inputs:
107  // ilabel - The first label to test.
108  // jlabel - The second label to test.
109  //
110  // Returns:
111  // +1 if the LHS references both.
112  // -1 if the RHS references both.
113  // 0 if neither reference both.
114  //
115  {
116  if (_lhs->has_labels(ilabel, jlabel))
117  return 1;
118  else if (_rhs->has_labels(ilabel, jlabel))
119  return -1;
120  else
121  return 0;
122  }
123 
125  //
126  // Purpose: Evaluate the mass constraint, using the data in EV.
127  // Return m(lhs)^2/2 - m(rhs)^2/2.
128  //
129  // Inputs:
130  // ev - The event for which the constraint should be evaluated.
131  //
132  // Returns:
133  // m(lhs)^2/2 - m(rhs)^2/2.
134  //
135  {
136  return _lhs->sum_mass_terms(ev) - _rhs->sum_mass_terms(ev);
137  }
138 
149  std::ostream& operator<<(std::ostream& s, const Constraint& c)
150  //
151  // Purpose: Print the object to S.
152  //
153  // Inputs:
154  // s - The stream to which to write.
155  // c - The object to write.
156  //
157  // Returns:
158  // The stream S.
159  //
160  {
161  s << *c._lhs.get() << " = " << *c._rhs.get();
162  return s;
163  }
164 
165 } // namespace hitfit
Represent a mass constraint equation. Mass constraints come in two varieties, either saying that the ...
Definition: Constraint.h:73
std::unique_ptr< Constraint_Intermed > make_constraint_intermed(std::string s)
Represent an event for kinematic fitting as a collection of four-momenta. Each object is represented ...
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
assert(be >=bs)
uint16_t size_type
std::unique_ptr< Constraint_Intermed > _rhs
Definition: Constraint.h:152
Constraint(std::string s)
Definition: Constraint.cc:77
Constraint & operator=(const Constraint &c)
Definition: Constraint.cc:54
Represent a mass constraint equation.
int has_labels(int ilabel, int jlabel) const
Definition: Constraint.cc:101
double sum_mass_terms(const Fourvec_Event &ev) const
Definition: Constraint.cc:124
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream...
std::unique_ptr< Constraint_Intermed > _lhs
Definition: Constraint.h:147
Represent one side of a mass constraint equation. Contains the abstract base class Constraint_Interme...
def move(src, dest)
Definition: eostools.py:511