//------------------------------------------------------------------------ // A sample root macro to read a file mn54-l.tsv which is a tab-separated // output of SpecTech spectrography analysis program. // // In ROOT, do the following: // root [0] .L read_tsv.C // root [1] read_tsv() // // This creates a global histogram called h_tsv which you can then plot and // otherwise manipulate as any other histogram: // root [2] h_tsv->Draw() // // Read the ROOT help web page on plotting options for TH1 (a base class // for TH1F used here). //------------------------------------------------------------------------ void read_tsv() { FILE *fp = fopen("mn54-l.tsv","r"); char line[80]; char token1[20]; bool foundData = false; while (fgets(&line,80,fp)) { sscanf(&line[0],"%s", token1); if (strcmp(token1,"Data:") == 0) { cout << "Token1 == " << token1 << endl; foundData = true; break; } } if (! foundData) { cout << "No `Data:' token found. Are you sure this is a tsv file?" << endl; } else { Float_t channel; Int_t count; TH1F * h_tsv = new TH1F( "h_tsv", "h_tsv", 1024, -0.5, 1023.5 ); while (fgets(&line,80,fp)) { cout << "Line = " << line << endl; sscanf(&line[0], "%f %d", &channel, &count); h_tsv->Fill( channel, count ); } } End: fclose(fp); }