10 #include "calibFmsTools.C"
12 static map<int, int> DumMapI[4];
13 static map<int, float> DumMapF[4];
14 static map<int, string> DumMapS[4];
15 static vector<int> DumVecI[4];
16 static TH2F* DumTH2F[4];
20 map<int, int> iToCh[4],
23 map<int, string> chToInfo[4] = DumMapS,
24 map<int, int> chToBS[4] = DumMapI,
25 map<int, float> chToGain[4] = DumMapF,
26 map<int, float> chToGainCorr[4] = DumMapF,
27 vector<int> chMarked[4] = DumVecI,
28 TH2F* H2Mass[4] = DumTH2F
36 unsigned int nRun = 0;
39 if (!in.is_open()) { cout <<
"Cannot open " <<inList <<endl;
return; }
44 if (!in.good()) {
break; in.close(); }
46 runList[nRun].clear();
47 runList[nRun] = inFile;
50 if (nRun >
sizeof(runList)/
sizeof(runList[0])) cout <<
"WARNING! # of runs exceeds allowed limit!" <<endl;
56 for (
int a=0; a<4; a++)
58 const int nCh = iToCh[a].size();
59 H2AdcQa1[a] =
new TH2F(Form(
"AdcQa1_d%i", a+8),
"", nRun,-0.5,nRun-0.5, nCh,0.5,nCh+0.5);
60 H2AdcQa1[a]->SetTitle(Form(
"detId=%i, nHit/nTrig;run index;ch index", a+8));
65 for (
unsigned int i=0; i<nRun; i++)
67 const char* inFile = runList[i].c_str();
68 TFile* F = TFile::Open(inFile);
69 if (!F || F->IsZombie()) { cout <<
"Cannot open file " <<inFile <<endl;
return; }
70 else cout <<Form(
"Open %s... %i", inFile, i) <<endl;
72 TH1F* H1TempTrig = (TH1F*)F->Get(
"trig");
73 if (!H1TempTrig || H1TempTrig->GetEntries()==0) { cout <<
"Trigger TH1?" <<endl;
return; }
74 const float nTrig = H1TempTrig->GetEntries();
77 for (
int a=0; a<4; a++)
79 TH2F* H2TempAdc = (TH2F*)F->Get(Form(
"adc_d%i_wide", a+8));
80 if (!H2TempAdc || H2TempAdc->GetEntries()==0) { cout <<
"ADC TH2?" <<endl;
return; }
83 const int adcMinBin = H2TempAdc->GetYaxis()->FindBin(adcMin + 0.1);
84 const int adcMaxBin = H2TempAdc->GetNbinsY();
85 TH1F* H1TempAdc = (TH1F*)H2TempAdc->ProjectionX(Form(
"detId%i", a+8), adcMinBin, adcMaxBin);
86 for (
unsigned int b=0; b<iToCh[a].size(); b++)
88 const int ch = iToCh[a][b];
89 if (ch == 0)
continue;
90 const float nHitNorm = H1TempAdc->GetBinContent(ch) / nTrig;
91 H2AdcQa1[a]->SetBinContent(i+1, b+1, nHitNorm);
98 H2AdcQa2[a] = (TH2F*)H2TempAdc->Clone(Form(
"AdcQa2_d%i", a+8));
99 H2AdcQa2[a]->SetTitle(Form(
"detId=%i;ch;ADC", a+8));
101 else H2AdcQa2[a]->Add(H2TempAdc);
110 gStyle->SetOptDate(0);
111 gStyle->SetTitleFontSize(0.06);
114 TCanvas* c1 =
new TCanvas(
"adcQaAll",
"AdcQaAll", 1600, 900);
116 for (
int a=0; a<4; a++)
118 c1->cd(a+1)->SetLogz();
119 gPad->SetRightMargin(0.125);
120 H2AdcQa1[a]->SetStats(
false);
121 H2AdcQa1[a]->Draw(
"colz");
123 if (PRINT) c1->Print(Form(
"%s.png", c1->GetName()));
128 TCanvas* c1a =
new TCanvas(
"adcQaHit",
"AdcQaHit", 1600, 900);
131 vector<int> HotList[4];
132 for (
int a=0; a<4; a++)
134 const int nCh = iToCh[a].size();
135 if (nCh != H2AdcQa1[a]->GetNbinsY()) cout <<
"WARNING! # of channels doesn't match!" <<endl;
136 TH1F* H1Temp = (TH1F*)H2AdcQa1[a]->ProjectionY();
137 H1Temp->Scale(1./nRun);
140 const float xMin = 1.e-3;
141 const float xMax = H1Temp->GetMaximum()*1.01;
142 H1AdcQa1A[a] =
new TH1F(Form(
"AdcQa1A_d%i", a+8),
"", 150,xMin,xMax);
143 H1AdcQa1A[a]->SetTitle(Form(
"detId=%i, Drawn x: [%4.3f, %4.3f];nHit/nTrig/nRun", a+8, xMin, xMax));
144 H1AdcQa1A[a]->Sumw2();
147 for (
int b=0; b<nCh; b++)
149 const float nScaledHit = H1Temp->GetBinContent(b+1);
150 H1AdcQa1A[a]->Fill(nScaledHit);
153 H1AdcQa1A[a]->DrawCopy(
"hist e");
156 const float tempM = H1AdcQa1A[a]->GetMean();
157 const float tempR = H1AdcQa1A[a]->GetRMS();
158 const float tempC = tempM + tempR * cutSig;
159 TLine* L1 =
new TLine(tempC, 0, tempC, H1AdcQa1A[a]->GetMaximum());
165 for (
int b=0; b<nCh; b++)
167 const int ch = iToCh[a][b];
168 const float nScaledHit = H1Temp->GetBinContent(b+1);
169 if (nScaledHit > tempC)
171 cout <<Form(
"Potential hot channels: %2i, %3i", a+8, ch) <<endl;
172 HotList[a].push_back(ch);
178 cout <<Form(
"Total: %i", HotList[0].size() + HotList[1].size() + HotList[2].size() + HotList[3].size()) <<endl;
179 if (PRINT) c1a->Print(Form(
"%s.png", c1a->GetName()));
184 bool showMark =
false;
185 bool showHitE =
false;
186 bool showMass =
false;
187 for (
int a=0; a<4; a++) {
if (chMarked[a].size() != 0) { showMark =
true;
break; } }
188 for (
int a=0; a<4; a++) {
if (chToGain[a].size()!=0 && chToGainCorr[a].size()!=0) { showHitE =
true;
break; } }
189 for (
int a=0; a<4; a++) { DumTH2F[a] =
new TH2F();
if (H2Mass[a]->GetEntries() > 0) { showMass =
true;
break; } }
196 for (
int a=0; a<4; a++)
204 TH2F* H2Temp = (TH2F*)H2AdcQa2[a]->Clone();
205 const int adcMinBin = H2AdcQa2[a]->GetYaxis()->FindBin(adcMin + 0.1);
206 for (
int x=0; x<H2AdcQa2[a]->GetNbinsX(); x++)
207 for (
int y=0; y<adcMinBin; y++)
209 H2Temp->SetBinContent(x+1, y+1, 0);
210 H2Temp->SetBinError (x+1, y+1, 0);
214 for (
unsigned int b=0; b<iToCh[a].size(); b++)
216 const int ch = iToCh[a][b];
221 bool drawThis =
false;
222 for (
unsigned int i=0; i<chMarked[a].size(); i++) {
if (ch == chMarked[a][i]) drawThis =
true; }
223 if (!drawThis)
continue;
229 const int REX = 400*nCOL;
230 const int REY = 225*nPAD/nCOL;
231 c2 =
new TCanvas(Form(
"adcQaSep%s_%i", showMark?
"":Form(
"_d%i", a+8), iCVS),
"", REX, REY);
232 c2->SetTitle(c2->GetName());
233 c2->Divide(nCOL, nPAD/nCOL);
235 c2->cd(iPAD)->SetLogy();
238 TH1F* H1 = (TH1F*)H2Temp->ProjectionY(Form(
"d%i_ch%i", a+8, ch), ch, ch);
240 H1->GetYaxis()->SetLabelSize(0.055);
241 string Title = chToInfo[a][ch];
242 if (!strcmp(Title.c_str(),
"")) Title = Form(
"d%i_ch%i", a+8, ch);
243 if (H1->GetXaxis()->GetBinUpEdge(H1->GetNbinsX()) > 250)
245 H1->GetXaxis()->SetRangeUser(0, 250);
246 const int nHitOverflow = H1->Integral(251, H1->GetNbinsX());
247 Title = Form(
"%s, ADC > 250: %i", Title.c_str(), nHitOverflow);
249 for (
unsigned int c=0; c<HotList[a].size(); c++) {
if (ch == HotList[a][c]) H1->SetLineColor(2); }
250 if (chToBS[a].size()!=0 && chToBS[a][ch]>0)
252 const float scaleF = pow(2, chToBS[a][ch]);
253 H1->Scale(1./scaleF);
254 Title = Form(
"%s, Scaled (1/2^{%i})", Title.c_str(), chToBS[a][ch]);
256 if (showHitE) Title = Form(
"%s, GC = %4.3f", Title.c_str(), chToGainCorr[a][ch]);
257 H1->SetTitle(Title.c_str());
258 H1->DrawCopy(
"hist e");
263 TH1F* H1e =
new TH1F(Form(
"%s_hitE", H1->GetName()),
";hit E", 1000, 0, 250);
264 for (
int x=0; x<H1->GetNbinsX(); x++)
266 if (x > 250)
continue;
267 const float tempGain = chToGain[a][ch];
268 const float tempGainCorr = chToGainCorr[a][ch];
269 const float tempHitE = H1->GetBinCenter(x+1) * tempGain * tempGainCorr * 10;
271 const int xBin = H1e->GetXaxis()->FindBin(tempHitE);
272 H1e->SetBinContent(xBin, H1->GetBinContent(x+1));
273 H1e->SetBinError (xBin, H1->GetBinError (x+1));
276 H1e->SetLineColor(4);
277 H1e->DrawCopy(
"hist same");
283 TPad* tempPad =
new TPad(Form(
"tempPad_d%i_ch%i", a+8, ch),
"", 0,0,1,1);
284 tempPad->SetFillColor(0);
285 tempPad->SetFillStyle(4000);
286 tempPad->SetFrameFillStyle(0);
287 tempPad->SetGrid(0, 0);
288 tempPad->SetTicks(0, 0);
292 TH1F* H1Mass = (TH1F*)H2Mass[a]->ProjectionY(Form(
"d%i_ch%i_mass", a+8, ch), ch, ch);
293 H1Mass->SetLineColor(6);
294 H1Mass->SetStats(
true);
295 H1Mass->GetXaxis()->SetLabelSize(0);
296 H1Mass->GetXaxis()->SetTitleSize(0);
297 H1Mass->GetYaxis()->SetLabelSize(0);
298 H1Mass->GetYaxis()->SetTitleSize(0);
299 H1Mass->DrawCopy(
"hist e");
301 TLine* L1Mass =
new TLine(0.135, 0, 0.135, H1Mass->GetMaximum());
302 L1Mass->SetLineColor(6);
303 L1Mass->SetLineStyle(2);
304 L1Mass->SetLineWidth(2);
305 L1Mass->Draw(
"same");
311 if ( (iPAD == nPAD+1) || (!showMark && b==iToCh[a].size()-1) )
313 if (PRINT) c2->Print(Form(
"%s.png", c2->GetName()));
321 if (PRINT && showMark) c2->Print(Form(
"%s.png", c2->GetName()));
325 gSystem->Exec(
"mkdir -p adcQa");
326 gSystem->Exec(
"mv adcQa*.png adcQa");
335 map<int, int> iToCh[4],
336 map<int, st_pos> chToPos[4],
337 const char* mapName =
"FMS",
338 bool smallOnly =
false,
339 bool showEta =
false,
341 map<int, float> chToGainCorr[4] = DumMapF,
342 map<int, int> chToCellStat[4] = DumMapI,
343 vector<int> chMarked[4] = DumVecI
353 bool showGain =
false;
354 bool showStat =
false;
355 bool showMark =
false;
356 for (
int a=0; a<4; a++) {
if (chToGainCorr[a].size()!=0) {showGain =
true;
break;} }
357 for (
int a=0; a<4; a++) {
if (chToCellStat[a].size()!=0) {showStat =
true;
break;} }
358 for (
int a=0; a<4; a++) {
if (chMarked[a].size()!=0) {showMark =
true;
break;} }
362 gStyle->SetOptDate(0);
363 gStyle->SetOptStat(0);
366 TCanvas* c1 =
new TCanvas(Form(
"Map%s", mapName), mapName, PRINT?2700:1000, PRINT?2700:1000);
368 const float fBin = (int)(smallOnly?110:210);
369 const float fEnd = fBin/2;
370 TH2F* H2F =
new TH2F(Form(
"FRM%s", mapName), Form(
"%s;X;Y", c1->GetTitle()), fBin,-fEnd,fEnd, fBin,-fEnd,fEnd);
373 gPad->SetRightMargin(0.125);
374 H2F->SetMaximum(5.0);
375 H2F->Fill(fEnd, fEnd, H2F->GetMaximum());
377 H2F->GetYaxis()->SetTitleOffset(1.25);
383 const int nRings = smallOnly?10:8;
384 const float stepWidth = smallOnly?0.1:0.2;
385 const float minEta = 4.1 - nRings*stepWidth;
386 H2F->SetTitle(Form(
"%s, %2.1f #leq #eta #leq 4.1", c1->GetTitle(), minEta));
387 for (
int i=0; i<=nRings; i++)
389 const float tempEta = 4.1 - stepWidth * i;
390 const float tempTheta = 2 * atan(exp(-tempEta));
391 const float tempRadius = tan(tempTheta) * 720.0;
392 TEllipse *E1 =
new TEllipse(0, 0, tempRadius);
394 E1->SetFillStyle(4000);
403 for (
unsigned int a=0; a<4; a++)
404 for (
unsigned int b=0; b<iToCh[a].size(); b++)
406 if (smallOnly && a<2)
continue;
408 const int ch = iToCh[a][b];
409 const float x = chToPos[a][ch].chX;
410 const float y = chToPos[a][ch].chY;
411 const float cellHW = a<2?(5.8/2):(3.8/2);
416 const float gainCorr = chToGainCorr[a][ch];
417 if (fabs(gainCorr) >= H2F->GetMaximum()) boxColor = 100;
418 else boxColor = (int)(fabs(gainCorr * 50.)/H2F->GetMaximum()) + 51;
423 const int cellStat = chToCellStat[a][ch];
424 if (cellStat == DEAD) boxColor = showGain?17:0;
425 else if (cellStat == BAD) boxColor = 1;
426 if (!showGain && cellStat == CONVERGED) boxColor = 220;
429 TPaveText* PT =
new TPaveText(x-cellHW, y-cellHW, x+cellHW, y+cellHW);
430 PT->SetFillStyle(3001);
431 PT->SetFillColor(boxColor);
432 PT->SetTextColor(kBlack);
433 PT->AddText(Form(
"%3i", ch));
434 if (showGain) PT->AddText(Form(
"%4.3f", chToGainCorr[a][ch]));
437 if (showGain && chToCellStat[a][ch]==CONVERGED)
439 TMarker* MK =
new TMarker(x, y, 20);
440 MK->SetMarkerColor(220);
441 if (boxColor>85 && boxColor<95) { MK->SetMarkerStyle(24); MK->SetMarkerColor(1); }
442 MK->SetMarkerSize(PRINT?1.1:0.4);
445 if (showStat && chToCellStat[a][ch]==DEAD)
447 TLine* DL1 =
new TLine(x-cellHW,y-cellHW,x+cellHW,y+cellHW); DL1->SetLineWidth(2); DL1->Draw(
"same");
448 TLine* DL2 =
new TLine(x-cellHW,y+cellHW,x+cellHW,y-cellHW); DL2->SetLineWidth(2); DL2->Draw(
"same");
453 for (
unsigned int c=0; c<chMarked[a].size(); c++) {
if (ch == chMarked[a][c]) Marked =
true; }
454 if (!Marked)
continue;
456 const int mCOL = 206;
457 PT->SetFillColor(mCOL);
458 PT->SetTextColor(mCOL);
459 TLine* LX1 =
new TLine(x-cellHW,y-cellHW,x-cellHW,y+cellHW); LX1->SetLineColor(mCOL); LX1->Draw(
"same");
460 TLine* LX2 =
new TLine(x+cellHW,y-cellHW,x+cellHW,y+cellHW); LX2->SetLineColor(mCOL); LX2->Draw(
"same");
461 TLine* LY1 =
new TLine(x-cellHW,y-cellHW,x+cellHW,y-cellHW); LY1->SetLineColor(mCOL); LY1->Draw(
"same");
462 TLine* LY2 =
new TLine(x-cellHW,y+cellHW,x+cellHW,y+cellHW); LY2->SetLineColor(mCOL); LY2->Draw(
"same");
466 if (PRINT) c1->Print(Form(
"%s%s%s.png", c1->GetName(), smallOnly?
"_small":
"", showMark?
"_marked":
""));
472 void DrawCompGainCorr(
473 map<int, int> iToCh[4],
474 map<int, int> chToCellStat[2][4],
475 map<int, float> chToGainCorr[2][4],
476 const char* setName1 =
"Set1",
477 const char* setName2 =
"Set2",
479 bool excBadDead =
false,
480 bool convOnly =
false
488 for (
int i=0; i<2; i++)
489 for (
int a=0; a<4; a++)
491 H1[i][a] =
new TH1F(Form(
"H1GainCorr_%i_d%i", i, a+8),
"", 105, -0.1, 4.1);
492 G1[i][a] =
new TGraph();
493 G1[i][a]->SetName(Form(
"G1GainCorr_%i_d%i", i, a+8));
496 G2[a] =
new TGraph();
497 G2[a]->SetName(Form(
"G2GainCorrDelta_d%i", a+8));
500 for (
unsigned int b=0; b<iToCh[a].size(); b++)
502 const int ch = iToCh[a][b];
505 chToCellStat[0][a][ch]!=CONVERGED &&
506 chToCellStat[1][a][ch]!=CONVERGED)
continue;
509 (chToCellStat[0][a][ch]==BAD ||
510 chToCellStat[1][a][ch]==BAD ||
511 chToCellStat[0][a][ch]==DEAD ||
512 chToCellStat[1][a][ch]==DEAD) )
continue;
514 const float maxGC = H1[i][a]->GetXaxis()->GetBinUpEdge(H1[i][a]->GetNbinsX());
515 float tempGC = chToGainCorr[i][a][ch];
516 if (tempGC > maxGC) tempGC = maxGC;
518 H1[i][a]->Fill(tempGC);
519 G1[i][a]->SetPoint(G1[i][a]->GetN(), ch, tempGC);
522 const float GC1 = chToGainCorr[0][a][ch];
523 const float GC2 = chToGainCorr[1][a][ch];
524 if (GC1==0. || GC2==0.)
continue;
527 float dGC = (GC1 - GC2)/GC1;
528 if (dGC < -1.5) dGC = -1.5;
529 if (dGC > +1.5) dGC = +1.5;
530 G2[a]->SetPoint(G2[a]->GetN(), ch, dGC);
537 gStyle->SetOptDate(0);
538 gStyle->SetOptStat(0);
540 const char* TitleOp =
"";
541 if (excBadDead) TitleOp = Form(
"%s, Excluded Bad/Dead", TitleOp);
542 if (convOnly) TitleOp = Form(
"%s, Converged Only", TitleOp);
545 for (
int x=0; x<3; x++)
547 c1[x] =
new TCanvas(Form(
"GCcomp%i_%sVs%s", x, setName1, setName2),
"", 1600, 900);
548 c1[x]->SetTitle(c1[x]->GetName());
552 for (
int i=0; i<2; i++)
553 for (
int a=0; a<4; a++)
556 H1[i][a]->SetLineColor(i+1);
559 H1[i][a]->SetTitle(Form(
"detId=%i%s;gainCorr", a+8, TitleOp));
560 const float max0 = H1[0][a]->GetMaximum();
561 const float max1 = H1[1][a]->GetMaximum();
562 if (max1 > max0) H1[0][a]->SetMaximum(max1*1.1);
566 H1[i][a]->SetFillColor(i+1);
567 H1[i][a]->SetFillStyle(3001);
568 TLegend *L1 =
new TLegend(0.70, 0.75, 0.95, 0.95);
570 L1->SetTextAlign(22);
571 L1->AddEntry(H1[0][a], Form(
"%s, RMS: %4.3f", setName1, H1[0][a]->GetRMS()),
"l");
572 L1->AddEntry(H1[1][a], Form(
"%s, RMS: %4.3f", setName2, H1[1][a]->GetRMS()),
"lf");
575 H1[i][a]->DrawCopy(i==0?
"hist e":
"hist ef same");
578 const char* TitleG1 = Form(
"detId=%i%s;ch;gainCorr", a+8, TitleOp);
579 if (i==0) gPad->DrawFrame(-10,-0.2,a<2?588:298,4.2, TitleG1);
580 G1[i][a]->SetMarkerSize(0.85);
581 G1[i][a]->SetMarkerColor(i+1);
582 G1[i][a]->SetMarkerStyle(i*4 + 20);
583 G1[i][a]->Draw(
"p same");
586 TLegend *L2 =
new TLegend(0.65, 0.80, 0.95, 0.95);
588 L2->SetTextAlign(22);
589 L2->AddEntry(G1[0][a], setName1,
"p");
590 L2->AddEntry(G1[1][a], setName2,
"p");
597 const char* TitleG2 = Form(
"detId=%i%s;ch;#DeltagainCorr (%s-%s)/%s",
598 a+8, TitleOp, setName1, setName2, setName1);
599 gPad->DrawFrame(-10, -1.5, a<2?588:298, 1.5, TitleG2);
600 G2[a]->SetFillColor(2);
601 G2[a]->SetFillStyle(3001);
602 G2[a]->Draw(
"b same");
608 for (
int x=0; x<3; x++)
610 c1[x]->Print(Form(
"%s%s%s.png", c1[x]->GetName(), excBadDead?
"_excBD":
"", convOnly?
"_conv":
""));
618 void DrawCompMassAll(
619 map<int, int> iToCh[4],
622 bool Normalize =
false,
632 gStyle->SetOptDate(0);
633 gStyle->SetOptStat(0);
635 TCanvas* c1 =
new TCanvas(
"massAll",
"massAll", 1600, 900);
638 for (
int a=0; a<4; a++)
642 TLegend* LEG =
new TLegend(0.6, 0.85-nComp*0.055, 0.85, 0.85);
646 for (
int i=0; i<nComp; i++)
648 if (H1[i][a]->GetMaximum()*1.1 > yMax) yMax = H1[i][a]->GetMaximum()*1.1;
651 for (
int i=0; i<nComp; i++)
653 TH1F* H1Temp = (TH1F*)H1[i][a]->Clone(Form(
"d%i_i%i", a+8, i));
654 H1Temp->SetTitle(Form(
"detId=%i", a+8));
656 if (Normalize) H1Temp->Scale(1/H1Temp->GetMaximum());
657 else H1Temp->SetMaximum(yMax);
659 H1Temp->SetLineColor((i+1)!=5?(i+1):95);
662 H1Temp->SetFillColor(H1Temp->GetLineColor());
663 H1Temp->SetFillStyle(3001);
665 H1Temp->DrawCopy(i==0?
"hist e":
"hist e same");
670 TLine* L1 =
new TLine(0.135, 0, 0.135, H1Temp->GetMaximum());
678 LEG->AddEntry(H1Temp, H1[i][a]->GetTitle(),
"lf");
679 if (i==nComp-1) LEG->Draw(
"same");
682 if (PRINT) c1->Print(Form(
"%s%s.png", c1->GetName(), Normalize?
"_norm":
""));
688 void DrawCompMassSep(
689 map<int, int> iToCh[4],
692 bool Normalize =
false,
694 map<int, string> chToInfo[4] = DumMapS,
695 vector<int> chMarked[4] = DumVecI
705 bool showMark =
false;
706 for (
int a=0; a<4; a++) {
if (chMarked[a].size() != 0) { showMark =
true;
break; } }
710 gStyle->SetOptDate(0);
711 gStyle->SetOptStat(0);
712 gStyle->SetTitleFontSize(0.06);
720 for (
int a=0; a<4; a++)
728 for (
unsigned int b=0; b<iToCh[a].size(); b++)
730 const int ch = iToCh[a][b];
735 bool drawThis =
false;
736 for (
unsigned int i=0; i<chMarked[a].size(); i++) {
if (ch == chMarked[a][i]) drawThis =
true; }
737 if (!drawThis)
continue;
743 const int REX = 400*nCOL;
744 const int REY = 225*nPAD/nCOL;
745 c1 =
new TCanvas(Form(
"massSep%s_%i", showMark?
"":Form(
"_d%i", a+8), iCVS),
"", REX, REY);
746 c1->SetTitle(c1->GetName());
747 c1->Divide(nCOL, nPAD/nCOL);
753 for (
int i=0; i<nComp; i++)
755 TH1F* H1 = (TH1F*)H2[i][a]->ProjectionY(
"H1Temp", ch, ch);
756 if (H1->GetNbinsX() == 250) H1->Rebin(5);
757 if (H1->GetMaximum()*1.1 > yMax) yMax = H1->GetMaximum()*1.1;
762 for (
int i=0; i<nComp; i++)
764 TH1F* H1 = (TH1F*)H2[i][a]->ProjectionY(Form(
"d%i_ch%i_%i", a+8, ch, i), ch, ch);
765 if (H1->GetNbinsX() == 250) H1->Rebin(5);
766 if (Normalize && H1->GetEntries()!=0) H1->Scale(1/H1->GetMaximum());
767 else H1->SetMaximum(yMax);
771 string Title = chToInfo[a][ch];
772 if (!strcmp(Title.c_str(),
"")) Title = Form(
"d%i_ch%i", a+8, ch);
773 H1->SetTitle(Title.c_str());
776 H1->SetLineColor((i+1)!=5?(i+1):95);
777 if (i==nComp-1 && i!=0)
779 H1->SetFillColor(H1->GetLineColor());
780 H1->SetFillStyle(3001);
782 H1->DrawCopy(i==0?
"hist e":
"hist e same");
786 TLine* L1 =
new TLine(0.135, 0, 0.135, H1->GetMaximum());
798 if ( (iPAD == nPAD+1) || (!showMark && b==iToCh[a].size()-1) )
800 if (PRINT) c1->Print(Form(
"%s%s.png", c1->GetName(), Normalize?
"_norm":
""));
806 if (PRINT && showMark) c1->Print(Form(
"%s%s.png", c1->GetName(), Normalize?
"_norm":
""));
810 gSystem->Exec(Form(
"mkdir -p massComp%s", Normalize?
"_norm":
""));
811 gSystem->Exec(Form(
"mv massSep*.png massComp%s", Normalize?
"_norm":
""));
818 void DrawConvProgress(
820 const char* pathIter,
821 map<int, int>iToCh[4],
822 bool excBadDead =
false,
830 for (
unsigned int a=0; a<4; a++) nCellSep[a] = iToCh[a].size();
832 TGraphErrors* G1All =
new TGraphErrors();
833 TGraphErrors* G1Sep[4];
834 for (
int a=0; a<4; a++) G1Sep[a] =
new TGraphErrors();
836 bool checkedFirstSet =
false;
837 for (
int i=0; i<nIter; i++)
839 const char* cellStatFile = Form(
"%s/FmsCellStat_%i.txt", pathIter, i);
840 if (FILE *FTest = fopen(cellStatFile,
"r")) fclose(FTest);
843 map<int, int> chToCellStatIter[4];
844 GetMapChToCellStat(cellStatFile, chToCellStatIter);
847 if (excBadDead==
true && checkedFirstSet==
false)
849 for (
unsigned int a=0; a<4; a++)
851 for (
unsigned int b=0; b<iToCh[a].size(); b++)
853 const int ch = iToCh[a][b];
854 const int cellStat = chToCellStatIter[a][ch];
855 if (cellStat==BAD || cellStat==DEAD)
861 cout <<Form(
"# of valid cells (detId=%2i): %3i", a+8, nCellSep[a]) <<endl;
863 cout <<Form(
"# of valid cells (total): %i", nCellAll) <<endl;
864 checkedFirstSet =
true;
869 int nConvSep[4] = {0};
870 float rConvSep[4] = {0};
871 for (
int a=0; a<4; a++)
873 for (
unsigned int b=0; b<iToCh[a].size(); b++)
875 const int ch = iToCh[a][b];
876 if (chToCellStatIter[a][ch] == CONVERGED)
882 rConvSep[a] = (float)nConvSep[a]/(
float)nCellSep[a];
883 G1Sep[a]->SetPoint(G1Sep[a]->GetN(), i, rConvSep[a]);
885 const float rConvAll = (float)nConvAll/(
float)nCellAll;
886 G1All->SetPoint(G1All->GetN(), i, rConvAll);
889 gStyle->SetOptDate(0);
890 gStyle->SetOptStat(0);
892 TLegend* LEG =
new TLegend(0.55, 0.225, 0.825, 0.375);
893 LEG->SetMargin(0.35);
894 TCanvas* c1 =
new TCanvas(
"convProg",
"Convergence ratio over iterations", 1600, 900);
896 for (
int a=0; a<4; a++)
898 const char* tempTitle1 = excBadDead?
", Excluded Bad/Dead":
"";
899 const char* tempTitle2 = Form(
"detId=%i%s;Iteration index;Convergence ratio", a+8, tempTitle1);
900 c1->cd(a+1)->DrawFrame(-1, -0.05, nIter, 1.05, tempTitle2);
901 G1Sep[a]->SetMarkerSize(1.1);
902 G1Sep[a]->SetMarkerStyle(20);
903 G1Sep[a]->Draw(
"pl same");
907 G1All->SetLineColor(2);
908 G1All->SetMarkerColor(2);
909 G1All->SetMarkerSize(1.1);
910 G1All->SetMarkerStyle(24);
912 LEG->AddEntry(G1Sep[a], Form(
"Ratio (each detId)"),
"pl");
913 LEG->AddEntry(G1All, Form(
"Ratio (all)"),
"pl");
916 G1All->Draw(
"pl same");
918 if (PRINT) c1->Print(Form(
"%s%s.png", c1->GetName(), excBadDead?
"_excBD":
""));
926 const char* pathIter,
927 map<int, int> iToCh[4],
928 map<int, int> chToCellStat[4],
930 vector<int> chMarked[4] = DumVecI
935 bool showMark =
false;
936 for (
int a=0; a<4; a++) {
if (chMarked[a].size() != 0) { showMark =
true;
break; } }
940 gStyle->SetOptDate(0);
949 for (
int a=0; a<4; a++)
957 for (
unsigned int b=0; b<iToCh[a].size(); b++)
959 const int ch = iToCh[a][b];
960 if (!showMark && (chToCellStat[a][ch]==BAD || chToCellStat[a][ch]==DEAD))
962 cout <<Form(
"Invalid channel: detId%i_ch%i, skip...", a+8, ch) <<endl;
969 bool drawThis =
false;
970 for (
unsigned int i=0; i<chMarked[a].size(); i++) {
if (ch == chMarked[a][i]) drawThis =
true; }
971 if (!drawThis)
continue;
977 for (
int i=0; i<nIter; i++)
979 F[i] = TFile::Open(Form(
"%s/out_fmsCalib_%i.root", pathIter, i));
982 c1 =
new TCanvas(Form(
"mass_d%i_ch%i_%i", a+8, ch, iCVS),
"", 400*nCOL, 300*(nPAD/nCOL));
983 c1->SetTitle(c1->GetName());
984 c1->Divide(nCOL, nPAD/nCOL);
988 TCanvas* tempCVS = (TCanvas*)F[i]->Get(Form(
"mass_d%i_ch%i", a+8, ch))->Clone();
990 tempCVS->DrawClonePad();
994 if ( (iPAD==nPAD+1) || (iPAD>nIter) || (!showMark && b==iToCh[a].size()) || (showMark && i==nIter-1) )
996 if (PRINT) c1->Print(Form(
"%s.png", c1->GetName()));
1002 for (
int i=0; i<nIter; i++) F[i]->Close();
1008 gSystem->Exec(
"mkdir -p iterMass");
1009 gSystem->Exec(
"mv *.png iterMass");
1016 void DrawIterMassSingle(
1018 const char* pathIter,
1019 vector<int> chMarked[4] = DumVecI,
1020 const char* outDir =
"iterMass"
1025 bool showMark =
false;
1026 for (
int a=0; a<4; a++) {
if (chMarked[a].size() != 0) { showMark =
true;
break; } }
1030 gStyle->SetOptDate(0);
1032 TFile* F = TFile::Open(Form(
"%s/out_fmsCalib_%i.root", pathIter, iIter));
1033 if (!F || F->IsZombie())
return;
1035 TDirectory* cDir = gDirectory;
1036 TIter keyNext(cDir->GetListOfKeys());
1041 while (keyNew = (TKey*)keyNext())
1045 bool Proceed =
false;
1046 for (
unsigned int a=0; a<4; a++)
1047 for (
unsigned int b=0; b<chMarked[a].size(); b++)
1049 const char* chMarkedName = Form(
"mass_d%i_ch%i", a+8, chMarked[a][b]);
1050 if (!strcmp(chMarkedName, keyNew->GetName())) Proceed =
true;
1052 if (!Proceed)
continue;
1055 if (keyOld && !strcmp(keyOld->GetName(), keyNew->GetName()))
continue;
1056 obj = keyNew->ReadObj();
1058 obj->Print(Form(
"%s.png", obj->GetName()));
1061 gSystem->Exec(Form(
"mkdir -p %s_i%i", outDir, iIter));
1062 gSystem->Exec(Form(
"mv mass_*.png %s_i%i", outDir, iIter));
1071 const char* pathIter,
1072 map<int, int> iToCh[4],
1073 map<int, int> chToCellStat[4],
1075 vector<int> chMarked[4] = DumVecI
1085 bool showMark =
false;
1086 for (
int a=0; a<4; a++) {
if (chMarked[a].size() != 0) { showMark =
true;
break; } }
1091 map<int, float> chToGainCorr[nIter][4];
1092 map<int, st_fitR> chToFitR[nIter][4];
1093 for (
int i=0; i<nIter; i++)
1095 GetMapChToGainCorr(Form(
"%s/FmsGainCorr_%i.txt", pathIter, i), chToGainCorr[i]);
1096 GetMapChToFitR(Form(
"%s/out_fmsCalibFit_%i.txt", pathIter, i), chToFitR[i]);
1099 gStyle->SetOptDate(0);
1100 gStyle->SetOptStat(0);
1101 gStyle->SetLabelSize(0.055,
"xyz");
1102 gStyle->SetTitleSize(0.060,
"xyz");
1103 gStyle->SetTitleOffset(0.75,
"xyz");
1104 gStyle->SetTitleFontSize(0.055);
1106 for (
unsigned int a=0; a<4; a++)
1107 for (
unsigned int b=0; b<iToCh[a].size(); b++)
1109 const int detId = a+8;
1110 const int ch = iToCh[a][b];
1111 if (chToCellStat[a][ch]==BAD || chToCellStat[a][ch]==DEAD)
continue;
1116 bool drawThis =
false;
1117 for (
unsigned int i=0; i<chMarked[a].size(); i++) {
if (ch == chMarked[a][i]) drawThis =
true; }
1118 if (!drawThis)
continue;
1122 TGraphErrors* G1[4];
1123 for (
int x=0; x<4; x++)
1125 G1[x] =
new TGraphErrors();
1126 G1[x]->SetName(Form(
"G1_d%i_ch%i_%i", detId, ch, x));
1127 G1[x]->SetLineColor(x+1);
1128 G1[x]->SetMarkerColor(x+1);
1129 G1[x]->SetMarkerStyle(20);
1133 for (
int i=0; i<nIter; i++)
1135 const float chi2 = chToFitR[i][a][ch].chi2;
1136 const float mass = chToFitR[i][a][ch].mass;
1137 const float massErr = chToFitR[i][a][ch].massErr;
1138 const float width = chToFitR[i][a][ch].width;
1139 const float widthErr = chToFitR[i][a][ch].widthErr;
1140 const float gainCorr = chToGainCorr[i][a][ch];
1142 G1[0]->SetPoint(G1[0]->GetN(), i, chi2);
1143 G1[1]->SetPoint(G1[1]->GetN(), i, mass);
1144 G1[2]->SetPoint(G1[2]->GetN(), i, width);
1145 G1[3]->SetPoint(G1[3]->GetN(), i, gainCorr);
1146 G1[1]->SetPointError(G1[1]->GetN()-1, 0, massErr);
1147 G1[2]->SetPointError(G1[2]->GetN()-1, 0, widthErr);
1149 if (G1[0]->GetN() == 0)
continue;
1151 TCanvas* c1 =
new TCanvas(Form(
"d%i_ch%i", detId, ch), Form(
"detId=%i, ch=%i", detId, ch), 800, 1000);
1154 for (
int x=0; x<4; x++)
1156 const char* statTitle = (chToCellStat[a][ch]==CONVERGED)?
"CONVERGED, ":
"";
1157 const char* subTitle =
"";
1158 if (x==0) subTitle = Form(
"chi2;Iteration;chi2/NDF");
1159 if (x==1) subTitle = Form(
"mass;Iteration;mass");
1160 if (x==2) subTitle = Form(
"width;Iteration;width");
1161 if (x==3) subTitle = Form(
"gainCorr;Iteration;gainCorr");
1162 const char* lastTitle = Form(
"%s%s, %s", statTitle, c1->GetTitle(), subTitle);
1164 const float yMin = G1[x]->GetHistogram()->GetMinimum()*0.9;
1165 const float yMax = G1[x]->GetHistogram()->GetMaximum()*1.1;
1166 c1->cd(x+1)->DrawFrame(-1,yMin,nIter,yMax, lastTitle);
1170 if (x==0) yLine = 1.0;
1171 if (x==1) yLine = 0.135;
1172 if (x==2) yLine = (a<2)?0.02:0.03;
1173 if (x==3) yLine = 1.0;
1174 L1[x] =
new TLine(-1, yLine, nIter, yLine);
1175 L1[x]->SetLineColor(6);
1176 L1[x]->SetLineStyle(2);
1177 L1[x]->SetLineWidth(2);
1178 if (yLine>yMin && yLine<yMax) L1[x]->Draw(
"same");
1183 c1->Print(Form(
"iterPars_%s%s.png", c1->GetName(), (chToCellStat[a][ch]==CONVERGED)?
"_CONV":
""));
1184 for (
int x=0; x<4; x++) { G1[x]->Delete(); L1[x]->Delete(); }
1192 gSystem->Exec(
"mkdir -p iterPars");
1193 gSystem->Exec(
"mv *.png iterPars");