CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConditionEvaluation.h
Go to the documentation of this file.
1 #ifndef GlobalTrigger_ConditionEvaluation_h
2 #define GlobalTrigger_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& threshold,
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& beginR, const Type1& endR,
120  const Type1& beginVetoR, const Type1& endVetoR ) const;
121 
123  template<class Type1> const bool checkRangePhi(const unsigned int bitNumber,
124  const Type1& beginR, const Type1& endR,
125  const Type1& beginVetoR, const Type1& endVetoR ) const;
126 
127 
129  template<class Type1> const bool checkRangeDeltaEta(const unsigned int obj1Eta, const unsigned int obj2Eta,
130  const Type1& lowerR, const Type1& upperR ) const;
131 
133  template<class Type1> const bool checkRangeDeltaPhi(const unsigned int obj1Phi, const unsigned int obj2Phi,
134  const Type1& lowerR, const Type1& upperR ) const;
135 
136 
137 protected:
138 
142 
145 
148 
151 
152 };
153 
154 // define templated methods
155 
156 // check if a value is greater than a threshold or
157 // greater-or-equal depending on the value of the condGEqValue flag
158 template<class Type1, class Type2> const bool ConditionEvaluation::checkThreshold(
159  const Type1& threshold, const Type2& value, const bool condGEqValue) const {
160 
161  //if (value > 0) {
162  // LogTrace("L1GlobalTrigger") << " threshold check for condGEqValue = "
163  // << condGEqValue << "\n hex: " << std::hex << "threshold = " << threshold
164  // << " value = " << value << "\n dec: " << std::dec << "threshold = " << threshold
165  // << " value = " << value << std::endl;
166  //}
167 
168  if (condGEqValue) {
169  if (value >= (Type2) threshold) {
170 
171  //LogTrace("L1GlobalTrigger") << " condGEqValue: value >= threshold"
172  // << std::endl;
173 
174  return true;
175  }
176 
177  return false;
178 
179  }
180  else {
181 
182  if (value == (Type2) threshold) {
183 
184  //LogTrace("L1GlobalTrigger") << " condGEqValue: value = threshold"
185  // << std::endl;
186 
187  return true;
188  }
189 
190  return false;
191  }
192 }
193 
194 // check if a bit with a given number is set in a mask
195 template<class Type1> const bool ConditionEvaluation::checkBit(const Type1& mask,
196  const unsigned int bitNumber) const {
197 
198  boost::uint64_t oneBit = 1ULL;
199 
200  if (bitNumber >= (sizeof(oneBit)*8)) {
201 
202  if (m_verbosity) {
203 
204  LogTrace("L1GlobalTrigger")
205  << " checkBit " << "\n Bit number = "
206  << bitNumber << " larger than maximum allowed " << sizeof ( oneBit ) * 8
207  << std::endl;
208  }
209 
210  return false;
211  }
212 
213  oneBit <<= bitNumber;
214 
215  //LogTrace("L1GlobalTrigger") << " checkBit " << "\n mask address = " << &mask
216  // << std::dec << "\n dec: " << "mask = " << mask << " oneBit = " << oneBit
217  // << " bitNumber = " << bitNumber << std::hex << "\n hex: " << "mask = " << mask
218  // << " oneBit = " << oneBit << " bitNumber = " << bitNumber << std::dec
219  // << "\n mask & oneBit result = " << bool ( mask & oneBit ) << std::endl;
220 
221  return (mask & oneBit);
222 }
223 
224 
226 template<class Type1> const bool ConditionEvaluation::checkRangeEta(const unsigned int bitNumber,
227  const Type1& beginR, const Type1& endR,
228  const Type1& beginVetoR, const Type1& endVetoR ) const {
229 
230  // set condtion to true if beginR==endR = default -1
231  if( beginR==endR && beginR==(Type1)-1 ){
232  return true;
233  }
234 
235  unsigned int diff1 = endR - beginR;
236  unsigned int diff2 = bitNumber - beginR;
237  unsigned int diff3 = endR - bitNumber;
238 
239  bool cond1 = ( (diff1>>7) & 1 ) ? false : true;
240  bool cond2 = ( (diff2>>7) & 1 ) ? false : true;
241  bool cond3 = ( (diff3>>7) & 1 ) ? false : true;
242 
243  LogDebug("l1t|Global")
244  << "\n l1t::ConditionEvaluation"
245  << "\n\t bitNumber = " << bitNumber
246  << "\n\t beginR = " << beginR
247  << "\n\t endR = " << endR
248  << "\n\t beginVetoR = " << beginVetoR
249  << "\n\t endVetoR = " << endVetoR
250  << "\n\t diff1 = " << diff1
251  << "\n\t cond1 = " << cond1
252  << "\n\t diff2 = " << diff2
253  << "\n\t cond2 = " << cond2
254  << "\n\t diff3 = " << diff3
255  << "\n\t cond3 = " << cond3
256  << std::endl;
257 
258  // check if value is in range
259  // for begin <= end takes [begin, end]
260  // for begin >= end takes [begin, end] over zero angle!
261  bool passWindow = false;
262  if( cond1 && (cond2 && cond3 ) ) passWindow=true;
263  else if( !cond1 && (cond2 || cond3) ) passWindow=true;
264  else{
265  return false;
266  }
267 
268  if( passWindow ){
269  if( beginVetoR==endVetoR && beginVetoR==(Type1)-1 ) return true;
270 
271  unsigned int diffV1 = endVetoR - beginVetoR;
272  unsigned int diffV2 = bitNumber - beginVetoR;
273  unsigned int diffV3 = endVetoR - bitNumber;
274 
275  bool condV1 = ( (diffV1>>7) & 1 ) ? false : true;
276  bool condV2 = ( (diffV2>>7) & 1 ) ? false : true;
277  bool condV3 = ( (diffV3>>7) & 1 ) ? false : true;
278 
279  if( condV1 && !(condV2 && condV3) ) return true;
280  else if( !condV1 && !(condV2 || condV3) ) return true;
281  else{
282  return false;
283  }
284  }
285  else{
286  LogDebug("l1t|Global") << "=====> ConditionEvaluation::checkRange: I should never be here." << std::endl;
287  return false;
288  }
289 
290  LogDebug("l1t|Global") << "=====> HELP!! I'm trapped and I cannot escape! AHHHHHH" << std::endl;
291 
292  }
293 
294 
295 
297 template<class Type1> const bool ConditionEvaluation::checkRangePhi(const unsigned int bitNumber,
298  const Type1& beginR, const Type1& endR,
299  const Type1& beginVetoR, const Type1& endVetoR ) const {
300 
301  // set condtion to true if beginR==endR = default -1
302  if( beginR==endR && beginR==(Type1)-1 ){
303  return true;
304  }
305 
306  int diff1 = endR - beginR;
307  int diff2 = bitNumber - beginR;
308  int diff3 = endR - bitNumber;
309 
310  bool cond1 = ( diff1<0 ) ? false : true;
311  bool cond2 = ( diff2<0 ) ? false : true;
312  bool cond3 = ( diff3<0 ) ? false : true;
313 
314  LogDebug("l1t|Global")
315  << "\n l1t::ConditionEvaluation"
316  << "\n\t bitNumber = " << bitNumber
317  << "\n\t beginR = " << beginR
318  << "\n\t endR = " << endR
319  << "\n\t beginVetoR = " << beginVetoR
320  << "\n\t endVetoR = " << endVetoR
321  << "\n\t diff1 = " << diff1
322  << "\n\t cond1 = " << cond1
323  << "\n\t diff2 = " << diff2
324  << "\n\t cond2 = " << cond2
325  << "\n\t diff3 = " << diff3
326  << "\n\t cond3 = " << cond3
327  << std::endl;
328 
329  // check if value is in range
330  // for begin <= end takes [begin, end]
331  // for begin >= end takes [begin, end] over zero angle!
332  bool passWindow = false;
333  if( cond1 && (cond2 && cond3 ) ) passWindow=true;
334  else if( !cond1 && (cond2 || cond3) ) passWindow=true;
335  else{
336  return false;
337  }
338 
339  if( passWindow ){
340  if( beginVetoR==endVetoR && beginVetoR==(Type1)-1 ) return true;
341 
342  int diffV1 = endVetoR - beginVetoR;
343  int diffV2 = bitNumber - beginVetoR;
344  int diffV3 = endVetoR - bitNumber;
345 
346  bool condV1 = ( diffV1<0 ) ? false : true;
347  bool condV2 = ( diffV2<0 ) ? false : true;
348  bool condV3 = ( diffV3<0 ) ? false : true;
349 
350  if( condV1 && !(condV2 && condV3) ) return true;
351  else if( !condV1 && !(condV2 || condV3) ) return true;
352  else{
353  return false;
354  }
355  }
356  else{
357  LogDebug("l1t|Global") << "=====> ConditionEvaluation::checkRange: I should never be here." << std::endl;
358  return false;
359  }
360 
361  LogDebug("l1t|Global") << "=====> HELP!! I'm trapped and I cannot escape! AHHHHHH" << std::endl;
362 
363  }
364 
365 template<class Type1> const bool ConditionEvaluation::checkRangeDeltaEta(const unsigned int obj1Eta, const unsigned int obj2Eta,
366  const Type1& lowerR, const Type1& upperR ) const {
367 
368 /* // set condtion to true if beginR==endR = default -1 */
369 /* if( beginR==endR && beginR==-1 ){ */
370 /* return true; */
371 /* } */
372 
373  unsigned int compare = obj1Eta - obj2Eta;
374  bool cond = ( (compare>>7) & 1 ) ? false : true;
375 
376  unsigned int larger, smaller;
377  if( cond ){
378  larger = obj1Eta;
379  smaller= obj2Eta;
380  }
381  else{
382  larger = obj2Eta;
383  smaller= obj1Eta;
384  }
385 
386  unsigned int diff = ( ( larger + ((~smaller + 1) & 255) ) & 255);
387 
388  unsigned int diff1 = upperR - lowerR;
389  unsigned int diff2 = diff - lowerR;
390  unsigned int diff3 = upperR - diff;
391 
392  bool cond1 = ( (diff1>>7) & 1 ) ? false : true;
393  bool cond2 = ( (diff2>>7) & 1 ) ? false : true;
394  bool cond3 = ( (diff3>>7) & 1 ) ? false : true;
395 
396  LogDebug("l1t|Global")
397  << "\n l1t::ConditionEvaluation"
398  << "\n\t obj1Eta = " << obj1Eta
399  << "\n\t obj2Eta = " << obj2Eta
400  << "\n\t lowerR = " << lowerR
401  << "\n\t upperR = " << upperR
402  << "\n\t compare = " << compare
403  << "\n\t cond = " << cond
404  << "\n\t diff = " << diff
405  << "\n\t diff1 = " << diff1
406  << "\n\t cond1 = " << cond1
407  << "\n\t diff2 = " << diff2
408  << "\n\t cond2 = " << cond2
409  << "\n\t diff3 = " << diff3
410  << "\n\t cond3 = " << cond3
411  << std::endl;
412 
413  if( cond1 && (cond2 && cond3 ) ) return true;
414  else if( !cond1 && (cond2 || cond3) ) return true;
415  else{
416  return false;
417  }
418 
419  }
420 
421 
422 
423 template<class Type1> const bool ConditionEvaluation::checkRangeDeltaPhi(const unsigned int obj1Phi, const unsigned int obj2Phi,
424  const Type1& lowerR, const Type1& upperR ) const {
425 
426  int deltaPhi = abs(obj1Phi-obj2Phi);
427  if( deltaPhi>71 ) deltaPhi = 143 - deltaPhi + 1; // Add +1 if the calculation is over 0
428 
429  int diff1 = upperR - lowerR;
430  int diff2 = deltaPhi - lowerR;
431  int diff3 = upperR - deltaPhi;
432 
433  bool cond1 = ( diff1<0 ) ? false : true;
434  bool cond2 = ( diff2<0 ) ? false : true;
435  bool cond3 = ( diff3<0 ) ? false : true;
436 
437  LogDebug("l1t|Global")
438  << "\n l1t::ConditionEvaluation"
439  << "\n\t obj1Phi = " << obj1Phi
440  << "\n\t obj2Phi = " << obj2Phi
441  << "\n\t deltaPhi = " << deltaPhi
442  << "\n\t lowerR = " << lowerR
443  << "\n\t upperR = " << upperR
444  << "\n\t diff1 = " << diff1
445  << "\n\t cond1 = " << cond1
446  << "\n\t diff2 = " << diff2
447  << "\n\t cond2 = " << cond2
448  << "\n\t diff3 = " << diff3
449  << "\n\t cond3 = " << cond3
450  << std::endl;
451 
452  // check if value is in range
453  // for begin <= end takes [begin, end]
454  // for begin >= end takes [begin, end] over zero angle!
455  if( cond1 && (cond2 && cond3 ) ) return true;
456  else if( !cond1 && (cond2 || cond3) ) return true;
457  else{
458  return false;
459  }
460 
461  }
462 
463 
464 }
465 #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
void setCondMaxNumberObjects(int condMaxNumberObjectsValue)
void setVerbosity(const int verbosity)
virtual void print(std::ostream &myCout) const
print condition
bool condLastResult() const
get the latest result for the condition
const bool checkRangePhi(const unsigned int bitNumber, const Type1 &beginR, const Type1 &endR, const Type1 &beginVetoR, const Type1 &endVetoR) const
check if a value is in a given range and outside of a veto range
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
CombinationsInCond m_combinationsInCond
store all the object combinations evaluated to true in the condition
virtual ~ConditionEvaluation()
destructor
#define LogTrace(id)
const bool checkThreshold(const Type1 &threshold, const Type2 &value, bool condGEqValue) const
const bool checkRangeDeltaEta(const unsigned int obj1Eta, const unsigned int obj2Eta, const Type1 &lowerR, const Type1 &upperR) const
check if a value is in a given range
int m_verbosity
verbosity level
unsigned long long uint64_t
Definition: Time.h:15
bool m_condLastResult
the last result of evaluateCondition()
virtual const bool evaluateCondition(const int bxEval) const =0
the core function to check if the condition matches
const bool checkRangeEta(const unsigned int bitNumber, const Type1 &beginR, const Type1 &endR, const Type1 &beginVetoR, const Type1 &endVetoR) const
check if a value is in a given range and outside of a veto range
volatile std::atomic< bool > shutdown_flag false
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...)