18#define CHECK_SLEWING 0
19#define TIME_LIMITS_VS_WIDTH 0
20#define USE_PRELIMINARY_OFFSETS 1
21#define USE_FIT_SLEWING 0
25#define USE_FINAL_OFFSETS 1
29#define LIMITS_ROOT_FILE 1
30#define PRINT_TIME_LIMITS 1
33#define PRELIMINARY_OFFSETS 1
34#define EQUAL_MAXIMA0 1
36#define PRINT_EQUALIZATION0_RESULTS 0
37#define DEBUG_EQUALIZATION0 1
45#define MAX_FIT_ATTEMPTS 5
46#define MIN_FIT_ENTRIES 10
58#define PRINT_SLEWING_RESULTS 0
59#define PRINT_SLEWING_PARAMETERS 0
60#define PRINT_FIT_RESULTS 0
64#define FINAL_OFFSETS 1
68#define PRINT_EQUALIZATION_RESULTS 0
69#define DEBUG_EQUALIZATION 1
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
100 TString dir = getenv(
"VMCWORKDIR");
101 TString path = dir +
"/input/";
108 const char* fname = RunFile.
Data();
109 if (strlen(fname) > 0) {
112 RUN = runString.
Atoi();
114 LOGF(error,
"Run file: \"%s\" - can't extract run number!", RunFile.
Data());
122 in.open((path + mappingFile).Data());
124 LOGF(info,
"Loading TOF700 Map from file: %s - file open error!", mappingFile.
Data());
130 if (SlewingRun > 0) {
132 sprintf((
char*)&
filname_base[0],
"bmn_run%04d_raw", SlewingRun);
134 if (SlewingChamber == 0)
135 LOGF(debug,
"Loading TOF700 Map from file: %s , reference slewing run %d", mappingFile.
Data(), SlewingRun);
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) {
142 LOGF(debug,
"Loading TOF700 Map from file: %s , reference slewing run %d", mappingFile.
Data(),
fRUN);
144 LOGF(debug,
"Loading TOF700 Map from file: %s , without slewing corrections!", mappingFile.
Data());
149 LOGF(info,
"Loading TOF700 Map from file: %s , reference slewing run %d", mappingFile.
Data(),
fRUN);
151 LOGF(info,
"Loading TOF700 Map from file: %s , without slewing corrections!", mappingFile.
Data());
155 if (strstr((
char*)mappingFile.
Data(),
"SRC"))
162 if ((perstr = strstr((
char*)mappingFile.
Data(),
"period"))) {
164 if (sscanf(perstr,
"period_%d", &per) == 1)
177 int crate, slot, chan, plane , filetype, cham, cable;
192 in >> dummy >> dummy;
194 in >> std::dec >> crate >> std::hex >> id_crate;
207 in >> dummy >> dummy >> dummy >> dummy >> dummy;
211 in >> crate >> slot >> std::hex >> devsernum >> std::dec >> filetype >> dnlfile;
219 devser[crate][slot] = devsernum;
225 dnltype[crate][slot] = filetype;
226 strcpy(&
dnlname[crate][slot][0], path.Data());
227 strcat(&
dnlname[crate][slot][0], dnlfile.Data());
235 in >> dummy >> dummy;
237 char line[256] = {
""};
238 in.getline(line, 128);
240 in.getline(line, 128);
242 sscanf(line,
"%d\t\t%f\n", &cham, &idcham);
255 in >> dummy >> dummy >> dummy >> dummy;
257 in.getline(line, 128);
262 in.getline(line, 128);
264 sscanf(line,
"%d\t%d\t%d\t%d\n", &crate, &slot, &plane, &cable);
276 for (
int ie = 1; ie <= 2; ie++) {
283 chan = is + (ie - 1) * 16;
292 for (
int ie = 1; ie <= 2; ie++) {
299 chan = 16 + is + (ie - 1) * 16;
307 }
else if (cable == 1) {
308 for (
int ie = 1; ie <= 2; ie++) {
315 chan = is + (ie - 1) * 16;
323 }
else if (cable == 2) {
324 for (
int ie = 1; ie <= 2; ie++) {
331 chan = 32 + is + (ie - 1) * 16;
344 LOGF(error,
"Wrong cable flag, line is %s", line);
357 for (
int c = 0; c < 10; c++)
358 for (
int i = 0;
i < 25;
i++) {
359 for (
int j = 0; j < 64; j++)
379 readXYCalibration((
char*)
"TOF700_tdiff_to_x_final_2019071.txt", (
char*)
"Y_calibration.txt");
390 readXYCalibrationNew((
char*)
"bmn_run9687_digi_x_calibration.txt", (
char*)
"bmn_run9687_digi_y_calibration.txt");
392 for (
int ind = 0; ind <
n_rec; ind++) {
393 if (
mapa[ind].pair == -1)
395 for (
int ind1 = 0; ind1 <
n_rec; ind1++) {
398 if (
mapa[ind1].plane ==
mapa[ind].plane &&
mapa[ind1].strip ==
mapa[ind].strip) {
399 mapa[ind].pair = ind1;
400 mapa[ind1].pair = -1;
406 LOGF(debug,
"\n===========================================================================");
408 LOGF(debug,
" #\tcrate\tcrateID\n===========================================================================");
412 LOGF(debug,
"===========================================================================");
413 LOGF(debug,
" #\tchamber\tchamberID\n===========================================================================");
417 LOGF(debug,
"===========================================================================");
419 "#\tcrate\tslot\tdevsernum\tfiletype\tfile\n==========================================================="
425 LOGF(debug,
"===========================================================================");
428 "#\tcrate\tslot\tchannel\tplane\tstrip\tside\n====================================================="
429 "======================");
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,
435 LOGF(debug,
"===========================================================================");
441 for (
int j = 0; j < 72; j++)
442 for (
int k = 0; k < 1024; k++)
457 for (
int j = 0; j < 500; j++)
460 for (
int j = 0; j < 500; j++)
501 for (
int ir = 0; ir < 4; ir++) {
548 for (
int ir = 0; ir < 4; ir++) {
571 LOGF(error,
"Wrong slewing chamber number %d", chamber);
575 LOGF(error,
"Wrong slewing reference chamber number %d", refchamber);
578 if (refrun < 0 || refrun > 9999) {
579 LOGF(error,
"Wrong slewing reference run number %d", refrun);
586 LOGF(info,
"Chamber %d(%.1f) - use slewing reference run number %d, reference chamber %d(%.1f)", chamber,
593 char name[128], title[128];
596 gStyle->SetOptStat(111111);
598 sprintf(name,
"Nhit");
599 sprintf(title,
"N hits");
600 Nhit =
new TH1F(name, title, 200, 0, 200);
602 sprintf(name,
"Time_T0");
603 sprintf(title,
"Time T0");
604 Lt0 =
new TH1F(name, title, 1500, 0, 300000);
606 sprintf(name,
"Width_T0");
607 sprintf(title,
"Width T0");
608 Wt0 =
new TH1F(name, title, 1500, 0, 1500);
610 sprintf(name,
"TS_difference");
611 sprintf(title,
"TS difference");
612 Wts =
new TH1F(name, title, 400, -200, 200);
614 sprintf(name,
"Chamber_rate");
615 sprintf(title,
"Chamber hit rate");
616 Hchambrate =
new TH2F(name, title, 30, -150, +150, 20, -100, 100);
618 sprintf(name,
"Chamber_id_rate");
619 sprintf(title,
"ChamberID hit rate");
622 sprintf(name,
"Strip_rate");
623 sprintf(title,
"Strip hit rate");
624 Hstriprate =
new TH2F(name, title, 300, -150, +150, 2000, -100, 100);
627 sprintf(name,
"Time_vs_Strip_Chamber_%.1f",
idchambers[
i]);
628 sprintf(title,
"Time vs Strip Chamber %.1f",
idchambers[
i]);
634 sprintf(name,
"Width_vs_Strip_Chamber_%.1f",
idchambers[
i]);
635 sprintf(title,
"Width vs Strip Chamber %.1f",
idchambers[
i]);
640 sprintf(name,
"Time_vs_Width_Chamber_%.1f_all",
idchambers[
i]);
641 sprintf(title,
"Time vs Width Chamber %.1f all",
idchambers[
i]);
647 sprintf(name,
"Time_vs_Width_Chamber_%.1f_max",
idchambers[
i]);
648 sprintf(title,
"Time vs Width Chamber %.1f, max strip",
idchambers[
i]);
656 sprintf(name,
"Time_offsets0");
657 sprintf(title,
"Time offsets0");
660 LOGF(info,
" TOF700 booking done for %d chambers!",
MaxPlane);
665 char name[128], title[128];
668 gStyle->SetOptStat(111111);
670 TString dir = getenv(
"VMCWORKDIR");
671 TString path = dir +
"/parameters/tof2_slewing/";
674 strcat(filnr,
".slewing.root");
677 sprintf(name,
"Time_T0");
678 sprintf(title,
"Time T0");
679 Lt0 =
new TH1F(name, title, 1500, 0, 300000);
681 sprintf(name,
"Width_T0");
682 sprintf(title,
"Width T0");
683 Wt0 =
new TH1F(name, title, 1500, 0, 1500);
685 sprintf(name,
"TS_difference");
686 sprintf(title,
"TS difference");
687 Wts =
new TH1F(name, title, 400, -200, 200);
689 sprintf(name,
"Chamber_rate");
690 sprintf(title,
"Chamber hit rate");
691 Hchambrate =
new TH2F(name, title, 30, -150, +150, 20, -100, 100);
693 sprintf(name,
"Chamber_id_rate");
694 sprintf(title,
"ChamberID hit rate");
697 sprintf(name,
"Strip_rate");
698 sprintf(title,
"Strip hit rate");
699 Hstriprate =
new TH2F(name, title, 300, -150, +150, 2000, -100, 100);
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);
705 sprintf(name,
"Time_fit_offsets_region_%d", ir + 1);
706 sprintf(title,
"Time fit_offsets region %d", ir + 1);
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);
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);
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);
761 sprintf(name,
"Time_Lead_Min");
762 sprintf(title,
"Time Lead Minimal for slewing");
764 sprintf(name,
"Time_Lead_Max");
765 sprintf(title,
"Time Lead Maximal for slewing");
771 sprintf(name,
"Time_offsets0");
772 sprintf(title,
"Time offsets0");
791 char name[128], title[128];
794 gStyle->SetOptStat(111111);
796 sprintf(name,
"Time_T0");
797 sprintf(title,
"Time T0");
798 Lt0 =
new TH1F(name, title, 1500, 0, 300000);
800 sprintf(name,
"Width_T0");
801 sprintf(title,
"Width T0");
802 Wt0 =
new TH1F(name, title, 1500, 0, 1500);
803 Wt0->SetDirectory(0);
805 sprintf(name,
"TS_difference");
806 sprintf(title,
"TS difference");
807 Wts =
new TH1F(name, title, 400, -200, 200);
808 Wts->SetDirectory(0);
810 sprintf(name,
"Chamber_rate");
811 sprintf(title,
"Chamber hit rate");
812 Hchambrate =
new TH2F(name, title, 30, -150, +150, 20, -100, 100);
815 sprintf(name,
"Chamber_id_rate");
816 sprintf(title,
"ChamberID hit rate");
820 sprintf(name,
"Strip_rate");
821 sprintf(title,
"Strip hit rate");
822 Hstriprate =
new TH2F(name, title, 300, -150, +150, 2000, -100, 100);
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);
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);
856 char name[128], title[128];
862 for (
int ir = 0; ir < 4; 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);
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);
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);
918 sprintf(name,
"Time_vs_Width_Chamber_%.1f_all",
idchambers[
i]);
919 sprintf(title,
"Time vs Width Chamber %.1f all",
idchambers[
i]);
921 TvsWall[
i] =
new TH2F(name, title, Wm / 50, 0, Wm, 5000, 0., 10000.);
927 sprintf(name,
"Time_vs_Width_Chamber_%.1f_max",
idchambers[
i]);
928 sprintf(title,
"Time vs Width Chamber %.1f, max strip",
idchambers[
i]);
930 TvsWallmax[
i] =
new TH2F(name, title, Wm / 50, 0, Wm, 5000, 0., 10000.);
950 f =
new TFile(filn,
"RECREATE",
"Preparation Results of BmnTOF700");
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");
1026 char rightname[128];
1032 sprintf(filn,
"%s_slewing_results.root", rightname);
1033 f =
new TFile(filn,
"RECREATE",
"Slewing Results of BmnTOF700");
1044 for (
int ir = 0; ir < 4; ir++) {
1063 TString dir = getenv(
"VMCWORKDIR");
1064 TString path = dir +
"/parameters/tof2_slewing/";
1066 sprintf(filn,
"%s%s_slewing_limits.txt", path.Data(),
filname_base);
1067 fout = fopen(filn,
"w");
1078 im = (h = (
TvsWallmax[
i]->ProjectionY(
"lims")))->GetMaximumBin();
1082 im = (h = (
TvsS[
i]->ProjectionY(
"lims")))->GetMaximumBin();
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);
1104 TString dir = getenv(
"VMCWORKDIR");
1105 TString path = dir +
"/parameters/tof2_slewing/";
1106 char filn[512], name[256], nname[256];
1112 sprintf(filn,
"%s%s_slewing_limits.txt", path.Data(),
filname_base);
1113 finl = fopen(filn,
"r");
1115 printf(
"No slewing limits file %s, use defaults\n", filn);
1125 LOGF(info,
"\t\tTOF2.SetW(%d,%d);",
Wcut,
Wmax);
1131 fscanf(finl,
"\t\tTOF2.SetLeadMinMax(%d, %d,%d);\n", &j, &lmi, &lma);
1133 printf(
"\t\tWrong limits - TOF2.SetLeadMinMax(%d, %d,%d);\n", j, lmi, lma);
1137 LOGF(debug,
"\t\tTOF2.SetLeadMinMax(%d, %d,%d);", j, lmi, lma);
1144 strcat(filn,
"_preparation.root");
1147 TFile* fPreparation =
new TFile(filn,
"READ");
1149 if (fPreparation == 0) {
1150 printf(
"Error input file %s for limits!\n", filn);
1166 LOGF(debug,
"\t\tTOF2.SetW(%d,%d);",
Wcut,
Wmax);
1168 LOGF(debug,
"\t\tTOF2.SetWT0(%d,%d);",
WT0min,
WT0max);
1174 double meant = 0, sigmat = 0.;
1176 for (
int plane = 0; plane <
MaxPlane; plane++) {
1178 sprintf(name,
"Time_vs_Width_Chamber_%.1f_max",
idchambers[plane]);
1180 sprintf(name,
"Time_vs_Width_Chamber_%.1f_all",
idchambers[plane]);
1181 hs = (
TH2F*)fPreparation->
Get(name);
1183 printf(
"Error input Time vs Strip hist for chamber %.1f!\n",
idchambers[plane]);
1191 bymin = (int)(tim->
FindBin(ymin));
1192 bymax = (int)(tim->
FindBin(ymax));
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++)
1201 sprintf(nname,
"Fit_Time_vs_Width_Chamber%.1fall_0",
idchambers[plane]);
1203 sprintf(nname,
"Fit_Time_vs_Width_Chamber%.1fall_1",
idchambers[plane]);
1205 sprintf(nname,
"Fit_Time_vs_Width_Chamber%.1fall_2",
idchambers[plane]);
1207 sprintf(nname,
"Fit_Time_vs_Width_Chamber%.1fall_chi2",
idchambers[plane]);
1219 gPad->WaitPrimitive();
1221 for (
int ibx = 1; ibx <= nb; ibx++) {
1224 if (sigmat == 0 || sigmat > 40) {
1225 LeadMinW[plane][ibx - 1] = (int)ymin;
1226 LeadMaxW[plane][ibx - 1] = (int)ymax;
1228 LeadMinW[plane][ibx - 1] = meant - sigmat;
1229 LeadMaxW[plane][ibx - 1] = meant + sigmat;
1241 LOGF(debug,
"\t\tTOF2.SetLeadMinMax(%d, %d,%d);", plane + 1, (
int)ymin, (
int)ymax);
1243 LOGF(error,
"\t\tWrong limits - TOF2.SetLeadMinMax(%d, %d,%d);", plane + 1, (
int)ymin, (
int)ymax);
1250 sprintf(name,
"Time_offsets0");
1253 LOGF(error,
"Error input TOffsets0 slewing profile!");
1264 fPreparation->
Close();
1275 TString dir = getenv(
"VMCWORKDIR");
1276 TString path = dir +
"/parameters/tof2_slewing/";
1278 char filnr[512], name[256];
1280 strcat(filnr,
".slewing.root");
1290 LOGF(error,
"Error open slewing file %s, work without slewing corrections!", filnr);
1293 LOGF(error,
"Error open slewing file %s, work without slewing corrections!", filnr);
1302 for (
int plane = 0; plane <
MaxPlane; plane++) {
1303 for (
int region = 0; region < 4; region++) {
1310 sprintf(name,
"Time_vs_T0_Width_Chamber_%.1f_Peak_%d",
idchambers[planer], region + 1);
1313 LOGF(error,
"Error input T0 slewing profile for chamber %.1f region %d!",
idchambers[planer],
1319 sprintf(name,
"Time_vs_Width_Chamber_%.1f_Peak_%d",
idchambers[planer], region + 1);
1322 LOGF(error,
"Error input RPC slewing profile for chamber %.1f region %d!",
idchambers[planer],
1328 sprintf(name,
"Time_vs_Strip_Chamber_%.1f_Peak_%d_Maxima",
idchambers[planer], region + 1);
1331 LOGF(error,
"Error input RPC time distribution for chamber %.1f region %d!",
idchambers[planer],
1338 for (
int region = 0; region < 4; region++) {
1339 sprintf(name,
"Time_offsets_region_%d", region + 1);
1342 LOGF(error,
"Error input TOffsets slewing profile for region %d!", region + 1);
1345 sprintf(name,
"Time_fit_offsets_region_%d", region + 1);
1348 LOGF(error,
"Error input TOffsets fit slewing profile for region %d!", region + 1);
1353 sprintf(name,
"Time_offsets0");
1356 LOGF(error,
"Error input TOffsets0 slewing profile!");
1359 sprintf(name,
"Time_Lead_Min");
1362 LOGF(error,
"Error input Time_Lead_Min hist!");
1365 sprintf(name,
"Time_Lead_Max");
1368 LOGF(error,
"Error input Time_Lead_Max hist!");
1371 for (
int plane = 0; plane <
MaxPlane && prof1 && prof2; plane++) {
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));
1379 sprintf(name,
"Wlimits");
1383 printf(
"Error input Wlimits hist!\n");
1391 LOGF(info,
"\t\tTOF2.SetW(%d,%d);", wc, wm);
1395 LOGF(info,
"\t\tTOF2.SetWT0(%d,%d);", wt0mi, wt0ma);
1412 LOGF(info,
"\n===========================================================================");
1414 LOGF(info,
" #\tcrate\tcrateID\n===========================================================================");
1418 LOGF(info,
"===========================================================================");
1419 LOGF(info,
" #\tchamber\tchamberID\n===========================================================================");
1423 LOGF(info,
"===========================================================================");
1425 "#\tcrate\tslot\tdevsernum\tfiletype\tfile\n============================================================"
1431 LOGF(info,
"===========================================================================");
1433 "#\tcrate\tslot\tchannel\tplane\tstrip\tside\n=========================================================="
1434 "=================");
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,
1439 LOGF(info,
"===========================================================================");
1444 for (
int ic = 0; ic <
ncrates; ic++) {
1452 unordered_map<UInt_t, Long64_t>* ts,
1458 unsigned rawtime = 0;
1499 int nc = -1, ind = 0, crate = -1, slot = 0;
1508 crate =
mapa[ind].crate;
1509 slot =
mapa[ind].slot;
1512 if (it == ts->end())
1514 ts_diff = it->second;
1517 unsigned devsernum = digit->
GetSerial();
1518 for (
int idev = 0; idev <
nslots + 1; idev++) {
1520 if ((
unsigned)
devnum[idev] == devsernum) {
1527 if (crate == -1 || slot == 0)
1530 auto it = ts->find(
idcrates[crate]);
1531 if (it == ts->end())
1533 ts_diff = it->second;
1538 ind =
nrec[nc][slot][chan];
1541 if (crate !=
mapa[ind].crate)
1543 if (slot !=
mapa[ind].slot)
1547 int dnl = rawtime & 0x3FF;
1548 float tm = (rawtime +
DNL_Table[crate][slot][chan][dnl]) -
chtima[crate][slot][chan]
1555 if (trail[ind] == 0)
1575 for (
int ind = 0; ind <
n_rec; ind++) {
1576 int ind1 =
mapa[ind].pair;
1579 if (lead[ind1] == 0 || trail[ind1] == 0)
1581 if (lead[ind] != 0 && trail[ind] != 0) {
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.;
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;
1622 Nhit->Fill(ngoodhits);
1631 unordered_map<UInt_t, Long64_t>* ts,
1640 unsigned rawtime = 0;
1681 int nc = -1, ind = 0, crate = -1, slot = 0;
1690 crate =
mapa[ind].crate;
1691 slot =
mapa[ind].slot;
1694 if (it == ts->end())
1696 ts_diff = it->second;
1699 unsigned devsernum = digit->
GetSerial();
1700 for (
int idev = 0; idev <
nslots + 1; idev++) {
1702 if ((
unsigned)
devnum[idev] == devsernum) {
1708 if (crate == -1 || slot == 0)
1711 auto it = ts->find(
idcrates[crate]);
1712 if (it == ts->end())
1714 ts_diff = it->second;
1719 ind =
nrec[nc][slot][chan];
1722 if (crate !=
mapa[ind].crate)
1724 if (slot !=
mapa[ind].slot)
1727 int dnl = rawtime & 0x3FF;
1728 float tm = (rawtime +
DNL_Table[crate][slot][chan][dnl]) -
chtima[crate][slot][chan]
1735 if (trail[ind] == 0)
1757 for (
int ind = 0; ind <
n_rec; ind++) {
1758 int ind1 =
mapa[ind].pair;
1761 if (lead[ind1] == 0 || trail[ind1] == 0)
1765 if (lead[ind] != 0 && trail[ind] != 0) {
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)
1799 if ((
int)W1 < Wc && (
int)W2 < Wc) {
1801 }
else if ((
int)W1 >= Wc && (
int)W2 >= Wc && (
int)W1 < Wm && (
int)W2 < Wm) {
1803 }
else if ((
int)W1 >= Wc && (
int)W2 < Wc && (
int)W1 < Wm) {
1805 }
else if ((
int)W2 >= Wc && (
int)W1 < Wc && (
int)W2 < Wm) {
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;
1834 unordered_map<UInt_t, Long64_t>* ts,
1843 unsigned rawtime = 0;
1881 int nc = -1, ind = 0, crate = -1, slot = 0;
1890 crate =
mapa[ind].crate;
1891 slot =
mapa[ind].slot;
1894 if (it == ts->end())
1896 ts_diff = it->second;
1899 unsigned devsernum = digit->
GetSerial();
1900 for (
int idev = 0; idev <
nslots + 1; idev++) {
1902 if ((
unsigned)
devnum[idev] == devsernum) {
1908 if (crate == -1 || slot == 0)
1911 auto it = ts->find(
idcrates[crate]);
1912 if (it == ts->end())
1914 ts_diff = it->second;
1919 ind =
nrec[nc][slot][chan];
1922 if (crate !=
mapa[ind].crate)
1924 if (slot !=
mapa[ind].slot)
1927 int dnl = rawtime & 0x3FF;
1928 float tm = (rawtime +
DNL_Table[crate][slot][chan][dnl]) -
chtima[crate][slot][chan]
1935 if (trail[ind] == 0)
1952 char nfun0[12] = {
""};
1955 for (
int ind = 0; ind <
n_rec; ind++) {
1956 int ind1 =
mapa[ind].pair;
1959 if (lead[ind1] == 0 || trail[ind1] == 0)
1963 if (lead[ind] != 0 && trail[ind] != 0) {
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.;
1983 if ((
int)W1 < Wc && (
int)W2 < Wc) {
1985 }
else if (W1 >= Wc && W2 >= Wc) {
1987 }
else if (W1 >= Wc && W2 < Wc) {
1989 }
else if (W1 < Wc && W2 >= Wc) {
1995 int binw = (int)(
W / 50.f);
1996 if (binw < 0 || binw >= 500)
2024 if ((fun0 =
TvsWt0[
mapa[ind].plane][ira]->GetFunction(
"slew0")) != NULL) {
2025 strcpy(nfun0,
"slew0");
2035 L -=
TvsWt0[
mapa[ind].plane][ira]->GetBinContent(
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;
2056 TvsW[
i][rmax[
i]]->Fill(wmaxs[
i], smax[
i], tmaxs[
i]);
2063 unordered_map<UInt_t, Long64_t>* ts,
2074 unsigned rawtime = 0;
2118 int nc = -1, ind = 0, crate = -1, slot = 0;
2128 crate =
mapa[ind].crate;
2129 slot =
mapa[ind].slot;
2132 if (it == ts->end())
2134 ts_diff = it->second;
2137 unsigned devsernum = digit->
GetSerial();
2138 for (
int idev = 0; idev <
nslots + 1; idev++) {
2141 if ((
unsigned)
devnum[idev] == devsernum) {
2148 if (crate == -1 || slot == 0)
2151 auto it = ts->find(
idcrates[crate]);
2152 if (it == ts->end())
2154 ts_diff = it->second;
2159 ind =
nrec[nc][slot][chan];
2162 if (crate !=
mapa[ind].crate)
2164 if (slot !=
mapa[ind].slot)
2170 int dnl = rawtime & 0x3FF;
2171 float tm = (rawtime +
DNL_Table[crate][slot][chan][dnl]) -
chtima[crate][slot][chan]
2180 if (trail[ind] == 0)
2187 char nfun0[12] = {
""};
2190 char nfun[12] = {
""};
2194 for (
int ind = 0; ind <
n_rec; ind++) {
2195 int ind1 =
mapa[ind].pair;
2198 if (lead[ind1] == 0 || trail[ind1] == 0)
2201 if (lead[ind] != 0 && trail[ind] != 0) {
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.;
2226 if (
fSlewing == 0 || t0 == 0. || t0width == 0.)
2229 if ((
int)W1 < Wc && (
int)W2 < Wc) {
2231 }
else if (W1 >= Wc && W2 >= Wc && W1 < Wm && W2 < Wm) {
2233 }
else if (W1 >= Wc && W2 < Wc && W1 < Wm) {
2235 }
else if (W1 < Wc && W2 >= Wc && W2 < Wm) {
2257 int binw = (int)(
W / 50.f);
2258 if (binw < 0 || binw >= 500)
2282 if ((fun0 =
TvsWt0[
mapa[ind].plane][ira]->GetFunction(
"slew0")) != NULL) {
2283 strcpy(nfun0,
"slew0");
2288 if ((fun =
TvsW[
mapa[ind].plane][ira]->GetFunction(
NSLFIT)) != NULL) {
2292 if ((fun =
TvsW[
mapa[ind].plane][ira]->GetFunction(
"slew")) != NULL) {
2293 strcpy(nfun,
"slew");
2301 if (
TvsWt0[
mapa[ind].plane][ira]->GetBinError(bin) <= 0.f)
2305 L -=
TvsWt0[
mapa[ind].plane][ira]->GetBinContent(bin);
2312 bin =
TvsW[
mapa[ind].plane][ira]->FindBin(
W,
mapa[ind].strip);
2313 if (
TvsW[
mapa[ind].plane][ira]->GetBinError(bin) <= 0.f)
2317 L -=
TvsW[
mapa[ind].plane][ira]->GetBinContent(bin);
2341 unordered_map<UInt_t, Long64_t>* ts,
2350 unsigned rawtime = 0;
2393 int nc = -1, ind = 0, crate = -1, slot = 0;
2401 crate =
mapa[ind].crate;
2402 slot =
mapa[ind].slot;
2405 if (it == ts->end())
2407 ts_diff = it->second;
2410 unsigned devsernum = digit->
GetSerial();
2411 for (
int idev = 0; idev <
nslots + 1; idev++) {
2414 if ((
unsigned)
devnum[idev] == devsernum) {
2421 if (crate == -1 || slot == 0)
2425 auto it = ts->find(
idcrates[crate]);
2426 if (it == ts->end())
2428 ts_diff = it->second;
2434 ind =
nrec[nc][slot][chan];
2437 if (crate !=
mapa[ind].crate)
2439 if (slot !=
mapa[ind].slot)
2444 int dnl = rawtime & 0x3FF;
2445 float tm = (rawtime +
DNL_Table[crate][slot][chan][dnl]) -
chtima[crate][slot][chan]
2454 if (trail[ind] == 0)
2461 char nfun0[12] = {
""};
2464 char nfun[12] = {
""};
2467 for (
int ind = 0; ind <
n_rec; ind++) {
2468 int ind1 =
mapa[ind].pair;
2471 if (lead[ind1] == 0 || trail[ind1] == 0)
2473 if (lead[ind] != 0 && trail[ind] != 0) {
2486 float L = (lead[ind1] + lead[ind]) / 2.;
2488 float W1 = trail[ind] - lead[ind];
2489 float W2 = trail[ind1] - lead[ind1];
2490 float W = (W1 + W2) / 2.;
2494 if ((
int)W1 < Wc && (
int)W2 < Wc) {
2496 }
else if (W1 >= Wc && W2 >= Wc) {
2498 }
else if (W1 >= Wc && W2 < Wc) {
2500 }
else if (W1 < Wc && W2 >= Wc) {
2504 int binw = (int)(
W / 50.f);
2505 if (binw < 0 || binw >= 500)
2536 if ((fun0 =
TvsWt0[
mapa[ind].plane][ira]->GetFunction(
"slew0")) != NULL) {
2537 strcpy(nfun0,
"slew0");
2542 if ((fun =
TvsW[
mapa[ind].plane][ira]->GetFunction(
NSLFIT)) != NULL) {
2546 if ((fun =
TvsW[
mapa[ind].plane][ira]->GetFunction(
"slew")) != NULL) {
2547 strcpy(nfun,
"slew");
2554 L -=
TvsWt0[
mapa[ind].plane][ira]->GetBinContent(
2560 L -=
TvsW[
mapa[ind].plane][ira]->GetBinContent(
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};
2589 gROOT->ProcessLine(
"gErrorIgnoreLevel = 3001;");
2591 TString dir = getenv(
"VMCWORKDIR");
2592 TString path = dir +
"/parameters/tof2_slewing/";
2594 strcat(filn,
".fit.log");
2595 fout = fopen(filn,
"w");
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];
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;
2612 gPad->WaitPrimitive();
2642 if (blast < prof->GetNbinsX())
2655 if (nonzero > nonzeromax) {
2656 nonzeromax = nonzero;
2663 if (nonzero > nonzeromax) {
2664 nonzeromax = nonzero;
2670 nonzeromax = nonzero;
2673 sscanf(
NSLFIT0,
"pol%d", &minpoints);
2674 if (nonzeromax > (minpoints + 1)) {
2675 char fun[12], nfun[12], nfunold[12];
2680 sprintf(nfun,
"pfi");
2681 TF1* pfi =
new TF1(nfun, fun,
TvsWt0[plane][pk]->GetBinCenter(bfirstmax),
2682 TvsWt0[plane][pk]->GetBinCenter(blast));
2684 result = prof->
Fit(pfi,
FIT,
"",
TvsWt0[plane][pk]->GetBinCenter(bfirstmax),
2685 TvsWt0[plane][pk]->GetBinCenter(blast));
2687 if (result->IsValid() && result->Chi2() > 0.)
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));
2696 result = prof->
Fit(pfi,
FITI0,
"",
TvsWt0[plane][pk]->GetBinCenter(bfirstmax),
2697 TvsWt0[plane][pk]->GetBinCenter(blast));
2699 if (!(result->IsValid() && result->Chi2() > 0.)) {
2701 strcpy(nfun, nfunold);
2706 strcpy(nfun, nfunold);
2710 strcpy(nfunold, nfun);
2713 if (result->IsValid() && result->Chi2() > 0.)
2721 bool badresult =
true;
2723 if (result->IsValid() && result->Chi2() > 0.)
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());
2736 prof->
SetMaximum(pmax + (pmax - pmin) * 0.10);
2737 prof->
SetMinimum(pmin - (pmax - pmin) * 0.10);
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());
2752 prof->
SetMaximum(pmax + (pmax - pmin) * 0.10);
2753 prof->
SetMinimum(pmin - (pmax - pmin) * 0.10);
2762 for (
int il = 0; il < nf; il++) {
2765 TF1 *fu = 0, *lfun[20] = {NULL};
2767 for (
int il = 0; il < nf; il++) {
2768 fu = (
TF1*)(l->
At(il));
2769 if (!strcmp(fu->
GetName(),
"slew0"))
2773 for (
int il = 0; il < nrej; il++) {
2778 for (
int il = 0; il < l->
GetEntries(); il++) {
2782 LOGF(info,
" Chamber %d (%.1f) peak %d T0 slewing - too few nonzero bins = %d", plane + 1,
2784 fprintf(fout,
" Chamber %d (%.1f) peak %d T0 slewing - too few nonzero bins = %d\n", plane + 1,
2788 prof2d =
TvsW[plane][pk];
2790 sprintf(name,
"%s_strip%d", prof2d->
GetTitle(), s);
2791 prof = prof2d->
ProfileX(name, s, s);
2796 gPad->WaitPrimitive();
2829 if (blast < prof->GetNbinsX())
2843 if (nonzero > nonzeromax) {
2844 nonzeromax = nonzero;
2851 if (nonzero > nonzeromax) {
2852 nonzeromax = nonzero;
2858 nonzeromax = nonzero;
2860 sscanf(
NSLFIT,
"pol%d", &minpoints);
2864 if (nonzeromax > (minpoints + 1)) {
2865 char fun[12], nfun[12], nfunold[12];
2868 strcpy(nfun,
"ptotal");
2869 float x0 =
TvsW[plane][pk]->GetBinCenter(bfirstmax);
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);
2881 prof->
Fit(p[is],
"Q0R+");
2883 prof->
Fit(p[is],
"Q0R+");
2894 sprintf(ntotal,
"%s(%d)", spol, is * (subdeg + 1));
2896 sprintf(ntotal,
"%s+%s(%d)", ntotal, spol, is * (subdeg + 1));
2900 ptotal =
new TF1(
"ptotal", ntotal, x0, xc + dxc);
2905 result = prof->
Fit(ptotal,
"Q0RS+",
"", x0, xc);
2906 if (result->IsValid() && result->Chi2() > 0. && prof->
GetFunction(
"ptotal"))
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));
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))
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));
2927 result = prof->
Fit(pfi,
FITI,
"",
TvsW[plane][pk]->GetBinCenter(bfirstmax),
2928 TvsW[plane][pk]->GetBinCenter(blast));
2930 if (!(result->IsValid() && result->Chi2() > 0.)) {
2932 strcpy(nfun, nfunold);
2937 strcpy(nfun, nfunold);
2941 strcpy(nfunold, nfun);
2944 if (result->IsValid() && result->Chi2() > 0.)
2953 bool badresult =
true;
2955 if (result->IsValid() && result->Chi2() > 0.)
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());
2968 prof->
SetMaximum(pmax + (pmax - pmin) * 0.10);
2969 prof->
SetMinimum(pmin - (pmax - pmin) * 0.10);
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());
2983 prof->
SetMaximum(pmax + (pmax - pmin) * 0.10);
2984 prof->
SetMinimum(pmin - (pmax - pmin) * 0.10);
2991 for (
int il = 0; il < nf; il++) {
2994 TF1 *fu = 0, *lfun[20] = {NULL};
2996 for (
int il = 0; il < nf; il++) {
2997 fu = (
TF1*)(l->
At(il));
2998 if (!strcmp(fu->
GetName(),
"slew"))
3002 for (
int il = 0; il < nrej; il++) {
3007 for (
int il = 0; il < l->
GetEntries(); il++) {
3011 LOGF(info,
" Chamber %d (%.1f) peak %d RPC slewing - too few nonzero bins = %d", plane + 1,
3013 fprintf(fout,
" Chamber %d (%.1f) peak %d RPC slewing - too few nonzero bins = %d\n", plane + 1,
3025 gROOT->ProcessLine(
"gErrorIgnoreLevel = 1001;");
3045 char namp[64], namf[64];
3050 TString dir = getenv(
"VMCWORKDIR");
3051 TString path = dir +
"/parameters/tof2_slewing/";
3054 strcat(filn,
".equalization.log");
3055 fout = fopen(filn,
"w");
3058 strcat(filn,
".equalization.debug");
3059 fdeb = fopen(filn,
"w");
3061 for (
int plane = 0; plane <
MaxPlane; plane++) {
3062 for (
int pk = 0; pk < 4; pk++) {
3065 "**************** %s Chamber %d Peak %d Time-Width area RPC slewing (write) "
3066 "******************************\n",
3070 "**************** %s Chamber %d Peak %d Time-Width area slewing *******************************\n\n",
3075 tmeane_average[plane][pk] = 0.;
3076 for (
int ind = 0; ind <
n_rec; ind++) {
3077 if (
mapa[ind].pair < 0)
3079 ip =
mapa[ind].plane;
3082 is =
mapa[ind].strip;
3084 sprintf(namp,
"Maxima_chamber_%d_strip_%d_equalization", ip + 1, is + 1);
3085 proj =
TvsSm[ip][pk]->ProjectionY(namp, is + 1, is + 1);
3091 LOGF(info,
"Chamber %d strip %d max %d at %f", ip, is, ncon, mpos);
3095 double sum = 0., sumx = 0.;
3096 for (
int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin);
3107 if (
FIT_MAXIMA && zflag == 0 && nonzero >= 5) {
3108 sprintf(namf,
"gaus%dstrip%d", ip + 1, is + 1);
3111 proj->
Fit(namf,
"QR0");
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]);
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]);
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]);
3134 tmeane_average[plane][pk] += tmeane[ind][pk];
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);
3147 tmeane[ind][pk] = sumx / sum;
3148 tmeane_average[plane][pk] += tmeane[ind][pk];
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]);
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]);
3163 tmeane[ind][pk] = 0.;
3167 tmeane[ind][pk] = 0.;
3169 if (ip == 18 && fdeb) {
3170 fprintf(fdeb,
"Mean: Chamber %d strip %d ntmean %d tmeane %f\n", ip, is, ncon, tmeane[ind][pk]);
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)
3190 ip =
mapa[ind].plane;
3193 is =
mapa[ind].strip;
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]);
3199 Toffsetsf[pk]->Fill(ind, tmeane[ind][pk]);
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]);
3210 Toffsetsf[pk]->Fill(ind, tmeane[ind][pk] - tmeane_average[plane][pk]);
3237 TH1D *proj = 0, *hmain = 0;
3239 char namp[64], namf[64];
3244 TString dir = getenv(
"VMCWORKDIR");
3245 TString path = dir +
"/parameters/tof2_slewing/";
3248 strcat(filn,
".equalization0.log");
3249 fout = fopen(filn,
"w");
3252 strcat(filn,
".equalization0.debug");
3253 fdeb = fopen(filn,
"w");
3255 for (
int plane = 0; plane <
MaxPlane; plane++) {
3257 printf(
"**************** %s Chamber %d primary equalization ******************************\n",
filname_base,
3259 fprintf(fout,
"**************** %s Chamber %d primary equalization *******************************\n\n",
3264 tmeane_average[plane] = 0.;
3267 int im, y, bymin, bymax;
3269 im = (hmain = (
TvsS[plane]->ProjectionY(
"lims")))->GetMaximumBin();
3270 y = (int)(hmain->GetBinCenter(im));
3274 for (
int ind = 0; ind <
n_rec; ind++) {
3275 if (
mapa[ind].pair < 0)
3277 ip =
mapa[ind].plane;
3280 is =
mapa[ind].strip;
3282 sprintf(namp,
"Maxima_chamber_%d_strip_%d_equalization0", ip + 1, is + 1);
3283 proj =
TvsS[ip]->ProjectionY(namp, is + 1, is + 1);
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)
3300 double sum = 0., sumx = 0.;
3301 for (
int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin); ib++)
3312 sprintf(namf,
"gaus%dstrip%d", ip + 1, is + 1);
3315 proj->
Fit(namf,
"QR0");
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]);
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]);
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]);
3338 tmeane_average[plane] += tmeane[ind];
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++)
3350 tmeane[ind] = sumx / sum;
3351 tmeane_average[plane] += tmeane[ind];
3353 if (ip == 18 && fdeb) {
3354 fprintf(fdeb,
"Mean: Chamber %d strip %d mpos %f ncon %d tmeane %f\n", ip, is, mpos, ncon,
3360 if (ip == 18 && fdeb) {
3361 fprintf(fdeb,
"Zero: Chamber %d strip %d tmeane %f\n", ip, is, tmeane[ind]);
3373 if (ip == 18 && fdeb) {
3374 fprintf(fdeb,
"Mean: Chamber %d strip %d ncon %d tmeane %f\n", ip, is, ncon, tmeane[ind]);
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)
3390 ip =
mapa[ind].plane;
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]);
3422 for (
int i = 0;
i < 1024;
i++) {
3423 fi.getline(atext, 50);
3424 sscanf(atext,
"%d %f %f\n", &pos, &tcor, &ecor);
3430 }
else if (
dnltype[c][s] % 10 == 0) {
3438 fi.getline(atext, 25600);
3441 for (
int i = 0;
i < 1024;
i++) {
3442 sscanf(&atext[post],
"%f %n", &tcor, &pos);
3453 }
else if (
dnltype[c][s] == 2) {
3461 fi.getline(atext, 25600);
3464 for (
int i = 0;
i < 1024;
i++) {
3465 sscanf(&atext[post],
"%f %n", &tcor, &pos);
3469 fi.getline(atext, 25600);
3476 }
else if (
dnltype[c][s] == 3) {
3478 int n, pos, post, ch, nerr = 0;
3483 fi.getline(atext, 25600);
3484 fi.getline(atext, 25600);
3486 if (strstr(atext,
"temp") == NULL)
3490 fi.getline(atext, 25600);
3494 sscanf(&atext[post],
"%d= %n", &ch, &pos);
3498 LOGF(error,
"Crate %d Slot %d Wrong line in %s file, channel %d != %d !", c, s,
3503 for (
int i = 0;
i < 1024;
i++) {
3504 sscanf(&atext[post],
"%f, %n", &tcor, &pos);
3515 }
else if (
dnltype[c][s] == 4)
3523 for (
int i = 0;
i < 1024;
i++) {
3524 fi.getline(atext, 50);
3525 sscanf(atext,
"%f\n", &tcor);
3531 }
else if (
dnltype[c][s] == 5) {
3533 int n, pos, post, ch, nerr = 0;
3538 fi.getline(atext, 25600);
3539 fi.getline(atext, 25600);
3541 if (strstr(atext,
"temp") == NULL)
3545 fi.getline(atext, 25600);
3549 sscanf(&atext[post],
"%d= %n", &ch, &pos);
3553 LOGF(error,
"Crate %d Slot %d Wrong line in %s file, channel %d != %d !", c, s,
3558 for (
int i = 0;
i < 1024;
i++) {
3559 sscanf(&atext[post],
"%f, %n", &tcor, &pos);
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};
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};
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];
3607 prof->
Fit(
"pol0",
"Q0");
3611 LOGF(error,
" Chamber %d slewing results (%d) - too few nonzero bins = %d", plane + 1, it, nonzero);
3626 int champos[] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
3629 memcpy(
champosn, champos,
sizeof champos);
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};
3634 memcpy(
champosn, champos,
sizeof champos);
3641 memcpy(
champosn, champos,
sizeof champos);
3647 float ymin, ymax, xmin, xmax;
3648 TString dir = getenv(
"VMCWORKDIR");
3649 TString path = dir +
"/parameters/tof2_slewing/";
3651 sprintf(filn,
"%s%s_slewing_limits.txt", path.Data(),
filname_base);
3659 if (
TvsS[
i]->GetEntries() < 500)
3662 gPad->AddExec(
"exselt",
"select_hist()");
3663 im = (
TvsS[
i]->ProjectionY())->GetMaximumBin();
3664 y = (int)((
TvsS[
i]->ProjectionY())->GetBinCenter(im));
3667 xmin = (
TvsS[
i]->GetXaxis())->GetXmin();
3668 xmax = (
TvsS[
i]->GetXaxis())->GetXmax();
3669 l =
new TLine(xmin, ymin, xmax, ymin);
3672 l =
new TLine(xmin, ymax, xmax, ymax);
3685 if (
TvsS[
i]->GetEntries() < 500)
3687 im = (
TvsS[
i]->ProjectionY())->GetMaximumBin();
3688 y = (int)((
TvsS[
i]->ProjectionY())->GetBinCenter(im));
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);
3698 l =
new TLine(ymax, xmin, ymax, xmax);
3708 if (
WvsS[
i]->GetEntries() < 500)
3711 gPad->AddExec(
"exselt",
"select_hist()");
3714 xmin = (
WvsS[
i]->GetXaxis())->GetXmin();
3715 xmax = (
WvsS[
i]->GetXaxis())->GetXmax();
3716 l =
new TLine(xmin, ymin, xmax, ymin);
3719 l =
new TLine(xmin, ymax, xmax, ymax);
3729 if (
WvsS[
i]->GetEntries() < 500)
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);
3740 l =
new TLine(ymax, xmin, ymax, xmax);
3750 gPad->AddExec(
"exselt",
"select_hist()");
3754 ymax =
Wt0->GetMaximum();
3755 l =
new TLine(xmin, ymin, xmin, ymax);
3758 l =
new TLine(xmax, ymin, xmax, ymax);
3763 gPad->AddExec(
"exselt",
"select_hist()");
3766 gPad->AddExec(
"exselt",
"select_hist()");
3769 gPad->AddExec(
"exselt",
"select_hist()");
3774 TCanvas* cp1 =
new TCanvas(
"cp1",
"Leadings vs widths", 900, 700);
3780 gPad->AddExec(
"exselt",
"select_hist()");
3783 TCanvas* cp2 =
new TCanvas(
"cp2",
"Leadings vs widths (max strip)", 900, 700);
3790 gPad->AddExec(
"exselt",
"select_hist()");
3800 int champos[] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
3803 memcpy(
champosn, champos,
sizeof champos);
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};
3808 memcpy(
champosn, champos,
sizeof champos);
3815 memcpy(
champosn, champos,
sizeof champos);
3818 TCanvas* callbe =
new TCanvas(
"callbe",
"Leadings vs widths (slewing RPC, peak 1)", 900, 700);
3822 callbe->
Divide(NDX, NDY);
3826 gPad->AddExec(
"exselt",
"select_hist()");
3829 TCanvas* callbe1 =
new TCanvas(
"callbe1",
"Leadings vs widths (slewing RPC, peak 2)", 900, 700);
3831 callbe1->
Divide(NDX, NDY);
3835 gPad->AddExec(
"exselt",
"select_hist()");
3846 int champos[] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
3849 memcpy(
champosn, champos,
sizeof champos);
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};
3854 memcpy(
champosn, champos,
sizeof champos);
3861 memcpy(
champosn, champos,
sizeof champos);
3864 TCanvas* callbe0 =
new TCanvas(
"callbe0",
"Leadings vs widths (slewing T0, peak 1)", 900, 700);
3867 callbe0->
Divide(NDX, NDY);
3871 gPad->AddExec(
"exselt",
"select_hist()");
3874 TCanvas* callbe01 =
new TCanvas(
"callbe01",
"Leadings vs widths (slewing T0, peak 2)", 900, 700);
3876 callbe01->
Divide(NDX, NDY);
3880 gPad->AddExec(
"exselt",
"select_hist()");
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!");
3897 if (strstr(geomfile,
"_run8"))
3899 if (is8 == 1 &&
fPeriod < 8) {
3900 LOGF(error,
"Geometry file for period 8, but init for period %d !",
fPeriod);
3902 }
else if (is8 == 0 &&
fPeriod == 8) {
3903 LOGF(error,
"Geometry file for early period (%s), but init for period 8 !", geomfile);
3908 fg = fopen(fname,
"r");
3910 LOGF(error,
"TOF700 geometry file %s open error!", fname);
3913 if (!fgets(line1,
sizeof(line1), fg)) {
3914 LOGF(error,
"TOF700 geometry file %s - first line read error!", fname);
3919 LOGF(error,
"Wrong first line (not 3 numbers) in TOF700 geometry file %s", fname);
3925 LOGF(error,
"Wrong first line (not 4 numbers) in TOF700 geometry file %s", fname);
3928 LOGF(debug,
"Loading TOF700 geometry from file %s", geomfile);
3931 while (fscanf(fg,
"%f %d %f %f %f %f %f %f\n", &ic, &
n, &step, &sy, &sx, &x, &y, &z) == 8) {
3942 for (
int ns =
n - 1; ns >= 0; ns--) {
3947 ycens[
i][ns] = y / 10. +
yoffs - (
n - ns - 1) * step / 10.;
3961 LOGF(error,
"Geometry for %d chambers only!", nf);
3969 *x =
xcens[chamber][strip];
3970 *y =
ycens[chamber][strip];
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++) {
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,
4024 if (strlen(offsetsfile) == 0) {
4025 LOGF(error,
"TOF700 Left-Right offsets file name not defined!");
4030 fg = fopen(fname,
"r");
4032 LOGF(error,
"TOF700 Left-Right offsets file %s open error!", fname);
4035 LOGF(debug,
"Loading TOF700 Left-Right offsets from file %s", offsetsfile);
4036 float idchamber, lroff;
4037 int ip, is, lrsig,
n = 0;
4039 fscanf(fg,
"Chamber %d (%f) strip %d offset %f time bins, direction %d\n", &ip, &idchamber, &is, &lroff, &lrsig)
4043 LOGF(error,
"L-R offsets: Chamber number %d >= %d, skip!", ip,
MaxPlane);
4051 LOGF(error,
"L-R offsets: Chamber ID %.1f != %.1f, skip!", idchamber,
idchambers[ip]);
4059 LOGF(debug,
"Read %d left-right offsets.",
n);
4065 float x = 0., dx = 0.;
4066 if (chamber <
MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4068 x =
xcens[chamber][strip] +
lrsign[chamber][strip] * dx;
4076 float x = 0., dx = 0.;
4077 if (chamber <
MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4079 x =
xcens[chamber][strip] +
lrsign[chamber][strip] * dx;
4096 return diff_corrected;
4103 float xh = 0., dxh = 0.;
4104 if (chamber <
MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4106 xh =
xcens[chamber][strip] +
lrsign[chamber][strip] * dxh;
4108 *y =
ycens[chamber][strip];
4117 float xh = 0., dxh = 0.;
4118 if (chamber <
MaxPlane && strip < TOF2_MAX_STRIPS_IN_CHAMBER && fVelosity > 7.f) {
4120 xh =
xcens[chamber][strip] +
lrsign[chamber][strip] * dxh;
4122 *y =
ycens[chamber][strip];
4134 float xoff, xslop, yoff, yslop, yofferr, ysloperr;
4137 if (strlen(xcalibrationfile) == 0) {
4138 LOGF(error,
"TOF700 X calibration file name not defined!");
4143 fg = fopen(fname,
"r");
4145 LOGF(error,
"TOF700 X calibration file %s open error!", fname);
4148 LOGF(debug,
"Loading TOF700 X calibration from file %s", xcalibrationfile);
4150 while (fscanf(fg,
"%d %d %f %f\n", &ip, &is, &xoff, &xslop) == 4) {
4152 LOGF(error,
"X calibration: Chamber number %d >= %d, skip!", ip,
MaxPlane);
4164 LOGF(debug,
"Read X calibration for %d strips.",
n);
4167 if (strlen(ycalibrationfile) == 0) {
4168 LOGF(error,
"TOF700 Y calibration file name not defined!");
4171 dir =
TString::Format(
"%s/geometry/%s", getenv(
"VMCWORKDIR"), ycalibrationfile);
4173 fg = fopen(fname,
"r");
4175 LOGF(error,
"TOF700 Y calibration file %s open error!", fname);
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) {
4181 LOGF(error,
"Y calibration: Chamber number %d >= %d, skip!", ip,
MaxPlane);
4189 LOGF(debug,
"Read Y calibrations for %d chambers.",
n);
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);
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);
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]);
4218 while (fscanf(fcaly,
" %d %d %f\n", &ip, &is, &
shifty[ip][is]) == 3) {
4222 LOGF(debug,
" Read TOF700 X calibration parameters - %d strips", nx);
4223 LOGF(debug,
" Read TOF700 Y calibration parameters - %d strips", ny);
4243 float xh = 0., yh = 0.;
4245 &&
yslope[chamber] != 0.)
4273 float xh = 0., yh = 0.;
4275 &&
shifty[chamber][strip] != 0.)
4278 yh =
shifty[chamber][strip] +
ycens[chamber][strip];
4303 float xh = 0., yh = 0.;
4305 &&
shifty[chamber][strip] != 0.)
4308 yh =
shifty[chamber][strip] +
ycens[chamber][strip];
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];
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];
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];
vector< Double_t > W(vector< Double_t > dist, Double_t sig)
#define MAX_RAW_TRAILING_TIME
#define MIN_RAW_LEADING_TIME
#define DEBUG_EQUALIZATION
#define PRINT_EQUALIZATION_RESULTS
#define PRELIMINARY_OFFSETS
#define PRINT_FIT_RESULTS
#define TIME_LIMITS_VS_WIDTH
#define USE_PRELIMINARY_OFFSETS
int champosn[TOF2_MAX_CHAMBERS]
#define PRINT_EQUALIZATION0_RESULTS
#define MIN_RAW_TRAILING_TIME
#define PRINT_TIME_LIMITS
#define MAX_RAW_LEADING_TIME
#define USE_FINAL_OFFSETS
#define DEBUG_EQUALIZATION0
#define TOF2_MAX_STRIPS_IN_CHAMBER
#define TOF2_MAX_CHAMBERS
#define TOF2_MAX_SLOTS_IN_CRATE
#define TOF2_MAX_CHANNELS_IN_SLOT
void memset(T *dest, T i, size_t num)
Copy to memory block [@dest, @dest+@num] num number of times the value of i of type @T with size @typ...
friend F32vec4 fabs(const F32vec4 &a)
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
const uint32_t kTDC64VHLE
const uint32_t kTDC64VHLE_E
UChar_t GetHptdcId() const
UChar_t GetChannel() const
Bool_t GetLeading() const
TProfile2D * TvsW[TOF2_MAX_CHAMBERS][4]
int Wcutc[TOF2_MAX_CHAMBERS]
void fillEvent(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width, TClonesArray *tof2digit)
float ycens[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
void getEventInfo(long long *ev, long long *t1, long long *t2)
float slopexl[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
float get_hit_diff(int chamber, int strip, float diff_corrected)
int idcrates[TOF2_MAX_CRATES]
float halfywidth[TOF2_MAX_CHAMBERS]
int devnum[TOF2_MAX_CRATES *TOF2_MAX_SLOTS_IN_CRATE]
int readXYCalibrationNew(char *xcalibration, char *ycalibration)
int numstrip[TOF2_MAX_CHAMBERS]
int readXYCalibration(char *xcalibration, char *ycalibration)
int devcrate[TOF2_MAX_CRATES *TOF2_MAX_SLOTS_IN_CRATE]
TH2F * TvsS[TOF2_MAX_CHAMBERS]
float interxl[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
int readGeom(const char *geomFile)
void get_hit_xyzp(int chamber, int strip, float diff, float *x, float *y, float *z)
int chamber_slewing[TOF2_MAX_CHAMBERS]
float xcens[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
int LeadMin[TOF2_MAX_CHAMBERS]
TH2F * TvsWt0p[TOF2_MAX_CHAMBERS][4]
virtual ~BmnTof2Raw2DigitNew()
double Toffsets00n[TOF2_MAX_CHANNEL]
void readSlewing(Bool_t update=false)
int get_strip_xyz(int chamber, int strip, float *x, float *y, float *z)
float xmaxs[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
float get_hit_xp(int chamber, int strip, float diff)
TH2F * TvsWall[TOF2_MAX_CHAMBERS]
float zchamb[TOF2_MAX_CHAMBERS]
void WritePreparationHists()
void BookSlewingResults()
float xmins[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
float yslope[TOF2_MAX_CHAMBERS]
int get_ch_tdc72vhl(unsigned int tdc, unsigned int ch)
int nrec[TOF2_MAX_CRATES][TOF2_MAX_SLOTS_IN_CRATE][TOF2_MAX_CHANNELS_IN_SLOT]
int numcrates[TOF2_MAX_CRATES]
float lroffsets[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
void fillSlewing(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
float halfxwidth[TOF2_MAX_CHAMBERS]
float get_hit_diff0(int chamber, int strip, float diff)
int devslot[TOF2_MAX_CRATES *TOF2_MAX_SLOTS_IN_CRATE]
float xoffset[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
int numcha[TOF2_MAX_CHAMBERS]
TH2F * TvsWallmax[TOF2_MAX_CHAMBERS]
float get_hit_xnl(int chamber, int strip, float diff)
char dnlname[TOF2_MAX_CRATES][TOF2_MAX_SLOTS_IN_CRATE][128]
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 numcr[TOF2_MAX_CRATES *TOF2_MAX_SLOTS_IN_CRATE]
int readLRoffsets(char *LRoffsetsFile)
float xslope[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
int LeadMaxW[TOF2_MAX_CHAMBERS][500]
void WritePreparationHists0()
TString fPreparationFileName
float get_hit_x(int chamber, int strip, float diff_corrected)
float ymins[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
void get_hit_xyzng(int chamber, int strip, float diff, float *x, float *y, float *z)
int numslots[TOF2_MAX_CRATES *TOF2_MAX_SLOTS_IN_CRATE]
Bmn_Tof2_map_element_new mapa[TOF2_MAX_CHANNEL]
float slopexg[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
char filname_slewing[TOF2_MAX_CHAMBERS][256]
void WriteSlewingResults()
int dnltype[TOF2_MAX_CRATES][TOF2_MAX_SLOTS_IN_CRATE]
void fillEqualization(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
unsigned devser[TOF2_MAX_CRATES][TOF2_MAX_SLOTS_IN_CRATE]
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)
float ymaxs[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
void fillSlewingT0(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
void writeSlewingLimits()
char filname_base_results[256]
TH2F * WvsS[TOF2_MAX_CHAMBERS]
float idchambers[TOF2_MAX_CHAMBERS]
void fillPreparation(TClonesArray *data, unordered_map< UInt_t, Long64_t > *ts, Double_t t0, Double_t t0width)
double chtima[10][25][64]
int lrsign[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
double Toffsets00[TOF2_MAX_CHANNEL]
void SetLeadMinMax(int c, int leadmin, int leadmax)
float interxg[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
float yoffset[TOF2_MAX_CHAMBERS]
TProfile * TvsWr[TOF2_MAX_CHAMBERS][4]
float shifty[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
int get_chamber_z(int chamber, float *z)
double DNL_Table[TOF2_MAX_CRATES][TOF2_MAX_SLOTS_IN_CRATE][72][1024]
int Wmaxc[TOF2_MAX_CHAMBERS]
int nstrips[TOF2_MAX_CHAMBERS]
TProfile * TvsWt0r[TOF2_MAX_CHAMBERS][4]
TH2F * TvsWp[TOF2_MAX_CHAMBERS][4]
void get_hit_xyznl(int chamber, int strip, float diff, float *x, float *y, float *z)
TH2F * TvsSm[TOF2_MAX_CHAMBERS][4]
int get_track_hits(float *xyz, float *cxyy, int *nhits, int *chamb, int *strip)
int LeadMinW[TOF2_MAX_CHAMBERS][500]
int type_slewing[TOF2_MAX_CHAMBERS]
TProfile2D * TvsWt0[TOF2_MAX_CHAMBERS][4]
int LeadMax[TOF2_MAX_CHAMBERS]
void SetSlewingReference(Int_t chamber, Int_t refrun, Int_t refchamber)
float get_hit_xng(int chamber, int strip, float diff)
double Toffsets00e[TOF2_MAX_CHANNEL]
virtual void SetLineColor(Color_t lcolor)
virtual void SetRange(Int_t first=0, Int_t last=0)
TVirtualPad * cd(Int_t subpadnumber=0) override
virtual Int_t GetEntries() const
T * Get(const char *namecycle)
virtual Double_t GetParameter(const TString &name) const
virtual Double_t * GetParameters() const
virtual void SetParameters(const Double_t *params)
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
void Close(Option_t *option="") override
virtual void Smooth(Int_t ntimes=1, Option_t *option="")
virtual Double_t GetBinCenter(Int_t bin) const
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
virtual Int_t GetNbinsX() const
virtual void SetMaximum(Double_t maximum=-1111)
virtual void SetBinError(Int_t bin, Double_t error)
void Draw(Option_t *option="") override
virtual void SetMinimum(Double_t minimum=-1111)
virtual void SetBinContent(Int_t bin, Double_t content)
virtual Double_t GetEntries() const
virtual TF1 * GetFunction(const char *name) const
TList * GetListOfFunctions() const
virtual Int_t GetMaximumBin() const
virtual Double_t GetBinContent(Int_t bin) const
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
virtual void SetStats(Bool_t stats=kTRUE)
TH1D * ProjectionY(const char *name="_py", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const
virtual void FitSlicesY(TF1 *f1=nullptr, Int_t firstxbin=0, Int_t lastxbin=-1, Int_t cut=0, Option_t *option="QNR", TObjArray *arr=nullptr)
void SetBinContent(Int_t bin, Double_t content) override
virtual Double_t GetBinContent(Int_t bin) const
TObject * At(Int_t idx) const override
const char * GetName() const override
const char * GetTitle() const override
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
virtual void Draw(Option_t *option="")
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
TObject * WaitPrimitive(const char *pname="", const char *emode="") override
TProfile * ProfileX(const char *name="_pfx", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="") const
Double_t GetBinContent(Int_t bin) const override
virtual void SetBinEntries(Int_t bin, Double_t w)
virtual Double_t GetBinEntries(Int_t bin) const
Double_t GetBinError(Int_t bin) const override
const char * Data() const
static TString Format(const char *fmt,...)
*brief user defined string literal for JSON values *sa std::size_t n