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!