26{
   28 
   29  string  inputFile;
   32  ULong_t seed;
   34 
   35  try {
   36 
   37    JParser<> zap(
"Example program to find smallest distance between two points.");
 
   38 
   44 
   45    zap(argc, argv);
   46  }
   47  catch(const exception &error) {
   48    FATAL(error.what() << endl);
 
   49  }
   50 
   51  gRandom->SetSeed(seed);
   52 
   54 
   55 
   57 
   58  typedef vector<JVector3D>::const_iterator const_iterator;
   59 
   60 
   61  if (inputFile != "") {
   62 
   63    ifstream in(inputFile.c_str());
   64 
   65    for (
double x, y, z; in >> 
x >> 
y >> z; ) {
 
   67    }
   68 
   69    in.close();
   70 
   72 
   73    NOTICE(
"Seed: " << gRandom->GetSeed() << endl);
 
   74 
   76 
   77      buffer.push_back(
JVector3D(gRandom->Uniform(-1.0, +1.0),
 
   78                                 gRandom->Uniform(-1.0, +1.0),
   79                                 gRandom->Uniform(-1.0, +1.0)));
   80    }
   81 
   83      
   85 
   86      for (const_iterator i = buffer.begin(); i != buffer.end(); ++i)
   87        out << setw(7) << i->getX() << ' ' 
   88            << setw(7) << i->getX() << ' ' 
   89            << setw(7) << i->getZ() << endl;
   90      
   91      out.close();
   92    }
   93  }
   94 
   95  if (buffer.size() < 2) {
   96    FATAL(
"Not enough points." << endl);
 
   97  }
   98 
   99  for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
  100    DEBUG(i->getX() << 
' ' << i->getY() << 
' ' << i->getZ() << endl);
 
  101  }
  102 
  103 
  104  {
  106  
  107    timer.start();
  108 
  109    double dmin = numeric_limits<double>::max();
  110    
  111    for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
  112      for (const_iterator j = i; ++
j != buffer.end(); ) {
 
  113        
  114        const double d = i->getDistance(*j);
  115        
  116        if (d < dmin) {
  117          dmin = d;
  118        }
  119      }
  120    }
  121    
  122    timer.stop();
  123 
  124    cout << 
"Minimal distance " << 
SCIENTIFIC(12,5) << dmin << endl;
 
  125    timer.print(cout);
  126  }
  127 
  128 
  129  JTimer timer(
"O(n log(n))");
 
  130  
  131  timer.start();
  132  
  133  const double dmin = getSmallestDistance3D(buffer.begin(), buffer.end());
  134 
  135  timer.stop();
  136 
  137  cout << 
"Minimal distance " << 
SCIENTIFIC(12,5) << dmin << endl;
 
  138  timer.print(cout);
  139}
#define DEBUG(A)
Message macros.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
Auxiliary class for CPU timing and usage.
 
Data structure for vector in three dimensions.
 
Utility class to parse command line options.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
Auxiliary data structure for floating point format specification.