92 UInt_t SlewingChamber,
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)
'.')))
105 strcpy(filname_base_results, filname_base);
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();
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());
128 fSlewCham = SlewingChamber;
130 if (SlewingRun > 0) {
131 fSlewRun = SlewingRun;
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) {
140 fSlewRun = SlewingRun;
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)
169 strcpy(&filname_slewing[
i][0], filname_base);
170 chamber_slewing[
i] = fSlewCham;
177 int crate, slot, chan, plane , filetype, cham, cable;
192 in >> dummy >> dummy;
193 for (
int i = 0;
i < ncrates;
i++) {
194 in >> std::dec >> crate >> std::hex >> id_crate;
199 numcrates[
i] = crate;
200 idcrates[crate] = id_crate;
205 in >> std::dec >> nslots;
207 in >> dummy >> dummy >> dummy >> dummy >> dummy;
210 for (
int i = 0;
i < (nslots + 1);
i++) {
211 in >> crate >> slot >> std::hex >> devsernum >> std::dec >> filetype >> dnlfile;
219 devser[crate][slot] = devsernum;
220 devnum[
i] = 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);
239 for (
int i = 0;
i < nchambers;
i++) {
240 in.getline(line, 128);
242 sscanf(line,
"%d\t\t%f\n", &cham, &idcham);
249 idchambers[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++) {
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;
292 for (
int ie = 1; ie <= 2; ie++) {
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;
307 }
else if (cable == 1) {
308 for (
int ie = 1; ie <= 2; ie++) {
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;
323 }
else if (cable == 2) {
324 for (
int ie = 1; ie <= 2; ie++) {
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;
344 LOGF(error,
"Wrong cable flag, line is %s", line);
349 if (plane > MaxPlane)
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.;
370 lroffsets[c][
i] = 0.;
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===========================================================================");
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]]);
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]]);
417 LOGF(debug,
"===========================================================================");
419 "#\tcrate\tslot\tdevsernum\tfiletype\tfile\n==========================================================="
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]]);
425 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);
435 LOGF(debug,
"===========================================================================");
441 for (
int j = 0; j < 72; j++)
442 for (
int k = 0; k < 1024; k++)
443 DNL_Table[c][
i][j][k] = 0.;
457 for (
int j = 0; j < 500; j++)
458 LeadMinW[
i][j] = -5000;
460 for (
int j = 0; j < 500; j++)
461 LeadMaxW[
i][j] = +5000;
501 for (
int ir = 0; ir < 4; ir++) {
511 fPreparationFileName =
"";
665 char name[128], title[128];
667 gStyle->SetOptFit(111);
668 gStyle->SetOptStat(111111);
670 TString dir = getenv(
"VMCWORKDIR");
671 TString path = dir +
"/parameters/tof2_slewing/";
673 sprintf(filnr,
"%s%s", path.Data(), filname_base);
674 strcat(filnr,
".slewing.root");
675 fSlewing =
new TFile(filnr,
"RECREATE");
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");
695 H1chambrate =
new TH1F(name, title, 150, 0, 150);
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);
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);
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);
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);
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);
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);
751 2 * (LeadMax[
i] - LeadMin[
i]), -(LeadMax[
i] - LeadMin[
i]), +(LeadMax[
i] - LeadMin[
i]));
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");
767 for (
int i = 0;
i < MaxPlane;
i++) {
768 pLeadMin->Fill(
i, LeadMin[
i]);
769 pLeadMax->Fill(
i, LeadMax[
i]);
771 sprintf(name,
"Time_offsets0");
772 sprintf(title,
"Time offsets0");
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]);
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);
791 char name[128], title[128];
793 gStyle->SetOptFit(111);
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);
813 Hchambrate->SetDirectory(0);
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);
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);
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);
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);
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);
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);
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);
1127 LOGF(info,
"\t\tTOF2.SetWT0(%d,%d);", WT0min, WT0max);
1128 for (
i = 0;
i < MaxPlane;
i++) {
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);
1142 if (fPreparationFileName ==
"") {
1143 sprintf(filn,
"%s%s", path.Data(), filname_base);
1144 strcat(filn,
"_preparation.root");
1146 sprintf(filn,
"%s%s", path.Data(), fPreparationFileName.Data());
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]);
1186 tim = hs->ProjectionY();
1187 im = tim->GetMaximumBin();
1188 y = (int)(tim->GetBinCenter(im));
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));
1210 if (idchambers[plane] == 18.2f &&
false) {
1211 TCanvas* c =
new TCanvas(
"c",
"c", 800, 900);
1219 gPad->WaitPrimitive();
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;
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");
1251 prof = (TProfile*)(fPreparation->Get(name));
1253 LOGF(error,
"Error input TOffsets0 slewing profile!");
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);
1264 fPreparation->Close();
1272 TProfile *prof1 = 0, *prof2 = 0;
1273 TProfile2D* prof = 0;
1275 TString dir = getenv(
"VMCWORKDIR");
1276 TString path = dir +
"/parameters/tof2_slewing/";
1278 char filnr[512], name[256];
1279 sprintf(filnr,
"%s%s", path.Data(), filname_base);
1280 strcat(filnr,
".slewing.root");
1282 fSlewing =
new TFile(filnr,
"UPDATE");
1284 fSlewing =
new TFile(filnr,
"READ");
1286 if (fSlewing->IsZombie()) {
1290 LOGF(error,
"Error open slewing file %s, work without slewing corrections!", filnr);
1292 }
else if (fSlewRun > 0) {
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++) {
1306 planer = fSlewCham - 1;
1307 if (chamber_slewing[plane] > 0)
1308 planer = chamber_slewing[plane] - 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));
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);
1320 prof = (TvsW[planer][region] = (TProfile2D*)fSlewing->Get(name));
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);
1329 plot = (TvsSm[planer][region] = (TH2F*)fSlewing->Get(name));
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);
1340 prof1 = (Toffsets[region] = (TProfile*)fSlewing->Get(name));
1342 LOGF(error,
"Error input TOffsets slewing profile for region %d!", region + 1);
1345 sprintf(name,
"Time_fit_offsets_region_%d", region + 1);
1346 prof1 = (Toffsetsf[region] = (TProfile*)fSlewing->Get(name));
1348 LOGF(error,
"Error input TOffsets fit slewing profile for region %d!", region + 1);
1353 sprintf(name,
"Time_offsets0");
1354 prof1 = (Toffsets0 = (TProfile*)(fSlewing->Get(name)));
1356 LOGF(error,
"Error input TOffsets0 slewing profile!");
1359 sprintf(name,
"Time_Lead_Min");
1360 prof1 = (pLeadMin = (TProfile*)(fSlewing->Get(name)));
1362 LOGF(error,
"Error input Time_Lead_Min hist!");
1365 sprintf(name,
"Time_Lead_Max");
1366 prof2 = (pLeadMax = (TProfile*)(fSlewing->Get(name)));
1368 LOGF(error,
"Error input Time_Lead_Max hist!");
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));
1379 sprintf(name,
"Wlimits");
1381 TH1F* hW = (TH1F*)(fSlewing->Get(name));
1383 printf(
"Error input Wlimits hist!\n");
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);
1395 LOGF(info,
"\t\tTOF2.SetWT0(%d,%d);", wt0mi, wt0ma);
1452 unordered_map<UInt_t, Long64_t>* ts,
1456 Long64_t ts_diff = 0L;
1457 Bool_t islead =
false;
1458 unsigned rawtime = 0;
1465 for (
int i = 0;
i < data->GetEntriesFast();
i++) {
1470 if (fPeriod == 8 && fSRC == 0) {
1487 if ((fPeriod == 8 && fSRC == 0) || type == 0)
1499 int nc = -1, ind = 0, crate = -1, slot = 0;
1500 if (fPeriod < 8 || fSRC != 0) {
1501 nc = numcrate((digit->
GetSerial()) & 0xFFFFFF);
1504 ind = nrec[nc][digit->
GetSlot()][chan];
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) {
1521 crate = devcrate[idev];
1522 slot = devslot[idev];
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)
1569 for (
int i = 0;
i < MaxPlane;
i++)
1571 for (
int i = 0;
i < MaxPlane;
i++)
1573 for (
int i = 0;
i < MaxPlane;
i++)
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) {
1582 if (idchambers[mapa[ind].plane] < 100.f)
1585 if (idchambers[mapa[ind].plane] > 100.f)
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]);
1600 H1chambrate->Fill(70.f);
1601 if (idchambers[mapa[ind].plane] < 100.f && idchambers[mapa[ind].plane] != 19.3f) {
1604 Hchambrate->Fill(x, y);
1605 Hstriprate->Fill(x, y);
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);
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);
1623 for (
int i = 0;
i < MaxPlane;
i++) {
1625 TvsWallmax[
i]->Fill(wmaxs[
i], tmaxs[
i]);
1631 unordered_map<UInt_t, Long64_t>* ts,
1635 if (fPeriod == 8 && fSRC == 0)
1636 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN >
MAX_RAW_T0_TIME)
1638 Long64_t ts_diff = 0L;
1639 Bool_t islead =
false;
1640 unsigned rawtime = 0;
1645 for (
int i = 0;
i < data->GetEntriesFast();
i++) {
1649 if (fPeriod == 8 && fSRC == 0) {
1667 if ((fPeriod == 8 && fSRC == 0) || type == 0)
1681 int nc = -1, ind = 0, crate = -1, slot = 0;
1682 if (fPeriod < 8 || fSRC != 0) {
1683 nc = numcrate((digit->
GetSerial()) & 0xFFFFFF);
1686 ind = nrec[nc][digit->
GetSlot()][chan];
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) {
1703 crate = devcrate[idev];
1704 slot = devslot[idev];
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)
1749 for (
int i = 0;
i < MaxPlane;
i++)
1751 for (
int i = 0;
i < MaxPlane;
i++)
1753 for (
int i = 0;
i < MaxPlane;
i++)
1755 for (
int i = 0;
i < MaxPlane;
i++)
1757 for (
int ind = 0; ind < n_rec; ind++) {
1758 int ind1 = mapa[ind].
pair;
1761 if (lead[ind1] == 0 || trail[ind1] == 0)
1763 if (numstrip[mapa[ind].plane] >= 0 && numstrip[mapa[ind].plane] != mapa[ind].strip)
1765 if (lead[ind] != 0 && trail[ind] != 0) {
1766 if (idchambers[mapa[ind].plane] < 100.f)
1769 if (idchambers[mapa[ind].plane] > 100.f)
1773 if (Wcutc[mapa[ind].plane] >= 0.)
1774 Wc = Wcutc[mapa[ind].
plane];
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)
1786 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
1788 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
1790 }
else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
1798 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
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;
1818 TvsWt0[mapa[ind].plane][ira]->Fill(t0width *
INVHPTIMEBIN, mapa[ind].strip, L);
1834 unordered_map<UInt_t, Long64_t>* ts,
1838 if (fPeriod == 8 && fSRC == 0)
1839 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN >
MAX_RAW_T0_TIME)
1841 Long64_t ts_diff = 0L;
1842 Bool_t islead =
false;
1843 unsigned rawtime = 0;
1848 for (
int i = 0;
i < data->GetEntriesFast();
i++) {
1853 if (fPeriod == 8 && fSRC == 0) {
1869 if ((fPeriod == 8 && fSRC == 0) || type == 0)
1881 int nc = -1, ind = 0, crate = -1, slot = 0;
1882 if (fPeriod < 8 || fSRC != 0) {
1883 nc = numcrate((digit->
GetSerial()) & 0xFFFFFF);
1886 ind = nrec[nc][digit->
GetSlot()][chan];
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) {
1903 crate = devcrate[idev];
1904 slot = devslot[idev];
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)
1944 for (
int i = 0;
i < MaxPlane;
i++)
1946 for (
int i = 0;
i < MaxPlane;
i++)
1948 for (
int i = 0;
i < MaxPlane;
i++)
1950 for (
int i = 0;
i < MaxPlane;
i++)
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)
1961 if (numstrip[mapa[ind].plane] >= 0 && numstrip[mapa[ind].plane] != mapa[ind].strip)
1963 if (lead[ind] != 0 && trail[ind] != 0) {
1964 if (idchambers[mapa[ind].plane] < 100.f)
1967 if (idchambers[mapa[ind].plane] > 100.f)
1972 if (Wcutc[mapa[ind].plane] >= 0.)
1973 Wc = Wcutc[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.;
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)
1998 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
2000 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
2002 }
else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
2020 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction(
NSLFIT0)) != NULL) {
2024 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction(
"slew0")) != NULL) {
2025 strcpy(nfun0,
"slew0");
2030 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
2035 L -= TvsWt0[mapa[ind].plane][ira]->GetBinContent(
2036 TvsWt0[mapa[ind].plane][ira]->FindBin(t0width *
INVHPTIMEBIN, mapa[ind].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;
2047 TvsW[mapa[ind].plane][ira]->Fill(
W, mapa[ind].strip, L);
2056 TvsW[
i][rmax[
i]]->Fill(wmaxs[
i], smax[
i], tmaxs[
i]);
2063 unordered_map<UInt_t, Long64_t>* ts,
2066 TClonesArray* tof2digit)
2068 if (fPeriod == 8 && fSRC == 0)
2069 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN >
MAX_RAW_T0_TIME)
2072 Long64_t ts_diff = 0L;
2073 Bool_t islead =
false;
2074 unsigned rawtime = 0;
2083 for (
int i = 0;
i < data->GetEntriesFast();
i++) {
2087 if (fPeriod == 8 && fSRC == 0) {
2104 if ((fPeriod == 8 && fSRC == 0) || type == 0)
2118 int nc = -1, ind = 0, crate = -1, slot = 0;
2119 if (fPeriod < 8 || fSRC != 0) {
2120 nc = numcrate((digit->
GetSerial()) & 0xFFFFFF);
2123 ind = nrec[nc][digit->
GetSlot()][chan];
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) {
2142 crate = devcrate[idev];
2143 slot = devslot[idev];
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) {
2202 if (idchambers[mapa[ind].plane] < 100.f)
2205 if (idchambers[mapa[ind].plane] > 100.f)
2209 if (Wcutc[mapa[ind].plane] >= 0.)
2210 Wc = Wcutc[mapa[ind].
plane];
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.;
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) {
2240 if (idchambers[mapa[ind].plane] != 19.3f)
2241 H1chambrate->Fill(idchambers[mapa[ind].plane]);
2243 H1chambrate->Fill(70.f);
2245 if (idchambers[mapa[ind].plane] < 100.f && idchambers[mapa[ind].plane] != 19.3f) {
2248 Hchambrate->Fill(x, y);
2249 Hstriprate->Fill(x, y);
2257 int binw = (int)(
W / 50.f);
2258 if (binw < 0 || binw >= 500)
2260 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
2262 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
2264 }
else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
2273 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
2278 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction(
NSLFIT0)) != NULL) {
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");
2300 bin = TvsWt0[mapa[ind].plane][ira]->FindBin(t0width *
INVHPTIMEBIN, mapa[ind].strip);
2301 if (TvsWt0[mapa[ind].plane][ira]->GetBinError(bin) <= 0.f)
2305 L -= TvsWt0[mapa[ind].plane][ira]->GetBinContent(bin);
2308 TvsWt0r[mapa[ind].plane][ira]->Fill(t0width *
INVHPTIMEBIN, L);
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);
2321 TvsWr[mapa[ind].plane][ira]->Fill(
W, L);
2323 L -= Toffsets[ira]->GetBinContent(Toffsets[ira]->FindBin(ind));
2325 L -= Toffsetsf[ira]->GetBinContent(Toffsetsf[ira]->FindBin(ind));
2332 new ((*tof2digit)[tof2digit->GetEntriesFast()])
2341 unordered_map<UInt_t, Long64_t>* ts,
2345 if (fPeriod == 8 && fSRC == 0)
2346 if (t0 * INVHPTIMEBIN < MIN_RAW_T0_TIME || t0 * INVHPTIMEBIN >
MAX_RAW_T0_TIME)
2348 Long64_t ts_diff = 0L;
2349 Bool_t islead =
false;
2350 unsigned rawtime = 0;
2357 for (
int i = 0;
i < data->GetEntriesFast();
i++) {
2361 if (fPeriod == 8 && fSRC == 0) {
2378 if ((fPeriod == 8 && fSRC == 0) || type == 0)
2393 int nc = -1, ind = 0, crate = -1, slot = 0;
2394 if (fPeriod < 8 || fSRC != 0) {
2395 nc = numcrate((digit->
GetSerial()) & 0xFFFFFF);
2398 ind = nrec[nc][digit->
GetSlot()][chan];
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) {
2415 crate = devcrate[idev];
2416 slot = devslot[idev];
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) {
2474 if (idchambers[mapa[ind].plane] < 100.f)
2477 if (idchambers[mapa[ind].plane] > 100.f)
2482 if (Wcutc[mapa[ind].plane] >= 0.)
2483 Wc = Wcutc[mapa[ind].
plane];
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)
2507 if (LeadMinW[mapa[ind].plane][binw] == 0 || LeadMaxW[mapa[ind].plane][binw] == 0)
2509 if (L < LeadMinW[mapa[ind].plane][binw] || L >= LeadMaxW[mapa[ind].plane][binw])
2511 }
else if (L < LeadMin[mapa[ind].plane] || L >= LeadMax[mapa[ind].plane])
2516 if (idchambers[mapa[ind].plane] != 19.3f)
2517 H1chambrate->Fill(idchambers[mapa[ind].plane]);
2519 H1chambrate->Fill(70.f);
2520 if (idchambers[mapa[ind].plane] < 100.f && idchambers[mapa[ind].plane] != 19.3f) {
2523 Hchambrate->Fill(x, y);
2524 Hstriprate->Fill(x, y);
2529 L -= Toffsets0->GetBinContent(Toffsets0->FindBin(ind));
2532 if ((fun0 = TvsWt0[mapa[ind].plane][ira]->GetFunction(
NSLFIT0)) != NULL) {
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(
2555 TvsWt0[mapa[ind].plane][ira]->FindBin(t0width *
INVHPTIMEBIN, mapa[ind].strip));
2560 L -= TvsW[mapa[ind].plane][ira]->GetBinContent(
2561 TvsW[mapa[ind].plane][ira]->FindBin(
W, mapa[ind].strip));
2563 Toffsets[ira]->Fill(ind, L);
2564 TvsSm[mapa[ind].plane][ira]->Fill(mapa[ind].strip, L);
2577 TProfile2D* prof2d = 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};
2589 gROOT->ProcessLine(
"gErrorIgnoreLevel = 3001;");
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");
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;
2612 gPad->WaitPrimitive();
2618 for (
int i = 1;
i <= prof->GetNbinsX();
i++) {
2619 if (prof->GetBinContent(
i) != 0) {
2621 prof->SetBinContent(
i, 0);
2622 prof->SetBinEntries(
i, 0);
2623 prof->SetBinError(
i, 0);
2629 if (prof->GetBinContent(
i) > pmax)
2630 pmax = prof->GetBinContent(
i);
2631 if (prof->GetBinContent(
i) < pmin)
2632 pmin = prof->GetBinContent(
i);
2635 prof->SetBinContent(
i, 0);
2636 prof->SetBinEntries(
i, 0);
2637 prof->SetBinError(
i, 0);
2642 if (blast < prof->GetNbinsX())
2649 for (
int i = 1;
i <= prof->GetNbinsX();
i++) {
2650 if (prof->GetBinContent(
i) != 0) {
2655 if (nonzero > nonzeromax) {
2656 nonzeromax = nonzero;
2663 if (nonzero > nonzeromax) {
2664 nonzeromax = nonzero;
2665 blast = prof->GetNbinsX();
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));
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.)
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.)) {
2701 strcpy(nfun, nfunold);
2706 strcpy(nfun, nfunold);
2710 strcpy(nfunold, nfun);
2712 if (prof->GetFunction(nfun))
2713 if (result->IsValid() && result->Chi2() > 0.)
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.)
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());
2735 prof->GetXaxis()->SetRange(bfirstmax, blast);
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());
2751 prof->GetXaxis()->SetRange(bfirstmax, blast);
2752 prof->SetMaximum(pmax + (pmax - pmin) * 0.10);
2753 prof->SetMinimum(pmin - (pmax - pmin) * 0.10);
2760 TList* l = prof->GetListOfFunctions();
2761 int nf = l->GetEntries();
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++) {
2777 l = prof->GetListOfFunctions();
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,
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);
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);
2796 gPad->WaitPrimitive();
2805 for (
int i = 1;
i <= prof->GetNbinsX();
i++) {
2806 if (prof->GetBinContent(
i) != 0) {
2808 prof->SetBinContent(
i, 0);
2809 prof->SetBinEntries(
i, 0);
2810 prof->SetBinError(
i, 0);
2816 if (prof->GetBinContent(
i) > pmax)
2817 pmax = prof->GetBinContent(
i);
2818 if (prof->GetBinContent(
i) < pmin)
2819 pmin = prof->GetBinContent(
i);
2822 prof->SetBinContent(
i, 0);
2823 prof->SetBinEntries(
i, 0);
2824 prof->SetBinError(
i, 0);
2829 if (blast < prof->GetNbinsX())
2837 for (
int i = 1;
i <= prof->GetNbinsX();
i++) {
2838 if (prof->GetBinContent(
i) != 0) {
2843 if (nonzero > nonzeromax) {
2844 nonzeromax = nonzero;
2851 if (nonzero > nonzeromax) {
2852 nonzeromax = nonzero;
2853 blast = prof->GetNbinsX();
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);
2878 p[is]->SetLineColor(col[is]);
2881 prof->Fit(p[is],
"Q0R+");
2883 prof->Fit(p[is],
"Q0R+");
2884 if (prof->GetFunction(snam[is]))
2885 (prof->GetFunction(snam[is]))->ResetBit(TF1::kNotDraw);
2887 p[is]->GetParameters(&par[is * (subdeg + 1)]);
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);
2901 ptotal->SetLineColor(kBlack);
2904 ptotal->SetParameters(par);
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));
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))
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.)) {
2932 strcpy(nfun, nfunold);
2937 strcpy(nfun, nfunold);
2941 strcpy(nfunold, nfun);
2943 if (prof->GetFunction(nfun))
2944 if (result->IsValid() && result->Chi2() > 0.)
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.)
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());
2967 prof->GetXaxis()->SetRange(bfirstmax, blast);
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());
2982 prof->GetXaxis()->SetRange(bfirstmax, blast);
2983 prof->SetMaximum(pmax + (pmax - pmin) * 0.10);
2984 prof->SetMinimum(pmin - (pmax - pmin) * 0.10);
2989 TList* l = prof->GetListOfFunctions();
2990 int nf = l->GetEntries();
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++) {
3006 l = prof->GetListOfFunctions();
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,
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);
3025 gROOT->ProcessLine(
"gErrorIgnoreLevel = 1001;");
3034 fSlewing->Write(0, TObject::kOverwrite);
3045 char namp[64], namf[64];
3050 TString dir = getenv(
"VMCWORKDIR");
3051 TString path = dir +
"/parameters/tof2_slewing/";
3053 sprintf(filn,
"%s%s", path.Data(), filname_base);
3054 strcat(filn,
".equalization.log");
3055 fout = fopen(filn,
"w");
3057 sprintf(filn,
"%s%s", path.Data(), filname_base);
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",
3067 filname_base, plane + 1, pk + 1);
3070 "**************** %s Chamber %d Peak %d Time-Width area slewing *******************************\n\n",
3071 filname_base, plane + 1, pk + 1);
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);
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);
3095 double sum = 0., sumx = 0.;
3096 for (
int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin);
3099 if (proj->GetBinContent(ib) > 0.) {
3101 sum += proj->GetBinContent(ib);
3102 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(ib);
3107 if (
FIT_MAXIMA && zflag == 0 && nonzero >= 5) {
3108 sprintf(namf,
"gaus%dstrip%d", ip + 1, is + 1);
3111 proj->Fit(namf,
"QR0");
3112 if (!(proj->GetFunction(namf))) {
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]);
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]);
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);
3141 if (proj->GetBinContent(ib) > 0.) {
3142 sum += proj->GetBinContent(ib);
3143 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(ib);
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]);
3161 if (proj->GetEntries()) {
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]);
3223 fSlewing->Write(0, TObject::kOverwrite);
3237 TH1D *proj = 0, *hmain = 0;
3239 char namp[64], namf[64];
3244 TString dir = getenv(
"VMCWORKDIR");
3245 TString path = dir +
"/parameters/tof2_slewing/";
3247 sprintf(filn,
"%s%s", path.Data(), filname_base);
3248 strcat(filn,
".equalization0.log");
3249 fout = fopen(filn,
"w");
3251 sprintf(filn,
"%s%s", path.Data(), filname_base);
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",
3260 filname_base, plane + 1);
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);
3285 int nbin = proj->GetNbinsX();
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);
3293 int mbin = proj->GetMaximumBin();
3294 mpos = proj->GetBinCenter(mbin);
3295 ncon = proj->GetBinContent(mbin);
3300 double sum = 0., sumx = 0.;
3301 for (
int ib = ((mbin - 6) > 0 ? (mbin - 6) : 1); ib < ((mbin + 6) < nbin ? (mbin + 6) : nbin); ib++)
3303 if (proj->GetBinContent(ib) > 0.) {
3305 sum += proj->GetBinContent(ib);
3306 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(ib);
3312 sprintf(namf,
"gaus%dstrip%d", ip + 1, is + 1);
3315 proj->Fit(namf,
"QR0");
3316 if (!(proj->GetFunction(namf))) {
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]);
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]);
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++)
3344 if (proj->GetBinContent(ib) > 0.) {
3345 sum += proj->GetBinContent(ib);
3346 sumx += proj->GetBinContent(ib) * proj->GetBinCenter(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]);
3365 if (proj->GetEntries()) {
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]);
3625 if (MaxPlane == 15) {
3626 int champos[] = {5, 10, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 0};
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};
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);
3654 TCanvas* cp =
new TCanvas(
"cp",
"Leadings vs strip", 900, 700);
3656 cp->Divide(NDX, NDY);
3657 for (
i = 0;
i < MaxPlane;
i++) {
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);
3671 l->SetLineColor(kRed);
3672 l =
new TLine(xmin, ymax, xmax, ymax);
3674 l->SetLineColor(kRed);
3680 TCanvas* cpp =
new TCanvas(
"cpp",
"Leadings", 900, 700);
3682 cpp->Divide(NDX, NDY);
3683 for (
i = 0;
i < MaxPlane;
i++) {
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);
3697 l->SetLineColor(kRed);
3698 l =
new TLine(ymax, xmin, ymax, xmax);
3700 l->SetLineColor(kRed);
3703 TCanvas* cpw =
new TCanvas(
"cpw",
"Widths vs strip", 900, 700);
3705 cpw->Divide(NDX, NDY);
3706 for (
i = 0;
i < MaxPlane;
i++) {
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);
3718 l->SetLineColor(kRed);
3719 l =
new TLine(xmin, ymax, xmax, ymax);
3721 l->SetLineColor(kRed);
3724 TCanvas* cpwp =
new TCanvas(
"cpwp",
"Widths", 900, 700);
3726 cpwp->Divide(NDX, NDY);
3727 for (
i = 0;
i < MaxPlane;
i++) {
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);
3739 l->SetLineColor(kRed);
3740 l =
new TLine(ymax, xmin, ymax, xmax);
3742 l->SetLineColor(kRed);
3745 TCanvas* cpt0 =
new TCanvas(
"cpt0",
"T0 hists", 900, 700);
3750 gPad->AddExec(
"exselt",
"select_hist()");
3754 ymax = Wt0->GetMaximum();
3755 l =
new TLine(xmin, ymin, xmin, ymax);
3757 l->SetLineColor(kRed);
3758 l =
new TLine(xmax, ymin, xmax, ymax);
3760 l->SetLineColor(kRed);
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);
3776 cp1->Divide(NDX, NDY);
3777 for (
i = 0;
i < MaxPlane;
i++) {
3780 gPad->AddExec(
"exselt",
"select_hist()");
3783 TCanvas* cp2 =
new TCanvas(
"cp2",
"Leadings vs widths (max strip)", 900, 700);
3786 cp2->Divide(NDX, NDY);
3787 for (
i = 0;
i < MaxPlane;
i++) {
3789 TvsWallmax[
i]->Draw();
3790 gPad->AddExec(
"exselt",
"select_hist()");