BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
DchDigitsAnalysis.C
Go to the documentation of this file.
1#include "TCanvas.h"
2#include "TChain.h"
3#include "TGraph.h"
4#include "TH1F.h"
5#include "TH2F.h"
6#include "TLine.h"
7#include "TMath.h"
8
9using namespace TMath;
10
11const UInt_t kNPLANES = 16;
12const UInt_t kNREALWIRES = 240;
13const UInt_t kNWIRES = 256;
14const Int_t Number = 4;
15const Int_t nb = 100;
16const Float_t angles[kNPLANES] = {135, 135, 45, 45, 90, 90, 180, 180, 135, 135, 45, 45, 90, 90, 180, 180};
17const TString names[kNPLANES] = {"VA_1", "VB_1", "UA_1", "UB_1", "YA_1", "YB_1", "XA_1", "XB_1",
18 "VA_2", "VB_2", "UA_2", "UB_2", "YA_2", "YB_2", "XA_2", "XB_2"};
19
20void DchDigitsAnalysis(UInt_t runId = 0, TString type = "pdf")
21{
22 gStyle->SetOptStat(0);
23 /* Load basic libraries */
24 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
25 bmnloadlibs(); // load bmn libraries
26
27 TChain* eveTree = new TChain("cbmsim");
28 TString inName = Form("bmn_run%04d_digi.root", runId);
29 eveTree->Add(inName);
30
31 TClonesArray* DchDigits;
32 eveTree->SetBranchAddress("DCH", &DchDigits);
33
34 Long64_t nEvents = eveTree->GetEntries();
35 cout << nEvents << endl;
36
37 TH1F* h_wires[kNPLANES];
38 Float_t v_wires[kNPLANES][kNWIRES] = {};
39
40 for (Int_t i = 0; i < kNPLANES; ++i)
41 h_wires[i] = new TH1F(names[i], names[i], kNREALWIRES, 0, kNREALWIRES);
42
43 for (Int_t iEv = 0; iEv < nEvents; iEv++) {
44 if (iEv % 100 == 0)
45 cout << "EVENT: " << iEv << endl;
46 eveTree->GetEntry(iEv);
47 for (Int_t iDig = 0; iDig < DchDigits->GetEntriesFast(); ++iDig) {
48 BmnDchDigit* dig = (BmnDchDigit*)DchDigits->At(iDig);
49 Int_t plane = dig->GetPlane();
50 Int_t wire = dig->GetWireNumber();
51
52 v_wires[plane][wire] += 1;
53 if (wire > kNREALWIRES - 1) {
54 wire -= 128; // 8 * 16 last preamplifier setup behind hole, so move signal in correct place
55 }
56 h_wires[plane]->Fill(wire);
57 }
58 }
59
60 for (Int_t i = 0; i < kNPLANES; ++i) {
61 Float_t maxSig = 0.0;
62 for (Int_t j = 0; j < kNWIRES; ++j) {
63 Float_t sig = v_wires[i][j];
64 if (sig > maxSig)
65 maxSig = sig;
66 }
67 for (Int_t j = 0; j < kNWIRES; ++j) {
68 v_wires[i][j] /= maxSig;
69 }
70 }
71
72 Int_t myPalette[nb];
73 Double_t R[Number] = {0.00, 0.00, 1.00, 1.00};
74 Double_t G[Number] = {0.00, 1.00, 0.65, 0.00};
75 Double_t B[Number] = {1.00, 0.00, 0.00, 0.00};
76 Double_t Length[Number] = {0.0, 0.33, 0.66, 1.0};
77
79 for (Int_t i = 0; i < nb; ++i) {
80 myPalette[i] = FI + i;
81 }
82
83 if (type == "pdf") {
84 TCanvas* SuperCave = new TCanvas("SuperCave", "SuperCave", 1000, 1500);
85 for (Int_t i = 0; i < kNPLANES; ++i) {
86
87 SuperCave->cd();
88 TPad* pad1 = new TPad("", "", 0, 0, 1.0, 2.0 / 3.0);
89 // pad1->SetMargin(0.16, 0.16, 0.01, 0.0);
90 DrawWires(pad1, myPalette, v_wires[i], angles[i]);
91 SuperCave->cd();
92 TPad* pad2 = new TPad("", "", 0, 2.0 / 3.0, 1.0, 1.0);
93 // pad2->SetMargin(0.16, 0.16, 0.0, 0.2);
94 pad2->SetBottomMargin(0.0);
95 pad2->Draw();
96 pad2->cd();
97 h_wires[i]->SetLineWidth(2);
98 h_wires[i]->SetFillColor(kBlue - 10);
99 h_wires[i]->SetLineColor(kBlue);
100 h_wires[i]->GetXaxis()->SetLabelSize(0.05);
101 h_wires[i]->GetYaxis()->SetLabelSize(0.05);
102 h_wires[i]->Draw("X+");
103
104 // DrawGemDigitsColz(h_wires_2d[i], h_wires[i], SuperCave);
105 if (i == 0) {
106 SuperCave->Print(Form("dch_run%04d.pdf(", runId), "");
107 } else if (i == (kNPLANES - 1)) {
108 SuperCave->Print(Form("dch_run%04d.pdf)", runId), "");
109 } else {
110 SuperCave->Print(Form("dch_run%04d.pdf", runId), "");
111 }
112 }
113 delete SuperCave;
114 } else if (type == "png") {
115 TCanvas* SuperCave = new TCanvas("SuperCave", "SuperCave", 1000, 1500);
116 for (Int_t i = 0; i < kNPLANES; ++i) {
117
118 SuperCave->cd();
119 TPad* pad1 = new TPad("", "", 0, 0, 1.0, 2.0 / 3.0);
120 pad1->SetMargin(0.16, 0.16, 0.01, 0.0);
121 DrawWires(pad1, myPalette, v_wires[i], angles[i]);
122 SuperCave->cd();
123 TPad* pad2 = new TPad("", "", 0, 2.0 / 3.0, 1.0, 1.0);
124 pad2->SetMargin(0.16, 0.16, 0.0, 0.2);
125 // pad2->SetBottomMargin(0.0);
126 pad2->Draw();
127 pad2->cd();
128 h_wires[i]->SetLineWidth(2);
129 h_wires[i]->SetFillColor(kBlue - 10);
130 h_wires[i]->SetLineColor(kBlue);
131 h_wires[i]->GetXaxis()->SetLabelSize(0.05);
132 h_wires[i]->GetYaxis()->SetLabelSize(0.05);
133 h_wires[i]->Draw("X+");
134 SuperCave->SaveAs(Form("dch_run%04d_plane%d.png", runId, i));
135 }
136 delete SuperCave;
137 }
138
139 TCanvas* chmb1 = new TCanvas("DCH-1", "DCH-1", 1000, 1000);
140 chmb1->cd();
141 for (Int_t i = 0; i < kNPLANES / 2; ++i) {
142 DrawAllWires(chmb1, myPalette, v_wires[i], angles[i], i);
143 }
144 chmb1->SaveAs("DCH1_wires.png");
145 TCanvas* chmb2 = new TCanvas("DCH-2", "DCH-2", 1000, 1000);
146 chmb2->cd();
147 for (Int_t i = kNPLANES / 2; i < kNPLANES; ++i) {
148 DrawAllWires(chmb2, myPalette, v_wires[i], angles[i], i);
149 }
150 chmb2->SaveAs("DCH2_wires.png");
151}
152
153void DrawAllWires(TCanvas* c, Int_t* palette, Float_t* wires, Float_t ang, Short_t planeId)
154{
155 const UInt_t kNANGLE = 8;
156 Double_t l = c->GetAbsWNDC();
157 Double_t a = l / (1 + Sqrt2());
158 Double_t b = l / (2 + Sqrt2());
159 Double_t xPol[kNANGLE] = {b, 0, 0, b, b + a, l, l, b + a};
160 Double_t yPol[kNANGLE] = {0, b, b + a, l, l, b + a, b, 0};
161 TGraph* gr = new TGraph(kNANGLE, xPol, yPol);
162 gr->GetXaxis()->SetRangeUser(0.0, 1.0);
163 gr->GetYaxis()->SetRangeUser(0.0, 1.0);
164 gr->SetTitle("");
165 gr->SetLineWidth(3);
166 gr->GetXaxis()->SetLabelColor(0);
167 gr->GetXaxis()->SetTickLength(0);
168 gr->GetYaxis()->SetLabelColor(0);
169 gr->GetYaxis()->SetTickLength(0);
170 gr->SetFillStyle(4000);
171 // gr->Draw("la");
172 Float_t w = l / kNREALWIRES;
173 Float_t x0 = 0.0;
174 Float_t x1 = 0.0;
175 Float_t y0 = 0.0;
176 Float_t y1 = 0.0;
177
178 TLine line;
179 line.SetLineWidth(2);
180 for (Int_t j = 0; j < kNWIRES; ++j) {
181
182 if (j >= 112 && j < 128) {
183 x0 = w * j;
184 x1 = x0;
185 y0 = 0;
186 y1 = l / 2;
187 } else if (j > kNREALWIRES - 1) {
188 x0 = w * (j - 128);
189 x1 = x0;
190 y0 = l / 2;
191 y1 = l;
192 } else {
193 x0 = w * j;
194 x1 = x0;
195 if (x0 <= b) {
196 y0 = -x0 + b;
197 y1 = x0 + a + b;
198 } else if (x0 >= a + b) {
199 y0 = -x0 + 2 * a + 3 * b;
200 y1 = x0 - a - b;
201 } else {
202 y0 = 0;
203 y1 = l;
204 }
205 }
206
207 Int_t colorId = Int_t(wires[j] * (nb - 1));
208 line.SetLineColor(palette[colorId]);
209 line.SetLineColorAlpha(palette[colorId], 0.9 - 0.9 / 7 * planeId); // transparency
210 if (colorId == 0) {
211 line.SetLineColor(kWhite);
212 line.SetLineColorAlpha(kWhite, planeId * 0.1);
213 }
214 Float_t sinPhi = Sin(ang * DegToRad());
215 Float_t cosPhi = Cos(ang * DegToRad());
216 Float_t x0_ = (x0 - l / 2) * cosPhi - (y0 - l / 2) * sinPhi + l / 2;
217 Float_t y0_ = (x0 - l / 2) * sinPhi + (y0 - l / 2) * cosPhi + l / 2;
218 Float_t x1_ = (x1 - l / 2) * cosPhi - (y1 - l / 2) * sinPhi + l / 2;
219 Float_t y1_ = (x1 - l / 2) * sinPhi + (y1 - l / 2) * cosPhi + l / 2;
220 line.DrawLine(x0_, y0_, x1_, y1_);
221 x0 += w;
222 x1 = x0;
223 }
224 TEllipse* hole = new TEllipse((a + 2 * b) / 2, (a + 2 * b) / 2, (a + 2 * b) / 30);
225 hole->Draw("same");
226}
227
228void DrawWires(TPad* pad, Int_t* palette, Float_t* wires, Float_t ang)
229{
230
231 pad->Draw();
232 pad->cd();
233 const UInt_t kNANGLE = 8;
234 Double_t l = pad->GetAbsWNDC();
235 Double_t a = l / (1 + Sqrt2());
236 Double_t b = l / (2 + Sqrt2());
237 Double_t xPol[kNANGLE] = {b, 0, 0, b, b + a, l, l, b + a};
238 Double_t yPol[kNANGLE] = {0, b, b + a, l, l, b + a, b, 0};
239 TGraph* gr = new TGraph(kNANGLE, xPol, yPol);
240 gr->GetXaxis()->SetRangeUser(0.0, 1.0);
241 gr->GetYaxis()->SetRangeUser(0.0, 1.0);
242 gr->SetTitle("");
243 gr->SetLineWidth(3);
244 gr->GetXaxis()->SetLabelColor(0);
245 gr->GetXaxis()->SetTickLength(0);
246 gr->GetYaxis()->SetLabelColor(0);
247 gr->GetYaxis()->SetTickLength(0);
248 gr->Draw("la");
249 Float_t w = l / kNREALWIRES;
250 Float_t x0 = 0.0;
251 Float_t x1 = 0.0;
252 Float_t y0 = 0.0;
253 Float_t y1 = 0.0;
254
255 TLine line;
256 line.SetLineWidth(3);
257 for (Int_t j = 0; j < kNWIRES; ++j) {
258
259 if (j >= 112 && j < 128) {
260 x0 = w * j;
261 x1 = x0;
262 y0 = 0;
263 y1 = l / 2;
264 } else if (j > kNREALWIRES - 1) {
265 x0 = w * (j - 128);
266 x1 = x0;
267 y0 = l / 2;
268 y1 = l;
269 } else {
270 x0 = w * j;
271 x1 = x0;
272 if (x0 <= b) {
273 y0 = -x0 + b;
274 y1 = x0 + a + b;
275 } else if (x0 >= a + b) {
276 y0 = -x0 + 2 * a + 3 * b;
277 y1 = x0 - a - b;
278 } else {
279 y0 = 0;
280 y1 = l;
281 }
282 }
283
284 Int_t colorId = Int_t(wires[j] * (nb - 1));
285 line.SetLineColor(palette[colorId]);
286 if (colorId == 0)
287 line.SetLineColor(kWhite);
288 Float_t sinPhi = Sin(ang * DegToRad());
289 Float_t cosPhi = Cos(ang * DegToRad());
290 Float_t x0_ = (x0 - l / 2) * cosPhi - (y0 - l / 2) * sinPhi + l / 2;
291 Float_t y0_ = (x0 - l / 2) * sinPhi + (y0 - l / 2) * cosPhi + l / 2;
292 Float_t x1_ = (x1 - l / 2) * cosPhi - (y1 - l / 2) * sinPhi + l / 2;
293 Float_t y1_ = (x1 - l / 2) * sinPhi + (y1 - l / 2) * cosPhi + l / 2;
294 line.DrawLine(x0_, y0_, x1_, y1_);
295 x0 += w;
296 x1 = x0;
297 }
298 TEllipse* hole = new TEllipse((a + 2 * b) / 2, (a + 2 * b) / 2, (a + 2 * b) / 30);
299 hole->Draw("same");
300}
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
float Float_t
short Short_t
double Double_t
long long Long64_t
kWhite
kBlue
#define gROOT
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Short_t GetWireNumber() const
Definition BmnDchDigit.h:19
UChar_t GetPlane() const
Definition BmnDchDigit.h:18
virtual void SetLabelSize(Float_t size=0.04)
virtual void SetTickLength(Float_t length=0.03)
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
virtual void SetFillColor(Color_t fcolor)
virtual void SetFillStyle(Style_t fstyle)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColorAlpha(Color_t lcolor, Float_t lalpha)
virtual void SetLineColor(Color_t lcolor)
virtual void SetBottomMargin(Float_t bottommargin)
virtual void SetMargin(Float_t left, Float_t right, Float_t bottom, Float_t top)
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
TVirtualPad * cd(Int_t subpadnumber=0) override
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
static Int_t CreateGradientColorTable(UInt_t Number, Double_t *Stops, Double_t *Red, Double_t *Green, Double_t *Blue, UInt_t NColors, Float_t alpha=1., Bool_t setPalette=kTRUE)
void Draw(Option_t *option="") override
void Draw(Option_t *chopt="") override
TAxis * GetXaxis() const
TAxis * GetYaxis() const
void SetTitle(const char *title="") override
TAxis * GetXaxis()
TAxis * GetYaxis()
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual TLine * DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
Double_t GetAbsWNDC() const override
void SaveAs(const char *filename="", Option_t *option="") const override
TVirtualPad * cd(Int_t subpadnumber=0) override
void Draw(Option_t *option="") override
void Print(const char *filename, Option_t *option) override
const Float_t angles[kNPLANES]
const TString names[kNPLANES]
const UInt_t kNPLANES
const UInt_t kNWIRES
void DrawAllWires(TCanvas *c, Int_t *palette, Float_t *wires, Float_t ang, Short_t planeId)
void DchDigitsAnalysis(UInt_t runId=0, TString type="pdf")
const Int_t Number
const UInt_t kNREALWIRES
void DrawWires(TPad *pad, Int_t *palette, Float_t *wires, Float_t ang)
const Int_t nb
constexpr Double_t G()
constexpr Double_t Sqrt2()
constexpr Double_t DegToRad()
Double_t Cos(Double_t)
constexpr Double_t R()
Double_t Sin(Double_t)