Commit a77bd0d5 authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

creating data files necessary for individual pixels to plot time walk curves for each pixels

parent dd8b5fea
void createfiles(int r, int c){
std::ifstream Energy_file("Energy_table.dat");
std::vector<double>Energy_e = {200,300,400,500,600,700,800,900,1000,1100,1200,
1300,1400,1500,1700,2200,2700,3200,4000,5000,6000,
7000,8000,9000,10000,11000,12000,13000,14000};
if (Energy_file.is_open()){
std::cout << "Energy_table.dat is opened..." << std::endl;
std::string ofilename = std::to_string(r)+"_"+std::to_string(c)+".txt";
ofstream ofile(ofilename.c_str(), ios::ate);//ios::ate- delete the output file before running each time. Otherwise will land with weird error
std::string line_1,line_2;
int Ecol1,Ecol2,Ecol3, TPcol1,TPcol2,TPcol3;
int ctr_E = 0, ctr_TOA = 0;
double Ecol4=0, tot,tot_var,toa=0,toa_var =0,toa_ref ;
std::vector<double> energy;
std::vector<double> TOA;
std::vector<double> TOA_VAR;
while(getline(Energy_file,line_1)){
istringstream ss1(line_1);
ss1 >> Ecol1 >> Ecol2 >> Ecol3 >> Ecol4;
energy.push_back(Ecol4);
// std::cout << "Elements " << Ecol4[ctr_E] << " ctr " << ctr_E << std::endl;
ctr_E++;
}
for(int i= 0; i < Energy_e.size(); i++){
// cout <<"testing..."<<std::endl;
stringstream Sfile;
Sfile << Energy_e.at(i) << ".dat";
// std::cout << "Files : " << Sfile.str() << std::endl;
std::vector<std::string>File_names = {std::string("tp_dat_" + Sfile.str())};
for (int j = 0; j < File_names.size(); j++ ) {
std::ifstream Data_file(File_names.at(j));
if(Data_file.is_open()){
// std::cout << "The data file " << File_names.at(j) << " is opened ..." << std::endl;
while(getline(Data_file,line_2)){
// cout << " looking at each line ... " <<std::endl;
if(line_2.rfind("#", 0) == 0) {
continue;
}
//cout <<" ignoring lines which start with #"<<std::endl;
istringstream ss2(line_2);
ss2 >> TPcol1 >> TPcol2 >> TPcol3 >> tot >> tot_var >> toa >> toa_var;
if (TPcol1==10){
// cout << " checking for row 125..."<<std::endl;
if (TPcol2==10){
TOA.push_back(toa);
TOA_VAR.push_back(toa_var);
// cout << " Checking for row 125 and col 125 ..."<<std::endl;
// std::cout << "Elements " << toa[ctr_TOA] << "\t" << toa_var[ctr_TOA] << std::endl;
ctr_TOA++;
}
}
}
}
else {
std::cout << "Unable to open " <<File_names.at(j) << " file ..." << std::endl;
}
}
}
for(int k = 0; k < TOA.size(); k++){
if(TOA.at(k)!=0){
ofile << energy.at(k) << "\t" << TOA.at(k) << "\t" << sqrt(TOA_VAR.at(k)) << std::endl;
}
}
cout << " Output file writen..."<<std::endl;
}
else{
std:: cout << "Unable to open Energy_table.dat file" <<std::endl;
}
}
void fullpixelmatrix(){
int row, col;
for(row =0; row <256; row ++){
for(col =0; col <256; col++){
createfiles(row,col);
}
}
std::cout << " Done ..." <<std ::endl;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment