TH3 and Sumw2()

Hello,

I really would appreciate to help me understanding what is wrong with my projections. I have a TH3 histogram that results from a weighted sum of 5 TH3 histograms. I do not get consistent results, namely the number of entries is very different, when projecting the Z axis in X or Y slices. The code i use to project is:

for(Int_t j = 0; j < nCentBins; j++){
int a=0, b=0;
for(Int_t i = 0; i < nEtJetBins/rebin; i++){
a=b+1;
b=a+rebin-1;
sprintf(HistName,“h15Projection_%i%i”,i,j);
a4ItrPervsEtT[i] = a4ItrPervsEtTEta_MT[j]->ProjectionZ(HistName,a,b,28,70);
a4HIItrJer[j][i]=a4ItrPervsEtT[i]->GetRMS();
erra4HIItrJer[j][i]=a4ItrPervsEtT[i]->GetRMSError();
a4HIItrJes[j][i]=a4ItrPervsEtT[i]->GetMean();
erra4HIItrJes[j][i]=a4ItrPervsEtT[i]->GetMeanError();
cout<<"ET “<<a4ItrPervsEtT[i]->GetEntries()<<” i,j “<<i<<” "<<j<<endl;
}
}

for(Int_t j = 0; j < nCentBins; j++){
int a=0, b=0;
for(Int_t i = 0; i < nEtaJetBins/rebin; i++){
a=b+1;
b=a+rebin-1;
sprintf(HistName,“h16Projection_%i%i”,i,j);
a4ItrPervsEtaT[i] = a4ItrPervsEtTEta_MT[j]->ProjectionZ(HistName,5,nEtJetBins,a,b);
a4HIItrJereta[j][i]=a4ItrPervsEtaT[i]->GetRMS();
erra4HIItrJereta[j][i]=a4ItrPervsEtaT[i]->GetRMSError();
a4HIItrJeseta[j][i]=a4ItrPervsEtaT[i]->GetMean();
erra4HIItrJeseta[j][i]=a4ItrPervsEtaT[i]->GetMeanError();
cout<<"eta “<<a4ItrPervsEtaT[i]->GetEntries()<<” i,j “<<i<<” "<<j<<endl;
if (a4ItrPervsEtaT[i]->GetEntries()==0){
a4HIItrJereta[j][i]=1000;
a4HIItrJeseta[j][i]=1000;
}
}
}

a4ItrPervsEtT[i]->GetEntries(), either in X or Y slices, are only consistent if all weights are set to 1. So, the problem seems to be in TH3 and sumw2:
a4ItrPervsEtTEta_MT_J1[j]->Sumw2();
a4ItrPervsEtTEta_MT_J2[j]->Sumw2();
a4ItrPervsEtTEta_MT_J3[j]->Sumw2();
a4ItrPervsEtTEta_MT_J4[j]->Sumw2();
a4ItrPervsEtTEta_MT_J5[j]->Sumw2();
a4ItrPervsEtTEta_MT[j]->Add(a4ItrPervsEtTEta_MT_J1[j],a4ItrPervsEtTEta_MT_J2[j],J1XS,J2XS );
a4ItrPervsEtTEta_MT[j]->Add(a4ItrPervsEtTEta_MT[j],a4ItrPervsEtTEta_MT_J3[j],1,J3XS );
a4ItrPervsEtTEta_MT[j]->Add(a4ItrPervsEtTEta_MT[j],a4ItrPervsEtTEta_MT_J4[j],1,J4XS );
a4ItrPervsEtTEta_MT[j]->Add(a4ItrPervsEtTEta_MT[j],a4ItrPervsEtTEta_MT_J5[j],1,J5XS );
a4ItrPervsEtTEta_MT[j]->Scale(1/(J1XS+J2XS+J3XS+J4XS+J5XS));

The results of the projections become also wrong, of course. Do you know where the problem might be? Do I need to first project and only then make the weighted sum?

Thank you so much in advance.
Best regards,
Helena

Hi,

First of all for a weighted histogram the number of entries does not make anymore much sense. When projecting or adding what is displayed as Entries are actually the effective entries. (sum of the weights square / sum of the square of the weights)
If you are sure that the projected histograms do not make sense, please attach a minimal running macro with a root file with the histograms

Best Regards

Lorenzo

Hi Lorenzo,

Thank you very much for help. You are right about GetEntries() that does not make sense when using weights. On the other hand the interplay among the different weights is not the same in X and Y (should not be, in fact). I also checked that i obtain the same result by projecting first and summing after, so I believe that the my algorithm is correct. i just want to be sure that the errors are correct (the mean values should be for sure). When I make:
erra4HIItrJer[j][i]=a4ItrPervsEtT[i]->GetRMSError();
erra4HIItrJes[j][i]=a4ItrPervsEtT[i]->GetMeanError();
does it return the correct errors (I mean are they also weighted)?

Thanks a lot.
Helena

Hi,

Yes, GetMeanError and GetRMSError should give correct results also in case of weighted histograms, since the number of effective entries is used for computing them.
If you find results which do not make sense to you, please let me know.

Lorenzo

Hi Lorenzo,

In fact there is one issue that it is worrysome. My error bars are larger if I weight the histograms. That is, in a range where a given sample is dominant the errors get much smaller if the sample is plotted alone (without weights, of course) . But adding statistics, even if they are small due to weight, can only decrease the statistical error. I’m puzzled and afraid that something is wrong. Could you, please, check? The root files are too big to be attached so I put them in lip.pt/~helena/. The macro is also there and it is called plot.C. Can you access to them?

J1_30112011.root, J2_30112011.root, J3_30112011.root, J4_30112011.root and J5_30112011.root
The relevant lines in the macro are around 550.

Thank you so much in advance.
Helena

Hi Helena,

I cannot run your script. There are many compilation error (if using ACLIC) it and when using CINT I get this error :

Cheers
Lorenzo

Hi Lorenzo,

Sorry, I was interested in printing values so I broke up the loop on purpose. Now it is ok. Could you, please, pick up the macro again?
I will see what is going one when compiling with AcLiC. Probably missing headers.

Thanks a lot!
Helena

Hi Helena,

Thanks for the update, I can run your macro now. But can you please explain which result is supposed not to be right ? I see many plots generated and fitted, but I need help to understand them if they are relevant for your problem.

Lorenzo

Hi Lorenzo,

The core of this macro is a weighted sum of TH3 histograms. Then I project these histograms in the Z axis, requiring X or Y slices, and get the mean, mean error, rms and rms error of each slice. The loop of these projections start in lines 469 and 520, respectively (BTW, I updated the macro in order to include the missing headers, so one can compile with ACLIC). The rms and mean of each slice are plotted in lines 635 and 650.

What I think may not be correct is the errors I obtain through:
erra4HIItrJes[j][i]=a4ItrPervsEtT[i]->GetMeanError();
and
erra4HIItrJeseta[j][i]=a4ItrPervsEtaT[i]->GetMeanError();
where, e.g., a4ItrPervsEtaT[i] is the TH1 histogram that results from the weighted sum:
a4ItrPervsEtaT[i]->Add(a4ItrPervsEtaT_J1[i],a4ItrPervsEtaT_J2[i],J1XS/(J1XS+J2XS),J2XS/(J1XS+J2XS) );
a4ItrPervsEtaT[i]->Add(a4ItrPervsEtaT_J3[i],J3XS/(J1XS+J2XS+J3XS) );
a4ItrPervsEtaT[i]->Add(a4ItrPervsEtaT_J4[i],J4XS/(J1XS+J2XS+J3XS+J4XS) );
a4ItrPervsEtaT[i]->Add(a4ItrPervsEtaT_J5[i],J5XS/(J1XS+J2XS+J3XS+J4XS+J5XS) );
If this algorithm that calculates the weighted sum of the five TH3 histograms is correct then the error of the mean of a4ItrPervsEtaT[i] is larger than the individual contributions (a4ItrPervsEtaT_J1[i],…a4ItrPervsEtaT_J5[i]). This happens due to the weights. It is the first time that I’m observing that adding a contribution to an histogram (i.e., adding entries) increases the statistical errors instead of decreasing them.
That’s why I want to be sure that the errors obtained though GetMeanError() (RMS/sqrt(EffectiveEntries)) are correct.

Thank you very much again.
Helena

Hi again Lorenzo,

Let me just one thing. In the loops that start lines 469 and 520, first I project the Z axis and only then I make the weighted sum. But this is equivalent of weighting the TH3 and then project the resulting histogram (as in the loop commented in line 423). The result is absolutely the same. Sorry for the glitch.

Helena