// Source Test Analysis // ------------------------------------------------------------ // Convert .raw files to root tree // For single Chip // ------------------------------------------------------------ // AuthoR: Jieh-Wen Tsung // 2010.05.14 // ------------------------------------------------------------ // compile: // g++ -c `root-config --cflags` raw_to_tree.cpp // g++ -o raw_to_tree `root-config --glibs` raw_to_tree.o // ------------------------------------------------------------ // Usage: // ex. the input files are : test_1.raw test_2.raw // ./raw_to_tree --tag test -i 1 -f 2 // --tag everything before -index.raw // -i initial index // -f final index // the out put files are: test_1.onlyhits.raw test_2.onlyhits.raw // the out put files are: test_1.root test_2.root // ------------------------------------------------------------ #include #include #include #include #include #include #include "Riostream.h" #include "TString.h" #include "TFile.h" #include "TTree.h" using namespace std; int main(int argc, char* argv[]) { //cout << "argc = " << argc << endl; string intag; //tag of data int initial; //initial index int final; //final index //Read arguements //for(int i = 0; i < argc; i++) cout << "argv[" << i << "] = " << argv[i] << endl; //cout << "----------read arguements----------" << endl; for(int i = 0; i < argc; i++){ if (strcmp(argv[i],"--tag") == 0){ intag=argv[i+1]; //cout << "input data tag =" << intag <Branch("trig",&trig,"trig/I"); tree->Branch("lv1",&lv1,"lv1/I"); tree->Branch("lv1_raw",&lv1_raw,"lv1_raw/I"); tree->Branch("column",&column,"column/I"); tree->Branch("row",&row,"row/I"); tree->Branch("scan_in",&scan_in,"scan_in/I"); tree->Branch("scan_fi",&scan_fi,"scan_fi/I"); tree->Branch("tot",&tot,"tot/I"); // read through the .onlyhits.raw file // read numers: // trig = trigger number // lv1 = position of the hit at the LV1 window // lv1_raw = lv1 stamps in the raw file (lv1 != lv1_raw) // column // raw // scan_in always 0 (redundant variable) // scan_fi always 0 (redundant variable) // tot while (1) { in >> trig >> lv1 >> lv1_raw >> column >> row >> scan_in >> scan_fi >> tot; if (!in.good()) break; //if (nlines < 20) printf("trig=%d, lv1=%d, column=%d, row=%d, tot=%d\n", trig, lv1, column, row, tot); tree->Fill(); nlines++; } printf(" found %d hits\n",nlines); in.close(); f->Write(); f->Close(); cout<<"output ROOT file name = "<< outfile_root <