AliPhysics  5dd2c10 (5dd2c10)
 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 #include "AliCutValueRange.h"
16 
20 
21 namespace EMCalTriggerPtAnalysis {
22 
26  template<typename t>
28  fNegate(false),
29  fUseSmallerEqual(true),
30  fUseLargerEqual(true)
31  {
32  fHasLimit[0] = fHasLimit[1] = false;
33  }
34 
41  template<typename t>
43  fNegate(false),
44  fUseSmallerEqual(true),
45  fUseLargerEqual(true)
46  {
47  fLimits[0] = min;
48  fLimits[1] = max;
49  fHasLimit[0] = fHasLimit[1] = true;
50  }
51 
58  template<typename t>
59  AliCutValueRange<t>::AliCutValueRange(t limit, bool isUpper):
60  fNegate(false),
61  fUseSmallerEqual(true),
62  fUseLargerEqual(true)
63  {
64  if(isUpper){
65  fLimits[1] = limit;
66  fHasLimit[0] = false;
67  fHasLimit[1] = true;
68  } else {
69  fLimits[0] = limit;
70  fHasLimit[0] = true;
71  fHasLimit[1] = false;
72  }
73  }
74 
81  template<typename t>
82  bool AliCutValueRange<t>::IsInRange(t value) const {
83  bool result = true;
84  if(fHasLimit[0] && fHasLimit[1]){
85  // Double-sided limited, correct choise of comparison operator
86  Bool_t withinUpper = fUseSmallerEqual ? (value <= fLimits[1]) : (value < fLimits[1]),
87  withinLower = fUseLargerEqual ? (value >= fLimits[1]) : (value > fLimits[1]);
88  result = withinLower && withinUpper;
89  if(fNegate)
90  result = !result;
91  } else if(fHasLimit[1]) {
92  // only upper bound, correct choise of comparison operator
93  result = fUseSmallerEqual ? (value <= fLimits[1]) : (value < fLimits[1]);
94  if(fNegate)
95  result = !result;
96  } else if(fHasLimit[0]){
97  // only lower bound, correct choise of comparison operator
98  result = fUseLargerEqual ? (value >= fLimits[0]) : (value > fLimits[0]);
99  if(fNegate)
100  result = !result;
101  }
102  return result;
103  }
104 
105  template class AliCutValueRange<int>;
106  template class AliCutValueRange<double>;
107  template class AliCutValueRange<float>;
108 
109 }
110 
t fLimits[2]
Specifies the limit in either of the direction (not used unless fHasLimit of that direction is true) ...
Class containing a range for a value to cut on.
Class containing a range for a value to cut on.
bool fHasLimit[2]
Specifies whether limit in any of the two directions is set.