toa_calib.C 2.59 KB
Newer Older
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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;

    ofstream file125_125("125_125.txt", 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[30] = {0}, tot,tot_var,toa[30] = {0},toa_var[30] = {0},toa_ref ;
    
    while(getline(Energy_file,line_1)){
      istringstream ss1(line_1);
      ss1 >> Ecol1 >> Ecol2 >> Ecol3 >> Ecol4[ctr_E];
      // 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[ctr_TOA] >> toa_var[ctr_TOA];
	    if (TPcol1==125){
	      // cout << " checking for row 125..."<<std::endl;
	      if (TPcol2==125){
		//	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 < 29; k++){
      if(toa[k]!=0){
	file125_125 << Ecol4[k] << "\t" << toa[k] << "\t" <<  sqrt(toa_var[k]) << std::endl;
      }
    }
    cout << " Output file writen..."<<std::endl;
  }

  else{
    std:: cout << "Unable to open Energy_table.dat file" <<std::endl;
  }
}


void toa_calib(){
  int row = 125, col = 125;
  createfiles(row,col);
  std::cout << " Done ..." <<std ::endl;
}