ROOTPWA
accumKinePlots.C
Go to the documentation of this file.
1 #include "TTree.h"
2 #include "TFile.h"
3 #include "TList.h"
4 #include "TLatex.h"
5 #include "TPaveText.h"
6 #include "TLorentzVector.h"
7 #include "TVector3.h"
8 #include "TLorentzRotation.h"
9 #include "TH1D.h"
10 #include "TH2D.h"
11 #include "TGraphErrors.h"
12 #include "TClonesArray.h"
13 #include "TROOT.h"
14 #include "TMath.h"
15 #include "TPad.h"
16 #include "TColor.h"
17 #include "TStyle.h"
18 #include "TGaxis.h"
19 #include "TCanvas.h"
20 #include "TString.h"
21 #include <iostream>
22 #include <vector>
23 
24 using namespace std;
25 
26 #define MCOLOR kOrange-3
27 
28 TGraphErrors* buildGraph(vector<TH1D*> histo, unsigned int n){
29  unsigned int nbins=histo[0]->GetNbinsX();
30 
31  TGraphErrors* g=new TGraphErrors(nbins);
32  for(unsigned int ib=0;ib<nbins;++ib){
33  double x=histo[0]->GetBinCenter(ib+1);
34  double val=histo[0]->GetBinContent(ib+1);
35  double dx=histo[0]->GetBinWidth(ib+1)*0.5;
36  g->SetPoint(ib,x,val);
37  // calculate error by looping over all histos
38  double sigma=0;
39  for(unsigned int ih=0;ih<n;++ih){
40  double xi=val-histo[ih]->GetBinContent(ib+1);
41  sigma+=xi*xi;
42  }
43  sigma/=n;
44  double sigmastat=histo[0]->GetBinError(ib+1); // add error from event sampling
45  sigmastat*=sigmastat;
46  g->SetPointError(ib,dx,sqrt(sigma+sigmastat));
47  }
48 
49  return g;
50 
51 }
52 
53 
54 // routine to make a nice, accumulated plot
55 TCanvas* plotAccu(TString histoname, TString xtitle, vector<TString> bins, unsigned int nsamples,TFile* infile, TString plotdir){
56 
57  TString mcname=histoname+"MC";
58  TString dataname=histoname+"Data";
59  TString apsname=histoname+"APS";
60  TString range=bins[0](2,4)+"."+bins.back()(7,4);
61 
62 
63  // vector of samples
64  vector<TH1D*> mcplots(nsamples);
65  TH1D* dataplot;
66  TH1D* apsplot;
67 
68  // loop over bins
69  for(unsigned int ib=0;ib<bins.size();++ib){
70  // data object
71  TString name=dataname+bins[ib];
72  //cout << "Searching for " << name << endl;
73  TH1D* datahisto=(TH1D*)infile->Get(name);
74  name=apsname+bins[ib];
75  //cout << "Searching for " << name << endl;
76  TH1D* apshisto=(TH1D*)infile->Get(name);
77 
78  if(datahisto==NULL || apshisto==NULL){
79 
80 
81  return NULL;
82  }
83  if(ib==0){ // create clone, rename and acccumulate into this
84  TString accname=dataname+range;
85  dataplot=(TH1D*)datahisto->Clone(accname);
86  TString accuapsname=apsname+range;
87  apsplot=(TH1D*)apshisto->Clone(accuapsname);
88  }
89  else {
90  dataplot->Add(datahisto);
91  apsplot->Add(apshisto);
92  }
93 
94  // loop over mc samples
95  for(unsigned int is=0;is<nsamples;++is){
96  // data object
97  TString name=mcname+bins[ib]+"_";name+=is;
98  //cout << "Searching for " << name << endl;
99  TH1D* mchisto=(TH1D*)infile->Get(name);
100  if(mchisto==NULL)return 0;
101  if(ib==0){ // create clone, rename and acccumulate into this
102  TString accname=mcname+range+"_";accname+=is;
103  mcplots[is]=(TH1D*)mchisto->Clone(accname);
104  }
105  else {
106  mcplots[is]->Add(mchisto);
107  }
108  mcplots[is]->SetLineColor(kRed);
109  } // end loop over samples
110  }// end loop over bins
111 
112  TGraphErrors* g=buildGraph(mcplots,nsamples);
113  g->SetLineColor(MCOLOR);
114  g->SetFillColor(MCOLOR);
115  g->SetMarkerColor(MCOLOR);
116 
117  TCanvas* c=new TCanvas(histoname+range,histoname+range,10,10,700,700);
118  dataplot->Draw("E");
119  g->Draw("same p2");
120  //for(unsigned int is=0;is<nsamples;++is)mcplots[is]->Draw("same");
121  //g->Draw("p2");
122  dataplot->Draw("same E");
123  dataplot->GetYaxis()->SetRangeUser(0,dataplot->GetMaximum()*1.5);
124  dataplot->GetXaxis()->SetTitle(xtitle);
125 
126  double xcenter=0.5;
127  double ycenter=0.5;
128  // compass 2004
129  double xc=xcenter+0.05;
130  //if(right)xc=xcenter+0.1;
131  double yc=ycenter+0.35;
132  TLatex* com04=new TLatex(xc,yc,"COMPASS 2004");
133  com04->SetNDC();
134  com04->SetTextSize(0.05);
135  com04->Draw();
136 
137  // 5 pi on pb
138  xc=xcenter+0.05;
139  //xc=xcenter+0.1;
140  yc=ycenter+0.31;
141  TLatex* react=new TLatex(xc,yc,"#pi^{-} Pb #rightarrow #pi^{-}#pi^{+}#pi^{-}#pi^{+}#pi^{-} Pb");
142  react->SetNDC();
143  react->SetTextSize(0.039);
144  react->Draw();
145  yc=ycenter+0.27;
146  TLatex* dat=new TLatex(xc,yc,"Data vs");
147  dat->SetNDC();
148  dat->SetTextSize(0.039);
149  dat->Draw();
150  //yc=ycenter+0.23;
151  //TLatex* mc=new TLatex(xc+0.115,yc,"weighted MC");
152  //mc->SetNDC();
153  //mc->SetTextSize(0.039);
154  //mc->SetTextColor(MCOLOR);
155  //mc->Draw();
156  TPaveText* mc= new TPaveText(xc+0.114,yc-0.009,xc+0.325,yc+0.031,"NDC");
157  //mc->SetX1NDC(xc+0.112);mc->SetX2NDC(xc+0.48);mc->SetY1NDC(yc);mc->SetY2NDC(yc+0.04);
158  mc->SetBorderSize(0);
159  mc->SetTextSize(0.039);
160  //mc->SetTextAlign(1);
161  mc->SetFillColor(MCOLOR);
162  mc->AddText("weighted MC");
163  mc->Draw();
164 
165  yc=ycenter+0.23;
166  TString rangelable("m_{5#pi} #in [");rangelable+=range;rangelable+="] MeV/c^{2}";rangelable.ReplaceAll(".",",");
167  TLatex* bin=new TLatex(xc,yc,rangelable);
168  bin->SetNDC();
169  bin->SetTextSize(0.032);
170  bin->Draw();
171 
172  range.ReplaceAll(".","_");
173  c->SaveAs(plotdir+histoname+range+".eps");
174 
175  TCanvas* c2=new TCanvas(apsname+range,apsname+range,10,10,700,700);
176  apsplot->Draw();
177  apsplot->SetFillColor(MCOLOR);
178  apsplot->GetYaxis()->SetRangeUser(0,apsplot->GetMaximum()*1.5);
179  apsplot->GetXaxis()->SetTitle(xtitle);
180  com04->Draw();
181  react->Draw();
182  yc=ycenter+0.27;
183  TLatex* dat2=new TLatex(xc,yc,"accepted phase-space MC");
184  dat2->SetNDC();
185  dat2->SetTextSize(0.034);
186  dat2->Draw();
187  yc=ycenter+0.23;
188  bin->Draw();
189  c2->SaveAs(plotdir+apsname+range+".eps");
190 
191  return c;
192 }
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 void accumKinePlots(TString plotsfile, TString outdir){
203 
204  TFile* infile=TFile::Open(plotsfile.Data(),"READ");
205  Int_t font=132;
206  gStyle->SetTextFont(font);
207  gStyle->SetLabelFont(font,"xy");
208  gStyle->SetTitleFont(font,"xy");
209  gStyle->SetOptStat(0);
210  gStyle->SetOptTitle(0);
211  gStyle->SetStripDecimals(1);
212  TGaxis::SetMaxDigits(4);
213  gStyle->SetFrameFillStyle(0);
214  gStyle->SetFrameBorderMode(0);
215 
216  gROOT->ForceStyle();
217 
218  // setup binning
219  unsigned int nbins=7;
220  vector<vector<TString> > bins(nbins);
221  int dm=60; int mstart=1360;
222  unsigned int nacc=4;
223  int mass=mstart;
224  for(unsigned int ib=0;ib<nbins;++ib){
225  cout << "Bin " << ib << " : " << endl;
226  for(unsigned int ia=0;ia<nacc;++ia){
227  TString masslabel("_m");
228  masslabel+=mass;masslabel+=".";masslabel+=(mass+dm);
229  bins[ib].push_back(masslabel);
230  cout << masslabel << endl;
231  mass+=dm;
232  }
233  }
234 
235  for(unsigned int bin=0;bin<nbins;++bin){
236  plotAccu("hMIsobar","invariant mass of #pi^{-}#pi^{+}#pi^{-}#pi^{+} system (GeV/c^{2})", bins[bin],100,infile,outdir);
237  plotAccu("hMIsobar2","invariant mass of #pi^{-}#pi^{+}#pi^{-} system (GeV/c^{2})", bins[bin],100,infile,outdir);
238  plotAccu("hMIsobar3","invariant mass of #pi^{-}#pi^{+} system (GeV/c^{2})", bins[bin],100,infile,outdir);
239 
240  plotAccu("hGJ","cos #theta_{GJ}(#pi^{-}#pi^{+}#pi^{-}#pi^{+})", bins[bin],100,infile,outdir);
241  plotAccu("hTY","#phi_{TY}(#pi^{-}#pi^{+}#pi^{-}#pi^{+})", bins[bin],100,infile,outdir);
242 
243  plotAccu("hGJ2","cos #theta_{GJ}(#pi^{+}#pi^{-}#pi^{-})" ,bins[bin],100,infile,outdir);
244  plotAccu("hHe22Th","cos #theta_{Hel}(#pi^{-}#pi^{+})(#pi^{-}#pi^{+})" ,bins[bin],100,infile,outdir);
245  plotAccu("hHe21Th","cos #theta_{Hel}(#pi^{-}#pi^{+})(#pi^{-})" ,bins[bin],100,infile,outdir);
246  plotAccu("hHe31Th","cos #theta_{Hel}(#pi^{-}#pi^{+}#pi^{-})(#pi^{+})" ,bins[bin],100,infile,outdir);
247  plotAccu("hHe22Phi","#phi_{Hel}(#pi^{-}#pi^{+})(#pi^{-}#pi^{+})" ,bins[bin],100,infile,outdir);
248  plotAccu("hHe21Phi","#phi_{Hel}(#pi^{-}#pi^{+})(#pi^{-})" ,bins[bin],100,infile,outdir);
249  plotAccu("hHe31Phi","#phi_{Hel}(#pi^{-}#pi^{+}#pi^{-})(#pi^{+})" ,bins[bin],100,infile,outdir);
250  //break;
251  }
252 
253 }
254