// // IWindowSurface::getDefaultCanvas // // Returns the default DCanvas object for the surface, creating it if it // has not yet been instantiated. // DCanvas* IWindowSurface::getDefaultCanvas() { if (mCanvas == NULL) mCanvas = createCanvas(); return mCanvas; }
KisCanvas2::KisCanvas2(KoViewConverter * viewConverter, KisView2 * view, KoShapeControllerBase * sc) : KoCanvasBase(sc) , m_d(new KisCanvas2Private(this, viewConverter, view)) { createCanvas(); connect(view->canvasController(), SIGNAL(moveDocumentOffset(const QPoint&)), SLOT(documentOffsetMoved(const QPoint&))); connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotConfigChanged())); }
void MainWindow::open() { QString fileName = QFileDialog::getOpenFileName(this, tr("Import Input File"), "/", tr("Geometry Files (*.nom *.sif *.anom)")); if(fileName == "") { return; } createCanvas(fileName); }
int svgTopng(char* inputFile,char* outputFile){ hmin=99999999; hmax=0; parseSVG(inputFile); createCanvas(); save(outputFile); return 0; }
static void processSvgElement(xmlTextReaderPtr const xmlReaderP, FILE * const ofP) { unsigned int width, height; bool endOfSvg; canvas * canvasP; assert(xmlTextReaderNodeType(xmlReaderP) == XML_READER_TYPE_ELEMENT); assert(streq(currentNodeName(xmlReaderP), "svg")); getSvgAttributes(xmlReaderP, &width, &height); createCanvas(width, height, 255, &canvasP); endOfSvg = xmlTextReaderIsEmptyElement(xmlReaderP); while (!endOfSvg) { int rc; rc = xmlTextReaderRead(xmlReaderP); switch (rc) { case 1: processSubSvgNode(xmlReaderP, canvasP, &endOfSvg); break; case 0: pm_error("Input file ends in the middle of a <svg>"); break; default: pm_error("xmlTextReaderRead() failed, rc=%d", rc); } } writePam(ofP, canvasP); destroyCanvas(canvasP); }
// ----------------------------------------------------------------------------- // TCanvas* createPlot( TDirectory* output_file, std::string output_canvas, //std::vector< std::vector<std::string> > input_files, std::vector<std::string> input_files, std::vector<std::string> input_histos, std::vector<std::string> input_legend, std::vector<int> marker_style, std::vector<int> marker_colour, std::vector<float> marker_size, std::vector<float> lumis, double lumi, int rebin, bool norm, bool log, double min = -1., double max = -1., int integral = -1 ) { // SetSomeStyles(); // Check integral if ( integral >= input_files.size() ) { integral = -1; } // Loop through histogram names std::vector<TH1D*> his; for ( uint ihis = 0; ihis < input_histos.size(); ++ihis ) { if ( integral < 0 || ihis <= integral ) { his.push_back( (TH1D*)getHisto( input_files[ihis], input_histos[ihis], "QcdBkgdEst", rebin ) ); } else { his.back()->Add( (TH1D*)getHisto( input_files[ihis], input_histos[ihis], "QcdBkgdEst", rebin ) ); } } // Create legend TLegend* legend = new TLegend( 0.65, 0.52-0.03*his.size(), 0.9, 0.52, NULL, "brNDC" ); legend->SetFillColor(0); legend->SetLineColor(0); legend->SetTextAlign(31); legend->SetTextSize(0.025); // Create canvas TCanvas* aCanvas = createCanvas( output_canvas, output_file, log ); TPaveText* stats = new TPaveText( 0.65, 0.54, 0.9, 0.54+0.03*his.size(), "brNDC" ); stats->SetFillColor(0); stats->SetLineColor(0); TLatex* prelim = new TLatex( 0.15, 0.96, "#scale[0.8]{CMS preliminary 2011}" ); prelim->SetTextSize(0.03); prelim->SetNDC(); std::stringstream ssl; ssl << "#scale[0.8]{#int L dt = " << lumi/1000. << " fb^{-1}, #sqrt{s} = 7 TeV}"; TLatex* lumistxt = new TLatex( 0.95, 0.96, ssl.str().c_str() ); lumistxt->SetTextSize(0.03); lumistxt->SetNDC(); lumistxt->SetTextAlign(31); // For Ted bool print_ted = true; std::stringstream ted; if ( print_ted ) { ted << "self._htMeans = ("; } // Loop through histograms double aMax = 0.; double aMin = 1.e12; for ( uint ihis = 0; ihis < his.size(); ++ihis ) { if ( !his[ihis] ) { continue; } // Line colour and fill his[ihis]->Scale(lumis[ihis]/100.); his[ihis]->SetMarkerStyle(marker_style[ihis]); his[ihis]->SetMarkerColor(marker_colour[ihis]); his[ihis]->SetMarkerSize(marker_size[ihis]); his[ihis]->SetLineColor(marker_colour[ihis]); his[ihis]->SetLineStyle(0); his[ihis]->SetLineWidth(0); // Populate legend if ( input_legend.size() > ihis ) { legend->AddEntry( his[ihis], input_legend[ihis].c_str(), "ep" ); } else { legend->AddEntry( his[ihis], input_histos[ihis].c_str(), "ep" ); } // Populate stats box std::stringstream ss; //ss << "Mean=" << int(his[ihis]->GetMean()*100.)/100. << ", RMS=" << int(his[ihis]->GetRMS()*100.)/100.; ss << "Entries=" << his[ihis]->GetEntries(); TText* text = stats->AddText(ss.str().c_str()); text->SetTextAlign(11); text->SetTextSize(0.025); text->SetTextColor(marker_colour[ihis]); // For Ted if ( print_ted ) ted << std::setw(9) << std::scientific << std::setprecision(3) << his[ihis]->GetMean() << ", "; // Calc min/max number of entries if ( his[ihis]->GetMaximum() > aMax ) { aMax = his[ihis]->GetMaximum(); } if ( his[ihis]->GetMinimum(1.e-12) < aMin ) { aMin = his[ihis]->GetMinimum(1.e-12); } } // For Ted if ( print_ted ) { ted << ")" << std::endl; std::cout << ted.str() << std::endl; } if ( !his.empty() ) { if ( his[0] ) his[0]->GetYaxis()->SetTitleOffset(1.43); if ( his[0] ) his[0]->GetYaxis()->SetTitleSize(0.06); if ( his[0] ) his[0]->GetXaxis()->SetTitleSize(0.06); if ( his[0] ) his[0]->GetXaxis()->SetTitleOffset(0.9); } // First histo be drawn bool first = true; for ( uint ihis = 0; ihis < his.size(); ++ihis ) { if ( !his[ihis] ) { continue; } //his[ihis]->GetYaxis()->SetTitle("a.u."); if ( log ) { his[ihis]->SetMaximum( aMax * 10. ); his[ihis]->SetMinimum( aMin * 0.1 ); } else { his[ihis]->SetMaximum( aMax * 1.1 ); his[ihis]->SetMinimum( aMin * 0.9 ); } if ( min > 0. ) his[ihis]->SetMinimum( min ); if ( max > 0. ) his[ihis]->SetMaximum( max ); if ( norm ) { std::string options = ""; if ( first ) { options = "Ehist"; first = false; } else { options = "psame"; } if ( his[ihis]->GetEntries() > 0. ) { his[ihis]->DrawNormalized(options.c_str()); } } else { std::string options = ""; if ( first ) { options = "Ehist"; first = false; } else { options = "psame"; } his[ihis]->Draw(options.c_str()); } } // Loop through histos output_file->cd(); legend->Draw("same"); stats->Draw("same"); prelim->Draw("same"); lumistxt->Draw("same"); aCanvas->Modified(); //aCanvas->SaveAs( std::string(output_canvas+".png").c_str() ); aCanvas->SaveAs( std::string(output_canvas+".pdf").c_str() ); aCanvas->SaveAs( std::string(output_canvas+".C").c_str() ); aCanvas->Write(); return aCanvas; }
// ----------------------------------------------------------------------------- // TCanvas* createPlot( TString path, TString canvas_name, TString name, TString dirmame, int rebin, bool norm, bool log, TDirectory* file ) { // SetSomeStyles(); float lumi = 250.0;// 15.04;//10.9;//6.8; // Create legend TLegend* legend = new TLegend(0.75, 0.6, 0.99, 0.99, "", "brNDC" ); legend->SetFillColor(0); legend->SetLineColor(0); legend->SetShadowColor(0); TLatex* prelim = new TLatex(0.6,0.54,"#scale[0.8]{CMS preliminary 2010}"); prelim->SetNDC(); TLatex* alumi = new TLatex(0.6,.45,"#scale[0.8]{#int L dt = 35 pb^{-1}, #sqrt{s} = 7 TeV}"); alumi->SetNDC(); // Create canvas TCanvas* aCanvas = createCanvas( canvas_name, file, log ); // Create histogram TString aname("nAll"); // TH1D* data1 = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",aname,rebin); // TH1D* data = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",dirmame,rebin); TH1D* data = getHisto( path+"", name, "tt.root", dirmame, rebin ); TH1D* qcd = getHisto( path+"", name, "lm1.root", dirmame, rebin ); TH1D* w_jets = getHisto( path+"", name, "w.root", dirmame, rebin ); TH1D* tt_jets = getHisto( path+"", name, "tt.root", dirmame, rebin ); TH1D* z_jets = getHisto( path+"", name, "z.root", dirmame, rebin ); TH1D* lm3 = getHisto( path+"", name, "lm3.root", dirmame, rebin ); TH1D* lm1 = getHisto( path+"", name, "lm1.root", dirmame, rebin ); TH1D* lm6 = getHisto( path+"", name, "data.root", dirmame, rebin ); TH1D* wm = getHisto( path+"", name, "w.root", dirmame, rebin ); data->Scale(lumi/100.); qcd->Scale(lumi/100.); tt_jets->Scale(lumi/100); w_jets->Scale(lumi/100); // w_jets->Scale(10); // z_inv->Scale(lumi/100); // lm6->Scale(lumi/100); lm1->Scale(lumi/100); lm3->Scale(lumi/100); z_jets->Scale(lumi/100); wm->Scale(lumi/100); // Combine Z+jets and Z->inv // TH1D* z_all = z_inv->Clone(); // z_all->Add(z_jets,1); //z_jets->Add(z_inv,1); TH1D* total = tt_jets->Clone(); total->Add(w_jets); total->Add(z_jets); // total-> Int_t binMax = total->GetNbinsX(); Double_t& err = new Double_t(0.); total->IntegralAndError(10,binMax ,err); Double_t& errW = new Double_t(0.); w_jets->IntegralAndError(10,binMax ,errW); Double_t& errtt = new Double_t(0.); tt_jets->IntegralAndError(10,binMax ,errtt); Double_t& errZ = new Double_t(0.); z_jets->IntegralAndError(10,binMax ,errZ); Double_t& errQCD = new Double_t(0.); qcd->IntegralAndError(10,binMax ,errQCD ); cout <<endl; // cout << "MC:" << total->IntegralAndError(11,binMax ,err) <<" && " << w_jets->Integral(11,binMax)<<" && "<<tt_jets->Integral(11,binMax) << "&& "<<z_jets->Integral(11,binMax)<<" && "<< "\/\ /\hline"<<endl; // cout << total->IntegralAndError(0,binMax ,err) <<" & " << lm1->Integral(0,binMax) <<" & " << lm3->Integral(0,binMax)<<" & " << lm6->Integral(0,binMax) <<"\\\\ \\hline"<<endl; // cout <<"270: " << total->IntegralAndError(27,binMax ,err) <<" & " << lm1->Integral(27,binMax) <<" & " << lm3->Integral(27,binMax)<<" & " << lm6->Integral(27,binMax) <<"\\\\ \\hline"<<endl; cout <<"250& " << total->IntegralAndError(6,binMax ,err) <<" & " << lm1->Integral(6,binMax) <<" & " << lm3->Integral(6,binMax)<<" & " << lm6->Integral(6,binMax) <<"\\\\ \\hline"<<endl; // cout << "300: " << total->IntegralAndError(7,binMax ,err) <<" & " << lm1->Integral(7,binMax) <<" & " << lm3->Integral(7,binMax)<<" &" << lm6->Integral(7,binMax) <<"\\\\ \\hline"<<endl; cout <<"350& " << total->IntegralAndError(8,binMax ,err) <<" & " << lm1->Integral(8,binMax) <<" & " << lm3->Integral(8,binMax)<<" & " << lm6->Integral(8,binMax) <<"\\\\ \\hline"<<endl; // cout << "400: " << total->IntegralAndError(9,binMax ,err) <<" & " << lm1->Integral(9,binMax) <<" & " << lm3->Integral(9,binMax)<<" & " << lm6->Integral(9,binMax) <<"\\\\ \\hline"<<endl; cout << "450& " << total->IntegralAndError(10,binMax ,err) <<" & " << lm1->Integral(10,binMax) <<" & " << lm3->Integral(10,binMax)<<" & " << lm6->Integral(10,binMax) <<"\\\\ \\hline"<<endl; //cout << "500: " << total->IntegralAndError(11,binMax ,err) <<" & " << lm1->Integral(11,binMax) <<" & " << lm3->Integral(11,binMax)<<" & " << lm6->Integral(11,binMax) <<"\\\\ \\hline"<<endl; cout <<"550& " << total->IntegralAndError(12,binMax ,err) <<" & " << lm1->Integral(12,binMax) <<" & " << lm3->Integral(12,binMax)<<" & " << lm6->Integral(12,binMax) <<"\\\\ \\hline"<<endl; /* cout << "MC:" << total->IntegralAndError(7,binMax ,err) <<" && " << lm1->Integral(7,binMax) <<" && " << lm3->Integral(7,binMax)<<" && " << lm6->Integral(6,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(8,binMax ,err) <<" && " << lm1->Integral(8,binMax) <<" && " << lm3->Integral(8,binMax)<<" && " << lm6->Integral(7,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(10,binMax ,err) <<" && " << lm1->Integral(10,binMax) <<" && " << lm3->Integral(10,binMax)<<" && " << lm6->Integral(10,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(11,binMax ,err) <<" && " << lm1->Integral(11,binMax) <<" && " << lm3->Integral(11,binMax)<<" && " << lm6->Integral(11,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(12,binMax ,err) <<" && " << lm1->Integral(12,binMax) <<" && " << lm3->Integral(12,binMax)<<" && " << lm6->Integral(12,binMax) <<"/\/\ /\hline"<<endl; // cout << "MC:" << err <<", W: " << errW<<", tt: "<<errtt << ", Z: "<<errZ<<", QCD: "<< errQCD<< endl; */ // cout << "data:" << data->Integral() << endl; TH1D* hcen = total->Clone(); TH1D* herr = total->Clone(); herr->SetLineColor(kTeal+3); herr->SetMarkerColor(kAzure+6); herr->SetFillColor(kAzure+6); herr->SetLineWidth(3); total->SetLineWidth(3); total->SetFillColor(kAzure+2); total->SetLineColor(kAzure+2); total->SetFillStyle(3245); hcen->SetFillStyle(0); hcen->SetMarkerColor(kTeal+3); hcen->SetLineColor(kTeal+3); hcen->SetLineWidth(3); // Merge Z+jets and Z->inv bool combine = false; // Line colour and fill qcd->SetLineColor(kPink+4); qcd->SetLineWidth(3); tt_jets->SetLineColor(kBlue+1); tt_jets->SetLineWidth(3); w_jets->SetLineColor(kPink+7); w_jets->SetLineWidth(3); z_jets->SetLineWidth(3); z_jets->SetLineColor(kTeal-7); if ( combine ) { z_all->SetLineColor(kBlack); z_all->SetLineStyle(3); z_all->SetLineWidth(1); } else { data->SetLineColor(1); data->SetLineStyle(1); data->SetLineWidth(3); data->SetMarkerStyle(20); data->SetFillColor(0); } // lm0->SetLineColor(kRed); // lm0->SetLineWidth(3); // lm1->SetLineColor(kRed+3); // lm1->SetLineWidth(3); // Populate legend // legend->AddEntry( data, "tt fully leptonic/", "LP" ); legend->AddEntry( herr, "full SM", "LP" ); legend->AddEntry( z_jets, " Z+jets ", "LP" ); legend->AddEntry( w_jets, " W+jets", "LP" ); legend->AddEntry( tt_jets, " t#bar{t}", "LP" ); // legend->AddEntry( lm3, " SUSY LM3", "LP" ); // legend->AddEntry( lm1, " SUSY LM1", "LP" ); legend->AddEntry( lm6, " data", "LP" ); // legend->AddEntry(wm,"W Mad","lp"); // Calc maximum number of entries double aMax = 0.; if( data->GetMaximum() > aMax ) { aMax = data->GetMaximum()+data->GetBinError(data->GetMaximumBin()); } if ( qcd->GetMaximum() > aMax ) { aMax = qcd->GetMaximum(); } // if ( lm0->GetMaximum() > aMax ) { aMax = lm0->GetMaximum(); } // if ( lm1->GetMaximum() > aMax ) { aMax = lm1->GetMaximum(); } if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); } if ( w_jets->GetMaximum() > aMax ) { aMax = w_jets->GetMaximum(); } if ( combine ) { if ( z_all->GetMaximum() > aMax ) { aMax = z_all->GetMaximum(); } } else { // if ( data->GetMaximum() > aMax ) { aMax = z_inv->GetMaximum(); } if ( z_jets->GetMaximum() > aMax ) { aMax = z_jets->GetMaximum(); } } // Calc minimum number of entries double aMin = 1.e12; if ( qcd->GetMinimum(1.e-12) < aMin ) { aMin = qcd->GetMinimum(1.e-12); } // if ( lm0->GetMinimum(1.e-12) < aMin ) { aMin = lm0->GetMinimum(1.e-12); } // if ( lm1->GetMinimum(1.e-12) < aMin ) { aMin = lm1->GetMinimum(1.e-12); } if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); } if ( w_jets->GetMinimum(1.e-12) < aMin ) { aMin = w_jets->GetMinimum(1.e-12); } if ( combine ) { if ( z_all->GetMinimum(1.e-12) < aMin ) { aMin = z_all->GetMinimum(1.e-12); } } else { // if ( data->GetMinimum(1.e-12) < aMin ) { aMin = z_inv->GetMinimum(1.e-12); } if ( z_jets->GetMinimum(1.e-12) < aMin ) { aMin = z_jets->GetMinimum(1.e-12); } } if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43); if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06); if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06); if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9); if ( log ) { if ( qcd ) herr->SetMaximum( aMax * 10. ); // if ( qcd ) herr->SetMinimum( aMin * 0.1 ); if ( qcd ) herr->SetMinimum( 0.005); } else { if ( qcd ) herr->SetMaximum( aMax * 1.1 ); // if ( qcd ) herr->SetMinimum( aMin * 0.9 ); if ( qcd ) herr->SetMinimum( 0.005); } /* TPad* mainPad = new TPad("","",0.01,0.25,0.99,0.99); mainPad->SetNumber(1); mainPad->SetFillColor(0); // mainPad->Range(-288.2483,-2.138147,1344.235,6.918939); mainPad->SetFillColor(0); mainPad->SetBorderMode(0); mainPad->SetBorderSize(2); if ( log == true)mainPad->SetLogy(); mainPad->SetLeftMargin(0.1765705); mainPad->SetRightMargin(0.05772496); mainPad->SetTopMargin(0.04778761); mainPad->SetBottomMargin(0.1256637); mainPad->SetFrameFillStyle(0); mainPad->SetFrameLineWidth(2); mainPad->SetFrameBorderMode(0); mainPad->SetFrameFillStyle(0); mainPad->SetFrameLineWidth(2); mainPad->SetFrameBorderMode(0); if ( log == true)mainPad->SetLogy(); mainPad->Draw(); TPad* ratioPad = new TPad("","",0.01,0.01,0.99,0.25); ratioPad->SetNumber(2); ratioPad->SetFillColor(0); ratioPad->SetFillColor(0); ratioPad->SetBorderMode(0); ratioPad->SetBorderSize(2); // if ( log == true)ratioPad->SetLogy(); ratioPad->SetLeftMargin(0.1765705); ratioPad->SetRightMargin(0.05772496); ratioPad->SetTopMargin(0.04778761); ratioPad->SetBottomMargin(0.1256637); ratioPad->SetFrameFillStyle(0); ratioPad->SetFrameLineWidth(2); ratioPad->SetFrameBorderMode(0); ratioPad->SetFrameFillStyle(0); ratioPad->SetFrameLineWidth(2); ratioPad->SetFrameBorderMode(0); // if ( log == true)ratioPad->SetLogy(); ratioPad->Draw(); aCanvas->cd(1); */ herr->GetYaxis()->SetTitle("events"); if ( norm ) { if ( qcd ) qcd->DrawNormalized("Ehist"); // if ( lm0->GetEntries() > 0. ) { lm0->DrawNormalized("hsame"); } if ( lm1->GetEntries() > 0. ) { lm1->DrawNormalized("hsame"); } if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); } if ( w_jets->GetEntries() > 0. ) { w_jets->DrawNormalized("hsame"); } if ( combine ) { if ( z_all->GetEntries() > 0. ) { z_all->DrawNormalized("hsame"); } } else { if ( data->GetEntries() > 0. ) { z_inv->DrawNormalized("hsame"); } if ( z_jets->GetEntries() > 0. ) { z_jets->DrawNormalized("hsame"); } } } else { herr->Draw("hist"); // qcd->SetFillStyle(3240); // qcd->SetFillColor(kPink+4); // qcd->Draw("hist"); w_jets->Draw("hSameh"); z_jets->Draw("9Sameh"); w_jets->Draw("9Sameh"); tt_jets->Draw("9SAMEh"); //data1->Draw("9SAMEh"); //lm0->Draw("9SAMEh"); lm1->SetLineColor(12); lm1->SetLineStyle(2); lm1->SetLineWidth(2); // lm1->Draw("9SAMEh"); lm3->SetLineColor(14); lm3->SetLineStyle(2); lm3->SetLineWidth(2); // lm3->Draw("9SAMEh"); lm6->Draw("9SAMEh"); wm->SetLineStyle(2); wm->SetLineColor(kPink+7); // wm->Draw("9Sameh"); // total->DrawNormalized("9E2same"); // data->Draw("SAMEh"); // tt_jets->Divide(data); // tt_jets->Draw("h"); // data->SetLineColor(kRed); // data->Draw("sameh"); // data1->SetLineColor(kRed); // data1->Draw("9SAMEP"); } legend->Draw(); // prelim->Draw(); // alumi->Draw(); /* TH1D* ratioBottom = total->Clone(); TH1D* ratioTop = data->Clone(); ratioTop->GetYaxis()->SetTitle("data / sim"); ratioTop->Divide(ratioBottom); aCanvas->cd(1)->Update(); aCanvas->cd(2); ratioTop->SetTitleSize(0.1, "XYZ"); ratioTop->SetTitleOffset(0.55, "X"); ratioTop->SetTitleOffset(0.3, "Y"); ratioTop->SetLabelSize(0.06,"XY"); // ratioTop->GetXaxis().SetRangeUser(MinX,MaxX); ratioTop->GetYaxis()->SetRangeUser(0.,2.0); ratioTop->Draw();*/ /* TBox* unity = TBox(ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetFirst()), 0.89,ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetLast()), 1.11); unity->SetLineWidth(2); unity->SetLineColor(2); unity->SetFillColor(2); unity->SetFillStyle(3002); unity->Draw(); */ file->cd(); aCanvas->SaveAs( std::string(canvas_name+".pdf").c_str() ); aCanvas->Write(); // aCanvas->Print(".png"); return aCanvas; }
void PhysicsClientExample::initPhysics() { if (m_guiHelper && m_guiHelper->getParameterInterface()) { int upAxis = 2; m_guiHelper->setUpAxis(upAxis); createButtons(); } else { MyCallback(CMD_LOAD_URDF, true, this); MyCallback(CMD_STEP_FORWARD_SIMULATION,true,this); MyCallback(CMD_STEP_FORWARD_SIMULATION,true,this); MyCallback(CMD_RESET_SIMULATION,true,this); } m_selectedBody = -1; m_prevSelectedBody = -1; if (m_options == eCLIENTEXAMPLE_SERVER) { m_canvas = m_guiHelper->get2dCanvasInterface(); if (m_canvas) { m_canvasIndex = m_canvas->createCanvas("Synthetic Camera",camVisualizerWidth, camVisualizerHeight); for (int i=0;i<camVisualizerWidth;i++) { for (int j=0;j<camVisualizerHeight;j++) { unsigned char red=255; unsigned char green=255; unsigned char blue=255; unsigned char alpha=255; if (i==j) { red = 0; green=0; blue=0; } m_canvas->setPixel(m_canvasIndex,i,j,red,green,blue,alpha); } } m_canvas->refreshImageData(m_canvasIndex); } m_isOptionalServerConnected = m_physicsServer.connectSharedMemory( m_guiHelper); } m_physicsClientHandle = b3ConnectSharedMemory(m_sharedMemoryKey); //m_physicsClientHandle = b3ConnectPhysicsLoopback(SHARED_MEMORY_KEY); //m_physicsClientHandle = b3ConnectPhysicsDirect(); if (!b3CanSubmitCommand(m_physicsClientHandle)) { b3Warning("Cannot connect to physics client"); } }
// ----------------------------------------------------------------------------- // TCanvas* createPlot( TString path, TString canvas_name, TString name, TString dirmame, int rebin, bool norm, bool log, TDirectory* file ) { // SetSomeStyles(); // Create legend TLegend* legend = new TLegend( 0.75, 0.65, 0.92, 0.92, NULL, "brNDC" ); legend->SetFillColor(0); legend->SetLineColor(0); // Create canvas TCanvas* aCanvas = createCanvas( canvas_name, file, log ); // Create histograms // TGraph* DataClean = getHisto( path, name, "Jet6.root", dirmame, rebin ); if(1){ TH1* Data = getHisto( path, name, "JetsDataPlotME.root", dirmame, rebin ); TH1* MC = getHisto( path, name, "JetsMCPlotME.root", dirmame, rebin ); } if(0){ TH1* Data = getHisto( path, name, "L1Jets_Data38.root", dirmame, rebin ); TH1* MC = getHisto( path, name, "L1Jets_MC38.root", dirmame, rebin ); } // Line colour and fill if ( Data ) Data->SetLineColor(1); if ( Data ) Data->SetFillColor(1); if ( Data ) Data->SetFillStyle(3003); if ( Data ) Data->SetMarkerStyle(20); if ( Data ) Data->SetMarkerColor(1); // if ( DataClean ) DataClean->SetLineColor(6); // if ( DataClean ) DataClean->SetFillColor(6); // if ( DataClean ) DataClean->SetFillStyle(3003); // if ( DataClean ) DataClean->SetMarkerStyle(25); // if ( DataClean ) DataClean->SetMarkerColor(6); if ( MC ) MC->SetLineColor(2); if ( MC ) MC->SetLineStyle(1); if ( MC ) MC->SetLineWidth(2); if ( MC ) MC->SetMarkerStyle(23); if ( MC ) MC->SetMarkerColor(2); // Populate legend legend->AddEntry( Data, " Data", "P" ); // legend->AddEntry( DataClean, " DataCleaned", "P" ); legend->AddEntry( MC, " MC", "P" ); // Calc maximum number of entries double aMax = 0.; if ( Data->GetMaximum() > aMax ) { aMax = Data->GetMaximum(); } if ( MC->GetMaximum() > aMax ) { aMax = MC->GetMaximum(); } // Calc minimum number of entries double aMin = 1.e12; if ( Data->GetMinimum(1.e-12) < aMin ) { aMin = Data->GetMinimum(1.e-12); } if ( MC->GetMinimum(1.e-12) < aMin ) { aMin = MC->GetMinimum(1.e-12); } // Data->GetYaxis()->SetRangeUser(-0.6,2.0); if ( Data ) Data->GetYaxis()->SetTitleOffset(1.43); if ( Data ) Data->GetYaxis()->SetTitleSize(0.06); if ( Data ) Data->GetXaxis()->SetTitleSize(0.06); if ( Data ) Data->GetXaxis()->SetTitleOffset(0.9); // Data->SumW2(); // MC->SumW2(); // DataClean->SumW2(); // if ( log ) { // if ( Data ) Data->SetMaximum( aMax * 10. ); // if ( Data ) Data->SetMinimum( aMin * 0.1 ); // } else { // if ( Data ) Data->SetMaximum( aMax * 1.1 ); // if ( Data ) Data->SetMinimum( aMin * 0.9 ); // } if ( norm ) { if ( Data ) Data->Draw("Phist"); if ( MC->GetEntries() > 0. ) { MC->Scale(Data->Integral()/MC->Integral()); MC->Draw("lsamehist"); // DataClean->Draw("Psame"); } }else{ Data->Draw("EPhist"); MC->Draw("EPLsamehist"); } file->cd(); legend->Draw("same"); aCanvas->SaveAs( std::string(canvas_name+".pdf").c_str() ); aCanvas->Write(); return aCanvas; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWindow) { ui->setupUi(this); createCanvas(); createActions(); createMenu(); }
Picasso::Picasso (unsigned int width, unsigned int height) { canvas_width = width; canvas_height = height; createCanvas(canvas_width, canvas_height); };
QMenuBar* MainWindow::createMenuBar() { QMenuBar* bar = new QMenuBar(this); QMenu* sessionMenu = bar->addMenu(tr("&File")); sessionMenu->addAction(QIcon(":/icons/16x16/canvas-add.png"), tr("&Create"), this, SLOT(createCanvas())); sessionMenu->addAction(QIcon(":/icons/16x16/canvas-add.png"), tr("N&etwork"), d->netWin, SLOT(show())); sessionMenu->addAction(QIcon(":/icons/16x16/save-as.png"), tr("&Save Image"), this, SLOT(renderCanvas()), tr("Ctrl+S")); sessionMenu->addSeparator(); sessionMenu->addAction(QIcon(":/icons/16x16/exit.png"), tr("&Quit"), this, SLOT(close()), tr("Ctrl+Q")); QMenu* editMenu = bar->addMenu(tr("&Edit")); editMenu->addAction(QIcon(":/icons/16x16/canvas-clear.png"), tr("&Clear"), d->containment, SLOT(clearCanvas())); editMenu->addSeparator(); editMenu->addAction(QIcon(":/icons/16x16/configure.png"), tr("&Gestures"),d->ge, SLOT(show())); editMenu->addAction(QIcon(":/icons/16x16/configure.png"), tr("&Options"))->setEnabled(false); QMenu* helpMenu = bar->addMenu(tr("&Help")); helpMenu->addAction(QIcon(":/icons/16x16/help-contents.png"), tr("&Help"))->setEnabled(false); helpMenu->addSeparator(); helpMenu->addAction(QIcon(":/icons/16x16/application.png"), tr("&About"), this, SLOT(about())); helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); return bar; }
gxFont *gxGraphics::loadFont( const string &f,int height,int flags ){ int bold=flags & gxFont::FONT_BOLD ? FW_BOLD : FW_REGULAR; int italic=flags & gxFont::FONT_ITALIC ? 1 : 0; int underline=flags & gxFont::FONT_UNDERLINE ? 1 : 0; int strikeout=0; string t; int n=f.find('.'); if( n!=string::npos ){ t=fullfilename(f); if( !font_res.count(t) && AddFontResource( t.c_str() ) ) font_res.insert( t ); t=filenamefile( f.substr(0,n) ); }else{ t=f; } //save and turn off font smoothing.... BOOL smoothing=FALSE; SystemParametersInfo( SPI_GETFONTSMOOTHING,0,&smoothing,0 ); SystemParametersInfo( SPI_SETFONTSMOOTHING,FALSE,0,0 ); HFONT hfont=CreateFont( height,0,0,0, bold,italic,underline,strikeout, ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,t.c_str() ); if( !hfont ){ //restore font smoothing SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 ); return 0; } HDC hdc=CreateCompatibleDC( 0 ); HFONT pfont=(HFONT)SelectObject( hdc,hfont ); TEXTMETRIC tm={0}; if( !GetTextMetrics( hdc,&tm ) ){ SelectObject( hdc,pfont ); DeleteDC( hdc ); DeleteObject( hfont ); SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 ); return 0; } height=tm.tmHeight; int first=tm.tmFirstChar,last=tm.tmLastChar; int sz=last-first+1; int *offs=d_new int[sz]; int *widths=d_new int[sz]; int *as=d_new int[sz]; //calc size of canvas to hold font. int x=0,y=0,max_x=0; for( int k=0;k<sz;++k ){ char t=k+first; SIZE sz; GetTextExtentPoint32( hdc,&t,1,&sz ); int w=sz.cx; as[k]=0; ABC abc; if( GetCharABCWidths( hdc,t,t,&abc ) ){ if( abc.abcA<0 ){ as[k]=ceil(-abc.abcA); w+=as[k]; } if( abc.abcC<0 ) w+=ceil(-abc.abcC); } if( x && x+w>getWidth() ){ x=0;y+=height; } offs[k]=(x<<16)|y; widths[k]=w; x+=w;if( x>max_x ) max_x=x; } SelectObject( hdc,pfont ); DeleteDC( hdc ); int cw=max_x,ch=y+height; if( gxCanvas *c=createCanvas( cw,ch,0 ) ){ ddSurf *surf=c->getSurface(); HDC surf_hdc; if( surf->GetDC( &surf_hdc )>=0 ){ HFONT pfont=(HFONT)SelectObject( surf_hdc,hfont ); SetBkColor( surf_hdc,0x000000 ); SetTextColor( surf_hdc,0xffffff ); for( int k=0;k<sz;++k ){ int x=(offs[k]>>16)&0xffff,y=offs[k]&0xffff; char t=k+first; RECT rect={x,y,x+widths[k],y+height}; ExtTextOut( surf_hdc,x+as[k],y,ETO_CLIPPED,&rect,&t,1,0 ); } SelectObject( surf_hdc,pfont ); surf->ReleaseDC( surf_hdc ); DeleteObject( hfont ); delete[] as; c->backup(); gxFont *font=d_new gxFont( this,c,tm.tmMaxCharWidth,height,first,last+1,tm.tmDefaultChar,offs,widths ); font_set.insert( font ); //restore font smoothing SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 ); return font; }else{