How to get an array of cuts

Hi
I have a 2D histogram and i want to have 7 cuts on this histogram i use this program but at the end i have 7 similar histogram like first histogram without any cut. for the points of cuts i use an input file (S[j],E1[j],E2[j]).

for(int bin=0; bin<sn; bin++){
   for(int j=1; j<1890 ; j++){
      double smax=100.58;
      double smin=35.18;
      int sn=7;
      st=(smax-smin)/sn;
      s1=smin+bin*st;
      s2=smin+(bin+1)*st;
      if(S[j]<=s1+0.05 && S[j]>=s1){
         E11=E1[j];
         E12=E2[j];
      }
      if(S[j]<=s2+0.05 && S[j]>=s2){
      E21=E1[j];
      E22=E2[j];
   }
}
sprintf(cha[1],"np%dE",bin);
sprintf(cha[2],"npp%d",bin);
Np[bin]=new TH1F(cha[1],cha[2],50, -50, 50); 
sprintf(cha[1],"hp%dE",bin);
sprintf(cha[2],"hpp%d",bin);
hp[bin]=new TH2F(cha[1],cha[2],140, 0, 140, 140,0, 140); 
m=(E22-E12)/(E21-E11);
n=-1/m;
b=-m*E21+E22;
b1=-n*E11+E12;
b2=-n*E21+E22;
x1=-b1/n;
x2=-b2/n;
x3=135;
x4=135;
y1=0;
y2=0;
y3=(n*x3)+b1;
y4=(n*x4)+b2;
double h[5]={x1,x2,x4,x3,x1};
double k[5]={y1,y2,y4,y3,y1};
sprintf(cha[1],"cut%d",bin); 
cut[bin]=new TCutG(cha[1],5,h,k);  
double Ein,Eout;
cut[bin]->IsInside(Eout,Ein);
hp[bin]->Fill(Eout,Ein);

please help me. thanks

You fill the histograms without testing the result of IsInside. I do not know what is the logic behind your code, but at least I would do:

if (cut[bin]->IsInside(Eout,Ein)) hp[bin]->Fill(Eout,Ein);

Thanks a lot
now hp[bin] is correct but in continue of program in addition of drawing the histogram with Ein and Eout in each bin i want to do some calculations like below but i have all of Ein and Eout for this calculation how can i chose Ein and Eout for each bin and use them?
thank you

cut[bin]->IsInside(Eout,Ein);

H=(mEout+b-Ein)/sqrt(1+mm);

Np[bin]->Fill(H);

Again the call to IsInside is useless if you do not test its return value.

Thank you
I use:
if (cut[bin]->IsInside(Eout,Ein))
hp[bin]->Fill(Eout,Ein);
H=(mEout+b-Ein)/sqrt(1+mm);
Np[bin]->Fill(H);

hp[bin] is correct but Np[bin] are containing all of Ein and Eout

I think you should have a quick look at a C++ manual before writing your code. What you are asking is really the basis of the language. You should do:

if (cut[bin]->IsInside(Eout,Ein)) {
   hp[bin]->Fill(Eout,Ein);
   H=(m*Eout+b-Ein)/sqrt(1+m*m);
   Np[bin]->Fill(H);
}

Thanks a lot :heart_eyes:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.