CFEL - ASG Software Suite  2.5.0
CASS
particle.cpp
Go to the documentation of this file.
1 //Copyright (C) 2009-2010 Lutz Foucar
2 
3 /**
4  * @file particle.cpp file contains the classes that describe a particle that hit
5  * a delayline detector.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <cmath>
11 #include <sstream>
12 #include <stdexcept>
13 
14 #include "particle.h"
15 #include "momenta_calculator.h"
16 #include "cass_settings.h"
17 #include "delayline_detector.h"
18 
19 using namespace cass::ACQIRIS;
20 using namespace std;
21 using namespace std::tr1;
22 
23 namespace cass
24 {
25 namespace ACQIRIS
26 {
27 /** base class of conditions for finding the right particle
28  *
29  * @author Lutz Foucar
30  */
32 {
33 public:
34  /** virtual destructor since this is a base class */
35  virtual ~IsParticleHit() {}
36 
37  /** typedef defining the types of available conditions */
38  enum ConditionType {tofcond, radcond, rectcond, tofradcond,tofrectcond};
39 
40  /** the comparison
41  *
42  * @return true when dethit fullfilles the condition
43  * @param dethit the detector hit to check for the condition
44  */
45  virtual bool operator()(const detectorHit_t &dethit)const=0;
46 
47  /** read the parameters of the condition from the .ini file
48  *
49  * @param s the CASSSettings object to read the information from
50  */
51  virtual void loadSettings(CASSSettings &s)=0;
52 
53  /** create an instance of the chosen class
54  *
55  * @return pointer to instance of requested class
56  * @param type the requested class type
57  */
58  static tr1::shared_ptr<IsParticleHit> instance(const ConditionType& type);
59 };
60 
61 /** a Time of Flight condition
62  *
63  * checks whether the detectorhit is in a predifined range in the time of
64  * flight
65  *
66  * @cassttng AcqirisDetectors/\%detectorname\%/\%particlename%/ToFCondition/{Low|High}\n
67  * The range to check whether the detectorhit is in.
68  * Default is 0|20000.
69  *
70  * @author Lutz Foucar
71  */
72 class TofCond : public IsParticleHit
73 {
74 public:
75  virtual ~TofCond() {}
76  bool operator()(const detectorHit_t &dethit) const
77  {
78  return (_tofcond.first < dethit[t] && dethit[t] < _tofcond.second);
79  }
80 
82  {
83  using namespace std;
84  s.beginGroup("ToFCondition");
85  _tofcond = make_pair(s.value("Low",0).toDouble(),
86  s.value("High",20000).toDouble());
87  s.endGroup();
88  }
89 
90 private:
91  /** the tof range */
92  std::pair<double,double> _tofcond;
93 };
94 
95 /** a radius position condition
96  *
97  * checks whether the position of the detectorhit on the detector is in a
98  * given radius around a predefined center.
99  *
100  * @cassttng AcqirisDetectors/\%detectorname\%/\%particlename%/RadiusCondition/{CenterX|CenterY}\n
101  * The position of the center of the radius to check for in mm
102  * Default is 0|0.
103  * @cassttng AcqirisDetectors/\%detectorname\%/\%particlename%/RadiusCondition/{MaximumRadius}\n
104  * The maximum radius the position is checked for in mm. Default
105  * is 100.
106  *
107  * @author Lutz Foucar
108  */
109 class RadCond : public IsParticleHit
110 {
111 public:
112  virtual ~RadCond() {}
113  bool operator()(const detectorHit_t &dethit) const
114  {
115  const double &xval (dethit[x]);
116  const double &yval (dethit[y]);
117  const double rad = sqrt((xval-_center.first)*(xval-_center.first) +
118  (yval-_center.second)*(yval-_center.second));
119  return (rad < _maxradius);
120  }
121 
123  {
124  using namespace std;
125  s.beginGroup("RadiusCondition");
126  _center = make_pair(s.value("CenterX",0).toDouble(),
127  s.value("CenterY",0).toDouble());
128  _maxradius = s.value("MaximumRadius",100).toDouble();
129  s.endGroup();
130  }
131 
132 private:
133  /** the center of the radius */
134  std::pair<double,double> _center;
135 
136  /** the maximum radius of the condtion */
137  double _maxradius;
138 };
139 
140 /** a simple position condition
141  *
142  * checks whether the detector hit falls in a simple rectangular condition
143  *
144  * @cassttng AcqirisDetectors/\%detectorname\%/\%particlename%/SimplePositionCondition/{XLow|XHigh}\n
145  * The range in the x-axis to check in mm. Default is -10|10.
146  * @cassttng AcqirisDetectors/\%detectorname\%/\%particlename%/SimplePositionCondition/{YLow|YHigh}\n
147  * The range in the y-axis to check in mm. Default is -10|10.
148  *
149  * @author Lutz Foucar
150  */
151 class RectCond : public IsParticleHit
152 {
153 public:
154  virtual ~RectCond() {}
155  bool operator()(const detectorHit_t &dethit) const
156  {
157  const double &xval (dethit[x]);
158  const double &yval (dethit[y]);
159  const bool checkX(_xrange.first < xval && xval < _xrange.second);
160  const bool checkY(_yrange.first < yval && yval < _yrange.second);
161  return (checkX && checkY);
162  }
163 
165  {
166  using namespace std;
167  s.beginGroup("SimplePositionCondition");
168  _xrange = make_pair(s.value("XLow",-10).toDouble(),
169  s.value("XHigh",10).toDouble());
170  _yrange = make_pair(s.value("YLow",-10).toDouble(),
171  s.value("YHigh",10).toDouble());
172  s.endGroup();
173  }
174 
175 private:
176  /** the range in x */
177  std::pair<double,double> _xrange;
178 
179  /** the range in y */
180  std::pair<double,double> _yrange;
181 };
182 
183 /** a combination of conditions
184  *
185  * this class combines two of the IsParticleHit conditions
186  *
187  * @cassttng see TofCond, RadCond and RectCond for possible settings
188  *
189  * @tparam FistCondition class that defines the first condition
190  * @tparam SecondCondition class that defines the second condition
191  *
192  * @author Lutz Foucar
193  */
194 template <class FirstCondition, class SecondCondition>
196 {
197 public:
199  :_conditions(std::make_pair(new FirstCondition, new SecondCondition))
200  {}
201 
202  virtual ~CombineConditions() {}
203 
204  bool operator()(const detectorHit_t &dethit) const
205  {
206  IsParticleHit &firstCond (*_conditions.first);
207  IsParticleHit &secondCond (*_conditions.second);
208  return (firstCond(dethit) && secondCond(dethit));
209  }
210 
212  {
213  _conditions.first->loadSettings(s);
214  _conditions.second->loadSettings(s);
215  }
216 
217 private:
218  std::pair<IsParticleHit*,IsParticleHit*> _conditions;
219 };
220 
221 tr1::shared_ptr<IsParticleHit> IsParticleHit::instance(const ConditionType &type)
222 {
223  std::tr1::shared_ptr<IsParticleHit> cond;
224  switch(type)
225  {
226  case tofcond:
227  cond = std::tr1::shared_ptr<IsParticleHit>(new TofCond);
228  break;
229  case radcond:
230  cond = std::tr1::shared_ptr<IsParticleHit>(new RadCond);
231  break;
232  case rectcond:
233  cond = std::tr1::shared_ptr<IsParticleHit>(new RectCond);
234  break;
235  case tofrectcond:
236  cond = std::tr1::shared_ptr<IsParticleHit>(new CombineConditions<TofCond,RectCond>());
237  break;
238  case tofradcond:
239  cond = std::tr1::shared_ptr<IsParticleHit>(new CombineConditions<TofCond,RadCond>());
240  break;
241  default:
242  throw invalid_argument("IsParticleHit::instance: Condition type '" +
243  toString(type) + "' not available");
244  break;
245  }
246  return cond;
247 }
248 
249 /** convert kartesian coordinates to polar coordinates
250  *
251  * will use the kartesian coordinates of the momentum vector of the particle
252  * hit and add its polarcoordinates to the hit.
253  *
254  * @param hit the hit to make the transition with
255  *
256  * @author Lutz Foucar
257  */
259 {
260  const double & xval (hit[px]);
261  const double & yval (hit[py]);
262  const double & zval (hit[pz]);
263  double & rhoval (hit[roh]);
264  double & thetaval (hit[theta]);
265  double & phival (hit[phi]);
266  rhoval = sqrt(xval*xval + yval*yval + zval*zval);
267  thetaval = atan2(yval,xval);
268  phival = acos(zval/rhoval);
269 }
270 
271 } //end namespace acqiris
272 } //end namespace cass
273 
275 {
276  _charge_au = s.value("Charge",1).toDouble();
277  _mass_au = s.value("Mass",1).toDouble();
278  _spectrometer.loadSettings(s,*this);
279  _copyandcorrect.loadSettings(s);
280  if (!(_mass_au == 1 && _charge_au == -1))
281  _mass_au *= 1836.15;
283  (static_cast<IsParticleHit::ConditionType>(s.value("ConditionType",IsParticleHit::tofcond).toInt()));
284  _isParticleHit = IsParticleHit::instance(condtype);
285  _isParticleHit->loadSettings(s);
286  if (_spectrometer.BFieldIsOn())
288  else
290  if (_spectrometer.regions().size() > 1)
292  else
294 }
295 
297 {
298  if (!_listIsCreated)
299  {
300  const IsParticleHit &isParticleHit (*_isParticleHit);
301  const MomentumCalculator &calcpxpy (*_calc_detplane);
302  const MomentumCalculator &calcpz (*_calc_tof);
303  _listIsCreated = true;
304  detectorHits_t & detectorhits (_detector->hits());
305  detectorHits_t::iterator dethit (detectorhits.begin());
306  for (; dethit != detectorhits.end(); ++dethit)
307  {
308  if (isParticleHit(*dethit))
309  {
310  particleHit_t hit(_copyandcorrect(*dethit));
311  calcpxpy(*this,hit);
312  calcpz(*this,hit);
313  kartesian2polar(hit);
314  hit[e_au] = hit[roh]*hit[roh] / (2.*_mass_au);
315  hit[e_eV] = 27.2*hit[e_au];
316  _particlehits.push_back(hit);
317  }
318  }
319  }
320  return _particlehits;
321 }
322 
324 {
325  _listIsCreated = false;
326  _particlehits.clear();
327  _detector = detector;
328 }
std::vector< double > detectorHit_t
define a detector hit
void loadSettings(CASSSettings &s)
read the parameters of the condition from the .ini file
Definition: particle.cpp:122
particleHits_t & hits()
retrieve the particle hits
Definition: particle.cpp:296
base class for calculating momenta from a detector hit
a simple position condition
Definition: particle.cpp:151
file contains the classes that calculate the momenta of particles from their detector hits...
bool operator()(const detectorHit_t &dethit) const
the comparison
Definition: particle.cpp:155
Settings for CASS.
Definition: cass_settings.h:30
a combination of conditions
Definition: particle.cpp:195
a Time of Flight condition
Definition: particle.cpp:72
std::vector< detectorHit_t > detectorHits_t
define container for all detector hits
define which of the hitfinders defined above will be used as hit
STL namespace.
bool operator()(const detectorHit_t &dethit) const
the comparison
Definition: particle.cpp:204
void kartesian2polar(particleHit_t &hit)
convert kartesian coordinates to polar coordinates
Definition: particle.cpp:258
a radius position condition
Definition: particle.cpp:109
file contains the classes that describe a delayline detector.
std::vector< double > particleHit_t
define a particle hit
base class of conditions for finding the right particle
Definition: particle.cpp:31
static std::tr1::shared_ptr< MomentumCalculator > instance(const MomCalcType &type)
create instance of requested type
std::pair< double, double > _center
the center of the radius
Definition: particle.cpp:134
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
std::pair< double, double > _xrange
the range in x
Definition: particle.cpp:177
std::pair< IsParticleHit *, IsParticleHit * > _conditions
Definition: particle.cpp:218
static tr1::shared_ptr< IsParticleHit > instance(const ConditionType &type)
create an instance of the chosen class
Definition: particle.cpp:221
value(const QString &key, const QVariant &defaultValue=QVariant()
void loadSettings(CASSSettings &s)
load the settings from .ini file
Definition: particle.cpp:274
void loadSettings(CASSSettings &s)
read the parameters of the condition from the .ini file
Definition: particle.cpp:81
bool operator()(const detectorHit_t &dethit) const
the comparison
Definition: particle.cpp:113
std::pair< double, double > _tofcond
the tof range
Definition: particle.cpp:92
void loadSettings(CASSSettings &s, CFDParameters &p, uint32_t &instrument, size_t &channelNbr)
implementation of loading settings for both CFD classes
Definition: cfd.cpp:210
file contains specialized class that do the settings for cass
double _maxradius
the maximum radius of the condtion
Definition: particle.cpp:137
void associate(DelaylineDetector *detector)
tell which are the detector hits to search through
Definition: particle.cpp:323
file contains the classes that describe a particle that hit a delayline detector. ...
ConditionType
typedef defining the types of available conditions
Definition: particle.cpp:38
void loadSettings(CASSSettings &s)
read the parameters of the condition from the .ini file
Definition: particle.cpp:164
Electron detector
Definition: hdf5-input.ini:62
virtual ~IsParticleHit()
virtual destructor since this is a base class
Definition: particle.cpp:35
std::vector< particleHit_t > particleHits_t
define container for all particle hits
beginGroup(const QString &prefix)
void loadSettings(CASSSettings &s)
read the parameters of the condition from the .ini file
Definition: particle.cpp:211
std::pair< double, double > _yrange
the range in y
Definition: particle.cpp:180
bool operator()(const detectorHit_t &dethit) const
the comparison
Definition: particle.cpp:76