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