Hi Michal, lijowski@cosray2.wustl.edu wrote: > > Hello Rooters, > > My first problem is with the attached macro which performs > linear least squares fits on a set of points. The first two > routines produce the correct result but when I use TGraph > the result is different. > TGraph::ListSquareFit, etc are internals to TGraph. You cannot call this function directly. I changed the status to private in my development version. I have replaced your statement gr -> LeastSquareLinearFit(NPts, CC[0], CC[1], iflag); cout << " Intercept " << CC[0] << " Slope " << CC[1] << endl; by gr -> Fit("pol1"); TF1 *f1 = (TF1*)gROOT->GetFunction("pol1"); cout << " Intercept " << f1->GetParameter(0) << " Slope " << f1->GetParameter(1) << endl; you get the same results. > ******************************************* > * * > * W E L C O M E to R O O T * > * * > * Version 2.23/10 17 December 1999 * > * * > * You are welcome to visit our Web site * > * http://root.cern.ch * > * * > ******************************************* > > CINT/ROOT C/C++ Interpreter version 5.14.25, Nov 25 1999 > Type ? for help. Commands must be C++ statements. > Enclose multiple statements between { }. > Intercept 5174.96 Slope -0.00393377 > Intercept 5174.96 Slope -0.00393377 > Intercept 1.11407e-05 Slope 0.818446 > test_TGraph: Real Time = 0.04 seconds Cpu Time = 0.04 seconds > > My second problem is with TTreeViewer. When I try to invoke it by > typing TTreeViewer TV1("TTC1"); I get a message > > TDirectory* TOP TOP > KEY: TDirectory Comments;1 Comments > KEY: TTree TT;1 MSU data > KEY: TTree TTC1;1 MSU CAMERA 1 data > KEY: TTree TTC2;1 MSU CAMERA 2 data > Error: No symbol TTreeViewerTV1("TTC1") in current scope FILE:/var/tmp/eaa1LaGwO_cint LINE:1 > Possible candidates are... > filename line:size busy function type and name > > There are spaces between TTreeViewer and TV1. Since our library restructuring in 2.23, the class TTreeViewer is in the library libTreeViewer.so. This library is not linked by default with the root executable module. If you use frequently the viewer, you can add the following statement in your rootlogon.C file: gSystem->Load("libTreeViewer"); or instead of TTreeViewer TV1("TTC1"); you can do TTC1.StartViewer(); The StartViewer is able to detect if the class TTreeViewer is already linked. If not it will take care of linking the corresponding library. Rene Brun > > I have been running root on Solaris 2.7. > > Thank you and regards, > > Michal Lijowski > > ------------------------------------------------------------------------ > > void LLeastSquareLinearFit(Int_t ndata, Double_t *fX, Double_t *fY, Double_t &a0, Double_t &a1, Int_t &ifail) > { > //*-*-*-*-*-*-*-*-*-*Least square linear fit without weights*-*-*-*-*-*-*-*-* > //*-* ======================================= > // > // extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun > // (added to LSQ by B. Schorr, 15.02.1982.) > // > > static Double_t xbar, ybar, x2bar; > static Int_t i, n; > static Double_t xybar; > static Float_t fn, xk, yk; > static Double_t det; > > n = TMath::Abs(ndata); > ifail = -2; > xbar = ybar = x2bar = xybar = 0; > for (i = 0; i < ndata; ++i) { > xk = fX[i]; > yk = fY[i]; > if (ndata < 0) { > if (yk <= 0) yk = 1e-9; > yk = TMath::Log(yk); > } > xbar += xk; > ybar += yk; > x2bar += xk*xk; > xybar += xk*yk; > } > fn = Float_t(n); > det = fn*x2bar - xbar*xbar; > ifail = -1; > if (det <= 0) { > a0 = ybar/fn; > a1 = 0; > return; > } > ifail = 0; > a0 = (x2bar*ybar - xbar*xybar) / det; > a1 = (fn*xybar - xbar*ybar) / det; > } > > // -------------------------------------------------------------------- > > /* fitw - weighted least-squares linear fit - Bevington pp. 104-5 */ > Double_t fitw(Double_t *xx, Double_t *yy, Double_t *eyy, Int_t n, > Double_t &a, Double_t &b) > { > Double_t chisq; > Double_t delta; > Int_t i; > Double_t sum, sumx, sumy, sumx2, sumy2, sumxy; > Double_t wt, siga, sigb; > > sum = sumx = sumy = sumx2 = sumy2 = sumxy = 0.0; > > for (Int_t ii = 0; ii < n; ii++) { > wt = 1.0 / (eyy[ii] * eyy[ii]); > sum += wt; > sumx += wt * xx[ii]; > sumy += wt * yy[ii]; > sumx2 += wt * (xx[ii] * xx[ii]); > sumxy += wt * xx[ii] * yy[ii]; > sumy2 += wt * (yy[ii] * yy[ii]); > } > > delta = (sum * sumx2) - (sumx * sumx); > a = (sumx2*sumy - sumx*sumxy) / delta; > b = (sumxy*sum - sumx*sumy) / delta; > > chisq = sumy2 - (2 * b * sumxy) - (2 * a * sumy) + > (b * b * sumx2) + (2 * b * a * sumx) + (a * a * sum); > // printf(" a = %f b = %f, chisq, = %f\n", a, b, chisq); > > siga = sqrt(chisq*sumx2/delta); > sigb = sqrt(chisq*sum/delta); > > return (chisq); > } > > // ---------------------------------------------------------------------------- > > void test_TGraph() > > { > // gROOT -> Reset(); > > Char_t MacroName[40] = "test_TGraph"; > gBenchmark -> Start(MacroName); > gROOT -> SetStyle("Plain"); > gStyle -> SetOptStat(11); > gStyle -> SetCanvasColor(10); > > const Int_t NPts = 21; > > Double_t xx[NPts], yy[NPts], eyy[NPts]; > Double_t AA[2], BB[2], CC[2], CC0, CC1; > Double_t TestPoints[NPts][2] = { > 6292.669, 5150.209, > 6354.875, 5149.962, > 6416.175, 5149.720, > 6478.532, 5149.470, > 6538.507, 5149.235, > 6599.249, 5148.998, > 6660.600, 5148.758, > 6723.483, 5148.511, > 6783.863, 5148.275, > 6844.507, 5148.036, > 6904.864, 5147.796, > 6965.783, 5147.556, > 7026.159, 5147.322, > 7084.326, 5147.090, > 7143.208, 5146.861, > 7202.485, 5146.628, > 7261.480, 5146.396, > 7320.899, 5146.161, > 7379.941, 5145.928, > 7440.569, 5145.688, > 7500.361, 5145.454}; > > for (Int_t ii = 0; ii < NPts; ii++) { > xx[ii] = TestPoints[ii][0]; > yy[ii] = TestPoints[ii][1]; > eyy[ii] = 1.0; > } > Int_t iflag; > LLeastSquareLinearFit(NPts, xx, yy, AA[0], AA[1], iflag); > cout << " Intercept " << AA[0] << " Slope " << AA[1] << endl; > > Double_t chisq = fitw(xx, yy, eyy, NPts, BB[0], BB[1]); > cout << " Intercept " << BB[0] << " Slope " << BB[1] << endl; > > TGraph *gr = new TGraph(NPts, xx, yy); > gr -> LeastSquareLinearFit(NPts, CC[0], CC[1], iflag); > cout << " Intercept " << CC[0] << " Slope " << CC[1] << endl; > > gBenchmark -> Show(MacroName); > }
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:16 MET