Draw data from a tree

Dear Rooters,

I have a problem with drawing data, I put this code and I got a plot, but it is false, the first point in the plot is very high and the rest points are almost horizontal line, the expected plot is almost Gaussian distribution, so please help me, I am biggener.

Regards

//******************************************************************************************************
 TChain* t1=new TChain("kpi");
   t1->Add("dstar11_all.root");
  int nevt = (int) t1->GetEntries();
Double_t dm1;
Double_t md1;

t1->SetBranchAddress("D0_M", &md1);
t1->SetBranchAddress("massDifferenceMB__bo0__bc", &dm1);

 RooRealVar D0_M("mass","mass",1.83,1.89,"GeV/c^{2}");

 RooDataSet *data = new RooDataSet("data","data",RooArgSet(D0_M));

for (Int_t i = 0; i < nevt; i++)
{
t1->GetEntry(i);
D0_M.setVal(md1);
if(dm1 > 0.143 && dm1 < 0.147) continue; 
  data->add(RooArgSet(D0_M));
 }
 TCanvas *c1 = new TCanvas("c1","m(D)",1000,500);
 c1->Divide(1,1);
 RooPlot *mdplot = data->plotOn(D0_M.frame(100));
   data->plotOn(mdplot);
 mdplot->Draw();
mdplot->GetYaxis()->SetTitle("Events");
}

Hi @B_K,

are you sure you placed the braces correctly? The indentation looks like it’s off, but it’s hard to say if the braces are correct, as there’s one more closing brace.

Is this what you tried to do, i.e. you want to skip the event if the mass is between 0.143 and 0.147?

for (Int_t i = 0; i < nevt; i++) {
  t1->GetEntry(i);
  if(0.143 < dm1 && dm1 < 0.147)
    continue; 
  
  D0_M.setVal(md1);
  data->add(RooArgSet(D0_M));
}

No , I need the events if the in this range

Thank you for your answer,

I deleted (continue), the plot became as I want but with a problem, all the plot points are good except the first point, it is too high.

Regards

This indicates that you might be filling the dataset, although you didn’t intend to do that. Look for something like this:

//Wrong: It always fills but only sometimes sets a new value
if (.....)
   D0_M.setVal(xxx);
data->add(...);

// Right: It only sets and fills if desired
if (....) {
  D0_M.setVal(xxx);
  data->add(...);
}

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