Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveCalo2DGL.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TEveCalo2DGL.h"
13#include "TEveCalo.h"
14#include "TEveProjections.h"
16#include "TEveRGBAPalette.h"
17
18#include "TGLRnrCtx.h"
19#include "TGLPhysicalShape.h"
20#include "TGLSelectRecord.h"
21#include "TGLIncludes.h"
22#include "TGLUtil.h"
23#include "TAxis.h"
24
25/** \class TEveCalo2DGL
26\ingroup TEve
27OpenGL renderer class for TEveCalo2D.
28*/
29
30
31////////////////////////////////////////////////////////////////////////////////
32/// Constructor.
33
35 TGLObject(),
36 fM(nullptr)
37{
38 // fDLCache = kFALSE; // Disable display list.
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Set model object.
44
46{
48 return kTRUE;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Set bounding box.
53
58
59////////////////////////////////////////////////////////////////////////////////
60/// Is current projection type RPhi
61
66
67////////////////////////////////////////////////////////////////////////////////
68/// Calculate vertices for the calorimeter cell in RPhi projection.
69/// Returns outside radius of the tower.
70
73{
74 using namespace TMath;
75
77 Float_t r2 = r1 + towerH;
78
79 Float_t pnts[8];
80
81 pnts[0] = r1*Cos(phiMin); pnts[1] = r1*Sin(phiMin);
82 pnts[2] = r2*Cos(phiMin); pnts[3] = r2*Sin(phiMin);
83 pnts[4] = r2*Cos(phiMax); pnts[5] = r2*Sin(phiMax);
84 pnts[6] = r1*Cos(phiMax); pnts[7] = r1*Sin(phiMax);
85
86 Float_t x, y, z;
88 for (Int_t i = 0; i < 4; ++i)
89 {
90 x = pnts[2*i];
91 y = pnts[2*i+1];
92 z = 0.f;
94 glVertex3f(x, y, z);
95 }
96 glEnd();
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Draw calorimeter cells in RPhi projection.
101
103{
105 Int_t nSlices = data->GetNSlices();
109
110 UInt_t nPhi = data->GetPhiBins()->GetNbins();
111 TAxis* axis = data->GetPhiBins();
112 for(UInt_t phiBin = 1; phiBin <= nPhi; ++phiBin)
113 {
114 if (cellLists[phiBin] )
115 {
116 // reset values
117 Float_t off = 0;
118 for (Int_t s=0; s<nSlices; ++s)
119 sliceVal[s] = 0;
120
121 // sum eta cells
123 for (TEveCaloData::vCellId_i it = cids->begin(); it != cids->end(); it++)
124 {
125 data->GetCellData(*it, cellData);
126 sliceVal[(*it).fSlice] += cellData.Value(fM->fPlotEt)*(*it).fFraction;
127 }
128
129 if (rnrCtx.SecSelection()) {
130 glLoadName(phiBin); // set name-stack phi bin
131 glPushName(0);
132 }
133 for (Int_t s = 0; s < nSlices; ++s)
134 {
135 if (rnrCtx.SecSelection()) glLoadName(s); // set name-stack slice
138 off += towerH;
139 }
140 if (rnrCtx.SecSelection()) glPopName(); // slice
141 }
142 }
143
144 delete [] sliceVal;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Draw selected calorimeter cells in RPhi projection.
149
150void TEveCalo2DGL::DrawRPhiHighlighted(std::vector<TEveCaloData::vCellId_t*>& cellLists) const
151{
152 static const TEveException eh("TEveCalo2DGL::DrawRPhiHighlighted ");
153
156 Int_t nSlices = data->GetNSlices();
157 UInt_t nPhiBins = data->GetPhiBins()->GetNbins();
161
162 TAxis* axis = data->GetPhiBins();
163 for(UInt_t phiBin = 1; phiBin <= nPhiBins; ++phiBin)
164 {
165 if (cellLists[phiBin])
166 {
167 if (!fM->fCellLists[phiBin]) {
168 delete[] sliceVal;
169 delete[] sliceValRef;
170 throw eh + "selected cell not in cell list cache.";
171 }
172
173 Float_t off = 0;
174 // selected eta sum
175 for (Int_t s=0; s<nSlices; ++s) sliceVal[s] = 0;
177 for (TEveCaloData::vCellId_i i=cids.begin(); i!=cids.end(); i++) {
178 data->GetCellData((*i), cellData);
179 sliceVal[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
180 }
181 // referenced eta sum
182 for (Int_t s=0; s<nSlices; ++s) sliceValRef[s] = 0;
184 for (TEveCaloData::vCellId_i i=cidsRef.begin(); i!=cidsRef.end(); i++) {
185 data->GetCellData(*i, cellData);
186 sliceValRef[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
187 }
188 // draw
189 for (Int_t s = 0; s < nSlices; ++s) {
191 if (sliceVal[s] > 0)
192 {
195 }
196 off += towerHRef;
197 }
198 }
199 }
200
201 delete [] sliceVal;
202 delete [] sliceValRef;
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Draw cell in RhoZ projection.
207
210{
211 using namespace TMath;
212
213 Float_t pnts[8];
214
215 Float_t sin1 = Sin(thetaMin);
216 Float_t cos1 = Cos(thetaMin);
217 Float_t sin2 = Sin(thetaMax);
218 Float_t cos2 = Cos(thetaMax);
219
220 if (isBarrel)
221 {
222 Float_t r1 = fM->fBarrelRadius/Abs(Sin(0.5f*(thetaMin+thetaMax))) + offset;
223 Float_t r2 = r1 + towerH;
224
225 pnts[0] = r1*sin1; pnts[1] = r1*cos1;
226 pnts[2] = r2*sin1; pnts[3] = r2*cos1;
227 pnts[4] = r2*sin2; pnts[5] = r2*cos2;
228 pnts[6] = r1*sin2; pnts[7] = r1*cos2;
229 }
230 else
231 {
232 // endcap
234 // uses a different theta definition than GetTransitionThetaBackward(), so we need a conversion
236 if (thetaMax >= transThetaB)
237 zE = Abs(fM->GetBackwardEndCapPos());
238 Float_t r1 = zE/Abs(Cos(0.5f*(thetaMin+thetaMax))) + offset;
239 Float_t r2 = r1 + towerH;
240
241 pnts[0] = r1*sin1; pnts[1] = r1*cos1;
242 pnts[2] = r2*sin1; pnts[3] = r2*cos1;
243 pnts[4] = r2*sin2; pnts[5] = r2*cos2;
244 pnts[6] = r1*sin2; pnts[7] = r1*cos2;
245 }
246
248 Float_t x, y, z;
249 for (Int_t i = 0; i < 4; ++i)
250 {
251 x = 0.f;
252 y = phiPlus ? Abs(pnts[2*i]) : -Abs(pnts[2*i]);
253 z = pnts[2*i+1];
255 glVertex3f(x, y, z);
256 }
257 glEnd();
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Draw calorimeter in RhoZ projection.
262
264{
266 Int_t nSlices = data->GetNSlices();
267
275
276 TAxis* axis = data->GetEtaBins();
277 UInt_t nEta = axis->GetNbins();
278 for (UInt_t etaBin = 1; etaBin <= nEta; ++etaBin)
279 {
280 if (cellLists[etaBin] )
281 {
284 Float_t etaMax = axis->GetBinUpEdge(etaBin);
287
288 // clear
289 Float_t offUp = 0;
290 Float_t offLow = 0;
291 for (Int_t s = 0; s < nSlices; ++s) {
292 sliceValsUp [s] = 0;
293 sliceValsLow[s] = 0;
294 }
295 // values
297 for (TEveCaloData::vCellId_i it = cids->begin(); it != cids->end(); ++it)
298 {
299 data->GetCellData(*it, cellData);
300 if (cellData.IsUpperRho())
301 sliceValsUp [it->fSlice] += cellData.Value(fM->fPlotEt)*(*it).fFraction;
302 else
303 sliceValsLow[it->fSlice] += cellData.Value(fM->fPlotEt)*(*it).fFraction;
304 }
305
306 isBarrel = !(etaMax > 0 && etaMax > transEtaF) && !(etaMin < 0 && etaMin < transEtaB);
307
308 // draw
309 if (rnrCtx.SecSelection()) glLoadName(etaBin); // name-stack eta bin
310 if (rnrCtx.SecSelection()) glPushName(0);
311
312 for (Int_t s = 0; s < nSlices; ++s)
313 {
314 if (rnrCtx.SecSelection()) glLoadName(s); // name-stack slice
315 if (rnrCtx.SecSelection()) glPushName(0);
316 // phi +
317 if (sliceValsUp[s])
318 {
319 if (rnrCtx.SecSelection()) glLoadName(1); // name-stack phi sign
322 offUp += towerH;
323 }
324 // phi -
325 if (sliceValsLow[s])
326 {
327 if (rnrCtx.SecSelection()) glLoadName(0); // name-stack phi sign
330 offLow += towerH;
331 }
332 if (rnrCtx.SecSelection()) glPopName(); // phi sign is pos
333 }
334 //
335 if (rnrCtx.SecSelection()) glPopName(); // slice
336 }
337 }
338
339 delete [] sliceValsUp;
340 delete [] sliceValsLow;
341}
342
343////////////////////////////////////////////////////////////////////////////////
344/// Draw selected calorimeter cells in RhoZ projection.
345
346void TEveCalo2DGL::DrawRhoZHighlighted(std::vector<TEveCaloData::vCellId_t*>& cellLists) const
347{
348 static const TEveException eh("TEveCalo2DGL::DrawRhoZHighlighted ");
349
351 TAxis* axis = data->GetEtaBins();
352 UInt_t nEtaBins = axis->GetNbins();
353 Int_t nSlices = data->GetNSlices();
356
361
365
366 for (UInt_t etaBin = 1; etaBin <= nEtaBins; ++etaBin)
367 {
368 if (cellLists[etaBin])
369 {
370 if (!fM->fCellLists[etaBin]) {
371 delete[] sliceValsUp;
372 delete[] sliceValsLow;
373 delete[] sliceValsUpRef;
374 delete[] sliceValsLowRef;
375 throw(eh + "selected cell not in cell list cache.");
376 }
377
378 offUp = 0; offLow =0;
379 // selected phi sum
380 for (Int_t s = 0; s < nSlices; ++s) {
381 sliceValsUp[s] = 0; sliceValsLow[s] = 0;
382 }
384 for (TEveCaloData::vCellId_i i=cids.begin(); i!=cids.end(); i++) {
385 data->GetCellData(*i, cellData);
386 if (cellData.IsUpperRho())
387 sliceValsUp [i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
388 else
389 sliceValsLow[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
390 }
391
392 // reference phi sum
393 for (Int_t s = 0; s < nSlices; ++s)
394 {
395 sliceValsUpRef[s] = 0; sliceValsLowRef[s] = 0;
396 }
398 for (TEveCaloData::vCellId_i i=cidsRef.begin(); i!=cidsRef.end(); i++)
399 {
400 data->GetCellData(*i, cellData);
401 if (cellData.IsUpperRho())
402 sliceValsUpRef [i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
403 else
404 sliceValsLowRef[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
405 }
406
409
410 for (Int_t s = 0; s < nSlices; ++s)
411 {
414 // phi +
416 if (sliceValsUp[s] > 0) {
419 }
420 offUp += towerHRef;
421
422 // phi -
424 if (sliceValsLow[s] > 0) {
427 }
428 offLow += towerHRef;
429 } // slices
430 } // if eta bin
431 } //eta bin
432
433 delete [] sliceValsUp;
434 delete [] sliceValsLow;
435 delete [] sliceValsUpRef;
436 delete [] sliceValsLowRef;
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// Render with OpenGL.
441
464
465////////////////////////////////////////////////////////////////////////////////
466/// Draw towers in highlight mode.
467
469{
470 static const TEveException eh("TEveCalo2DGL::DrawHighlight ");
471
472 if (fM->fData->GetCellsSelected().empty() && fM->fData->GetCellsHighlighted().empty())
473 {
474 return;
475 }
476
478
480 try
481 {
482 if (!fM->fData->GetCellsHighlighted().empty())
483 {
484 glColor4ubv(rnrCtx.ColorSet().Selection(3).CArr());
485
486 if (IsRPhi())
488 else
490 }
491 if (!fM->fData->GetCellsSelected().empty())
492 {
493 glColor4ubv(rnrCtx.ColorSet().Selection(1).CArr());
494 if (IsRPhi())
496 else
498
499 }
500 }
501 catch (TEveException& exc)
502 {
503 Warning(eh, "%s", exc.what());
504 }
506}
507
508////////////////////////////////////////////////////////////////////////////////
509/// Processes tower selection in eta bin or phi bin.
510/// Virtual function from TGLogicalShape. Called from TGLViewer.
511
513{
515 if (rec.GetN() > 2)
516 {
517 Int_t bin = rec.GetItem(1);
518 Int_t slice = rec.GetItem(2);
519 for (TEveCaloData::vCellId_i it = fM->fCellLists[bin]->begin();
520 it != fM->fCellLists[bin]->end(); ++it)
521 {
522 if ((*it).fSlice == slice)
523 {
524 if (IsRPhi())
525 {
526 sel.push_back(*it);
527 }
528 else
529 {
530 assert(rec.GetN() > 3);
531 Bool_t is_upper = (rec.GetItem(3) == 1);
533 fM->fData->GetCellData(*it, cd);
534 if ((is_upper && cd.IsUpperRho()) || (!is_upper && !cd.IsUpperRho()))
535 sel.push_back(*it);
536 }
537 }
538 }
539 }
541}
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
const_iterator begin() const
const_iterator end() const
Class to manage histogram axis.
Definition TAxis.h:32
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:481
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:521
Int_t GetNbins() const
Definition TAxis.h:127
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:531
void DrawRPhi(TGLRnrCtx &rnrCtx, TEveCalo2D::vBinCells_t &) const
Draw calorimeter cells in RPhi projection.
void ProcessSelection(TGLRnrCtx &rnrCtx, TGLSelectRecord &rec) override
Processes tower selection in eta bin or phi bin.
void MakeRPhiCell(Float_t phiMin, Float_t phiMax, Float_t towerH, Float_t offset) const
Calculate vertices for the calorimeter cell in RPhi projection.
void DrawRhoZ(TGLRnrCtx &rnrCtx, TEveCalo2D::vBinCells_t &) const
Draw calorimeter in RhoZ projection.
Bool_t IsRPhi() const
Is current projection type RPhi.
void DirectDraw(TGLRnrCtx &rnrCtx) const override
Render with OpenGL.
void SetBBox() override
Set bounding box.
void DrawRPhiHighlighted(std::vector< TEveCaloData::vCellId_t * > &cellLists) const
Draw selected calorimeter cells in RPhi projection.
void DrawRhoZHighlighted(std::vector< TEveCaloData::vCellId_t * > &cellLists) const
Draw selected calorimeter cells in RhoZ projection.
void MakeRhoZCell(Float_t thetaMin, Float_t thetaMax, Float_t &offset, Bool_t isBarrel, Bool_t phiPlus, Float_t towerH) const
Draw cell in RhoZ projection.
void DrawHighlight(TGLRnrCtx &rnrCtx, const TGLPhysicalShape *ps, Int_t lvl=-1) const override
Draw towers in highlight mode.
TEveCalo2DGL()
Constructor.
Bool_t SetModel(TObject *obj, const Option_t *opt=nullptr) override
Set model object.
TEveCalo2D * fM
Visualization of a calorimeter event data in 2D.
Definition TEveCalo.h:202
void BuildCellIdCache() override
Build lists of drawn cell IDs. See TEveCalo2DGL::DirecDraw().
Definition TEveCalo.cxx:556
std::vector< TEveCaloData::vCellId_t * > fCellListsHighlighted
Definition TEveCalo.h:220
std::vector< TEveCaloData::vCellId_t * > vBinCells_t
Definition TEveCalo.h:206
std::vector< TEveCaloData::vCellId_t * > fCellLists
Definition TEveCalo.h:217
std::vector< TEveCaloData::vCellId_t * > fCellListsSelected
Definition TEveCalo.h:219
A central manager for calorimeter event data.
std::vector< CellId_t > vCellId_t
static Float_t EtaToTheta(Float_t eta)
void ProcessSelection(vCellId_t &sel_cells, TGLSelectRecord &rec)
Process newly selected cells with given select-record.
virtual void GetCellData(const CellId_t &id, CellData_t &data) const =0
vCellId_t & GetCellsHighlighted()
vCellId_t & GetCellsSelected()
std::vector< CellId_t >::iterator vCellId_i
Float_t fPlotEt
Definition TEveCalo.h:55
Float_t GetTransitionEtaBackward() const
Get transition eta between barrel and backward end-cap cells.
Definition TEveCalo.cxx:226
Float_t fBarrelRadius
Definition TEveCalo.h:51
Float_t GetBackwardEndCapPos() const
Definition TEveCalo.h:104
Float_t GetForwardEndCapPos() const
Definition TEveCalo.h:103
TEveCaloData * GetData() const
Definition TEveCalo.h:87
TEveRGBAPalette * AssertPalette()
Make sure the TEveRGBAPalette pointer is not null.
Definition TEveCalo.cxx:377
Bool_t fCellIdCacheOK
Definition TEveCalo.h:41
TEveCaloData * fData
Definition TEveCalo.h:40
Float_t GetTransitionEtaForward() const
Get transition eta between barrel and forward end-cap cells.
Definition TEveCalo.cxx:208
void SetupColorHeight(Float_t value, Int_t slice, Float_t &height) const
Set color and height for a given value and slice using slice color or TEveRGBAPalette.
Definition TEveCalo.cxx:414
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
TEveProjectionManager * fManager
TEveProjection * GetProjection()
virtual void ProjectPoint(Float_t &x, Float_t &y, Float_t &z, Float_t d, EPProc_e p=kPP_Full)=0
EPType_e GetType() const
TObject * fExternalObj
first replica
Base-class for direct OpenGL renderers.
Definition TGLObject.h:22
Bool_t fMultiColor
Definition TGLObject.h:28
void SetAxisAlignedBBox(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax)
Set axis-aligned bounding-box.
Definition TGLObject.cxx:85
Concrete physical shape - a GL drawable.
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
Standard selection record including information about containing scene and details ob out selected ob...
static UInt_t LockColor()
Prevent further color changes.
Definition TGLUtil.cxx:1660
static UInt_t UnlockColor()
Allow color changes.
Definition TGLUtil.cxx:1668
Mother of all ROOT objects.
Definition TObject.h:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TMath.
Definition TMathBase.h:35
Cell data inner structure.
Bool_t IsUpperRho() const