]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/macros/alieve_online.C
cosmetics
[u/mrichter/AliRoot.git] / EVE / macros / alieve_online.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 class TEveProjectionManager;
8 class TEveGeoShape;
9 class TEveUtil;
10 class AliTriggerAnalysis;
11 class AliSysInfo;
12
13 TH2D* V0StateHistogram;
14
15 Bool_t gCenterProjectionsAtPrimaryVertex = kFALSE;
16
17 void alieve_online_init()
18 {
19   
20   if (gSystem->Getenv("ALICE_ROOT") != 0)
21   {
22     gInterpreter->AddIncludePath(Form("%s/MUON", gSystem->Getenv("ALICE_ROOT")));
23     gInterpreter->AddIncludePath(Form("%s/MUON/mapping", gSystem->Getenv("ALICE_ROOT")));
24   }
25   
26   TEveUtil::AssertMacro("VizDB_scan.C");
27
28   TEveBrowser *browser = gEve->GetBrowser();
29   browser->ShowCloseTab(kFALSE);
30
31   // Gentle-geom loading changes gGeoManager.
32   TEveGeoManagerHolder mgrRestore;
33
34   AliEveMultiView *multiView = new AliEveMultiView(kTRUE);
35
36   TEveUtil::LoadMacro("geom_gentle.C");
37   multiView->InitGeomGentle(geom_gentle(),
38                              geom_gentle_rphi(), 
39                              geom_gentle_rhoz(),
40                              geom_gentle_rhoz());
41
42   TEveUtil::LoadMacro("geom_gentle_trd.C");
43   multiView->InitGeomGentleTrd(geom_gentle_trd());
44
45   TEveUtil::LoadMacro("geom_gentle_muon.C");
46   multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);
47
48   //============================================================================
49   // Standard macros to execute -- not all are enabled by default.
50   //============================================================================
51
52   AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
53
54   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex",             "",                kTRUE));
55   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse",     "",                kTRUE));
56   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box",         "kFALSE, 3, 3, 3", kFALSE));
57   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_spd",         "",                kTRUE));
58   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_spd", "",                kTRUE));
59   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_spd",     "kFALSE, 3, 3, 3", kFALSE));
60   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_tpc",         "",                kFALSE));
61   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_tpc", "",                kFALSE));
62   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_tpc",     "kFALSE, 3, 3, 3", kFALSE));
63
64   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus ITS",   "its_clusters.C++",   "its_clusters"));
65   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TPC",   "tpc_clusters.C++",   "tpc_clusters"));
66   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TRD",   "trd_clusters.C++",   "trd_clusters"));
67   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TOF",   "tof_clusters.C++",   "tof_clusters"));
68   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus HMPID", "hmpid_clusters.C++", "hmpid_clusters"));
69   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus MUON",  "muon_clusters.C++",  "muon_clusters"));
70
71   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG EMCAL",   "emcal_digits.C++",   "emcal_digits"));
72
73   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ITS",     "its_raw.C",     "its_raw"));
74   //  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TPC",     "tpc_raw.C",     "tpc_raw"));
75   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TOF",     "tof_raw.C",     "tof_raw"));
76   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW VZERO",   "vzero_raw.C",   "vzero_raw", "", kFALSE));
77   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ACORDE",  "acorde_raw.C",  "acorde_raw", "", kFALSE));
78   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW MUON",    "muon_raw.C++",  "muon_raw"));
79   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW FMD",     "fmd_raw.C",     "fmd_raw"));
80
81   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C++",        "esd_tracks",             "", kFALSE));
82   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C++",        "esd_tracks_MI",          "", kFALSE));
83   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C++",        "esd_tracks_by_category", "", kTRUE));
84   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track MUON", "esd_muon_tracks.C++", "esd_muon_tracks",        "kTRUE,kFALSE", kTRUE));
85   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC FMD",        "fmd_esd.C",           "fmd_esd",                "", kTRUE));
86
87   // ???
88   // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C++", "trd_detectors",         "", kFALSE));
89   // trd_tracks disabled due to memory leaks
90
91   //----------------------------------------------------------------------------
92
93   slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
94   slot->StartEmbedding();
95   AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);
96   slot->StopEmbedding("DataSelection");
97   exewin->PopulateMacros();
98
99   //============================================================================
100   // VZERO state histogram
101   //============================================================================
102
103   slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
104   slot->StartEmbedding();  
105   TCanvas* pad = new TCanvas();
106
107   gStyle->SetCanvasColor(0);
108
109   V0StateHistogram = new TH2D("V0 Histogram","V0 Trigger State", 4, 0, 4, 4, 0, 4);
110   V0StateHistogram->Draw("colz");
111
112   V0StateHistogram->GetXaxis()->SetBinLabel(1,"V0A Invalid");
113   V0StateHistogram->GetXaxis()->SetBinLabel(2,"V0A Empty");
114   V0StateHistogram->GetXaxis()->SetBinLabel(3,"V0A BB");
115   V0StateHistogram->GetXaxis()->SetBinLabel(4,"V0A BG");
116
117   V0StateHistogram->GetYaxis()->SetBinLabel(1,"V0C Invalid");
118   V0StateHistogram->GetYaxis()->SetBinLabel(2,"V0C Empty");
119   V0StateHistogram->GetYaxis()->SetBinLabel(3,"V0C BB");
120   V0StateHistogram->GetYaxis()->SetBinLabel(4,"V0C BG");
121
122   slot->StopEmbedding("V0 Trigger State");
123
124   //============================================================================
125   // Final GUI setup
126   //============================================================================
127
128   browser->GetTabRight()->SetTab(1);
129
130   browser->StartEmbedding(TRootBrowser::kBottom);
131   new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
132   browser->StopEmbedding("EventCtrl");
133
134   browser->MoveResize(0, 0, gClient->GetDisplayWidth(),
135                       gClient->GetDisplayHeight() - 32);
136
137   gEve->GetViewers()->SwitchColorSet();
138
139   TString autoRun(gSystem->Getenv("ONLINERECO_AUTORUN"));
140   if (autoRun == "1" || autoRun.CompareTo("true", TString::kIgnoreCase) == 0)
141   {
142     AliEveEventManager::GetMaster()->SetAutoLoad(kTRUE);
143   }
144
145   {
146     TGTab *tab = gEve->GetBrowser()->GetTab(2);
147
148     TGHorizontalFrame *hf = (TGHorizontalFrame*) tab->GetParent();
149     TGVerticalFrame   *vf = (TGVerticalFrame*)   hf ->GetParent();
150
151     hf->Resize(hf->GetWidth(), hf->GetHeight() + 80);
152     vf->Layout();
153   }
154
155   gEve->GetWindowManager()->HideAllEveDecorations();
156
157   if(gEve->GetScenes()->FindChild("Geometry scene")->FindChild("Gentle MUON"))
158   {
159     gEve->GetScenes()->FindChild("Geometry scene")->FindChild("Gentle MUON")->SetRnrSelf(kFALSE);
160     gEve->GetScenes()->FindChild("Geometry scene")->FindChild("Gentle MUON")->SetRnrChildren(kFALSE);
161   }
162
163   if(gEve->GetScenes()->FindChild("Muon Geometry")->FindChild("Gentle MUON [P]"))
164   {
165     gEve->GetScenes()->FindChild("Muon Geometry")->FindChild("Gentle MUON [P]")->SetRnrSelf(kTRUE);
166     gEve->GetScenes()->FindChild("Muon Geometry")->FindChild("Gentle MUON [P]")->SetRnrChildren(kTRUE);
167   }
168
169   gEve->FullRedraw3D(kTRUE);
170
171   TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();
172   TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();
173   TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();
174
175   glv1->CurrentCamera().RotateRad(-0.4, -1.8);
176   glv2->CurrentCamera().Dolly(450, kFALSE, kFALSE);
177   glv3->CurrentCamera().Dolly(1500, kFALSE, kFALSE);
178
179   gEve->FullRedraw3D();
180
181 }
182
183 Int_t      g_pic_id  = 0;
184 Int_t      g_pic_max = 100;
185 TTimeStamp g_pic_prev(0, 0);
186
187 void alieve_online_on_new_event()
188 {
189   AliSysInfo::AddStamp("on_new_event_start");
190
191   AliTriggerAnalysis atr;
192
193   AliESDEvent* esd = AliEveEventManager::AssertESD();
194   Double_t x[3] = { 0, 0, 0 };
195   esd->GetPrimaryVertex()->GetXYZ(x);
196
197   TEveElement* top = gEve->GetCurrentEvent();
198
199   AliEveMultiView *multiView = AliEveMultiView::Instance();
200
201 /*
202   TGLViewer *glv = (dynamic_cast<TEveViewer*>(gEve->GetViewers()->FindChild("3D View")))->GetGLViewer();
203   
204   if(gEve->GetScenes()->FirstChild()->FindChild("Gentle MUON"))
205   {
206     if (esd->GetNumberOfMuonTracks() == 0 && !gEve->GetKeepEmptyCont())
207     {
208       gEve->GetScenes()->FirstChild()->FindChild("Gentle MUON")->SetRnrChildren(kFALSE);
209       
210       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters"))
211         gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters")->SetRnrSelf(kFALSE);
212       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits"))
213         gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits")->SetRnrChildren(kFALSE);
214
215       gEve->FullRedraw3D(kTRUE);
216       glv->CurrentCamera().RotateRad(-0.4, -1.8);
217     }
218     else
219     {
220       gEve->GetScenes()->FirstChild()->FindChild("Gentle MUON")->SetRnrChildren(kTRUE);
221
222       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters"))
223         gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters")->SetRnrSelf(kTRUE);
224       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits"))
225         gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits")->SetRnrChildren(kTRUE);
226
227       gEve->FullRedraw3D(kTRUE);
228       glv->CurrentCamera().RotateRad(-0.4, 1);
229     }
230   }
231
232   glv->DoDraw();
233 */
234
235   AliTriggerAnalysis::V0Decision decisionV0a = 
236     atr.V0Trigger(esd, AliTriggerAnalysis::kASide, kFALSE);
237   AliTriggerAnalysis::V0Decision decisionV0c = 
238     atr.V0Trigger(esd, AliTriggerAnalysis::kCSide, kFALSE);
239
240   Double_t a = 0;
241   Double_t c = 0;
242
243   if( decisionV0a == AliTriggerAnalysis::kV0Invalid ) a = 0.5;
244   if( decisionV0a == AliTriggerAnalysis::kV0Empty ) a = 1.5;
245   if( decisionV0a == AliTriggerAnalysis::kV0BB ) a = 2.5;
246   if( decisionV0a == AliTriggerAnalysis::kV0BG ) a = 3.5;
247
248   if( decisionV0c == AliTriggerAnalysis::kV0Invalid ) c = 0.5;
249   if( decisionV0c == AliTriggerAnalysis::kV0Empty ) c = 1.5;
250   if( decisionV0c == AliTriggerAnalysis::kV0BB ) c = 2.5;
251   if( decisionV0c == AliTriggerAnalysis::kV0BG ) c = 3.5;
252
253   V0StateHistogram->Fill(a,c);
254   AliSysInfo::AddStamp("on_new_event_after_trig");
255
256   TGLViewer *glv = multiView->Get3DView()->GetGLViewer();
257   TGLViewer *glv1 = multiView->GetRPhiView()->GetGLViewer();
258   TGLViewer *glv2 = multiView->GetRhoZView()->GetGLViewer();
259  
260   Double_t RPhiCameraFrustrumCenter = TMath::Sqrt(glv1->CurrentCamera().FrustumCenter().X()*glv1->CurrentCamera().FrustumCenter().X() + glv1->CurrentCamera().FrustumCenter().Y()*glv1->CurrentCamera().FrustumCenter().Y());
261
262   Double_t RhoZCameraFrustrumCenter = TMath::Sqrt(glv2->CurrentCamera().FrustumCenter().X()*glv2->CurrentCamera().FrustumCenter().X() + glv2->CurrentCamera().FrustumCenter().Y()*glv2->CurrentCamera().FrustumCenter().Y());
263
264   if(RPhiCameraFrustrumCenter > 500 || RhoZCameraFrustrumCenter > 500)
265   {
266
267     glv->ResetCurrentCamera();
268     glv1->ResetCurrentCamera();
269     glv2->ResetCurrentCamera();
270
271     glv->CurrentCamera().RotateRad(-0.4, -1.8);
272     glv1->CurrentCamera().Dolly(450, kFALSE, kFALSE);
273     glv2->CurrentCamera().Dolly(1500, kFALSE, kFALSE);
274
275     gEve->FullRedraw3D();
276
277   }
278
279   multiView->DestroyEventRPhi();
280   if (gCenterProjectionsAtPrimaryVertex)
281     multiView->SetCenterRPhi(x[0], x[1], x[2]);
282   multiView->ImportEventRPhi(top);
283
284   multiView->DestroyEventRhoZ();
285   if (gCenterProjectionsAtPrimaryVertex)
286     multiView->SetCenterRhoZ(x[0], x[1], x[2]);
287   multiView->ImportEventRhoZ(top);
288
289   AliSysInfo::AddStamp("on_new_event_after_rozphi");
290
291   if(multiView->IsMuonView()) { multiView->DestroyEventMuon(); multiView->ImportEventMuon(top); }
292
293   if(gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("MUON Clusters"))
294   {
295     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("MUON Clusters")->SetRnrSelf(kFALSE);
296     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("MUON Clusters")->SetRnrChildren(kFALSE);
297   }
298
299   if(gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("ESD MUON Clusters"))
300   {
301     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("ESD MUON Clusters")->SetRnrSelf(kFALSE);
302     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("ESD MUON Clusters")->SetRnrChildren(kFALSE);
303   }
304
305   if(gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("ESD MUON Tracks"))
306   {
307     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("ESD MUON Tracks")->SetRnrSelf(kFALSE);
308     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("ESD MUON Tracks")->SetRnrChildren(kFALSE);
309   }
310
311   if(gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("MUON Raw digits"))
312   {
313     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("MUON Raw digits")->SetRnrSelf(kFALSE);
314     gEve->GetScenes()->FindChild("Event scene")->FindChild("Online Event")->FindChild("MUON Raw digits")->SetRnrChildren(kFALSE);
315   }
316
317   if(gEve->GetScenes()->FindChild("Muon Event Data"))
318   {
319     if(gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]"))
320     {
321       if(gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("MUON Clusters [P]"))
322       {
323         gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("MUON Clusters [P]")->SetRnrSelf(kTRUE);
324         gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("MUON Clusters [P]")->SetRnrChildren(kTRUE);
325       }
326
327       if(gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("ESD MUON Clusters [P]"))
328       {
329         gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("ESD MUON Clusters [P]")->SetRnrSelf(kTRUE);
330         gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("ESD MUON Clusters [P]")->SetRnrChildren(kTRUE);
331       }
332
333       if(gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("ESD MUON Tracks [P]"))
334       {
335         gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("ESD MUON Tracks [P]")->SetRnrSelf(kTRUE);
336         gEve->GetScenes()->FindChild("Muon Event Data")->FindChild("Online Event [P]")->FindChild("ESD MUON Tracks [P]")->SetRnrChildren(kTRUE);
337       }
338     }
339   }
340
341   if(gEve->GetScenes()->FindChild("RhoZ Event Data"))
342   {
343     if(gEve->GetScenes()->FindChild("RhoZ Event Data")->FindChild("Online Event [P]"))
344     {
345       if(gEve->GetScenes()->FindChild("RhoZ Event Data")->FindChild("Online Event [P]")->FindChild("FMD [P]"))
346       {
347         gEve->GetScenes()->FindChild("RhoZ Event Data")->FindChild("Online Event [P]")->FindChild("FMD [P]")->SetRnrSelf(kFALSE);
348         gEve->GetScenes()->FindChild("RhoZ Event Data")->FindChild("Online Event [P]")->FindChild("FMD [P]")->SetRnrChildren(kFALSE);
349       }
350     }
351   }
352
353   if(gEve->GetScenes()->FindChild("RPhi Event Data"))
354   {
355     if(gEve->GetScenes()->FindChild("RPhi Event Data")->FindChild("Online Event [P]"))
356     {
357       if(gEve->GetScenes()->FindChild("RPhi Event Data")->FindChild("Online Event [P]")->FindChild("FMD [P]"))
358       {
359         gEve->GetScenes()->FindChild("RPhi Event Data")->FindChild("Online Event [P]")->FindChild("FMD [P]")->SetRnrSelf(kFALSE);
360         gEve->GetScenes()->FindChild("RPhi Event Data")->FindChild("Online Event [P]")->FindChild("FMD [P]")->SetRnrChildren(kFALSE);
361       }
362     }
363   }
364   AliSysInfo::AddStamp("on_new_event_after_muon");
365
366   gEve->FullRedraw3D();
367
368   // Register image to amore.
369   // const TString pichost("aldaqacrs3");
370   const TString pichost(gEnv->GetValue("AliEve.imageDumpHost", "aldaqacrs3"));
371   TTimeStamp now;
372   Double_t delta = now.AsDouble() - g_pic_prev.AsDouble();
373
374   printf("Pre image dump: host='%s', delta=%f.\n",
375          gSystem->HostName(), delta);
376
377   AliSysInfo::AddStamp("on_new_event_pic");
378   if (pichost == gSystem->HostName() && delta >= 30)
379   {
380     TString id;      id.Form("online-viz-%03d", g_pic_id);
381     TString pic(id); pic += ".png";
382
383     printf("In image dump: file='%s'.\n", pic.Data());
384
385     gEve->GetBrowser()->RaiseWindow();
386     gEve->FullRedraw3D();
387     gSystem->ProcessEvents();
388
389     Int_t status;
390
391     // create screenshots from OpenGL views
392     TEveUtil::LoadMacro("saveViews.C+");
393     saveViews(pic.Data()); 
394
395     // send screenshot to AMORE
396     status = gSystem->Exec(TString::Format("SendImageToAmore %s %s %d",
397                           id.Data(), pic.Data(),
398                           AliEveEventManager::AssertRawReader()->GetRunNumber()));
399
400     printf("Post AMORE reg -- status=%d, run=%d.\n", status,
401            AliEveEventManager::AssertRawReader()->GetRunNumber());
402
403     if (++g_pic_id >= g_pic_max)
404       g_pic_id = 0;
405     g_pic_prev.Set();
406   }
407   AliSysInfo::AddStamp("on_new_event_end");
408
409 }