~christopher-hunt08/maus/maus_DOE_review_version

« back to all changes in this revision

Viewing changes to src/common_cpp/Recon/EmittanceRecon/EmittanceHitCut.cc

  • Committer: Christopher Hunt
  • Date: 2014-07-08 16:52:34 UTC
  • Revision ID: christopher.hunt08@imperial.ac.uk-20140708165234-8532hqmj36m8ll4r
Everything

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "Recon/EmittanceRecon/EmittanceHitCut.hh"
 
3
 
 
4
#include <cmath>
 
5
 
 
6
namespace MAUS {
 
7
 
 
8
  namespace EmittanceRecon {
 
9
 
 
10
    cut_base::cut_base( hitParameter p, cutOperation o ) :
 
11
      _parameter( p ),
 
12
      _operation( o ) {
 
13
    }
 
14
 
 
15
    cut_base::cut_base( const cut_base& c ) :
 
16
      _parameter( c._parameter ),
 
17
      _operation( c._operation ) {
 
18
    }
 
19
 
 
20
    cut_base& cut_base::operator=( const cut_base& c ) {
 
21
      this->_parameter = c._parameter;
 
22
      this->_operation = c._operation;
 
23
 
 
24
      return *this;
 
25
    }
 
26
 
 
27
 
 
28
 
 
29
  ///////////////////////////////////////////////////////////////////////////////
 
30
 
 
31
 
 
32
    cut_int::cut_int() :
 
33
      cut_base( cut_base::no_parameter, cut_base::no_operation ),
 
34
      _value( 0 ) {
 
35
        this->_check();
 
36
    }
 
37
 
 
38
    cut_int::cut_int( cut_base::hitParameter p, cut_base::cutOperation o,
 
39
                                                                      int val ) :
 
40
      cut_base( p, o ),
 
41
      _value( val ) {
 
42
        this->_check();
 
43
    }
 
44
 
 
45
    cut_int::cut_int( const cut_int& c ) :
 
46
      cut_base( c ),
 
47
      _value( c._value ) {
 
48
    }
 
49
 
 
50
    cut_int& cut_int::operator=( const cut_int& c ) {
 
51
      cut_base::operator=( c );
 
52
      this->_value = c._value;
 
53
      return *this;
 
54
    }
 
55
 
 
56
    cut_base* cut_int::copyMe() const {
 
57
      return (cut_base*) new cut_int( *this );
 
58
    }
 
59
 
 
60
    bool cut_int::cutHit( emittanceHit hit ) const {
 
61
      int parameter = 0;
 
62
 
 
63
      switch ( this->getParameter() ) {
 
64
        case tracker_number :
 
65
          parameter = hit.getTrackerNumber();
 
66
          break;
 
67
 
 
68
        case station_number :
 
69
          parameter = hit.getStationNumber();
 
70
          break;
 
71
 
 
72
        case plane_number :
 
73
          parameter = hit.getPlaneNumber();
 
74
          break;
 
75
 
 
76
        case pid :
 
77
          parameter = hit.getPID();
 
78
          break;
 
79
 
 
80
        default :
 
81
          return true;
 
82
          break;
 
83
      }
 
84
 
 
85
      return this->switch_operation<int>( parameter, _value );
 
86
    }
 
87
 
 
88
    void cut_int::_check() {
 
89
      switch ( this->getParameter() )
 
90
      {
 
91
        case tracker_number :
 
92
        case station_number :
 
93
        case plane_number :
 
94
        case pid :
 
95
        break;
 
96
 
 
97
        default:
 
98
          throw Exception( Exception::nonRecoverable,
 
99
              "Attempting to cut a non integer parameter with an integer value",
 
100
              "cut_int::cutHit()" );
 
101
          break;
 
102
      }
 
103
 
 
104
      if ( this->getOperation() == no_operation || 
 
105
           this->getOperation() > less_equal ) {
 
106
        throw Exception( Exception::nonRecoverable,
 
107
            "Invalid Cut Operation Selected.",
 
108
            "cut_int::cutHit()" );
 
109
      }
 
110
 
 
111
    }
 
112
 
 
113
 
 
114
 
 
115
 
 
116
 
 
117
 
 
118
 
 
119
 
 
120
    cut_double::cut_double() :
 
121
      cut_base( cut_base::no_parameter, cut_base::no_operation ),
 
122
      _value( 0.0 ) {
 
123
        this->_check();
 
124
    }
 
125
 
 
126
    cut_double::cut_double( cut_base::hitParameter p, cut_base::cutOperation o,
 
127
                                                                   double val ) :
 
128
      cut_base( p, o ),
 
129
      _value( val ) {
 
130
        this->_check();
 
131
    }
 
132
 
 
133
    cut_double::cut_double( const cut_double& c ) :
 
134
      cut_base( c ),
 
135
      _value( c._value ) {
 
136
    }
 
137
 
 
138
    cut_double& cut_double::operator=( const cut_double& c ) {
 
139
      cut_base::operator=( c );
 
140
      this->_value = c._value;
 
141
      return *this;
 
142
    }
 
143
 
 
144
    cut_base* cut_double::copyMe() const {
 
145
      return (cut_base*) new cut_double( *this );
 
146
    }
 
147
 
 
148
 
 
149
    bool cut_double::cutHit( emittanceHit hit ) const {
 
150
      double parameter = 0.0;
 
151
      switch ( this->getParameter() ) {
 
152
        case x_position :
 
153
          parameter = hit.getPosition().x();
 
154
          break;
 
155
        case y_position :
 
156
          parameter = hit.getPosition().y();
 
157
          break;
 
158
        case z_position :
 
159
          parameter = hit.getPosition().z();
 
160
          break;
 
161
        case x_momentum :
 
162
          parameter = hit.getMomentum().x();
 
163
          break;
 
164
        case y_momentum :
 
165
          parameter = hit.getMomentum().y();
 
166
          break;
 
167
        case z_momentum :
 
168
          parameter = hit.getMomentum().z();
 
169
          break;
 
170
        case trans_position :
 
171
          parameter = std::sqrt( hit.getPosition().x()*hit.getPosition().x() + 
 
172
                                 hit.getPosition().y()*hit.getPosition().y() );
 
173
          break;
 
174
        case trans_momentum :
 
175
          parameter = std::sqrt( hit.getMomentum().x()*hit.getMomentum().x() + 
 
176
                                 hit.getMomentum().y()*hit.getMomentum().y() );
 
177
          break;
 
178
        case abs_position :
 
179
          parameter = hit.getPosition().mag();
 
180
          break;
 
181
        case abs_momentum :
 
182
          parameter = hit.getMomentum().mag();
 
183
          break;
 
184
          break;
 
185
        case p_value :
 
186
          parameter = hit.getPValue();
 
187
          break;
 
188
 
 
189
        default :
 
190
          return true;
 
191
          break;
 
192
      }
 
193
 
 
194
      return this->switch_operation<double>( parameter, _value );
 
195
    }
 
196
 
 
197
    void cut_double::_check() {
 
198
      switch( this->getParameter() )
 
199
      {
 
200
        case x_position :
 
201
        case y_position :
 
202
        case z_position :
 
203
        case x_momentum :
 
204
        case y_momentum :
 
205
        case z_momentum :
 
206
        case trans_position :
 
207
        case abs_position :
 
208
        case trans_momentum :
 
209
        case abs_momentum :
 
210
        case p_value:
 
211
        
 
212
        break;
 
213
        default:
 
214
          throw Exception( Exception::nonRecoverable,
 
215
              "Attempting to cut a non-double parameter with a double value",
 
216
              "cut_double::cutHit()" );
 
217
          break;
 
218
      }
 
219
 
 
220
      if ( this->getOperation() == no_operation || 
 
221
           this->getOperation() > less_equal ) {
 
222
        throw Exception( Exception::nonRecoverable,
 
223
            "Invalid Cut Operation Selected.",
 
224
            "cut_int::cutHit()" );
 
225
      }
 
226
    }
 
227
 
 
228
  }
 
229
 
 
230
}
 
231