9 #include <TGraphAsymmErrors.h>
20 #define IDMVTXV1_MAXRUID 4
21 #define IDMVTXV1_MAXRUCHN 28
33 string outHitLocations =
"/home/maps/meeg/felix/daq/felix_rcdaq/online_monitoring/hitLocations/locations.txt";
36 map<pair<int,int>,pair<int,int>>
chipmap = {
128 int chipMarker[] = {kFullCircle, kFullSquare, kFullDiamond, kFullCross};
173 hnevnt =
new TH1F(
"hnevent",
"", 1, -0.5, 0.5);
176 hchip =
new TH1F(
"hchip",
";chip index;N pixels", 4, -0.5, 3.5);
177 hchip->SetLineWidth(2);
178 hchip->SetLineColor(kBlue);
181 hwarn =
new TH1F(
"hwarn",
";chip index; warnings", 4, -0.5, 3.5);
182 hwarn->SetLineWidth(2);
183 hwarn->SetLineColor(kYellow+2);
186 herr =
new TH1F(
"herr",
";chip index; errors", 4, -0.5, 3.5);
187 herr->SetLineWidth(2);
188 herr->SetLineColor(kRed);
194 sprintf(name,
"hnhit_chip_%i",
i);
195 hnhit_chip[
i] =
new TH1F(name,
";N pixels / event; events", 201, -0.5, 200.5);
200 sprintf(name,
"hhittime_chip_%i", i);
201 hhittime_chip[
i] =
new TH1F(name,
";N pixels / 100 events; event number", 100, 0, 10000);
206 sprintf(name,
"h2d_chip_%i", i);
207 h2d_chip[
i] =
new TH2F(name,
";col;row;hits", 9216, -0.5, 9215.5, 512, -0.5, 511.5);
210 sprintf(name,
"gmpos_chip_%i", i);
218 sprintf(name,
"hdiffrow_chip_%i", i);
219 hdiffrow_chip[
i] =
new TH1F(name,
";row index diff", 1023, -511.5, 511.5);
223 sprintf(name,
"hdiffcol_chip_%i", i);
224 hdiffcol_chip[
i] =
new TH1F(name,
";col index diff", 1023, -511.5, 511.5);
236 ";chip index; N pixels / event",
237 NSTAVE, -0.5, NSTAVE-0.5);
242 ";N pixels / event; per event",
254 haxis_2d->GetYaxis()->SetLabelOffset(999);
255 haxis_2d->GetYaxis()->SetTickLength(0);
260 1023, -511.5, 511.5);
274 if (!
fg)
fg =
new TF1(
"fg",
"gaus", 0, 1024);
292 bool evnt_err =
false;
392 int npixels[
NSTAVE] = {0};
393 double mrow[
NSTAVE] = {0};
394 double mcol[
NSTAVE] = {0};
395 double mrow_refstave = -1;
396 double mcol_refstave = -1;
405 if (p->
iValue(ruid,ruchn)>0)
407 for (
int i=0;
i<p->
iValue(ruid,ruchn);
i++)
409 int hit = p->
iValue(ruid,ruchn,
i);
414 if (
chipmap.count({ruid,ruchn}) != 1) {
415 cout <<
"invalid: (ruid " << ruid <<
", ruchn " << ruchn <<
") " << endl;
417 pair<int, int> chiplocation =
chipmap[{ruid,ruchn}];
418 int istave = chiplocation.first;
419 int ichip = chiplocation.second;
423 mcol[istave]+=icol+1024*ichip;
425 h2d_chip[istave]->Fill(icol+1024*ichip,irow);
428 h2d_chip[istave]->Fill(icol+1024*ichip,511-irow);
441 for (
int istave=0;istave<
NSTAVE;istave++) {
442 if (npixels[istave] > 0 && npixels[istave] <
max_npixels)
444 mrow[istave] /= (float)npixels[istave];
445 mcol[istave] /= (float)npixels[istave];
447 hchip->Fill(istave, npixels[istave]);
452 cout <<
" chip:" << istave <<
" npixels:" << npixels[istave]
453 <<
" mean:(" << mcol[istave] <<
", " << mrow[istave] <<
")" << endl;
457 if ( npixels[NSTAVE-1] > 0 && npixels[NSTAVE-1] <
max_npixels )
459 mrow_refstave = mrow[NSTAVE-1];
460 mcol_refstave = mcol[NSTAVE-1];
461 for (
int istave=0;istave<
NSTAVE;istave++) {
462 if (npixels[istave] > 0 && npixels[istave] <
max_npixels)
464 if ( mrow_refstave >= 0 && mcol_refstave >= 0 )
516 cout <<
" processing event " <<
mvtx_evnts << endl;
531 cout <<
"-- stave " <<
i << endl;
533 for (
int ix = 1; ix <=
h2d_chip[
i]->GetNbinsX(); ix++)
535 for (
int iy = 1; iy <=
h2d_chip[
i]->GetNbinsY(); iy++)
537 if (
h2d_chip[
i]->GetBinContent(ix, iy) > thresh )
542 row = 1023-(
h2d_chip[
i]->GetYaxis()->GetBinCenter(iy));
545 row =
h2d_chip[
i]->GetYaxis()->GetBinCenter(iy);
547 col =
h2d_chip[
i]->GetXaxis()->GetBinCenter(ix);
548 cout <<
" row:" << row
554 cout <<
"Total: " << tot << endl;
567 string file_name_tb1 =
"/home/maps/git/RUv1_Test_sync2018-08/software/py/masklist_testbench1.txt";
568 string file_name_tb2 =
"/home/maps/git/RUv1_Test_sync2018-08/software/py/masklist_testbench2.txt";
569 ofstream write_mask_file_tb1(file_name_tb1.c_str());
570 ofstream write_mask_file_tb2(file_name_tb2.c_str());
572 write_mask_file_tb1<<
"#Connector, ChipID, Col, Row"<<endl;
573 write_mask_file_tb2<<
"#Connector, ChipID, Col, Row"<<endl;
576 int chipid, row,
col, tot, chip_tot, prev_tot;
577 Int_t stave_map[4] = {0, 4, 1, 2};
582 for (
int ix = 1; ix <=
h2d_chip[
i]->GetNbinsX(); ix++)
584 for (
int iy = 1; iy <=
h2d_chip[
i]->GetNbinsY(); iy++)
586 col =
h2d_chip[
i]->GetXaxis()->GetBinCenter(ix);
590 if (
h2d_chip[
i]->GetBinContent(ix, iy) > thresh )
595 row = 511-(
h2d_chip[
i]->GetYaxis()->GetBinCenter(iy));
599 row =
h2d_chip[
i]->GetYaxis()->GetBinCenter(iy);
601 if (
i != 1) { write_mask_file_tb1 << stave_map[
i] <<
"," << chipid <<
"," << col <<
"," << row << endl; }
602 else { write_mask_file_tb2 << stave_map[
i] <<
"," << chipid <<
"," << col <<
"," << row << endl; }
605 chip_tot = tot - prev_tot;
606 if (col == 1023) {prev_tot = tot;
printf(
"Total pixels masked on stave %i, chip %i: %i\n",
i, chipid, chip_tot);}
610 printf(
"Total pixels masked: %i\n", sum);
611 write_mask_file_tb1.close();
612 write_mask_file_tb2.close();
613 printf(
"New pixel mask has been created\n");
637 for (
int ichip = 0; ichip <
NSTAVE; ichip++)
639 sprintf(name,
"hnhit_chip_norm_%i", ichip);
642 sprintf(name,
"h2d_chip_norm_%i", ichip);
645 sprintf(name,
"hdiffrow_chip_norm_%i", ichip);
648 sprintf(name,
"hdiffcol_chip_norm_%i", ichip);
667 float bc =
hchip->GetBinContent(
ib);
677 bc =
herr->GetBinContent(
ib);
683 cBeamCenter =
new TCanvas(
"cBeamCenter",
"cBeamCenter", 1350, 900);
688 for (
int ichip = 0; ichip <
NSTAVE; ichip++)
701 for (
int ix = 1; ix <=
h2d_chip[ichip]->GetNbinsX(); ix++)
702 for (
int iy = 1; iy <=
h2d_chip[ichip]->GetNbinsY(); iy++)
704 float bc =
h2d_chip[ichip]->GetBinContent(ix, iy);
716 TH2D* h2d_beam = (TH2D*)
h2d_chip_norm[ichip]->Clone(
"h2d_beam");
717 h2d_beam->GetXaxis()->SetTitle(
"Stave_Cols");
718 h2d_beam->GetYaxis()->SetTitle(
"Stave_Rows");
719 h2d_beam->Draw(
"colz");
723 lt.SetTextSize(1.5*lt.GetTextSize());
725 lt.DrawText(0.5,0.96,
stave_name[ichip].c_str());
753 double m_col = h->GetMean();
754 double r_col = h->GetRMS();
755 fg->SetParameters(h->GetBinContent(h->GetMaximumBin()), m_col, r_col);
757 const int lastBinX = 9 * 1024 - 1;
758 const int lastBinY = 511;
759 fg->SetRange(0, lastBinX);
761 m =
fg->GetParameter(1);
762 s =
fg->GetParameter(2);
764 m = m - 2.5*s > lastBinX ? lastBinX :
m;
765 fg->SetRange(m - 2.5*s, m + 2.5*s);
766 fg->SetParameters(
fg->GetParameter(0),
m,
s);
768 m =
fg->GetParameter(1);
769 s =
fg->GetParameter(2);
773 s = s - (m - lastBinX);
789 h->GetXaxis()->SetTitle(
"Stave_Cols");
790 h->GetYaxis()->SetTitle(
"nClusters");
792 TF1* f_col = (TF1*)
fg->Clone(
"fx");
797 lt.SetTextSize(1.5*lt.GetTextSize());
799 lt.DrawLatex(.3, .7, Form(
"#mu_{COL} = %.2f #pm %.2f ", m_col, r_col));
800 lt.DrawLatex(.3, .6, Form(
"offset = %.2f", m_col));
807 double m_row = h->GetMean();
808 double r_row = h->GetRMS();
809 fg->SetParameters(h->GetBinContent(h->GetMaximumBin()), m_row, r_row);
810 fg->SetRange(0, 1023);
812 m =
fg->GetParameter(1);
813 s =
fg->GetParameter(2);
815 fg->SetRange(m - 2.5*s, m + 2.5*s);
816 fg->SetParameters(
fg->GetParameter(0),
m,
s);
818 m =
fg->GetParameter(1);
819 s =
fg->GetParameter(2);
823 s = s - (m - lastBinY);
839 h->GetXaxis()->SetTitle(
"Stave_Cols");
840 h->GetYaxis()->SetTitle(
"nClusters");
842 TF1* f_row = (TF1*)
fg->Clone(
"fy");
847 lt.SetTextSize(1.5*lt.GetTextSize());
849 lt.DrawLatex(.3, .7, Form(
"#mu_{ROW} = %.2f #pm %.2f ", m_row, r_row));
850 lt.DrawLatex(.3, .6, Form(
"offset = %.2f", lastBinY - m_row));
856 gmpos_chip[ichip]->SetPointError(0, r_col, r_col, r_row, r_row);
888 gStyle->SetOptStat(0);
891 static bool initialized =
false;
897 com =
new TCanvas(
"com",
"MVTX online monitoring", 2000, 800);
898 com->SetMargin(0, 0, 0, 0);
902 phitrate =
new TPad(
"phitrate",
"hit rate", 0.0, 0.60, 0.29, 0.89);
903 phitrate->SetMargin(0.15, 0.05, 0.15, 0.05);
924 pdiffcol =
new TPad(
"pdiffcol",
"pdiffcol", 0.00, 0.30, 0.29, 0.59);
926 pdiffcol->SetMargin(0.15, 0.05, 0.15, 0.05);
933 pdiffrow =
new TPad(
"pdiffrow",
"pdiffrow", 0.00, 0.00, 0.29, 0.29);
935 pdiffrow->SetMargin(0.15, 0.05, 0.15, 0.05);
943 sprintf(name,
"p2d_%i",
i);
947 p2d[
i] =
new TPad(name, name,
949 1.00, 0.9-0.22*(
i+1) );
951 p2d[
i]->SetMargin(0.01, 0.02, 0.25, 0.25);
952 p2d[
i]->SetTicks(1, 1);
958 sprintf(name,
"Number of Events: %.0f",
hnevnt->Integral());
959 lnevents =
new TLatex(0.5, 0.95, name);
961 lnevents->SetTextAlign(22);
987 lnhitmean[
i] =
new TLatex(0.8, 0.85 - 0.05*
i, name);
1019 for (
int i = 0;
i < NSTAVE - 1;
i++)
1024 ldiffcol[
i] =
new TLatex(0.8, 0.90 - 0.05*
i, name);
1030 lt.DrawLatex(0.5, 0.96,
"Col");
1038 for (
int i = 0;
i < NSTAVE - 1;
i++)
1043 ldiffrow[
i] =
new TLatex(0.8, 0.90 - 0.05*
i, name);
1049 lt.DrawLatex(0.5, 0.96,
"Row");
1051 for (
int i = 1;
i < 10; ++
i)
1053 chip_edges.push_back(
new TLine((1024*
i)-1, 0, (1024*
i)-1, 511));
1068 gPad->GetUxmin()-0.001,
1081 lt.DrawLatex(0.5, 0.96, name);
1100 sprintf(name,
"Run %i, Number of Events: %.0f",
mvtx_run,
hnevnt->Integral());
1101 lnevents->SetText(0.5, 0.95, name);
1107 for (
int i = 0;
i < NSTAVE - 1;
i++)
1112 sprintf(name,
"stave %s = %+.0f",
stave_name[
i].c_str(), dcol);
1116 ldiffcol[
i]->SetText(0.75, 0.83 - 0.05*
i, name);
1121 sprintf(name,
"stave %s = %+.0f",
stave_name[
i].c_str(), drow);
1125 ldiffrow[
i]->SetText(0.75, 0.83 - 0.05*
i, name);
1145 char outputFileName[128];
1146 sprintf(outputFileName,
"Run%0.4i.png",
mvtx_run);
1147 com->Print(outputFileName);
1158 cout <<
"==================================================" << endl;
1159 cout <<
"==================================================" << endl;
1160 cout <<
"== Number of events: " <<
hnevnt->Integral() << endl;
1164 if ( !(
hchip->GetBinContent(
i + 1) > 0) )
1167 cout <<
"==================================================" << endl;
1168 cout <<
"==== Chip " <<
i << endl;
1169 cout <<
"== events: " <<
hnhit_chip[
i]->Integral() << endl;
1170 cout <<
"== Total hits: " <<
hchip->GetBinContent(
i+1)
1173 cout <<
"== Total Warnings: " <<
hwarn->GetBinContent(
i+1)
1176 cout <<
"== Total Errors: " <<
herr->GetBinContent(
i+1)
1184 cout <<
"== <col>: " << mcol << endl;
1185 cout <<
"== <row>: " << mrow << endl;
1191 cout <<
"== <dcol>: " << dcol
1197 cout <<
"== <drow>: " << drow
1202 cout <<
"==================================================" << endl;
1203 cout <<
"==================================================" << endl;
1227 string fname(Form(
"beamcenter/beamcenter_%08d.txt",
mvtx_run));
1228 ofstream
fout(fname);
1230 for (
int istave=0; istave<
NSTAVE; ++istave)
1232 double m_col, m_row;
1233 gmpos_chip[istave]->GetPoint(0, m_col, m_row);
1234 m_row = 511 - m_row;
1236 fout << istave <<
" 0 " << fixed << setprecision(2) << m_row <<
" " << 0 <<
" " << m_col << endl;
1237 cout << istave <<
" 0 " << fixed << setprecision(2) << m_row <<
" " << 0 <<
" " << m_col << endl;