Home | News | Documentation | Download

Histogram is empty

Hi all, I’ll be missing something obvious but I really can’t work out why this histogram isn’t drawing. It shows 155 events in the legend but with mean and std deviation zero, but when I put a print statement after ‘Fill’ it prints entries that actually have values between 1000-3000. I have a loop here to make ROC curves which are created successfully and show up fine in the root file, and in this loop the cut value for the histograms that don’t print are also found.

for (int a=0; a<nHists; a++){
gluonTotal = gluonsOnly[a]->GetEntries();
std::cout<<"gluon total is "<<gluonTotal<<endl;
quarkTotal = quarksOnly[a]->GetEntries();
std::cout<<"quark total is "<<quarkTotal<<endl;

for (Long64_t k=0; k < faveBigNumber; k++){
gluons=0;
quarks=0;
signalEff=0;
backgEff=0;



for (int i=k; i<=gluonsOnly[a]->GetNbinsX(); i++){
       gluons+=gluonsOnly[a]->GetBinContent(i);
     quarks+=quarksOnly[a]->GetBinContent(i);
     }


     backgEff=quarks/quarkTotal;
     signalEff=gluons/gluonTotal;
     coordinatesX[k]=signalEff;
     coordinatesY[k]=backgEff;
     }
         sprintf(ROCName,"ROC%d",a);
         sprintf(ROCTitle,"ROC%d pT between %5.0f and %5.0f GeV",a,edges[a],edges[a+1]);
             ROC[a] = new TGraph(faveBigNumber-1,coordinatesX,coordinatesY);
                 ROC[a]->SetTitle(ROCTitle);
                     ROC[a]->SetName(ROCName);

        ROC[a]->Draw("L");
        ROC[a]->Write();
        mg->Add(ROC[a]);
        quarkGraphCoordinateY[a] = (float)( ROC[a]->Eval(0.5));


        std::vector<float> v50(std::begin(coordinatesX),std::end(coordinatesX));
        std::vector<float>::iterator low50;
        std::reverse(v50.begin(),v50.end());
        low50=std::lower_bound (v50.begin(), v50.end(), 0.5);
         std::cout << "lower_bound at position " << (low50- v50.begin()) << '\n';
        cutValue50[a]=1+low50- v50.begin();

}

This works fine, I’ve printed cutValue50 to check it is an array of integers which are the positions of the element closest to 0.5. Then next I try to make the histogram that isn’t printing:

TH1F *gluonPtTagged50 = new TH1F("gluonPtTagged50","Gluon pT",120,-0.5,119.5);

for (Long64_t x = 0; x < N; x++) {
   fChain->GetEntry(x);
     for (unsigned long j = 0; j <jet_pt->size(); j++) {
      float maxElement = *max_element(jet_pt->begin(), jet_pt->end());
       for(int y=0; y<nHists;y++){
        double minPt = edges[y];
        double maxPt = edges[y+1];
         if (jet_NumTrkPt1000PV->at(j)>cutValue50[y] && jet_pt->at(j)<maxPt && jet_pt->at(j) == maxElement && jet_eta->at(j)<2.5){
        gluonPtTagged50->Fill(jet_pt->at(j), mcEventWeight*JZ_weight);
//      std::cout<<"this pt element is "<<jet_pt->at(j)<<endl;
        break;
        }
       }
     }
}

gluonPtTagged50->Draw();
hfile.Write();
hfile.Close();

The histogram shows up in the root file but is blank, there are axes and the legend showing there should be 155 events but with mean and std deviation zero.

What I think the loop should be doing is taking each event, finding the jet with the largest pT, checking whether it’s in a certain pT range or not (edges is an array of bin edges), then if the number of tracks is above a certain value it’s a gluon jet and the gluon pT histogram is filled. I can’t work out what’s going wrong!

Thanks for any help!

Hello,

The gluonPtTagged50 is set to the range [-0.5, 119.5] but you say that your actual values are between 1000 and 3000. Does changing the histogram range show the data?

(As a side note, you seem to determine max(jet_pt) more often than you need to. You should be able to get the index of the largest pT once for every x with distance(jet_pt->begin(), max_element(jet_pt->begin(), jet_pt->end())))

Cheers,
Jakob

1 Like

Hi Jakob,

Thank you!!! I knew it would be something stupid but I just couldn’t spot it! Changing the range fixed it. Thank you for your other point as well, anything that might speed up the running is always great! Would that go in the outermost loop then, below GetEntry?

Glad I could help. Yes, it would go just below GetEntry.

Cheers,
Jakob