64 #include <TCollection.h>
75 #include <THashList.h>
78 #include <THnSparse.h>
82 #include <TLegendEntry.h>
84 #include <TObjArray.h>
85 #include <TObjString.h>
87 #include <TProfile2D.h>
88 #include <TProfile3D.h>
92 #include <TVirtualPS.h>
105 PairAnalysisHistos::PairAnalysisHistos()
107 TNamed(
"PairAnalysisHistos",
"PairAnalysis Histogram Container")
112 , fReservedWords(new TString(
"Hit;Track;Pair"))
113 , fPrecision(kFloat) {
117 fHistoList.SetOwner(kTRUE);
118 fHistoList.SetName(
"PairAnalysis_Histos");
124 PairAnalysisHistos::PairAnalysisHistos(
const char* name,
const char* title)
131 , fReservedWords(new TString(
"Hit;Track;Pair"))
132 , fPrecision(kFloat) {
136 fHistoList.SetOwner(kTRUE);
137 fHistoList.SetName(name);
143 PairAnalysisHistos::~PairAnalysisHistos() {
148 if (fUsedVars)
delete fUsedVars;
149 if (fList) fList->Clear();
150 if (fMetaData)
delete fMetaData;
151 delete fReservedWords;
155 void PairAnalysisHistos::UserHistogram(
const char* histClass,
165 isOk &= (ndim < 21 && ndim > 3);
169 "Array sizes should be between 3 and 20. Not adding Histogram to '%s'.",
173 isOk &= (ndim == limits->GetEntriesFast());
178 for (Int_t iv = 0; iv < ndim; iv++)
180 name.Resize(name.Length() - 1);
182 isOk &= IsHistogramOk(histClass, name);
188 for (Int_t idim = 0; idim < ndim; idim++) {
189 TVectorD* vec = (TVectorD*) limits->At(idim);
190 bins[idim] = vec->GetNrows() - 1;
193 hist =
new THnD(name.Data(),
"", ndim, bins, 0x0, 0x0);
196 for (Int_t idim = 0; idim < ndim; idim++) {
197 TVectorD* vec = (TVectorD*) limits->At(idim);
198 hist->SetBinEdges(idim, vec->GetMatrixArray());
202 StoreVariables(hist, vars);
203 hist->SetUniqueID(valTypeW);
206 for (Int_t
i = 0;
i < ndim;
i++)
207 fUsedVars->SetBitNumber(vars[
i], kTRUE);
208 fUsedVars->SetBitNumber(valTypeW, kTRUE);
210 Bool_t isReserved = fReservedWords->Contains(histClass);
212 UserHistogramReservedWords(histClass, hist);
214 UserHistogram(histClass, hist);
219 void PairAnalysisHistos::AddSparse(
const char* histClass,
229 isOk &= (ndim == limits->GetEntriesFast());
234 for (Int_t iv = 0; iv < ndim; iv++)
236 name.Resize(name.Length() - 1);
238 isOk &= IsHistogramOk(histClass, name);
245 for (Int_t idim = 0; idim < ndim; idim++) {
246 TVectorD* vec = (TVectorD*) limits->At(idim);
247 bins[idim] = vec->GetNrows() - 1;
254 for (Int_t idim = 0; idim < ndim; idim++) {
255 TVectorD* vec = (TVectorD*) limits->At(idim);
256 hist->SetBinEdges(idim, vec->GetMatrixArray());
260 StoreVariables(hist, vars);
261 hist->SetUniqueID(valTypeW);
264 for (Int_t
i = 0;
i < ndim;
i++)
265 fUsedVars->SetBitNumber(vars[
i], kTRUE);
266 fUsedVars->SetBitNumber(valTypeW, kTRUE);
268 Bool_t isReserved = fReservedWords->Contains(histClass);
270 UserHistogramReservedWords(histClass, hist);
272 UserHistogram(histClass, hist);
277 void PairAnalysisHistos::AddSparse(
const char* histClass,
287 isOk &= (ndim == limits->GetEntriesFast());
292 for (Int_t iv = 0; iv < ndim; iv++)
294 name.Resize(name.Length() - 1);
295 name.ReplaceAll(
"f(",
"");
296 name.ReplaceAll(
")",
"");
300 isOk &= IsHistogramOk(histClass, name);
307 for (Int_t idim = 0; idim < ndim; idim++) {
308 TVectorD* vec = (TVectorD*) limits->At(idim);
309 bins[idim] = vec->GetNrows() - 1;
316 for (Int_t idim = 0; idim < ndim; idim++) {
317 TVectorD* vec = (TVectorD*) limits->At(idim);
318 hist->SetBinEdges(idim, vec->GetMatrixArray());
322 for (Int_t idim = 0; idim < ndim; idim++) {
323 vars[idim]->SetName(Form(
"axis%dFormula", idim));
329 hist->SetUniqueID(valTypeW);
332 AdaptNameTitle(hist, histClass);
336 fUsedVars->SetBitNumber(valTypeW, kTRUE);
338 Bool_t isReserved = fReservedWords->Contains(histClass);
340 UserHistogramReservedWords(histClass, hist);
342 UserHistogram(histClass, hist);
347 TString PairAnalysisHistos::UserHistogram(
const char* histClass,
354 Bool_t isReserved = fReservedWords->Contains(histClass);
356 UserHistogramReservedWords(histClass, hist);
357 return hist->GetName();
365 UInt_t valType[20] = {0};
367 FillVarArray(hist, valType);
370 TString hclass = histClass;
371 if (hclass.Contains(
"MCtruth") && !(hist->IsA() == PairAnalysisHn::Class())) {
372 for (Int_t
i = 0;
i < 2;
i++) {
377 ((TH1*) hist)->GetXaxis()->GetName());
380 ((TH1*) hist)->GetYaxis()->GetName());
386 return hist->GetName();
388 fUsedVars->SetBitNumber(valType[
i], kTRUE);
391 StoreVariables(hist, valType);
392 hist->SetUniqueID(valType[19]);
394 if (hist->InheritsFrom(TH1::Class())) {
395 TIter next(((TH1*) hist)->GetListOfFunctions());
397 while ((
f =
dynamic_cast<TFormula*
>(next()))) {
398 for (Int_t
i = 0;
i <
f->GetNpar();
i++) {
403 return hist->GetName();
404 f->SetParameter(
i, parMC);
406 fUsedVars->SetBitNumber(parMC, kTRUE);
410 AdaptNameTitle((TH1*) hist, histClass);
413 StoreVariables(hist, valType);
414 hist->SetUniqueID(valType[19]);
418 if (!IsHistogramOk(histClass, hist->GetName()))
return hist->GetName();
419 THashList* classTable = (THashList*) fHistoList.FindObject(histClass);
421 if (classTable) classTable->Add(hist);
422 return hist->GetName();
426 TH1* PairAnalysisHistos::GetTHist(
const char* histClass,
429 const TVectorD*
const binsX,
430 const TVectorD*
const binsY,
431 const TVectorD*
const binsZ) {
436 isOk &= IsHistogramOk(histClass, name);
437 isOk &= (binsX != 0x0);
438 if (!isOk)
return 0x0;
439 switch (fPrecision) {
443 name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray()));
445 return (
new TH2F(name,
447 binsX->GetNrows() - 1,
448 binsX->GetMatrixArray(),
449 binsY->GetNrows() - 1,
450 binsY->GetMatrixArray()));
452 return (
new TH3F(name,
454 binsX->GetNrows() - 1,
455 binsX->GetMatrixArray(),
456 binsY->GetNrows() - 1,
457 binsY->GetMatrixArray(),
458 binsZ->GetNrows() - 1,
459 binsZ->GetMatrixArray()));
464 name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray()));
466 return (
new TH2D(name,
468 binsX->GetNrows() - 1,
469 binsX->GetMatrixArray(),
470 binsY->GetNrows() - 1,
471 binsY->GetMatrixArray()));
473 return (
new TH3D(name,
475 binsX->GetNrows() - 1,
476 binsX->GetMatrixArray(),
477 binsY->GetNrows() - 1,
478 binsY->GetMatrixArray(),
479 binsZ->GetNrows() - 1,
480 binsZ->GetMatrixArray()));
482 default:
return 0x0;
break;
487 TH1* PairAnalysisHistos::GetTProf(
const char* histClass,
490 const TVectorD*
const binsX,
491 const TVectorD*
const binsY,
492 const TVectorD*
const binsZ,
498 isOk &= IsHistogramOk(histClass, name);
499 isOk &= (binsX != 0x0);
500 if (!isOk)
return 0x0;
503 Double_t pmin = 0., pmax = 0.;
504 if (!option.IsNull()) {
505 TObjArray* arr = option.Tokenize(
";");
507 opt = ((TObjString*) arr->At(0))->GetString();
508 if (arr->GetEntriesFast() > 1)
509 pmin = (((TObjString*) arr->At(1))->GetString()).Atof();
510 if (arr->GetEntriesFast() > 2)
511 pmax = (((TObjString*) arr->At(2))->GetString()).Atof();
517 return (
new TProfile(name,
519 binsX->GetNrows() - 1,
520 binsX->GetMatrixArray(),
525 prof =
new TProfile2D(name,
527 binsX->GetNrows() - 1,
528 binsX->GetMatrixArray(),
529 binsY->GetNrows() - 1,
530 binsY->GetMatrixArray());
531 ((TProfile2D*) prof)->BuildOptions(pmin, pmax, opt.Data());
534 prof =
new TProfile3D(name,
536 binsX->GetNrows() - 1,
537 binsX->GetMatrixArray(),
538 binsY->GetNrows() - 1,
539 binsY->GetMatrixArray(),
540 binsZ->GetNrows() - 1,
541 binsZ->GetMatrixArray());
542 ((TProfile3D*) prof)->BuildOptions(pmin, pmax, opt.Data());
549 const char* formula) {
553 TFormula* form =
new TFormula(name, formula);
555 if (form->Compile())
return 0x0;
557 for (Int_t
i = 0;
i < form->GetNpar();
i++) {
560 fUsedVars->SetBitNumber((Int_t) form->GetParameter(
i), kTRUE);
566 void PairAnalysisHistos::AddClass(
const char* histClass) {
571 TString hists(histClass);
572 TObjArray* arr = hists.Tokenize(
";");
575 while ((o = next())) {
576 if (fHistoList.FindObject(o->GetName())) {
578 "AddClass",
"Cannot create class '%s' it already exists.", histClass);
581 if (fReservedWords->Contains(o->GetName())) {
582 Error(
"AddClass",
"Pair is a reserved word, please use another name");
585 THashList* table =
new THashList;
586 table->SetOwner(kTRUE);
587 table->SetName(o->GetName());
588 fHistoList.Add(table);
594 void PairAnalysisHistos::FillClass(TString histClass,
const Double_t* values) {
598 THashList* classTable = (THashList*) fHistoList.FindObject(histClass.Data());
604 TIter nextHist(classTable);
606 while ((obj = (TObject*) nextHist()))
607 FillValues(obj, values);
613 void PairAnalysisHistos::UserHistogramReservedWords(
const char* histClass,
614 const TObject* hist) {
618 TString title(hist->GetTitle());
620 TIter nextClass(&fHistoList);
622 while ((l =
static_cast<THashList*
>(nextClass()))) {
623 TString name(l->GetName());
624 if (name.Contains(histClass)) {
625 TObject*
h = hist->Clone();
628 if (
h->InheritsFrom(TH1::Class()))
629 ((TH1*)
h)->SetTitle(Form(
"%s %s", title.Data(), l->GetName()));
631 ((THnBase*)
h)->SetTitle(Form(
"%s %s", title.Data(), l->GetName()));
633 UserHistogram(l->GetName(),
h);
642 void PairAnalysisHistos::DumpToFile(
const char* file) {
646 TFile
f(file,
"recreate");
647 fHistoList.Write(fHistoList.GetName(), TObject::kSingleKey);
652 TObject* PairAnalysisHistos::GetHist(
const char* histClass,
653 const char* name)
const {
657 THashList* classTable = (THashList*) fHistoList.FindObject(histClass);
658 if (!classTable)
return 0x0;
659 return classTable->FindObject(name);
663 TH1* PairAnalysisHistos::GetHistogram(
const char* histClass,
664 const char* name)
const {
668 return ((TH1*) GetHist(histClass, name));
672 TObject* PairAnalysisHistos::GetHist(
const char* cutClass,
673 const char* histClass,
674 const char* name)
const {
680 if (!fList)
return 0x0;
681 THashList*
h =
dynamic_cast<THashList*
>(fList->FindObject(cutClass));
683 THashList* classTable =
dynamic_cast<THashList*
>(
h->FindObject(histClass));
684 if (!classTable)
return 0x0;
685 return classTable->FindObject(name);
689 TH1* PairAnalysisHistos::GetHistogram(
const char* cutClass,
690 const char* histClass,
691 const char* name)
const {
696 return ((TH1*) GetHist(cutClass, histClass, name));
700 void PairAnalysisHistos::Draw(
const Option_t* option) {
705 TString drawStr(option);
706 TObjArray* arr = drawStr.Tokenize(
";");
711 TObjString* ostr = 0x0;
715 while ((ostr = (TObjString*) nextOpt())) {
716 currentOpt = ostr->GetString();
717 currentOpt.Remove(TString::kBoth,
'\t');
718 currentOpt.Remove(TString::kBoth,
' ');
720 testOpt =
"classes=";
721 if (currentOpt.Contains(testOpt.Data())) {
722 drawClasses = currentOpt(testOpt.Length(), currentOpt.Length());
735 "When writing to a file you have to create a canvas before opening "
739 c = gPad->GetCanvas();
744 TIter nextClass(&fHistoList);
745 THashList* classTable = 0;
747 while ((classTable = (THashList*) nextClass())) {
749 if (!drawClasses.IsNull() && !drawClasses.Contains(classTable->GetName()))
752 Int_t nPads = classTable->GetEntries();
753 Int_t nCols = (Int_t) TMath::Ceil(TMath::Sqrt(nPads));
754 Int_t nRows = (Int_t) TMath::Ceil((Double_t) nPads / (Double_t) nCols);
759 canvasName.Form(
"c%s_%s", GetName(), classTable->GetName());
760 c = (TCanvas*) gROOT->FindObject(canvasName.Data());
762 c =
new TCanvas(canvasName.Data(),
763 Form(
"%s: %s", GetName(), classTable->GetName()));
770 if (nPads > 1) c->Clear();
773 if (nCols > 1 || nRows > 1) c->Divide(nCols, nRows);
776 TIter nextHist(classTable);
779 while ((
h = (TH1*) nextHist())) {
781 if ((
h->InheritsFrom(TH2::Class()))) drawOpt =
"colz";
782 if (nCols > 1 || nRows > 1) c->cd(++iPad);
783 if (TMath::Abs(
h->GetXaxis()->GetBinWidth(1)
784 -
h->GetXaxis()->GetBinWidth(2))
787 if (TMath::Abs(
h->GetYaxis()->GetBinWidth(1)
788 -
h->GetYaxis()->GetBinWidth(2))
791 if (TMath::Abs(
h->GetZaxis()->GetBinWidth(1)
792 -
h->GetZaxis()->GetBinWidth(2))
795 TString histOpt =
h->GetOption();
797 if (histOpt.Contains(
"logx")) gPad->SetLogx();
798 if (histOpt.Contains(
"logy")) gPad->SetLogy();
799 if (histOpt.Contains(
"logz")) gPad->SetLogz();
800 histOpt.ReplaceAll(
"logx",
"");
801 histOpt.ReplaceAll(
"logy",
"");
802 histOpt.ReplaceAll(
"logz",
"");
803 h->Draw(drawOpt.Data());
805 if (gVirtualPS) { c->Update(); }
811 void PairAnalysisHistos::Print(
const Option_t* option)
const {
815 TString optString(option);
817 if (optString.IsNull()) PrintStructure();
821 void PairAnalysisHistos::PrintStructure()
const {
826 TIter nextClass(&fHistoList);
827 THashList* classTable = 0;
828 while ((classTable = (THashList*) nextClass())) {
829 TIter nextHist(classTable);
831 Printf(
"+ %s\n", classTable->GetName());
832 while ((o = nextHist()))
833 Printf(
"| ->%s\n", o->GetName());
836 TIter nextCutClass(fList);
837 THashList* cutClass = 0x0;
838 while ((cutClass = (THashList*) nextCutClass())) {
839 TString cla = cutClass->GetName();
840 if (cla.Contains(
"QAcuts"))
continue;
841 Printf(
"+ %s\n", cutClass->GetName());
842 TIter nextClass(cutClass);
843 THashList* classTable = 0;
844 while ((classTable = (THashList*) nextClass())) {
845 TIter nextHist(classTable);
847 Printf(
"| + %s\n", classTable->GetName());
848 while ((o = nextHist()))
849 Printf(
"| | ->%s\n", o->GetName());
856 void PairAnalysisHistos::SetHistogramList(THashList& list,
861 ResetHistogramList();
862 TString name(GetName());
864 SetName(list.GetName());
867 while ((o = next())) {
871 list.SetOwner(kFALSE);
872 fHistoList.SetOwner(kTRUE);
873 fHistoList.SetName(list.GetName());
875 fHistoList.SetOwner(kFALSE);
876 fHistoList.SetName(list.GetName());
881 Bool_t PairAnalysisHistos::SetCutClass(
const char* cutClass) {
886 if (!fList)
return kFALSE;
887 ResetHistogramList();
888 THashList*
h =
dynamic_cast<THashList*
>(fList->FindObject(cutClass));
890 Warning(
"SetCutClass",
"cutClass '%s' not found", cutClass);
893 SetHistogramList(*
h, kFALSE);
897 Bool_t PairAnalysisHistos::IsHistogramOk(
const char* histClass,
902 Bool_t isReserved = fReservedWords->Contains(histClass);
903 if (!fHistoList.FindObject(histClass) && !isReserved) {
904 Warning(
"IsHistogramOk",
905 "Cannot create histogram. Class '%s' not defined. Please create it "
906 "using AddClass before.",
910 if (GetHist(histClass, name)) {
911 Warning(
"IsHistogramOk",
912 "Cannot create histogram '%s' in class '%s': It already exists!",
930 void PairAnalysisHistos::ReadFromFile(
const char* file,
932 const char* config) {
937 TIter nextKey(
f.GetListOfKeys());
939 while ((key = (TKey*) nextKey())) {
940 TString name = key->GetName();
942 if (name.Contains(Form(
"PairAnalysisMetaData_%s",
task))) {
944 fMetaData->SetMetaData(*
dynamic_cast<TList*
>(
f.Get(key->GetName())),
948 if (!name.Contains(Form(
"PairAnalysisHistos_%s",
task)))
continue;
949 if (!strlen(
task) && !name.Contains(
task))
continue;
950 TObject* o =
f.Get(key->GetName());
951 TList* list =
dynamic_cast<TList*
>(o);
956 THashList* listCfg =
dynamic_cast<THashList*
>(list->FindObject(config));
957 if (!listCfg)
continue;
958 SetHistogramList(*listCfg);
967 TObjArray* PairAnalysisHistos::DrawTaskSame(TString histName,
969 TString histClassDenom,
982 TObjArray* selections = histClassDenom.Tokenize(
":;,");
985 TString optString(opt);
986 Bool_t optGoff = optString.Contains(
"goff");
987 Bool_t optEff = optString.Contains(
"eff");
988 Bool_t optCutStep = optString.Contains(
"cutstep");
989 Bool_t optSelCfg = optString.Contains(
"selcfg");
990 opt.ReplaceAll(
"selcfg",
"");
991 fHistoList.SetOwner(kFALSE);
994 TObjArray* arr = NULL;
995 if (optGoff) Info(
"DrawTaskSame",
"graphics option off, collect an array");
1001 arr =
new TObjArray();
1003 arr->SetName(GetName());
1004 arr->SetOwner(kFALSE);
1008 TString legendname = GetName();
1012 TObjArray* reservedWords = fReservedWords->Tokenize(
":;");
1016 TString cutstepTask = fHistoList.GetName();
1017 THashList* listCutStep =
1018 dynamic_cast<THashList*
>(fList->FindObject(cutstepTask));
1019 if (listCutStep) fList = listCutStep;
1023 THashList* listDenom =
1024 dynamic_cast<THashList*
>(fList->FindObject(taskDenom.Data()));
1025 if (listDenom) opt +=
"div";
1028 TIter nextCfg(fList);
1029 THashList* listCfg = 0;
1030 while ((listCfg =
static_cast<THashList*
>(nextCfg()))) {
1032 TString lname = listCfg->GetName();
1035 if (lname.Contains(
"QAcuts_"))
continue;
1036 Info(
"DrawTaskSame",
" Task name %s ", lname.Data());
1039 if (!optEff && listDenom && lname.EqualTo(taskDenom))
continue;
1042 if (optSelCfg && selections->GetEntriesFast()) {
1043 Bool_t pass = kFALSE;
1044 for (Int_t is = 0; is < selections->GetEntriesFast(); is++) {
1045 Bool_t testIgnore = kFALSE;
1046 TString raw = ((TObjString*) selections->At(is))->GetString();
1052 for (Int_t ir = 0; ir < reservedWords->GetEntriesFast(); ir++) {
1054 raw.Contains(((TObjString*) reservedWords->At(ir))->GetString());
1055 if (testIgnore)
break;
1057 if (testIgnore)
continue;
1060 srch.ReplaceAll(
"!",
"");
1061 Bool_t optExclSel = !(srch.EqualTo(raw));
1066 if (!(!lname.EqualTo(srch)) ^ (optExclSel)) pass = kTRUE;
1068 if (lname.EqualTo(srch)) {
1069 pass = !(!lname.EqualTo(srch)) ^ (optExclSel);
1076 if (!pass)
continue;
1080 if (lname.EqualTo(legendname)) legendname =
"";
1083 ResetHistogramList();
1084 TIter next(listCfg);
1087 while ((o = next())) {
1088 fHistoList.AddAt(o, idx++);
1093 SetName(listCfg->GetName());
1095 DrawSame(histName, (opt +
"task").Data(), histClassDenom, listDenom));
1099 if (optString.Contains(
"leg")) {
1101 legendname.ReplaceAll(
".",
"");
1102 TList* prim = gPad->GetListOfPrimitives();
1103 TLegend* leg = (TLegend*) prim->FindObject(
"TPave");
1105 TList* llist = leg->GetListOfPrimitives();
1106 Int_t nent = llist->GetEntries();
1107 for (Int_t il = 0; il < nent; il++) {
1108 TLegendEntry* lent =
static_cast<TLegendEntry*
>(llist->At(il));
1109 TString lst(lent->GetLabel());
1110 lst.ReplaceAll(legendname.Data(),
"");
1111 lent->SetLabel(lst.Data());
1114 if (!legendname.EqualTo(
"none"))
1117 leg->SetHeader(legendname.Data());
1124 if (selections)
delete selections;
1125 if (reservedWords)
delete reservedWords;
1126 if (!optGoff)
delete arr;
1132 TObjArray* PairAnalysisHistos::DrawSame(TString histName,
1134 TString histClassDenom,
1135 THashList* listDenom) {
1183 TString optString(option);
1184 optString.ToLower();
1185 printf(
"Plot hist: '%s' class-denom/sel: '%s' \t listDenom: '%s' \t options: "
1188 histClassDenom.Data(),
1189 (listDenom ? listDenom->GetName() :
""),
1191 Bool_t optBack = optString.Contains(
"back");
1192 optString.ReplaceAll(
"back",
"");
1193 Bool_t optGoff = optString.Contains(
"goff");
1194 optString.ReplaceAll(
"goff",
"");
1195 Bool_t optTask = optString.Contains(
"task");
1196 optString.ReplaceAll(
"task",
"");
1197 Bool_t optCutStep = optString.Contains(
"cutstep");
1198 optString.ReplaceAll(
"cutstep",
"");
1200 Bool_t optDiv = optString.Contains(
"div");
1201 optString.ReplaceAll(
"div",
"");
1202 Bool_t optEff = optString.Contains(
"eff");
1203 optString.ReplaceAll(
"eff",
"");
1204 Bool_t optRatio = optString.Contains(
"ratio");
1205 optString.ReplaceAll(
"ratio",
"");
1206 Bool_t optOneOver = optString.Contains(
"oneover");
1207 optString.ReplaceAll(
"oneover",
"");
1209 Bool_t optNoMCtrue = optString.Contains(
"nomctrue");
1210 optString.ReplaceAll(
"nomctrue",
"");
1211 Bool_t optNoMC = optString.Contains(
"nomc");
1212 optString.ReplaceAll(
"nomc",
"");
1213 Bool_t optOnlyMCtrue = optString.Contains(
"onlymctrue");
1214 optString.ReplaceAll(
"onlymctrue",
"");
1215 Bool_t optOnlyMC = optString.Contains(
"onlymc");
1216 optString.ReplaceAll(
"onlymc",
"");
1217 Bool_t optSel = optString.Contains(
"sel");
1218 optString.ReplaceAll(
"sel",
"");
1220 Bool_t optCan = optString.Contains(
"can");
1221 optString.ReplaceAll(
"can",
"");
1222 Bool_t optLegFull = optString.Contains(
"legf");
1223 optString.ReplaceAll(
"legf",
"");
1224 Bool_t optLeg = optString.Contains(
"leg");
1225 optString.ReplaceAll(
"leg",
"");
1226 Bool_t optDet = optString.Contains(
"det");
1227 optString.ReplaceAll(
"det",
"");
1228 Bool_t optMeta = optString.Contains(
"meta");
1229 optString.ReplaceAll(
"meta",
"");
1230 Bool_t optWdth = optString.Contains(
"width");
1231 optString.ReplaceAll(
"width",
"");
1232 Bool_t optRbnStat = optString.Contains(
"rebinstat");
1233 optString.ReplaceAll(
"rebinstat",
"stat");
1234 Bool_t optRbn = optString.Contains(
"rebin");
1235 Bool_t optSmooth = optString.Contains(
"smooth");
1236 Bool_t optSclMax = optString.Contains(
"sclmax");
1237 optString.ReplaceAll(
"sclmax",
"");
1238 Bool_t optNormY = optString.Contains(
"normy");
1239 optString.ReplaceAll(
"normy",
"");
1240 Bool_t optNorm = optString.Contains(
"norm");
1241 optString.ReplaceAll(
"norm",
"");
1242 Bool_t optCumR = optString.Contains(
"cumr");
1243 optString.ReplaceAll(
"cumr",
"");
1244 Bool_t optCum = optString.Contains(
"cum");
1245 optString.ReplaceAll(
"cum",
"");
1246 Bool_t optEvt = optString.Contains(
"events");
1247 optString.ReplaceAll(
"events",
"");
1248 Bool_t optStack = optString.Contains(
"stack");
1249 optString.ReplaceAll(
"stack",
"");
1250 Bool_t optRstSty = optString.Contains(
"rststy");
1251 optString.ReplaceAll(
"rststy",
"");
1252 Bool_t optSlicesY = optString.Contains(
"slicesy");
1253 optString.ReplaceAll(
"slicesy",
"");
1255 Bool_t optMeanX = optString.Contains(
"meanx");
1256 optString.ReplaceAll(
"meanx",
"");
1257 Bool_t optRmsX = optString.Contains(
"rmsx");
1258 optString.ReplaceAll(
"rmsx",
"");
1259 Bool_t optMeanY = optString.Contains(
"meany");
1260 optString.ReplaceAll(
"meany",
"");
1261 Bool_t optRmsY = optString.Contains(
"rmsy");
1262 optString.ReplaceAll(
"rmsy",
"");
1263 Bool_t optGeant = optString.Contains(
"geant");
1264 optString.ReplaceAll(
"geant",
"");
1265 Bool_t optPdgClean = optString.Contains(
"pdgc");
1266 optString.ReplaceAll(
"pdgc",
"");
1267 Bool_t optPdg = optString.Contains(
"pdg");
1268 optString.ReplaceAll(
"pdg",
"");
1274 optString(optString.Index(
"rebin", 5, 0, TString::kExact) + 5));
1275 if (rebin.IsDigit()) {
1277 optString.ReplaceAll(rebin,
"");
1279 optString.ReplaceAll(
"rebin",
"");
1283 TArrayD* limits = NULL;
1284 Double_t stat = 0.8;
1287 optString(optString.Index(
"stat", 4, 0, TString::kExact) + 4, 4));
1288 if (!rebin.IsFloat())
1289 rebin = optString(optString.Index(
"stat", 4, 0, TString::kExact) + 4, 3);
1290 if (rebin.IsFloat()) {
1291 stat = rebin.Atof();
1293 optString.ReplaceAll(rebin,
"");
1295 optString.ReplaceAll(
"stat",
"");
1302 optString(optString.Index(
"smooth", 6, 0, TString::kExact) + 6));
1303 if (smooth.IsDigit()) {
1304 smth = smooth.Atoi();
1305 optString.ReplaceAll(smooth,
"");
1307 optString.ReplaceAll(
"smooth",
"");
1311 if (optLegFull) optLeg = kTRUE;
1312 if (optCumR) optCum = kTRUE;
1316 TObjArray* selections = (optSel ? histClassDenom.Tokenize(
":;,") : NULL);
1317 if (optSel) histClassDenom =
"";
1320 TObjArray* arr = 0x0;
1322 Info(
"DrawSame",
"graphics option off, collect an array");
1324 arr = (TObjArray*) gROOT->FindObject(GetName());
1326 Warning(
"DrawSame",
"Clear existing array %s", GetName());
1330 arr =
new TObjArray();
1332 arr->SetName(GetName());
1333 arr->SetOwner(kFALSE);
1345 c = (TCanvas*) gROOT->FindObject(Form(
"c%s", histName.Data()));
1347 c =
new TCanvas(Form(
"c%s", histName.Data()),
1348 Form(
"All '%s' histograms", histName.Data()));
1358 TList* prim = (gPad ? gPad->GetListOfPrimitives() : 0x0);
1361 for (Int_t io = 0; io < (prim ? prim->GetSize() : 0); io++) {
1363 if (obj->InheritsFrom(TH1::Class()) && obj != prim->At(io + 1)) nobj++;
1364 if (obj->InheritsFrom(THStack::Class()) && obj != prim->At(io + 1)) nobj++;
1365 if (nobj == 1) hFirst = (TH1*) obj;
1370 if ((optLeg && !nobj)) {
1371 leg =
new TLegend(0. + gPad->GetLeftMargin() + gStyle->GetTickLength(
"Y"),
1372 0. + gPad->GetBottomMargin() + gStyle->GetTickLength(
"X"),
1373 1. - gPad->GetRightMargin() + gStyle->GetTickLength(
"Y"),
1374 1. - gPad->GetTopMargin() + gStyle->GetTickLength(
"X"),
1377 if (optTask && !optCutStep) leg->SetHeader(
"");
1379 leg = (TLegend*) prim->FindObject(
"TPave");
1387 Info(
"DrawSame",
"Basics: nobj: %d \t leg: %p", nobj, leg);
1390 if (optString.Contains(
"logx")) gPad->SetLogx();
1391 if (optString.Contains(
"logy")) gPad->SetLogy();
1392 if (optString.Contains(
"logz")) gPad->SetLogz();
1393 optString.ReplaceAll(
"logx",
"");
1394 optString.ReplaceAll(
"logy",
"");
1395 optString.ReplaceAll(
"logz",
"");
1399 if (fMetaData && optEvt) fMetaData->GetMeta(
"events", &events);
1402 if (optTask && nobj)
i = nobj;
1403 TListIter next(&fHistoList, (optBack ? kIterBackward : kIterForward));
1405 THashList* classTable = 0;
1408 while ((classTable = (THashList*) next())) {
1409 TString histClass = classTable->GetName();
1411 Int_t ndel = histClass.CountChar(
'_');
1413 "Search for hist: '%s' class-denom: '%s' select: '%s' \t ndel: %d \t "
1416 histClassDenom.Data(),
1422 if ((optNoMC && ndel > 0) || (optEff && ndel < 1)
1423 || (optNoMCtrue && histClass.Contains(
"_MCtruth"))
1424 || (optOnlyMC && ndel < 1) || (optOnlyMCtrue && ndel < 2))
1428 if (optSel && selections->GetEntriesFast()) {
1429 Bool_t pass = kFALSE;
1430 for (Int_t is = 0; is < selections->GetEntriesFast(); is++) {
1431 TString raw = ((TObjString*) selections->At(is))->GetString();
1433 srch.ReplaceAll(
"!",
"");
1434 Bool_t optExclSel = !(srch.EqualTo(raw));
1436 if (!(!histClass.Contains(srch, TString::kIgnoreCase)) ^ (optExclSel))
1439 if (histClass.EqualTo(srch, TString::kIgnoreCase)) {
1441 !(!histClass.EqualTo(srch, TString::kIgnoreCase)) ^ (optExclSel);
1445 if (!pass)
continue;
1451 TH1*
h = (TH1*) classTable->FindObject(histName.Data());
1452 if (!
h && !optNoMC && !optNoMCtrue) {
1454 TString histdenomMC = histName +
"MC";
1455 h = (TH1*) classTable->FindObject(histdenomMC.Data());
1458 if (
h->GetEntries() < 1.)
continue;
1461 if (optEff && !histClass.Contains(
"_MCtruth"))
1462 histClassDenom = histClass +
"_MCtruth";
1464 " Hist found in histClass '%s' (search for denom '%s') ",
1466 histClassDenom.Data());
1469 if ((optEff || optRatio)
1470 && (histClass.EqualTo(histClassDenom)
1471 || !fHistoList.FindObject(histClassDenom.Data())))
1473 else if (!histClassDenom.IsNull())
1474 Info(
"DrawSame",
" Denom histClass '%s' found ", histClassDenom.Data());
1477 if (
i == 0 && !hFirst) hFirst =
h;
1480 if (optRbn || optRbnStat)
1482 " Rebin by %d, to <%.1f%% stat. uncertainty per bin",
1484 (optRbnStat ? stat * 100 : 0));
1485 if (optNormY || optNorm || optEvt)
1487 " Normalize in y-axis,2D's only(%d), by int.(%d), by #events(%d)",
1491 if (optSclMax) Info(
"DrawSame",
" Scale to maximum(%d)", optSclMax);
1494 " Cumulate sum of bins along x-axis, 1D's left-to-right(%d), "
1495 "right-to-left(%d)",
1501 if (optRbn &&
h->InheritsFrom(TH2::Class()))
1502 h = ((TH2*)
h)->RebinX(rbn,
h->GetName());
1505 if (optNormY &&
h->GetDimension() == 2 && !(
h->GetSumOfWeights() == 0)
1508 if (optRbnStat &&
h->GetDimension() == 1) {
1511 h =
h->Rebin(limits->GetSize() - 1,
h->GetName(), limits->GetArray());
1512 h->Scale(1.,
"width");
1516 if (optSmooth)
h->Smooth(smth);
1519 TString ytitle =
h->GetYaxis()->GetTitle();
1520 TString ztitle =
h->GetZaxis()->GetTitle();
1521 if (ytitle.Contains(
"{evt}")) optEvt = kFALSE;
1523 if (optNorm && !(
h->GetSumOfWeights() == 0) && !optCum)
1524 h =
h->DrawNormalized(
i > 0 ? (optString +
"same").Data()
1525 : optString.Data());
1526 if (optEvt)
h->Scale(1. / events);
1527 if (optSclMax)
h->Scale(1. /
h->GetBinContent(
h->GetMaximumBin()));
1530 switch (
h->GetDimension()) {
1532 if (optEvt)
h->SetYTitle((ytitle +
"/N_{evt}").Data());
1533 if (optNorm)
h->SetYTitle((ytitle.Append(
" (normalized)")).Data());
1534 if (optCum)
h->SetYTitle((ytitle.Prepend(
"cumulated ")).Data());
1535 if (optRatio)
h->SetYTitle(
"ratio");
1536 if (optDiv)
h->SetYTitle(
"ratio");
1537 if (optEff)
h->SetYTitle(
"acceptance #times efficiency");
1538 if (optSclMax)
h->SetYTitle((ytitle +
"/N_{max}").Data());
1541 if (optEvt)
h->SetZTitle((ztitle +
"/N_{evt}").Data());
1543 if (optNorm)
h->SetZTitle((ztitle.Prepend(
"normalized ")).Data());
1544 if (optRatio)
h->SetZTitle(
"ratio");
1545 if (optDiv)
h->SetZTitle(
"ratio");
1546 if (optEff)
h->SetZTitle(
"acceptance #times efficiency");
1547 if (optSclMax)
h->SetZTitle((ztitle +
"/N_{max}").Data());
1552 if ((optEff || optRatio) && !optNorm && !optEvt && !optTask) {
1554 " Calculate '%s' w/o normalisation and within the same task",
1555 (optEff ?
"efficiency" :
"ratio"));
1557 THashList* clDenom =
1558 (THashList*) fHistoList.FindObject(histClassDenom.Data());
1562 TString histdenomMC = UserHistogram(histClassDenom.Data(), hMC);
1563 TH1* hdenom = (TH1*) clDenom->FindObject(histdenomMC.Data());
1565 Error(
"DrawSame",
"Denominator object not found");
1569 " Divide %s(#=%.3e) by %s(#=%.3e)",
1573 hdenom->GetEntries());
1577 if (optRbnStat && (optEff || !(
i % 10))) {
1578 hdenom = hdenom->Rebin(
1579 limits->GetSize() - 1, hdenom->GetName(), limits->GetArray());
1580 hdenom->Scale(1.,
"width");
1582 if (optRbn && (optEff || !(
i % 10))) hdenom->RebinX(rbn);
1583 if (optEvt && (optEff || !(
i % 10))) hdenom->Scale(1. / events);
1584 if (!hdenom || !
h->Divide(hdenom)) {
1585 Warning(
"DrawSame(eff/ratio)",
"Division failed!!!!");
1588 }
else if (optTask && (optDiv || optEff || optRatio)) {
1590 " Calculate '%s' using different tasks",
1591 (optEff ?
"efficiency" : (optRatio ?
"ratio" :
"divison")));
1595 if (optEff || optRatio) {
1596 THashList* clDenom =
1597 (THashList*) fHistoList.FindObject(histClassDenom.Data());
1601 TString histdenomMC = UserHistogram(histClassDenom.Data(), hMC);
1606 hdenom = (TH1*) clDenom->FindObject(histdenomMC.Data());
1610 THashList* clTaskDen =
1611 (THashList*) listDenom->FindObject(histClassDenom.Data());
1614 htden = (TH1*) clTaskDen->FindObject(histdenomMC.Data());
1616 "calculate eff/ratio using task-denom: '%s' class-denom: '%s' "
1618 listDenom->GetName(),
1619 histClassDenom.Data(),
1620 histdenomMC.Data());
1622 if (htden) hdenom = 0x0;
1631 if (optDiv && !optEff) {
1633 " Search for '%s' in task '%s'",
1635 listDenom->GetName());
1636 THashList* clTaskNom =
1637 (THashList*) listDenom->FindObject(histClass.Data());
1638 if (!clTaskNom)
continue;
1639 htnom = (TH1*) clTaskNom->FindObject(histName.Data());
1640 if (!htnom)
continue;
1643 if (hdenom) hdenom->Sumw2();
1644 if (htden) htden->Sumw2();
1645 if (htnom) htnom->Sumw2();
1648 Int_t nbinsh = (
h ?
h->GetNbinsX() : -1);
1649 Int_t nbinsd = (hdenom ? hdenom->GetNbinsX() : -2);
1650 Int_t nbinstd = (htden ? htden->GetNbinsX() : -3);
1651 Int_t nbinstn = (htnom ? htnom->GetNbinsX() : -4);
1655 if (hdenom && nbinsd > nbinsh) hdenom->RebinX(rbn);
1656 if (htden && nbinstd > nbinsh) htden->RebinX(rbn);
1657 if (htnom && nbinstn > nbinsh) htnom->RebinX(rbn);
1660 if (hdenom && nbinsd > nbinsh) {
1661 hdenom = hdenom->Rebin(
1662 limits->GetSize() - 1, hdenom->GetName(), limits->GetArray());
1663 hdenom->Scale(1.,
"width");
1665 if (htden && nbinstd > nbinsh) {
1666 htden = htden->Rebin(
1667 limits->GetSize() - 1, htden->GetName(), limits->GetArray());
1668 htden->Scale(1.,
"width");
1670 if (htnom && nbinstn > nbinsh) {
1671 htnom = htnom->Rebin(
1672 limits->GetSize() - 1, htnom->GetName(), limits->GetArray());
1673 htnom->Scale(1.,
"width");
1678 if (hdenom) hdenom->Scale(1. / events);
1679 if (htden) htden->Scale(1. / events);
1680 if (htnom) htnom->Scale(1. / events);
1684 " Use nominator (%p,#=%.3e) and denominator 'same task & different "
1685 "class'(%p,#=%.3e), 'certain task & different class'(%p,#=%.3e), "
1686 "'certain task & same class'(%p,#=%.3e)",
1690 (hdenom ? hdenom->GetEntries() : 0),
1692 (htden ? htden->GetEntries() : 0),
1694 (htnom ? htnom->GetEntries() : 0));
1700 if (hdenom && !
h->Divide(hdenom)) {
1701 Warning(
"DrawSame(eff/ratio)",
"h & denom division failed!!!!");
1703 }
else if (htden && htnom && !
i && !htnom->Divide(htden)) {
1704 Warning(
"DrawSame(eff/ratio)",
1705 "task-nom/task-denom division failed!!!!");
1707 }
else if (optDiv && htnom && !
h->Divide(htnom)) {
1708 Warning(
"DrawSame(eff/ratio)",
"h & task-nom division failed!!!!");
1710 }
else if (htden && !
h->Divide(htden)) {
1711 Warning(
"DrawSame(eff/ratio)",
"h & task-denom division failed!!!!");
1717 if (optWdth && !optRbnStat)
h->Scale(1.,
"width");
1722 Info(
"DrawSame",
" Scale by 1/content");
1723 TH1* hOne = (TH1*)
h->Clone(
"one");
1724 hOne->Reset(
"ICSE");
1725 for (Int_t ib = 0; ib < (
h->GetNbinsX() + 2) * (
h->GetNbinsY() + 2)
1726 * (
h->GetNbinsZ() + 2);
1728 hOne->SetBinContent(ib, 1.);
1729 if (hOne->Divide(
h))
h = hOne;
1734 Info(
"DrawSame",
" Set GEANT bin labels");
1739 if (optPdg || optPdgClean) {
1740 Info(
"DrawSame",
" Set PDG bin labels");
1746 if (
h->GetLineColor() == kBlack
1747 && !optString.Contains(
"col")) {
1748 h->UseCurrentStyle();
1752 if (optString.Contains(
"scat"))
h->SetMarkerStyle(kDot);
1753 if (optString.Contains(
"e"))
h->SetLineStyle(kSolid);
1758 h->SetTitle(histClass.Data());
1763 if (optTask)
h->SetTitle(Form(
"%s %s", GetName(),
h->GetTitle()));
1765 }
else if (optStack) {
1769 Form(
";%s;%s",
h->GetXaxis()->GetTitle(),
h->GetYaxis()->GetTitle()));
1772 optString.ReplaceAll(
" ",
"");
1773 Info(
"DrawSame",
" Draw object with options: '%s'", optString.Data());
1776 h->Draw(
h != hFirst ? (optString +
"same").Data() : optString.Data());
1777 }
else if (
h->GetDimension() == 2) {
1779 for (Int_t bin = 1; bin <
h->GetNbinsX(); bin++) {
1780 TH1* hp = ((TH2*)
h)->ProjectionY(
1781 Form(
"%s_%d",
h->GetName(), bin), bin, bin,
"e");
1783 Long64_t nentries = Long64_t(hp->GetEntries());
1784 if (nentries == 0) {
1789 if (optRbn) hp->Rebin(rbn);
1794 limits->GetSize() - 1, hp->GetName(), limits->GetArray());
1795 hp->Scale(1.,
"width");
1798 if (optSmooth) hp->Smooth(smth);
1799 hp->Draw(hFirst ? (optString +
"same").Data() : optString.Data());
1806 if (
h &&
h->GetEntries() > 0.) {
1808 TString ratioName = histClassDenom;
1809 TString divName = (listDenom ? listDenom->GetName() :
"");
1810 if (optEff) divName += (listDenom ?
"(MC)" :
"");
1813 TObjArray* reservedWords = fReservedWords->Tokenize(
":;");
1814 for (Int_t ir = 0; ir < reservedWords->GetEntriesFast(); ir++) {
1816 histClass.ReplaceAll(((TObjString*) reservedWords->At(ir))->GetString(),
1818 ratioName.ReplaceAll(((TObjString*) reservedWords->At(ir))->GetString(),
1820 divName.ReplaceAll(((TObjString*) reservedWords->At(ir))->GetString(),
1829 && (rpl.EqualTo(leg->GetHeader()) || src.EqualTo(leg->GetHeader())))
1831 histClass.ReplaceAll(src, rpl);
1832 ratioName.ReplaceAll(src, rpl);
1833 divName.ReplaceAll(src, rpl);
1839 histClass.ReplaceAll(
"MCtruth",
"MC");
1840 ratioName.ReplaceAll(
"MCtruth",
"MC");
1841 divName.ReplaceAll(
"MCtruth",
"MC");
1847 if (ratioName.CountChar(
'_') > 0)
1849 if (divName.CountChar(
'_') > 0)
1853 histClass.ReplaceAll(
"_{Dalitz}",
"#{Dalitz}");
1854 ratioName.ReplaceAll(
"_{Dalitz}",
"#{Dalitz}");
1855 divName.ReplaceAll(
"_{Dalitz}",
"#{Dalitz}");
1856 histClass.ReplaceAll(
"_{S}",
"#{S}");
1857 ratioName.ReplaceAll(
"_{S}",
"#{S}");
1858 divName.ReplaceAll(
"_{S}",
"#{S}");
1860 histClass.ReplaceAll(
"_",
" ");
1861 ratioName.ReplaceAll(
"_",
" ");
1862 divName.ReplaceAll(
"_",
" ");
1863 histClass.ReplaceAll(
".",
"");
1864 ratioName.ReplaceAll(
".",
"");
1865 divName.ReplaceAll(
".",
"");
1867 histClass.ReplaceAll(
"#{Dalitz}",
"_{Dalitz}");
1868 ratioName.ReplaceAll(
"#{Dalitz}",
"_{Dalitz}");
1869 divName.ReplaceAll(
"#{Dalitz}",
"_{Dalitz}");
1870 histClass.ReplaceAll(
"#{S}",
"_{S}");
1871 ratioName.ReplaceAll(
"#{S}",
"_{S}");
1872 divName.ReplaceAll(
"#{S}",
"_{S}");
1874 histClass.Remove(TString::kBoth,
' ');
1875 ratioName.Remove(TString::kBoth,
' ');
1876 divName.Remove(TString::kBoth,
' ');
1879 if (optRatio) histClass +=
"/" + ratioName;
1882 delete reservedWords;
1885 TString legOpt = optString +
"L";
1886 legOpt.ReplaceAll(
"hist",
"");
1887 legOpt.ReplaceAll(
"scat",
"");
1888 if (legOpt.Contains(
"col")) legOpt =
"";
1889 legOpt.ReplaceAll(
"z",
"");
1890 legOpt.ReplaceAll(
"e",
"");
1891 if (optTask) histClass.Prepend(Form(
"%s ", GetName()));
1892 if ((optTask && optCutStep &&
i) || (optStack && (
i - nobj)))
1893 histClass.Prepend(
"+");
1894 if (optDiv && !optOneOver)
1895 histClass.ReplaceAll(GetName(),
1896 Form(
"%s/%s", GetName(), divName.Data()));
1897 if (optDiv && optOneOver) histClass.Prepend(Form(
"%s/", divName.Data()));
1907 if (optMeanX) histClass += Form(
" #LTx#GT=%.1e",
h->GetMean());
1908 if (optRmsX) histClass += Form(
" RMS(x)=%.1e",
h->GetRMS());
1909 if (optMeanY) histClass += Form(
" #LTy#GT=%.2e",
h->GetMean(2));
1910 if (optRmsY) histClass += Form(
" RMS(y)=%.2e",
h->GetRMS(2));
1911 histClass.ReplaceAll(
"e+00",
"");
1914 leg->AddEntry(
h, histClass.Data(), legOpt.Data());
1918 }
else if (nobj && leg)
1919 leg->AddEntry(hFirst,
"",
"");
1926 if (limits)
delete limits;
1931 optString.ReplaceAll(
" ",
"");
1933 "DrawSame",
" Draw stacked object with options: '%s'", optString.Data());
1934 hs->Draw(nobj > 0 ? (optString +
"same").Data() : optString.Data());
1941 if (!nobj) leg->Draw();
1946 Double_t
max = -1e10;
1947 Double_t
min = +1e10;
1948 TListIter nextObj(gPad->GetListOfPrimitives(), kIterBackward);
1950 while ((obj = nextObj())) {
1951 if (obj->InheritsFrom(TH1::Class())) {
1952 TH1* h1 =
static_cast<TH1*
>(obj);
1956 Double_t tmpmax =
max * (gPad->GetLogy() ? 5. : 1.1);
1957 if (optEff) tmpmax = 1.1;
1958 h1->SetMaximum(tmpmax);
1961 if (gPad->GetLogy() && objmin < 0.) objmin = 0.5;
1962 min = TMath::Min(
min, objmin);
1963 Double_t tmpmin =
min * (
min < 0. ? 1.1 : 0.9);
1965 h1->SetMinimum(tmpmin);
1980 && (tmpmax / (tmpmin > 0. ? tmpmin : 1.)
1981 > TMath::Power(10., TGaxis::GetMaxDigits())
1982 || tmpmin < TMath::Power(10., -TGaxis::GetMaxDigits())
1983 || tmpmin > TMath::Power(10., +TGaxis::GetMaxDigits()))) {
1985 h1->GetYaxis()->SetMoreLogLabels(kFALSE);
1986 h1->GetYaxis()->SetNoExponent(kFALSE);
1988 Double_t tmpXmin = h1->GetXaxis()->GetXmin();
1990 && h1->GetXaxis()->GetXmax()
1991 / (TMath::Abs(tmpXmin) < 1.e-10 ? 1. : tmpXmin)
1992 > TMath::Power(10., TGaxis::GetMaxDigits())) {
1995 h1->GetXaxis()->SetMoreLogLabels(kFALSE);
1996 h1->GetXaxis()->SetNoExponent(kFALSE);
2001 if (!nobj && optMeta && fMetaData && !gPad->GetPrimitive(
"meta")) {
2002 fMetaData->DrawSame(
"");
2007 if (!optTask && 0) {
2008 if (leg) leg->DrawClone();
2011 while ((obj = nextObj())) {
2012 if (obj->InheritsFrom(TLegend::Class())) {
2013 if (ileg > 0)
delete obj;
2028 if (selections)
delete selections;
2034 void PairAnalysisHistos::SetReservedWords(
const char* words) {
2039 (*fReservedWords) = words;
2043 void PairAnalysisHistos::StoreVariables(TObject* obj, UInt_t valType[20]) {
2048 if (obj->InheritsFrom(TH1::Class()))
2049 StoreVariables(
static_cast<TH1*
>(obj), valType);
2050 else if (obj->InheritsFrom(THnBase::Class()))
2051 StoreVariables(
static_cast<THnBase*
>(obj), valType);
2058 void PairAnalysisHistos::StoreVariables(TH1* obj, UInt_t valType[20]) {
2063 Int_t dim = obj->GetDimension();
2066 if (obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class()
2067 || obj->IsA() == TProfile3D::Class()) {
2072 case 4: obj->SetUniqueID(valType[3]);
2073 case 3: obj->GetZaxis()->SetUniqueID(valType[2]);
2074 case 2: obj->GetYaxis()->SetUniqueID(valType[1]);
2076 obj->GetXaxis()->SetUniqueID(valType[0]);
2084 void PairAnalysisHistos::StoreVariables(THnBase* obj, UInt_t valType[20]) {
2092 TList* list = obj->GetListOfFunctions();
2093 if (obj->IsA() == PairAnalysisHn::Class())
2094 list = (
static_cast<PairAnalysisHn*
>(obj))->GetListOfFunctions();
2095 if (list && list->Last())
return;
2097 Int_t dim = obj->GetNdimensions();
2099 for (Int_t it = 0; it < dim; it++) {
2100 obj->GetAxis(it)->SetUniqueID(valType[it]);
2101 obj->GetAxis(it)->SetName(
2103 obj->GetAxis(it)->SetTitle(
2112 void PairAnalysisHistos::FillValues(TObject* obj,
const Double_t* values) {
2117 if (obj->InheritsFrom(TH1::Class()))
2118 FillValues(
static_cast<TH1*
>(obj), values);
2119 else if (obj->InheritsFrom(THnBase::Class()))
2120 FillValues(
static_cast<THnBase*
>(obj), values);
2126 void PairAnalysisHistos::FillValues(TH1* obj,
const Double_t* values) {
2131 Int_t dim = obj->GetDimension();
2132 Bool_t bprf = kFALSE;
2134 UInt_t valueTypes = obj->GetUniqueID();
2135 if (valueTypes == (UInt_t) PairAnalysisHistos::kNoAutoFill)
return;
2136 Bool_t weight = (valueTypes != kNoWeights);
2139 if (obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class()
2140 || obj->IsA() == TProfile3D::Class())
2144 if (obj->IsA() == TProfile3D::Class()) weight = kFALSE;
2147 TList* list = obj->GetListOfFunctions();
2148 TFormula* xform =
dynamic_cast<TFormula*
>(list->FindObject(
"xFormula"));
2149 TFormula* yform =
dynamic_cast<TFormula*
>(list->FindObject(
"yFormula"));
2150 TFormula* zform =
dynamic_cast<TFormula*
>(list->FindObject(
"zFormula"));
2151 TFormula* pform =
dynamic_cast<TFormula*
>(list->FindObject(
"pFormula"));
2152 TFormula* wform =
dynamic_cast<TFormula*
>(list->FindObject(
"wFormula"));
2156 UInt_t value1 = obj->GetXaxis()->GetUniqueID();
2157 UInt_t value2 = obj->GetYaxis()->GetUniqueID();
2158 UInt_t value3 = obj->GetZaxis()->GetUniqueID();
2162 Double_t fvals[4] = {
2163 values[value1], values[value2], values[value3], values[value4]};
2184 if (!bprf && !weight)
2185 obj->Fill(fvals[0]);
2186 else if (!bprf && weight)
2187 obj->Fill(fvals[0], fvals[3]);
2188 else if (bprf && !weight)
2189 ((TProfile*) obj)->Fill(fvals[0], fvals[1]);
2192 ->
Fill(fvals[0], fvals[1], fvals[3]);
2195 if (!bprf && !weight)
2196 obj->Fill(fvals[0], fvals[1]);
2197 else if (!bprf && weight)
2199 ->Fill(fvals[0], fvals[1], fvals[3]);
2200 else if (bprf && !weight)
2201 ((TProfile2D*) obj)->Fill(fvals[0], fvals[1], fvals[2]);
2204 ->
Fill(fvals[0], fvals[1], fvals[2], fvals[3]);
2207 if (!bprf && !weight)
2208 ((TH3*) obj)->Fill(fvals[0], fvals[1], fvals[2]);
2209 else if (!bprf && weight)
2212 fvals[0], fvals[1], fvals[2], fvals[3]);
2213 else if (bprf && !weight)
2215 ->Fill(fvals[0], fvals[1], fvals[2], fvals[3]);
2217 Printf(
" WARNING: weighting NOT yet possible for TProfile3Ds !");
2260 void PairAnalysisHistos::FillValues(THnBase* obj,
const Double_t* values) {
2266 UInt_t value4 = obj->GetUniqueID();
2267 if (value4 == (UInt_t) PairAnalysisHistos::kNoAutoFill)
return;
2270 TList* list = obj->GetListOfFunctions();
2271 if (obj->IsA() == PairAnalysisHn::Class())
2272 list = (
static_cast<PairAnalysisHn*
>(obj))->GetListOfFunctions();
2273 Bool_t useFormulas = (list && list->Last());
2276 Bool_t weight = (value4 != kNoWeights);
2279 const Int_t dim = obj->GetNdimensions();
2283 for (Int_t it = 0; it < dim; it++) {
2285 TString formName = Form(
"axis%dFormula", it);
2286 TFormula* form =
dynamic_cast<TFormula*
>(list->FindObject(formName));
2289 fill[it] = values[obj->GetAxis(it)->GetUniqueID()];
2297 obj->Fill(fill, values[value4]);
2303 void PairAnalysisHistos::FillVarArray(TObject* obj, UInt_t* valType) {
2311 if (obj->InheritsFrom(TH1::Class())) {
2312 valType[0] = ((TH1*) obj)->GetXaxis()->GetUniqueID();
2313 valType[1] = ((TH1*) obj)->GetYaxis()->GetUniqueID();
2314 valType[2] = ((TH1*) obj)->GetZaxis()->GetUniqueID();
2318 }
else if (obj->InheritsFrom(THnBase::Class())) {
2319 for (Int_t it = 0; it < ((THn*) obj)->GetNdimensions(); it++)
2320 valType[it] = ((THn*) obj)->GetAxis(it)->GetUniqueID();
2322 valType[19] = obj->GetUniqueID();
2327 void PairAnalysisHistos::AdaptNameTitle(TH1* hist,
const char* histClass) {
2333 Int_t dim = hist->GetDimension();
2334 TString currentName =
"";
2335 TString currentTitle =
"";
2336 TString hclass = histClass;
2338 TObjArray* arr = hclass.Tokenize(
"_.");
2340 hclass = ((TObjString*) arr->At(0))->GetString();
2344 Bool_t bname = (currentName.IsNull());
2345 Bool_t btitle = (currentTitle.IsNull());
2346 Bool_t bprf = kFALSE;
2347 if (hist->IsA() == TProfile::Class() || hist->IsA() == TProfile2D::Class()
2348 || hist->IsA() == TProfile3D::Class())
2352 Double_t pmin = 0., pmax = 0.;
2353 TString option =
"", calcrange =
"";
2354 Bool_t bStdOpt = kTRUE;
2358 option = ((TProfile3D*) hist)->GetErrorOption();
2359 pmin = ((TProfile3D*) hist)->GetTmin();
2360 pmax = ((TProfile3D*) hist)->GetTmax();
2363 option = ((TProfile2D*) hist)->GetErrorOption();
2364 pmin = ((TProfile2D*) hist)->GetZmin();
2365 pmax = ((TProfile2D*) hist)->GetZmax();
2368 option = ((TProfile*) hist)->GetErrorOption();
2369 pmin = ((TProfile*) hist)->GetYmin();
2370 pmax = ((TProfile*) hist)->GetYmax();
2373 if (option.Contains(
"s", TString::kIgnoreCase)) bStdOpt = kFALSE;
2375 calcrange = Form(
"#cbar_{%+.*f}^{%+.*f}",
2382 UInt_t varx = hist->GetXaxis()->GetUniqueID();
2383 UInt_t vary = hist->GetYaxis()->GetUniqueID();
2384 UInt_t varz = hist->GetZaxis()->GetUniqueID();
2385 UInt_t varp = hist->GetUniqueID();
2386 Bool_t weight = (varp != kNoWeights);
2387 if (bprf && dim == 3) weight = kFALSE;
2397 TFormula* xform =
dynamic_cast<TFormula*
>(
2398 hist->GetListOfFunctions()->FindObject(
"xFormula"));
2399 TFormula* yform =
dynamic_cast<TFormula*
>(
2400 hist->GetListOfFunctions()->FindObject(
"yFormula"));
2401 TFormula* zform =
dynamic_cast<TFormula*
>(
2402 hist->GetListOfFunctions()->FindObject(
"zFormula"));
2403 TFormula* wform =
dynamic_cast<TFormula*
>(
2404 hist->GetListOfFunctions()->FindObject(
"wFormula"));
2406 hist->GetXaxis()->SetName(
2410 hist->GetYaxis()->SetName(
2414 hist->GetZaxis()->SetName(
2423 hist->GetXaxis()->SetTitle(
2427 hist->GetYaxis()->SetTitle(
2431 hist->GetZaxis()->SetTitle(
2435 if (bprf && dim < 3) {
2438 case 2: ax = hist->GetZaxis();
break;
2439 case 1: ax = hist->GetYaxis();
break;
2441 tit = ax->GetTitle();
2442 tit.Prepend((bStdOpt ?
"#LT" :
"RMS("));
2443 tit.Append((bStdOpt ?
"#GT" :
")"));
2445 tit.Append(calcrange.Data());
2446 ax->SetTitle(tit.Data());
2450 hist->GetXaxis()->GetTitle(),
2452 if (!xform) hist->GetXaxis()->SetTitle(tit.Data());
2454 hist->GetYaxis()->GetTitle(),
2456 if (!yform) hist->GetYaxis()->SetTitle(tit.Data());
2458 hist->GetZaxis()->GetTitle(),
2460 if (!zform) hist->GetZaxis()->SetTitle(tit.Data());
2464 case 1: hist->GetYaxis()->SetTitle(Form(
"%ss", hclass.Data()));
break;
2465 case 2: hist->GetZaxis()->SetTitle(Form(
"%ss", hclass.Data()));
break;
2470 TAxis* ax = hist->GetYaxis();
2471 if (dim == 2) ax = hist->GetZaxis();
2474 ax->SetTitle(Form(
"%s weighted %s", tit.Data(), ax->GetTitle()));
2478 TFormula* pform =
dynamic_cast<TFormula*
>(
2479 hist->GetListOfFunctions()->FindObject(
"pFormula"));
2480 if (bname)
switch (dim) {
2482 currentName += Form(
"%s_", hist->GetXaxis()->GetName());
2483 currentName += Form(
"%s_", hist->GetYaxis()->GetName());
2484 currentName += Form(
"%s", hist->GetZaxis()->GetName());
2486 currentName += Form(
"-%s%s",
2488 (bStdOpt ?
"avg" :
"rms"));
2493 (bStdOpt ?
"avg" :
"rms"));
2494 if (weight && !bprf)
2499 currentName += Form(
"%s_", hist->GetXaxis()->GetName());
2500 currentName += Form(
"%s", hist->GetYaxis()->GetName());
2502 currentName += Form(
2503 "-%s%s", hist->GetZaxis()->GetName(), (bStdOpt ?
"avg" :
"rms"));
2504 if (weight && !wform)
2507 else if (weight && wform)
2512 currentName += Form(
"%s", hist->GetXaxis()->GetName());
2514 currentName += Form(
2515 "-%s%s", hist->GetYaxis()->GetName(), (bStdOpt ?
"avg" :
"rms"));
2516 if (weight && !wform)
2519 else if (weight && wform)
2526 if (hclass.Contains(
"pair")) currentName.Prepend(
"p");
2527 hist->SetName(currentName.Data());
2533 void PairAnalysisHistos::AdaptNameTitle(THnBase* hist,
const char* histClass) {
2539 Int_t dim = hist->GetNdimensions();
2540 TString currentName =
"";
2541 TString currentTitle =
"";
2542 TString hclass = histClass;
2544 TObjArray* arr = hclass.Tokenize(
"_.");
2546 hclass = ((TObjString*) arr->At(0))->GetString();
2550 Bool_t bname = (currentName.IsNull());
2551 Bool_t btitle = (currentTitle.IsNull());
2553 TList* list = (
static_cast<PairAnalysisHn*
>(hist))->GetListOfFunctions();
2559 for (Int_t it = 0; it < dim; it++) {
2560 TString formName = Form(
"axis%dFormula", it);
2561 TFormula* form =
dynamic_cast<TFormula*
>(list->FindObject(formName));
2562 hist->GetAxis(it)->SetName(
2565 hist->GetAxis(it)->SetTitle(
2572 currentName = hist->GetName();
2573 if (hclass.Contains(
"pair")) currentName.Prepend(
"p");
2574 hist->SetName(currentName.Data());