CMS 3D CMS Logo

CSCDQM_StripClusterFinder.cc
Go to the documentation of this file.
1 
4 
5 namespace cscdqm {
6 
7  StripClusterFinder::StripClusterFinder(int l, int s, int cf, int st, bool ME11) {
8  //
9  // Options
10  //
11  // fOpt = new CalibOptions();
12  LayerNmb = l;
13  TimeSliceNmb = s;
14  StripNmb = cf * 16;
15  isME11 = ME11;
16  if (cf == 7) {
17  is7DCFEBs = true;
18  isME11 = true;
19  } else {
20  is7DCFEBs = false;
21  }
22  }
23  void StripClusterFinder::DoAction(int LayerId, float* Cathodes) {
24  int TimeId, StripId;
25  MEStripClusters.clear();
26  StripClusterFitData PulseHeightMapTMP;
27 
28  thePulseHeightMap.clear();
29 
30  // fill
31  //===========================================================================
32 
33  for (StripId = 0; StripId < StripNmb; StripId++) {
34  for (TimeId = 0; TimeId < TimeSliceNmb; TimeId++) {
35  PulseHeightMapTMP.height_[TimeId] = *(Cathodes + StripNmb * (TimeSliceNmb * LayerId + TimeId) + StripId);
36  }
37  PulseHeightMapTMP.bx_ = 0;
38  PulseHeightMapTMP.channel_ = StripId; // was StripId
39  thePulseHeightMap.push_back(PulseHeightMapTMP);
40  }
41  sort(thePulseHeightMap.begin(), thePulseHeightMap.end(), Sort());
42  //===========================================================================
43 
44  if (thePulseHeightMap.empty())
45  return;
46  SearchMax(LayerId);
47  SearchBorders();
48  Match();
49  RefindMax();
50  /*
51  int val;
52  for(i=0;i<MEStripClusters.size();i++){
53  val=MEStripClusters[i].LFTBNDStrip;
54  MEStripClusters[i].LFTBNDStrip=thePulseHeightMap[val].channel_;
55  val=MEStripClusters[i].IRTBNDStrip;
56  MEStripClusters[i].IRTBNDStrip=thePulseHeightMap[val].channel_;
57  for(j=0;j<MEStripClusters[i].localMax.size();j++){
58  val=MEStripClusters[i].localMax[j].Strip;
59  MEStripClusters[i].localMax[j].Strip=thePulseHeightMap[val].channel_;
60  }
61  }
62  */
63 
64  float sumstrip;
65  float sumtime;
66  float sumheight;
67 
68  for (uint32_t i = 0; i < MEStripClusters.size(); i++) {
69  MEStripClusters[i].ClusterPulseMapHeight.clear();
70  for (uint32_t j = 0; j < thePulseHeightMap.size(); j++) {
71  if (thePulseHeightMap[j].channel_ >= MEStripClusters[i].LFTBNDStrip &&
72  thePulseHeightMap[j].channel_ <= MEStripClusters[i].IRTBNDStrip)
73  MEStripClusters[i].ClusterPulseMapHeight.push_back(thePulseHeightMap[j]);
74  }
75  sumstrip = 0;
76  sumtime = 0;
77  sumheight = 0;
78  for (uint32_t k = 0; k < MEStripClusters[i].ClusterPulseMapHeight.size(); k++) {
79  for (int l = 0; l < 16; l++) {
80  sumstrip += MEStripClusters[i].ClusterPulseMapHeight[k].height_[l] *
81  (MEStripClusters[i].ClusterPulseMapHeight[k].channel_ + 1);
82  sumtime += MEStripClusters[i].ClusterPulseMapHeight[k].height_[l] * (l + 1);
83  sumheight += MEStripClusters[i].ClusterPulseMapHeight[k].height_[l];
84  }
85  }
86  if (sumheight) {
87  MEStripClusters[i].Mean[0] = sumstrip / sumheight;
88  MEStripClusters[i].Mean[1] = sumtime / sumheight;
89  }
90  }
91  // printClusters();
92  return;
93  }
94 
95  void StripClusterFinder::SearchMax(int32_t layerId) {
96  StripCluster tmpCluster;
97  for (uint32_t i = 1; i < (thePulseHeightMap.size() - 1); i++) {
98  if (isME11 && (thePulseHeightMap[i].channel_ == 63 || thePulseHeightMap[i].channel_ == 64))
99  continue;
100  for (uint32_t j = 1; j < 15; j++) {
101  if (thePulseHeightMap[i].height_[j] > thePulseHeightMap[i - 1].height_[j] &&
102  thePulseHeightMap[i].height_[j] > thePulseHeightMap[i + 1].height_[j] &&
103  thePulseHeightMap[i].height_[j] > thePulseHeightMap[i].height_[j - 1] &&
104  thePulseHeightMap[i].height_[j] > thePulseHeightMap[i].height_[j + 1] &&
105  thePulseHeightMap[i].height_[j] > thePulseHeightMap[i - 1].height_[j - 1] &&
106  thePulseHeightMap[i].height_[j] > thePulseHeightMap[i - 1].height_[j + 1] &&
107  thePulseHeightMap[i].height_[j] > thePulseHeightMap[i + 1].height_[j - 1] &&
108  thePulseHeightMap[i].height_[j] > thePulseHeightMap[i + 1].height_[j + 1]) {
109  tmpCluster.localMax.clear();
110  localMaxTMP.Strip = i;
111  localMaxTMP.Time = j;
112  tmpCluster.localMax.push_back(localMaxTMP);
113  tmpCluster.LayerId = layerId;
114  tmpCluster.LFTBNDTime = -100;
115  tmpCluster.LFTBNDStrip = -100;
116  tmpCluster.IRTBNDTime = -100;
117  tmpCluster.IRTBNDStrip = -100;
118  MEStripClusters.push_back(tmpCluster);
119  }
120  }
121  }
122  return;
123  }
125  uint32_t iS, iT, iL, jL, iR, jR;
126 
127  // SEARCHING PARAMETERS OF THE CLASTERS (LEFT DOWN & RIGHT UP)
128 
129  for (uint32_t i = 0; i < MEStripClusters.size(); i++) {
130  if (MEStripClusters[i].localMax.empty()) {
131  edm::LogWarning("NoLocalMax") << "Cluster " << i << " has no local Maxima";
132  continue;
133  }
134  iS = MEStripClusters[i].localMax[0].Strip;
135  iT = MEStripClusters[i].localMax[0].Time;
136  // LEFT DOWN
137  // strip
138  MEStripClusters[i].LFTBNDStrip = 0;
139  for (iL = iS - 1; iL > 0; iL--) {
140  if (isME11 && (thePulseHeightMap[iL].channel_ == 64)) {
141  MEStripClusters[i].LFTBNDStrip = iL;
142  break;
143  }
144  if (thePulseHeightMap[iL].height_[iT] == 0.) {
145  MEStripClusters[i].LFTBNDStrip = iL + 1;
146  break;
147  }
148  }
149  //time
150  MEStripClusters[i].LFTBNDTime = 0;
151  for (jL = iT - 1; jL > 0; jL--) {
152  if (thePulseHeightMap[iS].height_[jL] == 0.) {
153  MEStripClusters[i].LFTBNDTime = jL + 1;
154  break;
155  }
156  }
157  // RIGHT UP
158  //strip
159  MEStripClusters[i].IRTBNDStrip = thePulseHeightMap.size() - 1;
160  for (iR = iS + 1; iR < thePulseHeightMap.size(); iR++) {
161  if (isME11 && (thePulseHeightMap[iR].channel_ == 63)) {
162  MEStripClusters[i].IRTBNDStrip = iR;
163  break;
164  }
165  if (thePulseHeightMap[iR].height_[iT] == 0.) {
166  MEStripClusters[i].IRTBNDStrip = iR - 1;
167  break;
168  }
169  }
170  //time
171  MEStripClusters[i].IRTBNDTime = 15;
172  for (jR = iT + 1; jR < 16; jR++) {
173  if (thePulseHeightMap[iS].height_[jR] == 0.) {
174  MEStripClusters[i].IRTBNDTime = jR - 1;
175  break;
176  }
177  }
178  }
179  return;
180  }
181 
183  // MATCHING THE OVERLAPING CLASTERS
184  bool find2match = true;
185  do {
186  find2match = FindAndMatch();
187  } while (find2match);
188 
189  return;
190  }
191 
193  // Find clusters to match
194  for (uint32_t ic1 = 0; ic1 < MEStripClusters.size(); ic1++) {
195  C1 c1;
196  c1.IC1MIN = MEStripClusters[ic1].LFTBNDStrip;
197  c1.IC1MAX = MEStripClusters[ic1].IRTBNDStrip;
198  c1.JC1MIN = MEStripClusters[ic1].LFTBNDTime;
199  c1.JC1MAX = MEStripClusters[ic1].IRTBNDTime;
200  for (uint32_t ic2 = ic1 + 1; ic2 < MEStripClusters.size(); ic2++) {
201  C2 c2;
202  c2.IC2MIN = MEStripClusters[ic2].LFTBNDStrip;
203  c2.IC2MAX = MEStripClusters[ic2].IRTBNDStrip;
204  c2.JC2MIN = MEStripClusters[ic2].LFTBNDTime;
205  c2.JC2MAX = MEStripClusters[ic2].IRTBNDTime;
206  if ((c2.IC2MIN >= c1.IC1MIN && c2.IC2MIN <= c1.IC1MAX && c2.JC2MIN >= c1.JC1MIN && c2.JC2MIN <= c1.JC1MAX) ||
207  (c2.IC2MIN >= c1.IC1MIN && c2.IC2MIN <= c1.IC1MAX && c2.JC2MAX >= c1.JC1MIN && c2.JC2MAX <= c1.JC1MAX) ||
208  (c2.IC2MAX >= c1.IC1MIN && c2.IC2MAX <= c1.IC1MAX && c2.JC2MIN >= c1.JC1MIN && c2.JC2MIN <= c1.JC1MAX) ||
209  (c2.IC2MAX >= c1.IC1MIN && c2.IC2MAX <= c1.IC1MAX && c2.JC2MAX >= c1.JC1MIN && c2.JC2MAX <= c1.JC1MAX)) {
210  KillCluster(ic1, ic2, c1, c2);
211  return true;
212  } else {
213  if ((c1.IC1MIN >= c2.IC2MIN && c1.IC1MIN <= c2.IC2MAX && c1.JC1MIN >= c2.JC2MIN && c1.JC1MIN <= c2.JC2MAX) ||
214  (c1.IC1MIN >= c2.IC2MIN && c1.IC1MIN <= c2.IC2MAX && c1.JC1MAX >= c2.JC2MIN && c1.JC1MAX <= c2.JC2MAX) ||
215  (c1.IC1MAX >= c2.IC2MIN && c1.IC1MAX <= c2.IC2MAX && c1.JC1MIN >= c2.JC2MIN && c1.JC1MIN <= c2.JC2MAX) ||
216  (c1.IC1MAX >= c2.IC2MIN && c1.IC1MAX <= c2.IC2MAX && c1.JC1MAX >= c2.JC2MIN && c1.JC1MAX <= c2.JC2MAX)) {
217  KillCluster(ic1, ic2, c1, c2);
218  return true;
219  }
220  }
221  }
222  }
223  return false;
224  }
225  void StripClusterFinder::KillCluster(uint32_t ic1, uint32_t ic2, C1 const& c1, C2 const& c2) {
226  // Match Clusters and kill one of clusters.
227  if (c1.IC1MIN < c2.IC2MIN)
228  MEStripClusters[ic1].LFTBNDStrip = c1.IC1MIN;
229  else
230  MEStripClusters[ic1].LFTBNDStrip = c2.IC2MIN;
231  if (c1.JC1MIN < c2.JC2MIN)
232  MEStripClusters[ic1].LFTBNDTime = c1.JC1MIN;
233  else
234  MEStripClusters[ic1].LFTBNDTime = c2.JC2MIN;
235  if (c1.IC1MAX > c2.IC2MAX)
236  MEStripClusters[ic1].IRTBNDStrip = c1.IC1MAX;
237  else
238  MEStripClusters[ic1].IRTBNDStrip = c2.IC2MAX;
239  if (c1.JC1MAX > c2.JC2MAX)
240  MEStripClusters[ic1].IRTBNDTime = c1.JC1MAX;
241  else
242  MEStripClusters[ic1].IRTBNDTime = c2.JC2MAX;
243 
244  MEStripClusters.erase(MEStripClusters.begin() + ic2);
245  return;
246  }
248  // SEARCHING EXTREMUMS IN THE CLUSTERS
249 
250  for (uint32_t i = 0; i < MEStripClusters.size(); i++) {
251  MEStripClusters[i].localMax.clear();
252  int iLS = MEStripClusters[i].LFTBNDStrip;
253  int iRS = MEStripClusters[i].IRTBNDStrip;
254  int iLT = MEStripClusters[i].LFTBNDTime;
255  int iRT = MEStripClusters[i].IRTBNDTime;
256 
257  for (int iS = iLS; iS <= iRS; iS++) {
258  if (isME11 && (thePulseHeightMap[iS].channel_ == 63 || thePulseHeightMap[iS].channel_ == 64))
259  continue;
260  for (int jT = iLT; jT <= iRT; jT++) {
261  if (iS == 0 || jT == 0 || (!is7DCFEBs && (iS == 79)) || (is7DCFEBs && (iS == 111)) || jT == 7)
262  continue;
263  if (thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS - 1].height_[jT] &&
264  thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS + 1].height_[jT] &&
265  thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS].height_[jT - 1] &&
266  thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS].height_[jT + 1] &&
267  thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS - 1].height_[jT - 1] &&
268  thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS - 1].height_[jT + 1] &&
269  thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS + 1].height_[jT - 1] &&
270  thePulseHeightMap[iS].height_[jT] > thePulseHeightMap[iS + 1].height_[jT + 1]) {
271  localMaxTMP.Strip = iS;
272  localMaxTMP.Time = jT;
273  MEStripClusters[i].localMax.push_back(localMaxTMP);
274  }
275  }
276  }
277  // kill local maximums rellated to noise, maximums with pulse height less then 10% of Global max of clust.
278  //fing Global Max
279  float GlobalMax = 0;
280  if (!MEStripClusters[i].localMax.empty()) {
281  //std::cout << "Cluster: " << i << " Number of local maximums before erase: "
282  // << MEStripClusters[i].localMax.size() << std::endl;
283  for (uint32_t j = 0; j < MEStripClusters[i].localMax.size(); j++) {
284  int iS = MEStripClusters[i].localMax[j].Strip;
285  int jT = MEStripClusters[i].localMax[j].Time;
286  /*
287  std::cout << "Current Max:"
288  << " " << iS
289  << " " << jT
290  << " " << thePulseHeightMap[iS].height_[jT] << std::endl;
291  */
292  if (thePulseHeightMap[iS].height_[jT] > GlobalMax)
293  GlobalMax = thePulseHeightMap[iS].height_[jT];
294  }
295  GlobalMax = (float)(GlobalMax / 10.);
296  //erase noise localMaximums
297  bool Erased;
298  do {
299  Erased = false;
300  for (uint32_t j = 0; j < MEStripClusters[i].localMax.size(); j++) {
301  int iS = MEStripClusters[i].localMax[j].Strip;
302  int jT = MEStripClusters[i].localMax[j].Time;
303  if (thePulseHeightMap[iS].height_[jT] < GlobalMax) {
304  MEStripClusters[i].localMax.erase(MEStripClusters[i].localMax.begin() + j);
305  Erased = true;
306  break;
307  }
308  }
309  } while (Erased);
310 
311  //debug outs
312  //std::cout << "Cluster: " << i << " Number of local maximums: "
313  // << MEStripClusters[i].localMax.size() << std::endl;
314  /*
315  for(j=0;j<MEStripClusters[i].localMax.size();j++){
316  iS=MEStripClusters[i].localMax[j].Strip;
317  jT=MEStripClusters[i].localMax[j].Time;
318  std::cout << "Local Max: " << j << " Strip: " << iS << " Time: " << jT
319  << " Height: " << thePulseHeightMap[iS].height_[jT]
320  << " Cut Value: " << GlobalMax << std::endl;
321  }
322  */
323  }
324  }
325  return;
326  }
328  int iS, jT;
329  std::cout << "====================================================================" << std::endl;
330  std::cout << "debug information from StripClusterFinder" << std::endl;
331  for (uint32_t i = 0; i < MEStripClusters.size(); i++) {
332  if (MEStripClusters[i].localMax.empty())
333  continue;
334  std::cout << " Cluster: " << i + 1 << " Number of local Maximums " << MEStripClusters[i].localMax.size()
335  << std::endl;
336  for (uint32_t j = 0; j < MEStripClusters[i].localMax.size(); j++) {
337  iS = MEStripClusters[i].localMax[j].Strip;
338  jT = MEStripClusters[i].localMax[j].Time;
339 
340  // std::cout << "Local Max: " << j << " Strip: " << iS << " Time: " << jT << std::endl;
341  for (uint32_t k = 0; k < MEStripClusters[i].ClusterPulseMapHeight.size(); k++) {
342  if (MEStripClusters[i].ClusterPulseMapHeight[k].channel_ == iS)
343  std::cout << "Local Max: " << j + 1 << " Strip: " << iS + 1 << " Time: " << jT + 1
344  << " Height: " << MEStripClusters[i].ClusterPulseMapHeight[k].height_[jT] << std::endl;
345  }
346  }
347  for (uint32_t k = 0; k < MEStripClusters[i].ClusterPulseMapHeight.size(); k++) {
348  std::cout << "Strip: " << MEStripClusters[i].ClusterPulseMapHeight[k].channel_ + 1;
349  for (int l = 0; l < 16; l++)
350  std::cout << " " << MEStripClusters[i].ClusterPulseMapHeight[k].height_[l];
351  std::cout << std::endl;
352  }
353 
354  std::cout << " Left Top corner strip: " << MEStripClusters[i].LFTBNDStrip + 1 << " "
355  << " time: " << MEStripClusters[i].LFTBNDTime + 1 << std::endl;
356  std::cout << " Right Bottom corner strip: " << MEStripClusters[i].IRTBNDStrip + 1 << " "
357  << " time: " << MEStripClusters[i].IRTBNDTime + 1 << std::endl;
358  }
359  std::cout << "======================================================================" << std::endl;
360  return;
361  }
363  return a.channel_ < b.channel_;
364  }
365 
366 } // namespace cscdqm
std::vector< ClusterLocalMax > localMax
Strip Cluster Fit Data Object.
void KillCluster(uint32_t ic1, uint32_t ic2, C1 const &, C2 const &)
StripClusterFinder(int l, int s, int cf, int st, bool ME11=false)
std::vector< StripClusterFitData > thePulseHeightMap
void DoAction(int layerId, float *cathodes)
std::vector< StripCluster > MEStripClusters
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
bool operator()(const StripClusterFitData &a, const StripClusterFitData &b) const
Log< level::Warning, false > LogWarning