Jpp
JStart.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JSTART__
2 #define __JFIT__JSTART__
3 
4 #include <istream>
5 #include <ostream>
6 
7 
8 /**
9  * \file
10  * Auxiliary method to locate start and end point of muon trajectory.
11  * \author mdejong
12  */
13 namespace JFIT {}
14 namespace JPP { using namespace JFIT; }
15 
16 namespace JFIT {
17 
18  /**
19  * Auxiliary class for start or end point evaluation.
20  */
21  struct JStart {
22  /**
23  * Default constructor.
24  */
25  JStart() :
26  Pmin1(0.0),
27  Pmin2(0.0)
28  {}
29 
30 
31  /**
32  * Constructor.
33  *
34  * \param Pmin1 minimal probability single observation
35  * \param Pmin2 minimal probability each of two consecutive observations
36  */
37  JStart(const double Pmin1,
38  const double Pmin2)
39  {
40  this->Pmin1 = Pmin1;
41  this->Pmin2 = Pmin2;
42  }
43 
44 
45  /**
46  * Check validity of start or end point conditions.
47  *
48  * \return true if valid; else false
49  */
50  bool is_valid() const
51  {
52  return (Pmin1 > 0.0 && Pmin2 > 0.0);
53  }
54 
55 
56  /**
57  * Evaluate start or end point conditions.
58  *
59  * The template parameter should correspond to a data type which has the member method:
60  * <pre>
61  * double getP() const; // return probability
62  * </pre>
63  *
64  * \param observation observation
65  * \return true if start or end point; else false
66  */
67  template<class JHit_t>
68  bool operator()(const JHit_t& observation) const
69  {
70  return observation.getP() < Pmin1;
71  }
72 
73 
74  /**
75  * Evaluate start or end point conditions.
76  *
77  * The template parameter should correspond to a data type which has the member method:
78  * <pre>
79  * double getP() const; // return probability
80  * </pre>
81  *
82  * \param first first observation
83  * \param second second observation
84  * \return true if start or end point; else false
85  */
86  template<class JHit_t>
87  bool operator()(const JHit_t& first,
88  const JHit_t& second) const
89  {
90  return ((first.getP() < Pmin1) ||
91  (first.getP() < Pmin2 && second.getP() < Pmin2));
92  }
93 
94 
95  /**
96  * Get start or end point of muon trajectory.
97  *
98  * The template parameter should correspond to a data type which has the member method:
99  * <pre>
100  * double getP() const; // return probability
101  * </pre>
102  * The input data should have been sorted along the muon path.
103  *
104  * \param __begin begin of data
105  * \param __end end of data
106  */
107  template<class T>
108  inline T find(T __begin, T __end) const
109  {
110  if (__begin != __end) {
111  for (T q = __begin, p = q++; q != __end; ++p, ++q) {
112  if ((*this)(*p,*q)) {
113  return p;
114  }
115  }
116  }
117 
118  return __end;
119  }
120 
121 
122  /**
123  * Read parameters from input.
124  *
125  * \param in input stream
126  * \param parameters parameters
127  * \return input stream
128  */
129  friend inline std::istream& operator>>(std::istream& in, JStart& parameters)
130  {
131  in >> parameters.Pmin1 >> parameters.Pmin2;
132 
133  return in;
134  }
135 
136 
137  /**
138  * Write parameters to output.
139  *
140  * \param out output stream
141  * \param parameters parameters
142  * \return output stream
143  */
144  friend inline std::ostream& operator<<(std::ostream& out, const JStart& parameters)
145  {
146  out << parameters.Pmin1 << ' ' << parameters.Pmin2;
147 
148  return out;
149  }
150 
151 
152  double Pmin1; //!< minimal probability single observation
153  double Pmin2; //!< minimal probability each of two consecutive observations
154  };
155 }
156 
157 #endif
JFIT::JStart::JStart
JStart()
Default constructor.
Definition: JStart.hh:25
JAANET::JHit_t
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
JFIT::JStart::operator>>
friend std::istream & operator>>(std::istream &in, JStart &parameters)
Read parameters from input.
Definition: JStart.hh:129
JFIT
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
JFIT::JStart::operator()
bool operator()(const JHit_t &observation) const
Evaluate start or end point conditions.
Definition: JStart.hh:68
JFIT::JStart
Auxiliary class for start or end point evaluation.
Definition: JStart.hh:21
JFIT::JStart::is_valid
bool is_valid() const
Check validity of start or end point conditions.
Definition: JStart.hh:50
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JFIT::JStart::operator<<
friend std::ostream & operator<<(std::ostream &out, const JStart &parameters)
Write parameters to output.
Definition: JStart.hh:144
JFIT::JStart::JStart
JStart(const double Pmin1, const double Pmin2)
Constructor.
Definition: JStart.hh:37
JFIT::JStart::Pmin2
double Pmin2
minimal probability each of two consecutive observations
Definition: JStart.hh:153
JFIT::JStart::operator()
bool operator()(const JHit_t &first, const JHit_t &second) const
Evaluate start or end point conditions.
Definition: JStart.hh:87
JFIT::JStart::Pmin1
double Pmin1
minimal probability single observation
Definition: JStart.hh:152
JFIT::JStart::find
T find(T __begin, T __end) const
Get start or end point of muon trajectory.
Definition: JStart.hh:108