Home | News | Documentation | Download

a->Add(b), can't be initialized

Hello guys:
I want to know why one histogram can’t be initialized after adding a histogram, like below hQ2Q2Q2Q2_HFmHFmHFpHFp, even through I initial the histogram. Second times or more, though get the same histograms in files, I found the entries and mean of hQ2Q2Q2Q2_HFmHFmHFpHFp changed.
Thanks.

TH1D* hQ2Q2Q2Q2_HFmHFmHFpHFp ;
Tstring label_centbin = “”;
for(int pT=0; pT< n; pT++){
hQ2Q2Q2Q2_HFmHFmHFpHFp =
TH1D*)file1->Get(“Q2Q2Q2Q2_HFmHFmHFpHFp_Re_”+label_centbin);
TH1D hQ2Q2_HFmHFp = (TH1D)file1->Get(“Q2Q2_HFmHFp_Re_”+label_centbin);
TH1D* hQ4Q4_HFmHFp = (TH1D*)file1->Get(“Q4Q4_HFmHFp_Re_”+label_centbin);
TH1D* hQ4Q2Q2_HFmHFpHFp =
(TH1D*)file1->Get(“Q4Q2Q2_HFmHFpHFp_Re_”+label_centbin);
TH1D* hQ2Q2Q4_HFmHFmHFp =
(TH1D*)file1->Get(“Q2Q2Q4_HFmHFmHFp_Re_”+label_centbin);

   hQ2Q2Q2Q2_HFmHFmHFpHFp->Sumw2();
   hQ2Q2Q2Q2_HFmHFmHFpHFp->Add(hQ4Q4_HFmHFp);
   hQ2Q2Q2Q2_HFmHFmHFpHFp->Add(hQ4Q2Q2_HFmHFpHFp, -1);
   hQ2Q2Q2Q2_HFmHFmHFpHFp->Add(hQ2Q2Q4_HFmHFmHFp, -1);
      
   aux_Q2Q2Q2Q2_HFmHFmHFpHFp_mean = hQ2Q2Q2Q2_HFmHFmHFpHFp->GetMean();
   aux_Q2Q2_HFmHFp_mean = hQ2Q2_HFmHFp->GetMean();
   vn_den = TMath::Power(fabs(aux_Q2Q2Q2Q2_HFmHFmHFpHFp_mean - 2.0*aux_Q2Q2_HFmHFp_mean*aux_Q2Q2_HFmHFp_mean),3./4.);

}

Hi @Liuyao_Zhang,
please check this post about posting code on the forum.

I am afraid I did not understand the question: can you provide the simplest possible recipe for me to reproduce the problem and state what is the result you expect and what is the result you get instead?

Cheers,
Enrico

Hi @eguiraud
Thanks for your kind reminder.
I mean like below,

for(int pT=0; pT<npT; pT++){
TH1D* a = (TH1D*) file1->("a");
TH1D* b = (TH1D*) file1->("b");
a->Sumw2();
a->Add(b);
}

The “a” object in file1 in first pT has a right entries.
But Added “b” object. “a” object don’t has a right entires, mean value.
I think the value may be covered?
Now, I try to:

for(int pT=0; pT<npT; pT++){
TH1D* a = (TH1D*) file1->("a");
TH1D* a_copy = (TH1D*) a->Clone("a_copy");
TH1D* b = (TH1D*) file1->("b");
a_copy->Sumw2();
a_copy->Add(b);

That is is correct in every pT loop.

The variable … may (or might) not have be initialized". That means, there is some execution path of the program that has not been ruled out that could result in the variable not being assigned before it is used. The compile only uses what it can prove (or not prove) at compile time, which is somewhat limited: basically, no values can be used in this possible path detection.

Sorry, I had missed your reply.

@faeli’s reply is off-topic.

Your original loop creates many histograms with the same name. I don’t think that’s what you want?
Maybe you want to get the histogram from the file outside of the loop?

I can try to debug if you can produce a small reproducer that includes a check for the expected output.
Cheers,
Enrico