3626c858 |
1 | #include "MUONChamber.h" |
2 | |
3 | #include <Alieve/MUONData.h> |
4 | #include <Alieve/MUONChamberData.h> |
5 | |
6 | #include <TBuffer3D.h> |
7 | #include <TBuffer3DTypes.h> |
8 | #include <TVirtualPad.h> |
9 | #include <TVirtualViewer3D.h> |
10 | |
11 | #include <TStyle.h> |
12 | #include <TColor.h> |
13 | #include <TMath.h> |
14 | |
15 | using namespace Reve; |
16 | using namespace Alieve; |
17 | |
18 | //______________________________________________________________________ |
19 | // MUONChamber |
20 | // |
21 | |
22 | ClassImp(MUONChamber) |
23 | |
24 | //______________________________________________________________________ |
25 | MUONChamber::MUONChamber(const Text_t* n, const Text_t* t) : |
26 | Reve::RenderElement(fFrameColor), |
27 | TNamed(n,t), |
28 | fMUONData(0), |
29 | fFrameColor((Color_t)2), |
30 | fRTS(1), |
31 | fChamberID(0), |
32 | fQuadSet1(n,t), |
33 | fQuadSet2(n,t), |
34 | fThreshold(0), |
35 | fMaxVal(1024) |
36 | { |
37 | // |
38 | // constructor |
39 | // |
40 | |
41 | ComputeBBox(); |
42 | |
43 | } |
44 | |
45 | //______________________________________________________________________ |
46 | MUONChamber::~MUONChamber() |
47 | { |
48 | // |
49 | // destructor |
50 | // |
51 | |
52 | if(fMUONData) fMUONData->DecRefCount(); |
53 | |
54 | } |
55 | |
56 | //______________________________________________________________________ |
57 | void MUONChamber::ComputeBBox() |
58 | { |
59 | // |
60 | // bounding box |
61 | // |
62 | |
63 | #if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2) |
64 | bbox_init(); |
65 | #else |
66 | BBoxInit(); |
67 | #endif |
68 | |
69 | fBBox[0] = -300.0; |
70 | fBBox[1] = +300.0; |
71 | fBBox[2] = -300.0; |
72 | fBBox[3] = +300.0; |
73 | fBBox[4] = -1800.0; |
74 | fBBox[5] = -500.0; |
75 | |
76 | Float_t* b1 = fQuadSet1.AssertBBox(); |
77 | for(Int_t i=0; i<6; ++i) { b1[i] = fBBox[i]; } |
78 | Float_t* b2 = fQuadSet2.AssertBBox(); |
79 | for(Int_t i=0; i<6; ++i) { b2[i] = fBBox[i]; } |
80 | |
81 | } |
82 | |
83 | //______________________________________________________________________ |
84 | void MUONChamber::Paint(Option_t*) |
85 | { |
86 | // |
87 | // draw... |
88 | // |
89 | |
90 | if(fRnrElement == kFALSE) |
91 | return; |
92 | |
93 | TBuffer3D buffer(TBuffer3DTypes::kGeneric); |
94 | |
95 | buffer.fID = this; |
96 | buffer.fColor = 2; |
97 | buffer.fTransparency = 0; |
98 | buffer.fLocalFrame = 0; |
99 | |
100 | buffer.SetSectionsValid(TBuffer3D::kCore); |
101 | Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer); |
102 | if (reqSections == TBuffer3D::kNone) { |
103 | //printf("MUONChamber::Paint viewer was happy with Core buff3d.\n"); |
104 | return; |
105 | } |
106 | |
107 | printf("MUONChamber::Paint only GL supported.\n"); |
108 | return; |
109 | |
110 | } |
111 | |
112 | //______________________________________________________________________ |
113 | void MUONChamber::SetThreshold(Short_t t) |
114 | { |
115 | // |
116 | // digits amplitude threshold |
117 | // |
118 | |
119 | fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1)); |
120 | ClearColorArray(); |
121 | IncRTS(); |
122 | |
123 | } |
124 | |
125 | //______________________________________________________________________ |
126 | void MUONChamber::SetMaxVal(Int_t mv) |
127 | { |
128 | // |
129 | // digits amplitude maximum value |
130 | // |
131 | |
132 | fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1)); |
133 | ClearColorArray(); |
134 | IncRTS(); |
135 | |
136 | } |
137 | |
138 | //______________________________________________________________________ |
139 | void MUONChamber::SetupColor(Int_t val, UChar_t* pixel) const |
140 | { |
141 | // |
142 | // RGBA color for amplitude "val" |
143 | // |
144 | |
145 | Float_t div = TMath::Max(1, fMaxVal - fThreshold); |
146 | Int_t nCol = gStyle->GetNumberOfColors(); |
147 | Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div); |
148 | |
149 | ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel); |
150 | |
151 | } |
152 | |
153 | //______________________________________________________________________ |
154 | Int_t MUONChamber::ColorIndex(Int_t val) const |
155 | { |
156 | // |
157 | // index color |
158 | // |
159 | |
160 | if(val < fThreshold) val = fThreshold; |
161 | if(val > fMaxVal) val = fMaxVal; |
162 | |
163 | Float_t div = TMath::Max(1, fMaxVal - fThreshold); |
164 | Int_t nCol = gStyle->GetNumberOfColors(); |
165 | Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div); |
166 | |
167 | return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)); |
168 | |
169 | } |
170 | |
171 | //______________________________________________________________________ |
172 | void MUONChamber::SetupColorArray() const |
173 | { |
174 | // |
175 | // build array of colors |
176 | // |
177 | |
178 | if(fColorArray) |
179 | return; |
180 | |
181 | fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)]; |
182 | UChar_t* p = fColorArray; |
183 | for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4) |
184 | SetupColor(v, p); |
185 | |
186 | } |
187 | |
188 | //______________________________________________________________________ |
189 | void MUONChamber::ClearColorArray() |
190 | { |
191 | // |
192 | // delete array of colors |
193 | // |
194 | |
195 | if(fColorArray) { |
196 | delete [] fColorArray; |
197 | fColorArray = 0; |
198 | } |
199 | } |
200 | |
201 | //______________________________________________________________________ |
202 | void MUONChamber::SetDataSource(MUONData* data) |
203 | { |
204 | |
205 | if (data == fMUONData) return; |
206 | if(fMUONData) fMUONData->DecRefCount(); |
207 | fMUONData = data; |
208 | if(fMUONData) fMUONData->IncRefCount(); |
209 | IncRTS(); |
210 | |
211 | } |
212 | |
213 | //______________________________________________________________________ |
214 | MUONChamberData* MUONChamber::GetChamberData() const |
215 | { |
216 | |
217 | return fMUONData ? fMUONData->GetChamberData(fChamberID) : 0; |
218 | |
219 | } |
220 | |
221 | //______________________________________________________________________ |
222 | void MUONChamber::UpdateQuads() |
223 | { |
224 | |
225 | fQuadSet1.Quads().clear(); |
226 | fQuadSet2.Quads().clear(); |
227 | |
228 | MUONChamberData* data = GetChamberData(); |
229 | |
230 | Float_t *buffer; |
231 | Float_t x0, y0, x1, y1, z; |
232 | Int_t charge, cathode; |
233 | if (data != 0) { |
234 | |
235 | SetupColorArray(); |
236 | |
237 | Int_t ndigits = data->GetNDigits(); |
238 | |
239 | for (Int_t id = 0; id < ndigits; id++) { |
240 | |
241 | buffer = data->GetDigitBuffer(id); |
242 | |
243 | x0 = buffer[0]-buffer[2]; |
244 | y0 = buffer[1]-buffer[3]; |
245 | x1 = buffer[0]+buffer[2]; |
246 | y1 = buffer[1]+buffer[3]; |
247 | z = buffer[4]; |
248 | charge = (Int_t)buffer[5]; |
249 | cathode = (Int_t)buffer[6]; |
250 | |
251 | if (cathode == 0) { |
252 | |
253 | fQuadSet1.Quads().push_back(Reve::Quad()); |
254 | |
255 | fQuadSet1.Quads().back().ColorFromIdx(ColorIndex(charge)); |
256 | //ColorFromArray(charge,(UChar_t*)&fQuadSet1.fQuads.back().color); |
257 | |
258 | //UChar_t* c = (UChar_t*)&fQuadSet1.fQuads.back().color; |
259 | //printf("%d %d %d %d \n",c[0],c[1],c[2],c[3]); |
260 | |
261 | Float_t* p = fQuadSet1.Quads().back().vertices; |
262 | |
263 | p[0] = x0; p[1] = y0; p[2] = z; p += 3; |
264 | p[0] = x1; p[1] = y0; p[2] = z; p += 3; |
265 | p[0] = x1; p[1] = y1; p[2] = z; p += 3; |
266 | p[0] = x0; p[1] = y1; p[2] = z; p += 3; |
267 | |
268 | } |
269 | |
270 | if (cathode == 1) { |
271 | |
272 | fQuadSet2.Quads().push_back(Reve::Quad()); |
273 | |
274 | fQuadSet2.Quads().back().ColorFromIdx(ColorIndex(charge)); |
275 | //ColorFromArray(charge,(UChar_t*)&fQuadSet2.fQuads.back().color); |
276 | |
277 | //UChar_t* c = (UChar_t*)&fQuadSet2.fQuads.back().color; |
278 | //printf("%d %d %d %d \n",c[0],c[1],c[2],c[3]); |
279 | |
280 | Float_t* p = fQuadSet2.Quads().back().vertices; |
281 | |
282 | p[0] = x0; p[1] = y0; p[2] = z; p += 3; |
283 | p[0] = x1; p[1] = y0; p[2] = z; p += 3; |
284 | p[0] = x1; p[1] = y1; p[2] = z; p += 3; |
285 | p[0] = x0; p[1] = y1; p[2] = z; p += 3; |
286 | |
287 | } |
288 | |
289 | } // end digits loop |
290 | |
291 | } |
292 | |
293 | } |
294 | |
295 | //______________________________________________________________________ |
296 | void MUONChamber::SetChamberID(Int_t id) |
297 | { |
298 | |
299 | if (id < 0) id = 0; |
300 | if (id > 13) id = 13; |
301 | |
302 | fChamberID = id; |
303 | IncRTS(); |
304 | |
305 | } |
306 | |