Geometry for MFT (Brigitte)
[u/mrichter/AliRoot.git] / EVE / alice-macros / histo2d_all_events.C
CommitLineData
e18ce6a3 1// Author: Stefano Carrazza 2010
2
e516f157 3/**************************************************************************
4 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
5 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
6 * full copyright notice. *
7 **************************************************************************/
8
ba978640 9#if !defined(__CINT__) || defined(__MAKECINT__)
10#include <TGLViewer.h>
11#include <TGLWidget.h>
12#include <TH2.h>
13#include <TMath.h>
14#include <TTree.h>
15#include <TEveBrowser.h>
16#include <TEveCalo.h>
17#include <TEveCaloData.h>
18#include <TEveCaloLegoOverlay.h>
19#include <TEveLegoEventHandler.h>
20#include <TEveManager.h>
21#include <TEveProjectionManager.h>
22#include <TEveProjectionAxes.h>
23#include <TEveScene.h>
24#include <TEveTrans.h>
25#include <TEveViewer.h>
26#include <TEveWindow.h>
27
6c49a8e1 28#include <AliESDEvent.h>
29#include <AliEveEventManager.h>
ba978640 30#endif
31
e516f157 32double pi = TMath::Pi();
bfd5d6c1 33TEveViewer *g_histo2d_all_events_v0 = 0;
34TEveViewer *g_histo2d_all_events_v1 = 0;
35TEveViewer *g_histo2d_all_events_v2 = 0;
36TEveViewer *g_histo2d_all_events_v3 = 0;
37TEveScene *g_histo2d_all_events_s0 = 0;
38TEveScene *g_histo2d_all_events_s1 = 0;
39TEveScene *g_histo2d_all_events_s2 = 0;
40TEveScene *g_histo2d_all_events_s3 = 0;
41TEveCaloLegoOverlay* g_histo2d_all_events_lego_overlay = 0;
42TEveWindowSlot* g_histo2d_all_events_slot = 0;
e516f157 43
ba978640 44Double_t GetPhi(Double_t phi);
45TEveCaloLego* CreateHistoLego(TEveCaloData* data, TEveWindowSlot* slot);
46TEveCalo3D* Create3DView(TEveCaloData* data, TEveWindowSlot* slot);
47void CreateProjections(TEveCaloData* data, TEveCalo3D *calo3d, TEveWindowSlot* slot1, TEveWindowSlot* slot2);
e516f157 48
49TEveCaloDataHist* histo2d_all_events()
50{
51
52 TEveCaloDataHist* data_t;
53
e18ce6a3 54 if ( g_histo2d_all_events_slot == 0 ) {
ba978640 55 Info("histo2d_all_events", "Filling histogram...");
e516f157 56
57 // Access to esdTree
58 AliESDEvent* esd = AliEveEventManager::AssertESD();
59 TTree* t = AliEveEventManager::GetMaster()->GetESDTree();
60
61 // Creating 2D histograms
62 TH2F *histopos_t = new TH2F("histopos_t","Histo 2d positive",
63 100,-1.5,1.5,80,-pi,pi);
64 TH2F *histoneg_t = new TH2F("histoneg_t","Histo 2d negative",
65 100,-1.5,1.5,80,-pi,pi);
66
67 // Getting current tracks for each event, filling histograms
e18ce6a3 68 for ( int event = 0; event < t->GetEntries(); event++ ) {
e516f157 69 t->GetEntry(event);
e18ce6a3 70 for ( int n = 0; n < esd->GetNumberOfTracks(); ++n ) {
e516f157 71
e18ce6a3 72 if ( esd->GetTrack(n)->GetSign() > 0 ) {
e516f157 73 histopos_t->Fill(esd->GetTrack(n)->Eta(),
e18ce6a3 74 GetPhi(esd->GetTrack(n)->Phi()),
e516f157 75 fabs(esd->GetTrack(n)->Pt()));
76 } else {
77 histoneg_t->Fill(esd->GetTrack(n)->Eta(),
e18ce6a3 78 GetPhi(esd->GetTrack(n)->Phi()),
e516f157 79 fabs(esd->GetTrack(n)->Pt()));
80 }
81 }
82 }
83
84 data_t = new TEveCaloDataHist();
85 data_t->AddHistogram(histoneg_t);
86 data_t->RefSliceInfo(0).Setup("NegCg:", 0, kBlue);
87 data_t->AddHistogram(histopos_t);
88 data_t->RefSliceInfo(1).Setup("PosCg:", 0, kRed);
89 data_t->GetEtaBins()->SetTitleFont(120);
90 data_t->GetEtaBins()->SetTitle("h");
91 data_t->GetPhiBins()->SetTitleFont(120);
92 data_t->GetPhiBins()->SetTitle("f");
93 data_t->IncDenyDestroy();
94
95 // Creating frames
bfd5d6c1 96 g_histo2d_all_events_slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
97 TEveWindowPack* packH = g_histo2d_all_events_slot->MakePack();
e516f157 98 packH->SetElementName("Projections");
99 packH->SetHorizontal();
100 packH->SetShowTitleBar(kFALSE);
101
bfd5d6c1 102 g_histo2d_all_events_slot = packH->NewSlot();
103 TEveWindowPack* pack0 = g_histo2d_all_events_slot->MakePack();
e516f157 104 pack0->SetShowTitleBar(kFALSE);
105 TEveWindowSlot* slotLeftTop = pack0->NewSlot();
106 TEveWindowSlot* slotLeftBottom = pack0->NewSlot();
107
bfd5d6c1 108 g_histo2d_all_events_slot = packH->NewSlot();
109 TEveWindowPack* pack1 = g_histo2d_all_events_slot->MakePack();
e516f157 110 pack1->SetShowTitleBar(kFALSE);
111 TEveWindowSlot* slotRightTop = pack1->NewSlot();
112 TEveWindowSlot* slotRightBottom = pack1->NewSlot();
113
114 // Creating viewers and scenes
e18ce6a3 115 TEveCalo3D* calo3d = Create3DView(data_t, slotLeftTop);
116 CreateHistoLego(data_t, slotLeftBottom);
117 CreateProjections(data_t, calo3d, slotRightTop, slotRightBottom);
e516f157 118
119 gEve->Redraw3D(kTRUE);
120
ba978640 121 Info("histo2d_all_events", "...Finished");
e516f157 122 }
123
124 return data_t;
125}
126
127//______________________________________________________________________________
e18ce6a3 128Double_t GetPhi(Double_t phi)
e516f157 129{
130 if (phi > pi) {
131 phi -= 2*pi;
132 }
133 return phi;
134}
135
136//______________________________________________________________________________
e18ce6a3 137TEveCaloLego* CreateHistoLego(TEveCaloData* data, TEveWindowSlot* slot){
e516f157 138
139 TEveCaloLego* lego;
140
141 // Viewer initialization, tab creation
e18ce6a3 142 if ( g_histo2d_all_events_v0 == 0 ) {
e516f157 143
144 TEveBrowser *browser = gEve->GetBrowser();
145 slot->MakeCurrent();
bfd5d6c1 146 g_histo2d_all_events_v0 = gEve->SpawnNewViewer("2D Lego Histogram", "2D Lego Histogram");
147 g_histo2d_all_events_s0 = gEve->SpawnNewScene("2D Lego Histogram", "2D Lego Histogram");
148 g_histo2d_all_events_v0->AddScene(g_histo2d_all_events_s0);
149 g_histo2d_all_events_v0->SetElementName("2D Lego Viewer");
150 g_histo2d_all_events_s0->SetElementName("2D Lego Scene");
151
152 TGLViewer* glv = g_histo2d_all_events_v0->GetGLViewer();
153 g_histo2d_all_events_lego_overlay = new TEveCaloLegoOverlay();
154 glv->AddOverlayElement(g_histo2d_all_events_lego_overlay);
e516f157 155 glv->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
156
157 // Plotting histogram lego
158 lego = new TEveCaloLego(data);
bfd5d6c1 159 g_histo2d_all_events_s0->AddElement(lego);
e516f157 160
161 // Move to real world coordinates
162 lego->InitMainTrans();
163 Float_t sc = TMath::Min(lego->GetEtaRng(), lego->GetPhiRng());
164 lego->RefMainTrans().SetScale(sc, sc, sc);
165
166 // Set event handler to move from perspective to orthographic view.
167 glv->SetEventHandler(new TEveLegoEventHandler(glv->GetGLWidget(), glv, lego));
168
bfd5d6c1 169 g_histo2d_all_events_lego_overlay->SetCaloLego(lego);
e516f157 170 }
171
172 return lego;
173}
174
175//______________________________________________________________________________
e18ce6a3 176TEveCalo3D* Create3DView(TEveCaloData* data, TEveWindowSlot* slot){
e516f157 177
178 TEveCalo3D* calo3d;
179
e18ce6a3 180 if ( g_histo2d_all_events_v1 == 0 ) {
e516f157 181
182 TEveBrowser *browser = gEve->GetBrowser();
183 slot->MakeCurrent();
bfd5d6c1 184 g_histo2d_all_events_v1 = gEve->SpawnNewViewer("3D Histogram", "3D Histogram");
185 g_histo2d_all_events_s1 = gEve->SpawnNewScene("3D Histogram", "3D Histogram");
186 g_histo2d_all_events_v1->AddScene(g_histo2d_all_events_s1);
187 g_histo2d_all_events_v1->SetElementName("3D Histogram Viewer");
188 g_histo2d_all_events_s1->SetElementName("3D Histogram Scene");
e516f157 189
190 calo3d = new TEveCalo3D(data);
191
192 calo3d->SetBarrelRadius(550);
193 calo3d->SetEndCapPos(550);
bfd5d6c1 194 g_histo2d_all_events_s1->AddElement(calo3d);
e516f157 195 }
196
197 return calo3d;
198}
199
200//______________________________________________________________________________
e18ce6a3 201void CreateProjections(TEveCaloData* data, TEveCalo3D *calo3d, TEveWindowSlot* slot1, TEveWindowSlot* slot2){
e516f157 202
e18ce6a3 203 if ( g_histo2d_all_events_v2 == 0 ) {
e516f157 204
205 TEveBrowser *browser = gEve->GetBrowser();
206 slot1->MakeCurrent();
bfd5d6c1 207 g_histo2d_all_events_v2 = gEve->SpawnNewViewer("RPhi projection", "RPhi projection");
208 g_histo2d_all_events_s2 = gEve->SpawnNewScene("RPhi projection", "RPhi projection");
209 g_histo2d_all_events_v2->AddScene(g_histo2d_all_events_s2);
210 g_histo2d_all_events_v2->SetElementName("RPhi Projection Viewer");
211 g_histo2d_all_events_s2->SetElementName("RPhi Projection Scene");
e516f157 212
213 TEveProjectionManager* mng1 = new TEveProjectionManager();
214 mng1->SetProjection(TEveProjection::kPT_RPhi);
215
bfd5d6c1 216 TEveProjectionAxes* axeg_histo2d_all_events_s1 = new TEveProjectionAxes(mng1);
217 g_histo2d_all_events_s2->AddElement(axeg_histo2d_all_events_s1);
e516f157 218 TEveCalo2D* calo2d1 = (TEveCalo2D*) mng1->ImportElements(calo3d);
bfd5d6c1 219 g_histo2d_all_events_s2->AddElement(calo2d1);
e516f157 220
bfd5d6c1 221 g_histo2d_all_events_v2->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
e516f157 222 }
223
e18ce6a3 224 if ( g_histo2d_all_events_v3 == 0 ) {
e516f157 225
226 TEveBrowser *browser = gEve->GetBrowser();
227 slot2->MakeCurrent();
bfd5d6c1 228 g_histo2d_all_events_v3 = gEve->SpawnNewViewer("RhoZ projection", "RhoZ projection");
229 g_histo2d_all_events_s3 = gEve->SpawnNewScene("RhoZ projection", "RhoZ projection");
230 g_histo2d_all_events_v3->AddScene(g_histo2d_all_events_s3);
231 g_histo2d_all_events_v3->SetElementName("RhoZ Projection Viewer");
232 g_histo2d_all_events_s3->SetElementName("RhoZ Projection Viewer");
e516f157 233
234 TEveProjectionManager* mng2 = new TEveProjectionManager();
235 mng2->SetProjection(TEveProjection::kPT_RhoZ);
236
bfd5d6c1 237 TEveProjectionAxes* axeg_histo2d_all_events_s2 = new TEveProjectionAxes(mng2);
238 g_histo2d_all_events_s3->AddElement(axeg_histo2d_all_events_s2);
e516f157 239 TEveCalo2D* calo2d2 = (TEveCalo2D*) mng2->ImportElements(calo3d);
bfd5d6c1 240 g_histo2d_all_events_s3->AddElement(calo2d2);
e516f157 241
bfd5d6c1 242 g_histo2d_all_events_v3->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
e516f157 243 }
244
245 return;
246}