CMS 3D CMS Logo

imath_calculate.cc
Go to the documentation of this file.
3 
4 using namespace trklet;
5 
7  bool ok1 = true;
8  bool ok2 = true;
9  bool ok3 = true;
10 
11  if (p1_)
12  ok1 = p1_->calculate(debug_level);
13  if (p2_)
14  ok2 = p2_->calculate(debug_level);
15  if (p3_)
16  ok3 = p3_->calculate(debug_level);
17 
18  long int ival_prev = ival_;
20 
21  bool all_ok = ok1 && ok2 && ok3 && debug_level;
22 
23  if (fval_ > maxval_)
24  maxval_ = fval_;
25  if (fval_ < minval_)
26  minval_ = fval_;
27 #ifdef IMATH_ROOT
28  if (globals_->use_root) {
29  if (h_ == 0) {
30  globals_->h_file_->cd();
31  std::string hname = "h_" + name_;
32  h_ = (TH2F *)globals_->h_file_->Get(hname.c_str());
33  if (h_ == 0) {
34  h_precision_ = 0.5 * h_nbins_ * K_;
35  std::string st = name_ + ";fval;fval-ival*K";
36  h_ = new TH2F(hname.c_str(), name_.c_str(), h_nbins_, -range(), range(), h_nbins_, -h_precision_, h_precision_);
37  if (debug_level == 3)
38  edm::LogVerbatim("Tracklet") << " booking histogram " << hname;
39  }
40  }
41  if (ival_ != ival_prev || op_ == "def" || op_ == "const")
42  h_->Fill(fval_, K_ * ival_ - fval_);
43  }
44 #endif
45 
46  bool todump = false;
47  int nmax = sizeof(long int) * 8;
48  int ns = nmax - nbits_;
49  long int itest = ival_;
50  itest = itest << ns;
51  itest = itest >> ns;
52  if (itest != ival_) {
53  if (debug_level == 3 || (ival_ != ival_prev && all_ok)) {
54  edm::LogVerbatim("Tracklet") << "imath: truncated value mismatch!! " << ival_ << " != " << itest;
55  todump = true;
56  }
57  all_ok = false;
58  }
59 
60  val_ = ival_ * K_;
61  float ftest = val_;
62  float tolerance = 0.1 * std::abs(fval_);
63  if (tolerance < 2 * K_)
64  tolerance = 2 * K_;
65  if (std::abs(ftest - fval_) > tolerance) {
66  if (debug_level == 3 || (ival_ != ival_prev && (all_ok && (op_ != "inv" || debug_level >= 2)))) {
67  edm::LogVerbatim("Tracklet") << "imath: **GROSS** value mismatch!! " << fval_ << " != " << ftest;
68  if (op_ == "inv")
69  edm::LogVerbatim("Tracklet") << p1_->dump() << "\n-----------------------------------";
70  todump = true;
71  }
72  all_ok = false;
73  }
74 
75  if (todump)
76  edm::LogVerbatim("Tracklet") << dump();
77 
78  return all_ok;
79 }
80 
82  int max_step = 0;
83  for (const auto &cut : cuts_) {
84  if (!cut->cut_var())
85  continue;
86  if (cut->cut_var()->latency() + cut->cut_var()->step() > max_step)
87  max_step = cut->cut_var()->latency() + cut->cut_var()->step();
88  }
89  step_ = max_step;
90 }
91 
92 //
93 // local calculations
94 //
95 
97  fval_ = p1_->fval();
98  ival_ = p1_->ival();
99  if (lr_ > 0)
100  ival_ = ival_ >> lr_;
101  else if (lr_ < 0)
102  ival_ = ival_ << (-lr_);
103 }
104 
106  fval_ = p1_->fval();
107  ival_ = p1_->ival();
108  if (lr_ > 0)
109  ival_ = ((ival_ >> (lr_ - 1)) + 1) >> 1; //rounding
110  else if (lr_ < 0)
111  ival_ = ival_ << (-lr_);
112 }
113 
115  fval_ = p1_->fval() + p2_->fval();
116  long int i1 = p1_->ival();
117  long int i2 = p2_->ival();
118  if (shift1 > 0)
119  i1 = i1 << shift1;
120  if (shift2 > 0)
121  i2 = i2 << shift2;
122  ival_ = i1 + i2;
123  if (ps_ > 0)
124  ival_ = ival_ >> ps_;
125 }
126 
128  fval_ = p1_->fval() - p2_->fval();
129  long int i1 = p1_->ival();
130  long int i2 = p2_->ival();
131  if (shift1 > 0)
132  i1 = i1 << shift1;
133  if (shift2 > 0)
134  i2 = i2 << shift2;
135  ival_ = i1 - i2;
136  if (ps_ > 0)
137  ival_ = ival_ >> ps_;
138 }
139 
141  fval_ = p1_->fval();
142  ival_ = (p1_->ival() * cI_) >> ps_;
143 }
144 
146  fval_ = p1_->fval() * cF_;
147  ival_ = (p1_->ival() * cI_) >> ps_;
148 }
149 
151  fval_ = -p1_->fval();
152  ival_ = -p1_->ival();
153 }
154 
156  fval_ = p1_->fval() * pow(2, -shift_);
157  ival_ = p1_->ival();
158  if (shift_ > 0)
159  ival_ = ival_ >> shift_;
160  if (shift_ < 0)
161  ival_ = ival_ << (-shift_);
162 }
163 
165  fval_ = p1_->fval() * pow(2, -shift_);
166  ival_ = p1_->ival();
167  if (shift_ > 0)
168  ival_ = ((ival_ >> (shift_ - 1)) + 1) >> 1;
169  if (shift_ < 0)
170  ival_ = ival_ << (-shift_);
171 }
172 
174  fval_ = p1_->fval() * p2_->fval();
175  ival_ = (p1_->ival() * p2_->ival()) >> ps_;
176 }
177 
179  fval_ = p1_->fval() * p2_->fval() + p3_->fval();
180  ival_ = p3_->ival();
181  if (shift3_ > 0)
182  ival_ = ival_ << shift3_;
183  if (shift3_ < 0)
184  ival_ = ival_ >> (-shift3_);
185  ival_ += p1_->ival() * p2_->ival();
186  ival_ = ival_ >> ps_;
187 }
188 
190  fval_ = 1. / (offset_ + p1_->fval());
191  ival_ = LUT[ival_to_addr(p1_->ival())];
192 }
Log< level::Info, true > LogVerbatim
double fval() const
Definition: imath.h:212
void local_calculate() override
double val_
Definition: imath.h:306
const double tolerance
void local_calculate() override
double range() const
Definition: imath.h:245
VarBase * p1_
Definition: imath.h:297
void local_calculate() override
bool calculate(int debug_level)
imathGlobals * globals_
Definition: imath.h:295
VarBase * p2_
Definition: imath.h:298
int ival_to_addr(int ival)
Definition: imath.h:1011
void local_calculate() override
VarBase * p3_
Definition: imath.h:299
std::string op_
Definition: imath.h:300
double offset_
Definition: imath.h:1042
void local_calculate() override
virtual void local_calculate()
Definition: imath.h:255
void local_calculate() override
void local_calculate() override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void local_calculate() override
long int ival_
Definition: imath.h:305
void local_calculate() override
void local_calculate() override
double minval_
Definition: imath.h:322
long int ival() const
Definition: imath.h:213
std::vector< VarBase * > cuts_
Definition: imath.h:308
std::string name_
Definition: imath.h:296
double maxval_
Definition: imath.h:323
void local_calculate() override
bool calculate()
Definition: imath.h:254
double K_
Definition: imath.h:312
double cF_
Definition: imath.h:799
int shift1
Definition: imath.h:594
int shift2
Definition: imath.h:595
std::string dump()
Definition: imath.cc:78
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
double fval_
Definition: imath.h:304
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
void local_calculate() override