6 #include "TGraphErrors.h"
12 #include "TPaveText.h"
24 void NormalizeBsHisto(TH2F* H2)
27 const float max = H2->GetMaximum();
31 for (
int x=0; x<H2->GetNbinsX(); x++)
32 for (
int y=0; y<H2->GetNbinsY(); y++)
34 const float BC = H2->GetBinContent(x+1, y+1);
37 H2->SetBinContent(x+1, y+1, 0);
38 H2->SetBinError (x+1, y+1, 0);
46 void bsQaShow(
const char* inFile =
"fmsBsQa.root",
bool MARK =
true,
bool PRINT =
false)
51 TFile* F = TFile::Open(inFile);
52 if (!F || F->IsZombie()) { cout <<
"Cannot open " <<inFile <<endl;
return; }
57 map<int, int> nToCh[4];
58 for (
int a=0; a<4; a++)
60 const int detId = a+8;
61 TH2F* tempChMap = (TH2F*)F->Get(Form(
"ChMap_d%i", detId));
62 if (!tempChMap) { cout <<
"Cannot open channel map histogram!" <<endl;
return; }
65 for (
int x=0; x<tempChMap->GetNbinsX(); x++)
68 if (tempChMap->GetBinContent(x+1, 1) == 0)
continue;
71 nToCh[a].insert(std::pair<int, int>(index, ch));
83 for (
int a=0; a<4; a++)
85 const int nSepHisto = nToCh[a].size()/nSep + 1;
86 TH2F* H2Sep[2][nSepHisto];
87 for (
int b=0; b<2; b++)
89 TH2F* H2_BS = (TH2F*)F->Get(Form(
"BitShift_%s_d%i", b==0?
"DB":
"data", a+8));
90 TH2F* H2_ADC = (TH2F*)F->Get(Form(
"Adc_d%i", a+8));
91 if (!H2_BS || !H2_ADC) { cout <<
"Cannot open histograms! (1)" <<endl;
return; }
92 NormalizeBsHisto(H2_BS);
95 const float nCh = (H2_ADC->GetNbinsX()>300)?394:238;
96 const float nHitAll = H2_ADC->GetEntries();
97 const float nHitAvg = nHitAll/nCh;
102 const int nBit = H2_BS->GetNbinsY();
103 for (
unsigned int x=0; x<nToCh[a].size(); x++)
109 const char* tempN = Form(
"%s_%i", H2_BS->GetName(), Seq);
110 const char* tempT = Form(
"%s, from ch = %i;ch;Bit (BS)", H2_BS->GetTitle(), nToCh[a][nSep*Seq]);
111 H2Sep[b][Seq] =
new TH2F(tempN, tempT, nSep,0,nSep, nBit,0.5,nBit+0.5);
112 for (
int i=0; i<nSep; i++)
114 const int chTarget = i + (nSep * Seq);
115 if (nToCh[a][chTarget] == 0)
continue;
116 H2Sep[b][Seq]->GetXaxis()->SetBinLabel(i+1, Form(
"%i", nToCh[a][chTarget]));
118 H2Sep[b][Seq]->LabelsOption(
"v",
"X");
119 for (
int y=0; y<nBit; y++)
121 if (y+1 <= 6) H2Sep[b][Seq]->GetYaxis()->SetBinLabel(y+1, Form(
"%2i (#plus%i)", y+1, y+1));
122 else H2Sep[b][Seq]->GetYaxis()->SetBinLabel(y+1, Form(
"%2i (#minus%i)", y+1, abs(y-12)));
124 H2Sep[b][Seq]->GetYaxis()->SetTitleOffset(1.2);
128 const int xBinTarget = H2_BS->GetXaxis()->FindBin(nToCh[a][x] + 1.e-3);
129 const int xBinToFill = x - (nSep * Seq) + 1;
131 for (
int y=0; y<nBit; y++)
133 float BC = H2_BS->GetBinContent(xBinTarget, y+1);
if (BC==0)
continue;
134 float BE = H2_BS->GetBinError (xBinTarget, y+1);
135 H2Sep[b][Seq]->SetBinContent(xBinToFill, y+1, BC);
136 H2Sep[b][Seq]->SetBinError (xBinToFill, y+1, BE);
142 if (nBitFilled == nBit) chQuality = 1;
143 else if (abs(nBitFilled) > 5)
145 TH1F* H1_ADC_1ch = (TH1F*)H2_ADC->ProjectionY(
"", nToCh[a][x], nToCh[a][x]);
146 if (H1_ADC_1ch->GetEntries() < nHitAvg*1.e-2) chQuality = 1;
147 else if (H1_ADC_1ch->GetRMS() < 1.) chQuality = 2;
148 H1_ADC_1ch->Delete();
152 if (MARK==
true && chQuality!=0)
154 for (
int y=0; y<nBit; y++)
156 if (chQuality==1) H2Sep[b][Seq]->SetBinContent(xBinToFill, y+1, 0.1);
157 if (chQuality==2) H2Sep[b][Seq]->SetBinContent(xBinToFill, y+1, 0.3);
162 if (Count == nSep) Count = 0;
170 gStyle->SetOptDate(0);
171 gStyle->SetOptStat(0);
175 for (
int c=0; c<nSepHisto; c++)
179 c1 =
new TCanvas(Form(
"FmsBsQa_d%i_%i", a+8,iCVS), Form(
"detId=%i, %i",a+8,iCVS), 1600, 900);
182 c1->cd(iPAD+0); H2Sep[0][c]->DrawCopy(
"col");
183 c1->cd(iPAD+2); H2Sep[1][c]->DrawCopy(
"col");
187 if (PRINT) c1->Print(Form(
"%s.png", c1->GetName()));
199 vector<int> ListMM1[4];
200 vector<int> ListMM2[4];
201 for (
int a=0; a<4; a++)
204 TH2F* H2_ADC = (TH2F*)F->Get(Form(
"Adc_d%i", a+8));
205 const float nCh = (H2_ADC->GetNbinsX()>300)?394:238;
206 const float nHitAll = H2_ADC->GetEntries();
207 const float nHitAvg = nHitAll/nCh;
211 for (
int b=0; b<2; b++)
213 H2[b] = (TH2F*)F->Get(Form(
"BitShift_%s_d%i", b==0?
"DB":
"data", a+8));
214 if (!H2[b]) { cout <<
"Cannot open histograms! (2)" <<endl;
return; }
215 NormalizeBsHisto(H2[b]);
219 const int nBit = H2[db]->GetNbinsY();
220 for (
unsigned int x=0; x<nToCh[a].size(); x++)
222 const int ch = nToCh[a][x];
226 for (
int y=0; y<nBit; y++)
228 const int BC_DB = H2[db] ->GetBinContent(ch, y+1);
if (BC_DB == 0)
continue;
229 const int BC_data = H2[
data]->GetBinContent(ch, y+1);
230 if (BC_DB != BC_data)
232 ListMM1[a].push_back(ch);
237 if (FlagMM ==
true)
continue;
240 for (
int y=0; y<nBit; y++) {
if (H2[
data]->GetBinContent(ch, y+1) != 0) nBitFilled++; }
244 if (nBitFilled == nBit) chQuality = 1;
245 else if (abs(nBitFilled) > 5)
247 TH1F* H1_ADC_1ch = (TH1F*)H2_ADC->ProjectionY(
"", nToCh[a][x], nToCh[a][x]);
248 if (H1_ADC_1ch->GetEntries() < nHitAvg*1.e-2) chQuality = 1;
249 else if (H1_ADC_1ch->GetRMS() < 1.) chQuality = 2;
250 H1_ADC_1ch->Delete();
254 for (
int y=0; y<nBit; y++)
256 const int BC_data = H2[
data]->GetBinContent(ch, y+1);
259 const int BC_DB = H2[db]->GetBinContent(ch, y+1);
260 if (BC_data != BC_DB)
262 if (chQuality == 0) ListMM1[a].push_back(ch);
263 else ListMM2[a].push_back(ch);
277 TH2F* H2_Mismatch[2][2];
278 for (
int a=0; a<2; a++)
279 for (
int b=0; b<2; b++)
281 const char* tempN = Form(
"H2_MisMatch_%s_%i", a==0?
"DB":
"data", b);
282 const char* tempT = Form(
"%s, %s;;Bit (BS)", a==0?
"DB":
"data",b==0?
"Mismatch":
"Mismatch due to bad channel");
284 if (b==0) nMM = ListMM1[0].size() + ListMM1[1].size() + ListMM1[2].size() + ListMM1[3].size();
285 else nMM = ListMM2[0].size() + ListMM2[1].size() + ListMM2[2].size() + ListMM2[3].size();
286 H2_Mismatch[a][b] =
new TH2F(tempN, tempT, (nMM>30)?nMM:30,0,(nMM>30)?nMM:30, 12,0.5,12+0.5);
287 for (
int x=0; x<H2_Mismatch[a][b]->GetNbinsX(); x++) H2_Mismatch[a][b]->GetXaxis()->SetBinLabel(x+1,
"");
288 for (
int y=0; y<H2_Mismatch[a][b]->GetNbinsY(); y++)
290 if (y+1 <= 6) H2_Mismatch[a][b]->GetYaxis()->SetBinLabel(y+1, Form(
"%2i (#plus%i)", y+1, y+1));
291 else H2_Mismatch[a][b]->GetYaxis()->SetBinLabel(y+1, Form(
"%2i (#minus%i)", y+1, abs(y-12)));
293 H2_Mismatch[a][b]->LabelsOption(
"v",
"X");
294 H2_Mismatch[a][b]->GetYaxis()->SetLabelSize(0.045);
295 H2_Mismatch[a][b]->GetYaxis()->SetTitleOffset(1.2);
300 for (
int a=0; a<4; a++)
304 for (
int b=0; b<2; b++)
306 H2[b] = (TH2F*)F->Get(Form(
"BitShift_%s_d%i", b==0?
"DB":
"data", a+8));
307 if (!H2[b]) { cout <<
"Cannot open histograms! (2)" <<endl;
return; }
310 const float tempMax = H2[b]->GetMaximum();
311 H2[b]->Scale(1/tempMax);
312 for (
int x=0; x<H2[b]->GetNbinsX(); x++)
313 for (
int y=0; y<H2[b]->GetNbinsY(); y++)
315 const float BC = H2[b]->GetBinContent(x+1, y+1);
318 H2[b]->SetBinContent(x+1, y+1, 0);
319 H2[b]->SetBinError (x+1, y+1, 0);
325 const int nBit = H2[db]->GetNbinsY();
326 for (
unsigned int x=0; x<ListMM1[a].size(); x++)
328 const int ch = ListMM1[a][x];
329 for (
int y=0; y<nBit; y++)
331 for (
int b=0; b<2; b++)
333 const int BC = H2[b]->GetBinContent(ch, y+1);
334 H2_Mismatch[b][0]->SetBinContent(iMM1, y+1, BC);
335 H2_Mismatch[b][0]->GetXaxis()->SetBinLabel(iMM1, Form(
"%i_%i", a+8, ch));
340 for (
unsigned int x=0; x<ListMM2[a].size(); x++)
342 const int ch = ListMM2[a][x];
343 for (
int y=0; y<nBit; y++)
345 for (
int b=0; b<2; b++)
347 const int BC = H2[b]->GetBinContent(ch, y+1);
348 H2_Mismatch[b][1]->SetBinContent(iMM2, y+1, BC);
349 H2_Mismatch[b][1]->GetXaxis()->SetBinLabel(iMM2, Form(
"%i_%i", a+8, ch));
359 gStyle->SetOptDate(0);
360 gStyle->SetOptStat(0);
361 TCanvas *c2 =
new TCanvas(
"FmsBsQa_Summary",
"Summary", 1600, 900);
363 for (
int a=0; a<2; a++)
364 for (
int b=0; b<2; b++)
367 H2_Mismatch[a][b]->DrawCopy(
"col");
369 if (PRINT) c2->Print(Form(
"%s.png", c2->GetName()));