export ROOTSYS=/data/ppe01/sl5x/x86_64/root/5.32.00 export PATH=$ROOTSYS/bin:$PATH export LD_LIBRARY_PATH=$ROOTSYS/lib/root:$LD_LIBRARY_PATH
. /afs/cern.ch/sw/lcg/external/gcc/4.3.2/x86_64-slc5/setup.sh cd /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.00/x86_64-slc5-gcc43-opt/root/ . bin/thisroot.sh
On a MacBook Pro 7, 1 running Ubuntu 11.04, the compilation takes ~ 1 hour. Following the compilation, the ROOT environment variables can be set up. In Ubuntu or Scientific Linux, the following lines could be added to the ~/.bashrc file:#!/bin/bash # This script builds the latest version of ROOT with RooFit and RooStats in Ubuntu. # First, the ROOT prerequisites are installed, # then, the most common ROOT optional packages are installed. # Next, the latest version of ROOT in the CERN Subversion repository is checked out. # Finally, ROOT is compiled. # Install ROOT prerequisites. sudo apt-get install subversion sudo apt-get install make sudo apt-get install g++ sudo apt-get install gcc sudo apt-get install binutils sudo apt-get install libx11-dev sudo apt-get install libxpm-dev sudo apt-get install libxft-dev sudo apt-get install libxext-dev # Install optional ROOT packages. sudo apt-get install gfortran sudo apt-get install ncurses-dev sudo apt-get install libpcre3-dev sudo apt-get install xlibmesa-glu-dev sudo apt-get install libglew1.5-dev sudo apt-get install libftgl-dev sudo apt-get install libmysqlclient-dev sudo apt-get install libfftw3-dev sudo apt-get install cfitsio-dev sudo apt-get install graphviz-dev sudo apt-get install libavahi-compat-libdnssd-dev sudo apt-get install libldap-dev sudo apt-get install python-dev sudo apt-get install libxml2-dev sudo apt-get install libssl-dev sudo apt-get install libgsl0-dev # Check out the latest ROOT trunk. svn co http://root.cern.ch/svn/root/trunk /usr/local/root # Configure the build. cd /usr/local/root # Configure for the system architecture and configure to build the libRooFit advanced fitting package as part of the compilation. ./configure linuxx8664gcc --enable-roofit # See other possible configurations using the following command: ./configure --help # Compile. make
export ROOTSYS=/usr/local/root export PATH=$ROOTSYS/bin:$PATH export LD_LIBRARY_PATH=$ROOTSYS/lib/root:$LD_LIBRARY_PATH
Mathematical concept | RooFit class |
---|---|
variable | RooRealVar |
function | RooAbsReal |
RooAbsPdf | |
space point (set of parameters) | RooArgSet |
list of space points | RooAbsData |
integral | RooRealIntegral |
General form for defining a RooFit variable: RooRealVar x(<object name>, <object title>, <value>, <minimum value>, <maximum value>) Specific example for defining a RooFit variable x with the value 5: RooRealVar x("x", "x observable", 5, -10, 10)
{ // Build a Gaussian PDF. RooRealVar x("x", "x", -10, 10); RooRealVar mean("mean", "mean of Gaussian", 0, -10, 10); RooRealVar sigma("sigma", "width of Gaussian", 3); RooGaussian gauss("gauss", "Gaussian PDF", x, mean, sigma); // Plot the PDF. RooPlot* xframe = x.frame(); gauss.plotOn(xframe); xframe->Draw(); }
Not normalised (i.e., this is not a PDF): gauss.getVal(); Hey, RooFit! This is the thing to normalise over (i.e., guarantees Int[xmin, xmax] Gauss(x, m, s)dx == 1): gauss.getVal(x); What is the value if sigma is considered the observable? (i.e., guarantees Int[smin, smax] Gauss(x, m, s)ds == 1):
Plotting unbinned data is similar to plotting binned data with the exception that one can display it in some preferred binning.} // Create a RooDataSet and fill it with generated toy Monte Carlo data: RooDataSet* myData = gauss.generate(x, 100); // Plot the dataset. RooPlot* myFrame = x.frame(); myData.plotOn()(myFrame); myFrame.Draw(); }
RooPlot* myFrame = x.frame() ; myData.plotOn(myFrame, Binning(25)) ; myFrame->Draw()
{ // Access the file. TFile* myFile = new TFile("myFile.root"); // Load the histogram. TH1* myHistogram = (TH1*) myFile->Get("myHistogram"); // Draw the loaded histogram. myHistogram.Draw(); // Declare an observable x. RooRealVar x("x", "x", -1, 2); // Create a binned dataset that imports the contents of TH1 and associates its contents to observable 'x'. RooDataHist myData("myData", "myData", RooArgList(x), myHistogram); // Plot the imported dataset. RooPlot* myFrame = x.frame(); myData.plotOn(myFrame) myFrame.Draw() }
// Fit gauss to unbinned data gauss.fitTo(*myData);
// Create a Gaussian PDF using the Workspace Factory (this is essentially the shorthand for creating a Gaussian). RooWorkspace* myWorkspace = new RooWorkspace("myWorkspace"); myWorkspace->factory("Gaussian::g(x[-5, 5], mu[0], sigma[1]");
// Open the appropriate ROOT file. root -l myFile.root // Import the workspace. myWorkspace = (RooWorkspace*) _file0->Get("myWorkspace"); // Print the workspace contents. myWorkspace.Print(); // Example printout: // variables // --------- // (x,m,s) // // p.d.f.s // ------- // RooGaussian::g[ x=x mean=m sigma=s ] = 0 // // datasets // -------- // RooDataSet::d(x) // Import the variable saved as x. RooRealVar* myVariable = myWorkspace.var("x"); // Import the PDF saved as g. RooAbsPdf* myPDF = myWorkspace.pdf("g"); // Import the data saved as d. RooAbsData* myData = myWorkspace.data("d"); // Import the ModelConfig saved as m. ModelConfig* myModelConfig = (ModelConfig*) myWorkspace.obj("m");
// Create variables and a PDF using those variables. RooRealVar mu("mu", "mu", 150); RooRealVar sigma("sigma", "sigma", 5, 0, 20); RooGaussian myGaussianPDF("myGaussianPDF", "Gaussian PDF", x, mu, sigma); // Create a Graphviz DOT file with a representation of the object tree. myGaussianPDF.graphVizTree("myGaussianPDFTree.dot"); // This produced DOT file can be converted to some graphical representation: // Convert the DOT file to a 'top-to-bottom graph' using UNIX commands: // dot -Tgif -o myGaussianPDF_top-to-bottom_graph.gif myGaussianPDFTree.dot // Convert the DOT file to a 'spring-model graph' using UNIX commands: // fdp -Tgif -o myGaussianPDF_spring-model_graph.gif myGaussianPDFTree.dot // Print the PDF contents. myGaussianPDF.Print(); // Example output: // RooGaussian::G[ x=x mean=mu sigma=sigma ] = 1 // sigma.Print() // RooRealVar::sigma = 5 L(0 - 20) // Print the PDF contents in a detailed manner. myGaussianPDF.Print("verbose"); // Print the PDF contents to stdout. myGaussianPDF.Print("t"); // Example output: // 0x166eab0 RooGaussian::G = 1 [Auto] // 0x15f7fe0/V- RooRealVar::x = 150 // 0x1487090/V- RooRealVar::mu = 150 // 0x1487bc0/V- RooRealVar::sigma = 5 // Print the PDF contents to a file. myGaussianPDF.printCompactTree("", "myGaussianPDFTree.txt") // Example output file contents: // 0x166eab0 RooGaussian::G = 1 [Auto] // 0x15f7fe0/V- RooRealVar::x = 150 // 0x1487090/V- RooRealVar::mu = 150 // 0x1487bc0/V- RooRealVar::sigma = 5
void ModelInspector(const char* infile = "", const char* workspaceName = "combined", const char* modelConfigName = "ModelConfig", const char* dataName = "obsData")If the workspace(s) were made using hist2workspace, the names have a standard form (as shown above).
// Load the macro. root -L ModelInspector.C++ // Run the macro on the appropriate ROOT workspace file. ModelInspector("results/my_combined_example_model.root")The Model Inspector GUI should appear. The GUI consists of a number of plots, corresponding to the various channels in the model, and a few sliders, corresponding to the parameters of interest and the nuisance parameters in the model. The initial plots are based on the values of the parameters in the workspace. There is a little "Fit" button which fits the model to the data points (while also printing the standard terminal output detailing the fitting). After fitting, a yellow band is shown around the best fit model indicating the uncertainty from propagating the uncertainty of the fit through the model. On the plots, there is a red line shown (corresponding to the fit for each of the parameters at their nominal value pushed up by 1 sigma).
// Open the appropriate ROOT file. root -l BR5_MSSM_signal90_combined_datastat_model.root // Alternatively, you could open the file in a manner such as the following: myFileName = "BR5_MSSM_signal90_combined_datastat_model.root" TFile *myFile = TFile::Open(myFileName); // Import the workspace. RooWorkspace* myWorkspace = (RooWorkspace*) _file0->Get("combined"); // Print the workspace contents. myWorkspace->Print(); // Import the PDF. RooAbsPdf* myPDF = myWorkspace->pdf("model_BR5_MSSM_signal90"); // Import the variable representing the observable. RooRealVar* myObservable = myWorkspace->var("obs"); // Create a RooPlot frame using the imported variable.. RooPlot* myFrame = myObservable.frame(); // Plot the PDF on the created RooPlot frame. myPDF.plotOn(myFrame); // Draw the RooPlot. myFrame->Draw();
// Note that the following code is independent of actual PDF in the file. So, for example, a full Higgs combination could work with identical code. // Open a file and import the workspace. TFile myFile("myResults.root") ; RooWorkspace* myWorkspace = f.Get("myWorkspace") ; // Plot the data and PDF RooPlot* xframe = w->var("x")->frame() ; w->data("d")->plotOn(xframe) ; w->pdf("g")->plotOn(xframe) ; // Construct a likelihood and profile likelihood RooNLLVar nll("nll","nll",*myWorkspace->pdf("g"),*w->data("d")) ; RooProfileLL pll("pll","pll", nll,*myWorkspace->var("m")) ; RooPlot* myFrame = w->var("m")->frame(-1,1) ; pll.plotOn(myFrame) ; myFrame->Draw()
{ // In this script, a simple model is created using the Workspace Factory in RooFit. // ModelConfig is used to specify the parts of the model necessary for the statistical tools of RooStats. // A 95% confidence interval test is run using the ProfileLikelihoodCalculator of RooStats. // Define a RooFit random seed in order to produce reproducible results. RooRandom::randomGenerator()->SetSeed(271); // Make a simple model using the Workspace Factory. // Create a new workspace. RooWorkspace* myWorkspace = new RooWorkspace(); // Create the PDF G(x|mu,1) and the variables x, mu and sigma in one command using the factory syntax. myWorkspace->factory("Gaussian::normal(x[-10,10], mu[-1,1], sigma[1])"); // Define parameter sets for observables and parameters of interest. myWorkspace->defineSet("poi","mu"); myWorkspace->defineSet("obs","x"); // Print the workspace contents. myWorkspace->Print() ; // Specify for the statistical tools the components of the defined model. // Create a new ModelConfig. ModelConfig* myModelConfig = new ModelConfig("my G(x|mu,1)"); // Specify the workspace. myModelConfig->SetWorkspace(*myWorkspace); // Specify the PDF. myModelConfig->SetPdf(*myWorkspace->pdf("normal")); // Specify the parameters of interest. myModelConfig->SetParametersOfInterest(*myWorkspace->set("poi")); // Specify the observables. myModelConfig->SetObservables(*myWorkspace->set("obs")); // Create a toy dataset. // Create a toy dataset of 100 measurements of the observables (x). RooDataSet* myData = myWorkspace->pdf("normal")->generate(*myWorkspace->set("obs"), 100); //myData->print(); // Use the ProfileLikelihoodCalculator to obtain a 95% confidence interval. // Specify the confidence level required. double confidenceLevel = 0.95; // Create an instance of the ProfileLikelihoodCalculator, specifying the data and the ModelConfig for it. ProfileLikelihoodCalculator myProfileLikelihoodCalculator(*myData, *myModelConfig); // Set the confidence level. myProfileLikelihoodCalculator.SetConfidenceLevel(confidenceLevel); // Obtain the resulting interval. LikelihoodInterval* myProfileLikelihoodInterval = myProfileLikelihoodCalculator.GetInterval(); // Use this interval result. In this case, it makes sense to say what the lower and upper limits are. // Define the object variables for the purposes of the confidence interval. RooRealVar* x = myWorkspace->var("x"); RooRealVar* mu = myWorkspace->var("mu"); cout << "The profile likelihood calculator interval is [ "<< myProfileLikelihoodInterval->LowerLimit(*mu) << ", " << myProfileLikelihoodInterval->UpperLimit(*mu) << "] " << endl; // Set mu equal to zero. mu->setVal(0); // Is mu in the interval? cout << "Is mu = 0 in the interval?" << endl; if (myProfileLikelihoodInterval->IsInInterval(*mu) == 1){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
hist2workspace top_level.xml
<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'> <Combination OutputFilePrefix="./results/example" Mode="comb" > <Input>./config/example_channel.xml</Input> <Measurement Name="GaussExample" Lumi="1." LumiRelErr="0.1" BinLow="0" BinHigh="2" Mode="comb" > <POI>SigXsecOverSM</POI> <ParamSetting Const="True">Lumi alpha_syst1</ParamSetting> <!-- don't need <ConstraintTerm> default is Gaussian--> </Measurement> <Measurement Name="GammaExample" Lumi="1." LumiRelErr="0.1" BinLow="0" BinHigh="2" Mode="comb" > <POI>SigXsecOverSM</POI> <ParamSetting Const="True">Lumi alpha_syst1</ParamSetting> <ConstraintTerm Type="Gamma" RelativeUncertainty=".3">syst2</ConstraintTerm> </Measurement> <Measurement Name="LogNormExample" Lumi="1." LumiRelErr="0.1" BinLow="0" BinHigh="2" Mode="comb" > <POI>SigXsecOverSM</POI> <ParamSetting Const="True">Lumi alpha_syst1</ParamSetting> <ConstraintTerm Type="LogNormal" RelativeUncertainty=".3">syst2</ConstraintTerm> </Measurement> <Measurement Name="ConstExample" Lumi="1." LumiRelErr="0.1" BinLow="0" BinHigh="2" Mode="comb" ExportOnly="True"> <POI>SigXsecOverSM</POI> <ParamSetting Const="True">Lumi alpha_syst1</ParamSetting> </Measurement> </Combination>
<HistoSys Name="myShapeSystematic_1" HistoNameHigh="myShapeSystematic_1_high" HistoNameLow="myShapeSystematic_1_low" />
<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> <Channel Name="channel1" InputFile="./data/example.root" HistoName="" > <Data HistoName="data" HistoPath="" /> <Sample Name="signal" HistoPath="" HistoName="signal"> <OverallSys Name="syst1" High="1.05" Low="0.95"/> <NormFactor Name="SigXsecOverSM" Val="1" Low="0." High="3." Const="True" /> </Sample> <Sample Name="background1" HistoPath="" NormalizeByTheory="True" HistoName="background1"> <OverallSys Name="syst2" Low="0.95" High="1.05"/> </Sample> <Sample Name="background2" HistoPath="" NormalizeByTheory="True" HistoName="background2"> <OverallSys Name="syst3" Low="0.95" High="1.05"/> <!-- <HistoSys Name="syst4" HistoPathHigh="" HistoPathLow="histForSyst4"/>--> </Sample> </Channel>
Generic example | |
---|---|
Type of histogram | Histogram naming convention |
Phenomenon histogram | <phenomenon name>_m<mass point> |
Phenomenon upward systematic histogram | <phenomenon name>_m<mass point>_sys_<systematic name>_up |
Phenomenon downward systematic histogram | <phenomenon name>_m<mass point>_sys_<systematic name>_do |
Specific example | |
---|---|
Type of histogram | Histogram name |
ttH histogram | ttH_m110 |
ttH upward luminosity systematic histogram | ttH_m110_sys_Lumi_up |
ttH downward luminosity systematic histogram | ttH_m110_sys_Lumi_do |
ttH upward JES systematic histogram | ttH_m110_sys_JES_up |
ttH downward JES systematic histogram | ttH_m110_sys_JES_do |
WW Herwig 105987 upward luminosity systematic histogram | WW_Herwig_105987_m110_sys_Lumi_up |
WW Herwig 105987 downward luminosity systematic histogram | WW_Herwig_105987_m110_sys_Lumi_do |
WW Herwig 105987 upward JES systematic histogram | WW_Herwig_105987_m110_sys_JES_up |
WW Herwig 105987 downward JES systematic histogram | WW_Herwig_105987_m110_sys_JES_do |
<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> <!-- channel name and input file --> <Channel Name="ttH_m110" InputFile="data/ttH_histograms.root" HistoName=""> <!-- data --> <Data HistoName="data" /> <!-- signal --> <Sample Name="signal" HistoName="ttH_m110" NormalizeByTheory="False" > <NormFactor Name="SigXsecOverSM" Val="1.0" Low="0.0" High="100." Const="True" /> <!-- systematics: --> <HistoSys Name="Lumi" HistoNameHigh="ttH_m110_sys_Lumi_up" HistoNameLow="ttH_m110_sys_Lumi_do" /> <HistoSys Name="JES" HistoNameHigh="ttH_m110_sys_JES_up" HistoNameLow="ttH_m110_sys_JES_do" /> <OverallSys Name="scale_ttbar" High="1.05" Low="0.95"/> </Sample> <!-- backgrounds --> <!-- WW_Herwig_105987 --> <Sample Name="WW_Herwig_105987" NormalizeByTheory="True" HistoName="WW_Herwig_105987_m110"> </Sample> <!-- Wplusjets --> <Sample Name="Wplusjets" NormalizeByTheory="False" HistoName="Wplusjets_m110"> <!-- systematics --> <HistoSys Name="Lumi" HistoNameHigh="Wplusjets_m110_sys_Lumi_up" HistoNameLow="Wplusjets_m110_sys_Lumi_do" /> <HistoSys Name="JES" HistoNameHigh="Wplusjets_m110_sys_JES_up" HistoNameLow="Wplusjets_m110_sys_JES_do" /> </Sample> </Channel>
<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'> <!-- workspace output file prefix --> <Combination OutputFilePrefix="workspaces/ttH_m110_workspace" Mode="comb" > <!-- channel XML file(s) --> <Input>config/ttH_m110_channel.xml</Input> <!-- measurement and bin range --> <Measurement Name="datastat" Lumi="1" LumiRelErr="0.037" BinLow="0" BinHigh="21" Mode="comb" ExportOnly="True"> <POI>SigXsecOverSM</POI> </Measurement> </Combination>
#!/bin/bash # This script is designed for use with the naming conventions described in the following page: # https://ppes8.physics.gla.ac.uk/twiki/bin/view/ATLAS/HiggsAnalysisAtATLASUsingRooStats # The #userInput hashtag is used to indicate places in the script where the user might modify # things. createXMLFiles() # Arguments: originalMass { originalMass=$1 newMass=$2 # Set/specify the original XML configuration file names. originalChannelXMLFileName=ttH_m${originalMass}_channel.xml originalTopLevelXMLFileName=ttH_m${originalMass}_top-level.xml # Set/specify the new XML configuration file names. newChannelXMLFileName=ttH_m${newMass}_channel.xml newTopLevelXMLFileName=ttH_m${newMass}_top-level.xml # Duplicate the original XML configuration files while substituting the original mass # points with the new mass points in the new resulting file. # Here, the program sed is used to replace all occurrances of a specified pattern in # a specified file with another specified pattern. # The "s" correspondes to "substitute". # The "g" corresponds to "globally" (all instances in a line). sed "s/m$originalMass/m$newMass/g" $originalChannelXMLFileName > $newChannelXMLFileName sed "s/m$originalMass/m$newMass/g" $originalTopLevelXMLFileName > $newTopLevelXMLFileName } # Specify the original mass point. originalMass=110 #userInput # Execute the function for creation of new XML configuration files for all required mass points. createXMLFiles $originalMass 115 #userInput createXMLFiles $originalMass 120 #userInput createXMLFiles $originalMass 125 #userInput createXMLFiles $originalMass 130 #userInput createXMLFiles $originalMass 140 #userInput
cd ~ mkdir test cd testMake the directory for the XML configuration files.
mkdir configMake the directory for the input histogram ROOT files.
mkdir dataMake the directory for the workspace.
mkdir workspaces
cd dataRun some code such as the following. For fun, we will create a simulated data signal at about 126 GeV at about three times the number of events of that which was expected.
{ // Create the expected signal histogram. // Create the function used to describe the signal shape (a simple Gaussian shape). TF1 mySignalFunction("mySignalFunction", "(1/sqrt(2*pi*0.5^2))*2.718^(-(x-126)^2/(2*0.5^2))", 120, 130); // Create the histogram with 100 bins between 120 and 130 GeV. TH1F mySignal("mySignal", "mySignal", 100, 120, 130); // Fill the histogram using the signal function. mySignal.FillRandom("mySignalFunction", 10000000); // Create the background histogram. // Create the function used to describe the signal shape (a simple polynomial of the second order). TF1 myBackgroundFunction("myBackgroundFunction", "-2.3*10^(-6)*x^2+0.0007*x+0.4", 120, 130); // Create the histogram with 100 bins between 120 and 130 GeV. TH1F myBackground("myBackground", "myBackground", 100, 120, 130); // Fill the histogram using the background function. myBackground.FillRandom("myBackgroundFunction", 100000000000); // Create the (simulated) data histogram. This histogram represents what one might have as real data. // Create the histogram using by combining the signal histogram multiplied by 3 with the background histogram. TH1F myData=3*mySignal+myBackground; // Set the name of the histogram. myData->SetName("myData"); // Save the histograms created to a ROOT file. TFile myFile("test_histograms.root", "RECREATE"); mySignal->Write(); myBackground->Write(); myData->Write(); myFile.Close(); }
cd ~/test/configCopy the HistFactory XML schema to the configuration directory.
cp $ROOTSYS/etc/HistFactorySchema.dtd .Create XML configuration files in the configuration directory.
<!DOCTYPE Combination SYSTEM 'HistFactorySchema.dtd'> <!-- workspace output file prefix --> <Combination OutputFilePrefix="./workspaces/test_workspace" Mode="comb" > <!-- channel XML file(s) --> <Input>./config/test_channel.xml</Input> <!-- measurement and bin range --> <Measurement Name="datastat" Lumi="1" LumiRelErr="0.037" BinLow="0" BinHigh="99" Mode="comb" ExportOnly="True"> <POI>SigXsecOverSM</POI> </Measurement> </Combination>
As you can see, the model is very simple. There is the expected signal, the expected background and the actual data (in this case, the data is simulated). The point of interest relates to the signal and the expected data will be compared to the actual data.<!DOCTYPE Channel SYSTEM 'HistFactorySchema.dtd'> <!-- channel name and input file --> <Channel Name="test" InputFile="./data/test_histograms.root" HistoName=""> <!-- data --> <Data HistoName="myData" /> <!-- signal --> <Sample Name="signal" HistoName="mySignal" NormalizeByTheory="True" > <NormFactor Name="SigXsecOverSM" Val="1.0" Low="0.0" High="100." Const="True" /> </Sample> <!-- backgrounds --> <!-- background --> <Sample Name="background" NormalizeByTheory="True" HistoName="myBackground"> </Sample> </Channel>
hist2workspace config/test_top-level.xmlThere should now be created 4 files in the workspaces directory:
test_workspace_combined_datastat_model.root test_workspace_datastat.root test_workspace_results.table test_workspace_test_datastat_model.rootThe test_workspace_combined_datastat_model.root file is the ROOT file that contains the combined workspace object (is has constraints, weightings etc. properly incorporated). This is the file you are almost certainly interested in. The test_workspace_test_datastat_model.root file contains a workspace object without proper constraints, weightings etc. I don't know what the other two files are.
Compile this code using a Makefile such as the following:#include <iostream> #include <fstream> #include <sstream> #include <stdio.h> #include <string.h> #include <cmath> #include "TStyle.h" #include "TROOT.h" #include "TPluginManager.h" #include "TSystem.h" #include "TFile.h" #include "TGaxis.h" #include "TCanvas.h" #include "TH1.h" #include "TF1.h" #include "TLine.h" #include "TSpline.h" #include "RooAbsData.h" #include "RooDataHist.h" #include "RooCategory.h" #include "RooDataSet.h" #include "RooRealVar.h" #include "RooAbsPdf.h" #include "RooSimultaneous.h" #include "RooProdPdf.h" #include "RooNLLVar.h" #include "RooProfileLL.h" #include "RooFitResult.h" #include "RooPlot.h" #include "RooRandom.h" #include "RooMinuit.h" #include "TRandom3.h" #include "RooWorkspace.h" #include "RooStats/RooStatsUtils.h" #include "RooStats/ModelConfig.h" #include "RooStats/ProfileLikelihoodCalculator.h" #include "RooStats/LikelihoodInterval.h" #include "RooStats/LikelihoodIntervalPlot.h" #include "TStopwatch.h" using namespace std; using namespace RooFit; using namespace RooStats; int main(){ // Access the inputs. // Open the ROOT workspace file. TString myInputFileName = "workspaces/test_workspace_combined_datastat_model.root"; cout << "Opening file " << myInputFileName << "..." << endl; TFile *_file0 = TFile::Open(myInputFileName); // Access the workspace. cout << "Accessing workspace..." << endl; RooWorkspace* myWorkspace = (RooWorkspace*) _file0->Get("combined"); // Access the ModelConfig cout << "Accessing ModelConfig..." << endl; ModelConfig* myModelConfig = (ModelConfig*) myWorkspace->obj("ModelConfig"); // Access the data. cout << "Accessing data..." << endl; RooAbsData* myData = myWorkspace->data("obsData"); // Use the ProfileLikelihoodCalculator to calculate the 95% confidence interval on the parameter of interest as specified in the ModelConfig. cout << "Calculating profile likelihood...\n" << endl; ProfileLikelihoodCalculator myProfileLikelihood(*myData, *myModelConfig); myProfileLikelihood.SetConfidenceLevel(0.95); LikelihoodInterval* myConfidenceInterval = myProfileLikelihood.GetInterval(); // Access the confidence interval on the parameter of interest (POI). RooRealVar* myPOI = (RooRealVar*) myModelConfig->GetParametersOfInterest()->first(); // Print the results. cout << "Printing results..." << endl; // Print the confidence interval on the POI. cout << "\n95% confidence interval on the point of interest " << myPOI->GetName()<<": ["<< myConfidenceInterval->LowerLimit(*myPOI) << ", "<< myConfidenceInterval->UpperLimit(*myPOI) <<"]\n"<<endl; return 0; }
Compile the code.ProfileLikeliHoodCalculator_confidence_level.cpp : ProfileLikeliHoodCalculator_confidence_level.cpp g++ -g -O2 -fPIC -Wno-deprecated -o ProfileLikeliHoodCalculator_confidence_level.cpp ProfileLikeliHoodCalculator_confidence_level.cpp `root-config --cflags --libs --ldflags` -lHistFactory -lXMLParser -lRooStats -lRooFit -lRooFitCore -lThread -lMinuit -lFoam -lHtml -lMathMore -I$ROOTSYS/include -L$ROOTSYS/lib
make
95% confidence interval on the point of interest SigXsecOverSM: [2.99653, 3.00347]