MuonFit4sp.C
Go to the documentation of this file.
1 #include <iostream.h>
2 #include <fstream>
3 #include <iomanip.h>
4 #include <sstream>
5 #include <string>
6 #include <cstring>
7 
8 Double_t customFunc(Double_t *x, Double_t *par){
9 
10  Float_t xx = x[0];
11  Double_t f = 0.0;
12 
13  //Parameters:
14 
15  // par[0] = intercept
16  // par[1] = slope 1
17  // par[2] = slope 2
18  // par[3] = slope 3
19  // par[4] = stitch point 1
20  // par[5] = stitch point 2
21  // par[6] = slope 4
22  // par[7] = stitch point 3
23 
24  if (xx < par[4]){
25  f = par[1]*xx + par[0];
26  }
27 
28  else if (xx < par[5]) {
29  f = par[2]*xx + ((par[1]-par[2])*par[4]+par[0]);
30  }
31 
32  else if (xx < par[7]) {
33  f = par[3]*xx + ((par[2]-par[3])*par[5]+(par[1]-par[2])*par[4]+par[0]);
34  }
35  else {
36  f = par[6]*xx + ((par[3]-par[6])*par[7]+(par[2]-par[3])*par[5]+(par[1]-par[2])*par[4]+par[0]);
37  }
38  return f;
39 }
40 
41 void myfunc(){
42 
43  TF1 *f1 = new TF1("myfunc",customFunc,40,2000,8);
44  f1->SetParameters(0.1491,0.1951,0.2022,0.2067,3.42,5.2,0.2196,10.9);
45  f1->SetParNames("Intercept","Slope1","Slope2","Slope3","X1Point","X2Point","Slope4","X3Point");
46  //f1->Draw();
47 
48 }
49 
50 
51 void MuonFit4sp()
52 {
53  std::cout<<"Hiya!"<<std::endl;
54 
55  TFile* file = new TFile("./muonProfile.root","READ");
56 
57  TGraphAsymmErrors* CustomProfile = file->Get("1");
58 
59  gStyle->SetOptStat(00000);
60  CustomProfile->SetMarkerStyle(6);
61 
62  myfunc();
63  TF1 *f1=gROOT->GetFunction("myfunc");
64 
65  CustomProfile->Draw("AP");
66  CustomProfile->Fit("myfunc","EX0","",0.40,20); //EX means ignores error bars in x
67 
68  std::cout<<"I hope this gives me the right values, then #chi^{2} / ndf = "<<f1->GetChisquare()<<" / "<<f1->GetNDF()<<std::endl;
69 
70 }
71 
72 
73 
Double_t customFunc(Double_t *x, Double_t *par)
Definition: MuonFit4sp.C:8
Double_t xx
Definition: macro.C:12
Int_t par
Definition: SimpleIterate.C:24
void myfunc()
Definition: MuonFit4sp.C:41
void MuonFit4sp()
Definition: MuonFit4sp.C:51
Float_t f1
OStream cout
Definition: OStream.cxx:6
TFile * file
Definition: cellShifts.C:17