BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
txt2root.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <iomanip>
4#include <cstring>
5#include <string>
6#include <vector>
7#include <TFile.h>
8#include <TTree.h>
9#include <TString.h>
10#include <stdlib.h>
11#include <stdio.h>
12
13using namespace std;
14
15int main(int argc, char* argv[]){
16 int ratio(1);
17 if(argc<2){
18 cout << "please append txt file name" << endl;
19 cout << "usage: txt2root.exe filename [subratio]" << endl;
20 cout << "ex: txt2root.exe jpsi09_radBB.txt 5" << endl;
21 return 1;
22 }
23 if(argc==3){
24 ratio = atoi(argv[2]);
25 }
26
27 TString str_txt_file(argv[1]);
28 TString str_root_file(str_txt_file);
29 str_root_file.ReplaceAll(".txt", ".root");
30 TFile f(str_root_file, "recreate");
31 TTree *tree = new TTree("track", "track");
32 int run(0), event(0), index(0);
33 tree->Branch("run", &run, "run/I");
34 tree->Branch("event", &event, "event/I");
35 tree->Branch("index", &index, "index/I");
36 // read in txt file and assign the numbers to run, event and index of track
37 ifstream in(str_txt_file);
38 if(!in){
39 cout << "cannot open " << str_txt_file << endl;
40 return 0;
41 }
42 char str[255];
43 int count(0);
44 while(in){
45 count ++;
46 in.getline(str, 255);
47 sscanf(str ,"%d %d %d", &run, &event, &index);
48 if(count%ratio != 0) continue;
49 if(!run) continue; // protect of read at the end
50 tree->Fill();
51 }
52
53 tree->Write();
54 f.Close();
55 cout << "total events: " << count << " subratio: " << ratio << endl;
56 return 0;
57}
58
DOUBLE_PRECISION count[3]
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
int main()
Definition: test_IFile.cxx:11