AliPhysics  vAN-20150630 (513c479)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliCutValueRange.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 /*
17  * Class defining a range in which a value to be checked is valid. Can be used
18  * as a cut. In case a negative comparison (value valid only outside this range)
19  * is desired, this is handled when setting the object to negate (function Negate()).
20  * The class is a template, expecting the comparison operators to be overloaded.
21  *
22  * Author: Markus Fasel
23  */
24 
25 #include "AliCutValueRange.h"
26 
28 
29 namespace EMCalTriggerPtAnalysis {
30 
31  //______________________________________________________________________________
32  template<typename t>
33  AliCutValueRange<t>::AliCutValueRange():
34  fNegate(false)
35  {
36  /*
37  * Dummy constructor, producing a range open to both sides
38  */
39  fHasLimit[0] = fHasLimit[1] = false;
40  }
41 
42  //______________________________________________________________________________
43  template<typename t>
44  AliCutValueRange<t>::AliCutValueRange(t min, t max):
45  fNegate(false)
46  {
47  /*
48  * Constructor, producing a range closed to both sides
49  *
50  * @param min: lower limit
51  * @param max: upper limit
52  */
53  fLimits[0] = min;
54  fLimits[1] = max;
55  fHasLimit[0] = fHasLimit[1] = true;
56  }
57 
58  //______________________________________________________________________________
59  template<typename t>
60  AliCutValueRange<t>::AliCutValueRange(t limit, bool isUpper):
61  fNegate(false)
62  {
63  /*
64  * Constructor, producing a range closed to both sides
65  *
66  * @param limit: the limit to be set
67  * @param isUpper: defining whether the limit is the upper (case true) or lower limit
68  */
69  if(isUpper){
70  fLimits[1] = limit;
71  fHasLimit[0] = false;
72  fHasLimit[1] = true;
73  } else {
74  fLimits[0] = limit;
75  fHasLimit[0] = true;
76  fHasLimit[1] = false;
77  }
78  }
79 
80  //______________________________________________________________________________
81  template<typename t>
82  bool AliCutValueRange<t>::IsInRange(t value) const {
83  /*
84  * Check whether value is within a given range
85  *
86  * @param value: value to be checked
87  * @return: comparison result
88  */
89  bool result = true;
90  if(fHasLimit[0] && fHasLimit[1]){
91  // Double-sided limited
92  result = fNegate ? (value < fLimits[0] || value > fLimits[1]) : (value > fLimits[0] && value < fLimits[1]);
93  } else if(fHasLimit[1]) {
94  // only upper bound
95  result = fNegate ? (value > fLimits[1]) : (value < fLimits[1]);
96  } else if(fHasLimit[0]){
97  // only lower bound
98  result = fNegate ? (value < fLimits[0]) : (value > fLimits[0]);
99  }
100  return result;
101  }
102 
103  template class AliCutValueRange<int>;
104  template class AliCutValueRange<double>;
105  template class AliCutValueRange<float>;
106 
107 }
108 
templateClassImp(EMCalTriggerPtAnalysis::AliCutValueRange) namespace EMCalTriggerPtAnalysis