Advertisement
burandotorg

bananatree.c

Jan 17th, 2017
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 38.09 KB | None | 0 0
  1. #include "TTree.h"
  2. #include "TFile.h"
  3. #include "TRandom.h"
  4.  
  5. #include <iostream>
  6. #include <string>
  7.  
  8. const int NUM_PIXELS = 256;
  9.  
  10. string runNumber = ""; /* four digits; pad with 0 if necessary */
  11. //string runDir    = "/data/macros/treesort"; /* no trailing slash */
  12. string runDir    = "/data/files/atlas1593/gretina"; /* no trailing slash */
  13. string peakDir   = "/data/files/bananas";
  14.  
  15. bool verbose(false);
  16. bool debugBananas(false); /* going to debug with pixel 205 */
  17.  
  18. /* interpret user-input run list. Return -1 if there's not at least 1 or if */
  19. /* non-digit/space characters are encountered. Return number of runs otherwise. */
  20. /* If the boolean "checkexistence" is set, only runs that actually exist are  */
  21. /* loaded into the list or returned in the count. */
  22.  
  23. int ihist(2);
  24. int bananas  [3][256] = {{ }};                 /* type (AB=0, AC=1, BC=2), pixel */
  25. int vertices [3][256][5] = {{{ }}};            /* type, pixel, banana # */
  26. float points [3][5][256][2][99] = {{{{{ }}}}}; /* type, banana, pixel, X/Y, point */
  27. long int bananaCounts [3][5] = {{ }};          /* track hits in each banana (up to 2^32 hits) */
  28. int poly = -1;                                 /* which poly is the point in? */
  29. bool arraysReady(false);                       /* init done? */
  30. int bplot(-1), factor(1.0);
  31. /* initialise arrays for bananas */
  32.  
  33. float pix_angle[NUM_PIXELS] = {
  34.   37.141, 32.895, 28.445, 23.908, 19.653, 16.391, 15.165, 16.580,
  35.   40.971, 36.941, 32.748, 28.546, 24.730, 21.943, 20.940, 22.100,
  36.   45.272, 41.556, 37.721, 33.932, 30.574, 28.196, 27.361, 28.328,
  37.   50.035, 46.724, 43.333, 40.027, 37.149, 35.153, 34.462, 35.263,
  38.   55.164, 52.326, 49.446, 46.672, 44.293, 42.667, 42.109, 42.756,
  39.   60.528, 58.205, 55.871, 53.651, 51.772, 50.503, 50.071, 50.572,
  40.   65.983, 64.180, 62.390, 60.711, 59.308, 58.371, 58.054, 58.422,
  41.   71.434, 70.127, 68.848, 67.665, 66.691, 66.047, 65.831, 66.082,
  42.  
  43.   37.141, 32.895, 28.445, 23.908, 19.653, 16.391, 15.165, 16.580,
  44.   40.971, 36.941, 32.748, 28.546, 24.730, 21.943, 20.940, 22.100,
  45.   45.272, 41.556, 37.721, 33.932, 30.574, 28.196, 27.361, 28.328,
  46.   50.035, 46.724, 43.333, 40.027, 37.149, 35.153, 34.462, 35.263,
  47.   55.164, 52.326, 49.446, 46.672, 44.293, 42.667, 42.109, 42.756,
  48.   60.528, 58.205, 55.871, 53.651, 51.772, 50.503, 50.071, 50.572,
  49.   65.983, 64.180, 62.390, 60.711, 59.308, 58.371, 58.054, 58.422,
  50.   71.434, 70.127, 68.848, 67.665, 66.691, 66.047, 65.831, 66.082,
  51.  
  52.   37.141, 32.895, 28.445, 23.908, 19.653, 16.391, 15.165, 16.580,
  53.   40.971, 36.941, 32.748, 28.546, 24.730, 21.943, 20.940, 22.100,
  54.   45.272, 41.556, 37.721, 33.932, 30.574, 28.196, 27.361, 28.328,
  55.   50.035, 46.724, 43.333, 40.027, 37.149, 35.153, 34.462, 35.263,
  56.   55.164, 52.326, 49.446, 46.672, 44.293, 42.667, 42.109, 42.756,
  57.   60.528, 58.205, 55.871, 53.651, 51.772, 50.503, 50.071, 50.572,
  58.   65.983, 64.180, 62.390, 60.711, 59.308, 58.371, 58.054, 58.422,
  59.   71.434, 70.127, 68.848, 67.665, 66.691, 66.047, 65.831, 66.082,
  60.  
  61.   37.141, 32.895, 28.445, 23.908, 19.653, 16.391, 15.165, 16.580,
  62.   40.971, 36.941, 32.748, 28.546, 24.730, 21.943, 20.940, 22.100,
  63.   45.272, 41.556, 37.721, 33.932, 30.574, 28.196, 27.361, 28.328,
  64.   50.035, 46.724, 43.333, 40.027, 37.149, 35.153, 34.462, 35.263,
  65.   55.164, 52.326, 49.446, 46.672, 44.293, 42.667, 42.109, 42.756,
  66.   60.528, 58.205, 55.871, 53.651, 51.772, 50.503, 50.071, 50.572,
  67.   65.983, 64.180, 62.390, 60.711, 59.308, 58.371, 58.054, 58.422,
  68.   71.434, 70.127, 68.848, 67.665, 66.691, 66.047, 65.831, 66.082
  69. };
  70.  
  71. int group[NUM_PIXELS] = {
  72.   1, 1, 1, 0, 0, 0, 0, 0,
  73.   2, 1, 1, 1, 0, 0, 0, 0,
  74.   2, 2, 2, 1, 1, 1, 1, 1,
  75.   3, 2, 2, 2, 1, 1, 1, 1,
  76.   3, 3, 3, 2, 2, 2, 2, 2,
  77.   4, 3, 3, 3, 3, 3, 3, 3,
  78.   4, 4, 4, 4, 3, 3, 3, 3,
  79.   4, 4, 4, 4, 4, 4, 4, 4,
  80.  
  81.   1, 1, 1, 0, 0, 0, 0, 0,
  82.   2, 1, 1, 1, 0, 0, 0, 0,
  83.   2, 2, 2, 1, 1, 1, 1, 1,
  84.   3, 2, 2, 2, 1, 1, 1, 1,
  85.   3, 3, 3, 2, 2, 2, 2, 2,
  86.   4, 3, 3, 3, 3, 3, 3, 3,
  87.   4, 4, 4, 4, 3, 3, 3, 3,
  88.   4, 4, 4, 4, 4, 4, 4, 4,
  89.  
  90.   1, 1, 1, 0, 0, 0, 0, 0,
  91.   2, 1, 1, 1, 0, 0, 0, 0,
  92.   2, 2, 2, 1, 1, 1, 1, 1,
  93.   3, 2, 2, 2, 1, 1, 1, 1,
  94.   3, 3, 3, 2, 2, 2, 2, 2,
  95.   4, 3, 3, 3, 3, 3, 3, 3,
  96.   4, 4, 4, 4, 3, 3, 3, 3,
  97.   4, 4, 4, 4, 4, 4, 4, 4,
  98.  
  99.   1, 1, 1, 0, 0, 0, 0, 0,
  100.   2, 1, 1, 1, 0, 0, 0, 0,
  101.   2, 2, 2, 1, 1, 1, 1, 1,
  102.   3, 2, 2, 2, 1, 1, 1, 1,
  103.   3, 3, 3, 2, 2, 2, 2, 2,
  104.   4, 3, 3, 3, 3, 3, 3, 3,
  105.   4, 4, 4, 4, 3, 3, 3, 3,
  106.   4, 4, 4, 4, 4, 4, 4, 4
  107. };
  108.  
  109. float eff[NUM_PIXELS] = {
  110.   0.305, 0.356, 0.409, 0.460, 0.502, 0.531, 0.541, 0.530,
  111.   0.347, 0.411, 0.479, 0.546, 0.604, 0.643, 0.656, 0.641,
  112.   0.386, 0.464, 0.548, 0.633, 0.707, 0.758, 0.776, 0.755,
  113.   0.419, 0.509, 0.609, 0.710, 0.801, 0.864, 0.886, 0.861,
  114.   0.442, 0.541, 0.651, 0.766, 0.869, 0.942, 0.967, 0.938,
  115.   0.450, 0.553, 0.668, 0.787, 0.896, 0.973, 1.000, 0.969,
  116.   0.444, 0.544, 0.655, 0.771, 0.875, 0.949, 0.975, 0.945,
  117.   0.422, 0.514, 0.615, 0.718, 0.811, 0.876, 0.898, 0.872,
  118.  
  119.   0.305, 0.356, 0.409, 0.460, 0.502, 0.531, 0.541, 0.530,
  120.   0.347, 0.411, 0.479, 0.546, 0.604, 0.643, 0.656, 0.641,
  121.   0.386, 0.464, 0.548, 0.633, 0.707, 0.758, 0.776, 0.755,
  122.   0.419, 0.509, 0.609, 0.710, 0.801, 0.864, 0.886, 0.861,
  123.   0.442, 0.541, 0.651, 0.766, 0.869, 0.942, 0.967, 0.938,
  124.   0.450, 0.553, 0.668, 0.787, 0.896, 0.973, 1.000, 0.969,
  125.   0.444, 0.544, 0.655, 0.771, 0.875, 0.949, 0.975, 0.945,
  126.   0.422, 0.514, 0.615, 0.718, 0.811, 0.876, 0.898, 0.872,
  127.  
  128.   0.305, 0.356, 0.409, 0.460, 0.502, 0.531, 0.541, 0.530,
  129.   0.347, 0.411, 0.479, 0.546, 0.604, 0.643, 0.656, 0.641,
  130.   0.386, 0.464, 0.548, 0.633, 0.707, 0.758, 0.776, 0.755,
  131.   0.419, 0.509, 0.609, 0.710, 0.801, 0.864, 0.886, 0.861,
  132.   0.442, 0.541, 0.651, 0.766, 0.869, 0.942, 0.967, 0.938,
  133.   0.450, 0.553, 0.668, 0.787, 0.896, 0.973, 1.000, 0.969,
  134.   0.444, 0.544, 0.655, 0.771, 0.875, 0.949, 0.975, 0.945,
  135.   0.422, 0.514, 0.615, 0.718, 0.811, 0.876, 0.898, 0.872,
  136.  
  137.   0.305, 0.356, 0.409, 0.460, 0.502, 0.531, 0.541, 0.530,
  138.   0.347, 0.411, 0.479, 0.546, 0.604, 0.643, 0.656, 0.641,
  139.   0.386, 0.464, 0.548, 0.633, 0.707, 0.758, 0.776, 0.755,
  140.   0.419, 0.509, 0.609, 0.710, 0.801, 0.864, 0.886, 0.861,
  141.   0.442, 0.541, 0.651, 0.766, 0.869, 0.942, 0.967, 0.938,
  142.   0.450, 0.553, 0.668, 0.787, 0.896, 0.973, 1.000, 0.969,
  143.   0.444, 0.544, 0.655, 0.771, 0.875, 0.949, 0.975, 0.945,
  144.   0.422, 0.514, 0.615, 0.718, 0.811, 0.876, 0.898, 0.872
  145. };
  146.  
  147. float cos[NUM_PIXELS] = {
  148.   0.673, 0.709, 0.742, 0.772, 0.795, 0.810, 0.815, 0.809,
  149.   0.703, 0.744, 0.783, 0.817, 0.845, 0.863, 0.869, 0.862,
  150.   0.728, 0.774, 0.818, 0.858, 0.891, 0.912, 0.919, 0.911,
  151.   0.748, 0.799, 0.847, 0.892, 0.929, 0.953, 0.961, 0.951,
  152.   0.762, 0.815, 0.867, 0.915, 0.954, 0.980, 0.989, 0.979,
  153.   0.766, 0.821, 0.874, 0.923, 0.964, 0.991, 1.000, 0.989,
  154.   0.763, 0.816, 0.868, 0.917, 0.956, 0.983, 0.992, 0.981,
  155.   0.750, 0.801, 0.850, 0.896, 0.932, 0.957, 0.965, 0.955,
  156.  
  157.   0.673, 0.709, 0.742, 0.772, 0.795, 0.810, 0.815, 0.809,
  158.   0.703, 0.744, 0.783, 0.817, 0.845, 0.863, 0.869, 0.862,
  159.   0.728, 0.774, 0.818, 0.858, 0.891, 0.912, 0.919, 0.911,
  160.   0.748, 0.799, 0.847, 0.892, 0.929, 0.953, 0.961, 0.951,
  161.   0.762, 0.815, 0.867, 0.915, 0.954, 0.980, 0.989, 0.979,
  162.   0.766, 0.821, 0.874, 0.923, 0.964, 0.991, 1.000, 0.989,
  163.   0.763, 0.816, 0.868, 0.917, 0.956, 0.983, 0.992, 0.981,
  164.   0.750, 0.801, 0.850, 0.896, 0.932, 0.957, 0.965, 0.955,
  165.  
  166.   0.673, 0.709, 0.742, 0.772, 0.795, 0.810, 0.815, 0.809,
  167.   0.703, 0.744, 0.783, 0.817, 0.845, 0.863, 0.869, 0.862,
  168.   0.728, 0.774, 0.818, 0.858, 0.891, 0.912, 0.919, 0.911,
  169.   0.748, 0.799, 0.847, 0.892, 0.929, 0.953, 0.961, 0.951,
  170.   0.762, 0.815, 0.867, 0.915, 0.954, 0.980, 0.989, 0.979,
  171.   0.766, 0.821, 0.874, 0.923, 0.964, 0.991, 1.000, 0.989,
  172.   0.763, 0.816, 0.868, 0.917, 0.956, 0.983, 0.992, 0.981,
  173.   0.750, 0.801, 0.850, 0.896, 0.932, 0.957, 0.965, 0.955,
  174.  
  175.   0.673, 0.709, 0.742, 0.772, 0.795, 0.810, 0.815, 0.809,
  176.   0.703, 0.744, 0.783, 0.817, 0.845, 0.863, 0.869, 0.862,
  177.   0.728, 0.774, 0.818, 0.858, 0.891, 0.912, 0.919, 0.911,
  178.   0.748, 0.799, 0.847, 0.892, 0.929, 0.953, 0.961, 0.951,
  179.   0.762, 0.815, 0.867, 0.915, 0.954, 0.980, 0.989, 0.979,
  180.   0.766, 0.821, 0.874, 0.923, 0.964, 0.991, 1.000, 0.989,
  181.   0.763, 0.816, 0.868, 0.917, 0.956, 0.983, 0.992, 0.981,
  182.   0.750, 0.801, 0.850, 0.896, 0.932, 0.957, 0.965, 0.955
  183. };
  184.  
  185. bool haveBanana(int pixel, string histType) {
  186.   string thisPix  = to_string((long long int) pixel);
  187.   string strIhist = to_string((long long int) ihist);
  188.  
  189.   string fileName = peakDir + "/" + runNumber + "/ihist-"
  190.     + strIhist + "/" + histType + "/" + runNumber + "-ihist"
  191.     + strIhist + "-" + histType + "-pixel-" + thisPix + ".poly";
  192.  
  193.   struct stat st;
  194.   if (stat(fileName.c_str(),&st) == -1) {
  195.     return false;
  196.   } else {
  197.     return true;
  198.   }
  199. } //end haveBanana
  200.  
  201. bool fileExists (string input) {
  202.   ifstream f(input.c_str());
  203.   if (f.good()) {
  204.     f.close();
  205.     return true;
  206.   } else {
  207.     f.close();
  208.     return false;
  209.   }
  210. }
  211.  
  212. bool dirExists (string dir) {
  213.   string currentDir = gSystem->pwd();
  214.   bool existence    = gSystem->cd(dir.c_str());
  215.   gSystem->cd(currentDir.c_str());
  216.  
  217.   return existence;
  218. } //end ifdirexists ()
  219.  
  220. bool isNumber (string input) {
  221.   for (int i=0; i<input.length(); i++) {
  222.     if (isdigit((int) input[i]) == 0) {
  223.       return false;
  224.     }
  225.   }
  226.   return true;
  227. } // end isNumber
  228.  
  229. bool isPercent (string input) {
  230.   for (int i=0; i<(input.length()-1); i++) {
  231.     if (isdigit(input[i]) == 0) {
  232.       return false;
  233.     }
  234.   }
  235.   if (input[input.length()-1] != '%') {
  236.     return false;
  237.   }
  238. }
  239.  
  240. bool isNumberOrPercent (string input) {
  241.   for (int i=0; i<input.length()-1; i++) {
  242.     if (isdigit(input[i]) == 0) {
  243.       return false;
  244.     }
  245.   }
  246.   if (input[input.length()-0] != '%') {return false;}
  247.  
  248.   return true;
  249. }
  250.  
  251. string removeCommas (string input) {
  252.   string output = "";
  253.   int counter = 0;
  254.  
  255.   for (int i=0; i<input.length(); i++) {
  256.     if (input[i] != ',') {
  257.       output[counter] = input[i];
  258.       output.length()++;
  259.       counter++;
  260.     }
  261.   }
  262.   /* output[output.length] = '\0'; */
  263.   return output;
  264. }
  265.  
  266. string padRun (string input) {
  267.   string paddedrun(input);
  268.  
  269.   if (input.length() < 4) {
  270.     for (int iii=0; iii<(4-input.length()); iii++) {
  271.       if (iii == input.length()) {break;} /* stop runaway */
  272.       paddedrun = "0" + paddedrun;
  273.     }
  274.   }
  275.  
  276.   return paddedrun;
  277. }
  278.  
  279. bool setupPeakArrays (string stringRun, int whatIhist, string ABC) {
  280.   int linecount, banana, polys, type;
  281.   float coordX, coordY;
  282.   char throwaway; //throws out the delimiting character when parsing a line
  283.   string line, linedata, isotope, fileName;
  284.   stringstream convert;
  285.   struct stat st;
  286.   ifstream readFile;
  287.  
  288.   int maxPix = 256;
  289.  
  290.   for (int pix=0; pix < maxPix; pix++) {
  291.     convert << pix;
  292.     string thisPix = convert.str(); convert.str("");
  293.  
  294.     convert << whatIhist;
  295.     string whichIhist = convert.str(); convert.str("");
  296.  
  297.     fileName = peakDir + "/" + stringRun + "/ihist-" + whichIhist + "/" + ABC
  298.       + "/" + stringRun + "-ihist" + whichIhist + "-" + ABC + "-pixel-" + thisPix + ".poly";
  299.  
  300.     readFile.open(fileName.c_str());
  301.  
  302.     if (ABC == "AB") {type = 0;} //must match type settings in inPeak()
  303.     if (ABC == "AC") {type = 1;}
  304.     if (ABC == "BC") {type = 2;}
  305.  
  306.     //Vertex count - store vertex count in memory. Opens each file once,
  307.     //counts vertices, stores in array vertices, then closes file
  308.     if (!readFile.is_open()) {
  309.       if (verbose) {cout << "No polys for " << ABC << pix << "." << endl;}
  310.     } else {
  311.       banana = -1; polys = 0;
  312.       while (!readFile.eof()) {
  313.         getline(readFile,line); istringstream iss(line);
  314.  
  315.         if ((line[0] == '#') || (line[0] == '&')) {
  316.           linecount = -1;
  317.         } //reset line count when we hit a header line or a vertex count line
  318.  
  319.         if (line[0] == '&') {
  320.           banana++;
  321.           int vertexCount;
  322.           iss >> throwaway >> vertexCount;
  323.           vertices[type][pix][banana] = vertexCount;
  324.         } //end parsing vertex count (& line)
  325.  
  326.         if ((line.length() > 0) && (line[0] != '#') && (line[0] != '&') && (line[0] != '@')) {
  327.           linecount++;
  328.           iss >> coordX >> coordY;
  329.           points [type][banana][pix][0][linecount] = coordX;
  330.           points [type][banana][pix][1][linecount] = coordY;
  331.         } //parse standard line
  332.  
  333.         if (line[0] == '@') {
  334.           iss >> throwaway >> polys;
  335.           bananas [type][pix] = polys;
  336.         } //end parsing poly count (@ line)
  337.       } //done with readFile
  338.  
  339.       readFile.close();
  340.       readFile.clear();
  341.     } //done with file
  342.   } //end loading pixels into memory
  343.  
  344.   if (verbose) {
  345.     cout << "Poly debug:" << endl << endl;
  346.     for (int pixel=0; pixel < 256; pixel++) {
  347.       for (int banana=0; banana < bananas [type][pixel]; banana++) {
  348.         for (int vertex=0; vertex < vertices [type][pixel][banana]; vertex++) {
  349.           cout << "Pixel " << pixel << " Banana: " << banana
  350.                << " X: " << setw(7) << points [type][banana][pixel][0][vertex]
  351.                << " Y: " << setw(7) << points [type][banana][pixel][1][vertex] << endl;
  352.         }
  353.         cout << "Pixel " << ABC << pixel << " bananas: " << bananas [type][pixel] << endl << endl;
  354.       }
  355.     }
  356.   } //end debug output
  357.  
  358.   arraysReady = true;
  359. } // end setupPeakArrays
  360.  
  361. /* This version of the pnpoly function tests whether the point is inside a given banana. */
  362.  
  363. bool inBanana (int whatIhist, string ABC, int whatPixel, float InputX, float InputY, int banana) {
  364.   stringstream convert;
  365.   convert.str("");
  366.  
  367.   convert << whatPixel;
  368.   string whichPixel = convert.str(); convert.str("");
  369.  
  370.   bool inPoly = false;
  371.   int i, j, c(0), type;
  372.  
  373.   if (ABC == "AB") {type = 0;} /* must match type settings in setupPeakArrays() */
  374.   if (ABC == "AC") {type = 1;}
  375.   if (ABC == "BC") {type = 2;}
  376.  
  377.   if ((vertices[type][whatPixel][banana] != 0)) {
  378.     for (i = 0, j = vertices[type][whatPixel][banana]-1;
  379.          i < vertices[type][whatPixel][banana]; j = i++) {
  380.       if (((points[type][banana][whatPixel][1][i] > InputY)
  381.            != (points[type][banana][whatPixel][1][j] > InputY)) &&
  382.           (InputX < (points[type][banana][whatPixel][0][j]-points[type][banana][whatPixel][0][i])
  383.            * (InputY-points[type][banana][whatPixel][1][i]) /
  384.            (points[type][banana][whatPixel][1][j]-points[type][banana][whatPixel][1][i])
  385.            + points[type][banana][whatPixel][0][i]))
  386.         {c = !c;}
  387.     }
  388.     if (c == 1) {
  389.       inPoly = true;
  390.     }
  391.   }
  392.   return inPoly;
  393. }
  394.  
  395. string intStr (long int input) {
  396.   stringstream convert;
  397.   string output;
  398.  
  399.   convert << input;
  400.   output = convert.str();
  401.   convert.str("");
  402.  
  403.   return output;
  404. } //convert int to string
  405.  
  406. string addCommas (long long int number) {
  407.   std::string withCommas = intStr(number);
  408.   int pos = withCommas.length() - 3;
  409.   while (pos > 0) {
  410.     withCommas.insert(pos,",");
  411.     pos = pos - 3;
  412.   }
  413.   return withCommas;
  414. } //format counter with commas
  415.  
  416. int strInt (string input) {
  417.   //convert run number to integer
  418.  
  419.   for (int i=0; i<input.length(); i++) {
  420.     if (isdigit(input[i]) == 0) {
  421.       return -1;
  422.     }
  423.   }
  424.  
  425.   char junk[256]; int newInt;
  426.   for (int i=0; i<input.length(); i++) {
  427.     junk[i] = input[i];
  428.   } //convert value to an integer
  429.   junk[input.length()] = '\0';
  430.   newInt = atoi(junk);
  431.   for (int i=0; i<256; i++) {
  432.     junk[i] = '\0';
  433.   }
  434.   return newInt;
  435. } //convert string to int
  436.  
  437. string getUsername() {
  438.   struct passwd *passwd;
  439.   passwd = getpwuid(getuid());
  440.   string userName = (string) passwd->pw_name;
  441.  
  442.   return userName;
  443. } //end getUsername()
  444.  
  445. string showTime() {
  446.   stringstream convert;
  447.  
  448.   // current date/time based on current system
  449.   time_t now = time(0);
  450.  
  451.   // convert now to string form
  452.   convert << ctime(&now);
  453.  
  454.   string datestamp = convert.str(); convert.str("");
  455.   datestamp = datestamp.erase(datestamp.find_last_not_of( "\r\n\t")+1);
  456.  
  457.   return datestamp;
  458. } //end currentTime()
  459.  
  460. int digitcount (long long int input) {
  461.   stringstream convert;
  462.   string output;
  463.  
  464.   convert << input;
  465.   output = convert.str();
  466.   convert.str("");
  467.  
  468.   return output.length();
  469. }
  470.  
  471. /* START */
  472.  
  473. int bananatree () {
  474.  
  475.   double entries(-999); /* will stop after this many; set to -1 to loop over all */
  476.   double maxEntries(-999);
  477.   long long int totalEntries(0);
  478.  
  479.   string runlist[9];
  480.  
  481.   for (int i=0; i<9; i++) {
  482.     runlist[i] = "";
  483.   }
  484.  
  485.   /* shenanigans; converting to int and back removes leading zeroes */
  486.   //string bananaFolder = runNumber;
  487.   int bananaInt = strInt(runNumber);
  488.   //bananaFolder = intStr(bananaInt);
  489.   bool delorean(true);
  490.   int interval(1000000000);
  491.  
  492.   string bananaFolder = "654-667";
  493.  
  494.   /* SETUP */
  495.  
  496.   bool gotem(false);
  497.  
  498.   Int_t mult              = 0;
  499.   Int_t hitP[256]         = {-1};
  500.   Int_t hitA[256]         = {-1};
  501.   Int_t hitB[256]         = {-1};
  502.   Int_t hitC[256]         = {-1};
  503.   Int_t hitT[256]         = {-1};
  504.  
  505.   Int_t angle_group[256]  = {-1};
  506.   Float_t angle[256]      = {-1};
  507.   Float_t efficiency[256] = {-1};
  508.  
  509.   Float_t G[256]          = {-1};
  510.   Float_t d[256]          = {-1};
  511.   Int_t gs_det[256]       = {-1};
  512.  
  513.   Long64_t pw_time        = 0;
  514.   Long64_t gs_time[256]   = {0};
  515.   Long64_t ts_diff[256]   = {0};
  516.  
  517.   Int_t aux_mult          = 0;
  518.   Int_t qdc_chan[256]     = {0};
  519.   Int_t qdc_value[256]    = {0};
  520.   Int_t tdc_chan[256]     = {0};
  521.   Int_t tdc_value[256]    = {0};
  522.   Long64_t aux_time       = 0;
  523.  
  524.   Float_t t0[256]         = {0.0};
  525.  
  526.   /* Float_t qdc_chan[256]  = {0.0}; */
  527.   /* Float_t qdc_val[256]   = {0.0}; */
  528.   /* Float_t tdc_chan[256]  = {0.0}; */
  529.   /* Float_t tdc_val[256]   = {0.0}; */
  530.  
  531.   Int_t pw_mult(0), gs_mult(0);
  532.  
  533.   bool b0, b1, b2, b3, b4, bAny, bNone;
  534.   bool in0[256], in1[256], in2[256], in3[256], in4[256], inNone[256];
  535.   bool have0[256], have1[256], have2[256], have3[256], have4[256];
  536.  
  537.   bool declared;
  538.   if (!declared) {
  539.     gROOT->ProcessLine(".L /data/macros/treesort/gtree.C");
  540.     gtree ttree; /* load class into memory (not doing this causes crash) */
  541.     declared = true; /* value will persist between runs in this session */
  542.   }
  543.  
  544.   /* get multiple run numbers */
  545.  
  546.   string runs(""); int runcount(0);
  547.  
  548.   cout << "Input runs to analyze or 'c' to continue. 'q' quits." << endl;
  549.  
  550.   bool haveRun(false);
  551.  
  552.   while (1) {
  553.     string scratch("");
  554.  
  555.     haveRun = false;
  556.     cout << "Enter (c)ontinue/(q)uit or (run number): ";
  557.     cin >> scratch;
  558.  
  559.     if ((scratch.length() == 1) && (scratch[0] == 'c')) {
  560.       if (runcount > 0) {
  561.         break;
  562.       } else {
  563.         cout << "Can't continue with no runs. Select at least one or (q)uit." << endl;
  564.       }
  565.     }
  566.  
  567.     if ((scratch.length() == 1) && (scratch[0] == 'q')) {
  568.       return;
  569.     }
  570.  
  571.     /* string testDir = runDir + "/Run" + padRun(scratch);  */
  572.     string testFile= runDir + "/Run" + padRun(scratch) + ".root";
  573.  
  574.     if (fileExists(testFile)) {
  575.       if (runcount > 0) {
  576.         for (int w=0; w<runcount; w++) {
  577.           if (scratch.compare(runlist[w]) == 0) {
  578.             cout << "That run is already on the list. ";
  579.             haveRun = true;
  580.           }
  581.         }
  582.       }
  583.  
  584.       if (!haveRun) {
  585.         runlist[runcount] = scratch;
  586.         runcount++;
  587.       }
  588.     } else {
  589.       cout << "That run doesn't exist (" << testFile << ")." << endl;
  590.     }
  591.   } /* end while */
  592.  
  593.   /* check all files to see how many entries they have */
  594.  
  595.   bool fileGood[15][15] = {{false}};
  596.   string segmentName[15][15];
  597.  
  598.   long long int entryTotal(0);
  599.   long long int allEntries(0);
  600.  
  601.   int thisrunEntries(0);
  602.  
  603.   long long int runTotal[15] = {0};
  604.  
  605.   long int fileStart[15]   = {0};
  606.   long int fileEnd[15]     = {0};
  607.   long int fileEntries[15] = {0};
  608.  
  609.   /* cout << "runcount: " << runcount << endl; */
  610.  
  611.   for (int r=0; r<runcount; r++) {
  612.  
  613.     if (runlist[r].length() == 0) {cout << "exiting" << endl; break;}
  614.  
  615.     /* string dir = runDir + "/Run" + padRun(runlist[r]); */
  616.     string dir(runDir);
  617.  
  618.     entryTotal = 0;
  619.  
  620.     for (int iii=0; iii<15; iii++) {
  621.  
  622.       fileStart[iii] = 0; fileEnd[iii] = 0; fileEntries[iii] = 0;
  623.  
  624.       string part;
  625.       string fileName  = "";
  626.  
  627.       stringstream convert;
  628.  
  629.       convert << iii;
  630.       part = convert.str();
  631.       part = "_" + part;
  632.       convert.str("");
  633.  
  634.       if (iii == 0) {part = "";} /* there's no _0 */
  635.  
  636.       fileName = dir + "/Run" + padRun(runlist[r]) + part + ".root";
  637.  
  638.       if (!(fileExists(fileName))) {
  639.         fileGood[r][iii] = false;
  640.  
  641.         /* If the previous file was last file in a group, store total entry count */
  642.         if (iii > 0) {
  643.           if (fileGood[r][iii-1]) {
  644.             runTotal[r] = entryTotal;
  645.           }
  646.         } else {
  647.           runTotal[r] = entryTotal;
  648.         }
  649.  
  650.       } else {
  651.         fileGood[r][iii] = true;
  652.         segmentName[r][iii] = fileName;
  653.  
  654.         TFile *entryCheck = TFile::Open(segmentName[r][iii].c_str(),"READ");
  655.  
  656.         if ((gDirectory->GetListOfKeys()->Contains("teb")) == 0) {
  657.           fileGood[r][iii] = false;
  658.           break; /* skip invalid file */
  659.         } else {
  660.           fileGood[r][iii] = true;
  661.  
  662.           TTree *thistree = (TTree*)gROOT->FindObject("teb");
  663.  
  664.           fileEntries[iii] = thistree->GetEntries();
  665.           delete thistree;
  666.  
  667.           entryTotal = entryTotal + fileEntries[iii];
  668.  
  669.           if (iii == 0) {fileStart[iii] = 0;} else {fileStart[iii] = fileEnd[iii-1]+1;}
  670.           fileEnd[iii] = (fileStart[iii] + fileEntries[iii])-1;
  671.         }
  672.  
  673.         entryCheck->Close();
  674.         entryCheck->Clear();
  675.  
  676.         delete entryCheck;
  677.       }
  678.  
  679.     } /* existence check done (iii) */
  680.  
  681.     /* now add up total across all runs */
  682.     if (r == (runcount-1)) {
  683.       for (int t=0; t<15; t++) {
  684.         allEntries = allEntries + runTotal[t];
  685.       }
  686.     }
  687.   } /* end r loop */
  688.  
  689.   cout << "Entries across all runs: " << addCommas(allEntries) << endl;
  690.  
  691.   /* find out how many entries to check */
  692.   string entriesStr = "";
  693.  
  694.   cout << endl;
  695.  
  696.   cout << "How many entries (or what percentage) to process out of "
  697.        << addCommas(allEntries) << " entries (0 to quit)? "; cin >> entriesStr;
  698.  
  699.   while (1) {
  700.     if (entriesStr == '0') {
  701.       cout << endl << "Aw, sorry to see you go! Bye!" << endl;
  702.       cout << endl;
  703.       return;
  704.     }
  705.  
  706.     if ((entries > allEntries) || (entries == -1)) {
  707.       /* cout << "More or -1." << endl; */
  708.       entries = allEntries;
  709.       break;
  710.     }
  711.  
  712.     if (entriesStr[entriesStr.length()-1] == '%') {
  713.       entriesStr = entriesStr.substr(0, entriesStr.size()-1);
  714.       if (isNumber(entriesStr)) {
  715.         entries = atoi(entriesStr.c_str());
  716.       }
  717.       if (entries >= 100) {
  718.         entries = allEntries;
  719.       } else {
  720.         entries = TMath::Nint((float)(allEntries * (entries/100))); /* round off answer */
  721.       }
  722.       break;
  723.     } else if (isNumber(entriesStr)) {
  724.       entries = atoi(entriesStr.c_str());
  725.       break;
  726.     } else {
  727.       cout << "I don't understand your answer." << endl;
  728.       break;
  729.     }
  730.   } /* got count */
  731.  
  732.   cout << "Will process " << fixed << setprecision(2) << ((float)entries/(float)allEntries)*100
  733.        << "% of available events (" << fixed << setprecision(0) << addCommas(entries) << ")." << endl;
  734.  
  735.   interval = 1000;
  736.   /* if ((entries > 99)  && (entries <= 999))        {interval = 100;} */
  737.   /* if ((entries > 9)   && (entries <= 99))         {interval = 10;} */
  738.   /* if ((entries > 0)   && (entries <= 9))          {interval = 1;} */
  739.  
  740.   cout << "Will notify of progress every " << addCommas(interval) << " event(s)." << endl;
  741.   cout << "A total of " << addCommas(entries) << " events will be analysed." << endl << endl;
  742.  
  743.   if (debugBananas) {
  744.  
  745.   }
  746.  
  747.   /* loop over files */
  748.   for (int r=0; r<runcount; r++) {
  749.  
  750.     thisrunEntries = 0;
  751.  
  752.     for (int iExtra=0; iExtra<15; iExtra++) {
  753.  
  754.       if (!(fileGood[r][iExtra])) {
  755.         /* file will be skipped if that index didn't exist */
  756.       } else {
  757.  
  758.         TFile *thisFile = TFile::Open(segmentName[r][iExtra].c_str(),"READ");
  759.  
  760.         if (!(thisFile->IsOpen())) {
  761.           /* cout << "Could not open file." << endl; */
  762.         } else {
  763.           TKey *tebKey = gDirectory->FindKey("teb");
  764.           if (tebKey ==  0) {
  765.             cout << "Can't find tree 'teb'!" << endl;
  766.             return;
  767.           }
  768.  
  769.           gtree ttree; /* load class into memory (not doing this causes crash) */
  770.  
  771.           TTree *thistree = (TTree*)gROOT->FindObject("teb");
  772.  
  773.           /* Add tree-friend (is that an Ent?) */
  774.           string friendFile = segmentName[r][iExtra];
  775.           //friendFile = friendFile.substr(0, (friendFile.length()-5)); /* chop off ".root" */
  776.           friendFile = friendFile.substr(runDir.length(), (friendFile.length()-5)); /* chop off ".root" */
  777.           friendFile = friendFile + ".banana-tree-test-" + entriesStr + "-entries.root";
  778.           friendFile = "/data/files/atlas1593/gretina/bananas" + friendFile; /* no trailing slash */
  779.  
  780.           cout << "Now saving to " << friendFile << endl;
  781.  
  782.           TFile *ff = new TFile(friendFile.c_str(),"RECREATE");
  783.  
  784.           TTree *data = new TTree("data","Particle and gamma/Doppler data");
  785.           //data->AutoSave("500");
  786.           data->AutoSave("SaveSelf");
  787.  
  788.           thistree->SetBranchStatus("*",0); /* turn off branches we're not interested in right now */
  789.  
  790.           thistree->SetBranchStatus("pwall.raw.hit",1);
  791.           thistree->SetBranchStatus("pwall.raw.hit.pixel",1);
  792.           thistree->SetBranchStatus("pwall.raw.hit.A",1);
  793.           thistree->SetBranchStatus("pwall.raw.hit.B",1);
  794.           thistree->SetBranchStatus("pwall.raw.hit.C",1);
  795.           thistree->SetBranchStatus("pwall.raw.hit.T",1);
  796.           thistree->SetBranchStatus("pwall.timestamp",1);
  797.  
  798.           thistree->SetBranchStatus("pwall.aux.qdc.channel",1);
  799.           thistree->SetBranchStatus("pwall.aux.qdc.value",1);
  800.           thistree->SetBranchStatus("pwall.aux.tdc.channel",1);
  801.           thistree->SetBranchStatus("pwall.aux.tdc.value",1);
  802.           thistree->SetBranchStatus("pwall.aux.auxtimestamp",1);
  803.  
  804.           thistree->SetBranchStatus("xtals.cc",1);
  805.           thistree->SetBranchStatus("xtals.doppler",1);
  806.           thistree->SetBranchStatus("xtals.crystalID",1);
  807.           thistree->SetBranchStatus("xtals.timestamp",1);
  808.           thistree->SetBranchStatus("xtals.t0",1);
  809.  
  810.           thistree->SetBranchAddress("pwall.raw.hit",&mult);
  811.           thistree->SetBranchAddress("pwall.raw.hit.pixel",&hitP);
  812.           thistree->SetBranchAddress("pwall.raw.hit.A",&hitA);
  813.           thistree->SetBranchAddress("pwall.raw.hit.B",&hitB);
  814.           thistree->SetBranchAddress("pwall.raw.hit.C",&hitC);
  815.           thistree->SetBranchAddress("pwall.raw.hit.T",&hitT);
  816.           thistree->SetBranchAddress("pwall.timestamp",&pw_time);
  817.           thistree->SetBranchAddress("pwall.aux.auxtimestamp",&aux_time);
  818.  
  819.           thistree->SetBranchAddress("xtals.cc",&G);
  820.           thistree->SetBranchAddress("xtals.doppler",&d);
  821.           thistree->SetBranchAddress("xtals.crystalID",&gs_det);
  822.           thistree->SetBranchAddress("xtals.timestamp",&gs_time);
  823.           thistree->SetBranchAddress("xtals.t0",&t0);
  824.  
  825.           thistree->SetBranchAddress("pwall.aux.qdc.channel",&qdc_chan);
  826.           thistree->SetBranchAddress("pwall.aux.qdc.value",&qdc_value);
  827.           thistree->SetBranchAddress("pwall.aux.tdc.channel",&tdc_chan);
  828.           thistree->SetBranchAddress("pwall.aux.tdc.value",&tdc_value);
  829.  
  830.           data->Branch("pw_mult", &mult);
  831.           data->Branch("pixel", hitP, "pixel[pw_mult]/I");
  832.           data->Branch("A", hitA, "A[pw_mult]/I");
  833.           data->Branch("B", hitB, "B[pw_mult]/I");
  834.           data->Branch("C", hitC, "C[pw_mult]/I");
  835.           data->Branch("T", hitT, "T[pw_mult]/I");
  836.  
  837.           data->Branch("angle_group", angle_group, "angle_group[pw_mult]/I");
  838.           data->Branch("angle", angle, "angle[pw_mult]/F");
  839.           data->Branch("efficiency", efficiency, "efficiency[pw_mult]/F");
  840.  
  841.           data->Branch("pw_time", &pw_time);
  842.  
  843.           data->Branch("gs_mult", &gs_mult);
  844.           data->Branch("gs_det", gs_det, "gs_det[gs_mult]/I");
  845.           data->Branch("G", G, "G[gs_mult]/F");
  846.           data->Branch("d", d, "d[gs_mult]/F");
  847.  
  848.           data->Branch("gs_time", gs_time, "gs_time[gs_mult]/L");
  849.           data->Branch("ts_diff", ts_diff, "ts_diff[gs_mult]/L");
  850.           data->Branch("t0", t0, "t0[gs_mult]/F");
  851.  
  852.           /* data->Branch("have0", have0, "have0[pw_mult]/O"); */
  853.           /* data->Branch("have1", have1, "have1[pw_mult]/O"); */
  854.           /* data->Branch("have2", have2, "have2[pw_mult]/O"); */
  855.           /* data->Branch("have3", have3, "have3[pw_mult]/O"); */
  856.           /* data->Branch("have4", have4, "have4[pw_mult]/O"); */
  857.  
  858.           data->Branch("aux_mult", &aux_mult);
  859.           data->Branch("qdc_chan", qdc_chan, "qdc_chan[aux_mult]/I");
  860.           data->Branch("qdc_value", qdc_value, "qdc_value[aux_mult]/I");
  861.           data->Branch("tdc_chan", tdc_chan, "tdc_chan[aux_mult]/I");
  862.           data->Branch("tdc_value", tdc_value, "tdc_value[aux_mult]/I");
  863.           data->Branch("aux_time", &aux_time);
  864.  
  865.           data->Branch("in0", in0, "in0[pw_mult]/O");
  866.           data->Branch("in1", in1, "in1[pw_mult]/O");
  867.           data->Branch("in2", in2, "in2[pw_mult]/O");
  868.           data->Branch("in3", in3, "in3[pw_mult]/O");
  869.           data->Branch("in4", in4, "in4[pw_mult]/O");
  870.           data->Branch("inNone", inNone, "inNone[pw_mult]/O");
  871.  
  872.           /* data->Branch("b0", &b0); */
  873.           /* data->Branch("b1", &b1); */
  874.           /* data->Branch("b2", &b2); */
  875.           /* data->Branch("b3", &b3); */
  876.           /* data->Branch("b4", &b4); */
  877.  
  878.           //data->Branch("bAny", &bAny);
  879.           data->Branch("bNone", &bNone);
  880.  
  881.           setupPeakArrays(bananaFolder, 2, "AC");
  882.  
  883.           string bananasDir = peakDir + "/" + bananaFolder + "/ihist-" + intStr(ihist);
  884.  
  885.           if (debugBananas) {
  886.             TCanvas *DebugCanvas = new TCanvas("DebugCanvas", "Debug Canvas", 2);
  887.             int size = 2000; string title = "Debug canvas";
  888.             TH2C *Debug = new TH2C("Debug",title.c_str(),size,0,size,size,0,size);
  889.             Debug->Draw();
  890.           }
  891.  
  892.           if ((!gotem) && (iExtra == 0)) {
  893.             cout << "Getting " << addCommas(entries) << " events" << " ";
  894.           }
  895.  
  896.           /* ------------------------ ANALYSE ENTRY -------------------------- */
  897.  
  898.           /* loop over entries */
  899.           for (int thisentry=fileStart[iExtra]; thisentry<=fileEnd[iExtra]; thisentry++) {
  900.  
  901.             for (int iii=0; iii<256; iii++) {
  902.               in0[iii] = false; in1[iii] = false; in2[iii] = false; in3[iii] = false; in4[iii] = false; inNone[iii] = false;
  903.               have0[iii] = false; have1[iii] = false; have2[iii] = false; have3[iii] = false; have4[iii] = false;
  904.               G[iii] = 0.0; d[iii] = 0.0; gs_det[iii] = 0; gs_time[iii] = 0; ts_diff[iii] = 0;
  905.               qdc_chan[iii] = 0; qdc_value[iii] = 0; tdc_chan[iii] = 0; tdc_value[iii] = 0;
  906.               angle_group[iii] = 0; angle[iii] = 0; efficiency[iii] = 0.0;
  907.             }
  908.  
  909.             b0 = false; b1 = false; b2 = false; b3 = false; b4 = false; bAny = false; bNone = false;
  910.             pw_mult = 0; gs_mult = 0; aux_mult = 0; pw_time = 0; aux_time = 0;
  911.  
  912.             thistree->GetEntry(thisentry); /* grab entry */
  913.             thisrunEntries++;
  914.             totalEntries++;
  915.  
  916.             /* figure out mults */
  917.             for (int iii=0; iii<256; iii++) {
  918.               if (G[iii] != 0) {gs_mult = iii+1;}
  919.               if (qdc_chan[iii] != 0) {aux_mult = iii+1;}
  920.             }
  921.  
  922.             pw_mult = mult;
  923.  
  924.             /* get PW geometry stats */
  925.             for (int iii=0; iii<pw_mult; iii++) {
  926.               angle[iii] = pix_angle[hitP[iii]];
  927.               angle_group[iii] = group[hitP[iii]];
  928.               efficiency[iii] = 1.0/eff[hitP[iii]];
  929.             }
  930.  
  931.             char ticker;
  932.             if (thisentry%2 == 0) {ticker = '-';} else {ticker = '|';}
  933.  
  934.             if (thisentry % interval == 0) {
  935.               cout << "  Entries so far: " << addCommas(thisentry) << " \r" << flush;
  936.             }
  937.  
  938.             if ((thisentry == fileStart[iExtra]) && (thisentry < entries)) {
  939.               int last(fileEnd[iExtra]);
  940.               if (entries < fileEnd[iExtra]) {last = entries;}
  941.  
  942.               cout << endl << "Starting file " << segmentName[r][iExtra] /* << ": " << iExtra */
  943.                    << " (processing entries " << addCommas(fileStart[iExtra])
  944.                    << "-" << addCommas(last) << ")." << endl;
  945.  
  946.               cout << "entries: " << addCommas(entries) << " totalEntries: " << addCommas(totalEntries) << endl;
  947.               cout << endl;
  948.             }
  949.  
  950.             if (totalEntries > entries) {
  951.               gotem = true;
  952.               //return;
  953.               break;
  954.             } else {
  955.               if (thisrunEntries > entries) {
  956.                 gotem = true;
  957.                 break;
  958.               }
  959.             }
  960.  
  961.             for (int ii=0; ii<pw_mult; ii++) {
  962.               if (verbose) {
  963.               cout << "ii: " << ii << " pixel: " << setw(3) << hitP[ii]
  964.                    << " A: " << setw(4) << hitA[ii]
  965.                    << " C: " << setw(4) << hitC[ii]
  966.                    << " E: " << thisentry << endl;
  967.               }
  968.  
  969.               ts_diff[ii] = pw_time - gs_time[ii];
  970.  
  971.               if (gs_mult > 0) {
  972.                 /* check which AC bananas are defined */
  973.                 if (vertices[1][hitP[ii]][0] > 0) {have0[ii] = true;} else {have0[ii] = false;}
  974.                 if (vertices[1][hitP[ii]][1] > 0) {have1[ii] = true;} else {have1[ii] = false;}
  975.                 if (vertices[1][hitP[ii]][2] > 0) {have2[ii] = true;} else {have2[ii] = false;}
  976.                 if (vertices[1][hitP[ii]][3] > 0) {have3[ii] = true;} else {have3[ii] = false;}
  977.                 if (vertices[1][hitP[ii]][4] > 0) {have4[ii] = true;} else {have4[ii] = false;}
  978.  
  979.                 if (have0[ii]) {in0[ii] = inBanana(2,"AC",hitP[ii],hitA[ii],hitC[ii],0);}
  980.                 if (have1[ii]) {in1[ii] = inBanana(2,"AC",hitP[ii],hitA[ii],hitC[ii],1);}
  981.                 if (have2[ii]) {in2[ii] = inBanana(2,"AC",hitP[ii],hitA[ii],hitC[ii],2);}
  982.                 if (have3[ii]) {in3[ii] = inBanana(2,"AC",hitP[ii],hitA[ii],hitC[ii],3);}
  983.                 if (have4[ii]) {in4[ii] = inBanana(2,"AC",hitP[ii],hitA[ii],hitC[ii],4);}
  984.  
  985.                 /* how many bananas? */
  986.                 int howmany(0), inBananas(0);
  987.                 /* if (have4[ii])      {howmany = 5;} */
  988.                 /* else if (have3[ii]) {howmany = 4;} */
  989.                 /* else if (have2[ii]) {howmany = 3;} */
  990.                 /* else if (have1[ii]) {howmany = 2;} */
  991.                 /* else if (have0[ii]) {howmany = 1;} */
  992.  
  993.                 if (in0[ii] && have0[ii]) {inBananas++;}
  994.                 if (in1[ii] && have1[ii]) {inBananas++;}
  995.                 if (in2[ii] && have2[ii]) {inBananas++;}
  996.                 if (in3[ii] && have3[ii]) {inBananas++;}
  997.                 if (in4[ii] && have4[ii]) {inBananas++;}
  998.  
  999.                 if (inBananas == 0) {inNone[ii] = true;} else {inNone[ii] = false;}
  1000.               }
  1001.  
  1002.               /* if (howmany != inBananas) {inNone[ii] = true;} */
  1003.  
  1004.               /* if (in0[ii] && have0[ii]) {b0 = true; bAny = true;} */
  1005.               /* if (in1[ii] && have1[ii]) {b1 = true; bAny = true;} */
  1006.               /* if (in2[ii] && have2[ii]) {b2 = true; bAny = true;} */
  1007.               /* if (in3[ii] && have3[ii]) {b3 = true; bAny = true;} */
  1008.               /* if (in4[ii] && have4[ii]) {b4 = true; bAny = true;} */
  1009.  
  1010.               /* if ((!in0[ii] && have0[ii]) && (!in1[ii] && have1[ii]) && */
  1011.               /*          (!in2[ii] && have2[ii]) && (!in3[ii] && have3[ii]) && */
  1012.               /*          (!in4[ii] && have4[ii])) {inNone[ii] = true;} */
  1013.  
  1014.               //if (!in0[ii] && !in1[ii] && !in2[ii] && !in3[ii] && !in4[ii]) {bNone = true;}
  1015.               if (!bAny) {bNone = true;}
  1016.  
  1017.               if (debugBananas) {
  1018.                 TMarker *mark1 = new TMarker(hitA[ii],hitC[ii], 2);
  1019.                 TMarker *mark2 = new TMarker(hitA[ii],hitC[ii], 5);
  1020.  
  1021.                 mark1->SetMarkerColor(20);
  1022.                 if (in0[ii]) {mark1->SetMarkerColor(2);}
  1023.                 if (in1[ii]) {mark1->SetMarkerColor(3);}
  1024.                 if (in2[ii]) {mark1->SetMarkerColor(6);}
  1025.  
  1026.                 mark2->SetMarkerColor(20);
  1027.                 if (b0) {mark2->SetMarkerColor(2);}
  1028.                 if (b1) {mark2->SetMarkerColor(3);}
  1029.                 if (b2) {mark2->SetMarkerColor(6);}
  1030.  
  1031.                 mark1->Draw(); mark2->Draw();
  1032.                 DebugCanvas->Update();
  1033.               }
  1034.  
  1035.               if (verbose) {
  1036.                 cout << "Arguments: "
  1037.                      << "P: " << hitP[ii] << " "
  1038.                      << "A: " << hitA[ii] << " "
  1039.                      << "C: " << hitC[ii] << " "
  1040.                      << endl;
  1041.  
  1042.                 cout << "Results:" << " "
  1043.                      << in0[ii] << "/" << b0 << " "
  1044.                      << in1[ii] << "/" << b1 << " "
  1045.                      << in2[ii] << "/" << b2 << " "
  1046.                      << in3[ii] << "/" << b3 << " "
  1047.                      << in4[ii] << "/" << b4 << " "
  1048.                      << bAny << endl;
  1049.  
  1050.                 cout << "Vertices:" << " "
  1051.                      << "0: " << vertices[1][hitP[ii]][0] << " "
  1052.                      << "1: " << vertices[1][hitP[ii]][1] << " "
  1053.                      << "2: " << vertices[1][hitP[ii]][2] << " "
  1054.                      << "3: " << vertices[1][hitP[ii]][3] << " "
  1055.                      << "4: " << vertices[1][hitP[ii]][4] << " "
  1056.                      << endl;
  1057.  
  1058.                 cout << endl;
  1059.               }
  1060.             } /* end ii loop */
  1061.  
  1062.             /* if (!have0 && !have1 && !have2 && !have3 && !have4 && !bAny) {bNone = true;} */
  1063.             /* if ((have0 && !b0) && (have1 && !b1) && (have2 && !b2) && (have3 && !b3) && (have4 && !b4)) {bNone = true;} */
  1064.  
  1065.             /* if ((have0 && !b0) && (have1 && !b1) && (have2 && !b2) && (have3 && !b3) && (have4 && !b4)) { */
  1066.             /*   bNone = true; */
  1067.             /* } else { */
  1068.             /*   bNone = false; */
  1069.             /* } */
  1070.  
  1071.             data->Fill();
  1072.           } /* we still need more entries (END ENTRY LOOP HERE) */
  1073.         } /* entry loop end */
  1074.  
  1075.         cout << "Done." << endl;
  1076.  
  1077.         data->Write(); /* should save to file ff since it was last file opened */
  1078.  
  1079.         ff->Close();
  1080.  
  1081.         TFile *_file0 = new TFile(friendFile.c_str(),"READ");
  1082.       }
  1083.     }
  1084.   }
  1085.  
  1086.  
  1087.  
  1088.   return 1;
  1089. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement