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
38 if(!in){
39 cout << "cannot open " << str_txt_file << endl;
40 return 0;
41 }
42 char str[255];
44 while(in){
46 in.getline(str, 255);
47 sscanf(str ,"%d %d %d", &run, &event, &index);
48 if(
count%ratio != 0)
continue;
49 if(!run) continue;
50 tree->Fill();
51 }
52
53 tree->Write();
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]