AliPhysics  db95e02 (db95e02)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <iostream>
16 #include "AliCutValueRange.h"
17 
21 
22 namespace EMCalTriggerPtAnalysis {
23 
24  template<typename t>
26  fNegate(false),
27  fUseSmallerEqual(true),
28  fUseLargerEqual(true)
29  {
30  fHasLimit[0] = fHasLimit[1] = false;
31  }
32 
33  template<typename t>
35  fNegate(false),
36  fUseSmallerEqual(true),
37  fUseLargerEqual(true)
38  {
39  fLimits[0] = min;
40  fLimits[1] = max;
41  fHasLimit[0] = fHasLimit[1] = true;
42  }
43 
44  template<typename t>
45  AliCutValueRange<t>::AliCutValueRange(t limit, bool isUpper):
46  fNegate(false),
47  fUseSmallerEqual(true),
48  fUseLargerEqual(true)
49  {
50  if(isUpper){
51  fLimits[1] = limit;
52  fHasLimit[0] = false;
53  fHasLimit[1] = true;
54  } else {
55  fLimits[0] = limit;
56  fHasLimit[0] = true;
57  fHasLimit[1] = false;
58  }
59  }
60 
61  template<typename t>
62  bool AliCutValueRange<t>::IsInRange(t value) const {
63  bool result = true;
64  if(fHasLimit[0] && fHasLimit[1]){
65  // Double-sided limited, correct choise of comparison operator
66  Bool_t withinUpper = fUseSmallerEqual ? (value <= fLimits[1]) : (value < fLimits[1]),
67  withinLower = fUseLargerEqual ? (value >= fLimits[0]) : (value > fLimits[0]);
68  result = withinLower && withinUpper;
69  if(fNegate)
70  result = !result;
71  } else if(fHasLimit[1]) {
72  // only upper bound, correct choise of comparison operator
73  result = fUseSmallerEqual ? (value <= fLimits[1]) : (value < fLimits[1]);
74  if(fNegate)
75  result = !result;
76  } else if(fHasLimit[0]){
77  // only lower bound, correct choise of comparison operator
78  result = fUseLargerEqual ? (value >= fLimits[0]) : (value > fLimits[0]);
79  if(fNegate)
80  result = !result;
81  }
82  return result;
83  }
84 
85  template<typename t>
86  void AliCutValueRange<t>::PrintStream(std::ostream &stream) const {
87  stream << "[" << fLimits[0] << "|" << fLimits[1] << "]";
88  }
89 
90  template<typename t>
91  std::ostream &operator<<(std::ostream &stream, const AliCutValueRange<t> &val){
92  val.PrintStream(stream);
93  return stream;
94  }
95 
96  /*
97  * Template specifications
98  */
99  template class AliCutValueRange<int>;
100  template class AliCutValueRange<double>;
101  template class AliCutValueRange<float>;
102  template std::ostream &operator<<(std::ostream &stream, const AliCutValueRange<int> &val);
103  template std::ostream &operator<<(std::ostream &stream, const AliCutValueRange<double> &val);
104  template std::ostream &operator<<(std::ostream &stream, const AliCutValueRange<float> &val);
105 }
106 
templateClassImp(AliTHnT) template< class TemplateArray
void PrintStream(std::ostream &stream) const
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.
bool Bool_t
Definition: External.C:53
bool fHasLimit[2]
Specifies whether limit in any of the two directions is set.