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