Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
PicTree.cxx
1/*
2 * PicTree.cxx
3 *
4 * Created on: 4 lip 2024
5 * Author: daniel
6 */
7
8#include "PicTree.h"
9
10#include <Rtypes.h>
11#include <RtypesCore.h>
12#include <TArc.h>
13#include <TAttFill.h>
14#include <TAttLine.h>
15#include <TCanvas.h>
16#include <TLatex.h>
17#include <TLine.h>
18#include <TROOT.h>
19#include <TString.h>
20#include <algorithm>
21#include <initializer_list>
22#include <iostream>
23#include <vector>
24
25#include "Std.h"
26
27
28namespace Hal {
29
30 PicTree::PicTree() {}
31
32 void PicTree::AddLink(std::initializer_list<Int_t> depths, std::initializer_list<Int_t> ids, Int_t style) {
33 fLinks.push_back(link(depths, ids, style));
34 }
35 void PicTree::AddPoint(Int_t depth, Int_t number, Int_t style, Double_t ratio) {
36 fCircles.push_back(circle(depth, number, style, ratio));
37 };
38
39 void PicTree::SaveAs(TString path) {
40 Bool_t batch = gROOT->IsBatch();
41 gROOT->SetBatch(kTRUE);
42 TCanvas* c1 = new TCanvas("canv", "canv", fWindowWidth, fWindowHeight);
43 c1->Range(0, 0, fWindowWidth, fWindowHeight);
44 fDepthMax = 0;
45 for (int i = 0; i < fMaxExpDepth; i++) {
46 for (auto& acirc : fCircles) {
47 if (acirc.sDepth == i) fDepthMax = i;
48 }
49 }
50 ++fDepthMax;
51 fPoints.resize(fDepthMax);
52 for (int i = 0; i < fDepthMax; i++) {
53 int tiers[] = {0, 0, 0, 0};
54 for (auto& acirc : fCircles) {
55 if (acirc.sDepth == i) tiers[acirc.sStyles]++;
56 }
57 int maxLev = 0;
58 for (int j = 0; j < 4; j++) {
59 if (maxLev < tiers[j]) maxLev = tiers[j];
60 }
61 fPoints[i].resize(maxLev);
62 }
63 for (int i = 0; i < fDepthMax; i++) {
64 int maxLev = fPoints[i].size();
65 double depth = (double) i;
66 double maxNo = (double) maxLev;
67 for (int j = 0; j < fPoints[i].size(); j++) {
68 double collection = j;
69 Double_t Y_step = fWindowHeight / maxNo;
70 Double_t X_step = fWindowWidth / (double) fDepthMax;
71 Double_t X_center = X_step * (depth + 0.5);
72 Double_t Y_center = fWindowHeight - Y_step * (collection + 0.5);
73 fPoints[i][j].first = X_center;
74 fPoints[i][j].second = Y_center;
75 }
76 }
77
78 std::sort(fLinks.begin(), fLinks.end(), [](const link& a, const link& b) { return a.sStyles > b.sStyles; });
79 std::sort(fCircles.begin(), fCircles.end(), [](const circle& a, const circle& b) { return a.sStyles > b.sStyles; });
80
81
82 for (auto& aline : fLinks) {
83 aline.Draw(*this);
84 }
85 for (auto& acirc : fCircles) {
86 acirc.Draw(*this);
87 }
88
89 c1->SaveAs(path.Data());
90 gROOT->SetBatch(batch);
91 }
92
93 PicTree::link::link(std::initializer_list<Int_t> depths, std::initializer_list<Int_t> ids, Int_t style) {
94 {
95 sStyles = style;
96 auto vec = Hal::Std::GetVector(depths);
97 sFromDepth = vec[0];
98 sToDepth = vec[1];
99 auto vec2 = Hal::Std::GetVector(ids);
100 sFromNumber = vec2[0];
101 sToNumber = vec2[1];
102 }
103 }
104
105 void PicTree::link::Draw(const PicTree& tree) {
106
107 Double_t X1 = tree.GetCoords()[sFromDepth][sFromNumber].first;
108 Double_t Y1 = tree.GetCoords()[sFromDepth][sFromNumber].second;
109
110 Double_t X2 = tree.GetCoords()[sToDepth][sToNumber].first;
111 Double_t Y2 = tree.GetCoords()[sToDepth][sToNumber].second;
112 TLine* line = new TLine(X1, Y1, X2, Y2);
113 line->SetLineWidth(4.0);
114 switch (sStyles) {
115 case 0: {
116 line->SetLineWidth(2);
117 line->SetLineStyle(1);
118 line->SetLineColor(kBlack);
119 } break;
120 case 1: {
121 line->SetLineWidth(4);
122 line->SetLineStyle(9);
123 line->SetLineColor(kBlue);
124 } break;
125 default: break;
126 }
127 line->Draw();
128 }
129
130} // namespace Hal
131
132void Hal::PicTree::circle::Draw(const PicTree& tree) {
133
134 Double_t angle_pass = 360.0 * sRatio;
135 const Double_t X_coor = tree.GetCoords()[sDepth][sNumber].first;
136 const Double_t Y_coor = tree.GetCoords()[sDepth][sNumber].second;
137 switch (sStyles) {
138 case 0: {
139 TArc* b2 = new TArc(X_coor, Y_coor, 40, 0, 360);
140 b2->SetFillColor(kRed);
141 b2->Draw();
142 if (sRatio > 0.001) {
143 auto b1 = new TArc(X_coor, Y_coor, 40, 90, 90 - angle_pass);
144 b1->SetFillColor(kGreen);
145 b1->Draw("SAME");
146 }
147
148 } break;
149 case 1: {
150 TArc* b2 = new TArc(X_coor, Y_coor, 50, 0, 360);
151 b2->SetFillColor(kRed + 2);
152 b2->Draw();
153 if (sRatio > 0.001) {
154 auto b1 = new TArc(X_coor, Y_coor, 50, 90, 90 - angle_pass);
155 b1->SetFillColor(kGreen + 2);
156 b1->Draw("SAME");
157 }
158 } break;
159 default: break;
160 }
161 TLatex t;
162 if (sNumber < 10)
163 t.DrawText(X_coor - 10, Y_coor - 12, Form("%i", sNumber));
164 else
165 t.DrawText(X_coor - 15, Y_coor - 17, Form("%i", sNumber));
166 // t.DrawText(0, 0, Form("%i", sNumber));
167}
void AddPoint(Int_t depth, Int_t number, Int_t style, Double_t ratio)
Definition PicTree.cxx:35
void AddLink(std::initializer_list< Int_t > depths, std::initializer_list< Int_t > ids, Int_t style)
Definition PicTree.cxx:32
void SaveAs(TString path)
Definition PicTree.cxx:39