40 #include "TGFileDialog.h"
41 #include "TEveScene.h"
42 #include "TEveBrowser.h"
43 #include "TEveManager.h"
44 #include "TEveCaloData.h"
46 #include "TEveViewer.h"
47 #include "TEveCompound.h"
48 #include "TEveBoxSet.h"
49 #include "TEvePointSet.h"
50 #include "TEveTrackPropagator.h"
51 #include "TGeoManager.h"
58 using namespace DD4hep;
59 using namespace DD4hep::Geometry;
65 void EveDisplay(
const char* xmlConfig = 0,
const char* eventFileName = 0) {
67 if ( xmlConfig != 0 ) {
69 ::snprintf(text,
sizeof(text),
"%s%s",strncmp(xmlConfig,
"file:",5)==0 ?
"file:" :
"",xmlConfig);
73 display->
MessageBox(
INFO,
"No DDEve setup given.\nYou need to choose now.....\n"
74 "If you need an example, open\n\n"
75 "examples/CLIDSid/eve/DDEve.xml\n"
76 "and the corresponding event data\n"
77 "examples/CLIDSid/eve/CLICSiD_Events.root\n\n\n",
78 "Need to choos setup file");
82 if (eventFileName != 0) {
89 Display::CalodataContext::CalodataContext()
90 : slice(0), calo3D(0), caloViz(0), eveHist(0), config()
95 : slice(c.slice), calo3D(c.calo3D), caloViz(c.caloViz), eveHist(c.eveHist), config(c.config)
101 if ( &c ==
this )
return *
this;
115 TEveBrowser* br =
m_eve->GetBrowser();
116 TGMenuBar*
bar = br->GetMenuBar();
124 br->ShowCloseTab(kFALSE);
125 m_eve->GetViewers()->SwitchColorSet();
126 TFile::SetCacheFileDir(
".");
128 br->SetTabTitle(
"Global Scene",TRootBrowser::kRight,0);
133 TRootBrowser* br =
m_eve->GetBrowser();
164 m_eve->FullRedraw3D(kTRUE);
170 throw runtime_error(
"This call is not implemented !");
193 throw runtime_error(
"Invalid event handler");
199 menu->
Build(bar, hints);
200 m_eve->FullRedraw3D(kTRUE);
205 DisplayConfiguration::ViewConfigurations::const_iterator i;
206 for(i=config.
views.begin(); i!=config.
views.end(); ++i)
209 DisplayConfiguration::Configurations::const_iterator j;
227 const char* n = nam.c_str();
230 h->SetTitle(hits.c_str());
231 ctx.
eveHist =
new TEveCaloDataHist();
235 ctx.
eveHist->GetEtaBins()->SetTitleFont(120);
236 ctx.
eveHist->GetEtaBins()->SetTitle(
"h");
237 ctx.
eveHist->GetPhiBins()->SetTitleFont(120);
238 ctx.
eveHist->GetPhiBins()->SetTitle(
"f");
245 ctx.
calo3D->SetAutoRange(kTRUE);
259 i =
m_calodata.insert(make_pair(nam,ctx)).first;
262 throw runtime_error(
"Cannot access calodata configuration "+nam);
269 ViewConfigurations::const_iterator i =
m_viewConfigs.find(nam);
294 string path = TString::Format(
"%s/icons/", gSystem->Getenv(
"ROOTSYS")).Data();
295 const TGPicture* pic = 0;
297 pic =
client().GetPicture((path+
"mb_asterisk_s.xpm").c_str());
298 else if ( level ==
DEBUG )
299 pic =
client().GetPicture((path+
"mb_asterisk_s.xpm").c_str());
300 else if ( level ==
INFO )
301 pic =
client().GetPicture((path+
"mb_asterisk_s.xpm").c_str());
303 pic =
client().GetPicture((path+
"mb_excalamation_s.xpm").c_str());
304 else if ( level ==
ERROR )
305 pic =
client().GetPicture((path+
"mb_stop.xpm").c_str());
306 else if ( level ==
FATAL )
307 pic =
client().GetPicture((path+
"interrupt.xpm").c_str());
308 new TGMsgBox(gClient->GetRoot(),0,title.c_str(),text.c_str(),pic,
309 kMBDismiss,0,kVerticalFrame,kTextLeft|kTextCenterY);
314 static const char *evtFiletypes[] = {
315 "xml files",
"*.xml",
316 "XML files",
"*.XML",
321 fi.fFileTypes = evtFiletypes;
322 fi.fIniDir = StrDup(default_dir.c_str());
324 new TGFileDialog(
client().GetRoot(), 0, kFDOpen, &fi);
325 if ( fi.fFilename ) {
326 string ret = fi.fFilename;
327 if ( ret.find(
"file:") != 0 )
return "file:"+ret;
335 static const char *evtFiletypes[] = {
336 "ROOT files",
"*.root",
337 "SLCIO files",
"*.slcio",
338 "LCIO files",
"*.lcio",
343 fi.fFileTypes = evtFiletypes;
344 fi.fIniDir = StrDup(default_dir.c_str());
346 new TGFileDialog(
client().GetRoot(), 0, kFDOpen, &fi);
347 if ( fi.fFilename ) {
356 bar =
m_eve->GetBrowser()->GetMenuBar();
370 TFile* f = TFile::Open(name);
371 if ( f && !f->IsZombie() )
return f;
372 throw runtime_error(
"+++ Failed to open ROOT file:"+
string(name));
378 typedef vector<EventHandler::Collection> Collections;
379 const Types& types = handler->
data();
380 TEveElement* particles = 0;
383 manager().GetEventScene()->DestroyElements();
384 for(Types::const_iterator ityp=types.begin(); ityp!=types.end(); ++ityp) {
385 const Collections& colls = (*ityp).second;
386 for(Collections::const_iterator j=colls.begin(); j!=colls.end(); ++j) {
387 size_t len = (*j).second;
388 const char* nam = (*j).first;
396 if ( cfg.
hits ==
"PointSet" ) {
401 else if ( cfg.
hits ==
"BoxSet" ) {
406 else if ( cfg.
hits ==
"TowerSet" ) {
431 MCParticleCreator cr(
new TEveTrackPropagator(
"",
"",
new TEveMagFieldDuo(350, -3.5, 2.0)),
432 new TEveCompound(
"MC_Particles",
"MC_Particles"),cfg);
441 (*i).second.eveHist->GetHist(0)->Reset();
444 TH2F* h = ctx.
eveHist->GetHist(0);
448 printout(
INFO,
"FillEtaPhiHistogram",
"+++ %s: Filled %ld hits from %s....",
457 (*i)->ConfigureEventFromInfo();
476 GetGeo().AddElement(topic);
479 return *((*i).second);
486 throw runtime_error(
"Display: Attempt to access non-existing geometry topic:"+name);
488 return *((*i).second);
497 manager().GetEventScene()->AddElement(topic);
500 return *((*i).second);
507 throw runtime_error(
"Display: Attempt to access non-existing event topic:"+name);
509 return *((*i).second);
529 manager().GetEventScene()->AddElement(el);
534 using namespace DD4hep::Geometry;
536 if ( world.children().size() == 0 ) {
537 MessageBox(
INFO,
"It looks like there is no\nGeometry loaded.\nNo event display availible.\n");
539 else if ( levels > 0 ) {
545 printout(
INFO,
"Display",
"+++ Load children of %s to %d levels",
546 world.placement().name(), levels);
547 for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) {
552 if ( e.second && e.first ) {
553 parent.AddElement(e.second);
558 TGeoNode* n = (TGeoNode*)start->GetUserData();
562 const char* node_name = n->GetName();
565 pair<bool,TEveElement*>
e(
false,0);
567 for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) {
574 if ( !e.first && !e.second ) {
578 start->AddElement(e.second);
580 printout(
INFO,
"Display",
"+++ Import geometry node %s with %d levels.",node_name, levels);
583 printout(
INFO,
"Display",
"+++ FAILED to import geometry node %s with %d levels.",node_name, levels);
598 printout(
INFO,
"Display",
"+++ %s element %s with a depth of %d.",
DataConfigurations m_calodataConfigs
Handle class to hold the information of a sensitive detector.
const ViewConfig * GetViewConfiguration(const std::string &name) const
Access a data filter by name. Data filters are used to customize views.
std::pair< bool, TEveElement * > createEveShape(int level, int max_level, TEveElement *p, TGeoNode *n, TGeoHMatrix mat, const std::string &node_name)
Calodata m_calodata
Container with calorimeter data (projections)
IFACE * addExtension(CONCRETE *c)
Extend the sensitive detector element with an arbitrary structure accessible by the type...
virtual size_t collectionLoop(const std::string &collection, DDEveHitActor &actor)
Loop over collection and extract data.
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
ViewConfigurations m_viewConfigs
void LoadGeoChildren(TEveElement *start, int levels, bool redraw)
Load 'levels' Children into the geometry scene.
TEveManager & manager() const
Access to the EVE manager.
const char * name() const
Access the object name (or "" if not supported by the object)
void deletePtr(T *&p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
virtual CollectionType collectionType(const std::string &collection) const =0
Access to the collection type by name.
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
bool isValid() const
Check the validity of the object held by the handle.
void ImportEvent(TEveElement *el)
Call to import top level event elements.
virtual bool Open(const std::string &type, const std::string &file_name)
Open a new event data file.
DataConfigurations m_collectionsConfigs
TEveCaloDataHist * eveHist
virtual size_t collectionLoop(const std::string &collection, DDEveHitActor &actor)=0
Loop over collection and extract hit data.
std::pair< bool, TEveElement * > LoadDetElement(Geometry::DetElement element, int levels, TEveElement *parent)
TEveElement * element() const
Return eve element.
int findNodeWithMatrix(TGeoNode *p, TGeoNode *n, TGeoHMatrix *mat, std::string *sub_path=0)
Fill a 3D pointset from a hit collection.
CalodataContext & GetCaloHistogram(const std::string &name)
Access to calo data histograms by name as defined in the configuration.
ClassImp(Display) namespace DD4hep
Event handler base class. Interface to all DDEve I/O actions.
Local implementation with overrides of the TEveElementList.
DisplayConfiguration::Config config
virtual ~Display()
Default destructor.
Geometry::LCDD & lcdd() const
Access to geometry hub.
static LCDD & getInstance(void)
—Factory method----—
virtual SensitiveDetector sensitiveDetector(const std::string &name) const =0
Retrieve a sensitive detector by it's name from the detector description.
virtual void fromXML(const std::string &fname, LCDDBuildType type=BUILD_DEFAULT)=0
Read any geometry description or alignment file.
TEveManager * m_eve
Reference to TEve manager.
T * ptr() const
Access to the held object.
virtual const TypedEventCollections & data() const =0
Access the map of simulation data collections.
virtual void UnregisterEvents(View *view)
Unregister from the main event scene.
virtual void OnNewEvent(EventHandler *handler)
EventConsumer overload: Consumer event data.
virtual void Subscribe(EventConsumer *display)
Subscribe to notification of new data present.
virtual TEveElementList & GetGeoTopic(const std::string &name)
Access/Create an geometry topic by name.
const DataConfig * GetCalodataConfiguration(const std::string &name) const
Access a data filter by name. Data filters are used to customize views.
Event handler base class. Interface to all DDEve I/O actions.
Configurations collections
Fill EtaPhi histograms from a hit collection.
TFile * Open(const char *rootFile) const
Open ROOT file.
virtual void AddMenu(TGMenuBar *bar, PopupMenu *menu, int hints=kLHintsNormal)
Add new menu to the main menu bar.
TEveElement * element() const
Return eve element.
const char * GetName(T *p)
class View View.h DDEve/View.h
DisplayConfiguration DisplayConfiguration.h DDEve/DisplayConfiguration.h.
void close()
Close compounds.
std::string getEventHandlerName()
Get Event Handler Plugin name.
virtual void RegisterEvents(View *view)
Register to the main event scene on new events.
Fill eve particles from a MC particle collection.
void ChooseGeometry()
Load geometry with panel.
GenericEventHandler * m_evtHandler
Reference to the event reader object.
GenericEventHandler & eventHandler() const
Access to the event reader.
void ImportGeo(TEveElement *el)
Call to import geometry elements.
void LoadGeometryRoot(const char *rootFile)
Load geometry from compact xml file.
std::string OpenXmlFileDialog(const std::string &default_dir) const
Popup XML file chooser. returns chosen file name; empty on cancel.
void MakeNodesVisible(TEveElement *e, bool visible, int level)
Make a set of nodes starting from a top element (in-)visible with a given depth.
Fill a 3D box set from a hit collection.
PlacedVolume placement() const
Access to the physical volume of this detector element.
TEveElementList * m_geoGlobal
virtual TGeoManager & manager() const =0
Access the geometry manager of this instance.
void ImportConfiguration(const DisplayConfiguration &config)
Import configuration parameters.
void LoadXML(const char *xmlFile)
Load geometry from compact xml file.
virtual TEveElementList & GetEveTopic(const std::string &name)
Access/Create an event topic by name.
std::string OpenEventFileDialog(const std::string &default_dir) const
Popup ROOT file chooser. returns chosen file name; empty on cancel.
void MessageBox(PrintLevel level, const std::string &text, const std::string &title="") const
Open standard message box.
Handle class describing a detector element.
std::map< std::string, std::vector< Collection > > TypedEventCollections
Types collection: collections are grouped by type (class name)
TEveElementList & GetGeo()
Access / Create global geometry element.
int m_loadLevel
Load level for the eve geometry.
Fill a 3D tower set from a hit collection.
TGClient & client() const
Access to X-client.
The main interface to the DD4hep detector description package.
std::map< std::string, DetElement > Children
virtual void BuildMenus(TGMenuBar *bar=0)
Build the DDEve specific menues. Default bar is the ROOT browser's bar.
Geometry::LCDD * m_lcdd
Reference to geometry hub.
int m_visLevel
TGeoManager visualisation level.
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
void destroyData(bool destroy_mgr=true)
Assignment operator.
Display(TEveManager *eve)
Standard constructor.
The main class of the DDEve display.
T * removeExtension(bool destroy=true)
Remove an existing extension object from the LCDD instance. If not destroyed, the instance is returne...
void EveDisplay(const char *xmlFile, const char *eventFileName)
CalodataContext & operator=(const CalodataContext &c)
void MakeNodesVisible(TEveElement *e, bool visible, int level)
Make a set of nodes starting from a top element (in-)visible with a given depth.
Data implementation class of the LCDD interface.
TEveElementList * m_eveGlobal