Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Asimov.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, George Lewis
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11////////////////////////////////////////////////////////////////////////////////
12/** \class RooStats::HistFactory::Asimov
13 * \ingroup HistFactory
14 * TODO Here, we are missing some documentation.
15*/
16
17#include "RooRealVar.h"
19
21
23
24 // Here is where we set the values, and constantness
25 // of all parameters in the workspace before creating
26 // an asimov dataset
27
28 /*
29 // Okay, y'all, first we're going to create a snapshot
30 // of the current state of the variables in the workspace
31
32 std::string ListOfVariableNames = "";
33 for( std::map< std::string, double >::iterator itr = fParamValsToSet.begin();
34 itr != fParamValsToSet.end(); ++itr) {
35 // Extend the Variable Name list
36 ListOfVariableNames += "," + itr->first;
37 }
38 for( std::map< std::string, bool >::iterator itr = fParamsToFix.begin();
39 itr != fParamsToFix.end(); ++itr) {
40 // Extend the Variable Name list
41 ListOfVariableNames += "," + itr->first;
42 }
43
44 // Save a snapshot
45 std::string SnapShotName = "NominalParamValues";
46 wspace->saveSnapshot(SnapShotName.c_str(), ListOfVariableNames.c_str());
47 */
48
49 //
50 // First we set all parameters to their given values
51 //
52
53
54 for( std::map< std::string, double >::iterator itr = fParamValsToSet.begin();
55 itr != fParamValsToSet.end(); ++itr) {
56
57 std::string param = itr->first;
58 double val = itr->second;
59
60 // Try to get the variable in the workspace
61 RooRealVar* var = wspace->var(param.c_str());
62 if( !var ) {
63 std::cout << "Error: Trying to set variable: " << var
64 << " to a specific value in creation of asimov dataset: " << fName
65 << " but this variable doesn't appear to exist in the workspace"
66 << std::endl;
67 throw hf_exc();
68 }
69
70 // Check that the desired value is in the range of the variable
71 double inRange = var->inRange(val, NULL);
72 if( !inRange ) {
73 std::cout << "Error: Attempting to set variable: " << var
74 << " to value: " << val << ", however it appears"
75 << " that this is not withn the variable's range: "
76 << "[" << var->getMin() << ", " << var->getMax() << "]"
77 << std::endl;
78 throw hf_exc();
79 }
80
81 // Set its value
82 std::cout << "Configuring Asimov Dataset: Setting " << param
83 << " = " << val << std::endl;
84 var->setVal( val );
85 }
86
87
88 //
89 // Then, we set any variables to constant
90 //
91
92 for( std::map< std::string, bool >::iterator itr = fParamsToFix.begin();
93 itr != fParamsToFix.end(); ++itr) {
94
95 std::string param = itr->first;
96 bool isConstant = itr->second;
97
98 // Try to get the variable in the workspace
99 RooRealVar* var = wspace->var(param.c_str());
100 if( !var ) {
101 std::cout << "Error: Trying to set variable: " << var
102 << " constant in creation of asimov dataset: " << fName
103 << " but this variable doesn't appear to exist in the workspace"
104 << std::endl;
105 throw hf_exc();
106 }
107
108 std::cout << "Configuring Asimov Dataset: Setting " << param
109 << " to constant " << std::endl;
110 var->setConstant( isConstant );
111
112 }
113
114 return;
115
116}
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual Bool_t inRange(const char *name) const
Check if current value is inside range with given name.
void setConstant(Bool_t value=kTRUE)
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual void setVal(Double_t value)
Set value of variable to 'value'.
std::map< std::string, double > fParamValsToSet
Definition Asimov.h:45
void ConfigureWorkspace(RooWorkspace *)
Definition Asimov.cxx:22
std::map< std::string, bool > fParamsToFix
Definition Asimov.h:44
The RooWorkspace is a persistable container for RooFit projects.
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.