Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
collection_proxies.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3///
4/// This is an example of visualization of containers
5/// with REveDataCollection and REveDataProxyBuilders.
6/// \macro_code
7///
8/// \author Alja Mrak-Tadel
9
12#include "ROOT/REveManager.hxx"
15#include <ROOT/REveGeoShape.hxx>
16#include <ROOT/REveJetCone.hxx>
17#include <ROOT/REvePointSet.hxx>
20#include <ROOT/REveScene.hxx>
23#include <ROOT/REveTrack.hxx>
25#include <ROOT/REveViewer.hxx>
27#include <ROOT/REveBoxSet.hxx>
29#include <ROOT/REveCalo.hxx>
30
31#include "TGeoTube.h"
32#include "TROOT.h"
33#include "TList.h"
34#include "TParticle.h"
35#include "TRandom.h"
36#include "TApplication.h"
37#include "TFile.h"
38#include "TH2F.h"
39#include <iostream>
40
41const Double_t kR_min = 299;
42const Double_t kR_max = 300;
43const Double_t kZ_d = 500;
44
45namespace fw3dlego {
46const int xbins_n = 83;
47const double xbins[xbins_n] = {
48 -5.191, -4.889, -4.716, -4.538, -4.363, -4.191, -4.013, -3.839, -3.664, -3.489, -3.314, -3.139, -2.964, -2.853,
49 -2.650, -2.500, -2.322, -2.172, -2.043, -1.930, -1.830, -1.740, -1.653, -1.566, -1.479, -1.392, -1.305, -1.218,
50 -1.131, -1.044, -0.957, -0.870, -0.783, -0.696, -0.609, -0.522, -0.435, -0.348, -0.261, -0.174, -0.087, 0.000,
51 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609, 0.696, 0.783, 0.870, 0.957, 1.044, 1.131, 1.218,
52 1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830, 1.930, 2.043, 2.172, 2.322, 2.500, 2.650, 2.853,
53 2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191};
54} // namespace fw3dlego
55
58using namespace ROOT::Experimental;
59
60//==============================================================================
61//============== EMULATE FRAMEWORK CLASSES =====================================
62//==============================================================================
63
64// a demo class, can be provided from experiment framework
65class Jet : public TParticle {
66public:
67 float fEtaSize{0};
68 float fPhiSize{0};
69
70 float GetEtaSize() const { return fEtaSize; }
71 float GetPhiSize() const { return fPhiSize; }
72 void SetEtaSize(float iEtaSize) { fEtaSize = iEtaSize; }
73 void SetPhiSize(float iPhiSize) { fPhiSize = iPhiSize; }
74
77 : TParticle(pdg, status, mother1, mother2, daughter1, daughter2, px, py, pz, etot, 0, 0, 0, 0)
78 {
79 }
80
81 ClassDef(Jet, 1);
82};
83
84class RecHit : public TObject {
85public:
86 float fX{0};
87 float fY{0};
88 float fZ{0};
89 float fPt{0};
90
91 RecHit(float pt, float x, float y, float z) : fPt(pt), fX(x), fY(y), fZ(z) {}
92 ClassDef(RecHit, 1);
93};
94
95class RCaloTower : public TObject {
96public:
97 float fEta{0};
98 float fPhi{0};
99 float fEt{0};
100
101 RCaloTower(float eta, float phi, float et) : fEta(eta), fPhi(phi), fEt(et) {}
103};
104
106private:
107 REveDataCollection *fCollection{nullptr};
108 REveCaloDataHist *fCaloData{nullptr};
109
110public:
112 : REveCaloDataSliceSelector(s), fCollection(c), fCaloData(h)
113 {
114 }
115
116 using REveCaloDataSliceSelector::ProcessSelection;
117 void ProcessSelection(REveCaloData::vCellId_t &sel_cells, UInt_t selectionId, Bool_t multi) override
118 {
119 std::set<int> item_set;
121 for (auto &cellId : sel_cells) {
122 fCaloData->GetCellData(cellId, cd);
123
124 // loop over enire collection and check its eta/phi range
125 for (int t = 0; t < fCollection->GetNItems(); ++t) {
126 RCaloTower *tower = (RCaloTower *)fCollection->GetDataPtr(t);
127 if (tower->fEta > cd.fEtaMin && tower->fEta < cd.fEtaMax && tower->fPhi > cd.fPhiMin &&
128 tower->fPhi < cd.fPhiMax && fCollection->GetDataItem(t)->GetVisible()) {
129 item_set.insert(t);
130 }
131 }
132 }
133 REveSelection *sel = (REveSelection *)eveMng->FindElementById(selectionId);
134 fCollection->GetItemList()->RefSelectedSet() = item_set;
135 sel->NewElementPicked(fCollection->GetItemList()->GetElementId(), multi, true, item_set);
136 }
137
138 using REveCaloDataSliceSelector::GetCellsFromSecondaryIndices;
139 void GetCellsFromSecondaryIndices(const std::set<int> &idcs, REveCaloData::vCellId_t &out) override
140 {
141 TH2F *hist = fCaloData->GetHist(GetSliceIndex());
142 std::set<int> cbins;
143 float total = 0;
144 for (auto &i : idcs) {
145 RCaloTower *tower = (RCaloTower *)fCollection->GetDataPtr(i);
146 int bin = hist->FindBin(tower->fEta, tower->fPhi);
147 float frac = tower->fEt / hist->GetBinContent(bin);
148 bool ex = false;
149 for (size_t ci = 0; ci < out.size(); ++ci) {
150 if (out[ci].fTower == bin && out[ci].fSlice == GetSliceIndex()) {
151 float oldv = out[ci].fFraction;
152 out[ci].fFraction = oldv + frac;
153 ex = true;
154 break;
155 }
156 }
157 if (!ex) {
158 out.push_back(REveCaloData::CellId_t(bin, GetSliceIndex(), frac));
159 }
160 }
161 }
162};
163
164class Event {
165public:
166 int eventId{0};
167 int N_tracks{0};
168 int N_jets{0};
169 std::vector<TList *> fListData;
170
171 REveCaloDataHist *fCaloData{nullptr};
172
173 Event()
174 {
175 auto baseHist = new TH2F("dummy", "dummy", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -TMath::Pi(), TMath::Pi());
177 fCaloData->AddHistogram(baseHist);
178
179 auto selector = new REveCaloDataSelector();
180 fCaloData->SetSelector(selector);
181
182 eveMng->GetEventScene()->AddElement(fCaloData);
183 }
184
185 void MakeJets(int N)
186 {
187 TRandom &r = *gRandom;
188 r.SetSeed(0);
189 TList *list = new TList();
190 list->SetName("Jets");
191 for (int i = 1; i <= N; ++i) {
192 double pt = r.Uniform(0.5, 10);
193 double eta = r.Uniform(-2.55, 2.55);
194 double phi = r.Uniform(-TMath::Pi(), TMath::Pi());
195
196 double px = pt * std::cos(phi);
197 double py = pt * std::sin(phi);
198 double pz = pt * (1. / (std::tan(2 * std::atan(std::exp(-eta)))));
199
200 auto jet = new Jet(0, 0, 0, 0, 0, 0, px, py, pz, std::sqrt(px * px + py * py + pz * pz + 80 * 80));
201 jet->SetEtaSize(r.Uniform(0.02, 0.2));
202 jet->SetPhiSize(r.Uniform(0.01, 0.3));
203 list->Add(jet);
204 }
205 fListData.push_back(list);
206 }
207
208 void MakeParticles(int N)
209 {
210 TRandom &r = *gRandom;
211 r.SetSeed(0);
212 TList *list = new TList();
213 list->SetName("Tracks");
214 for (int i = 1; i <= N; ++i) {
215 double pt = r.Uniform(0.5, 10);
216 double eta = r.Uniform(-2.55, 2.55);
217 double phi = r.Uniform(0, TMath::TwoPi());
218
219 double px = pt * std::cos(phi);
220 double py = pt * std::sin(phi);
221 double pz = pt * (1. / (std::tan(2 * std::atan(std::exp(-eta)))));
222
223 // printf("Event::MakeParticles %2d: pt=%.2f, eta=%.2f, phi=%.2f\n", i, pt, eta, phi);
224 auto particle =
225 new TParticle(0, 0, 0, 0, 0, 0, px, py, pz, std::sqrt(px * px + py * py + pz * pz + 80 * 80), 0, 0, 0, 0);
226
227 int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
228 particle->SetPdgCode(pdg);
229
230 list->Add(particle);
231 }
232 fListData.push_back(list);
233 }
234
235 void MakeRecHits(int N)
236 {
237 TRandom &r = *gRandom;
238 r.SetSeed(0);
239 TList *list = new TList();
240 list->SetName("RecHits");
241
242 for (int i = 1; i <= N; ++i) {
243 float pt = r.Uniform(0.5, 10);
244 float x = r.Uniform(-200, 200);
245 float y = r.Uniform(-200, 200);
246 float z = r.Uniform(-500, 500);
247 auto rechit = new RecHit(pt, x, y, z);
248 list->Add(rechit);
249 }
250 fListData.push_back(list);
251 }
252
253 void Clear()
254 {
255 for (auto &l : fListData)
256 delete l;
257 fListData.clear();
258 }
259
260 void Create()
261 {
262 Clear();
263 MakeJets(4);
264 MakeParticles(100);
265 MakeRecHits(20);
266
267 // refill calo data from jet list
268 TList *jlist = fListData[0];
269 TList *elist = new TList();
270 elist->SetName("ECAL");
271 fListData.push_back(elist);
272 TList *hlist = new TList();
273 hlist->SetName("HCAL");
274 fListData.push_back(hlist);
275 for (int i = 0; i <= jlist->GetLast(); ++i) {
276 const Jet *j = (Jet *)jlist->At(i);
277 float offX = j->Eta();
278 float offY = j->Phi() > TMath::Pi() ? j->Phi() - TMath::TwoPi() : j->Phi();
279 for (int k = 0; k < 20; ++k) {
280 double x, y, v;
281 x = gRandom->Uniform(-j->GetEtaSize(), j->GetEtaSize());
282 y = gRandom->Uniform(-j->GetPhiSize(), j->GetPhiSize());
283 v = j->Pt();
284 auto etower = new RCaloTower(offX + x, offY + y, v + gRandom->Uniform(2, 3));
285 elist->Add(etower);
286 auto htower = new RCaloTower(offX + x, offY + y, v + gRandom->Uniform(1, 2));
287 hlist->Add(htower);
288 }
289 }
290 fCaloData->DataChanged();
291 eventId++;
292 }
293};
294
295//==============================================================================
296//== PROXY BUILDERS ============================================================
297//==============================================================================
298
300 bool HaveSingleProduct() const override { return false; }
301
302 using REveDataSimpleProxyBuilderTemplate<Jet>::BuildItemViewType;
303 void BuildItemViewType(const Jet &dj, int idx, REveElement *iItemHolder, const std::string &viewType,
304 const REveViewContext *context) override
305 {
306 auto jet = new REveJetCone();
307 jet->SetCylinder(context->GetMaxR(), context->GetMaxZ());
308 jet->AddEllipticCone(dj.Eta(), dj.Phi(), dj.GetEtaSize(), dj.GetPhiSize());
309 SetupAddElement(jet, iItemHolder, true);
310 jet->SetLineColor(jet->GetMainColor());
311
312 float size = 50.f * dj.Pt(); // values are saved in scale
313 double theta = dj.Theta();
314 // printf("%s jet theta = %f, phi = %f \n", iItemHolder->GetCName(), theta, dj.Phi());
315 double phi = dj.Phi();
316
317 if (viewType == "Projected") {
318 static const float_t offr = 6;
319 float r_ecal = context->GetMaxR() + offr;
320 float z_ecal = context->GetMaxZ() + offr;
321
322 float transAngle = abs(atan(r_ecal / z_ecal));
323 double r = 0;
324 bool debug = false;
325 if (theta < transAngle || 3.14 - theta < transAngle) {
326 z_ecal = context->GetMaxZ() + offr / transAngle;
327 r = z_ecal / fabs(cos(theta));
328 } else {
329 debug = true;
330 r = r_ecal / sin(theta);
331 }
332
333 REveVector p1(0, (phi < TMath::Pi() ? r * fabs(sin(theta)) : -r * fabs(sin(theta))), r * cos(theta));
334 REveVector p2(0, (phi < TMath::Pi() ? (r + size) * fabs(sin(theta)) : -(r + size) * fabs(sin(theta))),
335 (r + size) * cos(theta));
336
337 auto marker = new REveScalableStraightLineSet("jetline");
338 marker->SetScaleCenter(p1.fX, p1.fY, p1.fZ);
339 marker->AddLine(p1, p2);
340 marker->SetLineWidth(4);
341 if (debug)
342 marker->AddMarker(0, 0.9);
343
344 SetupAddElement(marker, iItemHolder, true);
345 marker->SetName(Form("line %s %d", Collection()->GetCName(), idx));
346 }
347 }
348
349 using REveDataProxyBuilderBase::LocalModelChanges;
350
351 void LocalModelChanges(int idx, REveElement *el, const REveViewContext *ctx) override
352 {
353 // printf("LocalModelChanges jet %s ( %s )\n", el->GetCName(), el->FirstChild()->GetCName());
354 REveJetCone *cone = dynamic_cast<REveJetCone *>(el->FirstChild());
355 cone->SetLineColor(cone->GetMainColor());
356 }
357};
358
361
362 void BuildItem(const TParticle &p, int idx, REveElement *iItemHolder, const REveViewContext *context) override
363 {
364 const TParticle *x = &p;
365 auto track = new REveTrack((TParticle *)(x), 1, context->GetPropagator());
366 track->MakeTrack();
367 SetupAddElement(track, iItemHolder, true);
368 }
369};
370
372private:
373 class FWBoxSet : public REveBoxSet {
374 public:
375 using REveElement::GetSelectionMaster;
376 REveElement *GetSelectionMaster() override
377 {
378 if (fSelectionMaster) {
379 REveDataItemList *il = dynamic_cast<REveDataItemList *>(fSelectionMaster);
380 il->RefSelectedSet() = RefSelectedSet();
381 return il;
382 }
383 return nullptr;
384 }
385 };
386
387 REveBoxSet *fBoxSet{nullptr};
389 {
390 auto collection = Collection();
391 boxset->SetMainColor(collection->GetMainColor());
392 boxset->SetName(collection->GetCName());
393 boxset->SetPickable(true);
394 boxset->SetAlwaysSecSelect(true);
395 boxset->SetDetIdsAsSecondaryIndices(true);
396 boxset->SetSelectionMaster(((REveDataCollection *)collection)->GetItemList());
397 boxset->Reset(REveBoxSet::kBT_FreeBox, true, collection->GetNItems());
398 TRandom r(0);
399
400#define RND_BOX(x) (Float_t) r.Uniform(-(x), (x))
401 for (int h = 0; h < collection->GetNItems(); ++h) {
402 RecHit *hit = (RecHit *)collection->GetDataPtr(h);
403 const REveDataItem *item = Collection()->GetDataItem(h);
404
405 Float_t x = hit->fX;
406 Float_t y = hit->fY;
407 Float_t z = hit->fZ;
408 Float_t a = hit->fPt;
409 Float_t d = 0.05;
410 Float_t verts[24] = {x - a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d), x - a + RND_BOX(d),
411 y + a + RND_BOX(d), z - a + RND_BOX(d), x + a + RND_BOX(d), y + a + RND_BOX(d),
412 z - a + RND_BOX(d), x + a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d),
413 x - a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d), x - a + RND_BOX(d),
414 y + a + RND_BOX(d), z + a + RND_BOX(d), x + a + RND_BOX(d), y + a + RND_BOX(d),
415 z + a + RND_BOX(d), x + a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d)};
416 boxset->AddBox(verts);
417
418 boxset->DigitValue(item->GetVisible() ? 1 : 0);
419 if (item->GetVisible())
420 boxset->DigitColor(item->GetMainColor());
421 }
422 boxset->RefitPlex();
423 boxset->StampObjProps();
424 }
425
426public:
427 using REveDataProxyBuilderBase::Build;
428 void BuildProduct(const REveDataCollection *collection, REveElement *product, const REveViewContext *) override
429 {
430 fBoxSet = new FWBoxSet();
432 product->AddElement(fBoxSet);
433 }
434
435 using REveDataProxyBuilderBase::FillImpliedSelected;
436 void FillImpliedSelected(REveElement::Set_t &impSet, const std::set<int> &sec_idcs, Product *p) override
437 {
438 // printf("RecHit fill implioed ----------------- !!!%zu\n",
439 // Collection()->GetItemList()->RefSelectedSet().size());
440 impSet.insert(fBoxSet);
441 }
442
443 using REveDataProxyBuilderBase::ModelChanges;
444 void ModelChanges(const REveDataCollection::Ids_t &ids, Product *product) override
445 {
446 for (auto &i : ids) {
447 auto digi = fBoxSet->GetDigit(i);
448 auto item = Collection()->GetDataItem(i);
449 fBoxSet->SetCurrentDigit(i);
450 if (item->GetVisible()) {
451 fBoxSet->DigitValue(1);
452 fBoxSet->DigitColor(item->GetMainColor());
453 } else {
454 fBoxSet->DigitValue(0);
455 }
456 }
457 fBoxSet->StampObjProps();
458 }
459}; // RecHitProxyBuilder
460
462private:
463 REveCaloDataHist *fCaloData{nullptr};
464 TH2F *fHist{nullptr};
465 int fSliceIndex{-1};
466
467 void assertSlice()
468 {
469 if (!fHist) {
471
472 TDirectory::TContext ctx{nullptr}; // Don't register histograms to the current directory
473 fHist = new TH2F("caloHist", "caloHist", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -M_PI, M_PI);
474 fSliceIndex = fCaloData->AddHistogram(fHist);
475
476 fCaloData->RefSliceInfo(fSliceIndex)
477 .Setup(Collection()->GetCName(), 0., Collection()->GetMainColor(), Collection()->GetMainTransparency());
478
479 fCaloData->GetSelector()->AddSliceSelector(std::unique_ptr<REveCaloDataSliceSelector>(
481 }
482 }
483
484public:
486
487 using REveDataProxyBuilderBase::Build;
488 void BuildProduct(const REveDataCollection *collection, REveElement *product, const REveViewContext *) override
489 {
490 assertSlice();
491 fHist->Reset();
492 if (collection->GetRnrSelf()) {
493 fCaloData->RefSliceInfo(fSliceIndex)
494 .Setup(Collection()->GetCName(), 0., Collection()->GetMainColor(), Collection()->GetMainTransparency());
495
496 for (int h = 0; h < collection->GetNItems(); ++h) {
497 RCaloTower *tower = (RCaloTower *)collection->GetDataPtr(h);
498 const REveDataItem *item = Collection()->GetDataItem(h);
499
500 if (!item->GetVisible())
501 continue;
502 fHist->Fill(tower->fEta, tower->fPhi, tower->fEt);
503 }
504 }
505 fCaloData->DataChanged();
506 }
507
508 using REveDataProxyBuilderBase::FillImpliedSelected;
509 void FillImpliedSelected(REveElement::Set_t &impSet, const std::set<int> &sec_idcs, Product *) override
510 {
511 fCaloData->GetSelector()->SetActiveSlice(fSliceIndex);
512 impSet.insert(fCaloData);
513 fCaloData->FillImpliedSelectedSet(impSet, sec_idcs);
514 }
515
516 using REveDataProxyBuilderBase::ModelChanges;
517 void ModelChanges(const REveDataCollection::Ids_t &ids, Product *product) override
518 {
519 BuildProduct(Collection(), nullptr, nullptr);
520 }
521
522}; // CaloTowerProxyBuilder
523
524//==============================================================================
525//== COLLECTION MANGER ================================================================
526//==============================================================================
527
528class CollectionManager {
529private:
530 Event *fEvent{nullptr};
531
532 std::vector<REveScene *> m_scenes;
533 REveViewContext *m_viewContext{nullptr};
534
535 std::vector<REveDataProxyBuilderBase *> m_builders;
536
537 REveScene *m_collections{nullptr};
538 bool m_inEventLoading{false};
539
540public:
541 CollectionManager(Event *event) : fEvent(event)
542 {
543 // view context
544 float r = 300;
545 float z = 300;
546 auto prop = new REveTrackPropagator();
547 prop->SetMagFieldObj(new REveMagFieldDuo(350, 3.5, -2.0));
548 prop->SetMaxR(r);
549 prop->SetMaxZ(z);
550 prop->SetMaxOrbs(6);
551 prop->IncRefCount();
552
553 m_viewContext = new REveViewContext();
554 m_viewContext->SetBarrel(r, z);
555 m_viewContext->SetTrackPropagator(prop);
556
557 // table specs
558 auto tableInfo = new REveTableViewInfo();
559
560 tableInfo->table("TParticle").column("pt", 1, "i.Pt()").column("eta", 3, "i.Eta()").column("phi", 3, "i.Phi()");
561
562 tableInfo->table("Jet")
563 .column("eta", 1, "i.Eta()")
564 .column("phi", 1, "i.Phi()")
565 .column("etasize", 2, "i.GetEtaSize()")
566 .column("phisize", 2, "i.GetPhiSize()");
567
568 tableInfo->table("RecHit").column("pt", 1, "i.fPt");
569
570 tableInfo->table("RCaloTower").column("eta", 3, "i.fEta").column("phi", 3, "i.fPhi").column("Et", 3, "i.fEt");
571
572 m_viewContext->SetTableViewInfo(tableInfo);
573
574 for (auto &c : eveMng->GetScenes()->RefChildren()) {
575 if (c != eveMng->GetGlobalScene() && strncmp(c->GetCName(), "Geometry", 8)) {
576 m_scenes.push_back((REveScene *)c);
577 }
578 if (!strncmp(c->GetCName(), "Table", 5))
579 c->AddElement(m_viewContext->GetTableViewInfo());
580 }
581
582 m_collections = eveMng->SpawnNewScene("Collections", "Collections");
583 }
584
586 {
587 for (auto &l : fEvent->fListData) {
588 TIter next(l);
589 if (collection->GetName() == std::string(l->GetName())) {
590 collection->ClearItems();
591
592 for (int i = 0; i <= l->GetLast(); ++i) {
593 std::string cname = collection->GetName();
594 auto len = cname.size();
595 char end = cname[len - 1];
596 if (end == 's') {
597 cname = cname.substr(0, len - 1);
598 }
599 TString pname(Form("%s %2d", cname.c_str(), i));
600 collection->AddItem(l->At(i), pname.Data(), "");
601 }
602 }
603 collection->ApplyFilter();
604 }
605 }
606
607 void LoadEvent()
608 {
609 m_inEventLoading = true;
610
611 for (auto &el : m_collections->RefChildren()) {
612 auto c = dynamic_cast<REveDataCollection *>(el);
614 }
615
616 for (auto proxy : m_builders) {
617 proxy->Build();
618 }
619
620 fEvent->fCaloData->DataChanged();
621 m_inEventLoading = false;
622 }
623
625 {
626 m_collections->AddElement(collection);
627
628 // load data
630 glBuilder->SetCollection(collection);
631 glBuilder->SetHaveAWindow(true);
632 for (auto scene : m_scenes) {
633 if (strncmp(scene->GetCName(), "Tables", 5) == 0)
634 continue;
635
636 REveElement *product = glBuilder->CreateProduct(scene->GetTitle(), m_viewContext);
637
638 if (!strncmp(scene->GetCTitle(), "Projected", 8)) {
639 g_projMng->ImportElements(product, scene);
640 } else {
641 scene->AddElement(product);
642 }
643 }
644 m_builders.push_back(glBuilder);
645 glBuilder->Build();
646
647 // Tables
649 tableBuilder->SetHaveAWindow(true);
650 tableBuilder->SetCollection(collection);
651 REveElement *tablep = tableBuilder->CreateProduct("table-type", m_viewContext);
652 auto tableMng = m_viewContext->GetTableViewInfo();
653 if (showInTable) {
654 tableMng->SetDisplayedCollection(collection->GetElementId());
655 }
656
657 for (auto s : m_scenes) {
658 if (strncmp(s->GetCTitle(), "Table", 5) == 0) {
659 s->AddElement(tablep);
660 tableBuilder->Build();
661 }
662 }
663 tableMng->AddDelegate([=]() { tableBuilder->ConfigChanged(); });
664 m_builders.push_back(tableBuilder);
665
666 // set tooltip expression for items
667 auto tableEntries = tableMng->RefTableEntries(collection->GetItemClass()->GetName());
668 int N = TMath::Min(int(tableEntries.size()), 3);
669 for (int t = 0; t < N; t++) {
670 auto te = tableEntries[t];
671 collection->GetItemList()->AddTooltipExpression(te.fName, te.fExpression);
672 }
673
674 collection->GetItemList()->SetItemsChangeDelegate(
676 this->ModelChanged(collection, ids);
677 });
678 collection->GetItemList()->SetFillImpliedSelectedDelegate(
679 [&](REveDataItemList *collection, REveElement::Set_t &impSelSet, const std::set<int> &sec_idcs) {
680 this->FillImpliedSelected(collection, impSelSet, sec_idcs);
681 });
682 }
683
684 void finishViewCreate()
685 {
686 auto mngTable = m_viewContext->GetTableViewInfo();
687 if (mngTable) {
688 for (auto &el : m_collections->RefChildren()) {
689 if (el->GetName() == "Tracks")
690 mngTable->SetDisplayedCollection(el->GetElementId());
691 }
692 }
693 }
694
696 {
698 return;
699
700 for (auto proxy : m_builders) {
701 if (proxy->Collection()->GetItemList() == itemList) {
702 // printf("Model changes check proxy %s: \n", proxy->Type().c_str());
703 proxy->ModelChanges(ids);
704 }
705 }
706 }
707
708 void FillImpliedSelected(REveDataItemList *itemList, REveElement::Set_t &impSelSet, const std::set<int> &sec_idcs)
709 {
711 return;
712
713 for (auto proxy : m_builders) {
714 if (proxy->Collection()->GetItemList() == itemList) {
715 proxy->FillImpliedSelected(impSelSet, sec_idcs);
716 }
717 }
718 }
719};
720
721//==============================================================================
722//== Event Manager =============================================================
723//==============================================================================
724
725class EventManager : public REveElement {
726private:
727 Event *fEvent;
729
730public:
731 EventManager(Event *e, CollectionManager *m) : fEvent(e), fCMng(m) {}
732
733 ~EventManager() override {}
734
735 virtual void NextEvent()
736 {
737 eveMng->GetSelection()->ClearSelection();
738 eveMng->GetHighlight()->ClearSelection();
739 fEvent->Create();
740 fCMng->LoadEvent();
741 }
742};
743
745public:
747
748 using REveSelection::Deviator::DeviateSelection;
749 bool DeviateSelection(REveSelection *selection, REveElement *el, bool multi, bool secondary,
750 const std::set<int> &secondary_idcs) override
751 {
752 if (el) {
753 auto *colItems = dynamic_cast<REveDataItemList *>(el);
754 if (colItems) {
755 // std::cout << "Deviate RefSelected=" << colItems->RefSelectedSet().size() << " passed set " <<
756 // secondary_idcs.size() << "\n";
757 ExecuteNewElementPicked(selection, colItems, multi, true, colItems->RefSelectedSet());
758 return true;
759 }
760 }
761 return false;
762 }
763};
764//==============================================================================
765//== main() ====================================================================
766//==============================================================================
767
768void collection_proxies(bool proj = true)
769{
770 eveMng = REveManager::Create();
771 auto event = new Event();
772 event->Create();
773
774 // divert selection to map proxy builder products with collection
775 auto deviator = std::make_shared<FWSelectionDeviator>();
776 eveMng->GetSelection()->SetDeviator(deviator);
777 eveMng->GetHighlight()->SetDeviator(deviator);
778
779 // create scenes and views
780 REveScene *rhoZEventScene = nullptr;
781
782 auto b1 = new REveGeoShape("Barrel 1");
783 b1->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
784 b1->SetMainColor(kCyan);
785 b1->SetMainTransparency(90);
786 eveMng->GetGlobalScene()->AddElement(b1);
787
788 rhoZEventScene = eveMng->SpawnNewScene("RhoZ Scene", "Projected");
789 g_projMng = new REveProjectionManager(REveProjection::kPT_RhoZ);
790 g_projMng->SetImportEmpty(true);
791
792 auto rhoZView = eveMng->SpawnNewViewer("RhoZ View");
793 rhoZView->SetCameraType(REveViewer::kCameraOrthoXOY);
794 rhoZView->AddScene(rhoZEventScene);
795 auto pgeoScene = eveMng->SpawnNewScene("Geometry projected");
796 rhoZView->AddScene(pgeoScene);
797 g_projMng->ImportElements(b1, pgeoScene);
798
799 auto tableScene = eveMng->SpawnNewScene("Tables", "Tables");
800 auto tableView = eveMng->SpawnNewViewer("Table", "Table View");
801 tableView->AddScene(tableScene);
802
803 // create event data from list
804 auto collectionMng = new CollectionManager(event);
805
807 trackCollection->SetItemClass(TParticle::Class());
808 trackCollection->SetMainColor(kGreen);
809 trackCollection->SetFilterExpr("i.Pt() > 4.1 && std::abs(i.Eta()) < 1");
810 collectionMng->addCollection(trackCollection, new TParticleProxyBuilder(), true);
811
813 jetCollection->SetItemClass(Jet::Class());
814 jetCollection->SetMainColor(kYellow);
815 jetCollection->SetFilterExpr("i.Pt() > 1");
816 collectionMng->addCollection(jetCollection, new JetProxyBuilder());
817
819 hitCollection->SetItemClass(RecHit::Class());
820 hitCollection->SetMainColor(kOrange + 7);
821 hitCollection->SetFilterExpr("i.fPt > 5");
822 collectionMng->addCollection(hitCollection, new RecHitProxyBuilder(), true);
823
824 // add calorimeters
825 auto calo3d = new REveCalo3D(event->fCaloData);
826 calo3d->SetBarrelRadius(kR_max);
827 calo3d->SetEndCapPos(kZ_d);
828 calo3d->SetMaxTowerH(300);
829 eveMng->GetEventScene()->AddElement(calo3d);
831
833 ecalCollection->SetItemClass(RCaloTower::Class());
834 ecalCollection->SetMainColor(kRed);
835 collectionMng->addCollection(ecalCollection, new CaloTowerProxyBuilder(event->fCaloData));
836
838 hcalCollection->SetItemClass(RCaloTower::Class());
839 hcalCollection->SetMainColor(kBlue);
840 collectionMng->addCollection(hcalCollection, new CaloTowerProxyBuilder(event->fCaloData));
841
842 // event navigation
843 auto eventMng = new EventManager(event, collectionMng);
844 eventMng->SetName("EventManager");
845 eveMng->GetWorld()->AddElement(eventMng);
846
847 eveMng->GetWorld()->AddCommand("NextEvent", "sap-icon://step", eventMng, "NextEvent()");
848
849 eveMng->Show();
850}
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define M_PI
Definition Rotated.cxx:105
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
#define ClassDef(name, id)
Definition Rtypes.h:344
@ kRed
Definition Rtypes.h:67
@ kOrange
Definition Rtypes.h:68
@ kGreen
Definition Rtypes.h:67
@ kCyan
Definition Rtypes.h:67
@ kBlue
Definition Rtypes.h:67
@ kYellow
Definition Rtypes.h:67
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define N
static unsigned int total
winID h TVirtualViewer3D TVirtualGLPainter p
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 r
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 prop
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 cname
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 Atom_t Atom_t Time_t UChar_t len
R__EXTERN TRandom * gRandom
Definition TRandom.h:73
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2570
Definition JetEvent.h:49
Jet()
Definition JetEvent.h:57
Collection of 3D primitives (fixed-size boxes, boxes of different sizes, or arbitrary sexto-epipeds,...
Visualization of a calorimeter event data in 2D.
Visualization of a calorimeter event data in 3D.
A central manager for calorimeter data of an event written in TH2F.
Cell data inner structure.
Base class for REveUtil visualization elements, providing hierarchy management, rendering control and...
Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TG...
Draws a jet cone with leading particle is specified in (eta,phi) and cone radius is given.
Implements constant magnetic filed that switches on given axial radius fR2 from vector fBIn to fBOut.
Manager class for steering of projections and managing projected objects.
Straight-line-set with extra scaling, useful for projectables that need to be scaled in accordance wi...
Eve representation of TGLScene.
Make sure there is a SINGLE running REveSelection for each selection type (select/highlight).
Holding structure for a number of track rendering parameters.
Visual representation of a track.
std::vector< CellId_t > vCellId_t
std::set< REveElement * > Set_t
REveProjectionManager Manager class for steering of projections and managing projected objects.
REveTrackPropagator * GetPropagator() const
void SetName(const char *name)
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
Cylindrical tube class.
Definition TGeoTube.h:17
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
Definition TH1.cxx:3823
static Bool_t AddDirectoryStatus()
Check whether TH1-derived classes should register themselves to the current gDirectory.
Definition TH1.cxx:772
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
Double_t GetBinContent(Int_t binx, Int_t biny) const override
Definition TH2.h:97
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
Mother of all ROOT objects.
Definition TObject.h:42
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:461
static TClass * Class()
Description of the dynamic properties of a particle.
Definition TParticle.h:26
static TClass * Class()
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition TRandom.cxx:681
Basic string class.
Definition TString.h:138
TPaveText * pt
RVec< PromoteType< T > > abs(const RVec< T > &v)
Definition RVec.hxx:1812
RVec< PromoteType< T > > cos(const RVec< T > &v)
Definition RVec.hxx:1832
RVec< PromoteType< T > > atan(const RVec< T > &v)
Definition RVec.hxx:1836
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition RVec.hxx:1831
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t ex[n]
Definition legend1.C:17
Namespace for ROOT features in testing.
Definition TROOT.h:100
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
double product(DoubleArray factors, std::size_t nFactors)
Definition MathFuncs.h:96
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
constexpr Double_t Pi()
Definition TMath.h:40
constexpr Double_t TwoPi()
Definition TMath.h:47
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4