Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Geant4 event viewer #300

Merged
merged 5 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/framework/core/inc/TRestEveEventViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#include "TRestEventViewer.h"

#define GEOM_SCALE 1
#define GEOM_SCALE 0.1

class TRestEveEventViewer : public TRestEventViewer {
protected:
Expand All @@ -64,8 +64,8 @@ class TRestEveEventViewer : public TRestEventViewer {

char pointName[256];

Double_t fMinRadius;
Double_t fMaxRadius;
Double_t fMinRadius = 0.2;
Double_t fMaxRadius = 3.0;

public:
virtual void Initialize();
Expand Down
96 changes: 63 additions & 33 deletions source/framework/core/src/TRestEveEventViewer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,79 @@ TRestEveEventViewer::~TRestEveEventViewer() {
DeleteGeometry();
}

void InitializePerspectiveView() {
const std::map<TString, TGLViewer::ECameraType> projectionsMap = {
{"Projection XY", TGLViewer::kCameraOrthoXnOY}, //
{"Projection XZ", TGLViewer::kCameraOrthoXnOZ}, //
{"Projection YZ", TGLViewer::kCameraOrthoZOY} //
};
for (const auto& [name, cameraType] : projectionsMap) {
auto slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
auto pack = slot->MakePack();
pack->SetElementName(name);
pack->SetHorizontal();
pack->SetShowTitleBar(kFALSE);
pack->NewSlot()->MakeCurrent();
auto f3DView = gEve->SpawnNewViewer("3D View", pack->GetName());
f3DView->AddScene(gEve->GetGlobalScene());
f3DView->AddScene(gEve->GetEventScene());
f3DView->GetGLViewer()->SetCurrentCamera(cameraType);
}
}

void TRestEveEventViewer::Initialize() {
gEve = TEveManager::Create();
gEve->GetBrowser()->DontCallClose();

fMinRadius = 0.2;
fMaxRadius = 3.;

gEve->AddEvent(new TEveEventManager("Event", "Event"));

auto singleViewer = gEve->GetDefaultViewer();
singleViewer->SetElementName("SingleView");

singleViewer->GetGLViewer()->SetClearColor(kBlack);

InitializePerspectiveView();
MultiView();
DrawTab();
}

void TRestEveEventViewer::SetGeometry(TGeoManager* geo) {
TRestEventViewer::SetGeometry(geo);
singleViewer->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);

if (fGeometry == nullptr) return;
gEve->GetBrowser()->GetTabRight()->SetTab(0); // select the "SingleView" viewer as active

TObjArray* arr = fGeometry->GetListOfVolumes();
Int_t nVolumes = arr->GetEntries();

for (int i = 0; i < nVolumes; i++) fGeometry->GetVolume(i)->SetTransparency(85);
singleViewer->GetGLViewer()->CurrentCamera().Reset();
gEve->FullRedraw3D(kTRUE);
}

TEveGeoTopNode* en = new TEveGeoTopNode(fGeometry, fGeometry->GetTopNode());
void TRestEveEventViewer::SetGeometry(TGeoManager* geo) {
TRestEventViewer::SetGeometry(geo);

gEve->AddGlobalElement(en);
if (fGeometry == nullptr) {
return;
}

const unsigned int nVolumes = fGeometry->GetListOfVolumes()->GetEntries();
double transparencyLevel = 85;
if (nVolumes > 30) {
transparencyLevel = 90;
}
for (int i = 0; i < fGeometry->GetListOfVolumes()->GetEntries(); i++) {
auto volume = fGeometry->GetVolume(i);
auto material = volume->GetMaterial();
if (material->GetDensity() <= 0.01) {
volume->SetTransparency(99);
if (material->GetDensity() <= 0.001) {
// We consider this vacuum for display purposes
volume->SetVisibility(kFALSE);
}
} else {
volume->SetTransparency(transparencyLevel);
}
}

TEveGeoTopNode* eveGeoTopNode = new TEveGeoTopNode(fGeometry, fGeometry->GetTopNode());
eveGeoTopNode->SetVisLevel(5);

gEve->AddGlobalElement(eveGeoTopNode);

viewer3D->AddScene(gEve->GetGlobalScene());
}
Expand All @@ -79,7 +126,7 @@ void TRestEveEventViewer::MultiView() {
slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());

pack = slot->MakePack();
pack->SetElementName("Tab");
pack->SetElementName("MultiView");
pack->SetHorizontal();
pack->SetShowTitleBar(kFALSE);
pack->NewSlot()->MakeCurrent();
Expand Down Expand Up @@ -119,24 +166,9 @@ void TRestEveEventViewer::MultiView() {
}

void TRestEveEventViewer::DrawTab() {
gEve->FullRedraw3D(kTRUE);

TGLViewer* v = gEve->GetDefaultGLViewer();
// v->GetClipSet()->SetClipType(TGLClip::EType(1));
v->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0);
v->SetStyle(TGLRnrCtx::kOutline);
v->RefreshPadEditor(v);

// v->CurrentCamera().RotateRad(-1.2, 0.5);
v->DoDraw();

TGLViewer* v2 = viewer3D->GetGLViewer();
v2->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0);
v2->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, nullptr);
v2->SetStyle(TGLRnrCtx::kOutline);
v2->RefreshPadEditor(v);
v2->DoDraw();

gEve->GetBrowser()->GetTabRight()->SetTab(1);
}

void TRestEveEventViewer::Update() {
Expand All @@ -149,11 +181,9 @@ void TRestEveEventViewer::Update() {
}

void TRestEveEventViewer::AddSphericalHit(double x, double y, double z, double radius, double en) {
// TEvePointSet* ps = new TEvePointSet();

fEnergyDeposits->SetOwnIds(kTRUE);
fEnergyDeposits->SetNextPoint(x * GEOM_SCALE, y * GEOM_SCALE, z * GEOM_SCALE);
fEnergyDeposits->SetMarkerColor(kYellow);
fEnergyDeposits->SetMarkerSize(radius);
fEnergyDeposits->SetMarkerSize(Size_t(radius));
fEnergyDeposits->SetMarkerStyle(4);
}