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