Error in TH1F while trying to fill vectors

Hi there,

I am trying to analyse a .root files with objects like

vector<float>   *mu_staco_pt;

in the header .h file that is generated from the MakeClass function.

When I try to add this within the for loop in the generated .C file

for(int i =0; i < mu_staco_n; i++){ h_mupt->Fill(mu_staco_pt[i]); } // end of internal for loop } // end of external for loop

it gives me the error

/home/user/Work/ROOTFiles/./newTestClass.C:50: error: no matching function for call to ‘TH1F::Fill(std::vector<float, std::allocator<float> >&)’

when I run

.L newTestClass.C++

in root.

I have already included an extra file (attached) for some of the new variable definitions that are within my header file already.

I have tried to google but had no luck, any advices?

Thanks a lot,
Jason
l.C (702 Bytes)

[quote=“jasonyctam”]Hi there,

vector<float>   *mu_staco_pt;

[/quote]

This is the pointer to vector

The expression mu_staco_pt[i] is a vector (mu_staco_pt is a pointer, pointer[i] is a pointed object, vector in your case).

TH1F does not have version of Fill, which accepts vector. So, you have to use vector instead of pointer to vector or do something else - depends on what do you really want to do.

Well, any popular book on C++ will be good.

Hi,

I have thought of that, but however the *mu_staco_pt is just one of the many variables in the header file that is generated by the MakeClass function, that is something that I can’t change. I can only change what I do within the for loop to apply selection cuts and/or plot it.

Cheers
Jason

[quote=“jasonyctam”]Hi,

I have thought of that, but however the *mu_staco_pt is just one of the many variables in the header file that is generated by the MakeClass function, that is something that I can’t change. I can only change what I do within the for loop to apply selection cuts and/or plot it.

Cheers
Jason[/quote]

Jason, mu_staco_pt is pointer, mu_staco_pt[i] is a *(mu_stack_pt + i) - dereferenced increased value of pointer, which is a vector.
What is your ‘i’? Are you sure mu_staco_pt pointer is initialized correctly? Are you trying to iterate on this vector? If yes, you can do:

hist->Fill((*mu_staco_pt)[i]);

Oh yes this was exactly what I need, thanks heaps!!!