diff --git a/analysis/femto/painters/CorrFit1DCFPainter.cxx b/analysis/femto/painters/CorrFit1DCFPainter.cxx index 5cf8508..ebf3688 100644 --- a/analysis/femto/painters/CorrFit1DCFPainter.cxx +++ b/analysis/femto/painters/CorrFit1DCFPainter.cxx @@ -17,6 +17,7 @@ #include "CorrFit.h" #include "CorrFit1DCF.h" #include "CorrFitFunc.h" +#include "Cout.h" #include "Femto1DCF.h" #include "Femto1DCFPainter.h" #include "Painter.h" diff --git a/analysis/femto/painters/CorrFit3DCFPainter.cxx b/analysis/femto/painters/CorrFit3DCFPainter.cxx index a003011..32279da 100644 --- a/analysis/femto/painters/CorrFit3DCFPainter.cxx +++ b/analysis/femto/painters/CorrFit3DCFPainter.cxx @@ -162,17 +162,27 @@ namespace Hal { return; } LockPad(); - int count = 1; - auto painter3d = (Femto3DCFPainter*) fCF->GetPainter(); - std::pair range; - if (painter3d) { range = painter3d->GetMinMax(); } - for (auto padfunc : fFunctions) { - GotoPad(count++); - for (auto func : padfunc) { - if (func) { - func->SetMinimum(range.first); - func->SetMaximum(range.second); - func->Draw(fDefFuncDrawOpt); + int count = 1; + if (CheckOpt(kTH1Draw)) { + for (auto padfunc : fPSeudoFunctions) { + GotoPad(count++); + for (auto func : padfunc) { + if (func) { func->Draw(fDefFuncDrawOpt); } + } + } + + } else { + auto painter3d = (Femto3DCFPainter*) fCF->GetPainter(); + std::pair range; + if (painter3d) { range = painter3d->GetMinMax(); } + for (auto padfunc : fFunctions) { + GotoPad(count++); + for (auto func : padfunc) { + if (func) { + func->SetMinimum(range.first); + func->SetMaximum(range.second); + func->Draw(fDefFuncDrawOpt); + } } } } diff --git a/analysis/femto/painters/CorrFitPainter.cxx b/analysis/femto/painters/CorrFitPainter.cxx index eb4d3d2..3c5f7f5 100644 --- a/analysis/femto/painters/CorrFitPainter.cxx +++ b/analysis/femto/painters/CorrFitPainter.cxx @@ -7,6 +7,7 @@ #include "CorrFitPainter.h" +#include #include #include @@ -18,10 +19,12 @@ #include "StdString.h" namespace Hal { - const int CorrFitPainter::kAutoNormBit = 8; - const int CorrFitPainter::kLegendBit = 9; - const int CorrFitPainter::kChi2 = 10; - const int CorrFitPainter::kChi2Short = 11; + const int CorrFitPainter::kAutoNormBit = 8; + const int CorrFitPainter::kLegendBit = 9; + const int CorrFitPainter::kChi2 = 10; + const int CorrFitPainter::kChi2Short = 11; + const int CorrFitPainter::kTH1Draw = 12; + const int CorrFitPainter::kTH1DrawSmooth = 13; CorrFitPainter::CorrFitPainter(CorrFitFunc* func) : Painter(), fFittedFunc(func) { fNormIndex = fFittedFunc->GetParameterIndex("N"); } @@ -33,6 +36,48 @@ namespace Hal { if (y) { y->FixParameter(y->GetNpar() - 1, flag); } } } + if (fPSeudoFunctions.size()) { + Int_t dim = 1; + if (fPSeudoFunctions[0].size()) + if (fPSeudoFunctions[0][0]->InheritsFrom("TF2")) dim = 2; + + for (unsigned int i = 0; i < fPSeudoFunctions.size(); i++) { + for (unsigned int j = 0; j < fPSeudoFunctions[i].size(); j++) { + auto histo = fPSeudoFunctions[i][j]; + TF1* func = nullptr; + if (fFunctions.size() > i) { + if (fFunctions[i].size() > j) func = fFunctions[i][j]; + } + if (!func) { // this might happen for sh opition + if (dim == 1) + for (int k = 1; k <= histo->GetNbinsX(); k++) { + histo->SetBinContent(k, -1E+9); + } + continue; + } + histo->SetLineColor(func->GetLineColor()); + histo->SetLineStyle(func->GetLineStyle()); + histo->SetLineWidth(func->GetLineWidth()); + if (dim == 2) { // oops it's 2d func + auto th2d = (TH2D*) histo; + for (int k = 1; k <= th2d->GetNbinsX(); k++) { + double x = histo->GetXaxis()->GetBinCenter(k); + for (int l = 1; l <= th2d->GetNbinsY(); l++) { + double y = histo->GetYaxis()->GetBinCenter(l); + double z = func->Eval(x, y); + histo->SetBinContent(k, l, z); + } + } + } else { + for (int k = 1; k <= histo->GetNbinsX(); k++) { + double x = histo->GetXaxis()->GetBinCenter(k); + double y = func->Eval(x); + histo->SetBinContent(k, y); + } + } + } + } + } } void CorrFitPainter::DeleteFunctions() { @@ -40,7 +85,12 @@ namespace Hal { for (auto y : x) if (y) delete y; } + for (auto x : fPSeudoFunctions) { + for (auto y : x) + if (y) delete y; + } fFunctions.clear(); + fPSeudoFunctions.clear(); } void CorrFitPainter::MakeLegend() { @@ -67,11 +117,17 @@ namespace Hal { fLegendPad->Update(); } + void CorrFitPainter::MakeFakeFuncs() { + if (!CheckOpt(kTH1Draw)) return; + if (fCFPainter) { fPSeudoFunctions = fCFPainter->GetFakeDrawFuncs(); } + } + CorrFitPainter::~CorrFitPainter() { DeleteFunctions(); } void CorrFitPainter::InnerPaint() { DeleteFunctions(); MakeFunctions(); + MakeFakeFuncs(); UpdateParameters(); ScaleFunctions(); ScaleHistograms(); @@ -98,10 +154,19 @@ namespace Hal { void CorrFitPainter::DrawFunctions() { LockPad(); int count = 1; - for (auto padfunc : fFunctions) { - GotoPad(count++); - for (auto func : padfunc) { - if (func) { func->Draw(fDefFuncDrawOpt); } + if (CheckOpt(kTH1Draw)) { + for (auto padfunc : fPSeudoFunctions) { + GotoPad(count++); + for (auto func : padfunc) { + if (func) { func->Draw(fDefFuncDrawOpt); } + } + } + } else { + for (auto padfunc : fFunctions) { + GotoPad(count++); + for (auto func : padfunc) { + if (func) { func->Draw(fDefFuncDrawOpt); } + } } } UnlockPad(); @@ -127,6 +192,12 @@ namespace Hal { SETBIT(newFlag, kChi2); SETBIT(newFlag, kChi2Short); } + if (Hal::Std::FindParam(opt, "th1c", kTRUE)) { + SETBIT(newFlag, kTH1DrawSmooth); + SETBIT(newFlag, kTH1Draw); + fDefFuncDrawOpt = "SAME+C"; + } + if (Hal::Std::FindParam(opt, "th1", kTRUE)) SETBIT(newFlag, kTH1Draw); if (Hal::Std::FindParam(opt, "legend", kTRUE)) { SETBIT(newFlag, kLegendBit); auto bra = Hal::Std::FindBrackets(opt, kTRUE, kTRUE); diff --git a/analysis/femto/painters/CorrFitPainter.h b/analysis/femto/painters/CorrFitPainter.h index fd6cb58..74858dd 100644 --- a/analysis/femto/painters/CorrFitPainter.h +++ b/analysis/femto/painters/CorrFitPainter.h @@ -19,6 +19,7 @@ #include "Painter.h" +class TH1D; class TLegend; class TVirtualPad; namespace Hal { @@ -38,18 +39,21 @@ namespace Hal { TString fDefFuncDrawOpt = "SAME"; std::array fLegendPos = {0.7, 0.95, 0.7, 0.95}; std::vector fLegendEntries; - static const int kAutoNormBit, kLegendBit, kChi2, kChi2Short; + static const int kAutoNormBit, kLegendBit, kChi2, kChi2Short, kTH1Draw, kTH1DrawSmooth; /** * * @param opt, for this class additional options are available: * - "chi2" - draw chi2 on legend (including total value of chi2 and NDF) * - "chi2s " - draw chi2 on legend * - "legend" - draw legend + * - "th1" - use TH1 instead of TF1 for drawing + * - "th1c" - same as th1 but uses "same+c" for drawing CF's * @param prev * @return */ virtual ULong64_t SetOptionInternal(TString opt, ULong64_t prev = 0); std::vector> fFunctions; + std::vector> fPSeudoFunctions; CorrFitFunc* fFittedFunc = {nullptr}; //! FemtoCFPainter* fCFPainter = {nullptr}; @@ -62,6 +66,7 @@ namespace Hal { virtual void MakeLegend(); virtual void UpdateLegend(); void DeleteFunctions(); + void MakeFakeFuncs(); std::vector GetLegendLabels() const; ULong64_t PrepBitTemplate(std::initializer_list temps) const; /** diff --git a/analysis/femto/painters/FemtoCFPainter.cxx b/analysis/femto/painters/FemtoCFPainter.cxx index 39604c1..b133af5 100644 --- a/analysis/femto/painters/FemtoCFPainter.cxx +++ b/analysis/femto/painters/FemtoCFPainter.cxx @@ -7,12 +7,14 @@ #include "FemtoCFPainter.h" +#include "Cout.h" #include "Std.h" #include #include #include +#include namespace Hal { const int FemtoCFPainter::kNumBit = 8; @@ -140,4 +142,26 @@ namespace Hal { return res; } + std::vector> FemtoCFPainter::GetFakeDrawFuncs() const { + std::vector> res; + int counter = 0; + for (auto i : fHistograms) { + std::vector row; + for (auto h : i) { + Int_t binx, biny; + Double_t minx, miny, maxx, maxy; + if (h->InheritsFrom("TH2")) { + Hal::Std::GetAxisPar(*h, binx, minx, maxx, "x"); + Hal::Std::GetAxisPar(*h, biny, miny, maxy, "y"); + row.push_back(new TH2D(Form("func_%i", counter++), "", binx, minx, maxx, biny, miny, maxy)); + } else { + Hal::Std::GetAxisPar(*h, binx, minx, maxx, "x"); + row.push_back(new TH1D(Form("func_%i", counter++), "", binx, minx, maxx)); + } + } + res.push_back(row); + } + return res; + } + } // namespace Hal diff --git a/analysis/femto/painters/FemtoCFPainter.h b/analysis/femto/painters/FemtoCFPainter.h index 9d19453..7e0f567 100644 --- a/analysis/femto/painters/FemtoCFPainter.h +++ b/analysis/femto/painters/FemtoCFPainter.h @@ -50,6 +50,11 @@ namespace Hal { Bool_t AreSimiliar(ULong64_t current, ULong64_t pattern) const; virtual void InnerPaint(); virtual void InnerRepaint(); + /** + * + * @return fake histograms used instead of TF1 if "th1" options is called + */ + virtual std::vector> GetFakeDrawFuncs() const; public: FemtoCFPainter() {}