BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
GemDigitsAnalysis.C
Go to the documentation of this file.
1#include "TCanvas.h"
2#include "TChain.h"
3#include "TH1F.h"
4#include "TH2F.h"
5
6void GemDigitsAnalysis(UInt_t runId = 0, TString type = "pdf")
7{
8 gStyle->SetOptStat(0);
9 /* Load basic libraries */
10 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
11 bmnloadlibs(); // load bmn libraries
12
13 TChain* eveTree = new TChain("cbmsim");
14 TString inName = Form("bmn_run%04d_digi.root", runId);
15 eveTree->Add(inName);
16
17 TClonesArray* GemDigits;
18 eveTree->SetBranchAddress("GEM", &GemDigits);
19
20 Long64_t nEvents = eveTree->GetEntries();
21 cout << nEvents << endl;
22
23 const UInt_t kNST = 8;
24 const UInt_t nStrips[kNST] = {256, 825, 825, 825, 825, 825, 1019, 1019};
25
26 TString name;
27 TH1F* h_X[kNST];
28 TH2F* h_X_2d[kNST];
29 TH1F* h_X0[kNST];
30 TH2F* h_X0_2d[kNST];
31 TH1F* h_Amp[kNST];
32 TH1F* h_XAmp[kNST];
33
34 for (Int_t i = 0; i < kNST; ++i) {
35 name = Form("X_%d", i);
36 h_X[i] = new TH1F(name, name, nStrips[i], 0, nStrips[i]);
37 name = Form("X_color_%d", i);
38 h_X_2d[i] = new TH2F(name, name, nStrips[i], 0, nStrips[i], 1, 0, 1);
39 name = Form("X0_%d", i);
40 h_X0[i] = new TH1F(name, name, 500, 1, 500);
41 name = Form("X0_color_%d", i);
42 h_X0_2d[i] = new TH2F(name, name, 500, 1, 500, 1, 0, 1);
43 name = Form("Amp_%d", i);
44 h_Amp[i] = new TH1F(name, name, 100, 0, 500);
45 name = Form("XAmp_%d", i);
46 h_XAmp[i] = new TH1F(name, name, 500, 0, 1000);
47 }
48
49 for (Int_t iEv = 0; iEv < nEvents; iEv++) {
50 if (iEv % 100 == 0)
51 cout << "EVENT: " << iEv << endl;
52 eveTree->GetEntry(iEv);
53 for (Int_t iDig = 0; iDig < GemDigits->GetEntriesFast(); ++iDig) {
54 BmnGemStripDigit* digX = (BmnGemStripDigit*)GemDigits->At(iDig);
55 Int_t lay = digX->GetStripLayer();
56 if (lay != 0)
57 continue; // use only X
58 Int_t st = digX->GetStation();
59 Int_t str = digX->GetStripNumber();
60 Int_t mod = digX->GetModule();
61 if (mod == 0) {
62 h_X[st]->Fill(str);
63 h_X_2d[st]->Fill(str, 0);
64 } else if (mod == 1 && st == 6) {
65 h_X[st + 1]->Fill(str);
66 h_X_2d[st + 1]->Fill(str, 0);
67 }
68 }
69 }
70
71 const Float_t kThresh = 0.15 * nEvents; // remove signals above threshold (guess it is noisy channels)
72
73 for (Int_t i = 0; i < kNST; ++i)
74 for (Int_t j = 1; j <= h_X[i]->GetNbinsX(); ++j) {
75 if (h_X[i]->GetBinContent(j) > kThresh)
76 h_X[i]->SetBinContent(j, 0.0);
77 for (Int_t k = 1; k <= h_X_2d[i]->GetNbinsY(); ++k)
78 if (h_X_2d[i]->GetBinContent(j, k) > kThresh)
79 h_X_2d[i]->SetBinContent(j, k, 0.0);
80 }
81
82 if (type == "pdf") {
83 TCanvas* SuperCave = new TCanvas("SuperCave", "SuperCave", 66 * 100, 41 * 100);
84 for (Int_t i = 0; i < kNST; ++i) {
85 DrawGemDigitsColz(h_X_2d[i], h_X[i], SuperCave);
86 if (i == 0) {
87 SuperCave->Print(Form("gem_run%04d.pdf(", runId), "");
88 } else if (i == (kNST - 1)) {
89 SuperCave->Print(Form("gem_run%04d.pdf)", runId), "");
90 } else {
91 SuperCave->Print(Form("gem_run%04d.pdf", runId), "");
92 }
93 }
94 delete SuperCave;
95 } else if (type == "png") {
96 TCanvas* SuperCave = new TCanvas("SuperCave", "SuperCave", 66 * 100, 41 * 100);
97 for (Int_t i = 0; i < kNST; ++i) {
98 DrawGemDigitsColz(h_X_2d[i], h_X[i], SuperCave);
99 SuperCave->SaveAs(Form("gem_run%04d_st%d.png", runId, i));
100 }
101 delete SuperCave;
102 }
103}
104
105void DrawGemDigits(TH1F* x0, TH1F* x1, TCanvas* cave, Bool_t right = kFALSE)
106{
107 const Float_t xBig = 66.0;
108 const Float_t yBig = 41.0;
109 const Float_t xSmall = 15.0;
110 const Float_t ySmall = 10.0;
111 const Float_t bigBottMarg = 0.1;
112 const Float_t bigTopMarg = 0.1;
113 const Float_t bigLeftMarg = 0.1;
114 const Float_t bigRightMarg = 0.1;
115
116 cave->cd();
117 TPad* pad1 = new TPad(x1->GetTitle(), x1->GetTitle(), 0, 0, 1, 1.0);
118 pad1->SetMargin(bigLeftMarg, bigRightMarg, bigBottMarg, bigTopMarg);
119 pad1->Draw();
120 pad1->cd();
121 x1->SetFillColor(kBlue - 10);
122 x1->SetLineColor(kBlue);
125 x1->Draw();
126 cave->cd();
127 TPad* pad2;
128 if (!right) {
129 pad2 = new TPad(x0->GetTitle(), x0->GetTitle(), bigLeftMarg, bigBottMarg, xSmall / xBig + bigLeftMarg,
130 ySmall / yBig + bigBottMarg);
131 pad2->SetMargin(0, bigRightMarg, 0, bigTopMarg);
132 } else {
133 pad2 = new TPad(x0->GetTitle(), x0->GetTitle(), 1.0 - bigRightMarg - xSmall / xBig, bigBottMarg,
134 1.0 - bigRightMarg, ySmall / yBig + bigBottMarg);
135 pad2->SetMargin(bigLeftMarg, 0, 0, bigTopMarg);
136 }
137
138 pad2->SetFillStyle(4000);
139 pad2->SetFrameFillColor(0);
140 pad2->SetFrameFillStyle(0);
141 pad2->SetFrameLineWidth(2);
142 pad2->Draw();
143 pad2->cd();
144 x0->SetFillColor(kRed - 10);
145 x0->SetLineColor(kRed);
147 x0->GetXaxis()->SetLabelSize(0.06);
149 x0->GetYaxis()->SetLabelSize(0.06);
150 if (!right) {
151 x0->Draw("Y+X+");
152 } else {
153 x0->Draw("X+");
154 }
155}
156
157void DrawGemDigitsColz(TH2F* h_2d, TH1F* h, TCanvas* cave)
158{
159 const Float_t xBig = 66.0;
160 const Float_t yBig = 41.0;
161 const Float_t xSmall = 15.0;
162 const Float_t ySmall = 10.0;
163 const Float_t bigBottMarg = 0.1;
164 const Float_t bigTopMarg = 0.1;
165 const Float_t bigLeftMarg = 0.1;
166 const Float_t bigRightMarg = 0.1;
167 cave->cd();
168 TPad* pad1 = new TPad(h_2d->GetTitle(), h_2d->GetTitle(), 0, 0, 1.0, 0.5);
169 pad1->SetFrameLineWidth(2);
170 pad1->SetTopMargin(0.0);
171 pad1->Draw();
172 pad1->cd();
173 h_2d->GetXaxis()->SetLabelColor(kWhite);
174 h_2d->GetYaxis()->SetLabelColor(kWhite);
175 h_2d->GetXaxis()->SetTickLength(0);
176 h_2d->GetYaxis()->SetTickLength(0);
177 h_2d->Draw("col");
178 // DrawStrips(h_2d);
179
180 cave->cd();
181 TPad* pad2 = new TPad("", "", 0, 0.5, 1.0, 1.0);
182 pad2->SetBottomMargin(0.0);
183 pad2->SetFrameLineWidth(2);
184 pad2->Draw();
185 pad2->cd();
186 h->SetFillColor(kBlue - 10);
188 h->Draw("X+");
189}
190
192{
193 Int_t nx = h->GetNbinsX();
194 Double_t x1 = h->GetXaxis()->GetXmin();
195 Double_t y1 = h->GetYaxis()->GetXmin();
196 Double_t y2 = h->GetYaxis()->GetXmax();
197 Double_t x = x1;
198
199 TLine l;
200 l.SetLineColor(16);
201
202 for (Int_t i = 0; i < nx; i++) {
203 l.DrawLine(x, y1, x, y2);
204 x = x + h->GetXaxis()->GetBinWidth(i);
205 }
206}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
unsigned int UInt_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
long long Long64_t
kRed
kWhite
kBlue
#define gROOT
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Int_t GetStripNumber()
Int_t GetStripLayer()
Int_t GetStation()
Int_t GetModule()
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 SetLineColor(Color_t lcolor)
virtual void SetBottomMargin(Float_t bottommargin)
void SetFrameFillColor(Color_t color=1)
void SetFrameFillStyle(Style_t styl=0)
virtual void SetTopMargin(Float_t topmargin)
void SetFrameLineWidth(Width_t width=1)
virtual void SetMargin(Float_t left, Float_t right, Float_t bottom, Float_t top)
Double_t GetXmax() const
Double_t GetXmin() const
virtual Double_t GetBinWidth(Int_t bin) const
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
virtual Int_t GetNbinsY() const
TAxis * GetXaxis()
virtual Int_t GetNbinsX() const
TAxis * GetYaxis()
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void SetBinContent(Int_t bin, Double_t content)
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
void SetBinContent(Int_t bin, Double_t content) override
virtual TLine * DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
const char * GetTitle() const override
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
void SetFillStyle(Style_t fstyle) 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
void DrawGemDigitsColz(TH2F *h_2d, TH1F *h, TCanvas *cave)
void GemDigitsAnalysis(UInt_t runId=0, TString type="pdf")
void DrawGemDigits(TH1F *x0, TH1F *x1, TCanvas *cave, Bool_t right=kFALSE)
void DrawStrips(TH2 *h)