Problem with Poisson p.d.f. in RooFit

I am trying to use composite model to fit my data. I suggest that my data is gaus+poisson. But my data scale is calibrated in such a way that signal poisson and background gaus should be shifted by an x0 and argument x should be scaled by a some factor scale. So I’ve created a function using RooClassFactory:

Double_t ShiftedPoisson::evaluate() const 
{ 
  Double_t arg = 0.
  if( scale > 0 )
  {
    return TMath::Poisson( (x - x0) / scale , lambda );
  }
} 

Then I try to fit my data with this function and ordinary gaussian RooGaussian. I provide a whole code in order to complete the picture. Important blocks are emphasized.

void ECaen()
{
    TFile* f = TFile::Open( "ENoise/tree_noise.root", "READ" );
    TH1F* hist = (TH1F*)f->Get("E");

    //DATA VARIABLE = integral
    RooRealVar integral( "integral", "integral, LSB (0.49V)", 0, 500 ); 
    RooDataHist data( "data", "dataset from tree", integral, hist );

    RooRealVar pMean( "pMean", "Pedestal mean", 100, 90, 250 );
    RooRealVar pSigma( "pSigma", "Pedestal sigma", 10, 0, 60 );
    RooGaussian pGaus( "pGaus", "Pedestal Peak", integral, pMean, pSigma );

    //IMPORTANT!!!
    RooRealVar x0( "x0", "Poisson shift", 150, 100, 300 );
    RooRealVar scale( "scale", "Poisson scale factor", 10, 1, 1000 );
    RooRealVar lambda( "lambda", "Poisson average", 1, 1, 200 );
    //THIS IS MY FUNCTION
    ShiftedPoisson sig( "sig", "Signal", integral, x0, lambda, scale );

    RooRealVar fSig( "fSig", "fSig", 0.5, 0, 1 );
    RooAddPdf model( "model", "model", RooArgList( pGaus, sig ), fSig );

    //IMPORTANT!!!
    lambda.setConstant( kTRUE );//        <---- THIS IS BECAUSE PARAMETER LAMBDA IS THE MEAN OF single ELECTRON NOISE
    model.fitTo( data, Range( 50, 280.) );

    //_mean = ppMean.getVal();
    //_sigma = ppSigma.getVal();

    #ifdef DRAW
    RooPlot* xFrame = integral.frame( Title( "Empty case" ) );
    data.plotOn( xFrame );
    model.plotOn( xFrame );
    model.plotOn( xFrame, Components(pGaus), LineStyle( kDashed ) );
    model.plotOn( xFrame, Components(sig), LineStyle( kDashed ) );

    TCanvas* c = new TCanvas( "c", "c", 800, 600 );
    xFrame->Draw();
    c->SetLogy();
    xFrame->GetYaxis()->SetRangeUser( 1, 2 * hist->GetMaximum() );
    #endif

    return;
}

And how is my data looks like:

When I try to run this code I am either getting a freezed terminal:

or very strange things like:

I do not know why is this so? Can you help?

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