BmnRoot
Loading...
Searching...
No Matches
BmnTof2Raw2DigitNew.cxx
Go to the documentation of this file.
2
3#include "FairLogger.h"
4#include "TCanvas.h"
5#include "TF1.h"
6#include "TFile.h"
7#include "TFitResult.h"
8#include "TH2D.h"
9#include "TLine.h"
10#include "TPRegexp.h"
11#include "TProfile2D.h"
12#include "TROOT.h"
13#include "TStyle.h"
14#include "TSystem.h"
15
16// Digitization stage flags
17// use hits in time limits
18#define CHECK_SLEWING 0
19#define TIME_LIMITS_VS_WIDTH 0
20#define USE_PRELIMINARY_OFFSETS 1
21#define USE_FIT_SLEWING 0
22// USE_FINAL_OFFSETS 0 - don't apply final strip offsets
23// USE_FINAL_OFFSETS 1 - apply final strip offsets (calculated as mean)
24// USE_FINAL_OFFSETS 2 - apply final strip offsets (calculated by time peak fit)
25#define USE_FINAL_OFFSETS 1
26//
27
28// Slewing Time limits flags
29#define LIMITS_ROOT_FILE 1
30#define PRINT_TIME_LIMITS 1
31
32// Strip equalization before slewing
33#define PRELIMINARY_OFFSETS 1
34#define EQUAL_MAXIMA0 1
35#define FIT_MAXIMA0 0
36#define PRINT_EQUALIZATION0_RESULTS 0
37#define DEBUG_EQUALIZATION0 1
38//
39
40// Slewing flags
41// Use for slewing plots not all hits in chamber but hit with maximal width
42#define MAX_STRIP 0
43#define FIT_SLEWING 0
44#define SKIP_SIDES 0
45#define MAX_FIT_ATTEMPTS 5
46#define MIN_FIT_ENTRIES 10
47#define SMOOTH 0
48#define FIT0 "Q0RS+"
49#define FIT "Q0RS+"
50#define FITI "Q0RS+"
51#define FITI0 "Q0RS+"
52#define SUBRANGES 0
53#define SUBDEG 4
54#define ITERATIONS 1
55#define ITERATIONS0 1
56#define DRAW_BAD 0
57#define DRAW_GOOD 0
58#define PRINT_SLEWING_RESULTS 0
59#define PRINT_SLEWING_PARAMETERS 0
60#define PRINT_FIT_RESULTS 0
61//
62
63// Strip equalization after slewing
64#define FINAL_OFFSETS 1
65#define TOZERO 1
66#define EQUAL_MAXIMA 1
67#define FIT_MAXIMA 1
68#define PRINT_EQUALIZATION_RESULTS 0
69#define DEBUG_EQUALIZATION 1
70
71#define MIN_RAW_LEADING_TIME 57500
72#define MAX_RAW_LEADING_TIME 67500
73#define MIN_RAW_TRAILING_TIME 60000
74#define MAX_RAW_TRAILING_TIME 71000
75#define MIN_RAW_T0_TIME 81000
76#define MAX_RAW_T0_TIME 84000
77
78// module IDs
79const UInt_t kTDC64VHLE = 0x53;
80const UInt_t kTDC64VHLE_E = 0xD3;
81const UInt_t kTDC72VHL = 0x12;
82const UInt_t kTDC32VL = 0x11;
83
88
90 TString RunFile,
91 Int_t SlewingRun,
92 UInt_t SlewingChamber,
93 TString geomFile)
94{
95
96 char* delim = 0 /*, name[128], title[128]*/;
97 n_rec = 0;
98 TString dummy;
99
100 TString dir = getenv("VMCWORKDIR");
101 TString path = dir + "/input/";
102 strcpy(filname_base, gSystem->BaseName(RunFile.Data()));
103 if ((delim = strrchr(filname_base, (int)'.')))
104 *delim = '\0';
105 strcpy(filname_base_results, filname_base);
106
107 int RUN = 0;
108 const char* fname = RunFile.Data();
109 if (strlen(fname) > 0) {
110 TString runString(fname);
111 TPRegexp(".*bmn_run(\\d+).*\\.root").Substitute(runString, "$1");
112 RUN = runString.Atoi();
113 if (RUN <= 0) {
114 LOGF(error, "Run file: \"%s\" - can't extract run number!", RunFile.Data());
115 return;
116 }
117 fRUN = RUN;
118 } else {
119 fRUN = 0;
120 }
121 ifstream in;
122 in.open((path + mappingFile).Data());
123 if (!in.is_open()) {
124 LOGF(info, "Loading TOF700 Map from file: %s - file open error!", mappingFile.Data());
125 return;
126 }
127
128 fSlewCham = SlewingChamber;
129 fSlewRun = fRUN;
130 if (SlewingRun > 0) {
131 fSlewRun = SlewingRun;
132 sprintf((char*)&filname_base[0], "bmn_run%04d_raw", SlewingRun);
133
134 if (SlewingChamber == 0)
135 LOGF(debug, "Loading TOF700 Map from file: %s , reference slewing run %d", mappingFile.Data(), SlewingRun);
136 else
137 LOGF(debug, "Loading TOF700 Map from file: %s , reference slewing run %d, chamber %d", mappingFile.Data(),
138 SlewingRun, SlewingChamber);
139 } else if (SlewingRun < 0) {
140 fSlewRun = SlewingRun;
141 if (fRUN > 0)
142 LOGF(debug, "Loading TOF700 Map from file: %s , reference slewing run %d", mappingFile.Data(), fRUN);
143 else
144 LOGF(debug, "Loading TOF700 Map from file: %s , without slewing corrections!", mappingFile.Data());
145 // LOGF(info,"Loading TOF700 Map from file: %s",mappingFile.Data());
146 // LOGF(info,"Loading TOF700 Map from file: %s, without slewing corrections!",mappingFile.Data());
147 } else {
148 if (fRUN > 0)
149 LOGF(info, "Loading TOF700 Map from file: %s , reference slewing run %d", mappingFile.Data(), fRUN);
150 else
151 LOGF(info, "Loading TOF700 Map from file: %s , without slewing corrections!", mappingFile.Data());
152 // LOGF(info,"Loading TOF700 Map from file: %s",mappingFile.Data());
153 }
154
155 if (strstr((char*)mappingFile.Data(), "SRC"))
156 fSRC = 1;
157 else
158 fSRC = 0;
159
160 fPeriod = 8;
161 char* perstr;
162 if ((perstr = strstr((char*)mappingFile.Data(), "period"))) {
163 int per = 0;
164 if (sscanf(perstr, "period_%d", &per) == 1)
165 fPeriod = per;
166 }
167
168 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++) {
169 strcpy(&filname_slewing[i][0], filname_base);
170 chamber_slewing[i] = fSlewCham;
171 type_slewing[i] = 0;
172 }
173 MaxPlane = 0;
174 TString dnlfile;
175 // char dnlfile[128];
176 unsigned devsernum;
177 int crate, slot, chan, plane /*, strip, side*/, filetype, cham, cable;
178 float idcham;
179 int id_crate;
180
181 for (int c = 0; c < TOF2_MAX_CRATES; c++)
182 for (int i = 0; i < TOF2_MAX_SLOTS_IN_CRATE; i++)
183 dnltype[c][i] = -1;
184
185 for (int c = 0; c < TOF2_MAX_CRATES; c++)
186 for (int s = 0; s < TOF2_MAX_SLOTS_IN_CRATE; s++)
187 for (int ch = 0; ch < TOF2_MAX_CHANNELS_IN_SLOT; ch++)
188 nrec[c][s][ch] = -1;
189
190 in >> dummy;
191 in >> ncrates;
192 in >> dummy >> dummy;
193 for (int i = 0; i < ncrates; i++) {
194 in >> std::dec >> crate >> std::hex >> id_crate;
195 if (!in.good())
196 break;
197 if (crate >= TOF2_MAX_CRATES)
198 break;
199 numcrates[i] = crate;
200 idcrates[crate] = id_crate;
201 if (in.eof())
202 break;
203 }
204 in >> dummy;
205 in >> std::dec >> nslots;
206 // LOGF(info,"%d",nslots);
207 in >> dummy >> dummy >> dummy >> dummy >> dummy;
208 // LOGF(info,"%s",dummy.Data());
209 // for (int i = 0; i < TOF2_MAX_SLOTS_IN_CRATE; i++)
210 for (int i = 0; i < (nslots + 1); i++) {
211 in >> crate >> slot >> std::hex >> devsernum >> std::dec >> filetype >> dnlfile;
212 // LOGF(info,"%d %d %d %s",crate,slot,filetype,dnlfile.Data());
213 if (!in.good())
214 break;
215 if (crate >= TOF2_MAX_CRATES)
216 break;
217 if (slot >= TOF2_MAX_SLOTS_IN_CRATE)
218 break;
219 devser[crate][slot] = devsernum;
220 devnum[i] = devsernum;
221 devcrate[i] = crate;
222 devslot[i] = slot;
223 numcr[i] = crate;
224 numslots[i] = slot;
225 dnltype[crate][slot] = filetype;
226 strcpy(&dnlname[crate][slot][0], path.Data());
227 strcat(&dnlname[crate][slot][0], dnlfile.Data());
228 if (in.eof())
229 break;
230 }
231
232 in >> dummy;
233 in >> nchambers;
234 // LOGF(info,"N_CHAMBERS = %d",nchambers);
235 in >> dummy >> dummy;
236 // LOGF(info,"%s",dummy.Data());
237 char line[256] = {""};
238 in.getline(line, 128);
239 for (int i = 0; i < nchambers; i++) {
240 in.getline(line, 128);
241 // in >> cham >> idcham;
242 sscanf(line, "%d\t\t%f\n", &cham, &idcham);
243 // LOGF(info,"%d %d %d %s",crate,slot,filetype,dnlfile.Data());
244 if (!in.good())
245 break;
246 if (cham >= TOF2_MAX_CHAMBERS)
247 break;
248 numcha[i] = cham;
249 idchambers[cham] = idcham;
250 if (in.eof())
251 break;
252 }
253
254 if (!in.eof())
255 in >> dummy >> dummy >> dummy >> dummy;
256 // LOGF(info,"%s",dummy.Data());
257 in.getline(line, 128);
258 // LOGF(info,"line %d %s", strlen(line),line);
259 while (!in.eof()) {
260 // in.getline(line,128);
261 // LOGF(info,"line %d %s", strlen(line),line);
262 in.getline(line, 128);
263 // LOGF(info,"line %d %s", strlen(line),line);
264 sscanf(line, "%d\t%d\t%d\t%d\n", &crate, &slot, &plane, &cable);
265 // in >> crate >> slot >> plane >> cable;
266 // LOGF(info,"%d %d %d %d",crate, slot, plane, cable);
267 if (!in.good())
268 break;
269 if (crate >= TOF2_MAX_CRATES)
270 break;
271 if (slot >= TOF2_MAX_SLOTS_IN_CRATE)
272 break;
273 if (plane >= TOF2_MAX_CHAMBERS)
274 break;
275 if (cable == 0) {
276 for (int ie = 1; ie <= 2; ie++) {
277 for (int is = 0; is < TOF2_MAX_STRIPS_IN_CHAMBER / 2; is++) {
278 mapa[n_rec].id = idcrates[crate];
279 mapa[n_rec].crate = crate;
280 mapa[n_rec].slot = slot;
281 mapa[n_rec].plane = plane;
282 mapa[n_rec].pair = -2;
283 chan = is + (ie - 1) * 16;
284 mapa[n_rec].chan = chan;
285 mapa[n_rec].strip = is;
286 mapa[n_rec].side = ie;
287 nrec[crate][slot][chan] = n_rec;
288 n_rec++;
289 }
290 }
291
292 for (int ie = 1; ie <= 2; ie++) {
293 for (int is = TOF2_MAX_STRIPS_IN_CHAMBER / 2; is < TOF2_MAX_STRIPS_IN_CHAMBER; is++) {
294 mapa[n_rec].id = idcrates[crate];
295 mapa[n_rec].crate = crate;
296 mapa[n_rec].slot = slot;
297 mapa[n_rec].plane = plane;
298 mapa[n_rec].pair = -2;
299 chan = 16 + is + (ie - 1) * 16;
300 mapa[n_rec].chan = chan;
301 mapa[n_rec].strip = is;
302 mapa[n_rec].side = ie;
303 nrec[crate][slot][chan] = n_rec;
304 n_rec++;
305 }
306 }
307 } else if (cable == 1) {
308 for (int ie = 1; ie <= 2; ie++) {
309 for (int is = 0; is < TOF2_MAX_STRIPS_IN_CHAMBER / 2; is++) {
310 mapa[n_rec].id = idcrates[crate];
311 mapa[n_rec].crate = crate;
312 mapa[n_rec].slot = slot;
313 mapa[n_rec].plane = plane;
314 mapa[n_rec].pair = -2;
315 chan = is + (ie - 1) * 16;
316 mapa[n_rec].chan = chan;
317 mapa[n_rec].strip = is;
318 mapa[n_rec].side = ie;
319 nrec[crate][slot][chan] = n_rec;
320 n_rec++;
321 }
322 }
323 } else if (cable == 2) {
324 for (int ie = 1; ie <= 2; ie++) {
325 for (int is = 0; is < TOF2_MAX_STRIPS_IN_CHAMBER / 2; is++) {
326 mapa[n_rec].id = idcrates[crate];
327 mapa[n_rec].crate = crate;
328 mapa[n_rec].slot = slot;
329 mapa[n_rec].plane = plane;
330 mapa[n_rec].pair = -2;
331 chan = 32 + is + (ie - 1) * 16;
332 mapa[n_rec].chan = chan;
333 mapa[n_rec].strip = is;
334 mapa[n_rec].side = ie;
335 nrec[crate][slot][chan] = n_rec;
336 n_rec++;
337 if (n_rec >= TOF2_MAX_CHANNEL)
338 break;
339 }
340 if (n_rec >= TOF2_MAX_CHANNEL)
341 break;
342 }
343 } else {
344 LOGF(error, "Wrong cable flag, line is %s", line);
345 continue;
346 }
347 if (n_rec >= TOF2_MAX_CHANNEL)
348 break;
349 if (plane > MaxPlane)
350 MaxPlane = plane;
351 }
352 if (n_rec)
353 MaxPlane++;
354 in.close();
355
356 // read channels offsets
357 for (int c = 0; c < 10; c++)
358 for (int i = 0; i < 25; i++) {
359 for (int j = 0; j < 64; j++)
360 chtima[c][i][j] = 0.;
361 }
362 readGeom(geomFile.Data());
363
364 // read Left-Right offsets
365 for (int c = 0; c < TOF2_MAX_CHAMBERS; c++) {
366
367 yslope[c] = 1.;
368 yoffset[c] = 0.;
369 for (int i = 0; i < TOF2_MAX_STRIPS_IN_CHAMBER; i++) {
370 lroffsets[c][i] = 0.;
371 lrsign[c][i] = +1;
372 xoffset[c][i] = 0.;
373 xslope[c][i] = 0.;
374 }
375 }
376 readLRoffsets((char*)"TOF700_left_right_offsets.txt");
377 // 15 cm/ns
378 fVelosity = 8.39f;
379 readXYCalibration((char*)"TOF700_tdiff_to_x_final_2019071.txt", (char*)"Y_calibration.txt");
380 // Argon data calibration
381 for (int c = 0; c < TOF2_MAX_CHAMBERS; c++) {
382 for (int i = 0; i < TOF2_MAX_STRIPS_IN_CHAMBER; i++) {
383 interxg[c][i] = 0.;
384 slopexg[c][i] = 0.;
385 interxl[c][i] = 0.;
386 slopexl[c][i] = 0.;
387 shifty[c][i] = 0.;
388 }
389 }
390 readXYCalibrationNew((char*)"bmn_run9687_digi_x_calibration.txt", (char*)"bmn_run9687_digi_y_calibration.txt");
391
392 for (int ind = 0; ind < n_rec; ind++) {
393 if (mapa[ind].pair == -1)
394 continue;
395 for (int ind1 = 0; ind1 < n_rec; ind1++) {
396 if (ind == ind1)
397 continue;
398 if (mapa[ind1].plane == mapa[ind].plane && mapa[ind1].strip == mapa[ind].strip) {
399 mapa[ind].pair = ind1;
400 mapa[ind1].pair = -1;
401 break;
402 }
403 }
404 }
405
406 LOGF(debug, "\n===========================================================================");
407 LOGF(debug, "Number of chambers %d, crates %d, slots %d, TDC channels %d\n", MaxPlane, ncrates, nslots, n_rec);
408 LOGF(debug, " #\tcrate\tcrateID\n===========================================================================");
409 for (int i = 0; i < ncrates; i++) {
410 LOGF(debug, "%3d\t%d\t0x%0x", i, numcrates[i], idcrates[numcrates[i]]);
411 }
412 LOGF(debug, "===========================================================================");
413 LOGF(debug, " #\tchamber\tchamberID\n===========================================================================");
414 for (int i = 0; i < nchambers; i++) {
415 LOGF(debug, "%3d\t%d\t%5.1f", i, numcha[i], idchambers[numcha[i]]);
416 }
417 LOGF(debug, "===========================================================================");
418 LOGF(debug, " "
419 "#\tcrate\tslot\tdevsernum\tfiletype\tfile\n==========================================================="
420 "================");
421 for (int i = 0; i < nslots + 1; i++) {
422 LOGF(debug, "%3d\t%d\t%d\t%0x\t\t%d\t%s", i, numcr[i], numslots[i], devser[numcr[i]][numslots[i]],
423 dnltype[numcr[i]][numslots[i]], dnlname[numcr[i]][numslots[i]]);
424 }
425 LOGF(debug, "===========================================================================");
426 if (false) {
427 LOGF(debug, " "
428 "#\tcrate\tslot\tchannel\tplane\tstrip\tside\n====================================================="
429 "======================");
430 for (int i = 0; i < n_rec; i++) {
431 LOGF(debug, "%4d\t%d\t%d\t%d\t%d\t%d\t%d", i, mapa[i].crate, mapa[i].slot, mapa[i].chan, mapa[i].plane,
432 mapa[i].strip, mapa[i].side);
433 }
434 }
435 LOGF(debug, "===========================================================================");
436 // return;
437
438 // read INL/DNL correction files
439 for (int c = 0; c < TOF2_MAX_CRATES; c++)
440 for (int i = 0; i < TOF2_MAX_SLOTS_IN_CRATE; i++) {
441 for (int j = 0; j < 72; j++)
442 for (int k = 0; k < 1024; k++)
443 DNL_Table[c][i][j][k] = 0.;
444 }
445 DNL_read();
446
447 Wcut = 2800;
448 Wmax = 9000;
449 WT0min = 720;
450 WT0max = 820;
451
452 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
453 LeadMin[i] = -5000;
454 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
455 LeadMax[i] = +5000;
456 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
457 for (int j = 0; j < 500; j++)
458 LeadMinW[i][j] = -5000;
459 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
460 for (int j = 0; j < 500; j++)
461 LeadMaxW[i][j] = +5000;
462 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
463 Wcutc[i] = -1;
464 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
465 Wmaxc[i] = -1;
466
467 // BmnSetup setup = BmnRawDataDecoder::instance()->GetBmnSetup();
468 // if (setup == kSRCSETUP)
469 // T0shift = -15000.; // SRC
470 // else
471 // T0shift = +147000.; // BMN
472
473 // LOGF(info,"Run number is %d",RUN);
474 // getchar();
475 // int run = RUN;
476 // if (run >= 9000) run -= 4000;
477 // if (run >= 7000) run -= 5000;
478 if (fPeriod < 8) {
479 if (fSRC)
480 T0shift = -15000.; // SRC
481 else
482 T0shift = +147000.; // BMN
483 } else {
484 if (fSRC)
485 T0shift = +75000.; // SRC
486 else
487 T0shift = +20000.; // BMN
488 }
489
490 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
491 numstrip[i] = -1;
492
493 Wt0 = 0;
494 Wts = 0;
495
496 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++) {
497 TvsS[i] = 0;
498 WvsS[i] = 0;
499 TvsWall[i] = 0;
500 TvsWallmax[i] = 0;
501 for (int ir = 0; ir < 4; ir++) {
502 TvsW[i][ir] = 0;
503 TvsWt0[i][ir] = 0;
504 TvsWr[i][ir] = 0;
505 TvsWt0r[i][ir] = 0;
506 TvsWp[i][ir] = 0;
507 TvsWt0p[i][ir] = 0;
508 TvsSm[i][ir] = 0;
509 }
510 }
511 fPreparationFileName = "";
512 fSlewing = 0;
513}
514
515// BmnTof2Raw2DigitNew destructor
517{
518
519 if (Wt0)
520 delete Wt0;
521 Wt0 = 0;
522
523 if (Wts)
524 delete Wts;
525 Wts = 0;
526
527 for (int i = 0; i < MaxPlane; i++) {
528 if (TvsS[i])
529 delete TvsS[i];
530 TvsS[i] = 0;
531 if (WvsS[i])
532 delete WvsS[i];
533 WvsS[i] = 0;
534 }
535 for (int i = 0; i < MaxPlane; i++) {
536 if (TvsWall[i])
537 delete TvsWall[i];
538 TvsWall[i] = 0;
539 if (TvsWallmax[i])
540 delete TvsWallmax[i];
541 TvsWallmax[i] = 0;
542 }
543
544 if (fSlewing == 0)
545 return;
546
547 for (int i = 0; i < MaxPlane; i++) {
548 for (int ir = 0; ir < 4; ir++) {
549 if (TvsW[i][ir])
550 delete TvsW[i][ir];
551 TvsW[i][ir] = 0;
552 if (TvsWt0[i][ir])
553 delete TvsWt0[i][ir];
554 TvsWt0[i][ir] = 0;
555 if (TvsWp[i][ir])
556 delete TvsWp[i][ir];
557 TvsWp[i][ir] = 0;
558 if (TvsWt0p[i][ir])
559 delete TvsWt0p[i][ir];
560 TvsWt0p[i][ir] = 0;
561 if (TvsSm[i][ir])
562 delete TvsSm[i][ir];
563 TvsSm[i][ir] = 0;
564 }
565 }
566}
567
568void BmnTof2Raw2DigitNew::SetSlewingReference(Int_t chamber, Int_t refrun, Int_t refchamber)
569{
570 if (chamber <= 0 || chamber > TOF2_MAX_CHAMBERS) {
571 LOGF(error, "Wrong slewing chamber number %d", chamber);
572 return;
573 }
574 if (refchamber <= 0 || refchamber > TOF2_MAX_CHAMBERS) {
575 LOGF(error, "Wrong slewing reference chamber number %d", refchamber);
576 return;
577 }
578 if (refrun < 0 || refrun > 9999) {
579 LOGF(error, "Wrong slewing reference run number %d", refrun);
580 return;
581 }
582 sprintf((char*)&filname_slewing[chamber - 1][strlen((char*)&filname_slewing[chamber - 1][0]) - 8], "%04d_raw",
583 refrun);
584 chamber_slewing[chamber - 1] = refchamber;
585 type_slewing[chamber - 1] = 1;
586 LOGF(info, "Chamber %d(%.1f) - use slewing reference run number %d, reference chamber %d(%.1f)", chamber,
587 idchambers[chamber - 1], refrun, refchamber, idchambers[refchamber - 1]);
588 return;
589}
590
592{
593 char name[128], title[128];
594
595 gStyle->SetOptFit(111);
596 gStyle->SetOptStat(111111);
597
598 sprintf(name, "Nhit");
599 sprintf(title, "N hits");
600 Nhit = new TH1F(name, title, 200, 0, 200);
601
602 sprintf(name, "Time_T0");
603 sprintf(title, "Time T0");
604 Lt0 = new TH1F(name, title, 1500, 0, 300000);
605
606 sprintf(name, "Width_T0");
607 sprintf(title, "Width T0");
608 Wt0 = new TH1F(name, title, 1500, 0, 1500);
609
610 sprintf(name, "TS_difference");
611 sprintf(title, "TS difference");
612 Wts = new TH1F(name, title, 400, -200, 200);
613
614 sprintf(name, "Chamber_rate");
615 sprintf(title, "Chamber hit rate");
616 Hchambrate = new TH2F(name, title, 30, -150, +150, 20, -100, 100);
617
618 sprintf(name, "Chamber_id_rate");
619 sprintf(title, "ChamberID hit rate");
620 H1chambrate = new TH1F(name, title, 150, 0, 150);
621
622 sprintf(name, "Strip_rate");
623 sprintf(title, "Strip hit rate");
624 Hstriprate = new TH2F(name, title, 300, -150, +150, 2000, -100, 100);
625
626 for (int i = 0; i < MaxPlane; i++) {
627 sprintf(name, "Time_vs_Strip_Chamber_%.1f", idchambers[i]);
628 sprintf(title, "Time vs Strip Chamber %.1f", idchambers[i]);
629 // SRC
630 TvsS[i] = new TH2F(name, title, TOF2_MAX_STRIPS_IN_CHAMBER, 0, TOF2_MAX_STRIPS_IN_CHAMBER, 5000, 0., 10000.);
631 // BMN
632 // TvsS[i] = new TH2F(name,title,TOF2_MAX_STRIPS_IN_CHAMBER,0,TOF2_MAX_STRIPS_IN_CHAMBER,5000, 0., 10000.);
633 // TvsS[i]->SetDirectory(0);
634 sprintf(name, "Width_vs_Strip_Chamber_%.1f", idchambers[i]);
635 sprintf(title, "Width vs Strip Chamber %.1f", idchambers[i]);
636 WvsS[i] = new TH2F(name, title, TOF2_MAX_STRIPS_IN_CHAMBER, 0, TOF2_MAX_STRIPS_IN_CHAMBER, Wmax / 50, 0., Wmax);
637 // WvsS[i]->SetDirectory(0);
638 }
639 for (int i = 0; i < MaxPlane; i++) {
640 sprintf(name, "Time_vs_Width_Chamber_%.1f_all", idchambers[i]);
641 sprintf(title, "Time vs Width Chamber %.1f all", idchambers[i]);
642 // SRC
643 TvsWall[i] = new TH2F(name, title, Wmax / 50, 0, Wmax, 5000, 0., 10000.);
644 // BMN
645 // TvsWall[i] = new TH2F(name,title,Wmax/50,0,Wmax, 5000, 0., 10000.);
646 // TvsWall[i]->SetDirectory(0);
647 sprintf(name, "Time_vs_Width_Chamber_%.1f_max", idchambers[i]);
648 sprintf(title, "Time vs Width Chamber %.1f, max strip", idchambers[i]);
649 // SRC
650 TvsWallmax[i] = new TH2F(name, title, Wmax / 50, 0, Wmax, 5000, 0., 10000.);
651 // BMN
652 // TvsWallmax[i] = new TH2F(name,title,Wmax/50,0,Wmax, 5000, 0., 10000.);
653 // TvsWallmax[i]->SetDirectory(0);
654 }
655
656 sprintf(name, "Time_offsets0");
657 sprintf(title, "Time offsets0");
658 Toffsets0 = new TProfile(name, title, TOF2_MAX_CHANNEL, 0, TOF2_MAX_CHANNEL, -10000., 10000., "e");
659
660 LOGF(info, " TOF700 booking done for %d chambers!", MaxPlane);
661}
662
664{
665 char name[128], title[128];
666
667 gStyle->SetOptFit(111);
668 gStyle->SetOptStat(111111);
669
670 TString dir = getenv("VMCWORKDIR");
671 TString path = dir + "/parameters/tof2_slewing/";
672 char filnr[512];
673 sprintf(filnr, "%s%s", path.Data(), filname_base);
674 strcat(filnr, ".slewing.root");
675 fSlewing = new TFile(filnr, "RECREATE");
676
677 sprintf(name, "Time_T0");
678 sprintf(title, "Time T0");
679 Lt0 = new TH1F(name, title, 1500, 0, 300000);
680
681 sprintf(name, "Width_T0");
682 sprintf(title, "Width T0");
683 Wt0 = new TH1F(name, title, 1500, 0, 1500);
684
685 sprintf(name, "TS_difference");
686 sprintf(title, "TS difference");
687 Wts = new TH1F(name, title, 400, -200, 200);
688
689 sprintf(name, "Chamber_rate");
690 sprintf(title, "Chamber hit rate");
691 Hchambrate = new TH2F(name, title, 30, -150, +150, 20, -100, 100);
692
693 sprintf(name, "Chamber_id_rate");
694 sprintf(title, "ChamberID hit rate");
695 H1chambrate = new TH1F(name, title, 150, 0, 150);
696
697 sprintf(name, "Strip_rate");
698 sprintf(title, "Strip hit rate");
699 Hstriprate = new TH2F(name, title, 300, -150, +150, 2000, -100, 100);
700
701 for (int ir = 0; ir < 4; ir++) {
702 sprintf(name, "Time_offsets_region_%d", ir + 1);
703 sprintf(title, "Time offsets region %d", ir + 1);
704 Toffsets[ir] = new TProfile(name, title, TOF2_MAX_CHANNEL, 0, TOF2_MAX_CHANNEL, -60., +60., "e");
705 sprintf(name, "Time_fit_offsets_region_%d", ir + 1);
706 sprintf(title, "Time fit_offsets region %d", ir + 1);
707 Toffsetsf[ir] = new TProfile(name, title, TOF2_MAX_CHANNEL, 0, TOF2_MAX_CHANNEL, -60., +60., "e");
708 }
709
710 for (int i = 0; i < MaxPlane; i++) {
711 float dL = (LeadMax[i] - LeadMin[i]) / 2.;
712 for (int ir = 0; ir < 4; ir++) {
713 sprintf(name, "Time_vs_Width_Chamber_%.1f_Peak_%d", idchambers[i], ir + 1);
714 sprintf(title, "Time vs Width Chamber %.1f Peak %d", idchambers[i], ir + 1);
715 if (TvsW[i][ir])
716 delete TvsW[i][ir];
717 TvsW[i][ir] = new TProfile2D(name, title, Wmax / 50, 0, Wmax, 32, 0, 32, -(LeadMax[i] - LeadMin[i]),
718 +(LeadMax[i] - LeadMin[i]), "e");
719 TvsW[i][ir]->Sumw2(kTRUE);
720 // TvsW[i][ir]->SetDirectory(0);
721 sprintf(name, "Time_vs_T0_Width_Chamber_%.1f_Peak_%d", idchambers[i], ir + 1);
722 sprintf(title, "Time vs T0 Width Chamber %.1f Peak %d", idchambers[i], ir + 1);
723 if (TvsWt0[i][ir])
724 delete TvsWt0[i][ir];
725 TvsWt0[i][ir] = new TProfile2D(name, title, (WT0max - WT0min) / 5, WT0min, WT0max, 32, 0, 32,
726 LeadMin[i] - dL, LeadMax[i] + dL, "e");
727 TvsWt0[i][ir]->Sumw2(kTRUE);
728 // TvsWt0[i][ir]->SetDirectory(0);
729 /*
730 sprintf(name, "Time_vs_Width_Chamber_%.1f_Peak_%d_plot",idchambers[i],ir+1);
731 sprintf(title, "Time vs Width Chamber %.1f Peak %d plot",idchambers[i],ir+1);
732 if (TvsWp[i][ir]) delete TvsWp[i][ir];
733 TvsWp[i][ir] = new
734 TH2F(name,title,Wmax/20,0,Wmax,2*(LeadMax[i]-LeadMin[i]),-(LeadMax[i]-LeadMin[i]),+(LeadMax[i]-LeadMin[i]));
735 // TvsWp[i][ir]->SetDirectory(0);
736 sprintf(name, "Time_vs_T0_Width_Chamber_%.1f_Peak_%d_plot",idchambers[i],ir+1);
737 sprintf(title, "Time vs T0 Width Chamber %.1f Peak %d plot",idchambers[i],ir+1);
738 if (TvsWt0p[i][ir]) delete TvsWt0p[i][ir];
739 TvsWt0p[i][ir] = new
740 TH2F(name,title,(WT0max-WT0min),WT0min,WT0max,2*(LeadMax[i]-LeadMin[i]),LeadMin[i]-dL,LeadMax[i]+dL);
741 // TvsWt0p[i][ir]->SetDirectory(0);
742
743 */
744 sprintf(name, "Time_vs_Strip_Chamber_%.1f_Peak_%d_Maxima", idchambers[i], ir + 1);
745 sprintf(title, "Time vs Strip Chamber %.1f Peak %d Maxima", idchambers[i], ir + 1);
746 if (TvsSm[i][ir])
747 delete TvsSm[i][ir];
748 // SRC
749 TvsSm[i][ir] =
751 2 * (LeadMax[i] - LeadMin[i]), -(LeadMax[i] - LeadMin[i]), +(LeadMax[i] - LeadMin[i]));
752 // TvsSm[i][ir] = new TH2F(name,title,TOF2_MAX_STRIPS_IN_CHAMBER,0,TOF2_MAX_STRIPS_IN_CHAMBER,10000, 0.,
753 // 10000.);
754 // BMN
755 // TvsSm[i][ir] = new TH2F(name,title,TOF2_MAX_STRIPS_IN_CHAMBER,0,TOF2_MAX_STRIPS_IN_CHAMBER,10000, 0.,
756 // 10000.); TvsSm[i][ir]->SetDirectory(0);
757
758 } // regions
759 } // chambers
760
761 sprintf(name, "Time_Lead_Min");
762 sprintf(title, "Time Lead Minimal for slewing");
763 pLeadMin = new TProfile(name, title, TOF2_MAX_CHAMBERS, 0, TOF2_MAX_CHAMBERS, -10000., 10000., "e");
764 sprintf(name, "Time_Lead_Max");
765 sprintf(title, "Time Lead Maximal for slewing");
766 pLeadMax = new TProfile(name, title, TOF2_MAX_CHAMBERS, 0, TOF2_MAX_CHAMBERS, -10000., 10000., "e");
767 for (int i = 0; i < MaxPlane; i++) {
768 pLeadMin->Fill(i, LeadMin[i]);
769 pLeadMax->Fill(i, LeadMax[i]);
770 }
771 sprintf(name, "Time_offsets0");
772 sprintf(title, "Time offsets0");
773 Toffsets0 = new TProfile(name, title, TOF2_MAX_CHANNEL, 0, TOF2_MAX_CHANNEL, -10000., 10000., "e");
774 for (int i = 1; i <= Toffsets0->GetNbinsX(); i++) {
775 Toffsets0->SetBinContent(i, Toffsets00[i]);
776 Toffsets0->SetBinEntries(i, Toffsets00n[i]);
777 Toffsets0->SetBinError(i, Toffsets00e[i]);
778 }
779 pWlimits = new TProfile("Wlimits", "Width limits", 4, 0, 4, 0, 1000000);
780 pWlimits->Fill(0.f, (double)Wcut);
781 pWlimits->Fill(1.f, (double)Wmax);
782 pWlimits->Fill(2.f, (double)WT0min);
783 pWlimits->Fill(3.f, (double)WT0max);
784}
785
787{
788 if (!CHECK_SLEWING)
789 return;
790
791 char name[128], title[128];
792
793 gStyle->SetOptFit(111);
794 gStyle->SetOptStat(111111);
795
796 sprintf(name, "Time_T0");
797 sprintf(title, "Time T0");
798 Lt0 = new TH1F(name, title, 1500, 0, 300000);
799
800 sprintf(name, "Width_T0");
801 sprintf(title, "Width T0");
802 Wt0 = new TH1F(name, title, 1500, 0, 1500);
803 Wt0->SetDirectory(0);
804
805 sprintf(name, "TS_difference");
806 sprintf(title, "TS difference");
807 Wts = new TH1F(name, title, 400, -200, 200);
808 Wts->SetDirectory(0);
809
810 sprintf(name, "Chamber_rate");
811 sprintf(title, "Chamber hit rate");
812 Hchambrate = new TH2F(name, title, 30, -150, +150, 20, -100, 100);
813 Hchambrate->SetDirectory(0);
814
815 sprintf(name, "Chamber_id_rate");
816 sprintf(title, "ChamberID hit rate");
817 H1chambrate = new TH1F(name, title, 150, 0, 150);
818 H1chambrate->SetDirectory(0);
819
820 sprintf(name, "Strip_rate");
821 sprintf(title, "Strip hit rate");
822 Hstriprate = new TH2F(name, title, 300, -150, +150, 2000, -100, 100);
823 Hstriprate->SetDirectory(0);
824
825 pWlimits = new TProfile("Wlimitsr", "Width limits", 4, 0, 4, 0, 1000000);
826 pWlimits->Fill(0.f, (double)Wcut);
827 pWlimits->Fill(1.f, (double)Wmax);
828 pWlimits->Fill(2.f, (double)WT0min);
829 pWlimits->Fill(3.f, (double)WT0max);
830 pWlimits->SetDirectory(0);
831
832 for (int i = 0; i < MaxPlane; i++) {
833 for (int ir = 0; ir < 4; ir++) {
834 sprintf(name, "Time_vs_Width_Chamber_%.1f_Peak_%d_slewing", idchambers[i], ir + 1);
835 sprintf(title, "Time vs Width Chamber %.1f Peak %d after slewing", idchambers[i], ir + 1);
836 if (TvsWr[i][ir])
837 delete TvsWr[i][ir];
838 TvsWr[i][ir] = new TProfile(name, title, Wmax / 50, 0, Wmax, -2.f * (LeadMax[i] - LeadMin[i]),
839 +2.f * (LeadMax[i] - LeadMin[i]), "e");
840 TvsWr[i][ir]->Sumw2(kTRUE);
841 TvsWr[i][ir]->SetDirectory(0);
842 sprintf(name, "Time_vs_T0_Width_Chamber_%.1f_Peak_%d_slewing", idchambers[i], ir + 1);
843 sprintf(title, "Time vs T0 Width Chamber %.1f Peak %d after slewing", idchambers[i], ir + 1);
844 if (TvsWt0r[i][ir])
845 delete TvsWt0r[i][ir];
846 TvsWt0r[i][ir] = new TProfile(name, title, (WT0max - WT0min) / 5, WT0min, WT0max,
847 -2.f * (LeadMax[i] - LeadMin[i]), +2.f * (LeadMax[i] - LeadMin[i]), "e");
848 TvsWt0r[i][ir]->Sumw2(kTRUE);
849 TvsWt0r[i][ir]->SetDirectory(0);
850 }
851 }
852}
853
855{
856 char name[128], title[128];
857 int /*Wc = Wcut, */ Wm = Wmax;
858 // if (Wcutc[i] >= 0.) Wc = Wcutc[i];
859 if (Wmaxc[i] >= 0.)
860 Wm = Wmaxc[i];
861 float dL = (LeadMax[i] - LeadMin[i]) / 2.;
862 for (int ir = 0; ir < 4; ir++) {
863 if (TvsW[i][ir]) {
864 delete TvsW[i][ir];
865 sprintf(name, "Time_vs_Width_Chamber_%.1f_Peak_%d", idchambers[i], ir + 1);
866 sprintf(title, "Time vs Width Chamber %.1f Peak %d", idchambers[i], ir + 1);
867 TvsW[i][ir] = new TProfile2D(name, title, Wm / 50, 0, Wm, 32, 0, 32, -(LeadMax[i] - LeadMin[i]),
868 +(LeadMax[i] - LeadMin[i]), "e");
869 TvsW[i][ir]->Sumw2(kTRUE);
870 // TvsW[i][ir]->SetDirectory(0);
871 }
872 if (TvsWt0[i][ir]) {
873 delete TvsWt0[i][ir];
874 sprintf(name, "Time_vs_T0_Width_Chamber_%.1f_Peak_%d", idchambers[i], ir + 1);
875 sprintf(title, "Time vs T0 Width Chamber %.1f Peak %d", idchambers[i], ir + 1);
876 TvsWt0[i][ir] = new TProfile2D(name, title, (WT0max - WT0min) / 5, WT0min, WT0max, 32, 0, 32,
877 LeadMin[i] - dL, LeadMax[i] + dL, "e");
878 TvsWt0[i][ir]->Sumw2(kTRUE);
879 // TvsWt0[i][ir]->SetDirectory(0);
880 }
881 /*
882 if (TvsWp[i][ir])
883 {
884 delete TvsWp[i][ir];
885 sprintf(name, "Time_vs_Width_Chamber_%.1f_Peak_%d_plot",idchambers[i],ir+1);
886 sprintf(title, "Time vs Width Chamber %.1f Peak %d plot",idchambers[i],ir+1);
887 TvsWp[i][ir] = new
888 TH2F(name,title,Wm/50,0,Wm,2*(LeadMax[i]-LeadMin[i]),-(LeadMax[i]-LeadMin[i]),+(LeadMax[i]-LeadMin[i]));
889 }
890 if (TvsWt0p[i][ir])
891 {
892 delete TvsWt0p[i][ir];
893 sprintf(name, "Time_vs_T0_Width_Chamber_%.1f_Peak_%d",idchambers[i],ir+1);
894 sprintf(title, "Time vs T0 Width Chamber %.1f Peak %d",idchambers[i],ir+1);
895 TvsWt0p[i][ir] = new
896 TH2F(name,title,(WT0max-WT0min)/5,WT0min,WT0max,2*(LeadMax[i]-LeadMin[i]),LeadMin[i]-dL,LeadMax[i]+dL);
897 }
898 */
899 if (TvsSm[i][ir]) {
900 delete TvsSm[i][ir];
901 sprintf(name, "Time_vs_Strip_Chamber_%.1f_Peak_%d_Maxima", idchambers[i], ir + 1);
902 sprintf(title, "Time vs Strip Chamber %.1f Peak %d Maxima", idchambers[i], ir + 1);
903 // SRC
904 TvsSm[i][ir] =
906 2 * (LeadMax[i] - LeadMin[i]), -(LeadMax[i] - LeadMin[i]), +(LeadMax[i] - LeadMin[i]));
907 // TvsSm[i][ir] = new TH2F(name,title,TOF2_MAX_STRIPS_IN_CHAMBER,0,TOF2_MAX_STRIPS_IN_CHAMBER,5000, 0.,
908 //+10000.);
909 // BMN
910 // TvsSm[i][ir] = new TH2F(name,title,TOF2_MAX_STRIPS_IN_CHAMBER,0,TOF2_MAX_STRIPS_IN_CHAMBER,5000, 0.,
911 //+10000.); TvsSm[i][ir]->SetDirectory(0);
912 }
913
914 } // regions
915
916 if (TvsWall[i]) {
917 delete TvsWall[i];
918 sprintf(name, "Time_vs_Width_Chamber_%.1f_all", idchambers[i]);
919 sprintf(title, "Time vs Width Chamber %.1f all", idchambers[i]);
920 // SRC
921 TvsWall[i] = new TH2F(name, title, Wm / 50, 0, Wm, 5000, 0., 10000.);
922 // BMN
923 // TvsWall[i] = new TH2F(name,title,Wm/50,0,Wm, 5000, 0., 10000.);
924 }
925 if (TvsWallmax[i]) {
926 delete TvsWallmax[i];
927 sprintf(name, "Time_vs_Width_Chamber_%.1f_max", idchambers[i]);
928 sprintf(title, "Time vs Width Chamber %.1f, max strip", idchambers[i]);
929 // SRC
930 TvsWallmax[i] = new TH2F(name, title, Wm / 50, 0, Wm, 5000, 0., 10000.);
931 // BMN
932 // TvsWallmax[i] = new TH2F(name,title,Wm/50,0,Wm, 5000, 0., 10000.);
933 }
934 // printf("c %d wc %d wm %d wt1 %d wt2 %d lmi %d lma %d\n", i, Wcut, Wmax, WT0min, WT0max, LeadMin[i],
935 // LeadMax[i]);
936}
937
939{
940 TFile* f = NULL;
941 char filn[512];
942
943 // TH1F *hW = new TH1F("Wlimits","Width limits",4,0,4);
944 // hW->Fill(0.f,(double)Wcut);
945 // hW->Fill(1.f,(double)Wmax);
946 // hW->Fill(2.f,(double)WT0min);
947 // hW->Fill(3.f,(double)WT0max);
948
949 sprintf(filn, "%s_preparation.root", filname_base);
950 f = new TFile(filn, "RECREATE", "Preparation Results of BmnTOF700");
951 Nhit->Write();
952 Lt0->Write();
953 Wt0->Write();
954 Wts->Write();
955 Hchambrate->Write();
956 H1chambrate->Write();
957 Hstriprate->Write();
958 for (int i = 0; i < MaxPlane; i++) {
959 if (TvsS[i])
960 TvsS[i]->Write();
961 if (WvsS[i])
962 WvsS[i]->Write();
963 if (TvsWall[i])
964 TvsWall[i]->Write();
965 if (TvsWallmax[i])
966 TvsWallmax[i]->Write();
967 }
968 if (Toffsets0)
969 Toffsets0->Write();
970 // hW->Write();
971 f->Close();
972 delete f;
973}
974
976{
977 TFile* f = NULL;
978 char filn[512];
979
980 // TH1F *hW = new TH1F("Wlimits","Width limits",4,0,4);
981 // hW->Fill(0.f,(double)Wcut);
982 // hW->Fill(1.f,(double)Wmax);
983 // hW->Fill(2.f,(double)WT0min);
984 // hW->Fill(3.f,(double)WT0max);
985
986 TString dir = getenv("VMCWORKDIR");
987 TString path = dir + "/parameters/tof2_slewing/";
988 sprintf(filn, "%s%s_preparation.root", path.Data(), filname_base);
989 f = new TFile(filn, "RECREATE", "Preparation Results of BmnTOF700");
990 Nhit->Write();
991 Lt0->Write();
992 Wt0->Write();
993 Wts->Write();
994 Hchambrate->Write();
995 H1chambrate->Write();
996 Hstriprate->Write();
997 for (int i = 0; i < MaxPlane; i++) {
998 if (TvsS[i])
999 TvsS[i]->Write();
1000 if (WvsS[i])
1001 WvsS[i]->Write();
1002 if (TvsWall[i])
1003 TvsWall[i]->Write();
1004 if (TvsWallmax[i])
1005 TvsWallmax[i]->Write();
1006 }
1007 if (Toffsets0)
1008 Toffsets0->Write();
1009 // hW->Write();
1010 f->Close();
1011 delete f;
1012}
1013
1015{
1016 if (fSlewing) {
1017 fSlewing->Close();
1018 fSlewing = 0;
1019 }
1020 if (!CHECK_SLEWING)
1021 return;
1022 if (fSlewRun < 0)
1023 return;
1024 TFile* f = NULL;
1025 char filn[128];
1026 char rightname[128];
1027 strcpy(rightname, filname_base_results);
1028 // sprintf((char *)&rightname[strlen(rightname) - 8], "%04d_raw", fRUN);
1029 // if (fSlewRun)
1030 // sprintf(filn, "%s_slewing%d_results.root", rightname, fSlewRun);
1031 // else
1032 sprintf(filn, "%s_slewing_results.root", rightname);
1033 f = new TFile(filn, "RECREATE", "Slewing Results of BmnTOF700");
1034 Lt0->Write();
1035 Wt0->Write();
1036 Wts->Write();
1037 Hchambrate->Write();
1038 H1chambrate->Write();
1039 Hstriprate->Write();
1040 // pLeadMin->Write();
1041 // pLeadMax->Write();
1042 pWlimits->Write();
1043 for (int i = 0; i < MaxPlane; i++) {
1044 for (int ir = 0; ir < 4; ir++) {
1045 if (TvsWr[i][ir])
1046 TvsWr[i][ir]->Write();
1047 if (TvsWt0r[i][ir])
1048 TvsWt0r[i][ir]->Write();
1049 // if (TvsWp[i][ir]) TvsWp[i][ir]->Write();
1050 // if (TvsWt0p[i][ir]) TvsWt0p[i][ir]->Write();
1051 // if (TvsSm[i][ir]) TvsSm[i][ir]->Write();
1052 }
1053 }
1054 f->Close();
1055 delete f;
1056}
1057
1059{
1060 FILE* fout = 0;
1061 int i, im, y;
1062 float ymin, ymax; // xmin, xmax;
1063 TString dir = getenv("VMCWORKDIR");
1064 TString path = dir + "/parameters/tof2_slewing/";
1065 char filn[512];
1066 sprintf(filn, "%s%s_slewing_limits.txt", path.Data(), filname_base);
1067 fout = fopen(filn, "w");
1068
1069 // fprintf(fout,"\t\tTOF2.SetW(%d,%d);\n", Wcut, Wmax);
1070 // if (PRINT_TIME_LIMITS) printf("\t\tTOF2.SetW(%d,%d);\n", Wcut, Wmax);
1071 // fprintf(fout,"\t\tTOF2.SetWT0(%d,%d);\n", WT0min, WT0max);
1072 // if (PRINT_TIME_LIMITS) printf("\t\tTOF2.SetWT0(%d,%d);\n", WT0min, WT0max);
1073
1074 TH1D* h = 0;
1075
1076 for (i = 0; i < MaxPlane; i++) {
1077 if (MAX_STRIP) {
1078 im = (h = (TvsWallmax[i]->ProjectionY("lims")))->GetMaximumBin();
1079 y = (int)(h->GetBinCenter(im));
1080 // printf("max i %d im %d y %d e %f\n",i,im,y,TvsWallmax[i]->GetEntries());
1081 } else {
1082 im = (h = (TvsS[i]->ProjectionY("lims")))->GetMaximumBin();
1083 y = (int)(h->GetBinCenter(im));
1084 // printf("all i %d im %d y %d e %f\n",i,im,y,TvsS[i]->GetEntries());
1085 }
1086 ymin = y - 60;
1087 ymax = y + 60;
1088 // xmin = (TvsS[i]->GetXaxis())->GetXmin();
1089 // xmax = (TvsS[i]->GetXaxis())->GetXmax();
1090 fprintf(fout, "\t\tTOF2.SetLeadMinMax(%d, %d,%d);\n", i + 1, (int)ymin, (int)ymax);
1092 LOGF(debug, "\t\tTOF2.SetLeadMinMax(%d, %d,%d);", i + 1, (int)ymin, (int)ymax);
1093 if (h)
1094 delete h;
1095 }
1096 fclose(fout);
1097 if (LIMITS_ROOT_FILE) {
1099 }
1100}
1101
1103{
1104 TString dir = getenv("VMCWORKDIR");
1105 TString path = dir + "/parameters/tof2_slewing/";
1106 char filn[512], name[256], nname[256];
1107 int i, im, y;
1108 float ymin, ymax /*, xmin, xmax*/;
1109 int j, lmi, lma /*, wc, wm, wt0mi, wt0ma*/;
1110 if (LIMITS_ROOT_FILE == 0) {
1111 FILE* finl = 0;
1112 sprintf(filn, "%s%s_slewing_limits.txt", path.Data(), filname_base);
1113 finl = fopen(filn, "r");
1114 if (finl == NULL) {
1115 printf("No slewing limits file %s, use defaults\n", filn);
1116 return;
1117 };
1118 // fscanf(finl,"\t\tTOF2.SetW(%d,%d);\n", &wc, &wm);
1119 // if (PRINT_TIME_LIMITS) printf("\t\tTOF2.SetW(%d,%d);\n", wc, wm);
1120 // SetW(wc,wm);
1121 // fscanf(finl,"\t\tTOF2.SetWT0(%d,%d);\n", &wt0mi, &wt0ma);
1122 // if (PRINT_TIME_LIMITS) printf("\t\tTOF2.SetWT0(%d,%d);\n", wt0mi, wt0ma);
1123 // SetWT0(wt0mi,wt0ma);
1125 LOGF(info, "\t\tTOF2.SetW(%d,%d);", Wcut, Wmax);
1127 LOGF(info, "\t\tTOF2.SetWT0(%d,%d);", WT0min, WT0max);
1128 for (i = 0; i < MaxPlane; i++) {
1129 lmi = 0;
1130 lma = 0;
1131 fscanf(finl, "\t\tTOF2.SetLeadMinMax(%d, %d,%d);\n", &j, &lmi, &lma);
1132 if (lmi >= lma) {
1133 printf("\t\tWrong limits - TOF2.SetLeadMinMax(%d, %d,%d);\n", j, lmi, lma);
1134 continue;
1135 }
1137 LOGF(debug, "\t\tTOF2.SetLeadMinMax(%d, %d,%d);", j, lmi, lma);
1138 SetLeadMinMax(j, lmi, lma);
1139 }
1140 fclose(finl);
1141 } else {
1142 if (fPreparationFileName == "") {
1143 sprintf(filn, "%s%s", path.Data(), filname_base);
1144 strcat(filn, "_preparation.root");
1145 } else
1146 sprintf(filn, "%s%s", path.Data(), fPreparationFileName.Data());
1147 TFile* fPreparation = new TFile(filn, "READ");
1148
1149 if (fPreparation == 0) {
1150 printf("Error input file %s for limits!\n", filn);
1151 return;
1152 }
1153
1154 // sprintf(name, "Wlimits");
1155 // TH1F *hW = (TH1F *)(fPreparation->Get(name));
1156 // wc = hW->GetBinContent(1);
1157 // wm = hW->GetBinContent(2);
1158 // wt0mi = hW->GetBinContent(3);
1159 // wt0ma = hW->GetBinContent(4);
1160 // if (PRINT_TIME_LIMITS) printf("\t\tTOF2.SetW(%d,%d);\n", wc, wm);
1161 // SetW(wc,wm);
1162 // if (PRINT_TIME_LIMITS) printf("\t\tTOF2.SetWT0(%d,%d);\n", wt0mi, wt0ma);
1163 // SetWT0(wt0mi,wt0ma);
1164
1166 LOGF(debug, "\t\tTOF2.SetW(%d,%d);", Wcut, Wmax);
1168 LOGF(debug, "\t\tTOF2.SetWT0(%d,%d);", WT0min, WT0max);
1169
1170 TH2F* hs = 0;
1171 int bymin = 0;
1172 int bymax = 0;
1173 int nb = 0;
1174 double meant = 0, sigmat = 0.;
1175 TH1D* tim = 0;
1176 for (int plane = 0; plane < MaxPlane; plane++) {
1177 if (MAX_STRIP)
1178 sprintf(name, "Time_vs_Width_Chamber_%.1f_max", idchambers[plane]);
1179 else
1180 sprintf(name, "Time_vs_Width_Chamber_%.1f_all", idchambers[plane]);
1181 hs = (TH2F*)fPreparation->Get(name);
1182 if (!hs) {
1183 printf("Error input Time vs Strip hist for chamber %.1f!\n", idchambers[plane]);
1184 continue;
1185 }
1186 tim = hs->ProjectionY();
1187 im = tim->GetMaximumBin();
1188 y = (int)(tim->GetBinCenter(im));
1189 ymin = y - 60;
1190 ymax = y + 60;
1191 bymin = (int)(tim->FindBin(ymin));
1192 bymax = (int)(tim->FindBin(ymax));
1193 nb = hs->GetNbinsX();
1195 sprintf(nname, "Fit_Time_vs_Width_Chamber%.1fall", idchambers[plane]);
1196 TH2F* htvsw = new TH2F(nname, nname, nb, 0, nb * 50, 60, ymin, ymax);
1197 for (int ibx = 1; ibx <= nb; ibx++)
1198 for (int iby = bymin; iby <= bymax; iby++)
1199 htvsw->SetBinContent(ibx, iby - bymin + 1, hs->GetBinContent(ibx, iby));
1200 htvsw->FitSlicesY(0, 0, -1, 10, "QNR");
1201 sprintf(nname, "Fit_Time_vs_Width_Chamber%.1fall_0", idchambers[plane]);
1202 TH1D* htvsw_0 = (TH1D*)(gDirectory->Get(nname));
1203 sprintf(nname, "Fit_Time_vs_Width_Chamber%.1fall_1", idchambers[plane]);
1204 TH1D* htvsw_1 = (TH1D*)(gDirectory->Get(nname));
1205 sprintf(nname, "Fit_Time_vs_Width_Chamber%.1fall_2", idchambers[plane]);
1206 TH1D* htvsw_2 = (TH1D*)(gDirectory->Get(nname));
1207 sprintf(nname, "Fit_Time_vs_Width_Chamber%.1fall_chi2", idchambers[plane]);
1208 TH1D* htvsw_chi2 = (TH1D*)(gDirectory->Get(nname));
1209 // printf("***************************************\n");
1210 if (idchambers[plane] == 18.2f && false) {
1211 TCanvas* c = new TCanvas("c", "c", 800, 900);
1212 c->Divide(1, 3);
1213 c->cd(1);
1214 hs->Draw();
1215 c->cd(2);
1216 htvsw->Draw();
1217 c->cd(3);
1218 htvsw_1->Draw();
1219 gPad->WaitPrimitive();
1220 }
1221 for (int ibx = 1; ibx <= nb; ibx++) {
1222 meant = htvsw_1->GetBinContent(ibx);
1223 sigmat = htvsw_2->GetBinContent(ibx);
1224 if (sigmat == 0 || sigmat > 40) {
1225 LeadMinW[plane][ibx - 1] = (int)ymin;
1226 LeadMaxW[plane][ibx - 1] = (int)ymax;
1227 } else {
1228 LeadMinW[plane][ibx - 1] = meant - sigmat;
1229 LeadMaxW[plane][ibx - 1] = meant + sigmat;
1230 }
1231 // printf("pl %d binw %d min %d max
1232 //%d\n",plane,ibx,LeadMinW[plane][ibx-1],LeadMaxW[plane][ibx-1]);
1233 }
1234 delete htvsw_0;
1235 delete htvsw_1;
1236 delete htvsw_2;
1237 delete htvsw_chi2;
1238 delete htvsw;
1239 } // limits vs width
1241 LOGF(debug, "\t\tTOF2.SetLeadMinMax(%d, %d,%d);", plane + 1, (int)ymin, (int)ymax);
1242 if (ymin >= ymax) {
1243 LOGF(error, "\t\tWrong limits - TOF2.SetLeadMinMax(%d, %d,%d);", plane + 1, (int)ymin, (int)ymax);
1244 } else
1245 SetLeadMinMax(plane + 1, (int)ymin, (int)ymax);
1246 // delete hs;
1247 }
1248
1249 TProfile* prof = 0;
1250 sprintf(name, "Time_offsets0");
1251 prof = (TProfile*)(fPreparation->Get(name));
1252 if (!prof) {
1253 LOGF(error, "Error input TOffsets0 slewing profile!");
1254 } else {
1255 for (i = 1; i <= prof->GetNbinsX(); i++) {
1256 Toffsets00[i] = prof->GetBinContent(i);
1257 Toffsets00n[i] = prof->GetBinEntries(i);
1258 Toffsets00e[i] = prof->GetBinError(i);
1259 }
1260 }
1261
1262 // prof->Draw();
1263 // gPad->WaitPrimitive();
1264 fPreparation->Close();
1265 }
1266
1267 return;
1268}
1269
1271{
1272 TProfile *prof1 = 0, *prof2 = 0;
1273 TProfile2D* prof = 0;
1274 TH2F* plot = 0;
1275 TString dir = getenv("VMCWORKDIR");
1276 TString path = dir + "/parameters/tof2_slewing/";
1277
1278 char filnr[512], name[256];
1279 sprintf(filnr, "%s%s", path.Data(), filname_base);
1280 strcat(filnr, ".slewing.root");
1281 if (update)
1282 fSlewing = new TFile(filnr, "UPDATE");
1283 else
1284 fSlewing = new TFile(filnr, "READ");
1285
1286 if (fSlewing->IsZombie()) {
1287 fSlewing = 0;
1288 if (fSlewRun < 0) {
1289 if (fRUN > 0)
1290 LOGF(error, "Error open slewing file %s, work without slewing corrections!", filnr);
1291 return;
1292 } else if (fSlewRun > 0) {
1293 LOGF(error, "Error open slewing file %s, work without slewing corrections!", filnr);
1294 // LOG(error)<<"Error open slewing file " << filnr << " - exit!";
1295 return;
1296 } else {
1297 return;
1298 }
1299 }
1300
1301 int planer = 0;
1302 for (int plane = 0; plane < MaxPlane; plane++) {
1303 for (int region = 0; region < 4; region++) {
1304 planer = plane;
1305 if (fSlewCham > 0)
1306 planer = fSlewCham - 1;
1307 if (chamber_slewing[plane] > 0)
1308 planer = chamber_slewing[plane] - 1;
1309 // printf("\nread for chamber %d region %d\n", plane+1, region+1);
1310 sprintf(name, "Time_vs_T0_Width_Chamber_%.1f_Peak_%d", idchambers[planer], region + 1);
1311 prof = (TvsWt0[planer][region] = (TProfile2D*)fSlewing->Get(name));
1312 if (!prof) {
1313 LOGF(error, "Error input T0 slewing profile for chamber %.1f region %d!", idchambers[planer],
1314 region + 1);
1315 // continue;
1316 }
1317 // printf(" C0 %d S %d R %d D %f\n",planer+1, 20, region+1,
1318 // TvsWt0[planer][region]->GetBinContent(TvsWt0[planer][region]->FindBin(900,20))); prof->Smooth();
1319 sprintf(name, "Time_vs_Width_Chamber_%.1f_Peak_%d", idchambers[planer], region + 1);
1320 prof = (TvsW[planer][region] = (TProfile2D*)fSlewing->Get(name));
1321 if (!prof) {
1322 LOGF(error, "Error input RPC slewing profile for chamber %.1f region %d!", idchambers[planer],
1323 region + 1);
1324 // continue;
1325 }
1326 // printf(" C %d S %d R %d D %f\n",planer+1, 20, region+1,
1327 // TvsW[planer][region]->GetBinContent(TvsW[planer][region]->FindBin(3000,20))); prof->Smooth();
1328 sprintf(name, "Time_vs_Strip_Chamber_%.1f_Peak_%d_Maxima", idchambers[planer], region + 1);
1329 plot = (TvsSm[planer][region] = (TH2F*)fSlewing->Get(name));
1330 if (!plot) {
1331 LOGF(error, "Error input RPC time distribution for chamber %.1f region %d!", idchambers[planer],
1332 region + 1);
1333 // continue;
1334 }
1335 }
1336 } // loop on chambers
1337
1338 for (int region = 0; region < 4; region++) {
1339 sprintf(name, "Time_offsets_region_%d", region + 1);
1340 prof1 = (Toffsets[region] = (TProfile*)fSlewing->Get(name));
1341 if (!prof1) {
1342 LOGF(error, "Error input TOffsets slewing profile for region %d!", region + 1);
1343 // continue;
1344 }
1345 sprintf(name, "Time_fit_offsets_region_%d", region + 1);
1346 prof1 = (Toffsetsf[region] = (TProfile*)fSlewing->Get(name));
1347 if (!prof1) {
1348 LOGF(error, "Error input TOffsets fit slewing profile for region %d!", region + 1);
1349 // continue;
1350 }
1351 }
1352
1353 sprintf(name, "Time_offsets0");
1354 prof1 = (Toffsets0 = (TProfile*)(fSlewing->Get(name)));
1355 if (!prof1) {
1356 LOGF(error, "Error input TOffsets0 slewing profile!");
1357 }
1358
1359 sprintf(name, "Time_Lead_Min");
1360 prof1 = (pLeadMin = (TProfile*)(fSlewing->Get(name)));
1361 if (!prof1) {
1362 LOGF(error, "Error input Time_Lead_Min hist!");
1363 }
1364
1365 sprintf(name, "Time_Lead_Max");
1366 prof2 = (pLeadMax = (TProfile*)(fSlewing->Get(name)));
1367 if (!prof2) {
1368 LOGF(error, "Error input Time_Lead_Max hist!");
1369 }
1370
1371 for (int plane = 0; plane < MaxPlane && prof1 && prof2; plane++) {
1372 LeadMin[plane] = prof1->GetBinContent(plane + 1);
1373 LeadMax[plane] = prof2->GetBinContent(plane + 1);
1375 LOGF(debug, "\t\tTOF2.SetLeadMinMax(%d, %d,%d);", plane + 1, (int)prof1->GetBinContent(plane + 1),
1376 (int)prof2->GetBinContent(plane + 1));
1377 }
1378
1379 sprintf(name, "Wlimits");
1380 // ToDo (to TProfile);
1381 TH1F* hW = (TH1F*)(fSlewing->Get(name));
1382 if (!hW) {
1383 printf("Error input Wlimits hist!\n");
1384 return;
1385 }
1386 int wc = hW->GetBinContent(1);
1387 int wm = hW->GetBinContent(2);
1388 int wt0mi = hW->GetBinContent(3);
1389 int wt0ma = hW->GetBinContent(4);
1391 LOGF(info, "\t\tTOF2.SetW(%d,%d);", wc, wm);
1392 Wcut = wc;
1393 Wmax = wm;
1395 LOGF(info, "\t\tTOF2.SetWT0(%d,%d);", wt0mi, wt0ma);
1396 WT0min = wt0mi;
1397 WT0max = wt0ma;
1398 // fSlewing->Close();
1399
1400 return;
1401}
1402
1403void BmnTof2Raw2DigitNew::getEventInfo(long long* ev, long long* t1, long long* t2)
1404{
1405 *ev = EVENT;
1406 *t1 = TIME_SEC;
1407 *t2 = TIME_NS;
1408}
1409
1411{
1412 LOGF(info, "\n===========================================================================");
1413 LOGF(info, "Number of chambers %d, crates %d, slots %d, TDC channels %d\n", MaxPlane, ncrates, nslots, n_rec);
1414 LOGF(info, " #\tcrate\tcrateID\n===========================================================================");
1415 for (int i = 0; i < ncrates; i++) {
1416 LOGF(info, "%3d\t%d\t0x%0x", i, numcrates[i], idcrates[numcrates[i]]);
1417 }
1418 LOGF(info, "===========================================================================");
1419 LOGF(info, " #\tchamber\tchamberID\n===========================================================================");
1420 for (int i = 0; i < nchambers; i++) {
1421 LOGF(info, "%3d\t%d\t%.1f", i, numcha[i], idchambers[numcha[i]]);
1422 }
1423 LOGF(info, "===========================================================================");
1424 LOGF(info, " "
1425 "#\tcrate\tslot\tdevsernum\tfiletype\tfile\n============================================================"
1426 "===============");
1427 for (int i = 0; i < nslots + 1; i++) {
1428 LOGF(info, "%3d\t%d\t%d\t%0x\t%d\t%s", i, numcr[i], numslots[i], devser[numcr[i]][numslots[i]],
1429 dnltype[numcr[i]][numslots[i]], dnlname[numcr[i]][numslots[i]]);
1430 }
1431 LOGF(info, "===========================================================================");
1432 LOGF(info, " "
1433 "#\tcrate\tslot\tchannel\tplane\tstrip\tside\n=========================================================="
1434 "=================");
1435 for (int i = 0; i < n_rec; i++) {
1436 LOGF(info, "%4d\t%d\t%d\t%d\t%d\t%d\t%d", i, mapa[i].crate, mapa[i].slot, mapa[i].chan, mapa[i].plane,
1437 mapa[i].strip, mapa[i].side);
1438 }
1439 LOGF(info, "===========================================================================");
1440}
1441
1442int BmnTof2Raw2DigitNew::numcrate(int id)
1443{
1444 for (int ic = 0; ic < ncrates; ic++) {
1445 if (id == idcrates[ic])
1446 return ic;
1447 }
1448 return -1;
1449}
1450
1452 unordered_map<UInt_t, Long64_t>* ts,
1453 Double_t t0,
1454 Double_t t0width)
1455{
1456 Long64_t ts_diff = 0L;
1457 Bool_t islead = false;
1458 unsigned rawtime = 0;
1459 Lt0->Fill(t0 * INVHPTIMEBIN);
1460 Wt0->Fill(t0width * INVHPTIMEBIN);
1461 float lead[TOF2_MAX_CHANNEL];
1462 float trail[TOF2_MAX_CHANNEL];
1463 memset(lead, 0, TOF2_MAX_CHANNEL * sizeof(float));
1464 memset(trail, 0, TOF2_MAX_CHANNEL * sizeof(float));
1465 for (int i = 0; i < data->GetEntriesFast(); i++) {
1466 BmnTDCDigit* digit = (BmnTDCDigit*)data->At(i);
1467 islead = digit->GetLeading();
1468 rawtime = digit->GetValue();
1469 // LOGF(info," Lead %d rawtime %u",islead,rawtime);
1470 if (fPeriod == 8 && fSRC == 0) {
1471 if (islead) {
1472 if (rawtime < MIN_RAW_LEADING_TIME)
1473 continue;
1474 if (rawtime > MAX_RAW_LEADING_TIME)
1475 continue;
1476 } else {
1477 if (rawtime < MIN_RAW_TRAILING_TIME)
1478 continue;
1479 if (rawtime > MAX_RAW_TRAILING_TIME)
1480 continue;
1481 }
1482 }
1483 int type = digit->GetType();
1484 int tdcnum = digit->GetHptdcId();
1485 int chanin = digit->GetChannel();
1486 int chan = -1;
1487 if ((fPeriod == 8 && fSRC == 0) || type == 0)
1488 type = kTDC64VHLE_E;
1489 if (type == kTDC32VL)
1490 chan = get_ch_tdc32vl(tdcnum, chanin * 4);
1491 else if (type == kTDC64VHLE)
1492 chan = get_ch_tdc64vhle(tdcnum, chanin * 4);
1493 else if (type == kTDC64VHLE_E)
1494 chan = chanin;
1495 else
1496 continue;
1497 if (chan < 0)
1498 continue;
1499 int nc = -1, ind = 0, crate = -1, slot = 0;
1500 if (fPeriod < 8 || fSRC != 0) {
1501 nc = numcrate((digit->GetSerial()) & 0xFFFFFF);
1502 if (nc < 0)
1503 continue;
1504 ind = nrec[nc][digit->GetSlot()][chan];
1505 if (ind == -1)
1506 continue;
1507 Wts->Fill(ts_diff);
1508 crate = mapa[ind].crate;
1509 slot = mapa[ind].slot;
1510 if (t0 != 0.) {
1511 auto it = ts->find(digit->GetSerial());
1512 if (it == ts->end())
1513 continue;
1514 ts_diff = it->second;
1515 }
1516 } else {
1517 unsigned devsernum = digit->GetSerial();
1518 for (int idev = 0; idev < nslots + 1; idev++) {
1519 // if (Debug) LOGF(info," %d %x %x", idev,devnum[idev], devsernum);
1520 if ((unsigned)devnum[idev] == devsernum) {
1521 crate = devcrate[idev];
1522 slot = devslot[idev];
1523 // LOGF(info,"devsernum 0x%0x crate %d slot %d chan %d", devsernum, crate, slot, chan);
1524 break;
1525 }
1526 }
1527 if (crate == -1 || slot == 0)
1528 continue;
1529 if (t0 != 0.) {
1530 auto it = ts->find(idcrates[crate]);
1531 if (it == ts->end())
1532 continue;
1533 ts_diff = it->second;
1534 }
1535 nc = crate;
1536 if (nc < 0)
1537 continue;
1538 ind = nrec[nc][slot][chan];
1539 if (ind == -1)
1540 continue;
1541 if (crate != mapa[ind].crate)
1542 continue;
1543 if (slot != mapa[ind].slot)
1544 continue;
1545 }
1546 Wts->Fill(ts_diff);
1547 int dnl = rawtime & 0x3FF;
1548 float tm = (rawtime + DNL_Table[crate][slot][chan][dnl]) - chtima[crate][slot][chan]
1549 - (t0 - ts_diff) * INVHPTIMEBIN + T0shift;
1550 // if(digit->GetLeading()) lead[ind]=tm; else trail[ind]=tm;
1551 if (islead) {
1552 if (lead[ind] == 0)
1553 lead[ind] = tm;
1554 } else {
1555 if (trail[ind] == 0)
1556 trail[ind] = tm;
1557 }
1558 // LOGF(info,"#%d slot %d chan %d td %d inl %f chtima %f t0 %f ts %ld t %f", i, mapa[ind].slot,
1559 // mapa[ind].chan, digit->GetValue(), DNL_Table[crate][slot][chan][dnl], chtima[crate][slot][chan], t0,
1560 // ts_diff, tm);
1561 }
1562
1563 // int Wc = Wcut;
1564
1565 int ngoodhits = 0;
1566
1567 float wmaxs[TOF2_MAX_CHAMBERS] = {0.}, tmaxs[TOF2_MAX_CHAMBERS] = {-1000.};
1568 int smax[TOF2_MAX_CHAMBERS] = {-1};
1569 for (int i = 0; i < MaxPlane; i++)
1570 wmaxs[i] = 0.;
1571 for (int i = 0; i < MaxPlane; i++)
1572 tmaxs[i] = -1000.;
1573 for (int i = 0; i < MaxPlane; i++)
1574 smax[i] = -1;
1575 for (int ind = 0; ind < n_rec; ind++) {
1576 int ind1 = mapa[ind].pair;
1577 if (ind1 < 0)
1578 continue;
1579 if (lead[ind1] == 0 || trail[ind1] == 0)
1580 continue;
1581 if (lead[ind] != 0 && trail[ind] != 0) {
1582 if (idchambers[mapa[ind].plane] < 100.f)
1583 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 1.5f)
1584 continue;
1585 if (idchambers[mapa[ind].plane] > 100.f)
1586 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 3.5f)
1587 continue;
1588 ngoodhits++;
1589 // LOGF(info," L1 %u T1 %u", lead[ind1], trail[ind1]);
1590 // LOGF(info," L %u T %u", lead[ind], trail[ind]);
1591 // Wc = Wcut;
1592 // if (Wcutc[mapa[ind].plane] >= 0.) Wc = Wcutc[mapa[ind].plane];
1593 float L = (lead[ind] + lead[ind1]) / 2.;
1594 float W1 = trail[ind] - lead[ind];
1595 float W2 = trail[ind1] - lead[ind1];
1596 float W = (W1 + W2) / 2.;
1597 if (idchambers[mapa[ind].plane] != 19.3f)
1598 H1chambrate->Fill(idchambers[mapa[ind].plane]);
1599 else
1600 H1chambrate->Fill(70.f);
1601 if (idchambers[mapa[ind].plane] < 100.f && idchambers[mapa[ind].plane] != 19.3f) {
1602 float x, y, z;
1603 get_hit_xyz0(mapa[ind].plane, mapa[ind].strip, (lead[ind] - lead[ind1]) * HPTIMEBIN, &x, &y, &z);
1604 Hchambrate->Fill(x, y);
1605 Hstriprate->Fill(x, y);
1606 }
1607 // if (((W1 < Wc && W2 < Wc)||(W1 >= Wc && W2 >= Wc)))
1608 // {
1609 TvsS[mapa[ind].plane]->Fill(mapa[ind].strip, L);
1610 WvsS[mapa[ind].plane]->Fill(mapa[ind].strip, W);
1611 TvsWall[mapa[ind].plane]->Fill(W, L);
1612 // LOGF(info,"%d %d %d %f %f %f", ind, mapa[ind].slot, mapa[ind].chan, L, W, t0);
1613 // }
1614 // if (W > wmaxs[mapa[ind].plane] && ((W1 < Wc && W2 < Wc)||(W1 >= Wc && W2 >= Wc)))
1615 if (W > wmaxs[mapa[ind].plane]) {
1616 wmaxs[mapa[ind].plane] = W;
1617 tmaxs[mapa[ind].plane] = L;
1618 smax[mapa[ind].plane] = mapa[ind].strip;
1619 }
1620 } // leading and trailing exists
1621 } // loop on strips
1622 Nhit->Fill(ngoodhits);
1623 for (int i = 0; i < MaxPlane; i++) {
1624 if (smax[i] > -1) {
1625 TvsWallmax[i]->Fill(wmaxs[i], tmaxs[i]);
1626 }
1627 }
1628}
1629
1631 unordered_map<UInt_t, Long64_t>* ts,
1632 Double_t t0,
1633 Double_t t0width)
1634{
1635 if (fPeriod == 8 && fSRC == 0)
1636 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN > MAX_RAW_T0_TIME)
1637 return;
1638 Long64_t ts_diff = 0L;
1639 Bool_t islead = false;
1640 unsigned rawtime = 0;
1641 float lead[TOF2_MAX_CHANNEL];
1642 float trail[TOF2_MAX_CHANNEL];
1643 memset(lead, 0, TOF2_MAX_CHANNEL * sizeof(float));
1644 memset(trail, 0, TOF2_MAX_CHANNEL * sizeof(float));
1645 for (int i = 0; i < data->GetEntriesFast(); i++) {
1646 BmnTDCDigit* digit = (BmnTDCDigit*)data->At(i);
1647 islead = digit->GetLeading();
1648 rawtime = digit->GetValue();
1649 if (fPeriod == 8 && fSRC == 0) {
1650 if (islead) {
1651 if (rawtime < MIN_RAW_LEADING_TIME)
1652 continue;
1653 if (rawtime > MAX_RAW_LEADING_TIME)
1654 continue;
1655 } else {
1656 if (rawtime < MIN_RAW_TRAILING_TIME)
1657 continue;
1658 if (rawtime > MAX_RAW_TRAILING_TIME)
1659 continue;
1660 }
1661 }
1662 int type = digit->GetType();
1663 int tdcnum = digit->GetHptdcId();
1664 int chanin = digit->GetChannel();
1665
1666 int chan = -1;
1667 if ((fPeriod == 8 && fSRC == 0) || type == 0)
1668 type = kTDC64VHLE_E;
1669 if (type == kTDC32VL)
1670 chan = get_ch_tdc32vl(tdcnum, chanin * 4);
1671 else if (type == kTDC64VHLE)
1672 chan = get_ch_tdc64vhle(tdcnum, chanin * 4);
1673 else if (type == kTDC64VHLE_E)
1674 chan = chanin;
1675 else
1676 continue;
1677 // LOGF(info," Type OK!");
1678 if (chan < 0)
1679 continue;
1680 // LOGF(info," Channel OK = %d!", chan);
1681 int nc = -1, ind = 0, crate = -1, slot = 0;
1682 if (fPeriod < 8 || fSRC != 0) {
1683 nc = numcrate((digit->GetSerial()) & 0xFFFFFF);
1684 if (nc < 0)
1685 continue;
1686 ind = nrec[nc][digit->GetSlot()][chan];
1687 if (ind == -1)
1688 continue;
1689 Wts->Fill(ts_diff);
1690 crate = mapa[ind].crate;
1691 slot = mapa[ind].slot;
1692 if (t0 != 0.) {
1693 auto it = ts->find(digit->GetSerial());
1694 if (it == ts->end())
1695 continue;
1696 ts_diff = it->second;
1697 }
1698 } else {
1699 unsigned devsernum = digit->GetSerial();
1700 for (int idev = 0; idev < nslots + 1; idev++) {
1701 // if (Debug) LOGF(info," %d %x %x", idev,devnum[idev], devsernum);
1702 if ((unsigned)devnum[idev] == devsernum) {
1703 crate = devcrate[idev];
1704 slot = devslot[idev];
1705 break;
1706 }
1707 }
1708 if (crate == -1 || slot == 0)
1709 continue;
1710 if (t0 != 0.) {
1711 auto it = ts->find(idcrates[crate]);
1712 if (it == ts->end())
1713 continue;
1714 ts_diff = it->second;
1715 }
1716 nc = crate;
1717 if (nc < 0)
1718 continue;
1719 ind = nrec[nc][slot][chan];
1720 if (ind == -1)
1721 continue;
1722 if (crate != mapa[ind].crate)
1723 continue;
1724 if (slot != mapa[ind].slot)
1725 continue;
1726 }
1727 int dnl = rawtime & 0x3FF;
1728 float tm = (rawtime + DNL_Table[crate][slot][chan][dnl]) - chtima[crate][slot][chan]
1729 - (t0 - ts_diff) * INVHPTIMEBIN + T0shift;
1730 // if(digit->GetLeading()) lead[ind]=tm; else trail[ind]=tm;
1731 if (islead) {
1732 if (lead[ind] == 0)
1733 lead[ind] = tm;
1734 } else {
1735 if (trail[ind] == 0)
1736 trail[ind] = tm;
1737 }
1738 // if(digit->GetLeading()) LOGF(info," t0 %f", t0*1024./25.);
1739 // if (tm > 100000.) LOGF(info,"%d %d %d %d %f %d %d %f", i, mapa[ind].slot, mapa[ind].chan,
1740 // digit->GetValue(),DNL_Table[crate][slot][chan][dnl], t0, ts_diff, tm); LOGF(info,"%d %d %d %d %f %f
1741 // %lld %f", i, mapa[ind].slot, mapa[ind].chan, digit->GetValue(),DNL_Table[crate][slot][chan][dnl], t0,
1742 // ts_diff, tm);
1743 }
1744 int Wc = Wcut;
1745 int Wm = Wmax;
1746 float wmaxs[TOF2_MAX_CHAMBERS] = {0.}, tmaxs[TOF2_MAX_CHAMBERS] = {-1000.};
1747 int smax[TOF2_MAX_CHAMBERS] = {-1};
1748 int rmax[TOF2_MAX_CHAMBERS] = {-1}, ira = -1;
1749 for (int i = 0; i < MaxPlane; i++)
1750 wmaxs[i] = 0.;
1751 for (int i = 0; i < MaxPlane; i++)
1752 tmaxs[i] = -1000.;
1753 for (int i = 0; i < MaxPlane; i++)
1754 smax[i] = -1;
1755 for (int i = 0; i < MaxPlane; i++)
1756 rmax[i] = -1;
1757 for (int ind = 0; ind < n_rec; ind++) {
1758 int ind1 = mapa[ind].pair;
1759 if (ind1 < 0)
1760 continue;
1761 if (lead[ind1] == 0 || trail[ind1] == 0)
1762 continue;
1763 if (numstrip[mapa[ind].plane] >= 0 && numstrip[mapa[ind].plane] != mapa[ind].strip)
1764 continue;
1765 if (lead[ind] != 0 && trail[ind] != 0) {
1766 if (idchambers[mapa[ind].plane] < 100.f)
1767 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 1.5f)
1768 continue;
1769 if (idchambers[mapa[ind].plane] > 100.f)
1770 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 3.5f)
1771 continue;
1772 Wc = Wcut;
1773 if (Wcutc[mapa[ind].plane] >= 0.)
1774 Wc = Wcutc[mapa[ind].plane];
1775 Wm = Wmax;
1776 if (Wmaxc[mapa[ind].plane] >= 0.)
1777 Wm = Wmaxc[mapa[ind].plane];
1778 float L = (lead[ind] + lead[ind1]) / 2.;
1779 float W1 = trail[ind] - lead[ind];
1780 float W2 = trail[ind1] - lead[ind1];
1781 float W = (W1 + W2) / 2.;
1783 int binw = (int)(W / 50.f);
1784 if (binw < 0 || binw >= 500)
1785 continue;
1786 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
1787 continue;
1788 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
1789 continue;
1790 } else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
1791 continue;
1792 // if (L >= LeadMin[mapa[ind].plane] && L < LeadMax[mapa[ind].plane])
1793 // {
1794 // inside time limits
1795 ira = -1;
1796 // inside time limits
1798 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
1799 if ((int)W1 < Wc && (int)W2 < Wc) {
1800 ira = 0;
1801 } else if ((int)W1 >= Wc && (int)W2 >= Wc && (int)W1 < Wm && (int)W2 < Wm) {
1802 ira = 1;
1803 } else if ((int)W1 >= Wc && (int)W2 < Wc && (int)W1 < Wm) {
1804 ira = 2;
1805 } else if ((int)W2 >= Wc && (int)W1 < Wc && (int)W2 < Wm) {
1806 ira = 3;
1807 }
1808 if (ira >= 0) // inside width regions
1809 {
1810 if (MAX_STRIP) {
1811 if (W > wmaxs[mapa[ind].plane]) {
1812 wmaxs[mapa[ind].plane] = W;
1813 tmaxs[mapa[ind].plane] = L;
1814 smax[mapa[ind].plane] = mapa[ind].strip;
1815 rmax[mapa[ind].plane] = ira;
1816 }
1817 } else {
1818 TvsWt0[mapa[ind].plane][ira]->Fill(t0width * INVHPTIMEBIN, mapa[ind].strip, L);
1819 // TvsWt0p[mapa[ind].plane][ira]->Fill(t0width*INVHPTIMEBIN, L);
1820 } // MAX_STRIP
1821 } // inside width regions ira
1822 // } // inside time limits
1823 } // lead and trail exists
1824 } // hits
1825 for (int i = 0; i < MaxPlane && MAX_STRIP; i++) {
1826 if (smax[i] > -1) {
1827 TvsWt0[i][rmax[i]]->Fill(t0width * INVHPTIMEBIN, smax[i], tmaxs[i]);
1828 // TvsWt0p[i][rmax[i]]->Fill(t0width*INVHPTIMEBIN, tmaxs[i]);
1829 }
1830 }
1831}
1832
1833void BmnTof2Raw2DigitNew::fillSlewing(TClonesArray* data,
1834 unordered_map<UInt_t, Long64_t>* ts,
1835 Double_t t0,
1836 Double_t t0width)
1837{
1838 if (fPeriod == 8 && fSRC == 0)
1839 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN > MAX_RAW_T0_TIME)
1840 return;
1841 Long64_t ts_diff = 0L;
1842 Bool_t islead = false;
1843 unsigned rawtime = 0;
1844 float lead[TOF2_MAX_CHANNEL];
1845 float trail[TOF2_MAX_CHANNEL];
1846 memset(lead, 0, TOF2_MAX_CHANNEL * sizeof(float));
1847 memset(trail, 0, TOF2_MAX_CHANNEL * sizeof(int));
1848 for (int i = 0; i < data->GetEntriesFast(); i++) {
1849 BmnTDCDigit* digit = (BmnTDCDigit*)data->At(i);
1850 int type = digit->GetType();
1851 islead = digit->GetLeading();
1852 rawtime = digit->GetValue();
1853 if (fPeriod == 8 && fSRC == 0) {
1854 if (islead) {
1855 if (rawtime < MIN_RAW_LEADING_TIME)
1856 continue;
1857 if (rawtime > MAX_RAW_LEADING_TIME)
1858 continue;
1859 } else {
1860 if (rawtime < MIN_RAW_TRAILING_TIME)
1861 continue;
1862 if (rawtime > MAX_RAW_TRAILING_TIME)
1863 continue;
1864 }
1865 }
1866 int tdcnum = digit->GetHptdcId();
1867 int chanin = digit->GetChannel();
1868 int chan = -1;
1869 if ((fPeriod == 8 && fSRC == 0) || type == 0)
1870 type = kTDC64VHLE_E;
1871 if (type == kTDC32VL)
1872 chan = get_ch_tdc32vl(tdcnum, chanin * 4);
1873 else if (type == kTDC64VHLE)
1874 chan = get_ch_tdc64vhle(tdcnum, chanin * 4);
1875 else if (type == kTDC64VHLE_E)
1876 chan = chanin;
1877 else
1878 continue;
1879 if (chan < 0)
1880 continue;
1881 int nc = -1, ind = 0, crate = -1, slot = 0;
1882 if (fPeriod < 8 || fSRC != 0) {
1883 nc = numcrate((digit->GetSerial()) & 0xFFFFFF);
1884 if (nc < 0)
1885 continue;
1886 ind = nrec[nc][digit->GetSlot()][chan];
1887 if (ind == -1)
1888 continue;
1889 Wts->Fill(ts_diff);
1890 crate = mapa[ind].crate;
1891 slot = mapa[ind].slot;
1892 if (t0 != 0.) {
1893 auto it = ts->find(digit->GetSerial());
1894 if (it == ts->end())
1895 continue;
1896 ts_diff = it->second;
1897 }
1898 } else {
1899 unsigned devsernum = digit->GetSerial();
1900 for (int idev = 0; idev < nslots + 1; idev++) {
1901 // if (Debug) LOGF(info," %d %x %x", idev,devnum[idev], devsernum);
1902 if ((unsigned)devnum[idev] == devsernum) {
1903 crate = devcrate[idev];
1904 slot = devslot[idev];
1905 break;
1906 }
1907 }
1908 if (crate == -1 || slot == 0)
1909 continue;
1910 if (t0 != 0.) {
1911 auto it = ts->find(idcrates[crate]);
1912 if (it == ts->end())
1913 continue;
1914 ts_diff = it->second;
1915 }
1916 nc = crate;
1917 if (nc < 0)
1918 continue;
1919 ind = nrec[nc][slot][chan];
1920 if (ind == -1)
1921 continue;
1922 if (crate != mapa[ind].crate)
1923 continue;
1924 if (slot != mapa[ind].slot)
1925 continue;
1926 }
1927 int dnl = rawtime & 0x3FF;
1928 float tm = (rawtime + DNL_Table[crate][slot][chan][dnl]) - chtima[crate][slot][chan]
1929 - (t0 - ts_diff) * INVHPTIMEBIN + T0shift;
1930 // if(digit->GetLeading()) lead[ind]=tm; else trail[ind]=tm;
1931 if (islead) {
1932 if (lead[ind] == 0)
1933 lead[ind] = tm;
1934 } else {
1935 if (trail[ind] == 0)
1936 trail[ind] = tm;
1937 }
1938 }
1939 int Wc = Wcut;
1940 // int Wm = Wmax;
1941 float wmaxs[TOF2_MAX_CHAMBERS] = {0.}, tmaxs[TOF2_MAX_CHAMBERS] = {-1000.};
1942 int smax[TOF2_MAX_CHAMBERS] = {-1};
1943 int rmax[TOF2_MAX_CHAMBERS] = {-1};
1944 for (int i = 0; i < MaxPlane; i++)
1945 wmaxs[i] = 0.;
1946 for (int i = 0; i < MaxPlane; i++)
1947 tmaxs[i] = -1000.;
1948 for (int i = 0; i < MaxPlane; i++)
1949 smax[i] = -1;
1950 for (int i = 0; i < MaxPlane; i++)
1951 rmax[i] = -1;
1952 char nfun0[12] = {""};
1953 int ifit0 = 0;
1954 TF1* fun0 = 0;
1955 for (int ind = 0; ind < n_rec; ind++) {
1956 int ind1 = mapa[ind].pair;
1957 if (ind1 < 0)
1958 continue;
1959 if (lead[ind1] == 0 || trail[ind1] == 0)
1960 continue;
1961 if (numstrip[mapa[ind].plane] >= 0 && numstrip[mapa[ind].plane] != mapa[ind].strip)
1962 continue;
1963 if (lead[ind] != 0 && trail[ind] != 0) {
1964 if (idchambers[mapa[ind].plane] < 100.f)
1965 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 1.5f)
1966 continue;
1967 if (idchambers[mapa[ind].plane] > 100.f)
1968 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 3.5f)
1969 continue;
1970 // if (mapa[ind].plane == 0) LOGF(info,"%f %f %f %f",lead[ind1],lead[ind],trail[ind1],trail[ind]);
1971 Wc = Wcut;
1972 if (Wcutc[mapa[ind].plane] >= 0.)
1973 Wc = Wcutc[mapa[ind].plane];
1974 // Wm = Wmax;
1975 // if (Wmaxc[mapa[ind].plane] >= 0.) Wm = Wmaxc[mapa[ind].plane];
1976 float L = (lead[ind1] + lead[ind]) / 2.;
1977 float W1 = trail[ind] - lead[ind];
1978 float W2 = trail[ind1] - lead[ind1];
1979 float W = (W1 + W2) / 2.;
1980
1981 int ira = -1;
1982
1983 if ((int)W1 < Wc && (int)W2 < Wc) {
1984 ira = 0;
1985 } else if (W1 >= Wc && W2 >= Wc) {
1986 ira = 1;
1987 } else if (W1 >= Wc && W2 < Wc) {
1988 ira = 2;
1989 } else if (W1 < Wc && W2 >= Wc) {
1990 ira = 3;
1991 }
1992 // LOGF(info,"Plane %d Strip %d Lead %f Width %f LeadMin %d LeadMax %d", mapa[ind].plane, mapa[ind].strip,
1993 // L, W, LeadMin[mapa[ind].plane], LeadMax[mapa[ind].plane]);
1995 int binw = (int)(W / 50.f);
1996 if (binw < 0 || binw >= 500)
1997 continue;
1998 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
1999 continue;
2000 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
2001 continue;
2002 } else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
2003 continue;
2004 // if (L >= LeadMin[mapa[ind].plane] && L < LeadMax[mapa[ind].plane])
2005 // {
2006 /*
2007 if (idchambers[mapa[ind].plane] != 19.3f) H1chambrate->Fill(idchambers[mapa[ind].plane]);
2008 else H1chambrate->Fill(70.f);
2009 if (idchambers[mapa[ind].plane] < 100.f && idchambers[mapa[ind].plane] != 19.3f)
2010 {
2011 float x,y,z;
2012 get_hit_xyz0(mapa[ind].plane, mapa[ind].strip, (lead[ind]-lead[ind1])*HPTIMEBIN, &x, &y, &z);
2013 Hchambrate->Fill(x,y);
2014 Hstriprate->Fill(x,y);
2015 }
2016 */
2017 if (ira >= 0) {
2018 if (USE_FIT_SLEWING) {
2019 ifit0 = 0;
2020 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction(NSLFIT0)) != NULL) {
2021 strcpy(nfun0, NSLFIT0);
2022 ifit0 = 1;
2023 }
2024 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction("slew0")) != NULL) {
2025 strcpy(nfun0, "slew0");
2026 ifit0 = 1;
2027 }
2028 }
2030 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
2031 // if (mapa[ind].plane == 18) LOGF(info," peak 1 l1 %f W %f",L,W);
2032 if (USE_FIT_SLEWING && ifit0) {
2033 L -= fun0->Eval(t0width * INVHPTIMEBIN);
2034 } else {
2035 L -= TvsWt0[mapa[ind].plane][ira]->GetBinContent(
2036 TvsWt0[mapa[ind].plane][ira]->FindBin(t0width * INVHPTIMEBIN, mapa[ind].strip));
2037 }
2038 // if (mapa[ind].plane == 18) LOGF(info," peak 1 l2 %f",L);
2039 if (MAX_STRIP) {
2040 if (W > wmaxs[mapa[ind].plane]) {
2041 wmaxs[mapa[ind].plane] = W;
2042 tmaxs[mapa[ind].plane] = L;
2043 smax[mapa[ind].plane] = mapa[ind].strip;
2044 rmax[mapa[ind].plane] = ira;
2045 }
2046 } else {
2047 TvsW[mapa[ind].plane][ira]->Fill(W, mapa[ind].strip, L);
2048 // TvsWp[mapa[ind].plane][ira]->Fill(W, L);
2049 } // MAX_STRIP
2050 } // in width limits
2051 // } // in time limits
2052 } // lead and trail exists
2053 } // hits
2054 for (int i = 0; i < MaxPlane && MAX_STRIP; i++) {
2055 if (smax[i] > -1) {
2056 TvsW[i][rmax[i]]->Fill(wmaxs[i], smax[i], tmaxs[i]);
2057 // TvsWp[i][rmax[i]]->Fill(wmaxs[i], tmaxs[i]);
2058 }
2059 }
2060}
2061
2062void BmnTof2Raw2DigitNew::fillEvent(TClonesArray* data,
2063 unordered_map<UInt_t, Long64_t>* ts,
2064 Double_t t0,
2065 Double_t t0width,
2066 TClonesArray* tof2digit)
2067{
2068 if (fPeriod == 8 && fSRC == 0)
2069 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN > MAX_RAW_T0_TIME)
2070 return;
2071 // LOGF(info,"In fillEvent!");
2072 Long64_t ts_diff = 0L;
2073 Bool_t islead = false;
2074 unsigned rawtime = 0;
2075 if (CHECK_SLEWING)
2076 Wt0->Fill(t0width * INVHPTIMEBIN);
2077 if (CHECK_SLEWING)
2078 Lt0->Fill(t0 * INVHPTIMEBIN);
2079 float lead[TOF2_MAX_CHANNEL];
2080 float trail[TOF2_MAX_CHANNEL];
2081 memset(lead, 0, TOF2_MAX_CHANNEL * sizeof(float));
2082 memset(trail, 0, TOF2_MAX_CHANNEL * sizeof(int));
2083 for (int i = 0; i < data->GetEntriesFast(); i++) {
2084 BmnTDCDigit* digit = (BmnTDCDigit*)data->At(i);
2085 islead = digit->GetLeading();
2086 rawtime = digit->GetValue();
2087 if (fPeriod == 8 && fSRC == 0) {
2088 if (islead) {
2089 if (rawtime < MIN_RAW_LEADING_TIME)
2090 continue;
2091 if (rawtime > MAX_RAW_LEADING_TIME)
2092 continue;
2093 } else {
2094 if (rawtime < MIN_RAW_TRAILING_TIME)
2095 continue;
2096 if (rawtime > MAX_RAW_TRAILING_TIME)
2097 continue;
2098 }
2099 }
2100 int type = digit->GetType();
2101 int tdcnum = digit->GetHptdcId();
2102 int chanin = digit->GetChannel();
2103 int chan = -1;
2104 if ((fPeriod == 8 && fSRC == 0) || type == 0)
2105 type = kTDC64VHLE_E;
2106 // LOGF(info," type 0x%0x", type);
2107 if (type == kTDC32VL)
2108 chan = get_ch_tdc32vl(tdcnum, chanin * 4);
2109 else if (type == kTDC64VHLE)
2110 chan = get_ch_tdc64vhle(tdcnum, chanin * 4);
2111 else if (type == kTDC64VHLE_E)
2112 chan = chanin;
2113 else
2114 continue;
2115 // LOGF(info," chan %d", chan);
2116 if (chan < 0)
2117 continue;
2118 int nc = -1, ind = 0, crate = -1, slot = 0;
2119 if (fPeriod < 8 || fSRC != 0) {
2120 nc = numcrate((digit->GetSerial()) & 0xFFFFFF);
2121 if (nc < 0)
2122 continue;
2123 ind = nrec[nc][digit->GetSlot()][chan];
2124 if (ind == -1)
2125 continue;
2126 if (CHECK_SLEWING)
2127 Wts->Fill(ts_diff);
2128 crate = mapa[ind].crate;
2129 slot = mapa[ind].slot;
2130 if (t0 != 0.) {
2131 auto it = ts->find(digit->GetSerial());
2132 if (it == ts->end())
2133 continue;
2134 ts_diff = it->second;
2135 }
2136 } else {
2137 unsigned devsernum = digit->GetSerial();
2138 for (int idev = 0; idev < nslots + 1; idev++) {
2139 // if (Debug) LOGF(info," %d %x %x", idev,devnum[idev], devsernum);
2140 // LOGF(info," %d %x %x", idev,devnum[idev], devsernum);
2141 if ((unsigned)devnum[idev] == devsernum) {
2142 crate = devcrate[idev];
2143 slot = devslot[idev];
2144 // LOGF(info," crate %d slot %d", idev,crate, slot);
2145 break;
2146 }
2147 }
2148 if (crate == -1 || slot == 0)
2149 continue;
2150 if (t0 != 0.) {
2151 auto it = ts->find(idcrates[crate]);
2152 if (it == ts->end())
2153 continue;
2154 ts_diff = it->second;
2155 }
2156 nc = crate;
2157 if (nc < 0)
2158 continue;
2159 ind = nrec[nc][slot][chan];
2160 if (ind == -1)
2161 continue;
2162 if (crate != mapa[ind].crate)
2163 continue;
2164 if (slot != mapa[ind].slot)
2165 continue;
2166 // LOGF(info,"OK!");
2167 }
2168 if (CHECK_SLEWING)
2169 Wts->Fill(ts_diff);
2170 int dnl = rawtime & 0x3FF;
2171 float tm = (rawtime + DNL_Table[crate][slot][chan][dnl]) - chtima[crate][slot][chan]
2172 - (t0 - ts_diff) * INVHPTIMEBIN + T0shift;
2173 // LOGF(info,"tm %f c %d s %d cor %f ts_diff %lld",tm, crate, slot, DNL_Table[crate][slot][chan][dnl],
2174 // ts_diff);
2175 // if(digit->GetLeading()) lead[ind]=tm; else trail[ind]=tm;
2176 if (islead) {
2177 if (lead[ind] == 0)
2178 lead[ind] = tm;
2179 } else {
2180 if (trail[ind] == 0)
2181 trail[ind] = tm;
2182 }
2183 }
2184 // LOGF(info,"n_rec = %d", n_rec);
2185 int Wc = Wcut;
2186 int Wm = Wmax;
2187 char nfun0[12] = {""};
2188 int ifit0 = 0;
2189 TF1* fun0 = 0;
2190 char nfun[12] = {""};
2191 int ifit = 0;
2192 TF1* fun = 0;
2193 // LOGF(info,"*****************************");
2194 for (int ind = 0; ind < n_rec; ind++) {
2195 int ind1 = mapa[ind].pair;
2196 if (ind1 < 0)
2197 continue;
2198 if (lead[ind1] == 0 || trail[ind1] == 0)
2199 continue;
2200 // if (tmeane[ind] == 0.) continue;
2201 if (lead[ind] != 0 && trail[ind] != 0) {
2202 if (idchambers[mapa[ind].plane] < 100.f)
2203 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 1.5f)
2204 continue;
2205 if (idchambers[mapa[ind].plane] > 100.f)
2206 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 3.5f)
2207 continue;
2208 Wc = Wcut;
2209 if (Wcutc[mapa[ind].plane] >= 0.)
2210 Wc = Wcutc[mapa[ind].plane];
2211 Wm = Wmax;
2212 if (Wmaxc[mapa[ind].plane] >= 0.)
2213 Wm = Wmaxc[mapa[ind].plane];
2214 float L = (lead[ind1] + lead[ind]) / 2.;
2215 float D = (lead[ind1] - lead[ind]);
2216 float W1 = trail[ind] - lead[ind];
2217 float W2 = trail[ind1] - lead[ind1];
2218 float W = (W1 + W2) / 2.;
2219
2220 int ira = -1;
2221
2222 Int_t bin = 1;
2223
2224 // LOGF(info," fSlewing 0x%x t0 %f tw %f", fSlewing, t0, t0width);
2225
2226 if (fSlewing == 0 || t0 == 0. || t0width == 0.)
2227 goto createdigit;
2228
2229 if ((int)W1 < Wc && (int)W2 < Wc) {
2230 ira = 0;
2231 } else if (W1 >= Wc && W2 >= Wc && W1 < Wm && W2 < Wm) {
2232 ira = 1;
2233 } else if (W1 >= Wc && W2 < Wc && W1 < Wm) {
2234 ira = 2;
2235 } else if (W1 < Wc && W2 >= Wc && W2 < Wm) {
2236 ira = 3;
2237 }
2238
2239 if (CHECK_SLEWING) {
2240 if (idchambers[mapa[ind].plane] != 19.3f)
2241 H1chambrate->Fill(idchambers[mapa[ind].plane]);
2242 else
2243 H1chambrate->Fill(70.f);
2244
2245 if (idchambers[mapa[ind].plane] < 100.f && idchambers[mapa[ind].plane] != 19.3f) {
2246 float x, y, z;
2247 get_hit_xyz0(mapa[ind].plane, mapa[ind].strip, D * HPTIMEBIN, &x, &y, &z);
2248 Hchambrate->Fill(x, y);
2249 Hstriprate->Fill(x, y);
2250 }
2251 }
2252 // test!!!!
2253 // LOGF(info,"Chamber %d Time %f Width %f Tmin %d Tmax %d Wcut %d Wmax %d T0shft
2254 //%f",mapa[ind].plane,L,W,LeadMin[mapa[ind].plane],LeadMax[mapa[ind].plane],Wc,Wm,T0shift);
2255 if (CHECK_SLEWING) {
2257 int binw = (int)(W / 50.f);
2258 if (binw < 0 || binw >= 500)
2259 continue;
2260 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
2261 continue;
2262 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
2263 continue;
2264 } else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
2265 continue;
2266 }
2267 //
2268 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L1 = %f",L);
2269
2270 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L1 = %f Toffs = %f range =
2271 //%d",L,Toffsets0->GetBinContent(Toffsets0->FindBin(ind)), ira);
2273 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
2274 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L2 = %f",L);
2275 if (ira >= 0) {
2276 if (USE_FIT_SLEWING) {
2277 ifit0 = 0;
2278 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction(NSLFIT0)) != NULL) {
2279 strcpy(nfun0, NSLFIT0);
2280 ifit0 = 1;
2281 }
2282 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction("slew0")) != NULL) {
2283 strcpy(nfun0, "slew0");
2284 ifit0 = 1;
2285 }
2286
2287 ifit = 0;
2288 if ((fun = TvsW[mapa[ind].plane][ira]->GetFunction(NSLFIT)) != NULL) {
2289 strcpy(nfun, NSLFIT);
2290 ifit = 1;
2291 }
2292 if ((fun = TvsW[mapa[ind].plane][ira]->GetFunction("slew")) != NULL) {
2293 strcpy(nfun, "slew");
2294 ifit = 1;
2295 }
2296 }
2297 if (USE_FIT_SLEWING && ifit0) {
2298 L -= fun0->Eval(t0width * INVHPTIMEBIN);
2299 } else {
2300 bin = TvsWt0[mapa[ind].plane][ira]->FindBin(t0width * INVHPTIMEBIN, mapa[ind].strip);
2301 if (TvsWt0[mapa[ind].plane][ira]->GetBinError(bin) <= 0.f)
2302 continue;
2303 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L3 = %f T0cor =
2304 //%f",L,TvsWt0[mapa[ind].plane][ira]->GetBinContent(bin));
2305 L -= TvsWt0[mapa[ind].plane][ira]->GetBinContent(bin);
2306 }
2307 if (CHECK_SLEWING)
2308 TvsWt0r[mapa[ind].plane][ira]->Fill(t0width * INVHPTIMEBIN, L);
2309 if (USE_FIT_SLEWING && ifit) {
2310 L -= fun->Eval(W);
2311 } else {
2312 bin = TvsW[mapa[ind].plane][ira]->FindBin(W, mapa[ind].strip);
2313 if (TvsW[mapa[ind].plane][ira]->GetBinError(bin) <= 0.f)
2314 continue;
2315 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L4 = %f Tcor =
2316 //%f",L,TvsW[mapa[ind].plane][ira]->GetBinContent(bin));;
2317 L -= TvsW[mapa[ind].plane][ira]->GetBinContent(bin);
2318 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L4 = %f",L);
2319 }
2320 if (CHECK_SLEWING)
2321 TvsWr[mapa[ind].plane][ira]->Fill(W, L);
2322 if (USE_FINAL_OFFSETS == 1)
2323 L -= Toffsets[ira]->GetBinContent(Toffsets[ira]->FindBin(ind));
2324 else if (USE_FINAL_OFFSETS == 2)
2325 L -= Toffsetsf[ira]->GetBinContent(Toffsetsf[ira]->FindBin(ind));
2326 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L5 = %f",L);
2327 // if (idchambers[mapa[ind].plane] == 19.2f) LOGF(info,"L5 = %f finaly, t0 = %f t0width = %f",L, t0,
2328 // t0width);
2329 createdigit:
2330 Float_t D_corrected = get_hit_diff0(mapa[ind].plane, mapa[ind].strip, D * HPTIMEBIN);
2331 if (!CHECK_SLEWING)
2332 new ((*tof2digit)[tof2digit->GetEntriesFast()])
2333 BmnTof2Digit(mapa[ind].plane, mapa[ind].strip, L * HPTIMEBIN, W, D_corrected);
2334 // LOGF(info,"%d %d %f %f %f t0 %f t0width %f",
2335 // mapa[ind].plane,mapa[ind].strip,L*HPTIMEBIN,W,D*HPTIMEBIN, t0, t0width);
2336 } // in width regions limits
2337 } // leading and trailing exists
2338 } // loop on strips
2339}
2341 unordered_map<UInt_t, Long64_t>* ts,
2342 Double_t t0,
2343 Double_t t0width)
2344{
2345 if (fPeriod == 8 && fSRC == 0)
2346 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN > MAX_RAW_T0_TIME)
2347 return;
2348 Long64_t ts_diff = 0L;
2349 Bool_t islead = false;
2350 unsigned rawtime = 0;
2351 Lt0->Fill(t0 * INVHPTIMEBIN);
2352 Wt0->Fill(t0width * INVHPTIMEBIN);
2353 float lead[TOF2_MAX_CHANNEL];
2354 float trail[TOF2_MAX_CHANNEL];
2355 memset(lead, 0, TOF2_MAX_CHANNEL * sizeof(float));
2356 memset(trail, 0, TOF2_MAX_CHANNEL * sizeof(int));
2357 for (int i = 0; i < data->GetEntriesFast(); i++) {
2358 BmnTDCDigit* digit = (BmnTDCDigit*)data->At(i);
2359 islead = digit->GetLeading();
2360 rawtime = digit->GetValue();
2361 if (fPeriod == 8 && fSRC == 0) {
2362 if (islead) {
2363 if (rawtime < MIN_RAW_LEADING_TIME)
2364 continue;
2365 if (rawtime > MAX_RAW_LEADING_TIME)
2366 continue;
2367 } else {
2368 if (rawtime < MIN_RAW_TRAILING_TIME)
2369 continue;
2370 if (rawtime > MAX_RAW_TRAILING_TIME)
2371 continue;
2372 }
2373 }
2374 int type = digit->GetType();
2375 int tdcnum = digit->GetHptdcId();
2376 int chanin = digit->GetChannel();
2377 int chan = -1;
2378 if ((fPeriod == 8 && fSRC == 0) || type == 0)
2379 type = kTDC64VHLE_E;
2380 if (type == kTDC32VL)
2381 chan = get_ch_tdc32vl(tdcnum, chanin * 4);
2382 else if (type == kTDC64VHLE)
2383 chan = get_ch_tdc64vhle(tdcnum, chanin * 4);
2384 else if (type == kTDC64VHLE_E)
2385 chan = chanin;
2386 else
2387 continue;
2388 // LOGF(info,"Point 1");
2389 if (chan < 0)
2390 continue;
2391 // LOGF(info,"Point 2");
2392
2393 int nc = -1, ind = 0, crate = -1, slot = 0;
2394 if (fPeriod < 8 || fSRC != 0) {
2395 nc = numcrate((digit->GetSerial()) & 0xFFFFFF);
2396 if (nc < 0)
2397 continue;
2398 ind = nrec[nc][digit->GetSlot()][chan];
2399 if (ind == -1)
2400 continue;
2401 crate = mapa[ind].crate;
2402 slot = mapa[ind].slot;
2403 if (t0 != 0.) {
2404 auto it = ts->find(digit->GetSerial());
2405 if (it == ts->end())
2406 continue;
2407 ts_diff = it->second;
2408 }
2409 } else {
2410 unsigned devsernum = digit->GetSerial();
2411 for (int idev = 0; idev < nslots + 1; idev++) {
2412 // if (Debug) LOGF(info," %d %x %x", idev,devnum[idev], devsernum);
2413 // LOGF(info," %d %x %x", idev,devnum[idev], devsernum);
2414 if ((unsigned)devnum[idev] == devsernum) {
2415 crate = devcrate[idev];
2416 slot = devslot[idev];
2417 // LOGF(info," crate %d slot %d", idev,crate, slot);
2418 break;
2419 }
2420 }
2421 if (crate == -1 || slot == 0)
2422 continue;
2423 // LOGF(info,"Point 3");
2424 if (t0 != 0.) {
2425 auto it = ts->find(idcrates[crate]);
2426 if (it == ts->end())
2427 continue;
2428 ts_diff = it->second;
2429 }
2430 // LOGF(info,"Point 4");
2431 nc = crate;
2432 if (nc < 0)
2433 continue;
2434 ind = nrec[nc][slot][chan];
2435 if (ind == -1)
2436 continue;
2437 if (crate != mapa[ind].crate)
2438 continue;
2439 if (slot != mapa[ind].slot)
2440 continue;
2441 // LOGF(info,"Point 5");
2442 }
2443 Wts->Fill(ts_diff);
2444 int dnl = rawtime & 0x3FF;
2445 float tm = (rawtime + DNL_Table[crate][slot][chan][dnl]) - chtima[crate][slot][chan]
2446 - (t0 - ts_diff) * INVHPTIMEBIN + T0shift;
2447 // LOGF(info,"tm %f c %d s %d cor %f ts_diff %lld",tm, crate, slot, DNL_Table[crate][slot][chan][dnl],
2448 // ts_diff);
2449 // if(digit->GetLeading()) lead[ind]=tm; else trail[ind]=tm;
2450 if (islead) {
2451 if (lead[ind] == 0)
2452 lead[ind] = tm;
2453 } else {
2454 if (trail[ind] == 0)
2455 trail[ind] = tm;
2456 }
2457 }
2458 // LOGF(info,"n_rec = %d", n_rec);
2459 int Wc = Wcut;
2460 // int Wm = Wmax;
2461 char nfun0[12] = {""};
2462 int ifit0 = 0;
2463 TF1* fun0 = 0;
2464 char nfun[12] = {""};
2465 int ifit = 0;
2466 TF1* fun = 0;
2467 for (int ind = 0; ind < n_rec; ind++) {
2468 int ind1 = mapa[ind].pair;
2469 if (ind1 < 0)
2470 continue;
2471 if (lead[ind1] == 0 || trail[ind1] == 0)
2472 continue;
2473 if (lead[ind] != 0 && trail[ind] != 0) {
2474 if (idchambers[mapa[ind].plane] < 100.f)
2475 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 1.5f)
2476 continue;
2477 if (idchambers[mapa[ind].plane] > 100.f)
2478 if (fabs(lead[ind] - lead[ind1]) * HPTIMEBIN > 3.5f)
2479 continue;
2480 // LOGF(info,"Ok!");
2481 Wc = Wcut;
2482 if (Wcutc[mapa[ind].plane] >= 0.)
2483 Wc = Wcutc[mapa[ind].plane];
2484 // Wm = Wmax;
2485 // if (Wmaxc[mapa[ind].plane] >= 0.) Wm = Wmaxc[mapa[ind].plane];
2486 float L = (lead[ind1] + lead[ind]) / 2.;
2487 // float D = (lead[ind1]-lead[ind]);
2488 float W1 = trail[ind] - lead[ind];
2489 float W2 = trail[ind1] - lead[ind1];
2490 float W = (W1 + W2) / 2.;
2491
2492 int ira = -1;
2493
2494 if ((int)W1 < Wc && (int)W2 < Wc) {
2495 ira = 0;
2496 } else if (W1 >= Wc && W2 >= Wc) {
2497 ira = 1;
2498 } else if (W1 >= Wc && W2 < Wc) {
2499 ira = 2;
2500 } else if (W1 < Wc && W2 >= Wc) {
2501 ira = 3;
2502 }
2504 int binw = (int)(W / 50.f);
2505 if (binw < 0 || binw >= 500)
2506 continue;
2507 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
2508 continue;
2509 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
2510 continue;
2511 } else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
2512 continue;
2513 // if (L >= LeadMin[mapa[ind].plane] && L < LeadMax[mapa[ind].plane])
2514 // {
2515
2516 if (idchambers[mapa[ind].plane] != 19.3f)
2517 H1chambrate->Fill(idchambers[mapa[ind].plane]);
2518 else
2519 H1chambrate->Fill(70.f);
2520 if (idchambers[mapa[ind].plane] < 100.f && idchambers[mapa[ind].plane] != 19.3f) {
2521 float x, y, z;
2522 get_hit_xyz0(mapa[ind].plane, mapa[ind].strip, (lead[ind] - lead[ind1]) * HPTIMEBIN, &x, &y, &z);
2523 Hchambrate->Fill(x, y);
2524 Hstriprate->Fill(x, y);
2525 }
2526
2527 if (ira >= 0) {
2529 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
2530 if (USE_FIT_SLEWING) {
2531 ifit0 = 0;
2532 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction(NSLFIT0)) != NULL) {
2533 strcpy(nfun0, NSLFIT0);
2534 ifit0 = 1;
2535 }
2536 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction("slew0")) != NULL) {
2537 strcpy(nfun0, "slew0");
2538 ifit0 = 1;
2539 }
2540
2541 ifit = 0;
2542 if ((fun = TvsW[mapa[ind].plane][ira]->GetFunction(NSLFIT)) != NULL) {
2543 strcpy(nfun, NSLFIT);
2544 ifit = 1;
2545 }
2546 if ((fun = TvsW[mapa[ind].plane][ira]->GetFunction("slew")) != NULL) {
2547 strcpy(nfun, "slew");
2548 ifit = 1;
2549 }
2550 }
2551 if (USE_FIT_SLEWING && ifit0) {
2552 L -= fun0->Eval(t0width * INVHPTIMEBIN);
2553 } else {
2554 L -= TvsWt0[mapa[ind].plane][ira]->GetBinContent(
2555 TvsWt0[mapa[ind].plane][ira]->FindBin(t0width * INVHPTIMEBIN, mapa[ind].strip));
2556 }
2557 if (USE_FIT_SLEWING && ifit) {
2558 L -= fun->Eval(W);
2559 } else {
2560 L -= TvsW[mapa[ind].plane][ira]->GetBinContent(
2561 TvsW[mapa[ind].plane][ira]->FindBin(W, mapa[ind].strip));
2562 }
2563 Toffsets[ira]->Fill(ind, L);
2564 TvsSm[mapa[ind].plane][ira]->Fill(mapa[ind].strip, L);
2565 } else {
2566 continue;
2567 }
2568 } // in width regions limits
2569 // } // in time limits
2570 } // loop on strips
2571}
2572
2574{
2575 if (!FIT_SLEWING)
2576 return;
2577 TProfile2D* prof2d = 0;
2578 TProfile* prof = 0;
2579 TFitResultPtr result = 0, resultold = 0;
2580 TF1 *ptotal, *p[20];
2581 int col[20] = {kGreen, kBlue, kMagenta, kYellow, 28, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
2582 double par[44] = {0.f};
2583 double pmin, pmax;
2584 char name[128];
2585 FILE* fout = 0;
2586 char filn[128];
2587 int subdeg = SUBDEG;
2588
2589 gROOT->ProcessLine("gErrorIgnoreLevel = 3001;");
2590
2591 TString dir = getenv("VMCWORKDIR");
2592 TString path = dir + "/parameters/tof2_slewing/";
2593 sprintf(filn, "%s%s", path.Data(), filname_base);
2594 strcat(filn, ".fit.log");
2595 fout = fopen(filn, "w");
2596 TCanvas* c = 0;
2597 if (DRAW_GOOD || DRAW_BAD)
2598 c = new TCanvas("c", "Slewing Fit", 800, 900);
2599 for (int plane = 0; plane < MaxPlane; plane++) {
2600 for (int pk = 0; pk < 4; pk++) {
2601 for (int s = 1; s <= 32; s++) {
2602 prof2d = TvsWt0[plane][pk];
2603 prof2d->SetStats(kFALSE);
2604 sprintf(name, "%s_strip%d", prof2d->GetTitle(), s);
2605 prof = prof2d->ProfileX(name, s, s);
2606 int nonzero = 0, bfirst = 0, blast = 0, nonzeromax = 0, bfirstmax = 0;
2607 int minpoints = 0;
2608 if (SMOOTH) {
2609 prof->Smooth();
2610 if (DRAW_GOOD) {
2611 prof->Draw();
2612 gPad->WaitPrimitive();
2613 }
2614 goto Rpc;
2615 }
2616 pmin = 1000000.;
2617 pmax = 0.;
2618 for (int i = 1; i <= prof->GetNbinsX(); i++) {
2619 if (prof->GetBinContent(i) != 0) {
2620 if (prof->GetBinEntries(i) < MIN_FIT_ENTRIES) {
2621 prof->SetBinContent(i, 0);
2622 prof->SetBinEntries(i, 0);
2623 prof->SetBinError(i, 0);
2624 } else {
2625 if (bfirst == 0)
2626 bfirst = i;
2627 blast = i;
2628 nonzero++;
2629 if (prof->GetBinContent(i) > pmax)
2630 pmax = prof->GetBinContent(i);
2631 if (prof->GetBinContent(i) < pmin)
2632 pmin = prof->GetBinContent(i);
2633 }
2634 } else {
2635 prof->SetBinContent(i, 0);
2636 prof->SetBinEntries(i, 0);
2637 prof->SetBinError(i, 0);
2638 }
2639 }
2640 if (bfirst > 1)
2641 bfirst--;
2642 if (blast < prof->GetNbinsX())
2643 blast++;
2644 if (SKIP_SIDES) {
2645 nonzero = 0;
2646 bfirst = 0;
2647 blast = 0;
2648 nonzeromax = 0;
2649 for (int i = 1; i <= prof->GetNbinsX(); i++) {
2650 if (prof->GetBinContent(i) != 0) {
2651 if (nonzero == 0)
2652 bfirst = i;
2653 nonzero++;
2654 } else {
2655 if (nonzero > nonzeromax) {
2656 nonzeromax = nonzero;
2657 blast = i - 1;
2658 bfirstmax = bfirst;
2659 }
2660 nonzero = 0;
2661 }
2662 }
2663 if (nonzero > nonzeromax) {
2664 nonzeromax = nonzero;
2665 blast = prof->GetNbinsX();
2666 bfirstmax = bfirst;
2667 }
2668 } else {
2669 bfirstmax = bfirst;
2670 nonzeromax = nonzero;
2671 }
2672
2673 sscanf(NSLFIT0, "pol%d", &minpoints);
2674 if (nonzeromax > (minpoints + 1)) {
2675 char fun[12], nfun[12], nfunold[12];
2676 for (int ifi = 0; ifi < MAX_FIT_ATTEMPTS; ifi++) {
2677
2678 if (!ITERATIONS0) {
2679 sprintf(fun, "%s", NSLFIT0);
2680 sprintf(nfun, "pfi");
2681 TF1* pfi = new TF1(nfun, fun, TvsWt0[plane][pk]->GetBinCenter(bfirstmax),
2682 TvsWt0[plane][pk]->GetBinCenter(blast));
2683 pfi->SetLineColor(kBlack);
2684 result = prof->Fit(pfi, FIT, "", TvsWt0[plane][pk]->GetBinCenter(bfirstmax),
2685 TvsWt0[plane][pk]->GetBinCenter(blast));
2686 if (prof->GetFunction(nfun))
2687 if (result->IsValid() && result->Chi2() > 0.)
2688 break;
2689 } else {
2690 for (int it = 0; it <= minpoints; it++) {
2691 sprintf(fun, "pol%d", it);
2692 sprintf(nfun, "pfi%d", it);
2693 TF1* pfi = new TF1(nfun, fun, TvsWt0[plane][pk]->GetBinCenter(bfirstmax),
2694 TvsWt0[plane][pk]->GetBinCenter(blast));
2695 pfi->SetLineColor(kBlack);
2696 result = prof->Fit(pfi, FITI0, "", TvsWt0[plane][pk]->GetBinCenter(bfirstmax),
2697 TvsWt0[plane][pk]->GetBinCenter(blast));
2698 if (prof->GetFunction(nfun)) {
2699 if (!(result->IsValid() && result->Chi2() > 0.)) {
2700 result = resultold;
2701 strcpy(nfun, nfunold);
2702 break;
2703 }
2704 } else {
2705 result = resultold;
2706 strcpy(nfun, nfunold);
2707 break;
2708 }
2709 resultold = result;
2710 strcpy(nfunold, nfun);
2711 }
2712 if (prof->GetFunction(nfun))
2713 if (result->IsValid() && result->Chi2() > 0.)
2714 break;
2715 }
2716 }
2717 if (prof->GetFunction(nfun))
2718 (prof->GetFunction(nfun))->ResetBit(TF1::kNotDraw);
2719 if (prof->GetFunction(nfun))
2720 (prof->GetFunction(nfun))->SetName("slew0");
2721 bool badresult = true;
2722 if (prof->GetFunction(nfun))
2723 if (result->IsValid() && result->Chi2() > 0.)
2724 badresult = false;
2725
2726 if (badresult) {
2727 if (PRINT_FIT_RESULTS) {
2728 LOGF(info, " Chamber %d peak %d T0 slewing - fit unsuccessful, chi2 = %f/%d", plane + 1,
2729 pk + 1, result->Chi2(), result->Ndf());
2730 fprintf(fout, " Chamber %d peak %d T0 slewing - fit unsuccessful, chi2 = %f/%d\n",
2731 plane + 1, pk + 1, result->Chi2(), result->Ndf());
2732 }
2733 if (DRAW_BAD) {
2734 prof->Draw();
2735 prof->GetXaxis()->SetRange(bfirstmax, blast);
2736 prof->SetMaximum(pmax + (pmax - pmin) * 0.10);
2737 prof->SetMinimum(pmin - (pmax - pmin) * 0.10);
2738 // LOGF(info,"min %f max %f",pmin,pmax);
2739 c->Update();
2740 c->WaitPrimitive();
2741 }
2742 } else {
2743 if (PRINT_FIT_RESULTS) {
2744 LOGF(info, " Chamber %d (%.1f) peak %d T0 slewing - fit OK, chi2 = %f/%d", plane + 1,
2745 idchambers[plane], pk + 1, result->Chi2(), result->Ndf());
2746 fprintf(fout, " Chamber %d (%.1f) peak %d T0 slewing - fit OK, chi2 = %f/%d\n", plane + 1,
2747 idchambers[plane], pk + 1, result->Chi2(), result->Ndf());
2748 }
2749 if (DRAW_GOOD) {
2750 prof->Draw();
2751 prof->GetXaxis()->SetRange(bfirstmax, blast);
2752 prof->SetMaximum(pmax + (pmax - pmin) * 0.10);
2753 prof->SetMinimum(pmin - (pmax - pmin) * 0.10);
2754 // LOGF(info,"min %f max %f",pmin,pmax);
2755 c->Update();
2756 c->WaitPrimitive();
2757 }
2758 }
2759
2760 TList* l = prof->GetListOfFunctions();
2761 int nf = l->GetEntries();
2762 for (int il = 0; il < nf; il++) {
2763 // LOGF(info," %s", (l->At(il))->GetName());
2764 }
2765 TF1 *fu = 0, *lfun[20] = {NULL};
2766 int nrej = 0;
2767 for (int il = 0; il < nf; il++) {
2768 fu = (TF1*)(l->At(il));
2769 if (!strcmp(fu->GetName(), "slew0"))
2770 continue;
2771 lfun[nrej++] = fu;
2772 }
2773 for (int il = 0; il < nrej; il++) {
2774 if (lfun[il])
2775 delete lfun[il];
2776 }
2777 l = prof->GetListOfFunctions();
2778 for (int il = 0; il < l->GetEntries(); il++) {
2779 // LOGF(info," ** %s", (l->At(il))->GetName());
2780 }
2781 } else {
2782 LOGF(info, " Chamber %d (%.1f) peak %d T0 slewing - too few nonzero bins = %d", plane + 1,
2783 idchambers[plane], pk + 1, nonzero);
2784 fprintf(fout, " Chamber %d (%.1f) peak %d T0 slewing - too few nonzero bins = %d\n", plane + 1,
2785 idchambers[plane], pk + 1, nonzero);
2786 }
2787 Rpc:
2788 prof2d = TvsW[plane][pk];
2789 prof2d->SetStats(kFALSE);
2790 sprintf(name, "%s_strip%d", prof2d->GetTitle(), s);
2791 prof = prof2d->ProfileX(name, s, s);
2792 if (SMOOTH) {
2793 prof->Smooth();
2794 if (DRAW_GOOD) {
2795 prof->Draw();
2796 gPad->WaitPrimitive();
2797 }
2798 continue;
2799 }
2800 pmin = 1000000.;
2801 pmax = 0.;
2802 nonzeromax = 0;
2803 bfirst = 0;
2804 blast = 0;
2805 for (int i = 1; i <= prof->GetNbinsX(); i++) {
2806 if (prof->GetBinContent(i) != 0) {
2807 if (prof->GetBinEntries(i) < MIN_FIT_ENTRIES) {
2808 prof->SetBinContent(i, 0);
2809 prof->SetBinEntries(i, 0);
2810 prof->SetBinError(i, 0);
2811 } else {
2812 if (bfirst == 0)
2813 bfirst = i;
2814 blast = i;
2815 nonzero++;
2816 if (prof->GetBinContent(i) > pmax)
2817 pmax = prof->GetBinContent(i);
2818 if (prof->GetBinContent(i) < pmin)
2819 pmin = prof->GetBinContent(i);
2820 }
2821 } else {
2822 prof->SetBinContent(i, 0);
2823 prof->SetBinEntries(i, 0);
2824 prof->SetBinError(i, 0);
2825 }
2826 }
2827 if (bfirst > 1)
2828 bfirst--;
2829 if (blast < prof->GetNbinsX())
2830 blast++;
2831 if (SKIP_SIDES) {
2832 nonzero = 0;
2833 bfirst = 0;
2834 blast = 0;
2835 nonzeromax = 0;
2836 bfirstmax = 0;
2837 for (int i = 1; i <= prof->GetNbinsX(); i++) {
2838 if (prof->GetBinContent(i) != 0) {
2839 if (nonzero == 0)
2840 bfirst = i;
2841 nonzero++;
2842 } else {
2843 if (nonzero > nonzeromax) {
2844 nonzeromax = nonzero;
2845 blast = i - 1;
2846 bfirstmax = bfirst;
2847 }
2848 nonzero = 0;
2849 }
2850 }
2851 if (nonzero > nonzeromax) {
2852 nonzeromax = nonzero;
2853 blast = prof->GetNbinsX();
2854 bfirstmax = bfirst;
2855 }
2856 } else {
2857 bfirstmax = bfirst;
2858 nonzeromax = nonzero;
2859 }
2860 sscanf(NSLFIT, "pol%d", &minpoints);
2861 // int minp = minpoints;
2862 // if (SUBRANGES) minp = (SUBRANGES+1)*subdeg;
2863 char ntotal[128];
2864 if (nonzeromax > (minpoints + 1)) {
2865 char fun[12], nfun[12], nfunold[12];
2866 for (int ifi = 0; ifi < MAX_FIT_ATTEMPTS; ifi++) {
2867 if (SUBRANGES) {
2868 strcpy(nfun, "ptotal");
2869 float x0 = TvsW[plane][pk]->GetBinCenter(bfirstmax);
2870 float dx =
2871 (TvsW[plane][pk]->GetBinCenter(blast) - TvsW[plane][pk]->GetBinCenter(bfirstmax)) / 3.f;
2872 float dx1 = dx / 2.f, xc = x0, dxc = dx1;
2873 char spol[12], snam[10][12];
2874 sprintf(spol, "pol%d", subdeg);
2875 for (int is = 0; is < (SUBRANGES + 1); is++) {
2876 sprintf(snam[is], "p%d", is + 1);
2877 p[is] = new TF1(snam[is], spol, xc, xc + dxc);
2878 p[is]->SetLineColor(col[is]);
2879 // Fit each function and add it to the list of functions
2880 if (is == 0)
2881 prof->Fit(p[is], "Q0R+");
2882 else
2883 prof->Fit(p[is], "Q0R+");
2884 if (prof->GetFunction(snam[is]))
2885 (prof->GetFunction(snam[is]))->ResetBit(TF1::kNotDraw);
2886 // Get the parameters from the fit
2887 p[is]->GetParameters(&par[is * (subdeg + 1)]);
2888 xc += dxc;
2889 if (is == 0)
2890 dxc = dx1;
2891 else
2892 dxc = dx;
2893 if (is == 0)
2894 sprintf(ntotal, "%s(%d)", spol, is * (subdeg + 1));
2895 else
2896 sprintf(ntotal, "%s+%s(%d)", ntotal, spol, is * (subdeg + 1));
2897 // LOGF(info,"%s %s %f %f",snam[is],spol,xc,xc+dxc);
2898 }
2899 // The total is the sum of the four, each has 7 parameters
2900 ptotal = new TF1("ptotal", ntotal, x0, xc + dxc);
2901 ptotal->SetLineColor(kBlack);
2902 // LOGF(info,"ptotal %s %f %f",ntotal,x0,xc+dxc);
2903 // Use the parameters on the sum
2904 ptotal->SetParameters(par);
2905 result = prof->Fit(ptotal, "Q0RS+", "", x0, xc);
2906 if (result->IsValid() && result->Chi2() > 0. && prof->GetFunction("ptotal"))
2907 break;
2908 } else {
2909 if (!ITERATIONS) {
2910
2911 sprintf(fun, "%s", NSLFIT);
2912 sprintf(nfun, "pfi");
2913 TF1* pfi = new TF1(nfun, fun, TvsW[plane][pk]->GetBinCenter(bfirstmax),
2914 TvsW[plane][pk]->GetBinCenter(blast));
2915 pfi->SetLineColor(kBlack);
2916 result = prof->Fit(pfi, FIT, "", TvsW[plane][pk]->GetBinCenter(bfirstmax),
2917 TvsW[plane][pk]->GetBinCenter(blast));
2918 if (result->IsValid() && result->Chi2() > 0. && prof->GetFunction(nfun))
2919 break;
2920 } else {
2921 for (int it = 0; it <= minpoints; it++) {
2922 sprintf(fun, "pol%d", it);
2923 sprintf(nfun, "pfi%d", it);
2924 TF1* pfi = new TF1(nfun, fun, TvsW[plane][pk]->GetBinCenter(bfirstmax),
2925 TvsW[plane][pk]->GetBinCenter(blast));
2926 pfi->SetLineColor(kBlack);
2927 result = prof->Fit(pfi, FITI, "", TvsW[plane][pk]->GetBinCenter(bfirstmax),
2928 TvsW[plane][pk]->GetBinCenter(blast));
2929 if (prof->GetFunction(nfun)) {
2930 if (!(result->IsValid() && result->Chi2() > 0.)) {
2931 result = resultold;
2932 strcpy(nfun, nfunold);
2933 break;
2934 }
2935 } else {
2936 result = resultold;
2937 strcpy(nfun, nfunold);
2938 break;
2939 }
2940 resultold = result;
2941 strcpy(nfunold, nfun);
2942 }
2943 if (prof->GetFunction(nfun))
2944 if (result->IsValid() && result->Chi2() > 0.)
2945 break;
2946 }
2947 }
2948 }
2949 if (prof->GetFunction(nfun))
2950 (prof->GetFunction(nfun))->ResetBit(TF1::kNotDraw);
2951 if (prof->GetFunction(nfun))
2952 (prof->GetFunction(nfun))->SetName("slew");
2953 bool badresult = true;
2954 if (prof->GetFunction(nfun))
2955 if (result->IsValid() && result->Chi2() > 0.)
2956 badresult = false;
2957
2958 if (badresult) {
2959 if (PRINT_FIT_RESULTS) {
2960 LOGF(info, " Chamber %d (%.1f) peak %d RPC slewing - fit unsuccessful, chi2 = %f/%d",
2961 plane + 1, idchambers[plane], pk + 1, result->Chi2(), result->Ndf());
2962 fprintf(fout, " Chamber %d (%.1f) peak %d RPC slewing - fit unsuccessful, chi2 = %f/%d\n",
2963 plane + 1, idchambers[plane], pk + 1, result->Chi2(), result->Ndf());
2964 }
2965 if (DRAW_BAD) {
2966 prof->Draw();
2967 prof->GetXaxis()->SetRange(bfirstmax, blast);
2968 prof->SetMaximum(pmax + (pmax - pmin) * 0.10);
2969 prof->SetMinimum(pmin - (pmax - pmin) * 0.10);
2970 c->Update();
2971 c->WaitPrimitive();
2972 }
2973 } else {
2974 if (PRINT_FIT_RESULTS) {
2975 LOGF(info, " Chamber %d (%.1f) peak %d RPC slewing - fit OK, chi2 = %f/%d", plane + 1,
2976 idchambers[plane], pk + 1, result->Chi2(), result->Ndf());
2977 fprintf(fout, " Chamber %d (%.1f) peak %d RPC slewing - fit OK, chi2 = %f/%d\n", plane + 1,
2978 idchambers[plane], pk + 1, result->Chi2(), result->Ndf());
2979 }
2980 if (DRAW_GOOD) {
2981 prof->Draw();
2982 prof->GetXaxis()->SetRange(bfirstmax, blast);
2983 prof->SetMaximum(pmax + (pmax - pmin) * 0.10);
2984 prof->SetMinimum(pmin - (pmax - pmin) * 0.10);
2985 c->Update();
2986 c->WaitPrimitive();
2987 }
2988 }
2989 TList* l = prof->GetListOfFunctions();
2990 int nf = l->GetEntries();
2991 for (int il = 0; il < nf; il++) {
2992 // LOGF(info," %s", (l->At(il))->GetName());
2993 }
2994 TF1 *fu = 0, *lfun[20] = {NULL};
2995 int nrej = 0;
2996 for (int il = 0; il < nf; il++) {
2997 fu = (TF1*)(l->At(il));
2998 if (!strcmp(fu->GetName(), "slew"))
2999 continue;
3000 lfun[nrej++] = fu;
3001 }
3002 for (int il = 0; il < nrej; il++) {
3003 if (lfun[il])
3004 delete lfun[il];
3005 }
3006 l = prof->GetListOfFunctions();
3007 for (int il = 0; il < l->GetEntries(); il++) {
3008 // LOGF(info," ** %s", (l->At(il))->GetName());
3009 }
3010 } else {
3011 LOGF(info, " Chamber %d (%.1f) peak %d RPC slewing - too few nonzero bins = %d", plane + 1,
3012 idchambers[plane], pk + 1, nonzero);
3013 fprintf(fout, " Chamber %d (%.1f) peak %d RPC slewing - too few nonzero bins = %d\n", plane + 1,
3014 idchambers[plane], pk + 1, nonzero);
3015 }
3016
3017 } // loop on strips
3018
3019 } // loop on peaks
3020
3021 } // loop on chambers
3022
3023 fclose(fout);
3024
3025 gROOT->ProcessLine("gErrorIgnoreLevel = 1001;");
3026
3027 return;
3028}
3029
3031{
3032 if (!FINAL_OFFSETS) {
3033 if (fSlewing) {
3034 fSlewing->Write(0, TObject::kOverwrite);
3035 fSlewing->Close();
3036 fSlewing = 0;
3037 }
3038 return;
3039 }
3040 float tmeane_average[TOF2_MAX_CHAMBERS][4];
3041 float tmeane[TOF2_MAX_CHANNEL][4];
3042 // TProfile *prof = 0;
3043 TH1D* proj = 0;
3044 // TF1 *gr = 0;
3045 char namp[64], namf[64];
3046 int ncon = 0;
3047 double mpos = 0.;
3048 FILE* fout = 0;
3049 FILE* fdeb = 0;
3050 TString dir = getenv("VMCWORKDIR");
3051 TString path = dir + "/parameters/tof2_slewing/";
3052 char filn[512];
3053 sprintf(filn, "%s%s", path.Data(), filname_base);
3054 strcat(filn, ".equalization.log");
3055 fout = fopen(filn, "w");
3056 if (DEBUG_EQUALIZATION) {
3057 sprintf(filn, "%s%s", path.Data(), filname_base);
3058 strcat(filn, ".equalization.debug");
3059 fdeb = fopen(filn, "w");
3060 }
3061 for (int plane = 0; plane < MaxPlane; plane++) {
3062 for (int pk = 0; pk < 4; pk++) {
3064 LOGF(info,
3065 "**************** %s Chamber %d Peak %d Time-Width area RPC slewing (write) "
3066 "******************************\n",
3067 filname_base, plane + 1, pk + 1);
3068 fprintf(
3069 fout,
3070 "**************** %s Chamber %d Peak %d Time-Width area slewing *******************************\n\n",
3071 filname_base, plane + 1, pk + 1);
3072
3073 int ip, is;
3074 int na = 0;
3075 tmeane_average[plane][pk] = 0.;
3076 for (int ind = 0; ind < n_rec; ind++) {
3077 if (mapa[ind].pair < 0)
3078 continue;
3079 ip = mapa[ind].plane;
3080 if (ip != plane)
3081 continue;
3082 is = mapa[ind].strip;
3083 // printf("** ip %d is %d nt %d t %f\n",ip,is,ntmeane[ind][pk],tmeane[ind][pk]);
3084 sprintf(namp, "Maxima_chamber_%d_strip_%d_equalization", ip + 1, is + 1);
3085 proj = TvsSm[ip][pk]->ProjectionY(namp, is + 1, is + 1);
3086 if (EQUAL_MAXIMA) {
3087 int mbin = proj->GetMaximumBin();
3088 int nbin = proj->GetNbinsX();
3089 mpos = proj->GetBinCenter(mbin);
3090 ncon = proj->GetBinContent(mbin);
3091 LOGF(info, "Chamber %d strip %d max %d at %f", ip, is, ncon, mpos);
3092 if (ncon > 50) {
3093 int nonzero = 0;
3094 int zflag = 0;
3095 double sum = 0., sumx = 0.;
3096 for (int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin);
3097 ib++)
3098 {
3099 if (proj->GetBinContent(ib) > 0.) {
3100 nonzero++;
3101 sum += proj->GetBinContent(ib);
3102 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(ib);
3103 } else {
3104 zflag = 1;
3105 }
3106 }
3107 if (FIT_MAXIMA && zflag == 0 && nonzero >= 5) {
3108 sprintf(namf, "gaus%dstrip%d", ip + 1, is + 1);
3109 // if (gr) delete gr;
3110 // gr = new TF1(namf,"gaus",mpos-6.,mpos+6.);
3111 proj->Fit(namf, "QR0");
3112 if (!(proj->GetFunction(namf))) {
3113 // tmeane[ind][pk] = mpos;
3114 tmeane[ind][pk] = sumx / sum;
3115 if (ip == 18 && fdeb) {
3116 fprintf(fdeb, "Max: Chamber %d strip %d zflag %d nonzero %d mpos %f tmeane %f\n",
3117 ip, is, zflag, nonzero, mpos, tmeane[ind][pk]);
3118 }
3119 } else {
3120 tmeane[ind][pk] = proj->GetFunction(namf)->GetParameter(1);
3121 if (ip == 18 && fdeb) {
3122 fprintf(fdeb, "Fit: Chamber %d strip %d zflag %d nonzero %d mpos %f tmeane %f\n",
3123 ip, is, zflag, nonzero, mpos, tmeane[ind][pk]);
3124 }
3125 }
3126 } else {
3127 // tmeane[ind][pk] = mpos;
3128 tmeane[ind][pk] = sumx / sum;
3129 if (ip == 18 && fdeb) {
3130 fprintf(fdeb, "Max: Chamber %d strip %d zflag %d nonzero %d mpos %f tmeane %f\n", ip,
3131 is, zflag, nonzero, mpos, tmeane[ind][pk]);
3132 }
3133 }
3134 tmeane_average[plane][pk] += tmeane[ind][pk];
3135 na++;
3136 } else if (ncon > 0) {
3137 double sum = 0., sumx = 0.;
3138 for (int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin);
3139 ib++)
3140 {
3141 if (proj->GetBinContent(ib) > 0.) {
3142 sum += proj->GetBinContent(ib);
3143 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(ib);
3144 }
3145 }
3146 // tmeane[ind][pk] = proj->GetMean();
3147 tmeane[ind][pk] = sumx / sum;
3148 tmeane_average[plane][pk] += tmeane[ind][pk];
3149 na++;
3150 if (ip == 18 && fdeb) {
3151 fprintf(fdeb, "Mean: Chamber %d strip %d mpos %f ntmeane %d tmeane %f\n", ip, is, mpos,
3152 ncon, tmeane[ind][pk]);
3153 }
3154 } else {
3155 tmeane[ind][pk] = 0.;
3156 if (ip == 18 && fdeb) {
3157 fprintf(fdeb, "Zero: Chamber %d strip %d tmeane %f\n", ip, is, tmeane[ind][pk]);
3158 }
3159 }
3160 } else {
3161 if (proj->GetEntries()) {
3162 // tmeane[ind][pk] = proj->GetMean();
3163 tmeane[ind][pk] = 0.;
3164 // tmeane_average[plane][pk] += tmeane[ind][pk];
3165 // na++;
3166 } else {
3167 tmeane[ind][pk] = 0.;
3168 }
3169 if (ip == 18 && fdeb) {
3170 fprintf(fdeb, "Mean: Chamber %d strip %d ntmean %d tmeane %f\n", ip, is, ncon, tmeane[ind][pk]);
3171 }
3172 }
3173
3174 // proj->Draw();
3175 // gPad->WaitPrimitive();
3176 // getchar();
3177 // printf("!! ip %d is %d nt %d t %f na %d\n",ip,is,ntmeane[ind],tmeane[ind],na);
3178 delete proj;
3179 } // loop on strips
3180 if (na)
3181 tmeane_average[plane][pk] /= (float)na;
3182 fprintf(fout, "Chamber #%d region %d channel offsets (average is %f)\n", plane + 1, pk + 1,
3183 tmeane_average[plane][pk]);
3185 LOGF(info, "Chamber #%d region %d channel offsets (average is %f)", plane + 1, pk + 1,
3186 tmeane_average[plane][pk]);
3187 for (int ind = 0; ind < n_rec; ind++) {
3188 if (mapa[ind].pair < 0)
3189 continue;
3190 ip = mapa[ind].plane;
3191 if (ip != plane)
3192 continue;
3193 is = mapa[ind].strip;
3194 if (TOZERO) {
3195 fprintf(fout, " strip %d time shift (left+right)/2 = %f\n", is, tmeane[ind][pk]);
3197 LOGF(info, " strip %d time shift (left+right)/2 = %f", is, tmeane[ind][pk]);
3198 // Toffsetsf[pk]->SetBinContent(Toffsetsf[pk]->FindBin(ind), tmeane[ind][pk]);
3199 Toffsetsf[pk]->Fill(ind, tmeane[ind][pk]);
3200 } else {
3201 if (tmeane[ind][pk] == 0.)
3202 tmeane[ind][pk] = tmeane_average[plane][pk];
3203 fprintf(fout, " strip %d time shift (left+right)/2 = %f\n", is,
3204 tmeane[ind][pk] - tmeane_average[plane][pk]);
3206 LOGF(info, " strip %d time shift (left+right)/2 = %f", is,
3207 tmeane[ind][pk] - tmeane_average[plane][pk]);
3208 // Toffsetsf[pk]->SetBinContent(Toffsetsf[pk]->FindBin(ind),
3209 // tmeane[ind][pk]-tmeane_average[plane][pk]);
3210 Toffsetsf[pk]->Fill(ind, tmeane[ind][pk] - tmeane_average[plane][pk]);
3211 }
3212 } // loop on strips
3213
3214 } // loop on peaks
3215
3216 } // loop on chambers
3217
3218 fclose(fout);
3219 if (fdeb)
3220 fclose(fdeb);
3221
3222 if (fSlewing) {
3223 fSlewing->Write(0, TObject::kOverwrite);
3224 fSlewing->Close();
3225 fSlewing = 0;
3226 }
3227
3228 return;
3229}
3230
3232{
3234 return;
3235 float tmeane_average[TOF2_MAX_CHAMBERS] = {0.};
3236 float tmeane[TOF2_MAX_CHANNEL] = {0.};
3237 TH1D *proj = 0, *hmain = 0;
3238 // TF1 *gr = 0;
3239 char namp[64], namf[64];
3240 int ncon = 0;
3241 double mpos = 0.;
3242 FILE* fout = 0;
3243 FILE* fdeb = 0;
3244 TString dir = getenv("VMCWORKDIR");
3245 TString path = dir + "/parameters/tof2_slewing/";
3246 char filn[512];
3247 sprintf(filn, "%s%s", path.Data(), filname_base);
3248 strcat(filn, ".equalization0.log");
3249 fout = fopen(filn, "w");
3250 if (DEBUG_EQUALIZATION0) {
3251 sprintf(filn, "%s%s", path.Data(), filname_base);
3252 strcat(filn, ".equalization0.debug");
3253 fdeb = fopen(filn, "w");
3254 }
3255 for (int plane = 0; plane < MaxPlane; plane++) {
3257 printf("**************** %s Chamber %d primary equalization ******************************\n", filname_base,
3258 plane + 1);
3259 fprintf(fout, "**************** %s Chamber %d primary equalization *******************************\n\n",
3260 filname_base, plane + 1);
3261
3262 int ip, is;
3263 int na = 0;
3264 tmeane_average[plane] = 0.;
3265
3266 // Select working area around main time peak for current chamber
3267 int im, y, bymin, bymax;
3268 float ymin, ymax;
3269 im = (hmain = (TvsS[plane]->ProjectionY("lims")))->GetMaximumBin();
3270 y = (int)(hmain->GetBinCenter(im));
3271 ymin = y - 60;
3272 ymax = y + 60;
3273
3274 for (int ind = 0; ind < n_rec; ind++) {
3275 if (mapa[ind].pair < 0)
3276 continue;
3277 ip = mapa[ind].plane;
3278 if (ip != plane)
3279 continue;
3280 is = mapa[ind].strip;
3281 // printf("** ip %d is %d nt %d t %f\n",ip,is,ntmeane[ind][pk],tmeane[ind][pk]);
3282 sprintf(namp, "Maxima_chamber_%d_strip_%d_equalization0", ip + 1, is + 1);
3283 proj = TvsS[ip]->ProjectionY(namp, is + 1, is + 1);
3284 if (EQUAL_MAXIMA0) {
3285 int nbin = proj->GetNbinsX();
3286 // reset bins outside main peak area
3287 bymin = (int)(proj->FindBin(ymin));
3288 bymax = (int)(proj->FindBin(ymax));
3289 for (int ib = 1; ib <= nbin; ib++)
3290 if (ib <= bymin || ib >= bymax)
3291 proj->SetBinContent(ib, 0);
3292 //
3293 int mbin = proj->GetMaximumBin();
3294 mpos = proj->GetBinCenter(mbin);
3295 ncon = proj->GetBinContent(mbin);
3296 // printf("Chamber %d strip %d max %d at %f\n", ip,is,ncon,mpos);
3297 if (ncon > 50) {
3298 int nonzero = 0;
3299 int zflag = 0;
3300 double sum = 0., sumx = 0.;
3301 for (int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin); ib++)
3302 {
3303 if (proj->GetBinContent(ib) > 0.) {
3304 nonzero++;
3305 sum += proj->GetBinContent(ib);
3306 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(ib);
3307 } else {
3308 zflag = 1;
3309 }
3310 }
3311 if (FIT_MAXIMA0 && zflag == 0 && nonzero >= 5) {
3312 sprintf(namf, "gaus%dstrip%d", ip + 1, is + 1);
3313 // if (gr) delete gr;
3314 // gr = new TF1(namf,"gaus",mpos-6.,mpos+6.);
3315 proj->Fit(namf, "QR0");
3316 if (!(proj->GetFunction(namf))) {
3317 // tmeane[ind] = mpos;
3318 tmeane[ind] = sumx / sum;
3319 if (ip == 18 && fdeb) {
3320 fprintf(fdeb, "Max: Chamber %d strip %d zflag %d nonzero %d mpos %f tmeane %f\n", ip,
3321 is, zflag, nonzero, mpos, tmeane[ind]);
3322 }
3323 } else {
3324 tmeane[ind] = proj->GetFunction(namf)->GetParameter(1);
3325 if (ip == 18 && fdeb) {
3326 fprintf(fdeb, "Fit: Chamber %d strip %d zflag %d nonzero %d mpos %f tmeane %f\n", ip,
3327 is, zflag, nonzero, mpos, tmeane[ind]);
3328 }
3329 }
3330 } else {
3331 // tmeane[ind] = mpos;
3332 tmeane[ind] = sumx / sum;
3333 if (ip == 18 && fdeb) {
3334 fprintf(fdeb, "Max: Chamber %d strip %d zflag %d nonzero %d mpos %f tmeane %f\n", ip, is,
3335 zflag, nonzero, mpos, tmeane[ind]);
3336 }
3337 }
3338 tmeane_average[plane] += tmeane[ind];
3339 na++;
3340 } else if (ncon > 0) {
3341 double sum = 0., sumx = 0.;
3342 for (int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin); ib++)
3343 {
3344 if (proj->GetBinContent(ib) > 0.) {
3345 sum += proj->GetBinContent(ib);
3346 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(ib);
3347 }
3348 }
3349 // tmeane[ind] = proj->GetMean();
3350 tmeane[ind] = sumx / sum;
3351 tmeane_average[plane] += tmeane[ind];
3352 na++;
3353 if (ip == 18 && fdeb) {
3354 fprintf(fdeb, "Mean: Chamber %d strip %d mpos %f ncon %d tmeane %f\n", ip, is, mpos, ncon,
3355 tmeane[ind]);
3356 }
3357 } else {
3358 tmeane[ind] = 0.;
3359 // na++;
3360 if (ip == 18 && fdeb) {
3361 fprintf(fdeb, "Zero: Chamber %d strip %d tmeane %f\n", ip, is, tmeane[ind]);
3362 }
3363 }
3364 } else {
3365 if (proj->GetEntries()) {
3366 // tmeane[ind] = proj->GetMean();
3367 tmeane[ind] = 0.;
3368 // tmeane_average[plane] += tmeane[ind];
3369 // na++;
3370 } else {
3371 tmeane[ind] = 0.;
3372 }
3373 if (ip == 18 && fdeb) {
3374 fprintf(fdeb, "Mean: Chamber %d strip %d ncon %d tmeane %f\n", ip, is, ncon, tmeane[ind]);
3375 }
3376 }
3377 // proj->Draw();
3378 // gPad->WaitPrimitive();
3379 // getchar();
3380 // printf("!! ip %d is %d t %f na %d\n",ip,is,tmeane[ind],na);
3381 } // loop on strips
3382 if (na)
3383 tmeane_average[plane] /= (float)na;
3384 fprintf(fout, "Chamber #%d preliminary channel offsets (average is %f)\n", plane + 1, tmeane_average[plane]);
3386 LOGF(info, "Chamber #%d preliminary channel offsets (average is %f)", plane + 1, tmeane_average[plane]);
3387 for (int ind = 0; ind < n_rec; ind++) {
3388 if (mapa[ind].pair < 0)
3389 continue;
3390 ip = mapa[ind].plane;
3391 if (ip != plane)
3392 continue;
3393 is = mapa[ind].strip;
3394 if (tmeane[ind] == 0.)
3395 tmeane[ind] = tmeane_average[plane];
3396 fprintf(fout, " strip %d time shift (left+right)/2 = %f\n", is, tmeane[ind] - tmeane_average[plane]);
3398 LOGF(info, " strip %d time shift (left+right)/2 = %f", is, tmeane[ind] - tmeane_average[plane]);
3399 Toffsets0->Fill(ind, tmeane[ind] - tmeane_average[plane]);
3400 }
3401
3402 } // loop on chambers
3403
3404 fclose(fout);
3405 if (fdeb)
3406 fclose(fdeb);
3407
3408 return;
3409}
3410
3412{
3413 for (int c = 0; c < TOF2_MAX_CRATES; c++) {
3414 for (int s = 0; s < TOF2_MAX_SLOTS_IN_CRATE; s++) {
3415 if (dnltype[c][s] == 1) {
3416 float tcor, ecor;
3417 int n, pos;
3418 char atext[50];
3419 ifstream fi(dnlname[c][s]);
3420 if (fi.is_open()) {
3421 for (n = 0; n < TOF2_MAX_CHANNELS_IN_SLOT; n++) {
3422 for (int i = 0; i < 1024; i++) {
3423 fi.getline(atext, 50);
3424 sscanf(atext, "%d %f %f\n", &pos, &tcor, &ecor);
3425 DNL_Table[c][s][n][i] = tcor;
3426 }
3427 }
3428 fi.close();
3429 }
3430 } else if (dnltype[c][s] % 10 == 0) {
3431 float tcor;
3432 int n, pos, post;
3433 char atext[25600];
3434 ifstream fi(dnlname[c][s]);
3435 if (fi.is_open()) {
3436 n = 0;
3437 while (!fi.eof()) {
3438 fi.getline(atext, 25600);
3439 post = 0;
3440 pos = 0;
3441 for (int i = 0; i < 1024; i++) {
3442 sscanf(&atext[post], "%f %n", &tcor, &pos);
3443 post += pos;
3444 DNL_Table[c][s][n][i] = tcor;
3445 }
3446 // fi.getline(atext,25600);
3447 n++;
3448 if (n == 72)
3449 break;
3450 }
3451 fi.close();
3452 }
3453 } else if (dnltype[c][s] == 2) {
3454 float tcor;
3455 int n, pos, post;
3456 char atext[25600];
3457 ifstream fi(dnlname[c][s]);
3458 if (fi.is_open()) {
3459 n = 0;
3460 while (!fi.eof()) {
3461 fi.getline(atext, 25600);
3462 post = 0;
3463 pos = 0;
3464 for (int i = 0; i < 1024; i++) {
3465 sscanf(&atext[post], "%f %n", &tcor, &pos);
3466 post += pos;
3467 DNL_Table[c][s][n][i] = tcor;
3468 }
3469 fi.getline(atext, 25600);
3470 n++;
3472 break;
3473 }
3474 fi.close();
3475 }
3476 } else if (dnltype[c][s] == 3) {
3477 float tcor;
3478 int n, pos, post, ch, nerr = 0;
3479 char atext[25600];
3480 ifstream fi(dnlname[c][s]);
3481 if (fi.is_open()) {
3482 n = 0;
3483 fi.getline(atext, 25600);
3484 fi.getline(atext, 25600);
3485 int getfirst = 1;
3486 if (strstr(atext, "temp") == NULL)
3487 getfirst = 0;
3488 while (!fi.eof()) {
3489 if (getfirst)
3490 fi.getline(atext, 25600);
3491 getfirst = 1;
3492 post = 0;
3493 pos = 0;
3494 sscanf(&atext[post], "%d= %n", &ch, &pos);
3495 post += pos;
3496 if (ch != n && 0) {
3497 if (nerr < 2) {
3498 LOGF(error, "Crate %d Slot %d Wrong line in %s file, channel %d != %d !", c, s,
3499 dnlname[c][s], n, ch);
3500 }
3501 nerr++;
3502 }
3503 for (int i = 0; i < 1024; i++) {
3504 sscanf(&atext[post], "%f, %n", &tcor, &pos);
3505 post += pos;
3506 DNL_Table[c][s][n][i] = tcor;
3507 }
3508 // fi.getline(atext,25600);
3509 n++;
3511 break;
3512 }
3513 fi.close();
3514 }
3515 } else if (dnltype[c][s] == 4) // fake
3516 {
3517 float tcor /*, ecor*/;
3518 int n /*, pos*/;
3519 char atext[50];
3520 ifstream fi(dnlname[c][s]);
3521 if (fi.is_open()) {
3522 for (n = 0; n < TOF2_MAX_CHANNELS_IN_SLOT; n++) {
3523 for (int i = 0; i < 1024; i++) {
3524 fi.getline(atext, 50);
3525 sscanf(atext, "%f\n", &tcor);
3526 DNL_Table[c][s][n][i] = tcor;
3527 }
3528 }
3529 fi.close();
3530 }
3531 } else if (dnltype[c][s] == 5) {
3532 float tcor;
3533 int n, pos, post, ch, nerr = 0;
3534 char atext[25600];
3535 ifstream fi(dnlname[c][s]);
3536 if (fi.is_open()) {
3537 n = 0;
3538 fi.getline(atext, 25600);
3539 fi.getline(atext, 25600);
3540 int getfirst = 1;
3541 if (strstr(atext, "temp") == NULL)
3542 getfirst = 0;
3543 while (!fi.eof()) {
3544 if (getfirst)
3545 fi.getline(atext, 25600);
3546 getfirst = 1;
3547 post = 0;
3548 pos = 0;
3549 sscanf(&atext[post], "%d= %n", &ch, &pos);
3550 post += pos;
3551 if (ch != n) {
3552 if (nerr < 2) {
3553 LOGF(error, "Crate %d Slot %d Wrong line in %s file, channel %d != %d !", c, s,
3554 dnlname[c][s], n, ch);
3555 }
3556 nerr++;
3557 }
3558 for (int i = 0; i < 1024; i++) {
3559 sscanf(&atext[post], "%f, %n", &tcor, &pos);
3560 post += pos;
3561 DNL_Table[c][s][n][i] = tcor;
3562 }
3563 // fi.getline(atext,25600);
3564 n++;
3565 if (n == 72)
3566 break;
3567 }
3568 fi.close();
3569 }
3570 }
3571 }
3572 }
3573}
3574
3575#if TOF2_MAX_CHAMBERS == 15
3576int champosn[TOF2_MAX_CHAMBERS] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
3577#else
3578#if TOF2_MAX_CHAMBERS == 24
3579int champosn[TOF2_MAX_CHAMBERS] = {17, 18, 3, 1, 19, 4, 23, 20, 5, 15, 21, 6,
3580 2, 22, 9, 10, 11, 12, 13, 14, 7, 8, 0, 16};
3581#else
3583#endif
3584#endif
3585
3587{
3588 TProfile* prof = 0;
3589 for (int it = 0; it < 2; it++) {
3590 for (int plane = 0; plane < MaxPlane; plane++) {
3591 for (int ir = 0; ir < 2; ir++) {
3592 prof = TvsWr[plane][ir];
3593 if (it == 0)
3594 prof = TvsWt0r[plane][ir];
3595 if (!prof)
3596 continue;
3597
3598 int nonzero = 0;
3599 for (int i = 1; i <= prof->GetNbinsX(); i++) {
3600 if (prof->GetBinContent(i) != 0) {
3601 nonzero++;
3602 if (prof->GetBinEntries(i) <= 4)
3603 prof->SetBinEntries(i, 0);
3604 }
3605 }
3606 if (nonzero >= 2) {
3607 prof->Fit("pol0", "Q0");
3608 if (prof->GetFunction("pol0"))
3609 (prof->GetFunction("pol0"))->ResetBit(TF1::kNotDraw);
3610 } else {
3611 LOGF(error, " Chamber %d slewing results (%d) - too few nonzero bins = %d", plane + 1, it, nonzero);
3612 }
3613
3614 } // loop on regions
3615 } // loop on chambers
3616 } // loop on T0 and RPC cases
3617
3618 return;
3619}
3620
3622{
3623 int NDX;
3624 int NDY;
3625 if (MaxPlane == 15) {
3626 int champos[] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
3627 NDX = 5;
3628 NDY = 3;
3629 memcpy(champosn, champos, sizeof champos);
3630 } else if (MaxPlane == 24) {
3631 int champos[] = {17, 18, 3, 1, 19, 4, 23, 20, 5, 15, 21, 6, 2, 22, 9, 10, 11, 12, 13, 14, 7, 8, 0, 16};
3632 NDX = 8;
3633 NDY = 3;
3634 memcpy(champosn, champos, sizeof champos);
3635 } else {
3636 int champos[TOF2_MAX_CHAMBERS] = {0};
3637 NDX = 6;
3638 NDY = 10;
3639 for (int ip = 0; ip < TOF2_MAX_CHAMBERS; ip++)
3640 champos[ip] = ip;
3641 memcpy(champosn, champos, sizeof champos);
3642 }
3643
3644 TLine* l = 0 /*, *l1 = 0*/;
3645 // FILE *fout = 0;
3646 int i, im, y;
3647 float ymin, ymax, xmin, xmax;
3648 TString dir = getenv("VMCWORKDIR");
3649 TString path = dir + "/parameters/tof2_slewing/";
3650 char filn[512];
3651 sprintf(filn, "%s%s_slewing_limits.txt", path.Data(), filname_base);
3652 // fout = fopen(filn,"w");
3653
3654 TCanvas* cp = new TCanvas("cp", "Leadings vs strip", 900, 700);
3655 cp->cd();
3656 cp->Divide(NDX, NDY);
3657 for (i = 0; i < MaxPlane; i++) {
3658 cp->cd(champosn[i] + 1);
3659 if (TvsS[i]->GetEntries() < 500)
3660 continue;
3661 TvsS[i]->Draw();
3662 gPad->AddExec("exselt", "select_hist()");
3663 im = (TvsS[i]->ProjectionY())->GetMaximumBin();
3664 y = (int)((TvsS[i]->ProjectionY())->GetBinCenter(im));
3665 ymin = y - 60;
3666 ymax = y + 60;
3667 xmin = (TvsS[i]->GetXaxis())->GetXmin();
3668 xmax = (TvsS[i]->GetXaxis())->GetXmax();
3669 l = new TLine(xmin, ymin, xmax, ymin);
3670 l->Draw();
3671 l->SetLineColor(kRed);
3672 l = new TLine(xmin, ymax, xmax, ymax);
3673 l->Draw();
3674 l->SetLineColor(kRed);
3675 // fprintf(fout,"\t\tTOF2.SetLeadMinMax(%d, %d,%d);\n", i+1, (int)ymin, (int)ymax);
3676 // if (PRINT_TIME_LIMITS) printf("\t\tTOF2.SetLeadMinMax(%d, %d,%d);\n", i+1, (int)ymin, (int)ymax);
3677 }
3678 // fclose(fout);
3679
3680 TCanvas* cpp = new TCanvas("cpp", "Leadings", 900, 700);
3681 cpp->cd();
3682 cpp->Divide(NDX, NDY);
3683 for (i = 0; i < MaxPlane; i++) {
3684 cpp->cd(champosn[i] + 1);
3685 if (TvsS[i]->GetEntries() < 500)
3686 continue;
3687 im = (TvsS[i]->ProjectionY())->GetMaximumBin();
3688 y = (int)((TvsS[i]->ProjectionY())->GetBinCenter(im));
3689 ymin = y - 60;
3690 ymax = y + 60;
3691 xmin = 0;
3692 xmax = (TvsS[i]->ProjectionY())->GetMaximum();
3693 TvsS[i]->ProjectionY(strcat(strcpy(filn, TvsS[i]->GetName()), "_y"), 1, 32, "D");
3694 gPad->AddExec("exselt", "select_hist()");
3695 l = new TLine(ymin, xmin, ymin, xmax);
3696 l->Draw();
3697 l->SetLineColor(kRed);
3698 l = new TLine(ymax, xmin, ymax, xmax);
3699 l->Draw();
3700 l->SetLineColor(kRed);
3701 }
3702
3703 TCanvas* cpw = new TCanvas("cpw", "Widths vs strip", 900, 700);
3704 cpw->cd();
3705 cpw->Divide(NDX, NDY);
3706 for (i = 0; i < MaxPlane; i++) {
3707 cpw->cd(champosn[i] + 1);
3708 if (WvsS[i]->GetEntries() < 500)
3709 continue;
3710 WvsS[i]->Draw();
3711 gPad->AddExec("exselt", "select_hist()");
3712 ymin = Wcut;
3713 ymax = Wmax;
3714 xmin = (WvsS[i]->GetXaxis())->GetXmin();
3715 xmax = (WvsS[i]->GetXaxis())->GetXmax();
3716 l = new TLine(xmin, ymin, xmax, ymin);
3717 l->Draw();
3718 l->SetLineColor(kRed);
3719 l = new TLine(xmin, ymax, xmax, ymax);
3720 l->Draw();
3721 l->SetLineColor(kRed);
3722 }
3723
3724 TCanvas* cpwp = new TCanvas("cpwp", "Widths", 900, 700);
3725 cpwp->cd();
3726 cpwp->Divide(NDX, NDY);
3727 for (i = 0; i < MaxPlane; i++) {
3728 cpwp->cd(champosn[i] + 1);
3729 if (WvsS[i]->GetEntries() < 500)
3730 continue;
3731 ymin = Wcut;
3732 ymax = Wmax;
3733 xmin = 0;
3734 xmax = (WvsS[i]->ProjectionY())->GetMaximum();
3735 WvsS[i]->ProjectionY(strcat(strcpy(filn, WvsS[i]->GetName()), "_y"), 1, 32, "D");
3736 gPad->AddExec("exselt", "select_hist()");
3737 l = new TLine(ymin, xmin, ymin, xmax);
3738 l->Draw();
3739 l->SetLineColor(kRed);
3740 l = new TLine(ymax, xmin, ymax, xmax);
3741 l->Draw();
3742 l->SetLineColor(kRed);
3743 }
3744
3745 TCanvas* cpt0 = new TCanvas("cpt0", "T0 hists", 900, 700);
3746 cpt0->cd();
3747 cpt0->Divide(2, 2);
3748 cpt0->cd(1);
3749 Wt0->Draw();
3750 gPad->AddExec("exselt", "select_hist()");
3751 xmin = WT0min;
3752 xmax = WT0max;
3753 ymin = 0.;
3754 ymax = Wt0->GetMaximum();
3755 l = new TLine(xmin, ymin, xmin, ymax);
3756 l->Draw();
3757 l->SetLineColor(kRed);
3758 l = new TLine(xmax, ymin, xmax, ymax);
3759 l->Draw();
3760 l->SetLineColor(kRed);
3761 cpt0->cd(2);
3762 Wts->Draw();
3763 gPad->AddExec("exselt", "select_hist()");
3764 cpt0->cd(3);
3765 Lt0->Draw();
3766 gPad->AddExec("exselt", "select_hist()");
3767 cpt0->cd(4);
3768 Nhit->Draw();
3769 gPad->AddExec("exselt", "select_hist()");
3770
3771 if (1)
3772 return;
3773
3774 TCanvas* cp1 = new TCanvas("cp1", "Leadings vs widths", 900, 700);
3775 cp1->cd();
3776 cp1->Divide(NDX, NDY);
3777 for (i = 0; i < MaxPlane; i++) {
3778 cp1->cd(champosn[i] + 1);
3779 TvsWall[i]->Draw();
3780 gPad->AddExec("exselt", "select_hist()");
3781 }
3782
3783 TCanvas* cp2 = new TCanvas("cp2", "Leadings vs widths (max strip)", 900, 700);
3784
3785 cp2->cd();
3786 cp2->Divide(NDX, NDY);
3787 for (i = 0; i < MaxPlane; i++) {
3788 cp2->cd(champosn[i] + 1);
3789 TvsWallmax[i]->Draw();
3790 gPad->AddExec("exselt", "select_hist()");
3791 }
3792 return;
3793}
3794
3796{
3797 int NDX;
3798 int NDY;
3799 if (MaxPlane == 15) {
3800 int champos[] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
3801 NDX = 5;
3802 NDY = 3;
3803 memcpy(champosn, champos, sizeof champos);
3804 } else if (MaxPlane == 24) {
3805 int champos[] = {17, 18, 3, 1, 19, 4, 23, 20, 5, 15, 21, 6, 2, 22, 9, 10, 11, 12, 13, 14, 7, 8, 0, 16};
3806 NDX = 8;
3807 NDY = 3;
3808 memcpy(champosn, champos, sizeof champos);
3809 } else {
3810 int champos[TOF2_MAX_CHAMBERS] = {0};
3811 NDX = 6;
3812 NDY = 10;
3813 for (int ip = 0; ip < TOF2_MAX_CHAMBERS; ip++)
3814 champos[ip] = ip;
3815 memcpy(champosn, champos, sizeof champos);
3816 }
3817
3818 TCanvas* callbe = new TCanvas("callbe", "Leadings vs widths (slewing RPC, peak 1)", 900, 700);
3819
3820 int i;
3821 callbe->cd();
3822 callbe->Divide(NDX, NDY);
3823 for (i = 0; i < MaxPlane; i++) {
3824 callbe->cd(champosn[i] + 1);
3825 TvsW[i][0]->Draw();
3826 gPad->AddExec("exselt", "select_hist()");
3827 }
3828
3829 TCanvas* callbe1 = new TCanvas("callbe1", "Leadings vs widths (slewing RPC, peak 2)", 900, 700);
3830 callbe1->cd();
3831 callbe1->Divide(NDX, NDY);
3832 for (i = 0; i < MaxPlane; i++) {
3833 callbe1->cd(champosn[i] + 1);
3834 TvsW[i][1]->Draw();
3835 gPad->AddExec("exselt", "select_hist()");
3836 }
3837
3838 return;
3839}
3840
3842{
3843 int NDX;
3844 int NDY;
3845 if (MaxPlane == 15) {
3846 int champos[] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
3847 NDX = 5;
3848 NDY = 3;
3849 memcpy(champosn, champos, sizeof champos);
3850 } else if (MaxPlane == 24) {
3851 int champos[] = {17, 18, 3, 1, 19, 4, 23, 20, 5, 15, 21, 6, 2, 22, 9, 10, 11, 12, 13, 14, 7, 8, 0, 16};
3852 NDX = 8;
3853 NDY = 3;
3854 memcpy(champosn, champos, sizeof champos);
3855 } else {
3856 int champos[TOF2_MAX_CHAMBERS] = {0};
3857 NDX = 6;
3858 NDY = 10;
3859 for (int ip = 0; ip < TOF2_MAX_CHAMBERS; ip++)
3860 champos[ip] = ip;
3861 memcpy(champosn, champos, sizeof champos);
3862 }
3863
3864 TCanvas* callbe0 = new TCanvas("callbe0", "Leadings vs widths (slewing T0, peak 1)", 900, 700);
3865 int i;
3866 callbe0->cd();
3867 callbe0->Divide(NDX, NDY);
3868 for (i = 0; i < MaxPlane; i++) {
3869 callbe0->cd(champosn[i] + 1);
3870 TvsWt0[i][0]->Draw();
3871 gPad->AddExec("exselt", "select_hist()");
3872 }
3873
3874 TCanvas* callbe01 = new TCanvas("callbe01", "Leadings vs widths (slewing T0, peak 2)", 900, 700);
3875 callbe01->cd();
3876 callbe01->Divide(NDX, NDY);
3877 for (i = 0; i < MaxPlane; i++) {
3878 callbe01->cd(champosn[i] + 1);
3879 TvsWt0[i][1]->Draw();
3880 gPad->AddExec("exselt", "select_hist()");
3881 }
3882 return;
3883}
3884
3885int BmnTof2Raw2DigitNew::readGeom(const char* geomfile)
3886{
3887 const char* fname;
3888 char line1[128];
3889 FILE* fg = 0;
3890 float ic = 0;
3891 int nf = 0, n = 0, i, is8 = 0;
3892 float step, sx, sy, x, y, z;
3893 if (strlen(geomfile) == 0) {
3894 LOGF(error, "TOF700 geometry file name not defined!");
3895 return 0;
3896 }
3897 if (strstr(geomfile, "_run8"))
3898 is8 = 1;
3899 if (is8 == 1 && fPeriod < 8) {
3900 LOGF(error, "Geometry file for period 8, but init for period %d !", fPeriod);
3901 return 0;
3902 } else if (is8 == 0 && fPeriod == 8) {
3903 LOGF(error, "Geometry file for early period (%s), but init for period 8 !", geomfile);
3904 return 0;
3905 };
3906 TString dir = TString::Format("%s/geometry/%s", getenv("VMCWORKDIR"), geomfile);
3907 fname = dir.Data();
3908 fg = fopen(fname, "r");
3909 if (fg == NULL) {
3910 LOGF(error, "TOF700 geometry file %s open error!", fname);
3911 return 0;
3912 }
3913 if (!fgets(line1, sizeof(line1), fg)) {
3914 LOGF(error, "TOF700 geometry file %s - first line read error!", fname);
3915 return 0;
3916 };
3917 if (is8 == 0)
3918 if (sscanf(line1, "%f %f %f\n", &xoffs, &yoffs, &zoffs) != 3) {
3919 LOGF(error, "Wrong first line (not 3 numbers) in TOF700 geometry file %s", fname);
3920 return 0;
3921 }
3922 xoffs2 = xoffs;
3923 if (is8 == 1)
3924 if (sscanf(line1, "%f %f %f %f\n", &xoffs, &xoffs2, &yoffs, &zoffs) != 4) {
3925 LOGF(error, "Wrong first line (not 4 numbers) in TOF700 geometry file %s", fname);
3926 return 0;
3927 }
3928 LOGF(debug, "Loading TOF700 geometry from file %s", geomfile);
3929 for (i = 0; i < MaxPlane; i++)
3930 nstrips[i] = 0;
3931 while (fscanf(fg, "%f %d %f %f %f %f %f %f\n", &ic, &n, &step, &sy, &sx, &x, &y, &z) == 8) {
3932 for (i = 0; i < MaxPlane; i++) {
3933 if (ic == idchambers[i])
3934 break;
3935 }
3936 if (i >= MaxPlane)
3937 continue;
3938 halfxwidth[i] = sx / 20.;
3939 halfywidth[i] = sy / 20.;
3940 zchamb[i] = z / 10. + zoffs;
3941 nstrips[i] = n;
3942 for (int ns = n - 1; ns >= 0; ns--) {
3943 if (z < 100.)
3944 xcens[i][ns] = -x / 10. + xoffs;
3945 else
3946 xcens[i][ns] = -x / 10. + xoffs2;
3947 ycens[i][ns] = y / 10. + yoffs - (n - ns - 1) * step / 10.;
3948 xmins[i][ns] = xcens[i][ns] - halfxwidth[i];
3949 xmaxs[i][ns] = xcens[i][ns] + halfxwidth[i];
3950 ymins[i][ns] = ycens[i][ns] - halfywidth[i];
3951 ymaxs[i][ns] = ycens[i][ns] + halfywidth[i];
3952 // LOGF(info,"C %d S %d %f %f %f %f
3953 // %f",ic,ns,zchamb[i],xmins[i][ns],xmaxs[i][ns],ymins[i][ns],ymaxs[i][ns]);
3954 }
3955 nf++;
3956 }
3957 /*int result = */ fclose(fg);
3958 if (nf == MaxPlane)
3959 return 1;
3960 else {
3961 LOGF(error, "Geometry for %d chambers only!", nf);
3962 return 0;
3963 }
3964}
3965
3966int BmnTof2Raw2DigitNew::get_strip_xyz(int chamber, int strip, float* x, float* y, float* z)
3967{
3968 if (chamber < MaxPlane) {
3969 *x = xcens[chamber][strip];
3970 *y = ycens[chamber][strip];
3971 *z = zchamb[chamber];
3972 return 1;
3973 } else
3974 return 0;
3975}
3976
3977int BmnTof2Raw2DigitNew::get_chamber_z(int chamber, float* z)
3978{
3979 if (chamber < MaxPlane) {
3980 *z = zchamb[chamber];
3981 return 1;
3982 } else
3983 return 0;
3984}
3985
3986int BmnTof2Raw2DigitNew::get_track_hits(float* xyz, float* cxyz, int* nhits, int* chamb, int* strip)
3987{
3988 int n = 0;
3989 float x, y /*, z*/;
3990 for (int j = 0; j < MaxPlane; j++) {
3991 x = xyz[0] + cxyz[0] * (zchamb[j] - xyz[2]);
3992 y = xyz[1] + cxyz[1] * (zchamb[j] - xyz[2]);
3993 for (int k = 0; k < nstrips[j]; k++) {
3994 if (x >= xmins[j][k] && x < xmaxs[j][k] && y >= ymins[j][k] && y < ymaxs[j][k]) {
3995 chamb[n] = j;
3996 strip[n] = k;
3997 n++;
3998 }
3999 }
4000 }
4001 *nhits = n;
4002 return n;
4003}
4004
4006{
4007 for (int j = 0; j < MaxPlane; j++) {
4008 LOGF(info, "Chamber %d (%.1f), number of strips %d, Z-coordinate %f, WidthX/2 %f, WidthY/2 %f", j + 1,
4009 idchambers[j], nstrips[j], zchamb[j], halfxwidth[j], halfywidth[j]);
4010 LOGF(info, " Upper strip X %f Y %f", xcens[j][nstrips[j] - 1], ycens[j][nstrips[j] - 1]);
4011 // for (int k=0; k<nstrips[j]; k++)
4012 // {
4013 // LOGF(info," Strip %d X %f Y %f", k+1, xcens[j][k],ycens[j][k]);
4014 // }
4015 }
4016 return 0;
4017}
4018
4020{
4021 const char* fname;
4022 FILE* fg = 0;
4023 // int i;
4024 if (strlen(offsetsfile) == 0) {
4025 LOGF(error, "TOF700 Left-Right offsets file name not defined!");
4026 return 0;
4027 }
4028 TString dir = TString::Format("%s/geometry/%s", getenv("VMCWORKDIR"), offsetsfile);
4029 fname = dir.Data();
4030 fg = fopen(fname, "r");
4031 if (fg == NULL) {
4032 LOGF(error, "TOF700 Left-Right offsets file %s open error!", fname);
4033 return 0;
4034 }
4035 LOGF(debug, "Loading TOF700 Left-Right offsets from file %s", offsetsfile);
4036 float idchamber, lroff;
4037 int ip, is, lrsig, n = 0;
4038 while (
4039 fscanf(fg, "Chamber %d (%f) strip %d offset %f time bins, direction %d\n", &ip, &idchamber, &is, &lroff, &lrsig)
4040 == 5)
4041 {
4042 if (ip >= MaxPlane) {
4043 LOGF(error, "L-R offsets: Chamber number %d >= %d, skip!", ip, MaxPlane);
4044 continue;
4045 }
4046 if (is >= TOF2_MAX_STRIPS_IN_CHAMBER) {
4047 LOGF(error, "L-R offsets: Strip number %d >= %d, skip!", is, TOF2_MAX_STRIPS_IN_CHAMBER);
4048 continue;
4049 }
4050 if (idchamber != idchambers[ip]) {
4051 LOGF(error, "L-R offsets: Chamber ID %.1f != %.1f, skip!", idchamber, idchambers[ip]);
4052 continue;
4053 }
4054 lroffsets[ip][is] = lroff;
4055 lrsign[ip][is] = lrsig;
4056 n++;
4057 }
4058 fclose(fg);
4059 LOGF(debug, "Read %d left-right offsets.", n);
4060 return 1;
4061}
4062
4063float BmnTof2Raw2DigitNew::get_hit_x0(int chamber, int strip, float diff)
4064{
4065 float x = 0., dx = 0.;
4066 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4067 dx = (diff + lroffsets[chamber][strip] * HPTIMEBIN) * fVelosity;
4068 x = xcens[chamber][strip] + lrsign[chamber][strip] * dx;
4069 return x;
4070 } else
4071 return 0.;
4072}
4073
4074float BmnTof2Raw2DigitNew::get_hit_x(int chamber, int strip, float diff_corrected)
4075{
4076 float x = 0., dx = 0.;
4077 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4078 dx = diff_corrected * fVelosity;
4079 x = xcens[chamber][strip] + lrsign[chamber][strip] * dx;
4080 return x;
4081 } else
4082 return 0.;
4083}
4084
4085float BmnTof2Raw2DigitNew::get_hit_diff0(int chamber, int strip, float diff)
4086{
4087 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER) {
4088 return (diff + lroffsets[chamber][strip] * HPTIMEBIN);
4089 } else
4090 return 0.;
4091}
4092
4093float BmnTof2Raw2DigitNew::get_hit_diff(int chamber, int strip, float diff_corrected)
4094{
4095 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER) {
4096 return diff_corrected;
4097 } else
4098 return 0.;
4099}
4100
4101void BmnTof2Raw2DigitNew::get_hit_xyz0(int chamber, int strip, float diff, float* x, float* y, float* z)
4102{
4103 float xh = 0., dxh = 0.;
4104 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4105 dxh = (diff + lroffsets[chamber][strip] * HPTIMEBIN) * fVelosity;
4106 xh = xcens[chamber][strip] + lrsign[chamber][strip] * dxh;
4107 *x = xh;
4108 *y = ycens[chamber][strip];
4109 *z = zchamb[chamber];
4110 return;
4111 } else
4112 return;
4113}
4114
4115void BmnTof2Raw2DigitNew::get_hit_xyz(int chamber, int strip, float diff_corrected, float* x, float* y, float* z)
4116{
4117 float xh = 0., dxh = 0.;
4118 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4119 dxh = diff_corrected * fVelosity;
4120 xh = xcens[chamber][strip] + lrsign[chamber][strip] * dxh;
4121 *x = xh;
4122 *y = ycens[chamber][strip];
4123 *z = zchamb[chamber];
4124 return;
4125 } else
4126 return;
4127}
4128
4129int BmnTof2Raw2DigitNew::readXYCalibration(char* xcalibrationfile, char* ycalibrationfile)
4130{
4131 const char* fname;
4132 FILE* fg = 0;
4133 // int i;
4134 float xoff, xslop, yoff, yslop, yofferr, ysloperr;
4135
4136 // X calibration
4137 if (strlen(xcalibrationfile) == 0) {
4138 LOGF(error, "TOF700 X calibration file name not defined!");
4139 return 0;
4140 }
4141 TString dir = TString::Format("%s/geometry/%s", getenv("VMCWORKDIR"), xcalibrationfile);
4142 fname = dir.Data();
4143 fg = fopen(fname, "r");
4144 if (fg == NULL) {
4145 LOGF(error, "TOF700 X calibration file %s open error!", fname);
4146 return 0;
4147 }
4148 LOGF(debug, "Loading TOF700 X calibration from file %s", xcalibrationfile);
4149 int ip, is, n = 0;
4150 while (fscanf(fg, "%d %d %f %f\n", &ip, &is, &xoff, &xslop) == 4) {
4151 if (ip >= MaxPlane) {
4152 LOGF(error, "X calibration: Chamber number %d >= %d, skip!", ip, MaxPlane);
4153 continue;
4154 }
4155 if (is >= TOF2_MAX_STRIPS_IN_CHAMBER) {
4156 LOGF(error, "X calibration: Strip number %d >= %d, skip!", is, TOF2_MAX_STRIPS_IN_CHAMBER);
4157 continue;
4158 }
4159 xoffset[ip][is] = xoff;
4160 xslope[ip][is] = xslop;
4161 n++;
4162 }
4163 fclose(fg);
4164 LOGF(debug, "Read X calibration for %d strips.", n);
4165 // Y calibration
4166 n = 0;
4167 if (strlen(ycalibrationfile) == 0) {
4168 LOGF(error, "TOF700 Y calibration file name not defined!");
4169 return 0;
4170 }
4171 dir = TString::Format("%s/geometry/%s", getenv("VMCWORKDIR"), ycalibrationfile);
4172 fname = dir.Data();
4173 fg = fopen(fname, "r");
4174 if (fg == NULL) {
4175 LOGF(error, "TOF700 Y calibration file %s open error!", fname);
4176 return 0;
4177 }
4178 LOGF(debug, "Loading TOF700 Y calibration from file %s", ycalibrationfile);
4179 while (fscanf(fg, "%d %f %f %f %f\n", &ip, &yoff, &yofferr, &yslop, &ysloperr) == 5) {
4180 if (ip >= MaxPlane) {
4181 LOGF(error, "Y calibration: Chamber number %d >= %d, skip!", ip, MaxPlane);
4182 continue;
4183 }
4184 yoffset[ip] = yoff;
4185 yslope[ip] = yslop;
4186 n++;
4187 }
4188 fclose(fg);
4189 LOGF(debug, "Read Y calibrations for %d chambers.", n);
4190
4191 return 1;
4192}
4193
4194int BmnTof2Raw2DigitNew::readXYCalibrationNew(char* xcalibrationfile, char* ycalibrationfile)
4195{
4196 FILE* fcalx = 0;
4197 FILE* fcaly = 0;
4198 char fname_calibr[128];
4199 TString dir = getenv("VMCWORKDIR");
4200 sprintf(fname_calibr, "%s/geometry/%s", dir.Data(), xcalibrationfile);
4201 fcalx = fopen(fname_calibr, "r");
4202 if (fcalx == NULL) {
4203 LOGF(error, "File %s open error!\n", fname_calibr);
4204 return 0;
4205 }
4206 sprintf(fname_calibr, "%s/geometry/%s", dir.Data(), ycalibrationfile);
4207 fcaly = fopen(fname_calibr, "r");
4208 if (fcaly == NULL) {
4209 LOGF(error, "File %s open error!\n", fname_calibr);
4210 return 0;
4211 }
4212 //
4213 Int_t nx = 0, ny = 0, ip = 0, is = 0;
4214 while (fscanf(fcalx, " l %d %d %f %f\n", &ip, &is, &interxl[ip][is], &slopexl[ip][is]) == 4) {
4215 fscanf(fcalx, " g %d %d %f %f\n", &ip, &is, &interxg[ip][is], &slopexg[ip][is]);
4216 nx++;
4217 };
4218 while (fscanf(fcaly, " %d %d %f\n", &ip, &is, &shifty[ip][is]) == 3) {
4219 ny++;
4220 };
4221 //
4222 LOGF(debug, " Read TOF700 X calibration parameters - %d strips", nx);
4223 LOGF(debug, " Read TOF700 Y calibration parameters - %d strips", ny);
4224 if (fcalx)
4225 fclose(fcalx);
4226 if (fcaly)
4227 fclose(fcaly);
4228 return nx;
4229}
4230
4231float BmnTof2Raw2DigitNew::get_hit_xp(int chamber, int strip, float diff)
4232{
4233 float x = 0. /*, dx = 0.*/;
4234 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && xslope[chamber][strip] != 0.) {
4235 x = xoffset[chamber][strip] + xslope[chamber][strip] * (diff - lroffsets[chamber][strip] * HPTIMEBIN) / 2.;
4236 return x;
4237 } else
4238 return 0.;
4239}
4240
4241void BmnTof2Raw2DigitNew::get_hit_xyzp(int chamber, int strip, float diff, float* x, float* y, float* z)
4242{
4243 float xh = 0., yh = 0.;
4244 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && xslope[chamber][strip] != 0.
4245 && yslope[chamber] != 0.)
4246 {
4247 xh = xoffset[chamber][strip] + xslope[chamber][strip] * (diff - lroffsets[chamber][strip] * HPTIMEBIN) / 2.;
4248 yh = yoffset[chamber] + yslope[chamber] * ycens[chamber][strip];
4249 *x = xh;
4250 *y = yh;
4251 *z = zchamb[chamber];
4252 return;
4253 } else {
4254 *x = 0.;
4255 *y = 0.;
4256 *z = 0.;
4257 return;
4258 }
4259}
4260
4261float BmnTof2Raw2DigitNew::get_hit_xng(int chamber, int strip, float diff)
4262{
4263 float x = 0. /*, dx = 0.*/;
4264 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fabs(slopexg[chamber][strip]) > 7.f) {
4265 x = interxg[chamber][strip] + slopexg[chamber][strip] * diff;
4266 return x;
4267 } else
4268 return 0.;
4269}
4270
4271void BmnTof2Raw2DigitNew::get_hit_xyzng(int chamber, int strip, float diff, float* x, float* y, float* z)
4272{
4273 float xh = 0., yh = 0.;
4274 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fabs(slopexg[chamber][strip]) > 7.f
4275 && shifty[chamber][strip] != 0.)
4276 {
4277 xh = interxg[chamber][strip] + slopexg[chamber][strip] * diff;
4278 yh = shifty[chamber][strip] + ycens[chamber][strip];
4279 *x = xh;
4280 *y = yh;
4281 *z = zchamb[chamber];
4282 return;
4283 } else {
4284 *x = 0.;
4285 *y = 0.;
4286 *z = 0.;
4287 return;
4288 }
4289}
4290
4291float BmnTof2Raw2DigitNew::get_hit_xnl(int chamber, int strip, float diff)
4292{
4293 float x = 0. /*, dx = 0.*/;
4294 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fabs(slopexl[chamber][strip]) > 7.f) {
4295 x = interxl[chamber][strip] + slopexl[chamber][strip] * diff + xcens[chamber][strip];
4296 return x;
4297 } else
4298 return 0.;
4299}
4300
4301void BmnTof2Raw2DigitNew::get_hit_xyznl(int chamber, int strip, float diff, float* x, float* y, float* z)
4302{
4303 float xh = 0., yh = 0.;
4304 if (chamber < MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fabs(slopexl[chamber][strip]) > 7.f
4305 && shifty[chamber][strip] != 0.)
4306 {
4307 xh = interxl[chamber][strip] + slopexl[chamber][strip] * diff + xcens[chamber][strip];
4308 yh = shifty[chamber][strip] + ycens[chamber][strip];
4309 *x = xh;
4310 *y = yh;
4311 *z = zchamb[chamber];
4312 return;
4313 } else {
4314 *x = 0.;
4315 *y = 0.;
4316 *z = 0.;
4317 return;
4318 }
4319}
4320
4321int BmnTof2Raw2DigitNew::get_ch_tdc32vl(unsigned int tdc, unsigned int ch)
4322{
4323 const int tdc32vl_tdcid2tdcnum[16] = {-1, 0, 1, -1, 3, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1};
4324 const int tdc32vl_tdcch2ch[32] = {7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4,
4325 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0};
4326 return tdc32vl_tdcid2tdcnum[tdc] * 8 + tdc32vl_tdcch2ch[ch % 32];
4327};
4328int BmnTof2Raw2DigitNew::get_ch_tdc64vhle(unsigned int tdc, unsigned int ch)
4329{
4330 const int tdc64vhle_tdcid2tdcnum[16] = {0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1};
4331 const int tdc64vhle_tdcch2ch[32] = {7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4,
4332 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0};
4333 return tdc64vhle_tdcid2tdcnum[tdc] * 8 + 7 - tdc64vhle_tdcch2ch[ch % 32];
4334};
4335int BmnTof2Raw2DigitNew::get_ch_tdc72vhl(unsigned int tdc, unsigned int ch)
4336{
4337 const int tdc72vhl_tdcid2tdcnum[16] = {2, 1, 0, 5, 4, 3, 8, 7, 6, -1, -1, -1, -1, -1, -1, -1};
4338 const int tdc72vhl_tdcch2ch[32] = {7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4,
4339 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0};
4340 return tdc72vhl_tdcid2tdcnum[tdc] * 8 + tdc72vhl_tdcch2ch[ch % 32];
4341}
vector< Double_t > W(vector< Double_t > dist, Double_t sig)
Definition BmnMath.cxx:878
#define FITI
#define USE_FIT_SLEWING
#define ITERATIONS0
#define MAX_RAW_TRAILING_TIME
#define SKIP_SIDES
#define MIN_RAW_LEADING_TIME
#define DRAW_GOOD
#define SMOOTH
#define MAX_RAW_T0_TIME
#define DEBUG_EQUALIZATION
#define PRINT_EQUALIZATION_RESULTS
#define FIT_SLEWING
#define SUBDEG
#define PRELIMINARY_OFFSETS
#define PRINT_FIT_RESULTS
#define FINAL_OFFSETS
const UInt_t kTDC64VHLE_E
#define TIME_LIMITS_VS_WIDTH
#define USE_PRELIMINARY_OFFSETS
const UInt_t kTDC32VL
#define FIT_MAXIMA0
#define EQUAL_MAXIMA
#define FIT_MAXIMA
#define FIT
#define ITERATIONS
int champosn[TOF2_MAX_CHAMBERS]
#define CHECK_SLEWING
#define PRINT_EQUALIZATION0_RESULTS
#define SUBRANGES
#define MIN_RAW_TRAILING_TIME
#define PRINT_TIME_LIMITS
#define MAX_RAW_LEADING_TIME
#define MIN_FIT_ENTRIES
#define EQUAL_MAXIMA0
#define DRAW_BAD
#define TOZERO
#define USE_FINAL_OFFSETS
#define LIMITS_ROOT_FILE
const UInt_t kTDC64VHLE
const UInt_t kTDC72VHL
#define MAX_FIT_ATTEMPTS
#define DEBUG_EQUALIZATION0
#define MAX_STRIP
#define FITI0
#define INVHPTIMEBIN
#define TOF2_MAX_STRIPS_IN_CHAMBER
#define TOF2_MAX_CHANNEL
#define NSLFIT0
#define TOF2_MAX_CHAMBERS
#define TOF2_MAX_SLOTS_IN_CRATE
#define TOF2_MAX_CRATES
#define TOF2_MAX_CHANNELS_IN_SLOT
#define NSLFIT
#define HPTIMEBIN
void memset(T *dest, T i, size_t num)
uses binary expansion of copied volume for speed up
Definition L1Grid.h:25
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
float f
Definition P4_F32vec4.h:21
const uint32_t kTDC64VHLE
Definition RawTypes.h:46
const uint32_t kTDC32VL
Definition RawTypes.h:49
const uint32_t kTDC64VHLE_E
Definition RawTypes.h:47
UInt_t GetValue() const
Definition BmnTDCDigit.h:32
UInt_t GetSerial() const
Definition BmnTDCDigit.h:22
UChar_t GetHptdcId() const
Definition BmnTDCDigit.h:34
UChar_t GetSlot() const
Definition BmnTDCDigit.h:26
UChar_t GetChannel() const
Definition BmnTDCDigit.h:30
UChar_t GetType() const
Definition BmnTDCDigit.h:24
Bool_t GetLeading() const
Definition BmnTDCDigit.h:28
void fillEvent(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width, TClonesArray *tof2digit)
void getEventInfo(long long *ev, long long *t1, long long *t2)
float get_hit_diff(int chamber, int strip, float diff_corrected)
int readXYCalibrationNew(char *xcalibration, char *ycalibration)
int readXYCalibration(char *xcalibration, char *ycalibration)
int readGeom(const char *geomFile)
void get_hit_xyzp(int chamber, int strip, float diff, float *x, float *y, float *z)
void readSlewing(Bool_t update=false)
int get_strip_xyz(int chamber, int strip, float *x, float *y, float *z)
float get_hit_xp(int chamber, int strip, float diff)
int get_ch_tdc72vhl(unsigned int tdc, unsigned int ch)
void fillSlewing(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
float get_hit_diff0(int chamber, int strip, float diff)
float get_hit_xnl(int chamber, int strip, float diff)
void get_hit_xyz0(int chamber, int strip, float diff, float *x, float *y, float *z)
int get_ch_tdc64vhle(unsigned int tdc, unsigned int ch)
int get_ch_tdc32vl(unsigned int tdc, unsigned int ch)
int readLRoffsets(char *LRoffsetsFile)
float get_hit_x(int chamber, int strip, float diff_corrected)
void get_hit_xyzng(int chamber, int strip, float diff, float *x, float *y, float *z)
void fillEqualization(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
float get_hit_x0(int chamber, int strip, float diff)
void get_hit_xyz(int chamber, int strip, float diff_corrected, float *x, float *y, float *z)
void fillSlewingT0(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
void fillPreparation(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
void SetLeadMinMax(int c, int leadmin, int leadmax)
int get_chamber_z(int chamber, float *z)
void get_hit_xyznl(int chamber, int strip, float diff, float *x, float *y, float *z)
int get_track_hits(float *xyz, float *cxyy, int *nhits, int *chamb, int *strip)
void SetSlewingReference(Int_t chamber, Int_t refrun, Int_t refchamber)
float get_hit_xng(int chamber, int strip, float diff)