Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HoughBinSize.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HoughBinSize.C
1 #include "FillHoughHist.h"
2 #include "TH1D.h"
3 #include "TH2D.h"
4 #include "ABlob.h"
5 #include "ATrack.h"
6 #include "groot.h"
7 
8 #include <iostream>
9 #include <cmath>
10 
11 TH2D* HoughHistMC = 0;
12 
13 using namespace std;
14 
16 {
17  if (!HoughHistMC)
18  {
19  HoughHistMC = new TH2D("HoughHistMC", "HoughHistMC" , 15 , -2.5 , 2.5, 12, 200, 2500);
20  }
21  //HoughHistMC->Reset();
22  groot* Tree=groot::instance();
23  int Npoints=0, k1=0; //number of points/blobs in an event. considering all tracks.
24  for (int i=0; i<Nr;i++)
25  {
26  Npoints+=Tree->theBlobs[i].size();
27  if (Tree->theBlobs[i].size()==1)
28  k1++;
29  }
30 
31  cout<<"checking............";
32  double points[2][k1];
33  for (int i=0; i<k1+1; i++)
34  {
35  points[0][i]=0;
36  points[1][i]=0;
37  }
38  cout<<"\n\n\n\t\t\t"<<Npoints<<"\n\n";
39  int k=0;
40  for (int i=0; i<Nr; i++)
41  {
42  for (int j=0; j< Tree->theBlobs[i].size(); j++)
43  { if (Tree->theBlobs[i].size()==1)
44  {
45  points[0][k] = (Tree->theBlobs[i])[j]->CentroidX(); //X value
46  points[1][k]= (Tree->theBlobs[i])[j]->CentroidY(); // Y value
47  //cout<<"\n"<<points[0][k]<<"\t\t"<<points[1][k];
48  k++;
49  }
50 
51  }
52  }
53 
54 
55  cout <<"\n N" << Npoints <<"\t k1"<<k1<<"\t K"<<k;
56  double m, c;
57 
58  static std::vector <double> inverse_slope;
59  static std::vector <double> offset;
60  double y1,y2,x1,x2;
61  for (int i=0; i<k; i++)
62  {
63  for (int j=i+1; j<k; j++)
64  {
65  x1=points[0][i];
66  x2=points[0][j];
67  y1=points[1][i];
68  y2=points[1][j];
69  m= (y2-y1)/(x2-x1);
70  c= (y2*x1 - y1*x2)/(x1-x2);
71  inverse_slope.push_back(1/m);
72  offset.push_back(c);
73  //HoughHistMC->Fill(1/m,c);
74  //cout<<"\n"<<m<<"\t"<<c;
75  }
76  }
77  int size = static_cast<int>(inverse_slope.size());
78  cout <<"\n Size "<< size;
79 
80  //Calculating Median of Slope and Offset for Bin Size determination.
81  double Median_InverseSlope, Median_Offset;
82  sort(inverse_slope.begin(), inverse_slope.end());
83  if (size % 2 != 0)
84  Median_InverseSlope = inverse_slope[(size+1)/2];
85  else
86  Median_InverseSlope = (inverse_slope[(size)/2] + inverse_slope[(size+2)/2])/2.0 ;
87  cout <<"\n Median_ Inverse Slope"<<Median_InverseSlope;
88 
89  sort(offset.begin(), offset.end());
90  if (size % 2 != 0)
91  Median_Offset = offset[(size+1)/2];
92  else
93  Median_Offset = (offset[(size)/2] + offset[(size+2)/2])/2.0 ;
94  cout <<"\nMedian_Offset"<<Median_Offset <<"\n";
95  /*
96  for(int i=0; i<size; ++i)
97  std::cout <<inverse_slope[i] << ' ';*/
98 
99 
100  //Calculating Std.devaition of Slope and Offset for Bin Size determination.
101 
102 
103 
104 
105  std::vector <double> accum_IS;
106  std::for_each (std::begin(inverse_slope), std::end(inverse_slope), [&](const double d) {
107  accum_IS.push_back(abs(d - Median_InverseSlope));
108  });
109  cout<<"\n Size of accum vector without static" << accum_IS.size();
110  /*
111  cout<<"\n the median deviation list\n";
112  for(int i=0; i<size; ++i)
113  std::cout <<accum[i] << ' ';*/
114 
115  double MAD_InverseSlope = 0;
116  sort(accum_IS.begin(), accum_IS.end());
117  if (size % 2 != 0)
118  MAD_InverseSlope = accum_IS[(size+1)/2];
119  else
120  MAD_InverseSlope = accum_IS[size/2];
121  //Med_dev = (accum[(size)/2] + accum[(size+2)/2])/2.0 ;
122 
123  cout <<"\n MAD_InverseSlope"<< MAD_InverseSlope;
124 
125 
126  std::vector <double> accum_O;
127  std::for_each (std::begin(inverse_slope), std::end(inverse_slope), [&](const double d) {
128  accum_O.push_back(abs(d - Median_Offset));
129  });
130 
131  cout<<"\n Size of accum vector with static" << accum_O.size();
132  /*
133  cout<<"\n the median deviation list\n";
134  for(int i=0; i<size; ++i)
135  std::cout <<accum[i] << ' ';*/
136 
137  double MAD_Offset = 0;
138  sort(accum_O.begin(), accum_O.end());
139  if (size % 2 != 0)
140  MAD_Offset = accum_O[(size+1)/2];
141  else
142  MAD_Offset = accum_O[size/2];
143  //Med_dev = (accum[(size)/2] + accum[(size+2)/2])/2.0 ;
144 
145  cout <<"\n MAD_Offset"<< MAD_Offset;
146 
147 
148 
149 
150 
151 
152  //ATrack *theTracks;
153  //int binmax = HoughHistMC->GetMaximumBin();
154  //double Var[2];
155  //Var[0] = 1/(HoughHistMC->GetXaxis()->GetBinCenter(binmax));
156  //Var[1] = HoughHistMC->GetYaxis()->GetBinCenter(binmax);
157  //Tree->theTracks->SetSlope(Var[0]);
158  //Tree->theTracks->SetOffset(Var[1]);
159  // cout<<"\nFinal\t"<<Tree->theTracks.Slope<<"\t"<<Tree->theTracks.Offset;
160  //cout <<"\ncheck........"<<(Tree->theTracks)->check();
161 
162 
163 }