#include #include #include #include #include #include #include using namespace std; void read(string fname1,string fname2,string fname3); int main() { read("../gluex_candidates.txt","../final_state_params.txt","../gluex_throwns.txt"); return 0; } void read(string fname1,string fname2,string fname3) { string fname="spherical_output.txt"; ofstream wfile(fname.c_str()); ifstream file1(fname1.c_str()); if(!file1.is_open()){ cout << "Unable to open file \"" << fname1 << "\"!" << endl; exit(-1); } ifstream file2(fname2.c_str()); if(!file2.is_open()){ cout << "Unable to open file \"" << fname2 << "\"!" << endl; exit(-1); } ifstream file3(fname3.c_str()); if(!file3.is_open()){ cout << "Unable to open file \"" << fname3 << "\"!" << endl; exit(-1); } cout << "Reading " << fname1 << " ..." << endl; cout << "Reading " << fname2 << " ..." << endl; cout << "Reading " << fname3 << " ..." << endl; int lineno=0; int Nevents = 0; while(true){ char line[50000]; lineno++; // keep track of line number in case we need to report error file1.getline(line, 50000); if(line[0] != '#') { stringstream ss(line); vector values; // Store values for line while (!ss.fail()) { float f; ss >> f; if (!ss.fail()) values.push_back(f); } if(!values.empty()) { float px, py, pz; px = values[4]; py = values[5]; pz = values[6]; float q_over_p = values[0]; float rho = sqrt(px*px + py*py + pz*pz); float theta = acos(pz/rho); float phi = atan2(py, px); wfile << rho << " " << phi << " " << theta << " "; } } file2.getline(line, 50000); if(line[0] != '#') { stringstream ss(line); vector values; // Store values for line while (!ss.fail()) { float f; ss >> f; if (!ss.fail()) values.push_back(f); } if(!values.empty()) { float px, py, pz; px = values[4]; py = values[5]; pz = values[6]; float q_over_p = values[0]; float rho = sqrt(px*px + py*py + pz*pz); float p = fabs(1.0/q_over_p); if(isinf(p) || isnan(p)) p = 0; float theta = acos(pz/rho); if(isinf(theta) || isnan(theta)) theta = 0; float phi = atan2(py, px); if(isinf(phi) || isnan(phi)) phi = 0; wfile << p << " " << phi << " " << theta << " "; } } file3.getline(line, 50000); if(line[0] != '#') { stringstream ss(line); vector values; // Store values for line while (!ss.fail()) { float f; ss >> f; if (!ss.fail()) values.push_back(f); } if(!values.empty()) { float px, py, pz; px = values[4]; py = values[5]; pz = values[6]; float q_over_p = values[0]; float rho = sqrt(px*px + py*py + pz*pz); float p = fabs(1.0/q_over_p); float theta = acos(pz/rho); float phi = atan2(py, px); wfile << p << " " << phi << " " << theta << " " << endl; } } if(file1.eof() || file2.eof() || file3.eof()) break; cout << "Event: " << ++Nevents << " \r"; cout.flush(); } file1.close(); file2.close(); file3.close(); wfile.close(); }