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 
95  template <class Type1>
96  const bool checkIndex(const Type1& indexLo, const Type1& indexHi, const unsigned int index) const;
97 
99  template <class Type1>
100  const bool checkBit(const Type1& mask, const unsigned int bitNumber) const;
101 
103  template <class Type1>
104  const bool checkRangeEta(const unsigned int bitNumber,
105  const Type1& W1beginR,
106  const Type1& W1endR,
107  const Type1& W2beginR,
108  const Type1& W2endR,
109  const unsigned int nEtaBits) const;
110 
112  template <class Type1>
113  const bool checkRangePhi(const unsigned int bitNumber,
114  const Type1& W1beginR,
115  const Type1& W1endR,
116  const Type1& W2beginR,
117  const Type1& W2endR) const;
118 
120  template <class Type1>
121  const bool checkRangeDeltaEta(const unsigned int obj1Eta,
122  const unsigned int obj2Eta,
123  const Type1& lowerR,
124  const Type1& upperR,
125  const unsigned int nEtaBits) const;
126 
128  template <class Type1>
129  const bool checkRangeDeltaPhi(const unsigned int obj1Phi,
130  const unsigned int obj2Phi,
131  const Type1& lowerR,
132  const Type1& upperR) const;
133 
134  protected:
138 
141 
144 
147  };
148 
149  // define templated methods
150 
151  // check if a value is greater than a threshold or
152  // greater-or-equal depending on the value of the condGEqValue flag
153  template <class Type1, class Type2>
154  const bool ConditionEvaluation::checkThreshold(const Type1& thresholdL,
155  const Type1& thresholdH,
156  const Type2& value,
157  const bool condGEqValue) const {
158  if (value > 0) {
159  LogTrace("L1GlobalTrigger") << " checkThreshold check for condGEqValue = " << condGEqValue
160  << "\n hex: " << std::hex << "threshold = " << thresholdL << " - " << thresholdH
161  << " value = " << value << "\n dec: " << std::dec << "threshold = " << thresholdL
162  << " - " << thresholdH << " value = " << value << std::endl;
163  }
164 
165  if (condGEqValue) {
166  if (value >= (Type2)thresholdL && (Type1)value < thresholdH) {
167  //LogTrace("L1GlobalTrigger") << " condGEqValue: value >= threshold"
168  // << std::endl;
169 
170  return true;
171  }
172 
173  return false;
174 
175  } else {
176  if (value == (Type2)thresholdL) {
177  //LogTrace("L1GlobalTrigger") << " condGEqValue: value = threshold"
178  // << std::endl;
179 
180  return true;
181  }
182 
183  return false;
184  }
185  }
186 
187  // check if a index in a given range
188  template <class Type1>
189  const bool ConditionEvaluation::checkIndex(const Type1& indexLo,
190  const Type1& indexHi,
191  const unsigned int index) const {
192  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
193  << "\n\t indexLo = " << indexLo << "\n\t indexHi = " << indexHi << "\n\t index = " << index
194  << std::endl;
195 
196  // set condtion to false if indexLo > indexHi
197  if (indexLo > indexHi) {
198  return false;
199  }
200  if (index >= indexLo && index <= indexHi) {
201  return true;
202  }
203 
204  return false;
205  }
206 
207  // check if a bit with a given number is set in a mask
208  template <class Type1>
209  const bool ConditionEvaluation::checkBit(const Type1& mask, const unsigned int bitNumber) const {
210  uint64_t oneBit = 1ULL;
211 
212  if (bitNumber >= (sizeof(oneBit) * 8)) {
213  if (m_verbosity) {
214  LogTrace("L1GlobalTrigger") << " checkBit "
215  << "\n Bit number = " << bitNumber << " larger than maximum allowed "
216  << sizeof(oneBit) * 8 << std::endl;
217  }
218 
219  return false;
220  }
221 
222  oneBit <<= bitNumber;
223 
224  //LogTrace("L1GlobalTrigger") << " checkBit " << "\n mask address = " << &mask
225  // << std::dec << "\n dec: " << "mask = " << mask << " oneBit = " << oneBit
226  // << " bitNumber = " << bitNumber << std::hex << "\n hex: " << "mask = " << mask
227  // << " oneBit = " << oneBit << " bitNumber = " << bitNumber << std::dec
228  // << "\n mask & oneBit result = " << bool ( mask & oneBit ) << std::endl;
229 
230  return (mask & oneBit);
231  }
232 
234  template <class Type1>
235  const bool ConditionEvaluation::checkRangeEta(const unsigned int bitNumber,
236  const Type1& W1beginR,
237  const Type1& W1endR,
238  const Type1& W2beginR,
239  const Type1& W2endR,
240  const unsigned int nEtaBits) const {
241  // set condtion to true if beginR==endR = default -1
242  if (W1beginR == W1endR && W1beginR == (Type1)-1) {
243  return true;
244  }
245 
246  unsigned int W1diff1 = W1endR - W1beginR;
247  unsigned int W1diff2 = bitNumber - W1beginR;
248  unsigned int W1diff3 = W1endR - bitNumber;
249 
250  bool W1cond1 = ((W1diff1 >> nEtaBits) & 1) ? false : true;
251  bool W1cond2 = ((W1diff2 >> nEtaBits) & 1) ? false : true;
252  bool W1cond3 = ((W1diff3 >> nEtaBits) & 1) ? false : true;
253 
254  // check if value is in range
255  // for begin <= end takes [begin, end]
256  // for begin >= end takes [begin, end] over zero angle!
257  bool passWindow1 = false;
258  if (W1cond1 && (W1cond2 && W1cond3))
259  passWindow1 = true;
260  else if (!W1cond1 && (W1cond2 || W1cond3))
261  passWindow1 = true;
262  else {
263  passWindow1 = false;
264  }
265 
266  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
267  << "\n\t bitNumber = " << bitNumber << "\n\t W1beginR = " << W1beginR
268  << "\n\t W1endR = " << W1endR << "\n\t W1diff1 = " << W1diff1
269  << "\n\t W1cond1 = " << W1cond1 << "\n\t W1diff2 = " << W1diff2
270  << "\n\t W1cond2 = " << W1cond2 << "\n\t W1diff3 = " << W1diff3
271  << "\n\t W1cond3 = " << W1cond3 << "\n\t passWindow1 = " << passWindow1 << std::endl;
272 
273  if (W2beginR == W2endR && W2beginR == (Type1)-1) {
274  return passWindow1;
275  }
276 
277  unsigned int W2diff1 = W2endR - W2beginR;
278  unsigned int W2diff2 = bitNumber - W2beginR;
279  unsigned int W2diff3 = W2endR - bitNumber;
280 
281  bool W2cond1 = ((W2diff1 >> nEtaBits) & 1) ? false : true;
282  bool W2cond2 = ((W2diff2 >> nEtaBits) & 1) ? false : true;
283  bool W2cond3 = ((W2diff3 >> nEtaBits) & 1) ? false : true;
284 
285  bool passWindow2 = false;
286  if (W2cond1 && (W2cond2 && W2cond3))
287  passWindow2 = true;
288  else if (!W2cond1 && (W2cond2 || W2cond3))
289  passWindow2 = true;
290  else {
291  passWindow2 = false;
292  }
293 
294  LogDebug("l1t|Global") << "\n\t W2beginR = " << W2beginR << "\n\t W2endR = " << W2endR
295  << "\n\t W2diff1 = " << W2diff1 << "\n\t W2cond1 = " << W2cond1
296  << "\n\t W2diff2 = " << W2diff2 << "\n\t W2cond2 = " << W2cond2
297  << "\n\t W2diff3 = " << W2diff3 << "\n\t W2cond3 = " << W2cond3
298  << "\n\t passWindow2 = " << passWindow2
299  << "\n\t pass W1 || W2 = " << (passWindow1 || passWindow2) << std::endl;
300 
301  if (passWindow1 || passWindow2) {
302  return true;
303  } else {
304  return false;
305  }
306  }
307 
309  template <class Type1>
310  const bool ConditionEvaluation::checkRangePhi(const unsigned int bitNumber,
311  const Type1& W1beginR,
312  const Type1& W1endR,
313  const Type1& W2beginR,
314  const Type1& W2endR) const {
315  // set condtion to true if beginR==endR = default -1
316  if (W1beginR == W1endR && W1beginR == (Type1)-1) {
317  return true;
318  }
319 
320  int W1diff1 = W1endR - W1beginR;
321  int W1diff2 = bitNumber - W1beginR;
322  int W1diff3 = W1endR - bitNumber;
323 
324  bool W1cond1 = (W1diff1 < 0) ? false : true;
325  bool W1cond2 = (W1diff2 < 0) ? false : true;
326  bool W1cond3 = (W1diff3 < 0) ? false : true;
327 
328  // check if value is in range
329  // for begin <= end takes [begin, end]
330  // for begin >= end takes [begin, end] over zero angle!
331  bool passWindow1 = false;
332  if (W1cond1 && (W1cond2 && W1cond3))
333  passWindow1 = true;
334  else if (!W1cond1 && (W1cond2 || W1cond3))
335  passWindow1 = true;
336  else {
337  passWindow1 = false;
338  }
339 
340  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
341  << "\n\t bitNumber = " << bitNumber << "\n\t W1beginR = " << W1beginR
342  << "\n\t W1endR = " << W1endR << "\n\t W1diff1 = " << W1diff1
343  << "\n\t W1cond1 = " << W1cond1 << "\n\t W1diff2 = " << W1diff2
344  << "\n\t W1cond2 = " << W1cond2 << "\n\t W1diff3 = " << W1diff3
345  << "\n\t W1cond3 = " << W1cond3 << std::endl;
346 
347  if (W2beginR == W2endR && W2beginR == (Type1)-1) {
348  return passWindow1;
349  }
350 
351  int W2diff1 = W2endR - W2beginR;
352  int W2diff2 = bitNumber - W2beginR;
353  int W2diff3 = W2endR - bitNumber;
354 
355  bool W2cond1 = (W2diff1 < 0) ? false : true;
356  bool W2cond2 = (W2diff2 < 0) ? false : true;
357  bool W2cond3 = (W2diff3 < 0) ? false : true;
358 
359  // check if value is in range
360  // for begin <= end takes [begin, end]
361  // for begin >= end takes [begin, end] over zero angle!
362  bool passWindow2 = false;
363  if (W2cond1 && (W2cond2 && W2cond3))
364  passWindow2 = true;
365  else if (!W2cond1 && (W2cond2 || W2cond3))
366  passWindow2 = true;
367  else {
368  passWindow2 = false;
369  }
370 
371  if (passWindow1 || passWindow2) {
372  return true;
373  } else {
374  return false;
375  }
376  }
377 
378  template <class Type1>
379  const bool ConditionEvaluation::checkRangeDeltaEta(const unsigned int obj1Eta,
380  const unsigned int obj2Eta,
381  const Type1& lowerR,
382  const Type1& upperR,
383  const unsigned int nEtaBits) const {
384  /* // set condtion to true if beginR==endR = default -1 */
385  /* if( beginR==endR && beginR==-1 ){ */
386  /* return true; */
387  /* } */
388 
389  unsigned int compare = obj1Eta - obj2Eta;
390  bool cond = ((compare >> nEtaBits) & 1) ? false : true;
391 
392  unsigned int larger, smaller;
393  if (cond) {
394  larger = obj1Eta;
395  smaller = obj2Eta;
396  } else {
397  larger = obj2Eta;
398  smaller = obj1Eta;
399  }
400 
401  unsigned int diff = ((larger + ((~smaller + 1) & 255)) & 255);
402 
403  unsigned int diff1 = upperR - lowerR;
404  unsigned int diff2 = diff - lowerR;
405  unsigned int diff3 = upperR - diff;
406 
407  bool cond1 = ((diff1 >> nEtaBits) & 1) ? false : true;
408  bool cond2 = ((diff2 >> nEtaBits) & 1) ? false : true;
409  bool cond3 = ((diff3 >> nEtaBits) & 1) ? false : true;
410 
411  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
412  << "\n\t obj1Eta = " << obj1Eta << "\n\t obj2Eta = " << obj2Eta << "\n\t lowerR = " << lowerR
413  << "\n\t upperR = " << upperR << "\n\t compare = " << compare << "\n\t cond = " << cond
414  << "\n\t diff = " << diff << "\n\t diff1 = " << diff1 << "\n\t cond1 = " << cond1
415  << "\n\t diff2 = " << diff2 << "\n\t cond2 = " << cond2 << "\n\t diff3 = " << diff3
416  << "\n\t cond3 = " << cond3 << std::endl;
417 
418  if (cond1 && (cond2 && cond3))
419  return true;
420  else if (!cond1 && (cond2 || cond3))
421  return true;
422  else {
423  return false;
424  }
425  }
426 
427  template <class Type1>
428  const bool ConditionEvaluation::checkRangeDeltaPhi(const unsigned int obj1Phi,
429  const unsigned int obj2Phi,
430  const Type1& lowerR,
431  const Type1& upperR) const {
432  int deltaPhi = abs(int(obj1Phi) - int(obj2Phi));
433  if (deltaPhi > 71)
434  deltaPhi = 143 - deltaPhi + 1; // Add +1 if the calculation is over 0
435 
436  int diff1 = upperR - lowerR;
437  int diff2 = deltaPhi - lowerR;
438  int diff3 = upperR - deltaPhi;
439 
440  bool cond1 = (diff1 < 0) ? false : true;
441  bool cond2 = (diff2 < 0) ? false : true;
442  bool cond3 = (diff3 < 0) ? false : true;
443 
444  LogDebug("l1t|Global") << "\n l1t::ConditionEvaluation"
445  << "\n\t obj1Phi = " << obj1Phi << "\n\t obj2Phi = " << obj2Phi
446  << "\n\t deltaPhi = " << deltaPhi << "\n\t lowerR = " << lowerR << "\n\t upperR = " << upperR
447  << "\n\t diff1 = " << diff1 << "\n\t cond1 = " << cond1 << "\n\t diff2 = " << diff2
448  << "\n\t cond2 = " << cond2 << "\n\t diff3 = " << diff3 << "\n\t cond3 = " << cond3
449  << std::endl;
450 
451  // check if value is in range
452  // for begin <= end takes [begin, end]
453  // for begin >= end takes [begin, end] over zero angle!
454  if (cond1 && (cond2 && cond3))
455  return true;
456  else if (!cond1 && (cond2 || cond3))
457  return true;
458  else {
459  return false;
460  }
461  }
462 
463 } // namespace l1t
464 #endif
HIPAlignmentAlgorithm_cfi.verbosity
verbosity
Definition: HIPAlignmentAlgorithm_cfi.py:7
change_name.diff
diff
Definition: change_name.py:13
l1t::ConditionEvaluation::checkIndex
const bool checkIndex(const Type1 &indexLo, const Type1 &indexHi, const unsigned int index) const
check if a index is in a given range
Definition: ConditionEvaluation.h:189
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
l1t::ConditionEvaluation::checkThreshold
const bool checkThreshold(const Type1 &thresholdL, const Type1 &thresholdH, const Type2 &value, bool condGEqValue) const
Definition: ConditionEvaluation.h:154
l1t::ConditionEvaluation::m_combinationsInCond
CombinationsInCond m_combinationsInCond
store all the object combinations evaluated to true in the condition
Definition: ConditionEvaluation.h:143
l1t::ConditionEvaluation::combinationsInCond
CombinationsInCond & combinationsInCond() const
get all the object combinations (to fill it...)
Definition: ConditionEvaluation.h:84
l1t::ConditionEvaluation::setVerbosity
void setVerbosity(const int verbosity)
Definition: ConditionEvaluation.h:80
l1t::ConditionEvaluation::evaluateCondition
virtual const bool evaluateCondition(const int bxEval) const =0
the core function to check if the condition matches
GlobalObjectMapFwd.h
l1t::ConditionEvaluation::print
virtual void print(std::ostream &myCout) const
print condition
Definition: ConditionEvaluation.cc:32
CombinationsInCond
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
Definition: L1GlobalTriggerObjectMapFwd.h:32
l1t::ConditionEvaluation::setCondMaxNumberObjects
void setCondMaxNumberObjects(int condMaxNumberObjectsValue)
Definition: ConditionEvaluation.h:52
l1t::ConditionEvaluation::checkRangePhi
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
Definition: ConditionEvaluation.h:310
l1t::ConditionEvaluation::checkBit
const bool checkBit(const Type1 &mask, const unsigned int bitNumber) const
check if a bit with a given number is set in a mask
Definition: ConditionEvaluation.h:209
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
l1t::ConditionEvaluation::getCombinationsInCond
CombinationsInCond const & getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
Definition: ConditionEvaluation.h:75
l1t::ConditionEvaluation::ConditionEvaluation
ConditionEvaluation()
constructor
Definition: ConditionEvaluation.h:42
l1t::ConditionEvaluation::checkRangeDeltaPhi
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
Definition: ConditionEvaluation.h:428
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
l1t
delete x;
Definition: CaloConfig.h:22
value
Definition: value.py:1
l1t::ConditionEvaluation::~ConditionEvaluation
virtual ~ConditionEvaluation()
destructor
Definition: ConditionEvaluation.h:45
l1t::ConditionEvaluation::evaluateConditionStoreResult
void evaluateConditionStoreResult(const int bxEval)
call evaluateCondition and save last result
Definition: ConditionEvaluation.h:60
l1t::ConditionEvaluation::checkRangeDeltaEta
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
Definition: ConditionEvaluation.h:379
l1t::ConditionEvaluation::condMaxNumberObjects
int condMaxNumberObjects() const
Definition: ConditionEvaluation.h:50
l1t::ConditionEvaluation::m_condLastResult
bool m_condLastResult
the last result of evaluateCondition()
Definition: ConditionEvaluation.h:140
l1t::ConditionEvaluation
Definition: ConditionEvaluation.h:39
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
l1t::ConditionEvaluation::getNumericExpression
virtual std::string getNumericExpression() const
get numeric expression
Definition: ConditionEvaluation.h:66
L1TBPTX_cfi.bitNumber
bitNumber
Definition: L1TBPTX_cfi.py:26
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
l1t::ConditionEvaluation::m_verbosity
int m_verbosity
verbosity level
Definition: ConditionEvaluation.h:146
l1t::ConditionEvaluation::m_condMaxNumberObjects
int m_condMaxNumberObjects
Definition: ConditionEvaluation.h:137
compare
Definition: compare.py:1
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
l1t::ConditionEvaluation::condLastResult
bool condLastResult() const
get the latest result for the condition
Definition: ConditionEvaluation.h:57
l1t::ConditionEvaluation::checkRangeEta
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
Definition: ConditionEvaluation.h:235