31from warnings
import warn
39 def __init__(self, **entries):
40 self.__dict__.
update(entries)
50 enableDetailedOutput=
True,
53optHT = HypoTestOptions
56def StandardHypoTestDemo(
58 workspaceName="combined",
59 modelSBName="ModelConfig",
124 filename =
"results/example_combined_GaussExample_model.root"
129 print(
"will run standard hist2workspace example")
132 print(
"\n\n---------------------")
133 print(
"Done creating example input")
134 print(
"---------------------\n\n")
144 print(f
"StandardRooStatsDemoMacro: Input file {filename} is not found")
154 print(f
"workspace not found")
160 sbModel =
w.obj(modelSBName)
166 if not data
or not sbModel:
168 print(f
"data or ModelConfig was not found")
172 bModel =
w.obj(modelBName)
179 print(f
"StandardHypoTestInvDemo")
180 print(
" - Switch off all systematics by setting them constant to their initial values")
189 ROOT.Info(
"StandardHypoTestInvDemo",
"The background model {} does not exist".
format(modelBName))
190 ROOT.Info(
"StandardHypoTestInvDemo",
"Copy it from ModelConfig {} and set POI to zero".
format(modelSBName))
203 ROOT.Info(
"StandardHypoTestDemo",
"Model {} has no snapshot - make one using model poi".
format(modelSBName))
234 if testStatType == 3:
261 (hypoCalc).StoreFitInfo(
True)
268 if testStatType == 3:
270 elif testStatType != 2
and testStatType != 3:
272 "StandardHypoTestDemo",
273 "Only the PL test statistic can be used with AsymptoticCalculator - use by default a two-sided PL",
280 nuisPdf =
w.pdf(nuisPriorName)
284 "StandardHypoTestDemo",
285 "No nuisance pdf given for the HybridCalculator - try to deduce pdf from the model",
296 "StandardHypoTestDemo",
297 "No nuisance pdf given - try to use %s that is defined as a prior pdf in the B model",
302 "StandardHypoTestDemo",
303 "Cannot run Hybrid calculator because no prior on the nuisance parameter is "
304 "specified or can be derived",
309 ROOT.Info(
"StandardHypoTestDemo",
"Using as nuisance Pdf ... ")
318 "StandardHypoTestDemo",
319 "Prior nuisance does not depend on nuisance parameters. They will be smeared in their full range",
331 if sampler
and (calcType == 0
or calcType == 1):
336 warn(
"StandardHypoTestDemo",
"Pdf is extended: but number counting flag is set: ignore it ")
342 "StandardHypoTestDemo",
343 "Pdf is not extended: number of events to generate taken from observed data set is {nEvents}",
347 ROOT.Info(
"StandardHypoTestDemo",
"using a number counting pdf")
351 msgfmt =
"Data set is weighted, nentries = {} and sum of weights = {:8.1f} but toy ".
format(
354 msgfmt +=
"generation is unbinned - it would be faster to set generateBinned to True\n"
356 ROOT.Info(
"StandardHypoTestDemo", msgfmt)
362 if testStatType == 0:
364 if testStatType == 1:
366 if testStatType == 2
or testStatType == 3:
389 print(
"Asymptotic results ")
412 " Expected p -value and significance at ",
430 " Expected p -value and significance at ",
440 writeResult = calcType != 2
444 ROOT.Info(
"StandardHypoTestDemo",
"Detailed output will be written in output result file")
449 calcTypeName =
"Freq" if (calcType == 0)
else (
"Hybr" if (calcType == 1)
else (
"Asym"))
455 resultFileName += name
457 fileOut =
ROOT.TFile(str(resultFileName),
"RECREATE")
470workspaceName =
"combined"
471modelSBName =
"ModelConfig"
483 infile, workspaceName, modelSBName, modelBName, dataName, calcType, testStatType, ntoys, useNC, nuisPriorName
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format