CMS 3D CMS Logo

imath_calculate.cc
Go to the documentation of this file.
3 
4 using namespace trklet;
5 
6 bool VarBase::calculate(int debug_level) {
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 }
trklet::VarBase::fval
double fval() const
Definition: imath.h:212
trklet::VarShiftround::shift_
int shift_
Definition: imath.h:732
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
trklet::VarTimesC::ps_
int ps_
Definition: imath.h:797
trklet::VarInv::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:189
trklet::VarFlag::calculate_step
void calculate_step()
Definition: imath_calculate.cc:81
trklet::VarAdd::shift1
int shift1
Definition: imath.h:594
MessageLogger.h
trklet::VarBase::step_
int step_
Definition: imath.h:302
trklet::VarSubtract::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:127
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
trklet::VarShiftround::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:164
trklet::VarTimesC::cF_
double cF_
Definition: imath.h:799
trklet::VarNounits::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:140
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
trklet::VarBase::calculate
bool calculate(int debug_level)
Definition: imath_calculate.cc:6
trklet::VarBase::globals_
imathGlobals * globals_
Definition: imath.h:295
trklet::VarBase::val_
double val_
Definition: imath.h:306
trklet::VarBase::p2_
VarBase * p2_
Definition: imath.h:298
trklet::VarBase::range
double range() const
Definition: imath.h:245
trklet::VarSubtract::ps_
int ps_
Definition: imath.h:681
trklet::VarBase::p1_
VarBase * p1_
Definition: imath.h:297
trklet::VarTimesC::cI_
int cI_
Definition: imath.h:798
trklet::VarAdd::shift2
int shift2
Definition: imath.h:595
trklet::VarShift::shift_
int shift_
Definition: imath.h:752
trklet::VarDSPPostadd::shift3_
int shift3_
Definition: imath.h:952
trklet::VarShift::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:155
trklet::VarSubtract::shift2
int shift2
Definition: imath.h:683
trklet::VarBase::p3_
VarBase * p3_
Definition: imath.h:299
trklet::VarBase::op_
std::string op_
Definition: imath.h:300
trklet::VarMult::ps_
int ps_
Definition: imath.h:846
trklet::VarSubtract::shift1
int shift1
Definition: imath.h:682
trklet::VarBase::local_calculate
virtual void local_calculate()
Definition: imath.h:255
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trklet::VarNounits::cI_
int cI_
Definition: imath.h:711
trklet::VarBase::ival_
long int ival_
Definition: imath.h:305
trklet::VarNounits::ps_
int ps_
Definition: imath.h:710
trklet::VarAdjustK::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:96
trklet::VarBase::minval_
double minval_
Definition: imath.h:322
trklet::VarDSPPostadd::ps_
int ps_
Definition: imath.h:951
createfilelist.int
int
Definition: createfilelist.py:10
tolerance
const double tolerance
Definition: HGCalGeomParameters.cc:26
trklet::VarInv::offset_
double offset_
Definition: imath.h:1042
trklet::VarMult::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:173
trklet::VarDSPPostadd::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:178
trklet::VarBase::ival
long int ival() const
Definition: imath.h:213
trklet
Definition: AllProjectionsMemory.h:9
trklet::VarAdd::ps_
int ps_
Definition: imath.h:593
trklet::VarNeg::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:150
trklet::VarBase::cuts_
std::vector< VarBase * > cuts_
Definition: imath.h:308
LUT
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
trklet::VarAdjustKR::lr_
int lr_
Definition: imath.h:412
trklet::VarBase::name_
std::string name_
Definition: imath.h:296
trklet::VarAdjustK::lr_
int lr_
Definition: imath.h:373
trklet::VarBase::maxval_
double maxval_
Definition: imath.h:323
imath.h
trklet::VarAdd::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:114
trklet::VarBase::calculate
bool calculate()
Definition: imath.h:254
trklet::VarTimesC::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:145
trklet::VarBase::K_
double K_
Definition: imath.h:312
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
trklet::VarInv::ival_to_addr
int ival_to_addr(int ival)
Definition: imath.h:1011
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trklet::VarBase::nbits_
int nbits_
Definition: imath.h:311
trklet::VarAdjustKR::local_calculate
void local_calculate() override
Definition: imath_calculate.cc:105
trklet::VarBase::dump
std::string dump()
Definition: imath.cc:78
trklet::VarBase::fval_
double fval_
Definition: imath.h:304