ROOTPWA
plotIsoFit.C
Go to the documentation of this file.
1 #include "TString.h"
2 #include "TCanvas.h"
3 #include <iostream>
4 #include <cstdlib>
5 #include <complex>
6 #include <vector>
7 #include <string>
8 
9 #include "TMatrixT.h"
10 
11 #include "TTree.h"
12 #include "TROOT.h"
13 #include "TStyle.h"
14 #include "TLatex.h"
15 #include "TGaxis.h"
16 #include "TAxis.h"
17 
18 #include "TGraphErrors.h"
19 #include "TFile.h"
20 #include "fitResult.h"
21 
22 using namespace std;
23 using namespace rpwa;
24 
25 void plotIsoFit(TString infilename, unsigned int bin=1) {
26  Int_t font=132;
27  gStyle->SetTextFont(font);
28  gStyle->SetLabelFont(font,"xy");
29  gStyle->SetTitleFont(font,"xy");
30  gStyle->SetOptStat(0);
31  gStyle->SetOptTitle(0);
32  gStyle->SetStripDecimals(1);
33  TGaxis::SetMaxDigits(4);
34  gStyle->SetFrameFillStyle(0);
35  gStyle->SetFrameBorderMode(0);
36 
37  gROOT->ForceStyle();
38 
39  // load fitResult tree
40  TFile* infile=TFile::Open(infilename,"READ");
41  if(infile==NULL){
42  cerr << "File " << infilename << " not found!"<< endl;
43  return;
44  }
45  TTree* pwa=(TTree*)infile->FindObjectAny("pwa");
46  if(pwa==NULL){
47  cerr << "Tree not found!"<< endl;
48  return;
49  }
50 
51  fitResult* res=0;//new fitResult();
52  string branchname("fitResult_v2");
53  if(pwa->FindBranch(branchname.c_str())==NULL){
54  cerr << "Invalid branch ."<<branchname<<endl;
55  throw;
56  }
57 
58 
59  unsigned int nbins=13;
60  TGraphErrors* gArgand=new TGraphErrors(0);//nbins);
61  TGraphErrors* gIntens=new TGraphErrors(0);//nbins);
62  TGraphErrors* gPhase=new TGraphErrors(0);//nbins);
63 
64  TGraph* gPS=new TGraph(nbins);
65 
66  vector<TString> labels(nbins);
67  vector<double> xlabels(nbins);
68  vector<double> ylabels(nbins);
69 
70 
71  pwa->SetBranchAddress(branchname.c_str(),&res);
72  cout << "Entries: " <<pwa->GetEntries() << endl;
73  pwa->GetEntry(bin);
74 
75  cout << "5pi Mass=" << res->massBinCenter() << endl;
76 
77  std::vector<std::string> names=res->prodAmpNames();
78  for(unsigned int i=0;i<names.size();++i)cout << names[i]<<endl;
79 
80  // now loop through know mass binning (hardcoded here)
81  // to collect isobar amplitude info
82  unsigned int waa=res->waveIndex("1-2-+0+pi-_02_f21270=pi-+_1_a11269=pi+-_0_rho770.amp");
83 
84  //unsigned int waa=res->waveIndex("1-1++0+pi-_11_f11285=pi-+_11_a11269=pi+-_0_rho770.amp");
85  typedef double tnum;
86  tnum m0=700;
87  tnum dm=100;
88  unsigned int i=0;
89  for(unsigned int c=0;c<nbins;++c){
90  tnum ml=m0+dm*c;
91  tnum mu=ml+dm;
92 
93  if(ml<1050)continue;
94 
95  //TString Wave("V0_1-1++0+pi-_11_f1");
96  //TString Wave("V0_1-2-+0+pi-_02_f2");
97  //TString Wave("V0_1-1++0+pi-_01_rho");
98  TString Wave("V0_1-1++0+pi-_01_eta1");
99  //TString Wave("V0_1-0-+0+pi-_00_f0");
100 
101  if(ml<1000)Wave.Append("0");
102  //itoa(ml,buf,4);
103  Wave+=(ml);
104  Wave.Append("t");
105  if(mu<1000)Wave.Append("0");
106  //itoa(mu,buf,4);
107  Wave+=(mu);
108  Wave.Append("=pi-+_01_a11269=pi+-_01_rho770.amp");
109  //Wave.Append("=rho770_01_sigma.amp");
110  //Wave.Append("=rho770_00_rho770.amp");
111  TString wav=Wave; wav.ReplaceAll("V0_","");
112 
113 
114  //cout << Wave << endl;
115 
116  // get amplitude
117  unsigned int wi1=res->prodAmpIndex(Wave.Data());
118  unsigned int wa1=res->waveIndex(wav.Data());
119  complex<double> amp=res->prodAmp(wi1);
120  double integral=res->phaseSpaceIntegral(wa1); // returns sqrt!
121  gPS->SetPoint(i,ml+0.5*dm,integral*integral);
122  if(amp.real()==0 && amp.imag()==0)continue;
123  TMatrixT<double> ampCov=res->prodAmpCov(wi1);
124  amp*=1./integral;
125  ampCov*=1./(integral*integral);
126 
127  //if(sqrt(ampCov[0][0])>amp.real() || sqrt(ampCov[1][1])>amp.imag())continue;
128 
129  gArgand->SetPoint(i,amp.real(),amp.imag());
130  gArgand->SetPointError(i,sqrt(ampCov[0][0]),sqrt(ampCov[1][1]));
131 
132  // build labels;
133  xlabels[i]=amp.real();
134  ylabels[i]=amp.imag();
135  labels[i]+=ml+0.5*dm;
136 
137  double intens=norm(amp); // res->intensity(wa1);
138  double intensE=res->intensityErr(wa1)/integral;
139  gIntens->SetPoint(i,ml+0.5*dm,intens);
140  gIntens->SetPointError(i,0.5*dm,intensE);
141 
142  double ph=180/TMath::Pi()*arg(amp);//res->phase(wi1,waa);
143  if(ph<0)ph+=360;
144  if(ph>300)ph-=360;
145  // error propagation:
146  double tn=amp.real()/amp.imag();
147  double dacot=-1./(1+tn*tn);
148  double dacotRe=dacot/amp.imag();
149  double dacotIm=dacot*amp.real();
150 
151  //ampCov.Print();
152 
153  //double dphi=sqrt(dacotRe*dacotRe*ampCov[0][0]+dacotIm*dacotIm*ampCov[1][1]+dacotRe*dacotIm*ampCov[0][1]+dacotRe*dacotIm*ampCov[1][0] );
154 
155 
156 
157  double pherr=res->phaseErr(wi1,waa);
158  // check if we should make a transformation by 2pi
159  // this is needed because of cyclical variable phi
160  if(i>10){
161  double mpre;
162  double phpre;
163  gPhase->GetPoint(i-1,mpre,phpre);
164  double diff1=fabs(ph-phpre);
165  double diff2=fabs(ph+360-phpre);
166  double diff3=fabs(ph-360-phpre);
167  if(diff2<diff1 && diff2<diff3)ph+=360;
168  else if(diff3<diff1 && diff3<diff2)ph-=360;
169  }
170 
171 
172 
173  gPhase->SetPoint(i,ml+0.5*dm,ph);
174  gPhase->SetPointError(i,dm*0.5,pherr);
175 
176  ++i;
177  }// end loop
178 
179  TCanvas* c= new TCanvas("c","c",10,10,1000,600);
180  c->Divide(3,1);
181  c->cd(1);
182  gIntens->Draw("APL");
183  gIntens->GetXaxis()->SetRangeUser(800,2000);
184  gIntens->GetXaxis()->SetTitle("4#pi mass (GeV/c^{2})");
185  gIntens->GetYaxis()->SetTitle("Intensity");
186  gIntens->GetYaxis()->SetTitleOffset(1.2);
187  //gPS->Draw("same");
188  c->cd(2);
189  gPhase->Draw("APL");
190  gPhase->GetXaxis()->SetRangeUser(800,2000);
191  gPhase->GetXaxis()->SetTitle("4#pi mass (GeV/c^{2})");
192  gPhase->GetYaxis()->SetTitle("Phase");
193  gPhase->GetYaxis()->SetTitleOffset(1.2);
194  c->cd(3);
195  gArgand->Draw("APL");
196  gArgand->GetXaxis()->SetTitle("Re");
197  gArgand->GetYaxis()->SetTitle("Im");
198  gArgand->GetYaxis()->SetTitleOffset(1.2);
199  // plot labels
200 
201  for(unsigned int j=0;j<nbins;++j){
202  cout << xlabels[j] << " "
203  << ylabels[j] << " " << labels[j].Data() << endl;
204  TLatex* lab=new TLatex(xlabels[j],ylabels[j],labels[j].Data());
205  //lab->SetNDC();
206  lab->Draw();
207  }
208 
209  infile->Close();
210 
211 }