#include "TH1.h" #include "TF1.h" #include "TFile.h" #include "TCanvas.h" #include "TGInputDialog.h" #include "Riostream.h" //Attempt at a fit function - x, y and z and are intended to stand in for the values in the arrays X0[i], X2[i] and X4[i] // par[0]=G2 and par[1]=G4 Double_t Gks(Double_t *x, Double_t *y, Double_t *z, Double_t *par) { const int n = 20; Double_t x[n]; Double_t y[n]; Double_t z[n]; return x[0]+par[0]*y[0]+par[1]*z[0]; } void test() { Double_t G2 = 0.63; //reasonable starting value for G2 Double_t G4 = 0.42; //reasonable starting value for G4 TFile* file = TFile::Open( "Ru960309_PhiCanvas.root", "READ" ); PhiCanvas->Draw(); TFile *f = new TFile("Ru960309.root","RECREATE"); TH1F *h1 = new TH1F("h1","Xk values",5,1,5); TTree *TREE = new TTree("TREE","heliofit data from ascii file"); Long64_t nlines = TREE->ReadFile("Ru960309.txt","theta:det_no:X0:X2:X4"); //read the ASCII file that contains the array values printf(" found %lld points\n",nlines); PhiCanvas->cd(1); hTheta90->SetLineWidth(1.0); hTheta90->SetStats(1); hTheta90->SetLineStyle(1); hTheta90->SetLineColor(kBlue); hTheta90->Draw("PCE1"); TREE->SetLineWidth(1.0); TREE->SetLineStyle(2); TREE->SetLineColor(kBlack); //Examples of the type of fit I am hoping to achieve TREE->Draw("X0+0.86*X2+0.64*X4:(det_no-1)*45","theta==90","same PC"); TREE->Draw("X0+0.75*X2+0.53*X4:(det_no-1)*45","theta==90","same PC"); TREE->Draw("X0+0.63*X2+0.42*X4:(det_no-1)*45","theta==90","same PC"); TREE->Draw("X0+0.52*X2+0.31*X4:(det_no-1)*45","theta==90","same PC"); TREE->Draw("X0+0.41*X2+0.20*X4:(det_no-1)*45","theta==90","same PC"); TF1 *Gks = new TF1("Gks",Gks,180,1,180); hTheta90->Fit("Gks"); Gks->SetParNames("G2","G4"); Gks->SetParameters(G2,G4); Gks->SetParLimits(0,0,1); Gks->SetParLimits(1,0,1); Gks->SetLineWidth(5.0); Gks->SetLineStyle(1); Gks->SetLineColor(kBlue); Gks->Draw("same"); }