HadFitCC4sp.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 //To run the fitting stuff, do:
9 //root [0] .L TestFit.C
10 //root [1] myfunc();
11 //root [3] TestFit();
12 
13 Double_t susieFunc(Double_t *x, Double_t *par){
14 
15  Float_t xx = x[0];
16  Double_t f = 0.0;
17 
18  //Parameters:
19 
20  // par[0] = intercept
21  // par[1] = slope 1
22  // par[2] = slope 2
23  // par[3] = slope 3
24  // par[4] = stitch point 1
25  // par[5] = stitch point 2
26  // par[6] = slope 4
27  // par[7] = stitch point 3
28 
29  if (xx < par[4]){
30  f = par[1]*xx + par[0];
31  }
32 
33  else if (xx < par[5]) {
34  f = par[2]*xx + ((par[1]-par[2])*par[4]+par[0]);
35  }
36 
37  else if (xx < par[7]){
38  f = par[3]*xx + ((par[2]-par[3])*par[5]+(par[1]-par[2])*par[4]+par[0]);
39  }
40  else {
41  f = par[6]*xx + ((par[3]-par[6])*par[7]+(par[2]-par[3])*par[5]+(par[1]-par[2])*par[4]+par[0]);
42  }
43  return f;
44 }
45 
46 void myfunc(){
47 
48  TF1 *f1 = new TF1("myfunc",susieFunc,0,5,8);
49  f1->SetParameters(0.05,0.8,1.4,1.7,0.08,0.2,1.9,1.0); //QE Values
50  //f1->SetParameters(0.22,0.9,1.0,1.7,0.10,0.25,1.9,1.1); //NonQE Values
51  f1->SetParNames("Intercept","Slope1","Slope2","Slope3","X1Point","X2Point","Slope4","X3Point");
52  f1->Draw();
53 
54 }
55 
56 
58 {
59  std::cout<<"Hiya!"<<std::endl;
60 
61  // TFile* file = new TFile("./hadronqeProfile.root","READ"); //QE
62  TFile* file = new TFile("./hadronccProfile.root","READ"); // non-QE
63 
64  TGraphAsymmErrors* SusieProfile = file->Get("1");
65 
66  gStyle->SetOptStat(00000);
67  SusieProfile->SetMarkerStyle(6);
68 
69  TF1 *f1=gROOT->GetFunction("myfunc");
70  // f1->SetParameters(0.05,0.8,1.4,1.7,0.08,0.2,1.9,1.0); //QE Values
71  f1->SetParameters(0.25,0.9,1.0,1.55,0.10,0.25,2.35,1.25); //NonQE Values
72  f1->SetParLimits(0,0,1);
73  f1->SetParLimits(1,0.5,5);
74  f1->SetParLimits(2,0.5,5);
75  f1->SetParLimits(3,0.5,5);
76  f1->SetParLimits(4,0,2);
77  f1->SetParLimits(5,0,2);
78  f1->SetParLimits(6,0.5,5);
79  f1->SetParLimits(7,0,2);
80 
81  SusieProfile->Draw("AP");
82  SusieProfile->Fit("myfunc","EX0","",0,2); //EX means ignores error bars in x
83 
84  std::cout<<"I hope this gives me the right values, then #chi^{2} / ndf = "<<f1->GetChisquare()<<" / "<<f1->GetNDF()<<std::endl;
85 
86 }
87 
88 
Double_t xx
Definition: macro.C:12
void HadFitCC4sp()
Definition: HadFitCC4sp.C:57
Int_t par
Definition: SimpleIterate.C:24
void myfunc()
Definition: HadFitCC4sp.C:46
Float_t f1
OStream cout
Definition: OStream.cxx:6
TFile * file
Definition: cellShifts.C:17
Double_t susieFunc(Double_t *x, Double_t *par)
Definition: HadFitCC4sp.C:13