void draw() { gStyle->SetOptStat(0000); TGraphErrors* gr = new TGraphErrors("papel_um.txt", "%lg %lg %lg %lg"); gr->Draw("A"); gr->GetXaxis()->SetTitle("Diametro (mm)"); gr->GetYaxis()->SetTitle("Massa (u.m.)"); gr->SetTitle("Dimensao Fractal - Papel"); gr->SetMarkerStyle(20); gr->SetMarkerSize(gr->GetMarkerSize()/2.); TCanvas* c1 = new TCanvas(); gr->Draw("AP"); c1->Print("gr1.png"); TGraphErrors* grlog = new TGraphErrors(); for (int i=0; i<gr->GetN(); i++) { grlog->SetPoint(i, TMath::Log(gr->GetX()[i]), TMath::Log(gr->GetY()[i])); grlog->SetPointError(i, gr->GetEX()[i]/gr->GetX()[i], 0.0); } grlog->Draw("A"); grlog->GetXaxis()->SetTitle("Logaritmo do diametro (diametro em mm)"); grlog->GetYaxis()->SetTitle("Logaritmo da massa (massa em unidade arbitraria)"); grlog->SetTitle("Dimensao Fractal - Papel"); grlog->SetMarkerStyle(20); // grlog->SetMarkerSize(gr->GetMarkerSize()/2.); grlog->Fit("pol1"); TCanvas* c2 = new TCanvas(); grlog->Draw("AP"); c2->Print("gr2.png"); }
void DrawClus(bool Flag_err,TTree* tree,Double_t *errx,char* varToPlot, char* cond, Int_t kColor, Int_t kMarker, char* Title,char* xTitle,char* yTitle, TLegend *leg, char* cLeg,Double_t downlim,Double_t uplim){ TGraphErrors* g; tree->Draw(varToPlot, cond,"goff"); cout << tree->GetSelectedRows() << endl; if(tree->GetSelectedRows()){ if(Flag_err) g=new TGraphErrors(tree->GetSelectedRows(),tree->GetV1(),tree->GetV2(),errx,tree->GetV3()); else g=new TGraphErrors(tree->GetSelectedRows(),tree->GetV1(),tree->GetV2(),errx,errx); g->SetMarkerStyle(kMarker); g->SetMarkerSize(0.9); g->SetMarkerColor(kColor); g->SetTitle(Title); g->GetXaxis()->SetTitle(xTitle); g->GetXaxis()->CenterTitle(); g->GetYaxis()->SetTitle(yTitle); g->GetYaxis()->CenterTitle(); g->GetYaxis()->SetRangeUser(downlim,uplim); g->Draw("Ap"); leg->AddEntry(g, cLeg,"p"); }else{ cout << "NO rows selected for leave " << varToPlot << endl; } }
void gerrors() { //Draw a graph with error bars // To see the output of this macro, click begin_html <a href="gif/gerrors.gif">here</a>. end_html //Author: Rene Brun TCanvas *c1 = new TCanvas("c1","A Simple Graph with error bars",200,10,700,500); c1->SetFillColor(42); c1->SetGrid(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderSize(12); const Int_t n = 10; Float_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95}; Float_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1}; Float_t ex[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05}; Float_t ey[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8}; TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey); gr->SetTitle("TGraphErrors Example"); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); gr->Draw("ALP"); c1->Update(); }
//========================================== //========================================== void createTgr(TString fname) { outH=new TFile(fname,"RECREATE"); assert(outH->IsOpen()); printf("save outH -->%s\n", fname.Data()); char *ampTit[mxAmp]={"An", "AnYell", "A#Sigma", "A#Delta"}; int ampCol[mxAmp]={kBlue, kYellow, kGreen, kMagenta}; int ic,iam; for (ic=0;ic<totC;ic++) { for (iam=0;iam<mxAmp;iam++) { char name[100]; sprintf(name,"%s*%s",ampL[iam],tCutL[ic]); //printf("ic=%d iam=%d name=%s=\n",ic,iam,name); TGraphErrors *gr =new TGraphErrors; gr->SetName(name); gr->SetTitle(ampTit[iam]); gr->SetMarkerColor(ampCol[iam]); gr->SetMarkerSize(0.8); gr->SetMarkerStyle(21); assert(nGr<mxGr); grL[nGr++]=gr; } } }
//______________________________________________________________________________ TGraphErrors *GraphRatio(TGraphErrors *g1,TGraphErrors *g2) { Int_t n = g1->GetN(); if (n != g2->GetN()) { Printf("!!!!!!!!!!!!!!!!"); return 0; } TGraphErrors *g = new TGraphErrors(n); g->SetMarkerStyle(20); g->GetXaxis()->SetTitle("p_{t}, GeV/c"); g->SetTitle(Form("#frac{%s}{%s}", g1->GetTitle(), g2->GetTitle())); Double_t x, y1, y2; Double_t c0, c1, c12, e0, e1; Double_t *ex = g1->GetEX(); Double_t *ey = g1->GetEY(); for (Int_t i = 0; i < n; i++) { g1->GetPoint(i, x, y1); g2->GetPoint(i, x, y2); if (TMath::Abs(y2) < 1.E-12) y2 = 1.0; c0 = y1; c1 = y2; c12 = c1*c1; e0 = g1->GetErrorY(i); e1 = g2->GetErrorY(i); g->SetPoint(i, x, y1/y2); g->SetPointError(i, ex[i], (e0*e0*c1*c1 + e1*e1*c0*c0)/(c12*c12)); } return g; }
void TMRCScanner::PlotMultiplicity(int opt){ ffile = new TFile(foutfile); if (ffile->IsOpen()) { ftree = (TTree*) ffile->Get("T"); ftree->SetMarkerStyle(23); switch (opt) { case 0: ftree->Draw("HitMultMean:HitMultMeanErr:DAC","","goff"); break; case 1: ftree->Draw("HitMultRMS:HitMultRMSErr:DAC","","goff"); break; default: break; } TGraphErrors *gr = new TGraphErrors(ftree->GetSelectedRows(),ftree->GetV3(), ftree->GetV1(),NULL,ftree->GetV2()); gr->SetTitle("TGraphErrors Example"); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); gr->Draw("ALP"); }else { printf("File %s not opened \n",foutfile); } delete ffile; }
void plotV2vstheta(){ gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetErrorX(0); int xbin = 0; TFile *f = new TFile("mergedV_Prod.root"); TVectorD *vecV = (TVectorD*)f->Get(Form("D_%d/V")); TVectorD *vecdeltaV = (TVectorD*)f->Get(Form("D_%d/deltaV")); TVectorD *vecVmean = (TVectorD*)f->Get(Form("Vmean")); double *V = vecV->GetMatrixArray(); double *deltaV = vecdeltaV->GetMatrixArray(); double *Vmean = vecVmean->GetMatrixArray(); double theta[ntheta]; for(int itheta=0;itheta<ntheta;itheta++){ theta[itheta]=itheta*TMath::Pi()/ntheta/nn; } TH1D *hFrame = new TH1D("","",300,-1,2); hFrame->GetXaxis()->SetTitle("#theta"); hFrame->GetYaxis()->SetTitle("referenceV_{2}"); hFrame->GetXaxis()->SetTitleSize(0.04); hFrame->GetYaxis()->SetTitleSize(0.04); hFrame->GetXaxis()->SetRangeUser(-0.1,1.5); hFrame->SetMaximum(0.055); hFrame->SetMinimum(0.045); hFrame->Draw(); TGraphErrors *gr = new TGraphErrors(ntheta,theta,V,0,deltaV); gr->SetMarkerSize(1.2); gr->SetMarkerStyle(20); gr->Draw("Psame"); TLine *l = new TLine(0,inV2,1.4,inV2); l->SetLineStyle(2); l->Draw("same"); c1->Print("V2vstheta.png"); }
void ExpManager::GetSim1DGraphZ(TString NameTitle, double xmin, double xmax, double ymin, double ymax, TString grid ){ // do the same thing as for the polar interpolation TGraphErrors *fGraph = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); fGraph->SetTitle("Simulated Data;Z (mm);Magnetic Field (mT)"); fGraph->SetMarkerSize(1.2); fGraph->SetMarkerStyle(20); fGraph->SetMarkerColor(kBlue); fGraph->SetLineColor(kBlue); fGraph->SetLineWidth(2); int graph_counter = 0 ; for (unsigned i=0; i< fExpY.size(); i++) { //cout << " X " << fExpX.at(i) ; if( (fExpX.at(i) >= xmin && fExpX.at(i) <= xmax) && (fExpY.at(i) >= ymin && fExpY.at(i) <= ymax) && fGrid.at(i)==grid ){ fGraph->SetPoint(graph_counter,fExpZ.at(i),fSimB.at(i)); fGraph->SetPointError(graph_counter,fExpZErr.at(i),0); graph_counter++; } } fGraph->SetTitle(NameTitle+Form(" Simulated Data : %.2f < X < %.2f mm __ %.2f < Y < %.2f mm;Z (mm);Magnetic Field (mT)",xmin,xmax,ymin,ymax)); fGraph->SetName(NameTitle+Form("_Sim_X_%.2f_%.2fmm_Y_%.2f_%.2fmm",xmin,xmax,ymin,ymax)); fGraph->Write(); }
void DrawSame(char* varToPlot, char* cond, Int_t kColor,TLegend* leg,char* cLeg) { TGraphErrors *g; TIFTree->Draw(varToPlot,cond,"goff"); Int_t nSel=TIFTree->GetSelectedRows(); if ( nSel ) { Double_t *ErrX= new Double_t[nSel]; for ( Int_t i=0; i<nSel; i++) ErrX[i]=0; g = new TGraphErrors(TIFTree->GetSelectedRows(), TIFTree->GetV1(), TIFTree->GetV2(), ErrX, TIFTree->GetV3()); g->SetMarkerStyle(21); g->SetMarkerSize(0.5); g->SetMarkerColor(kColor); g->SetLineColor(kColor); g->Draw("SP"); //draw graph in current pad // g->GetYaxis()->SetRangeUser(40., 100.); leg->AddEntry(g,cLeg); leg->Draw(); delete[] ErrX; } else { cout << "NO rows selected " << endl; } }
//______________________________________________________________________________ // Construct a graph from vectors and y error vector TGraphErrors *LoadGraphFromVectorsWithError(vector<double> xVector, vector<double> yVector, vector<double> yErrorVector, string xTitle, string yTitle) { int n = xVector.size(); if ((xVector.size() == yVector.size()) && (yVector.size() == yErrorVector.size())) { //Create a graph TGraphErrors *gr = new TGraphErrors(n, &xVector[0], &yVector[0], 0, &yErrorVector[0]); gr->SetTitle(""); gr->SetMarkerStyle(20); gr->SetMarkerSize(1.2); gr->SetLineWidth(2); gr->GetXaxis()->SetTitle(xTitle.c_str()); gr->GetXaxis()->CenterTitle(); gr->GetYaxis()->SetTitle(yTitle.c_str()); gr->GetYaxis()->CenterTitle(); return gr; delete gr; } else { TGraphErrors *gr0 = new TGraphErrors(); return gr0; delete gr0; } }
void LSF() { float x[100], y[100], ex[100], ey[100]; char filename[80]; printf("Enter filename.\n"); scanf("%s",filename); FILE *f = fopen(filename,"r"); if (f == NULL) { sprintf(line,"File %s not found.\n",filename); printf(line); return; } // Read data int i = 0; while (fscanf(f,"%f %f %f",&(x[i]),&(y[i]),&(ey[i])) == 3 ) { i++; } printf("Read %d data points.\n",i); TGraphErrors *tge = new TGraphErrors(i,x,y,ex,ey); tge->SetMarkerStyle(20); tge->SetMarkerColor(kBlue); tge->SetLineColor(kBlue); c1 = new TCanvas("c1","c1",600,600); tge->Draw("AP"); tge->Fit("pol1"); }
void ExpManager::GetExp1DGraphX(TString NameTitle, double zmin, double zmax, double ymin, double ymax, TString grid){ // do the same thing as for the polar interpolation TGraphErrors *fGraph = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); fGraph->SetTitle("Experimental Data;X (mm);Magnetic Field (mT)"); fGraph->SetMarkerSize(1.2); fGraph->SetMarkerStyle(20); fGraph->SetMarkerColor(kBlue); fGraph->SetLineColor(kBlue); fGraph->SetLineWidth(2); int graph_counter = 0 ; for (unsigned i=0; i< fExpY.size(); i++) { //cout << " X " << fExpX.at(i) ; if( (fExpY.at(i) >= ymin && fExpY.at(i) <= ymax) && (fExpZ.at(i) >= zmin && fExpZ.at(i) <= zmax) && fGrid.at(i)== grid ){ cout << " < ----- " ; fGraph->SetPoint(graph_counter,fExpX.at(i),fExpB.at(i)); // CHECK, add new the stuff for emag fGraph->SetPointError(graph_counter,fExpXErr.at(i),fExpBErr.at(i)); // CHECK, add new the stuff for emag graph_counter++; } cout << endl ; } fGraph->SetTitle(NameTitle+Form(" Experimental Data : %.2f < Depth < %.2f mm __ %.2f < Y < %.2f mm;X (mm);Magnetic Field (mT)",zmin,zmax,ymin,ymax)); fGraph->SetName(NameTitle+Form("_Exp_Depth_%.2f_%.2fmm_Y_%.2f_%.2fmm",zmin,zmax,ymin,ymax)); fGraph->Write(); }
void add_point( double coefover, double sigma, double dsigma ){//============================================================ TGraphErrors *fisig; if ( gROOT->GetListOfSpecials()->FindObject("fisig")!=NULL ){ fisig=(TGraphErrors*) gROOT->GetListOfSpecials()->FindObject("fisig"); printf("fisig exists\n%s",""); }else{ printf("\n\n NO fisig exists NONONO \n\n\n%s",""); fisig=new TGraphErrors(); fisig->SetTitle("fisig"); fisig->SetName("fisig"); gROOT->GetListOfSpecials()->Add( fisig );// TRICK TO KEEP IT gDirectory->Add( fisig ); fisig->SetMarkerStyle(7); } int n=fisig->GetN(); fisig->SetPoint(n,coefover,sigma); fisig->SetPointError(n,0.0,dsigma); // fisig->Print(); // too many data char text[100]; sprintf(text,"%.3f ... %d",coefover, fisig->GetN() ); // TText *t=new TText(from,0,text ); // t->SetTextSize(0.08);t->Draw(); }//============================================================
void Draw_ALICEFor_JPsi_RaaVsNpart(TLegend *lgd) { int nbinsALICE=9; Double_t NPartALICE[10]={357,262,187,128,86,53,30,16,8}; Double_t ErrNPartALICE[10]={0}; Double_t RaaALICE[10] = {0.47,0.48,0.51,0.51,0.52,0.61,0.70,0.74,0.94}; Double_t SystErrALICE[10] = {0.03,0.02,0.02,0.02,0.03,0.05,0.06,0.09,0.1}; TGraphErrors *grRaaALICE = new TGraphErrors(nbinsALICE, NPartALICE, RaaALICE, ErrNPartALICE, SystErrALICE); grRaaALICE->SetMarkerStyle(20); grRaaALICE->SetMarkerColor(4); grRaaALICE->GetYaxis()->SetRangeUser(0,1.7); TAxis *Xaxis2 = grRaaALICE->GetXaxis(); Xaxis2->SetLimits(0.,430.0); grRaaALICE->GetXaxis()->SetTitle("N_{Part}"); grRaaALICE->GetYaxis()->SetTitle("R_{AA}"); grRaaALICE->Draw("AP"); TLine *lh3 = new TLine(0.0,1.0,420,1.0); lh3->SetLineColor(1); lh3->SetLineStyle(1); lh3->SetLineWidth(1.5); lh3->Draw("same"); //TLatex *tb= new TLatex; //tb->SetNDC(); //tb->SetTextAlign(12); //tb->SetTextColor(1); //tb->SetTextSize(0.040); //tb->DrawLatex(0.22,0.22,"PbPb #sqrt{s_{NN}} = 2.76 TeV"); //tb->DrawLatex(0.22,0.16,"J/#psi #rightarrow #mu^{+} #mu^{-}, p_{T}^{J/#psi} > 0.0 GeV/c"); TBox *RaaJPsiALICESys[12]; for(int j=0;j<9;j++){ RaaJPsiALICESys[j] = new TBox(NPartALICE[j]-3, RaaALICE[j]-SystErrALICE[j], NPartALICE[j]+3, RaaALICE[j]+SystErrALICE[j]); } for(int j=0;j<9;j++){ RaaJPsiALICESys[j]->SetFillStyle(0000); RaaJPsiALICESys[j]->SetLineColor(4); RaaJPsiALICESys[j]->Draw("same"); } TBox *ALICEGlobalSysJPsi; ALICEGlobalSysJPsi = new TBox(400-5, 1 - 0.14, 400+5, 1 + 0.14); ALICEGlobalSysJPsi->SetFillStyle(3001); ALICEGlobalSysJPsi->SetLineColor(4); ALICEGlobalSysJPsi->SetFillColor(4); ALICEGlobalSysJPsi->Draw("same"); Draw_ALICEMid_JPsi_RaaVsNpart(lgd); lgd->AddEntry(grRaaALICE,"ALICE Data p_{T}^{J/#psi} > 0.0 GeV/c, 2.5 #leq y^{J/#psi} #leq 4.0","P"); }
void Draw_ALICEMid_JPsi_RaaVsNpart(TLegend *lgd) { //ALICE MID rapidity int nbinsALICEMid=3; Double_t NPartALICEMid[3]={357,193,46}; Double_t ErrNPartALICEMid[3]={0}; Double_t RaaALICEMid[3] = {0.82,0.65,0.73}; Double_t SystErrALICEMid[3] = {0.15,0.10,0.16}; TGraphErrors *grRaaALICEMid = new TGraphErrors(nbinsALICEMid, NPartALICEMid, RaaALICEMid, ErrNPartALICEMid, SystErrALICEMid); grRaaALICEMid->SetMarkerStyle(20); grRaaALICEMid->SetMarkerColor(2); //grRaaALICEMid->SetLineColor(2); grRaaALICEMid->GetYaxis()->SetRangeUser(0,1.5); TAxis *Xaxis = grRaaALICEMid->GetXaxis(); Xaxis->SetLimits(0.,430.0); grRaaALICEMid->GetXaxis()->SetTitle("N_{Part}"); grRaaALICEMid->GetYaxis()->SetTitle("R_{AA}"); grRaaALICEMid->Draw("Psame"); //TLatex *tb= new TLatex; //tb->SetNDC(); //tb->SetTextAlign(12); //tb->SetTextColor(1); //tb->SetTextSize(0.040); //tb->DrawLatex(0.55,0.90,"PbPb #sqrt{s_{NN}} = 2.76 TeV"); //tb->DrawLatex(0.22,0.16,"J/#psi #rightarrow #mu^{+} #mu^{-}, p_{T}^{J/#psi} > 0.0 GeV/c"); //tb->DrawLatex(0.55,0.85,"p_{T}^{J/#psi} > 0.0 GeV/c"); TLine *lh3 = new TLine(0.0,1.0,420,1.0); lh3->SetLineColor(1); lh3->SetLineStyle(1); lh3->SetLineWidth(1.5); lh3->Draw("same"); TBox *RaaJPsiALICEMidSys[12]; for(int j=0;j<3;j++){ RaaJPsiALICEMidSys[j] = new TBox(NPartALICEMid[j]-3, RaaALICEMid[j]-SystErrALICEMid[j], NPartALICEMid[j]+3, RaaALICEMid[j]+SystErrALICEMid[j]); } for(int j=0;j<3;j++){ RaaJPsiALICEMidSys[j]->SetFillStyle(0000); RaaJPsiALICEMidSys[j]->SetLineColor(2); RaaJPsiALICEMidSys[j]->Draw("same"); } TBox *ALICEMidGlobalSysJPsi; ALICEMidGlobalSysJPsi = new TBox(385-5, 1 - 0.26, 385+5, 1 + 0.26); ALICEMidGlobalSysJPsi->SetFillStyle(3001); ALICEMidGlobalSysJPsi->SetLineColor(2); ALICEMidGlobalSysJPsi->SetFillColor(2); ALICEMidGlobalSysJPsi->Draw("same"); lgd->AddEntry(grRaaALICEMid,"ALICE Data p_{T}^{J/#psi} > 0.0 GeV/c, |y^{J/#psi}| #leq 1.0","P"); }
void Draw_CMS_Y1S_RaaVsRap(TLegend *lgd) { const int nbinsRap=6; Double_t RapCMS[nbinsRap]={0.2,0.6,1.0,1.4,1.8,2.2}; Double_t ErrRapCMS[nbinsRap]={0}; Double_t RaaRapCMS[nbinsRap] = {0.402,0.377,0.452,0.461,0.466,0.35}; Double_t RaaRapStatErrCMS[nbinsRap] = {0.025,0.025,0.030,0.034,0.039,0.053}; Double_t RaaRapSystErrCMS[nbinsRap] = {0.0404,0.038,0.046,0.0466,0.0484,0.0373}; TGraphErrors *grRaaRapCMS = new TGraphErrors(nbinsRap, RapCMS, RaaRapCMS, ErrRapCMS, RaaRapStatErrCMS); grRaaRapCMS->SetMarkerStyle(20); grRaaRapCMS->SetMarkerColor(4); grRaaRapCMS->GetYaxis()->SetRangeUser(0,3.0); grRaaRapCMS->GetXaxis()->SetTitle("p_{T}(GeV/c)"); grRaaRapCMS->GetYaxis()->SetTitle("R_{AA}"); TAxis *Xaxis2 = grRaaRapCMS->GetXaxis(); Xaxis2->SetLimits(0.,2.4); grRaaRapCMS->Draw("AP"); TLine *lh4 = new TLine(0.0,1.0,20.0,1.0); lh4->SetLineColor(1); lh4->SetLineStyle(1); lh4->SetLineWidth(2); lh4->Draw("same"); TLatex *tb= new TLatex; tb->SetNDC(); tb->SetTextAlign(12); tb->SetTextColor(1); tb->SetTextSize(0.040); //tb->DrawLatex(0.55,0.22,"PbPb #sqrt{s_{NN}} = 2.76 TeV"); //tb->DrawLatex(0.55,0.16,"#varUpsilon #rightarrow #mu^{+} #mu^{-}, p_{T}^{#varUpsilon} > 0.0 GeV/c"); TBox *RaaRapCMSSys[nbinsRap]; for(int j=0;j<nbinsRap;j++){ RaaRapCMSSys[j] = new TBox(RapCMS[j]-0.1, RaaRapCMS[j]-RaaRapSystErrCMS[j], RapCMS[j]+0.1, RaaRapCMS[j]+RaaRapSystErrCMS[j]); } for(int j=0;j<nbinsRap;j++){ RaaRapCMSSys[j]->SetFillStyle(0000); RaaRapCMSSys[j]->SetLineColor(4); RaaRapCMSSys[j]->Draw("same"); } TBox *CMSGlobalSysRap; CMSGlobalSysRap = new TBox(18-0.2, 1 - 0.083, 18+0.2, 1 + 0.083); CMSGlobalSysRap->SetFillStyle(3001); CMSGlobalSysRap->SetLineColor(4); CMSGlobalSysRap->SetFillColor(4); //CMSGlobalSysRap->Draw("same"); lgd->AddEntry(grRaaRapCMS,"CMS Data", "P"); }
void Draw_CMS_JPsi_RaaVsRap(TLegend *lgd) { //=============== CMS Raa Vs Rap Data ===============================================================// //AvpT 10.92,9.65,8.92 int nbinsRapCMS=3; Double_t RapCMSD[3]={0.6,1.4,2.0}; Double_t ErrRapCMS[3]={0.6,0.2,0.4}; Double_t RaaRapCMS[3] = {0.31,0.33,0.36}; Double_t RaaRapStatErrCMS[3] = {0.02,0.03,0.03}; Double_t RaaRapSystErrCMS[3] = {0.03,0.04,0.04}; TGraphErrors *grRaaRapCMS = new TGraphErrors(nbinsRapCMS, RapCMSD, RaaRapCMS, ErrRapCMS, RaaRapStatErrCMS); grRaaRapCMS->SetMarkerStyle(20); grRaaRapCMS->SetMarkerColor(2); grRaaRapCMS->GetYaxis()->SetRangeUser(0,1.5); grRaaRapCMS->GetXaxis()->SetTitle("|y|"); grRaaRapCMS->GetYaxis()->SetTitle("R_{AA}"); TAxis *XaxisgrRaaRapCMS = grRaaRapCMS->GetXaxis(); XaxisgrRaaRapCMS->SetLimits(0.0,2.4); grRaaRapCMS->Draw("AP"); TLine *lh_grRaaRapCMS = new TLine(0.0,1.0,2.4,1.0); lh_grRaaRapCMS->SetLineColor(1); lh_grRaaRapCMS->SetLineStyle(1); lh_grRaaRapCMS->SetLineWidth(1.5); lh_grRaaRapCMS->Draw("same"); TLatex *tb= new TLatex; tb->SetNDC(); tb->SetTextAlign(12); tb->SetTextColor(1); tb->SetTextSize(0.040); tb->DrawLatex(0.20,0.20,"Pb+Pb #sqrt{s_{NN}} = 2.76 TeV"); tb->DrawLatex(0.20,0.15,"J/#psi #rightarrow #mu^{+} #mu^{-}, p_{T}^{J/#psi} > 6.5 GeV/c"); TBox *RaaRapJPsiCMSSys[4]; for(int j=0;j<3;j++){ RaaRapJPsiCMSSys[j] = new TBox(RapCMSD[j]-0.05, RaaRapCMS[j]-RaaRapSystErrCMS[j], RapCMSD[j]+0.05, RaaRapCMS[j]+RaaRapSystErrCMS[j]); } for(int j=0;j<3;j++){ RaaRapJPsiCMSSys[j]->SetFillStyle(0000); RaaRapJPsiCMSSys[j]->SetLineColor(2); RaaRapJPsiCMSSys[j]->Draw("same"); } TBox *CMSGlobalSysJPsiRap; CMSGlobalSysJPsiRap = new TBox(0.2-0.05, 1 - 0.05, 0.2+0.05, 1 + 0.05); CMSGlobalSysJPsiRap->SetFillStyle(3001); CMSGlobalSysJPsiRap->SetLineColor(2); CMSGlobalSysJPsiRap->SetFillColor(2); CMSGlobalSysJPsiRap->Draw("same"); lgd->AddEntry(grRaaRapCMS,"CMS Data", "P"); }
instrAsy() { gStyle->SetOptStat(0); gStyle->SetOptFit(0); TGraphErrors *gr =new TGraphErrors; gr->SetName("insyAsy"); gr->SetTitle("Instrumental Asymmetries"); //gr->SetMarkerColor(ampCol[iam]); gr->SetMarkerSize(0.8); gr->SetMarkerStyle(21); TGraphErrors *gr1=gr; TString wrkDir="final/"; TString fname=wrkDir+"defaultB-H/asyVer1.hist.root"; TFile *inpH=new TFile(fname); assert(inpH->IsOpen()); //inpH->ls(); const int nSel=5; char *selL[nSel]={ "a0*All","b0*All","a2*All","b2*All","c1*All"}; int isel; for (isel=0;isel<nSel;isel++) { TGraphErrors *gr =(TGraphErrors *) inpH->Get(selL[isel]); assert(gr); //gr->Print(); //gr->Draw("AP"); float x1=0; if(isel<2) x1=2189; gr->Fit("pol0","","",x1,3000); TF1 *ff=gr->GetFunction("pol0"); if(ff==0) continue; // no fit was made float val=ff->GetParameter(0); float err=ff->GetParError(0); printf("pol0= %f +/- %f\n",val,err); int n=gr1->GetN(); float x=isel+1; gr1->SetPoint(n,x,val); gr1->SetPointError(n,0,err); } gr1->Print(); // return; gr1->Draw("AP"); // save Tgraph TString fname=wrkDir+"instAsy.hist.root"; TFile *outH=new TFile(fname,"RECREATE"); assert(outH->IsOpen()); printf("save outH -->%s\n", fname.Data()); gr1->Write(); outH->ls(); outH->Write(); return; }
void Draw_CMS_JPsi_RaaVsNpart(TLegend *lgd) { int nbins = 12; Double_t RaaCMS[20]={0.23,0.24,0.29,0.33,0.38,0.40,0.45,0.41,0.52,0.52,0.64,0.64}; Double_t StatErrCMS[20]={0.01,0.01,0.02,0.02,0.02,0.03,0.03,0.03,0.04,0.04,0.05,0.05}; Double_t SystErrCMS[20]={0.02,0.03,0.03,0.03,0.04,0.04,0.05,0.04,0.05,0.05,0.07,0.13}; Double_t NPartCMS[20]={Npart(0,2),Npart(2,4),Npart(4,6),Npart(6,8),Npart(8,10),Npart(10,12), Npart(12,14),Npart(14,16),Npart(16,18),Npart(18,20),Npart(20,24), Npart(24,40)}; Double_t ErrNPartCMS[20]={0}; TGraphErrors *grRaaCMS = new TGraphErrors(nbins, NPartCMS, RaaCMS, ErrNPartCMS, StatErrCMS); grRaaCMS->SetMarkerStyle(21); grRaaCMS->SetMarkerColor(2); grRaaCMS->GetYaxis()->SetRangeUser(0,1.7); grRaaCMS->GetXaxis()->SetTitle("N_{Part}"); grRaaCMS->GetYaxis()->SetTitle("R_{AA}"); grRaaCMS->Draw("AP"); TBox *RaaJPsiSys[12]; for(int j=0;j<12;j++){ RaaJPsiSys[j] = new TBox(NPartCMS[j]-3, RaaCMS[j]-SystErrCMS[j], NPartCMS[j]+3, RaaCMS[j]+SystErrCMS[j]); } for(int j=0;j<12;j++){ RaaJPsiSys[j]->SetFillStyle(0000); RaaJPsiSys[j]->SetLineColor(6); RaaJPsiSys[j]->Draw("same"); } TLine *lh2 = new TLine(0.0,1.0,400,1.0); lh2->SetLineColor(1); lh2->SetLineStyle(1); lh2->SetLineWidth(2); lh2->Draw("same"); TBox *GlobalSysJPsi; GlobalSysJPsi = new TBox(400-5, 1 - 0.06, 400+5, 1 + 0.06); GlobalSysJPsi->SetFillStyle(3001); GlobalSysJPsi->SetLineColor(6); GlobalSysJPsi->SetFillColor(6); GlobalSysJPsi->Draw("same"); TLatex *tb= new TLatex; tb->SetNDC(); tb->SetTextAlign(12); tb->SetTextColor(1); tb->SetTextSize(0.040); tb->DrawLatex(0.17,0.23,"PbPb #sqrt{s_{NN}} = 2.76 TeV"); tb->DrawLatex(0.17,0.17,"p_{T}^{J/#psi} > 6.5 GeV/c"); lgd->AddEntry(grRaaCMS,"CMS Data", "P"); }
void gerrors() { TCanvas *mycanvas = new TCanvas("mycanvs","A Simple Graph with error bars",200,10,700,500); // mycanvas->SetFillColor(42); mycanvas->SetGrid(); // mycanvas->GetFrame()->SetFillColor(21); // mycanvas->GetFrame()->SetBorderSize(12); const int n_points =10; #double x_vals [ n_points]= {1,2,3,4,5,6,7,8,9,10}; double y_vals [ n_points]= {6 ,12 ,14 ,20 ,22 ,24 ,35 ,45 ,44 ,53}; double y_errs [ n_points]= {5 ,5 ,4.7 ,4.5 ,4.2 ,5.1,2.9,4.1,4.8,5.43}; TGraphErrors *gr = new TGraphErrors(n_points,x_vals,y_vals,NULL,y_errs); // TGraphErrors graph(n_points,x_vals,y_vals,NULL,y_errs); gROOT -> SetStyle("Plain"); gr->SetTitle("TGraphErrors Example; lengtht [cm];Arb. Units"); gr->SetMarkerColor(kBlue); gr->SetMarkerStyle(kOpenCircle); gr->SetLineColor ( kBlue ) ; gr->Draw("ALP"); //Define a linear function TF1 f("Linear law" ,"[0]+x*[1]" ,.5 ,10.5) ; // Let's make the funcion line nicer f.SetLineColor(kRed); f.SetLineStyle(2); // Fit it to the graph and draw it gr->Fit(&f); f.DrawClone("Same"); // Build and Draw a legend TLegend leg(.1 ,.7 ,.3 ,.9 ,"Lab. Lesson 1"); leg.SetFillColor (0) ; gr->SetFillColor (0) ; leg.AddEntry(gr,"Exp. Points"); leg.AddEntry(&f,"Th. Law"); leg.DrawClone("Same"); // Draw an arrow on the canvas TArrow arrow(8,8,6.2,23,0.02,"----|>"); arrow.SetLineWidth (2) ; arrow.DrawClone ( ) ; // Add some text to the plot TLatex text(8.2,7.5,"#splitline{Maximum}{Deviation}"); text.DrawClone ( ) ; mycanvas->Update(); mycanvas -> Print("example.pdf"); }
void JEC_fit_Uncertainty(int N) { TF1 *func[1000]; TFile *inf = new TFile("L3Graphs_test_Icone5.root"); TGraphErrors *g = (TGraphErrors*)inf->Get("Correction_vs_CaloPt"); TGraphErrors *vg[1000]; int i,k; double x[20],y[20],ex[20],ey[20]; double vx[20],vy[20],vex[20],vey[20]; for(i=0;i<g->GetN();i++) { g->GetPoint(i,x[i],y[i]); ex[i]=g->GetErrorX(i); ey[i]=g->GetErrorY(i); } TRandom *rnd = new TRandom(); rnd->SetSeed(0); for(k=0;k<N;k++) { for(i=0;i<g->GetN();i++) { vx[i] = rnd->Gaus(x[i],ex[i]); //vx[i] = x[i]; vy[i] = rnd->Gaus(y[i],ey[i]); vex[i] = ex[i]; vey[i] = ey[i]; } vg[k] = new TGraphErrors(g->GetN(),vx,vy,vex,vey); func[k] = new TF1("func","[0]+[1]/(pow(log10(x),[2])+[3])",1,2000); func[k]->SetParameters(1,3,6,5); vg[k]->Fit(func[k],"RQ"); } TCanvas *c = new TCanvas("c","c"); gPad->SetLogx(); g->SetMarkerStyle(20); g->SetMaximum(3.5); g->Draw("AP"); for(k=0;k<N;k++) { func[k]->SetLineColor(5); func[k]->SetLineWidth(1); cout<<func[k]->GetChisquare()<<endl; vg[k]->SetMarkerColor(2); vg[k]->SetLineColor(2); vg[k]->SetMarkerStyle(21); //if (func[k]->GetChisquare()<0.1) //vg[k]->Draw("sameP"); func[k]->Draw("same"); } }
void OneBin(Int_t bin, TH1* h0900, TH1* h2760, TH1* h7000, TH1* h8000, TMultiGraph* mg, TNtuple* tuple, Double_t sysErr=0.076) { Info("OneBin", "Getting one bin %d,%p,%p,%p,%p,%p", bin, h0900,h2760,h7000,h8000,tuple); Double_t eta = h0900->GetXaxis()->GetBinCenter(bin); Double_t w = h0900->GetXaxis()->GetBinWidth(bin); Info("", "Eta=%f +/- %f", eta, w); Double_t e[] = { 900., 2760., 7000., 8000., 0 }; TH1* h[] = { h0900, h2760, h7000, h8000, 0 }; Float_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; x[0] = eta; x[1] = w; TGraphErrors* g = new TGraphErrors(0); g->SetName(Form("eta%03d", bin)); g->SetTitle(Form("%f", eta)); g->SetMarkerStyle(bin % 10 + 20); g->SetMarkerColor(bin % 6 + 2); Double_t* pe = e; TH1** ph = h; Int_t i = 0; Int_t j = 1; while (*pe && *ph) { Double_t c = (*ph)->GetBinContent(bin); Double_t v = sysErr*c; if (c > 1e-6){ g->SetPoint(i, *pe, c); g->SetPointError(i, w, v); x[Int_t(2*j+0)] = c; x[Int_t(2*j+1)] = v; i++; } j++; pe++; ph++; } if (tuple) tuple->Fill(x); if (i > 0) mg->Add(g); else delete g; }
std::pair<double,double> plotVelocity(std::vector<double> positions, std::vector<double> means, int strip, std::vector<double> errors, char thresholdLabel) { TCanvas* c = new TCanvas(); TGraphErrors* vGraph = new TGraphErrors(positions.size(), &means[0], &positions[0], 0, &errors[0] ); vGraph->SetMarkerStyle(20); vGraph->SetMarkerSize(1); vGraph->Draw("AP"); vGraph->Fit("pol1"); TF1* fit = vGraph->GetFunction("pol1"); std::stringstream buf; buf << strip << "_" << thresholdLabel; c->SaveAs( (buf.str() + ".png").c_str() ); std::pair<double,double> resultOfFit = std::make_pair<double,double> ( (fit->GetParameter(1))*-0.2, (fit->GetParError(1))*-0.2 ); return resultOfFit; }
TGraphErrors *tools::ratioGraphs(TGraphErrors *g1, TF1 *f2) { assert(g1); assert(f2); TGraphErrors *g = new TGraphErrors(0); g->SetMarkerStyle(g1->GetMarkerStyle()); for (int i = 0; i != g1->GetN(); ++i) { double x, y, ex, ey; GetPoint(g1, i, x, y, ex, ey); double v = f2->Eval(x); SetPoint(g, i, x, v ? y/v : 0, ex, v ? ey/v : 0.); } return g; } // ratioGraphs (TF1*)
void TestGraphFillRandom() { TCanvas *c1 = new TCanvas("c1","My Awesome Test Graph!!",200,10,700,500); c1->SetFillColor(70); c1->SetGrid(); c1->GetFrame()->SetFillColor(100); c1->GetFrame()->SetBorderSize(1000); const int n = 10; double xarray[n], yarray[n], exarray[n], eyarray[n];// empty arrays of size n. TRandom3 jrand;// TRandom3 is the best so I'm making an object of the type TRandom3. jrand.RndmArray(n, xarray);// RndmArray(size of array, name of array) fills the arrays with random numbers. jrand.RndmArray(n, yarray); jrand.RndmArray(n, exarray); jrand.RndmArray(n, eyarray); vector<double> xVector; vector<double> yVector; vector<double> xErrorVector; vector<double> yErrorVector; for(int i =0; i<n; i=i+1){ xVector.push_back(xarray[i]); yVector.push_back(yarray[i]); xErrorVector.push_back(exarray[i]); yErrorVector.push_back(eyarray[i]); }// this for loop just fills the vectors with the values in the arrays TGraphErrors *gr = new TGraphErrors(n,&xVector[0],&yVector[0],&xErrorVector[0],&yErrorVector[0]); gr->SetTitle("Test Graph With Random Data and Error Bars"); gr->SetMarkerColor(2); gr->SetMarkerStyle(21); gr->Draw("ALP"); c1->Update(); }
void ExpManager::DrawMap(TString NameTitle, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) { TMultiGraph *mg = new TMultiGraph(); //Draw a cross TGraphErrors *frame = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); frame->SetPoint(0,+0,+100); frame->SetPoint(1,+0,-100); frame->SetPoint(2,0,0); frame->SetPoint(3,-100,0); frame->SetPoint(4,+100,0); frame->SetPoint(5,+0,+0); frame->SetPoint(6,+0,-100); frame->SetMarkerColor(kWhite); frame->SetDrawOption("ap"); //Draw the map TGraphErrors *fGraph = new TGraphErrors(); //= new TGraph2DErrors(np, x_array, y_array, bz_array, ex, ey, ez); fGraph->SetMarkerSize(1.2); fGraph->SetMarkerStyle(20); fGraph->SetMarkerColor(kBlue); fGraph->SetLineColor(kBlue); fGraph->SetLineWidth(1); //fGraph->SetDrawOption("ap"); int graph_counter = 0 ; for (unsigned i=0; i< fExpY.size(); i++) { if( (fExpX.at(i) >= xmin && fExpX.at(i) <= xmax) && (fExpY.at(i) >= ymin && fExpY.at(i) <= ymax) && (fExpZ.at(i) >= zmin && fExpZ.at(i) <= zmax) ) { fGraph->SetPoint(graph_counter,fExpX.at(i),fExpY.at(i)); fGraph->SetPointError(graph_counter,fExpXErr.at(i),fExpYErr.at(i)); graph_counter++; } } //fGraph->Write(); mg->SetTitle(NameTitle+Form(" Map : %.2f < X < %.2f mm %.2f < Y < %.2f mm %.2f < Z < %.2f mm;X (mm);Y (mm)",xmin,xmax,ymin,ymax,zmin,zmax)); mg->SetName(NameTitle+Form("_Map__X_%.2f_%.2fmm__Y_%.2f_%.2fmm__Z_%.2f_%.2fmm",xmin,xmax,ymin,ymax,zmin,zmax)); mg->Add(frame); mg->Add(fGraph); mg->Write(); }
void DrawSame(bool Flag_err,TTree *tree,Double_t *errx, char* varToPlot, char* cond, Int_t kColor,Int_t kMarker,TLegend* leg,char* cLeg){ TGraphErrors *g; tree->Draw(varToPlot,cond,"goff"); if (tree->GetSelectedRows()) { if(Flag_err) g = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(), errx, tree->GetV3()); else g=new TGraphErrors(tree->GetSelectedRows(),tree->GetV1(),tree->GetV2(),errx,errx); g->SetMarkerStyle(kMarker); g->SetMarkerSize(0.9); g->SetMarkerColor(kColor); g->Draw("SP"); //draw graph in current pad leg->AddEntry(g,cLeg,"p"); leg->Draw(); }else{ cout << "NO rows selected for leave " << varToPlot << endl; } }
void TestGraphRandBetter() {// named with the title so it will run automatically TCanvas *c1 = new TCanvas("c1","My Awesome Test Graph!!",200,10,700,500); c1->SetFillColor(70); c1->SetGrid(); c1->GetFrame()->SetFillColor(100); c1->GetFrame()->SetBorderSize(1000); const int n = 10; TRandom3 jrand; vector<double> xVector; vector<double> yVector; vector<double> xErrorVector; vector<double> yErrorVector; for(int i =0; i<n; i=i+1){ xVector.push_back(jrand.Integer(20)); yVector.push_back(jrand.Integer(20)); xErrorVector.push_back(jrand.Integer(5)); yErrorVector.push_back(jrand.Integer(5)); }// I changed my parameters so that the errors would be out of a smaller number than the x and y values. sort(xVector.begin(), xVector.end()); sort(yVector.begin(), yVector.end()); // This puts my vectors in order so that when I graph it, the points will be plotted from least to greatest. TGraphErrors *gr = new TGraphErrors(n,&xVector[0],&yVector[0],&xErrorVector[0],&yErrorVector[0]); gr->SetTitle("Test Graph With Random Data and Error Bars"); gr->SetMarkerColor(2); gr->SetMarkerStyle(21); gr->Draw("ALP"); c1->Update(); }
TGraphErrors* draw_single_spectra( string energy="15", string plc="la", string iCen="0", int color = kRed, string draw_opt = "", double scaler = 1.0 ){ Logger::setGlobalLogLevel( Logger::llAll ); gStyle->SetOptStat( 0 ); string fn = file_name( energy, plc, iCen ); if ( !file_exists( fn ) ) return new TGraphErrors(); INFO( "Loading " << fn ) SpectraLoader sl( fn ); sl = sl * scaler; TGraphErrors* stat = sl.statGraph( ); //stat->Scale( scaler ); // if ( "la" == plc || "ala" == plc){ // stat->SetBinContent( 1, 0 ); // stat->SetBinError( 1, 0 ); // } stat->SetTitle( " ; pT [GeV/c]; dN^{2} / ( N_{evt} 2 #pi pT dpT dy )" ); stat->SetLineColor( color ); stat->SetMarkerStyle( 8 ); stat->SetMarkerColor( color ); stat->Draw( draw_opt.c_str() ); gPad->SetLogy(1); return stat; }
TGraphErrors* getDataMcResponseRatio(TGraphErrors* gData, TGraphErrors* gMc, int aNumberOfPtBins, string XTitle) { Double_t x[aNumberOfPtBins]; Double_t ex[aNumberOfPtBins]; for(int j=0;j<aNumberOfPtBins; j++) { ex[j] = 0.; } Double_t xratio[aNumberOfPtBins]; Double_t ydata[aNumberOfPtBins]; Double_t ymc[aNumberOfPtBins]; Double_t yr[aNumberOfPtBins]; Double_t eydata[aNumberOfPtBins]; Double_t eymc[aNumberOfPtBins]; Double_t eyr[aNumberOfPtBins]; int nBins = 0; for(int i=0; i<aNumberOfPtBins; i++) { gMc->GetPoint(i,x[i],ymc[i]); gData->GetPoint(i,x[i],ydata[i]); eymc[i] = gMc->GetErrorY(i); eydata[i] = gData->GetErrorY(i); if (ymc[i] == 0 || ydata[i] == 0) continue; xratio[nBins] = x[i]; yr[nBins] = ydata[i]/ymc[i]; std::cout << yr[nBins] << std::endl; eyr[nBins] = sqrt(pow(eydata[i]/ymc[i],2)+pow(eymc[i]*ydata[i]/(pow(ymc[i],2)),2)); nBins++; } TGraphErrors *gDataMcResponseratio = new TGraphErrors(nBins,xratio,yr,ex,eyr); gDataMcResponseratio->SetMarkerStyle(20); gDataMcResponseratio->SetMarkerColor(1); gDataMcResponseratio->SetLineColor(1); gDataMcResponseratio->SetMarkerSize(1.0); //gDataMcResponseratio->SetMaximum(1.08); //gDataMcResponseratio->SetMinimum(0.90); gDataMcResponseratio->GetXaxis()->SetTitle(XTitle.c_str()); return gDataMcResponseratio; }