BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
txt2root.cxx File Reference
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <TFile.h>
#include <TTree.h>
#include <TString.h>
#include <stdlib.h>
#include <stdio.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 15 of file txt2root.cxx.

15 {
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}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
DOUBLE_PRECISION count[3]