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

Example program of JGEOMETRY2D::JEllipse2D class. More...

#include <iostream>
#include <vector>
#include "TFile.h"
#include "TEllipse.h"
#include "TGraph2D.h"
#include "TRandom3.h"
#include "JGeometry2D/JRotation2D.hh"
#include "JGeometry2D/JPosition2D.hh"
#include "JGeometry2D/JEllipse2D.hh"
#include "JLang/JManip.hh"
#include "JROOT/JRootToolkit.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 of JGEOMETRY2D::JEllipse2D class.

Author
mdejong

Definition in file JEllipse2D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 27 of file JEllipse2D.cc.

28{
29 using namespace std;
30 using namespace JPP;
31
33 string outputFile;
34 UInt_t seed;
35 int debug;
36
37 try {
38
39 JParser<> zap("Example program of JEllipse2D class.");
40
41 zap['n'] = make_field(numberOfPoints) = 10;
42 zap['o'] = make_field(outputFile) = "ellipse.root";
43 zap['S'] = make_field(seed) = 0;
44 zap['d'] = make_field(debug) = 3;
45
46 zap(argc, argv);
47 }
48 catch(const exception &error) {
49 FATAL(error.what() << endl);
50 }
51
52 gRandom->SetSeed(seed);
53
55
56 for (int i = 0; i != numberOfPoints; ++i) {
57
58 ps.push_back(JPosition2D(gRandom->Gaus(0.0, 1.0),
59 gRandom->Gaus(0.0, 1.0)));
60 }
61
62 try {
63
64 const JEllipse2D ellipse(ps.begin(), ps.end());
65
66 if (debug >= debug_t) {
67 cout << "number of iterations " << ellipse.numberOfIterations << endl;
68 cout << "center: (" << ellipse.getX() << ", " << ellipse.getY() << ")" << endl;
69 cout << "major Semi-Axis: " << ellipse.getMajorAxis() << endl;
70 cout << "minor Semi-Axis: " << ellipse.getMinorAxis() << endl;
71 cout << "rotation (degrees): " << ellipse.getAngle() * 180.0 / PI << endl;
72 }
73
76
77 for (const auto& p : ps) {
78 X.push_back(p.getX());
79 Y.push_back(p.getY());
80 }
81
82 TGraph gs(X.size(), X.data(), Y.data());
83
84 gs.SetName("gs");
85
86 TEllipse ts(ellipse.getX(),
87 ellipse.getY(),
88 ellipse.getMajorAxis(),
89 ellipse.getMinorAxis(),
90 0.0,
91 360.0,
92 ellipse.getAngle() * 180.0 / PI);
93
94 ts.SetFillStyle(0);
95
96 TFile out(outputFile.c_str(), "recreate");
97
98 out << gs;
99 out << ts;
100
101 out.Write();
102 out.Close();
103
104 } catch (const exception& error) {
105 cerr << "error: " << error.what() << endl;
106 }
107
108 return 0;
109}
string outputFile
#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
Data structure for position in two dimensions.
Utility class to parse command line options.
Definition JParser.hh:1664
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).