HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ptools.cc
Go to the documentation of this file.
1 //_HADES_CLASS_DESCRIPTION
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // Peter's Tools
5 //
6 // Author: Peter W. Zumbruch
7 // Contact: P.Zumbruch@gsi.de
8 // Created: Mar 21, 2002
9 //
10 // File: $RCSfile: ptools.cc,v $
11 // Version: $Revision: 1.79 $
12 // Modified by $Author: halo $ on $Date: 2009-07-23 14:50:51 $
13 ////////////////////////////////////////////////////////////////////////////////
14 
15 using namespace std;
16 
17 #include <cstdio>
18 #include <iostream>
19 #include <fstream>
20 #include <iomanip>
21 #include <cstdlib>
22 
23 #include "TArrayC.h"
24 #include "TArrayD.h"
25 #include "TArrayF.h"
26 #include "TArrayI.h"
27 #include "TArrayL.h"
28 #include "TArrayS.h"
29 #include "TApplication.h"
30 #include "TAxis.h"
31 #include "TCanvas.h"
32 #include "TEllipse.h"
33 #include "TError.h"
34 #include "TFile.h"
35 #include "TGaxis.h"
36 #include "TGraphErrors.h"
37 #include "TH1.h"
38 #include "TH2.h"
39 #include "TH3.h"
40 #include "TH1D.h"
41 #include "TH2D.h"
42 #include "TH3D.h"
43 #include "THashList.h"
44 #include "THStack.h"
45 #include "TLatex.h"
46 #include "TLegend.h"
47 #include "TLegendEntry.h"
48 #include "TLine.h"
49 #include "TMath.h"
50 #include "TObject.h"
51 #include "TObjString.h"
52 #include "TPaveText.h"
53 #include "TPad.h"
54 #include "TROOT.h"
55 #include "TStopwatch.h"
56 #include "TSystem.h"
57 #include "TString.h"
58 #include "TStyle.h"
59 #include "TTree.h"
60 #include "TUnixSystem.h"
61 
62 #include "ptools.h"
63 #include <cmath>
64 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 
69 
70 
71 PTools::PTools()
72 {
73  ;
74 }
76 {
77  ;
78 }
79 TPad* PTools::getDividedSubPad(TCanvas *canv,
80  Int_t xpads,
81  Int_t ypads)
82 {
83  // divides given canvas mycanvas into xpad times ypads pads
84  // returns pointer to pad of divided TPad
85 
86  TString title;
87  if (canv) title = canv->GetTitle();
88  else title ="";
89 
90  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title.Data(), (Char_t*)0, 0, (TPaveText*)0 );
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 TPad* PTools::getDividedSubPad(TCanvas *canv,
96  Int_t xpads,
97  Int_t ypads,
98  const Char_t * title)
99 {
100  // divides given canvas mycanvas into xpad times ypads pads
101  // adds a header with title
102  // returns pointer to pad of divided TPad
103  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, (Char_t*)0, 0, (TPaveText*)0 );
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 
108 TPad* PTools::getDividedSubPad(TCanvas *canv,
109  Int_t xpads,
110  Int_t ypads,
111  const Char_t * title,
112  const Char_t * filename)
113 {
114  // divides given canvas mycanvas into xpad times ypads pads
115  // adds a header with title
116  // containing filename and
117  // returns pointer to pad of divided TPad
118  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, 0, (TPaveText*)0 );
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 
123 TPad* PTools::getDividedSubPad(TCanvas *canv,
124  Int_t xpads,
125  Int_t ypads,
126  const Char_t * title,
127  const Char_t * filename,
128  Int_t nentries)
129 {
130  // divides given canvas mycanvas into xpad times ypads pads
131  // adds a header with title
132  // containing filename and
133  // number of entries
134  // returns pointer to pad of divided TPad
135 
136  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries,(TPaveText*)0 );
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 
141 TPad* PTools::getDividedSubPad(TCanvas *canv,
142  Int_t xpads,
143  Int_t ypads,
144  const Char_t * title,
145  const Char_t * filename,
146  Int_t nentries,
147  const Char_t * info)
148 {
149  // divides given canvas mycanvas into xpad times ypads pads
150  // adds a header with title
151  // containing filename and
152  // number of entries
153  // creates an info box at the right of the canvas
154  // returns pointer to pad of divided TPad
155 
156  TPaveText *infotext = new TPaveText(0,0,1,1);
157  infotext->SetTextSize(10);
158  infotext->AddText(info);
159  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries, infotext );
160 };
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 
164 TPad* PTools::getDividedSubPad(TCanvas *canv,
165  Int_t xpads,
166  Int_t ypads,
167  const Char_t * title,
168  const Char_t * filename,
169  Int_t nentries,
170  const TString info)
171 {
172  // divides given canvas mycanvas into xpad times ypads pads
173  // adds a header with title
174  // containing filename and
175  // number of entries
176  // creates an info box at the right of the canvas
177  // returns pointer to pad of divided TPad
178 
179  return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info.Data());
180 };
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 
184 TPad* PTools::getDividedSubPad(Int_t xpads,
185  Int_t ypads,
186  Int_t xsize, Int_t ysize)
187 {
188  // divides new canvas mycanvas of size xsizy * ysize
189  // into xpad times ypads pads
190  // returns pointer to pad of divided TPad
191  // memory leak! only for CINT use
192 
193  TCanvas *canv = new TCanvas();
194  canv->SetWindowSize(xsize,ysize);
195  canv->Resize();
196  canv->SetTitle(canv->GetName());
197 
198  TString title;
199 
200  if (canv) title = canv->GetTitle();
201  else title ="";
202 
203  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title.Data(), (Char_t*)0, 0, (TPaveText*)0 );
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 
208 TPad* PTools::getDividedSubPad(Int_t xpads,
209  Int_t ypads,
210  Int_t xsize, Int_t ysize,
211  const Char_t * title)
212 {
213  // divides new canvas mycanvas of size xsizy * ysize
214  // into xpad times ypads pads
215  // adds a header with title
216  // returns pointer to pad of divided TPad
217  // memory leak! only for CINT use
218 
219  TCanvas *canv = new TCanvas();
220  canv->SetWindowSize(xsize,ysize);
221  canv->Resize();
222  canv->SetTitle(title);
223 
224  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, (Char_t*)0, 0, (TPaveText*)0 );
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 
229 TPad* PTools::getDividedSubPad(Int_t xpads,
230  Int_t ypads,
231  Int_t xsize, Int_t ysize,
232  const Char_t * title,
233  const Char_t * filename)
234 {
235  // divides new canvas mycanvas of size xsizy * ysize
236  // into xpad times ypads pads
237  // adds a header with title
238  // containing filename and
239  // returns pointer to pad of divided TPad
240  // memory leak! only for CINT use
241 
242  TCanvas *canv = new TCanvas();
243  canv->SetWindowSize(xsize,ysize);
244  canv->Resize();
245  canv->SetTitle(title);
246  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, 0, (TPaveText*)0 );
247 }
248 
249 ////////////////////////////////////////////////////////////////////////////////
250 
251 TPad* PTools::getDividedSubPad(Int_t xpads,
252  Int_t ypads,
253  Int_t xsize, Int_t ysize,
254  const Char_t * title,
255  const Char_t * filename,
256  Int_t nentries)
257 {
258  // divides new canvas mycanvas of size xsizy * ysize
259  // into xpad times ypads pads
260  // adds a header with title
261  // containing filename and
262  // number of entries
263  // returns pointer to pad of divided TPad
264  // memory leak! only for CINT use
265 
266  TCanvas *canv = new TCanvas();
267  canv->SetWindowSize(xsize,ysize);
268  canv->Resize();
269  canv->SetTitle(title);
270  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries,(TPaveText*)0 );
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 
275 TPad* PTools::getDividedSubPad(Int_t xpads,
276  Int_t ypads,
277  Int_t xsize, Int_t ysize,
278  const Char_t * title,
279  const Char_t * filename,
280  Int_t nentries,
281  const Char_t * info)
282 {
283  // divides new canvas mycanvas of size xsizy * ysize
284  // into xpad times ypads pads
285  // adds a header with title
286  // containing filename and
287  // number of entries
288  // creates an info box at the right of the canvas
289  // returns pointer to pad of divided TPad
290  // memory leak! only for CINT use
291 
292  TCanvas *canv = new TCanvas();
293  canv->SetWindowSize(xsize,ysize);
294  canv->Resize();
295  canv->SetTitle(title);
296  TPaveText *infotext = new TPaveText(0,0,1,1);
297  infotext->SetTextSize(10);
298  infotext->AddText(info);
299  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries, infotext );
300 };
301 
302 ////////////////////////////////////////////////////////////////////////////////
303 
304 TPad* PTools::getDividedSubPad(Int_t xpads,
305  Int_t ypads,
306  Int_t xsize, Int_t ysize,
307  const Char_t * title,
308  const Char_t * filename,
309  Int_t nentries,
310  const TString info)
311 {
312  // divides new canvas mycanvas of size xsizy * ysize
313  // into xpad times ypads pads
314  // adds a header with title
315  // containing filename and
316  // number of entries
317  // creates an info box at the right of the canvas
318  // returns pointer to pad of divided TPad
319  // memory leak! only for CINT use
320 
321  TCanvas *canv = new TCanvas();
322  canv->SetWindowSize(xsize,ysize);
323  canv->Resize();
324  canv->SetTitle(title);
325  return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info.Data());
326 };
327 ////////////////////////////////////////////////////////////////////////////////
328 
329 TPad* PTools::getDividedSubPad(Int_t xpads,
330  Int_t ypads,
331  Int_t xsize, Int_t ysize,
332  const Char_t * title,
333  const Char_t * filename,
334  Int_t nentries,
335  TPaveText *info)
336 {
337  // divides new canvas mycanvas of size xsizy * ysize
338  // into xpad times ypads pads
339  // adds a header with title
340  // containing filename and
341  // number of entries
342  // creates an info box at the right of the canvas
343  // returns pointer to pad of divided TPad
344  // memory leak! only for CINT use
345 
346  TCanvas *canv = new TCanvas();
347  canv->SetWindowSize(xsize,ysize);
348  canv->Resize();
349  canv->SetTitle(title);
350  return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info);
351 };
352 
353 ////////////////////////////////////////////////////////////////////////////////
354 
355 TPad* PTools::getDividedSubPad(Int_t xpads,
356  Int_t ypads)
357 {
358  // divides new canvas mycanvas into xpad times ypads pads
359  // adds a header with title
360  // containing filename and
361  // memory leak! only for CINT use
362 
363  TCanvas *canv = new TCanvas();
364  canv->SetTitle(canv->GetName());
365 
366  TString title;
367 
368  if (canv) title = canv->GetTitle();
369  else title ="";
370 
371  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title.Data(), (Char_t*)0, 0, (TPaveText*)0 );
372 }
373 
374 ////////////////////////////////////////////////////////////////////////////////
375 
376 TPad* PTools::getDividedSubPad(Int_t xpads,
377  Int_t ypads,
378  const Char_t * title)
379 {
380  // divides new canvas mycanvas into xpad times ypads pads
381  // adds a header with title
382  // containing filename and
383  // memory leak! only for CINT use
384 
385  TCanvas *canv = new TCanvas();
386  canv->SetTitle(title);
387 
388  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, (Char_t*)0, 0, (TPaveText*)0 );
389 }
390 
391 ////////////////////////////////////////////////////////////////////////////////
392 
393 TPad* PTools::getDividedSubPad(Int_t xpads,
394  Int_t ypads,
395  const Char_t * title,
396  const Char_t * filename)
397 {
398  // divides new canvas mycanvas into xpad times ypads pads
399  // adds a header with title
400  // containing filename and
401  // memory leak! only for CINT use
402 
403  TCanvas *canv = new TCanvas();
404  canv->SetTitle(title);
405  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, 0, (TPaveText*)0 );
406 }
407 
408 ////////////////////////////////////////////////////////////////////////////////
409 
410 TPad* PTools::getDividedSubPad(Int_t xpads,
411  Int_t ypads,
412  const Char_t * title,
413  const Char_t * filename,
414  Int_t nentries)
415 {
416  // divides new canvas mycanvas into xpad times ypads pads
417  // adds a header with title
418  // containing filename and
419  // number of entries
420  // returns pointer to pad of divided TPad
421  // memory leak! only for CINT use
422 
423  TCanvas *canv = new TCanvas();
424  canv->SetTitle(title);
425  return getDividedSubPad(canv, xpads, ypads, title, filename, nentries,(TPaveText*)0 );
426 }
427 
428 ////////////////////////////////////////////////////////////////////////////////
429 
430 TPad* PTools::getDividedSubPad(Int_t xpads,
431  Int_t ypads,
432  const Char_t * title,
433  const Char_t * filename,
434  Int_t nentries,
435  const Char_t * info)
436 {
437  // divides new canvas mycanvas into xpad times ypads pads
438  // adds a header with title
439  // containing filename and
440  // number of entries
441  // creates an info box at the right of the canvas
442  // returns pointer to pad of divided TPad
443  // memory leak! only for CINT use
444 
445  TCanvas *canv = new TCanvas();
446  canv->SetTitle(title);
447  TPaveText *infotext = new TPaveText(0,0,1,1);
448  infotext->SetTextSize(10);
449  TString str(info);
450  while(str.Length() != 0)
451  {
452  if (str.First("/n") != str.Length())
453  {
454  infotext->AddText((str(0,str.First("/n")-1)).Data());
455  str=str(str.First("/n")+1,str.Length());
456  }
457  else
458  {
459  infotext->AddText(info);
460  str="";
461  }
462  }
463  return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries, infotext );
464 };
465 
466 ////////////////////////////////////////////////////////////////////////////////
467 
468 TPad* PTools::getDividedSubPad(Int_t xpads,
469  Int_t ypads,
470  const Char_t * title,
471  const Char_t * filename,
472  Int_t nentries,
473  const TString info)
474 {
475  // divides new canvas mycanvas into xpad times ypads pads
476  // adds a header with title
477  // containing filename and
478  // number of entries
479  // creates an info box at the right of the canvas
480  // returns pointer to pad of divided TPad
481  // memory leak! only for CINT use
482 
483  TCanvas *canv = new TCanvas();
484  canv->SetTitle(title);
485  return getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info.Data());
486 };
487 
488 ////////////////////////////////////////////////////////////////////////////////
489 
490 TPad* PTools::getDividedSubPad(Int_t xpads,
491  Int_t ypads,
492  const Char_t * title,
493  const Char_t * filename,
494  Int_t nentries,
495  TPaveText *info)
496 {
497  // divides new canvas mycanvas into xpad times ypads pads
498  // adds a header with title
499  // containing filename and
500  // number of entries
501  // creates an info box at the right of the canvas
502  // returns pointer to pad of divided TPad
503  // memory leak! only for CINT use
504 
505  TCanvas *canv = new TCanvas();
506  canv->SetTitle(title);
507  return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info);
508 };
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 TPad* PTools::getDividedSubPad(TCanvas *mycanvas,
512  Int_t xpads,
513  Int_t ypads,
514  const Char_t *titlehead,
515  const Char_t *mytextfilename,
516  Int_t nentries,
517  TPaveText *info)
518 {
519  // divides given canvas mycanvas into xpad times ypads pads
520  // adds a header with title
521  // containing filename and
522  // number of entries
523  // creates an info box at the right of the canvas
524  // returns pointer to pad of divided TPad
525 
526  if (!mycanvas) return NULL;
527 
528  Char_t name[200];
529  mycanvas->cd();
530  sprintf(name,"%s_header",gPad->GetName());
531  mycanvas->SetFillColor(0);
532 
533  TPad *mycanvas_header = new TPad(name,name,0.01,0.95,0.99,0.99);
534  mycanvas_header->Draw();
535  mycanvas_header->cd();
536 
537  printHeader(titlehead,mytextfilename,nentries,mycanvas_header);
538 
539  mycanvas->cd();
540 
541  TPad *mycanvas_body;
542 
543  if (info)
544  {
545  sprintf(name,"%s_info",gPad->GetName());
546  TPad *mycanvas_info = new TPad(name,name,0.80,0.01,0.99,0.94);
547  mycanvas_info->Draw();
548  mycanvas_info->cd();
549  gPad->SetFillStyle(4000);
550 
551  info->SetX1NDC(0.051);
552  info->SetY1NDC(0.02);
553  info->SetX2NDC(0.95);
554  info->SetY2NDC(0.98);
555  info->SetTextSize(0.08);
556  info->SetBorderSize(0);
557 // while (info->GetListOfLines()->LastIndex() < 2*(Int_t)((1/info->GetTextSize())-2)) info->AddText(" ");
558  info->SetFillColor(0);
559  info->Draw();
560 
561  mycanvas->cd();
562 
563  sprintf(name,"%s_body",gPad->GetName());
564 
565  mycanvas_body = new TPad(name,name,0.01,0.01,0.79,0.94);
566  }
567  else
568  {
569  sprintf(name,"%s_body",gPad->GetName());
570  mycanvas_body = new TPad(name,name,0.01,0.01,0.99,0.94);
571  }
572 
573  mycanvas_body->Draw();
574  mycanvas_body->cd();
575  gPad->SetFillStyle(4000);
576 
577  if (xpads > 1 || ypads > 1)
578  {
579  mycanvas_body->Divide(xpads,ypads);
580  mycanvas_body->cd(1);
581  }
582 
583  return mycanvas_body;
584 }
585 
586 ////////////////////////////////////////////////////////////////////////////////
587 
588 void PTools::printHeader(const Char_t *titlehead, const Char_t *mytextfilename, Int_t nentries, TPad *parentPad)
589 {
590  // prints header of canvas containing in the parent pad
591  // header contains filename and number of entries
592 
593  if (!parentPad) gPad->cd();
594  else parentPad->cd();
595 
596  const TDatime daytime;
597  Char_t texText[200];
598 
599  sprintf(texText,"%s",(titlehead)?titlehead:" ");
600  TLatex *tex = new TLatex(0.01,0.15,texText);
601  tex->SetTextSize(0.35);
602  tex->SetLineWidth(2);
603  tex->Draw();
604 
605  if (mytextfilename!=0 && nentries!=0)
606  {
607  sprintf(texText,"%i Events - File %s",nentries,mytextfilename);
608  }
609  else if (nentries==0 && mytextfilename==0)
610  {
611  sprintf(texText," ");
612  }
613  else if (nentries==0 && mytextfilename!=0)
614  {
615  sprintf(texText,"File %s",mytextfilename);
616  }
617  else
618  {
619  sprintf(texText,"%i Events",nentries);
620  }
621 
622  TLatex *tex2 = new TLatex(0.01,0.6,texText);
623  tex2->SetTextSize(0.35);
624  tex2->SetLineWidth(2);
625  tex2->Draw();
626 
627  sprintf(texText,"%s",daytime.AsSQLString());
628 
629  TLatex *tex3 = new TLatex(0.85,0.15,texText);
630  tex3->SetTextSize(0.35);
631  tex3->SetLineWidth(2);
632  tex3->Draw();
633 
634  return;
635 }
636 
637 ////////////////////////////////////////////////////////////////////////////////
638 
639 void PTools::evalStopwatch(TStopwatch *timer, Int_t nevts)
640 {
641  // evaluates Stopwatch for given number of events
642  // also plots the machine where it was running on
643 
644  Double_t realtime=(*timer).RealTime();
645  Double_t cputime =(*timer).CpuTime();
646  Int_t realHour=(Int_t) ((realtime/3600));
647  Int_t realMin =(Int_t) (((realtime-realHour*3600)/60));
648  Int_t realSec =(Int_t) ((realtime-realHour*3600-realMin*60));
649  Int_t realmSec=(Int_t) (((realtime - (Int_t) (realtime-realHour*3600-realMin*60))*1000));
650  Int_t cpuHour=(Int_t) (( cputime/3600));
651  Int_t cpuMin =(Int_t) ((( cputime- cpuHour*3600)/60));
652  Int_t cpuSec =(Int_t) (( cputime- cpuHour*3600- cpuMin*60));
653  Int_t cpumSec=(Int_t) ((( cputime - (Int_t) ( cputime- cpuHour*3600- cpuMin*60))*1000));
654 
655  printf("------------------------------------------------------\n");
656  printf("Events processed: %i\n",nevts);
657  printf("Real time(hh:mm:ss.ms): %02i:%02i:%02i.%03i\n",
658  realHour,realMin,realSec,realmSec);
659  printf("Cpu time (hh:mm:ss.ms): %02i:%02i:%02i.%03i\n",
660  cpuHour, cpuMin, cpuSec, cpumSec);
661  if (nevts && cputime >0) printf("cpu Performance: %f s/ev or %f.2 ev/s \n",(float) ( cputime/nevts),(float) (nevts/ cputime));
662  if (nevts && realtime>0) printf("real Performance: %f s/ev or %f.2 ev/s \n",(float) (realtime/nevts),(float) (nevts/realtime));
663  gSystem->Exec("cat /proc/cpuinfo | perl -ne 'print if(/cpu MHz/i || /model name/i )'");
664  return;
665 }
666 
667 ////////////////////////////////////////////////////////////////////////////////
668 
669 void PTools::setTitleArts( TH1* histogramm, const Char_t *xtitle, const Char_t *ytitle, TString color, Int_t type)
670 {
671  // sets titles of x axis, y axis, fill color and font type for histogramm
672  // with colors "black","red","bright green","bright blue","yellow","hot pink","aqua","green","blue","default"
673 
674  const TString col[11]={"","black","red","bright green","bright blue","yellow","hot pink","aqua","green","blue","default"};
675 
676  color.ToLower();
677  Int_t i;
678  for (i = 1; i <= 10; i++)
679  {
680  if (color.CompareTo(col[i])==0) break;
681  }
682  if (i==11)
683  {
684  Info("setTitleArts","no valid name for color chosen %s ... setting to default: %s",color.Data(),col[4].Data());
685  i=4;
686  }
687 
688  setTitleArts( histogramm, xtitle, ytitle, i , type);
689 }
690 
691 ////////////////////////////////////////////////////////////////////////////////
692 
693 void PTools::setTitleArts( TH1* histogramm, const TString xtitle, const TString ytitle, TString color, Int_t type)
694 {
695  // sets titles of x axis, y axis, fill color and font type for histogramm
696  // with colors "black","red","bright green","bright blue","yellow","hot pink","aqua","green","blue","default"
697  setTitleArts( histogramm, xtitle.Data(), ytitle.Data(), color, type);
698 }
699 
700 ////////////////////////////////////////////////////////////////////////////////
701 
702 void PTools::setTitleArts( TH1* histogramm, const TString xtitle, const TString ytitle,
703  Int_t fillColor, Int_t titleFont)
704 {
705  // sets titles of x axis, y axis, fill color and font type for histogramm
706  setTitleArts( histogramm, xtitle.Data(), ytitle.Data(), fillColor, titleFont);
707 }
708 
709 ////////////////////////////////////////////////////////////////////////////////
710 
711 void PTools::setTitleArts( TH1* histogramm, const Char_t *xtitle, const Char_t * ytitle,
712  Int_t fillColor, Int_t titleFont)
713 {
714  // sets titles of x axis, y axis, fill color and font type for histogramm
715  // with colors "black","red","bright green","bright blue","yellow","hot pink","aqua","green","blue","default"
716 
717  histogramm->SetXTitle(xtitle);
718  histogramm->SetYTitle(ytitle);
719  if (fillColor >= 0 ) histogramm->SetFillColor(fillColor);
720  ((TAxis*)histogramm->GetXaxis())->CenterTitle();
721  ((TAxis*)histogramm->GetXaxis())->SetTitleFont(titleFont);
722  ((TAxis*)histogramm->GetXaxis())->SetTitleColor(1);
723  ((TAxis*)histogramm->GetXaxis())->SetTitleOffset(1.2);
724  ((TAxis*)histogramm->GetYaxis())->SetTitleFont(titleFont);
725  ((TAxis*)histogramm->GetYaxis())->SetTitleOffset(1.2);
726  ((TAxis*)histogramm->GetYaxis())->SetTitleColor(1);
727 }
728 
729 ////////////////////////////////////////////////////////////////////////////////
730 
731 void PTools::setTitleArts( THStack* histogrammStack, const TString xtitle, const TString ytitle,
732  Int_t titleFont)
733 {
734  // sets titles of x axis, y axis, font type for histogramm for histogramm stack
735 
736  setTitleArts( histogrammStack, xtitle.Data(), ytitle.Data(), titleFont);
737 }
738 
739 ////////////////////////////////////////////////////////////////////////////////
740 
741 void PTools::setTitleArts( THStack* histogrammStack, const Char_t *xtitle, const Char_t * ytitle,
742  Int_t titleFont)
743 {
744  // sets titles of x axis, y axis, font type for histogramm for histogramm stack
745 
746  ((TAxis*)histogrammStack->GetXaxis())->SetTitle(xtitle);
747  ((TAxis*)histogrammStack->GetYaxis())->SetTitle(ytitle);
748  ((TAxis*)histogrammStack->GetXaxis())->CenterTitle();
749  ((TAxis*)histogrammStack->GetXaxis())->SetTitleFont(titleFont);
750  ((TAxis*)histogrammStack->GetXaxis())->SetTitleOffset(1.2);
751  ((TAxis*)histogrammStack->GetYaxis())->SetTitleFont(titleFont);
752  // ((TAxis*)histogrammStack->GetYaxis())->SetTitleOffset(1.2);
753 }
754 
755 ////////////////////////////////////////////////////////////////////////////////
756 
757 TCanvas* PTools::drawCanvas(const Char_t * name,
758  const Char_t * title,
759  TH1 **histarray,
760  Int_t xsize,
761  Int_t ysize)
762 {
763  // draws default canvas divided xsize times ysize and fills it with the contents of histarray[i] at pad(i) using plot option
764  // only useful for 6 pads!!
765 #ifndef __CINT__
766  static Int_t calls;
767 #else
768  Int_t calls=0;
769 #endif
770 
771  TCanvas *canv = new TCanvas(name,title,0+calls*25,0+calls*25,1000,800);
772 
773  canv->Divide(xsize,ysize);
774 
775  for (Int_t time=0 ;time < 6 ; time++)
776  {
777  canv->cd(time+1);
778  if (histarray[time]->GetEntries()>0)
779  {
780  histarray[time]->DrawCopy();
781  gPad->SetLogy();
782  }
783  else delete gPad;
784  }
785 
786  calls++;
787  return canv;
788 }
789 
790 ////////////////////////////////////////////////////////////////////////////////
791 
792 TCanvas* PTools::draw32Canvas(const Char_t * name, const Char_t * title, TH1F *histarray[])
793 {
794  // draws default canvas divided 3 times 2 and fills it with the contents of histarray[i] at pad(i) using plot option
795 
796 #ifndef __CINT__
797  static Int_t calls;
798 #else
799  Int_t calls=0;
800 #endif
801 
802  TCanvas *canv = new TCanvas(name,title,0+calls*25,0+calls*25,1000,800);
803  canv->Divide(3,2);
804 
805  for (Int_t time=0 ;time < 6 ; time++)
806  {
807  canv->cd(time+1);
808  if (histarray[time]->GetEntries()>0)
809  {
810  histarray[time]->DrawCopy();
811  gPad->SetLogy();
812  }
813  else delete gPad;
814  }
815 
816  calls++;
817  return canv;
818 }
819 
820 ////////////////////////////////////////////////////////////////////////////////
821 
822 TCanvas* PTools::draw32CanvasTH2(const Char_t * name, const Char_t * title, TH2F *histarray[], const Char_t * option)
823 {
824  // draws default canvas divided 3 times 2 and fills it with the contents of histarray[i] at pad(i) using plot option "option"
825 
826 #ifndef __CINT__
827  static Int_t calls;
828 #else
829  Int_t calls=0;
830 #endif
831 
832  TCanvas *canv = new TCanvas(name,title,0+calls*25,0+calls*25,1000,800);
833  canv->Divide(3,2);
834 
835  for (Int_t time=0 ;time < 6 ; time++)
836  {
837  canv->cd(time+1);
838 
839  if (histarray[time]->GetEntries()>0)
840  {
841  if (!option) histarray[time]->DrawCopy();
842  else histarray[time]->DrawCopy(option);
843  //gPad->SetLogz();
844  }
845  else {}// delete gPad;
846  }
847 
848  calls++;
849  return canv;
850 }
851 
852 ////////////////////////////////////////////////////////////////////////////////
853 
854 void PTools::cutEnd(Char_t * infi,const Char_t * end)
855 {
856  // cuts from infi end from the end
857 
858  Char_t textfile[200];
859  sprintf(textfile,"tempvar=\"%s\" ; echo ${tempvar%%%s}",infi,end);
860  Char_t *tmp = myexec(textfile);
861  sprintf(infi,"%s",myexec(textfile));
862  delete[] tmp;
863 }
864 
865 ////////////////////////////////////////////////////////////////////////////////
866 
867 Char_t * PTools::myexec(const Char_t * in)
868 {
869  // executes command in
870  // and returns Char_t pointer to result string
871  // user have to delete return string
872 
873  Char_t *tmp = new Char_t[1000];
874  Char_t textfile[1000];
875  FILE *pipe = gSystem->OpenPipe(in,"r");
876  Int_t n=fscanf(pipe,"%s",textfile);
877  if(n==0)cout<<"no value read back!"<<endl;
878  gSystem->ClosePipe(pipe);
879  sprintf(tmp,"%s",textfile);
880  return tmp;
881 }
882 
883 ////////////////////////////////////////////////////////////////////////////////
884 
885 TString PTools::myexec(TString in)
886 {
887  // executes command in
888  // and returns Char_t pointer to result string
889  // user have to delete return string
890 
891  const Char_t* tmp = myexec(in.Data());
892  TString st(tmp);
893  delete tmp;
894  return TString(st);
895 }
896 
897 ////////////////////////////////////////////////////////////////////////////////
898 
899 void PTools::mdb(Int_t called)
900 {
901  // small minidebug message, with increasing static counter
902  // prints out called if called different from -1
903  // useful example
904  // PTools::mdb(\__LINE__)
905 
906  static Int_t call;
907  if (called==-1)
908  {
909  call++;
910  cerr << "here" << call << endl;
911  }
912  else cerr << "here" << called << endl;
913  return;
914 }
915 
916 ////////////////////////////////////////////////////////////////////////////////
917 
918 TDirectory *PTools::Mkdir(TDirectory *dirOld,
919  const Char_t *newDirName,
920  Int_t index,
921  Int_t precision) //! Makes new Dir, changes to Dir, returns pointer to new Dir
922 {
923  // Function to create subdirectories
924  // of dirOld with name newDirName
925  // if index differs from -99 then index is attached to the name with the precision of precision
926  // changes to the new created directory
927  // returns the pointer to the new directory
928  //Thanks to J.Kempter (J.Markert)
929 
930  dirOld->cd();
931 
932  TString newName(newDirName);
933 
934  while (newName.Contains("/"))
935  {
936  TString directory = newName;
937  Int_t pos = directory.First("/");
938  PTools::Mkdir(gDirectory,directory.Remove(pos));
939  newName = newName(pos+1,newName.Length()-pos-1).Data();
940  dirOld=gDirectory;
941  }
942 
943  static Char_t sDir[255];
944  static Char_t sFmt[10];
945  if (index!=-99)
946  {
947  sprintf(sFmt, "%%s %%0%1ii", precision);
948  sprintf(sDir, sFmt, newName.Data(), index);
949  }
950  else
951  {
952  sprintf(sFmt, "%%s");
953  sprintf(sDir, sFmt, newName.Data());
954  }
955  TDirectory *dirNew;
956  if (!dirOld->FindKey(sDir))
957  {
958  dirNew = dirOld->mkdir(sDir);
959  }
960  else
961  {
962  dirNew = (TDirectory *) dirOld->Get(sDir);
963  }
964  dirOld->cd(sDir);
965  return dirNew;
966 }
967 
968 ////////////////////////////////////////////////////////////////////////////////
969 
970 TDirectory *PTools::Mkdir(TDirectory *dirOld,
971  const TString newDirName,
972  Int_t index,
973  Int_t precision) //! Makes new Dir, changes to Dir, returns pointer to new Dir
974 {
975  // see: PTools::Mkdir(TDirectory *dirOld, const Char_t *newDirName, Int_t index, Int_t precision
976  return Mkdir(dirOld, newDirName.Data(), index, precision);
977 }
978 
979 ////////////////////////////////////////////////////////////////////////////////
980 
982  Int_t& nbinsx , Axis_t& xmin , Axis_t& xmax,
983  Int_t& nbinsy , Axis_t& ymin , Axis_t& ymax,
984  Int_t& nbinsz , Axis_t& zmin , Axis_t& zmax)
985 {
986  // returns the limits of hist
987 
988  getHistogramLimits(hist, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
989  if (nbinsz) nbinsz = hist->GetNbinsZ();
990  if (zmin ) zmin = hist->GetZaxis()->GetXmin();
991  if (zmax ) zmax = hist->GetZaxis()->GetXmax();
992 }
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 
997  Int_t& nbinsx , Axis_t& xmin , Axis_t& xmax,
998  Int_t& nbinsy , Axis_t& ymin , Axis_t& ymax)
999 {
1000  // returns the limits of hist
1001 
1002  // if (nbinsx) nbinsx = hist->GetNbinsX();
1003  // if (xmin ) xmin = hist->GetXaxis()->GetXmin();
1004  // if (xmax ) xmax = hist->GetXaxis()->GetXmax();
1005  getHistogramLimits(hist, nbinsx, xmin, xmax);
1006  if (nbinsy) nbinsy = hist->GetNbinsY();
1007  if (ymin ) ymin = hist->GetYaxis()->GetXmin();
1008  if (ymax ) ymax = hist->GetYaxis()->GetXmax();
1009 
1010 }
1011 
1012 ////////////////////////////////////////////////////////////////////////////////
1013 
1015  Int_t& nbinsx , Axis_t& xmin , Axis_t& xmax)
1016 {
1017  // returns the limits of hist
1018 
1019  if (nbinsx) nbinsx = hist->GetNbinsX();
1020  if (xmin ) xmin = hist->GetXaxis()->GetXmin();
1021  if (xmax ) xmax = hist->GetXaxis()->GetXmax();
1022 }
1023 
1024 ////////////////////////////////////////////////////////////////////////////////
1025 
1027 {
1028  // prints the limits of hist
1029 
1030  Int_t nbinsx;
1031  Axis_t xmin, xmax;
1032 
1033  getHistogramLimits(hist, nbinsx, xmin, xmax);
1034  printf("nbinsx: %i \nxmin: \t %f \nxmax: \t %f\n",nbinsx, xmin, xmax);
1035 }
1036 
1037 ////////////////////////////////////////////////////////////////////////////////
1038 
1040 {
1041  // prints the limits of hist
1042 
1043  Int_t nbinsx, nbinsy;
1044  Axis_t xmin, xmax, ymin, ymax;
1045 
1046  getHistogramLimits(hist, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
1047  printf("nbinsx: %i \nxmin: \t %f \nxmax: \t %f\n",nbinsx, xmin, xmax);
1048  printf("nbinsy: %i \nymin: \t %f \nymax: \t %f\n",nbinsy, ymin, ymax);
1049 }
1050 
1051 ////////////////////////////////////////////////////////////////////////////////
1052 
1054 {
1055  // prints the limits of hist
1056 
1057  Int_t nbinsx, nbinsy, nbinsz;
1058  Axis_t xmin, xmax, ymin, ymax, zmin, zmax;
1059 
1060  getHistogramLimits(hist, nbinsx, xmin, xmax, nbinsy, ymin, ymax , nbinsz, zmin, zmax);
1061 
1062  printf("nbinsx: %i \nxmin: \t %f \nxmax: \t %f\n",nbinsx, xmin, xmax);
1063  printf("nbinsy: %i \nymin: \t %f \nymax: \t %f\n",nbinsy, ymin, ymax);
1064  printf("nbinsz: %i \nzmin: \t %f \nzmax: \t %f\n",nbinsz, zmin, zmax);
1065  printHistogramLimits((TH2*) hist);
1066 }
1067 
1068 ////////////////////////////////////////////////////////////////////////////////
1069 
1070 Bool_t PTools::compareHistogramLimits(TH1* hist1, TH1* hist2, Bool_t exitIfNotEqual )
1071 {
1072  // compares limits of hist1 with limits hist2 (nbins, min, max)
1073  // if exitIfNotEqual is set exit.
1074 
1075  Bool_t ok = kTRUE;
1076 
1077  Int_t nbinsx1, nbinsy1;
1078  Axis_t xmin1, xmax1, ymin1, ymax1;
1079  Int_t nbinsx2, nbinsy2;
1080  Axis_t xmin2, xmax2, ymin2, ymax2;
1081 
1082  getHistogramLimits( hist1, nbinsx1, xmin1, xmax1, nbinsy1, ymin1, ymax1);
1083  getHistogramLimits( hist2, nbinsx2, xmin2, xmax2, nbinsy2, ymin2, ymax2);
1084 
1085  if ( nbinsx1 != nbinsx2 ) ok = kFALSE;
1086  if ( nbinsy1 != nbinsy2 ) ok = kFALSE;
1087  if ( xmin1 != xmin2 ) ok = kFALSE;
1088  if ( xmax1 != xmax2 ) ok = kFALSE;
1089  if ( ymin1 != ymin2 ) ok = kFALSE;
1090  if ( ymax1 != ymax2 ) ok = kFALSE;
1091 
1092  if (!ok)
1093  {
1094  Error("checkRanges()",
1095  "parameters nbinsx(%i,%i),\n nbinsy(%i,%i), \n xmin(%f,%f), \n xmax(%f,%f), \n ymin(%f,%f), \n ymax(%f,%f) of hist1:%s and hist2:%s are not identical %s",
1096  nbinsx1,
1097  nbinsx2,
1098  nbinsy1,
1099  nbinsy2,
1100  xmin1,
1101  xmin2,
1102  xmax1,
1103  xmax2,
1104  ymin1,
1105  ymin2,
1106  ymax1,
1107  ymax2,
1108  hist2->GetName(),
1109  hist2->GetName(),
1110  (!exitIfNotEqual)?"!":"... exiting!"
1111 
1112  );
1113  if (exitIfNotEqual)
1114  {
1115  exit(EXIT_FAILURE);
1116  }
1117  }
1118 
1119  return ok;
1120 }
1121 
1122 ////////////////////////////////////////////////////////////////////////////////
1123 
1124 Int_t PTools::getNFilledBins(TH1 * hist, Double_t min, Double_t max)
1125 {
1126  // get number of filled bins where the
1127  // bin contents are within the limits of min and max
1128 
1129  Int_t nbinsx = hist->GetNbinsX();
1130  Int_t nbinsy = hist->GetNbinsY();
1131  Int_t nbinsz = hist->GetNbinsZ();
1132 
1133  if ( min==-1 && max == -1)
1134  {
1135  min = hist->GetMinimum();
1136  max = hist->GetMaximum();
1137  }
1138 
1139  if (hist->GetDimension()<2) nbinsy = -1;
1140  if (hist->GetDimension()<3) nbinsz = -1;
1141 
1142  Int_t binx,biny,binz,bin;
1143  Double_t g;
1144 
1145  Int_t ctr=0;
1146 
1147  for (binz=0;binz<=nbinsz+1;binz++)
1148  {
1149  for (biny=0;biny<=nbinsy+1;biny++)
1150  {
1151  for (binx=0;binx<=nbinsx+1;binx++)
1152  {
1153  bin = hist->GetBin(binx,biny,binz);
1154  g = hist->GetBinContent(bin);
1155 
1156  if (binx==0) continue;
1157  if (nbinsy !=-1) { if (biny==0) continue;}
1158  if (nbinsz !=-1) { if (binz==0) continue;}
1159  if (binx==nbinsx+1) continue;
1160  if (nbinsy !=-1){if (biny==nbinsy+1) continue;}
1161  if (nbinsz !=-1){if (binz==nbinsz+1) continue;}
1162 
1163  if (g >=min && g <=max)
1164  {
1165  if (g!=0.) ctr++;
1166  }
1167 
1168  }
1169  }
1170  }
1171  return ctr;
1172 }
1173 
1174 ////////////////////////////////////////////////////////////////////////////////
1175 
1176 void PTools::cleanHistogram(TH1 * hist, Double_t min, Double_t max, Int_t errorMode)
1177 {
1178  // cleans histograms
1179  // bin contents out of the limits of min and max
1180  // are set to 0
1181  // errors are set to 0
1182  //
1183  // if errorMode is not equal [default=0]
1184  // then instead of the binContent
1185  // the min-max condition is applied on the errors
1186  //
1187  // errorMode = 0: bin contents
1188  // errorMode > 0: absolute Values are compared
1189  // errorMode < 0: relative Errors are considere
1190  // (for this purpose the function getErrorsOfHistogram() is used, see there for definitions of exceptions)
1191 
1192  if (!hist)
1193  {
1194  ::Error("cleanHistogram"," hist is NULL pointer ... return NULL");
1195  return;
1196  }
1197 
1198  if (errorMode>0) errorMode = 1;
1199  if (errorMode<0) errorMode =-1;
1200 
1201  Int_t nbinsx = hist->GetNbinsX();
1202  Int_t nbinsy = hist->GetNbinsY();
1203  Int_t nbinsz = hist->GetNbinsZ();
1204 
1205  if (hist->GetDimension()<2) nbinsy = -1;
1206  if (hist->GetDimension()<3) nbinsz = -1;
1207 
1208  Int_t binx,biny,binz,bin;
1209  Double_t g=-100.;
1210  bin=0;
1211 
1212  TH1* errHist;
1213 
1214  switch(errorMode)
1215  {
1216  case 0:
1217  errHist = NULL;
1218  break;
1219  case 1:
1220  errHist = (TH1*) getErrorsOfHistogram(hist,kFALSE);
1221  break;
1222  case -1:
1223  errHist = (TH1*) getErrorsOfHistogram(hist,kTRUE);
1224  break;
1225  default:
1226  errHist = NULL;
1227  break;
1228  }
1229 
1230  for (binz=0;binz<=nbinsz+1;binz++)
1231  {
1232  for (biny=0;biny<=nbinsy+1;biny++)
1233  {
1234  for (binx=0;binx<=nbinsx+1;binx++)
1235  {
1236  switch(errorMode)
1237  {
1238  case 0:
1239  bin = hist->GetBin(binx,biny,binz);
1240  g = hist->GetBinContent(bin);
1241  break;
1242  case 1:
1243  bin = errHist->GetBin(binx,biny,binz);
1244  g = errHist->GetBinContent(bin);
1245  break;
1246  case -1:
1247  bin = errHist->GetBin(binx,biny,binz);
1248  g = errHist->GetBinContent(bin);
1249  break;
1250  default:
1251  break;
1252  }
1253 
1254  if(bin>=0)
1255  {
1256  if (g < min || g > max)
1257  {
1258  hist->SetBinContent(bin,0);
1259  hist->SetBinError(bin,0);
1260  }
1261  }
1262  }
1263  }
1264  }
1265 
1266  if (errorMode != 0 && errHist)
1267  {
1268  delete errHist;
1269  }
1270 }
1271 
1272 ////////////////////////////////////////////////////////////////////////////////
1273 
1274 void PTools::prefixToName(TNamed *name, TString prefix)
1275 {
1276  prefix+="_";
1277  prefix+= name->GetName();
1278  name->SetName(prefix.Data());
1279 }
1280 
1281 ////////////////////////////////////////////////////////////////////////////////
1282 
1283 void PTools::prefixToTitle(TNamed *name, TString prefix)
1284 {
1285  prefix+=" - ";
1286  prefix+= name->GetTitle();
1287  name->SetTitle(prefix.Data());
1288 }
1289 
1290 ////////////////////////////////////////////////////////////////////////////////
1291 
1292 void PTools::prefixToNameTitle(TNamed *name, TString prefix)
1293 {
1294  TString prefixTitle = prefix;
1295  prefix+="_";
1296  prefix+= name->GetName();
1297  name->SetName(prefix.Data());
1298  prefixTitle+=" - ";
1299  prefixTitle+= name->GetTitle();
1300  name->SetTitle(prefixTitle.Data());
1301 
1302 }
1303 
1304 ////////////////////////////////////////////////////////////////////////////////
1305 
1306 void PTools::postfixToName(TNamed *name, TString postfix)
1307 {
1308  // attaches to the name of TNamed name "_postfix"
1309  // and " - postfix" to its title
1310 
1311  TString postfixTitle = postfix;
1312 
1313  postfix=name->GetName()+TString("_")+postfix;
1314  name->SetName(postfix.Data());
1315 }
1316 
1317 ////////////////////////////////////////////////////////////////////////////////
1318 
1319 void PTools::postfixToTitle(TNamed *name, TString postfix)
1320 {
1321  // attaches to TNamed name " - postfix" to its title
1322 
1323  TString postfixTitle = postfix;
1324 
1325  postfixTitle=name->GetTitle()+TString(" - ")+postfixTitle;
1326  name->SetTitle(postfixTitle.Data());
1327 }
1328 
1329 ////////////////////////////////////////////////////////////////////////////////
1330 
1331 void PTools::postfixToNameTitle(TNamed *name, TString postfix)
1332 {
1333  // attaches to the name of TNamed name "_postfix"
1334  // and " - postfix" to its title
1335 
1336  TString postfixTitle = postfix;
1337 
1338  postfix=name->GetName()+TString("_")+postfix;
1339  name->SetName(postfix.Data());
1340 
1341  postfixTitle=name->GetTitle()+TString(" - ")+postfixTitle;
1342  name->SetTitle(postfixTitle.Data());
1343 }
1344 
1345 // void PTools::prefixToName (TNamed *name, Char_t *prefix){TString aa = prefix; prefixToName (name,aa);};
1346 // void PTools::prefixToTitle (TNamed *name, Char_t *prefix){TString aa = prefix; prefixToTitle (name,aa);};
1347 // void PTools::prefixToNameTitle (TNamed *name, Char_t *prefix){TString aa = prefix; prefixToNameTitle(name,aa);};
1348 // void PTools::postfixToName (TNamed *name, Char_t *postfix){TString aa = postfix; postfixToName (name,aa);};
1349 // void PTools::postfixToTitle (TNamed *name, Char_t *postfix){TString aa = postfix; postfixToTitle (name,aa);};
1350 // void PTools::postfixToNameTitle(TNamed *name, Char_t *postfix){TString aa = postfix; postfixToNameTitle(name,aa);};
1351 
1352 ////////////////////////////////////////////////////////////////////////////////
1353 
1354 void PTools::cutHistogram(TH2* hist, TCutG *cut, Bool_t complement)
1355 {
1356  // cuts 2-dim histogram hist by using the graphical cut
1357  // complement inverts the selection
1358 
1359  Int_t nbinsx = hist->GetNbinsX();
1360  Int_t nbinsy = hist->GetNbinsY();
1361  Int_t nbinsz = hist->GetNbinsZ();
1362 
1363  if (hist->GetDimension()<3) nbinsz = -1;
1364 
1365  Int_t binx,biny,binz,bin;
1366  Double_t gx,gy;
1367 
1368  for (binz=0;binz<=nbinsz+1;binz++)
1369  {
1370  for (biny=0;biny<=nbinsy+1;biny++)
1371  {
1372  for (binx=0;binx<=nbinsx+1;binx++)
1373  {
1374  bin = hist->GetBin(binx,biny,binz);
1375  gx = hist->GetXaxis()->GetBinCenter(binx);
1376  gy = hist->GetYaxis()->GetBinCenter(biny);
1377 
1378  if ((!complement && !cut->IsInside(gx,gy)) || (complement && cut->IsInside(gx,gy)))
1379  {
1380  hist->SetBinContent(bin,0);
1381  hist->SetBinError(bin,0);
1382  }
1383  }
1384  }
1385  }
1386 }
1387 
1388 ////////////////////////////////////////////////////////////////////////////////
1389 
1390 void PTools::cutHistogram(TH2* hist, TObjArray *cutarray, Bool_t complement)
1391 {
1392  // cuts 2-dim histogram hist by using logical or of the graphical cuts in the cutarray
1393  // complement inverts the selection
1394 
1395  TIterator *iter = cutarray->MakeIterator();
1396 
1397  Int_t nbinsx = hist->GetNbinsX();
1398  Int_t nbinsy = hist->GetNbinsY();
1399  Int_t nbinsz = hist->GetNbinsZ();
1400 
1401  if (hist->GetDimension()<3) nbinsz = -1;
1402 
1403  Int_t binx,biny,binz,bin;
1404  Double_t gx,gy;
1405  TCutG *cut;
1406  Bool_t keep;
1407  for (binz=0;binz<=nbinsz+1;binz++)
1408  {
1409  for (biny=0;biny<=nbinsy+1;biny++)
1410  {
1411  for (binx=0;binx<=nbinsx+1;binx++)
1412  {
1413  bin = hist->GetBin(binx,biny,binz);
1414  gx = hist->GetXaxis()->GetBinCenter(binx);
1415  gy = hist->GetYaxis()->GetBinCenter(biny);
1416 
1417  cut=0;
1418  iter->Reset();
1419  if (!complement)
1420  {
1421  keep=kFALSE;
1422  while( (cut = (TCutG*) iter->Next()) != NULL )
1423  {
1424  if (cut->IsInside(gx,gy))
1425  {
1426  keep=kTRUE;
1427  break;
1428  }
1429  }
1430  if (!keep)
1431  {
1432  hist->SetBinContent(bin,0);
1433  hist->SetBinError(bin,0);
1434  }
1435  }
1436  else
1437  {
1438  keep=kTRUE;
1439  while( (cut = (TCutG*) iter->Next()) != NULL )
1440  {
1441  if (cut->IsInside(gx,gy))
1442  {
1443  keep = keep & kFALSE;
1444  continue;
1445  }
1446  }
1447  if (!keep)
1448  {
1449  hist->SetBinContent(bin,0);
1450  hist->SetBinError(bin,0);
1451  }
1452  }
1453  }
1454  }
1455  }
1456 }
1457 
1458 ////////////////////////////////////////////////////////////////////////////////
1459 
1460 void PTools::plotCounts(TH1* hist, Int_t color, TString format)
1461 {
1462  // plots above each bin of hist
1463  // the bin content
1464  // in color
1465  // format can specify via e.g. %2.4f special output formats
1466  // but only fixed to floating precisions, so if you want to display just integers e.g. choose %4.0f
1467 
1468  if (hist->GetDimension()>1)
1469  {
1470  Error("plotCounts","this function can only be applied to 1-dimensional histograms");
1471  return;
1472  }
1473 
1474  Int_t first = hist->GetXaxis()->GetFirst();
1475  Int_t last = hist->GetXaxis()->GetLast();
1476  for (Int_t binx=first; binx<=last;binx++)
1477  {
1478  Double_t count = hist->GetBinContent(binx);
1479  Double_t xpos = hist->GetBinCenter(binx);
1480  Double_t ypos = (gPad->GetLogy())?log10(count):count;
1481  TString val="";
1482  if (format.IsNull())
1483  {
1484  val+=count;
1485  }
1486  else
1487  {
1488  val+=Form(format.Data(),count);
1489  }
1490  if (!(count>0 || count<0)) continue;
1491 
1492  hist->SetMaximum(hist->GetMaximum()* ((gPad->GetLogy())?5:1.05));
1493 
1494  TLatex *tex = drawLatexPadCoords(val, xpos, ypos, color, 0.025, 13, 72, 90);
1495  tex->SetLineWidth(2);
1496  }
1497 
1498 }
1499 
1500 ////////////////////////////////////////////////////////////////////////////////
1501 
1502 TH1F* PTools::getTH1F(TString name, TString title,
1503  Int_t xbin, Double_t xmin, Double_t xmax,
1504  TString xtitle, TString ytitle)
1505 {
1506  // one command for initializing a TH1F histogramm
1507  // object has to be deleted by user
1508  TH1F *hist = new TH1F(name,title, xbin,xmin,xmax);
1509  setTitleArts(hist,xtitle,ytitle);
1510  return hist;
1511 }
1512 ////////////////////////////////////////////////////////////////////////////////
1513 TH2F* PTools::getTH2F(TString name, TString title,
1514  Int_t xbin, Double_t xmin, Double_t xmax,
1515  Int_t ybin, Double_t ymin, Double_t ymax,
1516  TString xtitle, TString ytitle, TString ztitle)
1517 {
1518  // one command for initializing a TH2F histogramm
1519  // object has to be deleted by user
1520 
1521  TH2F *hist = new TH2F(name,title, xbin,xmin,xmax, ybin,ymin,ymax );
1522 
1523  if (! ztitle.IsNull())
1524  {
1525  hist->SetZTitle(ztitle.Data());
1526  ((TAxis*)hist->GetZaxis())->CenterTitle();
1527  ((TAxis*)hist->GetZaxis())->SetTitleFont(42);
1528  ((TAxis*)hist->GetZaxis())->SetTitleColor(1);
1529  ((TAxis*)hist->GetZaxis())->SetTitleOffset(1.2);
1530  }
1531 
1532  setTitleArts(hist,xtitle,ytitle);
1533  return hist;
1534 }
1535 ////////////////////////////////////////////////////////////////////////////////
1536 TH3F* PTools::getTH3F(TString name, TString title,
1537  Int_t xbin, Double_t xmin, Double_t xmax,
1538  Int_t ybin, Double_t ymin, Double_t ymax,
1539  Int_t zbin, Double_t zmin, Double_t zmax,
1540  TString xtitle, TString ytitle, TString ztitle)
1541 {
1542  // one command for initializing a TH3F histogramm
1543  // object has to be deleted by user
1544  TH3F *hist = new TH3F(name,title, xbin,xmin,xmax, ybin,ymin,ymax, zbin,zmin,zmax );
1545  setTitleArts(hist,xtitle,ytitle);
1546  hist->SetZTitle(ztitle.Data());
1547  ((TAxis*)hist->GetZaxis())->CenterTitle();
1548  ((TAxis*)hist->GetZaxis())->SetTitleFont(42);
1549  ((TAxis*)hist->GetZaxis())->SetTitleColor(1);
1550  ((TAxis*)hist->GetZaxis())->SetTitleOffset(1.2);
1551  return hist;
1552 }
1553 ////////////////////////////////////////////////////////////////////////////////
1554 
1555 TH1D* PTools::getTH1D(TString name, TString title,
1556  Int_t xbin, Double_t xmin, Double_t xmax,
1557  TString xtitle, TString ytitle)
1558 {
1559  // one command for initializing a TH1D histogramm
1560  // object has to be deleted by user
1561  TH1D *hist = new TH1D(name,title, xbin,xmin,xmax);
1562  setTitleArts(hist,xtitle,ytitle);
1563  return hist;
1564 }
1565 ////////////////////////////////////////////////////////////////////////////////
1566 TH2D* PTools::getTH2D(TString name, TString title,
1567  Int_t xbin, Double_t xmin, Double_t xmax,
1568  Int_t ybin, Double_t ymin, Double_t ymax,
1569  TString xtitle, TString ytitle, TString ztitle)
1570 {
1571  // one command for initializing a TH2D histogramm
1572  // object has to be deleted by user
1573 
1574  TH2D *hist = new TH2D(name,title, xbin,xmin,xmax, ybin,ymin,ymax );
1575 
1576  if (! ztitle.IsNull())
1577  {
1578  hist->SetZTitle(ztitle.Data());
1579  ((TAxis*)hist->GetZaxis())->CenterTitle();
1580  ((TAxis*)hist->GetZaxis())->SetTitleFont(42);
1581  ((TAxis*)hist->GetZaxis())->SetTitleColor(1);
1582  ((TAxis*)hist->GetZaxis())->SetTitleOffset(1.2);
1583  }
1584 
1585  setTitleArts(hist,xtitle,ytitle);
1586  return hist;
1587 }
1588 ////////////////////////////////////////////////////////////////////////////////
1589 TH3D* PTools::getTH3D(TString name, TString title,
1590  Int_t xbin, Double_t xmin, Double_t xmax,
1591  Int_t ybin, Double_t ymin, Double_t ymax,
1592  Int_t zbin, Double_t zmin, Double_t zmax,
1593  TString xtitle, TString ytitle, TString ztitle)
1594 {
1595  // one command for initializing a TH3D histogramm
1596  // object has to be deleted by user
1597  TH3D *hist = new TH3D(name,title, xbin,xmin,xmax, ybin,ymin,ymax, zbin,zmin,zmax );
1598  setTitleArts(hist,xtitle,ytitle);
1599  hist->SetZTitle(ztitle.Data());
1600  ((TAxis*)hist->GetZaxis())->CenterTitle();
1601  ((TAxis*)hist->GetZaxis())->SetTitleFont(42);
1602  ((TAxis*)hist->GetZaxis())->SetTitleColor(1);
1603  ((TAxis*)hist->GetZaxis())->SetTitleOffset(1.2);
1604  return hist;
1605 }
1606 
1607 ////////////////////////////////////////////////////////////////////////////////
1608 TH1* PTools::reverseXAxis(TH1* hist)
1609 {
1610  // reverses the X-Axis of the histogramm
1611  // creates a new histogramm
1612 
1613  Int_t nbinsx = hist->GetNbinsX();
1614  Int_t nbinsy = hist->GetNbinsY();
1615  Int_t nbinsz = hist->GetNbinsZ();
1616 
1617  if (hist->GetDimension()<2) nbinsy = -1;
1618  if (hist->GetDimension()<3) nbinsz = -1;
1619 
1620  Int_t binx,biny,binz,bin,bin2;
1621 
1622  TString name2 = hist->GetName(); name2 +="_Xreverse";
1623 
1624  TH1 * hist2 = (TH1*) hist->Clone(name2.Data());
1625  hist2->Reset();
1626 
1627  for (binz=0;binz<=nbinsz+1;binz++)
1628  {
1629  for (biny=0;biny<=nbinsy+1;biny++)
1630  {
1631  for (binx=0;binx<=nbinsx+1;binx++)
1632  {
1633  bin = hist->GetBin(binx,biny,binz);
1634  bin2 = hist->GetBin(nbinsx+1-binx,biny,binz);
1635  hist2->SetBinContent(bin2,hist->GetBinContent(bin));
1636  if (hist->GetSumw2N())
1637  {
1638  if (! hist2->GetSumw2N()) hist2->Sumw2();
1639  hist2->SetBinError(bin2,hist->GetBinError(bin));
1640  }
1641  }
1642  }
1643  }
1644  hist2->SetEntries(hist->GetEntries());
1645  return hist2;
1646 }
1647 
1648 
1649 ////////////////////////////////////////////////////////////////////////////////
1650 TH2* PTools::reverseYAxis(TH2* hist)
1651 {
1652  // reverses the Y-Axis of the histogramm
1653  // creates a new histogramm
1654 
1655  Int_t nbinsx = hist->GetNbinsX();
1656  Int_t nbinsy = hist->GetNbinsY();
1657  Int_t nbinsz = hist->GetNbinsZ();
1658 
1659  if (hist->GetDimension()<2) {Error("reverseYAxis","dimension %i to small ... exiting!",hist->GetDimension()<2); exit(EXIT_FAILURE);}
1660  if (hist->GetDimension()<3) nbinsz = -1;
1661 
1662  Int_t binx,biny,binz,bin,bin2;
1663 
1664  TString name2 = hist->GetName(); name2 +="_Yreverse";
1665 
1666  TH2 * hist2 = (TH2*) hist->Clone(name2.Data());
1667  hist2->Reset();
1668 
1669  for (binz=0;binz<=nbinsz+1;binz++)
1670  {
1671  for (biny=0;biny<=nbinsy+1;biny++)
1672  {
1673  for (binx=0;binx<=nbinsx+1;binx++)
1674  {
1675  bin = hist->GetBin(binx,biny,binz);
1676  bin2 = hist->GetBin(binx,nbinsy+1-biny,binz);
1677  hist2->SetBinContent(bin2,hist->GetBinContent(bin));
1678  if (hist->GetSumw2N())
1679  {
1680  if (! hist2->GetSumw2N()) hist2->Sumw2();
1681  hist2->SetBinError(bin2,hist->GetBinError(bin));
1682  }
1683  }
1684  }
1685  }
1686  hist2->SetEntries(hist->GetEntries());
1687  return hist2;
1688 }
1689 
1690 
1691 ////////////////////////////////////////////////////////////////////////////////
1692 
1693 TH3* PTools::reverseZAxis(TH3* hist)
1694 {
1695  // reverses the Z-Axis of the histogramm
1696  // creates a new histogramm
1697 
1698  Int_t nbinsx = hist->GetNbinsX();
1699  Int_t nbinsy = hist->GetNbinsY();
1700  Int_t nbinsz = hist->GetNbinsZ();
1701 
1702  if (hist->GetDimension()<2) {Error("reverseZAxis","dimension %i to small ... exiting!",hist->GetDimension()<2); exit(EXIT_FAILURE);}
1703  if (hist->GetDimension()<3) {Error("reverseZAxis","dimension %i to small ... exiting!",hist->GetDimension()<2); exit(EXIT_FAILURE);}
1704 
1705  Int_t binx,biny,binz,bin,bin2;
1706 
1707  TString name2 = hist->GetName(); name2 +="_Zreverse";
1708 
1709  TH3 * hist2 = (TH3*) hist->Clone(name2.Data());
1710  hist2->Reset();
1711 
1712  for (binz=0;binz<=nbinsz+1;binz++)
1713  {
1714  for (biny=0;biny<=nbinsy+1;biny++)
1715  {
1716  for (binx=0;binx<=nbinsx+1;binx++)
1717  {
1718  bin = hist->GetBin(binx,biny,binz);
1719  bin2 = hist->GetBin(binx,biny,nbinsz+1-binz);
1720  hist2->SetBinContent(bin2,hist->GetBinContent(bin));
1721  if (hist->GetSumw2N())
1722  {
1723  if (! hist2->GetSumw2N()) hist2->Sumw2();
1724  hist2->SetBinError(bin2,hist->GetBinError(bin));
1725  }
1726  }
1727  }
1728  }
1729  hist2->SetEntries(hist->GetEntries());
1730  return hist2;
1731 }
1732 
1733 ////////////////////////////////////////////////////////////////////////////////
1734 
1735 void PTools::plotPolarAxis(Double_t min, Double_t max, Int_t divisions, Float_t direction)
1736 {
1737  // plots polar axis
1738  // starting from min
1739  // ending at max
1740  // pointing in direction (angle [rad])
1741  // with n divisions
1742 
1743  direction*=(acos(-1.)/180.0);
1744  Float_t radius = 0.58;
1745 
1746  TGaxis *axis1 = new TGaxis(0,0, radius*cos(direction) ,radius*sin(direction) ,min,max,divisions,"+");
1747  axis1->SetLabelColor(1);
1748  axis1->Draw();
1749  // TGaxis *axis2 = new TGaxis(0.002,0, (radius+0.002)*cos(direction) , (radius+0.002)*sin(direction) ,min,max,divisions,"+");
1750  // axis2->Draw();
1751 }
1752 
1753 ////////////////////////////////////////////////////////////////////////////////
1754 
1755 void PTools::plotPolarAxis(TH2* hist, Int_t divisions, Float_t direction)
1756 {
1757  // plots polar axis using the limits of hist
1758  // see plotPolarAxis
1759  if (!hist)
1760  {
1761  Error("plotPolarAxis","hist has a NULL pointer ... nothing done");
1762  return;
1763  }
1764  plotPolarAxis(hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax(),divisions,direction);
1765 
1766 }
1767 ////////////////////////////////////////////////////////////////////////////////
1768 
1769 void PTools::plotPolarGrid(Int_t division)
1770 {
1771  // plots in polar coordiates
1772  // a circular grid
1773  // with the hades naming of phi angles
1774  //
1775 
1776  if (division == 0)
1777  {
1778  Error("plotPolarGrid","division of %i not realistic ... nothing done",division);
1779  return;
1780  }
1781 
1782  Float_t radius = 0.58;
1783  TEllipse *kDeg;
1784  TEllipse *kDeg2;
1785  {
1786  for (Int_t iter = 1; iter <= division; iter++)
1787  {
1788  kDeg = new TEllipse(0,0,(radius/division)*iter);
1789  kDeg->SetLineWidth(2);
1790  kDeg->SetLineColor(10);
1791  kDeg->Draw();
1792  kDeg2 = new TEllipse(0,0,(radius/division)*iter);
1793  kDeg2->SetLineWidth(1);
1794  kDeg2->Draw();
1795  }
1796  }
1797 }
1798 
1799 
1800 ////////////////////////////////////////////////////////////////////////////////
1801 
1803 {
1804  // plots in polar coordiates
1805  // a line axis grid
1806  // with the hades naming of phi angles
1807 
1808  TLine *lDeg[6];
1809  TLine *lDeg2[6];
1810  TString label[6]={"180#circ","120#circ","60#circ","0#circ","300#circ","240#circ"};
1811  TLatex * tex[6];
1812 
1813  for (Int_t iter = 0; iter < 6; iter++)
1814  {
1815  Float_t radius = 0.65;
1816  lDeg[iter] = new TLine(0,0,radius*cos(iter*60*acos(-1.)/180),radius*sin(iter*60*acos(-1.)/180));
1817  //lDeg[iter]->SetLineStyle(2);
1818  lDeg[iter]->SetLineWidth(2);
1819  lDeg[iter]->SetLineColor(10);
1820  lDeg[iter]->Draw();
1821  lDeg2[iter] = new TLine(0,0,radius*cos(iter*60*acos(-1.)/180),radius*sin(iter*60*acos(-1.)/180));
1822  // lDeg2[iter]->SetLineStyle(2);
1823  lDeg2[iter]->SetLineWidth(1);
1824  lDeg2[iter]->SetLineColor(1);
1825  lDeg2[iter]->Draw();
1826 
1827  radius+=0.07;
1828  tex[iter] = new TLatex(radius*cos(iter*60*acos(-1.)/180),radius*sin(iter*60*acos(-1.)/180),label[iter].Data());
1829  tex[iter]->Draw();
1830  }
1831 }
1832 
1833 
1834 /////////////////////////////////////////////////////////////////////////////////
1835 
1836 void PTools::saveToPdf(TCanvas* canvas,TString path,TString filename,Bool_t separate, Int_t selection)
1837 {
1838  // saves canvas to pdf
1839  // to path
1840  // using filename
1841  // if separate is used
1842  // each sub pad is printed to its own file
1843  // (requieres external function ps2pdf)
1844  // Thanks to Jochen Markert, GSI
1845  // selection selects one specific subpad number if selection > 0
1846  // produced now output in compatiblity mode 1.4 (Acrobat 5 and higher)
1847  saveToPdf((TPad*) canvas,path,filename,separate, selection);
1848 }
1849 
1850 /////////////////////////////////////////////////////////////////////////////////
1851 
1852 void PTools::saveToPdf(TPad* pad,TString path,TString filename,Bool_t separate, Int_t selection)
1853 {
1854  // saves pad to pdf
1855  // to path
1856  // using filename
1857  // if separate is used
1858  // each sub pad is printed to its own file
1859  // (requieres external function ps2pdf)
1860  // Thanks to Jochen Markert, GSI
1861  // selection selects one specific subpad number if selection > 0
1862  // produced now output in compatiblity mode 1.4 (Acrobat 5 and higher)
1863 
1864  if (filename.IsNull()) filename=pad->GetName();
1865 
1866  TString File =filename;
1867  TString Path =path;
1868  if (!Path.EndsWith("/") && !Path.IsNull())
1869  {
1870  Path = Path + "/";
1871  }
1872  TString command ="";
1873  TString totalin ="";
1874  TString totalout="";
1875  TString converter="ps2pdf -dCompatibilityLevel=1.4 -dEmbedAllFonts=true";
1876 
1877  TString check = TString("which ")+ converter + TString(" > /dev/null");
1878 
1879  if (gSystem->Exec(check.Data()))
1880  {
1881  Error("saveToPdf","external program \"%s\" not available ... nothing is done",converter.Data());
1882  return;
1883  }
1884 
1885  File.ReplaceAll(".ps","");
1886  if(!separate)
1887  {
1888  totalin = Path + File + ".ps";
1889  totalout= Path + File + ".pdf";
1890  pad->SaveAs(totalin.Data());
1891  command= converter + " " + totalin + " " + totalout;
1892  gSystem->Exec(command.Data());
1893  command= "rm " + totalin;
1894  gSystem->Exec(command.Data());
1895  }else{
1896  TString subpad="";
1897  Int_t npads= pad->GetListOfPrimitives()->GetSize();
1898  for(Int_t i=1;i<=npads;i++)
1899  {
1900  if (selection > 0 && i!=selection)
1901  {
1902  continue;
1903  }
1904  subpad="";
1905  subpad+=i;
1906  totalin = Path + File + "_" + subpad + ".ps";
1907  totalout= Path + File + "_" + subpad + ".pdf";
1908  pad->cd(i);
1909  TPad *clone = (TPad*) gPad->Clone();
1910  Bool_t batch = gROOT->IsBatch();
1911  gROOT->SetBatch();
1912  TCanvas *dummy = new TCanvas("dummy","dummy",1000,800);
1913  dummy->cd();
1914  clone->Draw();
1915  clone->SetPad(0,0,1,1);
1916  dummy->SaveAs(totalin.Data());
1917  command= converter + " " + totalin + " " + totalout;
1918  gSystem->Exec(command.Data());
1919  command= "rm " + totalin;
1920  gSystem->Exec(command.Data());
1921  dummy->Close();
1922  gROOT->SetBatch(batch);
1923  }
1924  }
1925 }
1926 
1927 /////////////////////////////////////////////////////////////////////////////////
1928 
1929 void PTools::saveToPng(TCanvas* canvas,TString path,TString filename,Bool_t separate, Int_t selection)
1930 {
1931  // saves canvas to png
1932  // to path
1933  // using filename
1934  // if separate is used
1935  // each sub pad is printed to its own file
1936  // (requieres external function convert)
1937  // Thanks to Jochen Markert, GSI
1938  // selection selects one specific subpad number if selection > 0
1939 
1940  saveToPng((TPad*)canvas,path, filename, separate, selection);
1941 }
1942 
1943 /////////////////////////////////////////////////////////////////////////////////
1944 
1945 void PTools::saveToPng(TPad* pad,TString path,TString filename,Bool_t separate, Int_t selection)
1946 {
1947  // saves pad to png
1948  // to path
1949  // using filename
1950  // if separate is used
1951  // each sub pad is printed to its own file
1952  // (requieres external function convert)
1953  // Thanks to Jochen Markert, GSI
1954  // selection selects one specific subpad number if selection > 0
1955 
1956  if (filename.IsNull()) {filename=pad->GetName();}
1957 
1958  TString File =filename;
1959  TString Path =path;
1960  if (!Path.EndsWith("/") && !Path.IsNull())
1961  {
1962  Path = Path + "/";
1963  }
1964  TString command ="";
1965  TString totalin ="";
1966  TString totalout="";
1967  TString converter="convert";
1968 
1969  TString check = TString("which ")+ converter + TString(" > /dev/null");
1970 
1971  if (gSystem->Exec(check.Data()))
1972  {
1973  Error("saveToPng","external program \"%s\" not available ... nothing is done",converter.Data());
1974  return;
1975  }
1976 
1977  File.ReplaceAll(".png","");
1978  if(!separate)
1979  {
1980  totalin = Path + File + ".ps";
1981  totalout= Path + File + ".png";
1982  pad->SaveAs(totalin.Data());
1983  command= converter + " " + totalin + " " + totalout;
1984  gSystem->Exec(command.Data());
1985  command= converter + " -rotate 90 " + totalout + " " + totalout;
1986  gSystem->Exec(command.Data());
1987  command= "rm " + totalin;
1988  gSystem->Exec(command.Data());
1989  }else{
1990  TString subpad="";
1991  Int_t npads= pad->GetListOfPrimitives()->GetSize();
1992  for(Int_t i=1;i<=npads;i++)
1993  {
1994  if (selection > 0 && i!=selection)
1995  {
1996  continue;
1997  }
1998  subpad="";
1999  subpad+=i;
2000  totalin = Path + File + "_" + subpad + ".ps";
2001  totalout= Path + File + "_" + subpad + ".png";
2002  pad->cd(i);
2003  TPad *clone = (TPad*) gPad->Clone();
2004  Bool_t batch = gROOT->IsBatch();
2005  gROOT->SetBatch();
2006  TCanvas *dummy = new TCanvas("dummy","dummy",1000,800);
2007  dummy->cd();
2008  clone->Draw();
2009  clone->SetPad(0,0,1,1);
2010  dummy->SaveAs(totalin.Data());
2011  command= converter + " " + totalin + " " + totalout;
2012  gSystem->Exec(command.Data());
2013  command= converter + " -rotate 90 " + totalout + " " + totalout;
2014  gSystem->Exec(command.Data());
2015  command= "rm " + totalin;
2016  gSystem->Exec(command.Data());
2017  dummy->Close();
2018  gROOT->SetBatch(batch);
2019  }
2020  }
2021 }
2022 
2023 /////////////////////////////////////////////////////////////////////////////////
2024 
2025 void PTools::saveGifToPdf(TCanvas* canvas,TString path,TString filename,Bool_t separate, Int_t selection)
2026 {
2027  // saves canvas to gif
2028  // to path
2029  // using filename
2030  // if separate is used
2031  // each sub pad is printed to its own file
2032  // (requieres external function convert)
2033  // Thanks to Jochen Markert, GSI
2034  // selection selects one specific subpad number if selection > 0
2035 
2036  saveGifToPdf((TPad*)canvas , path, filename, separate, selection);
2037 }
2038 
2039 /////////////////////////////////////////////////////////////////////////////////
2040 
2041 void PTools::saveGifToPdf(TPad* pad,TString path,TString filename,Bool_t separate, Int_t selection)
2042 {
2043  // saves pad to gif
2044  // to path
2045  // using filename
2046  // if separate is used
2047  // each sub pad is printed to its own file
2048  // (requieres external function convert)
2049  // Thanks to Jochen Markert, GSI
2050  // selection selects one specific subpad number if selection > 0
2051 
2052  if (filename.IsNull()) filename=pad->GetName();
2053 
2054  TString File =filename;
2055  TString Path =path;
2056  if (!Path.EndsWith("/") && !Path.IsNull())
2057  {
2058  Path = Path + "/";
2059  }
2060  TString command ="";
2061  TString totalin ="";
2062  TString totalout="";
2063  TString converter="convert";
2064  TString check = TString("which ")+ converter + TString(" > /dev/null");
2065 
2066  if (gSystem->Exec(check.Data()))
2067  {
2068  Error("saveGifToPdf","external program \"%s\" not available ... nothing is done",converter.Data());
2069  return;
2070  }
2071 
2072  File.ReplaceAll(".pdf","");
2073  if(!separate)
2074  {
2075  totalin = Path + File + ".gif";
2076  totalout= Path + File + ".pdf";
2077  pad->SaveAs(totalin.Data());
2078  command= converter + " " + totalin + " " + totalout;
2079  gSystem->Exec(command.Data());
2080  command= "rm " + totalin;
2081  gSystem->Exec(command.Data());
2082  }
2083  else
2084  {
2085  TString subpad="";
2086  Int_t npads= pad->GetListOfPrimitives()->GetSize();
2087  for(Int_t i=1;i<=npads;i++)
2088  {
2089  if (selection > 0 && i!=selection)
2090  {
2091  continue;
2092  }
2093  subpad="";
2094  subpad+=i;
2095  totalin = Path + File + "_" + subpad + ".ps";
2096  totalout= Path + File + "_" + subpad + ".pdf";
2097  pad->cd(i);
2098  TPad *clone = (TPad*) gPad->Clone();
2099  Bool_t batch = gROOT->IsBatch();
2100  gROOT->SetBatch();
2101  TCanvas *dummy = new TCanvas("dummy","dummy",1000,800);
2102  dummy->cd();
2103  clone->Draw();
2104  clone->SetPad(0,0,1,1);
2105  dummy->SaveAs(totalin.Data());
2106  command= converter + " " + totalin + " " + totalout;
2107  gSystem->Exec(command.Data());
2108  command= "rm " + totalin;
2109  gSystem->Exec(command.Data());
2110  dummy->Close();
2111  gROOT->SetBatch(batch);
2112  }
2113  }
2114 }
2115 
2116 /////////////////////////////////////////////////////////////////////////////////
2117 
2118 Int_t PTools::getColorJM(Int_t i)
2119 {
2120  // Thanks to Jochen Markert, GSI
2121  Int_t colors[] ={2,4,6,8,38,46,14,1,30,43};
2122  i%=((int)(sizeof(colors)/sizeof(Int_t)));
2123  return colors[i];
2124 }
2125 
2126 /////////////////////////////////////////////////////////////////////////////////
2127 
2128 Int_t PTools::getMarkerJM(Int_t i)
2129 {
2130  // Thanks to Jochen Markert, GSI
2131  Int_t style[] ={20,21,22,23,24,25,26,27,28,29};
2132  i%=((int)(sizeof(style)/sizeof(Int_t)));
2133  return style[i];
2134 }
2135 
2136 /////////////////////////////////////////////////////////////////////////////////
2137 
2138 void PTools::setGraph(TGraph* graph,Int_t mycolorindex,Int_t markerstyle,Int_t markercolor,Float_t markersize,Int_t linecolor)
2139 {
2140  // Thanks to Jochen Markert, GSI
2141  if(mycolorindex<0)
2142  {
2143  graph->SetMarkerColor(markercolor);
2144  graph->SetMarkerSize(markersize);
2145  graph->SetMarkerStyle(markerstyle);
2146  graph->SetLineColor(linecolor);
2147  }
2148  else
2149  {
2150  if (markercolor>=0)graph->SetMarkerColor(PTools::getColorJM(mycolorindex));
2151  else if(markercolor<0) graph->SetMarkerColor(PTools::getColorJM(-markercolor));
2152  graph->SetMarkerSize(markersize);
2153  if (markerstyle>=0)graph->SetMarkerStyle(PTools::getMarkerJM(mycolorindex));
2154  else if(markerstyle<0) graph->SetMarkerStyle(PTools::getMarkerJM(-markerstyle));
2155  graph->SetLineColor(linecolor);
2156  }
2157 }
2158 
2159 /////////////////////////////////////////////////////////////////////////////////
2160 
2161 void PTools::setHist(TH1* hist,Int_t mycolorindex,Int_t markerstyle,Int_t markercolor,Float_t markersize,Int_t linecolor)
2162 {
2163  // Thanks to Jochen Markert, GSI
2164  if(mycolorindex==-99)
2165  {
2166  hist->SetMarkerColor(markercolor);
2167  hist->SetMarkerSize(markersize);
2168  hist->SetMarkerStyle(markerstyle);
2169  hist->SetLineColor(linecolor);
2170  }
2171  else
2172  {
2173  if (markercolor>=0)hist->SetMarkerColor(PTools::getColorJM(mycolorindex));
2174  else if(markercolor<0) hist->SetMarkerColor(PTools::getMarkerJM(-markercolor));
2175  hist->SetMarkerSize(markersize);
2176  if (markerstyle>=0)hist->SetMarkerStyle(PTools::getMarkerJM(mycolorindex));
2177  else if(markerstyle<0) hist->SetMarkerStyle(PTools::getMarkerJM(-markerstyle));
2178  hist->SetLineColor(linecolor);
2179  }
2180 }
2181 
2182 /////////////////////////////////////////////////////////////////////////////////
2183 
2184 TLegend* PTools::plotLegend(TString pos,TString Title,
2185  Float_t scaleX,Float_t scaleY,
2186  Float_t offsetX,Float_t offsetY,
2187  TString Comment,
2188  Int_t commencolor)
2189 {
2190  // Thanks to Jochen Markert, GSI
2191  Float_t left =gPad->GetLeftMargin()*1.15;
2192  Float_t right =1-gPad->GetRightMargin();
2193  Float_t top =1-gPad->GetTopMargin();
2194  Float_t bottom=gPad->GetBottomMargin()*1.15;
2195  Float_t mid =gPad->GetLeftMargin() + (1-(gPad->GetRightMargin()+gPad->GetLeftMargin()))/2;
2196  Float_t width =(right-left)/2;
2197  Float_t heith =(top-bottom)/2;
2198  TLegend* legend = NULL;
2199  TLine* dummy=new TLine();
2200  dummy->SetLineColor(10);
2201 
2202  if(pos.CompareTo("left_top")==0) legend=new TLegend(left+offsetX,top+offsetY-(scaleY*heith),left+offsetX+(scaleX*width),top+offsetY,Title.Data()); // left top
2203  if(pos.CompareTo("mid_top")==0) legend=new TLegend(mid+offsetX-((scaleX*width)/2),top+offsetY-(scaleY*heith),mid+offsetX+((scaleX*width)/2),top+offsetY,Title.Data()); // mid up
2204  if(pos.CompareTo("right_top")==0) legend=new TLegend(right+offsetX-(scaleX*width),top+offsetY-(scaleY*heith),right+offsetX,top+offsetY,Title.Data()); // right top
2205  if(pos.CompareTo("left_bottom")==0) legend=new TLegend(left+offsetX,bottom+offsetY,left+offsetX+(scaleX*width),bottom+offsetY+(scaleY*heith),Title.Data()); // left bottom
2206  if(pos.CompareTo("mid_bottom")==0) legend=new TLegend(mid+offsetX-((scaleX*width)/2),bottom+offsetY,mid+offsetX+((scaleX*width)/2),bottom+offsetY+(scaleY*heith),Title.Data());// mid down
2207  if(pos.CompareTo("right_bottom")==0)legend=new TLegend(right+offsetX-(scaleX*width),bottom+offsetY,right+offsetX,bottom+offsetY+(scaleY*heith),Title.Data()); // right bottom
2208 
2209  if (!legend) return NULL;
2210  legend->SetFillStyle(0);
2211  legend->SetBorderSize(0);
2212  legend->SetMargin(0.15);
2213 
2214  if(Comment.CompareTo("")!=0)
2215  { // comment below header
2216  TLegendEntry* entry=legend->AddEntry(dummy,Comment.Data());
2217  entry->SetTextColor(1);
2218  entry->SetTextFont(62);
2219  entry->SetOption("l");
2220  }
2221  return legend;
2222 }
2223 
2224 /////////////////////////////////////////////////////////////////////////////////
2225 
2226 TLegendEntry* PTools::setLegendEntry(TLegend* legend,TObject* object,TString label,Int_t col,TString opt)
2227 {
2228  // add entry for object with label and color and option to legend
2229  //
2230  // Thanks to Jochen Markert, GSI
2231  TLegendEntry* entry=legend->AddEntry((TObject*)object,label.Data());
2232  entry->SetTextColor(col);
2233  entry->SetOption(opt.Data());
2234  return entry;
2235 }
2236 
2237 /////////////////////////////////////////////////////////////////////////////////
2238 
2239 TLatex* PTools::plotTopLegend(const Char_t* label,Float_t x,Float_t y,Float_t size,Int_t color)
2240 {
2241  // Thanks to Jochen Markert, GSI
2242  // coordinates in NDC!
2243  if(x<0||y<0)
2244  { // defaults
2245  x=gPad->GetLeftMargin()*1.15;
2246  y=(1-gPad->GetTopMargin())*1.02;
2247  }
2248  TLatex* text=new TLatex(x,y,label);
2249  text->SetTextSize(size);
2250  text->SetNDC();
2251  text->SetTextColor(color);
2252  text->Draw();
2253  return text;
2254 }
2255 
2256 /////////////////////////////////////////////////////////////////////////////////
2257 
2258 Double_t PTools::getMeanErrorRangeUser(TH1* hist, Axis_t minX, Axis_t maxX, TString pos)
2259 {
2260  // calculates the error of arithmetic mean of a TH1
2261  // in a range between minX and maxX
2262  // position: determines the value of the bin taken
2263  // "center" : bin center value [default]
2264  // "up" : bin upper edge
2265  // "low" : bin lower edge value
2266 
2267  if (!hist) {::Error("getMeanErrorRangeUser","no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2268  return getMeanErrorRange(hist, hist->FindBin(minX), hist->FindBin(maxX),pos);
2269 }
2270 
2271 /////////////////////////////////////////////////////////////////////////////////
2272 
2273 Double_t PTools::getMeanErrorRange(TH1* hist, Int_t minX, Int_t maxX, TString pos)
2274 {
2275  // calculates the error of arithmetic mean of a TH1
2276  // in a range between bin minX and bin maxX
2277  // position: determines the value of the bin taken
2278  // "center" : bin center value [default]
2279  // "up" : bin upper edge
2280  // "low" : bin lower edge value
2281 
2282  pos.ToLower();
2283  Int_t p=-10;
2284 
2285  if (pos.CompareTo("center")==0) p=0;
2286  if (pos.CompareTo("up")==0) p=1;
2287  if (pos.CompareTo("low")==0) p=-1;
2288 
2289  if (p==-10) { Error("getMeanErrorRange","wrong position parameter %s",pos.Data());exit(EXIT_FAILURE);}
2290 
2291  if (!hist) {::Error("getMeanErrorRange","no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2292 
2293  Int_t nbinsx = hist->GetNbinsX();
2294 
2295  if (hist->GetDimension()>2) {::Error("getMeanErrorRange","cannot be used for TH2 and TH3"); exit(EXIT_FAILURE);}
2296 
2297  Int_t binx;
2298 
2299  Double_t bin,binval=0,binError;
2300  Double_t sumw2=0;
2301  Double_t sum=0;
2302  Double_t sumv=0;
2303 
2304  for (binx=0;binx<=nbinsx+1;binx++)
2305  {
2306  if (minX>binx) continue;
2307  if (maxX<binx) continue;
2308  switch (p)
2309  {
2310  case 0:
2311  binval=hist->GetXaxis()->GetBinCenter(binx);
2312  break;
2313  case -1:
2314  binval=hist->GetXaxis()->GetBinLowEdge(binx);
2315  break;
2316  case 1:
2317  binval=hist->GetXaxis()->GetBinUpEdge(binx);
2318  break;
2319  default:
2320  binval=0;
2321  break;
2322  }
2323  bin = hist->GetBinContent(binx);
2324  sum+=bin;
2325  sumv+=(bin*binval);
2326  }
2327 
2328  for (binx=0;binx<=nbinsx+1;binx++)
2329  {
2330  if (minX>binx) continue;
2331  if (maxX<binx) continue;
2332  switch (p)
2333  {
2334  case 0:
2335  binval=hist->GetXaxis()->GetBinCenter(binx);
2336  break;
2337  case -1:
2338  binval=hist->GetXaxis()->GetBinLowEdge(binx);
2339  break;
2340  case 1:
2341  binval=hist->GetXaxis()->GetBinUpEdge(binx);
2342  break;
2343  default:
2344  binval=0;
2345  break;
2346  }
2347 
2348  bin = hist->GetBinContent(binx);
2349  binError = hist->GetBinError(binx);
2350  sumw2+=( ((binval*sum)-sumv)*binError*((binval*sum)-sumv)*binError);
2351  }
2352 
2353  // cout << sumv << " " << (sumv/sum) << endl;
2354 
2355  sumw2=(((sum*sum*sum*sum)>0) || ((sum*sum*sum*sum)<0))?sumw2/(sum*sum*sum*sum):-1;
2356  return (sumw2<0)?-1: ::std::sqrt(sumw2);
2357 }
2358 
2359 ////////////////////////////////////////////////////////////////////////////////
2360 
2361 Double_t PTools::getMeanRangeUser(TH1* hist, Axis_t minX, Axis_t maxX, TString pos)
2362 {
2363  // calculates the arithmetic mean of a TH1
2364  // in a range between minX and maxX
2365  // position: determines the value of the bin taken
2366  // "center" : bin center value [default]
2367  // "up" : bin upper edge
2368  // "low" : bin lower edge value
2369 
2370  if (!hist) {::Error("getMeanErrorRangeUser","no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2371  return getMeanErrorRange(hist, hist->FindBin(minX), hist->FindBin(maxX),pos);
2372 }
2373 
2374 /////////////////////////////////////////////////////////////////////////////////
2375 
2376 Double_t PTools::getMeanRange(TH1* hist, Int_t minX, Int_t maxX, TString pos)
2377 {
2378  // calculates the arithmetic mean of a TH1
2379  // in a range between bin minX and bin maxX
2380  // position: determines the value of the bin taken
2381  // "center" : bin center value [default]
2382  // "up" : bin upper edge
2383  // "low" : bin lower edge value
2384 
2385  pos.ToLower();
2386  Int_t p=-10;
2387 
2388  if (pos.CompareTo("center")==0) p=0;
2389  if (pos.CompareTo("up")==0) p=1;
2390  if (pos.CompareTo("low")==0) p=-1;
2391 
2392  if (p==-10) { Error("getMeanErrorRange","wrong position parameter %s",pos.Data());exit(EXIT_FAILURE);}
2393 
2394  if (!hist) {::Error("getMeanErrorRange","no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2395 
2396  Int_t nbinsx = hist->GetNbinsX();
2397 
2398  if (hist->GetDimension()>2) {::Error("getMeanErrorRange","cannot be used for TH2 and TH3"); exit(EXIT_FAILURE);}
2399 
2400  Int_t binx;
2401 
2402  Double_t bin,binval;
2403  Double_t sum=0;
2404  Double_t sumv=0;
2405 
2406  for (binx=0;binx<=nbinsx+1;binx++)
2407  {
2408  if (minX>binx) continue;
2409  if (maxX<binx) continue;
2410  switch (p)
2411  {
2412  case 0:
2413  binval=hist->GetXaxis()->GetBinCenter(binx);
2414  break;
2415  case -1:
2416  binval=hist->GetXaxis()->GetBinLowEdge(binx);
2417  break;
2418  case 1:
2419  binval=hist->GetXaxis()->GetBinUpEdge(binx);
2420  break;
2421  default:
2422  binval=0;
2423  break;
2424  }
2425 
2426  bin = hist->GetBinContent(binx);
2427  sum+=bin;
2428  sumv+=(bin*binval);
2429  }
2430 
2431  return (sum>0 || sum <0)?sumv/sum:-1;
2432 }
2433 
2434 ////////////////////////////////////////////////////////////////////////////////
2435 
2436 void PTools::sqrt(TH1* hist)
2437 {
2438  // calculates the sqrt of each histogram bin
2439 
2440  if (! hist->GetSumw2N()) hist->Sumw2();
2441 
2442  Int_t nbinsx = hist->GetNbinsX();
2443  Int_t nbinsy = hist->GetNbinsY();
2444  Int_t nbinsz = hist->GetNbinsZ();
2445 
2446  if (hist->GetDimension()<3) nbinsz = -1;
2447  if (hist->GetDimension()<2) nbinsy = -1;
2448 
2449  Int_t binx,biny,binz,bin;
2450 
2451  for (binz=0;binz<=nbinsz+1;binz++)
2452  {
2453  if (nbinsz!=-1)
2454  {
2455  if (binz == 0 ) continue;
2456  if (binz == nbinsz+1) continue;
2457  }
2458  for (biny=0;biny<=nbinsy+1;biny++)
2459  {
2460  if (nbinsy!=-1)
2461  {
2462  if (biny == 0 ) continue;
2463  if (biny == nbinsy+1) continue;
2464  }
2465  for (binx=0;binx<=nbinsx+1;binx++)
2466  {
2467  if (nbinsx!=-1)
2468  {
2469  if (binx == 0 ) continue;
2470  if (binx == nbinsx+1) continue;
2471  }
2472  bin = hist->GetBin(binx,biny,binz);
2473 
2474  if (hist->GetBinContent(bin) < 0)
2475  {
2476  Error("sqrt()","histogram %s contains negative values, cannot perform sqrt() operation ... exiting",
2477  hist->GetName());
2478  exit(EXIT_FAILURE);
2479  }
2480  }
2481  }
2482  }
2483 
2484  Stat_t val=0;
2485  Stat_t err=0;
2486  for (binz=0;binz<=nbinsz+1;binz++)
2487  {
2488  if (nbinsz!=-1)
2489  {
2490  if (binz == 0 ) continue;
2491  if (binz == nbinsz+1) continue;
2492  }
2493  for (biny=0;biny<=nbinsy+1;biny++)
2494  {
2495  if (nbinsy!=-1)
2496  {
2497  if (biny == 0 ) continue;
2498  if (biny == nbinsy+1) continue;
2499  }
2500  for (binx=0;binx<=nbinsx+1;binx++)
2501  {
2502  if (nbinsx!=-1)
2503  {
2504  if (binx == 0 ) continue;
2505  if (binx == nbinsx+1) continue;
2506  }
2507  bin = hist->GetBin(binx,biny,binz);
2508 
2509  val = hist->GetBinContent(bin);
2510  err = hist->GetBinError(bin);
2511 
2512  hist->SetBinContent(bin, ::std::sqrt(val));
2513 
2514  if (val==0.0 || ::std::sqrt(val) == 0.0)
2515  {
2516  hist->SetBinError(bin,0);
2517  }
2518  else
2519  {
2520  hist->SetBinError(bin, ( err*0.5 * 1./ ::std::sqrt(val)));
2521  }
2522  }
2523  }
2524  }
2525 
2526 }
2527 
2528 ////////////////////////////////////////////////////////////////////////////////
2529 
2530 TNamed* PTools::Clone(TNamed *name, TString newname, TString title)
2531 {
2532  // Clones named object name and sets the name no newname and its title to title
2533  // if newname and or title are empty
2534  // title and name are extended by "_clone"
2535 
2536  if (newname.IsNull())
2537  {
2538  newname=name->GetName();
2539  newname+="_clone";
2540  }
2541  if (title.IsNull())
2542  {
2543  title=name->GetTitle();
2544  title+="_clone";
2545  }
2546 
2547  TNamed *named = (TNamed*) name->Clone(newname.Data());
2548  named->SetTitle(title.Data());
2549 
2550  return named;
2551 }
2552 
2553 //memomory leak?
2554 ////////////////////////////////////////////////////////////////////////////////
2555 
2556 TH1* PTools::copyToTHxD(TH1 * hist)
2557 {
2558  // copies any THx histogramm to THxD histograms
2559  // you have to cast to the corresponding type
2560  // attaches to name "_THxD"
2561 
2562  if (! hist)
2563  {
2564  ::Error("copyToTHxD","histogram has NULL pointer ... exiting");
2565  exit(EXIT_FAILURE);
2566  return NULL;
2567  }
2568 
2569  Int_t nbinsx = hist->GetNbinsX();
2570  Int_t nbinsy = hist->GetNbinsY();
2571  Int_t nbinsz = hist->GetNbinsZ();
2572 
2573  TH1* histD = NULL;
2574 
2575  switch(hist->GetDimension())
2576  {
2577  case 1:
2578  {
2579  Int_t s = 0;
2580  s =
2581  ((int)(hist->GetXaxis()->GetXbins()->fN > 0)) * 1;
2582  TString name = hist->GetName()+TString("_TH1D");
2583 
2584  switch(s)
2585  {
2586  case 0:
2587  histD = new TH1D(name.Data(),hist->GetTitle(),
2588  nbinsx,
2589  hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax());
2590  break;
2591  case 1:
2592  histD = new TH1D(name.Data(),hist->GetTitle(),
2593  nbinsx,
2594  hist->GetXaxis()->GetXbins()->fArray);
2595  break;
2596  default:
2597 
2598  break;
2599  }
2600  break;
2601  }
2602  case 2:
2603  {
2604  Int_t s = 0;
2605  s = ((int)(hist->GetXaxis()->GetXbins()->fN > 0)) * 1 + ((int)( hist->GetYaxis()->GetXbins()->fN > 0)) * 10;
2606  TString name = hist->GetName()+TString("_TH2D");
2607 
2608  switch(s)
2609  {
2610  case 0:
2611  histD = new TH2D(name.Data(),hist->GetTitle(),
2612  nbinsx,
2613  hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
2614  nbinsy,
2615  hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
2616  break;
2617  case 1:
2618  histD = new TH2D(name.Data(),hist->GetTitle(),
2619  nbinsx,
2620  hist->GetXaxis()->GetXbins()->fArray,
2621  nbinsy,
2622  hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
2623 
2624  break;
2625  case 10:
2626  histD = new TH2D(name.Data(),hist->GetTitle(),
2627  nbinsx,
2628  hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
2629  nbinsy,
2630  hist->GetYaxis()->GetXbins()->fArray);
2631  break;
2632  default:
2633 
2634  break;
2635  }
2636  break;
2637  }
2638  case 3:
2639  {
2640  TString name = hist->GetName()+TString("_TH3D");
2641 
2642  histD = new TH3D(name.Data(),hist->GetTitle(),
2643  nbinsx,
2644  hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
2645  nbinsy,
2646  hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax(),
2647  nbinsz,
2648  hist->GetZaxis()->GetXmin(),hist->GetZaxis()->GetXmax());
2649 
2650  importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
2651  importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
2652  importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
2653  break;
2654  }
2655  }
2656 
2657  importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
2658  importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
2659  importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
2660 
2661  histD->SetEntries(hist->GetEntries());
2662 
2663  if (hist->GetDimension()<2) nbinsy = -1;
2664  if (hist->GetDimension()<3) nbinsz = -1;
2665 
2666  Int_t binx,biny,binz,bin;
2667 
2668  for (binz=0;binz<=nbinsz+1;binz++)
2669  {
2670  for (biny=0;biny<=nbinsy+1;biny++)
2671  {
2672  for (binx=0;binx<=nbinsx+1;binx++)
2673  {
2674  bin = hist->GetBin(binx,biny,binz);
2675  histD->SetBinContent(bin, hist->GetBinContent(bin));
2676  if (hist->GetSumw2N())
2677  {
2678  histD->SetBinError(bin,hist->GetBinError(bin));
2679  }
2680  }
2681  }
2682  }
2683  return histD;
2684 }
2685 
2686 ////////////////////////////////////////////////////////////////////////////////
2687 
2688 TH1D PTools::copyToTH1D(TH1 * hist)
2689 {
2690  // copy any TH1 histogramm to TH1D histogramm
2691 
2692  TH1D* tmp = (TH1D*) copyToTHxD(hist);
2693  TH1D h(*tmp);
2694  tmp->Delete();
2695  return TH1D(h);
2696 }
2697 
2698 ////////////////////////////////////////////////////////////////////////////////
2699 
2700 TH2D PTools::copyToTH2D(TH2 * hist)
2701 {
2702  // copy any TH2 histogramm to TH2D histogramm
2703  TH2D* tmp = (TH2D*) copyToTHxD(hist);
2704  TH2D h(*tmp);
2705  tmp->Delete();
2706  return TH2D(h);
2707 }
2708 
2709 ////////////////////////////////////////////////////////////////////////////////
2710 
2711 TH3D PTools::copyToTH3D(TH3 * hist)
2712 {
2713  // copy any TH3 histogramm to TH3D histogramm
2714  TH3D* tmp = (TH3D*) copyToTHxD(hist);
2715  TH3D h(*tmp);
2716  tmp->Delete();
2717  return TH3D(h);
2718 }
2719 
2720 ////////////////////////////////////////////////////////////////////////////////
2721 
2722 TH1D* PTools::createTH1D(TH1 * hist)
2723 {
2724  // copy any TH1 histogramm to TH1D histogramm
2725  // returned histogram has to be deleted by user
2726 
2727  return (hist) ? (TH1D*) copyToTHxD(hist) : NULL;
2728 }
2729 
2730 ////////////////////////////////////////////////////////////////////////////////
2731 
2732 TH2D* PTools::createTH2D(TH2 * hist)
2733 {
2734  // copy any TH2 histogramm to TH2D histogramm
2735  // returned histogram has to be deleted by user
2736 
2737  return (hist) ? (TH2D*) copyToTHxD(hist) : NULL;
2738 }
2739 
2740 ////////////////////////////////////////////////////////////////////////////////
2741 
2742 TH3D* PTools::createTH3D(TH3 * hist)
2743 {
2744  // copy any TH3 histogramm to TH3D histogramm
2745  // returned histogram has to be deleted by user
2746 
2747  return (hist) ? (TH3D*) copyToTHxD(hist) : NULL;
2748 }
2749 
2750 ////////////////////////////////////////////////////////////////////////////////
2751 
2752 void PTools::importAxisAttributes(TAxis *in, TAxis *out, Bool_t includeLabels)
2753 {
2754 // Copy TAxis attributes
2755 
2756  if (!in || !out)
2757  {
2758  Warning("importAxisAttributes","in or output axis is NULL ... nothing done");
2759  }
2760 
2761  out->SetAxisColor (in->GetAxisColor());
2762  out->SetTitleColor (in->GetTitleColor());
2763  out->SetTitleFont (in->GetTitleFont());
2764  out->SetLabelColor (in->GetLabelColor());
2765  out->SetLabelFont (in->GetLabelFont());
2766  out->SetLabelSize (in->GetLabelSize());
2767  out->SetLabelOffset(in->GetLabelOffset());
2768  out->SetTickLength (in->GetTickLength());
2769  out->SetTitle (in->GetTitle());
2770  out->SetTitleOffset(in->GetTitleOffset());
2771  out->SetTitleSize (in->GetTitleSize());
2772  out->SetBit(TAxis::kCenterTitle, in->TestBit(TAxis::kCenterTitle));
2773  out->SetBit(TAxis::kRotateTitle, in->TestBit(TAxis::kRotateTitle));
2774  out->SetBit(TAxis::kNoExponent, in->TestBit(TAxis::kNoExponent));
2775  out->SetBit(TAxis::kTickPlus, in->TestBit(TAxis::kTickPlus));
2776  out->SetBit(TAxis::kTickMinus, in->TestBit(TAxis::kTickMinus));
2777  out->SetTimeFormat(in->GetTimeFormat());
2778  if (includeLabels)
2779  {
2780  importAxisLabels(in,out);
2781  }
2782 }
2783 
2784 ////////////////////////////////////////////////////////////////////////////////
2785 
2786 void PTools::importAxisLabels(TAxis *in, TAxis *out)
2787 {
2788  // copies bin labels from one axis to the other
2789  // if bin numbers differ overlap is taken
2790 
2791  THashList* labels = in->GetLabels();
2792 
2793  if(labels !=NULL)
2794  {
2795  if(in->GetNbins() != out->GetNbins())
2796  {
2797  ::Warning("ImportAxisAttributes","axises do not have same binning copying labels for overlap");
2798  }
2799  TIter next(labels);
2800  TObjString *obj;
2801  while((obj=(TObjString*) next()))
2802  {
2803  out->SetBinLabel((Int_t)obj->GetUniqueID(),obj->GetName());
2804  }
2805  }
2806 }
2807 
2808 ////////////////////////////////////////////////////////////////////////////////
2809 
2811 {
2812  // checks whether h1 and h1
2813  //
2814  // * have the same type +(0000001)
2815  // * have the same dimension +(0000100)
2816  // * have the same binning +(0010000)
2817  // * have the same limits +(1000000)
2818  //
2819  // returns the sum of conditions not matched
2820  // i.e. not same type && not same binning => 1000001;
2821  // returns 0, if all conditions match
2822  // returns -1, if h1 or h2 is a NULL pointer
2823 
2824  // check for not NULL pointer
2825  if (!h1 || !h2)
2826  {
2827  Error("checkHistogrammCompatibility","can't compare, h1 (%p) or h2 (%p) is null pointer, returning -1",h1, h2);
2828  return -1;
2829  }
2830 
2831  Int_t val = 0;
2832 
2833  // type
2834  const TString n1 = h1->ClassName();
2835  const TString n2 = h2->ClassName();
2836 
2837  if (n1.CompareTo(n2))
2838  {
2839  val += 1;
2840  }
2841 
2842  // dimension
2843  if (h1->GetDimension() != h2->GetDimension())
2844  {
2845  val += 100;
2846  }
2847 
2848  // binning
2849  if ( h1->GetNbinsX() != h2->GetNbinsX() ||
2850  h1->GetNbinsY() != h2->GetNbinsY() ||
2851  h1->GetNbinsZ() != h2->GetNbinsZ())
2852  {
2853  val += 10000;
2854  }
2855 
2856  // variable sized binning
2857 
2858  if (!areArraysCompatible(h1->GetXaxis()->GetXbins(),h2->GetXaxis()->GetXbins()) ||
2859  !areArraysCompatible(h1->GetYaxis()->GetXbins(),h2->GetYaxis()->GetXbins()) ||
2860  !areArraysCompatible(h1->GetZaxis()->GetXbins(),h2->GetZaxis()->GetXbins()))
2861  {
2862  val += 100000;
2863  }
2864 
2865  // limits
2866  if (h1->GetXaxis()->GetXmin() != h2->GetXaxis()->GetXmin() ||
2867  h1->GetXaxis()->GetXmax() != h2->GetXaxis()->GetXmax() ||
2868  h1->GetYaxis()->GetXmin() != h2->GetYaxis()->GetXmin() ||
2869  h1->GetYaxis()->GetXmax() != h2->GetYaxis()->GetXmax() ||
2870  h1->GetZaxis()->GetXmin() != h2->GetZaxis()->GetXmin() ||
2871  h1->GetZaxis()->GetXmax() != h2->GetZaxis()->GetXmax())
2872  {
2873  val += 1000000;
2874  }
2875  return val;
2876 }
2877 
2878 ////////////////////////////////////////////////////////////////////////////////
2879 
2880 Bool_t PTools::areHistogramsCompatible(TH1* h1, TH1 *h2)
2881 {
2882  // checks whether h1 and h1
2883  //
2884  // * have the same binning
2885  // * have the same dimension
2886  // * have the same limits
2887  //
2888  // NOTE: it allows differences in the types (ClassNames)
2889  // if you want to check for this use checkHistogramCompatibility directly
2890  //
2891  // returns kTRUE if they are compatible to these checks
2892  // returns kFALSE if not
2893  // returns also kFALSE, if h1 or h2 is a NULL pointer
2894 
2895  Int_t val = checkHistogramCompatibility(h1, h2);
2896 
2897  if ( -1 < val && val < 100)
2898  {
2899  return kTRUE;
2900  }
2901 
2902  return kFALSE;
2903 }
2904 
2905 ////////////////////////////////////////////////////////////////////////////////
2906 
2907 Bool_t PTools::areArraysCompatible(const TArray* array1, const TArray* array2)
2908 {
2909  // compares two TArrays
2910  // in size, type and values
2911  //
2912  // if identical kTRUE is returned
2913  // else kFALSE
2914  // returns also kFALSE, if array1 or array2 is a NULL pointer
2915  //
2916  // supported types are TArrayC, TArrayD, TArrayF, TArrayI, TArrayL, TArrayS
2917  //
2918 
2919  // check for not NULL pointer
2920  if (!array1 || !array2)
2921  {
2922  Error("areArraysCompatible","can't compare, array1 (%p) or array2 (%p) is null pointer, returning -1",array1, array2);
2923  return -1;
2924  }
2925 
2926  // size
2927 
2928  Int_t arraySize1 = array1->GetSize();
2929  Int_t arraySize2 = array2->GetSize();
2930 
2931  if (arraySize1 != arraySize2)
2932  {
2933  return kFALSE;
2934  }
2935 
2936  // class names
2937  TString n1 = array1->IsA()->GetName();
2938  TString n2 = array2->IsA()->GetName();
2939 
2940  // type ???
2941  if (n1.CompareTo(n2))
2942  {
2943  return kFALSE;
2944  }
2945 
2946  // determine type number
2947  Int_t number = -1;
2948 
2949  if ( array1->IsA()->InheritsFrom("TArrayC") ) { number = 1; }
2950  if ( array1->IsA()->InheritsFrom("TArrayD") ) { number = 2; }
2951  if ( array1->IsA()->InheritsFrom("TArrayF") ) { number = 3; }
2952  if ( array1->IsA()->InheritsFrom("TArrayI") ) { number = 4; }
2953  if ( array1->IsA()->InheritsFrom("TArrayL") ) { number = 5; }
2954  if ( array1->IsA()->InheritsFrom("TArrayS") ) { number = 6; }
2955 
2956  // values
2957 
2958  switch(number)
2959  {
2960  case 1:
2961  for ( Int_t index=0; index < arraySize1; index++)
2962  {
2963  if ( ((TArrayC*)array1)->At(index) != ((TArrayC*)array2)->At(index))
2964  {
2965  return kFALSE;
2966  }
2967  }
2968  break;
2969  case 2:
2970  for ( Int_t index=0; index < arraySize1; index++)
2971  {
2972  if ( ((TArrayD*)array1)->At(index) != ((TArrayD*)array2)->At(index))
2973  {
2974  return kFALSE;
2975  }
2976  }
2977  break;
2978  case 3:
2979  for ( Int_t index=0; index < arraySize1; index++)
2980  {
2981  if ( ((TArrayF*)array1)->At(index) != ((TArrayF*)array2)->At(index))
2982  {
2983  return kFALSE;
2984  }
2985  }
2986  break;
2987  case 4:
2988  for ( Int_t index=0; index < arraySize1; index++)
2989  {
2990  if ( ((TArrayI*)array1)->At(index) != ((TArrayI*)array2)->At(index))
2991  {
2992  return kFALSE;
2993  }
2994  }
2995  break;
2996  case 5:
2997  for ( Int_t index=0; index < arraySize1; index++)
2998  {
2999  if ( ((TArrayL*)array1)->At(index) != ((TArrayL*)array2)->At(index))
3000  {
3001  return kFALSE;
3002  }
3003  }
3004  break;
3005  case 6:
3006  for ( Int_t index=0; index < arraySize1; index++)
3007  {
3008  if ( ((TArrayS*)array1)->At(index) != ((TArrayS*)array2)->At(index))
3009  {
3010  return kFALSE;
3011  }
3012  }
3013  break;
3014  default:
3015  ::Error("areArraysCompatible","unsupported type: \"%s\", returning kFALSE",array1->IsA()->ClassName());
3016  return kFALSE;
3017  break;
3018  }
3019  return kTRUE;
3020 
3021 }
3022 
3023 ////////////////////////////////////////////////////////////////////////////////
3024 
3025 TGraphErrors* PTools::fillGraphErr(TH1 *hist, TString name, TString position, Bool_t xerrors)
3026 {
3027  // fills an TH1 histogramm hist to a TGraphError
3028  // depending on position
3029  // the x value is chosen
3030  // "center" or "middle": in the middle of the bin
3031  // "low" or "left" : at the lower edge of the bin
3032  // "up" or "right" : at the upper edge of the bin
3033  //
3034  // if name is set, name is assigned as the objects name, otherwise "_graph" is put to the name of hist
3035  //
3036  // if xerrors is set xerrors are taken as 50% of the bin width
3037  //
3038  // returns pointer to TGraphError
3039  // if hist does not exists,
3040  // NULL pointer ist returned
3041  // if invalid position is chosen (case insensitive)
3042  // NULL pointer ist returned
3043 
3044  if (!hist)
3045  {
3046  Error(" fillGraphErr","hist is NULL, returning NULL pointer");
3047  return NULL;
3048  }
3049 
3050  if (name.IsNull())
3051  {
3052  name=hist->GetName();
3053  name+="_graph";
3054  }
3055 
3056  position.ToLower();
3057  Int_t swit = -1;
3058  if (!position.CompareTo("center")) {swit=1;}
3059  if (!position.CompareTo("middle")) {swit=1;}
3060  if (!position.CompareTo("low")) {swit=2;}
3061  if (!position.CompareTo("left")) {swit=2;}
3062  if (!position.CompareTo("up")) {swit=3;}
3063  if (!position.CompareTo("right")) {swit=3;}
3064 
3065  if (swit == -1)
3066  {
3067  Error("fillGraphErr",
3068  "no valid position name %s (center,middle,low,left,up,right) chosen, returning NULL",
3069  position.Data());
3070  return NULL;
3071  }
3072 
3073  Int_t nbinsx = hist->GetNbinsX();
3074 
3075  TArrayD xval(nbinsx);
3076  TArrayD yval(nbinsx);
3077  TArrayD xerrval(nbinsx);
3078  TArrayD yerrval(nbinsx);
3079 
3080  Int_t bin;
3081 
3082  for (Int_t binx=1; binx <= nbinsx; binx++)
3083  {
3084  bin = hist->GetBin(binx);
3085  yval[bin-1] = hist->GetBinContent(bin);
3086  yerrval[bin-1] = hist->GetBinError(bin);
3087  xerrval[bin-1] = 0.5*hist->GetBinWidth(bin);
3088 
3089  switch(swit)
3090  {
3091  case 1: // center middle
3092  xval[bin-1] = hist->GetXaxis()->GetBinCenter(bin);
3093  break;
3094  case 2: // left low
3095  xval[bin-1] = hist->GetXaxis()->GetBinLowEdge(bin);
3096  break;
3097  case 3: // right up
3098  xval[bin-1] = hist->GetXaxis()->GetBinUpEdge(bin);
3099  break;
3100  }
3101  }
3102 
3103 
3104  TGraphErrors* graph = NULL;
3105  if (xerrors)
3106  {
3107  graph = new TGraphErrors(nbinsx,
3108  xval.GetArray(),
3109  yval.GetArray(),
3110  xerrval.GetArray(),
3111  yerrval.GetArray());
3112  }
3113  else
3114  {
3115  graph = new TGraphErrors(nbinsx,
3116  xval.GetArray(),
3117  yval.GetArray(),
3118  0,
3119  yerrval.GetArray());
3120  }
3121 
3122  return graph;
3123 }
3124 
3125 ////////////////////////////////////////////////////////////////////////////////
3126 
3127 TPaveStats* PTools::getHistStats(TH1 *hist, Bool_t quiet)
3128 {
3129  // returns for a given (plotted) histogramm the pointer to the statistics TPaveStat
3130 
3131  if (hist)
3132  {
3133  TPaveStats* stats = ((TPaveStats*) hist->GetListOfFunctions()->FindObject("stats"));
3134  if (stats)
3135  {
3136  return stats;
3137  }
3138  else
3139  {
3140  if (! quiet) {::Error("getHistStats","stats do not exists, returning NULL pointer");}
3141  return stats;
3142  }
3143  }
3144  else
3145  {
3146  ::Error("getHistStats","histogram is NULL pointer, returning NULL pointer");
3147  return NULL;
3148  }
3149 }
3150 
3151 ////////////////////////////////////////////////////////////////////////////////
3152 
3153 TPaveStats* PTools::getHistStats(TPad* pad, TString name, Bool_t quiet, Bool_t noUpdate)
3154 {
3155  // returns for a given TCanvas/TPad pointer to the statistics TPaveStat of a
3156  // histogram with name "name"
3157  // before calling getHistStats(hist) a pad->Update() is executed
3158  //
3159 
3160  if (pad)
3161  {
3162  if (!noUpdate) pad->Update();
3163  return getHistStats(((TH1*) pad->FindObject(name.Data())), quiet);
3164  }
3165  else
3166  {
3167  if (!quiet){::Error("getHistStats()","pad does not exist, returning NULL pointer");}
3168  return NULL;
3169  }
3170 }
3171 
3172 
3173 ////////////////////////////////////////////////////////////////////////////////
3174 
3175 TPaveStats* PTools::setHistStatsYPosNDC(TH1 *hist, Double_t y1, Double_t y2)
3176 {
3177  // sets y1 and y2 position in NDC coordinates of stats box of histogramm
3178  // returns pointer to stats' TPaveStats
3179 
3180  TPaveStats *stats = getHistStats(hist);
3181  if (stats)
3182  {
3183  stats->SetY1NDC(y1);
3184  stats->SetY2NDC(y2);
3185  }
3186  else
3187  {
3188  ::Warning("setHistStatsYPosNDC","couldn't change position");
3189  }
3190  return stats;
3191 }
3192 
3193 ////////////////////////////////////////////////////////////////////////////////
3194 
3195 TPaveStats* PTools::setHistStatsYPosNDC(TPad* pad, TString name, Double_t y1, Double_t y2)
3196 {
3197  // sets y1 and y2 position in NDC coordinates of stats box of histogramm
3198  // with name "name" in pad
3199  // returns pointer to stats' TPaveStats
3200 
3201  if (pad)
3202  {
3203  return setHistStatsYPosNDC(((TH1*) pad->FindObject(name.Data())),y1,y2);
3204  }
3205  else
3206  {
3207  ::Error("setHistStatsYPosNDC()","pad does not exist, returning NULL pointer");
3208  return NULL;
3209  }
3210 }
3211 
3212 ////////////////////////////////////////////////////////////////////////////////
3213 
3214 TPaveStats* PTools::setHistStatsXPosNDC(TH1 *hist, Double_t x1, Double_t x2)
3215 {
3216  // sets x1 and x2 position in NDC coordinates of stats box of histogramm
3217  // returns pointer to stats' TPaveStats
3218 
3219  TPaveStats *stats = getHistStats(hist);
3220  if (stats)
3221  {
3222  stats->SetX1NDC(x1);
3223  stats->SetX2NDC(x2);
3224  }
3225  else
3226  {
3227  ::Warning("setHistStatsXPosNDC","couldn't change position");
3228  }
3229  return stats;
3230 }
3231 
3232 ////////////////////////////////////////////////////////////////////////////////
3233 
3234 TPaveStats* PTools::setHistStatsXPosNDC(TPad* pad, TString name, Double_t x1, Double_t x2)
3235 {
3236  // sets x1 and x2 position in NDC coordinates of stats box of histogramm
3237  // with name "name" in pad
3238  // returns pointer to stats' TPaveStats
3239 
3240  if (pad)
3241  {
3242  return setHistStatsXPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2);
3243  }
3244  else
3245  {
3246  ::Error("setHistStatsXPosNDC()","pad does not exist, returning NULL pointer");
3247  return NULL;
3248  }
3249 }
3250 
3251 ////////////////////////////////////////////////////////////////////////////////
3252 
3253 TPaveStats* PTools::setHistStatsPosNDC(TH1 *hist, Double_t x1, Double_t x2, Double_t y1, Double_t y2)
3254 {
3255  // sets x1,y1 and x2,y2 position in NDC coordinates of stats box of histogramm
3256  // returns pointer to stats' TPaveStats
3257 
3258  TPaveStats *stats = getHistStats(hist);
3259  if (stats)
3260  {
3261  stats->SetX1NDC(x1);
3262  stats->SetX2NDC(x2);
3263  stats->SetY1NDC(y1);
3264  stats->SetY2NDC(y2);
3265  }
3266  else
3267  {
3268  ::Warning("setHistStatsPosNDC","couldn't change position");
3269  }
3270  return stats;
3271 }
3272 
3273 ////////////////////////////////////////////////////////////////////////////////
3274 
3275 TPaveStats* PTools::setHistStatsPosNDC(TPad* pad, TString name, Double_t x1, Double_t x2, Double_t y1, Double_t y2)
3276 {
3277  // sets x1,y1 and x2,y2 position in NDC coordinates of stats box of histogramm
3278  // with name "name" in pad
3279  // returns pointer to stats' TPaveStats
3280 
3281  if (pad)
3282  {
3283  return setHistStatsPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2,y1,y2);
3284  }
3285  else
3286  {
3287  ::Error("setHistStatsPosNDC()","pad does not exist, returning NULL pointer");
3288  return NULL;
3289  }
3290 }
3291 
3292 ////////////////////////////////////////////////////////////////////////////////
3293 
3294 TPaveStats* PTools::getHistStatsYPosNDC(TH1 *hist, Double_t& y1, Double_t& y2)
3295 {
3296  // gets y1 and y2 position in NDC coordinates of stats box of histogramm
3297  // returns pointer to stats' TPaveStats
3298 
3299  TPaveStats *stats = getHistStats(hist);
3300  if (stats)
3301  {
3302  y1 = stats->GetY1NDC();
3303  y2 = stats->GetY2NDC();
3304  }
3305  else
3306  {
3307  ::Warning("getHistStatsYPosNDC","couldn't change position");
3308  }
3309  return stats;
3310 }
3311 
3312 ////////////////////////////////////////////////////////////////////////////////
3313 
3314 TPaveStats* PTools::getHistStatsYPosNDC(TPad* pad, TString name, Double_t& y1, Double_t& y2)
3315 {
3316  // gets y1 and y2 position in NDC coordinates of stats box of histogramm
3317  // with name "name" in pad
3318  // returns pointer to stats' TPaveStats
3319 
3320  if (pad)
3321  {
3322  return getHistStatsYPosNDC(((TH1*) pad->FindObject(name.Data())),y1,y2);
3323  }
3324  else
3325  {
3326  ::Error("getHistStatsYPosNDC()","pad does not exist, returning NULL pointer");
3327  return NULL;
3328  }
3329 }
3330 
3331 ////////////////////////////////////////////////////////////////////////////////
3332 
3333 TPaveStats* PTools::getHistStatsXPosNDC(TH1 *hist, Double_t& x1, Double_t& x2)
3334 {
3335  // gets x1 and x2 position in NDC coordinates of stats box of histogramm
3336  // returns pointer to stats' TPaveStats
3337 
3338  TPaveStats *stats = getHistStats(hist);
3339  if (stats)
3340  {
3341  x1 = stats->GetX1NDC();
3342  x2 = stats->GetX2NDC();
3343  }
3344  else
3345  {
3346  ::Warning("getHistStatsXPosNDC","couldn't change position");
3347  }
3348  return stats;
3349 }
3350 
3351 ////////////////////////////////////////////////////////////////////////////////
3352 
3353 TPaveStats* PTools::getHistStatsXPosNDC(TPad* pad, TString name, Double_t& x1, Double_t& x2)
3354 {
3355  // gets x1 and x2 position in NDC coordinates of stats box of histogramm
3356  // with name "name" in pad
3357  // returns pointer to stats' TPaveStats
3358 
3359  if (pad)
3360  {
3361  return getHistStatsXPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2);
3362  }
3363  else
3364  {
3365  ::Error("getHistStatsXPosNDC()","pad does not exist, returning NULL pointer");
3366  return NULL;
3367  }
3368 }
3369 
3370 ////////////////////////////////////////////////////////////////////////////////
3371 
3372 TPaveStats* PTools::getHistStatsPosNDC(TH1 *hist, Double_t& x1, Double_t& x2, Double_t& y1, Double_t& y2)
3373 {
3374  // gets x1,y1 and x2,y2 position in NDC coordinates of stats box of histogramm
3375  // returns pointer to stats' TPaveStats
3376 
3377  TPaveStats *stats = getHistStats(hist);
3378  if (stats)
3379  {
3380  x1 = stats->GetX1NDC();
3381  x2 = stats->GetX2NDC();
3382  y1 = stats->GetY1NDC();
3383  y2 = stats->GetY2NDC();
3384  }
3385  else
3386  {
3387  ::Warning("getHistStatsPosNDC","couldn't change position");
3388  }
3389  return stats;
3390 }
3391 
3392 ////////////////////////////////////////////////////////////////////////////////
3393 
3394 TPaveStats* PTools::getHistStatsPosNDC(TPad* pad, TString name, Double_t& x1, Double_t& x2, Double_t& y1, Double_t& y2)
3395 {
3396  // gets x1,y1 and x2,y2 position in NDC coordinates of stats box of histogramm
3397  // with name "name" in pad
3398  // returns pointer to stats' TPaveStats
3399 
3400  if (pad)
3401  {
3402  return getHistStatsPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2,y1,y2);
3403  }
3404  else
3405  {
3406  ::Error("getHistStatsPosNDC()","pad does not exist, returning NULL pointer");
3407  return NULL;
3408  }
3409 }
3410 
3411 ////////////////////////////////////////////////////////////////////////////////
3412 
3413 TPaveStats* PTools::setHistStatsTextColor(TH1 *hist, Int_t color)
3414 {
3415  // sets text color of stats box of histogramm
3416  // returns pointer to stats' TPaveStats
3417 
3418  TPaveStats *stats = getHistStats(hist);
3419  if (stats)
3420  {
3421  stats->SetTextColor(color);
3422  }
3423  else
3424  {
3425  ::Warning("setHistStatsTextColorNDC","couldn't change textColorition");
3426  }
3427  return stats;
3428 }
3429 
3430 ////////////////////////////////////////////////////////////////////////////////
3431 
3432 TPaveStats* PTools::setHistStatsTextColor(TPad* pad, TString name, Int_t color)
3433 {
3434  // sets text color of stats box of histogramm
3435  // with name "name" in pad
3436  // returns pointer to stats' TPaveStats
3437 
3438  if (pad)
3439  {
3440  return setHistStatsTextColor(((TH1*) pad->FindObject(name.Data())),color);
3441  }
3442  else
3443  {
3444  ::Error("setHistStatsTextColor()","pad does not exist, returning NULL pointer");
3445  return NULL;
3446  }
3447 }
3448 
3449 ////////////////////////////////////////////////////////////////////////////////
3450 
3451 void PTools::setLatexArts(TLatex * tex,
3452  Double_t x, Double_t y,
3453  Int_t color, Float_t size, Int_t align,
3454  Int_t font, Float_t angle, Bool_t ndc)
3455 {
3456  // sets attributes of TLatex object tex:
3457  // x,y positions (choose setLatexArtsNDC for NDC coords)
3458  // color
3459  // size
3460  // alignment
3461  // font
3462  // angle
3463  // ndc: use ndc coordinates
3464  //
3465  // see TAttText for detailed information
3466 
3467  if (tex)
3468  {
3469  tex->SetNDC(ndc);
3470  tex->SetX(x);
3471  tex->SetY(y);
3472  tex->SetTextColor(color);
3473  tex->SetTextSize(size);
3474  tex->SetTextAlign(align);
3475  tex->SetTextFont(font);
3476  tex->SetTextAngle(angle);
3477  }
3478  else
3479  {
3480  ::Error("setLatexArts()","tex pointer does not exist, no changes");
3481  }
3482 }
3483 
3484 ////////////////////////////////////////////////////////////////////////////////
3485 ////////////////////////////////////////////////////////////////////////////////
3486 
3487 void PTools::setLatexArtsNDC(TLatex * tex,
3488  Double_t x, Double_t y,
3489  Int_t color, Float_t size, Int_t align,
3490  Int_t font, Float_t angle)
3491 {
3492  // sets attributes of TLatex object tex:
3493  // x,y positions in NDC coords
3494  // color
3495  // size
3496  // alignment
3497  // font
3498  // angle
3499  // see TAttText for detailed information
3500 
3501  setLatexArts(tex,x,y,color,size,align,font,angle,kTRUE);
3502 }
3503 
3504 ////////////////////////////////////////////////////////////////////////////////
3505 
3506 Bool_t PTools::loadMacro(const Char_t *macro)
3507 {
3508  // loads Macro only if macro has not yet been loaded before
3509  // returns true if macro is loaded
3510  // returns true if no action is necessary
3511 
3512  if (!gInterpreter
3513  ||
3514  (gInterpreter && (!gInterpreter->IsLoaded(macro))))
3515  {
3516  gROOT->LoadMacro(macro);
3517  return kTRUE;
3518  }
3519  return kFALSE;
3520 }
3521 
3522 ////////////////////////////////////////////////////////////////////////////////
3523 
3524 Bool_t PTools::loadMacro(TString macro)
3525 {
3526  // loads Macro only if macro has not yet been loaded before
3527  // returns true if macro is loaded
3528  // returns true if no action is necessary
3529 
3530  return loadMacro(macro.Data());
3531 }
3532 
3533 ////////////////////////////////////////////////////////////////////////////////
3534 
3535 Int_t PTools::getLinearIndex( Int_t x1, UInt_t x1max,
3536  Int_t x2, UInt_t x2max,
3537  Int_t x3, UInt_t x3max,
3538  Int_t x4, UInt_t x4max,
3539  Int_t x5, UInt_t x5max)
3540 {
3541  // Translates i.e. array coordinate 0,2,3 of array[3][8][1]
3542  // in a linear unique coordinate starting from 0
3543  //
3544  // coordinates starting from 0 !!!
3545  //
3546  // if x(i) is < 0 then only the x(i-1) coords are taken into account
3547  // if indizes are out of bounds -1 is returned
3548 
3549  Int_t x[5];
3550  UInt_t xmax[5];
3551 
3552  x[0] = x1;
3553  x[1] = x2;
3554  x[2] = x3;
3555  x[3] = x4;
3556  x[4] = x5;
3557 
3558  xmax[0] = x1max;
3559  xmax[1] = x2max;
3560  xmax[2] = x3max;
3561  xmax[3] = x4max;
3562  xmax[4] = x5max;
3563 
3564  UInt_t dim = 5;
3565  for (UInt_t iter = 1; iter < dim; iter++)
3566  {
3567  if (x[iter] < 0 )
3568  {
3569  dim =iter;
3570 
3571  for (UInt_t fiter = iter-1; fiter < dim-1; fiter++)
3572  {
3573  x[iter] = 0;
3574  xmax[fiter]=0;
3575  }
3576  break;
3577  }
3578  }
3579 
3580  for (UInt_t iter = 1; iter < dim; iter++)
3581  {
3582  if ((UInt_t) x[iter] >= xmax[iter])
3583  {
3584  cout << x[iter] << endl;
3585  cout << xmax[iter] << endl;
3586  ::Error("getLinearIndex","index %i out of bounds %i, returning -1",x[iter],xmax[iter]);
3587  return -1;
3588  }
3589  }
3590 
3591  Int_t index = x[0];
3592  Int_t add;
3593  for (UInt_t iter = 1; iter < dim; iter++)
3594  {
3595  add = 1;
3596  for (UInt_t iter2 = 0; iter2 < iter; iter2++)
3597  {
3598  add *= xmax[iter2];
3599  }
3600  index += x[iter]*add;
3601  }
3602 
3603  return index;
3604 }
3605 
3606 ////////////////////////////////////////////////////////////////////////////////
3607 
3608 Int_t PTools::getLinearIndex( Int_t *x, UInt_t *xmax, UInt_t dim)
3609 {
3610  // Translates i.e. array coordinate 0,2,3 of array[3][8][1]
3611  // in a linear unique coordinate starting from 0
3612  //
3613  // coordinates starting from 0 !!!
3614  //
3615  // if x(i) is < 0 then only the x(i-1) coords are taken into account
3616  // x is contains the coordinates and has dimension dim
3617  // xmax are the sizes and is of dimension dim
3618  // if indizes are out of bounds -1 is returned
3619 
3620  if (x[0]<0)
3621  {
3622  ::Error("getLinearIndex","Bad Index return -1");
3623  }
3624 
3625 
3626  for (UInt_t iter = 1; iter < dim; iter++)
3627  {
3628  if (x[iter] < 0 )
3629  {
3630  for (UInt_t fiter = iter-1; fiter < dim-1; fiter++)
3631  {
3632  x[iter] = 0;
3633  xmax[fiter]=0;
3634  }
3635  break;
3636  }
3637  }
3638 
3639  for (UInt_t iter = 1; iter < dim; iter++)
3640  {
3641  if ((UInt_t) x[iter] >= xmax[iter])
3642  {
3643 // cout << x[iter] << endl;
3644 // cout << xmax[iter] << endl;
3645  ::Error("getLinearIndex","index %i out of bounds %i, returning -1",x[iter],xmax[iter]);
3646  return -1;
3647  }
3648  }
3649 
3650 // UInt_t index = x[dim-1];
3651 // for (UInt_t ai = dim-1; ai > 1 ; ai--)
3652 // {
3653 // index = x[ai-1] + xmax[ai-1] * index;
3654 // }
3655 
3656  Int_t index = x[0];
3657  Int_t add;
3658  for (UInt_t iter = 1; iter < dim; iter++)
3659  {
3660  add = 1;
3661  for (UInt_t iter2 = 0; iter2 < iter; iter2++)
3662  {
3663  add *= xmax[iter2];
3664  }
3665  index += x[iter]*add;
3666  }
3667 
3668  return index;
3669 }
3670 
3671 ////////////////////////////////////////////////////////////////////////////////
3672 
3673 TLatex * PTools::drawLatexWC(TString text, Double_t x, Double_t y,
3674  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3675 {
3676  // Draws text as TLatex in current pad
3677  // at pos x,y not in NDC but it WC
3678  // using setLatexArtsNDC
3679  // returns pointer to new created TLatex object (user must care of removal)
3680  TLatex *tex = new TLatex(0,0,text.Data());
3681  PTools::setLatexArts(tex, x, y, color, size, align, font, angle);
3682  tex->Draw();
3683  return tex;
3684 }
3685 
3686 ////////////////////////////////////////////////////////////////////////////////
3687 
3688 TLatex * PTools::drawLatexWC(const Char_t* text, Double_t x, Double_t y,
3689  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3690 {
3691  // Draws text as TLatex in current pad
3692  // at pos x,y not in NDC but it WC
3693  // using setLatexArtsNDC
3694  // returns pointer to new created TLatex object (user must care of removal)
3695  return drawLatexWC(TString(text), x, y, color, size, align, font, angle);
3696 }
3697 
3698 ////////////////////////////////////////////////////////////////////////////////
3699 
3700 TLatex * PTools::drawLatexNDC(const Char_t* text, Double_t x, Double_t y,
3701  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3702 {
3703  // Draws text as TLatex in current pad
3704  // at pos x,y in NDC
3705  // using setLatexArtsNDC
3706  // returns pointer to new created TLatex object (user must care of removal)
3707  return drawLatexPadCoords(text, x, y, color , size, align ,font , angle);
3708 }
3709 
3710 ////////////////////////////////////////////////////////////////////////////////
3711 
3712 TLatex * PTools::drawLatexNDC(TString text, Double_t x, Double_t y,
3713  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3714 {
3715  // Draws text as TLatex in current pad
3716  // at pos x,y in NDC
3717  // using setLatexArtsNDC
3718  // returns pointer to new created TLatex object (user must care of removal)
3719  return drawLatexPadCoords(text, x, y, color , size, align ,font , angle);
3720 }
3721 
3722 ////////////////////////////////////////////////////////////////////////////////
3723 
3724 TLatex * PTools::drawLatex(TString text, Double_t x, Double_t y,
3725  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3726 {
3727  // Draws text as TLatex in current pad
3728  // at pos x,y in NDC
3729  // using setLatexArtsNDC
3730  // returns pointer to new created TLatex object (user must care of removal)
3731  TLatex *tex = new TLatex(0,0,text.Data());
3732  PTools::setLatexArtsNDC(tex, x, y, color, size, align, font, angle);
3733  tex->Draw();
3734  return tex;
3735 }
3736 
3737 ////////////////////////////////////////////////////////////////////////////////
3738 
3739 TLatex * PTools::drawLatex(const Char_t* text, Double_t x, Double_t y,
3740  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3741 {
3742  // Draws text as TLatex in current pad
3743  // at pos x,y in NDC
3744  // using setLatexArtsNDC
3745  // returns pointer to new created TLatex object (user must care of removal)
3746  return drawLatex(TString(text), x, y, color, size, align, font, angle);
3747 }
3748 
3749 ////////////////////////////////////////////////////////////////////////////////
3750 
3751 TLatex * PTools::drawLatexPadCoords(TString text, Double_t x, Double_t y,
3752  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3753 {
3754  // Draws text as TLatex in current pad
3755  // at pos x,y in NDC
3756  // using setLatexArts
3757  // returns pointer to new created TLatex object (user must care of removal)
3758  TLatex *tex = new TLatex(0,0,text.Data());
3759  PTools::setLatexArts(tex, x, y, color, size, align, font, angle);
3760  tex->Draw();
3761  return tex;
3762 }
3763 
3764 ////////////////////////////////////////////////////////////////////////////////
3765 
3766 TLatex * PTools::drawLatexPadCoords(const Char_t* text, Double_t x, Double_t y,
3767  Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3768 {
3769  // Draws text as TLatex in current pad
3770  // at pos x,y in NDC
3771  // using setLatexArts
3772  // returns pointer to new created TLatex object (user must care of removal)
3773  return drawLatexPadCoords(TString(text), x, y, color, size, align, font, angle);
3774 }
3775 
3776 ////////////////////////////////////////////////////////////////////////////////
3777 
3778 TH1* PTools::getErrorsOfHistogram(TH1 * hist, Bool_t relativeError)
3779 {
3780  // creates histogram
3781  // which contains the errors of hist
3782  // if an error occurs NULL is returned
3783  // the name and title of the new histogramm will expanded by "_Error" or "_relError"
3784  // relativeError is kTRUE then |relativeError| is calculated
3785  // (if hist does not contain in a bin the relative error is set to -1)
3786  // otherwise the absolute error is given
3787 
3788  if (!hist)
3789  {
3790  ::Error("getErrorsOfHistogram"," hist is NULL pointer ... return NULL");
3791  return NULL;
3792  }
3793 
3794  TH1* err = (TH1*) hist->Clone();
3795  err->Reset();
3796 
3797  TString name = hist->GetName();
3798  TString title = hist->GetTitle();
3799 
3800  if (!relativeError)
3801  {
3802  name+="_Error";
3803  title+="_Error";
3804  }
3805  else
3806  {
3807  name+="_relError";
3808  title+="_relError";
3809  }
3810 
3811  err->SetName(name.Data());
3812  err->SetTitle(title.Data());
3813 
3814  Int_t nbinsx = hist->GetNbinsX();
3815  Int_t nbinsy = hist->GetNbinsY();
3816  Int_t nbinsz = hist->GetNbinsZ();
3817 
3818  if (hist->GetDimension()<2) nbinsy = -1;
3819  if (hist->GetDimension()<3) nbinsz = -1;
3820 
3821  Int_t binx,biny,binz,bin;
3822 
3823  for (binz=0;binz<=nbinsz+1;binz++)
3824  {
3825  for (biny=0;biny<=nbinsy+1;biny++)
3826  {
3827  for (binx=0;binx<=nbinsx+1;binx++)
3828  {
3829  bin = hist->GetBin(binx,biny,binz);
3830  if (! relativeError)
3831  {
3832  err->SetBinContent(bin,hist->GetBinError(bin));
3833  }
3834  else
3835  {
3836  if (hist->GetBinContent(bin))
3837  {
3838  err->SetBinContent(bin,fabs(hist->GetBinError(bin)/hist->GetBinContent(bin)));
3839  }
3840  else
3841  {
3842  err->SetBinContent(bin,-1);
3843  }
3844  }
3845  }
3846  }
3847  }
3848  return err;
3849 
3850 }
3851 
3852 ////////////////////////////////////////////////////////////////////////////////
3853 
3854 void PTools::setErrorsOfHistogram(TH1 * hist, TH1 *err)
3855 {
3856  // sets the errors of histogram hist with the bin contents of hist err
3857  // provided the histograms are compatible
3858  //
3859  // if hist or err are NULL pointer, or the histograms are not compatible,
3860  // an error message is issued, but nothing happens
3861 
3862  if (!hist)
3863  {
3864  ::Error("setErrorsOfHistogram"," hist is NULL pointer ... nothing done");
3865  return;
3866  }
3867 
3868  if (!err)
3869  {
3870  ::Error("setErrorsOfHistogram"," err is NULL pointer ... nothing done");
3871  return;
3872  }
3873 
3874  // compatibility
3875 
3876  Int_t check = checkHistogramCompatibility(hist, err);
3877  if (check > 0)
3878  {
3879  ::Error("setErrorsOfHistogram"," err and hist are not compatible %i ... nothing done",check);
3880  return;
3881  }
3882 
3883  //
3884 
3885  Int_t nbinsx = hist->GetNbinsX();
3886  Int_t nbinsy = hist->GetNbinsY();
3887  Int_t nbinsz = hist->GetNbinsZ();
3888 
3889  if (hist->GetDimension()<2) nbinsy = -1;
3890  if (hist->GetDimension()<3) nbinsz = -1;
3891 
3892  Int_t binx,biny,binz,bin;
3893 
3894  for (binz=0;binz<=nbinsz+1;binz++)
3895  {
3896  for (biny=0;biny<=nbinsy+1;biny++)
3897  {
3898  for (binx=0;binx<=nbinsx+1;binx++)
3899  {
3900  bin = hist->GetBin(binx,biny,binz);
3901  hist->SetBinError(bin, err->GetBinContent(bin));
3902  }
3903  }
3904  }
3905 }
3906 
3907 ////////////////////////////////////////////////////////////////////////////////
3908 
3909 TH1* PTools::copyToUnitBinsPlusLabels(TH1* hist , Double_t binningX, Double_t binningY, Double_t binningZ)
3910 {
3911  // copies any THx histogramm to THxD histograms
3912  // you have to cast to the corresponding type
3913  // attaches to name "_THxD"
3914  // the histogramm has as many bins as the original but a binning of binningXYZ [default =1]
3915 
3916  if (! hist)
3917  {
3918  ::Error("copyToUnitBinsPlusLabels","histogram has NULL pointer ... returning NULL");
3919  return NULL;
3920  }
3921 
3922  Int_t nbinsx = hist->GetNbinsX();
3923  Int_t nbinsy = hist->GetNbinsY();
3924  Int_t nbinsz = hist->GetNbinsZ();
3925 
3926  TH1* histD = NULL;
3927 
3928  switch(hist->GetDimension())
3929  {
3930  case 1:
3931  {
3932  TString name = hist->GetName()+TString("_TH1D");
3933  histD = new TH1D(name.Data(),hist->GetTitle(),
3934  nbinsx,
3935  0,
3936  binningX*nbinsx);
3937  break;
3938  }
3939  case 2:
3940  {
3941  TString name = hist->GetName()+TString("_TH2D");
3942 
3943  histD = new TH2D(name.Data(),hist->GetTitle(),
3944  nbinsx,
3945  0,
3946  binningX*nbinsx,
3947  nbinsy,
3948  0,
3949  binningY*nbinsy);
3950  break;
3951  }
3952  case 3:
3953  {
3954  TString name = hist->GetName()+TString("_TH3D");
3955 
3956  histD = new TH3D(name.Data(),hist->GetTitle(),
3957  nbinsx,
3958  0,
3959  binningX*nbinsx,
3960  nbinsy,
3961  0,
3962  binningY*nbinsy,
3963  nbinsz,
3964  0,
3965  binningZ*nbinsz);
3966 
3967  break;
3968  }
3969  }
3970 
3971  importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
3972  importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
3973  importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
3974 
3975  histD->SetEntries(hist->GetEntries());
3976 
3977  if (hist->GetDimension()<2) nbinsy = -1;
3978  if (hist->GetDimension()<3) nbinsz = -1;
3979 
3980  Int_t binx,biny,binz,bin;
3981 
3982  for (binz=0;binz<=nbinsz+1;binz++)
3983  {
3984  for (biny=0;biny<=nbinsy+1;biny++)
3985  {
3986  for (binx=0;binx<=nbinsx+1;binx++)
3987  {
3988  bin = hist->GetBin(binx,biny,binz);
3989  histD->SetBinContent(bin, hist->GetBinContent(bin));
3990  if (hist->GetSumw2N())
3991  {
3992  histD->SetBinError(bin,hist->GetBinError(bin));
3993  }
3994  }
3995  }
3996  }
3997  return histD;
3998 }
3999 
4000 ////////////////////////////////////////////////////////////////////////////////
4001 
4002 void PTools::substractFromHist(TH1 * hist, Double_t val, Bool_t inverse)
4003 {
4004  // substracts from each bin of histogram the value val newbin = bin - val
4005  // if inverse = kTRUE: newbin = val - bin
4006 
4007  if (!hist)
4008  {
4009  ::Error("substractFromHist"," hist is NULL pointer ... cannot act on a NULL pointer.");
4010  return;
4011  }
4012 
4013  Int_t nbinsx = hist->GetNbinsX();
4014  Int_t nbinsy = hist->GetNbinsY();
4015  Int_t nbinsz = hist->GetNbinsZ();
4016 
4017  if (hist->GetDimension()<2) nbinsy = -1;
4018  if (hist->GetDimension()<3) nbinsz = -1;
4019 
4020  Int_t binx,biny,binz,bin;
4021 
4022  for (binz=0;binz<=nbinsz+1;binz++)
4023  {
4024  for (biny=0;biny<=nbinsy+1;biny++)
4025  {
4026  for (binx=0;binx<=nbinsx+1;binx++)
4027  {
4028  bin = hist->GetBin(binx,biny,binz);
4029  if (!inverse)
4030  {
4031  hist->SetBinContent(bin,hist->GetBinContent(bin) - val);
4032  }
4033  else
4034  {
4035  hist->SetBinContent(bin,val - hist->GetBinContent(bin));
4036  }
4037  }
4038  }
4039  }
4040  return;
4041 
4042 }
4043 
4044 ////////////////////////////////////////////////////////////////////////////////
4045 TH1D *PTools::getBinContentDistribution(TH1* hist, Int_t binning, Bool_t excludeUnderAndOverFlowBins)
4046 {
4047  // returns a pointer to a histogram containing the distribution of the bin contents
4048  // by default in 1000 bins
4049  //
4050  // The histogram range is determined by searching for the minimum and maximum bin content
4051  // and then setting the output histograms minimum to the found minimum,
4052  // the maximum to maximum+(maximum - minimum)/binning, i.e. maximum+binWidth
4053  // this one bin more is accounted for by having not binning, but binning + 1 bins.
4054  //
4055  // if hist is NULL ... NULL is returned
4056  //
4057  // Also the underflow and overflow bins are by default taken into account
4058  // -- those can be excluded by setting excludeUnderAndOverFlowBins to kTRUE
4059 
4060  if (!hist)
4061  {
4062  ::Error("getBinContentDistribution"," hist is NULL pointer ... cannot act on a NULL pointer.");
4063  return NULL;
4064  }
4065 
4066  Int_t nbinsx = hist->GetNbinsX();
4067  Int_t nbinsy = hist->GetNbinsY();
4068  Int_t nbinsz = hist->GetNbinsZ();
4069 
4070  if (hist->GetDimension()<2) nbinsy = -1;
4071  if (hist->GetDimension()<3) nbinsz = -1;
4072 
4073  Int_t binx,biny,binz,bin;
4074 
4075  Double_t value;
4076  Double_t maximum = -FLT_MAX/10;
4077  Double_t minimum = FLT_MAX/10;
4078 
4079  for (binz=0;binz<=nbinsz+1;binz++)
4080  {
4081  if (excludeUnderAndOverFlowBins && nbinsz != -1 && ( binz == 0 || binz == nbinsz+1)) { continue; }
4082  for (biny=0;biny<=nbinsy+1;biny++)
4083  {
4084  if (excludeUnderAndOverFlowBins && nbinsy != -1 && ( biny == 0 || biny == nbinsy+1)) { continue; }
4085  for (binx=0;binx<=nbinsx+1;binx++)
4086  {
4087  if (excludeUnderAndOverFlowBins && nbinsx != -1 && ( binx == 0 || binx == nbinsx+1)) { continue; }
4088  bin = hist->GetBin(binx,biny,binz);
4089  value = hist->GetBinContent(bin);
4090 
4091  if (value > maximum) { maximum = value;}
4092  if (value < minimum) { minimum = value;}
4093  }
4094  }
4095  }
4096 
4097  if (binning<1)
4098  {
4099  binning=1000;
4100  }
4101 
4102  TH1D* dist = new TH1D(Form("binContent_of_%s",hist->GetName()),
4103  Form("bin content distribution of : %s",hist->GetTitle()),
4104  binning+1,minimum,maximum+(maximum-minimum)/binning);
4105  for (binz=0;binz<=nbinsz+1;binz++)
4106  {
4107  if (excludeUnderAndOverFlowBins && nbinsz != -1 && ( binz == 0 || binz == nbinsz+1)) { continue; }
4108  for (biny=0;biny<=nbinsy+1;biny++)
4109  {
4110  if (excludeUnderAndOverFlowBins && nbinsy != -1 && ( biny == 0 || biny == nbinsy+1)) { continue; }
4111  for (binx=0;binx<=nbinsx+1;binx++)
4112  {
4113  if (excludeUnderAndOverFlowBins && nbinsx != -1 && ( binx == 0 || binx == nbinsx+1)) { continue; }
4114  bin = hist->GetBin(binx,biny,binz);
4115  dist->Fill(hist->GetBinContent(bin));
4116  }
4117  }
4118  }
4119  return dist;
4120 }
4121 
4122 ////////////////////////////////////////////////////////////////////////////////
4123 
4124 TH1 *PTools::getOneOverHist(TH1* hist)
4125 {
4126  // returns a pointer to a histogram containing for each bin the value 1/value
4127  // if value = 0, the ratio is set to 0
4128  //
4129  // the name is "OneOverHist" and the title "1/hist"
4130  // if hist is NULL ... NULL is returned
4131 
4132  if (!hist)
4133  {
4134  ::Error("getOneOverHist"," hist is NULL pointer ... cannot act on a NULL pointer.");
4135  return NULL;
4136  }
4137 
4138  Int_t nbinsx = hist->GetNbinsX();
4139  Int_t nbinsy = hist->GetNbinsY();
4140  Int_t nbinsz = hist->GetNbinsZ();
4141 
4142  if (hist->GetDimension()<2) nbinsy = -1;
4143  if (hist->GetDimension()<3) nbinsz = -1;
4144 
4145  Int_t binx,biny,binz,bin;
4146 
4147  Double_t value, error;
4148 
4149  TH1* inv = (TH1*) copyToTHxD(hist);
4150  TString name = Form("OneOver_%s",inv->GetName());
4151  TString title = Form("1./%s",inv->GetTitle());
4152 
4153  inv->SetNameTitle(name.Data(), title.Data());
4154  inv->Reset();
4155 
4156  for (binz=0;binz<=nbinsz+1;binz++)
4157  {
4158  for (biny=0;biny<=nbinsy+1;biny++)
4159  {
4160  for (binx=0;binx<=nbinsx+1;binx++)
4161  {
4162  bin = hist->GetBin(binx,biny,binz);
4163  value = hist->GetBinContent(bin);
4164  error = hist->GetBinError(bin);
4165  inv->SetBinContent(bin,(value==0)?0.:1./value);
4166  inv->SetBinError(bin,(pow(value,2)==0)?0.:error/pow(value,2));
4167  }
4168  }
4169  }
4170  return inv;
4171 }
4172 
4173 ////////////////////////////////////////////////////////////////////////////////
4174 
4175 void PTools::setHistErrors(TH1* h,TH1* h2)
4176 {
4177  // sets bincontent of hist h2 as errors of h
4178  // lent from jochen
4179  if(h!=0&&h2!=0)
4180  {
4181  TString classname=h->ClassName();
4182  Int_t type=0;
4183 
4184  if(classname.Contains("TH1")==1)type=1;
4185  if(classname.Contains("TH2")==1)type=2;
4186 
4187  Int_t binsX=0,binsY=0;
4188 
4189  binsX=h->GetNbinsX();
4190  if(type==2)binsY=h->GetNbinsY();
4191 
4192  Double_t bincontent;
4193 
4194  if(type==1)
4195  {
4196  for(Int_t x=0;x<=binsX;x++)
4197  {
4198  bincontent= h2->GetBinContent(x+1);
4199  h->SetBinError(x+1,bincontent);
4200  }
4201  }
4202  if(type==2)
4203  {
4204  for(Int_t x=0;x<=binsX;x++)
4205  {
4206  for(Int_t y=0;y<=binsY;y++){
4207  bincontent= h2->GetBinContent(x+1,y+1);
4208  h->SetBinError(x+1,y+1,bincontent);
4209  }
4210  }
4211  }
4212  }
4213  else
4214  {
4215  cout<<"Warning: PTools::cleanHist : ZERO pointer for hist recieved!"<<endl;
4216  }
4217 }
4218 ////////////////////////////////////////////////////////////////////////////////
4219 // ////////////////////////////////////////////////////////////////////////////////
4220 
4221 
4222 // TH1* PTools::divide(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2, Option_t *option)
4223 // {
4224 // // following calculation
4225 // //
4226 // // h1 = c1*h1/(c2*h2)
4227 // //
4228 // // if errors are defined (see TH1::Sumw2), errors are also recalculated
4229 // // Note that if h1 or h2 have Sumw2 set, Sumw2 is automatically called for this
4230 // // if not already set.
4231 // // The resulting errors are calculated assuming uncorrelated histograms.
4232 // // However, if option ="B" is specified, Binomial errors are computed.
4233 // //
4234 // // IMPORTANT NOTE: If you intend to use the errors of this histogram later
4235 // // you should call Sumw2 before making this operation.
4236 // // This is particularly important if you fit the histogram after TH1::Divide
4237 
4238 // TString opt = option;
4239 // opt.ToLower();
4240 // Bool_t binomial = kFALSE;
4241 // if (opt.Contains("b")) binomial = kTRUE;
4242 
4243 // if (!h1)
4244 // {
4245 // ::Error("setErrorsOfHistogram"," h1 is NULL pointer ... nothing done");
4246 // return;
4247 // }
4248 
4249 // if (!h2)
4250 // {
4251 // ::Error("setErrorsOfHistogram"," h2 is NULL pointer ... nothing done");
4252 // return;
4253 // }
4254 
4255 // // compatibility
4256 
4257 // Int_t check = checkHistogramCompatibility(h1, h2);
4258 // if (check > 0)
4259 // {
4260 // ::Error("setErrorsOfHistogram"," h2 and h1 are not compatible %i ... nothing done",check);
4261 // return;
4262 // }
4263 
4264 // //
4265 
4266 // Int_t nbinsx = h1->GetNbinsX();
4267 // Int_t nbinsy = h1->GetNbinsY();
4268 // Int_t nbinsz = h1->GetNbinsZ();
4269 
4270 // if (h1->GetDimension()<2) nbinsy = -1;
4271 // if (h1->GetDimension()<3) nbinsz = -1;
4272 
4273 // // Create Sumw2 if h1 or h2 have Sumw2 set
4274 // if (h1->GetSumw2N() == 0 || h2->GetSumw2N() != 0) h1->Sumw2();
4275 // if (h1->GetSumw2N() != 0 || h2->GetSumw2N() == 0) h2->Sumw2();
4276 
4277 // // Reset the kCanRebin option. Otherwise SetBinContent on the overflow bin
4278 // // would resize the axis limits!
4279 // ResetBit(kCanRebin);
4280 
4281 // Int_t bin, binx, biny, binz;
4282 // Double_t b1,b2,w,d1,d2;
4283 // d1 = c1*c1;
4284 // d2 = c2*c2;
4285 // for (binz=0;binz<=nbinsz+1;binz++) {
4286 // for (biny=0;biny<=nbinsy+1;biny++) {
4287 // for (binx=0;binx<=nbinsx+1;binx++) {
4288 // bin = binx +(nbinsx+2)*(biny + (nbinsy+2)*binz);
4289 // b1 = h1->GetBinContent(bin);
4290 // b2 = h2->GetBinContent(bin);
4291 // if (b2) w = c1*b1/(c2*b2);
4292 // else w = 0;
4293 // SetBinContent(bin,w);
4294 // fEntries++;
4295 // if (fSumw2.fN) {
4296 // Double_t e1 = h1->GetBinError(bin);
4297 // Double_t e2 = h2->GetBinError(bin);
4298 // Double_t b22= b2*b2*d2;
4299 // if (!b2) { fSumw2.fArray[bin] = 0; continue;}
4300 // if (binomial) {
4301 // fSumw2.fArray[bin] = TMath::Abs(w*(1-w)/b2);
4302 // } else {
4303 // fSumw2.fArray[bin] = d1*d2*(e1*e1*b2*b2 + e2*e2*b1*b1)/(b22*b22);
4304 // }
4305 // }
4306 // }
4307 // }
4308 // }
4309 
4310 // Int_t binx,biny,binz,bin;
4311 
4312 // for (binz=0;binz<=nbinsz+1;binz++)
4313 // {
4314 // for (biny=0;biny<=nbinsy+1;biny++)
4315 // {
4316 // for (binx=0;binx<=nbinsx+1;binx++)
4317 // {
4318 // bin = hist->GetBin(binx,biny,binz);
4319 // hist->SetBinError(bin, err->GetBinContent(bin));
4320 // }
4321 // }
4322 // }
4323 // }
4324 
4325 
4326 // // modified Divide from TH1 of 400-08
4327 // // -*-*-*Replace contents of this histogram by the division of h1 by h2*-*-*
4328 // // ==============================================================
4329 // //
4330 // // hist = c1*h1/(c2*h2)
4331 // //
4332 
4333 // // - Reset statistics
4334 // Double_t nEntries = fEntries;
4335 // fEntries = fTsumw = 0;
4336 
4337 // SetMinimum();
4338 // SetMaximum();
4339 
4340 // // - Loop on bins (including underflows/overflows)
4341 
4342 
4343 // Stat_t s[10];
4344 // GetStats(s);
4345 // PutStats(s);
4346 // if (nEntries == 0) nEntries = h1->GetEntries();
4347 // if (nEntries == 0) nEntries = 1;
4348 // SetEntries(nEntries);
4349 // }
4350 
4351 
4352 ////////////////////////////////////////////////////////////////////////////////
4353 ////////////////////////////////////////////////////////////////////////////////
4354 ////////////////////////////////////////////////////////////////////////////////
4355 
4356 ////////////////////////////////////////////////////////////////////////////////
4357 
4358 TH2D *PTools::reBinHistX(TH2* hist,Int_t factor)
4359 {
4360  // returns a pointer to a histogram containing for each bin the value 1/value
4361  // if value = 0, the ratio is set to 0
4362  //
4363  // the name is "OneOverHist" and the title "1/hist"
4364  // if hist is NULL ... NULL is returned
4365 
4366  if (!hist)
4367  {
4368  ::Error("getOneOverHist"," hist is NULL pointer ... cannot act on a NULL pointer.");
4369  return NULL;
4370  }
4371 
4372  Int_t nbinsx = hist->GetNbinsX();
4373  Int_t nbinsy = hist->GetNbinsY();
4374  Int_t nbinsz = hist->GetNbinsZ();
4375 
4376  if (hist->GetDimension()<2) nbinsy = -1;
4377  if (hist->GetDimension()<3) nbinsz = -1;
4378 
4379  Int_t binx,biny,binz,bin=0;
4380 
4381  Double_t value, error;
4382 
4383  TString name = hist->GetName();
4384  name+="_rebin";
4385 
4386  TH2D* inv = new TH2D(name.Data(),name.Data(),
4387  Int_t (nbinsx/factor), hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
4388  Int_t (nbinsy), hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
4389 
4390  importAxisAttributes(hist->GetXaxis(), inv->GetXaxis(), kTRUE);
4391  importAxisAttributes(hist->GetYaxis(), inv->GetYaxis(), kTRUE);
4392  importAxisAttributes(hist->GetZaxis(), inv->GetZaxis(), kTRUE);
4393 
4394  inv->Reset();
4395  Int_t index=0;
4396 
4397  for (binz=0;binz<=nbinsz+1;binz++)
4398  {
4399  for (biny=0;biny<=nbinsy+1;biny++)
4400  {
4401  for (binx=0;binx<=nbinsx+1;binx++)
4402  {
4403  if (binx==0 || binx == nbinsx+1)
4404  {
4405  bin = hist->GetBin(binx,biny,binz);
4406  value = hist->GetBinContent(bin);
4407  error = hist->GetBinError(bin);
4408  inv->SetBinContent(bin,(value==0)?0.:1./value);
4409  inv->SetBinError(bin,(pow(value,2)==0)?0.:error/pow(value,2));
4410  }
4411  else
4412  {
4413  value=0;
4414  error=0;
4415  for (Int_t fctr=0; fctr < factor; fctr++)
4416  {
4417  if (fctr==nbinsx+1) {break;}
4418 
4419  bin = hist->GetBin(binx+fctr,biny,binz);
4420  value += hist->GetBinContent(bin);
4421  error += pow(hist->GetBinError(bin),2);
4422  }
4423  inv->SetBinContent(index,value);
4424  inv->SetBinError(index,::std::sqrt(error));
4425  binx+=(factor-1);
4426  }
4427  index++;
4428  }
4429  }
4430  }
4431  inv->SetStats(0);
4432  return inv;
4433 }
4434 
4435 ////////////////////////////////////////////////////////////////////////////////
4436 
4437 void PTools::cleanHistogramPtyOnP(TH2 * hist, Double_t mass, Double_t min, Double_t max, Double_t replaceBy)
4438 {
4439  // cleans histograms
4440  // bin contents out of the limits for p min and max
4441  // are set to replaceBy
4442  // errors are set to error 0
4443  // mass of particle needed
4444 
4445  if (!hist)
4446  {
4447  ::Error("cleanHistogram"," hist is NULL pointer ... return NULL");
4448  return;
4449  }
4450 
4451  Int_t nbinsx = hist->GetNbinsX();
4452  Int_t nbinsy = hist->GetNbinsY();
4453  Int_t nbinsz = hist->GetNbinsZ();
4454 
4455  if (hist->GetDimension()<2) nbinsy = -1;
4456  nbinsz = -1;
4457 
4458  Int_t binx,biny,binz,bin;
4459  Double_t p=0.;
4460  Double_t pt;
4461  Double_t y;
4462 
4463  for (binz=0;binz<=nbinsz+1;binz++)
4464  {
4465  for (biny=0;biny<=nbinsy+1;biny++)
4466  {
4467  pt = hist->GetYaxis()->GetBinCenter(biny);
4468  for (binx=0;binx<=nbinsx+1;binx++)
4469  {
4470  bin = hist->GetBin(binx,biny,binz);
4471  y = hist->GetXaxis()->GetBinCenter(binx);
4472  p = sinh(y)*::std::sqrt(2 *(pow(pt,2)+pow(mass,2)));
4473 
4474  if (p < min || p > max)
4475  {
4476  hist->SetBinContent(bin,replaceBy);
4477  hist->SetBinError(bin,0);
4478  }
4479  }
4480  }
4481  }
4482 }
4483 
4484 ////////////////////////////////////////////////////////////////////////////////
4485 
4486 Int_t PTools::findEndOfDistribution(TH1* hist, Int_t min, Double_t threshold, Bool_t compact)
4487 {
4488  // returns bin number where distribution ends
4489  // i.e where no data is beyond threshold
4490  // starting from left to right at bin number min
4491  // returns -1 if hist is NULL
4492  // if compact is set no bin larger min is accepted to be below threshold
4493  // otherwise wholes of 1 bins are allowed
4494 
4495  if (!hist)
4496  {
4497  ::Error("findEndOfDistribution"," hist is NULL pointer ... return -1");
4498  return -1;
4499  }
4500 
4501  if (min<1) {min=1;}
4502 
4503  Int_t nbinsx = hist->GetNbinsX();
4504 
4505  Int_t binIter;
4506 
4507  for (binIter=min; binIter<=nbinsx; binIter++)
4508  {
4509  if (hist->GetBinContent(binIter) > threshold) { continue;}
4510  if (compact)
4511  {
4512  if ((binIter+1 > nbinsx) ||(hist->GetBinContent(binIter+1) <= threshold)) break;
4513  }
4514  else
4515  {
4516  if ( ((binIter+1 > nbinsx) ||(hist->GetBinContent(binIter+1) <= threshold)) &&
4517  ((binIter+2 > nbinsx) ||(hist->GetBinContent(binIter+2) <= threshold))) break;
4518  }
4519  }
4520  return binIter;
4521 }
4522 
4523 ////////////////////////////////////////////////////////////////////////////////
4524 
4525 Int_t PTools::findBeginOfDistribution(TH1* hist, Int_t max, Double_t threshold, Bool_t compact)
4526 {
4527  // returns bin number where distribution begins
4528  // i.e where no data is beyond threshold
4529  // starting from right to left at bin number max
4530  // returns -1 if hist is NULL
4531  // if compact is set no bin smaller than max is accepted to be below threshold
4532  // otherwise wholes of 1 bins are allowed
4533 
4534  if (!hist)
4535  {
4536  ::Error("findBeginOfDistribution"," hist is NULL pointer ... return -1");
4537  return -1;
4538  }
4539 
4540  Int_t nbinsx = hist->GetNbinsX();
4541 
4542  Int_t binIter;
4543  if (max>nbinsx) { max = nbinsx; }
4544 
4545  for (binIter=max; binIter>0; binIter--)
4546  {
4547  if (hist->GetBinContent(binIter) > threshold) { continue;}
4548  if (compact)
4549  {
4550  if ( ((binIter-1 <= 0) ||(hist->GetBinContent(binIter-1) <= threshold))) break;
4551  }
4552  else
4553  {
4554  if ( ((binIter-1 <= 0) ||(hist->GetBinContent(binIter-1) <= threshold)) &&
4555  ((binIter-2 <= 0) ||(hist->GetBinContent(binIter-2) <= threshold))) break;
4556  }
4557 
4558  }
4559  return binIter;
4560 }
4561 
4562 ////////////////////////////////////////////////////////////////////////////////
4563 
4564 void PTools::scaleHistErrors(TH1* hist, Double_t scaleFactor)
4565 {
4566  // scales Errors of hist by scaleFactor
4567 
4568  if (!hist)
4569  {
4570  ::Error("scaleHistErrors"," hist is NULL pointer ... cannot act on a NULL pointer.");
4571  return;
4572  }
4573 
4574  Int_t nbinsx = hist->GetNbinsX();
4575  Int_t nbinsy = hist->GetNbinsY();
4576  Int_t nbinsz = hist->GetNbinsZ();
4577 
4578  if (hist->GetDimension()<2) nbinsy = -1;
4579  if (hist->GetDimension()<3) nbinsz = -1;
4580 
4581  Int_t binx,biny,binz,bin;
4582 
4583 
4584  for (binz=0;binz<=nbinsz+1;binz++)
4585  {
4586  for (biny=0;biny<=nbinsy+1;biny++)
4587  {
4588  for (binx=0;binx<=nbinsx+1;binx++)
4589  {
4590  bin = hist->GetBin(binx,biny,binz);
4591  hist->SetBinError(bin,hist->GetBinError(bin)*scaleFactor);
4592  }
4593  }
4594  }
4595  return;
4596 }
4597 
4598 ////////////////////////////////////////////////////////////////////////////////
4599 
4601  Int_t xbinmin, Int_t xbinmax,
4602  Int_t ybinmin, Int_t ybinmax,
4603  Int_t zbinmin, Int_t zbinmax
4604  )
4605 {
4606  // copies subsection of any THx histogramm hist to THxD histograms
4607  // you have to speciy via xbinmin [default:-1], xbinmax [default:-1],
4608  // ybinmin [default:-1], ybinmax [default:-1],
4609  // zbinmin [default:-1], zbinmax [default:-1]
4610  // the bin range you want to select
4611  // (NOTE: To choose the coordinates you have to use ((TAxis*)hist->GetXaxis())->FindBin(value); )
4612  // (NOTE: you have to cast to the corresponding type of histogram)
4613  //
4614  // attaches to name "_subset_X_xminbin-xmaxbin"
4615  // "_subset_X_xminbin-xmaxbin_Y_yminbin-ymaxbin"
4616  // "_subset_X_xminbin-xmaxbin_Y_yminbin-ymaxbin_Z_zminbin-zmaxbin
4617  //
4618  // if hist is NULL, NULL is returned
4619  // in case dimension doesn't match with bin minima and maxima dimensions
4620  // the choice is ignored.
4621  // if xbinmin, xbinmax, ybinmin, yzbinmax, zbinmin, yxbinmax are negativ the full range is taken
4622  // if minima > maxima NULL is returned
4623  //
4624  // The entries are copied from the original histogram, because they cannot calculated
4625 
4626  // check for valid histogram pointer
4627  if (! hist)
4628  {
4629  ::Error("copyBinSubsetOfHist","histogram has NULL pointer ... returning NULL");
4630  return NULL;
4631  }
4632 
4633  // check for valid limit order / excluding negativ values for full range
4634  if ( xbinmin > xbinmax && xbinmax > 0)
4635  {
4636  ::Error("copyBinSubsetOfHist","invalid choice of bin ranges xmin (%i) > xmax (%i) ... returning NULL",
4637  xbinmin, xbinmax);
4638  return NULL;
4639  }
4640  if ( ybinmin > ybinmax && ybinmax > 0)
4641  {
4642  ::Error("copyBinSubsetOfHist","invalid choice of bin ranges ymin (%i) > ymax (%i) ... returning NULL",
4643  ybinmin, ybinmax);
4644  return NULL;
4645  }
4646  if ( zbinmin > zbinmax && zbinmax > 0)
4647  {
4648  ::Error("copyBinSubsetOfHist","invalid choice of bin ranges zmin (%i) > zmax (%i) ... returning NULL",
4649  zbinmin, zbinmax);
4650  return NULL;
4651  }
4652 
4653  // get number of bins
4654  Int_t nbinsx = hist->GetNbinsX();
4655  Int_t nbinsy = hist->GetNbinsY();
4656  Int_t nbinsz = hist->GetNbinsZ();
4657 
4658  // get dimension;
4659  Int_t dimension = hist->GetDimension();
4660 
4661  // check if choice exceeds maximum bin
4662  if (dimension >= 1)
4663  {
4664  if ( xbinmax > nbinsx )
4665  {
4666  ::Error("copyBinSubsetOfHist","xbinmax: %i exceeds histograms bin range of %i ... returning NULL"
4667  , xbinmax, nbinsx);
4668  return NULL;
4669  }
4670  }
4671 
4672  if (dimension >= 2)
4673  {
4674  if ( ybinmax > nbinsy )
4675  {
4676  ::Error("copyBinSubsetOfHist","ybinmax: %i exceeds histograms bin range of %i ... returning NULL"
4677  , ybinmax, nbinsy);
4678  return NULL;
4679  }
4680  }
4681  if (dimension >= 3)
4682  {
4683  if ( zbinmax > nbinsz )
4684  {
4685  ::Error("copyBinSubsetOfHist","zbinmax: %i exceeds histograms bin range of %i ... returning NULL"
4686  , zbinmax, nbinsz);
4687  return NULL;
4688  }
4689  }
4690 
4691 
4692  // if ranges are negativ take maximum/minimum possible value;
4693  if (xbinmin < 0 ) xbinmin = 0;
4694  if (xbinmax < 0 ) xbinmax = nbinsx+1;
4695  if (ybinmin < 0 ) ybinmin = 0;
4696  if (ybinmax < 0 ) ybinmax = nbinsy+1;
4697  if (zbinmin < 0 ) zbinmin = 0;
4698  if (zbinmax < 0 ) zbinmax = nbinsz+1;
4699 
4700  if (dimension<2) {nbinsy = -1; ybinmin=0; ybinmax=0;}
4701  if (dimension<3) {nbinsz = -1; zbinmin=0; zbinmax=0;}
4702 
4703  // create new histogram
4704  TString name;
4705  TString title;
4706  TH1* histD = NULL;
4707 
4708  switch(dimension)
4709  {
4710  case 1:
4711  {
4712  name = Form("%s_subset_X_%i-%i",
4713  hist->GetName(),
4714  (xbinmin==0 )? 1 :xbinmin,
4715  (xbinmax==nbinsx+1)? nbinsx:xbinmax);
4716  title = Form("%s ( subset X: bin %i - bin %i )",
4717  hist->GetTitle(),
4718  (xbinmin==0 )? 1 :xbinmin,
4719  (xbinmax==nbinsx+1)? nbinsx:xbinmax);
4720  histD = new TH1D(name.Data(),title.Data(),
4721  xbinmax-xbinmin+1,
4722  hist->GetXaxis()->GetBinLowEdge(xbinmin),
4723  hist->GetXaxis()->GetBinUpEdge (xbinmax)
4724  );
4725  break;
4726  }
4727  case 2:
4728  {
4729  name = Form("%s_subset_X_%i-%i_Y_%i-%i",
4730  hist->GetName(),
4731  (xbinmin==0 )? 1 :xbinmin,
4732  (xbinmax==nbinsx+1)? nbinsx:xbinmax,
4733  (ybinmin==0 )? 1 :ybinmin,
4734  (ybinmax==nbinsy+1)? nbinsy:ybinmax);
4735  title = Form("%s ( subset X: bin %i - bin %i, Y: bin %i - bin %i )",
4736  hist->GetTitle(),
4737  (xbinmin==0 )? 1 :xbinmin,
4738  (xbinmax==nbinsx+1)? nbinsx:xbinmax,
4739  (ybinmin==0 )? 1 :ybinmin,
4740  (ybinmax==nbinsy+1)? nbinsy:ybinmax);
4741  histD = new TH2D(name.Data(),title.Data(),
4742  xbinmax-xbinmin+1,
4743  hist->GetXaxis()->GetBinLowEdge(xbinmin),
4744  hist->GetXaxis()->GetBinUpEdge (xbinmax),
4745  ybinmax-ybinmin+1,
4746  hist->GetYaxis()->GetBinLowEdge(ybinmin),
4747  hist->GetYaxis()->GetBinUpEdge (ybinmax)
4748  );
4749  break;
4750  }
4751  case 3:
4752  {
4753  name = Form("%s_subset_X_%i-%i_Y_%i-%i_Z_%i-%i",
4754  hist->GetName(),
4755  (xbinmin==0 )? 1 :xbinmin,
4756  (xbinmax==nbinsx+1)? nbinsx:xbinmax,
4757  (ybinmin==0 )? 1 :ybinmin,
4758  (ybinmax==nbinsy+1)? nbinsy:ybinmax,
4759  (zbinmin==0 )? 1 :zbinmin,
4760  (zbinmax==nbinsz+1)? nbinsz:zbinmax);
4761  title = Form("%s ( subset X: bin %i - bin %i, Y: bin %i - bin %i, Z: bin %i - bin %i )",
4762  hist->GetTitle(),
4763  (xbinmin==0 )? 1 :xbinmin,
4764  (xbinmax==nbinsx+1)? nbinsx:xbinmax,
4765  (ybinmin==0 )? 1 :ybinmin,
4766  (ybinmax==nbinsy+1)? nbinsy:ybinmax,
4767  (zbinmin==0 )? 1 :zbinmin,
4768  (zbinmax==nbinsz+1)? nbinsz:zbinmax);
4769  histD = new TH3D(name.Data(),title.Data(),
4770  xbinmax-xbinmin+1,
4771  hist->GetXaxis()->GetBinLowEdge(xbinmin),
4772  hist->GetXaxis()->GetBinUpEdge (xbinmax),
4773  ybinmax-ybinmin+1,
4774  hist->GetYaxis()->GetBinLowEdge(ybinmin),
4775  hist->GetYaxis()->GetBinUpEdge (ybinmax),
4776  zbinmax-zbinmin+1,
4777  hist->GetZaxis()->GetBinLowEdge(zbinmin),
4778  hist->GetZaxis()->GetBinUpEdge (zbinmax)
4779  );
4780  break;
4781  }
4782  default:
4783  {
4784  ::Error("copyBinSubsetOfHist","invalid dimension: %i ... returning NULL",dimension);
4785  return NULL;
4786  break;
4787  }
4788  }
4789 
4790  // copy axis attributes
4791  importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
4792  importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
4793  importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
4794 
4795  // misc settings
4796  histD->SetEntries(hist->GetEntries());
4797  if (hist->GetSumw2N()) {hist->Sumw2();}
4798 
4799  Int_t binx,biny,binz,bin,newbin;
4800 
4801  for (binz=zbinmin;binz<=zbinmax;binz++)
4802  {
4803  for (biny=ybinmin;biny<=ybinmax;biny++)
4804  {
4805  for (binx=xbinmin;binx<=xbinmax;binx++)
4806  {
4807  bin = hist->GetBin(binx,biny,binz);
4808  newbin = histD->GetBin(
4809  histD->GetXaxis()->FindBin( hist->GetXaxis()->GetBinCenter(binx)),
4810  histD->GetYaxis()->FindBin( hist->GetYaxis()->GetBinCenter(biny)),
4811  histD->GetZaxis()->FindBin( hist->GetZaxis()->GetBinCenter(binz))
4812  );
4813  histD->SetBinContent(newbin, hist->GetBinContent(bin));
4814  if (hist->GetSumw2N())
4815  {
4816  histD->SetBinError(newbin,hist->GetBinError(bin));
4817  }
4818  }
4819  }
4820  }
4821  return histD;
4822 }
4823 
4824 ////////////////////////////////////////////////////////////////////////////////
4825 const Double_t PTools::copySubsetOfHistDefaultValue = -1.35791e-300;
4826 
4828  Double_t xmin, Double_t xmax,
4829  Double_t ymin, Double_t ymax,
4830  Double_t zmin, Double_t zmax
4831  )
4832 {
4833  // copies subsection of any THx histogramm hist to THxD histograms
4834  // you have to speciy via xmin [default: PTools::copySubsetOfHistDefaultValue],
4835  // xmax [default: PTools::copySubsetOfHistDefaultValue],
4836  // ymin [default: PTools::copySubsetOfHistDefaultValue],
4837  // ymax [default: PTools::copySubsetOfHistDefaultValue],
4838  // zmin [default: PTools::copySubsetOfHistDefaultValue],
4839  // zmax [default: PTools::copySubsetOfHistDefaultValue]
4840  // the range you want to select
4841  // via ((TAxis*)hist->GetXaxis())->FindBin(value); the corresponding bin range is calculated
4842  //
4843  // Following copyBinSubsetOfHist is called and afterwards the name and title of the histogram are just adopted
4844  //
4845  // to name "_subset_X_xmin-xmax"
4846  // "_subset_X_xmin-xmax_Y_ymin-ymax"
4847  // "_subset_X_xmin-xmax_Y_ymin-ymax_Z_zmin-zmax
4848  //
4849  // if hist is NULL, NULL is returned
4850  // in case dimension doesn't match with bin minima and maxima dimensions
4851  // the choice is ignored.
4852  // if xbinmin, xbinmax, ybinmin, yzbinmax, zbinmin, yxbinmax are PTools::copySubsetOfHistDefaultValue
4853  // the full range is taken
4854  // if minima > maxima NULL is returned
4855  //
4856  // The entries are copied from the original histogram, because they cannot calculated
4857  //
4858  // (NOTE: you have to cast to the corresponding type of histogram)
4859 
4860  // check for valid histogram pointer
4861  if (! hist)
4862  {
4863  ::Error("copySubsetOfHist","histogram has NULL pointer ... returning NULL");
4864  return NULL;
4865  }
4866 
4867  Int_t dimension = hist->GetDimension();
4868  Int_t xbinmin=-1,xbinmax=-1,ybinmin=-1,ybinmax=-1,zbinmin=-1,zbinmax=-1;
4869 
4870  // get number of bins
4871  Int_t nbinsx = hist->GetNbinsX();
4872  Int_t nbinsy = hist->GetNbinsY();
4873  Int_t nbinsz = hist->GetNbinsZ();
4874 
4875  if (dimension > 0)
4876  {
4877  xbinmin = (xmin==PTools::copySubsetOfHistDefaultValue) ? -1 : hist->GetXaxis()->FindBin(xmin);
4878  // overflow/underflow bin check
4879  if (xbinmin<1 || xbinmin>nbinsx)
4880  {
4881  ::Error("copySubsetOfHist","xmin: %f exceeds range of x-axis [%f,%f] ... returning NULL",
4882  xmin,hist->GetXaxis()->GetBinLowEdge(1),hist->GetXaxis()->GetBinUpEdge(nbinsx));
4883  return NULL;
4884  }
4885  xbinmax = (xmax==PTools::copySubsetOfHistDefaultValue) ? -1 : hist->GetXaxis()->FindBin(xmax);
4886  // overflow/underflow bin check
4887  if (xbinmax<1 || xbinmax>nbinsx)
4888  {
4889  ::Error("copySubsetOfHist","xmax: %f exceeds range of x-axis [%f,%f] ... returning NULL",
4890  xmax,hist->GetXaxis()->GetBinLowEdge(1),hist->GetXaxis()->GetBinUpEdge(nbinsx));
4891  return NULL;
4892  }
4893  if (xbinmax!=-1) xbinmax--;
4894  }
4895  if (dimension > 1)
4896  {
4897  ybinmin = (ymin==PTools::copySubsetOfHistDefaultValue) ? -1 : hist->GetYaxis()->FindBin(ymin);
4898  // overflow/underflow bin check
4899  if (ybinmin<1 || ybinmin>nbinsy)
4900  {
4901  ::Error("copySubsetOfHist","ymin: %f exceeds range of y-axis [%f,%f] ... returning NULL",
4902  ymin,hist->GetYaxis()->GetBinLowEdge(1),hist->GetYaxis()->GetBinUpEdge(nbinsy));
4903  return NULL;
4904  }
4905  ybinmax = (ymax==PTools::copySubsetOfHistDefaultValue) ? -1 : hist->GetYaxis()->FindBin(ymax);
4906  // overflow/underflow bin check
4907  if (ybinmax<1 || ybinmax>nbinsy)
4908  {
4909  ::Error("copySubsetOfHist","ymax: %f exceeds range of y-axis [%f,%f] ... returning NULL",
4910  ymax,hist->GetYaxis()->GetBinLowEdge(1),hist->GetYaxis()->GetBinUpEdge(nbinsy));
4911  return NULL;
4912  }
4913  if (ybinmax!=-1) ybinmax--;
4914  }
4915  if (dimension > 2)
4916  {
4917  zbinmin = (zmin==PTools::copySubsetOfHistDefaultValue) ? -1 : hist->GetZaxis()->FindBin(zmin);
4918  // overflow/underflow bin check
4919  if (zbinmin<1 || zbinmin>nbinsz)
4920  {
4921  ::Error("copySubsetOfHist","zmin: %f exceeds range of z-axis [%f,%f] ... returning NULL",
4922  zmin,hist->GetZaxis()->GetBinLowEdge(1),hist->GetZaxis()->GetBinUpEdge(nbinsz));
4923  return NULL;
4924  }
4925  zbinmax = (zmax==PTools::copySubsetOfHistDefaultValue) ? -1 : hist->GetZaxis()->FindBin(zmax);
4926  // overflow/underflow bin check
4927  if (zbinmax<1 || zbinmax>nbinsz)
4928  {
4929  ::Error("copySubsetOfHist","zmax: %f exceeds range of z-axis [%f,%f] ... returning NULL",
4930  zmax,hist->GetZaxis()->GetBinLowEdge(1),hist->GetZaxis()->GetBinUpEdge(nbinsz));
4931  return NULL;
4932  }
4933  if (ybinmax!=-1) zbinmax--;
4934  }
4935 
4936  TH1* histD = copyBinSubsetOfHist(hist, xbinmin, xbinmax, ybinmin, ybinmax, zbinmin, zbinmax);
4937 
4938  // check for valid pointer
4939  if (!histD) return NULL;
4940 
4941  // rename histogram
4942 
4943  // create new histogram
4944  TString name;
4945  TString title;
4946 
4947  switch(dimension)
4948  {
4949  case 1:
4950  {
4951  name = Form("%s_subset_X_%2.2g-%2.2g",
4952  hist->GetName(),
4953  (xbinmin==0 )? hist->GetXaxis()->GetBinLowEdge(1) :xmin,
4954  (xbinmax==nbinsx+1)? hist->GetXaxis()->GetBinLowEdge(nbinsx):xmax);
4955  title = Form("%s ( subset X: %2.2g - %2.2g )",
4956  hist->GetTitle(),
4957  (xbinmin==0 )? hist->GetXaxis()->GetBinLowEdge(1) :xmin,
4958  (xbinmax==nbinsx+1)? hist->GetXaxis()->GetBinLowEdge(nbinsx):xmax);
4959  break;
4960  }
4961  case 2:
4962  {
4963  name = Form("%s_subset_X_%2.2g-%2.2g_Y_%2.2g-%2.2g",
4964  hist->GetName(),
4965  (xbinmin==0 )? hist->GetXaxis()->GetBinLowEdge(1) :xmin,
4966  (xbinmax==nbinsx+1)? hist->GetXaxis()->GetBinLowEdge(nbinsx):xmax,
4967  (ybinmin==0 )? hist->GetYaxis()->GetBinLowEdge(1) :ymin,
4968  (ybinmax==nbinsy+1)? hist->GetYaxis()->GetBinLowEdge(nbinsy):ymax);
4969  title = Form("%s ( subset X: %2.2g - %2.2g, Y: %2.2g - %2.2g )",
4970  hist->GetTitle(),
4971  (xbinmin==0 )? hist->GetXaxis()->GetBinLowEdge(1) :xmin,
4972  (xbinmax==nbinsx+1)? hist->GetXaxis()->GetBinLowEdge(nbinsx):xmax,
4973  (ybinmin==0 )? hist->GetYaxis()->GetBinLowEdge(1) :ymin,
4974  (ybinmax==nbinsy+1)? hist->GetYaxis()->GetBinLowEdge(nbinsy):ymax);
4975  break;
4976  }
4977  case 3:
4978  {
4979  name = Form("%s_subset_X_%2.2g-%2.2g_Y_%2.2g-%2.2g_Z_%2.2g-%2.2g",
4980  hist->GetName(),
4981  (xbinmin==0 )? hist->GetXaxis()->GetBinLowEdge(1) :xmin,
4982  (xbinmax==nbinsx+1)? hist->GetXaxis()->GetBinLowEdge(nbinsx):xmax,
4983  (ybinmin==0 )? hist->GetYaxis()->GetBinLowEdge(1) :ymin,
4984  (ybinmax==nbinsy+1)? hist->GetYaxis()->GetBinLowEdge(nbinsy):ymax,
4985  (zbinmin==0 )? hist->GetZaxis()->GetBinLowEdge(1) :zmin,
4986  (zbinmax==nbinsz+1)? hist->GetZaxis()->GetBinLowEdge(nbinsz):zmax);
4987  title = Form("%s ( subset X: %2.2g - %2.2g, Y: %2.2g - %2.2g, Z: %2.2g - %2.2g )",
4988  hist->GetTitle(),
4989  (xbinmin==0 )? hist->GetXaxis()->GetBinLowEdge(1) :xmin,
4990  (xbinmax==nbinsx+1)? hist->GetXaxis()->GetBinLowEdge(nbinsx):xmax,
4991  (ybinmin==0 )? hist->GetYaxis()->GetBinLowEdge(1) :ymin,
4992  (ybinmax==nbinsy+1)? hist->GetYaxis()->GetBinLowEdge(nbinsy):ymax,
4993  (zbinmin==0 )? hist->GetZaxis()->GetBinLowEdge(1) :zmin,
4994  (zbinmax==nbinsz+1)? hist->GetZaxis()->GetBinLowEdge(nbinsz):zmax);
4995  break;
4996  }
4997  default:
4998  {
4999  ::Error("copySubsetOfHist","invalid dimension: %i ... returning NULL",dimension);
5000  return NULL;
5001  break;
5002  }
5003  }
5004 
5005  histD->SetNameTitle(name.Data(),title.Data());
5006 
5007  return histD;
5008 }
static TPaveStats * getHistStatsYPosNDC(TH1 *hist, Double_t &y1, Double_t &y2)
Definition: ptools.cc:3294
static TLatex * drawLatexWC(TString text, Double_t x, Double_t y, Int_t color=1, Float_t size=0.1, Int_t align=11, Int_t font=62, Float_t angle=0.)
Definition: ptools.cc:3673
static TCanvas * draw32CanvasTH2(const Char_t *, const Char_t *, TH2F **, const Char_t *option=0)
Definition: ptools.cc:822
static void evalStopwatch(TStopwatch *timer, Int_t nevts)
Definition: ptools.cc:639
static TLatex * drawLatexNDC(TString text, Double_t x, Double_t y, Int_t color=1, Float_t size=0.1, Int_t align=11, Int_t font=62, Float_t angle=0.)
Definition: ptools.cc:3712
static void prefixToName(TNamed *name, TString prefix)
Definition: ptools.cc:1274
static TPaveStats * getHistStatsPosNDC(TH1 *hist, Double_t &x1, Double_t &x2, Double_t &y1, Double_t &y2)
Definition: ptools.cc:3372
static TLatex * plotTopLegend(const Char_t *label, Float_t x=-1, Float_t y=-1, Float_t size=0.05, Int_t color=1)
Definition: ptools.cc:2239
static TPaveStats * setHistStatsTextColor(TH1 *hist, Int_t color)
Definition: ptools.cc:3413
static void setErrorsOfHistogram(TH1 *hist, TH1 *err)
Definition: ptools.cc:3854
static void mdb(Int_t b=-1)
Definition: ptools.cc:899
static TH3D * getTH3D(TString name, TString title, Int_t xbin, Double_t xmin, Double_t xmax, Int_t ybin, Double_t ymin, Double_t ymax, Int_t zbin, Double_t zmin, Double_t zmax, TString xtitle, TString ytitle, TString ztitle)
Definition: ptools.cc:1589
static Double_t getMeanRange(TH1 *hist, Int_t minX, Int_t maxX, TString s="center")
Definition: ptools.cc:2376
static Double_t getMeanErrorRange(TH1 *hist, Int_t minX, Int_t maxX, TString s="center")
Definition: ptools.cc:2273
static TNamed * Clone(TNamed *name, TString newname="", TString title="")
Definition: ptools.cc:2530
static void sqrt(TH1 *hist)
Definition: ptools.cc:2436
static void printHeader(const Char_t *titlehead=0, const Char_t *mytextfilename=0, const Int_t nentries=0, TPad *pad=0)
Definition: ptools.cc:588
static TPaveStats * setHistStatsPosNDC(TH1 *hist, Double_t x1, Double_t x2, Double_t y1, Double_t y2)
Definition: ptools.cc:3253
static TH1F * getTH1F(TString name, TString title, Int_t xbin, Double_t xmin, Double_t xmax, TString xtitle, TString ytitle)
Definition: ptools.cc:1502
static TH2 * reverseYAxis(TH2 *hist)
Definition: ptools.cc:1650
static Double_t getMeanErrorRangeUser(TH1 *hist, Axis_t minX, Axis_t maxX, TString s="center")
Definition: ptools.cc:2258
static TCanvas * drawCanvas(const Char_t *, const Char_t *, TH1 **, Int_t, Int_t)
Definition: ptools.cc:757
static TLatex * drawLatex(TString text, Double_t x, Double_t y, Int_t color=1, Float_t size=0.1, Int_t align=11, Int_t font=62, Float_t angle=0.)
Definition: ptools.cc:3724
static TLatex * drawLatexPadCoords(TString text, Double_t x, Double_t y, Int_t color=1, Float_t size=0.1, Int_t align=11, Int_t font=62, Float_t angle=0.)
Definition: ptools.cc:3751
static Char_t * myexec(const Char_t *)
Definition: ptools.cc:867
static void saveToPng(TCanvas *canvas, TString path=".", TString filename="", Bool_t separate=kFALSE, Int_t selection=-1)
Definition: ptools.cc:1929
static TH2D * createTH2D(TH2 *hist)
Definition: ptools.cc:2732
static void printHistogramLimits(TH1 *hist)
Definition: ptools.cc:1026
p1 SetTitle("Momentum")
static const Double_t copySubsetOfHistDefaultValue
Definition: ptools.h:424
Int_t n
static TGraphErrors * fillGraphErr(TH1 *hist, TString name="", TString position="center", Bool_t xerrors=kFALSE)
Definition: ptools.cc:3025
static void scaleHistErrors(TH1 *hist, Double_t scaleFactor)
Definition: ptools.cc:4564
static void importAxisAttributes(TAxis *in, TAxis *out, Bool_t labels)
Definition: ptools.cc:2752
static TDirectory * Mkdir(TDirectory *dirOld, const Char_t *newDirName, Int_t i=-99, Int_t precision=1)
Makes new Dir, changes to Dir, returns pointer to new Dir.
Definition: ptools.cc:918
static void setLatexArtsNDC(TLatex *tex, Double_t x, Double_t y, Int_t color=1, Float_t size=0.1, Int_t align=11, Int_t font=62, Float_t angle=0.)
Definition: ptools.cc:3487
virtual ~PTools()
Definition: ptools.cc:75
static void setHist(TH1 *hist, Int_t mycolorindex=-99, Int_t markerstyle=20, Int_t markercolor=1, Float_t markersize=1., Int_t linecolor=1)
Definition: ptools.cc:2161
static TH1 * copyBinSubsetOfHist(TH1 *hist, Int_t xbinmin=-1, Int_t xbinmax=-1, Int_t ybinmin=-1, Int_t ybinmax=-1, Int_t zbinmin=-1, Int_t zbinmax=-1)
Definition: ptools.cc:4600
static void cleanHistogramPtyOnP(TH2 *hist, Double_t mass, Double_t min, Double_t max, Double_t replaceBy=0)
Definition: ptools.cc:4437
static void plotPolarGrid(Int_t divisions=18)
Definition: ptools.cc:1769
static void saveToPdf(TCanvas *canvas, TString path=".", TString filename="", Bool_t separate=kFALSE, Int_t selection=-1)
Definition: ptools.cc:1836
static TPaveStats * setHistStatsXPosNDC(TH1 *hist, Double_t x1, Double_t x2)
Definition: ptools.cc:3214
static Bool_t areArraysCompatible(const TArray *array1, const TArray *array2)
Definition: ptools.cc:2907
static TH2D copyToTH2D(TH2 *hist)
Definition: ptools.cc:2700
Double_t sum
static Int_t findEndOfDistribution(TH1 *hist, Int_t min, Double_t threshold, Bool_t compact=kFALSE)
Definition: ptools.cc:4486
static TH1 * reverseXAxis(TH1 *hist)
Definition: ptools.cc:1608
static TH1 * copyToUnitBinsPlusLabels(TH1 *hist, Double_t binningX=1., Double_t binningY=1., Double_t binningZ=1.)
Definition: ptools.cc:3909
static Bool_t loadMacro(const Char_t *macro)
Definition: ptools.cc:3506
static TH2F * getTH2F(TString name, TString title, Int_t xbin, Double_t xmin, Double_t xmax, Int_t ybin, Double_t ymin, Double_t ymax, TString xtitle, TString ytitle, TString ztitle="")
Definition: ptools.cc:1513
static void setGraph(TGraph *graph, Int_t mycolorindex=-99, Int_t markerstyle=20, Int_t markercolor=1, Float_t markersize=1., Int_t linecolor=1)
Definition: ptools.cc:2138
static void getHistogramLimits(TH1 *hist, Int_t &nbinsx, Axis_t &xmin, Axis_t &xmax)
Definition: ptools.cc:1014
static TH1D * getBinContentDistribution(TH1 *hist, Int_t binning=-1, Bool_t excludeUnderAndOverFlowBins=kFALSE)
Definition: ptools.cc:4045
Double_t pt
static TLegend * plotLegend(TString pos="right_top", TString Title="No Title", Float_t scaleX=0.9, Float_t scaleY=0.9, Float_t offsetX=0.0, Float_t offsetY=0.0, TString Comment="", Int_t commencolor=1)
Definition: ptools.cc:2184
static Int_t getMarkerJM(Int_t i)
Definition: ptools.cc:2128
static TH1D * getTH1D(TString name, TString title, Int_t xbin, Double_t xmin, Double_t xmax, TString xtitle, TString ytitle)
Definition: ptools.cc:1555
static void plotPolarAxis(Double_t min=0.0, Double_t max=180, Int_t divisions=10, Float_t direction=90)
Definition: ptools.cc:1735
static TH3F * getTH3F(TString name, TString title, Int_t xbin, Double_t xmin, Double_t xmax, Int_t ybin, Double_t ymin, Double_t ymax, Int_t zbin, Double_t zmin, Double_t zmax, TString xtitle, TString ytitle, TString ztitle)
Definition: ptools.cc:1536
static void setTitleArts(TH1 *histogramm, const Char_t *xtitle, const Char_t *ytitle, Int_t color=4, Int_t type=42)
Definition: ptools.cc:711
static void plotCounts(TH1 *hist, Int_t color=1, TString format="")
Definition: ptools.cc:1460
static void substractFromHist(TH1 *hist, Double_t val, Bool_t inverse=kFALSE)
Definition: ptools.cc:4002
static TH1 * copySubsetOfHist(TH1 *hist, Double_t xmin=copySubsetOfHistDefaultValue, Double_t xmax=copySubsetOfHistDefaultValue, Double_t ymin=copySubsetOfHistDefaultValue, Double_t ymax=copySubsetOfHistDefaultValue, Double_t zmin=copySubsetOfHistDefaultValue, Double_t zmax=copySubsetOfHistDefaultValue)
Definition: ptools.cc:4827
static TH1 * getErrorsOfHistogram(TH1 *hist, Bool_t relativeError=kFALSE)
Definition: ptools.cc:3778
static void postfixToName(TNamed *name, TString postfix)
Definition: ptools.cc:1306
ClassImp(PTools) PTools
Definition: ptools.cc:65
static TPaveStats * setHistStatsYPosNDC(TH1 *hist, Double_t y1, Double_t y2)
Definition: ptools.cc:3175
static TPad * getDividedSubPad(TCanvas *canv, Int_t xpads, Int_t ypads)
Definition: ptools.cc:79
static void cleanHistogram(TH1 *hist, Double_t min, Double_t max, Int_t errorMode=0)
Definition: ptools.cc:1176
static void saveGifToPdf(TCanvas *canvas, TString path=".", TString filename="", Bool_t separate=kFALSE, Int_t selection=-1)
Definition: ptools.cc:2025
static void prefixToTitle(TNamed *name, TString prefix)
Definition: ptools.cc:1283
static void setLatexArts(TLatex *tex, Double_t x, Double_t y, Int_t color=1, Float_t size=0.1, Int_t align=11, Int_t font=62, Float_t angle=0., Bool_t ndc=kFALSE)
Definition: ptools.cc:3451
static TH3D copyToTH3D(TH3 *hist)
Definition: ptools.cc:2711
static TH2D * reBinHistX(TH2 *hist, Int_t factor=1)
Definition: ptools.cc:4358
static TPaveStats * getHistStatsXPosNDC(TH1 *hist, Double_t &x1, Double_t &x2)
Definition: ptools.cc:3333
static TLegendEntry * setLegendEntry(TLegend *legend, TObject *object, TString label, Int_t col, TString opt)
Definition: ptools.cc:2226
static void plotPolarSectorGridHADES(void)
Definition: ptools.cc:1802
static TPaveStats * getHistStats(TH1 *hist, Bool_t quiet=kFALSE)
Definition: ptools.cc:3127
static void setHistErrors(TH1 *h, TH1 *h2)
Definition: ptools.cc:4175
static TH2D * getTH2D(TString name, TString title, Int_t xbin, Double_t xmin, Double_t xmax, Int_t ybin, Double_t ymin, Double_t ymax, TString xtitle, TString ytitle, TString ztitle="")
Definition: ptools.cc:1566
static void cutEnd(Char_t *, const Char_t *)
Definition: ptools.cc:854
static Int_t findBeginOfDistribution(TH1 *hist, Int_t max, Double_t threshold, Bool_t compact=kFALSE)
Definition: ptools.cc:4525
static TCanvas * draw32Canvas(const Char_t *, const Char_t *, TH1F **)
Definition: ptools.cc:792
static Int_t checkHistogramCompatibility(TH1 *h1, TH1 *h2)
Definition: ptools.cc:2810
static Int_t getNFilledBins(TH1 *hist, Double_t min=-1, Double_t max=-1)
Definition: ptools.cc:1124
static TH3D * createTH3D(TH3 *hist)
Definition: ptools.cc:2742
static void cutHistogram(TH2 *hist, TCutG *cut, Bool_t complement=kFALSE)
Definition: ptools.cc:1354
static Bool_t areHistogramsCompatible(TH1 *h1, TH1 *h2)
Definition: ptools.cc:2880
Definition: ptools.h:35
static Int_t getColorJM(Int_t i)
Definition: ptools.cc:2118
static Bool_t compareHistogramLimits(TH1 *hist1, TH1 *hist2, Bool_t exit_on_failure)
Definition: ptools.cc:1070
static void importAxisLabels(TAxis *in, TAxis *out)
Definition: ptools.cc:2786
static void prefixToNameTitle(TNamed *name, TString prefix)
Definition: ptools.cc:1292
static TH1D * createTH1D(TH1 *hist)
Definition: ptools.cc:2722
static void postfixToNameTitle(TNamed *name, TString postfix)
Definition: ptools.cc:1331
static TH1 * copyToTHxD(TH1 *hist)
Definition: ptools.cc:2556
static TH1 * getOneOverHist(TH1 *hist)
Definition: ptools.cc:4124
static TH1D copyToTH1D(TH1 *hist)
Definition: ptools.cc:2688
static Int_t getLinearIndex(Int_t x1, UInt_t x1max, Int_t x2, UInt_t x2max=0, Int_t x3=-1, UInt_t x3max=0, Int_t x4=-1, UInt_t x4max=0, Int_t x5=-1, UInt_t x5max=0)
Definition: ptools.cc:3535
static TH3 * reverseZAxis(TH3 *hist)
Definition: ptools.cc:1693
static void postfixToTitle(TNamed *name, TString postfix)
Definition: ptools.cc:1319
static Double_t getMeanRangeUser(TH1 *hist, Axis_t minX, Axis_t maxX, TString s="center")
Definition: ptools.cc:2361