Fill histogram using variables saved in vector

Dear all,

I have a vector in which I saved the variables that I have to plot.

vector<TString> PlotVars;


As I am reading this variable from a tree so I get it like

float ungroomed_PuppiAK8_jet_pt;

float LHEWeight[1164];

When I am trying to fill it in histogram inside event loop like

for (int i =0; i<mytree->GetEntries(); i++)
  hist->Fill(PlotVars[0], (LHEWeight[j+446]/LHEWeight[0]))

As PlotVars[0] is of type TString so I used .Data() to convert it to const char * like

for (int i =0; i<mytree->GetEntries(); i++)
  hhist->Fill(PlotVars[0].Data() , (LHEWeight[j+446]/LHEWeight[0]))

But, in both cases just saves the string ungroomed_PuppiAK8_jet_pt in the histogram, not its value from the tree.

Please let me know how I can do this.


ROOT Version: 6.08/05
Platform: lxplus
Compiler: Not Provided

Try something like: mytree->Project("SomeHistogramName", PlotVars[0]);

BTW. You do not need to call “SetBranchAddress”, if you do not use these variables for another purposes in your code.

Dear Coyote,

Thanks for the response.

I think my question was not clear so I modified it again. I am using that Fill inside the event loop. But, I think I can’t use mytree->Project() inside the event loop.

I want to use this using event loop only because one of the branche in the tree is of array type from which I am extracting the weights. So, if I use Draw method instead of event loop it becomes very slow.

with regards,

In this case, you need:

hist->Fill(ungroomed_PuppiAK8_jet_pt, (LHEWeight[j+446]/LHEWeight[0]));

BTW. What’s “j”? For an ordinary “integer” variable, you could simply use (no need for an explicit loop over entries):

                TString::Format("(LHEWeight[(%d + 446)] / LHEWeight[0])", j));

Dear Coyote,

I am looping over “j”. You can see the patch and/or full code here:

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