092578a7 |
1 | // $Header$ |
2 | |
3 | #include "TPCSector3D.h" |
4 | #include <Alieve/TPCSectorData.h> |
5 | |
8ac84a96 |
6 | #include <TBuffer3D.h> |
7 | #include <TBuffer3DTypes.h> |
8 | #include <TVirtualPad.h> |
9 | #include <TVirtualViewer3D.h> |
10 | |
9a7ad6a0 |
11 | #include <TStyle.h> |
12 | #include <TColor.h> |
13 | |
092578a7 |
14 | using namespace Reve; |
15 | using namespace Alieve; |
16 | |
17 | //______________________________________________________________________ |
18 | // TPCSector3D |
19 | // |
20 | |
21 | ClassImp(TPCSector3D) |
22 | |
23 | TPCSector3D::TPCSector3D(const Text_t* n, const Text_t* t) : |
24 | TPCSectorViz(n, t), |
9a7ad6a0 |
25 | |
26 | fBoxSet (n, t), |
27 | fPointSetArray(n, t), |
28 | fPointFrac (0.25), |
1a351260 |
29 | fPointSize (3), |
092578a7 |
30 | |
265ecb21 |
31 | fPointSetOn (0), |
32 | fPointSetMaxVal (0), |
33 | |
092578a7 |
34 | fDriftVel (1), |
35 | fZStep (250.0/450) |
36 | { |
8ac84a96 |
37 | fRnrFrame = kFALSE; |
092578a7 |
38 | ComputeBBox(); |
39 | } |
40 | |
41 | TPCSector3D::~TPCSector3D() |
42 | {} |
43 | |
44 | /**************************************************************************/ |
45 | |
092578a7 |
46 | void TPCSector3D::SetRnrFrame(Bool_t rf) |
47 | { |
48 | if(fRnrFrame != rf) { |
49 | fRnrFrame = rf; |
50 | IncRTS(); |
51 | } |
52 | } |
53 | |
54 | /**************************************************************************/ |
55 | |
56 | void TPCSector3D::ComputeBBox() |
57 | { |
58 | const TPCSectorData::SegmentInfo& iSeg = TPCSectorData::GetInnSeg(); |
59 | const TPCSectorData::SegmentInfo& o2Seg = TPCSectorData::GetOut2Seg(); |
60 | |
606c4ed7 |
61 | #if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2) |
092578a7 |
62 | bbox_init(); |
606c4ed7 |
63 | #else |
64 | BBoxInit(); |
65 | #endif |
8ac84a96 |
66 | Float_t w = 0.5*o2Seg.GetNMaxPads()*o2Seg.GetPadWidth(); |
092578a7 |
67 | fBBox[0] = -w; |
68 | fBBox[1] = w; |
69 | fBBox[2] = iSeg.GetRLow(); |
70 | fBBox[3] = o2Seg.GetRLow() + o2Seg.GetNRows()*o2Seg.GetPadHeight(); |
1a351260 |
71 | fBBox[4] = 0; |
72 | fBBox[5] = TPCSectorData::GetZLength(); |
66e0d878 |
73 | Float_t* b = fBoxSet.AssertBBox(); |
74 | for(Int_t i=0; i<6; ++i) { b[i] = fBBox[i]; } |
75 | |
092578a7 |
76 | } |
77 | |
8ac84a96 |
78 | void TPCSector3D::Paint(Option_t* /*option*/) |
092578a7 |
79 | { |
8ac84a96 |
80 | if(fRnrElement == kFALSE) |
81 | return; |
82 | |
83 | TBuffer3D buffer(TBuffer3DTypes::kGeneric); |
84 | |
85 | // Section kCore |
86 | buffer.fID = this; |
87 | buffer.fColor = 1; |
88 | buffer.fTransparency = 0; |
601bca51 |
89 | fHMTrans.SetBuffer3D(buffer); |
8ac84a96 |
90 | buffer.SetSectionsValid(TBuffer3D::kCore); |
91 | |
92 | Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer); |
93 | if (reqSections == TBuffer3D::kNone) { |
94 | return; |
5987168b |
95 | } |
092578a7 |
96 | |
601bca51 |
97 | Error("TPCSector3D::Paint", "only direct OpenGL rendering supported."); |
8ac84a96 |
98 | return; |
092578a7 |
99 | } |
100 | |
101 | /**************************************************************************/ |
102 | |
103 | void TPCSector3D::LoadPadrow(TPCSectorData::RowIterator& iter, |
104 | Float_t xs, Float_t ys, Float_t pw, Float_t ph) |
105 | { |
106 | Short_t pad, time, val; |
107 | Float_t x0, x1, z0, z1; |
9a7ad6a0 |
108 | Float_t ym = ys + 0.5*ph; |
092578a7 |
109 | Float_t ye = ys + ph; |
9a7ad6a0 |
110 | Float_t zs = fZStep/fDriftVel; |
092578a7 |
111 | |
112 | while (iter.NextPad()) { |
113 | pad = iter.Pad(); |
114 | while (iter.Next()) { |
115 | time = iter.Time(); |
116 | val = iter.Signal(); |
117 | |
118 | if(val <= fThreshold || time < fMinTime || time > fMaxTime) |
119 | continue; |
120 | |
9a7ad6a0 |
121 | if(fPointSetOn && val <= fPointSetMaxVal) { |
dcb387f7 |
122 | fPointSetArray.Fill(xs + (pad+0.5)*pw, ym, (time+0.5)*zs, val); |
9a7ad6a0 |
123 | } else { |
124 | fBoxSet.fBoxes.push_back(Reve::Box()); |
125 | ColorFromArray(val, fBoxSet.fBoxes.back().color); |
126 | x0 = xs + pad*pw; |
127 | x1 = x0 + pw; |
128 | z0 = time*zs; |
129 | z1 = z0 + zs; |
130 | Float_t* p = fBoxSet.fBoxes.back().vertices; |
131 | // front |
132 | p[0] = x0; p[1] = ys; p[2] = z0; p += 3; |
133 | p[0] = x1; p[1] = ys; p[2] = z0; p += 3; |
134 | p[0] = x1; p[1] = ye; p[2] = z0; p += 3; |
135 | p[0] = x0; p[1] = ye; p[2] = z0; p += 3; |
136 | // back |
137 | p[0] = x0; p[1] = ys; p[2] = z1; p += 3; |
138 | p[0] = x1; p[1] = ys; p[2] = z1; p += 3; |
139 | p[0] = x1; p[1] = ye; p[2] = z1; p += 3; |
140 | p[0] = x0; p[1] = ye; p[2] = z1; |
141 | } |
092578a7 |
142 | } |
143 | } |
144 | } |
145 | |
146 | void TPCSector3D::UpdateBoxes() |
147 | { |
148 | // Populate parent class Reve::BoxSet with digit information. |
149 | |
150 | // printf("TPCSector3D update boxes\n"); |
151 | |
152 | fBoxSet.ClearSet(); |
dcb387f7 |
153 | fPointSetArray.RemoveElements(); |
092578a7 |
154 | |
155 | TPCSectorData* data = GetSectorData(); |
156 | if (data != 0) { |
157 | Bool_t isOn[3]; |
158 | isOn[0] = fRnrInn; |
159 | isOn[1] = fRnrOut1; |
160 | isOn[2] = fRnrOut2; |
161 | |
8ac84a96 |
162 | SetupColorArray(); |
9a7ad6a0 |
163 | SetupPointSetArray(); |
8ac84a96 |
164 | |
092578a7 |
165 | // Loop over 3 main segments |
166 | for (Int_t sId = 0; sId <= 2; ++sId) { |
167 | if(isOn[sId] == kFALSE) |
168 | continue; |
169 | const TPCSectorData::SegmentInfo& sInfo = TPCSectorData::GetSeg(sId); |
170 | Float_t sy = sInfo.GetRLow(); |
171 | for (Int_t row=sInfo.GetFirstRow(); row<=sInfo.GetLastRow(); ++row) { |
172 | TPCSectorData::RowIterator i = data->MakeRowIterator(row); |
173 | Float_t sx = -0.5*TPCSectorData::GetNPadsInRow(row)*sInfo.GetPadWidth(); |
174 | LoadPadrow(i, sx, sy, sInfo.GetPadWidth(), sInfo.GetPadHeight()); |
175 | sy += sInfo.GetPadHeight(); |
176 | } |
177 | } |
9a7ad6a0 |
178 | |
179 | if(fPointSetOn) |
180 | fPointSetArray.CloseBins(); |
181 | } |
182 | } |
183 | |
184 | void TPCSector3D::SetupPointSetArray() |
185 | { |
186 | Int_t nBins = (Int_t) TMath::Nint(fPointFrac*gStyle->GetNumberOfColors()); |
187 | if(nBins > 0) { |
188 | fPointSetOn = kTRUE; |
189 | fPointSetMaxVal = fThreshold + (Int_t) TMath::Nint(fPointFrac*(fMaxVal - fThreshold)); |
190 | // printf("SetupPointSetArray frac=%f nbins=%d psmv=%d (%d,%d)\n", fPointFrac, nBins, fPointSetMaxVal, fThreshold, fMaxVal); |
dcb387f7 |
191 | fPointSetArray.InitBins("", nBins, fThreshold, fPointSetMaxVal, kFALSE); |
9a7ad6a0 |
192 | for(Int_t b=0; b<nBins; ++b) { |
193 | fPointSetArray.GetBin(b)->SetMarkerColor(gStyle->GetColorPalette(b)); |
194 | } |
195 | } else { |
196 | fPointSetOn = kFALSE; |
092578a7 |
197 | } |
092578a7 |
198 | } |