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