CMS 3D CMS Logo

ConditionEvaluation.h
Go to the documentation of this file.
1 #ifndef L1Trigger_L1TGlobal_ConditionEvaluation_h
2 #define L1Trigger_L1TGlobal_ConditionEvaluation_h
3 
19 // system include files
20 #include <iostream>
21 
22 #include <string>
23 #include <vector>
24 
25 // user include files
26 
27 // base class
28 
29 //
32 #include <cstdint>
33 
34 // forward declarations
35 
36 namespace l1t {
37 
38  // class interface
40  public:
43 
45  virtual ~ConditionEvaluation() {}
46 
47  public:
50  inline int condMaxNumberObjects() const { return m_condMaxNumberObjects; }
51 
52  inline void setCondMaxNumberObjects(int condMaxNumberObjectsValue) {
53  m_condMaxNumberObjects = condMaxNumberObjectsValue;
54  }
55 
57  inline bool condLastResult() const { return m_condLastResult; }
58 
60  inline void evaluateConditionStoreResult(const int bxEval) { m_condLastResult = evaluateCondition(bxEval); }
61 
63  virtual const bool evaluateCondition(const int bxEval) const = 0;
64 
67  if (m_condLastResult) {
68  return "1";
69  } else {
70  return "0";
71  }
72  }
73 
76 
78  virtual void print(std::ostream& myCout) const;
79 
80  inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }
81 
82  protected:
85 
88  template <class Type1, class Type2>
89  const bool checkThreshold(const Type1& thresholdL,
90  const Type1& thresholdH,
91  const Type2& value,
92  bool condGEqValue) const;
93 
99  template <class Type1, class Type2>
100  const bool checkUnconstrainedPt(const Type1& thresholdL,
101  const Type1& thresholdH,
102  const Type2& value,
103  bool condGEqValue) const;
104 
106  template <class Type1>
107  const bool checkIndex(const Type1& indexLo, const Type1& indexHi, const unsigned int index) const;
108 
110  template <class Type1>
111  const bool checkBit(const Type1& mask, const unsigned int bitNumber) const;
112 
114  template <class Type1>
115  const bool checkRangeEta(const unsigned int bitNumber,
116  const Type1& W1beginR,
117  const Type1& W1endR,
118  const Type1& W2beginR,
119  const Type1& W2endR,
120  const unsigned int nEtaBits) const;
121 
123  template <class Type1>
124  const bool checkRangePhi(const unsigned int bitNumber,
125  const Type1& W1beginR,
126  const Type1& W1endR,
127  const Type1& W2beginR,
128  const Type1& W2endR) const;
129 
131  template <class Type1>
132  const bool checkRangeDeltaEta(const unsigned int obj1Eta,
133  const unsigned int obj2Eta,
134  const Type1& lowerR,
135  const Type1& upperR,
136  const unsigned int nEtaBits) const;
137 
139  template <class Type1>
140  const bool checkRangeDeltaPhi(const unsigned int obj1Phi,
141  const unsigned int obj2Phi,
142  const Type1& lowerR,
143  const Type1& upperR) const;
144 
145  protected:
149 
152 
155 
158  };
159 
160  // define templated methods
161 
162  // check if a value is greater than a threshold or
163  // greater-or-equal depending on the value of the condGEqValue flag
164  template <class Type1, class Type2>
165  const bool ConditionEvaluation::checkThreshold(const Type1& thresholdL,
166  const Type1& thresholdH,
167  const Type2& value,
168  const bool condGEqValue) const {
169  if (value > 0) {
170  LogTrace("L1GlobalTrigger") << " checkThreshold check for condGEqValue = " << condGEqValue
171  << "\n hex: " << std::hex << "threshold = " << thresholdL << " - " << thresholdH
172  << " value = " << value << "\n dec: " << std::dec << "threshold = " << thresholdL
173  << " - " << thresholdH << " value = " << value << std::endl;
174  }
175 
176  if (condGEqValue) {
177  if (value >= (Type2)thresholdL && (Type1)value < thresholdH) {
178  //LogTrace("L1GlobalTrigger") << " condGEqValue: value >= threshold"
179  // << std::endl;
180 
181  return true;
182  }
183 
184  return false;
185 
186  } else {
187  if (value == (Type2)thresholdL) {
188  //LogTrace("L1GlobalTrigger") << " condGEqValue: value = threshold"
189  // << std::endl;
190 
191  return true;
192  }
193 
194  return false;
195  }
196  }
197 
198  // check if a value is greater than a threshold or
199  // greater-or-equal depending on the value of the condGEqValue flag
203  template <class Type1, class Type2>
204  const bool ConditionEvaluation::checkUnconstrainedPt(const Type1& thresholdL,
205  const Type1& thresholdH,
206  const Type2& value,
207  const bool condGEqValue) const {
208  if (value > 0) {
209  LogTrace("L1GlobalTrigger") << " checkUnconstrainedPt check for condGEqValue = " << condGEqValue
210  << "\n hex: " << std::hex << "threshold = " << thresholdL << " - " << thresholdH
211  << " value = " << value << "\n dec: " << std::dec << "threshold = " << thresholdL
212  << " - " << thresholdH << " value = " << value << std::endl;
213  }
214  if (thresholdH > 0) // Only evaluate cut if threshold window is valid
215  {
216  if (condGEqValue) {
217  if (value >= (Type2)thresholdL && (Type1)value <= thresholdH) {
218  return true;
219  }
220  return false;
221  } else {
222  if (value == (Type2)thresholdL) {
223  return true;
224  }
225  return false;
226  }
227  } else // If invalid threshold window, do not evaluate cut (ie. pass through)
228  return true;
229  }
230 
231  // check if a index in a given range
232  template <class Type1>
233  const bool ConditionEvaluation::checkIndex(const Type1& indexLo,
234  const Type1& indexHi,
235  const unsigned int index) const {
236  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
237  << "\n\t indexLo = " << indexLo << "\n\t indexHi = " << indexHi << "\n\t index = " << index
238  << std::endl;
239 
240  // set condtion to false if indexLo > indexHi
241  if (indexLo > indexHi) {
242  return false;
243  }
244  if (index >= indexLo && index <= indexHi) {
245  return true;
246  }
247 
248  return false;
249  }
250 
251  // check if a bit with a given number is set in a mask
252  template <class Type1>
253  const bool ConditionEvaluation::checkBit(const Type1& mask, const unsigned int bitNumber) const {
254  uint64_t oneBit = 1ULL;
255 
256  if (bitNumber >= (sizeof(oneBit) * 8)) {
257  if (m_verbosity) {
258  LogTrace("L1GlobalTrigger") << " checkBit "
259  << "\n Bit number = " << bitNumber << " larger than maximum allowed "
260  << sizeof(oneBit) * 8 << std::endl;
261  }
262 
263  return false;
264  }
265 
266  oneBit <<= bitNumber;
267 
268  //LogTrace("L1GlobalTrigger") << " checkBit " << "\n mask address = " << &mask
269  // << std::dec << "\n dec: " << "mask = " << mask << " oneBit = " << oneBit
270  // << " bitNumber = " << bitNumber << std::hex << "\n hex: " << "mask = " << mask
271  // << " oneBit = " << oneBit << " bitNumber = " << bitNumber << std::dec
272  // << "\n mask & oneBit result = " << bool ( mask & oneBit ) << std::endl;
273 
274  return (mask & oneBit);
275  }
276 
278  template <class Type1>
279  const bool ConditionEvaluation::checkRangeEta(const unsigned int bitNumber,
280  const Type1& W1beginR,
281  const Type1& W1endR,
282  const Type1& W2beginR,
283  const Type1& W2endR,
284  const unsigned int nEtaBits) const {
285  // set condtion to true if beginR==endR = default -1
286  if (W1beginR == W1endR && W1beginR == (Type1)-1) {
287  return true;
288  }
289 
290  unsigned int W1diff1 = W1endR - W1beginR;
291  unsigned int W1diff2 = bitNumber - W1beginR;
292  unsigned int W1diff3 = W1endR - bitNumber;
293 
294  bool W1cond1 = ((W1diff1 >> nEtaBits) & 1) ? false : true;
295  bool W1cond2 = ((W1diff2 >> nEtaBits) & 1) ? false : true;
296  bool W1cond3 = ((W1diff3 >> nEtaBits) & 1) ? false : true;
297 
298  // check if value is in range
299  // for begin <= end takes [begin, end]
300  // for begin >= end takes [begin, end] over zero angle!
301  bool passWindow1 = false;
302  if (W1cond1 && (W1cond2 && W1cond3))
303  passWindow1 = true;
304  else if (!W1cond1 && (W1cond2 || W1cond3))
305  passWindow1 = true;
306  else {
307  passWindow1 = false;
308  }
309 
310  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
311  << "\n\t bitNumber = " << bitNumber << "\n\t W1beginR = " << W1beginR
312  << "\n\t W1endR = " << W1endR << "\n\t W1diff1 = " << W1diff1
313  << "\n\t W1cond1 = " << W1cond1 << "\n\t W1diff2 = " << W1diff2
314  << "\n\t W1cond2 = " << W1cond2 << "\n\t W1diff3 = " << W1diff3
315  << "\n\t W1cond3 = " << W1cond3 << "\n\t passWindow1 = " << passWindow1 << std::endl;
316 
317  if (W2beginR == W2endR && W2beginR == (Type1)-1) {
318  return passWindow1;
319  }
320 
321  unsigned int W2diff1 = W2endR - W2beginR;
322  unsigned int W2diff2 = bitNumber - W2beginR;
323  unsigned int W2diff3 = W2endR - bitNumber;
324 
325  bool W2cond1 = ((W2diff1 >> nEtaBits) & 1) ? false : true;
326  bool W2cond2 = ((W2diff2 >> nEtaBits) & 1) ? false : true;
327  bool W2cond3 = ((W2diff3 >> nEtaBits) & 1) ? false : true;
328 
329  bool passWindow2 = false;
330  if (W2cond1 && (W2cond2 && W2cond3))
331  passWindow2 = true;
332  else if (!W2cond1 && (W2cond2 || W2cond3))
333  passWindow2 = true;
334  else {
335  passWindow2 = false;
336  }
337 
338  LogDebug("l1t|Global") << "\n\t W2beginR = " << W2beginR << "\n\t W2endR = " << W2endR
339  << "\n\t W2diff1 = " << W2diff1 << "\n\t W2cond1 = " << W2cond1
340  << "\n\t W2diff2 = " << W2diff2 << "\n\t W2cond2 = " << W2cond2
341  << "\n\t W2diff3 = " << W2diff3 << "\n\t W2cond3 = " << W2cond3
342  << "\n\t passWindow2 = " << passWindow2
343  << "\n\t pass W1 || W2 = " << (passWindow1 || passWindow2) << std::endl;
344 
345  if (passWindow1 || passWindow2) {
346  return true;
347  } else {
348  return false;
349  }
350  }
351 
353  template <class Type1>
354  const bool ConditionEvaluation::checkRangePhi(const unsigned int bitNumber,
355  const Type1& W1beginR,
356  const Type1& W1endR,
357  const Type1& W2beginR,
358  const Type1& W2endR) const {
359  // set condtion to true if beginR==endR = default -1
360  if (W1beginR == W1endR && W1beginR == (Type1)-1) {
361  return true;
362  }
363 
364  int W1diff1 = W1endR - W1beginR;
365  int W1diff2 = bitNumber - W1beginR;
366  int W1diff3 = W1endR - bitNumber;
367 
368  bool W1cond1 = (W1diff1 < 0) ? false : true;
369  bool W1cond2 = (W1diff2 < 0) ? false : true;
370  bool W1cond3 = (W1diff3 < 0) ? false : true;
371 
372  // check if value is in range
373  // for begin <= end takes [begin, end]
374  // for begin >= end takes [begin, end] over zero angle!
375  bool passWindow1 = false;
376  if (W1cond1 && (W1cond2 && W1cond3))
377  passWindow1 = true;
378  else if (!W1cond1 && (W1cond2 || W1cond3))
379  passWindow1 = true;
380  else {
381  passWindow1 = false;
382  }
383 
384  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
385  << "\n\t bitNumber = " << bitNumber << "\n\t W1beginR = " << W1beginR
386  << "\n\t W1endR = " << W1endR << "\n\t W1diff1 = " << W1diff1
387  << "\n\t W1cond1 = " << W1cond1 << "\n\t W1diff2 = " << W1diff2
388  << "\n\t W1cond2 = " << W1cond2 << "\n\t W1diff3 = " << W1diff3
389  << "\n\t W1cond3 = " << W1cond3 << std::endl;
390 
391  if (W2beginR == W2endR && W2beginR == (Type1)-1) {
392  return passWindow1;
393  }
394 
395  int W2diff1 = W2endR - W2beginR;
396  int W2diff2 = bitNumber - W2beginR;
397  int W2diff3 = W2endR - bitNumber;
398 
399  bool W2cond1 = (W2diff1 < 0) ? false : true;
400  bool W2cond2 = (W2diff2 < 0) ? false : true;
401  bool W2cond3 = (W2diff3 < 0) ? false : true;
402 
403  // check if value is in range
404  // for begin <= end takes [begin, end]
405  // for begin >= end takes [begin, end] over zero angle!
406  bool passWindow2 = false;
407  if (W2cond1 && (W2cond2 && W2cond3))
408  passWindow2 = true;
409  else if (!W2cond1 && (W2cond2 || W2cond3))
410  passWindow2 = true;
411  else {
412  passWindow2 = false;
413  }
414 
415  if (passWindow1 || passWindow2) {
416  return true;
417  } else {
418  return false;
419  }
420  }
421 
422  template <class Type1>
423  const bool ConditionEvaluation::checkRangeDeltaEta(const unsigned int obj1Eta,
424  const unsigned int obj2Eta,
425  const Type1& lowerR,
426  const Type1& upperR,
427  const unsigned int nEtaBits) const {
428  /* // set condtion to true if beginR==endR = default -1 */
429  /* if( beginR==endR && beginR==-1 ){ */
430  /* return true; */
431  /* } */
432 
433  unsigned int compare = obj1Eta - obj2Eta;
434  bool cond = ((compare >> nEtaBits) & 1) ? false : true;
435 
436  unsigned int larger, smaller;
437  if (cond) {
438  larger = obj1Eta;
439  smaller = obj2Eta;
440  } else {
441  larger = obj2Eta;
442  smaller = obj1Eta;
443  }
444 
445  unsigned int diff = ((larger + ((~smaller + 1) & 255)) & 255);
446 
447  unsigned int diff1 = upperR - lowerR;
448  unsigned int diff2 = diff - lowerR;
449  unsigned int diff3 = upperR - diff;
450 
451  bool cond1 = ((diff1 >> nEtaBits) & 1) ? false : true;
452  bool cond2 = ((diff2 >> nEtaBits) & 1) ? false : true;
453  bool cond3 = ((diff3 >> nEtaBits) & 1) ? false : true;
454 
455  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
456  << "\n\t obj1Eta = " << obj1Eta << "\n\t obj2Eta = " << obj2Eta << "\n\t lowerR = " << lowerR
457  << "\n\t upperR = " << upperR << "\n\t compare = " << compare << "\n\t cond = " << cond
458  << "\n\t diff = " << diff << "\n\t diff1 = " << diff1 << "\n\t cond1 = " << cond1
459  << "\n\t diff2 = " << diff2 << "\n\t cond2 = " << cond2 << "\n\t diff3 = " << diff3
460  << "\n\t cond3 = " << cond3 << std::endl;
461 
462  if (cond1 && (cond2 && cond3))
463  return true;
464  else if (!cond1 && (cond2 || cond3))
465  return true;
466  else {
467  return false;
468  }
469  }
470 
471  template <class Type1>
472  const bool ConditionEvaluation::checkRangeDeltaPhi(const unsigned int obj1Phi,
473  const unsigned int obj2Phi,
474  const Type1& lowerR,
475  const Type1& upperR) const {
476  int deltaPhi = abs(int(obj1Phi) - int(obj2Phi));
477  if (deltaPhi > 71)
478  deltaPhi = 143 - deltaPhi + 1; // Add +1 if the calculation is over 0
479 
480  int diff1 = upperR - lowerR;
481  int diff2 = deltaPhi - lowerR;
482  int diff3 = upperR - deltaPhi;
483 
484  bool cond1 = (diff1 < 0) ? false : true;
485  bool cond2 = (diff2 < 0) ? false : true;
486  bool cond3 = (diff3 < 0) ? false : true;
487 
488  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
489  << "\n\t obj1Phi = " << obj1Phi << "\n\t obj2Phi = " << obj2Phi
490  << "\n\t deltaPhi = " << deltaPhi << "\n\t lowerR = " << lowerR << "\n\t upperR = " << upperR
491  << "\n\t diff1 = " << diff1 << "\n\t cond1 = " << cond1 << "\n\t diff2 = " << diff2
492  << "\n\t cond2 = " << cond2 << "\n\t diff3 = " << diff3 << "\n\t cond3 = " << cond3
493  << std::endl;
494 
495  // check if value is in range
496  // for begin <= end takes [begin, end]
497  // for begin >= end takes [begin, end] over zero angle!
498  if (cond1 && (cond2 && cond3))
499  return true;
500  else if (!cond1 && (cond2 || cond3))
501  return true;
502  else {
503  return false;
504  }
505  }
506 
507 } // namespace l1t
508 #endif
const bool checkRangeDeltaEta(const unsigned int obj1Eta, const unsigned int obj2Eta, const Type1 &lowerR, const Type1 &upperR, const unsigned int nEtaBits) const
check if a value is in a given range
void evaluateConditionStoreResult(const int bxEval)
call evaluateCondition and save last result
const bool checkBit(const Type1 &mask, const unsigned int bitNumber) const
check if a bit with a given number is set in a mask
const bool checkUnconstrainedPt(const Type1 &thresholdL, const Type1 &thresholdH, const Type2 &value, bool condGEqValue) const
const bool checkRangePhi(const unsigned int bitNumber, const Type1 &W1beginR, const Type1 &W1endR, const Type1 &W2beginR, const Type1 &W2endR) const
check if a value is in a given range and outside of a veto range
void setCondMaxNumberObjects(int condMaxNumberObjectsValue)
void setVerbosity(const int verbosity)
delete x;
Definition: CaloConfig.h:22
const bool checkThreshold(const Type1 &thresholdL, const Type1 &thresholdH, const Type2 &value, bool condGEqValue) const
constexpr uint32_t mask
Definition: gpuClustering.h:26
#define LogTrace(id)
bool condLastResult() const
get the latest result for the condition
virtual std::string getNumericExpression() const
get numeric expression
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
CombinationsInCond m_combinationsInCond
store all the object combinations evaluated to true in the condition
virtual ~ConditionEvaluation()
destructor
const bool checkIndex(const Type1 &indexLo, const Type1 &indexHi, const unsigned int index) const
check if a index is in a given range
const int verbosity
virtual void print(std::ostream &myCout) const
print condition
int m_verbosity
verbosity level
unsigned long long uint64_t
Definition: Time.h:13
bool m_condLastResult
the last result of evaluateCondition()
Definition: plugin.cc:23
const bool checkRangeEta(const unsigned int bitNumber, const Type1 &W1beginR, const Type1 &W1endR, const Type1 &W2beginR, const Type1 &W2endR, const unsigned int nEtaBits) const
check if a value is in a given range and outside of a veto range
virtual const bool evaluateCondition(const int bxEval) const =0
the core function to check if the condition matches
const bool checkRangeDeltaPhi(const unsigned int obj1Phi, const unsigned int obj2Phi, const Type1 &lowerR, const Type1 &upperR) const
check if a value is in a given range
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
CombinationsInCond & combinationsInCond() const
get all the object combinations (to fill it...)
CombinationsInCond const & getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
#define LogDebug(id)