Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JWatershed.cc File Reference

Example program to test JGEOMETRY3D::JRotation3D class. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include "TRandom3.h"
#include "JMath/JConstants.hh"
#include "JMath/JWatershed.hh"
#include "JLang/JManip.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JGEOMETRY3D::JRotation3D class.

Author
mdejong

Definition in file JWatershed.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 88 of file JWatershed.cc.

89{
90 using namespace std;
91 using namespace JPP;
92
93 int numberOfEvents;
95 UInt_t seed;
96 double Y;
97 int debug;
98
99 try {
100
101 JParser<> zap("Example program to test watershed algorithm.");
102
103 zap['n'] = make_field(numberOfEvents) = 1;
104 zap['N'] = make_field(numberOfPoints) = 10;
105 zap['S'] = make_field(seed) = 0;
106 zap['Y'] = make_field(Y) = 0.0;
107 zap['d'] = make_field(debug) = 3;
108
109 zap(argc, argv);
110 }
111 catch(const exception &error) {
112 FATAL(error.what() << endl);
113 }
114
115
116 gRandom->SetSeed(seed);
117
118
119 const int M = 10; // number of maxima
120 const int N = numeric_limits<int>::max();
121
122 for (int count = 0; count != numberOfEvents; ++count) {
123
125
126 for (int i = 0; i != numberOfPoints; ++i) {
127 data.push_back(gRandom->Uniform(0.0, M * PI));
128 }
129
130 if (debug >= debug_t) {
131 for (const data_type& i : data) {
132 cout << ps(i) << endl;
133 }
134 }
135
136 vector<data_type>::iterator __end = watershed(data.begin(), data.end(), getValue, getDistance, Y, N);
137
138 DEBUG("number of soultions " << distance(data.begin(),__end) << endl);
139
140 ASSERT(distance(data.begin(), __end) > 0 && distance(data.begin(), __end) <= N, "number of solutions");
141
142 if (debug >= debug_t) {
143
144 vector<data_type> buffer = data;
145
146 vector<data_type>::iterator p1 = buffer.begin();
147
148 for (vector<data_type>::iterator i = data.begin(); i != __end; ++i) {
149
150 cout << ps(*i) << " | ";
151
152 auto compare = [i](const data_type first, const data_type second)
153 {
154 return getDistance(*i,first) < getDistance(*i,second);
155 };
156
157 sort(p1, buffer.end(), compare);
158
159 double y = getValue(*p1);
160
161 ++p1;
162
163 if (p1 != buffer.end()) {
164
165 for (vector<data_type>::iterator p2 = next(p1); p2 != buffer.end() &&
166 (getValue(*p1) <= y + Y ||
167 getValue(*p2) <= y);
168 ++p1, ++p2) {
169
170 cout << ' ' << ps(*p1) << ' ' << FIXED(6,3) << getDistance(*i,*p1);
171
172 y = getValue(*p1);
173 }
174 }
175
176 cout << endl;
177 }
178 }
179
180 if (distance(data.begin(), __end) > 1) {
181
182 {
183 auto compare = [](const data_type first, const data_type second)
184 {
185 return getValue(first) > getValue(second);
186 };
187
188 ASSERT(is_sorted(data.begin(), __end, compare), "test if maxima are sorted");
189 }
190 {
191 for (vector<data_type>::iterator p = data.begin(); p != __end; ++p) {
192 for (vector<data_type>::iterator q = p; ++q != __end; ) {
193
194 const ps p1(*p);
195 const ps p2(*q);
196
197 if (p1.l == p2.l) { ASSERT(p2.y <= p1.y, "test if maxima " << p1 << " and " << p2 << " are not compatible"); }
198 }
199 }
200 }
201 {
204
205 for (vector<data_type>::iterator i = data.begin(); i != __end; ++i) {
206 m1[ps(*i).l].push_back(*i);
207 }
208
209 for (vector<data_type>::iterator i = __end; i != data.end(); ++i) {
210 m2[ps(*i).l].push_back(*i);
211 }
212
213 auto compare = [](const data_type first, const data_type second)
214 {
215 return getValue(first) > getValue(second);
216 };
217
218 for (auto& i : m1) {
219 ASSERT(is_sorted(i.second.begin(), i.second.end(), compare), "test if maxima are sorted in bin " << i.first);
220 }
221 for (auto& i : m2) {
222 sort(i.second.begin(), i.second.end(), compare);
223 }
224
225 for (const auto& i : m1) {
226
227 const ps p1(i.second[0]);
228
229 if (m2.count(p1.l)) {
230
231 const ps p2(m2[p1.l][0]);
232
233 ASSERT(p1.y >= p2.y, "test maximum in " << p1.l << " " << p1 << " " << p2);
234 }
235 }
236 }
237 }
238 }
239
240 return 0;
241}
TPaveText * p1
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
int numberOfPoints
Definition JResultPDF.cc:22
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse command line options.
Definition JParser.hh:1664
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition JScale.hh:47
T watershed(T __begin, T __end, const JFunction_t &getValue, const JDistance_t &getDistance, double Y, int N=std::numeric_limits< int >::max())
Watershed algorithm.
Definition JWatershed.hh:29
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Data structure for measured coincidence rates of all pairs of PMTs in optical module.
Definition JFitK40.hh:110