FairRoot/PandaRoot
Functions | Variables
gethistos.C File Reference

Go to the source code of this file.

Functions

int gethistos ()
 
 plotandfithistosfromfile (TString filename="histos.root", TString ext=".pdf", Int_t divx=3, Int_t divy=3, Int_t pix=1200)
 
void GaussFitPlot (TH1 *his)
 

Variables

int ccc =0
 

Function Documentation

void GaussFitPlot ( TH1 *  his)

Definition at line 129 of file gethistos.C.

References ccc, Double_t, DrawText(), mean, par, range, sigma, and TString.

Referenced by plotandfithistosfromfile().

129  {
130  Double_t par[3]={0.,0.,0.};
131  Double_t range=250.;
132  TString fitname="mygaus";fitname+=ccc;
133  TF1* fitted = new TF1(fitname.Data(),"gaus",-range,range);
134  //fitted->SetParameters(par);
135  cout<<" --- Fitting Gaussian to histogram "<<his->GetName()<<" \""<<his->GetTitle()<<"\" ---"<<endl;
136  fitted->SetLineColor(4);
137  fitted->SetLineWidth(3);
138  fitted->SetLineStyle(2);
139  his->Fit(fitted,"","",-range,range);
140  fitted->GetParameters(par);
141  his->DrawCopy("");
142  Double_t mean = par[1];
143  Double_t sigma = par[2];
144  TString str="Gaussian Fit:";
145  DrawText( 0.18, 0.75, str.Data(),0.07,1);
146  str=Form("#mu = %.3g #mum",mean);
147  DrawText( 0.18, 0.65, str.Data(),0.07,1);
148  str=Form("#sigma = %.3g #mum",sigma);
149  DrawText( 0.18, 0.55, str.Data(),0.07,1);
150  ccc++;
151  return;
152 }
bool DrawText(Double_t posX=0., Double_t posY=0., const char *text="", Double_t size=0.08, Int_t col=1)
Definition: style/Tools.C:49
double range[]
Definition: evaltrig.C:67
Double_t par[3]
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
Double_t
Double_t mean[nsteps]
Definition: dedx_bands.C:65
int ccc
Definition: gethistos.C:127
int gethistos ( )

Definition at line 1 of file gethistos.C.

References i, LoadPandaStyle(), and plotandfithistosfromfile().

2 {
3  gROOT->LoadMacro("$VMCWORKDIR/macro/run/Tools.C");
5  //swotch things off
6  gStyle->SetOptTitle(1);
7  gStyle->SetOptStat(0);
8  gStyle->SetOptFit(0);
9  // use bigger font for many plots on a page
10  gStyle->SetTextSize(0.10);
11  gStyle->SetLabelSize(0.07,"x");
12  gStyle->SetTitleSize(0.07,"x");
13  gStyle->SetLabelSize(0.07,"y");
14  gStyle->SetTitleSize(0.07,"y");
15  gStyle->SetLabelSize(0.07,"z");
16  gStyle->SetTitleSize(0.07,"z");
17  gStyle->SetPadBottomMargin(0.17);
18 
19  TFile *canvasfile = new TFile("Residuals.root","READ");
20 
21  TCanvas *canne = (TCanvas*)canvasfile->Get("VtxPlots;1");
22  TList *canlist = canne->GetListOfPrimitives();
23 
24  TList *histolisto = new TList();
25 
26  if (!canlist) {cout<<"List not there..."<<endl;return;}
27 
28  for(int i=0;i<canlist->GetEntries();i++)
29  {
30  TPad *apad = (TPad*)canlist->At(i);
31  if (!apad) continue;
32  TList *padlist = apad->GetListOfPrimitives();
33  if (!padlist) continue;
34 // for(int k=0;k<canlist->GetEntries();k++)
35 // {
36 // TObject *anob = (TObject*)padlist->At(k);
37 // if (!anob) continue;
38 // //cout<<anob->GetName()<<endl;
39 // }
40  TH1D *his = (TH1D*)padlist->At(1);
41  histolisto->Add(his);
42  }
43 
44  canvasfile->Close();
45  TFile *histosfile = new TFile("Histos.root","RECREATE");
46  for(int j=0;j<histolisto->GetEntries();j++)
47  {
48  TH1D *his=(TH1D*)histolisto->At(j);
49  his->Write();
50  }
51  histosfile->Close();
52 
53  plotandfithistosfromfile("Histos.root",".pdf",3,3,900);
54  //plothistosfromfile("Histos.root",".pdf",3,5,250);
55  return 0;
56 }
Int_t i
Definition: run_full.C:25
plotandfithistosfromfile(TString filename="histos.root", TString ext=".pdf", Int_t divx=3, Int_t divy=3, Int_t pix=1200)
Definition: gethistos.C:62
LoadPandaStyle()
plotandfithistosfromfile ( TString  filename = "histos.root",
TString  ext = ".pdf",
Int_t  divx = 3,
Int_t  divy = 3,
Int_t  pix = 1200 
)

Definition at line 62 of file gethistos.C.

References ext, file, filename, GaussFitPlot(), i, and TString.

Referenced by gethistos().

63 { // Plot all histograms into a ps file
64  // works with TH1, TH2, & TProfile
65  TFile* file = new TFile(filename.Data());
66  if (!file) {cout<<"File \""<<filename.Data()<<"\" is not there..."<<endl;return;}
67  TCanvas* can = new TCanvas();
68  Int_t pixx = pix;
69  Int_t pixy = ceil(0.8*pix);
70  can->SetCanvasSize(pixx,pixy);
71  can->Divide(divx, divy);
72  TString picname = filename;
73  ext="-gfitsA4."+ext;
74  ext.ReplaceAll("..",".");
75  picname.ReplaceAll(".root",ext); // ps, png, pdf ...
76  TString pic = picname + "["; // open empty ps
77  cout << "opening: " << pic.Data()<<endl;
78  can->Print(pic);
79  pic=picname;
80 
81  TList* list = file->GetListOfKeys();
82  if (!list) {cout<<"List not there..."<<endl;return;}
83  int padcount = 1;
84  TString keyclass="";
85  for(int i=0;i<list->GetEntries();i++)
86  {
87  if(padcount > divx*divy)
88  {
89  can->Print(pic.Data());
90  can->Clear();
91  can->SetCanvasSize(pixx,pixy);
92  can->Divide(divx, divy);
93  padcount=1;
94  }
95  can->cd(padcount);
96  TKey* key = (TKey*)list->At(i);
97  keyclass = key->GetClassName();
98  //cout<<keyclass.Data()<<endl;
99  if(keyclass.Contains("TH1"))
100  {
101  //cout<<"try plotting a TH1"<<endl;
102  TH1* his = (TH1*)key->ReadObj();
103  TString titleO = his->GetTitle();
104  //TString titel ="#bar{D} ^{0}#rightarrow K^{0}#pi^{+}#pi^{-} Vertex Resolution - ";
105  TString titel ="Vertex Resolution - ";
106  if(titleO.Contains("Poca")) titel+="POCA";
107  else if(titleO.Contains("PRG")) titel+="PRG";
108  else if(titleO.Contains("Kin")) titel+="KINVTX";
109  his->SetTitle(titel.Data());
110  his->GetXaxis()->SetNoExponent(); // put exponents to numbers directly
111  his->GetYaxis()->SetNoExponent(); // put exponents to numbers directly
112  GaussFitPlot(his);
113  } else continue;
114 
115  padcount++;
116  }
117 
118  can->Print(pic.Data());
119  pic = picname + "]"; // close ps
120  can->Print(pic.Data());
121  cout << "closed: " << pic.Data()<<endl;
122  return;
123 }
Int_t i
Definition: run_full.C:25
TFile * file
void GaussFitPlot(TH1 *his)
Definition: gethistos.C:129
TNtuple * ext
Definition: reco_muo.C:24
const string filename

Variable Documentation

int ccc =0

Definition at line 127 of file gethistos.C.

Referenced by GaussFitPlot().