ATLAS Offline Software
PhiRange.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 /***************************************************************************
5  PhiRange.cxx - description
6  -------------------
7  begin : 26/02/2002
8  email : e.moyse@qmul.ac.uk
9 ***************************************************************************/
10 
11 
13 
14 #include <iostream>
15 #include "math.h"
16 
17 namespace LVL1 {
18 
20  : m_min( 0.0 ), m_max( 0.0 ) {
21 
22  }
23 
24  PhiRange::PhiRange( double min, double max )
25  : m_min( min ), m_max( max ) {
26 
27  checkValues();
28  }
29 
30  double PhiRange::min() const {
31  return m_min;
32  }
33 
34  double PhiRange::max() const {
35  return m_max;
36  }
37 
39  void PhiRange::setRange( double min, double max ) {
40  m_min = min;
41  m_max = max;
42  checkValues();
43  }
44 
45 
50  bool PhiRange::contains( double number ) const {
51 
52  double diff = fabs( m_min - m_max );
53  if ( diff > M_PI ) {
54  // range must overlap 2PI
55  return ( ( m_min <= number && number <= ( 2 * M_PI ) )
56  || ( ( 0 <= number && number <= m_max ) ) );
57  }
58  // diff must be <=M_PI
59  return ( ( m_min <= number ) && ( number <= m_max ) );
60  }
61 
63  void PhiRange::checkValues() {
64  // should really check for more extreme values.
65 
66 // double & tmpMin = m_min;
67 // double& tmpMax = m_max;
68 
69  if ( m_min < 0.0 ) m_min = ( 2.0 * M_PI ) + m_min;
70  if ( m_max > ( 2.0 * M_PI ) ) m_max -= ( 2.0 * M_PI );
71 
72  if ( fabs(m_min-m_max) > M_PI) {
73  // RoI range must span 2PI wraparound. In which case m_min should have higher value, m_max lower
74  if (m_min < m_max) {
75  // swap them
76  double temp = m_max;
77  m_max = m_min;
78  m_min = temp;
79  }
80  }
81  else if ( m_min >= m_max ) {
82  // swap them
83  double temp = m_max;
84  m_max = m_min;
85  m_min = temp;
86  }
87  // }
88  return;
89  }
90 
93  double LVL1::PhiRange::centre() const {
94  double diff = fabs( m_min - m_max );
95  if ( diff > M_PI ) {
96  // range must overlap 2PI
97  double cent = ( m_min + ( m_max - m_min + 2 * M_PI ) / 2 );
98  if ( cent < 0.0 ) return ( 2.0 * M_PI ) + cent;
99  if ( cent > ( 2.0 * M_PI ) ) return cent -( 2.0 * M_PI );
100  return cent;
101  }
102  // diff must be <=M_PI
103  return ( m_min + ( ( m_max - m_min ) / 2 ) );
104 
105  }
106 
107 } // namespace LVL1
max
#define max(a, b)
Definition: cfImp.cxx:41
LVL1::PhiRange::contains
bool contains(double number) const
returns true if the range contains the number (i.e.
Definition: PhiRange.cxx:55
M_PI
#define M_PI
Definition: ActiveFraction.h:11
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
LVL1::PhiRange::centre
double centre() const
returns the centre of the two ranges.
Definition: PhiRange.cxx:98
LVL1::PhiRange::m_min
double m_min
Definition: PhiRange.h:49
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
min
#define min(a, b)
Definition: cfImp.cxx:40
LVL1::PhiRange::m_max
double m_max
Definition: PhiRange.h:50
python.selection.number
number
Definition: selection.py:20
PhiRange.h
LVL1::PhiRange::min
double min() const
Definition: PhiRange.cxx:35
LVL1::PhiRange::max
double max() const
Definition: PhiRange.cxx:39
LVL1::PhiRange::checkValues
void checkValues()
This function makes sure m_min really is less than m_max.
Definition: PhiRange.cxx:68
LVL1::PhiRange::PhiRange
PhiRange()
Definition: PhiRange.cxx:24
LVL1::PhiRange::setRange
void setRange(double min, double max)
sets range
Definition: PhiRange.cxx:44