BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
EmbedStagesView.C
Go to the documentation of this file.
1
2#include <root/TClass.h>
3#include <root/TDirectory.h>
4
5/**
6 * Macro for decoders comparison
7 */
8R__ADD_INCLUDE_PATH($VMCWORKDIR)
9
10#define PAD_WIDTH_VIEW 1280
11#define PAD_HEIGHT_VIEW 640
12#define ROWS 5
13#define COLS 2
14#define EV_LIMIT 4
15using namespace std;
16using namespace TMath;
17const Int_t EtaNBins = 500;
18const Int_t EtaMax = 5;
19const Int_t PNBins = 500;
20const Int_t PMax = 5;
21const Int_t HitsNBins = 21;
22const Int_t HitsMax = 20;
23const Int_t Lims[ROWS][3] = {{EtaNBins, -EtaMax, EtaMax},
24 {PNBins, -PMax, PMax},
25 {PNBins, -PMax, PMax},
26 {PNBins, -PMax, PMax},
27 {HitsNBins, 0, HitsMax}};
28const Int_t nParticles = 2; // p, \pi-
29const Int_t nDetTypes = 3; // Sil, GEM, CSC
30const Int_t nCases = 3; // Background, MC Lambdas, Sum
31// StsPoint - GEM
32
33void DrawRef(TCanvas* canGemStrip, vector<PadInfo*>* canGemStripPads)
34{
35 Double_t maxy;
36 Double_t k = 1;
37 for (Int_t iPad = 0; iPad < canGemStripPads->size(); iPad++) {
38 TVirtualPad* pad = canGemStrip->cd(iPad + 1);
39 pad->Clear();
40 PadInfo* info = canGemStripPads->at(iPad);
41 if (!info)
42 continue;
43 if (info->current) {
44 maxy = info->current->GetMaximum(); // GetBinContent(info->current->GetMaximumBin());
45 info->current->Draw(info->opt.Data());
46 if (info->ref != NULL) {
47 if (info->ref->Integral() > 0)
48 info->ref->Draw("same hist");
49 k = info->ref->GetMaximum(); // GetBinContent(info->ref->GetMaximumBin());
50 if (maxy < k)
51 maxy = k;
52 info->current->SetMaximum(maxy * 1.2);
53 }
54 }
55 pad->Update();
56 pad->Modified();
57 }
58 canGemStrip->Update();
59 canGemStrip->Modified();
60}
61
62void EmbedStagesView(Int_t runID = 0)
63{
64#if !(!defined(__CLING__) || defined(__MAKECLING__))
65 bmnloadlibs(); // load BmnRoot libraries
66#endif
67 // gStyle->SetOptStat(0);
68 gDirectory->cd();
69 const Int_t nColors = 16;
70 Int_t ColorMap[nColors] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 49, 11, 12, 13, 14, 15, 16};
71 // Int_t runID = 4600;
72 Int_t fPeriodID = 7;
73 UInt_t sumMods = 0;
74 UInt_t maxLayers = 0;
75 BmnSetup fBmnSetup = kSRCSETUP;
76
77 TString treeName = "bmndata";
78 /**
79 * Draw expressions for phys values
80 */
81 const TString drawExpPseudoRapEve =
82 TString("-log(") + "MCTrack.GetPt()" + "/(" + "MCTrack.fPz + " + "MCTrack.GetP()" + "))";
83 const TString drawExpPEve = TString("MCTrack.GetP()");
84 const TString drawExpNHitsEve = TString(">>");
85
86 const TString drawExpPseudoRapDst = TString("-log(") + "sqrt(" + "sq(BmnGlobalTrack.fParamFirst.fTx) + "
87 + "sq(BmnGlobalTrack.fParamFirst.fTy)" + ")/(" + "1 + sqrt(" + "1 + "
88 + "sq(BmnGlobalTrack.fParamFirst.fTx) + " + "sq(BmnGlobalTrack.fParamFirst.fTy)"
89 + ")))";
90 const TString drawExpPDst = TString("1/BmnGlobalTrack.fParamFirst.fQp");
91 const TString drawExpNHitsDst = TString("BmnGlobalTrack.GetNHits()>>");
92
93 TString eveBG = Form("dst-%d.root", runID);
94 TString eveLam = Form("eve-%d-isAll.root", runID);
95 TString eveEmb = Form("merged-%d-qgsm-4h-isAll.root", runID);
96 TString dstBG = Form("dst-%d.root", runID);
97 TString dstLam = "dst-lam.root";
98 TString dstEmb = "dst-emb.root";
99
100 TString mcHitNames[nDetTypes] = {"StsPoint", "SiliconPoint", "CSCPoint"};
101 TString exHitNames[nDetTypes] = {"BmnGemStripHit", "BmnSiliconHit", "BmnCSCHit"};
102 Int_t pdg[nParticles] = {2212, -211};
103 TString pName[nParticles] = {"proton", "\\pi^{-}"};
104 TString valueName[ROWS] = {"eta", "momentum", "eta_momentum_eve", "eta_momentum_dst", "mult"};
105 TString valueShow[ROWS] = {"\\eta", "P", "\\eta X P", "\\eta\\ X\\ P", "NHits"};
106 TTree* treesMC[nCases] = {nullptr};
107 TTree* treesEx[nCases] = {nullptr};
108 TClonesArray* hitsMC[nCases][nDetTypes] = {nullptr};
109 TClonesArray* hitsEx[nCases][nDetTypes] = {nullptr};
110 TClass* hitsMCClasses[nDetTypes] = {CbmStsPoint::Class(), BmnSiliconPoint::Class(), BmnCSCPoint::Class()};
111 // TClass * hitsExClasses [nDetTypes] = {nullptr};
112 TClonesArray* mcTracks[nCases] = {nullptr};
113 TClonesArray* exTracks[nCases] = {nullptr};
114 TClonesArray* exTracksGem[nCases] = {nullptr};
115 TClonesArray* exTracksSil[nCases] = {nullptr};
116
117 TCanvas* cans[nCases] = {nullptr};
118 TFile* filesMC[nCases] = {nullptr};
119 TFile* filesEx[nCases] = {nullptr};
120 TString namesMC[nCases] = {eveBG, eveLam, eveEmb};
121 TString namesEx[nCases] = {dstBG, dstLam, dstEmb};
122 TClonesArray* hits[COLS] = {NULL};
123 TClonesArray* tracks[COLS] = {NULL};
124 DigiRunHeader* runHeaders[COLS] = {NULL, NULL};
125 BmnEventHeader* headers[COLS] = {NULL, NULL};
126 vector<vector<PadInfo*>> pads;
127 pads.resize(nCases, vector<PadInfo*>(ROWS * nParticles, nullptr));
128
129 // // ****************************
130 // // BG protons pads init
131 // // ****************************
132 // TCanvas *canBG = new TCanvas("can", "BG proton", PAD_WIDTH_VIEW * 1, PAD_HEIGHT_VIEW * ROWS);
133 // canBG->Divide(nParticles, ROWS);
134 // for (auto &pad : pads[0]) {
135 // pad = new PadInfo();
136 // }
137 // for (Int_t i = 0; i < 2; i++) {
138 // TString src = i ? "dst" : "eve";
139 // EColor color = i ? kRed : kBlue;
140 //
141 // TH1F* hEta = new TH1F(Form("hEta_p_%s", src.Data()), "proton\\ \\eta", EtaNBins, -EtaMax, EtaMax);
142 // hEta->SetLineColor(color);
143 // if (i)
144 // pads[0][0]->ref = hEta;
145 // else
146 // pads[0][0]->current = hEta;
147 //
148 // TH1F* hP = new TH1F(Form("hP_p_%s", src.Data()), " proton P", PNBins, 0, PMax);
149 // hP->SetLineColor(color);
150 // if (i)
151 // pads[0][1]->ref = hP;
152 // else
153 // pads[0][1]->current = hP;
154 // // padsBG[1]->opt = "logy logz";
155 // canBG->cd(2)->SetLogy();
156 //
157 // TH1F* hHits = new TH1F(Form("hHits_p_%s", src.Data()), "BG proton NHits", HitsNBins, 0, HitsMax);
158 // hHits->SetLineColor(color);
159 // if (i)
160 // pads[0][2]->ref = hHits;
161 // else
162 // pads[0][2]->current = hHits;
163 // }
164 //
165 // cans[0] = canBG;
166
167 // ****************************
168 // Other pads init
169 // ****************************
170 for (Int_t iCase = 0; iCase < nCases; iCase++) {
171 TCanvas* can = new TCanvas(Form("can_%d", iCase), "can", PAD_WIDTH_VIEW * nParticles, PAD_HEIGHT_VIEW * ROWS);
172 can->Divide(nParticles, ROWS);
173 cans[iCase] = can;
174 for (auto& pad : pads[iCase]) {
175 pad = new PadInfo();
176 }
177
178 for (Int_t iVal = 0; iVal < ROWS; iVal++) {
179 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
180 for (Int_t i = 0; i < 2; i++) {
181 TString src = i ? "dst" : "eve";
182 EColor color = i ? kRed : kBlue;
183
184 TH1* h = (iVal == 2 || iVal == 3)
185 ? (TH1*)new TH2F(Form("h%d_%s_%s_%s", iCase, src.Data(), valueName[iVal].Data(),
186 pName[iParticle].Data()),
187 Form("%s\\ %s", pName[iParticle].Data(), valueShow[iVal].Data()),
189 : (TH1*)new TH1F(Form("h%d_%s_%s_%s", iCase, src.Data(), valueName[iVal].Data(),
190 pName[iParticle].Data()),
191 Form("%s\\ %s", pName[iParticle].Data(), valueShow[iVal].Data()),
192 Lims[iVal][0], Lims[iVal][1], Lims[iVal][2]);
193 if (iVal == 2 || iVal == 3)
194 pads[iCase][iVal * nParticles + iParticle]->opt = "colz";
195 h->SetLineColor(color);
196 if (!i || (!i && iVal == 2) || (i && iVal == 3))
197 pads[iCase][iVal * nParticles + iParticle]->current = h;
198 else
199 pads[iCase][iVal * nParticles + iParticle]->ref = h;
200 if (iVal == 1) // valueName[iVal].Contains("momentum"))
201 can->cd(iVal * nParticles + iParticle + 1)->SetLogy();
202 }
203 }
204 }
205 }
206
207 // ********************
208 // Trees processing
209 // ********************
210 for (Int_t iCase = 0; iCase < nCases; iCase++) {
211 printf("case %d\n", iCase);
212 filesMC[iCase] = new TFile(namesMC[iCase].Data(), "READ");
213 if (filesMC[iCase]->IsOpen())
214 printf("file %s opened\n", namesMC[iCase].Data());
215 else {
216 fprintf(stderr, "file %s open error\n", namesMC[iCase].Data());
217 return;
218 }
219 filesEx[iCase] = new TFile(namesEx[iCase].Data(), "READ");
220 if (filesEx[iCase]->IsOpen())
221 printf("file %s opened\n", namesEx[iCase].Data());
222 else {
223 fprintf(stderr, "file %s open error\n", namesEx[iCase].Data());
224 return;
225 }
226 treesMC[iCase] = (TTree*)filesMC[iCase]->Get(treeName.Data());
227 treesEx[iCase] = (TTree*)filesEx[iCase]->Get(treeName.Data());
228
229 for (Int_t iDet = 0; iDet < nDetTypes; iDet++) {
230 treesMC[iCase]->SetBranchAddress(mcHitNames[iDet], &hitsMC[iCase][iDet]);
231 treesEx[iCase]->SetBranchAddress(exHitNames[iDet], &hitsEx[iCase][iDet]);
232 treesMC[iCase]->SetBranchAddress("MCTrack", &(mcTracks[iCase]));
233 treesEx[iCase]->SetBranchAddress("BmnGlobalTrack", &(exTracks[iCase]));
234 treesEx[iCase]->SetBranchAddress("BmnGemTrack", &(exTracksGem[iCase]));
235 treesEx[iCase]->SetBranchAddress("BmnSiliconTrack", &(exTracksSil[iCase]));
236 }
237 }
238
239 // runHeaders[i] = (DigiRunHeader*) files[i]->Get(runhdrNames[i].Data());
240 // ********************
241 // Draw all
242 // ********************
243 // put histos into gDirectory
244 for (Int_t iCase = 0; iCase < nCases; iCase++) {
245 for (Int_t i = 0; i < ROWS * nParticles; i++) {
246 if (pads[iCase][i]->current)
247 pads[iCase][i]->current->SetDirectory(gDirectory);
248 if (pads[iCase][i]->ref)
249 pads[iCase][i]->ref->SetDirectory(gDirectory);
250 }
251 // Draw pseudorapidity of the eve background protons
252 // printf("draw string: %s\n", drawExp.Data
253 // padsBG[0]->current = (TH1F*) gDirectory->Get(padsBG[0]->current->GetName());
254 // printf("ptr %d\n", padsBG[0]->current);
255 // TH1* h = (TH1*)gDirectory->Get("");
256 // padsBG[0]->current->Add(*h);
257 // Draw pseudorapidity of the dst background protons());
258 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
259 TString cond = Form("MCTrack.fPdgCode==%d", pdg[iParticle]);
260 TString drawExp = drawExpPseudoRapEve + ">>" + pads[iCase][iParticle]->current->GetName();
261 treesMC[iCase]->Draw(drawExp.Data(), cond.Data(), "goff");
262 drawExp = TString((iParticle ? "-" : "")) + drawExpPEve + ">>"
263 + pads[iCase][nParticles + iParticle]->current->GetName();
264 treesMC[iCase]->Draw(drawExp.Data(), cond.Data(), "goff");
265 drawExp = drawExpPseudoRapEve + ":" + TString((iParticle ? "-" : "")) + drawExpPEve + ">>"
266 + pads[iCase][2 * nParticles + iParticle]->current->GetName();
267 treesMC[iCase]->Draw(drawExp.Data(), cond.Data(), "goff");
268
269 cond = TString("BmnGlobalTrack.GetP()") + (pdg[iParticle] > 0 ? ">" : "<") + "0";
270 drawExp = drawExpPseudoRapDst + ">>" + pads[iCase][iParticle]->ref->GetName();
271 treesEx[iCase]->Draw(drawExp.Data(), cond.Data(), "goff");
272 drawExp = drawExpPDst + ">>" + pads[iCase][nParticles + iParticle]->ref->GetName();
273 treesEx[iCase]->Draw(drawExp.Data(), cond.Data(), "goff");
274 drawExp = drawExpPseudoRapDst + ":" + TString((iParticle ? "-" : "")) + drawExpPDst + ">>"
275 + pads[iCase][3 * nParticles + iParticle]->current->GetName();
276 treesEx[iCase]->Draw(drawExp.Data(), cond.Data(), "goff");
277 // // drawExp = drawExpNHitsEve + padsBG[2]->current->GetName();
278 // // treeEveBG->Draw(drawExp.Data(), "", "goff");
279 // drawExp = drawExpNHitsDst + padsBG[2]->ref->GetName();
280 // treeDstBG->Draw(drawExp.Data(), "", "goff");
281 }
282
283 for (Int_t iEv = 0; iEv < treesMC[iCase]->GetEntries(); iEv++) {
284 treesMC[iCase]->GetEntry(iEv);
285 for (Int_t iTrack = 0; iTrack < mcTracks[iCase]->GetEntriesFast(); iTrack++) {
286 CbmMCTrack* track = (CbmMCTrack*)mcTracks[iCase]->UncheckedAt(iTrack);
287
288 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
289 Int_t nHits = 0;
290 for (Int_t iDet = 0; iDet < nDetTypes; iDet++) {
291 for (Int_t iPoint = 0; iPoint < hitsMC[iCase][iDet]->GetEntriesFast(); iPoint++) {
292 CbmStsPoint* stsPoint = (CbmStsPoint*)hitsMC[iCase][iDet]->UncheckedAt(iPoint);
293 Int_t TrackID = stsPoint->GetTrackID();
294 if (TrackID != iTrack)
295 continue;
296 if (track->GetPdgCode() == pdg[iParticle])
297 nHits++;
298 }
299 }
300 if (nHits > 0)
301 pads[iCase][4 * nParticles + iParticle]->current->Fill(nHits);
302 }
303 }
304
305 treesEx[iCase]->GetEntry(iEv);
306 for (Int_t iTrack = 0; iTrack < exTracks[iCase]->GetEntriesFast(); iTrack++) {
307 BmnGlobalTrack* track = (BmnGlobalTrack*)exTracks[iCase]->UncheckedAt(iTrack);
308 // FairTrackParam* parFirst = track->GetParamFirst();
309 // FairTrackParam* parLast = track->GetParamLast();
310
311 // Put here your code ...
312
313 // Inner tracker contains GEM and SILICon detectors
314 BmnTrack* gemTr = nullptr;
315 BmnTrack* silTr = nullptr;
316
317 if (track->GetGemTrackIndex() != -1)
318 gemTr = (BmnTrack*)exTracksGem[iCase]->UncheckedAt(track->GetGemTrackIndex());
319
320 if (track->GetSilTrackIndex() != -1)
321 silTr = (BmnTrack*)exTracksSil[iCase]->UncheckedAt(track->GetSilTrackIndex());
322
323 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
324 // if (track->GetPDG() == pdg[iParticle]) {
325 if (track->GetP() * (pdg[iParticle]) > 0) {
326 Int_t nHits = 0;
327 if (gemTr)
328 nHits += gemTr->GetNHits();
329 if (silTr)
330 nHits += silTr->GetNHits();
331 if (track->GetCscHitIndex() > -1)
332 nHits++;
333 if (nHits > 0)
334 pads[iCase][4 * nParticles + iParticle]->ref->Fill(nHits);
335 }
336 }
337 // // GEM track
338 // if (track->GetGemTrackIndex() != -1)
339 // for (Int_t iHit = 0; iHit < gemTr->GetNHits(); iHit++) {
340 // BmnGemStripHit* hit = (BmnGemStripHit*)
341 // gemPoints->UncheckedAt(gemTr->GetHitIndex(iHit));
342 //
343 // }
344 //
345 // // SILICON track
346 // if (track->GetSilTrackIndex() != -1)
347 // for (Int_t iHit = 0; iHit < silTr->GetNHits(); iHit++) {
348 // BmnSiliconHit* hit = (BmnSiliconHit*)
349 // silPoints->UncheckedAt(silTr->GetHitIndex(iHit));
350 //
351 // }
352 } // for (Int_t iTrack = 0; iTrack < globTracks->GetEntriesFast(); iTrack++)
353 }
354 DrawRef(cans[iCase], &pads[iCase]);
355 cans[iCase]->SaveAs(Form("can-emb-%d.png", iCase));
356 }
357
358 // TImage *img = TImage::Create();
359 // img->FromPad(can);
360 // img->WriteImage("can-emb.png");
361 // canStrip->SaveAs(Form("can-run-%d.eps", runID));
362 // canStrip->SaveAs(Form("can-run-%d.pdf", runID));
363 //
364 // TCanvas *c1 = new TCanvas("c1");
365 // padsBG[0]->ref->Draw();
366 // c1->SaveAs("can-temp.png");
367 // delete c1;
368
369 for (Int_t iCase = 0; iCase < nCases; iCase++) {
370 if (filesMC[iCase])
371 filesMC[iCase]->Close();
372 if (filesEx[iCase])
373 filesEx[iCase]->Close();
374 }
375}
TCanvas * can(nullptr)
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
double Double_t
#define R__ADD_INCLUDE_PATH(PATH)
EColor
kRed
kBlue
#define COLS
#define gDirectory
char * Form(const char *fmt,...)
BmnSetup
Define experimental setup.
Definition BmnEnums.h:165
@ kSRCSETUP
Definition BmnEnums.h:167
BmnGlobalTrack.h.
Int_t GetGemTrackIndex() const
Accessors.
Int_t GetNHits() const
Accessors.
Definition BmnTrack.h:49
Double_t GetP()
Definition BmnTrack.h:67
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Int_t GetPdgCode() const
Accessors.
Definition CbmMCTrack.h:56
Storage for pad content and it's options.
Definition PadInfo.h:20
string opt
Definition PadInfo.h:88
TH1 * ref
Definition PadInfo.h:79
TH1 * current
Definition PadInfo.h:78
virtual void SetLineColor(Color_t lcolor)
TVirtualPad * cd(Int_t subpadnumber=0) override
void Update() override
void Close(Option_t *option="") override
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
virtual void SetMaximum(Double_t maximum=-1111)
void Draw(Option_t *option="") override
virtual Double_t Integral(Int_t binx1, Int_t binx2, Option_t *option="") const
Int_t GetEntriesFast() const
void Modified(Bool_t flag=true) override
void SaveAs(const char *filename="", Option_t *option="") const override
const char * Data() const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntries() const
virtual Long64_t Draw(const char *varexp, const char *selection, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual void Modified(Bool_t flag=1)=0
virtual void Update()=0
void Clear(Option_t *option="") override=0
#define ROWS
const Int_t EtaMax
const Int_t nCases
const Int_t nDetTypes
const Int_t HitsNBins
const Int_t EtaNBins
const Int_t PMax
const Int_t nParticles
const Int_t HitsMax
#define PAD_HEIGHT_VIEW
const Int_t Lims[ROWS][3]
#define PAD_WIDTH_VIEW
const Int_t PNBins
void DrawRef(TCanvas *canGemStrip, vector< PadInfo * > *canGemStripPads)
void EmbedStagesView(Int_t runID=0)
Definition json.hpp:4446