StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
referenceVzCorr.C
1 #include <iostream>
2 #include "TMath.h"
3 #include "TRandom3.h"
4 #include "TCanvas.h"
5 #include "TPad.h"
6 #include "TF1.h"
7 #include "TH1D.h"
8 #include "TGraph.h"
9 #include "TAxis.h"
10 #include "TGraphErrors.h"
11 #include "TFile.h"
12 #include "TNtuple.h"
13 #include <numeric>
14 #include <sstream>
15 
16 int referenceVzCorr(){
17 
18  TFile *f0 = new TFile("referenceData.root");
19 
20  int numHists = 29;
21  double Vz[numHists];
22  double VzErr[numHists];
23  TH1F *hist[numHists];
24  TH1F *clonedhist[numHists];
25  double h[numHists];
26  double par0[numHists];
27  double par1[numHists];
28  double hErr[numHists];
29  double chi2perNDF[numHists];
30  double minbin = 320.0;
31  double maxbin = 450.0;
32 
33 
34  for(int i=0; i<numHists; i++){
35  hist[i] = (TH1F *)f0->Get(Form("hRefMultPWVtxZ_%d",i));
36  TF1 *f1 = new TF1("f1","([0]/10.0) * (TMath::Erf( -[1]*(x - [2]) ) + 1)", minbin, maxbin);
37  f1->SetParameter(0,1.0e4);
38  f1->SetParameter(1,0.027);
39  f1->SetParameter(2,maxbin-50.0);
40  TFitResultPtr r = hist[i]->Fit("f1","RLMS");
41  h[i] = r->Parameter(2);
42  par0[i] = r->Parameter(0);
43  par1[i] = r->Parameter(1);
44  hErr[i] = r->ParError(2);
45  Vz[i]=10.0*(i-14.0);
46  VzErr[i] = 5.0;
47  TF1 *fit = hist[i]->GetFunction("f1");
48  Double_t chi2 = fit->GetChisquare();
49  double numbins = maxbin-minbin+1.0;
50  cout<<"CHi2/ndf: "<<chi2<<"/"<<numbins<<endl;
51  chi2perNDF[i] = chi2/numbins;
52  delete f1;
53  }
54 
55  TCanvas *c_100 = new TCanvas("c_100","Canvas",1200,600);
56  c_100->Draw();
57  TPad* pad_100 = new TPad("pad_100","Pad",0.,0.,1.,1.);
58  pad_100->Divide(4,2);
59  pad_100->Draw();
60  TCanvas *c_200 = new TCanvas("c_200","Canvas",1200,600);
61  c_200->Draw();
62  TPad* pad_200 = new TPad("pad_200","Pad",0.,0.,1.,1.);
63  pad_200->Divide(4,2);
64  pad_200->Draw();
65  TCanvas *c_300 = new TCanvas("c_300","Canvas",1200,600);
66  c_300->Draw();
67  TPad* pad_300 = new TPad("pad_300","Pad",0.,0.,1.,1.);
68  pad_300->Divide(4,2);
69  pad_300->Draw();
70  TCanvas *c_400 = new TCanvas("c_400","Canvas",1200,600);
71  c_400->Draw();
72  TPad* pad_400 = new TPad("pad_400","Pad",0.,0.,1.,1.);
73  pad_400->Divide(4,2);
74  pad_400->Draw();
75 
76 
77  for(int i=0; i<numHists; i++){
78  hist[i] = (TH1F *)f0->Get(Form("hRefMultPWVtxZ_%d",i));
79  hist[i]->GetXaxis()->SetTitle("Reference Multiplicity");
80 
81  TF1 *f1 = new TF1("f1","([0]/10.0) * (TMath::Erf( -[1]*(x - [2]) ) + 1)",minbin,maxbin);
82  f1->SetParameter(0,par0[i]);
83  f1->SetParameter(1,par1[i]);
84  f1->SetParameter(2,h[i]);
85  f1->SetLineWidth(5);
86  if(i<8){
87  pad_100->cd(i+1);
88  pad_100->cd(i+1)->SetLogy();
89  hist[i]->GetXaxis()->SetRangeUser(0,500.0);
90  hist[i]->Draw("E");
91  f1->Draw("SAME");
92  }
93  else if(i<16){
94  pad_200->cd(i+1-8);
95  pad_200->cd(i+1-8)->SetLogy();
96  hist[i]->GetXaxis()->SetRangeUser(0,500.0);
97  hist[i]->Draw("E");
98  f1->Draw("SAME");
99  }
100  else if(i<24){
101  pad_300->cd(i+1-16);
102  pad_300->cd(i+1-16)->SetLogy();
103  hist[i]->GetXaxis()->SetRangeUser(0,500.0);
104  hist[i]->Draw("E");
105  f1->Draw("SAME");
106  }
107  else if(i<32){
108  pad_400->cd(i+1-24);
109  pad_400->cd(i+1-24)->SetLogy();
110  hist[i]->GetXaxis()->SetRangeUser(0,500.0);
111  hist[i]->Draw("E");
112  f1->Draw("SAME");
113  }
114  }
115 
116 
117  TCanvas *allRefMult = new TCanvas("allRefMult","allRefMult",800,600);
118  allRefMult->cd();
119  TLegend *legP = new TLegend(0.45,0.65,0.9,0.9,"","NDC");
120  legP->SetNColumns(3);
121  int j[6]={0,0,0,0,0,0};
122  bool secondrepeat = false;
123  for(int i=0; i<29;i++){
124  clonedhist[i] = (TH1F*) hist[i]->Clone();
125  if(clonedhist[i]->GetBinContent(10)==0)continue;
126  clonedhist[i]->Scale(1.0/clonedhist[i]->Integral(25,50));
127  if(j[5]==5){j[0]=-1;j[1]=-1;j[2]=-1;j[3]=-1;j[4]=-1;j[5]=-1;secondrepeat=true;}
128  if(secondrepeat){j[0]=-2;j[1]=-2;j[2]=-2;j[3]=-2;j[4]=-2;j[5]=-2;}
129  if(i%6==0){clonedhist[i]->SetLineColor(kRed+j[0]);j[0]++;}
130  if(i%6==1){clonedhist[i]->SetLineColor(kOrange+j[1]);j[1]++;}
131  if(i%6==2){clonedhist[i]->SetLineColor(kGreen+j[2]);j[2]++;}
132  if(i%6==3){clonedhist[i]->SetLineColor(kCyan+j[3]);j[3]++;}
133  if(i%6==4){clonedhist[i]->SetLineColor(kBlue+j[4]);j[4]++;}
134  if(i%6==5){clonedhist[i]->SetLineColor(kMagenta+j[5]);j[5]++;}
135  clonedhist[i]->SetStats(0);
136  if(i==0)clonedhist[i]->Draw("HIST");
137  else clonedhist[i]->Draw("SAME HIST");
138  TString name=Form("(%d,%d)cm",(int)(-145.0+10.*(i)),(int)(-145.0+10.*(i+1)));
139  legP->AddEntry(clonedhist[i],name,"l");
140  }
141  legP->Draw();
142 
143  auto c1 = new TCanvas("c1","c1");
144  TGraphErrors* g = new TGraphErrors(numHists, Vz, h, VzErr, hErr);
145  g->SetMarkerStyle(kFullCircle);
146  g->Draw("AP");
147 
148  TGraph* g_chi = new TGraph(numHists, Vz, chi2perNDF);
149  auto cchi = new TCanvas("cchi","cchi");
150  g_chi->SetMarkerStyle(kFullCircle);
151  g_chi->Draw("AP");
152 
153  double lowedges[numHists];
154  for(int i=0; i<numHists+1; i++){
155  lowedges[i]=-145.0+10.0*(i);
156  cout<<"Bin edges: "<<lowedges[i]<<endl;
157  }
158  TH1D* upperEdge = new TH1D("upperEdge","h as a function of Vz",numHists, lowedges);
159  for(int i=0; i<numHists; i++){
160  upperEdge->Fill(Vz[i],h[i]);
161  upperEdge->SetBinError(i+1,hErr[i]);
162  }
163 
164  auto c3 = new TCanvas("c3","c3");
165  TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*x*x*x*x*x+[6]*x*x*x*x*x*x",-145.0,145.0);
166 
167  cout<<"***************************** SIXTH-ORDER VZ CORRECTION ********************************"<<endl;
168  TFitResultPtr r2 = upperEdge->Fit("f2","RMS");
169  TF1 *Vzfit = upperEdge->GetFunction("f2");
170  Double_t Vzchi2 = Vzfit->GetChisquare();
171  cout<<"CHI2/NDF: "<<Vzchi2/(29.0-f2->GetNumberFreeParameters())<<endl;
172 
173  cout<<"****************************** POINTWISE VZ CORRECTION ******************************"<<endl;
174  cout<<"double vz_corr[29];"<<endl;
175  for(int corrnum=0; corrnum<29; corrnum++){
176  cout<<"vz_corr["<<corrnum<<"]="<<h[14]/h[corrnum]<<Form("; //Correction for Vz of (%d,%d)cm",(int)(-145.0+10.*(corrnum)),(int)(-145.0+10.*(corrnum+1)))<<endl;
177  }
178 
179  return 0;
180 }
virtual TObject * Clone(const char *newname="") const
the custom implementation fo the TObject::Clone
Definition: TDataSet.cxx:308