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