BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
root_to_csv.cxx
Go to the documentation of this file.
1#include <iostream>
2#include "TFile.h"
3#include "TTree.h"
4#include <fstream>
5using namespace std;
6
8 TFile *f=new TFile("pre_data.root"); // opens the root file
9 TTree *tr=(TTree*)f->Get("n103"); // creates the TTree object
10 //tr->Scan(); // prints the content on the screen
11
12 Float_t de, co, ch, bg;
13 Int_t nh; // create variables of the same type as the branches you want to access
14
15 tr->SetBranchAddress("dEdx_meas",&de); // for all the TTree branches you need this
16 tr->SetBranchAddress("costheta",&co);
17 tr->SetBranchAddress("charge",&ch);
18 tr->SetBranchAddress("bg",&bg);
19 tr->SetBranchAddress("nhits",&nh);
20
21 ofstream myfile;
22 myfile.open ("pre_data.txt");
23
24 for (int i=0; i<tr->GetEntries(); i++){
25 // loop over the tree
26 tr->GetEntry(i);
27 myfile << de << "," << co << ","<< ch << "," << bg << "," << nh << "\n"; //write to file
28 }
29 myfile.close();
30}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
DOUBLE_PRECISION tr[3]
float bg
void root_to_csv()