Commit 0665dcb209f8f6152b5cf4d774dc5fc4e12d60f4

Authored by Bryony Lanigan
1 parent 34fce62c

Starter on fitting

Showing 1 changed file with 47 additions and 0 deletions   Show diff stats
fitting_starter.c 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +//This code gives an introduction to fitting. It's best run line by line from the prompt rather than as a macro.
  2 +
  3 +void fitting_starter(){
  4 +
  5 +TFile data("track_tree.root");
  6 +
  7 +TFile hfile("fitting_start_root.root","RECREATE","read-tree-test");
  8 +TTree *tracks = (TTree *) data.Get("SEL_TRACKS");
  9 +
  10 +tracks->Show(1); // this is a sneaky way of seeing what the event number of the first event is
  11 +
  12 +gStyle->SetOptFit(1111);
  13 +
  14 +TH1F pt1("pt1", "pt distribution of first event", 200, 400.0, 20400.0);
  15 +
  16 +tracks->Project("pt1","SEL_TRACKS_TRKS_pt","(SEL_TRACKS_TRKS_pt<20000)");
  17 +
  18 +TF1 fitfunction1("fitfunction1", "[0]*exp(-x/[1])", 0, 20000.0);
  19 +
  20 +double na = 60;
  21 +
  22 +double taua = 500;
  23 +
  24 +fitfunction1.SetParameters(na,taua);
  25 +
  26 +fitfunction1.SetParNames("Norma","Taua");
  27 +
  28 +auto fitResPtr1 = pt1.Fit(&fitfunction1, "S");
  29 +
  30 +fitResPtr1->Print();
  31 +
  32 +fitfunction1.GetParameter(0);
  33 +
  34 +fitfunction1.GetParError(0);
  35 +
  36 +fitfunction1.GetParameter(1);
  37 +
  38 +fitfunction1.GetParError(1);
  39 +
  40 +fitfunction1.GetChisquare();
  41 +
  42 +fitfunction1.GetNDF();
  43 +
  44 +hfile.Write();
  45 +hfile.Close();
  46 +
  47 +}
... ...