Re: [ROOT] fit - colour

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Aug 09 2001 - 12:08:54 MEST


Hi Hermine,

An example with two options. Uncomment the line with one of the options.

Rene Brun


#include "TH1.h"
#include "TF1.h"
   
Double_t fitf(Double_t *x, Double_t *par)
{
   Double_t arg = 0;
   if (par[2]) arg = (x[0] - par[1])/par[2];

   Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg);
   return fitval;
}
void myfit()
{

   TH1F *hpx = new TH1F("hpx","px distribution",100,-4,4);
   hpx->FillRandom("gaus",25000);
   
// Creates a Root function based on function fitf above
   TF1 *func = new TF1("fitf",fitf,-2,2,3);
   //func->SetLineColor(kRed);  //OPTION 1
   
// Sets initial values and parameter names
   func->SetParameters(100,0,1);
   func->SetParNames("Constant","Mean_value","Sigma");

// Fit histogram in range defined by function
   hpx->Fit("fitf","r");
   //hpx->GetFunction("fitf")->SetLineColor(kBlue); //OPTION 2
}


Hermine Katharina Woehri wrote:
> 
> Hello,
> 
> Into one pad I would like to draw 4 sets of data points, which I would
> like to fit. In order to additionally draw error bars, I set the
> MarkerSize of the histogram-points to zero and used the TGraphErrors() to
> draw the measured values with their error bars. The usage of filling a
> histogram was necessary in order to fit the data points. With
> SetMarkerColor for the TGraphErrors()-object I can select different
> colours for the data points.
> But, HOW, can I select different colours for the fitted curves?
> (hist1->SetColorLine(kBlue); does not work !).
> 
> Cheers,
> 
> Hermine
> 
> +------------------------------------------------------+
> |Hermine Katharina Woehri       hermine.woehri@cern.ch |
> +------------------------------------------------------|
> |EP Division                                           |
> |CERN                                                  |
> |CH-1211 Geneve 23             office:  +41 22 767-9408|
> |Switzerland                   private: +33 671 72 9888|
> +------------------------------------------------------+



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:56 MET