Newer
Older
TB_Chris / Kepler / Scripts / .svn / text-base / PixelMapAnalysis_KeplerConfig.cpp.svn-base
  1. #include "TFile.h"
  2. #include "TH2D.h"
  3. #include <iostream>
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <vector>
  7. #include <algorithm>
  8. #include "TROOT.h"
  9. #include "TKey.h"
  10. #include "TIterator.h"
  11.  
  12. /*
  13. ......................................................................
  14. Author: Hella Snoek (hella.snoek@cern.ch)
  15. Date: 22.07.2014
  16.  
  17. Simple ROOT analysis code to analyse the pixel hit maps for
  18. - DEAD: no hits
  19. - HOT: too many hits
  20. - LOW: too few hits
  21. pixel hits.
  22.  
  23. A pixel cell is compared to its 8 neighbouring (exception for pixel on
  24. the edge below) pixel cells. The 2 highest and 2 lowest hit counts
  25. are removed before making an average of the surrounding pixel cells.
  26. The minimum required count in a cell for the analysis is 20.
  27. A HOT cell is 40 times higher than the average.
  28. A LOW cell is 4 std deviations (sqrt) lower.
  29.  
  30. For the cells on the edge of the sensor the highest and lowest hits
  31. are not removed for the average.
  32.  
  33. Three text files are produced. With the format
  34. col row
  35.  
  36. Run this code as:
  37. root -b -q PixelMapAnalysis.cpp+\(\"inputfilename\",\"outputname\"\)
  38. or
  39. root -b -q PixelMapAnalysis.cpp+\(\"inputfilename\",\"outputname\",true\)
  40. for the verbose version.
  41.  
  42. or call it with a hitmap:
  43. .L PixelMapAnalysis.cpp+
  44. PixelMapAnalysis(yourTH2D,"outputname",true);
  45.  
  46.  
  47. ......................................................................
  48. */
  49. .*
  50.  
  51. #include <iostream>
  52. #include <fstream>
  53.  
  54. using namespace std;
  55. void PixelMapAnalysis(TH2D* hist, unsigned int plane, ostream& os = std::cout ){
  56. for (int col=0;col<256;col++){
  57. for (int row=0;row<256;row++){
  58. double count = hist->GetBinContent(col+1,row+1);
  59.  
  60. vector<double> neighbours{
  61. hist->GetBinContent(col,row),
  62. hist->GetBinContent(col+1,row),
  63. hist->GetBinContent(col+2,row),
  64. hist->GetBinContent(col,row+1),
  65. hist->GetBinContent(col+2,row+1),
  66. hist->GetBinContent(col,row+2),
  67. hist->GetBinContent(col+1,row+2),
  68. hist->GetBinContent(col+2,row+2)
  69. } ;
  70.  
  71.  
  72. if (col>0&&col<255&&row>0&&row<255) {
  73. std::sort( neighbours.begin(),neighbours.end());
  74. neighbours.erase(neighbours.begin(),neighbours.begin()+2);
  75. neighbours.erase(neighbours.end()-2,neighbours.end());
  76. double total(0.);
  77. for (uint i=0;i<neighbours.size();i++) {
  78. //cout << neighbours[i] << " " ;
  79. total=total+neighbours[i];
  80. // cout << total<< " ";
  81. }
  82.  
  83. if (count >10*total) {
  84. os << plane << setw(3) << " "<< setw(3) << col << " "<< row << endl;
  85. }
  86. }
  87. else {
  88. std::sort( neighbours.begin(),neighbours.end());
  89. double total(0);
  90. int active(neighbours.size());
  91. for (uint i=0;i<neighbours.size();i++) {
  92. active=active-1;
  93. total=total+neighbours[i];
  94. }
  95. if (count >10*total) {
  96. os << setw(3) << col << " " << row << endl;
  97. continue;
  98. }
  99. }
  100. }
  101. }
  102. }
  103.  
  104.  
  105. void PixelMapAnalysis_KeplerConfig(const char* filename){
  106. cout << "opening filename" << endl;
  107. TFile file(filename,"read");
  108. file.GetDirectory("Tb/TbHitMonitor/HitMap")->GetListOfKeys()->Print();
  109.  
  110. ofstream hotF(Form("%s_hot.dat",filename));
  111. TIter nextkey(file.GetDirectory("Tb/TbHitMonitor/HitMap")->GetListOfKeys());
  112.  
  113. TKey *key;
  114. while((key= (TKey*) nextkey())) {
  115. TH2D *hist = (TH2D*) key->ReadObj();
  116. std::cout << "-------Now processing: " << key->GetName() << "-----------" <<endl;
  117. std::string name = key->GetName();
  118. int plane(0);
  119. sscanf( &name.back(), "%d", &plane );
  120. PixelMapAnalysis(hist, plane, hotF);
  121. }
  122. hotF.close();
  123. }