Count in the shaded region (oddly-shaped)

Hello, I’m trying to determine the number of counts of the histogram ‘hist’ within a specific region depicted in the attached figure. The green line in the figure represents the function TF1 * F, the red line corresponds to the function TF1 *G, and the black line is positioned at x = L.

My goal is to compute the counts within the shaded area (indicated by blue stripes; a quadrilateral, not a triangle). Although this is more of a mathematical problem than a ROOT-related one, any suggestions or guidance would be greatly appreciated. Thank you!

If the sides are straight enough for your goal, you can define a TCutG with the corners and use the Area() method of TCutG (scroll down on the same page).

Hi,
I just made a small example with 2 gauss functions F and G and then I defined a new piece-wise function.
The new function is defined as the larger one between F and G in the range. Then I simply use the TF1::Integral() method to compute the counts below the curve.

{
   
    TF1 *F =new TF1("F","10*TMath::Gaus(x,4,1)",-5,10);
    TF1 * G =new TF1("G"," 5*TMath::Gaus(x,0,2)",-5,10);
    
    
    TF1 *FG =new TF1("FG","[&](double *x,double *p){ double y= (G->Eval(x[0])< F->Eval(x[0]))? G->Eval(x[0]): F->Eval(x[0]); return y;}",-5,10,0);

    
    
    F->SetLineColor(kGreen);
    F->Draw();
    G->Draw("same");
    
    FG->SetNpx(500);
    FG->SetLineColor(kBlue);
    FG->SetFillStyle(3000);
    FG->SetFillColor(kAzure);
    FG->Draw("same");
    cout<<"Integral from 2 to 6 is "<< FG->Integral(2,6)<<endl;

}

Here the resulting picture with G in red, F in Green and FG filled in Azure.

Best
Stefano

2 Likes

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