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