Logo ROOT   6.12/07
Reference Guide
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 
13 /*
14 BEGIN_HTML
15 <p>
16 </p>
17 END_HTML
18 */
19 //
20 
21 #include "RooRealVar.h"
23 
25 
27 
28  // Here is where we set the values, and constantness
29  // of all parameters in the workspace before creating
30  // an asimov dataset
31 
32  /*
33  // Okay, y'all, first we're going to create a snapshot
34  // of the current state of the variables in the workspace
35 
36  std::string ListOfVariableNames = "";
37  for( std::map< std::string, double >::iterator itr = fParamValsToSet.begin();
38  itr != fParamValsToSet.end(); ++itr) {
39  // Extend the Variable Name list
40  ListOfVariableNames += "," + itr->first;
41  }
42  for( std::map< std::string, bool >::iterator itr = fParamsToFix.begin();
43  itr != fParamsToFix.end(); ++itr) {
44  // Extend the Variable Name list
45  ListOfVariableNames += "," + itr->first;
46  }
47 
48  // Save a snapshot
49  std::string SnapShotName = "NominalParamValues";
50  wspace->saveSnapshot(SnapShotName.c_str(), ListOfVariableNames.c_str());
51  */
52 
53  //
54  // First we set all parameters to their given values
55  //
56 
57 
58  for( std::map< std::string, double >::iterator itr = fParamValsToSet.begin();
59  itr != fParamValsToSet.end(); ++itr) {
60 
61  std::string param = itr->first;
62  double val = itr->second;
63 
64  // Try to get the variable in the workspace
65  RooRealVar* var = wspace->var(param.c_str());
66  if( !var ) {
67  std::cout << "Error: Trying to set variable: " << var
68  << " to a specific value in creation of asimov dataset: " << fName
69  << " but this variable doesn't appear to exist in the workspace"
70  << std::endl;
71  throw hf_exc();
72  }
73 
74  // Check that the desired value is in the range of the variable
75  double inRange = var->inRange(val, NULL);
76  if( !inRange ) {
77  std::cout << "Error: Attempting to set variable: " << var
78  << " to value: " << val << ", however it appears"
79  << " that this is not withn the variable's range: "
80  << "[" << var->getMin() << ", " << var->getMax() << "]"
81  << std::endl;
82  throw hf_exc();
83  }
84 
85  // Set its value
86  std::cout << "Configuring Asimov Dataset: Setting " << param
87  << " = " << val << std::endl;
88  var->setVal( val );
89  }
90 
91 
92  //
93  // Then, we set any variables to constant
94  //
95 
96  for( std::map< std::string, bool >::iterator itr = fParamsToFix.begin();
97  itr != fParamsToFix.end(); ++itr) {
98 
99  std::string param = itr->first;
100  bool isConstant = itr->second;
101 
102  // Try to get the variable in the workspace
103  RooRealVar* var = wspace->var(param.c_str());
104  if( !var ) {
105  std::cout << "Error: Trying to set variable: " << var
106  << " constant in creation of asimov dataset: " << fName
107  << " but this variable doesn't appear to exist in the workspace"
108  << std::endl;
109  throw hf_exc();
110  }
111 
112  std::cout << "Configuring Asimov Dataset: Setting " << param
113  << " to constant " << std::endl;
114  var->setConstant( isConstant );
115 
116  }
117 
118  return;
119 
120 }
virtual Double_t getMin(const char *name=0) const
virtual Double_t getMax(const char *name=0) const
void ConfigureWorkspace(RooWorkspace *)
Definition: Asimov.cxx:26
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
std::map< std::string, double > fParamValsToSet
Definition: Asimov.h:46
virtual void setVal(Double_t value)
Set value of variable to &#39;value&#39;.
Definition: RooRealVar.cxx:205
void setConstant(Bool_t value=kTRUE)
std::map< std::string, bool > fParamsToFix
Definition: Asimov.h:45
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found...
virtual Bool_t inRange(const char *name) const
Check if current value is inside range with given name.
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42