Example program to find smallest distance between two points.
More...
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TRandom3.h"
#include "TH2D.h"
#include "TGraph.h"
#include "TMarker.h"
#include "TCanvas.h"
#include "TApplication.h"
#include "JGeometry2D/JVector2D.hh"
#include "JGeometry2D/JGeometry2DToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
Go to the source code of this file.
|
int | main (int argc, char *argv[]) |
|
Example program to find smallest distance between two points.
- Author
- mdejong
Definition in file JGetSmallestDistance2D.cc.
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 31 of file JGetSmallestDistance2D.cc.
43 JParser<> zap(
"Example program to find smallest distance between two points.");
53 catch(
const exception &error) {
54 FATAL(error.what() << endl);
57 gRandom->SetSeed(seed);
67 if (inputFile !=
"") {
69 ifstream
in(inputFile.c_str());
71 for (
double x,
y;
in >> x >>
y; ) {
72 buffer.push_back(JVector2D(x,y));
79 NOTICE(
"Seed: " << gRandom->GetSeed() << endl);
83 buffer.push_back(JVector2D(gRandom->Uniform(-1.0, +1.0),
84 gRandom->Uniform(-1.0, +1.0)));
91 for (const_iterator
i = buffer.begin();
i != buffer.end(); ++
i)
92 out << setw(7) <<
i->getX() <<
' '
93 << setw(7) <<
i->getY() << endl;
99 if (buffer.size() < 2) {
100 FATAL(
"Not enough points." << endl);
103 for (const_iterator
i = buffer.begin();
i != buffer.end(); ++
i) {
104 DEBUG(
i->getX() <<
' ' <<
i->getY() << endl);
109 JTimer timer(
"classic");
113 double dmin = numeric_limits<double>::max();
115 for (const_iterator
i = buffer.begin();
i != buffer.end(); ++
i) {
116 for (const_iterator
j =
i; ++
j != buffer.end(); ) {
118 const double d =
i->getDistance(*
j);
128 cout <<
"Minimal distance " <<
SCIENTIFIC(12,5) << dmin << endl;
133 JTimer timer(
"O(n log(n))");
141 cout <<
"Minimal distance " <<
SCIENTIFIC(12,5) << dmin << endl;
149 <<
"(" <<
FIXED(7,5) <<
result.second->getX() <<
"," <<
FIXED(7,5) <<
result.second->getY() <<
")" << endl;
153 TApplication* tp =
new TApplication(
"user", NULL, NULL);
155 TCanvas cv(
"cv",
"", 400, 400);
157 cv.SetFillStyle(4000);
164 const Int_t MAX_BUFFER_SIZE = buffer.size() + 1;
166 Double_t x[MAX_BUFFER_SIZE];
167 Double_t y[MAX_BUFFER_SIZE];
171 for (const_iterator
i = buffer.begin();
i != buffer.end(); ++
i, ++
N) {
177 Double_t
xmin = -1.1;
178 Double_t
xmax = +1.1;
179 Double_t ymin = -1.1;
180 Double_t ymax = +1.1;
182 TH2D h2(
"h2",
"", 1000,
xmin,
xmax, 1000, ymin, ymax);
190 g.SetMarkerStyle(20);
191 g.SetMarkerColor(kBlack);
192 g.SetMarkerSize(0.7);
195 TMarker m1(
result.first ->getX(),
result.first ->getY(), 20);
196 TMarker m2(
result.second->getX(),
result.second->getY(), 20);
198 m1.SetMarkerColor(kRed);
199 m2.SetMarkerColor(kRed);
201 m1.SetMarkerSize(0.7);
202 m2.SetMarkerSize(0.7);
Utility class to parse command line options.
static const JSmallestDistance2D getSmallestDistance2D
Function object for smallest distance determination.
Auxiliary data structure for floating point format specification.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Auxiliary data structure for floating point format specification.
#define DEBUG(A)
Message macros.