Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JStart.hh
Go to the documentation of this file.
1#ifndef __JRECONSTRUCTION__JSTART__
2#define __JRECONSTRUCTION__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 */
13namespace JRECONSTRUCTION {}
14namespace JPP { using namespace JRECONSTRUCTION; }
15
16namespace JRECONSTRUCTION {
17
18 /**
19 * Auxiliary class for start or end point evaluation.
20 */
21 struct JStart {
22 /**
23 * Default constructor.
24 */
26 Pmin1(0.0),
27 Pmin2(0.0),
28 Nmax2(0)
29 {}
30
31
32 /**
33 * Constructor.
34 *
35 * \param Pmin1 minimal probability single observation
36 * \param Pmin2 minimal probability for twofold observations
37 * \param Nmax2 maximal number for twofold observations
38 */
39 JStart(const double Pmin1,
40 const double Pmin2,
41 const int Nmax2) :
42 Pmin1(Pmin1),
43 Pmin2(Pmin2),
45 {}
46
47
48 /**
49 * Check validity of start or end point conditions.
50 *
51 * \return true if valid; else false
52 */
53 bool is_valid() const
54 {
55 return (Pmin1 >= 0.0 && Pmin1 <= 1.0 &&
56 Pmin2 >= 0.0 && Pmin2 <= 1.0);
57 }
58
59
60 /**
61 * Get start point of muon trajectory.
62 *
63 * The template parameter should correspond to a data type which has the member method:
64 * <pre>
65 * double getP() const; // return probability
66 * </pre>
67 * The input data should have been sorted along the muon path beforehand.\n
68 * A start point is triggered when an observed probability is less than Pmin1 or
69 * when there are two probabilities less than Pmin2 within Nmax2 consecutive observations.\n
70 * The start or end point can found by providing the data in ascending or descending order, respectively.
71 *
72 * \param __begin begin of data
73 * \param __end end of data
74 * \return start point
75 */
76 template<class T>
77 inline T find(T __begin, T __end) const
78 {
79 for (T p = __begin; p != __end; ++p) {
80
81 if (p->getP() < this->Pmin1) {
82 return p;
83 }
84
85 if (p->getP() < this->Pmin2) {
86 for (T q = p; ++q != __end && distance(p,q) < Nmax2; ) {
87 if (q->getP() < this->Pmin2) {
88 return p;
89 }
90 }
91 }
92 }
93
94 return __end;
95 }
96
97
98 /**
99 * Read parameters from input.
100 *
101 * \param in input stream
102 * \param parameters parameters
103 * \return input stream
104 */
105 friend inline std::istream& operator>>(std::istream& in, JStart& parameters)
106 {
107 in >> parameters.Pmin1 >> parameters.Pmin2 >> parameters.Nmax2;
108
109 return in;
110 }
111
112
113 /**
114 * Write parameters to output.
115 *
116 * \param out output stream
117 * \param parameters parameters
118 * \return output stream
119 */
120 friend inline std::ostream& operator<<(std::ostream& out, const JStart& parameters)
121 {
122 out << parameters.Pmin1 << ' ' << parameters.Pmin2 << ' ' << parameters.Nmax2;
123
124 return out;
125 }
126
127
128 double Pmin1; //!< minimal probability single observation
129 double Pmin2; //!< minimal probability for twofold observations
130 int Nmax2; //!< maximal number for twofold observations
131 };
132}
133
134#endif
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Model fits to data.
Auxiliary class for start or end point evaluation.
Definition JStart.hh:21
int Nmax2
maximal number for twofold observations
Definition JStart.hh:130
bool is_valid() const
Check validity of start or end point conditions.
Definition JStart.hh:53
double Pmin2
minimal probability for twofold observations
Definition JStart.hh:129
friend std::ostream & operator<<(std::ostream &out, const JStart &parameters)
Write parameters to output.
Definition JStart.hh:120
T find(T __begin, T __end) const
Get start point of muon trajectory.
Definition JStart.hh:77
JStart()
Default constructor.
Definition JStart.hh:25
JStart(const double Pmin1, const double Pmin2, const int Nmax2)
Constructor.
Definition JStart.hh:39
friend std::istream & operator>>(std::istream &in, JStart &parameters)
Read parameters from input.
Definition JStart.hh:105
double Pmin1
minimal probability single observation
Definition JStart.hh:128