void grshade() { TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500); c1->SetGrid(); c1->DrawFrame(0,0,2.2,12); const Int_t n = 20; Double_t x[n], y[n],ymin[n], ymax[n]; Int_t i; for (i=0;i<n;i++) { x[i] = 0.1+i*0.1; ymax[i] = 10*sin(x[i]+0.2); ymin[i] = 8*sin(x[i]+0.1); y[i] = 9*sin(x[i]+0.15); } TGraph *grmin = new TGraph(n,x,ymin); TGraph *grmax = new TGraph(n,x,ymax); TGraph *gr = new TGraph(n,x,y); TGraph *grshade = new TGraph(2*n); for (i=0;i<n;i++) { grshade->SetPoint(i,x[i],ymax[i]); grshade->SetPoint(n+i,x[n-i-1],ymin[n-i-1]); } grshade->SetFillStyle(3013); grshade->SetFillColor(16); grshade->Draw("f"); grmin->Draw("l"); grmax->Draw("l"); gr->SetLineWidth(4); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); gr->Draw("CP"); }
void FindFuncsLT(){ TGraph * FNegvsLT = new TGraph(); FNegvsLT->SetName("FNegvsLT"); double par[3] = {mtop, MW, mB}; for(int i = 0; i<1000; i++){ double x[4] = {1, 0, i*0.001, 0}; cout<<x[1]<<"\t"<<FNeg(x, par)<<endl; FNegvsLT->SetPoint(i, (i*0.001), FNeg(x, par)); } FNegvsLT->SaveAs("FNegvsLT.C"); TGraph * FPosvsLT = new TGraph(); FPosvsLT->SetName("FPosvsLT"); for(int i = 0; i<1000; i++){ double x[4] = {1, 0, i*0.001, 0}; cout<<x[1]<<"\t"<<FR(x, par)<<endl; FPosvsLT->SetPoint(i, (i*0.001), FR(x, par)); } FPosvsLT->SaveAs("FPosvsLT.C"); TGraph * FZerovsLT = new TGraph(); FZerovsLT->SetName("FZerovsLT"); for(int i = 0; i<1000; i++){ double x[4] = {1, 0, i*0.001, 0}; cout<<x[1]<<"\t"<<FZero(x, par)<<endl; FZerovsLT->SetPoint(i, (i*0.001), FZero(x, par)); } FZerovsLT->SaveAs("FZerovsLT.C"); }
TGraph *MarcosExclusionLine(TH2F *exclusionshape, int scantype) { // write_warning(__FUNCTION__,"USING MARIAS ALGORITHM..."); // return get_exclusion_line(exclusionshape); TH2F *fakehisto = flipth2f(exclusionshape); TGraph *fakegraph = get_mSUGRA_exclusion_line(fakehisto, scantype); TGraph *realgraph = new TGraph(fakegraph->GetN()); double x,y; float last_x=0; float last_y=0; int counter=0; for(int i=0;i<fakegraph->GetN();i++) { fakegraph->GetPoint(i,x,y); if(scantype==PlottingSetup::SMS) { if(y-x<75) { realgraph->SetPoint(counter,last_x,last_y); counter++; continue; } } realgraph->SetPoint(counter,y,x); last_x=y; last_y=x; counter++; } realgraph->SetLineColor(TColor::GetColor("#151515")); //nice black realgraph->SetLineWidth(2); //realgraph->SetLineWidth(4);//paper style delete fakegraph; return realgraph; }
vector<double> getValsFromLikelihood(TGraph *graph){ TGraph *grRot = new TGraph(); TGraph *grRotUpp = new TGraph(); TGraph *grRotLow = new TGraph(); int pLow=0,pHigh=0; pair<double,double> graphMin = getGraphMin(graph); for (int p=0; p<graph->GetN(); p++){ double x,y; graph->GetPoint(p,x,y); grRot->SetPoint(p,y,x); if (x<=graphMin.first) { grRotLow->SetPoint(pLow,y,x); pLow++; } if (x>=graphMin.first) { grRotUpp->SetPoint(pHigh,y,x); pHigh++; } } // return best fit and +/- 1/2 sigma errors vector<double> result; result.push_back(grRot->Eval(0.)); result.push_back(grRotLow->Eval(1.0)); result.push_back(grRotUpp->Eval(1.0)); result.push_back(grRotLow->Eval(4.0)); result.push_back(grRotUpp->Eval(4.0)); return result; }
TGraph * makeOBV(TGraph *Graph1){ TGraph *gr = new TGraph(); double X; double Y; int pp=0; Graph1->GetPoint(1,X,Y); for (double MDM=1;MDM<=Y;MDM+=0.1){ gr->SetPoint(pp,MDM,vecF(X,MDM)); pp++; } for (int p =1;p<Graph1->GetN();p++){ Graph1->GetPoint(p,X,Y); if (!(X >1)) continue; std::cout << X << " " << Y << std::endl; gr->SetPoint(pp,Y,vecF(X,Y)); pp++; } gr->GetXaxis()->SetTitle("m_{DM}"); gr->GetYaxis()->SetTitle("#sigma_{SD}"); gr->SetName(Form("%s_DD",Graph1->GetName())); gr->SetLineStyle(Graph1->GetLineStyle()); gr->SetLineColor(Graph1->GetLineColor()); gr->SetLineWidth(Graph1->GetLineWidth()); return gr; }
void MaxExposuretimeVsPixelClock() { TGraph * gr = new TGraph(); gr->SetMarkerStyle(20); gr->SetPoint(0, 24, 333); gr->SetPoint(1, 36, 222); gr->SetPoint(2, 43, 186); gr->Draw("AP"); }
void test_many_fits(int ntries, bool do_fit) { TH1F* means1d = new TH1F("means1d","Fitted means", 200, -10, 10); TH1F* sigmas1d = new TH1F("sigmas1d","Fitted sigmas", 100, 0, 10); TGraph* means = tgraph("means","Fitted means vs try", 1); TGraph* avgs = tgraph("avgs","Histogram average vs try", 2); TGraph* sigmas = tgraph("sigmas","Fitted sigmas vs try", 1); TGraph* rmses = tgraph("rmses","Histogram RMSs vs try", 2); for (int count=0; count < ntries; ++count) { vector<double> ret = one_fit(do_fit); if (ret[0] != 0) { means1d->Fill(ret[1]); means->SetPoint(count,count,ret[1]); sigmas1d->Fill(ret[2]); sigmas->SetPoint(count,count,ret[2]); } avgs->SetPoint(count,count,ret[3]); rmses->SetPoint(count,count,ret[4]); } canvas->Clear(); canvas->Divide(2,2); canvas->cd(1); means1d->Draw(); canvas->cd(2); avgs->Draw("AL"); if (do_fit) { means->Draw(""); } canvas->cd(3); sigmas1d->Draw(); canvas->cd(4); rmses->Draw("AL"); if (do_fit) { sigmas->Draw(""); } if (do_fit) { canvas->Print("test_fit.pdf"); } else { canvas->Print("test_hist.pdf"); } }
void processmarriage(const char* ifname="marry.txt",const char* ofname="marry.root"){ vector<int> mage; vector<float> mpercent; vector<int> fage; vector<float> fpercent; mage.push_back(0); mpercent.push_back(0.0); fage.push_back(0); fpercent.push_back(0.0); ifstream marry(ifname); while(1){ int gender,year; float percent; marry >> gender >> year >> percent; if(!marry.good())break; if(gender == 1){ mage.push_back(year); mpercent.push_back(percent); } if(gender == 0){ fage.push_back(year); fpercent.push_back(percent); } } TFile* outfile = new TFile(ofname,"RECREATE"); TGraph* man = new TGraph(mage.size()); TGraph* woman = new TGraph(fage.size()); for(int i = 0; i < (int)mage.size(); i++){ man->SetPoint(i,mage[i],mpercent[i]); } for(int i = 0; i < (int)fage.size(); i++){ woman->SetPoint(i,fage[i],fpercent[i]); } man->SetName("man"); woman->SetName("woman"); man->Write(); woman->Write(); outfile->Write(); outfile->Close(); }
void createInputs(int n = 2) { for(UInt_t i = 0; i < (UInt_t)n; ++i ) { TFile *file = TFile::Open(TString::Format("input%d.root",i),"RECREATE"); TH1F * h = new TH1F("h1","",10,0,100); h->Fill(10.5); h->Fill(20.5); Int_t nbins[5]; Double_t xmin[5]; Double_t xmax[5]; for(UInt_t j = 0; j < 5; ++j) { nbins[j] = 10; xmin[j] = 0; xmax[j] = 10; } THnSparseF *sparse = new THnSparseF("sparse", "sparse", 5, nbins, xmin, xmax); Double_t coord[5] = {0.5, 1.5, 2.5, 3.5, 4.5}; sparse->Fill(coord); sparse->Write(); THStack *stack = new THStack("stack",""); h = new TH1F("hs_1","",10,0,100); h->Fill(10.5); h->Fill(20.5); h->SetDirectory(0); stack->Add(h); h = new TH1F("hs_2","",10,0,100); h->Fill(30.5); h->Fill(40.5); h->SetDirectory(0); stack->Add(h); stack->Write(); TGraph *gr = new TGraph(3); gr->SetName("exgraph"); gr->SetPoint(0,1,1); gr->SetPoint(1,2,2); gr->SetPoint(2,3,3); gr->Write(); TTree *tree = new TTree("tree","simplistic tree"); Int_t data = 0; tree->Branch("data",&data); for(Int_t l = 0; l < 2; ++l) { data = l; tree->Fill(); } file->Write(); delete file; } }
void decorate(TCanvas *can,TH2D &h, bool addLHC=true){ TLatex * tex = new TLatex(); tex->SetNDC(); tex->SetTextFont(42); tex->SetLineWidth(2); tex->SetTextSize(0.03); tex->DrawLatex(0.32,0.93,"4.9 fb^{-1} (7 TeV) + 19.7 fb^{-1} (8 TeV) + 2.3 fb^{-1} (13 TeV)"); tex->SetTextFont(42); tex->SetTextSize(0.06); //if (!addLHC){ // tex->SetTextSize(0.04); // tex->SetTextColor(kWhite); // if (isPrelim) tex->DrawLatex(0.155, 0.85, "#bf{CMS} #it{Preliminary}"); // else tex->DrawLatex(0.155, 0.85, "#bf{CMS}"); //} else { if (isPrelim) { tex->SetTextSize(0.04); tex->DrawLatex(0.155, 0.85, "#bf{CMS} #it{Preliminary}"); } else tex->DrawLatex(0.14, 0.93, "#bf{CMS}"); //} TGraph *SM = new TGraph(); SM->SetPoint(0,1,1); SM->SetMarkerColor(kOrange); SM->SetMarkerStyle(33); SM->SetMarkerSize(4); SM->Draw("Psame"); TLegend *leg; if (addLHC) { if (isPrelim) leg = new TLegend(0.14,0.56,0.4,0.83); else leg = new TLegend(0.14,0.62,0.4,0.89); } else leg = new TLegend(0.52,0.84,0.78,0.89); leg->SetTextSize(0.042); leg->SetFillStyle(0); leg->SetTextColor(kWhite); leg->SetBorderSize(0); TGraph *gr = new TGraph(); gr->SetLineWidth(2); gr->SetMarkerStyle(34); gr->SetLineColor(kWhite); gr->SetMarkerColor(kWhite); TGraph *gr2 = new TGraph(); gr2->SetLineWidth(2); gr2->SetLineColor(kWhite); gr2->SetLineStyle(2); gr->SetMarkerSize(2); if (addLHC){ leg->AddEntry(SM,"SM production","P"); leg->AddEntry(gr,"LHC best fit","P"); leg->AddEntry(gr, "68% CL","L"); leg->AddEntry(gr2,"95% CL","L"); leg->Draw(); } else { TLatex *lat = new TLatex(); lat->SetTextSize(0.04); lat->SetTextColor(kWhite); lat->DrawLatex(1.05,1.05,"SM production"); } can->SetTicky(); can->SetTickx(); can->RedrawAxis(); }
TGraph* getGraph(string name, int color, int width, int style, TLegend* LEG, TGraph* Ref, int type, string filePath){ // filePath+="/LimitSummary"; FILE* pFile = fopen(filePath.c_str(),"r"); if(!pFile){printf("Can't open %s\n",filePath.c_str()); exit(0);} double mass, th, exp, obs, unused;// char buffer[1024]; TGraph* graph = new TGraph(250); int N=0; while(fscanf(pFile,"$%le$ & $%le$ & $[%le,%le]$ & $[%le,%le]$ & $%le$ & Th=$%le$ & pValue=$%le$\\\\\\hline\n",&mass, &exp, &unused, &unused, &unused,&unused,&obs, &th, &unused) != EOF){ // printf("%i %f - %f - %f\n",N,mass,exp, th); double value = exp; if(abs(type)==0) value = th; else if(abs(type)==1) value = exp; else value = obs; // if(type<0 && filePath.find("cp0.80")!=string::npos) value *= pow(0.8, 2); // if(type<0 && filePath.find("cp0.60")!=string::npos) value *= pow(0.6, 2); // if(type<0 && filePath.find("cp0.30")!=string::npos) value *= pow(0.3, 2); // if(type<0 && filePath.find("cp0.10")!=string::npos) value *= pow(0.1, 2); if(Ref){value/=Ref->Eval(mass);} graph->SetPoint(N, mass, value);N++; if(N>100)break; } graph->Set(N); graph->SetName(name.c_str()); graph->SetLineColor(color); graph->SetLineWidth(width); graph->SetLineStyle(style); if(LEG)LEG->AddEntry(graph, name.c_str() ,"L"); return graph; }
TGraph* makeGraph(const TArrayI& adcs, Int_t rate) { Int_t last = adcs.fArray[0]; TArrayI counts(4); TGraph* graph = new TGraph(rate * adcs.fN); graph->SetLineColor(rate); graph->SetMarkerColor(rate); graph->SetMarkerStyle(20+rate); graph->SetLineStyle(rate); graph->SetName(Form("rate%d", rate)); graph->SetTitle(Form("Rate %d", rate)); for (Int_t i = 0; i < adcs.fN; i++) { counts.Reset(-1); convert(rate, adcs.fArray[i], last, counts); for (Int_t j = 0; j < rate; j++) { Int_t idx = (i * rate + j); Double_t x = (i + (rate > 1 ? Float_t(j+1) / rate-1 : 0)); graph->SetPoint(idx, x, counts[j]); } last = counts[rate - 1]; } return graph; }
void ButkevichDrawer::adjust_graph(TGraph& graph) { for (int iPoint=0;iPoint<graph.GetN();iPoint++) { double x,y; graph.GetPoint(iPoint,x,y); graph.SetPoint(iPoint,x,y*1.0e-38); } }
void FBResults::GetbVSdEtaFromFit(vector<FBCorrel*>& vfbc , int accmin , int accmax , TGraph& p ){ for(int acc = accmin , i = 0 ; acc <= accmax ; ++acc , ++i){ double dEta = accMap->at(acc).etaP - accMap->at(acc).etaM; p.SetPoint(i , dEta , vfbc.at(acc)->b_fit ); } }
TGraph* getRoC( TH1D* h1_signal, TH1D* h1_bg ) { TGraph* graph = new TGraph(); graph->SetName("RoC"); int nbins = h1_signal->GetNbinsX(); for( unsigned ibin=1; ibin<nbins+1; ++ibin ) { float eff_signal_num = h1_signal->Integral( ibin, nbins ); float eff_signal_denom = h1_signal->Integral( 1, nbins ); float eff_bg_num = h1_bg->Integral( ibin, nbins ); float eff_bg_denom = h1_bg->Integral( 1, nbins ); float eff_signal = eff_signal_num/eff_signal_denom; float eff_bg = eff_bg_num/eff_bg_denom; graph->SetPoint( ibin-1, 1.-eff_bg, eff_signal ); } //for bins return graph; }
TGraph GetCurve(int Points,const double & hi_ex_set) { TGraph curve; if(!gPrimaryReaction.IsSet()){ std::cout<<"Reaction Masses have not been set"<<std::endl; exit(EXIT_FAILURE); } if(!gPrimaryReaction.BeamEnergy()){ std::cout<<"Beam Energy has not been set"<<std::endl; exit(EXIT_FAILURE); } sim::RN_SimEvent evt1(gPrimaryReaction.BeamEnergy(),gPrimaryReaction.M_Beam(),gPrimaryReaction.M_Target(),gPrimaryReaction.M_Recoil(),gPrimaryReaction.M_Fragment()); // Fill the points of the kinematic curve int p=0; while(p<Points){ double theta_deg = 180.0*p/Points; double phi=2.*M_PI*global::myRnd.Rndm(); TVector3 nv; nv.SetMagThetaPhi(1.,theta_deg*M_PI/180.0,phi); if(!evt1.radiate_in_CM(nv,hi_ex_set)) continue; else curve.SetPoint(p, evt1.getLVrad().Theta()*180/3.14,(double)(evt1.getLVrad().E()-evt1.getLVrad().M())); p++; } // end for(p) return curve; }
TGraph* makeSeparationCurve(const TH1* histogram_Z, const TH1* histogram_Higgs) { const double xMin = 0.; const double xMax = 200.; double normalization_Z = getIntegral(histogram_Z, xMin, xMax); double normalization_Higgs = getIntegral(histogram_Higgs, xMin, xMax); assert(histogram_Z->GetNbinsX() == histogram_Higgs->GetNbinsX()); const double epsilon = 1.e-3; double runningSum_Z = 0.; double runningSum_Higgs = 0.; int numBins = histogram_Z->GetNbinsX(); TGraph* graph = new TGraph(numBins); for ( int iBin = numBins; iBin >= 1; --iBin ) { assert(TMath::Abs(histogram_Z->GetBinCenter(iBin) - histogram_Higgs->GetBinCenter(iBin)) < epsilon); double binCenter = histogram_Z->GetBinCenter(iBin); if ( binCenter >= xMin && binCenter < xMax ) { runningSum_Z += histogram_Z->GetBinContent(iBin); runningSum_Higgs += histogram_Higgs->GetBinContent(iBin); } graph->SetPoint(iBin - 1, runningSum_Higgs/normalization_Higgs, 1. - runningSum_Z/normalization_Z); } return graph; }
TGraph *graphLH(std::string nuisname, double err ){ w->loadSnapshot("bestfitall"); // SetTo BestFit values as start // Get The parameter we want RooRealVar *nuis =(RooRealVar*) w->var(nuisname.c_str()); double bf = nuis->getVal(); double nll_0=nll->getVal(); TGraph *gr = new TGraph(2*npoints+1); for (int i=-1*npoints;i<=npoints;i++){ nuis->setVal(bf+err*( ((float)i)*nsigma/npoints)); double nll_v = nll->getVal(); gr->SetPoint(i+npoints,nuis->getVal(),nll_v-nll_0); } gr->SetTitle(""); gr->GetYaxis()->SetTitle("NLL - obs data"); gr->GetYaxis()->SetTitleOffset(1.1); gr->GetXaxis()->SetTitleSize(0.05); gr->GetYaxis()->SetTitleSize(0.05); gr->GetXaxis()->SetTitle(nuisname.c_str()); gr->SetLineColor(4); gr->SetLineWidth(2); gr->SetMarkerStyle(21); gr->SetMarkerSize(0.6); return gr; }
/** * \brief Plots the data * Plots the data in data_x and data_y * \param bool autox , bool autoy actually not needed ;) * \return bool on success */ bool Plotter::plot(bool autox , bool autoy){ for(size_t j = 0 ; j< graph.size(); j++){ try{ TGraph *gr = graph[j].get(); for(size_t i = 0; i < data_x.size(); i++){ gr->SetPoint(i,data_x[i], data_y[i]); } if(!opt.autox){ gr->GetHistogram()->GetXaxis()->SetRangeUser(opt.startx, opt.stopx); } if(!opt.autoy){ gr->GetHistogram()->GetYaxis()->SetRangeUser(opt.starty, opt.stopy); } gr->SetMarkerSize(0.2); gr->GetHistogram()->SetXTitle(opt.xlabel.c_str()); gr->GetHistogram()->SetYTitle(opt.ylabel.c_str()); gr->SetTitle(opt.plot_name.c_str()); gr->Draw("A*"); }catch(std::runtime_error &e){ std::cerr << e.what() << std::endl; return false; } } return true; }
TGraph *gr21Dspline_tanB(RooSplineND *spline, RooRealVar &ldu, RooRealVar &lVu, RooRealVar &kuu, int type, double minNLL, double fixcbma) { TGraph *points = new TGraph(); int pcounter = 0; double Vldu, VlVu, Vkuu; // holders for the values for (double th=0.001; th<=10;th+=0.1){ double x = fixcbma; double y = TMath::Tan(th); // x irrelevant in grid search if (type==1)type1(x, y, &Vldu, &VlVu, &Vkuu); if (type==2)type2(x, y, &Vldu, &VlVu, &Vkuu); ldu.setVal(Vldu); lVu.setVal(VlVu); kuu.setVal(Vkuu); val = 2*spline->getVal() - minNLL; points->SetPoint(pcounter,val,y); pcounter++; } points->GetYaxis()->SetTitle("tan(#beta)"); points->GetXaxis()->SetTitle("-2#Delta Log(L)"); return points; }
void KVCanvas::ProjectionX(TH2* hh) { TString pname = Form("%s_px", hh->GetName()); Int_t ip = 1; while (gROOT->FindObject(pname.Data())) { pname = Form("%s_px%d", hh->GetName(), ip); ip++; } TH1* px = hh->ProjectionX(pname.Data()); if (!px) return; Double_t minY = (hh->GetYaxis()->GetXmin()); Double_t maxY = (hh->GetYaxis()->GetXmax()); Double_t dY = (maxY - minY) * 0.8; Double_t maxH = px->GetBinContent(px->GetMaximumBin()); TGraph* gg = 0; if ((gg = (TGraph*)gROOT->FindObject(Form("%s_gjx", hh->GetName())))) gg->Delete(); gg = new TGraph; for (int i = 0; i < px->GetNbinsX(); i++) { gg->SetPoint(i, px->GetBinCenter(i), minY + px->GetBinContent(i)*dY / maxH); } gg->SetName(Form("%s_gjx", hh->GetName())); gg->SetTitle(Form("%s_gjx", hh->GetName())); gg->SetLineColor(kBlack); gg->SetMarkerColor(kBlack); gg->SetMarkerStyle(8); gg->Draw("PL"); Modified(); Update(); }
TGraph* graph_delta( TGraph* g1, TGraph* g2 ) { /* make sure both graph have smae number of entries- return NULL pointer if they don't */ if ( g1->GetN() != g2->GetN() ) { cerr << "Mismatch in number of points for graphs in calculating delta!" << endl; return NULL; } TGraph* gdelta = new TGraph( g1->GetN() );// (TGraph*)g1->Clone("gdelta"); for ( unsigned i = 0; i < g1->GetN(); i++ ) { Double_t x1 = 0; Double_t y1 = 0; Double_t x2 = 0; Double_t y2 = 0; g1->GetPoint( i , x1 , y1 ); g2->GetPoint( i , x2 , y2 ); Double_t xdelta = x1; Double_t ydelta = y1-y2; gdelta->SetPoint(i, xdelta, ydelta); } return gdelta; }
void plotMaxLikelihood(const char* filename, const char* channel, double min_=0., double max_=-1., bool log_=false, std::string dataset_="CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 19.4 fb^{-1} at 8 TeV", std::string xaxis_="m_{H} [GeV]", std::string yaxis_="best fit for #sigma/#sigma_{SM}", bool mssm_=false) { TFile* file = TFile::Open(filename); // retrieve TGraphs from file TGraph* expected = (TGraph*)file->Get(std::string(channel).append("/expected").c_str()); TGraphAsymmErrors* innerBand = (TGraphAsymmErrors*)file->Get(std::string(channel).append("/innerBand").c_str()); // set up styles SetStyle(); // create the unit line TGraph* unit = 0; if(!mssm_){ unit = new TGraph(); for(int imass=0, ipoint=0; imass<expected->GetN(); ++imass){ unit->SetPoint(ipoint, expected->GetX()[imass], 1.); ++ipoint; } } // set proper maximum float max = maximum(expected, max_); // do the plotting TCanvas canv = TCanvas("canv", "Limits", 600, 600); plottingLimit(canv, innerBand, 0, expected, 0, unit, xaxis_, yaxis_, min_, max, log_, "BESTFIT", "", mssm_); // setup CMS Preliminary CMSPrelim(dataset_.c_str(), "", 0.145, 0.835); // write results to files canv.Print(std::string(channel).append("_").append("bestfit").append(".png").c_str()); canv.Print(std::string(channel).append("_").append("bestfit").append(".pdf").c_str()); canv.Print(std::string(channel).append("_").append("bestfit").append(".eps").c_str()); return; }
double get_correctionFactorbb(){ double xx[5] = {39, 62.4, 200, 2760, 5000}; double yy[5] = {0.00944, 0.0709, 1.81, 94.92, 180}; TGraph *g = new TGraph(5); for(int i=0; i<5; i++){ g->SetPoint(i,xx[i],yy[i]); } TCanvas *c = new TCanvas("c","c",600,450); g->SetMarkerStyle(20); g->Draw("AP"); c->SetLogy(); c->SetLogx(); TF1 *f = new TF1("f","[0]+[1]*x+[2]*x*x",0,300); //TF1 *f = new TF1("f","[0]*pow(x,[1])",0,5500); //f->SetParameters(0,-5); g->Fit(f,"R"); double corr = (f->Eval(193))/(f->Eval(200)); return corr; }
void GraphCrdcPads(int num=0,int CRDCNum=0){ //This script will look at the Raw root trees //and plot a single crdc pad distribution S800Event * event= new S800Event(); rawtree->SetBranchAddress("s800event",&event); rawtree->GetEntry(num); // cout<<"Size of samples "<<event->GetS800()->GetCrdc(0)->GetSample().size()<<endl; // cout<<"Size of data "<<event->GetS800()->GetCrdc(0)->GetData().size()<<endl; // cout<<"Size of channels "<<event->GetS800()->GetCrdc(0)->GetChannels().size()<<endl; int size = event->GetS800()->GetCrdc(CRDCNum)->GetChannels().size(); TString install =gSystem->Getenv("R00TLeInstall"); TString calfile = install+"/prm/crdccalNone.dat"; TString pedfile = install+"/prm/crdcpedestals.dat"; S800Calibration calibration;//new S800Settings(install+"/prm/Raw2Cal.dat")); calibration.ReadCrdcCalibration(calfile,pedfile); //calibration.SetCrdc(event->GetS800()->GetCrdc(0)->GetChannels(),event->GetS800()->GetCrdc(0)->GetData(),0,0,0); calibration.CrdcCal(event->GetS800()->GetCrdc(CRDCNum)->GetChannels(),event->GetS800()->GetCrdc(CRDCNum)->GetData(),0); int size2=calibration.GetCRDCCal().size(); TGraph * graph = new TGraph(); for (int i=0;i<size2;i++){ if (TMath::IsNaN(calibration.GetCRDCCal()[i])){ graph->SetPoint(i,i,0); }else { graph->SetPoint(i,i,calibration.GetCRDCCal()[i]); } } graph->Fit("gaus"); graph->Draw("A*"); return; }
TGraph * GetIntersections(TGraph * a, TGraph * b) { TGraph * c = new TGraph(); Int_t i = 0; // Loop over all points in TGraph a for(size_t a_i = 0; a_i < a->GetN() - 1; a_i++) { // Loop over all points in TGraph b for(size_t b_i = 0; b_i < b->GetN() - 1; b_i++) { // Get the current point and the next point for each of the TGraphs Double_t ax1, ay1, ax2, ay2 = 0; Double_t bx1, by1, bx2, by2 = 0; a->GetPoint(a_i, ax1, ay1); a->GetPoint(a_i + 1, ax2, ay2); b->GetPoint(b_i, bx1, by1); b->GetPoint(b_i + 1, bx2, by2); // Calculate the intersection between two straight lines, x axis Double_t x = (bx1 * (by2 * (ax1 - ax2) + ax2 * ay1 - ax1 * ay2) + bx2 * (by1 * (ax2 - ax1) - ax2 * ay1 + ax1 * ay2)) / ((by2 - by1) * (ax1 - ax2) + (bx1 - bx2) * (ay1 - ay2)); // Calculate the intersection between two straight lines, y axis Double_t y = (bx1 * by2 * (ay1 - ay2) + bx2 * by1 * (ay2 - ay1) + (by1 - by2) * (ax2 * ay1 - ax1 * ay2)) / ((by2 - by1) * (ax1 - ax2) + (bx1 - bx2) * (ay1 - ay2)); // Find the tightest interval along the x-axis defined by the four points Double_t xrange_min = max(min(ax1, ax2), min(bx1, bx2)); Double_t xrange_max = min(max(ax1, ax2), max(bx1, bx2)); // If points from the two lines overlap, they are trivially intersecting if ((ax1 == bx1 && ay1 == by1) || (ax2 == bx2 && ay2 == by2)) { c->SetPoint(i, (ax1 == bx1 && ay1 == by1) ? ax1 : ax2, (ax1 == bx1 && ay1 == by1) ? ay1 : ay2); i++; } // If the intersection between the two lines is within the tight range, add it to the list of intersections. else if (x > xrange_min && x < xrange_max) { c->SetPoint(i, x, y); i++; } } } return c; }
TGraph * makeLog (TGraph * orig) { TGraph * dummy = new TGraph (orig->GetN ()) ; for (int k = 0 ; k < orig->GetN () ; ++k) { double x, y ; orig->GetPoint (k, x, y) ; dummy->SetPoint (k, x, TMath::Log (y)) ; } return dummy ; }
TGraph* makeBandGraph(TGraph* g1, TGraph* g2) { int n1 = g1->GetN(); int n2 = g2->GetN(); TGraph* graph = new TGraph(n1+n2); for(int i=0; i<n1; i++){ double x,y; g1->GetPoint(i,x,y); graph->SetPoint(i,x,y); } for(int i=0; i<n2; i++){ double x,y; g2->GetPoint(n2-1-i,x,y); graph->SetPoint(n1+i,x,y); } return graph; }
//___________________________________________________________ void pdfIO(const Int_t method = 0) { // Test interpolator IO response for several data dimensions. // method = 0 : use COG interpolator // method = 1 : use INT interpolator Float_t tw, tr; TGraph *gw = new TGraph(5); gw->SetMarkerStyle(24);gw->SetMarkerColor(2); TGraph *gr = new TGraph(5); gr->SetMarkerStyle(25);gr->SetMarkerColor(4); for(int idim = 1; idim<6; idim++){ tw = interpolWrite(method, idim); gw->SetPoint(idim-1, idim, tw); tr = interpolRead(idim); gr->SetPoint(idim-1, idim, tr); } gw->Draw("apl"); gr->Draw("pl"); }
void auto_lednic_input_new() { gROOT->SetStyle("Plain"); Double_t ZR_min = 0.5; Double_t ZR_max = 3.0; const Int_t n = 100; // lednic_input default values (ZT = 0.01, V = 0.001) Double_t ZT_min = 0.001; Double_t ZT_max = 2.0; Double_t V_min = 0.0001; Double_t V_max = 0.3; Double_t x[n], y_min[n], y_max[n], step = (ZR_max - ZR_min)/n; for (Int_t i = 0; i < n; i++) { x[i] = ZR_min + i*step; y_min[i] = CalcLednicR(x[i], ZT_min, V_min); y_max[i] = CalcLednicR(x[i], ZT_max, V_max); } TGraph *g_min = new TGraph(n, x, y_min); TGraph *g_max = new TGraph(n, x, y_max); TGraph *gg = new TGraph(2*n); for (Int_t i = 0; i < n; i++) { gg->SetPoint(i, x[i], y_max[i]); gg->SetPoint(n+i, x[n-i-1], y_min[n-i-1]); } gg->SetTitle(";r_{0} [fm];R (k = 0.02 GeV/c)"); gg->GetYaxis()->CenterTitle(); gg->SetMinimum(0); gg->SetFillStyle(3003); gg->Draw("AF"); g_min->Draw("C"); g_max->SetLineStyle(2); g_max->Draw("C"); TLegend *leg = new TLegend(0.50, 0.70, 0.85, 0.85); leg->AddEntry(g_min, Form("t_{0} = %.3f fm, v = %.4fc", ZT_min, V_min), "L"); leg->AddEntry(g_max, Form("t_{0} = %.3f fm, v = %.4fc", ZT_max, V_max), "L"); leg->SetFillColor(0); leg->Draw(); gPad->Print("pp_correl_r0.pdf"); }