File indexing completed on 2024-04-06 12:31:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include "TopQuarkAnalysis/TopHitFit/interface/Constraint_Intermed.h"
0036 #include "TopQuarkAnalysis/TopHitFit/interface/Fourvec_Event.h"
0037 #include <iostream>
0038 #include <cmath>
0039 #include <algorithm>
0040 #include <cstdlib>
0041
0042 using std::find;
0043 using std::ostream;
0044 using std::sqrt;
0045 using std::stable_sort;
0046 using std::string;
0047 using std::swap;
0048 using std::unique_ptr;
0049 using std::vector;
0050 #ifndef __GNUC__
0051 using std::atof;
0052 using std::atoi;
0053 #endif
0054
0055 namespace hitfit {
0056
0057
0058
0059 Constraint_Intermed_Constant::Constraint_Intermed_Constant(double constant)
0060
0061
0062
0063
0064
0065
0066 : _c2(constant * constant / 2) {}
0067
0068 Constraint_Intermed_Constant::Constraint_Intermed_Constant(const Constraint_Intermed_Constant& c)
0069
0070
0071
0072
0073
0074
0075 : _c2(c._c2) {}
0076
0077 bool Constraint_Intermed_Constant::has_labels(int ilabel, int jlabel) const
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 {
0091 return false;
0092 }
0093
0094 double Constraint_Intermed_Constant::sum_mass_terms(const Fourvec_Event& ) const
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 {
0106 return _c2;
0107 }
0108
0109 void Constraint_Intermed_Constant::print(std::ostream& s) const
0110
0111
0112
0113
0114
0115
0116 {
0117 s << sqrt(2 * _c2);
0118 }
0119
0120 unique_ptr<Constraint_Intermed> Constraint_Intermed_Constant::clone() const
0121
0122
0123
0124
0125
0126
0127 {
0128 return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Constant(*this));
0129 }
0130
0131
0132
0133 Constraint_Intermed_Labels::Constraint_Intermed_Labels(const std::vector<int>& labels)
0134
0135
0136
0137
0138
0139
0140 : _labels(labels) {
0141
0142 stable_sort(_labels.begin(), _labels.end());
0143 }
0144
0145 Constraint_Intermed_Labels::Constraint_Intermed_Labels(const Constraint_Intermed_Labels& c)
0146
0147
0148
0149
0150
0151
0152 : _labels(c._labels) {}
0153
0154 bool Constraint_Intermed_Labels::has_labels(int ilabel, int jlabel) const
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 {
0166 if (ilabel > jlabel)
0167 swap(ilabel, jlabel);
0168
0169 unsigned sz = _labels.size();
0170 unsigned i;
0171 for (i = 0; i < sz; i++) {
0172 if (_labels[i] == ilabel)
0173 break;
0174 }
0175
0176 if (i == sz)
0177 return false;
0178
0179 for (; i < sz; i++) {
0180 if (_labels[i] == jlabel)
0181 break;
0182 }
0183
0184 if (i == sz)
0185 return false;
0186
0187 return true;
0188 }
0189
0190 double Constraint_Intermed_Labels::sum_mass_terms(const Fourvec_Event& ev) const
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 {
0202 int nobjs = ev.nobjs();
0203 double sum = 0;
0204 for (int i = 0; i < nobjs; i++) {
0205 const FE_Obj& o = ev.obj(i);
0206 if (has_label(o.label))
0207 sum += o.mass * o.mass / 2;
0208 }
0209
0210 return sum;
0211 }
0212
0213 void Constraint_Intermed_Labels::print(std::ostream& s) const
0214
0215
0216
0217
0218
0219
0220 {
0221 s << "(";
0222 for (unsigned i = 0; i < _labels.size(); i++) {
0223 if (i > 0)
0224 s << "+";
0225 s << _labels[i];
0226 }
0227 s << ")";
0228 }
0229
0230 bool Constraint_Intermed_Labels::has_label(int label) const
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 {
0241 return find(_labels.begin(), _labels.end(), label) != _labels.end();
0242 }
0243
0244 unique_ptr<Constraint_Intermed> Constraint_Intermed_Labels::clone() const
0245
0246
0247
0248
0249
0250
0251 {
0252 return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Labels(*this));
0253 }
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268 std::ostream& operator<<(std::ostream& s, const hitfit::Constraint_Intermed& ci)
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279 {
0280 ci.print(s);
0281 return s;
0282 }
0283
0284 unique_ptr<Constraint_Intermed> make_constraint_intermed(string s)
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308 {
0309
0310 string::size_type i = 0;
0311 while (i < s.size() && s[i] == ' ')
0312 ++i;
0313 if (s[i] == '=')
0314 ++i;
0315 while (i < s.size() && s[i] == ' ')
0316 ++i;
0317 if (i < s.size() && s[i] == '<') {
0318 i = s.find('>', i);
0319 if (i == string::npos)
0320 return unique_ptr<Constraint_Intermed>();
0321 ++i;
0322 }
0323 while (i < s.size() && s[i] == ' ')
0324 ++i;
0325
0326
0327 if (i == s.size())
0328 return unique_ptr<Constraint_Intermed>();
0329
0330 if (s[i] == '(') {
0331
0332
0333 vector<int> labels;
0334 ++i;
0335 while (i < s.size()) {
0336 while (i < s.size() && s[i] == ' ')
0337 ++i;
0338 if (i < s.size() && s[i] == ')')
0339 break;
0340 if (i < s.size())
0341 labels.push_back(atoi(s.c_str() + i));
0342 while (i < s.size() && s[i] != ' ' && s[i] != ')')
0343 ++i;
0344 }
0345 return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Labels(labels));
0346 } else {
0347
0348 return unique_ptr<Constraint_Intermed>(new Constraint_Intermed_Constant(atof(s.c_str() + i)));
0349 }
0350 }
0351
0352 }