test
CMS 3D CMS Logo

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