DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
CaloLego.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DDEve/CaloLego.h>
16 #include <DDEve/Annotation.h>
17 #include <DDEve/Factories.h>
18 #include <DD4hep/InstanceCount.h>
19 
20 // Root include files
21 #include <TH2.h>
22 #include <TEveCalo.h>
23 #include <TEveTrans.h>
24 #include <TEveScene.h>
25 #include <TGLViewer.h>
26 #include <TGLWidget.h>
27 #include <TEveCaloLegoOverlay.h>
28 #include <TEveLegoEventHandler.h>
29 
30 // C/C++ include files
31 #include <limits>
32 
33 using namespace dd4hep;
34 
37 
38 CaloLego::CaloLego(Display* eve, const std::string& nam)
40 : View(eve, nam)
41 {
42  InstanceCount::increment(this);
43 }
44 
46 CaloLego::~CaloLego() {
48 }
49 
50 
52 View& CaloLego::Build(TEveWindow* slot) {
55  return Map(slot);
56 }
57 
60  DisplayConfiguration::Configurations::const_iterator j = config.subdetectors.begin();
63 
64  ctx.eveHist = new TEveCaloDataHist();
65  for( ; j != config.subdetectors.end(); ++j ) {
66  const char* n = (*j).name.c_str();
69  if ( calo.config.use.empty() ) {
70  for(int isl = 0; isl<calo.eveHist->GetNSlices(); ++isl) {
71  int nslice = ctx.eveHist->GetNSlices();
72  TH2F* h = new TH2F(*calo.eveHist->GetHist(isl));
73  ctx.eveHist->AddHistogram(h);
74  ctx.eveHist->RefSliceInfo(nslice).Setup(n,cd.threshold,cd.color,101);
75  Annotation* a = new Annotation(viewer(),n,Annotation::DefaultMargin(),legend_y,cd.color);
76  legend_y += a->GetTextSize();
77  }
78  }
79  }
80  TEveCaloLego* lego = new TEveCaloLego(ctx.eveHist);
81  ImportGeo(lego);
82  ctx.caloViz = lego;
83  ctx.caloViz->SetPlotEt(kFALSE);
84  // By the default lego extends is (1x1x1). Resize it to put in 'natural'
85  // coordinates, so that y extend in 2*Pi and set height of lego two times
86  // smaller than y extend to have better view in 3D perspective.
87  lego->InitMainTrans();
88  lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
89 
90  // draws scales and axis on borders of window
91  TGLViewer* glv = viewer()->GetGLViewer();
92  TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
93  glv->AddOverlayElement(overlay);
94  overlay->SetCaloLego(lego);
95 
96  // set event handler to move from perspective to orthographic view.
97  glv->SetEventHandler(new TEveLegoEventHandler(glv->GetGLWidget(), glv, lego));
98  glv->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
99  ctx.eveHist->GetEtaBins()->SetTitleFont(120);
100  ctx.eveHist->GetEtaBins()->SetTitle("h");
101  ctx.eveHist->GetPhiBins()->SetTitleFont(120);
102  ctx.eveHist->GetPhiBins()->SetTitle("f");
103  ctx.eveHist->IncDenyDestroy();
104  ctx.eveHist->DataChanged();
105 }
106 
109  DisplayConfiguration::Configurations::const_iterator j = config.subdetectors.begin();
110  printout(INFO,"CaloLego","+++ Import geometry topics for view %s.",name().c_str());
111  for(int ihist=0; j != config.subdetectors.end(); ++j) {
112  const char* n = (*j).name.c_str();
114  if ( ctx.config.use.empty() ) {
115  for(int isl = 0; isl<ctx.eveHist->GetNSlices(); ++isl) {
116  TH2F* global = ctx.eveHist->GetHist(isl);
117  TH2F* local = m_data.eveHist->GetHist(ihist);
118  *local = *global;
119  ihist++;
120  }
121  }
122  }
123  m_data.eveHist->DataChanged();
124 }
125 
127 void CaloLego::ImportGeoTopics(const std::string&) {
128 }
dd4hep::Display
The main class of the DDEve display.
Definition: Display.h:56
dd4hep::CaloLego::ConfigureGeometry
virtual void ConfigureGeometry(const DisplayConfiguration::ViewConfig &config) override
Configure a single geometry view.
Definition: CaloLego.cpp:59
dd4hep::DisplayConfiguration::Config::Values::calodata
Calodata calodata
Definition: DisplayConfiguration.h:99
dd4hep::View::m_eve
Display * m_eve
Definition: View.h:49
DECLARE_VIEW_FACTORY
#define DECLARE_VIEW_FACTORY(x)
Definition: Factories.h:30
dd4hep::Annotation::DefaultTextSize
static float DefaultTextSize()
Default text size.
Definition: Annotation.cpp:50
dd4hep::CaloLego::ConfigureEvent
virtual void ConfigureEvent(const DisplayConfiguration::ViewConfig &config) override
Configure a single event scene view.
Definition: CaloLego.cpp:108
dd4hep::DisplayConfiguration::Config::data
union dd4hep::DisplayConfiguration::Config::Values data
dd4hep::View::Map
virtual View & Map(TEveWindow *slot)
Map the view view to the slot.
Definition: View.cpp:334
dd4hep::CaloLego
Lego plot for calorimeter energy deposits.
Definition: CaloLego.h:35
dd4hep::DisplayConfiguration::ViewConfig::subdetectors
Configurations subdetectors
Definition: DisplayConfiguration.h:122
dd4hep::CaloLego::ImportGeoTopics
void ImportGeoTopics(const std::string &title) override
Call to import geometry topics.
Definition: CaloLego.cpp:127
Factories.h
dd4hep::CaloLego::m_data
Display::CalodataContext m_data
Definition: CaloLego.h:36
dd4hep::DisplayConfiguration::Defaults::color
int color
Definition: DisplayConfiguration.h:58
ClassImp
ClassImp(CaloLego) CaloLego
Initializing constructor.
Definition: CaloLego.cpp:35
dd4hep::View::name
const std::string & name() const
Access to the view name/title.
Definition: View.h:81
dd4hep::Display::GetCaloHistogram
CalodataContext & GetCaloHistogram(const std::string &name)
Access to calo data histograms by name as defined in the configuration.
Definition: Display.cpp:196
dd4hep::Display::CalodataContext::eveHist
TEveCaloDataHist * eveHist
Definition: Display.h:72
dd4hep::View::AddToGlobalItems
virtual TEveElementList * AddToGlobalItems(const std::string &nam)
Add the view to the global list of eve objects.
Definition: View.cpp:81
slot
View TEveWindowSlot * slot
Definition: MultiView.cpp:28
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::View::CreateGeoScene
virtual View & CreateGeoScene()
Create the geometry scene.
Definition: View.cpp:324
dd4hep::Annotation::DefaultMargin
static float DefaultMargin()
Default margin for placement in bottom left corner.
Definition: Annotation.cpp:54
dd4hep::Display::CalodataContext::config
DisplayConfiguration::Config config
Definition: Display.h:73
dd4hep::View::viewer
TEveViewer * viewer() const
Access to the Eve viewer.
Definition: View.h:84
CaloLego.h
dd4hep::DisplayConfiguration::ViewConfig
View configuration.
Definition: DisplayConfiguration.h:119
dd4hep::Annotation
Class to add annotations to eve viewers.
Definition: Annotation.h:34
dd4hep::DisplayConfiguration::Calodata::threshold
float threshold
Definition: DisplayConfiguration.h:69
dd4hep::DisplayConfiguration::Calodata
Configuration class for 3D calorimeter data display.
Definition: DisplayConfiguration.h:68
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::View
class View View.h DDEve/View.h
Definition: View.h:45
dd4hep::Display::CalodataContext
Calorimeter data context for the DDEve event display.
Definition: Display.h:68
dd4hep::Display::CalodataContext::caloViz
TEveCaloViz * caloViz
Definition: Display.h:71
dd4hep::CaloLego::Build
virtual View & Build(TEveWindow *slot) override
Build the projection view and map it to the given slot.
Definition: CaloLego.cpp:52
InstanceCount.h
dd4hep::CaloLego::CaloLego
CaloLego(Display *eve, const std::string &name)
Initializing constructor.
Annotation.h
dd4hep::View::ImportGeo
virtual void ImportGeo(const std::string &topic, TEveElement *element)
Call to import geometry elements into topics.
Definition: View.cpp:215
dd4hep::DisplayConfiguration::Config::use
std::string use
Definition: DisplayConfiguration.h:105