User Tools

Site Tools


root:custompdfsandworkspace

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
root:custompdfsandworkspace [2012/01/28 15:52] – created decianmroot:custompdfsandworkspace [2012/04/25 20:07] (current) decianm
Line 2: Line 2:
 ===== Idea ===== ===== Idea =====
 In RooFit you can define a custom PDF shape in a C++ class. This is a good idea if the model is widely used and speed is an issue. A popular example is the class "RooExpAndGauss", which is used for partly reconstructed background in B decays. However, you need to be careful when defining these if you also want to deal with RooWorkspaces. In RooFit you can define a custom PDF shape in a C++ class. This is a good idea if the model is widely used and speed is an issue. A popular example is the class "RooExpAndGauss", which is used for partly reconstructed background in B decays. However, you need to be careful when defining these if you also want to deal with RooWorkspaces.
-==== Problem & Solution ====+===== Problem & Solution =====
 You need to define a standard constructor in your Pdf-class, so it can be stored in (and retrieved from) a RooWorkspace. However, this standard constructor must initialize all the necessary variables, otherwise you will not be able to retrieve the pdf back from a RooWorkspace (it will end in an ugly segfault). For example for RooExpAndGauss: You need to define a standard constructor in your Pdf-class, so it can be stored in (and retrieved from) a RooWorkspace. However, this standard constructor must initialize all the necessary variables, otherwise you will not be able to retrieve the pdf back from a RooWorkspace (it will end in an ugly segfault). For example for RooExpAndGauss:
 <code C> <code C>
Line 52: Line 52:
    
 </code> </code>
 +you need to define something like:
 +<code C>
 + RooExpAndGauss::RooExpAndGauss()
 + {
 +   RooRealVar xRV("xRV","x", 0.0, 1.0);
 +   RooRealVar sh_meanRV("sh_meanRV", "sh_mean", 0.0, 1.0);
 +   RooRealVar sh_sigmaRV("sh_sigmaRV","sh_sigma", 0.0, 1.0);
 +   RooRealVar sh_transRV("sh_transRV","sh_trans", 0.0, 1.0);
  
 +   RooExpAndGauss("RooExpAndGauss", "RooExpAndGauss", xRV, sh_meanRV, sh_sigmaRV, sh_transRV);
 +}
 +</code>
 +to initialize the member variables (which are use in the evaluate-method).
  
 +You then can compile the class as all other private classes and add the library to you rootlogon to have it at hand.
  
 +**Note:** Make sure you have set the number in "ClassDef(myClass, number)" to something larger than 0. Otherwise the class won't allow I/O.
  
- +**Note:** Don't even think of using the constructor "x("x","x"this,other.x)" in the copy constructor of your class. It will compile but will ever let you wonder why it segfaults afterwards (http://root.cern.ch/phpBB3/viewtopic.php?f=15&t=12788)
- you need to define something like: +
-<code C> +
- +
- +
  
  
root/custompdfsandworkspace.1327762339.txt.gz · Last modified: 2012/01/28 15:52 by decianm