HadFit4sp.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,0,5,8);
44  //f1->SetParameters(0.0534636,0.631518,1.39952,1.73600,0.0593168,0.208919,2.19266,1.05000); //QE Values
45  //f1->SetParameters(0.232125,0.954274,1.28840,1.66420,0.10,0.3,1.90552,1.15544); //NonQE Values
46  f1->SetParameters(0.0534,0.956,2.14,1.78,0.0394,0.362,2.00,0.955); //CC Values
47  f1->SetParNames("Intercept","Slope1","Slope2","Slope3","X1Point","X2Point","Slope4","X3Point");
48 
49 }
50 
51 
52 void HadFit4sp()
53 {
54  std::cout<<"Hiya!"<<std::endl;
55 
56  TFile* file = new TFile("./hadronccProfile.root","READ"); //CC
57 
58  TGraphAsymmErrors* CustomProfile = file->Get("1");
59 
60  gStyle->SetOptStat(00000);
61  CustomProfile->SetMarkerStyle(6);
62 
63  myfunc();
64  TF1 *f1=gROOT->GetFunction("myfunc");
65 
66  CustomProfile->Draw("AP");
67  CustomProfile->Fit("myfunc","EX0","",0,2); //EX means ignores error bars in x
68 
69  std::cout<<"I hope this gives me the right values, then #chi^{2} / ndf = "<<f1->GetChisquare()<<" / "<<f1->GetNDF()<<std::endl;
70 
71 }
72 
73 
74 
Double_t xx
Definition: macro.C:12
Int_t par
Definition: SimpleIterate.C:24
Double_t customFunc(Double_t *x, Double_t *par)
Definition: HadFit4sp.C:8
void myfunc()
Definition: HadFit4sp.C:41
Float_t f1
OStream cout
Definition: OStream.cxx:6
TFile * file
Definition: cellShifts.C:17
void HadFit4sp()
Definition: HadFit4sp.C:52