Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FillHoughHist.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FillHoughHist.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 "AZigzag.h"
9 
10 #include <iostream>
11 #include <cmath>
12 
13 TH2D* HoughHistMC = 0; // This is in relative coordinates to "tune" the Hough Space.
14 TH2D* HoughHistABS = 0; // This is in absolute coordinates to "solve" the Hough Space.
15 
16 using namespace std;
17 
19 {
20  groot* Tree=groot::instance();
21 
22  if (!HoughHistMC)
23  {
24  HoughHistMC = new TH2D("HoughHistMC", "HoughHistMC" , 10, (Med_inverseSlope - 10*MAD_inverseSlope),(Med_inverseSlope + 10*MAD_inverseSlope), 10 , (Med_Offset - 10*MAD_Offset), (Med_Offset + 10*MAD_Offset));
25 
26 
27  double x00 = Tree->ZigzagMap2[0][0]->XCenter();
28  double y00 = Tree->ZigzagMap2[0][0]->YCenter();
29  double x11 = Tree->ZigzagMap2[Nr][Nphi]->XCenter();
30  double y11 = Tree->ZigzagMap2[Nr][Nphi]->YCenter();
31 
32  double mi = abs(inverseSlope(x00, y00, x11, y11));
33  double c = abs(intercept(x00, y00, x11, y11));
34 
35  int NHOUGHX = 2*mi/(HFACTOR*MAD_inverseSlope);
36  int NHOUGHY = 2*c/(HFACTOR*MAD_Offset);
37 
38  HoughHistABS = new TH2D("HoughHistABS", "HoughHistABS" , NHOUGHX, -mi, mi, NHOUGHY, -c, c);
39  }
40  HoughHistMC->Reset();
41  HoughHistABS->Reset();
42  int Npoints=0;
43  for (int i=0; i<Nr;i++)
44  {
45  Npoints+=Tree->theBlobs[i].size();
46  }
47 
48  //cout<<"checking............";
49  double points[2][Npoints];
50  for (int i=0; i<Npoints; i++)
51  {
52  points[0][i]=0;
53  points[1][i]=0;
54  }
55  //cout<<"\n\n\n\t\t\t"<<Npoints<<"\n\n";
56  int k=0;
57  for (int i=0; i<Nr; i++)
58  {
59  for (int j=0; j< Tree->theBlobs[i].size(); j++)
60  {
61  points[0][k] = (Tree->theBlobs[i])[j]->CentroidX(); //X value
62  points[1][k]= (Tree->theBlobs[i])[j]->CentroidY(); // Y value
63  //cout<<"\n"<<points[0][k]<<"\t\t"<<points[1][k];
64  k++;
65  }
66 
67  }
68 
69 
70  vector<double> MI;
71  vector<double> C;
72  double y1,y2,x1,x2;
73  for (int i=0; i<k; i++)
74  {
75  for (int j=i+1; j<k; j++)
76  {
77  x1=points[0][i];
78  x2=points[0][j];
79  y1=points[1][i];
80  y2=points[1][j];
81  double mi = inverseSlope(x1, y1, x2, y2);
82  double c = intercept (x1, y1, x2, y2);
83  HoughHistABS->Fill(mi, c);
84  MI.push_back(mi);
85  C.push_back(c);
86  }
87  }
88 
89 
90  for (int i=0; i<k; i++)
91  {
92  for (int j=i+1; j<k; j++)
93  {
94  x1=points[0][i];
95  x2=points[0][j];
96  y1=points[1][i];
97  y2=points[1][j];
98  double mi = inverseSlope(x1, y1, x2, y2);
99  double c = intercept (x1, y1, x2, y2);
100  HoughHistMC->Fill(mi, c);
101  }
102  }
103 
104  //ATrack *theTracks;
105  //int binmax = HoughHistMC->GetMaximumBin();
106  //double Var[2];
107  //Var[0] = 1/(HoughHistMC->GetXaxis()->GetBinCenter(binmax));
108  //Var[1] = HoughHistMC->GetYaxis()->GetBinCenter(binmax);
109  //Tree->theTracks->SetSlope(Var[0]);
110  //Tree->theTracks->SetOffset(Var[1]);
111  // cout<<"\nFinal\t"<<Tree->theTracks.Slope<<"\t"<<Tree->theTracks.Offset;
112  //cout <<"\ncheck........"<<(Tree->theTracks)->check();
113 
114 
115 }
116 
117 double inverseSlope(double x1, double y1, double x2, double y2)
118 {
119  double mi = (x2-x1)/(y2-y1);
120  return mi;
121 }
122 
123 double intercept (double x1, double y1, double x2, double y2)
124 {
125  double c= (y2*x1 - y1*x2)/(x1-x2);
126  return c;
127 }