BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
EmbEventView.C
Go to the documentation of this file.
1/**
2 * Macro for tracks versions comparison
3 */
4R__ADD_INCLUDE_PATH($VMCWORKDIR)
5
6#if !defined(__CLING__) || defined(__MAKECLING__)
7
8#include <FairMCEventHeader.h>
9#include <FairMCPoint.h>
10#include <FairTrackParam.h>
11#include <Rtypes.h>
12#include <TCanvas.h>
13#include <TChain.h>
14#include <TClass.h>
15#include <TClonesArray.h>
16#include <TDatime.h>
17#include <TF1.h>
18#include <TFile.h>
19#include <TH1.h>
20#include <TH2.h>
21#include <TMath.h>
22#include <TPad.h>
23#include <TROOT.h>
24#include <TString.h>
25#include <TStyle.h>
26#include <TTree.h>
27#include <TVirtualPad.h>
28#include <ncurses.h>
29
30#else
31#include "bmnloadlibs.C"
32#include "gconfig/basiclibs.C"
33
34#endif
35
36#define PAD_WIDTH 640
37#define PAD_HEIGHT 360
38#define ROWS 2
39#define COLS 3
40#define EV_LIMIT 4
41using namespace std;
42using namespace TMath;
43
45{
46#if !(!defined(__CLING__) || defined(__MAKECLING__))
47 bmnloadlibs(); // load BmnRoot libraries
48#endif
49 gStyle->SetOptStat(0);
50 const Int_t nColors = 16;
51 Int_t ColorMap[nColors] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 49, 11, 12, 13, 14, 15, 16};
52 Int_t runID = 4649;
53 const Int_t boxWidth = 40;
54 // TString inFileNameEve = Form("eve-%d-isAll.root", runID);
55 TString inFileNameEve = Form("eve-%d-isAll-nocurl.root", runID);
56 TString inFileNameBase = Form("dst-%d.root", runID); // Form("cbmdst_%d.root", runID);
57 // TString inFileNameEmb = Form("dst-p-nofield.root", runID);
58 TString inFileNameEmb = Form("dst-%d-emb-qgsm-4h-isAll-nocurl-BaseOff.root",
59 runID); // Form("dst_MK_%d.root", runID); //~/BMNDST_%d.root
60
61 TString fnames[COLS] = {inFileNameEve, inFileNameBase, inFileNameEmb};
62 TString treeNames[COLS] = {"bmndata", "bmndata", "bmndata"}; //{"BMN_DIGIT", "cbmsim", "cbmsim"};
63 TString EHNames[COLS] = {"MCEventHeader.", "DstEventHeader.", "DstEventHeader."};
64 TString hitNames[COLS] = {"StsPoint", "BmnInnerHits", "BmnInnerHits"};
65 TString trackNames[COLS] = {"MCTrack", "BmnGlobalTrack", "BmnGlobalTrack"};
66 TFile* files[COLS] = {NULL};
67 TTree* trees[COLS] = {NULL};
68 FairMCEventHeader* MCEH = NULL;
69 DstEventHeader* EHs[COLS] = {NULL};
70 TClonesArray* hits[COLS] = {NULL};
71 TClonesArray* tracks[COLS] = {NULL};
72 TClonesArray* silTrack[COLS] = {NULL};
73 TClonesArray* gemTrack[COLS] = {NULL};
74 TClonesArray* silHits[COLS] = {NULL};
75 TClonesArray* gemHits[COLS] = {NULL};
76 TH2D* h[COLS][ROWS][nColors] = {NULL};
77 for (Int_t ic = 0; ic < nColors; ic++) {
78 h[0][0][ic] = new TH2D(Form("h0-0-%d", ic), "Hits XZ MC", 400, -boxWidth, boxWidth, 400, 0, 200);
79 h[0][1][ic] = new TH2D(Form("h0-1-%d", ic), "Hits YZ MC", 400, -boxWidth, boxWidth, 400, 0, 200);
80 // h[0][2] = new TH1I("h0-2", "Track 1st TX CBM", 200, -0.5, 0.5);
81 // h[0][3] = new TH1I("h0-3", "Track 1st TY CBM", 200, -0.5, 0.5);
82 h[1][0][ic] = new TH2D(Form("h1-0-%d", ic), "Hits XZ Base", 400, -boxWidth, boxWidth, 400, 0, 200);
83 h[1][1][ic] = new TH2D(Form("h1-1-%d", ic), "Hits YZ Base", 400, -boxWidth, boxWidth, 400, 0, 200);
84 // h[1][2] = new TH1I("h0-2", "Track 1st TX CBM2BMN", 200, -0.5, 0.5);
85 // h[1][3] = new TH1I("h0-3", "Track 1st TY CBM2BMN", 200, -0.5, 0.5);
86 h[2][0][ic] = new TH2D(Form("h2-0-%d", ic), "Hits XZ Embedded", 400, -boxWidth, boxWidth, 400, 0, 200);
87 h[2][1][ic] = new TH2D(Form("h2-1-%d", ic), "Hits YZ Embedded", 400, -boxWidth, boxWidth, 400, 0, 200);
88 // h[2][2] = new TH1I("h0-2", "Track 1st TX BMN", 200, -0.5, 0.5);
89 // h[2][3] = new TH1I("h0-3", "Track 1st TY BMN", 200, -0.5, 0.5);
90 }
91 TCanvas* can = new TCanvas("canHits", "", PAD_WIDTH * COLS, PAD_HEIGHT * ROWS);
92 can->Divide(COLS, ROWS);
93 // can->Size(PAD_WIDTH * 2, PAD_HEIGHT * 2);
94
95 for (Int_t i = 0; i < COLS; i++) {
96 files[i] = new TFile(fnames[i], "READ");
97 if (files[i]->IsOpen())
98 printf("file %s opened\n", fnames[i].Data());
99 else {
100 fprintf(stderr, "file %s open error\n", fnames[i].Data());
101 continue;
102 // return;
103 }
104 trees[i] = (TTree*)files[i]->Get(treeNames[i]);
105 trees[i]->SetBranchAddress(hitNames[i], &hits[i]);
106 trees[i]->SetBranchAddress(trackNames[i], &tracks[i]);
107 for (Int_t j = 0; j < ROWS; j++) {
108 for (Int_t ic = 0; ic < nColors; ic++) {
109 h[i][j][ic]->SetMarkerStyle(ic > 0 ? 43 : 2);
110 h[i][j][ic]->SetMarkerSize(ic > 0 ? 2 : 1);
111 h[i][j][ic]->SetMarkerColor(ColorMap[ic]);
112 }
113 }
114 if (i) {
115 trees[i]->SetBranchAddress(EHNames[i], &EHs[i]);
116 trees[i]->SetBranchAddress("BmnSiliconTrack", &silTrack[i]);
117 trees[i]->SetBranchAddress("BmnGemTrack", &gemTrack[i]);
118 trees[i]->SetBranchAddress("BmnSiliconHit", &silHits[i]);
119 trees[i]->SetBranchAddress("BmnGemStripHit", &gemHits[i]);
120 printf(" %d EH %08X\n", i, EHs[i]);
121 } else {
122 // trees[i]->SetBranchAddress("BmnSiliconTrack", &silTrack[i]);
123 // trees[i]->SetBranchAddress("BmnGemTrack", &gemTrack[i]);
124 trees[i]->SetBranchAddress(EHNames[i], &MCEH);
125 trees[i]->SetBranchAddress("SiliconPoint", &silHits[i]);
126 trees[i]->SetBranchAddress("StsPoint", &gemHits[i]);
127 printf(" %d EH %08X\n", i, MCEH);
128 }
129 }
130
131 const UInt_t nEvs = trees[1]->GetEntries();
132 cout << "#recorded entries = " << nEvs << " in file" << endl;
133 Int_t ch = 0;
134 Int_t iEv = 0;
135 do {
136 ch = getchar();
137 switch (ch) {
138 case 'a':
139 iEv = (iEv == 0) ? iEv : iEv - 1;
140 break;
141 case 'd':
142 iEv = (iEv < nEvs) ? iEv + 1 : iEv;
143 break;
144 default:
145 // iEv++;
146 break;
147 }
148 if (ch == '\n')
149 continue;
150 Int_t hitCount[COLS] = {0};
151 trees[0]->GetEntry(iEv);
152 UInt_t EventId = MCEH->GetEventID();
153 printf("iEv = %d EventId = %u \n", iEv, EventId);
154
155 for (Int_t i = 1; i < COLS; i++) {
156 Long64_t iExpEvent = -1;
157 while (1) {
158 // printf("iExpEvent %lld\n", iExpEvent);
159 trees[i]->GetEntry(++iExpEvent);
160 // printf("trees[i]->GetEntry(iExpEvent) %d\n", trees[i]->GetEntry(iExpEvent));
161 // printf("check %lld \n", iExpEvent);
162 if (EventId == EHs[i]->GetEventId())
163 break;
164 if (EventId < EHs[i]->GetEventId()) {
165 printf("\n%d tree %u event lost!\n", i, EventId);
166 break;
167 }
168 }
169 }
170 for (Int_t i = 0; i < COLS; i++) {
171 for (Int_t row = 0; row < ROWS; row++)
172 for (Int_t ic = 0; ic < nColors; ic++)
173 h[i][row][ic]->Reset();
174 if (i)
175 for (Int_t iHit = 0; iHit < hits[i]->GetEntriesFast(); iHit++) {
176 BmnHit* hit = (BmnHit*)hits[i]->UncheckedAt(iHit);
177 h[i][0][0]->Fill(hit->GetX(), hit->GetZ());
178 h[i][1][0]->Fill(hit->GetY(), hit->GetZ());
179 }
180 // hitCount[i] += hits[i]->GetEntriesFast();
181
182 // if (tracks[1]->GetEntriesFast() < 2) {
183 // iEv++;
184 // continue;
185 // }
186 printf("%d branch %d tracks\n", i, tracks[i]->GetEntriesFast());
187 if (i > 0) {
188 for (Int_t iTrack = 0; iTrack < tracks[i]->GetEntriesFast(); iTrack++) {
189 if (iTrack > nColors - 2) {
190 printf("tracks overfull %d\n", iTrack);
191 continue;
192 }
193 BmnGlobalTrack* track = (BmnGlobalTrack*)tracks[i]->UncheckedAt(iTrack);
194 if (track->GetSilTrackIndex() != -1) {
195 BmnTrack* silTr = (BmnTrack*)silTrack[i]->UncheckedAt(track->GetSilTrackIndex());
196 // if (silTr->GetNHits() < 4)
197 // continue;
198 hitCount[i] += silTr->GetNHits();
199 for (Int_t iHit = 0; iHit < silTr->GetNHits(); iHit++) {
200 BmnHit* hit = (BmnHit*)silHits[i]->UncheckedAt(silTr->GetHitIndex(iHit));
201 h[i][0][iTrack + 1]->Fill(hit->GetX(), hit->GetZ());
202 h[i][1][iTrack + 1]->Fill(hit->GetY(), hit->GetZ());
203 }
204 }
205 if (track->GetGemTrackIndex() != -1) {
206 BmnTrack* gemTr = (BmnTrack*)gemTrack[i]->UncheckedAt(track->GetGemTrackIndex());
207 // if (gemTr->GetNHits() < 4)
208 // continue;
209 hitCount[i] += gemTr->GetNHits();
210 for (Int_t iHit = 0; iHit < gemTr->GetNHits(); iHit++) {
211 BmnHit* hit = (BmnHit*)gemHits[i]->UncheckedAt(gemTr->GetHitIndex(iHit));
212 h[i][0][iTrack + 1]->Fill(hit->GetX(), hit->GetZ());
213 h[i][1][iTrack + 1]->Fill(hit->GetY(), hit->GetZ());
214 }
215 }
216 // FairTrackParam* first = track->GetParamFirst();
217 // h[i][2][iTrack]->Fill(first->GetTx());
218 // h[i][3][iTrack]->Fill(first->GetTy());
219 }
220 } else {
221 for (Int_t iTrack = 0; iTrack < tracks[i]->GetEntriesFast(); iTrack++) {
222 CbmMCTrack* track = (CbmMCTrack*)tracks[i]->UncheckedAt(iTrack);
223 // hitCount[i] += track->GetNPoints(kGEM);
224 for (Int_t iPoint = 0; iPoint < gemHits[i]->GetEntriesFast(); iPoint++) {
225 FairMCPoint* hit = (FairMCPoint*)gemHits[i]->UncheckedAt(iPoint);
226 Int_t TrackID = hit->GetTrackID();
227 if (TrackID != iTrack)
228 continue;
229 h[i][0][iTrack + 1]->Fill(hit->GetX(), hit->GetZ());
230 h[i][1][iTrack + 1]->Fill(hit->GetY(), hit->GetZ());
231 }
232 for (Int_t iPoint = 0; iPoint < silHits[i]->GetEntriesFast(); iPoint++) {
233 FairMCPoint* hit = (FairMCPoint*)silHits[i]->UncheckedAt(iPoint);
234 Int_t TrackID = hit->GetTrackID();
235 if (TrackID != iTrack)
236 continue;
237 h[i][0][iTrack + 1]->Fill(hit->GetX(), hit->GetZ());
238 h[i][1][iTrack + 1]->Fill(hit->GetY(), hit->GetZ());
239 }
240 // FairTrackParam* first = track->GetParamFirst();
241 // h[i][2][iTrack]->Fill(first->GetTx());
242 // h[i][3][iTrack]->Fill(first->GetTy());
243 }
244 }
245 }
246 // if (/*hitCount[0] < EV_LIMIT || */hitCount[1] < EV_LIMIT || hitCount[2] < EV_LIMIT) {
247 // iEv++;
248 // continue;
249 // }
250 for (Int_t col = 0; col < COLS; col++)
251 for (Int_t row = 0; row < ROWS; row++) {
252 TVirtualPad* pad = can->cd(row * COLS + col + 1);
253 pad->Clear();
254 // if (row > 2)
255 // h[col][row]->Draw();
256 // else
257 for (Int_t iTrack = 0; iTrack < nColors; iTrack++)
258 if (iTrack)
259 h[col][row][iTrack]->Draw("SAME");
260 else
261 h[col][row][iTrack]->Draw("");
262 }
263 can->Update();
264 can->Modified();
265 can->SaveAs(Form("can-%d.pdf", runID));
266 } while (ch != 'q');
267
268 for (Int_t i = 0; i < COLS; i++) {
269 for (Int_t j = 0; j < ROWS; j++) {
270 for (Int_t ic = 0; ic < nColors; ic++) {
271 delete h[i][j][ic];
272 }
273 }
274 }
275
276 return;
277}
#define PAD_WIDTH
#define PAD_HEIGHT
TCanvas * can(nullptr)
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
long long Long64_t
#define R__ADD_INCLUDE_PATH(PATH)
#define COLS
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
BmnGlobalTrack.h.
Int_t GetGemTrackIndex() const
Accessors.
Int_t GetNHits() const
Accessors.
Definition BmnTrack.h:49
Int_t GetHitIndex(Int_t iHit) const
Definition BmnTrack.h:51
CbmMCTrack.h.
Definition CbmMCTrack.h:26
virtual void SetMarkerColor(Color_t mcolor=1)
virtual void SetMarkerStyle(Style_t mstyle=1)
virtual void SetMarkerSize(Size_t msize=1)
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
Int_t GetEntriesFast() const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntries() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
void Clear(Option_t *option="") override=0
#define ROWS
void EmbEventView()
Definition json.hpp:4446