From c2dab79308874113e75b19af1238706bdcb250e8 Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Tue, 22 Apr 2014 12:31:48 +0000 Subject: [PATCH] - added multi view to teve_display with projections of surfaces --- UtilityApps/src/MultiView.h | 196 +++++++++++++++++++++++ UtilityApps/src/next_event_lcio.cpp | 160 ++++++++++++------- UtilityApps/src/teve_display.cpp | 236 +++++----------------------- 3 files changed, 334 insertions(+), 258 deletions(-) create mode 100644 UtilityApps/src/MultiView.h diff --git a/UtilityApps/src/MultiView.h b/UtilityApps/src/MultiView.h new file mode 100644 index 000000000..52ca9c119 --- /dev/null +++ b/UtilityApps/src/MultiView.h @@ -0,0 +1,196 @@ +#ifndef MultiView_h +#define MultiView_h + +#include <TEveManager.h> +#include <TEveViewer.h> +#include <TGLViewer.h> + +#include <TEveScene.h> + +#include <TEveProjectionManager.h> +#include <TEveProjectionAxes.h> + +#include <TEveBrowser.h> +#include <TEveWindow.h> + +/** Multi-view (3d, rphi, rhoz) service class using EVE Window Manager. + * Author: Matevz Tadel 2009 + * MultiView + * + * Structure encapsulating standard views: 3D, r-phi and rho-z. + * Includes scenes and projection managers. + * + * Should be used in compiled mode. + * + * @author F.Gaede, DESY (modified original version from Matevz Tadel) + * @version "$Id:$" + */ + +class MultiView { + +public: + + TEveProjectionManager *fRPhiMgr; + TEveProjectionManager *fRhoZMgr; + + TEveViewer *f3DView; + TEveViewer *fRPhiView; + TEveViewer *fRhoZView; + + TEveScene *fRPhiGeomScene; + TEveScene *fRhoZGeomScene; + TEveScene *fRPhiEventScene; + TEveScene *fRhoZEventScene; + + //--------------------------------------------------------------------------- + + static MultiView* instance() { + static MultiView mw ; + return &mw ; + } + + MultiView() { + + // Constructor --- creates required scenes, projection managers + // and GL viewers. + + // Scenes + //======== + + fRPhiGeomScene = gEve->SpawnNewScene("RPhi Geometry", + "Scene holding projected geometry for the RPhi view."); + fRhoZGeomScene = gEve->SpawnNewScene("RhoZ Geometry", + "Scene holding projected geometry for the RhoZ view."); + fRPhiEventScene = gEve->SpawnNewScene("RPhi Event Data", + "Scene holding projected event-data for the RPhi view."); + fRhoZEventScene = gEve->SpawnNewScene("RhoZ Event Data", + "Scene holding projected event-data for the RhoZ view."); + + + // Projection managers + //===================== + + fRPhiMgr = new TEveProjectionManager(TEveProjection::kPT_RPhi); + gEve->AddToListTree(fRPhiMgr, kFALSE); + { + TEveProjectionAxes* a = new TEveProjectionAxes(fRPhiMgr); + a->SetMainColor(kWhite); + a->SetTitle("R-Phi"); + a->SetTitleSize(0.05); + a->SetTitleFont(102); + a->SetLabelSize(0.025); + a->SetLabelFont(102); + fRPhiGeomScene->AddElement(a); + } + + fRhoZMgr = new TEveProjectionManager(TEveProjection::kPT_RhoZ); + gEve->AddToListTree(fRhoZMgr, kFALSE); + { + TEveProjectionAxes* a = new TEveProjectionAxes(fRhoZMgr); + a->SetMainColor(kWhite); + a->SetTitle("Rho-Z"); + a->SetTitleSize(0.05); + a->SetTitleFont(102); + a->SetLabelSize(0.025); + a->SetLabelFont(102); + fRhoZGeomScene->AddElement(a); + } + + + // Viewers + //========= + + TEveWindowSlot *slot = 0; + TEveWindowPack *pack = 0; + + slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight()); + pack = slot->MakePack(); + pack->SetElementName("Multi View"); + pack->SetHorizontal(); + pack->SetShowTitleBar(kFALSE); + pack->NewSlot()->MakeCurrent(); + f3DView = gEve->SpawnNewViewer("3D View", ""); + f3DView->AddScene(gEve->GetGlobalScene()); + f3DView->AddScene(gEve->GetEventScene()); + + pack = pack->NewSlot()->MakePack(); + pack->SetShowTitleBar(kFALSE); + pack->NewSlot()->MakeCurrent(); + fRPhiView = gEve->SpawnNewViewer("RPhi View", ""); + fRPhiView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY); + fRPhiView->AddScene(fRPhiGeomScene); + fRPhiView->AddScene(fRPhiEventScene); + + pack->NewSlot()->MakeCurrent(); + fRhoZView = gEve->SpawnNewViewer("RhoZ View", ""); + fRhoZView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY); + fRhoZView->AddScene(fRhoZGeomScene); + fRhoZView->AddScene(fRhoZEventScene); + + + //fg: set white background: + f3DView->GetGLViewer()->ColorSet().Background().SetColor(kWhite); + fRPhiView->GetGLViewer()->ColorSet().Background().SetColor(kWhite); + fRhoZView->GetGLViewer()->ColorSet().Background().SetColor(kWhite); + } + + //--------------------------------------------------------------------------- + + void SetDepth(Float_t d) + { + // Set current depth on all projection managers. + + fRPhiMgr->SetCurrentDepth(d); + fRhoZMgr->SetCurrentDepth(d); + } + + //--------------------------------------------------------------------------- + + void ImportGeomRPhi(TEveElement* el) + { + fRPhiMgr->ImportElements(el, fRPhiGeomScene); + } + + void ImportGeomRhoZ(TEveElement* el) + { + fRhoZMgr->ImportElements(el, fRhoZGeomScene); + } + + void ImportEventRPhi(TEveElement* el) + { + fRPhiMgr->ImportElements(el, fRPhiEventScene); + } + + void ImportEventRhoZ(TEveElement* el) + { + fRhoZMgr->ImportElements(el, fRhoZEventScene); + } + + + void ImportEvent(TEveElement* el) + { + gEve->AddElement( el ) ; + fRPhiMgr->ImportElements(el, fRPhiEventScene); + fRhoZMgr->ImportElements(el, fRhoZEventScene); + } + + //--------------------------------------------------------------------------- + + void DestroyEventRPhi() + { + fRPhiEventScene->DestroyElements(); + } + + void DestroyEventRhoZ() + { + fRhoZEventScene->DestroyElements(); + } +}; + +//===================================================================================== + + + +#endif + + diff --git a/UtilityApps/src/next_event_lcio.cpp b/UtilityApps/src/next_event_lcio.cpp index b54673b85..43b024de2 100644 --- a/UtilityApps/src/next_event_lcio.cpp +++ b/UtilityApps/src/next_event_lcio.cpp @@ -1,5 +1,6 @@ #include "TEveManager.h" #include "TEveStraightLineSet.h" +#include "TEvePointSet.h" #include <iostream> #include "lcio.h" @@ -7,97 +8,138 @@ #include "EVENT/LCCollection.h" #include "EVENT/SimCalorimeterHit.h" #include "EVENT/SimTrackerHit.h" +#include "EVENT/CalorimeterHit.h" +#include "EVENT/TrackerHit.h" +#include "UTIL/Operators.h" #include "DD4hep/TGeoUnits.h" +#include "MultiView.h" + using namespace lcio; //===================================================================================== -TEveElement* drawSimTrackerHits( lcio::LCCollection* col, const std::string& name ) ; -//===================================================================================== +template <class T> +TEveElement* createPointSet( lcio::LCCollection* col, const std::string& name, unsigned color=kMagenta, unsigned size=1, unsigned style=4 ) ; + + //===================================================================================== + + /**Helper class for printing LCIO objects from TEve + */ + template <class T> + class LCIOTObject : public TObject{ + const T* _obj ; + LCIOTObject() {} + public: + LCIOTObject( const T* o) : _obj(o) {} + void Print() { + std::cout << *_obj ; + } + } ; -void next_event(){ + void next_event(){ - static int count = 1 ; + static int count = 1 ; - static LCReader* rdr = 0 ; + static LCReader* rdr = 0 ; - std::string lcioFileName = "teve_infile.slcio" ; + std::string lcioFileName = "teve_infile.slcio" ; - if( rdr == 0 ){ - rdr = LCFactory::getInstance()->createLCReader() ; - rdr->open( lcioFileName ) ; - } + if( rdr == 0 ){ + rdr = LCFactory::getInstance()->createLCReader() ; + rdr->open( lcioFileName ) ; + } - std::cout << " next_event_lcio called ..." << std::endl ; + std::cout << " next_event_lcio called ..." << std::endl ; - TEveElementList* tevent = (TEveElementList* ) gEve->GetCurrentEvent() ; + TEveElementList* tevent = (TEveElementList* ) gEve->GetCurrentEvent() ; - if( tevent ) - tevent->DestroyElements() ; + if( tevent ) + tevent->DestroyElements() ; - LCEvent* evt = rdr->readNextEvent() ; - - if( evt != 0 ){ - - const std::vector< std::string >& colNames = * evt->getCollectionNames() ; + LCEvent* evt = rdr->readNextEvent() ; - for(unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){ + if( evt != 0 ){ - LCCollection* col = evt->getCollection( colNames[ icol ] ) ; + const std::vector< std::string >& colNames = * evt->getCollectionNames() ; - std::cout << " **** reading collection " << colNames[ icol ] << std::endl ; + for(unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){ + LCCollection* col = evt->getCollection( colNames[ icol ] ) ; - if( col->getTypeName() == LCIO::SIMTRACKERHIT ){ + std::cout << " **** reading collection " << colNames[ icol ] << std::endl ; - gEve->AddElement( drawSimTrackerHits( col , colNames[ icol ] ) ) ; + if( col->getTypeName() == LCIO::SIMTRACKERHIT ){ + + MultiView::instance()->ImportEvent( createPointSet<EVENT::SimTrackerHit>( col , colNames[ icol ] , kMagenta+2 , 1 , 4 ) ) ; + } + else if( col->getTypeName() == LCIO::SIMCALORIMETERHIT ){ + + MultiView::instance()->ImportEvent( createPointSet<EVENT::SimCalorimeterHit>( col , colNames[ icol ] , kMagenta+4 , 1 , 4 ) ) ; + } + else if( col->getTypeName() == LCIO::TRACKERHIT ){ + + MultiView::instance()->ImportEvent( createPointSet<EVENT::TrackerHit>( col , colNames[ icol ] , kBlue+2 , 1 , 4 ) ) ; + } + else if( col->getTypeName() == LCIO::CALORIMETERHIT ){ + + MultiView::instance()->ImportEvent( createPointSet<EVENT::CalorimeterHit>( col , colNames[ icol ] , kBlue+4 , 1 , 4 ) ) ; + } + } - - } - } else{ + } else{ - std::cout << "WARNING: can't read LCEvent from input file ! " << std::endl ; - } + std::cout << "WARNING: can't read LCEvent from input file ! " << std::endl ; + } - gEve->Redraw3D(); + gEve->Redraw3D(); - count += 3 ; -} - - -//===================================================================================== -TEveElement* drawSimTrackerHits( lcio::LCCollection* col, const std::string& name ) { - - TEveStraightLineSet* ls = new TEveStraightLineSet( name.c_str() ); - - int nHit = col->getNumberOfElements() ; - - // ls->AddLine( o.x(), o.y(), o.z(), ou.x() , ou.y() , ou.z() ) ; - - for( int i=0 ; i< nHit ; ++i ){ - - SimTrackerHit* hit = (SimTrackerHit*) col->getElementAt( i ) ; - - const double* pos = hit->getPosition() ; - - ls->AddMarker( pos[0]*tgeo::mm , pos[1]*tgeo::mm, pos[2]*tgeo::mm ); + count += 3 ; } - ls->SetMarkerColor( kGreen ) ; - ls->SetMarkerSize(1); - ls->SetMarkerStyle(4); - - // gEve->AddElement(ls); - - return ls; + //===================================================================================== + template <class T> + TEveElement* createPointSet( lcio::LCCollection* col, const std::string& name, unsigned color, unsigned size, unsigned style ) { + + TEvePointSet* ps = new TEvePointSet( name.c_str() ); + ps->SetOwnIds(kTRUE); + + int nHit = col->getNumberOfElements() ; + + for( int i=0 ; i< nHit ; ++i ){ + + T* hit = (T*) col->getElementAt( i ) ; + + double pos[3] = { hit->getPosition()[0], hit->getPosition()[1] , hit->getPosition()[2] } ; + // pos[0] = hit->getPosition()[0] ; + // pos[1] = hit->getPosition()[1] ; + // pos[2] = hit->getPosition()[2] ; + + ps->SetNextPoint( pos[0]*tgeo::mm , pos[1]*tgeo::mm, pos[2]*tgeo::mm ); + + int id[2] ; + id[0] = hit->getCellID0() ; + id[1] = hit->getCellID1() ; + + ps->SetPointIntIds( id ) ; + // does work for the point itself ... + // ps->SetSourceObject( new LCIOTObject<T>( hit ) ) ; + } + + ps->SetMarkerColor( color ) ; + ps->SetMarkerSize( size ); + ps->SetMarkerStyle( style ); + + return ps; + + + } + //===================================================================================== -} -//===================================================================================== diff --git a/UtilityApps/src/teve_display.cpp b/UtilityApps/src/teve_display.cpp index 3e642fee0..2c000d3e0 100644 --- a/UtilityApps/src/teve_display.cpp +++ b/UtilityApps/src/teve_display.cpp @@ -13,6 +13,7 @@ #include "DDRec/SurfaceManager.h" #include "EvNavHandler.h" +#include "MultiView.h" #include "run_plugin.h" #include "TRint.h" @@ -31,12 +32,16 @@ #include "TGLPerspectiveCamera.h" #include "TGLCamera.h" #include "TEveStraightLineSet.h" - +#include "TSysEvtHandler.h" +//#include "TEvePad.h" +#include <TEveScene.h> +#include <TEveProjectionManager.h> +#include <TEveProjectionAxes.h> +#include <TEveWindow.h> #include "TGeoManager.h" //#include "TGLUtil.h" #include "TGLClip.h" -//#include "TSysEvtHandler.h" #include "TMap.h" #include "TObjString.h" @@ -60,183 +65,8 @@ TEveStraightLineSet* getSurfaceVectors() ; //===================================================================================== -// class MultiView; -// MultiView* gMultiView = 0; - -//===================================================================================== -// class EvNavHandler { -// public: -// void Fwd() { -// next_event(); -// } -// void Bck() {} -// }; -//===================================================================================== -// Multi-view (3d, rphi, rhoz) service class using EVE Window Manager. -// Author: Matevz Tadel 2009 - -// #include <TEveManager.h> - -// #include <TEveViewer.h> -// #include <TGLViewer.h> - -// #include <TEveScene.h> - -// #include <TEveProjectionManager.h> -// #include <TEveProjectionAxes.h> - -// #include <TEveBrowser.h> -// #include <TEveWindow.h> - -// // MultiView -// // -// // Structure encapsulating standard views: 3D, r-phi and rho-z. -// // Includes scenes and projection managers. -// // -// // Should be used in compiled mode. - -// struct MultiView -// { -// TEveProjectionManager *fRPhiMgr; -// TEveProjectionManager *fRhoZMgr; - -// TEveViewer *f3DView; -// TEveViewer *fRPhiView; -// TEveViewer *fRhoZView; - -// TEveScene *fRPhiGeomScene; -// TEveScene *fRhoZGeomScene; -// TEveScene *fRPhiEventScene; -// TEveScene *fRhoZEventScene; - -// //--------------------------------------------------------------------------- - -// MultiView() -// { -// // Constructor --- creates required scenes, projection managers -// // and GL viewers. - -// // Scenes -// //======== - -// fRPhiGeomScene = gEve->SpawnNewScene("RPhi Geometry", -// "Scene holding projected geometry for the RPhi view."); -// fRhoZGeomScene = gEve->SpawnNewScene("RhoZ Geometry", -// "Scene holding projected geometry for the RhoZ view."); -// fRPhiEventScene = gEve->SpawnNewScene("RPhi Event Data", -// "Scene holding projected event-data for the RPhi view."); -// fRhoZEventScene = gEve->SpawnNewScene("RhoZ Event Data", -// "Scene holding projected event-data for the RhoZ view."); - - -// // Projection managers -// //===================== - -// fRPhiMgr = new TEveProjectionManager(TEveProjection::kPT_RPhi); -// gEve->AddToListTree(fRPhiMgr, kFALSE); -// { -// TEveProjectionAxes* a = new TEveProjectionAxes(fRPhiMgr); -// a->SetMainColor(kWhite); -// a->SetTitle("R-Phi"); -// a->SetTitleSize(0.05); -// a->SetTitleFont(102); -// a->SetLabelSize(0.025); -// a->SetLabelFont(102); -// fRPhiGeomScene->AddElement(a); -// } - -// fRhoZMgr = new TEveProjectionManager(TEveProjection::kPT_RhoZ); -// gEve->AddToListTree(fRhoZMgr, kFALSE); -// { -// TEveProjectionAxes* a = new TEveProjectionAxes(fRhoZMgr); -// a->SetMainColor(kWhite); -// a->SetTitle("Rho-Z"); -// a->SetTitleSize(0.05); -// a->SetTitleFont(102); -// a->SetLabelSize(0.025); -// a->SetLabelFont(102); -// fRhoZGeomScene->AddElement(a); -// } - - -// // Viewers -// //========= - -// TEveWindowSlot *slot = 0; -// TEveWindowPack *pack = 0; - -// slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight()); -// pack = slot->MakePack(); -// pack->SetElementName("Multi View"); -// pack->SetHorizontal(); -// pack->SetShowTitleBar(kFALSE); -// pack->NewSlot()->MakeCurrent(); -// f3DView = gEve->SpawnNewViewer("3D View", ""); -// f3DView->AddScene(gEve->GetGlobalScene()); -// f3DView->AddScene(gEve->GetEventScene()); - -// pack = pack->NewSlot()->MakePack(); -// pack->SetShowTitleBar(kFALSE); -// pack->NewSlot()->MakeCurrent(); -// fRPhiView = gEve->SpawnNewViewer("RPhi View", ""); -// fRPhiView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY); -// fRPhiView->AddScene(fRPhiGeomScene); -// fRPhiView->AddScene(fRPhiEventScene); - -// pack->NewSlot()->MakeCurrent(); -// fRhoZView = gEve->SpawnNewViewer("RhoZ View", ""); -// fRhoZView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY); -// fRhoZView->AddScene(fRhoZGeomScene); -// fRhoZView->AddScene(fRhoZEventScene); -// } - -// //--------------------------------------------------------------------------- - -// void SetDepth(Float_t d) -// { -// // Set current depth on all projection managers. - -// fRPhiMgr->SetCurrentDepth(d); -// fRhoZMgr->SetCurrentDepth(d); -// } - -// //--------------------------------------------------------------------------- - -// void ImportGeomRPhi(TEveElement* el) -// { -// fRPhiMgr->ImportElements(el, fRPhiGeomScene); -// } - -// void ImportGeomRhoZ(TEveElement* el) -// { -// fRhoZMgr->ImportElements(el, fRhoZGeomScene); -// } - -// void ImportEventRPhi(TEveElement* el) -// { -// fRPhiMgr->ImportElements(el, fRPhiEventScene); -// } - -// void ImportEventRhoZ(TEveElement* el) -// { -// fRhoZMgr->ImportElements(el, fRhoZEventScene); -// } - -// //--------------------------------------------------------------------------- - -// void DestroyEventRPhi() -// { -// fRPhiEventScene->DestroyElements(); -// } - -// void DestroyEventRhoZ() -// { -// fRhoZEventScene->DestroyElements(); -// } -// }; -//===================================================================================== - static long teve_display(LCDD& lcdd, int /* argc */, char** /* argv */) { + TGeoManager* mgr = &lcdd.manager(); TEveManager::Create(); @@ -262,44 +92,52 @@ static long teve_display(LCDD& lcdd, int /* argc */, char** /* argv */) { gEve->AddGlobalElement( tn ); - gEve->AddGlobalElement( getSurfaceVectors() ) ; - gEve->AddGlobalElement( getSurfaces() ) ; - // gMultiView = new MultiView; - // gMultiView->ImportGeomRPhi( tn ); - // gMultiView->ImportGeomRhoZ( tn ); + TEveElement* surfaces = getSurfaces() ; + TEveElement* surfaceVectors = getSurfaceVectors() ; + + gEve->AddGlobalElement( surfaces ) ; + gEve->AddGlobalElement( surfaceVectors ) ; + + TGLViewer *v = gEve->GetDefaultGLViewer(); + // v->GetClipSet()->SetClipType(TGLClip::kClipPlane); + // v->ColorSet().Background().SetColor(kMagenta+4); + v->ColorSet().Background().SetColor(kWhite); + v->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0); + v->RefreshPadEditor(v); + // v->CurrentCamera().RotateRad(-1.2, 0.5); + + + // -- tgeo shapes cannot be projected ... + // MultiView::instance()->ImportGeomRPhi( tn ); + // MultiView::instance()->ImportGeomRhoZ( tn ); + MultiView::instance()->ImportGeomRPhi( surfaces ); + MultiView::instance()->ImportGeomRhoZ( surfaces ) ; + //-- don't show the surface vectors... + //MultiView::instance()->ImportGeomRPhi( surfaceVectors ); + //MultiView::instance()->ImportGeomRhoZ( surfaceVectors ); + make_gui(); + next_event(); gEve->FullRedraw3D(kTRUE); - - // // EClipType not exported to CINT (see TGLUtil.h): - // // 0 - no clip, 1 - clip plane, 2 - clip box - // TGLViewer *v = gEve->GetDefaultGLViewer(); - // // v->GetClipSet()->SetClipType(TGLClip::kClipPlane); - // // v->ColorSet().Background().SetColor(kMagenta+4); - // v->ColorSet().Background().SetColor(kWhite); - // v->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0); - // v->RefreshPadEditor(v); - // // v->CurrentCamera().RotateRad(-1.2, 0.5); - // v->DoDraw(); - return 1; } DECLARE_APPLY(DD4hepTEveDisplay,teve_display) -//______________________________________________________________________________ + +//===================================================================================================================== + int main(int argc,char** argv) { return main_default("DD4hepTEveDisplay",argc,argv); } +//===================================================================================================================== - - -//===================================================================================================================== TEveStraightLineSet* getSurfaceVectors() { TEveStraightLineSet* ls = new TEveStraightLineSet("SurfaceVectors"); -- GitLab