How to save histogram variable in the tree

Dear Experts,

I want to save a histogram variable defined as “rarityHistFi” in the TTree named as a tree. I saved the rarity distribution as a histogram in the root file. While trying to save in the tree, the distribution peak at 0 and does give the desired distribution. Could it be possible to save the variable in the tree?

Kindly attached the code. apply.C (5.9 KB)

Thank you.

I see you create and fill the histogram rarityHistFi. Then you write it in the opened ROOT file. Sounds good. But I am not sure I understand what you mean by “save the variable in the tree” ? which variable are you talking about ?

Thanks, @couet for your prompt reply. I want to save the rarity distribution in the tree.

Maybe something like this.
Before the “for” (event) loop:

Double_t rarity;
tree->Branch("rarity", &rarity);

In the end of the “for” (event) loop:

rarity = methodbase->GetRarity( pdf, TMVA::Types::kSignal );
rarityHistFi->Fill(rarity);
tree->Fill(); // this line already exists

Thank you @Wile_E_Coyote, for your suggestions. It works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.