-
Notifications
You must be signed in to change notification settings - Fork 0
/
trex1.c
25 lines (24 loc) · 805 Bytes
/
trex1.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
void trex1(){
// Create a ROOT file to store the TTree
TFile *file = TFile::Open("mytree.root", "RECREATE");
// Create a TTree with name "mytree" and a title
TTree *tree = new TTree("mytree", "My TTree example");
// Declare variables to be stored in the TTree
double x, y, z, t;
// Create branches in the TTree for each variable
tree->Branch("x", &x, "x/D");
tree->Branch("y", &y, "y/D");
tree->Branch("z", &z, "z/D");
tree->Branch("t", &t, "t/D");
// Generate data and fill the TTree
for (int i=0; i<10000; ++i){
x= gRandom->Uniform(0,10);
y= gRandom->Gaus(0,5);
z= gRandom->Exp(5);
t= gRandom->Landau(0,10);
tree->Fill();
}
// Write the TTree to the file and close the file
tree->Write();
file->Close();
}