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