29 #include "TApplication.h"
36 #include "TGraphErrors.h"
43 #include "THashList.h"
47 #include "TLegendEntry.h"
51 #include "TObjString.h"
52 #include "TPaveText.h"
55 #include "TStopwatch.h"
60 #include "TUnixSystem.h"
87 if (canv) title = canv->GetTitle();
90 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title.Data(), (Char_t*)0, 0, (TPaveText*)0 );
103 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, (Char_t*)0, 0, (TPaveText*)0 );
111 const Char_t * title,
112 const Char_t * filename)
118 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, 0, (TPaveText*)0 );
126 const Char_t * title,
127 const Char_t * filename,
136 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries,(TPaveText*)0 );
144 const Char_t * title,
145 const Char_t * filename,
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 );
167 const Char_t * title,
168 const Char_t * filename,
179 return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info.Data());
186 Int_t xsize, Int_t ysize)
193 TCanvas *canv =
new TCanvas();
194 canv->SetWindowSize(xsize,ysize);
196 canv->SetTitle(canv->GetName());
200 if (canv) title = canv->GetTitle();
203 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title.Data(), (Char_t*)0, 0, (TPaveText*)0 );
210 Int_t xsize, Int_t ysize,
211 const Char_t * title)
219 TCanvas *canv =
new TCanvas();
220 canv->SetWindowSize(xsize,ysize);
222 canv->SetTitle(title);
224 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, (Char_t*)0, 0, (TPaveText*)0 );
231 Int_t xsize, Int_t ysize,
232 const Char_t * title,
233 const Char_t * filename)
242 TCanvas *canv =
new TCanvas();
243 canv->SetWindowSize(xsize,ysize);
245 canv->SetTitle(title);
246 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, 0, (TPaveText*)0 );
253 Int_t xsize, Int_t ysize,
254 const Char_t * title,
255 const Char_t * filename,
266 TCanvas *canv =
new TCanvas();
267 canv->SetWindowSize(xsize,ysize);
269 canv->SetTitle(title);
270 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries,(TPaveText*)0 );
277 Int_t xsize, Int_t ysize,
278 const Char_t * title,
279 const Char_t * filename,
292 TCanvas *canv =
new TCanvas();
293 canv->SetWindowSize(xsize,ysize);
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 );
306 Int_t xsize, Int_t ysize,
307 const Char_t * title,
308 const Char_t * filename,
321 TCanvas *canv =
new TCanvas();
322 canv->SetWindowSize(xsize,ysize);
324 canv->SetTitle(title);
325 return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info.Data());
331 Int_t xsize, Int_t ysize,
332 const Char_t * title,
333 const Char_t * filename,
346 TCanvas *canv =
new TCanvas();
347 canv->SetWindowSize(xsize,ysize);
349 canv->SetTitle(title);
350 return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info);
363 TCanvas *canv =
new TCanvas();
364 canv->SetTitle(canv->GetName());
368 if (canv) title = canv->GetTitle();
371 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title.Data(), (Char_t*)0, 0, (TPaveText*)0 );
378 const Char_t * title)
385 TCanvas *canv =
new TCanvas();
386 canv->SetTitle(title);
388 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, (Char_t*)0, 0, (TPaveText*)0 );
395 const Char_t * title,
396 const Char_t * filename)
403 TCanvas *canv =
new TCanvas();
404 canv->SetTitle(title);
405 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, 0, (TPaveText*)0 );
412 const Char_t * title,
413 const Char_t * filename,
423 TCanvas *canv =
new TCanvas();
424 canv->SetTitle(title);
425 return getDividedSubPad(canv, xpads, ypads, title, filename, nentries,(TPaveText*)0 );
432 const Char_t * title,
433 const Char_t * filename,
445 TCanvas *canv =
new TCanvas();
446 canv->SetTitle(title);
447 TPaveText *infotext =
new TPaveText(0,0,1,1);
448 infotext->SetTextSize(10);
450 while(str.Length() != 0)
452 if (str.First(
"/n") != str.Length())
454 infotext->AddText((str(0,str.First(
"/n")-1)).Data());
455 str=str(str.First(
"/n")+1,str.Length());
459 infotext->AddText(info);
463 return (!canv) ? NULL : getDividedSubPad(canv, xpads, ypads, title, filename, nentries, infotext );
470 const Char_t * title,
471 const Char_t * filename,
483 TCanvas *canv =
new TCanvas();
484 canv->SetTitle(title);
485 return getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info.Data());
492 const Char_t * title,
493 const Char_t * filename,
505 TCanvas *canv =
new TCanvas();
506 canv->SetTitle(title);
507 return (!canv) ? NULL : getDividedSubPad(canv , xpads, ypads, title, filename, nentries, info);
514 const Char_t *titlehead,
515 const Char_t *mytextfilename,
526 if (!mycanvas)
return NULL;
530 sprintf(name,
"%s_header",gPad->GetName());
531 mycanvas->SetFillColor(0);
533 TPad *mycanvas_header =
new TPad(name,name,0.01,0.95,0.99,0.99);
534 mycanvas_header->Draw();
535 mycanvas_header->cd();
537 printHeader(titlehead,mytextfilename,nentries,mycanvas_header);
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();
549 gPad->SetFillStyle(4000);
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);
558 info->SetFillColor(0);
563 sprintf(name,
"%s_body",gPad->GetName());
565 mycanvas_body =
new TPad(name,name,0.01,0.01,0.79,0.94);
569 sprintf(name,
"%s_body",gPad->GetName());
570 mycanvas_body =
new TPad(name,name,0.01,0.01,0.99,0.94);
573 mycanvas_body->Draw();
575 gPad->SetFillStyle(4000);
577 if (xpads > 1 || ypads > 1)
579 mycanvas_body->Divide(xpads,ypads);
580 mycanvas_body->cd(1);
583 return mycanvas_body;
588 void PTools::printHeader(
const Char_t *titlehead,
const Char_t *mytextfilename, Int_t nentries, TPad *parentPad)
593 if (!parentPad) gPad->cd();
594 else parentPad->cd();
596 const TDatime daytime;
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);
605 if (mytextfilename!=0 && nentries!=0)
607 sprintf(texText,
"%i Events - File %s",nentries,mytextfilename);
609 else if (nentries==0 && mytextfilename==0)
611 sprintf(texText,
" ");
613 else if (nentries==0 && mytextfilename!=0)
615 sprintf(texText,
"File %s",mytextfilename);
619 sprintf(texText,
"%i Events",nentries);
622 TLatex *tex2 =
new TLatex(0.01,0.6,texText);
623 tex2->SetTextSize(0.35);
624 tex2->SetLineWidth(2);
627 sprintf(texText,
"%s",daytime.AsSQLString());
629 TLatex *tex3 =
new TLatex(0.85,0.15,texText);
630 tex3->SetTextSize(0.35);
631 tex3->SetLineWidth(2);
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));
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 )'");
669 void PTools::setTitleArts( TH1* histogramm,
const Char_t *xtitle,
const Char_t *ytitle, TString color, Int_t type)
674 const TString col[11]={
"",
"black",
"red",
"bright green",
"bright blue",
"yellow",
"hot pink",
"aqua",
"green",
"blue",
"default"};
678 for (i = 1; i <= 10; i++)
680 if (color.CompareTo(col[i])==0)
break;
684 Info(
"setTitleArts",
"no valid name for color chosen %s ... setting to default: %s",color.Data(),col[4].Data());
688 setTitleArts( histogramm, xtitle, ytitle, i , type);
693 void PTools::setTitleArts( TH1* histogramm,
const TString xtitle,
const TString ytitle, TString color, Int_t type)
697 setTitleArts( histogramm, xtitle.Data(), ytitle.Data(), color, type);
703 Int_t fillColor, Int_t titleFont)
706 setTitleArts( histogramm, xtitle.Data(), ytitle.Data(), fillColor, titleFont);
712 Int_t fillColor, Int_t titleFont)
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);
736 setTitleArts( histogrammStack, xtitle.Data(), ytitle.Data(), titleFont);
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);
758 const Char_t * title,
771 TCanvas *canv =
new TCanvas(name,title,0+calls*25,0+calls*25,1000,800);
773 canv->Divide(xsize,ysize);
775 for (Int_t time=0 ;time < 6 ; time++)
778 if (histarray[time]->GetEntries()>0)
780 histarray[time]->DrawCopy();
802 TCanvas *canv =
new TCanvas(name,title,0+calls*25,0+calls*25,1000,800);
805 for (Int_t time=0 ;time < 6 ; time++)
808 if (histarray[time]->GetEntries()>0)
810 histarray[time]->DrawCopy();
832 TCanvas *canv =
new TCanvas(name,title,0+calls*25,0+calls*25,1000,800);
835 for (Int_t time=0 ;time < 6 ; time++)
839 if (histarray[time]->GetEntries()>0)
841 if (!option) histarray[time]->DrawCopy();
842 else histarray[time]->DrawCopy(option);
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));
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);
891 const Char_t* tmp = myexec(in.Data());
910 cerr <<
"here" << call << endl;
912 else cerr <<
"here" << called << endl;
919 const Char_t *newDirName,
932 TString newName(newDirName);
934 while (newName.Contains(
"/"))
936 TString directory = newName;
937 Int_t pos = directory.First(
"/");
939 newName = newName(pos+1,newName.Length()-pos-1).Data();
943 static Char_t sDir[255];
944 static Char_t sFmt[10];
947 sprintf(sFmt,
"%%s %%0%1ii", precision);
948 sprintf(sDir, sFmt, newName.Data(), index);
952 sprintf(sFmt,
"%%s");
953 sprintf(sDir, sFmt, newName.Data());
956 if (!dirOld->FindKey(sDir))
958 dirNew = dirOld->mkdir(sDir);
962 dirNew = (TDirectory *) dirOld->Get(sDir);
971 const TString newDirName,
976 return Mkdir(dirOld, newDirName.Data(), index, precision);
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)
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();
997 Int_t& nbinsx , Axis_t& xmin , Axis_t& xmax,
998 Int_t& nbinsy , Axis_t& ymin , Axis_t& ymax)
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();
1015 Int_t& nbinsx , Axis_t& xmin , Axis_t& xmax)
1019 if (nbinsx) nbinsx = hist->GetNbinsX();
1020 if (xmin ) xmin = hist->GetXaxis()->GetXmin();
1021 if (xmax ) xmax = hist->GetXaxis()->GetXmax();
1033 getHistogramLimits(hist, nbinsx, xmin, xmax);
1034 printf(
"nbinsx: %i \nxmin: \t %f \nxmax: \t %f\n",nbinsx, xmin, xmax);
1043 Int_t nbinsx, nbinsy;
1044 Axis_t xmin, xmax, ymin, ymax;
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);
1057 Int_t nbinsx, nbinsy, nbinsz;
1058 Axis_t xmin, xmax, ymin, ymax, zmin, zmax;
1060 getHistogramLimits(hist, nbinsx, xmin, xmax, nbinsy, ymin, ymax , nbinsz, zmin, zmax);
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);
1077 Int_t nbinsx1, nbinsy1;
1078 Axis_t xmin1, xmax1, ymin1, ymax1;
1079 Int_t nbinsx2, nbinsy2;
1080 Axis_t xmin2, xmax2, ymin2, ymax2;
1082 getHistogramLimits( hist1, nbinsx1, xmin1, xmax1, nbinsy1, ymin1, ymax1);
1083 getHistogramLimits( hist2, nbinsx2, xmin2, xmax2, nbinsy2, ymin2, ymax2);
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;
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",
1110 (!exitIfNotEqual)?
"!":
"... exiting!"
1129 Int_t nbinsx = hist->GetNbinsX();
1130 Int_t nbinsy = hist->GetNbinsY();
1131 Int_t nbinsz = hist->GetNbinsZ();
1133 if ( min==-1 && max == -1)
1135 min = hist->GetMinimum();
1136 max = hist->GetMaximum();
1139 if (hist->GetDimension()<2) nbinsy = -1;
1140 if (hist->GetDimension()<3) nbinsz = -1;
1142 Int_t binx,biny,binz,bin;
1147 for (binz=0;binz<=nbinsz+1;binz++)
1149 for (biny=0;biny<=nbinsy+1;biny++)
1151 for (binx=0;binx<=nbinsx+1;binx++)
1153 bin = hist->GetBin(binx,biny,binz);
1154 g = hist->GetBinContent(bin);
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;}
1163 if (g >=min && g <=max)
1194 ::Error(
"cleanHistogram",
" hist is NULL pointer ... return NULL");
1198 if (errorMode>0) errorMode = 1;
1199 if (errorMode<0) errorMode =-1;
1201 Int_t nbinsx = hist->GetNbinsX();
1202 Int_t nbinsy = hist->GetNbinsY();
1203 Int_t nbinsz = hist->GetNbinsZ();
1205 if (hist->GetDimension()<2) nbinsy = -1;
1206 if (hist->GetDimension()<3) nbinsz = -1;
1208 Int_t binx,biny,binz,bin;
1220 errHist = (TH1*) getErrorsOfHistogram(hist,kFALSE);
1223 errHist = (TH1*) getErrorsOfHistogram(hist,kTRUE);
1230 for (binz=0;binz<=nbinsz+1;binz++)
1232 for (biny=0;biny<=nbinsy+1;biny++)
1234 for (binx=0;binx<=nbinsx+1;binx++)
1239 bin = hist->GetBin(binx,biny,binz);
1240 g = hist->GetBinContent(bin);
1243 bin = errHist->GetBin(binx,biny,binz);
1244 g = errHist->GetBinContent(bin);
1247 bin = errHist->GetBin(binx,biny,binz);
1248 g = errHist->GetBinContent(bin);
1256 if (g < min || g > max)
1258 hist->SetBinContent(bin,0);
1259 hist->SetBinError(bin,0);
1266 if (errorMode != 0 && errHist)
1277 prefix+= name->GetName();
1278 name->SetName(prefix.Data());
1286 prefix+= name->GetTitle();
1287 name->SetTitle(prefix.Data());
1294 TString prefixTitle = prefix;
1296 prefix+= name->GetName();
1297 name->SetName(prefix.Data());
1299 prefixTitle+= name->GetTitle();
1300 name->SetTitle(prefixTitle.Data());
1311 TString postfixTitle = postfix;
1313 postfix=name->GetName()+TString(
"_")+postfix;
1314 name->SetName(postfix.Data());
1323 TString postfixTitle = postfix;
1325 postfixTitle=name->GetTitle()+TString(
" - ")+postfixTitle;
1326 name->SetTitle(postfixTitle.Data());
1336 TString postfixTitle = postfix;
1338 postfix=name->GetName()+TString(
"_")+postfix;
1339 name->SetName(postfix.Data());
1341 postfixTitle=name->GetTitle()+TString(
" - ")+postfixTitle;
1342 name->SetTitle(postfixTitle.Data());
1359 Int_t nbinsx = hist->GetNbinsX();
1360 Int_t nbinsy = hist->GetNbinsY();
1361 Int_t nbinsz = hist->GetNbinsZ();
1363 if (hist->GetDimension()<3) nbinsz = -1;
1365 Int_t binx,biny,binz,bin;
1368 for (binz=0;binz<=nbinsz+1;binz++)
1370 for (biny=0;biny<=nbinsy+1;biny++)
1372 for (binx=0;binx<=nbinsx+1;binx++)
1374 bin = hist->GetBin(binx,biny,binz);
1375 gx = hist->GetXaxis()->GetBinCenter(binx);
1376 gy = hist->GetYaxis()->GetBinCenter(biny);
1378 if ((!complement && !cut->IsInside(gx,gy)) || (complement && cut->IsInside(gx,gy)))
1380 hist->SetBinContent(bin,0);
1381 hist->SetBinError(bin,0);
1395 TIterator *iter = cutarray->MakeIterator();
1397 Int_t nbinsx = hist->GetNbinsX();
1398 Int_t nbinsy = hist->GetNbinsY();
1399 Int_t nbinsz = hist->GetNbinsZ();
1401 if (hist->GetDimension()<3) nbinsz = -1;
1403 Int_t binx,biny,binz,bin;
1407 for (binz=0;binz<=nbinsz+1;binz++)
1409 for (biny=0;biny<=nbinsy+1;biny++)
1411 for (binx=0;binx<=nbinsx+1;binx++)
1413 bin = hist->GetBin(binx,biny,binz);
1414 gx = hist->GetXaxis()->GetBinCenter(binx);
1415 gy = hist->GetYaxis()->GetBinCenter(biny);
1422 while( (cut = (TCutG*) iter->Next()) != NULL )
1424 if (cut->IsInside(gx,gy))
1432 hist->SetBinContent(bin,0);
1433 hist->SetBinError(bin,0);
1439 while( (cut = (TCutG*) iter->Next()) != NULL )
1441 if (cut->IsInside(gx,gy))
1443 keep = keep & kFALSE;
1449 hist->SetBinContent(bin,0);
1450 hist->SetBinError(bin,0);
1468 if (hist->GetDimension()>1)
1470 Error(
"plotCounts",
"this function can only be applied to 1-dimensional histograms");
1474 Int_t first = hist->GetXaxis()->GetFirst();
1475 Int_t last = hist->GetXaxis()->GetLast();
1476 for (Int_t binx=first; binx<=last;binx++)
1478 Double_t count = hist->GetBinContent(binx);
1479 Double_t xpos = hist->GetBinCenter(binx);
1480 Double_t ypos = (gPad->GetLogy())?log10(count):count;
1482 if (format.IsNull())
1488 val+=Form(format.Data(),count);
1490 if (!(count>0 || count<0))
continue;
1492 hist->SetMaximum(hist->GetMaximum()* ((gPad->GetLogy())?5:1.05));
1494 TLatex *tex = drawLatexPadCoords(val, xpos, ypos, color, 0.025, 13, 72, 90);
1495 tex->SetLineWidth(2);
1503 Int_t xbin, Double_t xmin, Double_t xmax,
1504 TString xtitle, TString ytitle)
1508 TH1F *hist =
new TH1F(name,title, xbin,xmin,xmax);
1509 setTitleArts(hist,xtitle,ytitle);
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)
1521 TH2F *hist =
new TH2F(name,title, xbin,xmin,xmax, ybin,ymin,ymax );
1523 if (! ztitle.IsNull())
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);
1532 setTitleArts(hist,xtitle,ytitle);
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)
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);
1556 Int_t xbin, Double_t xmin, Double_t xmax,
1557 TString xtitle, TString ytitle)
1561 TH1D *hist =
new TH1D(name,title, xbin,xmin,xmax);
1562 setTitleArts(hist,xtitle,ytitle);
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)
1574 TH2D *hist =
new TH2D(name,title, xbin,xmin,xmax, ybin,ymin,ymax );
1576 if (! ztitle.IsNull())
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);
1585 setTitleArts(hist,xtitle,ytitle);
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)
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);
1613 Int_t nbinsx = hist->GetNbinsX();
1614 Int_t nbinsy = hist->GetNbinsY();
1615 Int_t nbinsz = hist->GetNbinsZ();
1617 if (hist->GetDimension()<2) nbinsy = -1;
1618 if (hist->GetDimension()<3) nbinsz = -1;
1620 Int_t binx,biny,binz,bin,bin2;
1622 TString name2 = hist->GetName(); name2 +=
"_Xreverse";
1624 TH1 * hist2 = (TH1*) hist->Clone(name2.Data());
1627 for (binz=0;binz<=nbinsz+1;binz++)
1629 for (biny=0;biny<=nbinsy+1;biny++)
1631 for (binx=0;binx<=nbinsx+1;binx++)
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())
1638 if (! hist2->GetSumw2N()) hist2->Sumw2();
1639 hist2->SetBinError(bin2,hist->GetBinError(bin));
1644 hist2->SetEntries(hist->GetEntries());
1655 Int_t nbinsx = hist->GetNbinsX();
1656 Int_t nbinsy = hist->GetNbinsY();
1657 Int_t nbinsz = hist->GetNbinsZ();
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;
1662 Int_t binx,biny,binz,bin,bin2;
1664 TString name2 = hist->GetName(); name2 +=
"_Yreverse";
1666 TH2 * hist2 = (TH2*) hist->Clone(name2.Data());
1669 for (binz=0;binz<=nbinsz+1;binz++)
1671 for (biny=0;biny<=nbinsy+1;biny++)
1673 for (binx=0;binx<=nbinsx+1;binx++)
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())
1680 if (! hist2->GetSumw2N()) hist2->Sumw2();
1681 hist2->SetBinError(bin2,hist->GetBinError(bin));
1686 hist2->SetEntries(hist->GetEntries());
1698 Int_t nbinsx = hist->GetNbinsX();
1699 Int_t nbinsy = hist->GetNbinsY();
1700 Int_t nbinsz = hist->GetNbinsZ();
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);}
1705 Int_t binx,biny,binz,bin,bin2;
1707 TString name2 = hist->GetName(); name2 +=
"_Zreverse";
1709 TH3 * hist2 = (TH3*) hist->Clone(name2.Data());
1712 for (binz=0;binz<=nbinsz+1;binz++)
1714 for (biny=0;biny<=nbinsy+1;biny++)
1716 for (binx=0;binx<=nbinsx+1;binx++)
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())
1723 if (! hist2->GetSumw2N()) hist2->Sumw2();
1724 hist2->SetBinError(bin2,hist->GetBinError(bin));
1729 hist2->SetEntries(hist->GetEntries());
1743 direction*=(acos(-1.)/180.0);
1744 Float_t radius = 0.58;
1746 TGaxis *axis1 =
new TGaxis(0,0, radius*cos(direction) ,radius*sin(direction) ,min,max,divisions,
"+");
1747 axis1->SetLabelColor(1);
1761 Error(
"plotPolarAxis",
"hist has a NULL pointer ... nothing done");
1764 plotPolarAxis(hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax(),divisions,direction);
1778 Error(
"plotPolarGrid",
"division of %i not realistic ... nothing done",division);
1782 Float_t radius = 0.58;
1786 for (Int_t iter = 1; iter <= division; iter++)
1788 kDeg =
new TEllipse(0,0,(radius/division)*iter);
1789 kDeg->SetLineWidth(2);
1790 kDeg->SetLineColor(10);
1792 kDeg2 =
new TEllipse(0,0,(radius/division)*iter);
1793 kDeg2->SetLineWidth(1);
1810 TString label[6]={
"180#circ",
"120#circ",
"60#circ",
"0#circ",
"300#circ",
"240#circ"};
1813 for (Int_t iter = 0; iter < 6; iter++)
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));
1818 lDeg[iter]->SetLineWidth(2);
1819 lDeg[iter]->SetLineColor(10);
1821 lDeg2[iter] =
new TLine(0,0,radius*cos(iter*60*acos(-1.)/180),radius*sin(iter*60*acos(-1.)/180));
1823 lDeg2[iter]->SetLineWidth(1);
1824 lDeg2[iter]->SetLineColor(1);
1825 lDeg2[iter]->Draw();
1828 tex[iter] =
new TLatex(radius*cos(iter*60*acos(-1.)/180),radius*sin(iter*60*acos(-1.)/180),label[iter].Data());
1836 void PTools::saveToPdf(TCanvas* canvas,TString path,TString filename,Bool_t separate, Int_t selection)
1847 saveToPdf((TPad*) canvas,path,filename,separate, selection);
1864 if (filename.IsNull()) filename=pad->GetName();
1866 TString File =filename;
1868 if (!Path.EndsWith(
"/") && !Path.IsNull())
1872 TString command =
"";
1873 TString totalin =
"";
1874 TString totalout=
"";
1875 TString converter=
"ps2pdf -dCompatibilityLevel=1.4 -dEmbedAllFonts=true";
1877 TString check = TString(
"which ")+ converter + TString(
" > /dev/null");
1879 if (gSystem->Exec(check.Data()))
1881 Error(
"saveToPdf",
"external program \"%s\" not available ... nothing is done",converter.Data());
1885 File.ReplaceAll(
".ps",
"");
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());
1897 Int_t npads= pad->GetListOfPrimitives()->GetSize();
1898 for(Int_t i=1;i<=npads;i++)
1900 if (selection > 0 && i!=selection)
1906 totalin = Path + File +
"_" + subpad +
".ps";
1907 totalout= Path + File +
"_" + subpad +
".pdf";
1909 TPad *clone = (TPad*) gPad->Clone();
1910 Bool_t batch = gROOT->IsBatch();
1912 TCanvas *dummy =
new TCanvas(
"dummy",
"dummy",1000,800);
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());
1922 gROOT->SetBatch(batch);
1929 void PTools::saveToPng(TCanvas* canvas,TString path,TString filename,Bool_t separate, Int_t selection)
1940 saveToPng((TPad*)canvas,path, filename, separate, selection);
1956 if (filename.IsNull()) {filename=pad->GetName();}
1958 TString File =filename;
1960 if (!Path.EndsWith(
"/") && !Path.IsNull())
1964 TString command =
"";
1965 TString totalin =
"";
1966 TString totalout=
"";
1967 TString converter=
"convert";
1969 TString check = TString(
"which ")+ converter + TString(
" > /dev/null");
1971 if (gSystem->Exec(check.Data()))
1973 Error(
"saveToPng",
"external program \"%s\" not available ... nothing is done",converter.Data());
1977 File.ReplaceAll(
".png",
"");
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());
1991 Int_t npads= pad->GetListOfPrimitives()->GetSize();
1992 for(Int_t i=1;i<=npads;i++)
1994 if (selection > 0 && i!=selection)
2000 totalin = Path + File +
"_" + subpad +
".ps";
2001 totalout= Path + File +
"_" + subpad +
".png";
2003 TPad *clone = (TPad*) gPad->Clone();
2004 Bool_t batch = gROOT->IsBatch();
2006 TCanvas *dummy =
new TCanvas(
"dummy",
"dummy",1000,800);
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());
2018 gROOT->SetBatch(batch);
2036 saveGifToPdf((TPad*)canvas , path, filename, separate, selection);
2052 if (filename.IsNull()) filename=pad->GetName();
2054 TString File =filename;
2056 if (!Path.EndsWith(
"/") && !Path.IsNull())
2060 TString command =
"";
2061 TString totalin =
"";
2062 TString totalout=
"";
2063 TString converter=
"convert";
2064 TString check = TString(
"which ")+ converter + TString(
" > /dev/null");
2066 if (gSystem->Exec(check.Data()))
2068 Error(
"saveGifToPdf",
"external program \"%s\" not available ... nothing is done",converter.Data());
2072 File.ReplaceAll(
".pdf",
"");
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());
2086 Int_t npads= pad->GetListOfPrimitives()->GetSize();
2087 for(Int_t i=1;i<=npads;i++)
2089 if (selection > 0 && i!=selection)
2095 totalin = Path + File +
"_" + subpad +
".ps";
2096 totalout= Path + File +
"_" + subpad +
".pdf";
2098 TPad *clone = (TPad*) gPad->Clone();
2099 Bool_t batch = gROOT->IsBatch();
2101 TCanvas *dummy =
new TCanvas(
"dummy",
"dummy",1000,800);
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());
2111 gROOT->SetBatch(batch);
2121 Int_t colors[] ={2,4,6,8,38,46,14,1,30,43};
2122 i%=((int)(
sizeof(colors)/
sizeof(Int_t)));
2131 Int_t style[] ={20,21,22,23,24,25,26,27,28,29};
2132 i%=((int)(
sizeof(style)/
sizeof(Int_t)));
2138 void PTools::setGraph(TGraph* graph,Int_t mycolorindex,Int_t markerstyle,Int_t markercolor,Float_t markersize,Int_t linecolor)
2143 graph->SetMarkerColor(markercolor);
2144 graph->SetMarkerSize(markersize);
2145 graph->SetMarkerStyle(markerstyle);
2146 graph->SetLineColor(linecolor);
2152 graph->SetMarkerSize(markersize);
2155 graph->SetLineColor(linecolor);
2161 void PTools::setHist(TH1* hist,Int_t mycolorindex,Int_t markerstyle,Int_t markercolor,Float_t markersize,Int_t linecolor)
2164 if(mycolorindex==-99)
2166 hist->SetMarkerColor(markercolor);
2167 hist->SetMarkerSize(markersize);
2168 hist->SetMarkerStyle(markerstyle);
2169 hist->SetLineColor(linecolor);
2175 hist->SetMarkerSize(markersize);
2178 hist->SetLineColor(linecolor);
2185 Float_t scaleX,Float_t scaleY,
2186 Float_t offsetX,Float_t offsetY,
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);
2202 if(pos.CompareTo(
"left_top")==0) legend=
new TLegend(left+offsetX,top+offsetY-(scaleY*heith),left+offsetX+(scaleX*width),top+offsetY,Title.Data());
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());
2204 if(pos.CompareTo(
"right_top")==0) legend=
new TLegend(right+offsetX-(scaleX*width),top+offsetY-(scaleY*heith),right+offsetX,top+offsetY,Title.Data());
2205 if(pos.CompareTo(
"left_bottom")==0) legend=
new TLegend(left+offsetX,bottom+offsetY,left+offsetX+(scaleX*width),bottom+offsetY+(scaleY*heith),Title.Data());
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());
2207 if(pos.CompareTo(
"right_bottom")==0)legend=
new TLegend(right+offsetX-(scaleX*width),bottom+offsetY,right+offsetX,bottom+offsetY+(scaleY*heith),Title.Data());
2209 if (!legend)
return NULL;
2210 legend->SetFillStyle(0);
2211 legend->SetBorderSize(0);
2212 legend->SetMargin(0.15);
2214 if(Comment.CompareTo(
"")!=0)
2216 TLegendEntry* entry=legend->AddEntry(dummy,Comment.Data());
2217 entry->SetTextColor(1);
2218 entry->SetTextFont(62);
2219 entry->SetOption(
"l");
2231 TLegendEntry* entry=legend->AddEntry((TObject*)
object,label.Data());
2232 entry->SetTextColor(col);
2233 entry->SetOption(opt.Data());
2245 x=gPad->GetLeftMargin()*1.15;
2246 y=(1-gPad->GetTopMargin())*1.02;
2248 TLatex* text=
new TLatex(x,y,label);
2249 text->SetTextSize(size);
2251 text->SetTextColor(color);
2267 if (!hist) {::Error(
"getMeanErrorRangeUser",
"no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2268 return getMeanErrorRange(hist, hist->FindBin(minX), hist->FindBin(maxX),pos);
2285 if (pos.CompareTo(
"center")==0) p=0;
2286 if (pos.CompareTo(
"up")==0) p=1;
2287 if (pos.CompareTo(
"low")==0) p=-1;
2289 if (p==-10) { Error(
"getMeanErrorRange",
"wrong position parameter %s",pos.Data());exit(EXIT_FAILURE);}
2291 if (!hist) {::Error(
"getMeanErrorRange",
"no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2293 Int_t nbinsx = hist->GetNbinsX();
2295 if (hist->GetDimension()>2) {::Error(
"getMeanErrorRange",
"cannot be used for TH2 and TH3"); exit(EXIT_FAILURE);}
2299 Double_t bin,binval=0,binError;
2304 for (binx=0;binx<=nbinsx+1;binx++)
2306 if (minX>binx)
continue;
2307 if (maxX<binx)
continue;
2311 binval=hist->GetXaxis()->GetBinCenter(binx);
2314 binval=hist->GetXaxis()->GetBinLowEdge(binx);
2317 binval=hist->GetXaxis()->GetBinUpEdge(binx);
2323 bin = hist->GetBinContent(binx);
2328 for (binx=0;binx<=nbinsx+1;binx++)
2330 if (minX>binx)
continue;
2331 if (maxX<binx)
continue;
2335 binval=hist->GetXaxis()->GetBinCenter(binx);
2338 binval=hist->GetXaxis()->GetBinLowEdge(binx);
2341 binval=hist->GetXaxis()->GetBinUpEdge(binx);
2348 bin = hist->GetBinContent(binx);
2349 binError = hist->GetBinError(binx);
2350 sumw2+=( ((binval*
sum)-sumv)*binError*((binval*
sum)-sumv)*binError);
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);
2370 if (!hist) {::Error(
"getMeanErrorRangeUser",
"no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2371 return getMeanErrorRange(hist, hist->FindBin(minX), hist->FindBin(maxX),pos);
2388 if (pos.CompareTo(
"center")==0) p=0;
2389 if (pos.CompareTo(
"up")==0) p=1;
2390 if (pos.CompareTo(
"low")==0) p=-1;
2392 if (p==-10) { Error(
"getMeanErrorRange",
"wrong position parameter %s",pos.Data());exit(EXIT_FAILURE);}
2394 if (!hist) {::Error(
"getMeanErrorRange",
"no valid histogramm NULL pointer"); exit(EXIT_FAILURE);}
2396 Int_t nbinsx = hist->GetNbinsX();
2398 if (hist->GetDimension()>2) {::Error(
"getMeanErrorRange",
"cannot be used for TH2 and TH3"); exit(EXIT_FAILURE);}
2402 Double_t bin,binval;
2406 for (binx=0;binx<=nbinsx+1;binx++)
2408 if (minX>binx)
continue;
2409 if (maxX<binx)
continue;
2413 binval=hist->GetXaxis()->GetBinCenter(binx);
2416 binval=hist->GetXaxis()->GetBinLowEdge(binx);
2419 binval=hist->GetXaxis()->GetBinUpEdge(binx);
2426 bin = hist->GetBinContent(binx);
2431 return (sum>0 || sum <0)?sumv/sum:-1;
2440 if (! hist->GetSumw2N()) hist->Sumw2();
2442 Int_t nbinsx = hist->GetNbinsX();
2443 Int_t nbinsy = hist->GetNbinsY();
2444 Int_t nbinsz = hist->GetNbinsZ();
2446 if (hist->GetDimension()<3) nbinsz = -1;
2447 if (hist->GetDimension()<2) nbinsy = -1;
2449 Int_t binx,biny,binz,bin;
2451 for (binz=0;binz<=nbinsz+1;binz++)
2455 if (binz == 0 )
continue;
2456 if (binz == nbinsz+1)
continue;
2458 for (biny=0;biny<=nbinsy+1;biny++)
2462 if (biny == 0 )
continue;
2463 if (biny == nbinsy+1)
continue;
2465 for (binx=0;binx<=nbinsx+1;binx++)
2469 if (binx == 0 )
continue;
2470 if (binx == nbinsx+1)
continue;
2472 bin = hist->GetBin(binx,biny,binz);
2474 if (hist->GetBinContent(bin) < 0)
2476 Error(
"sqrt()",
"histogram %s contains negative values, cannot perform sqrt() operation ... exiting",
2486 for (binz=0;binz<=nbinsz+1;binz++)
2490 if (binz == 0 )
continue;
2491 if (binz == nbinsz+1)
continue;
2493 for (biny=0;biny<=nbinsy+1;biny++)
2497 if (biny == 0 )
continue;
2498 if (biny == nbinsy+1)
continue;
2500 for (binx=0;binx<=nbinsx+1;binx++)
2504 if (binx == 0 )
continue;
2505 if (binx == nbinsx+1)
continue;
2507 bin = hist->GetBin(binx,biny,binz);
2509 val = hist->GetBinContent(bin);
2510 err = hist->GetBinError(bin);
2512 hist->SetBinContent(bin, ::std::sqrt(val));
2514 if (val==0.0 || ::std::sqrt(val) == 0.0)
2516 hist->SetBinError(bin,0);
2520 hist->SetBinError(bin, ( err*0.5 * 1./ ::std::sqrt(val)));
2536 if (newname.IsNull())
2538 newname=name->GetName();
2543 title=name->GetTitle();
2547 TNamed *named = (TNamed*) name->Clone(newname.Data());
2548 named->SetTitle(title.Data());
2564 ::Error(
"copyToTHxD",
"histogram has NULL pointer ... exiting");
2569 Int_t nbinsx = hist->GetNbinsX();
2570 Int_t nbinsy = hist->GetNbinsY();
2571 Int_t nbinsz = hist->GetNbinsZ();
2575 switch(hist->GetDimension())
2581 ((int)(hist->GetXaxis()->GetXbins()->fN > 0)) * 1;
2582 TString name = hist->GetName()+TString(
"_TH1D");
2587 histD =
new TH1D(name.Data(),hist->GetTitle(),
2589 hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax());
2592 histD =
new TH1D(name.Data(),hist->GetTitle(),
2594 hist->GetXaxis()->GetXbins()->fArray);
2605 s = ((int)(hist->GetXaxis()->GetXbins()->fN > 0)) * 1 + ((int)( hist->GetYaxis()->GetXbins()->fN > 0)) * 10;
2606 TString name = hist->GetName()+TString(
"_TH2D");
2611 histD =
new TH2D(name.Data(),hist->GetTitle(),
2613 hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
2615 hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
2618 histD =
new TH2D(name.Data(),hist->GetTitle(),
2620 hist->GetXaxis()->GetXbins()->fArray,
2622 hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
2626 histD =
new TH2D(name.Data(),hist->GetTitle(),
2628 hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
2630 hist->GetYaxis()->GetXbins()->fArray);
2640 TString name = hist->GetName()+TString(
"_TH3D");
2642 histD =
new TH3D(name.Data(),hist->GetTitle(),
2644 hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
2646 hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax(),
2648 hist->GetZaxis()->GetXmin(),hist->GetZaxis()->GetXmax());
2650 importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
2651 importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
2652 importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
2657 importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
2658 importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
2659 importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
2661 histD->SetEntries(hist->GetEntries());
2663 if (hist->GetDimension()<2) nbinsy = -1;
2664 if (hist->GetDimension()<3) nbinsz = -1;
2666 Int_t binx,biny,binz,bin;
2668 for (binz=0;binz<=nbinsz+1;binz++)
2670 for (biny=0;biny<=nbinsy+1;biny++)
2672 for (binx=0;binx<=nbinsx+1;binx++)
2674 bin = hist->GetBin(binx,biny,binz);
2675 histD->SetBinContent(bin, hist->GetBinContent(bin));
2676 if (hist->GetSumw2N())
2678 histD->SetBinError(bin,hist->GetBinError(bin));
2692 TH1D* tmp = (TH1D*) copyToTHxD(hist);
2703 TH2D* tmp = (TH2D*) copyToTHxD(hist);
2714 TH3D* tmp = (TH3D*) copyToTHxD(hist);
2727 return (hist) ? (TH1D*) copyToTHxD(hist) : NULL;
2737 return (hist) ? (TH2D*) copyToTHxD(hist) : NULL;
2747 return (hist) ? (TH3D*) copyToTHxD(hist) : NULL;
2758 Warning(
"importAxisAttributes",
"in or output axis is NULL ... nothing done");
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());
2780 importAxisLabels(in,out);
2791 THashList* labels = in->GetLabels();
2795 if(in->GetNbins() != out->GetNbins())
2797 ::Warning(
"ImportAxisAttributes",
"axises do not have same binning copying labels for overlap");
2801 while((obj=(TObjString*) next()))
2803 out->SetBinLabel((Int_t)obj->GetUniqueID(),obj->GetName());
2827 Error(
"checkHistogrammCompatibility",
"can't compare, h1 (%p) or h2 (%p) is null pointer, returning -1",h1, h2);
2834 const TString n1 = h1->ClassName();
2835 const TString n2 = h2->ClassName();
2837 if (n1.CompareTo(n2))
2843 if (h1->GetDimension() != h2->GetDimension())
2849 if ( h1->GetNbinsX() != h2->GetNbinsX() ||
2850 h1->GetNbinsY() != h2->GetNbinsY() ||
2851 h1->GetNbinsZ() != h2->GetNbinsZ())
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()))
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())
2895 Int_t val = checkHistogramCompatibility(h1, h2);
2897 if ( -1 < val && val < 100)
2920 if (!array1 || !array2)
2922 Error(
"areArraysCompatible",
"can't compare, array1 (%p) or array2 (%p) is null pointer, returning -1",array1, array2);
2928 Int_t arraySize1 = array1->GetSize();
2929 Int_t arraySize2 = array2->GetSize();
2931 if (arraySize1 != arraySize2)
2937 TString n1 = array1->IsA()->GetName();
2938 TString n2 = array2->IsA()->GetName();
2941 if (n1.CompareTo(n2))
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; }
2961 for ( Int_t index=0; index < arraySize1; index++)
2963 if ( ((TArrayC*)array1)->At(index) != ((TArrayC*)array2)->At(index))
2970 for ( Int_t index=0; index < arraySize1; index++)
2972 if ( ((TArrayD*)array1)->At(index) != ((TArrayD*)array2)->At(index))
2979 for ( Int_t index=0; index < arraySize1; index++)
2981 if ( ((TArrayF*)array1)->At(index) != ((TArrayF*)array2)->At(index))
2988 for ( Int_t index=0; index < arraySize1; index++)
2990 if ( ((TArrayI*)array1)->At(index) != ((TArrayI*)array2)->At(index))
2997 for ( Int_t index=0; index < arraySize1; index++)
2999 if ( ((TArrayL*)array1)->At(index) != ((TArrayL*)array2)->At(index))
3006 for ( Int_t index=0; index < arraySize1; index++)
3008 if ( ((TArrayS*)array1)->At(index) != ((TArrayS*)array2)->At(index))
3015 ::Error(
"areArraysCompatible",
"unsupported type: \"%s\", returning kFALSE",array1->IsA()->ClassName());
3046 Error(
" fillGraphErr",
"hist is NULL, returning NULL pointer");
3052 name=hist->GetName();
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;}
3067 Error(
"fillGraphErr",
3068 "no valid position name %s (center,middle,low,left,up,right) chosen, returning NULL",
3073 Int_t nbinsx = hist->GetNbinsX();
3075 TArrayD xval(nbinsx);
3076 TArrayD yval(nbinsx);
3077 TArrayD xerrval(nbinsx);
3078 TArrayD yerrval(nbinsx);
3082 for (Int_t binx=1; binx <= nbinsx; binx++)
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);
3092 xval[bin-1] = hist->GetXaxis()->GetBinCenter(bin);
3095 xval[bin-1] = hist->GetXaxis()->GetBinLowEdge(bin);
3098 xval[bin-1] = hist->GetXaxis()->GetBinUpEdge(bin);
3104 TGraphErrors* graph = NULL;
3107 graph =
new TGraphErrors(nbinsx,
3111 yerrval.GetArray());
3115 graph =
new TGraphErrors(nbinsx,
3119 yerrval.GetArray());
3133 TPaveStats* stats = ((TPaveStats*) hist->GetListOfFunctions()->FindObject(
"stats"));
3140 if (! quiet) {::Error(
"getHistStats",
"stats do not exists, returning NULL pointer");}
3146 ::Error(
"getHistStats",
"histogram is NULL pointer, returning NULL pointer");
3162 if (!noUpdate) pad->Update();
3163 return getHistStats(((TH1*) pad->FindObject(name.Data())), quiet);
3167 if (!quiet){::Error(
"getHistStats()",
"pad does not exist, returning NULL pointer");}
3180 TPaveStats *stats = getHistStats(hist);
3183 stats->SetY1NDC(y1);
3184 stats->SetY2NDC(y2);
3188 ::Warning(
"setHistStatsYPosNDC",
"couldn't change position");
3203 return setHistStatsYPosNDC(((TH1*) pad->FindObject(name.Data())),y1,y2);
3207 ::Error(
"setHistStatsYPosNDC()",
"pad does not exist, returning NULL pointer");
3219 TPaveStats *stats = getHistStats(hist);
3222 stats->SetX1NDC(x1);
3223 stats->SetX2NDC(x2);
3227 ::Warning(
"setHistStatsXPosNDC",
"couldn't change position");
3242 return setHistStatsXPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2);
3246 ::Error(
"setHistStatsXPosNDC()",
"pad does not exist, returning NULL pointer");
3258 TPaveStats *stats = getHistStats(hist);
3261 stats->SetX1NDC(x1);
3262 stats->SetX2NDC(x2);
3263 stats->SetY1NDC(y1);
3264 stats->SetY2NDC(y2);
3268 ::Warning(
"setHistStatsPosNDC",
"couldn't change position");
3283 return setHistStatsPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2,y1,y2);
3287 ::Error(
"setHistStatsPosNDC()",
"pad does not exist, returning NULL pointer");
3299 TPaveStats *stats = getHistStats(hist);
3302 y1 = stats->GetY1NDC();
3303 y2 = stats->GetY2NDC();
3307 ::Warning(
"getHistStatsYPosNDC",
"couldn't change position");
3322 return getHistStatsYPosNDC(((TH1*) pad->FindObject(name.Data())),y1,y2);
3326 ::Error(
"getHistStatsYPosNDC()",
"pad does not exist, returning NULL pointer");
3338 TPaveStats *stats = getHistStats(hist);
3341 x1 = stats->GetX1NDC();
3342 x2 = stats->GetX2NDC();
3346 ::Warning(
"getHistStatsXPosNDC",
"couldn't change position");
3361 return getHistStatsXPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2);
3365 ::Error(
"getHistStatsXPosNDC()",
"pad does not exist, returning NULL pointer");
3377 TPaveStats *stats = getHistStats(hist);
3380 x1 = stats->GetX1NDC();
3381 x2 = stats->GetX2NDC();
3382 y1 = stats->GetY1NDC();
3383 y2 = stats->GetY2NDC();
3387 ::Warning(
"getHistStatsPosNDC",
"couldn't change position");
3402 return getHistStatsPosNDC(((TH1*) pad->FindObject(name.Data())),x1,x2,y1,y2);
3406 ::Error(
"getHistStatsPosNDC()",
"pad does not exist, returning NULL pointer");
3418 TPaveStats *stats = getHistStats(hist);
3421 stats->SetTextColor(color);
3425 ::Warning(
"setHistStatsTextColorNDC",
"couldn't change textColorition");
3440 return setHistStatsTextColor(((TH1*) pad->FindObject(name.Data())),color);
3444 ::Error(
"setHistStatsTextColor()",
"pad does not exist, returning NULL pointer");
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)
3472 tex->SetTextColor(color);
3473 tex->SetTextSize(size);
3474 tex->SetTextAlign(align);
3475 tex->SetTextFont(font);
3476 tex->SetTextAngle(angle);
3480 ::Error(
"setLatexArts()",
"tex pointer does not exist, no changes");
3488 Double_t x, Double_t y,
3489 Int_t color, Float_t size, Int_t align,
3490 Int_t font, Float_t angle)
3501 setLatexArts(tex,x,y,color,size,align,font,angle,kTRUE);
3514 (gInterpreter && (!gInterpreter->IsLoaded(macro))))
3516 gROOT->LoadMacro(macro);
3530 return loadMacro(macro.Data());
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)
3565 for (UInt_t iter = 1; iter < dim; iter++)
3571 for (UInt_t fiter = iter-1; fiter < dim-1; fiter++)
3580 for (UInt_t iter = 1; iter < dim; iter++)
3582 if ((UInt_t) x[iter] >= xmax[iter])
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]);
3593 for (UInt_t iter = 1; iter < dim; iter++)
3596 for (UInt_t iter2 = 0; iter2 < iter; iter2++)
3600 index += x[iter]*add;
3622 ::Error(
"getLinearIndex",
"Bad Index return -1");
3626 for (UInt_t iter = 1; iter < dim; iter++)
3630 for (UInt_t fiter = iter-1; fiter < dim-1; fiter++)
3639 for (UInt_t iter = 1; iter < dim; iter++)
3641 if ((UInt_t) x[iter] >= xmax[iter])
3645 ::Error(
"getLinearIndex",
"index %i out of bounds %i, returning -1",x[iter],xmax[iter]);
3658 for (UInt_t iter = 1; iter < dim; iter++)
3661 for (UInt_t iter2 = 0; iter2 < iter; iter2++)
3665 index += x[iter]*add;
3674 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3680 TLatex *tex =
new TLatex(0,0,text.Data());
3689 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3695 return drawLatexWC(TString(text), x, y, color, size, align, font, angle);
3701 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3707 return drawLatexPadCoords(text, x, y, color , size, align ,font , angle);
3713 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3719 return drawLatexPadCoords(text, x, y, color , size, align ,font , angle);
3725 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3731 TLatex *tex =
new TLatex(0,0,text.Data());
3740 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3746 return drawLatex(TString(text), x, y, color, size, align, font, angle);
3752 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3758 TLatex *tex =
new TLatex(0,0,text.Data());
3767 Int_t color, Float_t size, Int_t align, Int_t font, Float_t angle)
3773 return drawLatexPadCoords(TString(text), x, y, color, size, align, font, angle);
3790 ::Error(
"getErrorsOfHistogram",
" hist is NULL pointer ... return NULL");
3794 TH1* err = (TH1*) hist->Clone();
3797 TString name = hist->GetName();
3798 TString title = hist->GetTitle();
3811 err->SetName(name.Data());
3812 err->SetTitle(title.Data());
3814 Int_t nbinsx = hist->GetNbinsX();
3815 Int_t nbinsy = hist->GetNbinsY();
3816 Int_t nbinsz = hist->GetNbinsZ();
3818 if (hist->GetDimension()<2) nbinsy = -1;
3819 if (hist->GetDimension()<3) nbinsz = -1;
3821 Int_t binx,biny,binz,bin;
3823 for (binz=0;binz<=nbinsz+1;binz++)
3825 for (biny=0;biny<=nbinsy+1;biny++)
3827 for (binx=0;binx<=nbinsx+1;binx++)
3829 bin = hist->GetBin(binx,biny,binz);
3830 if (! relativeError)
3832 err->SetBinContent(bin,hist->GetBinError(bin));
3836 if (hist->GetBinContent(bin))
3838 err->SetBinContent(bin,fabs(hist->GetBinError(bin)/hist->GetBinContent(bin)));
3842 err->SetBinContent(bin,-1);
3864 ::Error(
"setErrorsOfHistogram",
" hist is NULL pointer ... nothing done");
3870 ::Error(
"setErrorsOfHistogram",
" err is NULL pointer ... nothing done");
3876 Int_t check = checkHistogramCompatibility(hist, err);
3879 ::Error(
"setErrorsOfHistogram",
" err and hist are not compatible %i ... nothing done",check);
3885 Int_t nbinsx = hist->GetNbinsX();
3886 Int_t nbinsy = hist->GetNbinsY();
3887 Int_t nbinsz = hist->GetNbinsZ();
3889 if (hist->GetDimension()<2) nbinsy = -1;
3890 if (hist->GetDimension()<3) nbinsz = -1;
3892 Int_t binx,biny,binz,bin;
3894 for (binz=0;binz<=nbinsz+1;binz++)
3896 for (biny=0;biny<=nbinsy+1;biny++)
3898 for (binx=0;binx<=nbinsx+1;binx++)
3900 bin = hist->GetBin(binx,biny,binz);
3901 hist->SetBinError(bin, err->GetBinContent(bin));
3918 ::Error(
"copyToUnitBinsPlusLabels",
"histogram has NULL pointer ... returning NULL");
3922 Int_t nbinsx = hist->GetNbinsX();
3923 Int_t nbinsy = hist->GetNbinsY();
3924 Int_t nbinsz = hist->GetNbinsZ();
3928 switch(hist->GetDimension())
3932 TString name = hist->GetName()+TString(
"_TH1D");
3933 histD =
new TH1D(name.Data(),hist->GetTitle(),
3941 TString name = hist->GetName()+TString(
"_TH2D");
3943 histD =
new TH2D(name.Data(),hist->GetTitle(),
3954 TString name = hist->GetName()+TString(
"_TH3D");
3956 histD =
new TH3D(name.Data(),hist->GetTitle(),
3971 importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
3972 importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
3973 importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
3975 histD->SetEntries(hist->GetEntries());
3977 if (hist->GetDimension()<2) nbinsy = -1;
3978 if (hist->GetDimension()<3) nbinsz = -1;
3980 Int_t binx,biny,binz,bin;
3982 for (binz=0;binz<=nbinsz+1;binz++)
3984 for (biny=0;biny<=nbinsy+1;biny++)
3986 for (binx=0;binx<=nbinsx+1;binx++)
3988 bin = hist->GetBin(binx,biny,binz);
3989 histD->SetBinContent(bin, hist->GetBinContent(bin));
3990 if (hist->GetSumw2N())
3992 histD->SetBinError(bin,hist->GetBinError(bin));
4009 ::Error(
"substractFromHist",
" hist is NULL pointer ... cannot act on a NULL pointer.");
4013 Int_t nbinsx = hist->GetNbinsX();
4014 Int_t nbinsy = hist->GetNbinsY();
4015 Int_t nbinsz = hist->GetNbinsZ();
4017 if (hist->GetDimension()<2) nbinsy = -1;
4018 if (hist->GetDimension()<3) nbinsz = -1;
4020 Int_t binx,biny,binz,bin;
4022 for (binz=0;binz<=nbinsz+1;binz++)
4024 for (biny=0;biny<=nbinsy+1;biny++)
4026 for (binx=0;binx<=nbinsx+1;binx++)
4028 bin = hist->GetBin(binx,biny,binz);
4031 hist->SetBinContent(bin,hist->GetBinContent(bin) - val);
4035 hist->SetBinContent(bin,val - hist->GetBinContent(bin));
4062 ::Error(
"getBinContentDistribution",
" hist is NULL pointer ... cannot act on a NULL pointer.");
4066 Int_t nbinsx = hist->GetNbinsX();
4067 Int_t nbinsy = hist->GetNbinsY();
4068 Int_t nbinsz = hist->GetNbinsZ();
4070 if (hist->GetDimension()<2) nbinsy = -1;
4071 if (hist->GetDimension()<3) nbinsz = -1;
4073 Int_t binx,biny,binz,bin;
4076 Double_t maximum = -FLT_MAX/10;
4077 Double_t minimum = FLT_MAX/10;
4079 for (binz=0;binz<=nbinsz+1;binz++)
4081 if (excludeUnderAndOverFlowBins && nbinsz != -1 && ( binz == 0 || binz == nbinsz+1)) {
continue; }
4082 for (biny=0;biny<=nbinsy+1;biny++)
4084 if (excludeUnderAndOverFlowBins && nbinsy != -1 && ( biny == 0 || biny == nbinsy+1)) {
continue; }
4085 for (binx=0;binx<=nbinsx+1;binx++)
4087 if (excludeUnderAndOverFlowBins && nbinsx != -1 && ( binx == 0 || binx == nbinsx+1)) {
continue; }
4088 bin = hist->GetBin(binx,biny,binz);
4089 value = hist->GetBinContent(bin);
4091 if (value > maximum) { maximum = value;}
4092 if (value < minimum) { minimum = value;}
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++)
4107 if (excludeUnderAndOverFlowBins && nbinsz != -1 && ( binz == 0 || binz == nbinsz+1)) {
continue; }
4108 for (biny=0;biny<=nbinsy+1;biny++)
4110 if (excludeUnderAndOverFlowBins && nbinsy != -1 && ( biny == 0 || biny == nbinsy+1)) {
continue; }
4111 for (binx=0;binx<=nbinsx+1;binx++)
4113 if (excludeUnderAndOverFlowBins && nbinsx != -1 && ( binx == 0 || binx == nbinsx+1)) {
continue; }
4114 bin = hist->GetBin(binx,biny,binz);
4115 dist->Fill(hist->GetBinContent(bin));
4134 ::Error(
"getOneOverHist",
" hist is NULL pointer ... cannot act on a NULL pointer.");
4138 Int_t nbinsx = hist->GetNbinsX();
4139 Int_t nbinsy = hist->GetNbinsY();
4140 Int_t nbinsz = hist->GetNbinsZ();
4142 if (hist->GetDimension()<2) nbinsy = -1;
4143 if (hist->GetDimension()<3) nbinsz = -1;
4145 Int_t binx,biny,binz,bin;
4147 Double_t value, error;
4149 TH1* inv = (TH1*) copyToTHxD(hist);
4150 TString name = Form(
"OneOver_%s",inv->GetName());
4151 TString title = Form(
"1./%s",inv->GetTitle());
4153 inv->SetNameTitle(name.Data(), title.Data());
4156 for (binz=0;binz<=nbinsz+1;binz++)
4158 for (biny=0;biny<=nbinsy+1;biny++)
4160 for (binx=0;binx<=nbinsx+1;binx++)
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));
4181 TString classname=h->ClassName();
4184 if(classname.Contains(
"TH1")==1)type=1;
4185 if(classname.Contains(
"TH2")==1)type=2;
4187 Int_t binsX=0,binsY=0;
4189 binsX=h->GetNbinsX();
4190 if(type==2)binsY=h->GetNbinsY();
4192 Double_t bincontent;
4196 for(Int_t x=0;x<=binsX;x++)
4198 bincontent= h2->GetBinContent(x+1);
4199 h->SetBinError(x+1,bincontent);
4204 for(Int_t x=0;x<=binsX;x++)
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);
4215 cout<<
"Warning: PTools::cleanHist : ZERO pointer for hist recieved!"<<endl;
4368 ::Error(
"getOneOverHist",
" hist is NULL pointer ... cannot act on a NULL pointer.");
4372 Int_t nbinsx = hist->GetNbinsX();
4373 Int_t nbinsy = hist->GetNbinsY();
4374 Int_t nbinsz = hist->GetNbinsZ();
4376 if (hist->GetDimension()<2) nbinsy = -1;
4377 if (hist->GetDimension()<3) nbinsz = -1;
4379 Int_t binx,biny,binz,bin=0;
4381 Double_t value, error;
4383 TString name = hist->GetName();
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());
4390 importAxisAttributes(hist->GetXaxis(), inv->GetXaxis(), kTRUE);
4391 importAxisAttributes(hist->GetYaxis(), inv->GetYaxis(), kTRUE);
4392 importAxisAttributes(hist->GetZaxis(), inv->GetZaxis(), kTRUE);
4397 for (binz=0;binz<=nbinsz+1;binz++)
4399 for (biny=0;biny<=nbinsy+1;biny++)
4401 for (binx=0;binx<=nbinsx+1;binx++)
4403 if (binx==0 || binx == nbinsx+1)
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));
4415 for (Int_t fctr=0; fctr < factor; fctr++)
4417 if (fctr==nbinsx+1) {
break;}
4419 bin = hist->GetBin(binx+fctr,biny,binz);
4420 value += hist->GetBinContent(bin);
4421 error += pow(hist->GetBinError(bin),2);
4423 inv->SetBinContent(index,value);
4424 inv->SetBinError(index,::std::sqrt(error));
4447 ::Error(
"cleanHistogram",
" hist is NULL pointer ... return NULL");
4451 Int_t nbinsx = hist->GetNbinsX();
4452 Int_t nbinsy = hist->GetNbinsY();
4453 Int_t nbinsz = hist->GetNbinsZ();
4455 if (hist->GetDimension()<2) nbinsy = -1;
4458 Int_t binx,biny,binz,bin;
4463 for (binz=0;binz<=nbinsz+1;binz++)
4465 for (biny=0;biny<=nbinsy+1;biny++)
4467 pt = hist->GetYaxis()->GetBinCenter(biny);
4468 for (binx=0;binx<=nbinsx+1;binx++)
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)));
4474 if (p < min || p > max)
4476 hist->SetBinContent(bin,replaceBy);
4477 hist->SetBinError(bin,0);
4497 ::Error(
"findEndOfDistribution",
" hist is NULL pointer ... return -1");
4503 Int_t nbinsx = hist->GetNbinsX();
4507 for (binIter=min; binIter<=nbinsx; binIter++)
4509 if (hist->GetBinContent(binIter) > threshold) {
continue;}
4512 if ((binIter+1 > nbinsx) ||(hist->GetBinContent(binIter+1) <= threshold))
break;
4516 if ( ((binIter+1 > nbinsx) ||(hist->GetBinContent(binIter+1) <= threshold)) &&
4517 ((binIter+2 > nbinsx) ||(hist->GetBinContent(binIter+2) <= threshold)))
break;
4536 ::Error(
"findBeginOfDistribution",
" hist is NULL pointer ... return -1");
4540 Int_t nbinsx = hist->GetNbinsX();
4543 if (max>nbinsx) { max = nbinsx; }
4545 for (binIter=max; binIter>0; binIter--)
4547 if (hist->GetBinContent(binIter) > threshold) {
continue;}
4550 if ( ((binIter-1 <= 0) ||(hist->GetBinContent(binIter-1) <= threshold)))
break;
4554 if ( ((binIter-1 <= 0) ||(hist->GetBinContent(binIter-1) <= threshold)) &&
4555 ((binIter-2 <= 0) ||(hist->GetBinContent(binIter-2) <= threshold)))
break;
4570 ::Error(
"scaleHistErrors",
" hist is NULL pointer ... cannot act on a NULL pointer.");
4574 Int_t nbinsx = hist->GetNbinsX();
4575 Int_t nbinsy = hist->GetNbinsY();
4576 Int_t nbinsz = hist->GetNbinsZ();
4578 if (hist->GetDimension()<2) nbinsy = -1;
4579 if (hist->GetDimension()<3) nbinsz = -1;
4581 Int_t binx,biny,binz,bin;
4584 for (binz=0;binz<=nbinsz+1;binz++)
4586 for (biny=0;biny<=nbinsy+1;biny++)
4588 for (binx=0;binx<=nbinsx+1;binx++)
4590 bin = hist->GetBin(binx,biny,binz);
4591 hist->SetBinError(bin,hist->GetBinError(bin)*scaleFactor);
4601 Int_t xbinmin, Int_t xbinmax,
4602 Int_t ybinmin, Int_t ybinmax,
4603 Int_t zbinmin, Int_t zbinmax
4629 ::Error(
"copyBinSubsetOfHist",
"histogram has NULL pointer ... returning NULL");
4634 if ( xbinmin > xbinmax && xbinmax > 0)
4636 ::Error(
"copyBinSubsetOfHist",
"invalid choice of bin ranges xmin (%i) > xmax (%i) ... returning NULL",
4640 if ( ybinmin > ybinmax && ybinmax > 0)
4642 ::Error(
"copyBinSubsetOfHist",
"invalid choice of bin ranges ymin (%i) > ymax (%i) ... returning NULL",
4646 if ( zbinmin > zbinmax && zbinmax > 0)
4648 ::Error(
"copyBinSubsetOfHist",
"invalid choice of bin ranges zmin (%i) > zmax (%i) ... returning NULL",
4654 Int_t nbinsx = hist->GetNbinsX();
4655 Int_t nbinsy = hist->GetNbinsY();
4656 Int_t nbinsz = hist->GetNbinsZ();
4659 Int_t dimension = hist->GetDimension();
4664 if ( xbinmax > nbinsx )
4666 ::Error(
"copyBinSubsetOfHist",
"xbinmax: %i exceeds histograms bin range of %i ... returning NULL"
4674 if ( ybinmax > nbinsy )
4676 ::Error(
"copyBinSubsetOfHist",
"ybinmax: %i exceeds histograms bin range of %i ... returning NULL"
4683 if ( zbinmax > nbinsz )
4685 ::Error(
"copyBinSubsetOfHist",
"zbinmax: %i exceeds histograms bin range of %i ... returning NULL"
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;
4700 if (dimension<2) {nbinsy = -1; ybinmin=0; ybinmax=0;}
4701 if (dimension<3) {nbinsz = -1; zbinmin=0; zbinmax=0;}
4712 name = Form(
"%s_subset_X_%i-%i",
4714 (xbinmin==0 )? 1 :xbinmin,
4715 (xbinmax==nbinsx+1)? nbinsx:xbinmax);
4716 title = Form(
"%s ( subset X: bin %i - bin %i )",
4718 (xbinmin==0 )? 1 :xbinmin,
4719 (xbinmax==nbinsx+1)? nbinsx:xbinmax);
4720 histD =
new TH1D(name.Data(),title.Data(),
4722 hist->GetXaxis()->GetBinLowEdge(xbinmin),
4723 hist->GetXaxis()->GetBinUpEdge (xbinmax)
4729 name = Form(
"%s_subset_X_%i-%i_Y_%i-%i",
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 )",
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(),
4743 hist->GetXaxis()->GetBinLowEdge(xbinmin),
4744 hist->GetXaxis()->GetBinUpEdge (xbinmax),
4746 hist->GetYaxis()->GetBinLowEdge(ybinmin),
4747 hist->GetYaxis()->GetBinUpEdge (ybinmax)
4753 name = Form(
"%s_subset_X_%i-%i_Y_%i-%i_Z_%i-%i",
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 )",
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(),
4771 hist->GetXaxis()->GetBinLowEdge(xbinmin),
4772 hist->GetXaxis()->GetBinUpEdge (xbinmax),
4774 hist->GetYaxis()->GetBinLowEdge(ybinmin),
4775 hist->GetYaxis()->GetBinUpEdge (ybinmax),
4777 hist->GetZaxis()->GetBinLowEdge(zbinmin),
4778 hist->GetZaxis()->GetBinUpEdge (zbinmax)
4784 ::Error(
"copyBinSubsetOfHist",
"invalid dimension: %i ... returning NULL",dimension);
4791 importAxisAttributes(hist->GetXaxis(), histD->GetXaxis(), kTRUE);
4792 importAxisAttributes(hist->GetYaxis(), histD->GetYaxis(), kTRUE);
4793 importAxisAttributes(hist->GetZaxis(), histD->GetZaxis(), kTRUE);
4796 histD->SetEntries(hist->GetEntries());
4797 if (hist->GetSumw2N()) {hist->Sumw2();}
4799 Int_t binx,biny,binz,bin,newbin;
4801 for (binz=zbinmin;binz<=zbinmax;binz++)
4803 for (biny=ybinmin;biny<=ybinmax;biny++)
4805 for (binx=xbinmin;binx<=xbinmax;binx++)
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))
4813 histD->SetBinContent(newbin, hist->GetBinContent(bin));
4814 if (hist->GetSumw2N())
4816 histD->SetBinError(newbin,hist->GetBinError(bin));
4828 Double_t xmin, Double_t xmax,
4829 Double_t ymin, Double_t ymax,
4830 Double_t zmin, Double_t zmax
4863 ::Error(
"copySubsetOfHist",
"histogram has NULL pointer ... returning NULL");
4867 Int_t dimension = hist->GetDimension();
4868 Int_t xbinmin=-1,xbinmax=-1,ybinmin=-1,ybinmax=-1,zbinmin=-1,zbinmax=-1;
4871 Int_t nbinsx = hist->GetNbinsX();
4872 Int_t nbinsy = hist->GetNbinsY();
4873 Int_t nbinsz = hist->GetNbinsZ();
4879 if (xbinmin<1 || xbinmin>nbinsx)
4881 ::Error(
"copySubsetOfHist",
"xmin: %f exceeds range of x-axis [%f,%f] ... returning NULL",
4882 xmin,hist->GetXaxis()->GetBinLowEdge(1),hist->GetXaxis()->GetBinUpEdge(nbinsx));
4887 if (xbinmax<1 || xbinmax>nbinsx)
4889 ::Error(
"copySubsetOfHist",
"xmax: %f exceeds range of x-axis [%f,%f] ... returning NULL",
4890 xmax,hist->GetXaxis()->GetBinLowEdge(1),hist->GetXaxis()->GetBinUpEdge(nbinsx));
4893 if (xbinmax!=-1) xbinmax--;
4899 if (ybinmin<1 || ybinmin>nbinsy)
4901 ::Error(
"copySubsetOfHist",
"ymin: %f exceeds range of y-axis [%f,%f] ... returning NULL",
4902 ymin,hist->GetYaxis()->GetBinLowEdge(1),hist->GetYaxis()->GetBinUpEdge(nbinsy));
4907 if (ybinmax<1 || ybinmax>nbinsy)
4909 ::Error(
"copySubsetOfHist",
"ymax: %f exceeds range of y-axis [%f,%f] ... returning NULL",
4910 ymax,hist->GetYaxis()->GetBinLowEdge(1),hist->GetYaxis()->GetBinUpEdge(nbinsy));
4913 if (ybinmax!=-1) ybinmax--;
4919 if (zbinmin<1 || zbinmin>nbinsz)
4921 ::Error(
"copySubsetOfHist",
"zmin: %f exceeds range of z-axis [%f,%f] ... returning NULL",
4922 zmin,hist->GetZaxis()->GetBinLowEdge(1),hist->GetZaxis()->GetBinUpEdge(nbinsz));
4927 if (zbinmax<1 || zbinmax>nbinsz)
4929 ::Error(
"copySubsetOfHist",
"zmax: %f exceeds range of z-axis [%f,%f] ... returning NULL",
4930 zmax,hist->GetZaxis()->GetBinLowEdge(1),hist->GetZaxis()->GetBinUpEdge(nbinsz));
4933 if (ybinmax!=-1) zbinmax--;
4936 TH1* histD = copyBinSubsetOfHist(hist, xbinmin, xbinmax, ybinmin, ybinmax, zbinmin, zbinmax);
4939 if (!histD)
return NULL;
4951 name = Form(
"%s_subset_X_%2.2g-%2.2g",
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 )",
4957 (xbinmin==0 )? hist->GetXaxis()->GetBinLowEdge(1) :xmin,
4958 (xbinmax==nbinsx+1)? hist->GetXaxis()->GetBinLowEdge(nbinsx):xmax);
4963 name = Form(
"%s_subset_X_%2.2g-%2.2g_Y_%2.2g-%2.2g",
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 )",
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);
4979 name = Form(
"%s_subset_X_%2.2g-%2.2g_Y_%2.2g-%2.2g_Z_%2.2g-%2.2g",
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 )",
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);
4999 ::Error(
"copySubsetOfHist",
"invalid dimension: %i ... returning NULL",dimension);
5005 histD->SetNameTitle(name.Data(),title.Data());