44 JParser<> zap(
"Example program to test convex hull and enclosing circle.");
54 catch(
const exception &error) {
55 FATAL(error.what() << endl);
58 gRandom->SetSeed(seed);
69 if (inputFile !=
"") {
71 ifstream
in(inputFile.c_str());
73 for (
double x, y;
in >> x >> y; ) {
74 buffer.push_back(JVector2D(x,y));
81 NOTICE(
"Seed: " << gRandom->GetSeed() << endl);
85 buffer.push_back(JVector2D(gRandom->Uniform(-1.0, +1.0),
86 gRandom->Uniform(-1.0, +1.0)));
93 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i)
94 out <<
FIXED(7,3) << i->getX() <<
' '
95 <<
FIXED(7,3) << i->getY() << endl;
102 FATAL(
"No points to draw." << endl);
105 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
106 DEBUG(
FIXED(7,3) << i->getX() <<
' ' <<
FIXED(7,3) << i->getY() << endl);
109 const JCircle2D circle(buffer.begin(), buffer.end());
117 <<
distance(buffer.begin(),hull.first) << endl);
120 <<
distance(buffer.begin(),hull.first) <<
' '
121 <<
distance(buffer.begin(),hull.second) << endl);
123 DEBUG(
"circle: " << circle.getX() <<
' ' << circle.getY() <<
' ' << circle.getRadius() << endl);
125 double area =
getArea2D(buffer.begin(), hull.second);
127 NOTICE(
"Area: " << area << endl);
133 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
134 if (!
inside2D(buffer.begin(), hull.second, *i)) { ++n[0]; }
135 if (!
inside2D(buffer.begin(), hull.first, hull.second, *i)) { ++n[1]; }
137 if (!
inside2D(buffer.begin(), hull.first, hull.second, *i)) {
142 for (
int i = 0; i !=
sizeof(
n)/
sizeof(n[0]); ++i) {
143 NOTICE(
"Number of points outside [" << i <<
"] " << n[i] << endl);
147 TApplication* tp =
new TApplication(
"user", NULL, NULL);
149 TCanvas cv(
"cv",
"", 400, 400);
151 cv.SetFillStyle(4000);
158 TEllipse ellipse(circle.getX(), circle.getY(), circle.getRadius());
161 const Int_t MAX_BUFFER_SIZE = buffer.size() + 1;
163 Double_t x[MAX_BUFFER_SIZE];
164 Double_t y[MAX_BUFFER_SIZE];
168 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i, ++
N) {
174 Double_t xmin = -2.0;
175 Double_t xmax = +2.0;
176 Double_t ymin = -2.0;
177 Double_t ymax = +2.0;
179 TH2D h2(
"h2",
"", 1, xmin, xmax, 1, ymin, ymax);
185 ellipse.SetLineWidth(2);
191 g.SetMarkerStyle(20);
192 g.SetMarkerColor(kBlack);
193 g.SetMarkerSize(0.7);
199 N =
distance(buffer.begin(), hull.first);
203 g1.SetLineColor(kBlack);
212 N =
distance(buffer.begin(), hull.second);
219 TGraph g2(
N, &x[i], &y[i]);
221 g2.SetLineColor(kRed);
Utility class to parse command line options.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Auxiliary data structure for floating point format specification.
bool inside2D(T __begin, T __end, const JVector2D &pos)
Check if given point is inside a convex polygon.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
double getArea2D(T __begin, T __end)
Get area of a convex polygon.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
static const JConvexHull2D getConvexHull2D
Function object for convex hull determination.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Double_t g1(const Double_t x)
Function.