void piechart() { Float_t vals[] = {.2,1.1,.6,.9,2.3}; Int_t colors[] = {2,3,4,5,6}; Int_t nvals = sizeof(vals)/sizeof(vals[0]); TCanvas *cpie = new TCanvas("cpie","TPie test",700,700); cpie->Divide(2,2); TPie *pie1 = new TPie("pie1", "Pie with offset and no colors",nvals,vals); TPie *pie2 = new TPie("pie2", "Pie with radial labels",nvals,vals,colors); TPie *pie3 = new TPie("pie3", "Pie with tangential labels",nvals,vals,colors); TPie *pie4 = new TPie("pie4", "Pie with verbose labels",nvals,vals,colors); cpie->cd(1); pie1->SetAngularOffset(30.); pie1->SetEntryRadiusOffset( 4, 0.1); pie1->SetRadius(.35); pie1->Draw("3d"); cpie->cd(2); pie2->SetEntryRadiusOffset(2,.05); pie2->SetEntryLineColor(2,2); pie2->SetEntryLineWidth(2,5); pie2->SetEntryLineStyle(2,2); pie2->SetEntryFillStyle(1,3030); pie2->SetCircle(.5,.45,.3); pie2->Draw("rsc"); cpie->cd(3); pie3->SetY(.32); pie3->GetSlice(0)->SetValue(.8); pie3->GetSlice(1)->SetFillStyle(3031); pie3->SetLabelsOffset(-.1); pie3->Draw("3d t nol"); TLegend *pieleg = pie3->MakeLegend(); pieleg->SetY1(.56); pieleg->SetY2(.86); cpie->cd(4); pie4->SetRadius(.2); pie4->SetLabelsOffset(.01); pie4->SetLabelFormat("#splitline{%val (%perc)}{%txt}"); pie4->Draw("nol <"); }
void plot_efficiencies( TFile* file, Int_t type = 2, TDirectory* BinDir) { // input: - Input file (result from TMVA), // - type = 1 --> plot efficiency(B) versus eff(S) // = 2 --> plot rejection (B) versus efficiency (S) Bool_t __PLOT_LOGO__ = kTRUE; Bool_t __SAVE_IMAGE__ = kTRUE; // the coordinates Float_t x1 = 0; Float_t x2 = 1; Float_t y1 = 0; Float_t y2 = 0.8; // reverse order if "rejection" if (type == 2) { Float_t z = y1; y1 = 1 - y2; y2 = 1 - z; // cout << "--- type==2: plot background rejection versus signal efficiency" << endl; } else { // cout << "--- type==1: plot background efficiency versus signal efficiency" << endl; } // create canvas TCanvas* c = new TCanvas( "c", "the canvas", 200, 0, 650, 500 ); // global style settings c->SetGrid(); c->SetTicks(); // legend Float_t x0L = 0.107, y0H = 0.899; Float_t dxL = 0.457-x0L, dyH = 0.22; if (type == 2) { x0L = 0.15; y0H = 1 - y0H + dyH + 0.07; } TLegend *legend = new TLegend( x0L, y0H-dyH, x0L+dxL, y0H ); legend->SetTextSize( 0.05 ); legend->SetHeader( "MVA Method:" ); legend->SetMargin( 0.4 ); TString xtit = "Signal efficiency"; TString ytit = "Background efficiency"; if (type == 2) ytit = "Background rejection"; TString ftit = ytit + " versus " + xtit; if (TString(BinDir->GetName()).Contains("multicut")){ ftit += " Bin: "; ftit += (BinDir->GetTitle()); } // draw empty frame if(gROOT->FindObject("frame")!=0) gROOT->FindObject("frame")->Delete(); TH2F* frame = new TH2F( "frame", ftit, 500, x1, x2, 500, y1, y2 ); frame->GetXaxis()->SetTitle( xtit ); frame->GetYaxis()->SetTitle( ytit ); TMVAGlob::SetFrameStyle( frame, 1.0 ); frame->Draw(); Int_t color = 1; Int_t nmva = 0; TKey *key, *hkey; TString hNameRef = "effBvsS"; if (type == 2) hNameRef = "rejBvsS"; TList hists; TList methods; UInt_t nm = TMVAGlob::GetListOfMethods( methods ); // TIter next(file->GetListOfKeys()); TIter next(&methods); // loop over all methods while (key = (TKey*)next()) { TDirectory * mDir = (TDirectory*)key->ReadObj(); TList titles; UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles); TIter nextTitle(&titles); TKey *titkey; TDirectory *titDir; while ((titkey = TMVAGlob::NextKey(nextTitle,"TDirectory"))) { titDir = (TDirectory *)titkey->ReadObj(); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,titDir); TIter nextKey( titDir->GetListOfKeys() ); while ((hkey = TMVAGlob::NextKey(nextKey,"TH1"))) { TH1 *h = (TH1*)hkey->ReadObj(); TString hname = h->GetName(); if (hname.Contains( hNameRef ) && hname.BeginsWith( "MVA_" )) { h->SetLineWidth(3); h->SetLineColor(color); color++; if (color == 5 || color == 10 || color == 11) color++; h->Draw("csame"); hists.Add(h); nmva++; } } } } while (hists.GetSize()) { TListIter hIt(&hists); TH1* hist(0); Double_t largestInt=-1; TH1* histWithLargestInt(0); while ((hist = (TH1*)hIt())!=0) { Double_t integral = hist->Integral(1,hist->FindBin(0.9999)); if (integral>largestInt) { largestInt = integral; histWithLargestInt = hist; } } if (histWithLargestInt == 0) { cout << "ERROR - unknown hist \"histWithLargestInt\" --> serious problem in ROOT file" << endl; break; } legend->AddEntry(histWithLargestInt,TString(histWithLargestInt->GetTitle()).ReplaceAll("MVA_",""),"l"); hists.Remove(histWithLargestInt); } // rescale legend box size // current box size has been tuned for 3 MVAs + 1 title if (type == 1) { dyH *= (1.0 + Float_t(nmva - 3.0)/4.0); legend->SetY1( y0H - dyH ); } else { dyH *= (Float_t(nmva - 3.0)/4.0); legend->SetY2( y0H + dyH); } // redraw axes frame->Draw("sameaxis"); legend->Draw("same"); // ============================================================ if (__PLOT_LOGO__) TMVAGlob::plot_logo(); // ============================================================ c->Update(); TString fname = "plots/" + hNameRef; if (TString(BinDir->GetName()).Contains("multicut")){ TString fprepend(BinDir->GetName()); fprepend.ReplaceAll("multicutMVA_",""); fname = "plots/" + fprepend + "_" + hNameRef; } if (__SAVE_IMAGE__) TMVAGlob::imgconv( c, fname ); return; }
void NLSimpleGuiWindow::drawClarkAnalysis( const ConsentrationGraph &xGraph, const ConsentrationGraph &yGraph, bool isCgmsVMeter ) { ui->tabWidget->setCurrentWidget(ui->clarkeGridTab); cleanupClarkAnalysis(); TimeDuration cmgsDelay(0,0,0,0); if( isCgmsVMeter ) { TCanvas *can = ui->clarkResultsWidget->GetCanvas(); can->cd(); can->SetEditable( kTRUE ); TPaveText *delayErrorEqnPt = new TPaveText(0, 0, 1.0, 1.0, "NDC"); delayErrorEqnPt->SetBorderSize(0); delayErrorEqnPt->SetTextAlign(12); cmgsDelay = m_model->findCgmsDelayFromFingerStick(); double sigma = 1000.0 * m_model->findCgmsErrorFromFingerStick(cmgsDelay); sigma = static_cast<int>(sigma + 0.5) / 10.0; //nearest tenth of a percent string delayStr = "Delay="; delayStr += boost::posix_time::to_simple_string(cmgsDelay).substr(3,5); delayStr += " "; ostringstream uncertDescript; uncertDescript << "#sigma_{cgms}^{finger}=" << sigma << "%"; delayErrorEqnPt->AddText( uncertDescript.str().c_str() ); delayErrorEqnPt->AddText( delayStr.c_str() ); delayErrorEqnPt->Draw(); can->SetEditable( kFALSE ); can->Update(); }//if( isCgmsVMeter ) TCanvas *can = ui->clarkeErrorGridWidget->GetCanvas(); can->cd(); can->SetEditable( kTRUE ); vector<TObject *> clarkesObj; clarkesObj = getClarkeErrorGridObjs( yGraph, xGraph, cmgsDelay, true ); assert( dynamic_cast<TH1 *>(clarkesObj[0]) ); dynamic_cast<TH1 *>(clarkesObj[0])->GetYaxis()->SetTitleOffset(1.3); clarkesObj[0]->Draw("SCAT"); clarkesObj[1]->Draw("SCAT SAME"); clarkesObj[2]->Draw("SCAT SAME"); clarkesObj[3]->Draw("SCAT SAME"); clarkesObj[4]->Draw("SCAT SAME"); TLegend *leg = dynamic_cast<TLegend *>( clarkesObj[5] ); assert( leg ); //Now draw all the boundry lines for( size_t i=6; i < clarkesObj.size(); ++i ) clarkesObj[i]->Draw(); can->SetEditable( kFALSE ); can->Update(); // can->ResizePad(); // ui->clarkeErrorGridWidget->Refresh(); can = ui->clarkeLegendWidget->GetCanvas(); can->cd(); leg->SetX1(-0.1); leg->SetX2(1.1); leg->SetY1(0.0); leg->SetY2(1.0); leg->Draw(); can->SetEditable( kFALSE ); can->Update(); }// void NLSimpleGuiWindow::drawPredictedClarkAnalysis()
//-------------------------------------------------------------------------------------------------- void plot(long int xStart, long int xEnd, TString text, TString pngFileName) { // Make sure we have the right styles MitRootStyle::Init(); MitRootStyle::SetStyleWide(); gStyle->SetPadRightMargin(0.07); // to make sure the exponent is on the picture // will execute a shell command to get the data TString timeSeriesFile("timeSeriesOfRates.txt"); // Now open our database output ifstream input; input.open(timeSeriesFile.Data()); Int_t time=0, nConn=0, nLines=0; Double_t rate=0, xMin=double(xStart), xMax=double(xEnd), maxRate=1.0; // First loop to determine the boundaries (could be done in one round, dynamically) //--------------------------------------------------------------------------------- while (1) { // read in input >> time >> rate >> nConn; // check it worked if (! input.good()) break; //printf(" Min / Time / Max: %d %d %d\n",xStart,time,xEnd); // check whether in our requested time window if (xStart>0 && xStart>time) continue; if (xEnd>0 && xEnd<time) continue; // Show what we are reading if (nLines < 5) printf(" time=%d, rate=%8f nConnections=%d\n",time, rate, nConn); // Determine plot maximum if (rate > maxRate) maxRate = rate; if (nConn > maxRate) maxRate = double(nConn); nLines++; } input.close(); printf(" \n"); printf(" Found %d measurements.\n",nLines); printf(" Maximum tranfer rate at: %6.2f MB/sec\n",maxRate); printf(" \n"); // Open a canvas TCanvas *cv = new TCanvas(); cv->Draw(); if (nLines<1) { printf(" WARNING - no measurements selected.\n"); plotFrame(double(xStart),double(xEnd)); double dX = double(xEnd)-double(xStart); TText *plotText = new TText(xMin-dX*0.14,0.-(maxRate*1.2*0.14),text.Data()); printf("Text size: %f\n",plotText->GetTextSize()); plotText->SetTextSize(0.04); plotText->SetTextColor(kBlue); plotText->Draw(); cv->SaveAs(pngFileName.Data()); return; } const int numVals = nLines; double xVals[numVals]; double y1Vals[numVals]; double y2Vals[numVals]; input.open(timeSeriesFile.Data()); // Second loop to register the measured values //-------------------------------------------- Int_t i = 0; while (1) { // read in input >> time >> rate >> nConn; // check it worked if (!input.good()) break; // check whether in our requested time window if (xStart>0 && xStart>time) continue; if (xEnd>0 && xEnd<time) continue; xVals[i] = time; y1Vals[i] = rate; y2Vals[i] = nConn; i++; } input.close(); // Make a good frame plotFrame(xMin,xMax,maxRate); double dX = double(xEnd)-double(xStart); TText *plotText = new TText(xMin-dX*0.14,0.-(maxRate*1.2*0.14),text.Data()); plotText->SetTextSize(0.04); plotText->SetTextColor(kBlue); plotText->Draw(); // Prepare our graphs TGraph* graph1 = new TGraph(numVals, xVals, y1Vals); graph1->SetLineColor(2); graph1->SetLineWidth(2); graph1->SetMarkerColor(4); graph1->SetMarkerStyle(21); graph1->SetMarkerSize(0.4); TGraph* graph2 = new TGraph(numVals, xVals, y2Vals); graph2->SetLineColor(3); graph2->SetLineWidth(2); graph2->SetMarkerColor(4); graph2->SetMarkerStyle(20); graph2->SetMarkerSize(0.4); // Through them into the multigraph TMultiGraph *mg = new TMultiGraph(); mg->Add(graph1,"lp"); mg->Add(graph2,"lp"); // Draw the graphs mg->Draw("CP"); // Add a nice legend to the picture TLegend *leg = new TLegend(0.4,0.6,0.89,0.89); //leg->SetTextSize(0.036); leg->SetX1(0.15); leg->SetX2(0.30); leg->SetY1(0.95); leg->SetY2(0.85); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->AddEntry(graph2,"number of tranfers","lp"); leg->AddEntry(graph1,"data tranfer rate","lp"); leg->Draw(); cv->SaveAs(pngFileName); }
void macro_MakeFRClosureTest() { // parameters ////////////////////////////////////////////////////////////// // luminosity of data const float lumi = 10445; string inputFilePrefix = "invMassHistos"; // lumi and .root will be added //string inputFilePrefix = "test"; // plot data? const bool plotData = true; //const bool plotData = false; // which closure tests should be plotted? bool plotClosureTest[4]; plotClosureTest[0] = true; // no corrections plotClosureTest[1] = true; // GSF electrons not passing HEEP plotClosureTest[2] = true; // all above + HEEP-GSF corrected with DY contribuion plotClosureTest[3] = true; // all above + GSF-GSF corrected with W+jet and gamma+jet contribution // which histograms should be plotted? bool plotHisto[4]; plotHisto[0] = true; // EB-EB + EB-EE plotHisto[1] = true; // EB-EB plotHisto[2] = true; // EB-EE plotHisto[3] = true; // EE-EE int font = 42; //////////////////////////////////////////////////////////////////////////// const double yAxisMin = 0.001; // const int rebin = 10; float massMin = 50; float massMax = 2050; int nBins = 2000; vector<pair<float, float> > binning; // VARIABLE BINNING // binning.push_back(make_pair(100, 1)); // binning.push_back(make_pair(500, 10)); // binning.push_back(make_pair(massMax, 50)); // CONSTANT BINNING binning.push_back(make_pair(massMax, 10)); vector<float> bins; bins.push_back(massMin); for (vector<pair<float,float> >::iterator it = binning.begin(); it < binning.end(); ++it) { while (bins.back() < it->first) bins.push_back(bins.back() + it->second); } if (bins.back() < massMax) bins.push_back(massMax); nBins = bins.size() - 1; Double_t binArray[nBins + 1]; for (int i = 0; i <= nBins; ++i) binArray[i] = (Double_t)bins.at(i); stringstream sStream; sStream << "Photon_Run2012A-13Jul2012_06Aug2012+DoublePhotonHighPt_Run2012B-13Jul2012+DoublePhotonHighPt_Run2012C-PromptReco-v1+v2_Cert_190456-202016_8TeV_PromptReco_gct1_35_" << lumi << "pb-1"; //sStream << lumi << "pb-1"; TString folderDataHisto = sStream.str().c_str(); // select histograms dynamically depending on state of correction ////////// vector<TString> folderHeepGsfHisto; folderHeepGsfHisto.push_back(sStream.str().c_str()); folderHeepGsfHisto.push_back(sStream.str().c_str()); folderHeepGsfHisto.push_back("combinations"); folderHeepGsfHisto.push_back("combinations"); vector<TString> folderGsfGsfHisto; folderGsfGsfHisto.push_back(sStream.str().c_str()); folderGsfGsfHisto.push_back(sStream.str().c_str()); folderGsfGsfHisto.push_back(sStream.str().c_str()); folderGsfGsfHisto.push_back("combinations"); vector<TString> heepGsfHisto; heepGsfHisto.push_back("histoHeepGsfMassFR"); heepGsfHisto.push_back("histoHeepGsfMassNoHeepFR"); heepGsfHisto.push_back("histoHeepGsfCorr"); heepGsfHisto.push_back("histoHeepGsfCorr"); vector<TString> gsfGsfHisto; gsfGsfHisto.push_back("histoGsfGsfMassFR"); gsfGsfHisto.push_back("histoGsfGsfMassNoHeepFR"); gsfGsfHisto.push_back("histoGsfGsfMassNoHeepFR"); gsfGsfHisto.push_back("histoGsfGsfCorr"); //////////////////////////////////////////////////////////////////////////// vector<TString> canvasName; canvasName.push_back("closureFR"); canvasName.push_back("closureFRNoHeep"); canvasName.push_back("closureFRCorrDY"); canvasName.push_back("closureFRCorrFull"); vector<TString> canvasTitle; canvasTitle.push_back("Fake rate closure test uncorrected"); canvasTitle.push_back("Fake rate closure test GSF (non HEEP)"); canvasTitle.push_back("Fake rate closure test DY corrected"); canvasTitle.push_back("Fake rate closure test fully corrected"); vector<TString> legendHeepGsf; legendHeepGsf.push_back("HEEP-GSF uncorrected"); legendHeepGsf.push_back("HEEP-GSF(non HEEP)"); legendHeepGsf.push_back("HEEP-GSF DY corrected"); legendHeepGsf.push_back("HEEP-GSF DY corrected"); vector<TString> legendGsfGsf; legendGsfGsf.push_back("GSF-GSF uncorrected"); legendGsfGsf.push_back("GSF-GSF (non HEEP)"); legendGsfGsf.push_back("GSF-GSF (non HEEP)"); legendGsfGsf.push_back("GSF-GSF W+jet + \\gamma+jet corrected"); vector<TString> acroSuffix; acroSuffix.push_back(""); acroSuffix.push_back("BB"); acroSuffix.push_back("BE"); acroSuffix.push_back("EE"); vector<TString> suffix; suffix.push_back(""); suffix.push_back(" EB-EB"); suffix.push_back(" EB-EE"); suffix.push_back(" EE-EE"); sStream.str(""); sStream << inputFilePrefix << lumi << "pb-1.root"; TFile input(sStream.str().c_str(), "read"); input.cd(); cout << endl << "Input file: " << sStream.str() << endl; // to keep the histogram when the file is closed TH1::AddDirectory(kFALSE); TH1::SetDefaultSumw2(kTRUE); for (unsigned int j = 0; j < 4; ++j) { if (!plotClosureTest[j]) continue; for (unsigned int p = 0; p < 4; ++p) { if (!plotHisto[p]) continue; TCanvas *c0 = new TCanvas(canvasName[j] + acroSuffix[p], canvasTitle[j] + suffix[p], 100, 100, 800, 600); c0->cd(); c0->SetBorderMode(0); c0->SetFrameBorderMode(0); c0->SetFillColor(0); c0->SetFrameFillColor(0); c0->SetLogy(); gStyle->SetTitleFont(font); gStyle->SetLabelFont(font); gStyle->SetOptStat(0); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); // get the histograms input.cd(folderGsfGsfHisto[j]); TH1F *histoGsfGsf = (TH1F *)gDirectory->Get(gsfGsfHisto[j] + acroSuffix[p]); input.cd(folderHeepGsfHisto[j]); TH1F *histoHeepGsf = (TH1F *)gDirectory->Get(heepGsfHisto[j] + acroSuffix[p]); input.cd(folderDataHisto); TH1F *histoData = (TH1F *)gDirectory->Get("histoHeepHeepMass" + acroSuffix[p]); TH1F *histoGsfGsfRebinned = (TH1F *)histoGsfGsf->Rebin(nBins, gsfGsfHisto[j] + "Rebinned" + acroSuffix[p], binArray); TH1F *histoHeepGsfRebinned = (TH1F *)histoHeepGsf->Rebin(nBins, heepGsfHisto[j] + "Rebinned" + acroSuffix[p], binArray); TH1F *histoDataRebinned = (TH1F *)histoData->Rebin(nBins, "histoHeepHeepMassRebinned" + acroSuffix[p], binArray); histoGsfGsfRebinned->SetLineColor(4); histoGsfGsfRebinned->SetMarkerColor(4); histoGsfGsfRebinned->SetMarkerStyle(20); histoGsfGsfRebinned->SetTitleFont(font); histoHeepGsfRebinned->SetLineColor(2); histoHeepGsfRebinned->SetMarkerColor(2); histoHeepGsfRebinned->SetMarkerStyle(21); histoHeepGsfRebinned->SetTitleFont(font); histoHeepGsfRebinned->GetYaxis()->SetTitleFont(font); histoHeepGsfRebinned->GetYaxis()->SetLabelFont(font); histoHeepGsfRebinned->GetXaxis()->SetLabelFont(font); histoDataRebinned->SetLineColor(1); histoDataRebinned->SetMarkerColor(1); histoDataRebinned->SetMarkerStyle(20); histoDataRebinned->SetTitleFont(font); histoDataRebinned->GetYaxis()->SetTitleFont(font); histoDataRebinned->GetYaxis()->SetLabelFont(font); histoDataRebinned->GetXaxis()->SetLabelFont(font); sStream.str(""); if (binning.size() > 1) sStream << "# of events / bin"; else sStream << "# of events / " << binning.begin()->second << "GeV"; if (plotData) { histoDataRebinned->SetMinimum(yAxisMin); histoDataRebinned->SetTitle(canvasTitle[j] + suffix[p]); histoDataRebinned->GetYaxis()->SetTitle(sStream.str().c_str()); histoDataRebinned->Draw(); histoHeepGsfRebinned->Draw("sames"); } else { histoHeepGsfRebinned->SetTitle(canvasTitle[j] + suffix[p]); histoHeepGsfRebinned->GetYaxis()->SetTitle(sStream.str().c_str()); histoHeepGsfRebinned->Draw(); } histoGsfGsfRebinned->Draw("sames"); sStream.str(""); sStream << "#sqrt{s} = 8TeV, #int L dt = " << lumi << "pb^{-1}"; TPaveLabel *label0 = new TPaveLabel(0.6, 0.79, 0.9, 0.89, sStream.str().c_str(), "brNDC"); label0->SetFillColor(0); label0->SetFillStyle(0); label0->SetBorderSize(0); label0->SetTextSize(0.30); label0->SetTextFont(font); label0->Draw("sames"); TPaveLabel *label1 = new TPaveLabel(0.7, 0.89, 0.91, 0.98, "CMS preliminary", "brNDC"); label1->SetFillColor(0); label1->SetFillStyle(0); label1->SetBorderSize(0); label1->SetTextSize(0.40); label1->SetTextFont(font); label1->Draw("sames"); TLegend *legend = new TLegend(0.38, 0.6, 0.53, 0.9); if (!plotData) legend->SetY2(0.8); legend->SetTextSize(0.03); legend->SetTextFont(font); legend->SetBorderSize(0); legend->SetFillStyle(0); if (plotData) legend->AddEntry(histoDataRebinned, "Data", "lep"); legend->AddEntry(histoHeepGsfRebinned, legendHeepGsf[j], "lep"); legend->AddEntry(histoGsfGsfRebinned, legendGsfGsf[j], "lep"); legend->Draw("sames"); } // end loop over eta ranges } // end loop over corrections input.Close(); }
//-------------------------------------------------------------------------------------------------- void plot(long int xStart, long int xEnd, TString text, TString pngFileName) { // Make sure we have the right styles MitStyle::Init(); MitStyle::SetStyleWide(); gStyle->SetPadRightMargin(0.07); // to make sure the exponent is on the picture // will execute a shell command to get the data TString timeSeriesFile("timeSeriesOfFailures.txt"); // Now open our database output ifstream input; input.open(timeSeriesFile.Data()); Int_t time=0, nFail=0, nLines=0; Double_t xMin=double(xStart), xMax=double(xEnd), max=1.0; // First loop to determine the boundaries (could be done in one round, dynamically) //--------------------------------------------------------------------------------- while (1) { // read in input >> time >> nFail; // check it worked if (! input.good()) break; //printf(" Min / Time / Max: %d %d %d\n",xStart,time,xEnd); // check whether in our requested time window if (xStart>0 && xStart>time) continue; if (xEnd>0 && xEnd<time) continue; // Show what we are reading if (nLines < 5) printf(" time=%d, nFails=%d\n",time, nFail); // Determine plot maximum if (nFail > max) max = nFail; nLines++; } input.close(); printf(" \n"); printf(" Found %d measurements.\n",nLines); printf(" Maximum failures at: %6.2f in 90 sec\n",max); printf(" \n"); // Open a canvas TCanvas *cv = new TCanvas(); cv->SetLogy(kTRUE); cv->Draw(); if (nLines<1) { printf(" WARNING - no measurements selected.\n"); plotFrame(double(xStart),double(xEnd)); overlayFrame(text); cv->SaveAs(pngFileName.Data()); return; } const int numVals = nLines; double xVals[numVals]; double yVals[numVals]; input.open(timeSeriesFile.Data()); // Second loop to register the measured values //-------------------------------------------- Int_t i = 0; while (1) { // read in input >> time >> nFail; // check it worked if (!input.good()) break; // check whether in our requested time window if (xStart>0 && xStart>time) continue; if (xEnd>0 && xEnd<time) continue; xVals[i] = time; yVals[i] = nFail; i++; } input.close(); // Make a good frame plotFrame(xMin,xMax,max); // Prepare our graphs TGraph* graph1 = new TGraph(numVals, xVals, yVals); graph1->SetLineColor(2); graph1->SetLineWidth(2); graph1->SetMarkerColor(4); graph1->SetMarkerStyle(21); graph1->SetMarkerSize(0.4); // Through them into the multigraph TMultiGraph *mg = new TMultiGraph(); mg->Add(graph1,"lp"); // Draw the graphs mg->Draw("CP"); // Add a nice legend to the picture TLegend *leg = new TLegend(0.4,0.6,0.89,0.89); leg->SetX1(0.15); leg->SetX2(0.30); leg->SetY1(0.95); leg->SetY2(0.85); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->AddEntry(graph1,"number of failures","lp"); leg->Draw(); overlayFrame(text); cv->SaveAs(pngFileName); }