BmnRoot
Loading...
Searching...
No Matches
BmnSiliconLayer.cxx
Go to the documentation of this file.
1#include "BmnSiliconLayer.h"
2
3#include "TMath.h"
4
5#include <iostream>
6
7using namespace TMath;
8using namespace std;
9
10Int_t BmnSiliconLayer::fUniqueIdL = 0;
11Int_t BmnSiliconLayer::fUniqueIdU = 0;
12
14
15 Verbosity = true;
16
17 ZoneID = -1;
18 LayerType = LowerStripLayer;
19 FirstStripNumber = 0;
20
21 XMinLayer = 0.0;
22 XMaxLayer = 10.0;
23 YMinLayer = 0.0;
24 YMaxLayer = 10.0;
25
26 Pitch = 0.01; //cm
27 AngleDeg = 2.5; //in degrees from a vertical line where a plus value is clockwise
28 AngleRad = AngleDeg*Pi()/180; //in radians
29
30 StripOrder = LeftToRight;
31
32 if(AngleDeg <= 0.0 && AngleDeg >= -90.0) {
34 }
35 else {
36 if(AngleDeg > 0.0 && AngleDeg <= 90.0) {
38 }
39 }
40
41 ClusterFindingThreshold = 0.0;
42
44}
45
47 StripLayerType layer_type, Int_t first_strip_number,
48 Double_t xsize, Double_t ysize,
49 Double_t xorig, Double_t yorig,
50 Double_t pitch, Double_t adeg) {
51
52 Verbosity = true;
53
54 ZoneID = zone_id;
55 LayerType = layer_type;
56 FirstStripNumber = first_strip_number;
57
58 XMinLayer = xorig;
59 XMaxLayer = xorig + xsize;
60 YMinLayer = yorig;
61 YMaxLayer = yorig + ysize;
62
63 Pitch = pitch;
64 AngleDeg = adeg; //in degrees from a vertical line where a plus value is clockwise
65 AngleRad = AngleDeg*Pi()/180; //in radians
66
67 StripOrder = LeftToRight;
68
69 if(AngleDeg <= 0.0 && AngleDeg >= -90.0) {
71 }
72 else {
73 if(AngleDeg > 0.0 && AngleDeg <= 90.0) {
75 }
76 }
77
78 ClusterFindingThreshold = 0.0;
79
81}
82
86
88 Int_t NStrips = GetNStrips();
89
90 //strips
91 Strips.clear();
92 Strips.resize(NStrips, 0.0);
93
94 //matches
97
98 //strip hits
100
101 BmnSiliconLayer::fUniqueIdL = 0;
102 BmnSiliconLayer::fUniqueIdU = 0;
103}
104
108
110 Double_t xleft_layer = ConvertNormalPointToStripX(XLeftPointOfStripNumbering, YLeftPointOfStripNumbering);
111 Double_t xright_layer = ConvertNormalPointToStripX(XRightPointOfStripNumbering, YRightPointOfStripNumbering);
112 Double_t n_strips = (xright_layer - xleft_layer)/Pitch;
113
114 if( (n_strips - (Int_t)n_strips) < 1E-10 ) {
115 return (Int_t)n_strips;
116 }
117 else {
118 return (Int_t)(n_strips+1);
119 }
120}
121
122void BmnSiliconLayer::SetPitch(Double_t pitch) {
123 Pitch = pitch;
124
126}
127
128void BmnSiliconLayer::SetLayerSizes(Double_t xsize, Double_t ysize, Double_t xorig, Double_t yorig) {
129 XMinLayer = xorig;
130 XMaxLayer = xorig + xsize;
131 YMinLayer = yorig;
132 YMaxLayer = yorig + ysize;
133
135}
136
138 if(Abs(deg) <= 90.0) {
139 AngleDeg = deg;
140 }
141 else {
142 AngleDeg = 0.0;
143 if(Verbosity) cerr << "WARNING: BmnSiliconLayer::SetAngleDeg(): the strip angle is incorrect and has been set to zero\n";
144 }
145
146 AngleRad = AngleDeg*Pi()/180;
147
149}
150
151Bool_t BmnSiliconLayer::SetStripNumberingBorders(Double_t x_left, Double_t y_left, Double_t x_right, Double_t y_right) {
152 if(x_right < x_left) return false;
153
154 XLeftPointOfStripNumbering = x_left;
155 YLeftPointOfStripNumbering = y_left;
156 XRightPointOfStripNumbering = x_right;
157 YRightPointOfStripNumbering = y_right;
158
159 ResetLayer();
160
161 return true;
162}
163
165
166 if( left != LeftTop && left != LeftBottom ) {
167 if(Verbosity) cerr << "WARNING: SetStripNumberingBorders: left strip border point is incorrect\n";
168 return false;
169 }
170 if( right != RightTop && right != RightBottom ) {
171 if(Verbosity) cerr << "WARNING: SetStripNumberingBorders: right strip border point is incorrect\n";
172 return false;
173 }
174
175 XLeftPointOfStripNumbering = XMinLayer;
176 XRightPointOfStripNumbering = XMaxLayer;
177
178 switch (left) {
179 case LeftTop:
180 YLeftPointOfStripNumbering = YMaxLayer;
181 break;
182 case LeftBottom:
183 YLeftPointOfStripNumbering = YMinLayer;
184 break;
185 default:
186 return false;
187 }
188
189 switch (right) {
190 case RightTop:
191 YRightPointOfStripNumbering = YMaxLayer;
192 break;
193 case RightBottom:
194 YRightPointOfStripNumbering = YMinLayer;
195 break;
196 default:
197 return false;
198 }
199
200 ResetLayer();
201
202 return true;
203}
204
206 StripOrder = strip_direction;
207
208 ResetLayer();
209
210 return true;
211}
212
213Bool_t BmnSiliconLayer::AddDeadZone(Int_t n_points, Double_t *x_points, Double_t *y_points) {
214 DeadZoneOfStripLayer dead_zone;
215 Bool_t status = dead_zone.SetDeadZone(n_points, x_points, y_points);
216 if(status == true) {
217 DeadZones.push_back(dead_zone);
218 return true;
219 }
220 else {
221 return false;
222 }
223}
224
226 if(dead_zone.GetNPoints() > 2) {
227 DeadZones.push_back(dead_zone);
228 return true;
229 }
230 else {
231 return false;
232 }
233}
234
235Bool_t BmnSiliconLayer::IsPointInsideDeadZones(Double_t x, Double_t y) {
236 for (size_t izone = 0; izone < DeadZones.size(); ++izone)
237 if(DeadZones[izone].IsInside(x,y)) return true;
238
239 return false;
240}
241
242Bool_t BmnSiliconLayer::IsPointInsideStripLayer(Double_t x, Double_t y) {
243 if( x >= XMinLayer && x <= XMaxLayer &&
244 y >= YMinLayer && y <= YMaxLayer &&
245 !IsPointInsideDeadZones(x, y) ) return true;
246 else
247 return false;
248}
249
250Bool_t BmnSiliconLayer::SetStripSignal(Int_t strip_num, Double_t signal) {
251 if (strip_num >= FirstStripNumber && strip_num < ((Int_t)Strips.size()+FirstStripNumber) ) {
252 Strips[strip_num-FirstStripNumber] = signal;
253 return true;
254 }
255 else return false;
256}
257
258Bool_t BmnSiliconLayer::AddStripSignal(Int_t strip_num, Double_t signal) {
259 if (strip_num >= FirstStripNumber && strip_num < ((Int_t)Strips.size()+FirstStripNumber)) {
260 Strips[strip_num-FirstStripNumber] += signal;
261 return true;
262 }
263 else return false;
264}
265
266Double_t BmnSiliconLayer::GetStripSignal(Int_t strip_num) {
267 if ( strip_num >= FirstStripNumber && strip_num < ((Int_t)Strips.size()+FirstStripNumber) )
268 return Strips[strip_num-FirstStripNumber];
269 else return -1;
270}
271
272Bool_t BmnSiliconLayer::SetStripMatch(Int_t strip_num, BmnMatch mc_match) {
273 if ( strip_num >= FirstStripNumber && strip_num < ((Int_t)StripMatches.size()+FirstStripNumber) ) {
274 StripMatches[strip_num-FirstStripNumber] = mc_match;
275 return true;
276 }
277 else return false;
278}
279
280Bool_t BmnSiliconLayer::AddLinkToStripMatch(Int_t strip_num, Double_t weight, Int_t mc_num) {
281 if (strip_num >= FirstStripNumber && strip_num < ((Int_t)StripMatches.size()+FirstStripNumber)) {
282 StripMatches[strip_num-FirstStripNumber].AddLink(weight, mc_num);
283 return true;
284 }
285 else return false;
286}
287
288Bool_t BmnSiliconLayer::SetStripDigitNumberMatch(Int_t strip_num, BmnMatch digit_num_match) {
289 if (strip_num >= FirstStripNumber && strip_num < ((Int_t)StripDigitNumberMatches.size()+FirstStripNumber)) {
290 StripDigitNumberMatches[strip_num-FirstStripNumber] = digit_num_match;
291 return true;
292 }
293 else return false;
294}
295
296Bool_t BmnSiliconLayer::AddLinkToStripDigitNumberMatch(Int_t strip_num, Double_t weight, Int_t digit_num) {
297 if (strip_num >= FirstStripNumber && strip_num < ((Int_t)StripDigitNumberMatches.size()+FirstStripNumber)) {
298 StripDigitNumberMatches[strip_num-FirstStripNumber].AddLink(weight, digit_num);
299 return true;
300 }
301 else return false;
302}
303
305 if (strip_num >= FirstStripNumber && strip_num < ((Int_t)StripMatches.size()+FirstStripNumber))
306 return StripMatches[strip_num-FirstStripNumber];
307 else return BmnMatch(); //return an empty match
308}
309
311 if (strip_num >= FirstStripNumber && strip_num < ((Int_t)StripDigitNumberMatches.size()+FirstStripNumber))
312 return StripDigitNumberMatches[strip_num-FirstStripNumber];
313 else return BmnMatch(); //return an empty match
314}
315
317 Int_t NStrips = GetNStrips();
318
319 StripMatches.clear();
320 StripMatches.resize(NStrips, BmnMatch());
321}
322
324 Int_t NStrips = GetNStrips();
325
326 StripDigitNumberMatches.clear();
327 StripDigitNumberMatches.resize(NStrips, BmnMatch());
328}
329
331 if (num >= 0 && num < (Int_t)StripHits.size())
332 return StripHits[num];
333
334 return -1.0;
335}
336
338 if (num >= 0 && num < (Int_t)StripHitsTotalSignal.size())
339 return StripHitsTotalSignal[num];
340
341 return -1.0;
342}
343
345 if (num >= 0 && num < (Int_t)StripHitsErrors.size())
346 return StripHitsErrors[num];
347
348 return -1.0;
349}
350
352 if (num >= 0 && num < (Int_t)StripHitsClusterSize.size())
353 return StripHitsClusterSize[num];
354
355 return -1.0;
356}
357
359 StripHits.clear();
360 StripHitsTotalSignal.clear();
361 StripHitsErrors.clear();
362 StripHitsClusterSize.clear();
363 StripClusters.clear();
364}
365
366Double_t BmnSiliconLayer::ConvertNormalPointToStripX(Double_t x, Double_t y) {
367 Double_t XRotationCenter;
368 Double_t YRotationCenter;
369
370 if(StripOrder == LeftToRight) {
371 XRotationCenter = XLeftPointOfStripNumbering;
372 YRotationCenter = YLeftPointOfStripNumbering;
373 }
374 else {
375 if(StripOrder == RightToLeft) {
376 XRotationCenter = XRightPointOfStripNumbering;
377 YRotationCenter = YRightPointOfStripNumbering;
378 }
379 }
380 Double_t StripX = (x - XRotationCenter)*Cos(-AngleRad) + (y - YRotationCenter)*Sin(-AngleRad) + XRotationCenter;//see
381 return StripX;
382}
383
384Double_t BmnSiliconLayer::ConvertNormalPointToStripY(Double_t x, Double_t y) {
385 Double_t XRotationCenter;
386 Double_t YRotationCenter;
387
388 if(StripOrder == LeftToRight) {
389 XRotationCenter = XLeftPointOfStripNumbering;
390 YRotationCenter = YLeftPointOfStripNumbering;
391 }
392 else {
393 if(StripOrder == RightToLeft) {
394 XRotationCenter = XRightPointOfStripNumbering;
395 YRotationCenter = YRightPointOfStripNumbering;
396 }
397 }
398 Double_t StripY = -(x - XRotationCenter)*Sin(-AngleRad) + (y - YRotationCenter)*Cos(-AngleRad) + YRotationCenter;//see
399 return StripY;
400}
401
402Double_t BmnSiliconLayer::ConvertPointToStripPosition(Double_t x, Double_t y) {
403 //This function returns real(double) value,
404 //where integer part - number of a strip, fractional part - position on this strip (as ratio from begin)
405
406 if(StripOrder == LeftToRight) {
407 return (ConvertNormalPointToStripX(x, y)-XLeftPointOfStripNumbering)/Pitch + FirstStripNumber;
408 }
409 else {
410 if(StripOrder == RightToLeft) {
411 return (XRightPointOfStripNumbering-ConvertNormalPointToStripX(x, y))/Pitch + FirstStripNumber;
412 }
413 }
414
415 return -1;
416}
417
418Double_t BmnSiliconLayer::CalculateStripEquationB(Double_t strip_pos) {
419
420 Double_t b;
421
422 if(Abs(AngleDeg) != 90.0) { //case: y=a*x+b
423 Double_t x_strip_shift = ((strip_pos-FirstStripNumber)*Pitch)/Cos(Abs(AngleRad));
424 Double_t xcoord;
425
426 if(StripOrder == LeftToRight) {
427 xcoord = XLeftPointOfStripNumbering + x_strip_shift;
428 b = YLeftPointOfStripNumbering - Tan(PiOver2()-AngleRad)*xcoord;
429 }
430 else {
431 if(StripOrder == RightToLeft) {
432 xcoord = XRightPointOfStripNumbering-x_strip_shift;
433 b = YRightPointOfStripNumbering - Tan(PiOver2()-AngleRad)*xcoord;
434 }
435 }
436 }
437 else { //case: y=b
438 Double_t y_strip_shift = (strip_pos-FirstStripNumber)*Pitch*Sin(AngleRad);
439
440 if(StripOrder == LeftToRight) {
441 b = YLeftPointOfStripNumbering - y_strip_shift;
442 }
443 else {
444 if(StripOrder == RightToLeft) {
445 b = YRightPointOfStripNumbering + y_strip_shift;
446 }
447 }
448 }
449
450 return b;
451}
452
454
456
457 Double_t threshold = ClusterFindingThreshold;
458 //Double_t threshold = 500.0;
459
460 StripCluster cluster;
461
462 Bool_t ascent = false;
463 Bool_t descent = false;
464
465 //Processing strips
466 vector<Double_t> AnalyzableStrips = Strips;
467
468 //Smooth strip signal ------------------------------------------------------
469 //if(Pitch > 0.079) SmoothStripSignal(AnalyzableStrips, 1, 1, 1.0);
470 //else SmoothStripSignal(AnalyzableStrips, 2, 1, 1.0);
471 //--------------------------------------------------------------------------
472
473 for (Int_t is = 0; is < (Int_t)AnalyzableStrips.size(); is++)
474 {
475 if(AnalyzableStrips.at(is) <= threshold) {
476 if(descent || ascent) {
477 descent = false;
478 ascent = false;
479 //make strip hit
480 MakeStripHit(cluster, AnalyzableStrips, is);
481 }
482 continue;
483 }
484
485 if( cluster.GetClusterSize() > 0 ) {
486 if( AnalyzableStrips.at(is) >= (cluster.Signals.at(cluster.GetClusterSize()-1)) ) {
487 if(descent) {
488 ascent = false;
489 descent = false;
490 //make strip hit
491 MakeStripHit(cluster, AnalyzableStrips, is);
492 //continue;
493 }
494 ascent = true;
495 descent = false;
496 }
497 else {
498 ascent = false;
499 descent = true;
500 }
501 }
502 else {
503 ascent = true;
504 descent = false;
505 }
506
507 cluster.AddStrip(is, AnalyzableStrips.at(is));
508 }
509
510 if(cluster.GetClusterSize() != 0) {
511 //make strip hit
512 Int_t lastnum = AnalyzableStrips.size()-1;
513 MakeStripHit(cluster, AnalyzableStrips, lastnum);
514 }
515}
516
517 void BmnSiliconLayer::MakeStripHit(StripCluster &cluster, vector<Double_t> &AnalyzableStrips, Int_t &curcnt) {
518
519 Double_t mean_strip_position = 0.0;
520 Double_t total_cluster_signal = 0.0;
521 Double_t cluster_rms = 0.0;
522
523 Int_t NStripsInCluster = cluster.GetClusterSize();
524
525 //Share the common strip signal of two adjacent clusters in half
526 if(true) {
527 if(AnalyzableStrips.at(curcnt) >= AnalyzableStrips.at(curcnt-1)) {
528 cluster.Signals.at(cluster.Signals.size()-1) *= 0.5;
529 AnalyzableStrips.at(curcnt-1) *= 0.5;
530 }
531 }
532
533 //mean position and cluster signal -----------------------------------------
534 for(Int_t i = 0; i < NStripsInCluster; ++i) {
535 Double_t strip_num = cluster.Strips.at(i) + FirstStripNumber;
536 Double_t signal = cluster.Signals.at(i);
537 total_cluster_signal += signal;
538 mean_strip_position += (strip_num+0.5)*signal;
539 }
540 mean_strip_position /= total_cluster_signal;
541
542 if(mean_strip_position < FirstStripNumber) mean_strip_position = FirstStripNumber;
543 if(mean_strip_position >= AnalyzableStrips.size()+FirstStripNumber) mean_strip_position = AnalyzableStrips.size() - 0.001;
544 //--------------------------------------------------------------------------
545
546 //cluster standard deviation (sigma): RMS ----------------------------------
547// if(NStripsInCluster > 1) {
548// for(Int_t i = 0; i < NStripsInCluster; ++i) {
549// Double_t strip_num = cluster.Strips.at(i) + FirstStripNumber;
550// Double_t signal = cluster.Signals.at(i);
551// Double_t residual = (strip_num+0.5) - mean_strip_position;
552// cluster_rms += residual*residual*signal;
553// }
554// cluster_rms /= total_cluster_signal;
555// cluster_rms = TMath::Sqrt(cluster_rms);
556// }
557// else {
558// cluster_rms = 1.0/TMath::Sqrt(12.0);
559// }
560//
561
562 // AZ, STS, method2
563 Double_t sumW = total_cluster_signal;
564 Double_t sumWX = 0.;
565 Double_t sumWX2 = 0.;
566 if(NStripsInCluster > 1) {
567 for(Int_t i = 0; i < NStripsInCluster; ++i) {
568 Double_t strip_num = cluster.Strips.at(i) + FirstStripNumber;
569 Double_t signal = cluster.Signals.at(i);
570 sumWX += strip_num * signal;
571 sumWX2 += strip_num * strip_num * signal;
572 }
573 cluster_rms = (sumWX2 - sumWX * sumWX / sumW) / sumW;
574 }
575
576 else {
577 cluster_rms = 1.0 /TMath::Sqrt(12.0);
578 }
579
580 //--------------------------------------------------------------------------
581
582 StripHits.push_back(mean_strip_position);
583 StripHitsTotalSignal.push_back(total_cluster_signal);
584 StripHitsErrors.push_back(cluster_rms);
585 StripHitsClusterSize.push_back(NStripsInCluster);
586
587 cluster.MeanPosition = mean_strip_position;
588 cluster.TotalSignal = total_cluster_signal;
589 cluster.SetWidth(NStripsInCluster);
590 cluster.Error = cluster_rms;
591 if (LayerType == LowerStripLayer) {
592 cluster.SetType(0);
593 cluster.SetUniqueID(fUniqueIdL++);
594 } else {
595 cluster.SetType(1);
596 cluster.SetUniqueID(fUniqueIdU++);
597 }
598
599 /* Update strip numbers in the local cluster according to
600 * the FirstStripNumber shift before we can use it in the outer code
601 */
602 for(Int_t i = 0; i < NStripsInCluster; ++i) {
603 cluster.Strips.at(i) += FirstStripNumber;
604 }
605
606 StripClusters.push_back(cluster);
607
608 //return to a previous strip
609 curcnt--;
610 if( curcnt < 0 ) curcnt = 0;
611
612 cluster.Clear();
613 }
614
615 void BmnSiliconLayer::SmoothStripSignal(vector<Double_t>& AnalyzableStrips, Int_t NIterations, Int_t SmoothWindow, Double_t Weight) {
616 //It's the Simple Moving Average (SMA) method
617 //AnalyzableStrips - analyzable strip layer (ref)
618 //NIterations - number of smooth iterations (usually 1)
619 //SmoothWindow - number of strips on the left-right of the current strip (usually 1)
620 //Weight - weight of the current strip (usually 1.0 - for simplicity, greater - for weighted value))
621
622 SmoothStrips.clear();
623 Int_t NStrips = AnalyzableStrips.size();
624
625 for(Int_t iteration = 0; iteration < NIterations; ++iteration) {
626 SmoothStrips.clear();
627 for(Int_t istrip = 0; istrip < NStrips; ++istrip) {
628 Double_t mean_value = 0.0;
629 for(Int_t iw = istrip-SmoothWindow; iw <= istrip+SmoothWindow; ++iw) {
630 if(iw >= 0 && iw < NStrips) {
631 if(iw == istrip) mean_value += AnalyzableStrips[iw]*Weight;
632 else mean_value += AnalyzableStrips[iw];
633 }
634 }
635 mean_value /= 2.0*SmoothWindow + Weight;
636 SmoothStrips.push_back(mean_value);
637 }
638 AnalyzableStrips = SmoothStrips;
639 }
640
641 return;
642}
int i
Definition P4_F32vec4.h:22
StripBorderPoint
@ LeftTop
@ RightBottom
@ LeftBottom
@ RightTop
StripNumberingDirection
@ RightToLeft
@ LeftToRight
StripLayerType
@ LowerStripLayer
Bool_t AddDeadZone(Int_t n_points, Double_t *x_points, Double_t *y_points)
Double_t CalculateStripEquationB(Double_t strip_pos)
Bool_t IsPointInsideStripLayer(Double_t x, Double_t y)
Double_t GetStripSignal(Int_t strip_num)
Bool_t SetStripDigitNumberMatch(Int_t strip_num, BmnMatch digit_num_match)
void MakeStripHit(StripCluster &cluster, vector< Double_t > &AnalyzableStrips, Int_t &curcnt)
BmnMatch GetStripMatch(Int_t strip_num)
Bool_t SetStripMatch(Int_t strip_num, BmnMatch mc_match)
void SmoothStripSignal(vector< Double_t > &AnalyzableStrips, Int_t NIterations, Int_t SmoothWindow, Double_t Weight)
Bool_t AddStripSignal(Int_t strip_num, Double_t signal)
Bool_t SetStripSignal(Int_t strip_num, Double_t signal)
void SetAngleDeg(Double_t deg)
Bool_t IsPointInsideDeadZones(Double_t x, Double_t y)
Bool_t AddLinkToStripMatch(Int_t strip_num, Double_t weight, Int_t mc_num)
void ResetStripDigitNumberMatches()
Bool_t SetStripNumberingBorders(Double_t x_left, Double_t y_left, Double_t x_right, Double_t y_right)
BmnMatch GetStripDigitNumberMatch(Int_t strip_num)
Double_t GetStripHitPos(Int_t num)
Bool_t SetStripNumberingOrder(StripNumberingDirection strip_direction)
Double_t ConvertNormalPointToStripY(Double_t x, Double_t y)
Double_t GetStripHitError(Int_t num)
Int_t GetStripHitClusterSize(Int_t num)
void SetPitch(Double_t pitch)
Bool_t AddLinkToStripDigitNumberMatch(Int_t strip_num, Double_t weight, Int_t digit_num)
void SetLayerSizes(Double_t xsize, Double_t ysize, Double_t xorig=0.0, Double_t yorig=0.0)
Double_t ConvertNormalPointToStripX(Double_t x, Double_t y)
Double_t ConvertPointToStripPosition(Double_t x, Double_t y)
Double_t GetStripHitTotalSignal(Int_t num)
virtual ~BmnSiliconLayer()
Bool_t SetDeadZone(Int_t n_points, Double_t *xpoints, Double_t *ypoints)
Double_t TotalSignal
Int_t GetClusterSize()
Double_t MeanPosition
Double_t Error
void SetWidth(Int_t w)
void AddStrip(Int_t strip_num, Double_t strip_signal)
void SetType(Int_t type)
vector< Int_t > Strips
vector< Double_t > Signals
STL namespace.