#include #include #include #include #include #include #include #include void make_ttree(TString filename){ //constant int nsample = 1023; //global variable double voltage[nsample]; double value; std::cout << "FILENAME : " << filename << std::endl; std::ifstream data(filename); TString rootfile_name = filename.ReplaceAll(".txt",".root"); TFile *rootfile = new TFile(rootfile_name,"recreate"); TTree * tree = new TTree("tree","tree"); tree->Branch("nsample",&nsample,"nsample/I"); tree->Branch("voltage",voltage,"voltage[nsample]/D"); std::string line; int j = 0; int i = 0; while(std::getline(data,line)) { voltage[i] = stod(line); std::cout << "time " << i << " : " << voltage[i] << std::endl; i++; if(i == nsample) { tree->Fill(); i = 0; j++; } } std::cout << "# of event : " << j << std::endl; tree->Write(); rootfile->Close(); return 0; }