How to plot normalized data points in roofit?

Hi,

I have two different datasets in two root files. I want to plot one variable mass for both the data sets in one frame in roofit . Like drawing two histograms in one canvas from two different rootfiles by normalizing them.

But When I am plotting in one frame its giving segmentation violation.
The trial code is here , Any suggestion is most welcome.

regards,
debashis

void normalized_roofit() {
using namespace RooFit;

RooRealVar x("x", "x",3,3.2);
RooDataSet* data = new RooDataSet("data", "data",RooArgSet(x));

// fit variable
Float_t jpsimass,jpsif;

// Read data file
TFile* input=new TFile("charm_stream0.root");
TTree* t1 = (TTree*) input->Get("h1");

// no of entries in the datafile

Int_t n_tot = (int)t1->GetEntries();
cout << " n_tot = " << n_tot << endl;
t1->SetBranchAddress("jpsimass",&jpsimass);
t1->SetBranchAddress("jpsif",&jpsif);

// Import the data points
  for(int i=0; i<n_tot; i++) {
      t1->GetEntry(i); 
  if(jpsif ==1){
  if(jpsimass >=2.9 && jpsimass <=3.3) {   
     x.setVal(jpsimass); 
     data->add(RooArgSet(x));
            // if its double than I can fill in histogram
     }   
    }                                                  
  }
RooPlot *myframe =x.frame(100);//100 is number of bins.


RooRealVar x2("x2", "x2",3,3.2);
RooDataSet* data2 = new RooDataSet("data2", "data2",RooArgSet(x2));


// fit variable
Float_t jpsimass2,jpsif2;

// Read data file
TFile* input2=new TFile("charged_stream0.root");
TTree* t2 = (TTree*) input2->Get("h1");

// no of entries in the datafile

Int_t n_tot2 = (int)t2->GetEntries();
cout << " n_tot2 = " << n_tot2 << endl;
t2->SetBranchAddress("jpsimass",&jpsimass2);
t2->SetBranchAddress("jpsif",&jpsif2);

// Import the data points
  for(int i=0; i<n_tot2; i++) {
      t2->GetEntry(i); 
  if(jpsif2 ==1){
  if(jpsimass2 >=2.9 && jpsimass2 <=3.3) {   
     x2.setVal(jpsimass2); 
     data2->add(RooArgSet(x2));       
     }   
    }                                                  
  }

RooPlot *myframe2 =x2.frame(100);
//data->plotOn(myframe2);
data2->plotOn(myframe2);
myframe2->Draw();

}

Hi,

Can you please post your datafile so we can reproduce this problem?
Thank you

Lorenzo

Hi,
Thank you for your response. But actually, how can I upload root files to here? Is there any link or any upload options?

Thanks,
debashis

Click on “Reply” the you will see the following menu tool bar:

Click on the Icon I circled in red

Hi,

Thank you very much. I have already tried this one. But I don’t know why none of the menu tool bar options are not working for me. Means no cruser or palm mark is coming on the menu bar.

That’s weird. When you click on the blue button “Reply” you should see a typing area appearing at the bottom of the your browser window and on top of this area the menu bar I pictured in my previous post should appear. Then when you click on the icon I circled a file selector should pop up allowing you to choose which file you want to upload … Are you using some “exotic” web browser ?

Hi,

Thank you very much. I was trying with firefox web browser. It’s not working for me. Now I tried with google chrome and it works. Since the size of the files are more, I have
shared the google drive link , please find this.

https://drive.google.com/open?id=16nbVL64v8KSk-W6psoh1IzCZsqv-hFkf
https://drive.google.com/open?id=1u65ZpND01J-FugoUloUZ9uMfpsbBRzr7

Thanks,

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