Geometry for MFT (Brigitte)
[u/mrichter/AliRoot.git] / EVE / alice-macros / histo2d.C
1 // Author: Stefano Carrazza 2010
2
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
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 <TEveScene.h>
22 #include <TEveTrans.h>
23 #include <TEveViewer.h>
24 #include <TEveWindow.h>
25
26 #include <AliESDEvent.h>
27 #include <AliEveEventManager.h>
28 #include <AliEveMultiView.h>
29 #endif
30
31 double pi = TMath::Pi();
32 TEveViewer *g_histo2d_v   = 0;
33 TEveScene  *g_histo2d_s   = 0;
34 TEveScene  *g_histo2d_s2  = 0;
35 TEveCaloLegoOverlay* g_histo2d_lego_overlay = 0;
36
37 Double_t GetPhi(Double_t phi);
38 TEveCaloLego* CreateHistoLego(TEveCaloData* data);
39 TEveCalo3D* Create3DView(TEveCaloData* data);
40 AliEveMultiView* CreateProjections(TEveCaloData* data, TEveCalo3D *calo3d);
41
42 TEveCaloDataHist* histo2d()
43
44
45    // Access to esdTree
46    AliESDEvent* esd = AliEveEventManager::AssertESD();
47
48    // Creating 2D histograms
49    TH2F *histopos = new TH2F("histopos","Histo 2d positive",100,-1.5,1.5,80,-pi,pi);
50    TH2F *histoneg = new TH2F("histoneg","Histo 2d negative",100,-1.5,1.5,80,-pi,pi);
51
52    Info("histo2d", "Event: %d, Number of tracks: %d\n", AliEveEventManager::GetMaster()->GetEventId(), esd->GetNumberOfTracks() );
53
54    // Getting current tracks, filling histograms 
55    for ( int n = 0; n < esd->GetNumberOfTracks(); ++n ) {    
56   
57       if (esd->GetTrack(n)->GetSign() > 0) {
58          histopos->Fill(esd->GetTrack(n)->Eta(),
59                         GetPhi(esd->GetTrack(n)->Phi()),
60                         fabs(esd->GetTrack(n)->Pt()));
61       } else {
62          histoneg->Fill(esd->GetTrack(n)->Eta(),
63                         GetPhi(esd->GetTrack(n)->Phi()),
64                         fabs(esd->GetTrack(n)->Pt()));
65       }
66    }
67
68    TEveCaloDataHist* data = new TEveCaloDataHist();
69    AliEveEventManager::RegisterTransient(data);
70    
71    data->AddHistogram(histoneg);
72    data->RefSliceInfo(0).Setup("NegCg:", 0, kBlue);
73    data->AddHistogram(histopos);
74    data->RefSliceInfo(1).Setup("PosCg:", 0, kRed);
75    data->GetEtaBins()->SetTitleFont(120);
76    data->GetEtaBins()->SetTitle("h");
77    data->GetPhiBins()->SetTitleFont(120);
78    data->GetPhiBins()->SetTitle("f");
79    data->IncDenyDestroy();
80
81    // Plotting the lego histogram in a new tab
82    CreateHistoLego(data);
83    
84    // Plotting the 3D histogram
85    TEveCalo3D *calo3d = Create3DView(data);
86
87    // Plotting projections RPhi and RhoZ
88    CreateProjections(data, calo3d);
89    
90    gEve->Redraw3D(kTRUE);
91
92    return data;
93 }
94
95 //______________________________________________________________________________
96 Double_t GetPhi(Double_t phi)
97 {
98    if (phi > pi) {
99       phi -= 2*pi;
100    }
101    return phi;
102 }
103
104 //______________________________________________________________________________
105 TEveCaloLego* CreateHistoLego(TEveCaloData* data){
106
107    TGLViewer* glv;
108
109    // Viewer initialization, tab creation
110    if ( g_histo2d_v == 0 ) {
111       TEveWindowSlot *slot    = 0;
112       TEveBrowser    *browser = gEve->GetBrowser();
113
114       slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
115       slot->MakeCurrent();
116       g_histo2d_v = gEve->SpawnNewViewer("2D Lego Histogram", "2D Lego Histogram");
117       g_histo2d_s = gEve->SpawnNewScene("2D Lego Histogram", "2D Lego Histogram");
118       g_histo2d_v->AddScene(g_histo2d_s);
119       g_histo2d_v->SetElementName("2D Lego Viewer");
120       g_histo2d_s->SetElementName("2D Lego Scene");
121
122       glv = g_histo2d_v->GetGLViewer();
123       g_histo2d_lego_overlay = new TEveCaloLegoOverlay();
124       glv->AddOverlayElement(g_histo2d_lego_overlay);
125       glv->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
126    } else {
127       glv = g_histo2d_v->GetGLViewer(); 
128    }
129    
130    //plotting histo
131    TEveCaloLego* lego = new TEveCaloLego(data);
132    g_histo2d_s->AddElement(lego);
133    AliEveEventManager::RegisterTransient(lego);
134
135    // move to real world coordinates
136    lego->InitMainTrans();
137    Float_t sc = TMath::Min(lego->GetEtaRng(), lego->GetPhiRng());
138    lego->RefMainTrans().SetScale(sc, sc, sc);
139
140    // set event handler to move from perspective to orthographic view.
141    glv->SetEventHandler(new TEveLegoEventHandler(glv->GetGLWidget(), glv, lego));
142
143    g_histo2d_lego_overlay->SetCaloLego(lego);
144
145    return lego;
146 }
147
148 //______________________________________________________________________________
149 TEveCalo3D* Create3DView(TEveCaloData* data){
150   
151    //initialization
152    if ( g_histo2d_s2 == 0 ) {
153       g_histo2d_s2 = gEve->SpawnNewScene("3D Histogram", "3D Histogram");
154       gEve->GetDefaultViewer()->AddScene(g_histo2d_s2);
155       g_histo2d_s2->SetElementName("3D Histogram Scene");
156    }
157  
158    TEveCalo3D* calo3d = new TEveCalo3D(data);
159    AliEveEventManager::RegisterTransient(calo3d);
160    
161    calo3d->SetBarrelRadius(550);
162    calo3d->SetEndCapPos(550);
163    g_histo2d_s2->AddElement(calo3d);
164  
165    return calo3d;
166 }
167
168 //______________________________________________________________________________
169 AliEveMultiView* CreateProjections(TEveCaloData* data, TEveCalo3D *calo3d){
170
171    AliEveMultiView *al = AliEveMultiView::Instance();
172    al->ImportEventRPhi(calo3d);
173    al->ImportEventRhoZ(calo3d);
174
175    return al;
176 }