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