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