BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnIdentificationTOF700.C
Go to the documentation of this file.
1#include <Rtypes.h>
2#include <fstream>
3R__ADD_INCLUDE_PATH($VMCWORKDIR)
4#include "bmndata/BmnEnums.h"
5#include "macro/run/bmnloadlibs.C"
6
7// GEMTYPE = 0 - Merts, 1 - Gleb, 2 - Gleb recent all, 3 - Gleb recent filtered
8#define GEMTYPE 2
9#if GEMTYPE == 0
10// New Merts -> Old Gleb
11#define XSHIFT -1.9008
12#define YSHIFT +5.7794
13#define ZSHIFT +5.6300
14#define TXSHIFT -0.00643
15#define TYSHIFT +0.00054
16#define MINGEMNDF 4
17#elif GEMTYPE == 1
18// New Gleb -> Old Gleb
19#define XSHIFT -0.2770
20#define YSHIFT -0.5900
21#define ZSHIFT +1.1400
22#define TXSHIFT 0.0
23#define TYSHIFT 0.0
24#define MINGEMNDF 3
25#elif GEMTYPE == 2
26// Recent all Gleb -> Old Gleb
27#define XSHIFT -1.0584
28#define YSHIFT -1.2412
29#define ZSHIFT +2.4400
30#define TXSHIFT 0.0
31#define TYSHIFT 0.0
32#define MINGEMNDF 4
33#elif GEMTYPE == 3
34// Recent filtered Gleb -> Old Gleb
35#define XSHIFT -0.0304
36#define YSHIFT -1.0934
37#define ZSHIFT +6.2000
38#define TXSHIFT 0.0
39#define TYSHIFT 0.0
40#define MINGEMNDF 4
41#endif
42
43#define MINTIME true
44
45#define GEMDEBUG false
46
47#define XYPANIN 0
48
49#define DXGEMDCHMAX 5.
50#define DYGEMDCHMAX 3.
51
52#define USE_CLUSTERS 1
53
54#define STRIP_CORRECTIONS 1
55#define LIST_STRIP_CORRECTIONS 0
56
57// CALIBRATION - 0 - read corrections from root file *calibration.root, main time peak from TOF700_MC_time_run7.txt
58// 1 - no calibration correction on input, calculation and store corrections in *calibration.root file,
59// mean time peak from beam momentum 2 - no calibration correction on input, calculation and store
60// corrections in *calibration.root file, mean time peak from TOF700_MC_time_run7.txt 3 - no calibration
61// correction on input, calculation and store corrections in *calibration.root file, mean time peak from
62// TOF700_MC_time_run7.txt
63#define CALIBRATION 0
64
65// GEMCUTS = 0 - don't use additional cuts on GEM tracks, 1 - use additional cuts
66#define GEMCUTS 1
67
68// CVERS=0 - use last calibration tables, 1 - use *;1 version
69#define CVERS 1
70
71// CFACTOR - beta factor for main time peak particles
72#define CFACTOR 0.97f
73
74// FLAG -1 - (GEM+DCH1+DCH2), 0 - all, +1 (GEM+DCH1)
75#define FLAG 0
76
77// BETAMAX max velocity for proton selection
78#define BETAMAX 1.00f
79
80// PMIN min momentum for track selection
81#define PMIN 0.5f
82
83// PMAX max momentum for track selection
84#define PMAX 5.0f
85
86// PMAX1 max momentum for proton mass limits for calculate corrections
87#define PMAX1 3.0f
88
89// PMAX2 max momentum for proton mass limits for resolution hists
90#define PMAX2 2.5f
91
92// PRES min momentum for resolution hists
93#define PRES 2.0f
94
95// PRES1 another min momentum for resolution hists
96#define PRES1 3.0f
97
98// PMAXPI max momentum for pion track selection for calculate corrections
99#define PMAXPI 3.0f
100
101// MPIMAX max limit pion mass
102#define MPIMAX 0.2f
103
104// MP proton mass
105#define MP 0.938f
106
107// MP2 proton mass sqare
108#define MP2 (MP * MP)
109
110// pion mass
111#define MPI 0.139
112
113// pion mass square
114#define MPI2 (MPI * MPI)
115
116// scale factor for min mass proton region selection
117#define DMPSCALE1 1.
118
119// scale factor for max mass proton region selection
120#define DMPSCALE2 1.
121
122// scale factor for min mass proton region selection for time hist
123#define DMPSCALET1 1.
124
125// scale factor for max mass proton region selection for time hist
126#define DMPSCALET2 1.5
127
128// scale factor for pion region selection
129#define DMPISCALE 1.
130
131// PSCALE - momentum scale factor
132// #define PSCALE 0.96f
133#define PSCALE 0.99f
134// #define PSCALE 1.00f
135
136#define WRITE_CALIBRATION 0
137
138#define XFACTOR 5.0f
139// #define DISTMAX 20.0f
140// #define DXMAX 5.0f
141// #define DYMAX 3.0f
142#define DISTMAX 20.0f
143#define DXMAX 5.0f
144#define DYMAX 3.0f
145#define DXMAXPAN 5.0f
146#define DYMAXPAN 5.0f
147
148#define TOFMAX 20.0f
149
150#define IN_WIDTH_LIMITS 0
151#define WMIN 2900
152#define WMAX 9000
153
154#define NUMBER_CHAMBERS 59
155
158
159int wmi[NUMBER_CHAMBERS] = {2900};
160int wma[NUMBER_CHAMBERS] = {9000};
161
162int nhi = 0;
164int nhits[NUMBER_CHAMBERS][32] = {{0}};
165float tof[NUMBER_CHAMBERS][32] = {{0.}};
166float tofWidths[NUMBER_CHAMBERS][32] = {{0.}};
167double xhi[1000], yhi[1000], zhi[1000];
168double lrd[1000];
169double xhic[1000], yhic[1000], zhic[1000];
170using namespace std;
171using namespace TMath;
172
174
177
178float idchambers[59] = {27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1, 19.3, 31.1, 6.1,
179 2.1, 32.1, 15.2, 16.2, 17.2, 18.2, 19.2, 20.2, 7.1, 115.2, 113.1, 117.1,
180 35.1, 9.1, 37.1, 11.1, 39.1, 13.1, 34.1, 8.1, 36.1, 10.1, 38.1, 12.1,
181 21.2, 23.2, 25.2, 22.2, 24.2, 26.2, 107.2, 108.2, 109.2, 110.2, 111.2, 112.2,
182 114.1, 116.2, 118.1, 14.1, 40.1, 119.2, 120.2, 121.2, 122.2, 123.2, 124.2};
183
187
188Int_t readMCTimeFile(const char* MCTimeFile = "TOF700_MC_argon_qgsm_time_run7.txt");
189
190// void BmnIdentificationTOF700(const char *TracksGemDch = "tracks/Allowed4649.root", const char *DigitsTOF700 =
191// "digits/bmn_run9649_digi.root") {
192
193// void BmnIdentificationTOF700(const char *TracksGemDch = "argon_tracks_merts_files.txt", const char *DigitsTOF700 =
194// "argon_tof700_digits_files.txt") {
195
196void BmnIdentificationTOF700(const char* TracksGemDch = "argon_tracks_gleb_newall_files.txt",
197 const char* DigitsTOF700 = "argon_tof700_digits_files.txt")
198{
199
200 /* Load basic libraries */
201#if ROOT_VERSION_CODE < ROOT_VERSION(5, 99, 99)
202 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
203#endif
204 bmnloadlibs(); // load BmnRoot libraries
205
206 int RunPeriod = 7;
207 char mapping[256];
208 if (RunPeriod >= 1 && RunPeriod <= 7) {
209 sprintf(mapping, "TOF700_map_period_%d.txt", RunPeriod);
210 } else {
211 printf("Non-existing run period number %d!", RunPeriod);
212 return;
213 }
214
215 TClonesArray* eventHeadertof700 = NULL;
216 TClonesArray *tof700Digits = NULL, *eventHeader = NULL;
217 TClonesArray *tracks = NULL, *mtracks = NULL;
218 TString filename;
219
220 TChain* bmnTree = new TChain("bmndata");
221 if (strstr(TracksGemDch, ".root")) {
222 bmnTree->Add(TracksGemDch);
223 } else {
224 ifstream fin(TracksGemDch);
225 if (fin.is_open()) {
226 for (int idx = 0; idx < 1000; idx++) {
227 if (fin.eof())
228 break;
229 fin >> filename;
230 if (strlen(filename.Data()) == 0)
231 break;
232 if ((filename.Data())[0] == '#')
233 continue;
234 cout << " GEM+DCH tracks file #" << idx + 1 << " " << filename.Data() << endl;
235 bmnTree->Add(filename);
236 }
237 fin.close();
238 } else {
239 printf("Non-existing run list file: %s!", TracksGemDch);
240 return;
241 }
242 }
243 bmnTree->SetBranchAddress("EventHeader", &eventHeader);
244 bmnTree->SetBranchAddress("GemDchTracks", &mtracks);
245
246 char fnametof700[256];
247 TChain* bmnTreetof700 = new TChain("cbmsim");
248 if (strstr(DigitsTOF700, ".root")) {
249 bmnTreetof700->Add(DigitsTOF700); //
250 strcpy(fnametof700, DigitsTOF700);
251 } else {
252 ifstream fin(DigitsTOF700);
253 if (fin.is_open()) {
254 for (int idx = 0; idx < 1000; idx++) {
255 if (fin.eof())
256 break;
257 fin >> filename;
258 if (strlen(filename.Data()) == 0)
259 break;
260 if ((filename.Data())[0] == '#')
261 continue;
262 cout << " TOF digits file #" << idx + 1 << " " << filename.Data() << endl;
263 bmnTreetof700->Add(filename);
264 strcpy(fnametof700, filename.Data());
265 }
266 fin.close();
267 } else {
268 printf("Non-existing run list file: %s!", DigitsTOF700);
269 return;
270 }
271 }
272 bmnTreetof700->SetBranchAddress("EventHeader", &eventHeadertof700);
273 bmnTreetof700->SetBranchAddress("TOF700", &tof700Digits);
274
275 char fnametof700raw[256];
276 strcpy(fnametof700raw, fnametof700);
277 strcpy(strstr(fnametof700raw, "digi.root"), "raw.root");
278 if (XYPANIN)
279 TOF2 = new BmnTof2Raw2DigitNew(mapping, fnametof700raw, 0, 0, "TOF700_geometry_run7_panin.txt");
280 else
281 TOF2 = new BmnTof2Raw2DigitNew(mapping, fnametof700raw, 0, 0, "TOF700_geometry_run7.txt");
282
283 for (int c = 0; c < NUMBER_CHAMBERS; c++) {
284 halfwidthy[c] = 0.5f;
285 if (idchambers[c] < 100.f) {
286 halfwidthx[c] = 8.0f;
287 } else {
288 halfwidthx[c] = 28.0f;
289 }
290 wmi[c] = WMIN;
291 wma[c] = WMAX;
292 }
293
294 char name[128], title[128];
295
296 gStyle->SetOptFit(111);
297 gStyle->SetOptStat(111111);
298
300
301 if (CALIBRATION == 0) {
302 char fname_calib_root[128], *delim = 0;
303 strcpy(fname_calib_root, gSystem->BaseName(fnametof700));
304 if ((delim = strrchr(fname_calib_root, (int)'.')))
305 *delim = '\0';
306 strcat(fname_calib_root, "_calibration.root");
307 TFile* fc = new TFile(fname_calib_root, "READ", "Proton mass based calibration of BmnTOF700");
308 if (CVERS == 0) {
309 itcalibr = (TProfile2D*)fc->Get("tcalibr");
310 itcalibrc = (TProfile*)fc->Get("tcalibrc");
311 } else {
312 itcalibr = (TProfile2D*)fc->Get("tcalibr;1");
313 itcalibrc = (TProfile*)fc->Get("tcalibrc;1");
314 }
315 printf("\n ******************* Time offsets for whole chamber **********************\n");
316 for (int c = 0; c < NUMBER_CHAMBERS; c++) {
317 tofcalc[c] = itcalibrc->GetBinContent(c + 1);
318 printf("%d %f\n", c, tofcalc[c]);
319 }
320 if (STRIP_CORRECTIONS) {
322 printf("\n ******************* Time offsets for one strip **************************\n");
323 for (int c = 0; c < NUMBER_CHAMBERS; c++) {
325 printf("\n Chamber %d %.1f\n", c, idchambers[c]);
326 int smax = 32;
327 if (idchambers[c] >= 100.f)
328 smax = 16;
329 for (int s = 0; s < smax; s++) {
330 tofcals[c][s] = itcalibr->GetBinContent(c + 1, s + 1);
332 printf(" strip %d %f\n", s, tofcals[c][s]);
333 }
335 printf("\n *************************************************************************\n");
336 }
337 }
338 }
339
340 TFile* f = NULL;
341 if (strlen(fnametof700)) {
342 char fname_root[128], *delim = 0;
343 strcpy(fname_root, gSystem->BaseName(fnametof700));
344 if ((delim = strrchr(fname_root, (int)'.')))
345 *delim = '\0';
346 strcat(fname_root, "_identification_results.root");
347 f = new TFile(fname_root, "RECREATE", "Results of BmnTOF700");
348 }
349
350 TH1F* hntr = new TH1F("hntr", "Number of all tracks", 200, 0, 200);
351 TH1F* hntr0 = new TH1F("hntr0", "Number of selected tracks", 200, 0, 200);
352 TH1F* hntr1 = new TH1F("hntr1", "Number of tracks with FLAG conditions", 200, 0, 200);
353 TH2F* hxytr = new TH2F("hxytr", "XY tracks", 1500, -150, 150, 1000, -100, 100);
354 TH1F* hptr = new TH1F("hptr", "Momentum of tracks", 1000, -10, 10);
355 TH1F* hp0 = new TH1F("hp0", "Momentum of tracks (all)", 1000, -10, 10);
356 TH1F* hltr = new TH1F("hltr", "Lenght of GEM tracks", 100, 500, 700);
357 TH1F* hltra = new TH1F("hltra", "Lenght of GEM+DCH tracks", 100, 500, 700);
358 TH2F* hxytrtof = new TH2F("hxytrtof", "XY tracks with TOF700 hits", 1500, -150, 150, 1000, -100, 100);
359 TH2F* hxyhit = new TH2F("hxyhit", "XY track hit distance from TOF700 hit", 100, -50, 50, 40, -10, 10);
360 TH1F* hlrdiffs = new TH1F("hlrdiffs", "LR difference for TOF700 hits with track (small chamber)", 100, -5, +5);
361 TH1F* hlrdiffb = new TH1F("hlrdiffb", "LR difference for TOF700 hits with track (big chamber)", 100, -5, +5);
362 TH1F* hxdiff = new TH1F("hxdiff", "X difference for TOF700 hits with track", 100, -50, +50);
363 TH2F* hxxhits = new TH2F("hxxhits", "X track hit vs TOF700 hit (small chambers)", 200, -100, 100, 200, -100, 100);
364 TH2F* hxxhitb = new TH2F("hxxhitb", "X track hit vs TOF700 hit (big chambers)", 200, -100, 100, 200, -100, 100);
365 TH2F* hlrxhits = new TH2F("hlrxhits", "X TOF700 hit vs LR difference (small chamber)", 100, -5, 5, 200, -100, 100);
366 TH2F* hlrxhitb = new TH2F("hlrxhitb", "X TOF700 hit vs LR difference (big chamber)", 100, -5, 5, 200, -100, 100);
367
368 TH2F* hlrxtrs = new TH2F("hlrxtrs", "X TOF700 tr vs LR difference (small chamber)", 100, -5, 5, 200, -100, 100);
369 TH2F* hlrxtrb = new TH2F("hlrxtrb", "X TOF700 tr vs LR difference (big chamber)", 100, -5, 5, 200, -100, 100);
370
371 TH1F* hcsignp = new TH1F("hsignp", "Chambers with right correlation (x vs lr)", 60, 0, 60);
372 TH1F* hcsignm = new TH1F("hsignm", "Chambers with wrong correlation (x vs lr)", 60, 0, 60);
373
374 TH1F* htoftr = new TH1F("htoftr", "TOF of tracks with TOF700 hits", 600, -20, 40);
375 TH1F* htof = new TH1F("htof", "TOF for hits", 600, -20, 40);
376 TH1F* hntof = new TH1F("hntof", "Number of hits", 100, 0, 100);
377 TH1F* hnhit = new TH1F("hnhit", "Number of hits in width limits", 100, 0, 100);
378 TH2F* hxytof = new TH2F("hxytof", "XY TOF700 hits", 1500, -150, 150, 1000, -100, 100);
379 TH2F* hpbeta = new TH2F("hpbeta", "Beta vs momentum", 200, 0, 10, 220, 0, 1.1f);
380 hpbeta->SetOption("COLZ");
381 TH2F* hpbetac = new TH2F("hpbetac", "Beta vs momentum, chamber corrections", 200, 0, 10, 220, 0, 1.1f);
382 hpbetac->SetOption("COLZ");
383 TH2F* hpbetas = new TH2F("hpbetas", "Beta vs momentum, strip corrections", 200, 0, 10, 220, 0, 1.1f);
384 hpbetas->SetOption("COLZ");
385 TH2F* hpbetacm = new TH2F("hpbetacm", "Beta vs momentum, Z<0, chamber corrections", 200, 0, 10, 220, 0, 1.1f);
386 hpbetacm->SetOption("COLZ");
387 TH2F* hpbetasm = new TH2F("hpbetasm", "Beta vs momentum, Z<0, strip corrections", 200, 0, 10, 220, 0, 1.1f);
388 hpbetasm->SetOption("COLZ");
389 TH1F* hmass = new TH1F("hmass", "Mass, p<2", 100, -0.5, 4.5);
390 TH1F* hmassc = new TH1F("hmassc", "Mass, chamber corrections", 100, -0.5, 4.5);
391 TH1F* hmassc15 = new TH1F("hmassc15", "Mass, chamber corrections, p<1.5", 100, -0.5, 4.5);
392 TH1F* hmassc20 = new TH1F("hmassc20", "Mass, chamber corrections, p<2.0", 100, -0.5, 4.5);
393 TH1F* hmasss = new TH1F("hmasss", "Mass, strip corrections", 100, -0.5, 4.5);
394 TH1F* hmasss15 = new TH1F("hmasss15", "Mass, strip corrections, p<1.5", 100, -0.5, 4.5);
395 TH1F* hmasss20 = new TH1F("hmasss20", "Mass, strip corrections, p<2.0", 100, -0.5, 4.5);
396 TH1F* hmasscm = new TH1F("hmasscm", "Mass, Z<0, chamber corrections", 200, -1, 4);
397 TH1F* hmasssm = new TH1F("hmasssm", "Mass, Z<0, strip corrections", 200, -1, 4);
398
399 TH1F* hdtps = new TH1F("hdtps", "Time resolution, protons, strip corrections", 200, -1., +1.);
400 TH2F* hdtpsvsp =
401 new TH2F("hdtpsvsp", "Time resolution vs momentum, protons, strip corrections", 240, 0., 6., 200, -1., +1.);
402 hdtpsvsp->SetOption("COLZ");
403 TH1F* hdtpc = new TH1F("hdtpc", "Time resolution, protons, chamber corrections", 200, -1., +1.);
404 TH2F* hdtpcvsp =
405 new TH2F("hdtpcvsp", "Time resolution vs momentum, protons, chamber corrections", 240, 0., 6., 200, -1., +1.);
406 hdtpcvsp->SetOption("COLZ");
407 TH2F* hdtpcvspwlim = new TH2F("hdtpcvspwlim", "Time resolution vs momentum, protons, chamber corrections, w>3000",
408 240, 0., 6., 200, -1., +1.);
409 hdtpcvspwlim->SetOption("COLZ");
410 TH1F* hdtpcplim = new TH1F("hdtpcplim", "Time resolution, protons, p>3", 200, -1., +1.);
411 TH1F* hdtpcp1lim = new TH1F("hdtpcp1lim", "Time resolution, protons, p>4", 200, -1., +1.);
412 TH1F* hdtpcp2lim = new TH1F("hdtpcp2lim", "Time resolution, protons, p<2", 200, -1., +1.);
413 TH1F* hdtpcp3lim = new TH1F("hdtpcp3lim", "Time resolution, protons, 2<p<5", 200, -1., +1.);
414 TH1F* hdtpcwlim = new TH1F("hdtpcwlim", "Time resolution, protons, w>3000", 200, -1., +1.);
415 TH1F* hdtpcwplim = new TH1F("hdtpcwplim", "Time resolution, protons, p>3, w>3000", 200, -1., +1.);
416 TH1F* hdtpcwp1lim = new TH1F("hdtpcwp1lim", "Time resolution, protons, p>4, w>3000", 200, -1., +1.);
417
418 TH2F* hmassvsp = new TH2F("hmassvsp", "Mass vs momentum", 240, 0., 6., 200, -0.2, 4.8);
419 hmassvsp->SetOption("COLZ");
420 TH2F* hmasssvsp = new TH2F("hmasssvsp", "Mass vs momentum, strip correction", 240, 0., 6., 200, -0.2, 4.8);
421 hmasssvsp->SetOption("COLZ");
422 TH2F* hmasscvsp = new TH2F("hmasscvsp", "Mass vs momentum, chamber corrections", 240, 0., 6., 200, -0.2, 4.8);
423 hmasscvsp->SetOption("COLZ");
424 TH2F* hmasssmvsp = new TH2F("hmasssmvsp", "Mass vs momentum, Z<0, strip correction", 240, 0., 6., 200, -0.2, 4.8);
425 hmasssmvsp->SetOption("COLZ");
426 TH2F* hmasscmvsp =
427 new TH2F("hmasscmvsp", "Mass vs momentum, Z<0, chamber corrections", 240, 0., 6., 200, -0.2, 4.8);
428 hmasscmvsp->SetOption("COLZ");
429
430 TH1F* htofp = new TH1F("htofp", "TOF for proton hits, p<2", 600, -20, 40);
431 TH1F* hstr = new TH1F("hstr", "Strips", 32, 0, 32);
432 TH1F* hcha = new TH1F("hcha", "Chambers", 60, 0, 60);
433 TH1F* hstrtr = new TH1F("hstrtr", "Strips with tracks", 32, 0, 32);
434 TH1F* hchatr = new TH1F("hchatr", "Chambers with tracks", 60, 0, 60);
435
436 TH2F* hdxy0 = new TH2F("hdxy0", "DxDy all", 40, -10, +10, 40, -10, +10);
437 TH1F* hdx = new TH1F("hdx", "dx all", 40, -10, +10);
438 TH1F* hdy = new TH1F("hdy", "dy all", 40, -10, +10);
439 TH2F* hdxy = new TH2F("hdxy", "DxDy selected", 40, -10, +10, 40, -10, +10);
440 TH2F* hdxytof = new TH2F("hdxytof", "DxDy with TOF700 hits", 40, -10, +10, 40, -10, +10);
441 TH2F* hdxyeff = new TH2F("hdxyeff", "Efficiency vs DxDy", 40, -10, +10, 40, -10, +10);
442 hdxyeff->SetOption("COLZ");
443 TH1F* hdxeff = new TH1F("hdxeff", "Efficiency vs Dx", 40, -10, +10);
444 TH1F* hdyeff = new TH1F("hdyeff", "Efficiency vs Dy", 40, -10, +10);
445 TH2F* hxygoodtr = new TH2F("hxygoodtr", "XY good tracks", 70, -140, 140, 60, -90, 90);
446 TH2F* hxygoodhit = new TH2F("hxygoodhit", "XY good tracks with good hits", 70, -140, 140, 60, -90, 90);
447 TH2F* hxyeff = new TH2F("hxyeff", "Efficiency vs XY good tracks", 70, -140, 140, 60, -90, 90);
448 hxyeff->SetOption("COLZ");
449 TH1F* hxeff = new TH1F("hxeff", "Efficiency vs X good tracks", 70, -140, 140);
450 TH1F* hyeff = new TH1F("hyeff", "Efficiency vs Y good tracks", 60, -90, 90);
451 TH1F* hdtx = new TH1F("hdtx", "dtx", 100, -0.25, +0.25);
452 TH1F* hdty = new TH1F("hdty", "dty", 100, -0.25, +0.25);
453 TH1F* hDdx = new TH1F("hDdx", "Err dx", 100, 0, 10);
454 TH1F* hDdy = new TH1F("hDdy", "Err dy", 100, 0, 10);
455 TH1F* hDdtx = new TH1F("hDdtx", "Err dtx", 100, 0, 0.05);
456 TH1F* hDdty = new TH1F("hDdty", "Err dty", 100, 0, 0.05);
457 TH1F* hpdx = new TH1F("hpdx", "Pull dx", 500, -2.5, +2.5);
458 TH1F* hpdy = new TH1F("hpdy", "Pull dy", 500, -2.5, +2.5);
459 TH1F* hpdtx = new TH1F("hpdtx", "Pull dtx", 500, -25., +25.);
460 TH1F* hpdty = new TH1F("hpdty", "Pull dty", 500, -25., +25.);
461 TH1F* hchi2m = new TH1F("hChi2m", "Chi2 GemDch track", 1000, 0, 100);
462 TH1F* hchi2 = new TH1F("hchi2", "Chi2 tracks matching", 1000, 0, 100);
463
464 TProfile2D* tcalibrs = new TProfile2D("tcalibr", "Time calibration based on proton mass, strips", NUMBER_CHAMBERS,
465 0, NUMBER_CHAMBERS, 32, 0, 32, -1., +1., "e");
466 TProfile* tcalibrc = new TProfile("tcalibrc", "Time calibration based on proton mass, chambers", NUMBER_CHAMBERS, 0,
467 NUMBER_CHAMBERS, -1., +1., "e");
468
469 TProfile* tpeak = new TProfile("tpeak", "Peak time vs chamber", NUMBER_CHAMBERS, 0, NUMBER_CHAMBERS, 0., +30., "e");
470 TProfile* bpeak =
471 new TProfile("bpeak", "Peak velosity vs chamber", NUMBER_CHAMBERS, 0, NUMBER_CHAMBERS, 0., +1.5, "e");
472
473 char nam[64], tit[64];
474
475 float cvel = 29.97925f;
476 float ekin = 3.2f, ebeam = ekin + MP, pbeam = TMath::Sqrt(ebeam * ebeam + MP * MP);
477 float cbeam = pbeam / ebeam;
478 float cpeak = cbeam * CFACTOR * cvel;
479 float ztarg = -2.2f;
480 float zc[NUMBER_CHAMBERS] = {0.f};
481 for (int i = 0; i < NUMBER_CHAMBERS; i++) {
482 TOF2->get_chamber_z(i, &zc[i]);
483 }
484
485 Int_t startEvent = 0;
486 Int_t nEvents = bmnTree->GetEntries();
487 Int_t nEventstof700 = bmnTreetof700->GetEntries();
488 printf("\nNumber of events in tracks chain is %d (tof700 chain %d)\n", nEvents, nEventstof700);
489
490 int Ntr = 0, Ntr1 = 0, Ntr1g = 0, Ntr0 = 0;
491 Int_t iEv = 0, iEvtof700 = 0, fCurrent = -1;
492 UInt_t trackEvId = 0, tof700EvId = 0;
493 UInt_t trackRunId = 0, tof700RunId = 0;
494 for (Int_t iEv0 = startEvent; iEv0 < startEvent + nEvents; iEv0++) {
495 if (iEv % 10000 == 0) {
496 cout << "Event: " << iEv << "/" << startEvent + nEvents << " ( Run " << trackRunId << " EvId " << trackEvId
497 << " )" << endl;
498 }
499 BmnGemDchTrack* gemdchtrack0 = NULL;
500 do {
501 if (iEv >= nEvents)
502 break;
503 bmnTree->GetEntry(iEv);
504 if (mtracks == NULL) {
505 iEv++;
506 continue;
507 };
508 gemdchtrack0 = (BmnGemDchTrack*)(mtracks->UncheckedAt(0));
509 // gemdchtrack0 = (BmnGemDchTrack*)(mtracks->At(0));
510 // printf("First attempt, iEv = %d, iEv0 = %d\n",iEv,iEv0);
511 iEv++;
512 } while (gemdchtrack0 == NULL);
513 // printf("Point 0, iEv = %d\n",iEv);
514 if (iEv >= nEvents)
515 break;
516 // trackEvId = gemdchtrack0->GetEventId();
517 trackEvId = ((BmnEventHeader*)eventHeader)->GetEventId();
518 // printf("Point 1, iEv = %d, trackEvId = %d\n",iEv,trackEvId);
519 if (eventHeader == NULL)
520 continue;
521 // trackRunId = ((BmnEventHeader*)eventHeader->UncheckedAt(0))->GetRunId();
522 trackRunId = ((BmnEventHeader*)eventHeader)->GetRunId();
523 // printf("Point 2, iEv = %d, trackRunId = %d\n",iEv,trackRunId);
524 if (tof700RunId == trackRunId && tof700EvId > trackEvId)
525 continue;
526 if (tof700RunId > trackRunId)
527 continue;
528 // printf("Point 3, iEv = %d\n",iEv);
529 if (!(tof700EvId == trackEvId && tof700RunId == trackRunId)) {
530 do {
531 bmnTreetof700->GetEntry(iEvtof700);
532 if (eventHeadertof700 == NULL)
533 break;
534 tof700EvId = ((BmnEventHeader*)eventHeadertof700->UncheckedAt(0))->GetEventId();
535 tof700RunId = ((BmnEventHeader*)eventHeadertof700->UncheckedAt(0))->GetRunId();
536 // cout << "Tracks Event: " << iEv << ", TOF700 Event: " << iEvtof700 << endl;
537 // cout << "Tracks EventId: " << trackEvId << ", TOF700 EventId: " << tof700EvId << endl;
538 // cout << "Tracks RunId: " << trackRunId << ", TOF700 RunId: " << tof700RunId << endl;
539 iEvtof700++;
540 if (iEvtof700 >= nEventstof700)
541 break;
542 if (tof700RunId > trackRunId)
543 break;
544 if (tof700RunId == trackRunId && tof700EvId > trackEvId)
545 break;
546 } while (!(tof700EvId == trackEvId && tof700RunId == trackRunId));
547 }
548 if (eventHeadertof700 == NULL)
549 continue;
550 if (!(tof700EvId == trackEvId && tof700RunId == trackRunId)) {
551 cout << "Not found EventId " << trackEvId << " in tof700 digits file" << endl;
552 cout << "Tracks Event: " << iEv << ", TOF700 Event: " << iEvtof700 << endl;
553 cout << "Tracks RunId: " << trackRunId << ", TOF700 RunId: " << tof700RunId << endl;
554 cout << "Tracks EventId: " << trackEvId << ", TOF700 EventId: " << tof700EvId << endl;
555 if (iEvtof700 >= nEventstof700)
556 break;
557 if (tof700RunId > trackRunId)
558 continue;
559 if (tof700RunId == trackRunId && tof700EvId > trackEvId)
560 continue;
561 break;
562 // continue;
563 }
564 float wmax[NUMBER_CHAMBERS] = {0.};
565 float tmax[NUMBER_CHAMBERS] = {-10000000.};
566 int smax[NUMBER_CHAMBERS] = {-1};
567 int smax1[NUMBER_CHAMBERS] = {-1};
568 int istr[NUMBER_CHAMBERS] = {-1};
569
570 for (int i = 0; i < NUMBER_CHAMBERS; i++) {
571 wmax[i] = 0.;
572 tmax[i] = -1000000.;
573 smax[i] = -1;
574 smax1[i] = -1;
575 nhit[i] = 0;
576 for (int j = 0; j < 32; j++)
577 nhits[i][j] = 0;
578 for (int j = 0; j < 32; j++)
579 tofWidths[i][j] = 0.;
580 for (int j = 0; j < 32; j++)
581 tof[i][j] = 0.;
582 }
583 nhi = 0;
584
585 int ntof = tof700Digits->GetEntriesFast();
586 hntof->Fill(ntof);
587 float x = 0., y = 0., z = 0.;
588 int hchamb[1000] = {0}, hstrip[1000] = {0};
589 int clchamb[1000] = {0}, clstrip[1000] = {0};
590 Bool_t usedstrip[1000] = {false};
591 Int_t numhit[NUMBER_CHAMBERS][32] = {{0}};
592 for (Int_t iDig = 0; iDig < ntof; ++iDig) {
593 BmnTof2Digit* digit = (BmnTof2Digit*)tof700Digits->At(iDig);
594 if (digit == NULL)
595 continue;
596 Short_t plane = digit->GetPlane();
597 Short_t strip = digit->GetStrip();
598 Float_t time = digit->GetTime();
599 Float_t width = digit->GetAmplitude();
600 Float_t lrdiff = digit->GetDiff();
601 // if (iEv % 10 == 0) cout << "plane = " << plane << " strip = " << strip << " time = " << time <<
602 // " width = " << width << endl; if (iEv % 10 == 0) cout << "wmi = " << wmi[plane] << " wma = "
603 // << wma[plane] << endl;
604 if (plane >= NUMBER_CHAMBERS)
605 continue;
606 if (XYPANIN && (TOF2->get_hit_xp(plane, strip, lrdiff) == 0.))
607 continue;
608 // if (lrdiff < -0.5 || lrdiff > 0.5) continue;
609 smax1[plane] = strip;
610 if (width > wmax[plane]) {
611 wmax[plane] = width;
612 tmax[plane] = time;
613 smax[plane] = strip;
614 }
615 if (IN_WIDTH_LIMITS)
616 if (width < wmi[plane] || width > wma[plane])
617 continue;
618 htof->Fill(time);
619 hchamb[nhi] = plane;
620 hstrip[nhi] = strip;
621 nhit[plane]++;
622 nhits[plane][strip]++;
623 tof[plane][strip] = time;
624 tofWidths[plane][strip] = width;
625 istr[plane] = strip;
626 if (XYPANIN)
627 TOF2->get_hit_xyzp(plane, strip, lrdiff, &x, &y, &z);
628 else
629 TOF2->get_hit_xyz(plane, strip, lrdiff, &x, &y, &z);
630 xhi[nhi] = x;
631 yhi[nhi] = y;
632 zhi[nhi] = z;
633 lrd[nhi] = lrdiff;
634 hxytof->Fill(x, y);
635 TOF2->get_strip_xyz(plane, strip, &x, &y, &z);
636 xhic[nhi] = x;
637 yhic[nhi] = y;
638 zhic[nhi] = z;
639 hstr->Fill(strip);
640 hcha->Fill(plane);
641 numhit[plane][strip] = nhi;
642 nhi++;
643 } // tof700Digits loop
644 hnhit->Fill(nhi);
645
646 float xyz[3] = {0.}, cxyz[3] = {0.}, xrpc = 0., yrpc = 0., dz = 100., tx = 0., ty = 0., zcha = 0.;
647 float beta = 1.0f, mass = 1.0f, mass2 = 1.0f, tcor = 0., tcorc = 0., tcors = 0., tcorspi = 0., tcorcpi = 0.;
648 int nh = 0;
649 int ntr = mtracks->GetEntriesFast();
650 hntr->Fill(ntr);
651 Ntr += ntr;
652 int ntr0 = 0;
653 int ntr1 = 0, ntr1g = 0;
654 int iflag = 0, igem = 0, idch = 0;
655 float chi2 = 0.f;
656 BmnGemDchTrack* gemdchtrack = NULL;
657 BmnTrack* track = NULL;
658#if GEMTYPE == 0
659 BmnTrack* gtrack = NULL; // Merts GEM tracks
660#else
661 CbmStsTrack* gtrack = NULL; // Gleb GEM tracks
662#endif
663 Double_t xGem = 0.;
664 Double_t yGem = 0.;
665 Double_t txGem = 0.;
666 Double_t tyGem = 0.;
667 Double_t QpGem = 0.;
668 Double_t QpDch = 0.;
669 Int_t nGemHits = 0;
670 Double_t Xpv = 0.;
671 Double_t Ypv = 0.;
672 Double_t dxm = 0.;
673 Double_t dym = 0.;
674 Double_t dtx = 0.;
675 Double_t dty = 0.;
676 Double_t Ddx = 0.;
677 Double_t Ddy = 0.;
678 Double_t Ddtx = 0.;
679 Double_t Ddty = 0.;
680 Double_t Chi2m = 0.;
681 Double_t xgoodtr = 0.;
682 Double_t ygoodtr = 0.;
683 Double_t le = 0., p = 0., ps = 0., pmod = 0., lenr = 0.;
684 int himin = -1;
685 double dx, dy, dl;
686 double dist = 0., distmin = 1000000000.0f;
687 Float_t xc, yc, zc;
688 int ic;
689 int is;
690 double cosa = 0.;
691 float hidist = 0.;
692 Double_t tofr0 = 0.f;
693 Double_t tofr = 0.f;
694 Double_t tofp = 0.f;
695 Double_t tofpi = 0.f;
696 float massmin1 = 0.;
697 float massmax1 = 0.;
698 float massmin2 = 0.;
699 float massmax2 = 0.;
700
701 float massmaxpi = 0.;
702 float massminpi = 0.;
703 float tcorpi = 0.;
704 float tofrc = 0.;
705 float tofrs = 0.;
706 float betac = 0.;
707 float betas = 0.;
708 float masss2 = 0.;
709 float masss = 0.;
710 float massc2 = 0.;
711 float massc = 0.;
712 double timepeak = 0., betapeak = 0.;
713
714 for (Int_t iTr = 0; iTr < ntr; ++iTr) {
715 gemdchtrack = (BmnGemDchTrack*)mtracks->At(iTr);
716 if (gemdchtrack == NULL)
717 continue;
718 track = (BmnTrack*)gemdchtrack->GetDchTrack();
719 if (track == NULL)
720 continue;
721 if (track->GetUniqueID() != 100)
722 continue;
723 if (FLAG < 0 && track->GetFlag() >= 0)
724 continue;
725 if (FLAG > 0 && track->GetFlag() < 0)
726 continue;
727#if GEMTYPE == 0
728 gtrack = (BmnTrack*)gemdchtrack->GetGemTrack(); // Merts GEM tracks
729#else
730 gtrack = (CbmStsTrack*)gemdchtrack->GetGemTrack(); // Gleb GEM tracks
731#endif
732 if (gtrack == NULL)
733 continue;
734 // Selection criteria
735 QpGem = gtrack->GetParamLast()->GetQp();
736 QpDch = track->GetParamLast()->GetQp();
737 if (TMath::IsNaN(QpGem)) { /*printf("NaN of INF inv. momentum %f, momentum %f\n",ps,p);*/
738 continue;
739 }
740 if (TMath::IsNaN(QpDch)) { /*printf("NaN of INF inv. momentum %f, momentum %f\n",ps,p);*/
741 continue;
742 }
743 if (QpGem != 0.) {
744 hp0->Fill(1. / QpGem);
745 } else {
746 // hp0->Fill(0.);
747 }
748 ntr1++;
749 xGem = gtrack->GetParamLast()->GetX();
750 yGem = gtrack->GetParamLast()->GetY();
751 txGem = gtrack->GetParamLast()->GetTx();
752 tyGem = gtrack->GetParamLast()->GetTy();
753#if GEMTYPE == 0
754 nGemHits = gtrack->GetNHits(); // Merts GEM tracks
755#else
756 nGemHits = gtrack->GetNDF(); // Gleb GEM tracks
757#endif
758 Xpv = gemdchtrack->GetXpv();
759 Ypv = gemdchtrack->GetYpv();
760
761 if (GEMCUTS)
762 if (nGemHits < MINGEMNDF || xGem < -140.f || xGem > 240.f || yGem < -40.f || yGem > 200.f
763 || txGem < -0.5f || txGem > 1.0f || tyGem < -0.1f || tyGem > 0.5f || Xpv < -3.5f || Xpv > 4.0f
764 || Ypv < -1.0f || Ypv > 6.0f || QpGem == 0.0f || 1.0f / TMath::Abs(QpGem) > 15.0f
765 || 1.0f / TMath::Abs(QpGem) < 0.15f)
766 {
767 if (GEMDEBUG)
768 printf("xGem %f yGem %f txGem %f tyGem %f Xpv %f Ypv %f QpGem %f\n", xGem, yGem, txGem, tyGem,
769 Xpv, Ypv, QpGem);
770 continue;
771 }
772
773 ntr1g++;
774 // fill matching parameters
775 dxm = gemdchtrack->GetDx();
776 dym = gemdchtrack->GetDy();
777 dtx = gemdchtrack->GetDtx();
778 dty = gemdchtrack->GetDty();
779 Ddx = gemdchtrack->GetDdx();
780 Ddy = gemdchtrack->GetDdy();
781 Ddtx = gemdchtrack->GetDdtx();
782 Ddty = gemdchtrack->GetDdty();
783 Chi2m = gemdchtrack->GetChi2();
784 hdx->Fill(dxm);
785 hdy->Fill(dym);
786 hdxy0->Fill(dxm, dym);
787 hdtx->Fill(dtx);
788 hdty->Fill(dty);
789 hDdx->Fill(sqrt(Ddx));
790 hDdy->Fill(sqrt(Ddy));
791 hDdtx->Fill(sqrt(Ddtx));
792 hDdty->Fill(sqrt(Ddty));
793 hpdx->Fill(dxm / sqrt(Ddx));
794 hpdy->Fill(dym / sqrt(Ddy));
795 hpdtx->Fill(dtx / sqrt(Ddtx));
796 hpdty->Fill(dty / sqrt(Ddty));
797 xyz[0] = track->GetParamLast()->GetX() + XSHIFT;
798 xyz[1] = track->GetParamLast()->GetY() + YSHIFT;
799 xyz[2] = track->GetParamLast()->GetZ() + ZSHIFT;
800 tx = track->GetParamLast()->GetTx() + TXSHIFT;
801 ty = track->GetParamLast()->GetTy() + TYSHIFT;
802 xgoodtr = xyz[0] + tx * 100.;
803 ygoodtr = xyz[1] + ty * 100.;
804 hxytr->Fill(xgoodtr, ygoodtr);
805 // Selection criteria - x and y tracks matching
806 if (dxm < -DXGEMDCHMAX || dxm > +DXGEMDCHMAX)
807 continue;
808 if (dym < -DYGEMDCHMAX || dym > +DYGEMDCHMAX)
809 continue;
810 // if (dxm > -DXGEMDCHMAX && dxm < +DXGEMDCHMAX)
811 // if (dym > -DYGEMDCHMAX && dym < +DYGEMDCHMAX) continue;
812 hchi2m->Fill(Chi2m);
813 // if (Chi2m > 30.f) continue;
814 chi2 = dxm * dxm / Ddx + dym * dym / Ddy;
815 hchi2->Fill(chi2);
816 // if (chi2 > 30.f) continue;
817 ntr0++;
818 hdxy->Fill(dxm, dym);
819 le = gemdchtrack->GetLength() - ztarg;
820 p = QpGem;
821 ps = p;
822 if (p == 0.)
823 continue;
824 p = 1. / p;
825 p *= PSCALE;
826 hptr->Fill(p); // GeV/c
827 hltr->Fill(le); // cm
828 pmod = TMath::Abs(p);
829 // get xyz and cxyz here
830 hxygoodtr->Fill(xgoodtr, ygoodtr);
831 cxyz[0] = tx / TMath::Sqrt(1. + tx * tx + ty * ty);
832 cxyz[1] = ty / TMath::Sqrt(1. + tx * tx + ty * ty);
833 cxyz[2] = 1. / TMath::Sqrt(1. + tx * tx + ty * ty);
834
835 int ncl0 = 0, ncl[NUMBER_CHAMBERS] = {0};
836 Float_t tcl[NUMBER_CHAMBERS][32] = {{0}};
837 Int_t acl[NUMBER_CHAMBERS][32] = {{0}};
838 Int_t wcl[NUMBER_CHAMBERS][32] = {{0}};
839 if (USE_CLUSTERS) {
840 for (int i = 0; i < NUMBER_CHAMBERS; i++) {
841 ncl[i] = 0;
842 int clstart = -1, clwidth = -1, cstr = -1;
843 float samps = 0., timemin = 1000000000.;
844 float widthmax = 0.;
845 int nstr = 32;
846 if (idchambers[i] > 100.f)
847 nstr = 16;
848 for (int j = 0; j < nstr && nhit[i] > 0; j++) {
849 if (tofWidths[i][j] > 0.) {
850 if (clstart < 0) {
851 clstart = j;
852 cstr = j;
853 timemin = tof[i][j];
854 widthmax = tofWidths[i][j];
855 } else {
856 if (MINTIME) {
857 if (tof[i][j] < timemin) {
858 timemin = tof[i][j];
859 cstr = j;
860 }
861 } else {
862 if (tofWidths[i][j] > widthmax) {
863 widthmax = tofWidths[i][j];
864 cstr = j;
865 }
866 }
867 }
868 samps += tofWidths[i][j];
869 if (j == (nstr - 1)) {
870 clchamb[ncl0] = i;
871 clstrip[ncl0] = cstr;
872 clwidth = (j + 1 - clstart);
873 tcl[i][ncl[i]] = timemin;
874 acl[i][ncl[i]] = samps;
875 wcl[i][ncl[i]] = clwidth;
876 ncl0++;
877 ncl[i]++;
878 samps = 0.;
879 timemin = 1000000000.;
880 widthmax = 0.;
881 }
882 } else if (clstart >= 0) {
883 clchamb[ncl0] = i;
884 clstrip[ncl0] = cstr;
885 clwidth = (j - clstart);
886 tcl[i][ncl[i]] = timemin;
887 acl[i][ncl[i]] = samps;
888 wcl[i][ncl[i]] = clwidth;
889 ncl0++;
890 ncl[i]++;
891 samps = 0.;
892 timemin = 1000000000.;
893 widthmax = 0.;
894 clstart = -1;
895 }
896 }
897 }
898 himin = -1;
899 dist = 0.;
900 distmin = 1000000000.0f;
901 for (int icl = 0; icl < ncl0; icl++) {
902 ic = clchamb[icl];
903 is = clstrip[icl];
904 int ih = numhit[ic][is];
905 if (usedstrip[ih])
906 continue;
907 dz = zhi[ih] - xyz[2];
908 xrpc = xyz[0] + dz * tx;
909 yrpc = xyz[1] + dz * ty;
910 if (!XYPANIN) {
911 if ((xrpc - xhic[ih]) < -(halfwidthx[ic] + DXMAX)
912 || (xrpc - xhic[ih]) > +(halfwidthx[ic] + DXMAX))
913 continue;
914 if ((yrpc - yhic[ih]) < -(halfwidthy[ic] + DYMAX)
915 || (yrpc - yhic[ih]) > +(halfwidthy[ic] + DYMAX))
916 continue;
917 }
918 dx = xrpc - xhi[ih];
919 dy = yrpc - yhi[ih];
920 if (XYPANIN) {
921 if (TMath::Abs(dx) > DXMAXPAN)
922 continue;
923 if (TMath::Abs(dy) > DYMAXPAN)
924 continue;
925 dist = TMath::Sqrt(dx * dx + dy * dy);
926 } else {
927 dist = TMath::Sqrt(dx * dx / XFACTOR + dy * dy);
928 }
929 if (dist < distmin) {
930 distmin = dist;
931 himin = numhit[ic][is];
932 }
933 }
934 } else {
935 nh = nhi;
936 himin = -1;
937 dist = 0.;
938 distmin = 1000000000.0f;
939 for (int ih = 0; ih < nh; ih++) {
940 if (usedstrip[ih])
941 continue;
942 ic = hchamb[ih];
943 is = hstrip[ih];
944 dz = zhi[ih] - xyz[2];
945 xrpc = xyz[0] + dz * tx;
946 yrpc = xyz[1] + dz * ty;
947 if (!XYPANIN) {
948 if ((xrpc - xhic[ih]) < -(halfwidthx[ic] + DXMAX)
949 || (xrpc - xhic[ih]) > +(halfwidthx[ic] + DXMAX))
950 continue;
951 if ((yrpc - yhic[ih]) < -(halfwidthy[ic] + DYMAX)
952 || (yrpc - yhic[ih]) > +(halfwidthy[ic] + DYMAX))
953 continue;
954 }
955 dx = xrpc - xhi[ih];
956 dy = yrpc - yhi[ih];
957 if (XYPANIN) {
958 if (TMath::Abs(dx) > DXMAXPAN)
959 continue;
960 if (TMath::Abs(dy) > DYMAXPAN)
961 continue;
962 dist = TMath::Sqrt(dx * dx + dy * dy);
963 } else {
964 dist = TMath::Sqrt(dx * dx / XFACTOR + dy * dy);
965 }
966 if (dist < distmin) {
967 distmin = dist;
968 himin = ih;
969 }
970 }
971 }
972 if (himin < 0)
973 continue;
974 // Selection criteria on minimal distance track-hit
975 if (distmin > DISTMAX)
976 continue;
977 usedstrip[himin] = true;
978 hdxytof->Fill(dxm, dym);
979 hxygoodhit->Fill(xgoodtr, ygoodtr);
980 ic = hchamb[himin];
981 is = hstrip[himin];
982 xc = xhic[himin];
983 yc = yhic[himin];
984 zc = zhic[himin];
985 dz = zhi[himin] - xyz[2];
986 xrpc = xyz[0] + dz * tx;
987 yrpc = xyz[1] + dz * ty;
988
989 hxyhit->Fill(xrpc - xhi[himin], yrpc - yhi[himin]);
990 if (idchambers[ic] < 100.f)
991 hlrdiffs->Fill(lrd[himin]);
992 if (idchambers[ic] > 100.f)
993 hlrdiffb->Fill(lrd[himin]);
994 hxdiff->Fill(xhi[himin] - xc);
995 if (idchambers[ic] < 100.f)
996 hxxhits->Fill(xhi[himin] - xc, xrpc - xc);
997 if (idchambers[ic] > 100.f)
998 hxxhitb->Fill(xhi[himin] - xc, xrpc - xc);
999 if (idchambers[ic] < 100.f)
1000 hlrxhits->Fill(lrd[himin], xhi[himin] - xc);
1001 if (idchambers[ic] > 100.f)
1002 hlrxhitb->Fill(lrd[himin], xhi[himin] - xc);
1003
1004 if (idchambers[ic] < 100.f)
1005 hlrxtrs->Fill(lrd[himin], xrpc - xc);
1006 if (idchambers[ic] > 100.f)
1007 hlrxtrb->Fill(lrd[himin], xrpc - xc);
1008
1009 if (lrd[himin] > 0. && (xhi[himin] - xc) > 0.)
1010 hcsignp->Fill(ic);
1011 if (lrd[himin] < 0. && (xhi[himin] - xc) < 0.)
1012 hcsignp->Fill(ic);
1013 if (lrd[himin] > 0. && (xhi[himin] - xc) < 0.)
1014 hcsignm->Fill(ic);
1015 if (lrd[himin] < 0. && (xhi[himin] - xc) > 0.)
1016 hcsignm->Fill(ic);
1017
1018 cosa = sqrt(1. + tx * tx + ty * ty);
1019 dl = dz * cosa;
1020 lenr = le + dl;
1021 hltra->Fill(lenr);
1022 hidist = TMath::Sqrt(xc * xc + yc * yc + (zc - ztarg) * (zc - ztarg));
1023 // Selection criteria time-of-flight
1024 if (tof[ic][is] > TOFMAX)
1025 continue;
1026 hstrtr->Fill(is);
1027 hchatr->Fill(ic);
1028 hxytrtof->Fill(xrpc, yrpc);
1029
1030 htoftr->Fill(tof[ic][is]);
1031 //
1032 tofr = 0.f;
1033 if (CALIBRATION == 0) {
1034 tofr = tof[ic][is] + tofcalmc[ic];
1035 } else if (CALIBRATION == 1) {
1036 tofr = tof[ic][is] + lenr / cpeak;
1037 } else if (CALIBRATION == 2) {
1038 tofr = tof[ic][is] + tofcalmc[ic];
1039 } else if (CALIBRATION == 3) {
1040 tofr = tof[ic][is] + tofcalmc[ic];
1041 } else {
1042 continue;
1043 }
1044 tofr0 = tof[ic][is];
1045 tofp = 0.f;
1046 tofpi = 0.f;
1047 beta = lenr / tofr / cvel;
1048 // Selection criteria
1049 if (beta <= 0.)
1050 continue;
1051 mass2 = p * p * (1.f / beta / beta - 1.f);
1052 mass = TMath::Sqrt(mass2);
1053 hpbeta->Fill(fabs(p), beta);
1054 hmass->Fill(mass2);
1055 hmassvsp->Fill(fabs(p), mass2);
1056
1057 massmin1 = MP2 - MP2 / (DMPSCALE1 * PMAX1) * (p - 0.5);
1058 massmax1 = MP2 + MP2 / (DMPSCALE2 * PMAX1) * (p - 0.5);
1059 if (p > 0.f && mass2 > massmin1 && mass2 < massmax1 && pmod > PMIN && pmod < PMAX) {
1060 tofp = (lenr / 29.97925f) * TMath::Sqrt(MP2 + p * p) / p;
1061 tcor = tofp - tofr;
1062 tcorc = tcor - tofcalc[ic];
1063 tcors = tcor - tofcals[ic][is];
1064 tcalibrc->Fill(ic, tcorc);
1065 tcalibrs->Fill(ic, is, tcors);
1066 htofp->Fill(tofr0);
1067 massmin2 = MP2 - MP2 / (DMPSCALET1 * PMAX2) * (p - 0.5);
1068 massmax2 = MP2 + MP2 / (DMPSCALET2 * PMAX2) * (p - 0.5);
1069 if (mass2 > massmin2 && mass2 < massmax2) {
1070 hdtpc->Fill(tcorc);
1071 hdtpcvsp->Fill(p, tcorc);
1072 hdtps->Fill(tcors);
1073 hdtpsvsp->Fill(p, tcors);
1074 if (p > PRES)
1075 hdtpcplim->Fill(tcorc);
1076 if (p > PRES1)
1077 hdtpcp1lim->Fill(tcorc);
1078 if (p < 2.0f)
1079 hdtpcp2lim->Fill(tcorc);
1080 if (p >= 2.0f && p < 5.0f)
1081 hdtpcp3lim->Fill(tcorc);
1082 if (tofWidths[ic][is] > WMIN && tofWidths[ic][is] < WMAX) {
1083 hdtpcwlim->Fill(tcorc);
1084 hdtpcvspwlim->Fill(p, tcorc);
1085 if (p > PRES)
1086 hdtpcwplim->Fill(tcorc);
1087 if (p > PRES1)
1088 hdtpcwp1lim->Fill(tcorc);
1089 }
1090 }
1091 }
1092 // massmaxpi = 0.1 + MPIMAX*TMath::Abs(p-0.5)/PMAXPI/DMPISCALE; // Kapishin
1093 massmaxpi = 0.1 + MPIMAX * TMath::Abs(pmod - 0.5) / PMAXPI;
1094 if (p > 0 && massmaxpi > massmin1)
1095 massmaxpi = massmin1;
1096 // massminpi =-0.1 - MPIMAX*TMath::Abs(p-0.5)/PMAXPI/DMPISCALE; // Kapishin
1097 massminpi = -0.1 - MPIMAX * TMath::Abs(pmod - 0.5) / PMAXPI;
1098 if (mass2 < massmaxpi && mass2 > massminpi && pmod > PMIN && pmod < PMAXPI) {
1099 tofpi = (lenr / 29.97925f) * TMath::Sqrt(MPI2 + p * p) / pmod;
1100 tcorpi = tofpi - tofr;
1101 tcorcpi = tcorpi - tofcalc[ic];
1102 tcorspi = tcorpi - tofcals[ic][is];
1103 tcalibrc->Fill(ic, tcorcpi);
1104 tcalibrs->Fill(ic, is, tcorspi);
1105 }
1106 timepeak = tofcalmc[ic] + tofcalc[ic];
1107 betapeak = lenr / timepeak / cvel;
1108 tpeak->Fill(ic, timepeak);
1109 bpeak->Fill(ic, betapeak);
1110 tofrc = tofr + tofcalc[ic];
1111 tofrs = tofr + tofcals[ic][is];
1112 betac = lenr / tofrc / cvel;
1113 betas = lenr / tofrs / cvel;
1114 masss2 = p * p * (1.f / betas / betas - 1.f);
1115 masss = TMath::Sqrt(masss2);
1116 massc2 = p * p * (1.f / betac / betac - 1.f);
1117 massc = TMath::Sqrt(massc2);
1118 if (p > 0) {
1119 hpbetac->Fill(p, betac);
1120 hmassc->Fill(massc2);
1121 hmasscvsp->Fill(p, massc2);
1122 hpbetas->Fill(p, betas);
1123 hmasss->Fill(masss2);
1124 hmasssvsp->Fill(p, masss2);
1125 if (p < 1.5) {
1126 hmasss15->Fill(masss2);
1127 hmassc15->Fill(massc2);
1128 }
1129 if (p < 2.0) {
1130 hmasss20->Fill(masss2);
1131 hmassc20->Fill(massc2);
1132 }
1133 } else {
1134 hpbetacm->Fill(fabs(p), betac);
1135 hmasscm->Fill(massc2);
1136 hmasscmvsp->Fill(fabs(p), massc2);
1137 hpbetasm->Fill(fabs(p), betas);
1138 hmasssm->Fill(masss2);
1139 hmasssmvsp->Fill(fabs(p), masss2);
1140 }
1141 } // tracks loop
1142 hntr1->Fill(ntr1);
1143 Ntr1 += ntr1;
1144 Ntr1g += ntr1g;
1145 hntr0->Fill(ntr0);
1146 Ntr0 += ntr0;
1147 // t_out->Fill();
1148 } // event loop
1149
1150 TH1D *projtmp = 0, *projtmp1 = 0;
1151 hdxyeff->Divide(hdxytof, hdxy);
1152 hdxeff->Divide((projtmp = hdxytof->ProjectionX()), (projtmp1 = hdxy->ProjectionX()));
1153 if (projtmp)
1154 delete projtmp;
1155 if (projtmp1)
1156 delete projtmp1;
1157 hdyeff->Divide((projtmp = hdxytof->ProjectionY()), (projtmp1 = hdxy->ProjectionY()));
1158 if (projtmp)
1159 delete projtmp;
1160 if (projtmp1)
1161 delete projtmp1;
1162 hxyeff->Divide(hxygoodhit, hxygoodtr);
1163 hxeff->Divide((projtmp = hxygoodhit->ProjectionX()), (projtmp1 = hxygoodtr->ProjectionX()));
1164 if (projtmp)
1165 delete projtmp;
1166 if (projtmp1)
1167 delete projtmp1;
1168 hyeff->Divide((projtmp = hxygoodhit->ProjectionY()), (projtmp1 = hxygoodtr->ProjectionY()));
1169 if (projtmp)
1170 delete projtmp;
1171 if (projtmp1)
1172 delete projtmp1;
1173
1174 if (FLAG < 0) {
1175 printf("Number of tracks %d, per event %f\n", Ntr, (float)Ntr / nEvents);
1176 printf("GEM+DCH1+DCH2 tracks %d, per event %f (%f%% per track)\n", Ntr1, (float)Ntr1 / nEvents,
1177 (float)Ntr1 / Ntr * 100.f);
1178 printf("Good GEM+DCH1+DCH2 tracks %d, per event %f (%f%% per track)\n", Ntr0, (float)Ntr0 / nEvents,
1179 (float)Ntr0 / Ntr * 100.f);
1180 } else if (FLAG > 0) {
1181 printf("Number of tracks %d, per event %f\n", Ntr, (float)Ntr / nEvents);
1182 printf("GEM+DCH1 tracks %d, per event %f (%f%% per track)\n", Ntr1, (float)Ntr1 / nEvents,
1183 (float)Ntr1 / Ntr * 100.f);
1184 printf("Good GEM+DCH1 tracks %d, per event %f (%f%% per track)\n", Ntr0, (float)Ntr0 / nEvents,
1185 (float)Ntr0 / Ntr * 100.f);
1186 } else {
1187 printf("Number of tracks %d, per event %f\n", Ntr, (float)Ntr / nEvents);
1188 printf("GEM+DCH tracks %d, per event %f (%f%% per track)\n", Ntr1, (float)Ntr1 / nEvents,
1189 Ntr > 0 ? (float)Ntr1 / Ntr * 100.f : 0.f);
1190 printf("Good GEM+DCH tracks %d, per event %f (%f%% per valid track)\n", Ntr1g, (float)Ntr1g / nEvents,
1191 Ntr1 > 0 ? (float)Ntr1g / Ntr1 * 100.f : 0.f);
1192 printf("Matched GEM+DCH tracks %d, per event %f (%f%% per good track)\n", Ntr0, (float)Ntr0 / nEvents,
1193 Ntr1g > 0 ? (float)Ntr0 / Ntr1g * 100.f : 0.f);
1194 }
1195
1196 if (f) {
1197 f->Write();
1198 }
1199
1200 if (WRITE_CALIBRATION) {
1201 char fname_calibr_root[128], *delim = 0;
1202 strcpy(fname_calibr_root, gSystem->BaseName(fnametof700));
1203 if ((delim = strrchr(fname_calibr_root, (int)'.')))
1204 *delim = '\0';
1205 strcat(fname_calibr_root, "_calibration.root");
1206 TFile* fc = new TFile(fname_calibr_root, "RECREATE", "Proton mass based calibration of BmnTOF700");
1207 tcalibrs->Write();
1208 tcalibrc->Write();
1209 fc->Close();
1210 }
1211
1212 return;
1213}
1214
1216{
1217 // example of macro called when a mouse event occurs in a pad.
1218 // Example:
1219 // Root > TFile f("hsimple.root");
1220 // Root > hpxpy.Draw();
1221 // Root > c1.AddExec("exsel","select_hist()");
1222 // When moving the mouse in the canvas, a second canvas shows the
1223 // projection along X of the bin corresponding to the Y position
1224 // of the mouse. The resulting histogram is fitted with a gaussian.
1225 // A "dynamic" line shows the current bin position in Y.
1226 // This more elaborated example can be used as a starting point
1227 // to develop more powerful interactive applications exploiting CINT
1228 // as a development engine.
1229 // Author: Rene Brun
1230
1231 int event = gPad->GetEvent();
1232 if (event != 11)
1233 return;
1234
1235 TObject* select = gPad->GetSelected();
1236 if (!select)
1237 return;
1238 if (!(select->InheritsFrom("TH1")))
1239 return;
1240
1241 // create or set the new canvas c2
1242 TCanvas* csingle = 0;
1243 if ((csingle = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("csingle")))
1244 ;
1245 else
1246 csingle = new TCanvas("csingle");
1247 csingle->cd();
1248
1249 // draw slice corresponding to mouse position
1250 if (!(select->InheritsFrom("TH1F"))) {
1251 TH1F* h = (TH1F*)select;
1252 h->Draw();
1253 } else if (!(select->InheritsFrom("TH2F"))) {
1254 TH2F* h = (TH2F*)select;
1255 h->Draw();
1256 } else if (!(select->InheritsFrom("TProfile"))) {
1257 TProfile* h = (TProfile*)select;
1258 h->Draw();
1259 } else if (!(select->InheritsFrom("TH1D"))) {
1260 TH1D* h = (TH1D*)select;
1261 h->Draw();
1262 } else if (!(select->InheritsFrom("TH2D"))) {
1263 TH2D* h = (TH2D*)select;
1264 h->Draw();
1265 } else if (!(select->InheritsFrom("TProfile2D"))) {
1266 TProfile2D* h = (TProfile2D*)select;
1267 h->Draw();
1268 } else
1269 return;
1270 csingle->Update();
1271}
1272
1273int readMCTimeFile(const char* MCTimeFile)
1274{
1275 // cout << "readMCTimeFile: " << MCTimeFile << endl;
1276 float idchambers[59] = {27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1, 19.3, 31.1, 6.1,
1277 2.1, 32.1, 15.2, 16.2, 17.2, 18.2, 19.2, 20.2, 7.1, 115.2, 113.1, 117.1,
1278 35.1, 9.1, 37.1, 11.1, 39.1, 13.1, 34.1, 8.1, 36.1, 10.1, 38.1, 12.1,
1279 21.2, 23.2, 25.2, 22.2, 24.2, 26.2, 107.2, 108.2, 109.2, 110.2, 111.2, 112.2,
1280 114.1, 116.2, 118.1, 14.1, 40.1, 119.2, 120.2, 121.2, 122.2, 123.2, 124.2};
1281 bool notused[59] = {true};
1282 int order[59] = {-1};
1283 int c = 0, cmin = -1, c0 = 0;
1284 float idmin = 200.f;
1285 for (c0 = 0; c0 < 59; c0++) {
1286 notused[c0] = true;
1287 order[c0] = -1;
1288 }
1289 for (c0 = 0; c0 < 59; c0++) {
1290 cmin = -1;
1291 idmin = 200.f;
1292 for (c = 0; c < 59; c++) {
1293 if (notused[c] && (idchambers[c] < idmin)) {
1294 idmin = idchambers[c];
1295 cmin = c;
1296 }
1297 }
1298 // printf("c0 %d cmin %d notused %d\n",c0,cmin,(int)notused[cmin]);
1299 if (cmin >= 0) {
1300 notused[cmin] = false;
1301 order[c0] = cmin;
1302 }
1303 }
1304 char fname[128];
1305 FILE* ft = 0;
1306 float time = 0.f, timesigma = 0.f;
1307 if (MCTimeFile == NULL) {
1308 printf("TOF700 MC time-of-flight file name not defined!\n");
1309 return 0;
1310 }
1311 if (strlen(MCTimeFile) == 0) {
1312 printf("TOF700 MC time-of-flight file name not defined!\n");
1313 return 0;
1314 }
1315 TString dir = getenv("VMCWORKDIR");
1316 sprintf(fname, "%s/geometry/%s", dir.Data(), MCTimeFile);
1317 ft = fopen(fname, "r");
1318 if (ft == NULL) {
1319 printf("TOF700 MC time-of-flight file %s open error!\n", fname);
1320 return 0;
1321 }
1322 int cexp = 0, ic = -1;
1323 while (fscanf(ft, "%d %f %f\n", &ic, &time, &timesigma) == 3) {
1324 if (ic > 0 && ic <= 59) {
1325 cexp = order[ic - 1];
1326 tofcalmc[cexp] = time;
1327 if (1)
1328 printf("Chamber %.1f (MC %d, EXP %d) average time-of-flight %f with sigma %f\n", idchambers[cexp], ic,
1329 cexp, time, timesigma);
1330 }
1331 }
1332 fclose(ft);
1333 return 1;
1334}
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
Definition BmnMath.cxx:869
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
unsigned int UInt_t
float Float_t
short Short_t
double Double_t
#define R__ADD_INCLUDE_PATH(PATH)
#define gROOT
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
#define gPad
Double_t GetDdtx() const
Double_t GetDtx() const
Double_t GetYpv() const
Double_t GetChi2() const
Double_t GetDdx() const
CbmStsTrack * GetGemTrack()
Int_t GetEventId() const
Double_t GetDdty() const
Double_t GetLength() const
Double_t GetXpv() const
Double_t GetDdy() const
Double_t GetDx() const
Double_t GetDty() const
Double_t GetDy() const
BmnTrack * GetDchTrack()
Short_t GetPlane() const
Short_t GetStrip() const
Float_t GetTime() const
Float_t GetAmplitude() const
Int_t GetNDF() const
Definition BmnTrack.h:57
Int_t GetNHits() const
Accessors.
Definition BmnTrack.h:49
FairTrackParam * GetParamLast()
Definition BmnTrack.h:65
Int_t GetFlag() const
Definition BmnTrack.h:53
TVirtualPad * cd(Int_t subpadnumber=0) override
void Update() 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
T * Get(const char *namecycle)
void Close(Option_t *option="") override
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual Bool_t Divide(const TH1 *h1)
virtual void SetOption(Option_t *option=" ")
TH1D * ProjectionY(const char *name="_py", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
TH1D * ProjectionX(const char *name="_px", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="") const
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
TObject * UncheckedAt(Int_t i) const
virtual UInt_t GetUniqueID() const
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Int_t Fill(const char *namex, const char *namey, Double_t z) override
Int_t Fill(const char *namex, Double_t y) override
const char * Data() const
double beta(double x, double y)
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
#define IN_WIDTH_LIMITS
int wma[NUMBER_CHAMBERS]
#define NUMBER_CHAMBERS
float idchambers[59]
int wmi[NUMBER_CHAMBERS]
#define WMIN
#define PMAX2
int nhits[NUMBER_CHAMBERS][32]
#define CVERS
float tofWidths[NUMBER_CHAMBERS][32]
#define YSHIFT
#define MPIMAX
#define DMPSCALET2
double yhi[1000]
#define TXSHIFT
#define GEMDEBUG
#define XYPANIN
Double_t tofcalc[NUMBER_CHAMBERS]
TProfile * itcalibrc
#define DYMAXPAN
#define DISTMAX
#define PMAX
Float_t halfwidthy[NUMBER_CHAMBERS]
#define CALIBRATION
#define XFACTOR
Float_t halfwidthx[NUMBER_CHAMBERS]
double zhic[1000]
#define MP
#define DXMAXPAN
#define PRES
float tof[NUMBER_CHAMBERS][32]
#define USE_CLUSTERS
double lrd[1000]
#define LIST_STRIP_CORRECTIONS
#define XSHIFT
double xhi[1000]
#define PMIN
#define ZSHIFT
#define STRIP_CORRECTIONS
#define DXGEMDCHMAX
#define MPI2
double yhic[1000]
#define TYSHIFT
#define WRITE_CALIBRATION
#define DMPSCALE2
Double_t tofcals[NUMBER_CHAMBERS][32]
#define DXMAX
#define GEMCUTS
#define PMAXPI
#define PSCALE
#define WMAX
Double_t tofcalmc[NUMBER_CHAMBERS]
double zhi[1000]
#define PRES1
#define DMPSCALE1
#define MINGEMNDF
#define MINTIME
#define DYMAX
double xhic[1000]
#define CFACTOR
#define MP2
int nhit[NUMBER_CHAMBERS]
#define PMAX1
#define DYGEMDCHMAX
#define TOFMAX
TProfile2D * itcalibr
#define DMPSCALET1
void BmnIdentificationTOF700(const char *TracksGemDch="argon_tracks_gleb_newall_files.txt", const char *DigitsTOF700="argon_tof700_digits_files.txt")
Int_t readMCTimeFile(const char *MCTimeFile="TOF700_MC_argon_qgsm_time_run7.txt")
void select_hist()
#define FLAG
Bool_t IsNaN(Double_t x)
Double_t Sqrt(Double_t x)
Double_t Abs(Double_t d)
Definition json.hpp:4446