Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCylinder3D.cc File Reference

Example program to test intersection of straight line with cylinder. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include "TRandom3.h"
#include "JGeometry3D/JAxis3D.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JGeometry3D/JGeometry3DToolkit.hh"
#include "Jeep/JPrint.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 intersection of straight line with cylinder.

Author
mdejong

Definition in file JCylinder3D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file JCylinder3D.cc.

23 {
24  using namespace std;
25 
26  int numberOfEvents;
27  double precision;
28  UInt_t seed;
29  int debug;
30 
31  try {
32 
33  JParser<> zap("Example program to test intersection of straight line with cylinder.");
34 
35  zap['n'] = make_field(numberOfEvents) = 1000;
36  zap['e'] = make_field(precision) = 1.0e-12;
37  zap['S'] = make_field(seed) = 0;
38  zap['d'] = make_field(debug) = 3;
39 
40  zap(argc, argv);
41  }
42  catch(const exception &error) {
43  FATAL(error.what() << endl);
44  }
45 
46  gRandom->SetSeed(seed);
47 
48 
49  using namespace JPP;
50 
51  const JCylinder3D cylinder(JCircle2D(JVector2D(0.0,0.0), 2.0), -1.0, +1.0);
52 
53 
54  int number_of_errors = 0;
55  int number_of_events = 0;
56 
57  for (int i = 0; i != numberOfEvents; ++i) {
58 
59  STATUS(setw(4) << i << '\r'); DEBUG(endl);
60 
61  const double x = gRandom->Uniform(-1.0, +1.0);
62  const double y = gRandom->Uniform(-1.0, +1.0);
63  const double z = gRandom->Uniform(-1.0, +1.0);
64 
65  double dx;
66  double dy;
67  double dz;
68 
69  gRandom->Sphere(dx, dy, dz, 1.0);
70 
71  JAxis3D axis(JVector3D(x, y, z), JVersor3D(dx, dy, dz));
72 
73  JCylinder3D::intersection_type intersection = cylinder.getIntersection(axis);
74 
75  const pair<double, bool> path[] = {
76  make_pair(intersection.first - 1*precision, false),
77  make_pair(2*precision, true),
78  make_pair(intersection.second - intersection.first - 2*precision, true),
79  make_pair(2*precision, false)
80  };
81 
82  ++number_of_events;
83 
84  bool ok = true;
85 
86  const int N = sizeof(path)/sizeof(path[0]);
87 
88  JVector3D pos[N];
89 
90  for (int i = 0; i != N; ++i) {
91 
92  axis.move(path[i].first);
93 
94  if ((getDistance(cylinder, axis.getPosition()) < 1e-3*precision) != path[i].second) {
95  ok = false;
96  }
97 
98  pos[i] = axis.getPosition();
99  }
100 
101  if (!ok) {
102 
103  for (int i = 0; i != N; ++i) {
104  cout << endl << "point[" << noshowpos << setw(1) << i << "] = "
105  << showpos << FIXED(9,5) << pos[i].getX() << ' '
106  << showpos << FIXED(9,5) << pos[i].getY() << ' '
107  << showpos << FIXED(9,5) << pos[i].getZ() << ' '
108  << SCIENTIFIC(12,3) << cylinder.getDistance(pos[i]) << ' '
109  << (cylinder.getDistance(pos[i]) < 1e-3*precision ? "in" : "out") << endl;
110  }
111  }
112 
113  if (!ok) {
114  ++number_of_errors;
115  }
116  }
117  STATUS(endl);
118 
119  NOTICE("Number of errors: " << number_of_errors << " out of " << number_of_events << " events." << endl);
120 
121  ASSERT(number_of_events > 0);
122  ASSERT(number_of_errors == 0);
123 
124  return 0;
125 }
Utility class to parse command line options.
Definition: JParser.hh:1517
#define STATUS(A)
Definition: JMessage.hh:63
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define NOTICE(A)
Definition: JMessage.hh:64
$WORKDIR driver txt done cat $WORKDIR driver txt<< EOFprocess ${DATAFILTER}$FILTER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataFilter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAFILTER}-P $PORT</dev/null > &/dev/null &))';process ${DATAWRITER}$WRITER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataWriter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAWRITER}</dev/null > &/dev/null &))';print enterevent ev_init{RC_CMD}event ev_reset{RC_CMD}event ev_init{RC_CMD}event ev_configure{RC_DFLTR%<$WORKDIR/ev_configure_datafilter.txt > RC_DQSIM<$WORKDIR/ev_configure_dqsimulator.txt > RC_DWRT path
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62