CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
12 
37 #include <iostream>
38 #include <cassert>
39 
40 
41 using std::auto_ptr;
42 using std::ostream;
43 using std::string;
44 
45 namespace hitfit {
46 
47 
49 //
50 // Purpose: Copy constructor.
51 //
52 // Inputs:
53 // c - The instance to copy.
54 //
55  : _lhs (c._lhs->clone ()),
56  _rhs (c._rhs->clone ())
57 {
58 }
59 
60 
62 //
63 // Purpose: Assignment.
64 //
65 // Inputs:
66 // c - The instance to copy.
67 //
68 // Returns:
69 // This instance.
70 //
71 {
72  {
73  auto_ptr<Constraint_Intermed> ci = c._lhs->clone ();
74  _lhs = ci;
75  }
76  {
77  auto_ptr<Constraint_Intermed> ci = c._rhs->clone ();
78  _rhs = ci;
79  }
80 
81  return *this;
82 }
83 
84 
86 //
87 // Purpose: Constructor.
88 // Build a constraint from the string describing it.
89 //
90 // Inputs:
91 // s - The string describing the constraint.
92 //
93 {
94  // Split it at the equals sign.
95  string::size_type i = s.find ('=');
96  assert (i != string::npos);
97 
98  // And then build the two halves.
99  {
100  auto_ptr<Constraint_Intermed> ci =
101  make_constraint_intermed (s.substr (0, i));
102  _lhs = ci;
103  }
104  {
105  auto_ptr<Constraint_Intermed> ci =
106  make_constraint_intermed (s.substr (i+1));
107  _rhs = ci;
108  }
109 }
110 
111 
112 int Constraint::has_labels (int ilabel, int jlabel) const
113 //
114 // Purpose: See if this guy references both labels ILABEL and JLABEL
115 // on a single side of the constraint equation.
116 //
117 // Inputs:
118 // ilabel - The first label to test.
119 // jlabel - The second label to test.
120 //
121 // Returns:
122 // +1 if the LHS references both.
123 // -1 if the RHS references both.
124 // 0 if neither reference both.
125 //
126 {
127  if (_lhs->has_labels (ilabel, jlabel))
128  return 1;
129  else if (_rhs->has_labels (ilabel, jlabel))
130  return -1;
131  else
132  return 0;
133 }
134 
135 
137 //
138 // Purpose: Evaluate the mass constraint, using the data in EV.
139 // Return m(lhs)^2/2 - m(rhs)^2/2.
140 //
141 // Inputs:
142 // ev - The event for which the constraint should be evaluated.
143 //
144 // Returns:
145 // m(lhs)^2/2 - m(rhs)^2/2.
146 //
147 {
148  return _lhs->sum_mass_terms (ev) - _rhs->sum_mass_terms (ev);
149 }
150 
151 
162 std::ostream& operator<< (std::ostream& s, const Constraint& c)
163 //
164 // Purpose: Print the object to S.
165 //
166 // Inputs:
167 // s - The stream to which to write.
168 // c - The object to write.
169 //
170 // Returns:
171 // The stream S.
172 //
173 {
174  s << *c._lhs.get() << " = " << *c._rhs.get();
175  return s;
176 }
177 
178 
179 } // namespace hitfit
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< Constraint_Intermed > _rhs
Definition: Constraint.h:160
Represent a mass constraint equation. Mass constraints come in two varieties, either saying that the ...
Definition: Constraint.h:79
std::auto_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::auto_ptr< Constraint_Intermed > _lhs
Definition: Constraint.h:155
bool ev
double sum_mass_terms(const Fourvec_Event &ev) const
Definition: Constraint.cc:136
uint16_t size_type
Constraint(std::string s)
Definition: Constraint.cc:85
Constraint & operator=(const Constraint &c)
Definition: Constraint.cc:61
Represent a mass constraint equation.
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...
int has_labels(int ilabel, int jlabel) const
Definition: Constraint.cc:112
Represent one side of a mass constraint equation. Contains the abstract base class Constraint_Interme...