BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
drawResidualsSRC.C
Go to the documentation of this file.
1
2#include <FairHit.h>
3#include <Rtypes.h>
4#include <TCanvas.h>
5#include <TChain.h>
6#include <TClonesArray.h>
7#include <TFitResultPtr.h>
8#include <TGraph.h>
9#include <TH2F.h>
10#include <TLatex.h>
11#include <TString.h>
12#include <TStyle.h>
13
14R__ADD_INCLUDE_PATH($VMCWORKDIR)
15#include "macro/run/bmnloadlibs.C"
16//
17void drawResidualsSRC(TString fileName = "../run/srcdst_3332.root", Int_t nEvents = 50000)
18{
19 bmnloadlibs(); // load libraries
20
21 TChain* out = new TChain("bmndata");
22 out->Add(fileName.Data());
23
24 cout << "#recorded entries = " << out->GetEntries() << endl;
25
26 TClonesArray* dchHits = nullptr;
27 out->SetBranchAddress("BmnDchHit", &dchHits);
28 TClonesArray* gemTracks = nullptr;
29 out->SetBranchAddress("BmnGemTrack", &gemTracks);
30 TClonesArray* cscHits = nullptr;
31 out->SetBranchAddress("BmnCSCHit", &cscHits);
32 TClonesArray* tof700Hits = nullptr;
33 out->SetBranchAddress("BmnTof700Hit", &tof700Hits);
34
35 const Int_t nDet = 4;
36 const Int_t nRes = 2;
37
38 TString namesDet[nDet] = {"CSC", "DCH1", "TOF-700", "DCH2"};
39 TString namesRes[nRes] = {"X-residuals", "Y-residuals"};
40
41 gStyle->SetOptStat(0);
42 gStyle->SetPalette(53); //(kGreyScale);
43
44 TH1F* hist[nDet][nRes];
45
46 const Int_t nMod = 60;
47 TH1F* hResTof700Mod[nMod][nRes];
48 for (Int_t iMod = 0; iMod < nMod; iMod++) {
49 for (Int_t jRes = 0; jRes < nRes; jRes++) {
50 TString histName = Form("TOF-700 mod-%d %s", iMod, namesRes[jRes].Data());
51 hResTof700Mod[iMod][jRes] = new TH1F(histName, histName, 100, -7, 7);
52 }
53 }
54
55 for (Int_t iDet = 0; iDet < nDet; iDet++) {
56 for (Int_t jRes = 0; jRes < nRes; jRes++) {
57 TString histName = namesDet[iDet] + namesRes[jRes];
58 TString histNameEv = namesDet[iDet] + namesRes[jRes] + "Ev";
59 hist[iDet][jRes] = new TH1F(histName, "", 100, -7, 7);
60 }
61 }
62
63 for (Int_t iEv = 0; iEv < nEvents; iEv++) {
64 out->GetEntry(iEv);
65 if (iEv % 1000 == 0)
66 printf("event: %d\n", iEv);
67 for (Int_t iHit = 0; iHit < cscHits->GetEntriesFast(); iHit++) {
68 BmnHit* hit = (BmnHit*)cscHits->At(iHit);
69 hist[0][0]->Fill(hit->GetResX());
70 hist[0][1]->Fill(hit->GetResY());
71 }
72 for (Int_t iHit = 0; iHit < dchHits->GetEntriesFast(); iHit++) {
73 BmnHit* hit = (BmnHit*)dchHits->At(iHit);
74 if (hit->GetStation() == 0) {
75 hist[1][0]->Fill(hit->GetResX());
76 hist[1][1]->Fill(hit->GetResY());
77 }
78 if (hit->GetStation() == 1) {
79 hist[3][0]->Fill(hit->GetResX());
80 hist[3][1]->Fill(hit->GetResY());
81 }
82 }
83 for (Int_t iHit = 0; iHit < tof700Hits->GetEntriesFast(); iHit++) {
84 BmnHit* hit = (BmnHit*)tof700Hits->At(iHit);
85 Int_t module = (hit->GetDetectorID() >> 8) & 0xFF;
86 hResTof700Mod[module][0]->Fill(hit->GetResX());
87 hResTof700Mod[module][1]->Fill(hit->GetResY());
88 hist[2][0]->Fill(hit->GetResX());
89 hist[2][1]->Fill(hit->GetResY());
90 }
91 }
92
93 gStyle->SetFitFormat("5.3f");
94 gStyle->SetOptFit(0010);
95 gStyle->SetStatY(0.98);
96 gStyle->SetStatX(0.98);
97 gStyle->SetStatW(0.2);
98 gStyle->SetStatH(0.5);
99 gStyle->SetOptStat("i");
100 TCanvas* res = new TCanvas("res", "res", 2000, 1000);
101 res->Divide(nDet, nRes, 0, 0);
102 for (Int_t jRes = 0; jRes < nRes; jRes++) {
103 for (Int_t iDet = 0; iDet < nDet; iDet++) {
104 Int_t padId = iDet + nDet * jRes + 1;
105 TPad* pad = (TPad*)res->cd(padId);
106 pad->SetGrid(0, 0);
107 hist[iDet][jRes]->Fit("gaus", "WWQ");
108 hist[iDet][jRes]->Draw();
109 hist[iDet][jRes]->GetXaxis()->SetLabelSize(0.08);
110 TLatex latexDet;
111 latexDet.SetTextSize(0.08);
112 latexDet.DrawLatex(-4.5, 0.9 * hist[iDet][jRes]->GetMaximum(), namesDet[iDet]);
113 TLatex latexRes;
114 latexRes.SetTextSize(0.06);
115 latexRes.DrawLatex(-4.5, 0.8 * hist[iDet][jRes]->GetMaximum(), namesRes[jRes]);
116 }
117 }
118 res->SaveAs("ResidualsSRC.pdf");
119
120 const Int_t nRow = 6;
121 const Int_t nCol = 10;
122
123 TCanvas* ResYTof700Mod = new TCanvas("ResYTof700Mod", "ResYTof700Mod", 2000, 1200);
124 ResYTof700Mod->Divide(nCol, nRow, 0, 0);
125 for (Int_t iMod = 0; iMod < nMod; iMod++) {
126 Int_t padId = iMod % nCol + (iMod / nCol) * nCol + 1;
127 TPad* pad = (TPad*)ResYTof700Mod->cd(padId);
128 pad->SetGrid(0, 0);
129 hResTof700Mod[iMod][1]->Fit("gaus", "WWQ");
130 hResTof700Mod[iMod][1]->Draw();
131 hResTof700Mod[iMod][1]->GetXaxis()->SetLabelSize(0.08);
132 // TLatex latexDet;
133 // latexDet.SetTextSize(0.08);
134 // latexDet.DrawLatex(-4.5, 0.9 * hResXTof700Mod[iMod][0]->GetMaximum(), namesDet[iDet]);
135 // TLatex latexRes;
136 // latexRes.SetTextSize(0.06);
137 // latexRes.DrawLatex(-4.5, 0.8 * hResXTof700Mod[iMod][0]->GetMaximum(), namesRes[0]);
138 }
139 ResYTof700Mod->SaveAs("ResidualsY_SRC_tof700_mod.pdf");
140
141 TCanvas* ResXTof700Mod = new TCanvas("ResXTof700Mod", "ResXTof700Mod", 2000, 1200);
142 ResXTof700Mod->Divide(nCol, nRow, 0, 0);
143 for (Int_t iMod = 0; iMod < nMod; iMod++) {
144 Int_t padId = iMod % nCol + (iMod / nCol) * nCol + 1;
145 TPad* pad = (TPad*)ResXTof700Mod->cd(padId);
146 pad->SetGrid(0, 0);
147 hResTof700Mod[iMod][0]->Fit("gaus", "WWQ");
148 hResTof700Mod[iMod][0]->Draw();
149 hResTof700Mod[iMod][0]->GetXaxis()->SetLabelSize(0.08);
150 // TLatex latexDet;
151 // latexDet.SetTextSize(0.08);
152 // latexDet.DrawLatex(-4.5, 0.9 * hResXTof700Mod[iMod][0]->GetMaximum(), namesDet[iDet]);
153 // TLatex latexRes;
154 // latexRes.SetTextSize(0.06);
155 // latexRes.DrawLatex(-4.5, 0.8 * hResXTof700Mod[iMod][0]->GetMaximum(), namesRes[0]);
156 }
157 ResXTof700Mod->SaveAs("ResidualsX_SRC_tof700_mod.pdf");
158}
int Int_t
#define R__ADD_INCLUDE_PATH(PATH)
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Double_t GetResX()
Definition BmnHit.h:40
Double_t GetResY()
Definition BmnHit.h:41
Short_t GetStation() const
Definition BmnHit.h:35
virtual void SetLabelSize(Float_t size=0.04)
virtual void SetTextSize(Float_t tsize=1)
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
TAxis * GetXaxis()
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
TLatex * DrawLatex(Double_t x, Double_t y, const char *text)
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
void SaveAs(const char *filename="", Option_t *option="") const override
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)=0
void drawResidualsSRC(TString fileName="../run/srcdst_3332.root", Int_t nEvents=50000)