Skip to content

Commit

Permalink
Added new option of drawing th1 and th1c. Note: not supported with 2d…
Browse files Browse the repository at this point in the history
… and 3d option.
  • Loading branch information
DanielWielanek committed Nov 20, 2024
1 parent dffa9f7 commit 715905e
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 20 deletions.
1 change: 1 addition & 0 deletions analysis/femto/painters/CorrFit1DCFPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 21 additions & 11 deletions analysis/femto/painters/CorrFit3DCFPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,27 @@ namespace Hal {
return;
}
LockPad();
int count = 1;
auto painter3d = (Femto3DCFPainter*) fCF->GetPainter();
std::pair<Double_t, Double_t> 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<Double_t, Double_t> 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);
}
}
}
}
Expand Down
87 changes: 79 additions & 8 deletions analysis/femto/painters/CorrFitPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "CorrFitPainter.h"

#include <TH2D.h>
#include <TLegend.h>
#include <TVirtualPad.h>

Expand All @@ -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");
}
Expand All @@ -33,14 +36,61 @@ 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() {
for (auto x : fFunctions) {
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() {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion analysis/femto/painters/CorrFitPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "Painter.h"

class TH1D;
class TLegend;
class TVirtualPad;
namespace Hal {
Expand All @@ -38,18 +39,21 @@ namespace Hal {
TString fDefFuncDrawOpt = "SAME";
std::array<Double_t, 4> fLegendPos = {0.7, 0.95, 0.7, 0.95};
std::vector<TLegendEntry*> 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<std::vector<TF1*>> fFunctions;
std::vector<std::vector<TH1*>> fPSeudoFunctions;
CorrFitFunc* fFittedFunc = {nullptr}; //!
FemtoCFPainter* fCFPainter = {nullptr};

Expand All @@ -62,6 +66,7 @@ namespace Hal {
virtual void MakeLegend();
virtual void UpdateLegend();
void DeleteFunctions();
void MakeFakeFuncs();
std::vector<TString> GetLegendLabels() const;
ULong64_t PrepBitTemplate(std::initializer_list<int> temps) const;
/**
Expand Down
24 changes: 24 additions & 0 deletions analysis/femto/painters/FemtoCFPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

#include "FemtoCFPainter.h"

#include "Cout.h"
#include "Std.h"

#include <iostream>

#include <TCanvas.h>
#include <TH1.h>
#include <TH2.h>

namespace Hal {
const int FemtoCFPainter::kNumBit = 8;
Expand Down Expand Up @@ -140,4 +142,26 @@ namespace Hal {
return res;
}

std::vector<std::vector<TH1*>> FemtoCFPainter::GetFakeDrawFuncs() const {
std::vector<std::vector<TH1*>> res;
int counter = 0;
for (auto i : fHistograms) {
std::vector<TH1*> 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
5 changes: 5 additions & 0 deletions analysis/femto/painters/FemtoCFPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<TH1*>> GetFakeDrawFuncs() const;

public:
FemtoCFPainter() {}
Expand Down

0 comments on commit 715905e

Please sign in to comment.