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 
23 // system include files
24 #include <iostream>
25 
26 #include <string>
27 #include <vector>
28 
29 // user include files
30 
31 // base class
32 
33 //
36 #include <cstdint>
37 
38 // forward declarations
39 
40 namespace l1t {
41 
42  // class interface
44  public:
47 
49  virtual ~ConditionEvaluation() {}
50 
51  public:
54  inline int condMaxNumberObjects() const { return m_condMaxNumberObjects; }
55 
56  inline void setCondMaxNumberObjects(int condMaxNumberObjectsValue) {
57  m_condMaxNumberObjects = condMaxNumberObjectsValue;
58  }
59 
61  inline bool condLastResult() const { return m_condLastResult; }
62 
64  inline void evaluateConditionStoreResult(const int bxEval) { m_condLastResult = evaluateCondition(bxEval); }
65 
67  virtual const bool evaluateCondition(const int bxEval) const = 0;
68 
71  if (m_condLastResult) {
72  return "1";
73  } else {
74  return "0";
75  }
76  }
77 
80 
82  virtual void print(std::ostream& myCout) const;
83 
84  inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }
85 
86  protected:
89 
92  template <class Type1, class Type2>
93  const bool checkThreshold(const Type1& thresholdL,
94  const Type1& thresholdH,
95  const Type2& value,
96  bool condGEqValue) const;
97 
103  template <class Type1, class Type2>
104  const bool checkUnconstrainedPt(const Type1& thresholdL,
105  const Type1& thresholdH,
106  const Type2& value,
107  bool condGEqValue) const;
108 
110  template <class Type1>
111  const bool checkIndex(const Type1& indexLo, const Type1& indexHi, const unsigned int index) const;
112 
114  template <class Type1>
115  const bool checkBit(const Type1& mask, const unsigned int bitNumber) const;
116 
120  template <class Type1>
121  const bool checkRangeEta(const unsigned int bitNumber,
122  const std::vector<Type1>& windows,
123  const unsigned int nEtaBits) const;
124 
126  template <class Type1>
127  const bool checkRangePhi(const unsigned int bitNumber,
128  const Type1& W1beginR,
129  const Type1& W1endR,
130  const Type1& W2beginR,
131  const Type1& W2endR) const;
132 
134  template <class Type1>
135  const bool checkRangeDeltaEta(const unsigned int obj1Eta,
136  const unsigned int obj2Eta,
137  const Type1& lowerR,
138  const Type1& upperR,
139  const unsigned int nEtaBits) const;
140 
142  template <class Type1>
143  const bool checkRangeDeltaPhi(const unsigned int obj1Phi,
144  const unsigned int obj2Phi,
145  const Type1& lowerR,
146  const Type1& upperR) const;
147 
149  template <class Type1>
150  const bool checkRangeTfMuonIndex(const unsigned int bitNumber, const std::vector<Type1>& windows) const;
151 
152  protected:
156 
159 
162 
165  };
166 
167  // define templated methods
168 
169  // check if a value is greater than a threshold or
170  // greater-or-equal depending on the value of the condGEqValue flag
171  template <class Type1, class Type2>
172  const bool ConditionEvaluation::checkThreshold(const Type1& thresholdL,
173  const Type1& thresholdH,
174  const Type2& value,
175  const bool condGEqValue) const {
176  if (value > 0) {
177  LogTrace("L1GlobalTrigger") << " checkThreshold check for condGEqValue = " << condGEqValue
178  << "\n hex: " << std::hex << "threshold = " << thresholdL << " - " << thresholdH
179  << " value = " << value << "\n dec: " << std::dec << "threshold = " << thresholdL
180  << " - " << thresholdH << " value = " << value << std::endl;
181  }
182 
183  if (condGEqValue) {
184  if (value >= (Type2)thresholdL && (Type1)value < thresholdH) {
185  //LogTrace("L1GlobalTrigger") << " condGEqValue: value >= threshold"
186  // << std::endl;
187 
188  return true;
189  }
190 
191  return false;
192 
193  } else {
194  if (value == (Type2)thresholdL) {
195  //LogTrace("L1GlobalTrigger") << " condGEqValue: value = threshold"
196  // << std::endl;
197 
198  return true;
199  }
200 
201  return false;
202  }
203  }
204 
205  // check if a value is greater than a threshold or
206  // greater-or-equal depending on the value of the condGEqValue flag
210  template <class Type1, class Type2>
211  const bool ConditionEvaluation::checkUnconstrainedPt(const Type1& thresholdL,
212  const Type1& thresholdH,
213  const Type2& value,
214  const bool condGEqValue) const {
215  if (value > 0) {
216  LogTrace("L1GlobalTrigger") << " checkUnconstrainedPt check for condGEqValue = " << condGEqValue
217  << "\n hex: " << std::hex << "threshold = " << thresholdL << " - " << thresholdH
218  << " value = " << value << "\n dec: " << std::dec << "threshold = " << thresholdL
219  << " - " << thresholdH << " value = " << value << std::endl;
220  }
221  if (thresholdH > 0) // Only evaluate cut if threshold window is valid
222  {
223  if (condGEqValue) {
224  if (value >= (Type2)thresholdL && (Type1)value <= thresholdH) {
225  return true;
226  }
227  return false;
228  } else {
229  if (value == (Type2)thresholdL) {
230  return true;
231  }
232  return false;
233  }
234  } else // If invalid threshold window, do not evaluate cut (ie. pass through)
235  return true;
236  }
237 
238  // check if a index in a given index range
239  template <class Type1>
240  const bool ConditionEvaluation::checkIndex(const Type1& indexLo,
241  const Type1& indexHi,
242  const unsigned int index) const {
243  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
244  << "\n\t indexLo = " << indexLo << "\n\t indexHi = " << indexHi << "\n\t index = " << index
245  << std::endl;
246 
247  // set condition to false if indexLo > indexHi
248  if (indexLo > indexHi) {
249  return false;
250  }
251  if (index >= indexLo && index <= indexHi) {
252  return true;
253  }
254 
255  return false;
256  }
257 
258  // check if a bit with a given number is set in a mask
259  template <class Type1>
260  const bool ConditionEvaluation::checkBit(const Type1& mask, const unsigned int bitNumber) const {
261  uint64_t oneBit = 1ULL;
262 
263  if (bitNumber >= (sizeof(oneBit) * 8)) {
264  if (m_verbosity) {
265  LogTrace("L1GlobalTrigger") << " checkBit "
266  << "\n Bit number = " << bitNumber << " larger than maximum allowed "
267  << sizeof(oneBit) * 8 << std::endl;
268  }
269 
270  return false;
271  }
272 
273  oneBit <<= bitNumber;
274 
275  //LogTrace("L1GlobalTrigger") << " checkBit " << "\n mask address = " << &mask
276  // << std::dec << "\n dec: " << "mask = " << mask << " oneBit = " << oneBit
277  // << " bitNumber = " << bitNumber << std::hex << "\n hex: " << "mask = " << mask
278  // << " oneBit = " << oneBit << " bitNumber = " << bitNumber << std::dec
279  // << "\n mask & oneBit result = " << bool ( mask & oneBit ) << std::endl;
280 
281  return (mask & oneBit);
282  }
283 
287  template <class Type1>
288  const bool ConditionEvaluation::checkRangeEta(const unsigned int bitNumber,
289  const std::vector<Type1>& windows,
290  const unsigned int nEtaBits) const {
291  if (windows.empty()) {
292  return true;
293  }
294 
295  for (const auto& window : windows) {
296  const unsigned int diff1 = window.upper - window.lower;
297  const unsigned int diff2 = bitNumber - window.lower;
298  const unsigned int diff3 = window.upper - bitNumber;
299 
300  const bool cond1 = ((diff1 >> nEtaBits) & 1) ? false : true;
301  const bool cond2 = ((diff2 >> nEtaBits) & 1) ? false : true;
302  const bool cond3 = ((diff3 >> nEtaBits) & 1) ? false : true;
303 
304  // check if value is in range
305  // for begin <= end takes [begin, end]
306  // for begin >= end takes [begin, end] over zero angle!
307  bool passWindow = false;
308  if (cond1 && (cond2 && cond3))
309  passWindow = true;
310  else if (!cond1 && (cond2 || cond3))
311  passWindow = true;
312  else
313  passWindow = false;
314 
315  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
316  << "\n\t bitNumber = " << bitNumber << "\n\t window.lower = " << window.lower
317  << "\n\t window.upper = " << window.upper << "\n\t diff1 = " << diff1
318  << "\n\t cond1 = " << cond1 << "\n\t diff2 = " << diff2 << "\n\t cond2 = " << cond2
319  << "\n\t diff3 = " << diff3 << "\n\t cond3 = " << cond3
320  << "\n\t passWindow = " << passWindow << std::endl;
321 
322  if (passWindow) {
323  return true;
324  }
325  }
326 
327  return false;
328  }
329 
331  template <class Type1>
332  const bool ConditionEvaluation::checkRangePhi(const unsigned int bitNumber,
333  const Type1& W1beginR,
334  const Type1& W1endR,
335  const Type1& W2beginR,
336  const Type1& W2endR) const {
337  // set condition to true if beginR==endR = default -1
338  if (W1beginR == W1endR && W1beginR == (Type1)-1) {
339  return true;
340  }
341 
342  int W1diff1 = W1endR - W1beginR;
343  int W1diff2 = bitNumber - W1beginR;
344  int W1diff3 = W1endR - bitNumber;
345 
346  bool W1cond1 = (W1diff1 < 0) ? false : true;
347  bool W1cond2 = (W1diff2 < 0) ? false : true;
348  bool W1cond3 = (W1diff3 < 0) ? false : true;
349 
350  // check if value is in range
351  // for begin <= end takes [begin, end]
352  // for begin >= end takes [begin, end] over zero angle!
353  bool passWindow1 = false;
354  if (W1cond1 && (W1cond2 && W1cond3))
355  passWindow1 = true;
356  else if (!W1cond1 && (W1cond2 || W1cond3))
357  passWindow1 = true;
358  else {
359  passWindow1 = false;
360  }
361 
362  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
363  << "\n\t bitNumber = " << bitNumber << "\n\t W1beginR = " << W1beginR
364  << "\n\t W1endR = " << W1endR << "\n\t W1diff1 = " << W1diff1
365  << "\n\t W1cond1 = " << W1cond1 << "\n\t W1diff2 = " << W1diff2
366  << "\n\t W1cond2 = " << W1cond2 << "\n\t W1diff3 = " << W1diff3
367  << "\n\t W1cond3 = " << W1cond3 << std::endl;
368 
369  if (W2beginR == W2endR && W2beginR == (Type1)-1) {
370  return passWindow1;
371  }
372 
373  int W2diff1 = W2endR - W2beginR;
374  int W2diff2 = bitNumber - W2beginR;
375  int W2diff3 = W2endR - bitNumber;
376 
377  bool W2cond1 = (W2diff1 < 0) ? false : true;
378  bool W2cond2 = (W2diff2 < 0) ? false : true;
379  bool W2cond3 = (W2diff3 < 0) ? false : true;
380 
381  // check if value is in range
382  // for begin <= end takes [begin, end]
383  // for begin >= end takes [begin, end] over zero angle!
384  bool passWindow2 = false;
385  if (W2cond1 && (W2cond2 && W2cond3))
386  passWindow2 = true;
387  else if (!W2cond1 && (W2cond2 || W2cond3))
388  passWindow2 = true;
389  else {
390  passWindow2 = false;
391  }
392 
393  if (passWindow1 || passWindow2) {
394  return true;
395  } else {
396  return false;
397  }
398  }
399 
400  template <class Type1>
401  const bool ConditionEvaluation::checkRangeDeltaEta(const unsigned int obj1Eta,
402  const unsigned int obj2Eta,
403  const Type1& lowerR,
404  const Type1& upperR,
405  const unsigned int nEtaBits) const {
406  /* // set condition to true if beginR==endR = default -1 */
407  /* if( beginR==endR && beginR==-1 ){ */
408  /* return true; */
409  /* } */
410 
411  unsigned int compare = obj1Eta - obj2Eta;
412  bool cond = ((compare >> nEtaBits) & 1) ? false : true;
413 
414  unsigned int larger, smaller;
415  if (cond) {
416  larger = obj1Eta;
417  smaller = obj2Eta;
418  } else {
419  larger = obj2Eta;
420  smaller = obj1Eta;
421  }
422 
423  unsigned int diff = ((larger + ((~smaller + 1) & 255)) & 255);
424 
425  unsigned int diff1 = upperR - lowerR;
426  unsigned int diff2 = diff - lowerR;
427  unsigned int diff3 = upperR - diff;
428 
429  bool cond1 = ((diff1 >> nEtaBits) & 1) ? false : true;
430  bool cond2 = ((diff2 >> nEtaBits) & 1) ? false : true;
431  bool cond3 = ((diff3 >> nEtaBits) & 1) ? false : true;
432 
433  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
434  << "\n\t obj1Eta = " << obj1Eta << "\n\t obj2Eta = " << obj2Eta << "\n\t lowerR = " << lowerR
435  << "\n\t upperR = " << upperR << "\n\t compare = " << compare << "\n\t cond = " << cond
436  << "\n\t diff = " << diff << "\n\t diff1 = " << diff1 << "\n\t cond1 = " << cond1
437  << "\n\t diff2 = " << diff2 << "\n\t cond2 = " << cond2 << "\n\t diff3 = " << diff3
438  << "\n\t cond3 = " << cond3 << std::endl;
439 
440  if (cond1 && (cond2 && cond3))
441  return true;
442  else if (!cond1 && (cond2 || cond3))
443  return true;
444  else {
445  return false;
446  }
447  }
448 
449  template <class Type1>
450  const bool ConditionEvaluation::checkRangeDeltaPhi(const unsigned int obj1Phi,
451  const unsigned int obj2Phi,
452  const Type1& lowerR,
453  const Type1& upperR) const {
454  int deltaPhi = abs(int(obj1Phi) - int(obj2Phi));
455  if (deltaPhi > 71)
456  deltaPhi = 143 - deltaPhi + 1; // Add +1 if the calculation is over 0
457 
458  int diff1 = upperR - lowerR;
459  int diff2 = deltaPhi - lowerR;
460  int diff3 = upperR - deltaPhi;
461 
462  bool cond1 = (diff1 < 0) ? false : true;
463  bool cond2 = (diff2 < 0) ? false : true;
464  bool cond3 = (diff3 < 0) ? false : true;
465 
466  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
467  << "\n\t obj1Phi = " << obj1Phi << "\n\t obj2Phi = " << obj2Phi
468  << "\n\t deltaPhi = " << deltaPhi << "\n\t lowerR = " << lowerR << "\n\t upperR = " << upperR
469  << "\n\t diff1 = " << diff1 << "\n\t cond1 = " << cond1 << "\n\t diff2 = " << diff2
470  << "\n\t cond2 = " << cond2 << "\n\t diff3 = " << diff3 << "\n\t cond3 = " << cond3
471  << std::endl;
472 
473  // check if value is in range
474  // for begin <= end takes [begin, end]
475  // for begin >= end takes [begin, end] over zero angle!
476  if (cond1 && (cond2 && cond3))
477  return true;
478  else if (!cond1 && (cond2 || cond3))
479  return true;
480  else {
481  return false;
482  }
483  }
484 
485  template <class Type1>
486  const bool ConditionEvaluation::checkRangeTfMuonIndex(const unsigned int value,
487  const std::vector<Type1>& windows) const {
488  if (windows.empty()) {
489  return true;
490  }
491 
492  for (const auto& window : windows) {
493  if ((window.lower <= value) and (value <= window.upper)) {
494  return true;
495  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
496  << "\n\t window.lower = " << window.lower << "\n\t window.upper = " << window.upper
497  << "Passed TfMuonIndex window" << std::endl;
498  }
499  }
500 
501  return false;
502  }
503 
504 } // namespace l1t
505 #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 deltaEta 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 phi 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
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643
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 std::vector< Type1 > &windows, const unsigned int nEtaBits) const
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 deltaPhi 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...)
const bool checkRangeTfMuonIndex(const unsigned int bitNumber, const std::vector< Type1 > &windows) const
check if a value is in a given muon track finder index range
CombinationsInCond const & getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
#define LogDebug(id)