Error in plotting inside a for loop using tree->Draw()

Hi, I’m trying to have a correlation plot (6 columns * 4 rows) between two branches inside two “for” loops. A snippet of the code is below:

 for(int ippac=0; ippac<7; ippac++){
      if (ippac == 5) {
        continue;
    } //This is to ignore ippac = 5 coz that is a faulty detector  
    for (int j=0; j<4; j++){
       
        c1->Divide(ippac,j); 

        c1->cd(ippac+j*6+1);

        gPad-> SetLogz();
        gPad->SetGrid(1,1);
        gStyle->SetPalette(kRainBow);

//ch1 is the chain of root files. and greater than >-9999 just to plot the meaningful values.

         ch1->Draw(("PPAC_Tx2[%d][%d] : PPAC_Tx1[%d][%d]",ippac,j,ippac,j), ("PPAC_Tx2[%d][%d]>-9999 && PPAC_Tx1[%d][%d]>-9999",ippac,j,ippac,j));

//this is where I’m getting the error. and it’s obvious why I’m getting the error because Draw() takes 5 arguments at most but I’m giving more than that; Not sure how I can accommodate all the indexes;

    }
}

//FYI: PPAC_Tx1[ippac][j] or PPAC_Tx2[ippac][j] has a dimension of [7][4]

Thanks for any suggestions. Also, let me know if you need more info to assist.

ch1->Draw(TString::Format("PPAC_Tx2[%d][%d] : PPAC_Tx1[%d][%d]", ippac, j, ippac, j), TString::Format("PPAC_Tx2[%d][%d]>-9999 && PPAC_Tx1[%d][%d]>-9999", ippac, j , ippac, j));

@Wile_E_Coyote thanks a lot for your help. I replaced that part in my plotting routine, However, it doesn’t plot anything on the canvas (blank canvas) after successful compilation and running for around 10mins. I have attached the plotting routine along with this in case you wanna look at it. Thanks again for your time and help.

correlationplot.c (1.3 KB)

Before the first “for” loop, add: c1->Divide(7, 4);
Remove: c1->Divide(ippac,j);
Change “c1->cd(ippac+j*6+1);” into: c1->cd(ippac + j * 7 + 1);
After the “Draw” line, add: gPad->Modified(); gPad->Update();