File: samplefiles.C

package info (click to toggle)
labplot 2.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,528 kB
  • sloc: cpp: 241,047; ansic: 6,324; python: 915; xml: 400; yacc: 237; sh: 221; awk: 35; makefile: 11
file content (95 lines) | stat: -rw-r--r-- 2,432 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
    File                 : samplefiles.C
    Project              : LabPlot
    Description          : ROOT script to create test files for ROOT importer
    -------------------------------------------------------------------------
    SPDX-FileCopyrightText: 2018 Christoph Roick <chrisito@gmx.de>
    SPDX-License-Identifier: GPL-2.0-or-later
*/

// ROOT test files are regenerated by calling 'root samplefiles.C'.
// Note that creation date and random numbers will be different in the new files.

void samplefiles()
{
	TFile fBasic("basic_lz4.root", "RECREATE");
	fBasic.SetCompressionAlgorithm(ROOT::kLZ4);

	TH1D doubleHist("doubleHist", "", 100, -5., 5.);
	doubleHist.Sumw2();
	doubleHist.FillRandom("gaus", 10000);
	doubleHist.Write();

	TH1F floatHist("floatHist", "", 100, -5., 5.);
	floatHist.Sumw2();
	floatHist.FillRandom("gaus", 10000);
	floatHist.Write();

	TH1I intHist("intHist", "", 100, -5., 5.);
	intHist.Sumw2();
	intHist.FillRandom("gaus", 10000);
	intHist.Write();

	TH1S shortHist("shortHist", "", 100, -5., 5.);
	shortHist.Sumw2();
	shortHist.FillRandom("gaus", 10000);
	shortHist.Write();

	TH1C charHist("charHist", "", 100, -5., 5.);
	charHist.Sumw2();
	charHist.FillRandom("gaus", 1000);
	charHist.Write();

	fBasic.Close();

	TFile fAdvanced("advanced_zlib.root", "RECREATE");
	fAdvanced.SetCompressionAlgorithm(ROOT::kZLIB);

	vector<double> borders;
	for (size_t i = 0; i < 101; ++i)
		borders.push_back(0.09 * i - 5. + 1.e-4 * i * i);

	TH1D variableBinHist("variableBinHist", "", 100, borders.data());
	variableBinHist.Sumw2();
	variableBinHist.FillRandom("gaus", 10000);
	variableBinHist.Write();
	variableBinHist.FillRandom("gaus", 1000000);
	variableBinHist.Write();

	TTree tree("tree", "TTree title");
	double d;
	int i;
	struct {
		int a[2];
		Double_t d;
		float f;
	} s;
	tree.Branch("doubleTest", &d, "doubleTest/D");
	tree.Branch("intTest", &i, "intTest/I");
	tree.Branch("structTest", &s, "array[2]/I:double/D:float/F");

	for (size_t j = 0; j < 10; ++j) {
		d = j;
		i = j;
		s.f = 9 - j;
		s.a[0] = j; s.a[1] = 2 * j;
		s.d = s.f * s.f;
		tree.Fill();
	}
	tree.Write();

	TNtuple tuple("tuple", "TNtuple title", "x:y:z");
	tuple.Fill(1., 2., 3.);
	tuple.Write();
	tuple.Fill(3., 4., 5.);
	tuple.Write();

	fAdvanced.Close();

	ifstream infile("basic_lz4.root");
	ofstream outfile("broken_basic.root");

	char buffer[3000];
	infile.read(buffer, 3000);
	outfile.write(buffer, 3000);
}