ROOT logo
// Author: Stefano Carrazza 2010

/**************************************************************************
 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
 * full copyright notice.                                                 *
 **************************************************************************/

#if !defined(__CINT__) || defined(__MAKECINT__)
#include <TGLViewer.h>
#include <TGLWidget.h>
#include <TH2.h>
#include <TMath.h>
#include <TTree.h>
#include <TEveBrowser.h>
#include <TEveCalo.h>
#include <TEveCaloData.h>
#include <TEveCaloLegoOverlay.h>
#include <TEveLegoEventHandler.h>
#include <TEveManager.h>
#include <TEveScene.h>
#include <TEveTrans.h>
#include <TEveViewer.h>
#include <TEveWindow.h>

#include <AliESDEvent.h>
#include <AliEveEventManager.h>
#include <AliEveMultiView.h>
#endif

double pi = TMath::Pi();
TEveViewer *g_histo2d_v   = 0;
TEveScene  *g_histo2d_s   = 0;
TEveScene  *g_histo2d_s2  = 0;
TEveCaloLegoOverlay* g_histo2d_lego_overlay = 0;

Double_t GetPhi(Double_t phi);
TEveCaloLego* CreateHistoLego(TEveCaloData* data);
TEveCalo3D* Create3DView(TEveCaloData* data);
AliEveMultiView* CreateProjections(TEveCaloData* data, TEveCalo3D *calo3d);

TEveCaloDataHist* histo2d()
{ 

   // Access to esdTree
   AliESDEvent* esd = AliEveEventManager::AssertESD();

   // Creating 2D histograms
   TH2F *histopos = new TH2F("histopos","Histo 2d positive",100,-1.5,1.5,80,-pi,pi);
   TH2F *histoneg = new TH2F("histoneg","Histo 2d negative",100,-1.5,1.5,80,-pi,pi);

   Info("histo2d", "Event: %d, Number of tracks: %d\n", AliEveEventManager::GetMaster()->GetEventId(), esd->GetNumberOfTracks() );

   // Getting current tracks, filling histograms 
   for ( int n = 0; n < esd->GetNumberOfTracks(); ++n ) {    
  
      if (esd->GetTrack(n)->GetSign() > 0) {
         histopos->Fill(esd->GetTrack(n)->Eta(),
	      	        GetPhi(esd->GetTrack(n)->Phi()),
                        fabs(esd->GetTrack(n)->Pt()));
      } else {
         histoneg->Fill(esd->GetTrack(n)->Eta(),
                        GetPhi(esd->GetTrack(n)->Phi()),
                        fabs(esd->GetTrack(n)->Pt()));
      }
   }

   TEveCaloDataHist* data = new TEveCaloDataHist();
   AliEveEventManager::RegisterTransient(data);
   
   data->AddHistogram(histoneg);
   data->RefSliceInfo(0).Setup("NegCg:", 0, kBlue);
   data->AddHistogram(histopos);
   data->RefSliceInfo(1).Setup("PosCg:", 0, kRed);
   data->GetEtaBins()->SetTitleFont(120);
   data->GetEtaBins()->SetTitle("h");
   data->GetPhiBins()->SetTitleFont(120);
   data->GetPhiBins()->SetTitle("f");
   data->IncDenyDestroy();

   // Plotting the lego histogram in a new tab
   CreateHistoLego(data);
   
   // Plotting the 3D histogram
   TEveCalo3D *calo3d = Create3DView(data);

   // Plotting projections RPhi and RhoZ
   CreateProjections(data, calo3d);
   
   gEve->Redraw3D(kTRUE);

   return data;
}

//______________________________________________________________________________
Double_t GetPhi(Double_t phi)
{
   if (phi > pi) {
      phi -= 2*pi;
   }
   return phi;
}

//______________________________________________________________________________
TEveCaloLego* CreateHistoLego(TEveCaloData* data){

   TGLViewer* glv;

   // Viewer initialization, tab creation
   if ( g_histo2d_v == 0 ) {
      TEveWindowSlot *slot    = 0;
      TEveBrowser    *browser = gEve->GetBrowser();

      slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
      slot->MakeCurrent();
      g_histo2d_v = gEve->SpawnNewViewer("2D Lego Histogram", "2D Lego Histogram");
      g_histo2d_s = gEve->SpawnNewScene("2D Lego Histogram", "2D Lego Histogram");
      g_histo2d_v->AddScene(g_histo2d_s);
      g_histo2d_v->SetElementName("2D Lego Viewer");
      g_histo2d_s->SetElementName("2D Lego Scene");

      glv = g_histo2d_v->GetGLViewer();
      g_histo2d_lego_overlay = new TEveCaloLegoOverlay();
      glv->AddOverlayElement(g_histo2d_lego_overlay);
      glv->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
   } else {
      glv = g_histo2d_v->GetGLViewer(); 
   }
   
   //plotting histo
   TEveCaloLego* lego = new TEveCaloLego(data);
   g_histo2d_s->AddElement(lego);
   AliEveEventManager::RegisterTransient(lego);

   // move to real world coordinates
   lego->InitMainTrans();
   Float_t sc = TMath::Min(lego->GetEtaRng(), lego->GetPhiRng());
   lego->RefMainTrans().SetScale(sc, sc, sc);

   // set event handler to move from perspective to orthographic view.
   glv->SetEventHandler(new TEveLegoEventHandler(glv->GetGLWidget(), glv, lego));

   g_histo2d_lego_overlay->SetCaloLego(lego);

   return lego;
}

//______________________________________________________________________________
TEveCalo3D* Create3DView(TEveCaloData* data){
  
   //initialization
   if ( g_histo2d_s2 == 0 ) {
      g_histo2d_s2 = gEve->SpawnNewScene("3D Histogram", "3D Histogram");
      gEve->GetDefaultViewer()->AddScene(g_histo2d_s2);
      g_histo2d_s2->SetElementName("3D Histogram Scene");
   }
 
   TEveCalo3D* calo3d = new TEveCalo3D(data);
   AliEveEventManager::RegisterTransient(calo3d);
   
   calo3d->SetBarrelRadius(550);
   calo3d->SetEndCapPos(550);
   g_histo2d_s2->AddElement(calo3d);
 
   return calo3d;
}

//______________________________________________________________________________
AliEveMultiView* CreateProjections(TEveCaloData* data, TEveCalo3D *calo3d){

   AliEveMultiView *al = AliEveMultiView::Instance();
   al->ImportEventRPhi(calo3d);
   al->ImportEventRhoZ(calo3d);

   return al;
}
 histo2d.C:1
 histo2d.C:2
 histo2d.C:3
 histo2d.C:4
 histo2d.C:5
 histo2d.C:6
 histo2d.C:7
 histo2d.C:8
 histo2d.C:9
 histo2d.C:10
 histo2d.C:11
 histo2d.C:12
 histo2d.C:13
 histo2d.C:14
 histo2d.C:15
 histo2d.C:16
 histo2d.C:17
 histo2d.C:18
 histo2d.C:19
 histo2d.C:20
 histo2d.C:21
 histo2d.C:22
 histo2d.C:23
 histo2d.C:24
 histo2d.C:25
 histo2d.C:26
 histo2d.C:27
 histo2d.C:28
 histo2d.C:29
 histo2d.C:30
 histo2d.C:31
 histo2d.C:32
 histo2d.C:33
 histo2d.C:34
 histo2d.C:35
 histo2d.C:36
 histo2d.C:37
 histo2d.C:38
 histo2d.C:39
 histo2d.C:40
 histo2d.C:41
 histo2d.C:42
 histo2d.C:43
 histo2d.C:44
 histo2d.C:45
 histo2d.C:46
 histo2d.C:47
 histo2d.C:48
 histo2d.C:49
 histo2d.C:50
 histo2d.C:51
 histo2d.C:52
 histo2d.C:53
 histo2d.C:54
 histo2d.C:55
 histo2d.C:56
 histo2d.C:57
 histo2d.C:58
 histo2d.C:59
 histo2d.C:60
 histo2d.C:61
 histo2d.C:62
 histo2d.C:63
 histo2d.C:64
 histo2d.C:65
 histo2d.C:66
 histo2d.C:67
 histo2d.C:68
 histo2d.C:69
 histo2d.C:70
 histo2d.C:71
 histo2d.C:72
 histo2d.C:73
 histo2d.C:74
 histo2d.C:75
 histo2d.C:76
 histo2d.C:77
 histo2d.C:78
 histo2d.C:79
 histo2d.C:80
 histo2d.C:81
 histo2d.C:82
 histo2d.C:83
 histo2d.C:84
 histo2d.C:85
 histo2d.C:86
 histo2d.C:87
 histo2d.C:88
 histo2d.C:89
 histo2d.C:90
 histo2d.C:91
 histo2d.C:92
 histo2d.C:93
 histo2d.C:94
 histo2d.C:95
 histo2d.C:96
 histo2d.C:97
 histo2d.C:98
 histo2d.C:99
 histo2d.C:100
 histo2d.C:101
 histo2d.C:102
 histo2d.C:103
 histo2d.C:104
 histo2d.C:105
 histo2d.C:106
 histo2d.C:107
 histo2d.C:108
 histo2d.C:109
 histo2d.C:110
 histo2d.C:111
 histo2d.C:112
 histo2d.C:113
 histo2d.C:114
 histo2d.C:115
 histo2d.C:116
 histo2d.C:117
 histo2d.C:118
 histo2d.C:119
 histo2d.C:120
 histo2d.C:121
 histo2d.C:122
 histo2d.C:123
 histo2d.C:124
 histo2d.C:125
 histo2d.C:126
 histo2d.C:127
 histo2d.C:128
 histo2d.C:129
 histo2d.C:130
 histo2d.C:131
 histo2d.C:132
 histo2d.C:133
 histo2d.C:134
 histo2d.C:135
 histo2d.C:136
 histo2d.C:137
 histo2d.C:138
 histo2d.C:139
 histo2d.C:140
 histo2d.C:141
 histo2d.C:142
 histo2d.C:143
 histo2d.C:144
 histo2d.C:145
 histo2d.C:146
 histo2d.C:147
 histo2d.C:148
 histo2d.C:149
 histo2d.C:150
 histo2d.C:151
 histo2d.C:152
 histo2d.C:153
 histo2d.C:154
 histo2d.C:155
 histo2d.C:156
 histo2d.C:157
 histo2d.C:158
 histo2d.C:159
 histo2d.C:160
 histo2d.C:161
 histo2d.C:162
 histo2d.C:163
 histo2d.C:164
 histo2d.C:165
 histo2d.C:166
 histo2d.C:167
 histo2d.C:168
 histo2d.C:169
 histo2d.C:170
 histo2d.C:171
 histo2d.C:172
 histo2d.C:173
 histo2d.C:174
 histo2d.C:175
 histo2d.C:176
 histo2d.C:177