forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_ntuple_to_file_advanced.C
34 lines (28 loc) · 1.23 KB
/
write_ntuple_to_file_advanced.C
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
// Fill an n-tuple and write it to a file simulating measurement of
// conductivity of a material in different conditions of pressure
// and temperature using branches.
void write_ntuple_to_file_advanced(
const std::string& outputFileName="conductivity_experiment.root"
,unsigned int numDataPoints=1000000){
TFile ofile(outputFileName.c_str(),"RECREATE");
// Initialise the TNtuple
TTree cond_data("cond_data", "Example N-Tuple");
// define the variables and book them for the ntuple
float pot,cur,temp,pres;
cond_data.Branch("Potential", &pot, "Potential/F");
cond_data.Branch("Current", &cur, "Current/F");
cond_data.Branch("Temperature", &temp, "Temperature/F");
cond_data.Branch("Pressure", &pres, "Pressure/F");
for (int i=0;i<numDataPoints;++i){
// Fill it randomly to fake the acquired data
pot=gRandom->Uniform(0.,10.)*gRandom->Gaus(1.,0.01);
temp=gRandom->Uniform(250.,350.)+gRandom->Gaus(0.,0.3);
pres=gRandom->Uniform(0.5,1.5)*gRandom->Gaus(1.,0.02);
cur=pot/(10.+0.05*(temp-300.)-0.2*(pres-1.))*
gRandom->Gaus(1.,0.01);
// write to ntuple
cond_data.Fill();}
// Save the ntuple and close the file
cond_data.Write();
ofile.Close();
}