CMS 3D CMS Logo

EcalTBHodoscopeRecInfoAlgo.cc
Go to the documentation of this file.
3 
4 #include <list>
5 
7  const std::vector<double>& planeShift,
8  const std::vector<double>& zPosition)
9  : fitMethod_(fitMethod), planeShift_(planeShift), zPosition_(zPosition), myGeometry_() {}
10 
12  float& x, float& xQuality, const int& ipl, const int& xclus, const int& width) const {
13  if (width == 1) {
14  // Single fiber
15  x = (myGeometry_.getFibreLp(ipl, xclus) + myGeometry_.getFibreRp(ipl, xclus)) / 2.0 - planeShift_[ipl];
16  xQuality = (myGeometry_.getFibreRp(ipl, xclus) - myGeometry_.getFibreLp(ipl, xclus));
17  } else if (width == 2) {
18  // Two half overlapped fibers
19  x = (myGeometry_.getFibreLp(ipl, xclus + 1) + myGeometry_.getFibreRp(ipl, xclus)) / 2.0 - planeShift_[ipl];
20  xQuality = (myGeometry_.getFibreRp(ipl, xclus) - myGeometry_.getFibreLp(ipl, xclus + 1));
21  } else {
22  // More then two fibers case
23  x = (myGeometry_.getFibreLp(ipl, xclus) + myGeometry_.getFibreRp(ipl, xclus + width - 1)) / 2.0 - planeShift_[ipl];
24  xQuality = (myGeometry_.getFibreRp(ipl, xclus + width - 1) - myGeometry_.getFibreLp(ipl, xclus));
25  }
26 }
27 
29  float& xQuality,
30  const int& ipl,
31  const int& nclus,
32  const std::vector<int>& xclus,
33  const std::vector<int>& wclus) const {
34  if (nclus == 1) {
35  // Fill real x as mean position inside the cluster
36  // Quality - width of cluster
37  // To calculate sigma one can do sigma=sqrt(Quality**2/12.0)
38  clusterPos(x, xQuality, ipl, xclus[0], wclus[0]);
39  } else {
40  xQuality = -10 - nclus;
41  }
42 }
43 
45  float& xSlope,
46  float& xQuality,
47  const int& ipl1,
48  const int& nclus1,
49  const std::vector<int>& xclus1,
50  const std::vector<int>& wclus1,
51  const int& ipl2,
52  const int& nclus2,
53  const std::vector<int>& xclus2,
54  const std::vector<int>& wclus2) const {
55  if (nclus1 == 0) { // Fit with one plane
56  fitHodo(x, xQuality, ipl2, nclus2, xclus2, wclus2);
57  xSlope = 0.0; //?? Should we put another number indicating that is not fitted
58  return;
59  }
60  if (nclus2 == 0) { // Fit with one plane
61  fitHodo(x, xQuality, ipl1, nclus1, xclus1, wclus1);
62  xSlope = 0.0; //?? Should we put another number indicating that is not fitted
63  return;
64  }
65 
66  // We have clusters in both planes
67 
68  float x1, x2, xQ1, xQ2;
69  float xs, x0, xq;
70 
71  std::list<BeamTrack> tracks;
72 
73  for (int i1 = 0; i1 < nclus1; i1++) {
74  for (int i2 = 0; i2 < nclus2; i2++) {
75  clusterPos(x1, xQ1, ipl1, xclus1[i1], wclus1[i1]);
76  clusterPos(x2, xQ2, ipl2, xclus2[i2], wclus2[i2]);
77 
78  xs = (x2 - x1) / (zPosition_[ipl2] - zPosition_[ipl1]); // slope
79  x0 = ((x2 + x1) - xs * (zPosition_[ipl2] + zPosition_[ipl1])) / 2.0; // x0
80  xq = (xQ1 + xQ2) / 2.0; // Quality, how i can do better ?
81  tracks.push_back(BeamTrack(x0, xs, xq));
82  }
83  }
84 
85  // find track with minimal slope
86  tracks.sort();
87 
88  // Return results
89  x = tracks.begin()->x;
90  xSlope = tracks.begin()->xS;
91  xQuality = tracks.begin()->xQ;
92 }
93 
95  // Reset Hodo data
96  float x = -100.0, y = -100.0;
97  float xSlope = 0.0, ySlope = 0.0;
98  float xQuality = -100.0, yQuality = -100.0;
99 
100  int nclus[4] = {0};
101  std::vector<int> xclus[4];
102  std::vector<int> wclus[4];
103 
104  for (int ipl = 0; ipl < myGeometry_.getNPlanes(); ipl++) {
105  int nhits = hodoscopeRawInfo[ipl].numberOfFiredHits();
106  // Finding clusters
107  nclus[ipl] = 0;
108  if (nhits > 0) {
109  int nh = nhits;
110  int first = 0;
111  int last = 0;
112  while (nh > 0) {
113  while (hodoscopeRawInfo[ipl][first] == 0)
114  first++; // start
115  last = first + 1;
116  nh--;
117  do {
118  while (last < myGeometry_.getNFibres() && hodoscopeRawInfo[ipl][last]) {
119  last++;
120  nh--;
121  } //end
122  if (last + 1 < myGeometry_.getNFibres() && hodoscopeRawInfo[ipl][last + 1]) { //Skip 1 fibre hole
123  last += 2;
124  nh--;
125  //std::cout << "Skip fibre " << ipl << " " << first << " "<< last << std::endl;
126  } else {
127  break;
128  }
129  } while (nh > 0 && last < myGeometry_.getNFibres());
130  wclus[ipl].push_back(last - first);
131  xclus[ipl].push_back(first); // Left edge !!!
132  nclus[ipl]++;
133 
134  first = last + 1;
135  }
136  }
137  // printClusters(ipl);
138  }
139 
141  // Straight line fit for one axis
142  if (fitMethod_ == 0) {
143  fitLine(x,
144  xSlope,
145  xQuality,
146  0,
147  nclus[0],
148  xclus[0],
149  wclus[0], // X1
150  2,
151  nclus[2],
152  xclus[2],
153  wclus[2]); // X2
154  fitLine(y,
155  ySlope,
156  yQuality,
157  1,
158  nclus[1],
159  xclus[1],
160  wclus[1], // Y1
161  3,
162  nclus[3],
163  xclus[3],
164  wclus[3]); // Y2
165  } else if (fitMethod_ == 1) {
167  // x1 and y2 hodoscope
168  fitHodo(x, xQuality, 0, nclus[0], xclus[0], wclus[0]); // X1
169  // if ( xQuality[1] < 0.0 ) {
170  // printFibres(0);
171  // printClusters(0);
172  // }
173  fitHodo(y, yQuality, 1, nclus[1], xclus[1], wclus[1]); // Y1
174  // if ( yQuality[1] < 0.0 ) {
175  // printFibres(1);
176  // printClusters(1);
177  // }
178  } else if (fitMethod_ == 2) {
180  //x2 and y2 hodoscope
181  fitHodo(x, xQuality, 2, nclus[2], xclus[2], wclus[2]); // X2
182  // if ( xQuality[2] < 0.0 ) {
183  // printFibres(2);
184  // printClusters(2);
185  // }
186  fitHodo(y, yQuality, 3, nclus[3], xclus[3], wclus[3]); // Y2
187  // if ( yQuality[2] < 0.0 ) {
188  // printFibres(3);
189  // printClusters(3);
190  // }
191  }
192 
193  return EcalTBHodoscopeRecInfo(x, y, xSlope, ySlope, xQuality, yQuality);
194 }
EcalTBHodoscopeRecInfo reconstruct(const EcalTBHodoscopeRawInfo &hodoscopeRawInfo) const
void fitHodo(float &x, float &xQuality, const int &ipl, const int &nclus, const std::vector< int > &xclus, const std::vector< int > &wclus) const
static float getFibreLp(int plane, int fibre)
void clusterPos(float &x, float &xQuality, const int &ipl, const int &xclus, const int &wclus) const
uint32_t nh
EcalTBHodoscopeGeometry myGeometry_
float x
static float getFibreRp(int plane, int fibre)
void fitLine(float &x, float &xSlope, float &xQuality, const int &ipl1, const int &nclus1, const std::vector< int > &xclus1, const std::vector< int > &wclus1, const int &ipl2, const int &nclus2, const std::vector< int > &xclus2, const std::vector< int > &wclus2) const