Weird Roofit problem when running "rf104_classfactory.C"

Hi,

I’ve found a weird problem when running a modified version of rf104_classfactory.C.

In my version, the modification is rather simple : solely trying to use MyPdfV1.cxx, instead of
the default MyPdfV3.cxx.
Of course, I’ve also modified the MyPdfV1.cxx by replacing the default line of

return 1

to

return A + x *B

The running is a kind of OK in the sense I’ve produced a plot with a linear function.

However, the problem is, after running this script ("root rf104_classfactory.C -l "),
the “MyPdfV1.cxx” was modified automatically to its original version, saying, the return line is like this :

return 1

The line I’ve modified

return A + x *B

is disappeared.

Do your guys have any comments on this ?
And how to fix it ?

Thanks !
Best,
Junhui

Dear Junhui,

Your question is about a RoofFit class and this section of the forum is about PROOF, so it is not the right one.
You should submit or have submitted to 'Stat and Math tool …" .

Nevertheless, each time rf104_classfactory.C is run it creates a fresh MyPdfV1.cxx , so your modified MyPdfV1.cxx gets overwritten.
You should change the name not the modified file though, depending on how you want to use the file later, that may not be the right solution.

G. Ganis

Hi, G.Ganis and others,

Thanks for your reply and movement.
My apologizes for submitting in an inappropriate forum.

Well, the problem is, imaging I’ve coded a script which represents either a signal or background model.
I definitely don’t like it would be changed to a “blank” version every time of running.
(And I guess nobody wants his/her models shown in scripts have been killed after running.)

Do you guys have any idea on keeping the scripts alive after running ?

Thanks !

Best,
Junhui

Dear Junhui,

I am not sure to understand the problem.
The macro ‘rf104_classfactory.C’ is just an example of how to use RooClassFactory::makePdf .

In your own macro, you can, for example, check if the file exists already and add an option to overwrite or not. I can send an example of this, if it would help.
In any case, the files produced by RooClassFactory::makePdf are templates and it is likely that you have to modify them to adapt to your case.

Regards,
G Ganis

Hi, G Ganis,

Thanks for response !

Here, I’ve attached three pieces of codes.
The “template code[1]” is the one produced by “f104_classfactory.C” automatically.
The “my code[2]” apparently is my model.
The “My scripts[3]” is the script i’m going to run.

The script I’m running for this analysis is in [3] .

Every time, after running [3], [2] has been modified to [1].

Hopefully, I’ve explained clearly enough … :slight_smile:

Any comments ?

[1] template code :

/***************************************************************************** 
 * Project: RooFit                                                           * 
 *                                                                           * 
 * This code was autogenerated by RooClassFactory                            * 
 *****************************************************************************/ 

// Your description goes here... 

#include "Riostream.h" 

#include "QfPdf.h" 
#include "RooAbsReal.h" 
#include "RooAbsCategory.h" 
#include <math.h> 
#include "TMath.h" 

ClassImp(QfPdf) 

 QfPdf::QfPdf(const char *name, const char *title, 
                        RooAbsReal& _x,
                        RooAbsReal& _A,
                        RooAbsReal& _B) :
   RooAbsPdf(name,title), 
   x("x","x",this,_x),
   A("A","A",this,_A),
   B("B","B",this,_B)
 { 
 } 


 QfPdf::QfPdf(const QfPdf& other, const char* name) :  
   RooAbsPdf(other,name), 
   x("x",this,other.x),
   A("A",this,other.A),
   B("B",this,other.B)
 { 
 } 



 Double_t QfPdf::evaluate() const 
 { 
   // ENTER EXPRESSION IN TERMS OF VARIABLE ARGUMENTS HERE 
   return 1.0 ; 
 } 

[2] My code.


/***************************************************************************** 
 * Project: RooFit                                                           * 
 *                                                                           * 
 * This code was autogenerated by RooClassFactory                            * 
 *****************************************************************************/ 

// Your description goes here... 

#include "Riostream.h" 

#include "QfPdf.h" 
#include "RooAbsReal.h" 
#include "RooAbsCategory.h" 
#include <math.h> 
#include "TMath.h" 

ClassImp(QfPdf) 

 QfPdf::QfPdf(const char *name, const char *title, 
                        RooAbsReal& _x,
                        RooAbsReal& _A,
                        RooAbsReal& _B) :
   RooAbsPdf(name,title), 
   x("x","x",this,_x),
   A("A","A",this,_A),
   B("B","B",this,_B)
 { 
 } 


 QfPdf::QfPdf(const QfPdf& other, const char* name) :  
   RooAbsPdf(other,name), 
   x("x",this,other.x),
   A("A",this,other.A),
   B("B",this,other.B)
 { 
 } 



 Double_t QfPdf::evaluate() const 
 { 

      Double_t ER = x[0];

      Double_t SiZ = 14; //Z of Silicon.
      Double_t SiA = 28; //A of Silicon.
      Double_t epsln = 11.5 * ER * TMath::Power(SiZ, -7/3);
      Double_t gfunction = 3 * TMath::Power(epsln,0.15) + 0.7 * TMath::Power(epsln,0.6) + epsln;
      Double_t kappa = 0.133 * TMath::Power(SiZ,2/3) / TMath::Sqrt(SiA);
      Double_t QF = kappa * gfunction / (1 + kappa * gfunction);
      Double_t ED = ER * QF ;

      return ED + A + B;


} 

My scripts[3]

void GausExpModel(int nsig = 100,    // number of signal events 
                  int nbkg = 10 )  // number of background events
{ 

   RooWorkspace w("w");

  RooClassFactory::makePdf("BkgLinearPdf","x,A,B") ;
  RooClassFactory::makePdf("OOnePdf","x,A,B") ;
  RooClassFactory::makePdf("QfPdf","x,A,B") ;

#ifdef __CINT__
  gROOT->ProcessLineSync(".x BkgLinearPdf.cxx+") ;
  gROOT->ProcessLineSync(".x OOnePdf.cxx+") ;
  gROOT->ProcessLineSync(".x QfPdf.cxx+") ;
#endif

 
   w.factory("BkgLinearPdf:bkg_pdf(x[0,10], a[2.5,2.0,3.0], b[-0.0125,-0.025,0])");
   w.factory("OOnePdf:oone_pdf(x, mass[2], sigma[0.5])");
   w.factory("QfPdf:qf_pdf(x, kev[1], sigkev[0.3])");

.......

Dear Junhui,

This is the expected behaviour from your script, because this line

RooClassFactory::makePdf("QfPdf","x,A,B") ;

recreates the file.
But since you have already your own, modified version of QfPdf.C, you do not need the line, you should just comment it out.

Anyhow, this is not my field of expertise, I will ask a colleague of mine to follow the thread.

Regards,

G Ganis

Hi, Ganis,

Thanks for your comments !

However, after trying your suggestion, there was an error.
Once uncommented again, it came back to normal.

So, I guess I misunderstood something on the code #-o

Best,
Junhui