Bin selection

Hello experts,
I am having trouble selecting the bins in following code.Feel like I selected some underflows.Could you please help me figure it out?

Double_t pLowBinEdge[6]= {0.30, 0.45, 0.65, 0.95, 1.65, 2.00};
    TH1F *Pbins = new TH1F("Pbins","Pbins",5,pLowBinEdge);
    TH1F *ithetabins = new TH1F("ithetabins","ithetabins",4,0,4);
    int i_theta_bins=4;
    int n_p=5;
    TH1F *h_pipCDMX2array_3fold[i_theta_bins][n_p];
    char histName[64];
        for (int ith=0; ith<i_theta_bins; ith++) { //is this bin selection is correct??
            for (int ipipCD=0; ipipCD<n_p; ipipCD++) {
                h_pipCDMX2array_3fold[ith][ipipCD] = new TH1F(histName,"3fold pip missing CD",300,-0.1,0.29);
                h_pipCDMX2array_3fold[ith][ipipCD]->SetTitle(Form("P bin %d / th bin %d ",ipipCD,ith));

 itheta = ( (Miss_pipCD_3fold.Theta()*TMath::RadToDeg()-theta_min_pipCD->Eval(pPip_3fold) )/ (theta_max_pipCD->Eval(pPip_3fold)-theta_min_pipCD->Eval(pPip_3fold)) );
   itheta *=(double)ntheta;

 //is this correct way of binning histogram?
int Pbinning = Pbins->GetXaxis()->FindBin(pPip_3fold)-1;
 int Thetabinning = ithetabins->GetXaxis()->FindBin(itheta)-1;

//Is following bin selection is correct?
if (itheta>0 && itheta<=ntheta) if(Pbinning>-1 && Pbinning<n_p && Thetabinning>-1 && Thetabinning<i_theta_bins)



Hi @Dil ,

hard to tell at a glance, probably the best way forward is for you to share a self-contained macro that we can run (including any input data necessary) and a clear description of what you expect to obtain vs what you obtain.