57#include <TCollection.h>
75#include <TLegendEntry.h>
78#include <TObjString.h>
80#include <TProfile2D.h>
81#include <TProfile3D.h>
85#include <TVirtualPS.h>
98 PairAnalysisHistos::PairAnalysisHistos()
100 TNamed(
"PairAnalysisHistos",
"PairAnalysis Histogram Container")
105 , fReservedWords(new TString(
"Hit;Track;Pair"))
106 , fPrecision(Eprecision::kFloat)
111 fHistoList.SetOwner(kTRUE);
112 fHistoList.SetName(
"PairAnalysis_Histos");
118PairAnalysisHistos::PairAnalysisHistos(
const char* name,
const char* title)
125 , fReservedWords(new TString(
"Hit;Track;Pair"))
126 , fPrecision(Eprecision::kFloat)
131 fHistoList.SetOwner(kTRUE);
132 fHistoList.SetName(name);
138PairAnalysisHistos::~PairAnalysisHistos()
144 if (fUsedVars)
delete fUsedVars;
145 if (fList) fList->Clear();
146 if (fMetaData)
delete fMetaData;
147 delete fReservedWords;
151void PairAnalysisHistos::UserHistogram(
const char* histClass, Int_t ndim, TObjArray* limits, UInt_t* vars,
159 isOk &= (ndim < 21 && ndim > 3);
161 Warning(
"UserHistogram",
"Array sizes should be between 3 and 20. Not adding Histogram to '%s'.", histClass);
164 isOk &= (ndim == limits->GetEntriesFast());
169 for (Int_t iv = 0; iv < ndim; iv++)
171 name.Resize(name.Length() - 1);
173 isOk &= IsHistogramOk(histClass, name);
179 for (Int_t idim = 0; idim < ndim; idim++) {
180 TVectorD* vec = (TVectorD*) limits->At(idim);
181 bins[idim] = vec->GetNrows() - 1;
184 hist =
new THnD(name.Data(),
"", ndim, bins, 0x0, 0x0);
187 for (Int_t idim = 0; idim < ndim; idim++) {
188 TVectorD* vec = (TVectorD*) limits->At(idim);
189 hist->SetBinEdges(idim, vec->GetMatrixArray());
193 StoreVariables(hist, vars);
194 hist->SetUniqueID(valTypeW);
197 for (Int_t i = 0; i < ndim; i++)
198 fUsedVars->SetBitNumber(vars[i], kTRUE);
199 fUsedVars->SetBitNumber(valTypeW, kTRUE);
201 Bool_t isReserved = fReservedWords->Contains(histClass);
202 if (isReserved) UserHistogramReservedWords(histClass, hist);
204 UserHistogram(histClass, hist);
209void PairAnalysisHistos::AddSparse(
const char* histClass, Int_t ndim, TObjArray* limits, UInt_t* vars, UInt_t valTypeW)
216 isOk &= (ndim == limits->GetEntriesFast());
221 for (Int_t iv = 0; iv < ndim; iv++)
223 name.Resize(name.Length() - 1);
225 isOk &= IsHistogramOk(histClass, name);
232 for (Int_t idim = 0; idim < ndim; idim++) {
233 TVectorD* vec = (TVectorD*) limits->At(idim);
234 bins[idim] = vec->GetNrows() - 1;
241 for (Int_t idim = 0; idim < ndim; idim++) {
242 TVectorD* vec = (TVectorD*) limits->At(idim);
243 hist->SetBinEdges(idim, vec->GetMatrixArray());
247 StoreVariables(hist, vars);
248 hist->SetUniqueID(valTypeW);
251 for (Int_t i = 0; i < ndim; i++)
252 fUsedVars->SetBitNumber(vars[i], kTRUE);
253 fUsedVars->SetBitNumber(valTypeW, kTRUE);
255 Bool_t isReserved = fReservedWords->Contains(histClass);
256 if (isReserved) UserHistogramReservedWords(histClass, hist);
258 UserHistogram(histClass, hist);
263void PairAnalysisHistos::AddSparse(
const char* histClass, Int_t ndim, TObjArray* limits, TFormula** vars,
271 isOk &= (ndim == limits->GetEntriesFast());
276 for (Int_t iv = 0; iv < ndim; iv++)
278 name.Resize(name.Length() - 1);
279 name.ReplaceAll(
"f(",
"");
280 name.ReplaceAll(
")",
"");
284 isOk &= IsHistogramOk(histClass, name);
291 for (Int_t idim = 0; idim < ndim; idim++) {
292 TVectorD* vec = (TVectorD*) limits->At(idim);
293 bins[idim] = vec->GetNrows() - 1;
300 for (Int_t idim = 0; idim < ndim; idim++) {
301 TVectorD* vec = (TVectorD*) limits->At(idim);
302 hist->SetBinEdges(idim, vec->GetMatrixArray());
306 for (Int_t idim = 0; idim < ndim; idim++) {
307 vars[idim]->SetName(Form(
"axis%dFormula", idim));
313 hist->SetUniqueID(valTypeW);
316 AdaptNameTitle(hist, histClass);
320 fUsedVars->SetBitNumber(valTypeW, kTRUE);
322 Bool_t isReserved = fReservedWords->Contains(histClass);
323 if (isReserved) UserHistogramReservedWords(histClass, hist);
325 UserHistogram(histClass, hist);
330TString PairAnalysisHistos::UserHistogram(
const char* histClass, TObject* hist)
337 Bool_t isReserved = fReservedWords->Contains(histClass);
339 UserHistogramReservedWords(histClass, hist);
340 return hist->GetName();
348 UInt_t valType[20] = {0};
350 FillVarArray(hist, valType);
353 TString hclass = histClass;
354 if (hclass.Contains(
"MCtruth") && !(hist->IsA() == PairAnalysisHn::Class())) {
355 for (Int_t i = 0; i < 2; i++) {
367 fUsedVars->SetBitNumber(valType[i], kTRUE);
370 StoreVariables(hist, valType);
371 hist->SetUniqueID(valType[19]);
373 if (hist->InheritsFrom(TH1::Class())) {
374 TIter next(((TH1*) hist)->GetListOfFunctions());
376 while ((f =
dynamic_cast<TFormula*
>(next()))) {
377 for (Int_t i = 0; i < f->GetNpar(); i++) {
381 f->SetParameter(i, parMC);
383 fUsedVars->SetBitNumber(parMC, kTRUE);
387 AdaptNameTitle((TH1*) hist, histClass);
391 StoreVariables(hist, valType);
392 hist->SetUniqueID(valType[19]);
396 if (!IsHistogramOk(histClass, hist->GetName()))
return hist->GetName();
397 THashList* classTable = (THashList*) fHistoList.FindObject(histClass);
399 if (classTable) classTable->Add(hist);
400 return hist->GetName();
404TH1* PairAnalysisHistos::GetTHist(
const char* histClass,
const char* name,
const char* title,
405 const TVectorD*
const binsX,
const TVectorD*
const binsY,
const TVectorD*
const binsZ)
411 isOk &= IsHistogramOk(histClass, name);
412 isOk &= (binsX != 0x0);
413 if (!isOk)
return 0x0;
414 switch (fPrecision) {
415 case Eprecision::kFloat:
416 if (!binsY)
return (
new TH1F(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray()));
418 return (
new TH2F(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray(), binsY->GetNrows() - 1,
419 binsY->GetMatrixArray()));
421 return (
new TH3F(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray(), binsY->GetNrows() - 1,
422 binsY->GetMatrixArray(), binsZ->GetNrows() - 1, binsZ->GetMatrixArray()));
424 case Eprecision::kDouble:
425 if (!binsY)
return (
new TH1D(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray()));
427 return (
new TH2D(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray(), binsY->GetNrows() - 1,
428 binsY->GetMatrixArray()));
430 return (
new TH3D(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray(), binsY->GetNrows() - 1,
431 binsY->GetMatrixArray(), binsZ->GetNrows() - 1, binsZ->GetMatrixArray()));
433 default:
return 0x0;
break;
438TH1* PairAnalysisHistos::GetTProf(
const char* histClass,
const char* name,
const char* title,
439 const TVectorD*
const binsX,
const TVectorD*
const binsY,
const TVectorD*
const binsZ,
446 isOk &= IsHistogramOk(histClass, name);
447 isOk &= (binsX != 0x0);
448 if (!isOk)
return 0x0;
451 Double_t pmin = 0., pmax = 0.;
452 if (!option.IsNull()) {
453 TObjArray* arr = option.Tokenize(
";");
455 opt = ((TObjString*) arr->At(0))->GetString();
456 if (arr->GetEntriesFast() > 1) pmin = (((TObjString*) arr->At(1))->GetString()).Atof();
457 if (arr->GetEntriesFast() > 2) pmax = (((TObjString*) arr->At(2))->GetString()).Atof();
463 return (
new TProfile(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray(), pmin, pmax, opt.Data()));
465 prof =
new TProfile2D(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray(), binsY->GetNrows() - 1,
466 binsY->GetMatrixArray());
467 ((TProfile2D*) prof)->BuildOptions(pmin, pmax, opt.Data());
471 prof =
new TProfile3D(name, title, binsX->GetNrows() - 1, binsX->GetMatrixArray(), binsY->GetNrows() - 1,
472 binsY->GetMatrixArray(), binsZ->GetNrows() - 1, binsZ->GetMatrixArray());
473 ((TProfile3D*) prof)->BuildOptions(pmin, pmax, opt.Data());
479TFormula* PairAnalysisHistos::GetFormula(
const char* name,
const char* formula)
484 TFormula* form =
new TFormula(name, formula);
486 if (form->Compile())
return 0x0;
488 for (Int_t i = 0; i < form->GetNpar(); i++) {
490 fUsedVars->SetBitNumber((Int_t) form->GetParameter(i), kTRUE);
496void PairAnalysisHistos::AddClass(
const char* histClass)
502 TString hists(histClass);
503 TObjArray* arr = hists.Tokenize(
";");
506 while ((o = next())) {
507 if (fHistoList.FindObject(o->GetName())) {
508 Warning(
"AddClass",
"Cannot create class '%s' it already exists.", histClass);
511 if (fReservedWords->Contains(o->GetName())) {
512 Error(
"AddClass",
"Pair is a reserved word, please use another name");
515 THashList* table =
new THashList;
516 table->SetOwner(kTRUE);
517 table->SetName(o->GetName());
518 fHistoList.Add(table);
524void PairAnalysisHistos::FillClass(TString histClass,
const Double_t* values)
529 THashList* classTable = (THashList*) fHistoList.FindObject(histClass.Data());
535 TIter nextHist(classTable);
537 while ((obj = (TObject*) nextHist()))
538 FillValues(obj, values);
544void PairAnalysisHistos::UserHistogramReservedWords(
const char* histClass,
const TObject* hist)
549 TString title(hist->GetTitle());
551 TIter nextClass(&fHistoList);
553 while ((l =
static_cast<THashList*
>(nextClass()))) {
554 TString name(l->GetName());
555 if (name.Contains(histClass)) {
556 TObject*
h = hist->Clone();
559 if (
h->InheritsFrom(TH1::Class())) ((TH1*)
h)->SetTitle(Form(
"%s %s", title.Data(), l->GetName()));
561 ((THnBase*)
h)->SetTitle(Form(
"%s %s", title.Data(), l->GetName()));
563 UserHistogram(l->GetName(),
h);
572void PairAnalysisHistos::DumpToFile(
const char* file)
577 TFile f(file,
"recreate");
578 fHistoList.Write(fHistoList.GetName(), TObject::kSingleKey);
583TObject* PairAnalysisHistos::GetHist(
const char* histClass,
const char* name)
const
588 THashList* classTable = (THashList*) fHistoList.FindObject(histClass);
589 if (!classTable)
return 0x0;
590 return classTable->FindObject(name);
594TH1* PairAnalysisHistos::GetHistogram(
const char* histClass,
const char* name)
const
599 return ((TH1*) GetHist(histClass, name));
603TObject* PairAnalysisHistos::GetHist(
const char* cutClass,
const char* histClass,
const char* name)
const
610 if (!fList)
return 0x0;
611 THashList*
h =
dynamic_cast<THashList*
>(fList->FindObject(cutClass));
613 THashList* classTable =
dynamic_cast<THashList*
>(
h->FindObject(histClass));
614 if (!classTable)
return 0x0;
615 return classTable->FindObject(name);
619TH1* PairAnalysisHistos::GetHistogram(
const char* cutClass,
const char* histClass,
const char* name)
const
625 return ((TH1*) GetHist(cutClass, histClass, name));
629void PairAnalysisHistos::Draw(
const Option_t* option)
635 TString drawStr(option);
636 TObjArray* arr = drawStr.Tokenize(
";");
641 TObjString* ostr = 0x0;
645 while ((ostr = (TObjString*) nextOpt())) {
646 currentOpt = ostr->GetString();
647 currentOpt.Remove(TString::kBoth,
'\t');
648 currentOpt.Remove(TString::kBoth,
' ');
650 testOpt =
"classes=";
651 if (currentOpt.Contains(testOpt.Data())) { drawClasses = currentOpt(testOpt.Length(), currentOpt.Length()); }
662 Error(
"Draw",
"When writing to a file you have to create a canvas before opening "
666 c = gPad->GetCanvas();
671 TIter nextClass(&fHistoList);
672 THashList* classTable = 0;
674 while ((classTable = (THashList*) nextClass())) {
676 if (!drawClasses.IsNull() && !drawClasses.Contains(classTable->GetName()))
continue;
678 Int_t nPads = classTable->GetEntries();
679 Int_t nCols = (Int_t) TMath::Ceil(TMath::Sqrt(nPads));
680 Int_t nRows = (Int_t) TMath::Ceil((Double_t) nPads / (Double_t) nCols);
685 canvasName.Form(
"c%s_%s", GetName(), classTable->GetName());
686 c = (TCanvas*) gROOT->FindObject(canvasName.Data());
687 if (!c) c =
new TCanvas(canvasName.Data(), Form(
"%s: %s", GetName(), classTable->GetName()));
695 if (nPads > 1) c->Clear();
698 if (nCols > 1 || nRows > 1) c->Divide(nCols, nRows);
701 TIter nextHist(classTable);
704 while ((
h = (TH1*) nextHist())) {
706 if ((
h->InheritsFrom(TH2::Class()))) drawOpt =
"colz";
707 if (nCols > 1 || nRows > 1) c->cd(++iPad);
708 if (TMath::Abs(
h->GetXaxis()->GetBinWidth(1) -
h->GetXaxis()->GetBinWidth(2)) > 1e-10) gPad->SetLogx();
709 if (TMath::Abs(
h->GetYaxis()->GetBinWidth(1) -
h->GetYaxis()->GetBinWidth(2)) > 1e-10) gPad->SetLogy();
710 if (TMath::Abs(
h->GetZaxis()->GetBinWidth(1) -
h->GetZaxis()->GetBinWidth(2)) > 1e-10) gPad->SetLogz();
711 TString histOpt =
h->GetOption();
713 if (histOpt.Contains(
"logx")) gPad->SetLogx();
714 if (histOpt.Contains(
"logy")) gPad->SetLogy();
715 if (histOpt.Contains(
"logz")) gPad->SetLogz();
716 histOpt.ReplaceAll(
"logx",
"");
717 histOpt.ReplaceAll(
"logy",
"");
718 histOpt.ReplaceAll(
"logz",
"");
719 h->Draw(drawOpt.Data());
721 if (gVirtualPS) { c->Update(); }
727void PairAnalysisHistos::Print(
const Option_t* option)
const
732 TString optString(option);
734 if (optString.IsNull()) PrintStructure();
738void PairAnalysisHistos::PrintStructure()
const
744 TIter nextClass(&fHistoList);
745 THashList* classTable = 0;
746 while ((classTable = (THashList*) nextClass())) {
747 TIter nextHist(classTable);
749 Printf(
"+ %s\n", classTable->GetName());
750 while ((o = nextHist()))
751 Printf(
"| ->%s\n", o->GetName());
755 TIter nextCutClass(fList);
756 THashList* cutClass = 0x0;
757 while ((cutClass = (THashList*) nextCutClass())) {
758 TString cla = cutClass->GetName();
759 if (cla.Contains(
"QAcuts"))
continue;
760 Printf(
"+ %s\n", cutClass->GetName());
761 TIter nextClass(cutClass);
762 THashList* classTable = 0;
763 while ((classTable = (THashList*) nextClass())) {
764 TIter nextHist(classTable);
766 Printf(
"| + %s\n", classTable->GetName());
767 while ((o = nextHist()))
768 Printf(
"| | ->%s\n", o->GetName());
775void PairAnalysisHistos::SetHistogramList(THashList& list, Bool_t setOwner )
780 ResetHistogramList();
781 TString name(GetName());
783 SetName(list.GetName());
786 while ((o = next())) {
790 list.SetOwner(kFALSE);
791 fHistoList.SetOwner(kTRUE);
792 fHistoList.SetName(list.GetName());
795 fHistoList.SetOwner(kFALSE);
796 fHistoList.SetName(list.GetName());
801Bool_t PairAnalysisHistos::SetCutClass(
const char* cutClass)
807 if (!fList)
return kFALSE;
808 ResetHistogramList();
809 THashList*
h =
dynamic_cast<THashList*
>(fList->FindObject(cutClass));
811 Warning(
"SetCutClass",
"cutClass '%s' not found", cutClass);
814 SetHistogramList(*
h, kFALSE);
818Bool_t PairAnalysisHistos::IsHistogramOk(
const char* histClass,
const char* name)
823 Bool_t isReserved = fReservedWords->Contains(histClass);
824 if (!fHistoList.FindObject(histClass) && !isReserved) {
825 Warning(
"IsHistogramOk",
826 "Cannot create histogram. Class '%s' not defined. Please create it "
827 "using AddClass before.",
831 if (GetHist(histClass, name)) {
832 Warning(
"IsHistogramOk",
"Cannot create histogram '%s' in class '%s': It already exists!", name, histClass);
848void PairAnalysisHistos::ReadFromFile(
const char* file,
const char* task,
const char* config)
854 TIter nextKey(f.GetListOfKeys());
856 while ((key = (TKey*) nextKey())) {
857 TString name = key->GetName();
859 if (name.Contains(Form(
"PairAnalysisMetaData_%s", task))) {
861 fMetaData->SetMetaData(*
dynamic_cast<TList*
>(f.Get(key->GetName())), kFALSE);
864 if (!name.Contains(Form(
"PairAnalysisHistos_%s", task)))
continue;
865 if (!strlen(task) && !name.Contains(task))
continue;
866 TObject* o = f.Get(key->GetName());
867 TList* list =
dynamic_cast<TList*
>(o);
871 THashList* listCfg =
dynamic_cast<THashList*
>(list->FindObject(config));
872 if (!listCfg)
continue;
873 SetHistogramList(*listCfg);
882TObjArray* PairAnalysisHistos::DrawTaskSame(TString histName, TString opt, TString histClassDenom, TString taskDenom)
895 TObjArray* selections = histClassDenom.Tokenize(
":;,");
898 TString optString(opt);
899 Bool_t optGoff = optString.Contains(
"goff");
900 Bool_t optEff = optString.Contains(
"eff");
901 Bool_t optCutStep = optString.Contains(
"cutstep");
902 Bool_t optSelCfg = optString.Contains(
"selcfg");
903 opt.ReplaceAll(
"selcfg",
"");
904 fHistoList.SetOwner(kFALSE);
907 TObjArray* arr = NULL;
908 if (optGoff) Info(
"DrawTaskSame",
"graphics option off, collect an array");
914 arr =
new TObjArray();
916 arr->SetName(GetName());
917 arr->SetOwner(kFALSE);
921 TString legendname = GetName();
925 TObjArray* reservedWords = fReservedWords->Tokenize(
":;");
929 TString cutstepTask = fHistoList.GetName();
930 THashList* listCutStep =
dynamic_cast<THashList*
>(fList->FindObject(cutstepTask));
931 if (listCutStep) fList = listCutStep;
935 THashList* listDenom =
dynamic_cast<THashList*
>(fList->FindObject(taskDenom.Data()));
936 if (listDenom) opt +=
"div";
939 TIter nextCfg(fList);
940 THashList* listCfg = 0;
941 while ((listCfg =
static_cast<THashList*
>(nextCfg()))) {
943 TString lname = listCfg->GetName();
946 if (lname.Contains(
"QAcuts_"))
continue;
947 Info(
"DrawTaskSame",
" Task name %s ", lname.Data());
950 if (!optEff && listDenom && lname.EqualTo(taskDenom))
continue;
953 if (optSelCfg && selections->GetEntriesFast()) {
954 Bool_t pass = kFALSE;
955 for (Int_t is = 0; is < selections->GetEntriesFast(); is++) {
956 Bool_t testIgnore = kFALSE;
957 TString raw = ((TObjString*) selections->At(is))->GetString();
963 for (Int_t ir = 0; ir < reservedWords->GetEntriesFast(); ir++) {
964 testIgnore = raw.Contains(((TObjString*) reservedWords->At(ir))->GetString());
965 if (testIgnore)
break;
967 if (testIgnore)
continue;
970 srch.ReplaceAll(
"!",
"");
971 Bool_t optExclSel = !(srch.EqualTo(raw));
976 if (!(!lname.EqualTo(srch)) ^ (optExclSel)) pass = kTRUE;
978 if (lname.EqualTo(srch)) {
979 pass = !(!lname.EqualTo(srch)) ^ (optExclSel);
990 if (lname.EqualTo(legendname)) legendname =
"";
993 ResetHistogramList();
997 while ((o = next())) {
998 fHistoList.AddAt(o, idx++);
1003 SetName(listCfg->GetName());
1004 arr->AddAll(DrawSame(histName, (opt +
"task").Data(), histClassDenom, listDenom));
1008 if (optString.Contains(
"leg")) {
1010 legendname.ReplaceAll(
".",
"");
1011 TList* prim = gPad->GetListOfPrimitives();
1012 TLegend* leg = (TLegend*) prim->FindObject(
"TPave");
1014 TList* llist = leg->GetListOfPrimitives();
1015 Int_t nent = llist->GetEntries();
1016 for (Int_t il = 0; il < nent; il++) {
1017 TLegendEntry* lent =
static_cast<TLegendEntry*
>(llist->At(il));
1018 TString lst(lent->GetLabel());
1019 lst.ReplaceAll(legendname.Data(),
"");
1020 lent->SetLabel(lst.Data());
1023 if (!legendname.EqualTo(
"none")) leg->SetHeader(
"");
1025 leg->SetHeader(legendname.Data());
1031 if (selections)
delete selections;
1032 if (reservedWords)
delete reservedWords;
1033 if (!optGoff)
delete arr;
1039TObjArray* PairAnalysisHistos::DrawSame(TString histName, TString option, TString histClassDenom, THashList* listDenom)
1088 TString optString(option);
1089 optString.ToLower();
1090 printf(
"Plot hist: '%s' class-denom/sel: '%s' \t listDenom: '%s' \t options: "
1092 histName.Data(), histClassDenom.Data(), (listDenom ? listDenom->GetName() :
""), optString.Data());
1093 Bool_t optBack = optString.Contains(
"back");
1094 optString.ReplaceAll(
"back",
"");
1095 Bool_t optGoff = optString.Contains(
"goff");
1096 optString.ReplaceAll(
"goff",
"");
1097 Bool_t optTask = optString.Contains(
"task");
1098 optString.ReplaceAll(
"task",
"");
1099 Bool_t optCutStep = optString.Contains(
"cutstep");
1100 optString.ReplaceAll(
"cutstep",
"");
1102 Bool_t optDiv = optString.Contains(
"div");
1103 optString.ReplaceAll(
"div",
"");
1104 Bool_t optEff = optString.Contains(
"eff");
1105 optString.ReplaceAll(
"eff",
"");
1106 Bool_t optRatio = optString.Contains(
"ratio");
1107 optString.ReplaceAll(
"ratio",
"");
1108 Bool_t optOneOver = optString.Contains(
"oneover");
1109 optString.ReplaceAll(
"oneover",
"");
1111 Bool_t optNoMCtrue = optString.Contains(
"nomctrue");
1112 optString.ReplaceAll(
"nomctrue",
"");
1113 Bool_t optNoMC = optString.Contains(
"nomc");
1114 optString.ReplaceAll(
"nomc",
"");
1115 Bool_t optOnlyMCtrue = optString.Contains(
"onlymctrue");
1116 optString.ReplaceAll(
"onlymctrue",
"");
1117 Bool_t optOnlyMC = optString.Contains(
"onlymc");
1118 optString.ReplaceAll(
"onlymc",
"");
1119 Bool_t optSel = optString.Contains(
"sel");
1120 optString.ReplaceAll(
"sel",
"");
1122 Bool_t optCan = optString.Contains(
"can");
1123 optString.ReplaceAll(
"can",
"");
1124 Bool_t optLegFull = optString.Contains(
"legf");
1125 optString.ReplaceAll(
"legf",
"");
1126 Bool_t optLeg = optString.Contains(
"leg");
1127 optString.ReplaceAll(
"leg",
"");
1128 Bool_t optDet = optString.Contains(
"det");
1129 optString.ReplaceAll(
"det",
"");
1130 Bool_t optMeta = optString.Contains(
"meta");
1131 optString.ReplaceAll(
"meta",
"");
1132 Bool_t optWdth = optString.Contains(
"width");
1133 optString.ReplaceAll(
"width",
"");
1134 Bool_t optRbnStat = optString.Contains(
"rebinstat");
1135 optString.ReplaceAll(
"rebinstat",
"stat");
1136 Bool_t optRbn = optString.Contains(
"rebin");
1137 Bool_t optSmooth = optString.Contains(
"smooth");
1138 Bool_t optSclMax = optString.Contains(
"sclmax");
1139 optString.ReplaceAll(
"sclmax",
"");
1140 Bool_t optNormY = optString.Contains(
"normy");
1141 optString.ReplaceAll(
"normy",
"");
1142 Bool_t optNorm = optString.Contains(
"norm");
1143 optString.ReplaceAll(
"norm",
"");
1144 Bool_t optCumR = optString.Contains(
"cumr");
1145 optString.ReplaceAll(
"cumr",
"");
1146 Bool_t optCum = optString.Contains(
"cum");
1147 optString.ReplaceAll(
"cum",
"");
1148 Bool_t optEvt = optString.Contains(
"events");
1149 optString.ReplaceAll(
"events",
"");
1150 Bool_t optStack = optString.Contains(
"stack");
1151 optString.ReplaceAll(
"stack",
"");
1152 Bool_t optRstSty = optString.Contains(
"rststy");
1153 optString.ReplaceAll(
"rststy",
"");
1154 Bool_t optSlicesY = optString.Contains(
"slicesy");
1155 optString.ReplaceAll(
"slicesy",
"");
1157 Bool_t optMeanX = optString.Contains(
"meanx");
1158 optString.ReplaceAll(
"meanx",
"");
1159 Bool_t optRmsX = optString.Contains(
"rmsx");
1160 optString.ReplaceAll(
"rmsx",
"");
1161 Bool_t optMeanY = optString.Contains(
"meany");
1162 optString.ReplaceAll(
"meany",
"");
1163 Bool_t optRmsY = optString.Contains(
"rmsy");
1164 optString.ReplaceAll(
"rmsy",
"");
1165 Bool_t optGeant = optString.Contains(
"geant");
1166 optString.ReplaceAll(
"geant",
"");
1167 Bool_t optPdgClean = optString.Contains(
"pdgc");
1168 optString.ReplaceAll(
"pdgc",
"");
1169 Bool_t optPdg = optString.Contains(
"pdg");
1170 optString.ReplaceAll(
"pdg",
"");
1175 TString rebin(optString(optString.Index(
"rebin", 5, 0, TString::kExact) + 5));
1176 if (rebin.IsDigit()) {
1178 optString.ReplaceAll(rebin,
"");
1180 optString.ReplaceAll(
"rebin",
"");
1184 TArrayD* limits = NULL;
1185 Double_t stat = 0.8;
1187 TString rebin(optString(optString.Index(
"stat", 4, 0, TString::kExact) + 4, 4));
1188 if (!rebin.IsFloat()) rebin = optString(optString.Index(
"stat", 4, 0, TString::kExact) + 4, 3);
1189 if (rebin.IsFloat()) {
1190 stat = rebin.Atof();
1192 optString.ReplaceAll(rebin,
"");
1194 optString.ReplaceAll(
"stat",
"");
1200 TString smooth(optString(optString.Index(
"smooth", 6, 0, TString::kExact) + 6));
1201 if (smooth.IsDigit()) {
1202 smth = smooth.Atoi();
1203 optString.ReplaceAll(smooth,
"");
1205 optString.ReplaceAll(
"smooth",
"");
1209 if (optLegFull) optLeg = kTRUE;
1210 if (optCumR) optCum = kTRUE;
1214 TObjArray* selections = (optSel ? histClassDenom.Tokenize(
":;,") : NULL);
1215 if (optSel) histClassDenom =
"";
1218 TObjArray* arr = 0x0;
1220 Info(
"DrawSame",
"graphics option off, collect an array");
1222 arr = (TObjArray*) gROOT->FindObject(GetName());
1224 Warning(
"DrawSame",
"Clear existing array %s", GetName());
1229 arr =
new TObjArray();
1231 arr->SetName(GetName());
1232 arr->SetOwner(kFALSE);
1244 c = (TCanvas*) gROOT->FindObject(Form(
"c%s", histName.Data()));
1245 if (!c) { c =
new TCanvas(Form(
"c%s", histName.Data()), Form(
"All '%s' histograms", histName.Data())); }
1254 TList* prim = (gPad ? gPad->GetListOfPrimitives() : 0x0);
1257 for (Int_t io = 0; io < (prim ? prim->GetSize() : 0); io++) {
1259 if (obj->InheritsFrom(TH1::Class()) && obj != prim->At(io + 1)) nobj++;
1260 if (obj->InheritsFrom(THStack::Class()) && obj != prim->At(io + 1)) nobj++;
1261 if (nobj == 1) hFirst = (TH1*) obj;
1266 if ((optLeg && !nobj)) {
1267 leg =
new TLegend(0. + gPad->GetLeftMargin() + gStyle->GetTickLength(
"Y"),
1268 0. + gPad->GetBottomMargin() + gStyle->GetTickLength(
"X"),
1269 1. - gPad->GetRightMargin() + gStyle->GetTickLength(
"Y"),
1270 1. - gPad->GetTopMargin() + gStyle->GetTickLength(
"X"), GetName(),
"nbNDC");
1271 if (optTask && !optCutStep) leg->SetHeader(
"");
1274 leg = (TLegend*) prim->FindObject(
"TPave");
1282 Info(
"DrawSame",
"Basics: nobj: %d \t leg: %p", nobj, leg);
1285 if (optString.Contains(
"logx")) gPad->SetLogx();
1286 if (optString.Contains(
"logy")) gPad->SetLogy();
1287 if (optString.Contains(
"logz")) gPad->SetLogz();
1288 optString.ReplaceAll(
"logx",
"");
1289 optString.ReplaceAll(
"logy",
"");
1290 optString.ReplaceAll(
"logz",
"");
1294 if (fMetaData && optEvt) fMetaData->GetMeta(
"events", &events);
1297 if (optTask && nobj) i = nobj;
1298 TListIter next(&fHistoList, (optBack ? kIterBackward : kIterForward));
1300 THashList* classTable = 0;
1303 while ((classTable = (THashList*) next())) {
1304 TString histClass = classTable->GetName();
1306 Int_t ndel = histClass.CountChar(
'_');
1308 "Search for hist: '%s' class-denom: '%s' select: '%s' \t ndel: %d \t "
1310 histName.Data(), histClassDenom.Data(), select.Data(), ndel, histClass.Data());
1313 if ((optNoMC && ndel > 0) || (optEff && ndel < 1) || (optNoMCtrue && histClass.Contains(
"_MCtruth"))
1314 || (optOnlyMC && ndel < 1) || (optOnlyMCtrue && ndel < 2))
1318 if (optSel && selections->GetEntriesFast()) {
1319 Bool_t pass = kFALSE;
1320 for (Int_t is = 0; is < selections->GetEntriesFast(); is++) {
1321 TString raw = ((TObjString*) selections->At(is))->GetString();
1323 srch.ReplaceAll(
"!",
"");
1324 Bool_t optExclSel = !(srch.EqualTo(raw));
1326 if (!(!histClass.Contains(srch, TString::kIgnoreCase)) ^ (optExclSel)) pass = kTRUE;
1328 if (histClass.EqualTo(srch, TString::kIgnoreCase)) {
1329 pass = !(!histClass.EqualTo(srch, TString::kIgnoreCase)) ^ (optExclSel);
1333 if (!pass)
continue;
1339 TH1*
h = (TH1*) classTable->FindObject(histName.Data());
1340 if (!
h && !optNoMC && !optNoMCtrue) {
1342 TString histdenomMC = histName +
"MC";
1343 h = (TH1*) classTable->FindObject(histdenomMC.Data());
1346 if (
h->GetEntries() < 1.)
continue;
1349 if (optEff && !histClass.Contains(
"_MCtruth")) histClassDenom = histClass +
"_MCtruth";
1350 Info(
"DrawSame",
" Hist found in histClass '%s' (search for denom '%s') ", histClass.Data(), histClassDenom.Data());
1353 if ((optEff || optRatio)
1354 && (histClass.EqualTo(histClassDenom) || !fHistoList.FindObject(histClassDenom.Data())))
1356 else if (!histClassDenom.IsNull())
1357 Info(
"DrawSame",
" Denom histClass '%s' found ", histClassDenom.Data());
1360 if (i == 0 && !hFirst) hFirst =
h;
1363 if (optRbn || optRbnStat)
1364 Info(
"DrawSame",
" Rebin by %d, to <%.1f%% stat. uncertainty per bin", (optRbn ? rbn : 0),
1365 (optRbnStat ? stat * 100 : 0));
1366 if (optNormY || optNorm || optEvt)
1367 Info(
"DrawSame",
" Normalize in y-axis,2D's only(%d), by int.(%d), by #events(%d)", optNormY, optNorm, optEvt);
1368 if (optSclMax) Info(
"DrawSame",
" Scale to maximum(%d)", optSclMax);
1371 " Cumulate sum of bins along x-axis, 1D's left-to-right(%d), "
1372 "right-to-left(%d)",
1377 if (optRbn &&
h->InheritsFrom(TH2::Class()))
h = ((TH2*)
h)->RebinX(rbn,
h->GetName());
1380 if (optNormY &&
h->GetDimension() == 2 && !(
h->GetSumOfWeights() == 0) && !optCum)
1382 if (optRbnStat &&
h->GetDimension() == 1) {
1385 h =
h->Rebin(limits->GetSize() - 1,
h->GetName(), limits->GetArray());
1386 h->Scale(1.,
"width");
1390 if (optSmooth)
h->Smooth(smth);
1393 TString ytitle =
h->GetYaxis()->GetTitle();
1394 TString ztitle =
h->GetZaxis()->GetTitle();
1395 if (ytitle.Contains(
"{evt}")) optEvt = kFALSE;
1397 if (optNorm && !(
h->GetSumOfWeights() == 0) && !optCum)
1398 h =
h->DrawNormalized(i > 0 ? (optString +
"same").Data() : optString.Data());
1399 if (optEvt)
h->Scale(1. / events);
1400 if (optSclMax)
h->Scale(1. /
h->GetBinContent(
h->GetMaximumBin()));
1403 switch (
h->GetDimension()) {
1405 if (optEvt)
h->SetYTitle((ytitle +
"/N_{evt}").Data());
1406 if (optNorm)
h->SetYTitle((ytitle.Append(
" (normalized)")).Data());
1407 if (optCum)
h->SetYTitle((ytitle.Prepend(
"cumulated ")).Data());
1408 if (optRatio)
h->SetYTitle(
"ratio");
1409 if (optDiv)
h->SetYTitle(
"ratio");
1410 if (optEff)
h->SetYTitle(
"acceptance #times efficiency");
1411 if (optSclMax)
h->SetYTitle((ytitle +
"/N_{max}").Data());
1414 if (optEvt)
h->SetZTitle((ztitle +
"/N_{evt}").Data());
1416 if (optNorm)
h->SetZTitle((ztitle.Prepend(
"normalized ")).Data());
1417 if (optRatio)
h->SetZTitle(
"ratio");
1418 if (optDiv)
h->SetZTitle(
"ratio");
1419 if (optEff)
h->SetZTitle(
"acceptance #times efficiency");
1420 if (optSclMax)
h->SetZTitle((ztitle +
"/N_{max}").Data());
1425 if ((optEff || optRatio) && !optNorm && !optEvt && !optTask) {
1426 Info(
"DrawSame",
" Calculate '%s' w/o normalisation and within the same task", (optEff ?
"efficiency" :
"ratio"));
1428 THashList* clDenom = (THashList*) fHistoList.FindObject(histClassDenom.Data());
1429 TH1* hMC = (TH1*)
h->Clone();
1430 TString histdenomMC = UserHistogram(histClassDenom.Data(), hMC);
1431 TH1* hdenom = (TH1*) clDenom->FindObject(histdenomMC.Data());
1433 Error(
"DrawSame",
"Denominator object not found");
1436 Info(
"DrawSame",
" Divide %s(#=%.3e) by %s(#=%.3e)",
h->GetName(),
h->GetEntries(), hdenom->GetName(),
1437 hdenom->GetEntries());
1441 if (optRbnStat && (optEff || !(i % 10))) {
1442 hdenom = hdenom->Rebin(limits->GetSize() - 1, hdenom->GetName(), limits->GetArray());
1443 hdenom->Scale(1.,
"width");
1445 if (optRbn && (optEff || !(i % 10))) hdenom->RebinX(rbn);
1446 if (optEvt && (optEff || !(i % 10))) hdenom->Scale(1. / events);
1447 if (!hdenom || !
h->Divide(hdenom)) {
1448 Warning(
"DrawSame(eff/ratio)",
"Division failed!!!!");
1452 else if (optTask && (optDiv || optEff || optRatio)) {
1453 Info(
"DrawSame",
" Calculate '%s' using different tasks",
1454 (optEff ?
"efficiency" : (optRatio ?
"ratio" :
"divison")));
1458 if (optEff || optRatio) {
1459 THashList* clDenom = (THashList*) fHistoList.FindObject(histClassDenom.Data());
1460 TH1* hMC = (TH1*)
h->Clone();
1461 TString histdenomMC = UserHistogram(histClassDenom.Data(), hMC);
1465 if (clDenom) { hdenom = (TH1*) clDenom->FindObject(histdenomMC.Data()); }
1468 THashList* clTaskDen = (THashList*) listDenom->FindObject(histClassDenom.Data());
1471 htden = (TH1*) clTaskDen->FindObject(histdenomMC.Data());
1473 "calculate eff/ratio using task-denom: '%s' class-denom: '%s' "
1475 listDenom->GetName(), histClassDenom.Data(), histdenomMC.Data());
1477 if (htden) hdenom = 0x0;
1486 if (optDiv && !optEff) {
1487 Info(
"DrawSame",
" Search for '%s' in task '%s'", histClass.Data(), listDenom->GetName());
1488 THashList* clTaskNom = (THashList*) listDenom->FindObject(histClass.Data());
1489 if (!clTaskNom)
continue;
1490 htnom = (TH1*) clTaskNom->FindObject(histName.Data());
1491 if (!htnom)
continue;
1494 if (hdenom) hdenom->Sumw2();
1495 if (htden) htden->Sumw2();
1496 if (htnom) htnom->Sumw2();
1499 Int_t nbinsh = (
h ?
h->GetNbinsX() : -1);
1500 Int_t nbinsd = (hdenom ? hdenom->GetNbinsX() : -2);
1501 Int_t nbinstd = (htden ? htden->GetNbinsX() : -3);
1502 Int_t nbinstn = (htnom ? htnom->GetNbinsX() : -4);
1506 if (hdenom && nbinsd > nbinsh) hdenom->RebinX(rbn);
1507 if (htden && nbinstd > nbinsh) htden->RebinX(rbn);
1508 if (htnom && nbinstn > nbinsh) htnom->RebinX(rbn);
1511 if (hdenom && nbinsd > nbinsh) {
1512 hdenom = hdenom->Rebin(limits->GetSize() - 1, hdenom->GetName(), limits->GetArray());
1513 hdenom->Scale(1.,
"width");
1515 if (htden && nbinstd > nbinsh) {
1516 htden = htden->Rebin(limits->GetSize() - 1, htden->GetName(), limits->GetArray());
1517 htden->Scale(1.,
"width");
1519 if (htnom && nbinstn > nbinsh) {
1520 htnom = htnom->Rebin(limits->GetSize() - 1, htnom->GetName(), limits->GetArray());
1521 htnom->Scale(1.,
"width");
1526 if (hdenom) hdenom->Scale(1. / events);
1527 if (htden) htden->Scale(1. / events);
1528 if (htnom) htnom->Scale(1. / events);
1532 " Use nominator (%p,#=%.3e) and denominator 'same task & different "
1533 "class'(%p,#=%.3e), 'certain task & different class'(%p,#=%.3e), "
1534 "'certain task & same class'(%p,#=%.3e)",
1535 h,
h->GetEntries(), hdenom, (hdenom ? hdenom->GetEntries() : 0), htden, (htden ? htden->GetEntries() : 0),
1536 htnom, (htnom ? htnom->GetEntries() : 0));
1542 if (hdenom && !
h->Divide(hdenom)) {
1543 Warning(
"DrawSame(eff/ratio)",
"h & denom division failed!!!!");
1546 else if (htden && htnom && !i && !htnom->Divide(htden)) {
1547 Warning(
"DrawSame(eff/ratio)",
"task-nom/task-denom division failed!!!!");
1550 else if (optDiv && htnom && !
h->Divide(htnom)) {
1551 Warning(
"DrawSame(eff/ratio)",
"h & task-nom division failed!!!!");
1554 else if (htden && !
h->Divide(htden)) {
1555 Warning(
"DrawSame(eff/ratio)",
"h & task-denom division failed!!!!");
1561 if (optWdth && !optRbnStat)
h->Scale(1.,
"width");
1566 Info(
"DrawSame",
" Scale by 1/content");
1567 TH1* hOne = (TH1*)
h->Clone(
"one");
1568 hOne->Reset(
"ICSE");
1569 for (Int_t ib = 0; ib < (
h->GetNbinsX() + 2) * (
h->GetNbinsY() + 2) * (
h->GetNbinsZ() + 2); ib++)
1570 hOne->SetBinContent(ib, 1.);
1571 if (hOne->Divide(
h))
h = hOne;
1576 Info(
"DrawSame",
" Set GEANT bin labels");
1581 if (optPdg || optPdgClean) {
1582 Info(
"DrawSame",
" Set PDG bin labels");
1588 if (
h->GetLineColor() == kBlack && !optString.Contains(
"col")) {
1589 h->UseCurrentStyle();
1593 if (optString.Contains(
"scat"))
h->SetMarkerStyle(kDot);
1594 if (optString.Contains(
"e"))
h->SetLineStyle(kSolid);
1599 h->SetTitle(histClass.Data());
1604 if (optTask)
h->SetTitle(Form(
"%s %s", GetName(),
h->GetTitle()));
1607 else if (optStack) {
1608 if (!hs) hs =
new THStack(
"hs", Form(
";%s;%s",
h->GetXaxis()->GetTitle(),
h->GetYaxis()->GetTitle()));
1612 optString.ReplaceAll(
" ",
"");
1613 Info(
"DrawSame",
" Draw object with options: '%s'", optString.Data());
1615 if (!optSlicesY) {
h->Draw(
h != hFirst ? (optString +
"same").Data() : optString.Data()); }
1616 else if (
h->GetDimension() == 2) {
1618 for (Int_t bin = 1; bin <
h->GetNbinsX(); bin++) {
1619 TH1* hp = ((TH2*)
h)->ProjectionY(Form(
"%s_%d",
h->GetName(), bin), bin, bin,
"e");
1621 Long64_t nentries = Long64_t(hp->GetEntries());
1622 if (nentries == 0) {
1627 if (optRbn) hp->Rebin(rbn);
1631 hp = hp->Rebin(limits->GetSize() - 1, hp->GetName(), limits->GetArray());
1632 hp->Scale(1.,
"width");
1635 if (optSmooth) hp->Smooth(smth);
1636 hp->Draw(hFirst ? (optString +
"same").Data() : optString.Data());
1643 if (
h &&
h->GetEntries() > 0.) {
1645 TString ratioName = histClassDenom;
1646 TString divName = (listDenom ? listDenom->GetName() :
"");
1647 if (optEff) divName += (listDenom ?
"(MC)" :
"");
1650 TObjArray* reservedWords = fReservedWords->Tokenize(
":;");
1651 for (Int_t ir = 0; ir < reservedWords->GetEntriesFast(); ir++) {
1653 histClass.ReplaceAll(((TObjString*) reservedWords->At(ir))->GetString(),
"");
1654 ratioName.ReplaceAll(((TObjString*) reservedWords->At(ir))->GetString(),
"");
1655 divName.ReplaceAll(((TObjString*) reservedWords->At(ir))->GetString(),
"");
1662 if (leg && (rpl.EqualTo(leg->GetHeader()) || src.EqualTo(leg->GetHeader()))) rpl =
"";
1663 histClass.ReplaceAll(src, rpl);
1664 ratioName.ReplaceAll(src, rpl);
1665 divName.ReplaceAll(src, rpl);
1671 histClass.ReplaceAll(
"MCtruth",
"MC");
1672 ratioName.ReplaceAll(
"MCtruth",
"MC");
1673 divName.ReplaceAll(
"MCtruth",
"MC");
1682 histClass.ReplaceAll(
"_{Dalitz}",
"#{Dalitz}");
1683 ratioName.ReplaceAll(
"_{Dalitz}",
"#{Dalitz}");
1684 divName.ReplaceAll(
"_{Dalitz}",
"#{Dalitz}");
1685 histClass.ReplaceAll(
"_{S}",
"#{S}");
1686 ratioName.ReplaceAll(
"_{S}",
"#{S}");
1687 divName.ReplaceAll(
"_{S}",
"#{S}");
1689 histClass.ReplaceAll(
"_",
" ");
1690 ratioName.ReplaceAll(
"_",
" ");
1691 divName.ReplaceAll(
"_",
" ");
1692 histClass.ReplaceAll(
".",
"");
1693 ratioName.ReplaceAll(
".",
"");
1694 divName.ReplaceAll(
".",
"");
1696 histClass.ReplaceAll(
"#{Dalitz}",
"_{Dalitz}");
1697 ratioName.ReplaceAll(
"#{Dalitz}",
"_{Dalitz}");
1698 divName.ReplaceAll(
"#{Dalitz}",
"_{Dalitz}");
1699 histClass.ReplaceAll(
"#{S}",
"_{S}");
1700 ratioName.ReplaceAll(
"#{S}",
"_{S}");
1701 divName.ReplaceAll(
"#{S}",
"_{S}");
1703 histClass.Remove(TString::kBoth,
' ');
1704 ratioName.Remove(TString::kBoth,
' ');
1705 divName.Remove(TString::kBoth,
' ');
1708 if (optRatio) histClass +=
"/" + ratioName;
1711 delete reservedWords;
1714 TString legOpt = optString +
"L";
1715 legOpt.ReplaceAll(
"hist",
"");
1716 legOpt.ReplaceAll(
"scat",
"");
1717 if (legOpt.Contains(
"col")) legOpt =
"";
1718 legOpt.ReplaceAll(
"z",
"");
1719 legOpt.ReplaceAll(
"e",
"");
1720 if (optTask) histClass.Prepend(Form(
"%s ", GetName()));
1721 if ((optTask && optCutStep && i) || (optStack && (i - nobj))) histClass.Prepend(
"+");
1722 if (optDiv && !optOneOver) histClass.ReplaceAll(GetName(), Form(
"%s/%s", GetName(), divName.Data()));
1723 if (optDiv && optOneOver) histClass.Prepend(Form(
"%s/", divName.Data()));
1730 if (optMeanX) histClass += Form(
" #LTx#GT=%.1e",
h->GetMean());
1731 if (optRmsX) histClass += Form(
" RMS(x)=%.1e",
h->GetRMS());
1732 if (optMeanY) histClass += Form(
" #LTy#GT=%.2e",
h->GetMean(2));
1733 if (optRmsY) histClass += Form(
" RMS(y)=%.2e",
h->GetRMS(2));
1734 histClass.ReplaceAll(
"e+00",
"");
1736 if (optLeg && leg ) leg->AddEntry(
h, histClass.Data(), legOpt.Data());
1740 else if (nobj && leg)
1741 leg->AddEntry(hFirst,
"",
"");
1748 if (limits)
delete limits;
1753 optString.ReplaceAll(
" ",
"");
1754 Info(
"DrawSame",
" Draw stacked object with options: '%s'", optString.Data());
1755 hs->Draw(nobj > 0 ? (optString +
"same").Data() : optString.Data());
1762 if (!nobj) leg->Draw();
1767 Double_t max = -1e10;
1768 Double_t min = +1e10;
1769 TListIter nextObj(gPad->GetListOfPrimitives(), kIterBackward);
1771 while ((obj = nextObj())) {
1772 if (obj->InheritsFrom(TH1::Class())) {
1773 TH1* h1 =
static_cast<TH1*
>(obj);
1776 Double_t tmpmax = max * (gPad->GetLogy() ? 5. : 1.1);
1777 if (optEff) tmpmax = 1.1;
1778 h1->SetMaximum(tmpmax);
1781 if (gPad->GetLogy() && objmin < 0.) objmin = 0.5;
1782 min = TMath::Min(min, objmin);
1783 Double_t tmpmin = min * (min < 0. ? 1.1 : 0.9);
1785 h1->SetMinimum(tmpmin);
1800 && (tmpmax / (tmpmin > 0. ? tmpmin : 1.) > TMath::Power(10., TGaxis::GetMaxDigits())
1801 || tmpmin < TMath::Power(10., -TGaxis::GetMaxDigits())
1802 || tmpmin > TMath::Power(10., +TGaxis::GetMaxDigits()))) {
1804 h1->GetYaxis()->SetMoreLogLabels(kFALSE);
1805 h1->GetYaxis()->SetNoExponent(kFALSE);
1807 Double_t tmpXmin = h1->GetXaxis()->GetXmin();
1809 && h1->GetXaxis()->GetXmax() / (TMath::Abs(tmpXmin) < 1.e-10 ? 1. : tmpXmin)
1810 > TMath::Power(10., TGaxis::GetMaxDigits())) {
1813 h1->GetXaxis()->SetMoreLogLabels(kFALSE);
1814 h1->GetXaxis()->SetNoExponent(kFALSE);
1819 if (!nobj && optMeta && fMetaData && !gPad->GetPrimitive(
"meta")) { fMetaData->DrawSame(
""); }
1823 if (!optTask && 0) {
1824 if (leg) leg->DrawClone();
1827 while ((obj = nextObj())) {
1828 if (obj->InheritsFrom(TLegend::Class())) {
1829 if (ileg > 0)
delete obj;
1844 if (selections)
delete selections;
1850void PairAnalysisHistos::SetReservedWords(
const char* words)
1856 (*fReservedWords) = words;
1860void PairAnalysisHistos::StoreVariables(TObject* obj, UInt_t valType[20])
1866 if (obj->InheritsFrom(TH1::Class())) StoreVariables(
static_cast<TH1*
>(obj), valType);
1867 else if (obj->InheritsFrom(THnBase::Class()))
1868 StoreVariables(
static_cast<THnBase*
>(obj), valType);
1875void PairAnalysisHistos::StoreVariables(TH1* obj, UInt_t valType[20])
1881 Int_t dim = obj->GetDimension();
1884 if (obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class()) {
1888 if (dim >= 1) { obj->GetXaxis()->SetUniqueID(valType[0]); }
1889 if (dim >= 2) { obj->GetYaxis()->SetUniqueID(valType[1]); }
1890 if (dim >= 3) { obj->GetZaxis()->SetUniqueID(valType[2]); }
1892 if (dim >= 4) { obj->SetUniqueID(valType[3]); }
1898void PairAnalysisHistos::StoreVariables(THnBase* obj, UInt_t valType[20])
1907 TList* list = obj->GetListOfFunctions();
1908 if (obj->IsA() == PairAnalysisHn::Class()) list = (
static_cast<PairAnalysisHn*
>(obj))->GetListOfFunctions();
1909 if (list && list->Last())
return;
1911 Int_t dim = obj->GetNdimensions();
1913 for (Int_t it = 0; it < dim; it++) {
1914 obj->GetAxis(it)->SetUniqueID(valType[it]);
1923void PairAnalysisHistos::FillValues(TObject* obj,
const Double_t* values)
1929 if (obj->InheritsFrom(TH1::Class())) FillValues(
static_cast<TH1*
>(obj), values);
1930 else if (obj->InheritsFrom(THnBase::Class()))
1931 FillValues(
static_cast<THnBase*
>(obj), values);
1937void PairAnalysisHistos::FillValues(TH1* obj,
const Double_t* values)
1943 Int_t dim = obj->GetDimension();
1944 Bool_t bprf = kFALSE;
1946 UInt_t valueTypes = obj->GetUniqueID();
1947 if (valueTypes ==
static_cast<UInt_t
>(PairAnalysisHistos::Eoption::kNoAutoFill))
return;
1948 Bool_t weight = (valueTypes !=
static_cast<UInt_t
>(Eoption::kNoWeights));
1951 if (obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class())
1955 if (obj->IsA() == TProfile3D::Class()) weight = kFALSE;
1958 TList* list = obj->GetListOfFunctions();
1959 TFormula* xform =
dynamic_cast<TFormula*
>(list->FindObject(
"xFormula"));
1960 TFormula* yform =
dynamic_cast<TFormula*
>(list->FindObject(
"yFormula"));
1961 TFormula* zform =
dynamic_cast<TFormula*
>(list->FindObject(
"zFormula"));
1962 TFormula* pform =
dynamic_cast<TFormula*
>(list->FindObject(
"pFormula"));
1963 TFormula* wform =
dynamic_cast<TFormula*
>(list->FindObject(
"wFormula"));
1967 UInt_t value1 = obj->GetXaxis()->GetUniqueID();
1968 UInt_t value2 = obj->GetYaxis()->GetUniqueID();
1969 UInt_t value3 = obj->GetZaxis()->GetUniqueID();
1970 UInt_t value4 = obj->GetUniqueID();
1972 Double_t fvals[4] = {values[value1], values[value2], values[value3], values[value4]};
1991 if (!bprf && !weight) obj->Fill(fvals[0]);
1992 else if (!bprf && weight)
1993 obj->Fill(fvals[0], fvals[3]);
1994 else if (bprf && !weight)
1995 ((TProfile*) obj)->Fill(fvals[0], fvals[1]);
1997 ((TProfile*) obj)->Fill(fvals[0], fvals[1], fvals[3]);
2000 if (!bprf && !weight) obj->Fill(fvals[0], fvals[1]);
2001 else if (!bprf && weight)
2002 ((TH2*) obj)->Fill(fvals[0], fvals[1], fvals[3]);
2003 else if (bprf && !weight)
2004 ((TProfile2D*) obj)->Fill(fvals[0], fvals[1], fvals[2]);
2006 ((TProfile2D*) obj)->Fill(fvals[0], fvals[1], fvals[2], fvals[3]);
2009 if (!bprf && !weight) ((TH3*) obj)->Fill(fvals[0], fvals[1], fvals[2]);
2010 else if (!bprf && weight)
2011 ((TH3*) obj)->Fill(fvals[0], fvals[1], fvals[2], fvals[3]);
2012 else if (bprf && !weight)
2013 ((TProfile3D*) obj)->Fill(fvals[0], fvals[1], fvals[2], fvals[3]);
2015 Printf(
" WARNING: weighting NOT yet possible for TProfile3Ds !");
2058void PairAnalysisHistos::FillValues(THnBase* obj,
const Double_t* values)
2065 UInt_t value4 = obj->GetUniqueID();
2066 if (value4 ==
static_cast<UInt_t
>(PairAnalysisHistos::Eoption::kNoAutoFill))
return;
2069 TList* list = obj->GetListOfFunctions();
2070 if (obj->IsA() == PairAnalysisHn::Class()) list = (
static_cast<PairAnalysisHn*
>(obj))->GetListOfFunctions();
2071 Bool_t useFormulas = (list && list->Last());
2074 Bool_t weight = (value4 !=
static_cast<UInt_t
>(Eoption::kNoWeights));
2077 const Int_t dim = obj->GetNdimensions();
2081 for (Int_t it = 0; it < dim; it++) {
2083 TString formName = Form(
"axis%dFormula", it);
2084 TFormula* form =
dynamic_cast<TFormula*
>(list->FindObject(formName));
2088 fill[it] = values[obj->GetAxis(it)->GetUniqueID()];
2093 if (!weight) obj->Fill(fill);
2095 obj->Fill(fill, values[value4]);
2101void PairAnalysisHistos::FillVarArray(TObject* obj, UInt_t* valType)
2110 if (obj->InheritsFrom(TH1::Class())) {
2111 valType[0] = ((TH1*) obj)->GetXaxis()->GetUniqueID();
2112 valType[1] = ((TH1*) obj)->GetYaxis()->GetUniqueID();
2113 valType[2] = ((TH1*) obj)->GetZaxis()->GetUniqueID();
2114 valType[3] = ((TH1*) obj)->GetUniqueID();
2116 else if (obj->InheritsFrom(THnBase::Class())) {
2117 for (Int_t it = 0; it < ((THn*) obj)->GetNdimensions(); it++)
2118 valType[it] = ((THn*) obj)->GetAxis(it)->GetUniqueID();
2120 valType[19] = obj->GetUniqueID();
2125void PairAnalysisHistos::AdaptNameTitle(TH1* hist,
const char* histClass)
2132 Int_t dim = hist->GetDimension();
2133 TString currentName =
"";
2134 TString currentTitle =
"";
2135 TString hclass = histClass;
2137 TObjArray* arr = hclass.Tokenize(
"_.");
2139 hclass = ((TObjString*) arr->At(0))->GetString();
2143 Bool_t bname = (currentName.IsNull());
2144 Bool_t btitle = (currentTitle.IsNull());
2145 Bool_t bprf = kFALSE;
2146 if (hist->IsA() == TProfile::Class() || hist->IsA() == TProfile2D::Class() || hist->IsA() == TProfile3D::Class())
2150 Double_t pmin = 0., pmax = 0.;
2151 TString option =
"", calcrange =
"";
2152 Bool_t bStdOpt = kTRUE;
2156 option = ((TProfile3D*) hist)->GetErrorOption();
2157 pmin = ((TProfile3D*) hist)->GetTmin();
2158 pmax = ((TProfile3D*) hist)->GetTmax();
2161 option = ((TProfile2D*) hist)->GetErrorOption();
2162 pmin = ((TProfile2D*) hist)->GetZmin();
2163 pmax = ((TProfile2D*) hist)->GetZmax();
2166 option = ((TProfile*) hist)->GetErrorOption();
2167 pmin = ((TProfile*) hist)->GetYmin();
2168 pmax = ((TProfile*) hist)->GetYmax();
2171 if (option.Contains(
"s", TString::kIgnoreCase)) bStdOpt = kFALSE;
2177 UInt_t varx = hist->GetXaxis()->GetUniqueID();
2178 UInt_t vary = hist->GetYaxis()->GetUniqueID();
2179 UInt_t varz = hist->GetZaxis()->GetUniqueID();
2180 UInt_t varp = hist->GetUniqueID();
2181 Bool_t weight = (varp !=
static_cast<UInt_t
>(Eoption::kNoWeights));
2182 if (bprf && dim == 3) weight = kFALSE;
2192 TFormula* xform =
dynamic_cast<TFormula*
>(hist->GetListOfFunctions()->FindObject(
"xFormula"));
2193 TFormula* yform =
dynamic_cast<TFormula*
>(hist->GetListOfFunctions()->FindObject(
"yFormula"));
2194 TFormula* zform =
dynamic_cast<TFormula*
>(hist->GetListOfFunctions()->FindObject(
"zFormula"));
2195 TFormula* wform =
dynamic_cast<TFormula*
>(hist->GetListOfFunctions()->FindObject(
"wFormula"));
2208 if (bprf && dim < 3) {
2211 case 2: ax = hist->GetZaxis();
break;
2212 case 1: ax = hist->GetYaxis();
break;
2214 tit = ax->GetTitle();
2215 tit.Prepend((bStdOpt ?
"#LT" :
"RMS("));
2216 tit.Append((bStdOpt ?
"#GT" :
")"));
2218 tit.Append(calcrange.Data());
2219 ax->SetTitle(tit.Data());
2223 if (!xform) hist->GetXaxis()->SetTitle(tit.Data());
2225 if (!yform) hist->GetYaxis()->SetTitle(tit.Data());
2227 if (!zform) hist->GetZaxis()->SetTitle(tit.Data());
2231 case 1: hist->GetYaxis()->SetTitle(Form(
"%ss", hclass.Data()));
break;
2232 case 2: hist->GetZaxis()->SetTitle(Form(
"%ss", hclass.Data()));
break;
2237 TAxis* ax = hist->GetYaxis();
2238 if (dim == 2) ax = hist->GetZaxis();
2241 ax->SetTitle(Form(
"%s weighted %s", tit.Data(), ax->GetTitle()));
2245 TFormula* pform =
dynamic_cast<TFormula*
>(hist->GetListOfFunctions()->FindObject(
"pFormula"));
2246 if (bname)
switch (dim) {
2248 currentName += Form(
"%s_", hist->GetXaxis()->GetName());
2249 currentName += Form(
"%s_", hist->GetYaxis()->GetName());
2250 currentName += Form(
"%s", hist->GetZaxis()->GetName());
2258 currentName += Form(
"%s_", hist->GetXaxis()->GetName());
2259 currentName += Form(
"%s", hist->GetYaxis()->GetName());
2260 if (bprf) currentName += Form(
"-%s%s", hist->GetZaxis()->GetName(), (bStdOpt ?
"avg" :
"rms"));
2262 else if (weight && wform)
2266 currentName += Form(
"%s", hist->GetXaxis()->GetName());
2267 if (bprf) currentName += Form(
"-%s%s", hist->GetYaxis()->GetName(), (bStdOpt ?
"avg" :
"rms"));
2269 else if (weight && wform)
2275 if (hclass.Contains(
"pair")) currentName.Prepend(
"p");
2276 hist->SetName(currentName.Data());
2282void PairAnalysisHistos::AdaptNameTitle(THnBase* hist,
const char* histClass)
2289 Int_t dim = hist->GetNdimensions();
2290 TString currentName =
"";
2291 TString currentTitle =
"";
2292 TString hclass = histClass;
2294 TObjArray* arr = hclass.Tokenize(
"_.");
2296 hclass = ((TObjString*) arr->At(0))->GetString();
2300 Bool_t bname = (currentName.IsNull());
2301 Bool_t btitle = (currentTitle.IsNull());
2303 TList* list = (
static_cast<PairAnalysisHn*
>(hist))->GetListOfFunctions();
2309 for (Int_t it = 0; it < dim; it++) {
2310 TString formName = Form(
"axis%dFormula", it);
2311 TFormula* form =
dynamic_cast<TFormula*
>(list->FindObject(formName));
2320 currentName = hist->GetName();
2321 if (hclass.Contains(
"pair")) currentName.Prepend(
"p");
2322 hist->SetName(currentName.Data());
@ kNofSystems
For loops over active systems.
ClassImp(PairAnalysisHistos) PairAnalysisHistos
Data class with information on a STS local track.
TList * GetListOfFunctions() const
static const char * fgkSignals[static_cast< int >(EDefinedSignal::kNSignals)][2]
static const char * GetValueName(Int_t i)
static const char * GetValueUnit(Int_t i)
static void InitFormulas()
static UInt_t GetValueTypeMC(UInt_t var)
static UInt_t GetValueType(const char *valname)
static const char * GetValueLabel(Int_t i)
static const char * PairClassName(Int_t i)
static constexpr Int_t fNTypes
Int_t GetPrecision(Double_t value)
void NormalizeSlicesY(TH2 *h)
TString GetFormulaName(TFormula *form)
void SetGEANTBinLabels(TH1 *hist)
TArrayD * MakeStatBinLimits(TH1 *h, Double_t stat)
TString GetFormulaTitle(TFormula *form)
Double_t GetContentMinimum(TH1 *h, Bool_t inclErr=kTRUE)
Double_t GetContentMaximum(TH1 *h, Bool_t inclErr=kTRUE)
Double_t EvalFormula(TFormula *form, const Double_t *values)
void SetPDGBinLabels(TH1 *hist, Bool_t clean)
TString GetDetName(ECbmModuleId det)
void Cumulate(TH1 *h, Bool_t reverse=kFALSE, Bool_t norm=kFALSE)
void Style(TObject *obj, Int_t idx=0)
void SetLegendAttributes(TLegend *leg, Bool_t fill=kFALSE)