Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
JEllipse2D.cc
Go to the documentation of this file.
1#include <iostream>
2#include <vector>
3
4#include "TFile.h"
5#include "TEllipse.h"
6#include "TGraph2D.h"
7#include "TRandom3.h"
8
12
13#include "JLang/JManip.hh"
14
15#include "JROOT/JRootToolkit.hh"
16
17#include "Jeep/JParser.hh"
18#include "Jeep/JMessage.hh"
19
20
21/**
22 * \file
23 *
24 * Example program of JGEOMETRY2D::JEllipse2D class.
25 * \author mdejong
26 */
27int main(int argc, char**argv)
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
I/O manipulators.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
Utility class to parse command line options.
#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.
double getY() const
Get y position.
Definition JVector2D.hh:74
double getX() const
Get x position.
Definition JVector2D.hh:63
Utility class to parse command line options.
Definition JParser.hh:1664
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getMajorAxis() const
Get major axis.
double getMinorAxis() const
Get minor axis.
double getAngle() const
Get rotation angle.