Added optional 3rd side view in AliEveMultiViwe (with MUON arm),
[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
11 Bool_t gCenterProjectionsAtPrimaryVertex = kFALSE;
12
13 void alieve_online_init()
14 {
15   
16   if (gSystem->Getenv("ALICE_ROOT") != 0)
17   {
18     gInterpreter->AddIncludePath(Form("%s/MUON", gSystem->Getenv("ALICE_ROOT")));
19     gInterpreter->AddIncludePath(Form("%s/MUON/mapping", gSystem->Getenv("ALICE_ROOT")));
20   }
21   
22   TEveUtil::AssertMacro("VizDB_scan.C");
23
24   TEveBrowser *browser = gEve->GetBrowser();
25   browser->ShowCloseTab(kFALSE);
26
27   // Gentle-geom loading changes gGeoManager.
28   TEveGeoManagerHolder mgrRestore;
29
30   AliEveMultiView *multiView = new AliEveMultiView(kTRUE);
31
32   TEveUtil::LoadMacro("geom_gentle.C");
33   multiView->InitGeomGentle(geom_gentle(),
34                              geom_gentle_rphi(), 
35                              geom_gentle_rhoz(),
36                              geom_gentle_rhoz());
37
38   TEveUtil::LoadMacro("geom_gentle_trd.C");
39   multiView->InitGeomGentleTrd(geom_gentle_trd());
40
41   TEveUtil::LoadMacro("geom_gentle_muon.C");
42   multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);
43
44   //============================================================================
45   // Standard macros to execute -- not all are enabled by default.
46   //============================================================================
47
48   AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
49
50   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex",             "",                kTRUE));
51   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse",     "",                kTRUE));
52   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box",         "kFALSE, 3, 3, 3", kFALSE));
53   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_spd",         "",                kTRUE));
54   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_spd", "",                kTRUE));
55   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_spd",     "kFALSE, 3, 3, 3", kFALSE));
56   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_tpc",         "",                kFALSE));
57   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_tpc", "",                kFALSE));
58   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_tpc",     "kFALSE, 3, 3, 3", kFALSE));
59
60   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus ITS",   "its_clusters.C++",   "its_clusters"));
61   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TPC",   "tpc_clusters.C++",   "tpc_clusters"));
62   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TRD",   "trd_clusters.C++",   "trd_clusters"));
63   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TOF",   "tof_clusters.C++",   "tof_clusters"));
64   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus HMPID", "hmpid_clusters.C++", "hmpid_clusters"));
65   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus MUON",  "muon_clusters.C++",  "muon_clusters"));
66
67   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TOF",   "emcal_digits.C++",   "emcal_digits"));
68
69   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ITS",     "its_raw.C",     "its_raw"));
70   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TPC",     "tpc_raw.C",     "tpc_raw"));
71   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TOF",     "tof_raw.C",     "tof_raw"));
72   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW VZERO",   "vzero_raw.C",   "vzero_raw"));
73   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ACORDE",  "acorde_raw.C",  "acorde_raw"));
74   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW MUON",    "muon_raw.C++",  "muon_raw"));
75   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW FMD",     "fmd_raw.C",     "fmd_raw"));
76
77   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks",             "", kFALSE));
78   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_MI",          "", kFALSE));
79   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_by_category", "", kTRUE));
80   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track MUON", "esd_muon_tracks.C++", "esd_muon_tracks",        "kTRUE,kFALSE", kTRUE));
81   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC FMD",        "fmd_esd.C",           "fmd_esd",                "", kTRUE));
82
83   // ???
84   // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C++", "trd_detectors",         "", kFALSE));
85   // trd_tracks disabled due to memory leaks
86
87   //----------------------------------------------------------------------------
88
89   slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
90   slot->StartEmbedding();
91   AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);
92   slot->StopEmbedding("DataSelection");
93   exewin->PopulateMacros();
94
95   //============================================================================
96   // Final GUI setup
97   //============================================================================
98
99   browser->GetTabRight()->SetTab(1);
100
101   browser->StartEmbedding(TRootBrowser::kBottom);
102   new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
103   browser->StopEmbedding("EventCtrl");
104
105   browser->MoveResize(0, 0, gClient->GetDisplayWidth(),
106                       gClient->GetDisplayHeight() - 32);
107
108   gEve->GetViewers()->SwitchColorSet();
109
110   TString autoRun(gSystem->Getenv("ONLINERECO_AUTORUN"));
111   if (autoRun == "1" || autoRun.CompareTo("true", TString::kIgnoreCase) == 0)
112   {
113     AliEveEventManager::GetMaster()->SetAutoLoad(kTRUE);
114   }
115
116   {
117     TGTab *tab = gEve->GetBrowser()->GetTab(2);
118
119     TGHorizontalFrame *hf = (TGHorizontalFrame*) tab->GetParent();
120     TGVerticalFrame   *vf = (TGVerticalFrame*)   hf ->GetParent();
121
122     hf->Resize(hf->GetWidth(), hf->GetHeight() + 80);
123     vf->Layout();
124   }
125
126   gEve->GetWindowManager()->HideAllEveDecorations();
127
128   gEve->FullRedraw3D(kTRUE);
129
130   TGLViewer *glv = multiView->Get3DView()->GetGLViewer();
131   gEve->FullRedraw3D(kTRUE);
132   glv->CurrentCamera().RotateRad(-0.4, -1.8);
133
134 }
135
136 //   multiView->Get3DView()->GetGLViewer()->CurrentCamera().RotateRad(-1, 1)
137
138 Int_t      g_pic_id  = 0;
139 Int_t      g_pic_max = 100;
140 TTimeStamp g_pic_prev(0, 0);
141
142 void alieve_online_on_new_event()
143 {
144   AliESDEvent* esd = AliEveEventManager::AssertESD();
145   Double_t x[3] = { 0, 0, 0 };
146   esd->GetPrimaryVertex()->GetXYZ(x);
147
148   TEveElement* top = gEve->GetCurrentEvent();
149
150   AliEveMultiView *multiView = AliEveMultiView::Instance();
151
152 /*
153   TGLViewer *glv = (dynamic_cast<TEveViewer*>(gEve->GetViewers()->FindChild("3D View")))->GetGLViewer();
154   
155   if(gEve->GetScenes()->FirstChild()->FindChild("Gentle MUON"))
156   {
157     if (esd->GetNumberOfMuonTracks() == 0 && !gEve->GetKeepEmptyCont())
158     {
159       gEve->GetScenes()->FirstChild()->FindChild("Gentle MUON")->SetRnrChildren(kFALSE);
160       
161       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters"))
162         gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters")->SetRnrSelf(kFALSE);
163       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits"))
164         gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits")->SetRnrChildren(kFALSE);
165
166       gEve->FullRedraw3D(kTRUE);
167       glv->CurrentCamera().RotateRad(-0.4, -1.8);
168     }
169     else
170     {
171       gEve->GetScenes()->FirstChild()->FindChild("Gentle MUON")->SetRnrChildren(kTRUE);
172
173       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters"))
174         gEve->GetEventScene()->FirstChild()->FindChild("MUON Clusters")->SetRnrSelf(kTRUE);
175       if(gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits"))
176         gEve->GetEventScene()->FirstChild()->FindChild("MUON Raw digits")->SetRnrChildren(kTRUE);
177
178       gEve->FullRedraw3D(kTRUE);
179       glv->CurrentCamera().RotateRad(-0.4, 1);
180     }
181   }
182
183   glv->DoDraw();
184 */
185   TGLViewer *glv = (dynamic_cast<TEveViewer*>(gEve->GetViewers()->FindChild("3D View")))->GetGLViewer();
186   TGLViewer *glv1 = (dynamic_cast<TEveViewer*>(gEve->GetViewers()->FindChild("RPhi View")))->GetGLViewer();
187   TGLViewer *glv2 = (dynamic_cast<TEveViewer*>(gEve->GetViewers()->FindChild("RhoZ View")))->GetGLViewer();
188  
189   Double_t RPhiCameraFrustrumCenter = TMath::Sqrt(glv1->CurrentCamera().FrustumCenter().X()*glv1->CurrentCamera().FrustumCenter().X() + glv1->CurrentCamera().FrustumCenter().Y()*glv1->CurrentCamera().FrustumCenter().Y());
190
191   Double_t RhoZCameraFrustrumCenter = TMath::Sqrt(glv2->CurrentCamera().FrustumCenter().X()*glv2->CurrentCamera().FrustumCenter().X() + glv2->CurrentCamera().FrustumCenter().Y()*glv2->CurrentCamera().FrustumCenter().Y());
192
193   if(RPhiCameraFrustrumCenter > 500 || RhoZCameraFrustrumCenter > 500)
194   {
195
196     glv->ResetCurrentCamera();
197     glv->CurrentCamera().RotateRad(-0.3, -1.8);
198     glv->CurrentCamera().Dolly(250, kFALSE, kFALSE);
199
200     glv1->ResetCurrentCamera();
201     glv2->ResetCurrentCamera();
202
203     gEve->FullRedraw3D();
204
205   }
206
207   multiView->DestroyEventRPhi();
208   if (gCenterProjectionsAtPrimaryVertex)
209     multiView->SetCenterRPhi(x[0], x[1], x[2]);
210   multiView->ImportEventRPhi(top);
211
212   multiView->DestroyEventRhoZ();
213   if (gCenterProjectionsAtPrimaryVertex)
214     multiView->SetCenterRhoZ(x[0], x[1], x[2]);
215   multiView->ImportEventRhoZ(top);
216
217   if(multiView->IsMuonView()) multiView->ImportEventMuon(top);
218
219   // Register image to amore.
220   const TString pichost("aldaqacrs3");
221   TTimeStamp now;
222   Double_t delta = now.AsDouble() - g_pic_prev.AsDouble();
223
224   printf("Pre image dump: host='%s', delta=%f.\n",
225          gSystem->HostName(), delta);
226
227   if (pichost == gSystem->HostName() && delta >= 30)
228   {
229     TString id;      id.Form("online-viz-%03d", g_pic_id);
230     TString pic(id); pic += ".png";
231
232     printf("In image dump: file='%s'.\n", pic.Data());
233
234     gEve->GetBrowser()->RaiseWindow();
235     gEve->FullRedraw3D();
236     gSystem->ProcessEvents();
237
238     Int_t status;
239
240     status = gSystem->Exec(TString::Format("xwd -id %u | convert - %s",
241                            gEve->GetBrowser()->GetId(), pic.Data()));
242
243     printf("Post capture -- status=%d.\n", status);
244
245     status = gSystem->Exec(TString::Format("SendImageToAmore %s %s %d",
246                           id.Data(), pic.Data(),
247                           AliEveEventManager::AssertRawReader()->GetRunNumber()));
248
249     printf("Post AMORE reg -- status=%d, run=%d.\n", status,
250            AliEveEventManager::AssertRawReader()->GetRunNumber());
251
252     if (++g_pic_id >= g_pic_max)
253       g_pic_id = 0;
254     g_pic_prev.Set();
255   }
256 }