From $ROOTSYS/tutorials/eve/calorimeters.C

// @(#)root/eve:$Id$
// Author: Alja Mrak-Tadel

// Demonstrates usage of EVE calorimetry classes.

#include "TEveProjections.h"

const char* histFile =
   "http://amraktad.web.cern.ch/amraktad/cms_calo_hist.root";

TEveCaloLego* MakeCaloLego(TEveCaloData* data, TEveWindowSlot* slot);
TEveCalo2D* MakeCalo2D(TEveCalo3D* calo3d, TEveWindowSlot* slot, TEveProjection::EPType_e t);
TEveCalo3D* MakeCalo3D(TEveCaloData* data, TEveWindowSlot* slot);
TEveCalo2D* MakeCalo2D(TEveCalo3D* calo3d, TEveWindowSlot* slot, TEveProjection::EPType_e t);
void MakeViewerScene(TEveWindowSlot* slot, TEveViewer*& v, TEveScene*& s);
void add_jet(TEveElement*, const char*, Float_t, Float_t, Float_t, Float_t);

void calorimeters()
{
   gSystem->IgnoreSignal(kSigSegmentationViolation, true);
   TEveManager::Create();

   // event data
   TFile::SetCacheFileDir(".");
   TFile* hf = TFile::Open(histFile, "CACHEREAD");
   TH2F* ecalHist = (TH2F*)hf->Get("ecalLego");
   TH2F* hcalHist = (TH2F*)hf->Get("hcalLego");
   TEveCaloDataHist* data = new TEveCaloDataHist();
   data->AddHistogram(ecalHist);
   data->RefSliceInfo(0).Setup("ECAL", 0.3, kBlue);
   data->AddHistogram(hcalHist);
   data->RefSliceInfo(1).Setup("HCAL", 0.1, kRed);
   data->GetEtaBins()->SetTitleFont(120);
   data->GetEtaBins()->SetTitle("h");
   data->GetPhiBins()->SetTitleFont(120);
   data->GetPhiBins()->SetTitle("f");
   data->IncDenyDestroy();
   gEve->AddToListTree(data, kFALSE);


   // first tab
   TEveCaloLego* lego = MakeCaloLego(data, 0);

   //
   // second tab
   //

   // frames
   TEveWindowSlot* slot =
      TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
   TEveWindowPack* packH = slot->MakePack();
   packH->SetElementName("Projections");
   packH->SetHorizontal();
   packH->SetShowTitleBar(kFALSE);

   slot = packH->NewSlot();
   TEveWindowPack* pack0 = slot->MakePack();
   pack0->SetShowTitleBar(kFALSE);
   TEveWindowSlot*  slotLeftTop   = pack0->NewSlot();
   TEveWindowSlot* slotLeftBottom = pack0->NewSlot();

   slot = packH->NewSlot();
   TEveWindowPack* pack1 = slot->MakePack();
   pack1->SetShowTitleBar(kFALSE);
   TEveWindowSlot* slotRightTop    = pack1->NewSlot();
   TEveWindowSlot* slotRightBottom = pack1->NewSlot();

   // viewers ans scenes in second tab
   TEveCalo3D* calo3d = MakeCalo3D(data, slotRightTop);
   MakeCalo2D(calo3d, slotLeftTop, TEveProjection::kPT_RPhi);
   MakeCalo2D(calo3d, slotLeftBottom, TEveProjection::kPT_RhoZ);
   lego = MakeCaloLego(data, slotRightBottom);


   gEve->GetBrowser()->GetTabRight()->SetTab(1);
   gEve->Redraw3D(kTRUE);
}

//______________________________________________________________________________
TEveCaloLego* MakeCaloLego(TEveCaloData* data, TEveWindowSlot* slot)
{
   // Eta-phi lego view.

   TEveViewer* v;
   TEveScene* s;
   if (slot)
   {
      TEveViewer* v; TEveScene* s;
      MakeViewerScene(slot, v, s);
   } else {
      v = gEve->GetDefaultViewer();
      s = gEve->GetEventScene();
   }
   v->SetElementName("Viewer - Lego");
   s->SetElementName("Scene - Lego");

   gStyle->SetPalette(1, 0);
   TEveCaloLego* lego = new TEveCaloLego(data);
   s->AddElement(lego);

   // By the default lego extends is (1x1x1). Resize it to put in 'natural'
   // coordinates, so that y extend in 2*Pi and set height of lego two times
   //  smaller than y extend to have better view in 3D perspective.
   lego->InitMainTrans();
   lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());

   // draws scales and axis on borders of window
   TGLViewer* glv = v->GetGLViewer();
   TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
   glv->AddOverlayElement(overlay);
   overlay->SetCaloLego(lego);

   // set event handler to move from perspective to orthographic view.
   glv->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
   glv->SetEventHandler
      (new TEveLegoEventHandler(glv->GetGLWidget(), glv, lego));
   gEve->AddToListTree(lego, kTRUE);

   return lego;
}

//______________________________________________________________________________
TEveCalo3D* MakeCalo3D(TEveCaloData* data, TEveWindowSlot* slot)
{
   // 3D catersian view.

   TEveViewer* v; TEveScene* s;
   MakeViewerScene(slot, v, s);
   v->SetElementName("Viewer - 3D");
   s->SetElementName("Scene - 3D");

   TEveCalo3D* calo3d = new TEveCalo3D(data);
   calo3d->SetBarrelRadius(129.00);
   calo3d->SetEndCapPos(268.36);
   s->AddElement(calo3d);

   add_jet(calo3d, "JetCone Lojz",  1.4,  1.0, 0.4, 0.2);
   add_jet(calo3d, "JetCone Mici", -2.0, -2.1, 0.2, 0.4);

   return calo3d;
}

//______________________________________________________________________________
TEveCalo2D* MakeCalo2D(TEveCalo3D* calo3d, TEveWindowSlot* slot,
                       TEveProjection::EPType_e t)
{
   // Projected calorimeter.

   TEveViewer* v; TEveScene* s;
   MakeViewerScene(slot, v, s);
   v->SetElementName("Viewer - 2D");
   s->SetElementName("Scene - 2D");

   TEveProjectionManager* mng = new TEveProjectionManager();
   mng->SetProjection(t);

   TEveProjectionAxes* axes = new TEveProjectionAxes(mng);
   s->AddElement(axes);
   TEveCalo2D* calo2d = (TEveCalo2D*) mng->ImportElements(calo3d);
   s->AddElement(calo2d);

   v->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);

   gEve->AddToListTree(mng, kTRUE);
   gEve->AddToListTree(calo2d, kTRUE);

   return calo2d;
}

//______________________________________________________________________________
void MakeViewerScene(TEveWindowSlot* slot, TEveViewer*& v, TEveScene*& s)
{
   // Create a scene and a viewer in the given slot.

   v = new TEveViewer("Viewer");
   v->SpawnGLViewer(gEve->GetEditor());
   slot->ReplaceWindow(v);
   gEve->GetViewers()->AddElement(v);
   s = gEve->SpawnNewScene("Scene");
   v->AddScene(s);
}

//______________________________________________________________________________
void add_jet(TEveElement* parent, const char* name,
             Float_t eta, Float_t phi,
             Float_t deta, Float_t dphi)
{
   TEveJetCone* jet = new TEveJetCone(name, name);
   jet->SetMainTransparency(60);
   jet->SetLineColor(kRed);
   jet->SetCylinder(129 - 10, 268.36 - 10);
   jet->AddEllipticCone(eta, phi, deta, dphi);
   jet->SetPickable(kTRUE);
   jet->SetHighlightFrame(kFALSE);
   parent->AddElement(jet);
}
 calorimeters.C:1
 calorimeters.C:2
 calorimeters.C:3
 calorimeters.C:4
 calorimeters.C:5
 calorimeters.C:6
 calorimeters.C:7
 calorimeters.C:8
 calorimeters.C:9
 calorimeters.C:10
 calorimeters.C:11
 calorimeters.C:12
 calorimeters.C:13
 calorimeters.C:14
 calorimeters.C:15
 calorimeters.C:16
 calorimeters.C:17
 calorimeters.C:18
 calorimeters.C:19
 calorimeters.C:20
 calorimeters.C:21
 calorimeters.C:22
 calorimeters.C:23
 calorimeters.C:24
 calorimeters.C:25
 calorimeters.C:26
 calorimeters.C:27
 calorimeters.C:28
 calorimeters.C:29
 calorimeters.C:30
 calorimeters.C:31
 calorimeters.C:32
 calorimeters.C:33
 calorimeters.C:34
 calorimeters.C:35
 calorimeters.C:36
 calorimeters.C:37
 calorimeters.C:38
 calorimeters.C:39
 calorimeters.C:40
 calorimeters.C:41
 calorimeters.C:42
 calorimeters.C:43
 calorimeters.C:44
 calorimeters.C:45
 calorimeters.C:46
 calorimeters.C:47
 calorimeters.C:48
 calorimeters.C:49
 calorimeters.C:50
 calorimeters.C:51
 calorimeters.C:52
 calorimeters.C:53
 calorimeters.C:54
 calorimeters.C:55
 calorimeters.C:56
 calorimeters.C:57
 calorimeters.C:58
 calorimeters.C:59
 calorimeters.C:60
 calorimeters.C:61
 calorimeters.C:62
 calorimeters.C:63
 calorimeters.C:64
 calorimeters.C:65
 calorimeters.C:66
 calorimeters.C:67
 calorimeters.C:68
 calorimeters.C:69
 calorimeters.C:70
 calorimeters.C:71
 calorimeters.C:72
 calorimeters.C:73
 calorimeters.C:74
 calorimeters.C:75
 calorimeters.C:76
 calorimeters.C:77
 calorimeters.C:78
 calorimeters.C:79
 calorimeters.C:80
 calorimeters.C:81
 calorimeters.C:82
 calorimeters.C:83
 calorimeters.C:84
 calorimeters.C:85
 calorimeters.C:86
 calorimeters.C:87
 calorimeters.C:88
 calorimeters.C:89
 calorimeters.C:90
 calorimeters.C:91
 calorimeters.C:92
 calorimeters.C:93
 calorimeters.C:94
 calorimeters.C:95
 calorimeters.C:96
 calorimeters.C:97
 calorimeters.C:98
 calorimeters.C:99
 calorimeters.C:100
 calorimeters.C:101
 calorimeters.C:102
 calorimeters.C:103
 calorimeters.C:104
 calorimeters.C:105
 calorimeters.C:106
 calorimeters.C:107
 calorimeters.C:108
 calorimeters.C:109
 calorimeters.C:110
 calorimeters.C:111
 calorimeters.C:112
 calorimeters.C:113
 calorimeters.C:114
 calorimeters.C:115
 calorimeters.C:116
 calorimeters.C:117
 calorimeters.C:118
 calorimeters.C:119
 calorimeters.C:120
 calorimeters.C:121
 calorimeters.C:122
 calorimeters.C:123
 calorimeters.C:124
 calorimeters.C:125
 calorimeters.C:126
 calorimeters.C:127
 calorimeters.C:128
 calorimeters.C:129
 calorimeters.C:130
 calorimeters.C:131
 calorimeters.C:132
 calorimeters.C:133
 calorimeters.C:134
 calorimeters.C:135
 calorimeters.C:136
 calorimeters.C:137
 calorimeters.C:138
 calorimeters.C:139
 calorimeters.C:140
 calorimeters.C:141
 calorimeters.C:142
 calorimeters.C:143
 calorimeters.C:144
 calorimeters.C:145
 calorimeters.C:146
 calorimeters.C:147
 calorimeters.C:148
 calorimeters.C:149
 calorimeters.C:150
 calorimeters.C:151
 calorimeters.C:152
 calorimeters.C:153
 calorimeters.C:154
 calorimeters.C:155
 calorimeters.C:156
 calorimeters.C:157
 calorimeters.C:158
 calorimeters.C:159
 calorimeters.C:160
 calorimeters.C:161
 calorimeters.C:162
 calorimeters.C:163
 calorimeters.C:164
 calorimeters.C:165
 calorimeters.C:166
 calorimeters.C:167
 calorimeters.C:168
 calorimeters.C:169
 calorimeters.C:170
 calorimeters.C:171
 calorimeters.C:172
 calorimeters.C:173
 calorimeters.C:174
 calorimeters.C:175
 calorimeters.C:176
 calorimeters.C:177
 calorimeters.C:178
 calorimeters.C:179
 calorimeters.C:180
 calorimeters.C:181
 calorimeters.C:182
 calorimeters.C:183
 calorimeters.C:184
 calorimeters.C:185
 calorimeters.C:186
 calorimeters.C:187
 calorimeters.C:188
 calorimeters.C:189
 calorimeters.C:190
 calorimeters.C:191
 calorimeters.C:192
 calorimeters.C:193
 calorimeters.C:194
 calorimeters.C:195
 calorimeters.C:196
 calorimeters.C:197