21 bool PlotCompareUtility::compare<Plot2D>(
HistoData *HD) {
24 TH2F *href2d = (TH2F *)HD->getRefHisto();
25 TH2F *hnew2d = (TH2F *)HD->getNewHisto();
28 if (hnew2d ==
NULL || href2d ==
NULL || hnew2d->GetEntries() <= 1 || href2d->GetEntries() <= 1) {
30 HD->setIsEmpty(
true);
return false;
34 bool projectionsPassed =
true;
37 for (
int axis = axisX; axis <= axisY; ++axis) {
40 if (axis == axisX && !HD->getDoProjectionsX())
continue;
41 if (axis == axisX && href2d->GetNbinsY() != hnew2d->GetNbinsY()) {
42 std::cerr << HD->getName() <<
" error: incorrect number of bins for X projection tests\n";
43 projectionsPassed =
false;
continue;
47 if (axis == axisY && !HD->getDoProjectionsY())
continue;
48 if (axis == axisY && href2d->GetNbinsX() != hnew2d->GetNbinsX()) {
49 std::cerr << HD->getName() <<
" error: incorrect number of bins for Y projection tests\n";
50 projectionsPassed =
false;
continue;
54 int nBins = (axis == axisX) ? href2d->GetNbinsY() : href2d->GetNbinsX();
55 int nProjections = (axis == axisX) ? HD->getMaxProjectionsX() : HD->getMaxProjectionsY();
56 int nGroups = (int)ceil(
float(nBins) / nProjections);
57 bool rebinned =
false;
60 if (axis == axisX && HD->getDoAllow2DRebinningX() && nGroups > 1) {
61 href2d = (TH2F *)(((TH2F *)(href2d->Clone()))->RebinY(nGroups));
62 hnew2d = (TH2F *)(((TH2F *)(hnew2d->Clone()))->RebinY(nGroups));
63 nBins = href2d->GetNbinsY();
68 if (axis == axisY && HD->getDoAllow2DRebinningY() && nGroups > 1) {
69 href2d = (TH2F *)(((TH2F *)(href2d->Clone()))->RebinX(nGroups));
70 hnew2d = (TH2F *)(((TH2F *)(hnew2d->Clone()))->RebinX(nGroups));
71 nBins = href2d->GetNbinsX();
79 std::cout <<
"bin " <<
bin <<
" of " << nBins << std::endl;
81 TString projName = HD->getName() + (axis == axisX ?
"_px" :
"_py"); projName +=
bin;
82 TString newProjName =
"new_"; newProjName += projName;
83 TString refProjName =
"ref_"; refProjName += projName;
86 TH1D *hnew = (axis == axisX) ? hnew2d->ProjectionX(newProjName.Data(),
bin,
bin) : hnew2d->ProjectionY(newProjName.Data(),
bin,
bin);
87 TH1D *href = (axis == axisX) ? href2d->ProjectionX(refProjName.Data(),
bin,
bin) : href2d->ProjectionY(refProjName.Data(),
bin,
bin);
90 hnew->GetXaxis()->SetTitle((axis == axisX ? hnew2d->GetXaxis()->GetTitle() : hnew2d->GetYaxis()->GetTitle()));
91 href->GetXaxis()->SetTitle((axis == axisX ? href2d->GetXaxis()->GetTitle() : href2d->GetYaxis()->GetTitle()));
94 hnew->SetBit(kCanDelete);
95 href->SetBit(kCanDelete);
98 HistoData *proj = (axis == axisX) ? addProjectionXData(HD,projName.Data(),
Plot1D,
bin,hnew,href) \
99 : addProjectionYData(HD,projName.Data(),
Plot1D,
bin,hnew,href);
103 if (hnew->GetEntries() <= 1 || href->GetEntries() <= 1||hnew->Integral() == 0 || href->Integral() == 0)
continue;
106 projectionsPassed &= compare<Plot1D>(proj);
110 if (lowScore < HD->getLowScore()) HD->setLowScore(lowScore);
111 if (highScore > HD->getHighScore()) HD->setHighScore(highScore);
117 delete href2d; href2d = (TH2F *)HD->getRefHisto();
118 delete hnew2d; hnew2d = (TH2F *)HD->getNewHisto();
124 HD->setResult(projectionsPassed);
125 HD->setIsEmpty(
false);
128 return projectionsPassed;
133 void PlotCompareUtility::makePlots<Plot2D>(
HistoData *HD) {
136 if (HD->getIsEmpty()) {
137 HD->setResultImage(
"NoData_Results.gif");
138 HD->setResultTarget(
"NoData_Results.gif");
143 std::vector<HistoData>::iterator hd;
144 for (hd = projectionsX[HD].
begin(); hd != projectionsX[HD].end(); hd++) makePlots<Plot1D>(&(*hd));
145 for (hd = projectionsY[HD].
begin(); hd != projectionsY[HD].end(); hd++) makePlots<Plot1D>(&(*hd));
148 for (
int axis = axisX; axis <= axisY; ++axis) {
151 std::vector<HistoData> *proj = (axis == axisX) ? &projectionsX[HD] : &projectionsY[HD];
152 if (proj ==
NULL || proj->size() == 0)
continue;
156 TH2F *href2d = (TH2F *)HD->getRefHisto();
159 int numHistos = proj->size();
160 int bodyWidth = int(
float(numHistos * projectionsBarsThickness) * 1.5);
161 projectionsWidth = projectionsLeftMargin + projectionsRightMargin + bodyWidth;
164 int projectionsCanvasWidth = projectionsWidth + 4;
165 int projectionsCanvasHeight = projectionsHeight + 28;
168 TCanvas projectionsCanvas(
"projectionsCanvas",
"projectionsCanvas",projectionsCanvasWidth,projectionsCanvasHeight);
169 projectionsCanvas.SetFrameFillColor(10);
170 projectionsCanvas.SetLogy(1);
171 projectionsCanvas.SetTopMargin(
float(projectionsTopMargin) / projectionsHeight);
172 projectionsCanvas.SetLeftMargin(
float(projectionsLeftMargin) / projectionsWidth);
173 projectionsCanvas.SetRightMargin(
float(projectionsRightMargin) / projectionsWidth);
174 projectionsCanvas.SetBottomMargin(
float(projectionsBottomMargin) / projectionsHeight);
175 projectionsCanvas.Draw();
178 TH1F projectionsSummary(
"projectionsSummary",
"Compatibility with Reference Histograms",numHistos,1,numHistos+1);
179 projectionsSummary.GetYaxis()->SetRangeUser(getThreshold()/10,2);
180 projectionsSummary.SetStats(0);
183 projectionsSummary.Draw(
"AH");
186 float xMin = hnew2d->GetXaxis()->GetXmin();
187 float xMax = hnew2d->GetXaxis()->GetXmax();
188 int ticksNDiv = numHistos * 20 + bodyWidth / 50;
189 TGaxis *xAxis =
new TGaxis(1,0,numHistos + 1,0,xMin,xMax,ticksNDiv,
"");
190 if (axis == axisX) xAxis->SetTitle(hnew2d->GetYaxis()->GetTitle());
191 if (axis == axisY) xAxis->SetTitle(hnew2d->GetXaxis()->GetTitle());
195 float yMin = getThreshold()/10;
197 TGaxis *yAxis =
new TGaxis(1,yMin,1,yMax,yMin,yMax,510,
"G");
198 yAxis->SetTitle(
"Compatibility");
202 std::vector<HistoData>::iterator pd;
203 for (pd = proj->begin(); pd != proj->end(); pd++)
204 pd->drawResult(&projectionsSummary,
true,
false);
207 TLine passLine(1, getThreshold(), numHistos + 1, getThreshold());
208 passLine.SetLineColor(kRed);
209 passLine.SetLineWidth(2);
210 passLine.SetLineStyle(2);
211 passLine.Draw(
"SAME");
214 std::string gifName = HD->getName() + (axis == axisX ?
"_Results_px.gif" :
"_Results_py.gif");
215 projectionsCanvas.Print(gifName.c_str());
218 std::string projName = HD->getName() + (axis == axisX ?
"_py" :
"_px");
221 TH1D *href = (axis == axisX) ? href2d->ProjectionY(refBinsProj.c_str()) : href2d->ProjectionX(refBinsProj.c_str());
222 TH1D *hnew = (axis == axisX) ? hnew2d->ProjectionY(newBinsProj.c_str()) : hnew2d->ProjectionX(newBinsProj.c_str());
225 href->SetBit(kCanDelete);
226 hnew->SetBit(kCanDelete);
230 allBins.setIsEmpty(
false);
231 allBins.setShadedFillColor(HD->getShadedFillColor());
232 allBins.setShadedFillStyle(HD->getShadedFillStyle());
233 allBins.setShadedLineColor(HD->getShadedLineColor());
234 makePlots<Plot1D>(&allBins);
237 if (HD->getResultImage() ==
"" || axis == axisY) HD->setResultImage(projName +
"_Results.gif");
241 std::string xImgTarget = HD->getName() +
"_px_Results.gif";
242 if (currentTarget ==
"" || (axis == axisY && currentTarget == xImgTarget)) HD->setResultTarget(projName +
"_Results.gif");
319 void PlotCompareUtility::makeHTML<Plot2D>(
HistoData *HD) {
332 bool pfDone[2] = {
false,
false };
333 for (
int axis = axisX; axis <= axisY; axis++) {
336 std::vector<HistoData> *proj = (axis == axisX) ? &projectionsX[HD] : &projectionsY[HD];
337 if (proj ==
NULL || proj->size() == 0)
continue;
else pfDone[axis] =
true;
340 std::string gifNameProjections = Name + (axis == axisX ?
"_Results_px.gif" :
"_Results_py.gif");
341 std::string gifNameAllProj = Name + (axis == axisX ?
"_py_Results.gif" :
"_px_Results.gif");
342 std::string gifNameProfile = Name + (axis == axisX ?
"_pfx.gif" :
"_pfy.gif");
343 std::string gifBinPrefix = Name + (axis == axisX ?
"_px" :
"_py");
347 int thumbWidth = plotsWidth / 4;
348 int thumbHeight = plotsHeight / 4;
349 int bodyWidth = projectionsWidth - projectionsLeftMargin - projectionsRightMargin;
350 int leftThumbPos = offset + projectionsLeftMargin + bodyWidth / 4 - thumbWidth / 2;
351 int rightThumbPos = leftThumbPos + bodyWidth / 2;
352 int thumbsLoc = projectionsTopMargin + thumbHeight / 2;
355 std::string htmlNameProfile = Name + (axis == axisX ?
"_Results_px.html" :
"_Results_py.html");
356 std::ofstream
fout(htmlNameProfile.c_str());
359 fout <<
"<!DOCTYPE gif PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>" << std::endl
360 <<
"<html>" << std::endl
361 <<
" <head>" << std::endl
362 <<
" <title>Compatibility of Projections for " << HD->getRefHisto()->GetTitle() <<
"</title>" << std::endl
363 <<
" <script type='text/javascript'>" << std::endl << std::endl
364 <<
" function tn(target,image,class) {" << std::endl
365 <<
" clear()" << std::endl
366 <<
" document.getElementById('thumb_div').setAttribute('class',class)" << std::endl
367 <<
" document.getElementById('thumb_div').setAttribute('className',class)" << std::endl
368 <<
" document.getElementById('thumb_link').href = target" << std::endl
369 <<
" document.getElementById('thumb_img').src = image" << std::endl
370 <<
" document.getElementById('thumb_img').width = '" << thumbWidth <<
"'" << std::endl
371 <<
" document.getElementById('thumb_img').height = '" << thumbHeight <<
"'" << std::endl
372 <<
" document.getElementById('thumb_img').border = '1'" << std::endl
373 <<
" }" << std::endl << std::endl
374 <<
" function clear() {" << std::endl
375 <<
" document.getElementById('thumb_link').href = '#'" << std::endl
376 <<
" document.getElementById('thumb_img').src = ''" << std::endl
377 <<
" document.getElementById('thumb_img').width = '0'" << std::endl
378 <<
" document.getElementById('thumb_img').height = '0'" << std::endl
379 <<
" document.getElementById('thumb_img').border = '0'" << std::endl
380 <<
" }" << std::endl << std::endl
381 <<
" </script>" << std::endl
382 <<
" </head>" << std::endl
383 <<
" <body onClick=\"window.location.href='index.html'\">" << std::endl
385 <<
" <style type='text/css'>" << std::endl
386 <<
" #thumb_div {}" << std::endl
387 <<
" div.thumb_left {position: absolute; left: " << leftThumbPos <<
"px; top: " << thumbsLoc <<
"px;}" << std::endl
388 <<
" div.thumb_right {position: absolute; left: " << rightThumbPos <<
"px; top: " << thumbsLoc <<
"px;}" << std::endl
389 <<
" #main_d {position: absolute; left: " << offset <<
"px;}" << std::endl
390 <<
" a:link {color: #000000}" << std::endl
391 <<
" a:visited {color: #000000}" << std::endl
392 <<
" a:hover {color: #000000}" << std::endl
393 <<
" a:active {color: #000000}" << std::endl
394 <<
" </style>" << std::endl
395 <<
" <div id='main_d'>" << std::endl
397 <<
" <img src='" << gifNameProjections <<
"' usemap='#results' alt=''"
398 <<
" height=" << projectionsHeight <<
" width=" << projectionsWidth <<
" border=0>" << std::endl
399 <<
" <map id='#results' name='results' onMouseOut=\"clear()\">" << std::endl;
402 std::vector<HistoData>::iterator pd;
403 for (pd = proj->begin(); pd != proj->end(); pd++) {
406 int bin = pd->getBin();
407 int x1 = projectionsLeftMargin + int(
float(bin * 1.5 - 1.25) * projectionsBarsThickness);
408 int x2 = x1 + projectionsBarsThickness;
409 int y1 = projectionsTopMargin + 1;
410 int y2 = projectionsHeight - projectionsBottomMargin;
415 std::string tnClass = (bin - 1 >= float(proj->size()) / 2 ?
"thumb_left" :
"thumb_right");
416 fout <<
" <area shape='rect' alt='' coords='" << x1 <<
"," << y1 <<
"," << x2 <<
"," << y2 <<
"'"
417 <<
" href='" << target <<
"' onMouseOver=\"tn('" << target <<
"','" << image <<
"','" << tnClass
419 <<
"onMouseDown=\"window.location.href='" << target <<
"'\">" << std::endl;
423 fout <<
" <area shape='default' nohref='nohref' onMouseDown='window.location.reload()' alt=''>" << std::endl
424 <<
" </map>" << std::endl
425 <<
" <br><img src=\"" << gifNameAllProj <<
"\">" << std::endl
426 <<
" </div>" << std::endl
427 <<
" <div id='thumb_div'><a href='#' id='thumb_link'><img src='' id='thumb_img' width=0 height=0 border=0></a></div>" << std::endl
429 <<
" </body>" << std::endl
430 <<
"</html>" << std::endl;
433 HD->setResultTarget(htmlNameProfile);
439 if (pfDone[axisX] && pfDone[axisY]) {
443 std::ofstream
fout(html.c_str());
446 fout <<
"<html>" << std::endl
447 <<
" <frameset rows=\"50%,50%\">" << std::endl
448 <<
" <frame src=\"" << Name <<
"_Results_py.html\">" << std::endl
449 <<
" <frame src=\"" << Name <<
"_Results_px.html\">" << std::endl
450 <<
" <noframes><body>" << std::endl
451 <<
" unable to display frames -- click to select desired page" << std::endl
452 <<
" <br><a href =\"" << Name <<
"_Results_py.html\">Y Projections</a>" << std::endl
453 <<
" <br><a href =\"" << Name <<
"_Results_px.html\">X Projections</a>" << std::endl
454 <<
" </body></noframes>" << std::endl
455 <<
" </frameset>" << std::endl
456 <<
"</html>" << std::endl;
459 HD->setResultTarget(html);
float getLowScore() const
float getHighScore() const
TH1 * getNewHisto() const