DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloLego.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DDEve/CaloLego.h"
17 #include "DDEve/Annotation.h"
18 #include "DDEve/Factories.h"
19 #include "DD4hep/InstanceCount.h"
20 
21 // Root include files
22 #include "TH2.h"
23 #include "TEveCalo.h"
24 #include "TEveTrans.h"
25 #include "TEveScene.h"
26 #include "TGLViewer.h"
27 #include "TGLWidget.h"
28 #include "TEveCaloLegoOverlay.h"
29 #include "TEveLegoEventHandler.h"
30 
31 #include <limits>
32 using namespace std;
33 using namespace DD4hep;
34 
37 
39 CaloLego::CaloLego(Display* eve, const std::string& nam)
40 : View(eve, nam)
41 {
42  InstanceCount::increment(this);
43 }
44 
46 CaloLego::~CaloLego() {
47  InstanceCount::decrement(this);
48 }
49 
50 
52 View& CaloLego::Build(TEveWindow* slot) {
53  CreateGeoScene();
54  AddToGlobalItems(name());
55  return Map(slot);
56 }
57 
59 void CaloLego::ConfigureGeometry(const DisplayConfiguration::ViewConfig& config) {
60  DisplayConfiguration::Configurations::const_iterator j = config.subdetectors.begin();
61  Display::CalodataContext& ctx = m_data;
62  float legend_y = Annotation::DefaultTextSize()+Annotation::DefaultMargin();
63 
64  ctx.eveHist = new TEveCaloDataHist();
65  for( ; j != config.subdetectors.end(); ++j ) {
66  const char* n = (*j).name.c_str();
67  Display::CalodataContext& calo = m_eve->GetCaloHistogram(n);
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 
108 void CaloLego::ConfigureEvent(const DisplayConfiguration::ViewConfig& config) {
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();
113  const Display::CalodataContext& ctx = m_eve->GetCaloHistogram(n);
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 string&) {
128 }
#define DECLARE_VIEW_FACTORY(x)
Definition: Factories.h:31
TEveCaloDataHist * eveHist
Definition: Display.h:72
Lego plot for calorimeter energy deposits.
Definition: CaloLego.h:36
DisplayConfiguration::Config config
Definition: Display.h:73
union DD4hep::DisplayConfiguration::Config::Values data
View TEveWindowSlot * slot
Definition: MultiView.cpp:30
class View View.h DDEve/View.h
Definition: View.h:46
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
ClassImp(CaloLego) CaloLego
Initializing constructor.
Definition: CaloLego.cpp:35
The main class of the DDEve display.
Definition: Display.h:57
Class to add annotations to eve viewers.
Definition: Annotation.h:35