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