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