FairRoot/PandaRoot
Functions | Variables
tools/Tools.C File Reference

Go to the source code of this file.

Functions

bool DrawText (Double_t posX=0., Double_t posY=0., const char *text="", Double_t size=0.08, Int_t col=1)
 
bool DrawNice2DHisto (TH2 *h, const char *opt="", double range=10.)
 
bool set_nicer_2d_plot_style ()
 
bool BetterStatBox (TPad *pad)
 
bool ImproveDefaultStyle ()
 
bool LoadPandaStyle (bool)
 
TH1D TransformHisto (TH2 *h2, double min, double max)
 
bool plothistosfromfile (TString filename="histos.root", TString ext=".pdf", Int_t divx=2, Int_t divy=2, Int_t pix=300)
 
bool plotntuplefromfile (TString filename="ntps.root", TString ext=".pdf", Int_t divx=2, Int_t divy=2, Int_t pix=300)
 
bool LoadManySimFiles (TString treename="pndsim")
 
TString InitDefaultRun (TString filetag)
 
bool DrawHistSecondScale (TH1 *hist, int color=kRed)
 
int PullFitPlot (TH1 *his)
 
int GaussFitPlot (TH1 *his)
 
int LineFitPlot (TH1 *his)
 
int Tools ()
 

Variables

Int_t gCanvasCounter =0
 

Function Documentation

bool BetterStatBox ( TPad *  pad)

Vorgehensweise:

  • Histogramme in ein TPad zeichnen (1. Histogramm: Draw(), ntes Histogramm: Draw("sames"))
  • die Update() Funktion vom Canvas aufrufen (die Statistikboxen werden erst erzeugt, wenn das Histogramm wirklich gezeichnet wird)
  • der Funktion das aktuelle TPad uebergeben (z.B.: TPad* p=(TPad*)gPad; BetterStatBox(p);)

Definition at line 100 of file tools/Tools.C.

References hist, i, name, obj, and TString.

100  {
108 
109  int entries = pad->GetListOfPrimitives()->GetEntries();
110  TString name = "";
111  TPaveStats *st;
112  int obj = 1;
113 
114  for(int i=0; i<entries; i++){
115  name = pad->GetListOfPrimitives()->At(i)->IsA()->GetName();
116  if( name.Contains("TH1") ){
117  TH1* hist = (TH1*)pad->GetListOfPrimitives()->At(i);
118  st = (TPaveStats*)hist->GetListOfFunctions()->FindObject("stats");
119  if(st){
120  st->SetOptStat(1);
121  st->SetX1NDC(0.80);
122  st->SetY1NDC(1-0.16*obj) ;
123  st->SetY2NDC( st->GetY1NDC()+0.15 ) ;
124  st->SetTextColor( hist->GetLineColor() );
125  st->SetLineColor( hist->GetLineColor() );
126  st->Draw("same");
127  obj++;
128  }
129  }
130  }
131  return true;
132 }
Int_t i
Definition: run_full.C:25
TString name
TH1F * hist
PndAnaPidSelector *& obj
bool DrawHistSecondScale ( TH1 *  hist,
int  color = kRed 
)

Definition at line 537 of file tools/Tools.C.

538 {
539  // scale hint1 to the pad coordinates
540  Float_t rightmax = 1.1*hist->GetMaximum();
541  Float_t scale = gPad->GetUymax()/rightmax;
542  hist->SetLineColor(color);
543  hist->Scale(scale);
544  hist->Draw("same");
545 
546  // draw an axis on the right side
547  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
548  gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"+L");
549  axis->SetLineColor(color);
550  axis->SetTextColor(color);
551  axis->Draw();
552  return true;
553 }
axis
Definition: PndRadMapPlane.h:9
TH1F * hist
bool DrawNice2DHisto ( TH2 *  h,
const char *  opt = "",
double  range = 10. 
)

Definition at line 63 of file tools/Tools.C.

References range, and TString.

Referenced by plothistosfromfile().

64 {
65  // Draw a 2D histo with the rainbow colors and the palette besides
66  TString options = "colz"; options += opt;
67  if(gPad->GetLogz() == 1 && h->GetMaximum()<range) h->SetAxisRange(0.,range,"Z");
68  else {
69  // we squeeze here to see better the mean value
70  //range = 10*h->Integral()/(h->GetNbinsX()/h->GetNbinsY());
71  cout << "range "<<range<<" max "<<h->GetMaximum()<<" min "<<h->GetMinimum()<<endl;
72  if( range < h->GetMaximum()) range = h->GetMaximum();
73  if(-range > h->GetMinimum()) range = -1*h->GetMinimum();
74  range *= 1.1; // zoom a bit out to see the max better
75  if(h->GetMinimum() < 0.) h->SetAxisRange(-range,range,"Z");
76  else h->SetAxisRange(0,range,"Z");
77  }
78  h->SetStats(kFALSE);
79  h->SetTitleOffset(0.8,"T");
80  gPad->SetRightMargin(0.15);
81  h->DrawCopy(options.Data());
82  return true;
83 }
double range[]
Definition: evaltrig.C:67
bool DrawText ( Double_t  posX = 0.,
Double_t  posY = 0.,
const char *  text = "",
Double_t  size = 0.08,
Int_t  col = 1 
)

Definition at line 45 of file tools/Tools.C.

References col.

Referenced by GaussFitPlot(), LineFitPlot(), and PullFitPlot().

50 {
51  // Drawing some TLatex text in a root canvas, overlaying the content
52 
53  TLatex* pText=new TLatex(posX,posY,text);
54  pText->SetNDC(kTRUE);
55  // pText->SetNDC(bNDC);
56  pText->SetTextColor(col); pText->SetTextSize(size);
57  // pText->SetTextAngle(angle);
58  // pText->SetTextFont(font); pText->SetTextAlign(align);
59  pText->Draw();
60  return true;
61 }
int col
Definition: anaLmdDigi.C:67
int GaussFitPlot ( TH1 *  his)

Definition at line 588 of file tools/Tools.C.

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

589 {
590  //his->SetName(Form("%s%i",his->GetName(),gCanvasCounter));
591  double range=1.1*his->GetMaximum();
592  his->SetAxisRange(0.,range,"Y");
593  Double_t par[3]={0.,0.,0.};
594  TString fitname="mygaus";fitname+=gCanvasCounter;
595  TF1* fitted = new TF1(fitname.Data(),"gaus",-5,5);
596  //fitted->SetParameters(par);
597  cout<<" --- Fitting Gaussian to histogram "<<his->GetName()<<" \""<<his->GetTitle()<<"\" ---"<<endl;
598  fitted->SetLineColor(4);
599  fitted->SetLineWidth(2);
600  fitted->SetLineStyle(2);
601  his->Fit(fitted);
602  fitted->GetParameters(par);
603  his->Draw("");
604  Double_t mean = par[1];
605  Double_t sigma = par[2];
606  TString str="Gaussian Fit:";
607  DrawText( 0.15, 0.8, str.Data(),0.06,1);
608  str=Form("#mu = %.3g",mean);
609  DrawText( 0.15, 0.73, str.Data(),0.06,1);
610  str=Form("#sigma = %.3g",sigma);
611  DrawText( 0.15, 0.66, str.Data(),0.06,1);
612  gCanvasCounter++;
613  return 0;
614 }
double range[]
Definition: evaltrig.C:67
Double_t par[3]
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
Double_t
Int_t gCanvasCounter
Definition: tools/Tools.C:43
bool DrawText(Double_t posX=0., Double_t posY=0., const char *text="", Double_t size=0.08, Int_t col=1)
Definition: tools/Tools.C:45
Double_t mean[nsteps]
Definition: dedx_bands.C:65
bool ImproveDefaultStyle ( )

Definition at line 147 of file tools/Tools.C.

148 {
149  gStyle->SetOptFit ( 1011 );
150  gStyle->SetPaperSize(20,26);
151  gStyle->SetPadTopMargin(0.14);
152  gStyle->SetPadRightMargin(0.05);
153  gStyle->SetPadBottomMargin(0.14);
154  gStyle->SetPadLeftMargin(0.14);
155  gStyle->SetTextFont(22);//changed to bold (R.K.)
156  gStyle->SetTextSize(0.08);
157  gStyle->SetLabelFont(22,"x");//changed to bold (R.K.)
158  gStyle->SetLabelFont(22,"y");//changed to bold (R.K.)
159  gStyle->SetLabelFont(22,"z");//changed to bold (R.K.)
160  gStyle->SetLabelSize(0.05,"x");
161  gStyle->SetTitleSize(0.06,"x");
162  gStyle->SetLabelSize(0.05,"y");
163  gStyle->SetTitleSize(0.06,"y");
164  gStyle->SetLabelSize(0.05,"z");
165  gStyle->SetTitleSize(0.06,"z");
166  // use bold lines and markers
167  gStyle->SetMarkerStyle(8);
168  gStyle->SetHistLineWidth(1);//1.85);
169  gStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
170 
171  // do not display any of the standard histogram decorations
172  gStyle->SetOptTitle(1);
173  gStyle->SetOptStat(1);
174  gStyle->SetOptFit(1);
175 
176  // put tick marks on top and RHS of plots
177  gStyle->SetPadTickX(1);
178  gStyle->SetPadTickY(1);
179 
180  //R.K. abool clumsy axis lables
181  gStyle->SetNdivisions(509); // default root value is 510
182 
183  return true;
184 }
TString InitDefaultRun ( TString  filetag)

Definition at line 498 of file tools/Tools.C.

References fRun, PndFileNameCreator::GetCustomFileName(), PndFileNameCreator::GetParFileName(), PndFileNameCreator::GetRecoFileName(), PndFileNameCreator::GetSimFileName(), namecreator, outFile, parFile, recoFile, rtdb, simFile, sysFile, and TString.

499 {
500  cout << "-I- Using InitDefaultRun() from macro/run/Tools.C with the sim file " << filetag.Data() << endl;
501  FairRunAna* fRun = new FairRunAna();
502  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
503 
504  filetag.ReplaceAll("_sim.root",".root");
505  PndFileNameCreator namecreator(filetag.Data());
509  TString tracksFile = namecreator.GetCustomFileName("tracks");
510  TString pidFile = namecreator.GetCustomFileName("pid");
511  TString histoFile = namecreator.GetCustomFileName("histos");
512  TString evrdummy = namecreator.GetCustomFileName("evrdummy");
513  std::cout<<"simFile="<<simFile.Data()<<std::endl;
514  std::cout<<"parFile="<<parFile.Data()<<std::endl;
515  std::cout<<"recoFile="<<recoFile.Data()<<std::endl;
516  std::cout<<"trkFile="<<tracksFile.Data()<<std::endl;
517  std::cout<<"pidFile="<<pidFile.Data()<<std::endl;
518  fRun->SetInputFile(simFile);
519  fRun->AddFriend(recoFile);//,"rec");
520  fRun->AddFriend(tracksFile);//,"trk");
521  fRun->AddFriend(pidFile);//,"pid");
522  FairParRootFileIo* parIO = new FairParRootFileIo();
523  parIO->open(parFile.Data());
524  rtdb->setFirstInput(parIO);
525  rtdb->setOutput(parIO);
526 
527  TString outFile = evrdummy;
528  TString sysFile = gSystem->Getenv("VMCWORKDIR");
529 
530  fRun->SetOutputFile(outFile.Data());
531  FairGeane* geane = new FairGeane();
532  fRun->AddTask(geane);
533  fRun->Init();
534  return histoFile;
535 }
std::string GetParFileName(std::string addon="", bool cut=false)
TString outFile
Definition: hit_dirc.C:17
std::string GetSimFileName(std::string addon="", bool cut=false)
FairRunAna * fRun
Definition: hit_dirc.C:58
TString simFile
Definition: bump_emc.C:11
std::string GetRecoFileName(std::string addon="", bool cut=false)
TString sysFile
A simple class which adds the corresponding file extensions to a given base class.
TString parFile
Definition: hit_dirc.C:14
std::string GetCustomFileName(std::string ext, std::string addon="", bool cut=false)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
PndFileNameCreator namecreator("../data/Lars/MvdDtsSim.root")
std::string recoFile
int LineFitPlot ( TH1 *  his)

Definition at line 616 of file tools/Tools.C.

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

617 {
618  //his->SetName(Form("%s%i",his->GetName(),gCanvasCounter));
619  double range=1.2*his->GetMaximum();
620  his->SetAxisRange(0.,range,"Y");
621  Double_t par[2]={0.,0.};
622  TString fitname="myline";fitname+=gCanvasCounter;
623  TF1* fitted = new TF1(fitname.Data(),"pol1",0.05,0.95);
624  cout<<" --- Fitting Line to histogram "<<his->GetName()<<" \""<<his->GetTitle()<<"\" ---"<<endl;
625  fitted->SetLineColor(4);
626  fitted->SetLineWidth(2);
627  fitted->SetLineStyle(2);
628  his->Fit(fitted,"R");
629  fitted->GetParameters(par);
630  his->Draw("");
631  TString str="Line Fit:";
632  DrawText( 0.2, 0.425, str.Data(),0.07,1);
633  str=Form("const = %.3g",par[0]);
634  DrawText( 0.2, 0.325, str.Data(),0.07,1);
635  str=Form("slope = %.2g",par[1]);
636  DrawText( 0.2, 0.225, str.Data(),0.07,1);
637  gCanvasCounter++;
638  return 0;
639 }
double range[]
Definition: evaltrig.C:67
Double_t par[3]
Double_t
Int_t gCanvasCounter
Definition: tools/Tools.C:43
bool DrawText(Double_t posX=0., Double_t posY=0., const char *text="", Double_t size=0.08, Int_t col=1)
Definition: tools/Tools.C:45
bool LoadManySimFiles ( TString  treename = "pndsim")

Definition at line 484 of file tools/Tools.C.

References fi, next, and R.

485 { // to use that method you should have opened some files
486  // containing the same tree structure, like splitted files of
487  // mass production simulations. (like "root -f data/sim01*.root"
488  // tree examination is available via TTree::Draw(...)
489 
490  TIter next(gROOT->GetListOfFiles());
491  TFile *fi=0;
492  TChain *R=new TChain(treename.Data());
493  while ( (fi=(TFile*)next()) ) R->Add(fi->GetName());
494  cout<<(Int_t)R->GetEntries()<<endl;
495  return true;
496 }
TFile * fi
static int next[96]
Definition: ranlxd.cxx:374
Double_t R
Definition: checkhelixhit.C:61
bool LoadPandaStyle ( bool  )

Definition at line 186 of file tools/Tools.C.

References set_nicer_2d_plot_style().

187 {
188 
189  //--------------------------------------------------------------------------
190  // File and Version Information:
191  // $Id: PBase.C,v 1.8 2006/09/22 12:04:13 kliemt Exp $
192  //
193  // Description:
194  // Initialization code executed at the start of a ROOT session.
195  // Set up the Panda style for approved plots.
196  //
197  // Environment:
198  // Software developed for the PANDA Detector at GSI, Darmstadt
199  //
200  // Author List:
201  // Sergey Ganzhur Original Author
202  // Ralf Kliemt (2008) Small adjustments for PandaRoot use
203  //
204  // Copyright Information:
205  // Copyright (C) 2001-2002 Ruhr Universitaet Bochum
206  //
207  //------------------------------------------------------------------------
208 
209  if( strcmp(gStyle->GetName(),"PANDA")==0 ) return true;
210  // use the 'plain' style for plots (white backgrounds, etc)
211  //cout << "...using style 'Plain'" << endl;
212  //gROOT->SetStyle("Plain");
213 
214  // Create the 'PANDA' style for approved plots. Note that this style may need
215  // some fine tuning in your macro depending on what you are plotting, e.g.
216  //
217  // gStyle->SetMarkerSize(0.75); // use smaller markers in a histogram with many bins
218  // gStyle->SetTitleOffset(0.65,"y"); // bring y axis label closer to narrow values
219 
220  // Ralf Kliemt:
221  // I changed a bit for myself here
222 
223  TStyle *pandaStyle= new TStyle("PANDA","PANDA approved plots style, modified by ralfk");
224 
225  // use plain black on white colors
226  pandaStyle->SetFrameBorderMode(0);
227  pandaStyle->SetCanvasBorderMode(0);
228  pandaStyle->SetPadBorderMode(0);
229  pandaStyle->SetPadColor(0);
230  pandaStyle->SetCanvasColor(0);
231  pandaStyle->SetTitleColor(1);
232  pandaStyle->SetStatColor(0);
233  // pandaStyle->SetFillColor(0);// conflict with 2D plots
234  // pandaStyle->SetPalette(1);
235  //R.K: Now remove the title box
236  //pandaStyle->SetTitleAlign(33);
237  pandaStyle->SetTitleBorderSize(0);
238  pandaStyle->SetTitleColor(1);
239  pandaStyle->SetTitleFillColor(0);
240  pandaStyle->SetTitleFontSize(0.07);
241 
242  // set the paper & margin sizes
243  pandaStyle->SetPaperSize(20,26);
244  pandaStyle->SetPadTopMargin(0.14);
245  pandaStyle->SetPadRightMargin(0.05);
246  pandaStyle->SetPadBottomMargin(0.14);
247  pandaStyle->SetPadLeftMargin(0.14);
248 // pandaStyle->SetPaperSize(20,26);
249 // pandaStyle->SetPadTopMargin(0.05);
250 // pandaStyle->SetPadRightMargin(0.05);
251 // pandaStyle->SetPadBottomMargin(0.16);
252 // pandaStyle->SetPadLeftMargin(0.12);
253 
254  // use large Times-Roman fonts
255  // pandaStyle->SetTextFont(132);
256  // pandaStyle->SetLabelFont(132,"x");
257  // pandaStyle->SetLabelFont(132,"y");
258  // pandaStyle->SetLabelFont(132,"z");
259  pandaStyle->SetTextFont(22);//changed to bold (R.K.)
260  pandaStyle->SetTextSize(0.08);
261  pandaStyle->SetLabelFont(22,"x");//changed to bold (R.K.)
262  pandaStyle->SetLabelFont(22,"y");//changed to bold (R.K.)
263  pandaStyle->SetLabelFont(22,"z");//changed to bold (R.K.)
264  pandaStyle->SetLabelSize(0.05,"x");
265  pandaStyle->SetTitleSize(0.06,"x");
266  pandaStyle->SetLabelSize(0.05,"y");
267  pandaStyle->SetTitleSize(0.06,"y");
268  pandaStyle->SetLabelSize(0.05,"z");
269  pandaStyle->SetTitleSize(0.06,"z");
270 
271  // use bold lines and markers
272  pandaStyle->SetMarkerStyle(8);
273  pandaStyle->SetHistLineWidth(1);//2
274  pandaStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
275 
276  // do not display any of the standard histogram decorations
277  pandaStyle->SetOptTitle(1);
278  pandaStyle->SetOptStat(1);
279  pandaStyle->SetOptFit(1);
280 
281  // put tick marks on top and RHS of plots
282  pandaStyle->SetPadTickX(1);
283  pandaStyle->SetPadTickY(1);
284 
285  //R.K. abool clumsy axis lables
286  pandaStyle->SetNdivisions(509); // default root value is 510
287 
288  //cout <<" For approved plots use: gROOT->SetStyle(\"PANDA\");"<< endl;
289 
290  pandaStyle->cd();
291  gROOT->ForceStyle();
292  set_nicer_2d_plot_style();//[R.K.] use nicer 2D plots
293  return true;
294 }//bool PBase::LoadPandaStyle(bool)
bool set_nicer_2d_plot_style()
Definition: tools/Tools.C:85
bool plothistosfromfile ( TString  filename = "histos.root",
TString  ext = ".pdf",
Int_t  divx = 2,
Int_t  divy = 2,
Int_t  pix = 300 
)

Definition at line 314 of file tools/Tools.C.

References DrawNice2DHisto(), ext, file, filename, i, set_nicer_2d_plot_style(), and TString.

315 { // Plot all histograms into a ps file
316  // works with TH1, TH2, & TProfile
317  //LoadPandaStyle();
319  TFile* file = new TFile(filename.Data());
320  if (!file) {cout<<"File \""<<filename.Data()<<"\" is not there..."<<endl;return true;}
321  TCanvas* can = new TCanvas();
322  Int_t pixx = ceil(1.4*pix*divx);
323  Int_t pixy = pix*divy;
324  can->SetCanvasSize(pixx,pixy);
325  can->Divide(divx, divy);
326  TString picname = filename;
327  ext="."+ext;
328  ext.ReplaceAll("..",".");
329  picname.ReplaceAll(".root",ext); // ps, png, pdf ...
330  TString pic = picname + "["; // open empty ps
331  cout << "opening: " << pic.Data()<<endl;
332  can->Print(pic);
333  pic=picname;
334 
335  TList* list = file->GetListOfKeys();
336  if (!list) {cout<<"List not there..."<<endl;return true;}
337  int padcount = 1;
338  TString keyclass="";
339  for(int i=0;i<list->GetEntries();i++)
340  {
341  if(padcount > divx*divy)
342  {
343  can->Print(pic.Data());
344  can->Clear();
345  can->SetCanvasSize(pixx,pixy);
346  can->Divide(divx, divy);
347  padcount=1;
348  }
349  can->cd(padcount);
350  TKey* key = (TKey*)list->At(i);
351  keyclass = key->GetClassName();
352  //cout<<keyclass.Data()<<endl;
353  if(keyclass.Contains("TH1"))
354  {
355  //cout<<"try plotting a TH1"<<endl;
356  TH1* his = (TH1*)key->ReadObj();
357  his->GetXaxis()->SetNoExponent(); // put exponents to numbers directly
358  his->GetYaxis()->SetNoExponent(); // put exponents to numbers directly
359  TString options(his->GetOption());
360  if(options.Contains("log")){
361  gPad->SetLogy();
362  options.ReplaceAll("log","");
363  his->SetOption(options.Data());
364  }
365  his->Draw();
366  }else if(keyclass.Contains("TH2"))
367  {
368  //cout<<"try plotting a TH2"<<endl;
369  TH2* his2 = (TH2*)key->ReadObj();
370  his2->GetXaxis()->SetNoExponent(); // put exponents to numbers directly
371  his2->GetYaxis()->SetNoExponent(); // put exponents to numbers directly
372  TString options(his2->GetOption());
373  if(options.Contains("log")){
374  gPad->SetLogz();
375  options.ReplaceAll("log","");
376  his2->SetOption(options.Data());
377  }
378  if(options.Contains("nice")){
379  options.ReplaceAll("nice","");
380  his2->SetOption(options.Data());
381  DrawNice2DHisto(his2);
382  } else {
383  his2->Draw("colz");
384  }
385  }else if(keyclass.Contains("TProfile"))
386  {
387  //cout<<"try plotting a TH2"<<endl;
388  TProfile* hpro = (TProfile*)key->ReadObj();
389  hpro->GetXaxis()->SetNoExponent(); // put exponents to numbers directly
390  hpro->GetYaxis()->SetNoExponent(); // put exponents to numbers directly
391  TString options(hpro->GetOption());
392  if(options.Contains("log")){
393  gPad->SetLogy();
394  options.ReplaceAll("log","");
395  hpro->SetOption(options.Data());
396  }
397  hpro->Draw();
398  } else continue;
399 
400  padcount++;
401  }
402 
403  can->Print(pic.Data());
404  pic = picname + "]"; // close ps
405  can->Print(pic.Data());
406  cout << "closed: " << pic.Data()<<endl;
407  //TString convertcmd = "test -r ps2pdf && ps2pdf ";
408  //convertcmd += pic.Data();
409  //gSystem->Exec(convertcmd.Data());
410  delete can;
411  return true;
412 }
Int_t i
Definition: run_full.C:25
TFile * file
bool DrawNice2DHisto(TH2 *h, const char *opt="", double range=10.)
Definition: tools/Tools.C:63
TNtuple * ext
Definition: reco_muo.C:24
bool set_nicer_2d_plot_style()
Definition: tools/Tools.C:85
const string filename
bool plotntuplefromfile ( TString  filename = "ntps.root",
TString  ext = ".pdf",
Int_t  divx = 2,
Int_t  divy = 2,
Int_t  pix = 300 
)

Definition at line 414 of file tools/Tools.C.

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

415 {
416  // Plot all columns of an NTuple into a pdf (or ps file)
417  TFile* file = new TFile(filename.Data());
418  if (!file) {cout<<"File \""<<filename.Data()<<"\" is not there..."<<endl;return true;}
419  TCanvas* can = new TCanvas();
420  Int_t pixx = ceil(1.4*pix*divx);
421  Int_t pixy = pix*divy;
422  can->SetCanvasSize(pixx,pixy);
423  can->Divide(divx, divy);
424  TString picname = filename;
425  ext="."+ext;
426  ext.ReplaceAll("..",".");
427  picname.ReplaceAll(".root",ext); // ps, png, pdf ...
428  TString pic = picname + "["; // open empty ps
429  cout << "opening: " << pic.Data()<<endl;
430  can->Print(pic);
431  pic=picname;
432 
433  TList* list = file->GetListOfKeys();
434  if (!list) {cout<<"List not there..."<<endl;return true;}
435  int padcount = 1;
436  TString keyclass="";
437  for(int i=0;i<list->GetEntries();i++)
438  {
439  TKey* key = (TKey*)list->At(i);
440  keyclass = key->GetClassName();
441  if(keyclass.CompareTo("TTree"))continue;
442  TTree* baum = (TTree*)key->ReadObj();
443  printf("\t - Tree: %s\n",baum->GetName());
444  TObjArray* aeste = baum->GetListOfBranches();
445  for(int asti=0;asti<aeste->GetEntriesFast();asti++)
446  {
447  TBranch* ast = (TBranch*)aeste->At(asti);
448  printf("\t\t - Branch: %s\n",ast->GetName());
449  TObjArray* bleatter = ast->GetListOfLeaves();
450  for(int blatti=0;blatti<bleatter->GetEntriesFast();blatti++)
451  {
452  TLeaf* blatt = (TLeaf*)bleatter->At(blatti);
453  TString blattsorte=blatt->GetTypeName();
454  if( !blattsorte.CompareTo("Float_t") || !blattsorte.CompareTo("Int_t") || !blattsorte.CompareTo("Double_t"))
455  {
456  if(padcount > divx*divy)
457  {
458  printf(" --- canvasdump ---");
459  can->Print(pic.Data());
460  can->Clear();
461  can->SetCanvasSize(pixx,pixy);
462  can->Divide(divx, divy);
463  padcount=1;
464  }
465  can->cd(padcount);
466  printf("\t\t\t - Leaf: %s (%s)\n",blatt->GetName(),blatt->GetTypeName());
467  baum->Draw(blatt->GetName());
468  padcount++;
469  }
470  }
471  }
472  }
473  can->Print(pic.Data());
474  pic = picname + "]"; // close ps
475  can->Print(pic.Data());
476  cout << "closed: " << pic.Data()<<endl;
477 // TString convertcmd = "test -r ps2pdf && ps2pdf ";
478 // convertcmd += pic.Data();
479 // gSystem->Exec(convertcmd.Data());
480  delete can;
481  return true;
482 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Int_t i
Definition: run_full.C:25
TFile * file
TNtuple * ext
Definition: reco_muo.C:24
const string filename
int PullFitPlot ( TH1 *  his)

Definition at line 555 of file tools/Tools.C.

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

556 {
557  //his->SetName(Form("%s%i",his->GetName(),gCanvasCounter));
558  double range=1.1*his->GetMaximum();
559  his->SetAxisRange(0.,range,"Y");
560  Double_t par[3]={0.,0.,0.};
561  TString fitname="mygaus";fitname+=gCanvasCounter;
562  TF1* fitted = new TF1(fitname.Data(),"gaus",-5,5);
563  //fitted->SetParameters(par);
564  cout<<" --- Fitting Gaussian to histogram "<<his->GetName()<<" \""<<his->GetTitle()<<"\" ---"<<endl;
565  fitted->SetLineColor(4);
566  fitted->SetLineWidth(2);
567  fitted->SetLineStyle(2);
568  his->Fit(fitted);
569  fitted->GetParameters(par);
570  his->Draw("");
571  Double_t mean = par[1];
572  Double_t sigma = par[2];
573  TString str="Gaussian Fit:";
574  DrawText( 0.15, 0.8, str.Data(),0.06,1);
575  str=Form("#mu = %.3g",mean);
576  DrawText( 0.15, 0.73, str.Data(),0.06,1);
577  str=Form("#sigma = %.3g",sigma);
578  DrawText( 0.15, 0.66, str.Data(),0.06,1);
579  TH2F coloredbox("colbox",";;",2,3.5,4.5,1,0.85*range,0.9*range);
580  coloredbox.Fill(3.8,0.86*range,2*mean+1.);
581  coloredbox.Fill(4.2,0.86*range,sigma);
582  coloredbox.SetAxisRange(0.,2.,"Z");
583  coloredbox.DrawCopy("col same");
584  gCanvasCounter++;
585  return 0;
586 }
double range[]
Definition: evaltrig.C:67
Double_t par[3]
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
Double_t
Int_t gCanvasCounter
Definition: tools/Tools.C:43
bool DrawText(Double_t posX=0., Double_t posY=0., const char *text="", Double_t size=0.08, Int_t col=1)
Definition: tools/Tools.C:45
Double_t mean[nsteps]
Definition: dedx_bands.C:65
bool set_nicer_2d_plot_style ( )

Definition at line 85 of file tools/Tools.C.

References Double_t.

Referenced by LoadPandaStyle(), and plothistosfromfile().

86 {
87  const Int_t NRGBs = 5;
88  const Int_t NCont = 99;//255;
89 
90  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
91  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
92  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
93  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
94  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
95  // gStyle->CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
96  gStyle->SetNumberContours(NCont);
97  return true;
98 }
Double_t
int Tools ( )

Definition at line 641 of file tools/Tools.C.

642 {
643  cout<<"pandaroot/macro/run/Tools.C loaded. Enjoy it."<<endl;
644  return 0;
645 }
TH1D TransformHisto ( TH2 *  h2,
double  min,
double  max 
)

Definition at line 296 of file tools/Tools.C.

References i, and nbins.

297 {
298  /*
299  * Created on: Feb 25, 2009
300  * Author: stockman
301  */
302 
303  TH1D result("h1","h1", 1000, min, max);
304  int nbins = h2->GetNbinsX() * h2->GetNbinsY();
305  for (int i = 0; i < nbins; i++){
306  //std::cout << h2->GetBinContent(i) << std::endl;
307  result.Fill(h2->GetBinContent(i));
308  if (i == 10)
309  cout << h2->GetBinContent(i) << endl;
310  }
311  return result;
312 }
Int_t i
Definition: run_full.C:25
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
int nbins
Definition: full_core_ntp.C:33
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25

Variable Documentation

Int_t gCanvasCounter =0

Definition at line 43 of file tools/Tools.C.

Referenced by GaussFitPlot(), LineFitPlot(), and PullFitPlot().