30 ClassImp(TEveCalo2DGL);
35 TEveCalo2DGL::TEveCalo2DGL() :
46 Bool_t TEveCalo2DGL::SetModel(TObject* obj,
const Option_t* )
48 fM = SetModelDynCast<TEveCalo2D>(obj);
55 void TEveCalo2DGL::SetBBox()
57 SetAxisAlignedBBox(((TEveCalo2D*)fExternalObj)->AssertBBox());
63 Bool_t TEveCalo2DGL::IsRPhi()
const
65 return fM->fManager->GetProjection()->GetType() == TEveProjection::kPT_RPhi;
72 void TEveCalo2DGL::MakeRPhiCell(Float_t phiMin, Float_t phiMax,
73 Float_t towerH, Float_t offset)
const
75 using namespace TMath;
77 Float_t r1 = fM->fBarrelRadius + offset;
78 Float_t r2 = r1 + towerH;
82 pnts[0] = r1*Cos(phiMin); pnts[1] = r1*Sin(phiMin);
83 pnts[2] = r2*Cos(phiMin); pnts[3] = r2*Sin(phiMin);
84 pnts[4] = r2*Cos(phiMax); pnts[5] = r2*Sin(phiMax);
85 pnts[6] = r1*Cos(phiMax); pnts[7] = r1*Sin(phiMax);
89 for (Int_t i = 0; i < 4; ++i)
94 fM->fManager->GetProjection()->ProjectPoint(x, y, z, fM->fDepth);
103 void TEveCalo2DGL::DrawRPhi(TGLRnrCtx & rnrCtx, TEveCalo2D::vBinCells_t& cellLists)
const
105 TEveCaloData* data = fM->GetData();
106 Int_t nSlices = data->GetNSlices();
107 Float_t *sliceVal =
new Float_t[nSlices];
108 TEveCaloData::CellData_t cellData;
111 UInt_t nPhi = data->GetPhiBins()->GetNbins();
112 TAxis* axis = data->GetPhiBins();
113 for(UInt_t phiBin = 1; phiBin <= nPhi; ++phiBin)
115 if (cellLists[phiBin] )
119 for (Int_t s=0; s<nSlices; ++s)
123 TEveCaloData::vCellId_t* cids = cellLists[phiBin];
124 for (TEveCaloData::vCellId_i it = cids->begin(); it != cids->end(); it++)
126 data->GetCellData(*it, cellData);
127 sliceVal[(*it).fSlice] += cellData.Value(fM->fPlotEt)*(*it).fFraction;
130 if (rnrCtx.SecSelection()) {
134 for (Int_t s = 0; s < nSlices; ++s)
136 if (rnrCtx.SecSelection()) glLoadName(s);
137 fM->SetupColorHeight(sliceVal[s], s, towerH);
138 MakeRPhiCell(axis->GetBinLowEdge(phiBin), axis->GetBinUpEdge(phiBin), towerH, off);
141 if (rnrCtx.SecSelection()) glPopName();
151 void TEveCalo2DGL::DrawRPhiHighlighted(std::vector<TEveCaloData::vCellId_t*>& cellLists)
const
153 static const TEveException eh(
"TEveCalo2DGL::DrawRPhiHighlighted ");
155 TEveCaloData* data = fM->fData;
156 TEveCaloData::CellData_t cellData;
157 Int_t nSlices = data->GetNSlices();
158 UInt_t nPhiBins = data->GetPhiBins()->GetNbins();
159 Float_t *sliceVal =
new Float_t[nSlices];
160 Float_t *sliceValRef =
new Float_t[nSlices];
161 Float_t towerH, towerHRef;
163 TAxis* axis = data->GetPhiBins();
164 for(UInt_t phiBin = 1; phiBin <= nPhiBins; ++phiBin)
166 if (cellLists[phiBin])
168 if (!fM->fCellLists[phiBin]) {
170 delete[] sliceValRef;
171 throw eh +
"selected cell not in cell list cache.";
176 for (Int_t s=0; s<nSlices; ++s) sliceVal[s] = 0;
177 TEveCaloData::vCellId_t& cids = *(cellLists[phiBin]);
178 for (TEveCaloData::vCellId_i i=cids.begin(); i!=cids.end(); i++) {
179 data->GetCellData((*i), cellData);
180 sliceVal[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
183 for (Int_t s=0; s<nSlices; ++s) sliceValRef[s] = 0;
184 TEveCaloData::vCellId_t& cidsRef = *(fM->fCellLists[phiBin]);
185 for (TEveCaloData::vCellId_i i=cidsRef.begin(); i!=cidsRef.end(); i++) {
186 data->GetCellData(*i, cellData);
187 sliceValRef[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
190 for (Int_t s = 0; s < nSlices; ++s) {
191 fM->SetupColorHeight(sliceValRef[s], s, towerHRef);
194 fM->SetupColorHeight(sliceVal[s], s, towerH);
195 MakeRPhiCell(axis->GetBinLowEdge(phiBin), axis->GetBinUpEdge(phiBin), towerH, off);
203 delete [] sliceValRef;
209 void TEveCalo2DGL::MakeRhoZCell(Float_t thetaMin, Float_t thetaMax,
210 Float_t& offset, Bool_t isBarrel, Bool_t phiPlus, Float_t towerH)
const
212 using namespace TMath;
216 Float_t sin1 = Sin(thetaMin);
217 Float_t cos1 = Cos(thetaMin);
218 Float_t sin2 = Sin(thetaMax);
219 Float_t cos2 = Cos(thetaMax);
223 Float_t r1 = fM->fBarrelRadius/Abs(Sin(0.5f*(thetaMin+thetaMax))) + offset;
224 Float_t r2 = r1 + towerH;
226 pnts[0] = r1*sin1; pnts[1] = r1*cos1;
227 pnts[2] = r2*sin1; pnts[3] = r2*cos1;
228 pnts[4] = r2*sin2; pnts[5] = r2*cos2;
229 pnts[6] = r1*sin2; pnts[7] = r1*cos2;
234 Float_t zE = fM->GetForwardEndCapPos();
236 Float_t transThetaB = TEveCaloData::EtaToTheta(fM->GetTransitionEtaBackward());
237 if (thetaMax >= transThetaB)
238 zE = Abs(fM->GetBackwardEndCapPos());
239 Float_t r1 = zE/Abs(Cos(0.5f*(thetaMin+thetaMax))) + offset;
240 Float_t r2 = r1 + towerH;
242 pnts[0] = r1*sin1; pnts[1] = r1*cos1;
243 pnts[2] = r2*sin1; pnts[3] = r2*cos1;
244 pnts[4] = r2*sin2; pnts[5] = r2*cos2;
245 pnts[6] = r1*sin2; pnts[7] = r1*cos2;
250 for (Int_t i = 0; i < 4; ++i)
253 y = phiPlus ? Abs(pnts[2*i]) : -Abs(pnts[2*i]);
255 fM->fManager->GetProjection()->ProjectPoint(x, y, z, fM->fDepth);
264 void TEveCalo2DGL::DrawRhoZ(TGLRnrCtx & rnrCtx, TEveCalo2D::vBinCells_t& cellLists)
const
266 TEveCaloData* data = fM->GetData();
267 Int_t nSlices = data->GetNSlices();
269 TEveCaloData::CellData_t cellData;
270 Float_t *sliceValsUp =
new Float_t[nSlices];
271 Float_t *sliceValsLow =
new Float_t[nSlices];
274 Float_t transEtaF = fM->GetTransitionEtaForward();
275 Float_t transEtaB = fM->GetTransitionEtaBackward();
277 TAxis* axis = data->GetEtaBins();
278 UInt_t nEta = axis->GetNbins();
279 for (UInt_t etaBin = 1; etaBin <= nEta; ++etaBin)
281 if (cellLists[etaBin] )
283 assert(fM->fCellLists[etaBin]);
284 Float_t etaMin = axis->GetBinLowEdge(etaBin);
285 Float_t etaMax = axis->GetBinUpEdge(etaBin);
286 Float_t thetaMin = TEveCaloData::EtaToTheta(etaMax);
287 Float_t thetaMax = TEveCaloData::EtaToTheta(etaMin);
292 for (Int_t s = 0; s < nSlices; ++s) {
297 TEveCaloData::vCellId_t* cids = cellLists[etaBin];
298 for (TEveCaloData::vCellId_i it = cids->begin(); it != cids->end(); ++it)
300 data->GetCellData(*it, cellData);
301 if (cellData.IsUpperRho())
302 sliceValsUp [it->fSlice] += cellData.Value(fM->fPlotEt)*(*it).fFraction;
304 sliceValsLow[it->fSlice] += cellData.Value(fM->fPlotEt)*(*it).fFraction;
307 isBarrel = !(etaMax > 0 && etaMax > transEtaF) && !(etaMin < 0 && etaMin < transEtaB);
310 if (rnrCtx.SecSelection()) glLoadName(etaBin);
311 if (rnrCtx.SecSelection()) glPushName(0);
313 for (Int_t s = 0; s < nSlices; ++s)
315 if (rnrCtx.SecSelection()) glLoadName(s);
316 if (rnrCtx.SecSelection()) glPushName(0);
320 if (rnrCtx.SecSelection()) glLoadName(1);
321 fM->SetupColorHeight(sliceValsUp[s], s, towerH);
322 MakeRhoZCell(thetaMin, thetaMax, offUp, isBarrel, kTRUE , towerH);
328 if (rnrCtx.SecSelection()) glLoadName(0);
329 fM->SetupColorHeight(sliceValsLow[s], s, towerH);
330 MakeRhoZCell(thetaMin, thetaMax, offLow, isBarrel, kFALSE , towerH);
333 if (rnrCtx.SecSelection()) glPopName();
336 if (rnrCtx.SecSelection()) glPopName();
340 delete [] sliceValsUp;
341 delete [] sliceValsLow;
347 void TEveCalo2DGL::DrawRhoZHighlighted(std::vector<TEveCaloData::vCellId_t*>& cellLists)
const
349 static const TEveException eh(
"TEveCalo2DGL::DrawRhoZHighlighted ");
351 TEveCaloData* data = fM->GetData();
352 TAxis* axis = data->GetEtaBins();
353 UInt_t nEtaBins = axis->GetNbins();
354 Int_t nSlices = data->GetNSlices();
355 Float_t transEtaF = fM->GetTransitionEtaForward();
356 Float_t transEtaB = fM->GetTransitionEtaBackward();
358 Float_t *sliceValsUp =
new Float_t[nSlices];
359 Float_t *sliceValsLow =
new Float_t[nSlices];
360 Float_t *sliceValsUpRef =
new Float_t[nSlices];
361 Float_t *sliceValsLowRef =
new Float_t[nSlices];
364 Float_t towerH, towerHRef, offUp, offLow;
365 TEveCaloData::CellData_t cellData;
367 for (UInt_t etaBin = 1; etaBin <= nEtaBins; ++etaBin)
369 if (cellLists[etaBin])
371 if (!fM->fCellLists[etaBin]) {
372 delete[] sliceValsUp;
373 delete[] sliceValsLow;
374 delete[] sliceValsUpRef;
375 delete[] sliceValsLowRef;
376 throw(eh +
"selected cell not in cell list cache.");
379 offUp = 0; offLow =0;
381 for (Int_t s = 0; s < nSlices; ++s) {
382 sliceValsUp[s] = 0; sliceValsLow[s] = 0;
384 TEveCaloData::vCellId_t& cids = *(cellLists[etaBin]);
385 for (TEveCaloData::vCellId_i i=cids.begin(); i!=cids.end(); i++) {
386 data->GetCellData(*i, cellData);
387 if (cellData.IsUpperRho())
388 sliceValsUp [i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
390 sliceValsLow[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
394 for (Int_t s = 0; s < nSlices; ++s)
396 sliceValsUpRef[s] = 0; sliceValsLowRef[s] = 0;
398 TEveCaloData::vCellId_t& cidsRef = *(fM->fCellLists[etaBin]);
399 for (TEveCaloData::vCellId_i i=cidsRef.begin(); i!=cidsRef.end(); i++)
401 data->GetCellData(*i, cellData);
402 if (cellData.IsUpperRho())
403 sliceValsUpRef [i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
405 sliceValsLowRef[i->fSlice] += cellData.Value(fM->fPlotEt)*(*i).fFraction;
408 Float_t bincenterEta = axis->GetBinCenter(etaBin);
409 isBarrel = !(bincenterEta > 0 && bincenterEta > transEtaF) && !(bincenterEta < 0 && bincenterEta < transEtaB);
411 for (Int_t s = 0; s < nSlices; ++s)
413 Float_t thetaMin = TEveCaloData::EtaToTheta(axis->GetBinUpEdge(etaBin));
414 Float_t thetaMax = TEveCaloData::EtaToTheta(axis->GetBinLowEdge(etaBin));
416 fM->SetupColorHeight(sliceValsUpRef[s], s, towerHRef);
417 if (sliceValsUp[s] > 0) {
418 fM->SetupColorHeight(sliceValsUp[s], s, towerH);
419 MakeRhoZCell(thetaMin, thetaMax, offUp, isBarrel, kTRUE , towerH);
424 fM->SetupColorHeight(sliceValsLowRef[s], s, towerHRef);
425 if (sliceValsLow[s] > 0) {
426 fM->SetupColorHeight(sliceValsLow[s], s, towerH);
427 MakeRhoZCell(thetaMin, thetaMax, offLow, isBarrel, kFALSE , towerH);
434 delete [] sliceValsUp;
435 delete [] sliceValsLow;
436 delete [] sliceValsUpRef;
437 delete [] sliceValsLowRef;
443 void TEveCalo2DGL::DirectDraw(TGLRnrCtx & rnrCtx)
const
445 TGLCapabilitySwitch light_off(GL_LIGHTING, kFALSE);
446 TGLCapabilitySwitch cull_off (GL_CULL_FACE, kFALSE);
448 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
450 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
452 if (fM->fCellIdCacheOK == kFALSE)
453 fM->BuildCellIdCache();
457 if (rnrCtx.SecSelection()) glPushName(0);
459 DrawRPhi(rnrCtx, fM->fCellLists);
461 DrawRhoZ(rnrCtx, fM->fCellLists);
462 if (rnrCtx.SecSelection()) glPopName();
469 void TEveCalo2DGL::DrawHighlight(TGLRnrCtx& rnrCtx,
const TGLPhysicalShape* , Int_t )
const
471 static const TEveException eh(
"TEveCalo2DGL::DrawHighlight ");
473 if (fM->fData->GetCellsSelected().empty() && fM->fData->GetCellsHighlighted().empty())
478 TGLCapabilitySwitch cull_off (GL_CULL_FACE, kFALSE);
480 TGLUtil::LockColor();
483 if (!fM->fData->GetCellsHighlighted().empty())
485 glColor4ubv(rnrCtx.ColorSet().Selection(3).CArr());
488 DrawRPhiHighlighted(fM->fCellListsHighlighted);
490 DrawRhoZHighlighted(fM->fCellListsHighlighted);
492 if (!fM->fData->GetCellsSelected().empty())
494 glColor4ubv(rnrCtx.ColorSet().Selection(1).CArr());
496 DrawRPhiHighlighted(fM->fCellListsSelected);
498 DrawRhoZHighlighted(fM->fCellListsSelected);
502 catch (TEveException& exc)
504 Warning(eh,
"%s", exc.what());
506 TGLUtil::UnlockColor();
513 void TEveCalo2DGL::ProcessSelection(TGLRnrCtx & , TGLSelectRecord & rec)
515 TEveCaloData::vCellId_t sel;
518 Int_t bin = rec.GetItem(1);
519 Int_t slice = rec.GetItem(2);
520 for (TEveCaloData::vCellId_i it = fM->fCellLists[bin]->begin();
521 it != fM->fCellLists[bin]->end(); ++it)
523 if ((*it).fSlice == slice)
531 assert(rec.GetN() > 3);
532 Bool_t is_upper = (rec.GetItem(3) == 1);
533 TEveCaloData::CellData_t cd;
534 fM->fData->GetCellData(*it, cd);
535 if ((is_upper && cd.IsUpperRho()) || (!is_upper && !cd.IsUpperRho()))
541 fM->fData->ProcessSelection(sel, rec);