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 | //______________________________________________________________________ |
eadce74d |
25 | MUONChamber::MUONChamber(Int_t id, const Text_t* n, const Text_t* t) : |
3626c858 |
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), |
eadce74d |
34 | fPointSet1(n), |
35 | fPointSet2(n), |
3626c858 |
36 | fThreshold(0), |
eadce74d |
37 | fMaxVal(4096), |
38 | fClusterSize(5), |
39 | fHitSize(5) |
3626c858 |
40 | { |
41 | // |
42 | // constructor |
43 | // |
44 | |
eadce74d |
45 | Char_t name[256]; |
46 | if (id < 10) { |
47 | sprintf(name,"Chamber %02d (trac)",id); |
48 | } else { |
49 | sprintf(name,"Chamber %02d (trig)",id); |
50 | } |
51 | SetName(name); |
52 | |
3626c858 |
53 | ComputeBBox(); |
54 | |
55 | } |
56 | |
57 | //______________________________________________________________________ |
58 | MUONChamber::~MUONChamber() |
59 | { |
60 | // |
61 | // destructor |
62 | // |
63 | |
64 | if(fMUONData) fMUONData->DecRefCount(); |
65 | |
66 | } |
67 | |
68 | //______________________________________________________________________ |
69 | void MUONChamber::ComputeBBox() |
70 | { |
71 | // |
72 | // bounding box |
73 | // |
74 | |
75 | #if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2) |
76 | bbox_init(); |
77 | #else |
78 | BBoxInit(); |
79 | #endif |
80 | |
eadce74d |
81 | fBBox[0] = - 400.0; |
82 | fBBox[1] = + 400.0; |
83 | fBBox[2] = - 400.0; |
84 | fBBox[3] = + 400.0; |
3626c858 |
85 | fBBox[4] = -1800.0; |
eadce74d |
86 | fBBox[5] = + 500.0; |
3626c858 |
87 | |
88 | Float_t* b1 = fQuadSet1.AssertBBox(); |
89 | for(Int_t i=0; i<6; ++i) { b1[i] = fBBox[i]; } |
90 | Float_t* b2 = fQuadSet2.AssertBBox(); |
91 | for(Int_t i=0; i<6; ++i) { b2[i] = fBBox[i]; } |
eadce74d |
92 | Float_t* b3 = fPointSet1.AssertBBox(); |
93 | for(Int_t i=0; i<6; ++i) { b3[i] = fBBox[i]; } |
94 | Float_t* b4 = fPointSet2.AssertBBox(); |
95 | for(Int_t i=0; i<6; ++i) { b4[i] = fBBox[i]; } |
3626c858 |
96 | |
97 | } |
98 | |
99 | //______________________________________________________________________ |
100 | void MUONChamber::Paint(Option_t*) |
101 | { |
102 | // |
103 | // draw... |
104 | // |
105 | |
2caed564 |
106 | if(fRnrSelf == kFALSE) |
3626c858 |
107 | return; |
108 | |
109 | TBuffer3D buffer(TBuffer3DTypes::kGeneric); |
110 | |
111 | buffer.fID = this; |
112 | buffer.fColor = 2; |
113 | buffer.fTransparency = 0; |
114 | buffer.fLocalFrame = 0; |
115 | |
116 | buffer.SetSectionsValid(TBuffer3D::kCore); |
117 | Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer); |
118 | if (reqSections == TBuffer3D::kNone) { |
119 | //printf("MUONChamber::Paint viewer was happy with Core buff3d.\n"); |
120 | return; |
121 | } |
122 | |
123 | printf("MUONChamber::Paint only GL supported.\n"); |
124 | return; |
125 | |
126 | } |
127 | |
128 | //______________________________________________________________________ |
129 | void MUONChamber::SetThreshold(Short_t t) |
130 | { |
131 | // |
132 | // digits amplitude threshold |
133 | // |
134 | |
135 | fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1)); |
136 | ClearColorArray(); |
137 | IncRTS(); |
138 | |
139 | } |
140 | |
141 | //______________________________________________________________________ |
142 | void MUONChamber::SetMaxVal(Int_t mv) |
143 | { |
144 | // |
145 | // digits amplitude maximum value |
146 | // |
147 | |
148 | fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1)); |
149 | ClearColorArray(); |
150 | IncRTS(); |
151 | |
152 | } |
153 | |
eadce74d |
154 | //______________________________________________________________________ |
155 | void MUONChamber::SetClusterSize(Int_t size) |
156 | { |
157 | // |
158 | // cluster point size |
159 | // |
160 | |
161 | fClusterSize = TMath::Max(1, size); |
162 | IncRTS(); |
163 | |
164 | } |
165 | |
166 | //______________________________________________________________________ |
167 | void MUONChamber::SetHitSize(Int_t size) |
168 | { |
169 | // |
170 | // hit point size |
171 | // |
172 | |
173 | fHitSize = TMath::Max(1, size); |
174 | IncRTS(); |
175 | |
176 | } |
177 | |
3626c858 |
178 | //______________________________________________________________________ |
179 | void MUONChamber::SetupColor(Int_t val, UChar_t* pixel) const |
180 | { |
181 | // |
182 | // RGBA color for amplitude "val" |
183 | // |
184 | |
185 | Float_t div = TMath::Max(1, fMaxVal - fThreshold); |
186 | Int_t nCol = gStyle->GetNumberOfColors(); |
187 | Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div); |
188 | |
189 | ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel); |
190 | |
191 | } |
192 | |
193 | //______________________________________________________________________ |
194 | Int_t MUONChamber::ColorIndex(Int_t val) const |
195 | { |
196 | // |
197 | // index color |
198 | // |
199 | |
200 | if(val < fThreshold) val = fThreshold; |
201 | if(val > fMaxVal) val = fMaxVal; |
202 | |
203 | Float_t div = TMath::Max(1, fMaxVal - fThreshold); |
204 | Int_t nCol = gStyle->GetNumberOfColors(); |
205 | Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div); |
206 | |
207 | return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)); |
208 | |
209 | } |
210 | |
211 | //______________________________________________________________________ |
212 | void MUONChamber::SetupColorArray() const |
213 | { |
214 | // |
215 | // build array of colors |
216 | // |
217 | |
218 | if(fColorArray) |
219 | return; |
220 | |
221 | fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)]; |
222 | UChar_t* p = fColorArray; |
223 | for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4) |
224 | SetupColor(v, p); |
225 | |
226 | } |
227 | |
228 | //______________________________________________________________________ |
229 | void MUONChamber::ClearColorArray() |
230 | { |
231 | // |
232 | // delete array of colors |
233 | // |
234 | |
235 | if(fColorArray) { |
236 | delete [] fColorArray; |
237 | fColorArray = 0; |
238 | } |
239 | } |
240 | |
241 | //______________________________________________________________________ |
242 | void MUONChamber::SetDataSource(MUONData* data) |
243 | { |
244 | |
245 | if (data == fMUONData) return; |
246 | if(fMUONData) fMUONData->DecRefCount(); |
247 | fMUONData = data; |
248 | if(fMUONData) fMUONData->IncRefCount(); |
249 | IncRTS(); |
250 | |
251 | } |
252 | |
253 | //______________________________________________________________________ |
254 | MUONChamberData* MUONChamber::GetChamberData() const |
255 | { |
256 | |
257 | return fMUONData ? fMUONData->GetChamberData(fChamberID) : 0; |
258 | |
259 | } |
260 | |
261 | //______________________________________________________________________ |
262 | void MUONChamber::UpdateQuads() |
263 | { |
264 | |
265 | fQuadSet1.Quads().clear(); |
266 | fQuadSet2.Quads().clear(); |
eadce74d |
267 | fPointSet1.Reset(); |
268 | fPointSet2.Reset(); |
3626c858 |
269 | |
270 | MUONChamberData* data = GetChamberData(); |
271 | |
272 | Float_t *buffer; |
eadce74d |
273 | Float_t x0, y0, x1, y1, z, clsq; |
274 | Int_t charge, cathode, nDigits, nClusters, nHits, oldSize, ic1, ic2; |
275 | Double_t clsX, clsY, clsZ; |
276 | Float_t hitX, hitY, hitZ; |
277 | |
3626c858 |
278 | if (data != 0) { |
279 | |
280 | SetupColorArray(); |
281 | |
eadce74d |
282 | // digits |
283 | |
284 | nDigits = data->GetNDigits(); |
3626c858 |
285 | |
eadce74d |
286 | for (Int_t id = 0; id < nDigits; id++) { |
3626c858 |
287 | |
288 | buffer = data->GetDigitBuffer(id); |
289 | |
290 | x0 = buffer[0]-buffer[2]; |
291 | y0 = buffer[1]-buffer[3]; |
292 | x1 = buffer[0]+buffer[2]; |
293 | y1 = buffer[1]+buffer[3]; |
294 | z = buffer[4]; |
295 | charge = (Int_t)buffer[5]; |
296 | cathode = (Int_t)buffer[6]; |
297 | |
eadce74d |
298 | if (charge <= fThreshold) continue; |
299 | |
3626c858 |
300 | if (cathode == 0) { |
301 | |
302 | fQuadSet1.Quads().push_back(Reve::Quad()); |
303 | |
304 | fQuadSet1.Quads().back().ColorFromIdx(ColorIndex(charge)); |
305 | //ColorFromArray(charge,(UChar_t*)&fQuadSet1.fQuads.back().color); |
306 | |
307 | //UChar_t* c = (UChar_t*)&fQuadSet1.fQuads.back().color; |
308 | //printf("%d %d %d %d \n",c[0],c[1],c[2],c[3]); |
309 | |
310 | Float_t* p = fQuadSet1.Quads().back().vertices; |
311 | |
312 | p[0] = x0; p[1] = y0; p[2] = z; p += 3; |
313 | p[0] = x1; p[1] = y0; p[2] = z; p += 3; |
314 | p[0] = x1; p[1] = y1; p[2] = z; p += 3; |
315 | p[0] = x0; p[1] = y1; p[2] = z; p += 3; |
316 | |
317 | } |
318 | |
319 | if (cathode == 1) { |
320 | |
321 | fQuadSet2.Quads().push_back(Reve::Quad()); |
322 | |
323 | fQuadSet2.Quads().back().ColorFromIdx(ColorIndex(charge)); |
324 | //ColorFromArray(charge,(UChar_t*)&fQuadSet2.fQuads.back().color); |
325 | |
326 | //UChar_t* c = (UChar_t*)&fQuadSet2.fQuads.back().color; |
327 | //printf("%d %d %d %d \n",c[0],c[1],c[2],c[3]); |
328 | |
329 | Float_t* p = fQuadSet2.Quads().back().vertices; |
330 | |
331 | p[0] = x0; p[1] = y0; p[2] = z; p += 3; |
332 | p[0] = x1; p[1] = y0; p[2] = z; p += 3; |
333 | p[0] = x1; p[1] = y1; p[2] = z; p += 3; |
334 | p[0] = x0; p[1] = y1; p[2] = z; p += 3; |
335 | |
336 | } |
337 | |
338 | } // end digits loop |
339 | |
eadce74d |
340 | // clusters |
341 | |
342 | nClusters = data->GetNClusters()/2; // only one cathode plane |
343 | oldSize = fPointSet1.GrowFor(nClusters); |
344 | ic1 = ic2 = 0; |
345 | for (Int_t ic = 0; ic < (nClusters*2); ic++) { |
346 | |
347 | buffer = data->GetClusterBuffer(ic); |
348 | |
349 | clsX = (Double_t)buffer[0]; |
350 | clsY = (Double_t)buffer[1]; |
351 | clsZ = (Double_t)buffer[2]; |
352 | clsq = buffer[3]; |
353 | cathode = (Int_t)buffer[4]; |
354 | |
355 | if (cathode == 0) { |
356 | fPointSet1.SetPoint(ic1,clsX,clsY,clsZ); |
357 | ic1++; |
358 | } |
359 | |
360 | } // end clusters loop |
361 | |
362 | // hits |
363 | |
364 | nHits = data->GetNHits(); |
365 | oldSize = fPointSet2.GrowFor(nHits); |
366 | for (Int_t ih = 0; ih < nHits; ih++) { |
367 | buffer = data->GetHitBuffer(ih); |
368 | hitX = buffer[0]; |
369 | hitY = buffer[1]; |
370 | hitZ = buffer[2]; |
371 | fPointSet2.SetPoint(ih,hitX,hitY,hitZ); |
372 | } |
373 | |
374 | } // end data |
3626c858 |
375 | |
376 | } |
377 | |
378 | //______________________________________________________________________ |
379 | void MUONChamber::SetChamberID(Int_t id) |
380 | { |
381 | |
382 | if (id < 0) id = 0; |
383 | if (id > 13) id = 13; |
384 | |
385 | fChamberID = id; |
386 | IncRTS(); |
387 | |
388 | } |
389 | |