9#include "ROOT/REveDataClasses.hxx"
12#include "ROOT/REveDataSimpleProxyBuilderTemplate.hxx"
13#include "ROOT/REveManager.hxx"
14#include "ROOT/REveScalableStraightLineSet.hxx"
15#include "ROOT/REveViewContext.hxx"
16#include <ROOT/REveGeoShape.hxx>
17#include <ROOT/REveJetCone.hxx>
18#include <ROOT/REvePointSet.hxx>
19#include <ROOT/REveProjectionBases.hxx>
20#include <ROOT/REveProjectionManager.hxx>
21#include <ROOT/REveScene.hxx>
22#include <ROOT/REveTableProxyBuilder.hxx>
23#include <ROOT/REveTableInfo.hxx>
24#include <ROOT/REveTrack.hxx>
25#include <ROOT/REveTrackPropagator.hxx>
26#include <ROOT/REveViewer.hxx>
27#include <ROOT/REveViewContext.hxx>
55 float GetEtaSize()
const {
return m_etaSize; }
56 float GetPhiSize()
const {
return m_phiSize; }
57 void SetEtaSize(
float iEtaSize) { m_etaSize = iEtaSize; }
58 void SetPhiSize(
float iPhiSize) { m_phiSize = iPhiSize; }
60 TParticle(pdg, status, mother1, mother2, daughter1, daughter2, px, py, pz, etot, 0, 0, 0, 0) {}
79 for (
int i = 1; i <=
N; ++i)
81 double pt =
r.Uniform(0.5, 10);
82 double eta =
r.Uniform(-2.55, 2.55);
89 auto jet =
new XYJet(0, 0, 0, 0, 0, 0, px, py, pz,
std::sqrt(px*px + py*py + pz*pz + 80*80));
90 jet->SetEtaSize(
r.Uniform(0.02, 0.2));
91 jet->SetPhiSize(
r.Uniform(0.01, 0.3));
94 m_data.push_back(list);
97 void MakeParticles(
int N)
103 for (
int i = 1; i <=
N; ++i)
105 double pt =
r.Uniform(0.5, 10);
106 double eta =
r.Uniform(-2.55, 2.55);
113 printf(
"Event::MakeParticles %2d: pt=%.2f, eta=%.2f, phi=%.2f\n", i,
pt, eta, phi);
115 auto particle =
new TParticle(0, 0, 0, 0, 0, 0,
116 px, py, pz,
std::sqrt(px*px + py*py + pz*pz + 80*80),
119 int pdg = 11 * (
r.Integer(2) > 0 ? 1 : -1);
120 particle->SetPdgCode(pdg);
124 m_data.push_back(list);
127 std::vector<TList*> m_data;
130 for (
auto &
l : m_data)
146class XYJetProxyBuilder:
public REX::REveDataSimpleProxyBuilderTemplate<XYJet>
148 virtual bool HaveSingleProduct()
const {
return false; }
150 using REveDataSimpleProxyBuilderTemplate<XYJet>::BuildViewType;
151 virtual void BuildViewType(
const XYJet& dj, REX::REveElement* iItemHolder, std::string viewType,
const REX::REveViewContext* context)
153 auto jet =
new REX::REveJetCone();
154 jet->SetCylinder(context->GetMaxR(), context->GetMaxZ());
155 jet->AddEllipticCone(dj.Eta(), dj.Phi(), dj.GetEtaSize(), dj.GetPhiSize());
156 SetupAddElement(jet, iItemHolder,
true);
161 float size = 50.f * dj.Pt();
162 double theta = dj.Theta();
164 double phi = dj.Phi();
167 if (viewType ==
"Projected" )
169 static const float_t offr = 6;
170 float r_ecal = context->GetMaxR() + offr;
171 float z_ecal = context->GetMaxZ() + offr;
173 float transAngle = abs(
atan(r_ecal/z_ecal));
176 if ( theta < transAngle || 3.14-theta < transAngle)
178 z_ecal = context->GetMaxZ() + offr/transAngle;
184 r = r_ecal/
sin(theta);
191 auto marker =
new REX::REveScalableStraightLineSet(
"jetline");
192 marker->SetScaleCenter(p1.fX, p1.fY, p1.fZ);
193 marker->AddLine(p1, p2);
195 marker->SetLineWidth(4);
197 marker->AddMarker(0, 0.9);
199 SetupAddElement(marker, iItemHolder,
true);
202 jet->SetName(
Form(
"element %s", iItemHolder->GetName().c_str()));
206class TrackProxyBuilder :
public REX::REveDataSimpleProxyBuilderTemplate<TParticle>
208 using REveDataSimpleProxyBuilderTemplate<TParticle>::Build;
209 virtual void Build(
const TParticle& p, REX::REveElement* iItemHolder,
const REX::REveViewContext* context)
213 auto track =
new REX::REveTrack((
TParticle*)(
x), 1, context->GetPropagator());
215 SetupAddElement(track, iItemHolder,
true);
217 track->SetName(
Form(
"element %s id=%d", iItemHolder->GetCName(), track->GetElementId()));
230 Event *m_event{
nullptr};
232 std::vector<REX::REveScene *> m_scenes;
233 REX::REveViewContext *m_viewContext{
nullptr};
234 REX::REveProjectionManager *m_mngRhoZ{
nullptr};
236 std::vector<REX::REveDataProxyBuilderBase *> m_builders;
237 REX::REveScene *m_collections{
nullptr};
238 bool m_inEventLoading{
false};
241 XYManager(Event* event): m_event(event)
246 auto prop =
new REX::REveTrackPropagator();
247 prop->SetMagFieldObj(
new REX::REveMagFieldDuo(350, -3.5, 2.0));
253 m_viewContext =
new REX::REveViewContext();
254 m_viewContext->SetBarrel(
r, z);
255 m_viewContext->SetTrackPropagator(prop);
258 auto tableInfo =
new REX::REveTableViewInfo();
259 tableInfo->table(
"XYTracks").
260 column(
"pt", 1,
"Pt").
261 column(
"eta", 3,
"Eta").
262 column(
"phi", 3,
"Phi");
264 tableInfo->table(
"XYJets").
265 column(
"eta", 1,
"Eta").
266 column(
"phi", 1,
"Phi").
267 column(
"etasize", 2,
"GetEtaSize").
268 column(
"phisize", 2,
"GetPhiSize");
270 m_viewContext->SetTableViewInfo(tableInfo);
272 createScenesAndViews();
275 void createScenesAndViews()
278 m_collections =
eveMng->SpawnNewScene(
"Collections",
"Collections");
281 m_scenes.push_back(
eveMng->GetEventScene());
284 auto b1 =
new REX::REveGeoShape(
"Barrel 1");
286 b1->SetShape(
new TGeoTube(m_viewContext->GetMaxR() , m_viewContext->GetMaxR() + dr, m_viewContext->GetMaxZ()));
287 b1->SetMainColor(
kCyan);
288 eveMng->GetGlobalScene()->AddElement(b1);
293 m_mngRhoZ =
new REX::REveProjectionManager(REX::REveProjection::kPT_RhoZ);
294 m_mngRhoZ->SetImportEmpty(
true);
299 auto pgeoScene =
eveMng->SpawnNewScene(
"Projection Geometry",
"xxx");
300 m_mngRhoZ->ImportElements(b1,pgeoScene );
306 auto tableScene =
eveMng->SpawnNewScene(
"Tables",
"Tables");
307 auto tableView =
eveMng->SpawnNewViewer(
"Table",
"Table View");
308 tableView->AddScene(tableScene);
309 tableScene->AddElement(m_viewContext->GetTableViewInfo());
310 m_scenes.push_back(tableScene);
316 REX::REveDataProxyBuilderBase* makeGLBuilderForType(
TClass*
c)
318 std::string cn =
c->GetName();
321 return new XYJetProxyBuilder();
325 return new TrackProxyBuilder();
329 void LoadCurrentEvent(REX::REveDataCollection* collection)
332 for (
auto &
l : m_event->m_data) {
334 if (collection->GetName() == std::string(
l->GetName()))
337 collection->ClearItems();
338 collection->DestroyElements();
340 for (
int i = 0; i <=
l->GetLast(); ++i)
343 collection->AddItem(
l->At(i), pname.
Data(),
"");
352 m_inEventLoading =
true;
353 for (
auto &el: m_collections->RefChildren())
355 auto c =
dynamic_cast<REX::REveDataCollection *
>(el);
360 for (
auto proxy : m_builders) {
363 m_inEventLoading =
false;
366 void addCollection(REX::REveDataCollection* collection,
bool makeTable)
369 LoadCurrentEvent(collection);
372 auto glBuilder = makeGLBuilderForType(collection->GetItemClass());
373 glBuilder->SetCollection(collection);
374 glBuilder->SetHaveAWindow(
true);
375 for (
auto scene : m_scenes) {
376 REX::REveElement *product = glBuilder->CreateProduct(scene->GetTitle(), m_viewContext);
377 if (strncmp(scene->GetCTitle(),
"Table", 5) == 0)
continue;
378 if (!strncmp(scene->GetCTitle(),
"Projected", 8)) {
379 m_mngRhoZ->ImportElements(product, scene);
382 scene->AddElement(product);
385 m_builders.push_back(glBuilder);
390 auto tableBuilder =
new REX::REveTableProxyBuilder();
391 tableBuilder->SetHaveAWindow(
true);
392 tableBuilder->SetCollection(collection);
393 REX::REveElement* tablep = tableBuilder->CreateProduct(
"table-type", m_viewContext);
395 auto tableMng = m_viewContext->GetTableViewInfo();
396 tableMng->SetDisplayedCollection(collection->GetElementId());
397 tableMng->AddDelegate([=](REX::ElementId_t elId) { tableBuilder->DisplayedCollectionChanged(elId); });
399 for (REX::REveScene* scene : m_scenes) {
400 if (strncmp(scene->GetCTitle(),
"Table", 5) == 0) {
401 scene->AddElement(tablep);
402 tableBuilder->Build(collection, tablep, m_viewContext );
406 m_builders.push_back(tableBuilder);
409 m_collections->AddElement(collection);
410 collection->SetHandlerFunc([&] (REX::REveDataCollection* collection) { this->CollectionChanged( collection ); });
411 collection->SetHandlerFuncIds([&] (REX::REveDataCollection* collection,
const REX::REveDataCollection::Ids_t& ids) { this->ModelChanged( collection, ids ); });
414 void finishViewCreate()
416 auto mngTable = m_viewContext->GetTableViewInfo();
418 for (
auto &el : m_collections->RefChildren())
420 if (el->GetName() ==
"XYTracks")
421 mngTable->SetDisplayedCollection(el->GetElementId());
426 void CollectionChanged(REX::REveDataCollection* collection) {
427 printf(
"collection changes not implemented %s!\n", collection->GetCName());
430 void ModelChanged(REX::REveDataCollection* collection,
const REX::REveDataCollection::Ids_t& ids) {
431 if (m_inEventLoading)
return;
433 for (
auto proxy : m_builders) {
434 if (proxy->Collection() == collection) {
436 proxy->ModelChanges(ids);
445class EventManager :
public REX::REveElement
452 EventManager(Event*
e, XYManager*
m): m_event(
e), m_xymng(
m) {}
454 virtual ~EventManager() {}
456 virtual void NextEvent()
459 m_xymng->NextEvent();
462 virtual void QuitRoot()
464 printf(
"Quit ROOT\n");
474 eveMng = REX::REveManager::Create();
476 auto event =
new Event();
478 event->N_tracks = 10;
484 auto xyManager =
new XYManager(event);
487 REX::REveDataCollection* trackCollection =
new REX::REveDataCollection(
"XYTracks");
489 trackCollection->SetMainColor(
kGreen);
491 xyManager->addCollection(trackCollection,
true);
495 REX::REveDataCollection* jetCollection =
new REX::REveDataCollection(
"XYJets");
497 jetCollection->SetMainColor(
kRed);
498 xyManager->addCollection(jetCollection,
false);
501 auto eventMng =
new EventManager(event, xyManager);
502 eventMng->SetName(
"EventManager");
503 eveMng->GetWorld()->AddElement(eventMng);
505 eveMng->GetWorld()->AddCommand(
"QuitRoot",
"sap-icon://log", eventMng,
"QuitRoot()");
506 eveMng->GetWorld()->AddCommand(
"NextEvent",
"sap-icon://step", eventMng,
"NextEvent()");
#define ClassDef(name, id)
R__EXTERN TApplication * gApplication
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
TClass instances represent classes, structs and namespaces in the ROOT type system.
void SetName(const char *name)
virtual void Add(TObject *obj)
Description of the dynamic properties of a particle.
TParticle()
reference to the particle record in PDG database
This is the base class for the ROOT Random number generators.
const char * Data() const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
void collection_proxies(bool proj=true)
REX::REveManager * eveMng
REX::REveViewer * rhoZView
REX::REveScene * rhoZEventScene
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
constexpr Double_t TwoPi()