]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/histo2d_all_events.C
Update of the 2d histograms from Stefano
[u/mrichter/AliRoot.git] / EVE / alice-macros / histo2d_all_events.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_all_events_v0 = 0;
11 TEveViewer *g_histo2d_all_events_v1 = 0;
12 TEveViewer *g_histo2d_all_events_v2 = 0;
13 TEveViewer *g_histo2d_all_events_v3 = 0;
14 TEveScene  *g_histo2d_all_events_s0 = 0;
15 TEveScene  *g_histo2d_all_events_s1 = 0;
16 TEveScene  *g_histo2d_all_events_s2 = 0;
17 TEveScene  *g_histo2d_all_events_s3 = 0;
18 TEveCaloLegoOverlay* g_histo2d_all_events_lego_overlay = 0;
19 TEveWindowSlot* g_histo2d_all_events_slot = 0;
20
21
22 TEveCaloDataHist* histo2d_all_events()
23 {
24
25    TEveCaloDataHist* data_t;
26    
27    if ( g_histo2d_all_events_slot == 0 ) {
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 
41          for ( int event = 0; event < t->GetEntries(); event++ ) {      
42             t->GetEntry(event);
43                for ( int n = 0; n < esd->GetNumberOfTracks(); ++n ) {    
44   
45                   if ( esd->GetTrack(n)->GetSign() > 0 ) {
46                      histopos_t->Fill(esd->GetTrack(n)->Eta(),
47                                       GetPhi(esd->GetTrack(n)->Phi()),
48                                       fabs(esd->GetTrack(n)->Pt()));
49                   } else {
50                      histoneg_t->Fill(esd->GetTrack(n)->Eta(),
51                                       GetPhi(esd->GetTrack(n)->Phi()),
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
69       g_histo2d_all_events_slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
70       TEveWindowPack* packH = g_histo2d_all_events_slot->MakePack();
71       packH->SetElementName("Projections");
72       packH->SetHorizontal();
73       packH->SetShowTitleBar(kFALSE);
74
75       g_histo2d_all_events_slot = packH->NewSlot();
76       TEveWindowPack* pack0 = g_histo2d_all_events_slot->MakePack();
77       pack0->SetShowTitleBar(kFALSE);
78       TEveWindowSlot*  slotLeftTop   = pack0->NewSlot();
79       TEveWindowSlot* slotLeftBottom = pack0->NewSlot();
80
81       g_histo2d_all_events_slot = packH->NewSlot();
82       TEveWindowPack* pack1 = g_histo2d_all_events_slot->MakePack();
83       pack1->SetShowTitleBar(kFALSE);
84       TEveWindowSlot* slotRightTop    = pack1->NewSlot();
85       TEveWindowSlot* slotRightBottom = pack1->NewSlot();
86
87       // Creating viewers and scenes   
88       TEveCalo3D* calo3d = Create3DView(data_t, slotLeftTop);
89       CreateHistoLego(data_t, slotLeftBottom);
90       CreateProjections(data_t, calo3d, slotRightTop, slotRightBottom);
91
92       gEve->Redraw3D(kTRUE);
93
94       cout<<"Filling histogram... Finished"<<endl;
95    }
96
97    return data_t;
98 }
99
100 //______________________________________________________________________________
101 Double_t GetPhi(Double_t phi)
102 {
103    if (phi > pi) {
104       phi -= 2*pi;
105    }
106    return phi;
107 }
108
109 //______________________________________________________________________________
110 TEveCaloLego* CreateHistoLego(TEveCaloData* data, TEveWindowSlot* slot){
111
112    TEveCaloLego* lego;
113
114    // Viewer initialization, tab creation
115    if ( g_histo2d_all_events_v0 == 0 ) {
116
117       TEveBrowser *browser = gEve->GetBrowser();
118       slot->MakeCurrent();
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);
128       glv->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
129
130       // Plotting histogram lego
131       lego = new TEveCaloLego(data);
132       g_histo2d_all_events_s0->AddElement(lego);
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
142       g_histo2d_all_events_lego_overlay->SetCaloLego(lego);
143    }
144
145    return lego;
146 }
147
148 //______________________________________________________________________________
149 TEveCalo3D* Create3DView(TEveCaloData* data, TEveWindowSlot* slot){
150
151    TEveCalo3D* calo3d;
152
153    if ( g_histo2d_all_events_v1 == 0 ) {
154       
155       TEveBrowser *browser = gEve->GetBrowser();
156       slot->MakeCurrent();
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");
162
163       calo3d = new TEveCalo3D(data);
164    
165       calo3d->SetBarrelRadius(550);
166       calo3d->SetEndCapPos(550);
167       g_histo2d_all_events_s1->AddElement(calo3d);
168    } 
169
170    return calo3d;
171 }
172
173 //______________________________________________________________________________
174 void CreateProjections(TEveCaloData* data, TEveCalo3D *calo3d, TEveWindowSlot* slot1, TEveWindowSlot* slot2){
175
176    if ( g_histo2d_all_events_v2 == 0 ) {
177       
178       TEveBrowser *browser = gEve->GetBrowser();
179       slot1->MakeCurrent();
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");
185
186       TEveProjectionManager* mng1 = new TEveProjectionManager();
187       mng1->SetProjection(TEveProjection::kPT_RPhi);
188
189       TEveProjectionAxes* axeg_histo2d_all_events_s1 = new TEveProjectionAxes(mng1);
190       g_histo2d_all_events_s2->AddElement(axeg_histo2d_all_events_s1);
191       TEveCalo2D* calo2d1 = (TEveCalo2D*) mng1->ImportElements(calo3d);
192       g_histo2d_all_events_s2->AddElement(calo2d1);
193
194       g_histo2d_all_events_v2->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
195    } 
196
197    if ( g_histo2d_all_events_v3 == 0 ) {
198       
199       TEveBrowser *browser = gEve->GetBrowser();
200       slot2->MakeCurrent();
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");
206
207       TEveProjectionManager* mng2 = new TEveProjectionManager();
208       mng2->SetProjection(TEveProjection::kPT_RhoZ);
209
210       TEveProjectionAxes* axeg_histo2d_all_events_s2 = new TEveProjectionAxes(mng2);
211       g_histo2d_all_events_s3->AddElement(axeg_histo2d_all_events_s2);
212       TEveCalo2D* calo2d2 = (TEveCalo2D*) mng2->ImportElements(calo3d);
213       g_histo2d_all_events_s3->AddElement(calo2d2);
214
215       g_histo2d_all_events_v3->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
216    } 
217
218    return;
219 }