Logo ROOT   6.12/07
Reference Guide
calorimeters.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_eve
3 /// Demonstrates usage of EVE calorimetry classes.
4 ///
5 /// \image html eve_calorimeters.png
6 /// \macro_code
7 ///
8 /// \author Alja Mrak-Tadel
9 
10 #include "TEveProjections.h"
11 #include "TSystem.h"
12 #include "TEveCalo.h"
13 #include "TEveWindow.h"
14 #include "TEveManager.h"
15 #include "TEveBrowser.h"
16 #include "TEveProjectionAxes.h"
17 #include "TEveScene.h"
18 #include "TEveViewer.h"
19 #include "TEveTrans.h"
20 #include "TEveCaloLegoOverlay.h"
21 #include "TEveLegoEventHandler.h"
22 #include "TEveGedEditor.h"
23 #include "TEveJetCone.h"
24 
25 #include "TGLWidget.h"
26 #include "TGLViewer.h"
27 #include "TGTab.h"
28 
29 #include "TFile.h"
30 #include "TAxis.h"
31 
32 
33 const char* histFile =
34  "http://amraktad.web.cern.ch/amraktad/cms_calo_hist.root";
35 
36 TEveCaloLego* MakeCaloLego(TEveCaloData* data, TEveWindowSlot* slot);
37 TEveCalo2D* MakeCalo2D(TEveCalo3D* calo3d, TEveWindowSlot* slot, TEveProjection::EPType_e t);
38 TEveCalo3D* MakeCalo3D(TEveCaloData* data, TEveWindowSlot* slot);
39 TEveCalo2D* MakeCalo2D(TEveCalo3D* calo3d, TEveWindowSlot* slot, TEveProjection::EPType_e t);
40 void MakeViewerScene(TEveWindowSlot* slot, TEveViewer*& v, TEveScene*& s);
41 void add_jet(TEveElement*, const char*, Float_t, Float_t, Float_t, Float_t);
42 
43 void calorimeters()
44 {
45  // gSystem->IgnoreSignal(kSigSegmentationViolation, true);
47 
48  // event data
50  TFile* hf = TFile::Open(histFile, "CACHEREAD");
51  TH2F* ecalHist = (TH2F*)hf->Get("ecalLego");
52  TH2F* hcalHist = (TH2F*)hf->Get("hcalLego");
54  data->AddHistogram(ecalHist);
55  data->RefSliceInfo(0).Setup("ECAL", 0.3, kBlue);
56  data->AddHistogram(hcalHist);
57  data->RefSliceInfo(1).Setup("HCAL", 0.1, kRed);
58  data->GetEtaBins()->SetTitleFont(120);
59  data->GetEtaBins()->SetTitle("h");
60  data->GetPhiBins()->SetTitleFont(120);
61  data->GetPhiBins()->SetTitle("f");
62  data->IncDenyDestroy();
63  gEve->AddToListTree(data, kFALSE);
64 
65 
66  // first tab
67  TEveCaloLego* lego = MakeCaloLego(data, 0);
68 
69  //
70  // second tab
71  //
72 
73  // frames
74  TEveWindowSlot* slot =
76  TEveWindowPack* packH = slot->MakePack();
77  packH->SetElementName("Projections");
78  packH->SetHorizontal();
79  packH->SetShowTitleBar(kFALSE);
80 
81  slot = packH->NewSlot();
82  TEveWindowPack* pack0 = slot->MakePack();
83  pack0->SetShowTitleBar(kFALSE);
84  TEveWindowSlot* slotLeftTop = pack0->NewSlot();
85  TEveWindowSlot* slotLeftBottom = pack0->NewSlot();
86 
87  slot = packH->NewSlot();
88  TEveWindowPack* pack1 = slot->MakePack();
89  pack1->SetShowTitleBar(kFALSE);
90  TEveWindowSlot* slotRightTop = pack1->NewSlot();
91  TEveWindowSlot* slotRightBottom = pack1->NewSlot();
92 
93  // viewers ans scenes in second tab
94  TEveCalo3D* calo3d = MakeCalo3D(data, slotRightTop);
95  MakeCalo2D(calo3d, slotLeftTop, TEveProjection::kPT_RPhi);
96  MakeCalo2D(calo3d, slotLeftBottom, TEveProjection::kPT_RhoZ);
97  lego = MakeCaloLego(data, slotRightBottom);
98 
99 
100  gEve->GetBrowser()->GetTabRight()->SetTab(1);
101  gEve->Redraw3D(kTRUE);
102 }
103 
104 //______________________________________________________________________________
105 TEveCaloLego* MakeCaloLego(TEveCaloData* data, TEveWindowSlot* slot)
106 {
107  // Eta-phi lego view.
108 
109  TEveViewer* v;
110  TEveScene* s;
111  if (slot)
112  {
113  MakeViewerScene(slot, v, s);
114  } else {
115  v = gEve->GetDefaultViewer();
116  s = gEve->GetEventScene();
117  }
118  v->SetElementName("Viewer - Lego");
119  s->SetElementName("Scene - Lego");
120 
121  TEveCaloLego* lego = new TEveCaloLego(data);
122  s->AddElement(lego);
123 
124  // By the default lego extends is (1x1x1). Resize it to put in 'natural'
125  // coordinates, so that y extend in 2*Pi and set height of lego two times
126  // smaller than y extend to have better view in 3D perspective.
127  lego->InitMainTrans();
129 
130  // draws scales and axis on borders of window
131  TGLViewer* glv = v->GetGLViewer();
132  TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
133  glv->AddOverlayElement(overlay);
134  overlay->SetCaloLego(lego);
135 
136  // set event handler to move from perspective to orthographic view.
138  glv->SetEventHandler
139  (new TEveLegoEventHandler(glv->GetGLWidget(), glv, lego));
140  gEve->AddToListTree(lego, kTRUE);
141 
142  return lego;
143 }
144 
145 //______________________________________________________________________________
146 TEveCalo3D* MakeCalo3D(TEveCaloData* data, TEveWindowSlot* slot)
147 {
148  // 3D catersian view.
149 
150  TEveViewer* v; TEveScene* s;
151  MakeViewerScene(slot, v, s);
152  v->SetElementName("Viewer - 3D");
153  s->SetElementName("Scene - 3D");
154 
155  TEveCalo3D* calo3d = new TEveCalo3D(data);
156  calo3d->SetBarrelRadius(129.00);
157  calo3d->SetEndCapPos(268.36);
158  s->AddElement(calo3d);
159 
160  add_jet(calo3d, "JetCone Lojz", 1.4, 1.0, 0.4, 0.2);
161  add_jet(calo3d, "JetCone Mici", -2.0, -2.1, 0.2, 0.4);
162 
163  return calo3d;
164 }
165 
166 //______________________________________________________________________________
167 TEveCalo2D* MakeCalo2D(TEveCalo3D* calo3d, TEveWindowSlot* slot,
169 {
170  // Projected calorimeter.
171 
172  TEveViewer* v; TEveScene* s;
173  MakeViewerScene(slot, v, s);
174  v->SetElementName("Viewer - 2D");
175  s->SetElementName("Scene - 2D");
176 
178  mng->SetProjection(t);
179 
180  TEveProjectionAxes* axes = new TEveProjectionAxes(mng);
181  s->AddElement(axes);
182  TEveCalo2D* calo2d = (TEveCalo2D*) mng->ImportElements(calo3d);
183  s->AddElement(calo2d);
184 
186 
187  gEve->AddToListTree(mng, kTRUE);
188  gEve->AddToListTree(calo2d, kTRUE);
189 
190  return calo2d;
191 }
192 
193 //______________________________________________________________________________
194 void MakeViewerScene(TEveWindowSlot* slot, TEveViewer*& v, TEveScene*& s)
195 {
196  // Create a scene and a viewer in the given slot.
197 
198  v = new TEveViewer("Viewer");
200  slot->ReplaceWindow(v);
201  gEve->GetViewers()->AddElement(v);
202  s = gEve->SpawnNewScene("Scene");
203  v->AddScene(s);
204 }
205 
206 //______________________________________________________________________________
207 void add_jet(TEveElement* parent, const char* name,
208  Float_t eta, Float_t phi,
209  Float_t deta, Float_t dphi)
210 {
211  TEveJetCone* jet = new TEveJetCone(name, name);
212  jet->SetMainTransparency(60);
213  jet->SetLineColor(kRed);
214  jet->SetCylinder(129 - 10, 268.36 - 10);
215  jet->AddEllipticCone(eta, phi, deta, dphi);
216  jet->SetPickable(kTRUE);
218  parent->AddElement(jet);
219 }
virtual TEveWindowSlot * NewSlot()
Create a new frame-slot at the last position of the pack.
virtual TEveWindowSlot * NewSlot()
Definition: TEveWindow.h:242
Encapsulates TGPack into an eve-window.
Definition: TEveWindow.h:360
A central manager for calorimeter event data.
Definition: TEveCaloData.h:26
A base class of TGLEventHandler.
virtual TAxis * GetEtaBins() const
Definition: TEveCaloData.h:218
virtual void SetHighlightFrame(Bool_t f)
Definition: TEveShape.h:63
SliceInfo_t & RefSliceInfo(Int_t s)
Definition: TEveCaloData.h:203
void Setup(const char *name, Float_t threshold, Color_t col, Char_t transp=101)
Definition: TEveCaloData.h:41
Eve representation of TGLScene.
Definition: TEveScene.h:26
static TEveWindowSlot * CreateWindowInTab(TGTab *tab, TEveWindow *eve_parent=0)
Create a new tab in a given tab-widget and populate it with a default window-slot.
float Float_t
Definition: RtypesCore.h:53
Definition: Rtypes.h:59
constexpr Double_t TwoPi()
Definition: TMath.h:44
TEveBrowser * GetBrowser() const
Definition: TEveManager.h:137
void SetScale(Double_t sx, Double_t sy, Double_t sz)
Set scaling.
Definition: TEveTrans.cxx:688
void SetPickable(Bool_t p)
Definition: TEveElement.h:340
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition: TFile.h:303
virtual void SetEventHandler(TGEventHandler *handler)
Set the event-handler.
Definition: TGLViewer.cxx:2293
virtual void SetLineColor(Color_t c)
Definition: TEveShape.h:60
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
void IncDenyDestroy()
Increases the deny-destroy count of the element.
Draws a jet cone with leading particle is specified in (eta,phi) and cone radius is given...
Definition: TEveJetCone.h:23
Description of TEveWindowSlot.
Definition: TEveWindow.h:301
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition: TAttAxis.cxx:322
TGListTreeItem * AddToListTree(TEveElement *re, Bool_t open, TGListTree *lt=0)
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
Axes for non-linear projections.
Int_t AddEllipticCone(Float_t eta, Float_t phi, Float_t reta, Float_t rphi, Float_t length=0)
Add jet cone.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3950
void SetBarrelRadius(Float_t r)
Definition: TEveCalo.h:100
Visualization of a calorimeter event data in 2D.
Definition: TEveCalo.h:199
virtual TEveElement * ImportElements(TEveElement *el, TEveElement *ext_list=0)
Recursively import elements and apply projection to the newly imported objects.
void ReplaceWindow(TEveWindow *w)
Replace this window with the passed one.
Definition: TEveWindow.cxx:819
TEveViewerList * GetViewers() const
Definition: TEveManager.h:145
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
constexpr Double_t Pi()
Definition: TMath.h:40
virtual void SetElementName(const char *name)
Virtual function for setting of name of an element.
Definition: TEveElement.h:484
Manager class for steering of projections and managing projected objects.
void SetCaloLego(TEveCaloLego *c)
Int_t AddHistogram(TH2F *hist)
Add new slice to calo tower.
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix.
SVector< double, 2 > v
Definition: Dict.h:5
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:249
virtual Bool_t SetTab(Int_t tabIndex, Bool_t emit=kTRUE)
Brings the composite frame with the index tabIndex to the front and generate the following event if t...
Definition: TGTab.cxx:507
TEveGedEditor * GetEditor() const
Returns main object editor.
Base GL viewer object - used by both standalone and embedded (in pad) GL.
Definition: TGLViewer.h:53
virtual void AddElement(TEveElement *el)
Add el to the list of children.
TGTab * GetTabRight() const
Definition: TRootBrowser.h:141
virtual void SetMainTransparency(Char_t t)
Set main-transparency.
const Bool_t kFALSE
Definition: RtypesCore.h:88
Visualization of calorimeter data as eta/phi histogram.
Definition: TEveCalo.h:249
virtual void AddOverlayElement(TGLOverlayElement *el)
Add overlay element.
TGLViewer * GetGLViewer() const
Definition: TEveViewer.h:51
TEveWindowPack * MakePack()
A pack is created in place of this window-slot.
TEveScene * GetEventScene() const
Definition: TEveManager.h:148
static constexpr double s
virtual TAxis * GetPhiBins() const
Definition: TEveCaloData.h:221
void SetCurrentCamera(ECameraType camera)
Set current active camera - &#39;cameraType&#39; one of: kCameraPerspX, kCameraPerspY, kCameraPerspZ, kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY, kCameraOrthoXnOY, kCameraOrthoXnOZ, kCameraOrthoZnOY.
Definition: TGLViewer.cxx:1794
TEveViewer * GetDefaultViewer() const
Returns the default viewer - the first one in the fViewers list.
void SetProjection(TEveProjection::EPType_e type)
Set projection type and distortion.
void SetEndCapPos(Float_t z)
Definition: TEveCalo.h:104
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
virtual void AddElement(TEveElement *el)
Call base-class implementation.
Definition: TEveViewer.cxx:358
TEveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
Definition: Rtypes.h:59
Visualization of a calorimeter event data in 3D.
Definition: TEveCalo.h:156
void SetShowTitleBar(Bool_t x)
Set display state of the title-bar.
Definition: TEveWindow.cxx:898
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
GL-overlay control GUI for TEveCaloLego.
const Bool_t kTRUE
Definition: RtypesCore.h:87
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33
char name[80]
Definition: TGX11.cxx:109
Eve representation of TGLViewer.
Definition: TEveViewer.h:30
void SetCylinder(Float_t r, Float_t z)
Definition: TEveJetCone.h:55
A central manager for calorimeter data of an event written in TH2F.
Definition: TEveCaloData.h:297
TGLSAViewer * SpawnGLViewer(TGedEditor *ged=0, Bool_t stereo=kFALSE, Bool_t quad_buf=kTRUE)
Spawn new GLViewer and adopt it.
Definition: TEveViewer.cxx:155
TGLWidget * GetGLWidget()
Definition: TGLViewer.h:225
virtual void AddScene(TEveScene *scene)
Add &#39;scene&#39; to the list of scenes.
Definition: TEveViewer.cxx:261