Logo ROOT   6.12/07
Reference Guide
ModifyInterpolation.C
Go to the documentation of this file.
1 /*
2 An example script to modify the interpolation used in HistFactory models.
3 Usage:
4 
5 make the standard example workspace with histfactory
6 $ prepareHistFactory
7 $ hist2workspace config/example.xml
8 
9 inspect file (note we are using the model with Gaussian constraints)
10 $ root.exe results/example_combined_GaussExample_model.root
11 root [1] combined->Print()
12 
13 notice there is a new class in the new version:
14 RooStats::HistFactory::FlexibleInterpVar::background1_channel1_epsilon[ paramList=(alpha_syst2) ] = 0.999209
15 
16 You only need this macro if you don't want the CMS style normalization interpolation.
17 
18 root [2] .L $ROOTSYS/tutorials/histfactory/ModifyInterpolation.C+
19 root [3] CheckInterpolation(combined)
20 [#1] INFO:InputArguments -- interp code for alpha_syst1 = 1
21 [#1] INFO:InputArguments -- interp code for alpha_syst2 = 1
22 [#1] INFO:InputArguments -- interp code for alpha_syst3 = 1
23 
24 One can change the interpolation for a specific set of parameters
25 root [5] combined->set("ModelConfig_NuisParams")->Print()
26 RooArgSet:: = (alpha_syst2,alpha_syst3)
27 root [6] ModifyInterpolationForSet(combined->set("ModelConfig_NuisParams"),2)
28 root [7] CheckInterpolation(combined)
29 [#1] INFO:InputArguments -- interp code for alpha_syst1 = 1
30 [#1] INFO:InputArguments -- interp code for alpha_syst2 = 2
31 [#1] INFO:InputArguments -- interp code for alpha_syst3 = 2
32 
33 Or one can change the interpolation type for all the parameters:
34 root [11] ModifyInterpolationForAll(combined,2)
35 root [12] CheckInterpolation(combined)
36 [#1] INFO:InputArguments -- interp code for alpha_syst1 = 2
37 [#1] INFO:InputArguments -- interp code for alpha_syst2 = 2
38 [#1] INFO:InputArguments -- interp code for alpha_syst3 = 2
39 
40 and then you can save the workspace with those modifications
41 root [13] combined->writeToFile("testModified.root")
42 
43 then test to make sure the changes are in the file
44 $ root.exe testModified.root
45 root [1] .L $ROOTSYS/tutorials/histfactory/ModifyInterpolation.C+
46 root [2] CheckInterpolation(combined)
47 [#1] INFO:InputArguments -- interp code for alpha_syst1 = 2
48 [#1] INFO:InputArguments -- interp code for alpha_syst2 = 2
49 [#1] INFO:InputArguments -- interp code for alpha_syst3 = 2
50 */
51 #include "RooRealVar.h"
52 #include "TIterator.h"
53 #include "RooWorkspace.h"
55 
56 using namespace RooStats;
57 using namespace HistFactory;
58 
59 // define functions for ACLIC
60 void ModifyInterpolationForAll(RooWorkspace* ws, int code=1);
61 void ModifyInterpolationForSet(RooArgSet* modifySet, int code = 1);
63 
64 // Codes for interpolation
65 // code = 0: piece-wise linear
66 // code = 1: pice-wise log
67 // code = 2: parabolic interp with linear extrap
68 // code = 3: parabolic version of log-normal
69 
71  cout <<"Choose from the following"<<endl;
72  cout <<"void ModifyInterpolationForAll(RooWorkspace* ws, int code=1);"<<endl;
73  cout <<"void ModifyInterpolationForSet(RooArgSet* modifySet, int code = 1);"<<endl;
74  cout <<"void CheckInterpolation(RooWorkspace* ws);"<<endl;
75 }
76 
78  RooArgSet funcs = ws->allFunctions();
79  TIterator* it = funcs.createIterator();
80  TObject* tempObj=0;
81  while((tempObj=it->Next())){
82  FlexibleInterpVar* flex = dynamic_cast<FlexibleInterpVar*>(tempObj);
83  if(flex){
84  flex->setAllInterpCodes(code);
85  }
86  }
87 }
88 
89 void ModifyInterpolationForSet(RooArgSet* modifySet, int code){
90 
91  TIterator* it = modifySet->createIterator();
92  RooRealVar* alpha=0;
93  while((alpha=(RooRealVar*)it->Next())){
94  TIterator* serverIt = alpha->clientIterator();
95  TObject* tempObj=0;
96  while((tempObj=serverIt->Next())){
97  FlexibleInterpVar* flex = dynamic_cast<FlexibleInterpVar*>(tempObj);
98  if(flex){
99  flex->printAllInterpCodes();
100  flex->setInterpCode(*alpha,code);
101  flex->printAllInterpCodes();
102  }
103  }
104  }
105 
106 }
107 
108 
110  RooArgSet funcs = ws->allFunctions();
111  TIterator* it = funcs.createIterator();
112  TObject* tempObj=0;
113  while((tempObj=it->Next())){
114  FlexibleInterpVar* flex = dynamic_cast<FlexibleInterpVar*>(tempObj);
115  if(flex){
116  flex->printAllInterpCodes();
117  }
118  }
119 }
TIterator * createIterator(Bool_t dir=kIterForward) const
void ws()
Definition: ws.C:62
void setInterpCode(RooAbsReal &param, int code)
Iterator abstract base class.
Definition: TIterator.h:30
RooArgSet allFunctions() const
Return set with all function objects.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
void ModifyInterpolationForSet(RooArgSet *modifySet, int code=1)
void CheckInterpolation(RooWorkspace *ws)
Namespace for the RooStats classes.
Definition: Asimov.h:20
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Next()=0
void ModifyInterpolation()
void ModifyInterpolationForAll(RooWorkspace *ws, int code=1)
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42
TIterator * clientIterator() const
Definition: RooAbsArg.h:100