BmnRoot
Loading...
Searching...
No Matches
BmnTof1GeoUtils.h
Go to the documentation of this file.
1#ifndef __BMN_TOF1_HIT_GEOUTILS_H
2#define __BMN_TOF1_HIT_GEOUTILS_H 1
3
4#include <TClonesArray.h>
5#include <TH1D.h>
6#include <TH2D.h>
7#include <TList.h>
8#include <TVector3.h>
9#include <iostream>
10#include <map>
11
12class LRectangle1 : public TObject // convex quadrangle
13{
14 private:
15 bool IsInvalid;
16
17 public:
18 enum Side_t
19 {
20 kRight = 0,
21 kLeft = 1,
22 kInvalid = -1,
23 kUpper = 0,
24 kLower = 1
25 };
26 // enum Side701_t
27 // {
28 // kUpper = 0,
29 // kLower = 1
30 // };
31
32 Int_t volumeUID;
33 Double_t length, width;
34
35 TVector3 A, B, C, D, center, perp; // [cm]
36
38 : IsInvalid(true)
40 {}
41 LRectangle1(Int_t uid,
42 const TVector3& a,
43 const TVector3& b,
44 const TVector3& c,
45 const TVector3& d,
46 bool check = false);
47
48 Double_t GetLength() const { return length; }
49 Double_t GetWidth() const { return width; }
50 void GetInteriorAngle(int vertexIndex) const {} // FIXME
51 TVector3 GetCenter() const { return (A + B + C + D) * 0.25; }
52 bool isInvalid() const { return IsInvalid; }
53
54 Double_t DistanceFromPointToLineSegment(const TVector3* pos, const TVector3& P1, const TVector3& P2) const;
55 Double_t DistanceFromPointToLine(const TVector3* pos, const TVector3& P1, const TVector3& P2) const;
56 Double_t MinDistanceToEdge(const TVector3* pos, Side_t& side) const;
57 Double_t MinDistanceToEdge701(const TVector3* pos, Side_t& side) const;
58
59 void Print(std::ostream& out, const TVector3& point, const char* comment = nullptr) const;
60 void Dump(const char* comment, std::ostream& out = std::cout) const;
61
62 void Shift(const TVector3& shift)
63 {
64 A += shift;
65 B += shift;
66 C += shift;
67 D += shift;
68 };
69
70 inline void InitCenterPerp()
71 {
72 center = (A + B + C + D) * 0.25;
73 perp = (B - A).Cross(D - A).Unit();
74 }
75
77 {
78 length = TMath::Abs(B.X() - A.X());
79 if (length != 16 && length != 56) {
80 if (length == 15)
81 length = 16;
82 else if (length == 55)
83 length = 56;
84 }
85 width = TMath::Abs(C.Y() - B.Y());
86 }
87
88 inline void CheckInValid()
89 {
90 IsInvalid = false;
91
92 // Convex Polygon Definition: A polygon that has all interior angles less than 180°
93 ;
94 // Sum of Interior Angles, sum = 180*(n-2) degree, where n is the number of sides
95 // A square has 4 sides, so interior angles sum = 360°
96 ;
97 // Rectangle check - all angles == 90 degree
98 TVector3 ab = A - B, bc = B - C, cd = C - D, da = D - A;
99 if (ab.Dot(bc) != 0. || bc.Dot(cd) != 0. || cd.Dot(da) != 0. || da.Dot(ab) != 0.) {
100 std::cerr << "\n ---> ERROR: invalid Rectangle.";
101 Dump("", std::cerr);
102 IsInvalid = true;
103 }
104 }
105 // ClassDef(LRectangle1, 1);
106};
107
108class LStrip1 : public LRectangle1
109{
110 public:
111 Bool_t isKilled = false;
113 Int_t neighboring[2]; // dim same as Side_t enum
114
116 LStrip1(Int_t uid, Int_t sector, Int_t box, Int_t detector, Int_t strip);
117
118 void SetIDs(Int_t uid, Int_t sector, Int_t box, Int_t detector, Int_t strip)
119 {
120 volumeUID = uid;
121 sectorID = sector;
122 boxID = box;
124 stripID = strip;
125 }
126
127 inline void SetIsKilled(bool status) { isKilled = status; }
128 inline bool GetIsKilled() const { return isKilled; }
129 inline bool IsSameDetector(const LStrip1& strip) const
130 {
131 return (sectorID == strip.sectorID && boxID == strip.boxID && detectorID == strip.detectorID);
132 }
133 inline bool operator==(const LStrip1& rhs)
134 {
135 return (sectorID == rhs.sectorID && boxID == rhs.boxID && detectorID == rhs.detectorID
136 && stripID == rhs.stripID);
137 }
138 inline bool operator!=(const LStrip1& rhs) { return !((*this) == rhs); }
139
140 void Dump(const char* comment = nullptr, std::ostream& out = std::cout) const;
141 Double_t Distance(Side_t side, const LStrip1& strip);
142 Double_t Distance701(Side_t side, const LStrip1& strip);
143
144 // ClassDef(LStrip1, 1);
145};
146
147class BmnTof1GeoUtils : public TObject
148{
149 typedef std::map<Int_t, LStrip1> MStripType; // pair<detectorUID, Strip parameters>
150 typedef MStripType::const_iterator MStripCIT;
151 typedef MStripType::iterator MStripIT;
152
153 MStripType mStrips;
154
155 public:
157
158 void FindNeighborStrips(Int_t verbose = 0);
159 void FindNeighborStrips701(Int_t verbose = 0);
160 Int_t ParseTGeoManager(bool useMCinput, bool forced = false, Int_t verbose = 0);
161 Int_t ParseTGeoManager701(bool useMCinput, bool forced = false, Int_t verbose = 0);
162 const LStrip1* FindStrip(Int_t UID);
163 const LStrip1* FindStrip701(Int_t UID);
164
165 // ClassDef(BmnTof1GeoUtils, 1);
166};
167
168#endif
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
const LStrip1 * FindStrip(Int_t UID)
void FindNeighborStrips701(Int_t verbose=0)
const LStrip1 * FindStrip701(Int_t UID)
Int_t ParseTGeoManager701(bool useMCinput, bool forced=false, Int_t verbose=0)
BmnTof1GeoUtils()
indexing strips by detectorUID
Int_t ParseTGeoManager(bool useMCinput, bool forced=false, Int_t verbose=0)
void FindNeighborStrips(Int_t verbose=0)
void CheckInValid()
Double_t GetWidth() const
void GetInteriorAngle(int vertexIndex) const
Double_t MinDistanceToEdge701(const TVector3 *pos, Side_t &side) const
TVector3 GetCenter() const
Double_t GetLength() const
void InitCenterPerp()
Double_t DistanceFromPointToLineSegment(const TVector3 *pos, const TVector3 &P1, const TVector3 &P2) const
Double_t DistanceFromPointToLine(const TVector3 *pos, const TVector3 &P1, const TVector3 &P2) const
void Shift(const TVector3 &shift)
void Dump(const char *comment, std::ostream &out=std::cout) const
bool isInvalid() const
void Print(std::ostream &out, const TVector3 &point, const char *comment=nullptr) const
LRectangle1(Int_t uid, const TVector3 &a, const TVector3 &b, const TVector3 &c, const TVector3 &d, bool check=false)
void CalculateLengthnWidth()
TVector3 center
Double_t MinDistanceToEdge(const TVector3 *pos, Side_t &side) const
Double_t length
LStrip1(Int_t uid, Int_t sector, Int_t box, Int_t detector, Int_t strip)
bool IsSameDetector(const LStrip1 &strip) const
Int_t neighboring[2]
void SetIsKilled(bool status)
void SetIDs(Int_t uid, Int_t sector, Int_t box, Int_t detector, Int_t strip)
bool operator!=(const LStrip1 &rhs)
bool GetIsKilled() const
Double_t Distance701(Side_t side, const LStrip1 &strip)
Bool_t isKilled
Int_t detectorID
bool operator==(const LStrip1 &rhs)
Double_t Distance(Side_t side, const LStrip1 &strip)
void Dump(const char *comment=nullptr, std::ostream &out=std::cout) const