-
Notifications
You must be signed in to change notification settings - Fork 1
/
memoryManagement.C
74 lines (55 loc) · 1.64 KB
/
memoryManagement.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <utility>
#include <vector>
#include <algorithm>
class my_point
{
public:
my_point(UInt_t p_i, Double_t p_x, Double_t p_y) : index(p_i), xcoord(p_x), ycoord(p_y) {}
~my_point() {}
friend bool operator< (const my_point& lhs, const my_point& rhs) { return lhs.xcoord < rhs.xcoord; }
public:
UInt_t index;
Double_t xcoord;
Double_t ycoord;
};
void ConstructGraph(TGraph* inGraph);
void memoryManagement()
{
gStyle->SetMarkerSize(1);
gStyle->SetMarkerStyle(20);
gStyle->SetMarkerColor(kRed);
TCanvas* canvFunc = new TCanvas("canvFunc", "canvFunc", 100, 100, 1000, 600);
TF1* func = new TF1("func", "sin(10.0*x)", 0., 1.);
canvFunc->cd();
func->Draw();
func->SetLineColor(kBlack);
gPad->SetGrid(1,1);
TRandom3* rndGen = new TRandom3();
TGraph* graphArray[10];
TCanvas* canvasArray[10];
std::vector<my_point> data[10];
for (UInt_t iGraph=0; iGraph<10; iGraph++) {
graphArray[iGraph] = new TGraph();
TString canvasName;
canvasName.Form("canvas_%d", iGraph);
canvasArray[iGraph] = new TCanvas(canvasName, canvasName);
for (UInt_t iPoint=0; iPoint<100; iPoint++) {
Double_t x = rndGen->Rndm(); // from 0.0 to 1.0
Double_t y = func->Eval(x);
my_point pointObj(iPoint, x, y);
data[iGraph].push_back(pointObj);
} // iPoint
std::sort(data[iGraph].begin(), data[iGraph].end());
std::vector<my_point>::iterator iter;
UInt_t counter=0;
for (iter = data[iGraph].begin(); iter != data[iGraph].end(); ++iter) {
graphArray[iGraph]->SetPoint(counter++, iter->xcoord, iter->ycoord);
}
graphArray[iGraph]->Draw();
ConstructGraph(graphArray[iGraph]);
} // iGraph
return;
}
void ConstructGraph(TGraph* inGraph)
{
}