Forming average of two TProfile histogram


I am trying to form an average of these two TProfiles I have but I could not make it to work.

I declared an array to store 3 TProfiles and I want to add the last two Tprofiles and form an average and store it into v2_TProfileSum. The syntax I am using is

TProfile* v2_TProfile[3]     //array of 3 tprofiles
TProfile* v2_TProfileSum;
v2_TProfileSum = (v2_TProfile[1]->Add(v2_TProfile[2])/2.0;

but somehow I am getting an error saying
error invalid operands to binary expression (‘TProfile *’ and ‘double’)

I have also tried to use the Copy() function to copy the average to v2_TProfileSum but it still not working.

I am not sure how to fix it. Can someone help me please. Thanks


v2_TProfileSum = (v2_TProfile[1]->Add(v2_TProfile[2])/2.0;

Instead of “/2.0”, use Divide(…) described ere:

v2_TProfileSum = ((TProfile*)(v2_TProfile[1]->Clone(“v2_TProfileSum”)));
v2_TProfileSum->Add(v2_TProfile[1], v2_TProfile[2], 0.5, 0.5);

Hi THanks for answering,

but I still failed to do so. I wasn’t trying to multiply two profile histograms but adding two profile histograms and then divide by 2.0 :frowning:

Yes, the division using the divide operator “/” is not valid. That’s the sense of the error message you get “invalid operands”. That’s why I suggested you to use the Divide() method instead.

[quote=“Wile E. Coyote”]Try:
v2_TProfileSum = ((TProfile*)(v2_TProfile[1]->Clone(“v2_TProfileSum”)));
v2_TProfileSum->Add(v2_TProfile[1], v2_TProfile[2], 0.5, 0.5);[/quote]


Thanks for answering,

it works! thanks for helping