Dear Rooters,

I am learning to use ProjectionY function in TH2 draw a 1D Projection to y axis from a 2D dot plot. What I am trying to do is like this:

I first draw a TCutG sub-region in 2D plot and then project 2D data to y axis. I know the (x,y) of each vertex in the TCutG sub-region. So I use GlobalBin = FindBin(x,y) to get corresponding Global Bin number. I try to use the smallest and the biggest GlobalBins to assign to arguments firstxbin and lastxbin in ProjectionY() function. It didn’t work. Then I try to use GetBinXYZ(globalxbin, firstxbin, biny, binz) to assign to firstxbin and lastxbin. It failed again.

So, my question is what value I should assign to firstxbin and lastxbin. Thank you very much for your help in advance! Appreciate for your advice

The code is as below:

```
void TestDialog::Project2Y(){
int CurReg = ActRegion;
int Points = Region[CurReg]->GetN();
char CurCutName[16], ProjName[16];
//dX, dY represents the real double coordinates
double dX=0.0, dY=0.0;
// double dY_Bottom=0.0, dY_Top=0.0, dX_Left=0.0, dX_Right=0.0;
//iX, iY represents the relative int coordinates in XVertex and YVertex
int fxbin=0, lxbin=-1; //First xbin, Last xbin
int iX=0, iY=0;
int iY_Bottom=YVertex[CurReg][0], iY_Top=YVertex[CurReg][0], iX_Left=XVertex[CurReg][0], iX_Right=XVertex[CurReg][0];
for(int i=0;i<Points;i++){
ParseXY(XVertex[CurReg][i], YVertex[CurReg][i], dX, dY);
iX = fHpxpy->FindBin(dX, dY);
if(i==0){
fxbin = iX;
lxbin = fxbin;
} else {
if(fxbin > iX)
fxbin = iX;
if(lxbin < iX)
lxbin = iX;
}
}
sprintf(CurCutName,"[CUT%d]",CurReg+1);
sprintf(ProjName, "Projection%d",CurReg+1);
if(fHprojy)
fHprojy->Delete();
// fHpxpy->GetBinXYZ(fxbin, fxbin, iX, iY);
// fHpxpy->GetBinXYZ(lxbin, lxbin, iX, iY);
fxbin = 10;
lxbin = 35;
printf("1stxbin = %d, lastxbin = %d\n", fxbin, lxbin);
fHprojy = (TH1F*)fHpxpy->ProjectionY(ProjName, fxbin, lxbin, "[CUT1]");
fCanvas[2]->cd();
fHprojy->SetTitle(ProjName);
fHprojy->SetFillColor(kBlue);
fHprojy->SetTickLength(0.02);
fHprojy->GetXaxis()->SetTicks("+-");
fHprojy->Draw("LF2");
fCanvas[2]->Modified();
fCanvas[2]->Update();
}
```