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  bool all_ok = debug_level && ok1 && ok2 && ok3;
19  long int ival_prev = ival_;
20 
22 
23  val_ = ival_ * K_;
24 
25 #ifdef IMATH_ROOT
26  if (globals_->use_root) {
27  if (h_ == 0) {
28  globals_->h_file_->cd();
29  std::string hname = "h_" + name_;
30  h_ = (TH2F *)globals_->h_file_->Get(hname.c_str());
31  if (h_ == 0) {
32  h_precision_ = 0.5 * h_nbins_ * K_;
33  std::string st = name_ + ";fval;fval-ival*K";
34  h_ = new TH2F(hname.c_str(), name_.c_str(), h_nbins_, -range(), range(), h_nbins_, -h_precision_, h_precision_);
35  if (debug_level == 3)
36  edm::LogVerbatim("Tracklet") << " booking histogram " << hname;
37  }
38  }
39  if (ival_ != ival_prev || op_ == "def" || op_ == "const")
40  h_->Fill(fval_, K_ * ival_ - fval_);
41  }
42 #endif
43 
44  if (debug_level)
45  calcDebug(debug_level, ival_prev, all_ok);
46 
47  return all_ok;
48 }
49 
50 void VarBase::calcDebug(int debug_level, long int ival_prev, bool &all_ok) {
51  if (fval_ > maxval_)
52  maxval_ = fval_;
53  if (fval_ < minval_)
54  minval_ = fval_;
55 
56  bool todump = false;
57  int nmax = sizeof(long int) * 8;
58  int ns = nmax - nbits_;
59  long int itest = ival_;
60  itest = l1t::bitShift(itest, ns);
61  itest = itest >> ns;
62  if (itest != ival_) {
63  if (debug_level == 3 || (ival_ != ival_prev && all_ok)) {
64  edm::LogVerbatim("Tracklet") << "imath: truncated value mismatch!! " << ival_ << " != " << itest;
65  todump = true;
66  }
67  all_ok = false;
68  }
69 
70  float ftest = val_;
71  float tolerance = 0.1 * std::abs(fval_);
72  if (tolerance < 2 * K_)
73  tolerance = 2 * K_;
74  if (std::abs(ftest - fval_) > tolerance) {
75  if (debug_level == 3 || (ival_ != ival_prev && (all_ok && (op_ != "inv" || debug_level >= 2)))) {
76  edm::LogVerbatim("Tracklet") << "imath: **GROSS** value mismatch!! " << fval_ << " != " << ftest;
77  if (op_ == "inv")
78  edm::LogVerbatim("Tracklet") << p1_->dump() << "\n-----------------------------------";
79  todump = true;
80  }
81  all_ok = false;
82  }
83  if (todump)
84  edm::LogVerbatim("Tracklet") << dump();
85 }
86 
88  int max_step = 0;
89  for (const auto &cut : cuts_) {
90  if (!cut->cut_var())
91  continue;
92  if (cut->cut_var()->latency() + cut->cut_var()->step() > max_step)
93  max_step = cut->cut_var()->latency() + cut->cut_var()->step();
94  }
95  step_ = max_step;
96 }
97 
98 //
99 // local calculations
100 //
101 
103  fval_ = p1_->fval();
104  ival_ = p1_->ival();
105  if (lr_ > 0)
106  ival_ = ival_ >> lr_;
107  else if (lr_ < 0)
108  ival_ = l1t::bitShift(ival_, (-lr_));
109 }
110 
112  fval_ = p1_->fval();
113  ival_ = p1_->ival();
114  if (lr_ > 0)
115  ival_ = ((ival_ >> (lr_ - 1)) + 1) >> 1; //rounding
116  else if (lr_ < 0)
117  ival_ = l1t::bitShift(ival_, (-lr_));
118 }
119 
121  fval_ = p1_->fval() + p2_->fval();
122  long int i1 = p1_->ival();
123  long int i2 = p2_->ival();
124  if (shift1 > 0)
126  if (shift2 > 0)
128  ival_ = i1 + i2;
129  if (ps_ > 0)
130  ival_ = ival_ >> ps_;
131 }
132 
134  fval_ = p1_->fval() - p2_->fval();
135  long int i1 = p1_->ival();
136  long int i2 = p2_->ival();
137  if (shift1 > 0)
139  if (shift2 > 0)
141  ival_ = i1 - i2;
142  if (ps_ > 0)
143  ival_ = ival_ >> ps_;
144 }
145 
147  fval_ = p1_->fval();
148  ival_ = (p1_->ival() * cI_) >> ps_;
149 }
150 
152  fval_ = p1_->fval() * cF_;
153  ival_ = (p1_->ival() * cI_) >> ps_;
154 }
155 
157  fval_ = -p1_->fval();
158  ival_ = -p1_->ival();
159 }
160 
162  fval_ = p1_->fval() * pow(2, -shift_);
163  ival_ = p1_->ival();
164  if (shift_ > 0)
165  ival_ = ival_ >> shift_;
166  if (shift_ < 0)
168 }
169 
171  fval_ = p1_->fval() * pow(2, -shift_);
172  ival_ = p1_->ival();
173  if (shift_ > 0)
174  ival_ = ((ival_ >> (shift_ - 1)) + 1) >> 1;
175  if (shift_ < 0)
177 }
178 
180  fval_ = p1_->fval() * p2_->fval();
181  ival_ = (p1_->ival() * p2_->ival()) >> ps_;
182 }
183 
185  fval_ = p1_->fval() * p2_->fval() + p3_->fval();
186  ival_ = p3_->ival();
187  if (shift3_ > 0)
189  if (shift3_ < 0)
190  ival_ = ival_ >> (-shift3_);
191  ival_ += p1_->ival() * p2_->ival();
192  ival_ = ival_ >> ps_;
193 }
194 
196  fval_ = 1. / (offset_ + p1_->fval());
197  ival_ = LUT[ival_to_addr(p1_->ival())];
198 }
Log< level::Info, true > LogVerbatim
void calcDebug(int debug_level, long int ival_prev, bool &all_ok)
double fval() const
Definition: imath.h:213
void local_calculate() override
double val_
Definition: imath.h:307
const double tolerance
void local_calculate() override
double range() const
Definition: imath.h:246
VarBase * p1_
Definition: imath.h:298
void local_calculate() override
imathGlobals * globals_
Definition: imath.h:296
VarBase * p2_
Definition: imath.h:299
int ival_to_addr(int ival)
Definition: imath.h:1012
void local_calculate() override
VarBase * p3_
Definition: imath.h:300
std::string op_
Definition: imath.h:301
double offset_
Definition: imath.h:1043
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:306
void local_calculate() override
void local_calculate() override
double minval_
Definition: imath.h:323
long int ival() const
Definition: imath.h:214
std::vector< VarBase * > cuts_
Definition: imath.h:309
std::string name_
Definition: imath.h:297
double maxval_
Definition: imath.h:324
void local_calculate() override
double K_
Definition: imath.h:313
double cF_
Definition: imath.h:800
int shift1
Definition: imath.h:595
int shift2
Definition: imath.h:596
std::string dump()
Definition: imath.cc:78
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
double fval_
Definition: imath.h:305
bool calculate(int debug_level=0)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
int bitShift(int num, int bits)
Definition: BitShift.h:6
void local_calculate() override