Skip to content

Commit

Permalink
Merge pull request #334 from Marcellocosti/kde
Browse files Browse the repository at this point in the history
Remove redundant kde function and warning prints
  • Loading branch information
stefanopolitano authored Jan 9, 2025
2 parents bd74c13 + b8000cf commit f25ebf2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
11 changes: 4 additions & 7 deletions run3/flow/get_vn_vs_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ROOT import InvMassFitter, VnVsMassFitter
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle, DivideCanvas
from utils.FitUtils import SingleGaus, DoubleGaus, DoublePeakSingleGaus, DoublePeakDoubleGaus, RebinHisto
from kde_producer import kde_producer_grid, kde_producer_sim
from kde_producer import kde_producer

def get_vn_vs_mass(fitConfigFileName, centClass, inFileName,
outputdir, suffix, vn_method, batch):
Expand Down Expand Up @@ -126,12 +126,9 @@ def get_vn_vs_mass(fitConfigFileName, centClass, inFileName,
for iPt in range(len(ptMins)):
for iFlag, flag in enumerate(fitConfig['TemplsFlags']):
if fitConfig.get('FromGrid'):
KDEtemplates[iPt][iFlag], hist_templ = kde_producer_grid(fitConfig['TemplsInputs'][iFlag],
'fM', ptMins[iPt], ptMaxs[iPt], flag)
elif fitConfig.get('FromSim'):
KDEtemplates[iPt][iFlag] = kde_producer_sim(fitConfig['TemplsInputs'][iFlag],
fitConfig['TemplsTreeNames'][iFlag],
ptMins[iPt], ptMaxs[iPt], fitConfig['TemplsFlags'][iFlag])
KDEtemplates[iPt][iFlag] = kde_producer(fitConfig['TemplsInputs'][iFlag],
'fM', ptMins[iPt], ptMaxs[iPt], flag, '',
fitConfig['TemplsTreeNames'][iFlag])
elif fitConfig.get('FromFile'):
templFile = TFile.Open(f'{fitConfig["FromFile"]}', 'r')
KDEtemplates[iPt][iFlag] = templFile.Get(f'KDE_pt_{ptMins[iPt]}_{ptMaxs[iPt]}_flag{flag}')
Expand Down
3 changes: 3 additions & 0 deletions run3/flow/invmassfitter/VnVsMassFitter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ Bool_t VnVsMassFitter::SimultaneousFit(Bool_t drawFit) {

ROOT::Fit::FitResult result = fitter.Result();
result.Print(std::cout);
if(fTemplates) {
printf("\n --->Templates share the vn parameter with the signal! \n");
}

//set parameters in every function
fVnBkgFunc = new TF1("fVnBkgFunc",this,&VnVsMassFitter::vnBkgFunc,fMassMin,fMassMax,fNParsVnBkg,"VnVsMassFitter","vnBkgFunc");
Expand Down
1 change: 1 addition & 0 deletions run3/flow/invmassfitter/VnVsMassFitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class VnVsMassFitter : public TObject {
void SetKDETemplates(std::vector<TF1> templs, std::vector<std::string> templsnames,
std::vector<Double_t> initweights, std::vector<Double_t> minweights,
std::vector<Double_t> maxweights) {
printf("WARNING: Vn parameter of templates will be the same as the one of the signal! \n");
fKDETemplates=templs;
fInitWeights=initweights;
fWeightsLowerLims=minweights;
Expand Down
31 changes: 2 additions & 29 deletions run3/flow/kde_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import ctypes
from ROOT import TFile, TKDE, TCanvas, TH1D

def kde_producer_grid(tree_file, var, pt_min, pt_max, flag, outfile=''):
def kde_producer(tree_file, var, pt_min, pt_max, flag, outfile='', tree_name='O2hfcanddplite'):

print(f"Producing KDE from {tree_file} for var {var}, {pt_min} <= pt < {pt_max}, flag {flag}")
# convert the tree_file to a pandas dataframe
dfsData = []
with uproot.open(f'{tree_file}') as f:
for key in f.keys():
if 'O2hfcanddplite' in key:
if tree_name in key:
dfData = f[key].arrays(library='pd')
dfsData.append(dfData)
full_dataset = pd.concat([df for df in dfsData], ignore_index=True)
Expand All @@ -40,33 +40,6 @@ def kde_producer_grid(tree_file, var, pt_min, pt_max, flag, outfile=''):
kde_func.Write()
cOverlap.Write()

return kde, binned_var_values

def kde_producer_sim(tree_file, tree_name, pt_min, pt_max, flag=0):

print(f"Producing KDE from sim {tree_file} for process {tree_name}, {pt_min} <= pt < {pt_max}, flag {flag}")
# convert the tree_file to a pandas dataframe
dfsData = []
with uproot.open(f'{tree_file}') as f:
for key in f.keys():
if f'{tree_name}' in key:
dfData = f[key].arrays(library='pd')
dfsData.append(dfData)

full_dataset = pd.concat([df for df in dfsData], ignore_index=True)
if flag!=0:
flagged_dataset = full_dataset.query(f"decayflag == {flag}")
else:
flagged_dataset = full_dataset
pt_filtered_df = flagged_dataset.query(f"{pt_min} <= pt < {pt_max}")
var_values = pt_filtered_df["mass"].tolist() # Or use `.tolist()` to get a list

kde = TKDE(len(var_values), np.asarray(var_values, 'd'), 1.7, 2.0)

binned_var_values = TH1D(f'hBinned', f'hBinned', 5000, 1, 3)
for var_value in var_values:
binned_var_values.Fill(var_value)

return kde

if __name__ == "__main__":
Expand Down

0 comments on commit f25ebf2

Please sign in to comment.