noise2.cpp 2.56 KB
Newer Older
1
2
3
4
void noise2(){
  double row, col;
  TCanvas* c1 = new TCanvas();
  // std::string hist_name = "h" + std::to_string(row) + "_" + std::to_string(col);
5
  TH2D* histo = new TH2D("histo", "Noise distribution",256,0.,256.,256,0.,256.);
6
7
8
9
10
11
  
  for (row = 0; row < 256; row++){
    for(col = 0; col < 256; col++){
      stringstream foldername, filename;

       foldername << std::setw(3) << std::setfill('0') << row;
12
       // std::cout << " Foldername : " << foldername.str()<< std::endl;
13
14
15

       filename << std::setw(3) << std::setfill('0') << row << "_"
		<< std::setw(3) << std::setfill('0') << col << ".dat";
16
       //cout << "Filename : " << filename.str() << std::endl;
17
18
19
20
21

     
      
      std::ifstream infile(foldername.str()+"/"+filename.str());
      if(infile.is_open()){
22
	//	std::cout<<"The data file  is opened..."<<std::endl;
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
	 std::string line;
	 double avr=0.,rms=0.;
	 
	 while(!infile.eof()){
	   std::getline(infile,line);
	   if(line.rfind("#",0)!=0){
	     continue;
	   }
	   //  cout<<"original line : " <<line<<std::endl;
	   std::string newline = " ";
	   for(int i=0;i<line.length();i++){
	     if(line[i]!=':'){
	       newline=newline+line[i];
	     }
	     else{
	       newline=newline+line[i]+" ";
	     }
	   }

	   // cout<<"The new line with spaces " <<newline<<std::endl;
      
	   std::stringstream s;
	   s<<newline;
	   //cout<<"The line is stored in the stringstream object..."<<std::endl;
	   string temp;
	   double num=0.;
	   double arr[2]={ };
	   int i=0;
	   while(!s.eof()){
	     s>>temp;
	     if(std::stringstream(temp)>>num){
	       //cout<<num<<std::endl;
	       arr[i] =num;
	       i++;
	     }
	     temp = " ";
	   }
	   avr = arr[0];
	   rms = arr[1];
	 }

64
65
66
67
68
69
	 // cout << " avr : " << avr << " " << " rms : " << rms << std::endl;

	 if(rms >= 0){
	   histo->Fill(row,col,rms);
	 }
	 else{
70
71
	   cout<< " Foldername : " << foldername.str() << " " <<  " filename : " << filename.str() << " "
	       <<  " avr : " << avr << " " << " rms : " << rms <<  std::endl;
72
73
	 }
       
74
75
76
77
78
79
      }
      else{
	cout<<"Error..."<<std::endl;
      }
    }
  }
80
81
82
83
84
  histo->SetStats(0);
  // gStyle->SetOptStat(111100);
  histo->Draw("COLZ");
  
  
85
86
87
  histo->GetXaxis()->SetTitle("Row");
  histo->GetYaxis()->SetTitle("Column");
  histo->GetZaxis()->SetTitle("Baseline");
88
  histo->GetZaxis()->SetRangeUser(5,25);
89
  
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  /* histo->Draw("COLZ");
  gPad->Update();
  auto stat = dynamic_cast<TPaveStats*>(histo->FindObject("stats"));
  if (stat)
    {
      stat->SetX1NDC(0.4);
      stat->SetX2NDC(0.6);
      stat->Draw();
    }
  else
    {
      cerr << "No stats box found!\n";
      }*/

104
}
105
106
107
108