Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:04

0001 #include <TCanvas.h>
0002 #include <TH1D.h>
0003 #include <TText.h>
0004 #include <TLine.h>
0005 #include <iostream>
0006 #include "JetMETComp.hh"
0007 
0008 JetMETComp::JetMETComp(map<string, double> compatibilities_v){
0009   compatibilities =   compatibilities_v;
0010 }
0011 
0012 void JetMETComp::MakePlot(string name) {
0013   // build vector with compatibility values
0014   // and vector with path names
0015   vector<double> values;
0016   vector<string> names;
0017   map<string,double>::iterator iter;
0018   for( iter = compatibilities.begin(); iter != compatibilities.end(); iter++ ) {
0019     string tmpstring = iter->first;
0020     if(tmpstring.find(name) != string::npos) {
0021       values.push_back(iter->second);
0022       string tmpstring2 = iter->first;
0023       names.push_back(tmpstring2.erase(0, name.length()-3));
0024     }
0025   }
0026 
0027   string filename = name+"_compatibility";
0028 
0029   TH1D* comp = new TH1D(filename.c_str(), filename.c_str(), values.size(),0., double(values.size()));
0030   for(int i=0; i< int(values.size()); i++) {
0031     comp->GetXaxis()->SetBinLabel(i+1,names[i].c_str());
0032     comp->SetBinContent(i+1,values[i]);
0033   }
0034   
0035   // From JetMET code
0036   // create summary canvas
0037   TCanvas main_c("main_c","main_c",799,780);
0038   main_c.SetFillColor(0);
0039   main_c.SetBorderMode(0);
0040 
0041   main_c.Draw();
0042 
0043   TPad main_p("main_p","main_p",0.01,0.01,0.99,0.94);
0044   main_p.SetFillColor(0);
0045   main_p.SetBorderMode(0);
0046   main_p.SetLeftMargin(0.30);
0047   main_p.SetBottomMargin(0.15);
0048   main_p.SetLogx(1);
0049   main_p.SetGrid();
0050   main_p.SetFrameFillColor(10);
0051   main_p.Draw();
0052   
0053   main_c.cd();
0054   //   TText summary_title(.01, .95, "");
0055   //   summary_title.Draw("SAME");
0056 
0057   main_p.cd();
0058 
0059   // setup the passing test bars
0060   comp->SetStats(0);
0061   comp->GetXaxis()->SetLabelSize(0.04);
0062   //  comp->GetYaxis()->SetTitle(filename.c_str());
0063   comp->GetYaxis()->SetTitle("");
0064   comp->SetBarWidth(0.7);
0065   comp->SetBarOffset(0.1);
0066   comp->SetFillColor(38);
0067   comp->SetLineColor(2);
0068   comp->GetYaxis()->SetRangeUser(1E-7,2.);
0069   comp->Draw("hbar2");
0070 
0071 //   // setup the failing test bars
0072 //   h1dResults_failed.SetStats(0);
0073 //   h1dResults_failed.GetXaxis()->SetLabelSize(0.04);
0074 //   h1dResults_failed.GetYaxis()->SetTitle(filename.c_str());
0075 //   h1dResults_failed.SetBarWidth(0.7);
0076 //   h1dResults_failed.SetBarOffset(0.1);
0077 //   h1dResults_failed.SetFillColor(kRed);
0078 //   h1dResults_failed.SetLineColor(1);
0079 //   h1dResults_failed.GetYaxis()->SetRangeUser(1E-7,2);
0080 //   h1dResults_failed.Draw("hbar0SAME");
0081 
0082   // draw the pass/fail threshold line
0083   float threshold = std::pow(10.,-6.);
0084   TLine l(threshold, 0, threshold, values.size());
0085   l.SetLineColor(kRed);
0086   l.SetLineWidth(2);
0087   l.SetLineStyle(2);
0088   l.Draw("SAME"); 
0089   
0090   main_c.SaveAs(string(filename+".eps").c_str());
0091   
0092   lines.push_back("<div id=\"main_d\">");
0093   lines.push_back("<div id=\"main_d\">"); 
0094   lines.push_back("<img src=\""+filename+".jpg\" usemap=\"#"+filename+
0095           "\" alt=\"\" style=\"border-style: none;\">"); 
0096   lines.push_back("<map id=\""+filename+"\" name=\""+filename+"\">");
0097 //   for(int i=1; i<=names.size(); i++) {
0098 //     char coordinates[256];
0099 //     sprintf(coordinates,"\"241,%i,689,%i\"",88+26*(i-1),105+26*(i-1));
0100 //     lines.push_back("<area shape=\"rect\" alt=\"\" coords="+string(coordinates)+" href=\""+
0101 //          name+names[names.size()-i].erase(0,3)+".jpg\">"); 
0102 //   }
0103   int barsize = (15*26/names.size());
0104   for(int i=1; i<=names.size(); i++) {
0105     char coordinates[256];
0106     sprintf(coordinates,"\"241,%i,689,%i\"",88+barsize*(i-1),int(88+barsize*(i-0.3)));
0107     lines.push_back("<area shape=\"rect\" alt=\"\" coords="+string(coordinates)+" href=\""+
0108             name+names[names.size()-i].erase(0,3)+".jpg\">"); 
0109   }
0110   lines.push_back("</map>");
0111   lines.push_back("</div>");
0112 }
0113 
0114 void JetMETComp::WriteFile() {
0115   system("\\rm compatibility.html");
0116   FILE*  f=fopen("compatibility.html","w");
0117   for(unsigned int j = 0; j< lines.size(); j++) {
0118     fprintf(f,"%s\n",lines[j].c_str());
0119   }
0120   fclose(f);
0121 }