Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
collection_proxies.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
3///
4/// This is an example of visualization of containers
5/// with REveDataCollection and REveDataProxyBuilders.
6/// \macro_code
7///
8
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
41
42const Double_t kR_min = 299;
43const Double_t kR_max = 300;
44const Double_t kZ_d = 500;
45
46
47namespace fw3dlego {
48 const int xbins_n = 83;
49 const double xbins[xbins_n] = {
50 -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,
51 -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,
52 -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,
53 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,
54 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,
55 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};
56} // namespace fw3dlego
57
58
61using namespace ROOT::Experimental;
62
63//==============================================================================
64//============== EMULATE FRAMEWORK CLASSES =====================================
65//==============================================================================
66
67
68// a demo class, can be provided from experiment framework
69class Jet : public TParticle
70{
71public:
72 float fEtaSize{0};
73 float fPhiSize{0};
74
75 float GetEtaSize() const { return fEtaSize; }
76 float GetPhiSize() const { return fPhiSize; }
77 void SetEtaSize(float iEtaSize) { fEtaSize = iEtaSize; }
78 void SetPhiSize(float iPhiSize) { fPhiSize = iPhiSize; }
79
80 Jet(Int_t pdg, Int_t status, Int_t mother1, Int_t mother2, Int_t daughter1, Int_t daughter2,
81 Double_t px, Double_t py, Double_t pz, Double_t etot) :
82 TParticle(pdg, status, mother1, mother2, daughter1, daughter2, px, py, pz, etot, 0, 0, 0, 0)
83 {}
84
86};
87
88class RecHit : public TObject
89{
90public:
91 float fX{0};
92 float fY{0};
93 float fZ{0};
94 float fPt{0};
95
96 RecHit(float pt, float x, float y, float z): fPt(pt), fX(x), fY(y), fZ(z) {}
98};
99
100class RCaloTower : public TObject
101{
102public:
103 float fEta{0};
104 float fPhi{0};
105 float fEt{0};
106
107 RCaloTower(float eta, float phi, float et): fEta(eta), fPhi(phi), fEt(et) {}
109};
110
112{
113private:
116
117public:
119
121 void ProcessSelection(REveCaloData::vCellId_t& sel_cells, UInt_t selectionId, Bool_t multi) override
122 {
123 std::set<int> item_set;
125 for (auto &cellId : sel_cells)
126 {
127 fCaloData->GetCellData(cellId, cd);
128
129 // loop over enire collection and check its eta/phi range
130 for (int t = 0; t < fCollection->GetNItems(); ++t)
131 {
133 if (tower->fEta > cd.fEtaMin && tower->fEta < cd.fEtaMax &&
134 tower->fPhi > cd.fPhiMin && tower->fPhi < cd.fPhiMax &&
136 {
137 item_set.insert(t);
138 }
139 }
140 }
142 fCollection->GetItemList()->RefSelectedSet() = item_set;
143 sel->NewElementPicked(fCollection->GetItemList()->GetElementId(), multi, true, item_set);
144 }
145
147 void GetCellsFromSecondaryIndices(const std::set<int>& idcs, REveCaloData::vCellId_t& out) override
148 {
150 std::set<int> cbins;
151 float total = 0;
152 for( auto &i : idcs ) {
154 int bin = hist->FindBin(tower->fEta, tower->fPhi);
155 float frac = tower->fEt/hist->GetBinContent(bin);
156 bool ex = false;
157 for (size_t ci = 0; ci < out.size(); ++ci)
158 {
159 if (out[ci].fTower == bin && out[ci].fSlice == GetSliceIndex())
160 {
161 float oldv = out[ci].fFraction;
162 out[ci].fFraction = oldv + frac;
163 ex = true;
164 break;
165 }
166 }
167 if (!ex) {
168 out.push_back(REveCaloData::CellId_t(bin, GetSliceIndex(), frac));
169 }
170 }
171 }
172};
173
174class Event
175{
176public:
177 int eventId{0};
178 int N_tracks{0};
179 int N_jets{0};
180 std::vector<TList*> fListData;
181
183
185 {
186 auto baseHist = new TH2F("dummy", "dummy", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -TMath::Pi(), TMath::Pi());
188 fCaloData->AddHistogram(baseHist);
189
190 auto selector = new REveCaloDataSelector();
191 fCaloData->SetSelector(selector);
192
194 }
195
196 void MakeJets(int N)
197 {
198 TRandom &r = *gRandom;
199 r.SetSeed(0);
200 TList* list = new TList();
201 list->SetName("Jets");
202 for (int i = 1; i <= N; ++i)
203 {
204 double pt = r.Uniform(0.5, 10);
205 double eta = r.Uniform(-2.55, 2.55);
206 double phi = r.Uniform(-TMath::Pi(), TMath::Pi());
207
208 double px = pt * std::cos(phi);
209 double py = pt * std::sin(phi);
210 double pz = pt * (1. / (std::tan(2*std::atan(std::exp(-eta)))));
211
212 auto jet = new Jet(0, 0, 0, 0, 0, 0, px, py, pz, std::sqrt(px*px + py*py + pz*pz + 80*80));
213 jet->SetEtaSize(r.Uniform(0.02, 0.2));
214 jet->SetPhiSize(r.Uniform(0.01, 0.3));
215 list->Add(jet);
216 }
217 fListData.push_back(list);
218 }
219
220 void MakeParticles(int N)
221 {
222 TRandom &r = *gRandom;
223 r.SetSeed(0);
224 TList* list = new TList();
225 list->SetName("Tracks");
226 for (int i = 1; i <= N; ++i)
227 {
228 double pt = r.Uniform(0.5, 10);
229 double eta = r.Uniform(-2.55, 2.55);
230 double phi = r.Uniform(0, TMath::TwoPi());
231
232 double px = pt * std::cos(phi);
233 double py = pt * std::sin(phi);
234 double pz = pt * (1. / (std::tan(2*std::atan(std::exp(-eta)))));
235
236 // printf("Event::MakeParticles %2d: pt=%.2f, eta=%.2f, phi=%.2f\n", i, pt, eta, phi);
237 auto particle = new TParticle(0, 0, 0, 0, 0, 0,
238 px, py, pz, std::sqrt(px*px + py*py + pz*pz + 80*80),
239 0, 0, 0, 0 );
240
241 int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
242 particle->SetPdgCode(pdg);
243
244 list->Add(particle);
245 }
246 fListData.push_back(list);
247 }
248
249 void MakeRecHits(int N)
250 {
251 TRandom &r = *gRandom;
252 r.SetSeed(0);
253 TList* list = new TList();
254 list->SetName("RecHits");
255
256 for (int i = 1; i <= N; ++i)
257 {
258 float pt = r.Uniform(0.5, 10);
259 float x = r.Uniform(-200, 200);
260 float y = r.Uniform(-200, 200);
261 float z = r.Uniform(-500, 500);
262 auto rechit = new RecHit(pt, x, y, z);
263 list->Add(rechit);
264 }
265 fListData.push_back(list);
266 }
267
268 void Clear()
269 {
270 for (auto &l : fListData)
271 delete l;
272 fListData.clear();
273 }
274
275 void Create()
276 {
277 Clear();
278 MakeJets(4);
279 MakeParticles(100);
280 MakeRecHits(20);
281
282 // refill calo data from jet list
283 TList* jlist = fListData[0];
284 TList* elist = new TList();
285 elist->SetName("ECAL");
286 fListData.push_back(elist);
287 TList* hlist = new TList();
288 hlist->SetName("HCAL");
289 fListData.push_back(hlist);
290 for (int i = 0; i <= jlist->GetLast(); ++i) {
291 const Jet* j = (Jet*)jlist->At(i);
292 float offX = j->Eta();
293 float offY = j->Phi() > TMath::Pi() ? j->Phi() - TMath::TwoPi() : j->Phi();
294 for (int k=0; k<20; ++k) {
295 double x, y, v;
296 x = gRandom->Uniform(-j->GetEtaSize(), j->GetEtaSize());
297 y = gRandom->Uniform(-j->GetPhiSize(),j->GetPhiSize());
298 v = j->Pt();
299 auto etower = new RCaloTower(offX + x, offY + y, v + gRandom->Uniform(2,3));
300 elist->Add(etower);
301 auto htower = new RCaloTower(offX + x, offY + y, v + gRandom->Uniform(1,2));
302 hlist->Add(htower);
303 }
304 }
306 eventId++;
307 }
308};
309
310
311//==============================================================================
312//== PROXY BUILDERS ============================================================
313//==============================================================================
314
316{
317 bool HaveSingleProduct() const override { return false; }
318
320 void BuildItemViewType(const Jet& dj, int idx, REveElement* iItemHolder,
321 const std::string& viewType, const REveViewContext* context) override
322 {
323 auto jet = new REveJetCone();
324 jet->SetCylinder(context->GetMaxR(), context->GetMaxZ());
325 jet->AddEllipticCone(dj.Eta(), dj.Phi(), dj.GetEtaSize(), dj.GetPhiSize());
326 SetupAddElement(jet, iItemHolder, true);
327 jet->SetLineColor(jet->GetMainColor());
328
329 float size = 50.f * dj.Pt(); // values are saved in scale
330 double theta = dj.Theta();
331 // printf("%s jet theta = %f, phi = %f \n", iItemHolder->GetCName(), theta, dj.Phi());
332 double phi = dj.Phi();
333
334
335 if (viewType == "Projected" )
336 {
337 static const float_t offr = 6;
338 float r_ecal = context->GetMaxR() + offr;
339 float z_ecal = context->GetMaxZ() + offr;
340
341 float transAngle = abs(atan(r_ecal/z_ecal));
342 double r = 0;
343 bool debug = false;
344 if (theta < transAngle || 3.14-theta < transAngle)
345 {
346 z_ecal = context->GetMaxZ() + offr/transAngle;
347 r = z_ecal/fabs(cos(theta));
348 }
349 else
350 {
351 debug = true;
352 r = r_ecal/sin(theta);
353 }
354
355 REveVector p1(0, (phi<TMath::Pi() ? r*fabs(sin(theta)) : -r*fabs(sin(theta))), r*cos(theta));
356 REveVector p2(0, (phi<TMath::Pi() ? (r+size)*fabs(sin(theta)) : -(r+size)*fabs(sin(theta))), (r+size)*cos(theta));
357
358 auto marker = new REveScalableStraightLineSet("jetline");
359 marker->SetScaleCenter(p1.fX, p1.fY, p1.fZ);
360 marker->AddLine(p1, p2);
361 marker->SetLineWidth(4);
362 if (debug)
363 marker->AddMarker(0, 0.9);
364
365 SetupAddElement(marker, iItemHolder, true);
366 marker->SetName(Form("line %s %d", Collection()->GetCName(), idx));
367 }
368 }
369
370
372
373 void LocalModelChanges(int idx, REveElement* el, const REveViewContext* ctx) override
374 {
375 // printf("LocalModelChanges jet %s ( %s )\n", el->GetCName(), el->FirstChild()->GetCName());
376 REveJetCone* cone = dynamic_cast<REveJetCone*>(el->FirstChild());
377 cone->SetLineColor(cone->GetMainColor());
378 }
379};
380
381
383{
385
386 void BuildItem(const TParticle& p, int idx, REveElement* iItemHolder, const REveViewContext* context) override
387 {
388 const TParticle *x = &p;
389 auto track = new REveTrack((TParticle*)(x), 1, context->GetPropagator());
390 track->MakeTrack();
391 SetupAddElement(track, iItemHolder, true);
392 }
393};
394
395
397private:
398 class FWBoxSet : public REveBoxSet {
399 public:
400 using REveElement::GetSelectionMaster;
402 {
403 if (fSelectionMaster) {
406 return il;
407 }
408 return nullptr;
409 }
410 };
411
414 {
415 auto collection = Collection();
416 boxset->SetMainColor(collection->GetMainColor());
417 boxset->SetName(collection->GetCName());
418 boxset->SetPickable(true);
419 boxset->SetAlwaysSecSelect(true);
420 boxset->SetDetIdsAsSecondaryIndices(true);
421 boxset->SetSelectionMaster(((REveDataCollection *)collection)->GetItemList());
422 boxset->Reset(REveBoxSet::kBT_FreeBox, true, collection->GetNItems());
423 TRandom r(0);
424
425#define RND_BOX(x) (Float_t) r.Uniform(-(x), (x))
426 for (int h = 0; h < collection->GetNItems(); ++h) {
427 RecHit *hit = (RecHit *)collection->GetDataPtr(h);
428 const REveDataItem *item = Collection()->GetDataItem(h);
429
430 Float_t x = hit->fX;
431 Float_t y = hit->fY;
432 Float_t z = hit->fZ;
433 Float_t a = hit->fPt;
434 Float_t d = 0.05;
435 Float_t verts[24] = {x - a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d), x - a + RND_BOX(d),
436 y + a + RND_BOX(d), z - a + RND_BOX(d), x + a + RND_BOX(d), y + a + RND_BOX(d),
437 z - a + RND_BOX(d), x + a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d),
438 x - a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d), x - a + RND_BOX(d),
439 y + a + RND_BOX(d), z + a + RND_BOX(d), x + a + RND_BOX(d), y + a + RND_BOX(d),
440 z + a + RND_BOX(d), x + a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d)};
441 boxset->AddBox(verts);
442
443 boxset->DigitValue(item->GetVisible() ? 1 : 0);
444 if (item->GetVisible())
445 boxset->DigitColor(item->GetMainColor());
446 }
447 boxset->RefitPlex();
448 boxset->StampObjProps();
449 }
450
451public:
453 void BuildProduct(const REveDataCollection* collection, REveElement* product, const REveViewContext*)override
454 {
455 fBoxSet = new FWBoxSet();
457 product->AddElement(fBoxSet);
458 }
459
461 void FillImpliedSelected(REveElement::Set_t& impSet, const std::set<int>& sec_idcs, Product* p) override
462 {
463 // printf("RecHit fill implioed ----------------- !!!%zu\n", Collection()->GetItemList()->RefSelectedSet().size());
464 impSet.insert(fBoxSet);
465 }
466
468 void ModelChanges(const REveDataCollection::Ids_t& ids, Product* product) override
469 {
470 for (auto &i : ids)
471 {
472 auto digi = fBoxSet->GetDigit(i);
473 auto item = Collection()->GetDataItem(i);
475 if (item->GetVisible()) {
477 fBoxSet->DigitColor(item->GetMainColor());
478 } else {
480 }
481 }
483 }
484}; // RecHitProxyBuilder
485
487{
488private:
490 TH2F* fHist {nullptr};
491 int fSliceIndex {-1};
492
493 void assertSlice() {
494 if (!fHist) {
496
497 TH1::AddDirectory(kFALSE); //Keeps histogram from going into memory
498 fHist = new TH2F("caloHist", "caloHist", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -M_PI, M_PI);
499 TH1::AddDirectory(status);
501
503 .Setup(Collection()->GetCName(),
504 0.,
505 Collection()->GetMainColor(),
506 Collection()->GetMainTransparency());
507
508 fCaloData->GetSelector()->AddSliceSelector(std::unique_ptr<REveCaloDataSliceSelector>
510 }
511 }
512
513public:
515
517 void BuildProduct(const REveDataCollection* collection, REveElement* product, const REveViewContext*)override
518 {
519 assertSlice();
520 fHist->Reset();
521 if (collection->GetRnrSelf())
522 {
524 .Setup(Collection()->GetCName(),
525 0.,
526 Collection()->GetMainColor(),
527 Collection()->GetMainTransparency());
528
529
530 for (int h = 0; h < collection->GetNItems(); ++h)
531 {
532 RCaloTower* tower = (RCaloTower*)collection->GetDataPtr(h);
533 const REveDataItem* item = Collection()->GetDataItem(h);
534
535 if (!item->GetVisible())
536 continue;
537 fHist->Fill(tower->fEta, tower->fPhi, tower->fEt);
538 }
539 }
541 }
542
544 void FillImpliedSelected(REveElement::Set_t& impSet, const std::set<int>& sec_idcs, Product*) override
545 {
547 impSet.insert(fCaloData);
548 fCaloData->FillImpliedSelectedSet(impSet, sec_idcs);
549 }
550
552 void ModelChanges(const REveDataCollection::Ids_t& ids, Product* product) override
553 {
554 BuildProduct(Collection(), nullptr, nullptr);
555 }
556
557}; // CaloTowerProxyBuilder
558
559//==============================================================================
560//== COLLECTION MANGER ================================================================
561//==============================================================================
562
564{
565private:
566 Event *fEvent{nullptr};
567
568 std::vector<REveScene *> m_scenes;
570
571 std::vector<REveDataProxyBuilderBase *> m_builders;
572
574 bool m_inEventLoading {false};
575
576public:
578 {
579 //view context
580 float r = 300;
581 float z = 300;
582 auto prop = new REveTrackPropagator();
583 prop->SetMagFieldObj(new REveMagFieldDuo(350, 3.5, -2.0));
584 prop->SetMaxR(r);
585 prop->SetMaxZ(z);
586 prop->SetMaxOrbs(6);
587 prop->IncRefCount();
588
592
593 // table specs
594 auto tableInfo = new REveTableViewInfo();
595
596 tableInfo->table("TParticle").
597 column("pt", 1, "i.Pt()").
598 column("eta", 3, "i.Eta()").
599 column("phi", 3, "i.Phi()");
600
601 tableInfo->table("Jet").
602 column("eta", 1, "i.Eta()").
603 column("phi", 1, "i.Phi()").
604 column("etasize", 2, "i.GetEtaSize()").
605 column("phisize", 2, "i.GetPhiSize()");
606
607 tableInfo->table("RecHit").
608 column("pt", 1, "i.fPt");
609
610 tableInfo->table("RCaloTower").
611 column("eta", 3, "i.fEta").
612 column("phi", 3, "i.fPhi").
613 column("Et", 3, "i.fEt");
614
616
617 for (auto &c : eveMng->GetScenes()->RefChildren()) {
618 if (c != eveMng->GetGlobalScene() && strncmp(c->GetCName(), "Geometry", 8) )
619 {
620 m_scenes.push_back((REveScene*)c);
621 }
622 if (!strncmp(c->GetCName(),"Table", 5))
623 c->AddElement(m_viewContext->GetTableViewInfo());
624
625 }
626
627 m_collections = eveMng->SpawnNewScene("Collections", "Collections");
628 }
629
631 {
632 for (auto &l : fEvent->fListData) {
633 TIter next(l);
634 if (collection->GetName() == std::string(l->GetName()))
635 {
636 collection->ClearItems();
637
638 for (int i = 0; i <= l->GetLast(); ++i)
639 {
640 std::string cname = collection->GetName();
641 auto len = cname.size();
642 char end = cname[len-1];
643 if (end == 's') {
644 cname = cname.substr(0, len-1);
645 }
646 TString pname(Form("%s %2d", cname.c_str(), i));
647 collection->AddItem(l->At(i), pname.Data(), "");
648 }
649 }
650 collection->ApplyFilter();
651 }
652 }
653
655 {
656 m_inEventLoading = true;
657
658 for (auto &el: m_collections->RefChildren())
659 {
660 auto c = dynamic_cast<REveDataCollection *>(el);
662 }
663
664 for (auto proxy : m_builders)
665 {
666 proxy->Build();
667 }
668
670 m_inEventLoading = false;
671 }
672
673 void addCollection(REveDataCollection* collection, REveDataProxyBuilderBase* glBuilder, bool showInTable = false)
674 {
675 m_collections->AddElement(collection);
676
677 // load data
678 SetDataItemsFromEvent(collection);
679 glBuilder->SetCollection(collection);
680 glBuilder->SetHaveAWindow(true);
681 for (auto scene : m_scenes)
682 {
683 if (strncmp(scene->GetCName(), "Tables", 5) == 0) continue;
684
685 REveElement *product = glBuilder->CreateProduct(scene->GetTitle(), m_viewContext);
686
687 if (!strncmp(scene->GetCTitle(), "Projected", 8))
688 {
689 g_projMng->ImportElements(product, scene);
690 }
691 else
692 {
693 scene->AddElement(product);
694 }
695 }
696 m_builders.push_back(glBuilder);
697 glBuilder->Build();
698
699 // Tables
700 auto tableBuilder = new REveTableProxyBuilder();
701 tableBuilder->SetHaveAWindow(true);
702 tableBuilder->SetCollection(collection);
703 REveElement* tablep = tableBuilder->CreateProduct("table-type", m_viewContext);
704 auto tableMng = m_viewContext->GetTableViewInfo();
705 if (showInTable)
706 {
707 tableMng->SetDisplayedCollection(collection->GetElementId());
708 }
709
710 for (auto s : m_scenes)
711 {
712 if (strncmp(s->GetCTitle(), "Table", 5) == 0)
713 {
714 s->AddElement(tablep);
715 tableBuilder->Build();
716 }
717 }
718 tableMng->AddDelegate([=]() { tableBuilder->ConfigChanged(); });
719 m_builders.push_back(tableBuilder);
720
721
722 // set tooltip expression for items
723 auto tableEntries = tableMng->RefTableEntries(collection->GetItemClass()->GetName());
724 int N = TMath::Min(int(tableEntries.size()), 3);
725 for (int t = 0; t < N; t++) {
726 auto te = tableEntries[t];
727 collection->GetItemList()->AddTooltipExpression(te.fName, te.fExpression);
728 }
729
730 collection->GetItemList()->SetItemsChangeDelegate([&] (REveDataItemList* collection, const REveDataCollection::Ids_t& ids)
731 {
732 this->ModelChanged( collection, ids );
733 });
734 collection->GetItemList()->SetFillImpliedSelectedDelegate([&] (REveDataItemList* collection, REveElement::Set_t& impSelSet, const std::set<int>& sec_idcs)
735 {
736 this->FillImpliedSelected( collection, impSelSet, sec_idcs);
737 });
738 }
739
741 {
742 auto mngTable = m_viewContext->GetTableViewInfo();
743 if (mngTable)
744 {
745 for (auto &el : m_collections->RefChildren())
746 {
747 if (el->GetName() == "Tracks")
748 mngTable->SetDisplayedCollection(el->GetElementId());
749 }
750 }
751 }
752
753
755 {
756 if (m_inEventLoading) return;
757
758 for (auto proxy : m_builders)
759 {
760 if (proxy->Collection()->GetItemList() == itemList)
761 {
762 // printf("Model changes check proxy %s: \n", proxy->Type().c_str());
763 proxy->ModelChanges(ids);
764 }
765 }
766 }
767
768 void FillImpliedSelected(REveDataItemList* itemList, REveElement::Set_t& impSelSet, const std::set<int>& sec_idcs)
769 {
770 if (m_inEventLoading) return;
771
772 for (auto proxy : m_builders)
773 {
774 if (proxy->Collection()->GetItemList() == itemList)
775 {
776 proxy->FillImpliedSelected(impSelSet, sec_idcs);
777 }
778 }
779 }
780
781};
782
783
784//==============================================================================
785//== Event Manager =============================================================
786//==============================================================================
787
789{
790private:
793
794public:
796
797 ~EventManager() override {}
798
799 virtual void NextEvent()
800 {
803 fEvent->Create();
804 fCMng->LoadEvent();
805 }
806};
807
809public:
811
813 bool DeviateSelection(REveSelection *selection, REveElement *el, bool multi, bool secondary,
814 const std::set<int> &secondary_idcs) override
815 {
816 if (el) {
817 auto *colItems = dynamic_cast<REveDataItemList *>(el);
818 if (colItems) {
819 // std::cout << "Deviate RefSelected=" << colItems->RefSelectedSet().size() << " passed set " << secondary_idcs.size() << "\n";
820 ExecuteNewElementPicked(selection, colItems, multi, true, colItems->RefSelectedSet());
821 return true;
822 }
823 }
824 return false;
825 }
826};
827//==============================================================================
828//== main() ====================================================================
829//==============================================================================
830
831void collection_proxies(bool proj=true)
832{
833 eveMng = REveManager::Create();
834 auto event = new Event();
835 event->Create();
836
837 // divert selection to map proxy builder products with collection
838 auto deviator = std::make_shared<FWSelectionDeviator>();
839 eveMng->GetSelection()->SetDeviator(deviator);
840 eveMng->GetHighlight()->SetDeviator(deviator);
841
842 // create scenes and views
843 REveScene* rhoZEventScene = nullptr;
844
845 auto b1 = new REveGeoShape("Barrel 1");
846 b1->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
847 b1->SetMainColor(kCyan);
848 b1->SetMainTransparency(90);
850
851 rhoZEventScene = eveMng->SpawnNewScene("RhoZ Scene","Projected");
852 g_projMng = new REveProjectionManager(REveProjection::kPT_RhoZ);
854
855 auto rhoZView = eveMng->SpawnNewViewer("RhoZ View");
856 rhoZView->SetCameraType(REveViewer::kCameraOrthoXOY);
858 auto pgeoScene = eveMng->SpawnNewScene("Geometry projected");
859 rhoZView->AddScene(pgeoScene);
860 g_projMng->ImportElements(b1, pgeoScene);
861
862 auto tableScene = eveMng->SpawnNewScene ("Tables", "Tables");
863 auto tableView = eveMng->SpawnNewViewer("Table", "Table View");
864 tableView->AddScene(tableScene);
865
866 // create event data from list
867 auto collectionMng = new CollectionManager(event);
868
869 REveDataCollection* trackCollection = new REveDataCollection("Tracks");
870 trackCollection->SetItemClass(TParticle::Class());
871 trackCollection->SetMainColor(kGreen);
872 trackCollection->SetFilterExpr("i.Pt() > 4.1 && std::abs(i.Eta()) < 1");
873 collectionMng->addCollection(trackCollection, new TParticleProxyBuilder(), true);
874
875 REveDataCollection* jetCollection = new REveDataCollection("Jets");
876 jetCollection->SetItemClass(Jet::Class());
877 jetCollection->SetMainColor(kYellow);
878 jetCollection->SetFilterExpr("i.Pt() > 1");
879 collectionMng->addCollection(jetCollection, new JetProxyBuilder());
880
881 REveDataCollection* hitCollection = new REveDataCollection("RecHits");
882 hitCollection->SetItemClass(RecHit::Class());
883 hitCollection->SetMainColor(kOrange + 7);
884 hitCollection->SetFilterExpr("i.fPt > 5");
885 collectionMng->addCollection(hitCollection, new RecHitProxyBuilder(), true);
886
887 // add calorimeters
888 auto calo3d = new REveCalo3D(event->fCaloData);
889 calo3d->SetBarrelRadius(kR_max);
890 calo3d->SetEndCapPos(kZ_d);
891 calo3d->SetMaxTowerH(300);
892 eveMng->GetEventScene()->AddElement(calo3d);
894
895 REveDataCollection* ecalCollection = new REveDataCollection("ECAL");
896 ecalCollection->SetItemClass(RCaloTower::Class());
897 ecalCollection->SetMainColor(kRed);
898 collectionMng->addCollection(ecalCollection, new CaloTowerProxyBuilder(event->fCaloData));
899
900 REveDataCollection* hcalCollection = new REveDataCollection("HCAL");
901 hcalCollection->SetItemClass(RCaloTower::Class());
902 hcalCollection->SetMainColor(kBlue);
903 collectionMng->addCollection(hcalCollection, new CaloTowerProxyBuilder(event->fCaloData));
904
905 // event navigation
906 auto eventMng = new EventManager(event, collectionMng);
907 eventMng->SetName("EventManager");
908 eveMng->GetWorld()->AddElement(eventMng);
909
910 eveMng->GetWorld()->AddCommand("NextEvent", "sap-icon://step", eventMng, "NextEvent()");
911
912 eveMng->Show();
913}
#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
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
#define ClassDef(name, id)
Definition Rtypes.h:342
@ kRed
Definition Rtypes.h:66
@ kOrange
Definition Rtypes.h:67
@ kGreen
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
#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:62
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
CaloTowerProxyBuilder(REveCaloDataHist *cd)
REveCaloDataHist * fCaloData
void FillImpliedSelected(REveElement::Set_t &impSet, const std::set< int > &sec_idcs, Product *) override
void BuildProduct(const REveDataCollection *collection, REveElement *product, const REveViewContext *) override
void ModelChanges(const REveDataCollection::Ids_t &ids, Product *product) override
void addCollection(REveDataCollection *collection, REveDataProxyBuilderBase *glBuilder, bool showInTable=false)
CollectionManager(Event *event)
std::vector< REveScene * > m_scenes
void FillImpliedSelected(REveDataItemList *itemList, REveElement::Set_t &impSelSet, const std::set< int > &sec_idcs)
void ModelChanged(REveDataItemList *itemList, const REveDataCollection::Ids_t &ids)
std::vector< REveDataProxyBuilderBase * > m_builders
REveViewContext * m_viewContext
void SetDataItemsFromEvent(REveDataCollection *collection)
CollectionManager * fCMng
~EventManager() override
EventManager(Event *e, CollectionManager *m)
virtual void NextEvent()
void MakeParticles(int N)
std::vector< TList * > fListData
void MakeRecHits(int N)
REveCaloDataHist * fCaloData
void MakeJets(int N)
bool DeviateSelection(REveSelection *selection, REveElement *el, bool multi, bool secondary, const std::set< int > &secondary_idcs) override
void LocalModelChanges(int idx, REveElement *el, const REveViewContext *ctx) override
bool HaveSingleProduct() const override
void BuildItemViewType(const Jet &dj, int idx, REveElement *iItemHolder, const std::string &viewType, const REveViewContext *context) override
void SetEtaSize(float iEtaSize)
static TClass * Class()
float GetPhiSize() const
Jet(Int_t pdg, Int_t status, Int_t mother1, Int_t mother2, Int_t daughter1, Int_t daughter2, Double_t px, Double_t py, Double_t pz, Double_t etot)
float fPhiSize
void SetPhiSize(float iPhiSize)
float fEtaSize
float GetEtaSize() const
RCaloTower(float eta, float phi, float et)
static TClass * Class()
Cell data inner structure.
void ProcessSelection(REveCaloData::vCellId_t &sel_cells, UInt_t selectionId, Bool_t multi) override
void GetCellsFromSecondaryIndices(const std::set< int > &idcs, REveCaloData::vCellId_t &out) override
REveCaloTowerSliceSelector(int s, REveDataCollection *c, REveCaloDataHist *h)
REveDataCollection * fCollection
void AddBox(const Float_t *verts)
void Reset(EBoxType_e boxType, Bool_t valIsCol, Int_t chunkSize)
Int_t AddHistogram(TH2F *hist)
Add new slice to calo tower.
void DataChanged() override
Update limits and notify data users.
TH2F * GetHist(Int_t slice) const
Get histogram in given slice.
void GetCellData(const REveCaloData::CellId_t &id, REveCaloData::CellData_t &data) const override
Get cell geometry and value from cell ID.
void AddSliceSelector(std::unique_ptr< REveCaloDataSliceSelector > s)
virtual void ProcessSelection(REveCaloData::vCellId_t &sel_cells, UInt_t selectionId, bool multi)=0
virtual void GetCellsFromSecondaryIndices(const std::set< int > &idcs, REveCaloData::vCellId_t &out)=0
void SetSelector(REveCaloDataSelector *iSelector)
REveCaloDataSelector * GetSelector()
SliceInfo_t & RefSliceInfo(Int_t s)
std::vector< CellId_t > vCellId_t
void FillImpliedSelectedSet(Set_t &impSelSet, const std::set< int > &sec_idcs) override
Populate set impSelSet with derived / dependant elements.
void AddItem(void *data_ptr, const std::string &n, const std::string &t)
void SetMainColor(Color_t) override
Set main color of the element.
const REveDataItem * GetDataItem(Int_t i) const
void AddTooltipExpression(const std::string &title, const std::string &expr, bool init=true)
void SetFillImpliedSelectedDelegate(FillImpliedSelectedFunc_t)
virtual void LocalModelChanges(int idx, REveElement *el, const REveViewContext *ctx)
virtual REveElement * CreateProduct(const std::string &viewType, const REveViewContext *)
void FillImpliedSelected(REveElement::Set_t &impSet, const std::set< int > &)
void ModelChanges(const REveDataCollection::Ids_t &)
void SetupAddElement(REveElement *el, REveElement *parent, bool set_color=true)
void SetMainColor(Color_t color) override
Override from REveElement, forward to Frame.
void DigitColor(Color_t ci)
Set color for the last digit added.
void SetCurrentDigit(Int_t idx)
Set current digit – the one that will receive calls to DigitValue/Color/Id/UserData() functions.
void RefitPlex()
Instruct underlying memory allocator to regroup itself into a contiguous memory chunk.
DigitBase_t * GetDigit(Int_t n) const
void DigitValue(Int_t value)
Set signal value for the last digit added.
const std::string & GetName() const
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual Bool_t GetRnrSelf() const
REveElement * FirstChild() const
Returns the first child element or 0 if the list is empty.
void SetSelectionMaster(REveElement *el)
std::set< REveElement * > Set_t
ElementId_t GetElementId() const
virtual Color_t GetMainColor() const
void SetName(const std::string &name)
Set name of an element.
REveMagFieldDuo Interface to magnetic field with two different values depending on radius.
REveScene * GetEventScene() const
REveSelection * GetHighlight() const
REveSceneList * GetScenes() const
REveSelection * GetSelection() const
REveElement * FindElementById(ElementId_t id) const
Lookup ElementId in element map and return corresponding REveElement*.
REveScene * GetGlobalScene() const
REveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
REveViewer * SpawnNewViewer(const char *name, const char *title="")
Create a new GL viewer.
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
REveProjectionManager Manager class for steering of projections and managing projected objects.
virtual REveElement * ImportElements(REveElement *el, REveElement *ext_list=nullptr)
Recursively import elements and apply projection to the newly imported objects.
void AddCommand(const std::string &name, const std::string &icon, const REveElement *element, const std::string &action)
Definition REveScene.cxx:90
virtual bool DeviateSelection(REveSelection *s, REveElement *el, bool multi, bool secondary, const std::set< int > &secondary_idcs)=0
REveSelection Container for selected and highlighted elements.
void SetDeviator(std::shared_ptr< Deviator > d)
void ClearSelection()
Clear selection if not empty.
REveTrackPropagator Calculates path of a particle taking into account special path-marks and imposed ...
REveTrack Track with given vertex, momentum and optional referece-points (path-marks) along its path.
Definition REveTrack.hxx:40
REveTableViewInfo * GetTableViewInfo() const
void SetTrackPropagator(REveTrackPropagator *p)
void SetTableViewInfo(REveTableViewInfo *ti)
REveTrackPropagator * GetPropagator() const
void SetCameraType(ECameraType t)
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
REveElement * GetSelectionMaster() override
Returns the master element - that is:
void ModelChanges(const REveDataCollection::Ids_t &ids, Product *product) override
void buildBoxSet(REveBoxSet *boxset)
void FillImpliedSelected(REveElement::Set_t &impSet, const std::set< int > &sec_idcs, Product *p) override
void BuildProduct(const REveDataCollection *collection, REveElement *product, const REveViewContext *) override
static TClass * Class()
RecHit(float pt, float x, float y, float z)
void SetName(const char *name)
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition TH1.cxx:1294
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:3672
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Definition TH1.cxx:754
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
void Reset(Option_t *option="") override
Reset this histogram: contents, errors, etc.
Definition TH2.cxx:3972
Double_t GetBinContent(Int_t binx, Int_t biny) const override
Definition TH2.h:93
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:393
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:355
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:456
void BuildItem(const TParticle &p, int idx, REveElement *iItemHolder, const REveViewContext *context) override
Description of the dynamic properties of a particle.
Definition TParticle.h:26
static TClass * Class()
Double_t Pt() const
Definition TParticle.h:135
Double_t Phi() const
Definition TParticle.h:149
Double_t Eta() const
Definition TParticle.h:137
Double_t Theta(const TParticle &p)
Definition TParticle.h:115
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition TRandom.cxx:682
virtual Int_t GetLast() const
Returns index of last object in collection.
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
ROOT::Experimental::REveProjectionManager * g_projMng
ROOT::Experimental::REveManager * eveMng
#define RND_BOX(x)
const Double_t kR_max
void collection_proxies(bool proj=true)
const Double_t kZ_d
const Double_t kR_min
TPaveText * pt
REX::REveManager * eveMng
Definition event_demo.C:41
REX::REveViewer * rhoZView
Definition event_demo.C:47
REX::REveScene * rhoZEventScene
Definition event_demo.C:45
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t ex[n]
Definition legend1.C:17
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
constexpr Double_t Pi()
Definition TMath.h:37
constexpr Double_t TwoPi()
Definition TMath.h:44
const int xbins_n
const double xbins[xbins_n]
void Setup(const char *name, Float_t threshold, Color_t col, Char_t transp=101)
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4