StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
doYieldError.C
1 void divideGraphWithFunction(TGraphErrors *graph,TF1 *func)
2 {
3  for(int i=0;i<graph->GetN();i++){
4  double x=0.;
5  double y=0.;
6  graph->GetPoint(i,x,y);
7  double ey=graph->GetErrorY(i);
8  graph->SetPoint(i,x,y/func->Eval(x));
9  graph->SetPointError(i,0.,ey/func->Eval(x));
10  }
11 }
12 void divideGraphs(TGraphErrors *g1,TGraphErrors *g2)
13 {
14  for(int i=0;i<g1->GetN();i++){
15  double x=0.;
16  double y=1.;
17  double ex=0.;
18  double ey=0;
19  double y2=1.;
20  double ey2=0.;
21  g1->GetPoint(i,x,y);
22  ey=g1->GetErrorY(i);
23  g2->GetPoint(i,x,y2);
24  ey2=0.;//take error into account once..
25 
26  double xn=x;
27  double exn=0.;
28  double yn=y/y2;
29  double eyn=(ey*ey/(y*y) + ey2*ey2/(y2*y2));
30  eyn=sqrt(eyn)*yn;
31  yn+=-1.;
32  g1->SetPoint(i,xn,yn);
33  g1->SetPointError(i,exn,eyn);
34  }
35 
36 }
37 void doYieldError(char *nom,char *left,char *right,char *mid)
38 {
39  TF1 *err_mb_hi=new TF1("err_mb_hi","0.035",1.,5.);
40  TF1 *err_mb_lo=new TF1("err_mb_hi","-0.035",1.,5.);
41  TF1 *err_ht_hi=new TF1("err_mb_hi","0.05",4.,15.);
42  TF1 *err_ht_lo=new TF1("err_mb_hi","-0.05",4.,15.);
43 
44  bool isPP05=false;
45  TPad *p_c;
46  int i_mb=0;
47  int i_ht1=1;
48  int i_ht2=2;
49 
50  TFile *f_nom=new TFile(nom,"OPEN");
51  TCanvas *c_nom=f_nom->Get("compare");
52  c_nom->Draw();
53  if(isPP05){
54  i_mb=3;
55  i_ht1=4;
56  i_ht2=5;
57  p_c=(TPad*)gPad->FindObject("padt");
58  p_c->cd();
59  }
60  TMultiGraph *m_nom=gPad->FindObject("m_pions")->Clone();
61  TGraphErrors *mb_nom=m_nom->GetListOfGraphs()->At(i_mb)->Clone();
62  mb_nom->SetName("mb_nom");
63  TGraphErrors *ht1_nom=m_nom->GetListOfGraphs()->At(i_ht1)->Clone();
64  ht1_nom->SetName("ht1_nom");
65  TGraphErrors *ht2_nom=m_nom->GetListOfGraphs()->At(i_ht2)->Clone();
66  ht2_nom->SetName("ht2_nom");
67  delete c_nom;
68  delete m_nom;
69 
70 
71  TFile *f_left=new TFile(left,"OPEN");
72  TCanvas *c_left=f_left->Get("compare");
73  c_left->Draw();
74  if(isPP05){
75  p_c=(TPad*)gPad->FindObject("padt");
76  p_c->cd();
77  }
78  TMultiGraph *m_left=gPad->FindObject("m_pions")->Clone();
79  TGraphErrors *mb_left=m_left->GetListOfGraphs()->At(i_mb)->Clone();
80  mb_left->SetName("mb_left");
81  TGraphErrors *ht1_left=m_left->GetListOfGraphs()->At(i_ht1)->Clone();
82  ht1_left->SetName("ht1_left");
83  TGraphErrors *ht2_left=m_left->GetListOfGraphs()->At(i_ht2)->Clone();
84  ht2_left->SetName("ht2_left");
85  delete c_left;
86  delete m_left;
87 
88 
89  TFile *f_right=new TFile(right,"OPEN");
90  TCanvas *c_right=f_right->Get("compare");
91  c_right->Draw();
92  if(isPP05){
93  p_c=(TPad*)gPad->FindObject("padt");
94  p_c->cd();
95  }
96  TMultiGraph *m_right=gPad->FindObject("m_pions")->Clone();
97  TGraphErrors *mb_right=m_right->GetListOfGraphs()->At(i_mb)->Clone();
98  mb_right->SetName("mb_right");
99  TGraphErrors *ht1_right=m_right->GetListOfGraphs()->At(i_ht1)->Clone();
100  ht1_right->SetName("ht1_right");
101  TGraphErrors *ht2_right=m_right->GetListOfGraphs()->At(i_ht2)->Clone();
102  ht2_right->SetName("ht2_right");
103  delete c_right;
104  delete m_right;
105 
106 
107  TFile *f_mid=new TFile(mid,"OPEN");
108  TCanvas *c_mid=f_mid->Get("compare");
109  c_mid->Draw();
110  if(isPP05){
111  p_c=(TPad*)gPad->FindObject("padt");
112  p_c->cd();
113  }
114  TMultiGraph *m_mid=gPad->FindObject("m_pions")->Clone();
115  TGraphErrors *mb_mid=m_mid->GetListOfGraphs()->At(i_mb)->Clone();
116  mb_mid->SetName("mb_mid");
117  TGraphErrors *ht1_mid=m_mid->GetListOfGraphs()->At(i_ht1)->Clone();
118  ht1_mid->SetName("ht1_mid");
119  TGraphErrors *ht2_mid=m_mid->GetListOfGraphs()->At(i_ht2)->Clone();
120  ht2_mid->SetName("ht2_mid");
121  delete c_mid;
122  delete m_mid;
123  f_mid->Close();
124 
125 
126  divideGraphs(mb_left,mb_nom);
127  divideGraphs(ht1_left,ht1_nom);
128  divideGraphs(ht2_left,ht2_nom);
129 
130  divideGraphs(mb_right,mb_nom);
131  divideGraphs(ht1_right,ht1_nom);
132  divideGraphs(ht2_right,ht2_nom);
133 
134  divideGraphs(mb_mid,mb_nom);
135  divideGraphs(ht1_mid,ht1_nom);
136  divideGraphs(ht2_mid,ht2_nom);
137 
138  divideGraphs(mb_nom,mb_nom);
139  divideGraphs(ht1_nom,ht1_nom);
140  divideGraphs(ht2_nom,ht2_nom);
141 
142 
143  TCanvas *c=new TCanvas("c","c",400,300);
144  TMultiGraph *m=new TMultiGraph();
145 
146  //m->Add(mb_nom);
147  //m->Add(ht1_nom);
148  //m->Add(ht2_nom);
149  m->Add(mb_left);
150  m->Add(ht1_left);
151  m->Add(ht2_left);
152  m->Add(mb_right);
153  m->Add(ht1_right);
154  m->Add(ht2_right);
155  m->Add(mb_mid);
156  m->Add(ht1_mid);
157  m->Add(ht2_mid);
158 
159  m->SetMinimum(-0.5);
160  m->SetMaximum(0.5);
161 
162 
163  TLegend *leg=new TLegend(0.5,0.5,0.7,0.7);
164  //leg->AddEntry(mb_nom,"nominal","p");
165  leg->AddEntry(mb_left,"{-3#sigma,2#sigma}","p");
166  leg->AddEntry(mb_right,"{-2#sigma,3#sigma}","p");
167  leg->AddEntry(mb_mid,"{-2#sigma,2#sigma}","p");
168 
169  m->Draw("ape");
170  err_mb_hi->Draw("same");
171  err_mb_lo->Draw("same");
172  err_ht_hi->Draw("same");
173  err_ht_lo->Draw("same");
174 
175  leg->Draw();
176 
177  if(isPP05){
178  c->SaveAs("error_yield_pp.eps");
179  c->SaveAs("error_yield_pp.root");
180  }
181  else{
182  c->SaveAs("error_yield_dau.eps");
183  c->SaveAs("error_yield_dau.root");
184  }
185 }