RooRealVar::SetRange() causes RooFormulaVar to not compile

Hi,

I am trying to write a fit function for a Z mass peak and I am trying to introduce a gaussian smearing parameter which depends on the mass/muon momenta, etc. As a first step, I am trying to build a simple model in which the mass resolution is a fit parameter multiplied by the mass.

Whenever I run the code below, it works fine (though quite slow, I assume because of all the integrals it must calculate because of the conditional pdf). However, if I try to change the range of the Mass variable from (-120.0,120.0) to (x,120.0), where x is anything else I’ve tried, I get a continuous stream of the following error:

[#0] ERROR:Eval – RooFormula::eval(Sigma_fft): Formula doesn’t compile: fabs(Mass)*Res_a0
[#0] ERROR:Eval – RooFormula::eval(Sigma_fft): Formula doesn’t compile: fabs(Mass)*Res_a0
[#0] ERROR:Eval – RooFormula::eval(Sigma_fft): Formula doesn’t compile: fabs(Mass)*Res_a0
[#0] ERROR:Eval – RooFormula::eval(Sigma_fft): Formula doesn’t compile: fabs(Mass)*Res_a0

Clearly this is a valid formula. Why would changing the range on the RooRealVar affect the compilation of the RooFormulaVar?

Thank you for any help!
-Jon

  double p_max = 300000.0;
  RooRealVar* Positive_Px = new RooRealVar("Positive_Px","Positive_Px", -p_max, p_max);
  RooRealVar* Positive_Py = new RooRealVar("Positive_Py","Positive_Py", -p_max, p_max);
  RooRealVar* Positive_Pz = new RooRealVar("Positive_Pz","Positive_Pz", -p_max, p_max);

  RooRealVar* Negative_Px = new RooRealVar("Negative_Px","Negative_Px", -p_max, p_max);
  RooRealVar* Negative_Py = new RooRealVar("Negative_Py","Negative_Py", -p_max, p_max);
  RooRealVar* Negative_Pz = new RooRealVar("Negative_Pz","Negative_Pz", -p_max, p_max);

  RooArgSet* All_Observables = new RooArgSet(*Positive_Px, *Positive_Py, *Positive_Pz, *Negative_Px, *Negative_Py, *Negative_Pz);

  RooDataSet* data = new RooDataSet("data", "Zmumu Data",input_tree, *All_Observables);

  //-----------------------------------------------------


  //Calculate Mass -------------------------------------

  RooFormulaVar* Mass_func = new RooFormulaVar("Mass", "sqrt(2*(105.658)*(105.658)+2*(sqrt((105.658)*(105.658)+Positive_Px^2+Positive_Py^2+Positive_Pz^2)*sqrt((105.658)*(105.658)+Negative_Px^2+Negative_Py^2+Negative_Pz^2)-(Positive_Px*Negative_Px+Positive_Py*Negative_Py+Positive_Pz*Negative_Pz)))/1000.0",*All_Observables);
  RooRealVar* Mass = (RooRealVar*) data->addColumn(*Mass_func);
  
  Mass->setRange(-120.0,120.0);  //Problem on this line!
  
  //-----------------------------------------------------

  //Mass Scale ------------------------------

  RooRealVar* mu = new RooRealVar("Mu", "#mu" , 0.0, -10., 5.) ;
  mu->setConstant(kTRUE);

  //-----------------------------------------------------

  //Mass Resolution -------------------------
  
  //resolution parameters  
  RooRealVar* Res_a0 = new RooRealVar("Res_a0","a_0", 0.05, 0.01, 0.5);  

  //calculate total resolution
  RooFormulaVar* Sigma = new RooFormulaVar("Sigma", "fabs(Mass)*Res_a0",RooArgSet(*Mass_func, *Res_a0) );
  //fit works perfectly well if I use this instead of the formula RooFormulaVar above
  //RooRealVar* Sigma = new RooRealVar("Sigma","#sigma", 5.0, 1.0, 10.0);

  //-----------------------------------------------------


  //Create PDF in Z mass/resolution ---------------------
  
  // BreitWigner/Z mass line shape + background terms, mostly fixed parameters
  RooRealVar* A = new RooRealVar("A","A", 3.35048e-07, 0 ,10.0);
  RooRealVar* B = new RooRealVar("B","B", -5.52495e-01);//,-1.0,0);
  RooRealVar* C = new RooRealVar("C","C", 3.25031e-01);//,0,5);
  RooRealVar* mean = new RooRealVar("mean", "Mean of RooEggePdf(Z mass)" , 91.1876);//, 70.,100.) ;
  RooRealVar* width = new RooRealVar("width","Z mass width", 2.4952 );//, 0.5 ,10.);

  RooEggePdf* f1 = new RooEggePdf("f1","f1",*Mass,*A,*B,*C,*mean,*width) ;

  //simple mass resolution model
  RooGaussModel* MassResGaussian = new RooGaussModel("MassResGaussian", "Mass resolution function", *Mass, *mu, *Sigma);


  Mass->setBins(1000,"cache") ;

  RooFFTConvPdf* pdf = new RooFFTConvPdf("pdf","Z Mass PDF", *Mass, *f1, *MassResGaussian);
  //-----------------------------------------------------



  //Fit Data --------------------------------------------
  RooFitResult* r = pdf->fitTo(*data,Save(true),Hesse(true),Minos(false),ConditionalObservables(*All_Observables));

  r->Print();

  //-----------------------------------------------------



  //Plot Results --------------------------------------------

  TCanvas* can1 = new TCanvas();  
  RooPlot* mframe1 = Mass->frame(70,110);
  mframe1->GetXaxis()->SetTitle("Mass [GeV]");
  data->plotOn(mframe1);
  pdf->plotOn(mframe1, ProjWData(*All_Observables,*data)) ;
  mframe1->Draw();

Hi Jon,

RooFormulaVars get interpreted by a derived class of TFormula. This class recognizes abs(),
but not fabs(). It will work fine if you switch to abs().

Wouter