21 bool PlotCompareUtility::compare<Plot2D>(
HistoData *HD) {
23 TH2F *href2d = (TH2F *)HD->getRefHisto();
24 TH2F *hnew2d = (TH2F *)HD->getNewHisto();
27 if (hnew2d ==
nullptr || href2d ==
nullptr || hnew2d->GetEntries() <= 1 || href2d->GetEntries() <= 1) {
35 bool projectionsPassed =
true;
38 for (
int axis = axisX; axis <= axisY; ++axis) {
41 if (axis == axisX && !HD->getDoProjectionsX())
43 if (axis == axisX && href2d->GetNbinsY() != hnew2d->GetNbinsY()) {
44 std::cerr << HD->getName() <<
" error: incorrect number of bins for X projection tests\n";
45 projectionsPassed =
false;
51 if (axis == axisY && !HD->getDoProjectionsY())
53 if (axis == axisY && href2d->GetNbinsX() != hnew2d->GetNbinsX()) {
54 std::cerr << HD->getName() <<
" error: incorrect number of bins for Y projection tests\n";
55 projectionsPassed =
false;
60 int nBins = (axis == axisX) ? href2d->GetNbinsY() : href2d->GetNbinsX();
61 int nProjections = (axis == axisX) ? HD->getMaxProjectionsX() : HD->getMaxProjectionsY();
62 int nGroups = (
int)ceil(
float(nBins) / nProjections);
63 bool rebinned =
false;
66 if (axis == axisX && HD->getDoAllow2DRebinningX() && nGroups > 1) {
67 href2d = (TH2F *)(((TH2F *)(href2d->Clone()))->RebinY(nGroups));
68 hnew2d = (TH2F *)(((TH2F *)(hnew2d->Clone()))->RebinY(nGroups));
69 nBins = href2d->GetNbinsY();
74 if (axis == axisY && HD->getDoAllow2DRebinningY() && nGroups > 1) {
75 href2d = (TH2F *)(((TH2F *)(href2d->Clone()))->RebinX(nGroups));
76 hnew2d = (TH2F *)(((TH2F *)(hnew2d->Clone()))->RebinX(nGroups));
77 nBins = href2d->GetNbinsX();
84 std::cout <<
"bin " <<
bin <<
" of " << nBins << std::endl;
86 TString projName = HD->getName() + (axis == axisX ?
"_px" :
"_py");
88 TString newProjName =
"new_";
89 newProjName += projName;
90 TString refProjName =
"ref_";
91 refProjName += projName;
94 TH1D *hnew = (axis == axisX) ? hnew2d->ProjectionX(newProjName.Data(),
bin,
bin)
95 : hnew2d->ProjectionY(newProjName.Data(),
bin,
bin);
96 TH1D *
href = (axis == axisX) ? href2d->ProjectionX(refProjName.Data(),
bin,
bin)
97 : href2d->ProjectionY(refProjName.Data(),
bin,
bin);
100 hnew->GetXaxis()->SetTitle((axis == axisX ? hnew2d->GetXaxis()->GetTitle() : hnew2d->GetYaxis()->GetTitle()));
101 href->GetXaxis()->SetTitle((axis == axisX ? href2d->GetXaxis()->GetTitle() : href2d->GetYaxis()->GetTitle()));
104 hnew->SetBit(kCanDelete);
105 href->SetBit(kCanDelete);
109 : addProjectionYData(HD, projName.Data(),
Plot1D,
bin, hnew,
href);
113 if (hnew->GetEntries() <= 1 || href->GetEntries() <= 1 || hnew->Integral() == 0 || href->Integral() == 0)
117 projectionsPassed &= compare<Plot1D>(proj);
122 if (lowScore < HD->getLowScore())
123 HD->setLowScore(lowScore);
124 if (highScore > HD->getHighScore())
125 HD->setHighScore(highScore);
131 href2d = (TH2F *)HD->getRefHisto();
133 hnew2d = (TH2F *)HD->getNewHisto();
138 HD->setResult(projectionsPassed);
139 HD->setIsEmpty(
false);
142 return projectionsPassed;
146 void PlotCompareUtility::makePlots<Plot2D>(
HistoData *HD) {
148 if (HD->getIsEmpty()) {
149 HD->setResultImage(
"NoData_Results.gif");
150 HD->setResultTarget(
"NoData_Results.gif");
155 std::vector<HistoData>::iterator hd;
156 for (hd = projectionsX[HD].
begin(); hd != projectionsX[HD].end(); hd++)
157 makePlots<Plot1D>(&(*hd));
158 for (hd = projectionsY[HD].
begin(); hd != projectionsY[HD].end(); hd++)
159 makePlots<Plot1D>(&(*hd));
162 for (
int axis = axisX; axis <= axisY; ++axis) {
164 std::vector<HistoData> *proj = (axis == axisX) ? &projectionsX[HD] : &projectionsY[HD];
165 if (proj ==
nullptr || proj->empty())
169 TH2F *hnew2d = (TH2F *)HD->getNewHisto();
170 TH2F *href2d = (TH2F *)HD->getRefHisto();
173 int numHistos = proj->size();
174 int bodyWidth =
int(
float(numHistos * projectionsBarsThickness) * 1.5);
175 projectionsWidth = projectionsLeftMargin + projectionsRightMargin + bodyWidth;
179 int projectionsCanvasWidth = projectionsWidth + 4;
180 int projectionsCanvasHeight = projectionsHeight + 28;
183 TCanvas projectionsCanvas(
184 "projectionsCanvas",
"projectionsCanvas", projectionsCanvasWidth, projectionsCanvasHeight);
185 projectionsCanvas.SetFrameFillColor(10);
186 projectionsCanvas.SetLogy(1);
187 projectionsCanvas.SetTopMargin(
float(projectionsTopMargin) / projectionsHeight);
188 projectionsCanvas.SetLeftMargin(
float(projectionsLeftMargin) / projectionsWidth);
189 projectionsCanvas.SetRightMargin(
float(projectionsRightMargin) / projectionsWidth);
190 projectionsCanvas.SetBottomMargin(
float(projectionsBottomMargin) / projectionsHeight);
191 projectionsCanvas.Draw();
194 TH1F projectionsSummary(
195 "projectionsSummary",
"Compatibility with Reference Histograms", numHistos, 1, numHistos + 1);
196 projectionsSummary.GetYaxis()->SetRangeUser(getThreshold() / 10, 2);
197 projectionsSummary.SetStats(
false);
200 projectionsSummary.Draw(
"AH");
203 float xMin = hnew2d->GetXaxis()->GetXmin();
204 float xMax = hnew2d->GetXaxis()->GetXmax();
205 int ticksNDiv = numHistos * 20 + bodyWidth / 50;
206 TGaxis *
xAxis =
new TGaxis(1, 0, numHistos + 1, 0, xMin, xMax, ticksNDiv,
"");
208 xAxis->SetTitle(hnew2d->GetYaxis()->GetTitle());
210 xAxis->SetTitle(hnew2d->GetXaxis()->GetTitle());
214 float yMin = getThreshold() / 10;
216 TGaxis *
yAxis =
new TGaxis(1, yMin, 1, yMax, yMin, yMax, 510,
"G");
217 yAxis->SetTitle(
"Compatibility");
221 std::vector<HistoData>::iterator pd;
222 for (pd = proj->begin(); pd != proj->end(); pd++)
223 pd->drawResult(&projectionsSummary,
true,
false);
226 TLine passLine(1, getThreshold(), numHistos + 1, getThreshold());
227 passLine.SetLineColor(kRed);
228 passLine.SetLineWidth(2);
229 passLine.SetLineStyle(2);
230 passLine.Draw(
"SAME");
233 std::string gifName = HD->getName() + (axis == axisX ?
"_Results_px.gif" :
"_Results_py.gif");
234 projectionsCanvas.Print(gifName.c_str());
237 std::string projName = HD->getName() + (axis == axisX ?
"_py" :
"_px");
240 TH1D *
href = (axis == axisX) ? href2d->ProjectionY(refBinsProj.c_str()) : href2d->ProjectionX(refBinsProj.c_str());
241 TH1D *hnew = (axis == axisX) ? hnew2d->ProjectionY(newBinsProj.c_str()) : hnew2d->ProjectionX(newBinsProj.c_str());
244 href->SetBit(kCanDelete);
245 hnew->SetBit(kCanDelete);
253 makePlots<Plot1D>(&allBins);
256 if (HD->getResultImage().empty() || axis == axisY)
257 HD->setResultImage(projName +
"_Results.gif");
261 std::string xImgTarget = HD->getName() +
"_px_Results.gif";
262 if (currentTarget.empty() || (axis == axisY && currentTarget == xImgTarget))
263 HD->setResultTarget(projName +
"_Results.gif");
340 void PlotCompareUtility::makeHTML<Plot2D>(
HistoData *HD) {
353 bool pfDone[2] = {
false,
false};
354 for (
int axis = axisX; axis <= axisY; axis++) {
356 std::vector<HistoData> *proj = (axis == axisX) ? &projectionsX[HD] : &projectionsY[HD];
357 if (proj ==
nullptr || proj->empty())
363 std::string gifNameProjections = Name + (axis == axisX ?
"_Results_px.gif" :
"_Results_py.gif");
364 std::string gifNameAllProj = Name + (axis == axisX ?
"_py_Results.gif" :
"_px_Results.gif");
365 std::string gifNameProfile = Name + (axis == axisX ?
"_pfx.gif" :
"_pfy.gif");
366 std::string gifBinPrefix = Name + (axis == axisX ?
"_px" :
"_py");
370 int thumbWidth = plotsWidth / 4;
371 int thumbHeight = plotsHeight / 4;
372 int bodyWidth = projectionsWidth - projectionsLeftMargin - projectionsRightMargin;
373 int leftThumbPos = offset + projectionsLeftMargin + bodyWidth / 4 - thumbWidth / 2;
374 int rightThumbPos = leftThumbPos + bodyWidth / 2;
375 int thumbsLoc = projectionsTopMargin + thumbHeight / 2;
378 std::string htmlNameProfile = Name + (axis == axisX ?
"_Results_px.html" :
"_Results_py.html");
379 std::ofstream
fout(htmlNameProfile.c_str());
382 fout <<
"<!DOCTYPE gif PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>" << std::endl
383 <<
"<html>" << std::endl
384 <<
" <head>" << std::endl
385 <<
" <title>Compatibility of Projections for " << HD->getRefHisto()->GetTitle() <<
"</title>" << std::endl
386 <<
" <script type='text/javascript'>" << std::endl
388 <<
" function tn(target,image,class) {" << std::endl
389 <<
" clear()" << std::endl
391 "document.getElementById('thumb_div').setAttribute('class',class)" 394 "document.getElementById('thumb_div').setAttribute('className'," 397 <<
" document.getElementById('thumb_link').href = target" << std::endl
398 <<
" document.getElementById('thumb_img').src = image" << std::endl
399 <<
" document.getElementById('thumb_img').width = '" << thumbWidth <<
"'" << std::endl
400 <<
" document.getElementById('thumb_img').height = '" << thumbHeight <<
"'" << std::endl
401 <<
" document.getElementById('thumb_img').border = '1'" << std::endl
404 <<
" function clear() {" << std::endl
405 <<
" document.getElementById('thumb_link').href = '#'" << std::endl
406 <<
" document.getElementById('thumb_img').src = ''" << std::endl
407 <<
" document.getElementById('thumb_img').width = '0'" << std::endl
408 <<
" document.getElementById('thumb_img').height = '0'" << std::endl
409 <<
" document.getElementById('thumb_img').border = '0'" << std::endl
412 <<
" </script>" << std::endl
413 <<
" </head>" << std::endl
414 <<
" <body onClick=\"window.location.href='index.html'\">" 417 <<
" <style type='text/css'>" << std::endl
418 <<
" #thumb_div {}" << std::endl
419 <<
" div.thumb_left {position: absolute; left: " << leftThumbPos <<
"px; top: " << thumbsLoc <<
"px;}" 421 <<
" div.thumb_right {position: absolute; left: " << rightThumbPos <<
"px; top: " << thumbsLoc <<
"px;}" 423 <<
" #main_d {position: absolute; left: " << offset <<
"px;}" << std::endl
424 <<
" a:link {color: #000000}" << std::endl
425 <<
" a:visited {color: #000000}" << std::endl
426 <<
" a:hover {color: #000000}" << std::endl
427 <<
" a:active {color: #000000}" << std::endl
428 <<
" </style>" << std::endl
429 <<
" <div id='main_d'>" 433 <<
" <img src='" << gifNameProjections <<
"' usemap='#results' alt=''" 434 <<
" height=" << projectionsHeight <<
" width=" << projectionsWidth <<
" border=0>" << std::endl
435 <<
" <map id='#results' name='results' onMouseOut=\"clear()\">" << std::endl;
438 std::vector<HistoData>::iterator pd;
439 for (pd = proj->begin(); pd != proj->end(); pd++) {
441 int bin = pd->getBin();
442 int x1 = projectionsLeftMargin +
int(
float(bin * 1.5 - 1.25) * projectionsBarsThickness);
443 int x2 = x1 + projectionsBarsThickness;
444 int y1 = projectionsTopMargin + 1;
445 int y2 = projectionsHeight - projectionsBottomMargin;
450 std::string tnClass = (bin - 1 >=
float(proj->size()) / 2 ?
"thumb_left" :
"thumb_right");
451 fout <<
" <area shape='rect' alt='' coords='" << x1 <<
"," << y1 <<
"," << x2 <<
"," << y2 <<
"'" 452 <<
" href='" << target <<
"' onMouseOver=\"tn('" << target <<
"','" << image <<
"','" << tnClass <<
"')\" " 453 <<
"onMouseDown=\"window.location.href='" << target <<
"'\">" << std::endl;
456 fout <<
" <area shape='default' nohref='nohref' " 457 "onMouseDown='window.location.reload()' alt=''>" 459 <<
" </map>" << std::endl
460 <<
" <br><img src=\"" << gifNameAllProj <<
"\">" << std::endl
461 <<
" </div>" << std::endl
462 <<
" <div id='thumb_div'><a href='#' id='thumb_link'><img src='' " 463 "id='thumb_img' width=0 height=0 border=0></a></div>" 466 <<
" </body>" << std::endl
467 <<
"</html>" << std::endl;
470 HD->setResultTarget(htmlNameProfile);
475 if (pfDone[axisX] && pfDone[axisY]) {
478 std::ofstream
fout(html.c_str());
481 fout <<
"<html>" << std::endl
482 <<
" <frameset rows=\"50%,50%\">" << std::endl
483 <<
" <frame src=\"" << Name <<
"_Results_py.html\">" << std::endl
484 <<
" <frame src=\"" << Name <<
"_Results_px.html\">" << std::endl
485 <<
" <noframes><body>" << std::endl
486 <<
" unable to display frames -- click to select desired page" << std::endl
487 <<
" <br><a href =\"" << Name <<
"_Results_py.html\">Y Projections</a>" << std::endl
488 <<
" <br><a href =\"" << Name <<
"_Results_px.html\">X Projections</a>" << std::endl
489 <<
" </body></noframes>" << std::endl
490 <<
" </frameset>" << std::endl
491 <<
"</html>" << std::endl;
494 HD->setResultTarget(html);
void setIsEmpty(bool Toggle)
void setShadedFillColor(int Color)
float getLowScore() const
void setShadedLineColor(int Color)
bin
set the eta bin as selection string.
float getHighScore() const
void setShadedFillStyle(int Style)