3 Make histograms to use for testing the validation system. 5 Original author: J. Wolcott <jwolcott@fnal.gov> 15 OUTDIR =
"/nova/ana/users/jwolcott/mc_valid/new_test" 27 MOCK_DATA_DATASETS = [
31 COMPONENT_DISTRIBUTIONS = [
33 "TMath::Landau(x-2, 1)",
34 "2*TMath::Student(3*x, 5)",
36 sum_f = ROOT.TF1(
"fsum",
" + ".join(COMPONENT_DISTRIBUTIONS), 0, 5)
37 integral = sum_f.Integral(0, 5)
40 COMPONENT_FUNCTIONS = [ ROOT.TF1(
"%f * f%d" % (1./integral, fnum), distr, 0, 5)
for fnum, distr
in enumerate(COMPONENT_DISTRIBUTIONS) ]
41 thresholds = [f.Integral(0, 5)/integral
for f
in COMPONENT_FUNCTIONS]
42 for i
in range(1, len(thresholds)):
43 thresholds[i] += thresholds[i-1]
45 for dataset_name, num_evts
in DATASET_NUMEVTS.iteritems():
46 outf = ROOT.TFile( os.path.join(OUTDIR,
"test_hists_%s.root" % dataset_name),
"recreate" )
47 assert not outf.IsZombie()
50 if dataset_name
in MOCK_DATA_DATASETS:
51 hists.append(ROOT.TH1D(
"dir1/h_var",
"Test ariable;Var (unit);Events", 50, 0, 5))
53 for hist_num
in range(len(COMPONENT_FUNCTIONS)):
54 hists.append(ROOT.TH1D(
"dir1/h_var{cat%d}" % hist_num,
"Test variable;Var (unit);Events", 50, 0, 5))
56 for evt_num
in xrange(
int(num_evts)):
59 for distr_num, threshold
in enumerate(thresholds):
60 if rnd < threshold
or distr_num == len(thresholds)-1:
64 val = COMPONENT_FUNCTIONS[distr_num].GetRandom()
65 h = hists[distr_num]
if len(hists) == len(COMPONENT_DISTRIBUTIONS)
else hists[0]