Plotting from ttree with constrain

Hi,
I want to plot a 2D histogram (TKE:M_Tot) from a TTree with the constraint condition “Psd_All[i]>=1000 && Psd_All[i]<=2500”, where i =34 as Psd_All is an array of size 34. The following is the small peice of code :

void Noconstrain_3gauss_try()
{
Double_t s1;


// DEFINING CANVAS
TCanvas *c1 = new TCanvas("c1","Without constraint",800,600);


gStyle->SetOptStat(2211);
gStyle->SetOptFit(1111);

/////////////////// Tree opening  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\

TFile *file1=TFile::Open("RAW1_treeFF01.root");
TTree *tree1=(TTree*)file1->Get("Analysis");


   TH2D*h1 = new TH2D("h1","With_Constraint",81.,49.5,130.5, 101., 79.5, 180.5); 
  
c1->cd();
for (int i=0; i<34 ; i++){
   
    TString str1("");
    str1.Form("Psd_All[%d]>=1000.0 && Psd_All[%d] <= 2500.0",i);

   tree1->Draw("Tke:M_Tot>>h1", str1.Data());
}

}

but when I run this I get the error shown in the attachment. I want to plot the2D histogram by constarining my Psd_all, can someone tell me what is my mistake ??

Thank you !

Hi,

str1.Form("Psd_All[%d]>=1000.0 && Psd_Shift[%d] <= 2500.0",i);

should probably be

str1.Form("Psd_All[%d]>=1000.0 && Psd_Shift[%d] <= 2500.0",i,i);

That doesn’t work… I get the same error…

Also, you have

str1.Form("Psd_All[%d]>=1000.0 && Psd_Shift[%d] <= 2500.0",i,i);

in the code, but on the screenshot it’s

str1.Form("Psd_Shift_All[%d]>=1000.0 && Psd_All_Shift[%d] <= 2500.0",i,i);

– why is that? Can it make the difference?

Both Psd_All and Psd_Shift_All are the same, I just renamed the variable in the post…

And on the screenshot you have Psd_Shift_All and Psd_All_Shift - are these the same, too?

1 Like

It is Psd_All_Shift. I corrected for the name and its working now…

thank you