FairRoot/PandaRoot
Functions | Variables
Poormantracks/drawhistosA4.C File Reference

Go to the source code of this file.

Functions

int drawhistosA4 (TString filename="Data/HistoVertexing.root")
 
 plotandfithistosfromfile (TString filename="histos.root", TString ext=".pdf", Int_t divx=2, Int_t divy=2, Int_t pix=1200)
 
void GaussFitPlot (TH1 *his)
 
void LineFitPlot (TH1 *his)
 

Variables

int ccc =0
 

Function Documentation

int drawhistosA4 ( TString  filename = "Data/HistoVertexing.root")

Definition at line 2 of file Poormantracks/drawhistosA4.C.

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

3 {
4  gROOT->LoadMacro("$VMCWORKDIR/macro/run/Tools.C");
6  //swotch things off
7  gStyle->SetOptTitle(1);
8  gStyle->SetOptStat(0);
9  gStyle->SetOptFit(0);
10 
11  // use bigger font for many plots on a page
12  gStyle->SetTextSize(0.10);
13  gStyle->SetLabelSize(0.07,"x");
14  gStyle->SetTitleSize(0.07,"x");
15  gStyle->SetLabelSize(0.07,"y");
16  gStyle->SetTitleSize(0.07,"y");
17  gStyle->SetLabelSize(0.07,"z");
18  gStyle->SetTitleSize(0.07,"z");
19  gStyle->SetPadBottomMargin(0.17);
20 
21  plotandfithistosfromfile(filename.Data(),"pdf",3,5,1200);
22 
23  return 0;
24 
25 }
plotandfithistosfromfile(TString filename="histos.root", TString ext=".pdf", Int_t divx=2, Int_t divy=2, Int_t pix=1200)
LoadPandaStyle()
const string filename
void GaussFitPlot ( TH1 *  his)

Definition at line 109 of file Poormantracks/drawhistosA4.C.

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

109  {
110  Double_t par[3]={0.,0.,0.};
111  TString fitname="mygaus";fitname+=ccc;
112  TF1* fitted = new TF1(fitname.Data(),"gaus",-5,5);
113  //fitted->SetParameters(par);
114  cout<<" --- Fitting Gaussian to histogram "<<his->GetName()<<" \""<<his->GetTitle()<<"\" ---"<<endl;
115  fitted->SetLineColor(4);
116  fitted->SetLineWidth(2);
117  fitted->SetLineStyle(2);
118  his->Fit(fitted);
119  fitted->GetParameters(par);
120  his->DrawCopy("");
121  Double_t mean = par[1];
122  Double_t sigma = par[2];
123  TString str="Gaussian Fit:";
124  DrawText( 0.2, 0.75, str.Data(),0.07,1);
125  str=Form("#mu = %.3g",mean);
126  DrawText( 0.2, 0.65, str.Data(),0.07,1);
127  str=Form("#sigma = %.3g",sigma);
128  DrawText( 0.2, 0.55, str.Data(),0.07,1);
129  ccc++;
130  return;
131 }
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_t par[3]
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
Double_t
Double_t mean[nsteps]
Definition: dedx_bands.C:65
void LineFitPlot ( TH1 *  his)

Definition at line 134 of file Poormantracks/drawhistosA4.C.

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

134  {
135  range=1.2*his->GetMaximum();
136  his->SetAxisRange(0.,range,"Y");
137  Double_t par[2]={0.,0.};
138  TString fitname="myline";fitname+=ccc;
139  TF1* fitted = new TF1(fitname.Data(),"pol1");
140  cout<<" --- Fitting Line to histogram "<<his->GetName()<<" \""<<his->GetTitle()<<"\" ---"<<endl;
141  fitted->SetLineColor(4);
142  fitted->SetLineWidth(2);
143  fitted->SetLineStyle(2);
144  his->Fit(fitted);
145  fitted->GetParameters(par);
146  his->DrawCopy("");
147  TString str="Line Fit:";
148  DrawText( 0.2, 0.425, str.Data(),0.07,1);
149  str=Form("const = %.3g",par[0]);
150  DrawText( 0.2, 0.325, str.Data(),0.07,1);
151  str=Form("slope = %.2g",par[1]);
152  DrawText( 0.2, 0.225, str.Data(),0.07,1);
153  ccc++;
154  return;
155 }
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
plotandfithistosfromfile ( TString  filename = "histos.root",
TString  ext = ".pdf",
Int_t  divx = 2,
Int_t  divy = 2,
Int_t  pix = 1200 
)

Definition at line 29 of file Poormantracks/drawhistosA4.C.

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

30 { // Plot all histograms into a ps file
31  // works with TH1, TH2, & TProfile
32  TFile* file = new TFile(filename.Data());
33  if (!file) {cout<<"File \""<<filename.Data()<<"\" is not there..."<<endl;return;}
34  TCanvas* can = new TCanvas();
35  Int_t pixx = pix;
36  Int_t pixy = ceil(1.2*pix);
37  can->SetCanvasSize(pixx,pixy);
38  can->Divide(divx, divy);
39  TString picname = filename;
40  ext="-gfitsA4."+ext;
41  ext.ReplaceAll("..",".");
42  picname.ReplaceAll(".root",ext); // ps, png, pdf ...
43  TString pic = picname + "["; // open empty ps
44  cout << "opening: " << pic.Data()<<endl;
45  can->Print(pic);
46  pic=picname;
47 
48  TList* list = file->GetListOfKeys();
49  if (!list) {cout<<"List not there..."<<endl;return;}
50  int padcount = 1;
51  TString keyclass="";
52  for(int i=0;i<list->GetEntries();i++)
53  {
54  if(padcount > divx*divy)
55  {
56  can->Print(pic.Data());
57  can->Clear();
58  can->SetCanvasSize(pixx,pixy);
59  can->Divide(divx, divy);
60  padcount=1;
61  }
62  can->cd(padcount);
63  TKey* key = (TKey*)list->At(i);
64  keyclass = key->GetClassName();
65  //cout<<keyclass.Data()<<endl;
66  if(keyclass.Contains("TH1"))
67  {
68  //cout<<"try plotting a TH1"<<endl;
69  TH1* his = (TH1*)key->ReadObj();
70  TString titel=his->GetTitle();
71  TString vorname = his->GetName();
72  if(titel.Contains("value")) continue; // skip this one
73  if(titel.Contains("#Theta")) continue; // skip this one
74  if(titel.Contains("#Phi")) continue; // skip this one
75  //if(titel.Contains("kin")) continue; // skip this one
76  //if(titel.Contains("pull")&&!titel.Contains("full")) continue; // skip this one
77  //if(titel.Contains("Pull")) continue; // skip this one
78  if(vorname.EndsWith("the")||vorname.EndsWith("phi"))continue;
79 
80  if(titel.Contains("Momentum reco")) his->SetTitle("Momentum Smearing");
81  his->GetXaxis()->SetNoExponent(); // put exponents to numbers directly
82  his->GetYaxis()->SetNoExponent(); // put exponents to numbers directly
83  if(titel.Contains("#chi")||titel.Contains("#Chi"))
84  {
85  LineFitPlot(his);
86  }
87  else {
88  GaussFitPlot(his);
89  }
90  } else continue;
91 
92  padcount++;
93  }
94 
95  can->Print(pic.Data());
96  pic = picname + "]"; // close ps
97  can->Print(pic.Data());
98  cout << "closed: " << pic.Data()<<endl;
99  TString convertcmd = "test -r ps2pdf && ps2pdf ";
100  convertcmd += pic.Data();
101  gSystem->Exec(convertcmd.Data());
102  return;
103 }
void LineFitPlot(TH1 *his)
Int_t i
Definition: run_full.C:25
TFile * file
void GaussFitPlot(TH1 *his)
TNtuple * ext
Definition: reco_muo.C:24
const string filename

Variable Documentation

int ccc =0

Definition at line 107 of file Poormantracks/drawhistosA4.C.