Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00038 #include "TopQuarkAnalysis/TopHitFit/interface/Constraint_Intermed.h"
00039 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
00040 #include <iostream>
00041 #include <cmath>
00042 #include <algorithm>
00043 #include <cstdlib>
00044
00045
00046 using std::auto_ptr;
00047 using std::ostream;
00048 using std::sqrt;
00049 using std::stable_sort;
00050 using std::find;
00051 using std::swap;
00052 using std::string;
00053 using std::vector;
00054 #ifndef __GNUC__
00055 using std::atoi;
00056 using std::atof;
00057 #endif
00058
00059
00060 namespace hitfit {
00061
00062
00063
00064
00065
00066 Constraint_Intermed_Constant::Constraint_Intermed_Constant (double constant)
00067
00068
00069
00070
00071
00072
00073 : _c2 (constant * constant / 2)
00074 {
00075 }
00076
00077
00078 Constraint_Intermed_Constant::Constraint_Intermed_Constant
00079 (const Constraint_Intermed_Constant& c)
00080
00081
00082
00083
00084
00085
00086 : _c2 (c._c2)
00087 {
00088 }
00089
00090
00091 bool Constraint_Intermed_Constant::has_labels (int ilabel, int jlabel) const
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 {
00105 return false;
00106 }
00107
00108
00109 double
00110 Constraint_Intermed_Constant::sum_mass_terms (const Fourvec_Event&) const
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 {
00122 return _c2;
00123 }
00124
00125
00126 void Constraint_Intermed_Constant::print (std::ostream& s) const
00127
00128
00129
00130
00131
00132
00133 {
00134 s << sqrt (2 * _c2);
00135 }
00136
00137
00138 auto_ptr<Constraint_Intermed> Constraint_Intermed_Constant::clone () const
00139
00140
00141
00142
00143
00144
00145 {
00146 return auto_ptr<Constraint_Intermed>
00147 (new Constraint_Intermed_Constant (*this));
00148 }
00149
00150
00151
00152
00153
00154 Constraint_Intermed_Labels::Constraint_Intermed_Labels
00155 (const std::vector<int>& labels)
00156
00157
00158
00159
00160
00161
00162 : _labels (labels)
00163 {
00164
00165 stable_sort (_labels.begin(), _labels.end());
00166 }
00167
00168
00169 Constraint_Intermed_Labels::Constraint_Intermed_Labels
00170 (const Constraint_Intermed_Labels& c)
00171
00172
00173
00174
00175
00176
00177 : _labels (c._labels)
00178 {
00179 }
00180
00181
00182 bool Constraint_Intermed_Labels::has_labels (int ilabel, int jlabel) const
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 {
00194 if (ilabel > jlabel)
00195 swap (ilabel, jlabel);
00196
00197 unsigned sz = _labels.size();
00198 unsigned i;
00199 for (i=0; i < sz; i++) {
00200 if (_labels[i] == ilabel)
00201 break;
00202 }
00203
00204 if (i == sz)
00205 return false;
00206
00207 for (; i < sz; i++) {
00208 if (_labels[i] == jlabel)
00209 break;
00210 }
00211
00212 if (i == sz)
00213 return false;
00214
00215 return true;
00216 }
00217
00218
00219 double
00220 Constraint_Intermed_Labels::sum_mass_terms (const Fourvec_Event& ev) const
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 {
00232 int nobjs = ev.nobjs();
00233 double sum = 0;
00234 for (int i = 0; i < nobjs; i++) {
00235 const FE_Obj& o = ev.obj (i);
00236 if (has_label (o.label))
00237 sum += o.mass * o.mass / 2;
00238 }
00239
00240 return sum;
00241 }
00242
00243
00244 void Constraint_Intermed_Labels::print (std::ostream& s) const
00245
00246
00247
00248
00249
00250
00251 {
00252 s << "(";
00253 for (unsigned i = 0; i < _labels.size(); i++) {
00254 if (i > 0)
00255 s << "+";
00256 s << _labels[i];
00257 }
00258 s << ")";
00259 }
00260
00261
00262 bool Constraint_Intermed_Labels::has_label (int label) const
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 {
00273 return find (_labels.begin(), _labels.end(), label) != _labels.end();
00274 }
00275
00276
00277 auto_ptr<Constraint_Intermed> Constraint_Intermed_Labels::clone () const
00278
00279
00280
00281
00282
00283
00284 {
00285 return auto_ptr<Constraint_Intermed>
00286 (new Constraint_Intermed_Labels (*this));
00287 }
00288
00289
00290
00291
00292
00304 std::ostream& operator<< (std::ostream& s, const hitfit::Constraint_Intermed& ci)
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 {
00316 ci.print (s);
00317 return s;
00318 }
00319
00320
00321 auto_ptr<Constraint_Intermed> make_constraint_intermed (string s)
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 {
00346
00347 string::size_type i = 0;
00348 while (i < s.size() && s[i] == ' ')
00349 ++i;
00350 if (s[i] == '=')
00351 ++i;
00352 while (i < s.size() && s[i] == ' ')
00353 ++i;
00354 if (i < s.size() && s[i] == '<') {
00355 i = s.find ('>', i);
00356 if (i == string::npos)
00357 return auto_ptr<Constraint_Intermed> ();
00358 ++i;
00359 }
00360 while (i < s.size() && s[i] == ' ')
00361 ++i;
00362
00363
00364 if (i == s.size())
00365 return auto_ptr<Constraint_Intermed> ();
00366
00367 if (s[i] == '(') {
00368
00369
00370 vector<int> labels;
00371 ++i;
00372 while (i < s.size()) {
00373 while (i < s.size() && s[i] == ' ')
00374 ++i;
00375 if (i < s.size() && s[i] == ')')
00376 break;
00377 if (i < s.size())
00378 labels.push_back (atoi (s.c_str() + i));
00379 while (i < s.size() && s[i] != ' ' && s[i] != ')')
00380 ++i;
00381 }
00382 return auto_ptr<Constraint_Intermed>
00383 (new Constraint_Intermed_Labels (labels));
00384 }
00385 else {
00386
00387 return auto_ptr<Constraint_Intermed>
00388 (new Constraint_Intermed_Constant (atof (s.c_str() + i)));
00389 }
00390 }
00391
00392
00393 }
00394