1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
//This program must be inside the folder with the all the energy's folders
{
char name[20], title[20], file_name[30];
ifstream read;
string line;
float x, y, rms, file=8.0;
int i, n;
TProfile *h;
TObjArray Hlist(0);
//open data files
for(i=0; i<=6; i++, file+=0.5){
sprintf(file_name,"%.1fmev/energy-ph-trans.dat",file);
read.open(file_name);
//Check if data file is open and reports
if(read.is_open())
cout << "File ./" << file_name << " is open.\n";
else
cout << "Error opening " << file_name << ".\n";
//put stream pointer in the 6th line
for(n=1; n<=5; n++){
std::getline (read,line);
cout << "Stream pointer currently in line " << n << ".\n";
cout << "Confirmation: " << line << "\n";
}
//create histogram
h = new TProfile(name,title,60,5000000,11000000);
Hlist.Add(h);
//get and write data lines
while( std::getline (read,line)){
//read data from file
std::istringstream(line,ios_base::in) >> x >> y >> rms;
printf("Confirmation of data reading: x=%.2E; y=%.2E; rms=%.2E\n", x, y, rms);
/* cout << "; y=" << y;
cout << "; rms=" << rms << ".\n";*/
//write name and title of histogram
sprintf(name,"%.1f", file);
sprintf(title,"%.1f MeV", file);
//Fill histogram with data from a line
h->Fill(x,y,rms);
line.clear();
}
//close the data files
read.close();
}
TFile f("histograms.root","RECREATE","Bremsstrahlung");
Hlist->Write();
}
|