Merging STORAGE-dev to master
[u/mrichter/AliRoot.git] / EVE / macros / alieve_online_new.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_new()
18 {
19     printf("alieve_online_init() ...\n");
20  
21  if (gSystem->Getenv("ALICE_ROOT") != 0)
22  {
23          gInterpreter->AddIncludePath(Form("%s/MUON", gSystem->Getenv("ALICE_ROOT")));
24          gInterpreter->AddIncludePath(Form("%s/MUON/mapping", gSystem->Getenv("ALICE_ROOT")));
25  }
26   
27    AliEveEventManager::SetCdbUri("local://$ALICE_ROOT/OCDB");
28   
29   Info("alieve_init", "Adding standard macros.");
30   TString  hack = gSystem->pwd(); // Problem with TGFileBrowser cding
31   alieve_init_import_macros();
32   gSystem->cd(hack);
33   
34   new AliEveEventManager("online", -1);
35   //AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event()");
36   gEve->AddEvent(AliEveEventManager::GetMaster());
37   
38   
39   TEveUtil::AssertMacro("VizDB_scan.C");
40   
41   gSystem->ProcessEvents();
42    
43   
44   
45  
46   
47   AliEveMacroExecutor *exec  = AliEveEventManager::GetMaster()->GetExecutor();
48   TEveBrowser         *browser = gEve->GetBrowser();
49   browser->ShowCloseTab(kFALSE);
50   
51
52   // Gentle-geom loading changes gGeoManager.
53   //TEveGeoManagerHolder mgrRestore;
54
55   AliEveMultiView *multiView = new AliEveMultiView(kTRUE);
56
57   TEveUtil::LoadMacro("geom_gentle.C");
58   multiView->InitGeomGentle(geom_gentle(),
59                              geom_gentle_rphi(), 
60                              geom_gentle_rhoz(),
61                              geom_gentle_rhoz());
62
63     //These macros crashes on mac os. To be checked
64     
65   //TEveUtil::LoadMacro("geom_gentle_trd.C");
66   //multiView->InitGeomGentleTrd(geom_gentle_trd());
67
68   //TEveUtil::LoadMacro("geom_gentle_muon.C");
69   //multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);
70
71   //============================================================================
72   // Standard macros to execute -- not all are enabled by default.
73   //============================================================================
74
75   
76    printf("============ Setting macro executor\n");
77
78   AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
79
80   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex",             "",                kTRUE));
81   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse",     "",                kTRUE));
82   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box",         "kFALSE, 3, 3, 3", kFALSE));
83   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_spd",         "",                kTRUE));
84   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_spd", "",                kTRUE));
85   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_spd",     "kFALSE, 3, 3, 3", kFALSE));
86   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_tpc",         "",                kFALSE));
87   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_tpc", "",                kFALSE));
88   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_tpc",     "kFALSE, 3, 3, 3", kFALSE));
89
90   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus ITS",   "its_clusters.C",   "its_clusters"));
91   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TPC",   "tpc_clusters.C",   "tpc_clusters"));
92   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TRD",   "trd_clusters.C",   "trd_clusters"));
93   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TOF",   "tof_clusters.C",   "tof_clusters"));
94   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus HMPID", "hmpid_clusters.C", "hmpid_clusters"));
95   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus MUON",  "muon_clusters.C",  "muon_clusters"));
96
97   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG EMCAL",   "emcal_digits.C",   "emcal_digits"));
98
99   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ITS",     "its_raw.C",     "its_raw"));
100   //  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TPC",     "tpc_raw.C",     "tpc_raw"));
101   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TOF",     "tof_raw.C",     "tof_raw"));
102   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW VZERO",   "vzero_raw.C",   "vzero_raw", "", kFALSE));
103   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ACORDE",  "acorde_raw.C",  "acorde_raw", "", kFALSE));
104   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW MUON",    "muon_raw.C",  "muon_raw"));
105   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW FMD",     "fmd_raw.C",     "fmd_raw"));
106
107   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks",             "", kFALSE));
108   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_MI",          "", kFALSE));
109   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_by_category", "", kTRUE));
110   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track MUON", "esd_muon_tracks.C", "esd_muon_tracks",        "kTRUE,kFALSE", kTRUE));
111   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC FMD",        "fmd_esd.C",           "fmd_esd",                "", kTRUE));
112
113   // ???
114   // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C", "trd_detectors",         "", kFALSE));
115   // trd_tracks disabled due to memory leaks
116
117   //----------------------------------------------------------------------------
118
119   slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
120   slot->StartEmbedding();
121   AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);
122   slot->StopEmbedding("DataSelection");
123   exewin->PopulateMacros();
124
125   //============================================================================
126   // Final GUI setup
127   //============================================================================
128
129   browser->GetTabRight()->SetTab(1);
130
131   browser->StartEmbedding(TRootBrowser::kBottom);
132   new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
133   browser->StopEmbedding("EventCtrl");
134
135   browser->MoveResize(0, 0, gClient->GetDisplayWidth(),
136                       gClient->GetDisplayHeight() - 32);
137
138   gEve->GetViewers()->SwitchColorSet();
139   gEve->FullRedraw3D(kTRUE);
140         gSystem->ProcessEvents();
141
142   TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();
143   TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();
144   TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();
145
146   glv1->CurrentCamera().RotateRad(-0.4, -1.8);
147   glv2->CurrentCamera().Dolly(450, kFALSE, kFALSE);
148   glv3->CurrentCamera().Dolly(1500, kFALSE, kFALSE);
149
150 //////
151   AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");
152    ///////
153   gEve->FullRedraw3D();
154   gSystem->ProcessEvents();
155   gEve->Redraw3D(kTRUE);
156 }
157
158
159 Int_t      g_pic_id  = 0;
160 Int_t      g_pic_max = 100;
161 TTimeStamp g_pic_prev(0, 0);
162
163 void alieve_online_on_new_event()
164 {
165         AliSysInfo::AddStamp("on_new_event_start");
166
167         Double_t x[3] = { 0, 0, 0 };
168
169         if (AliEveEventManager::HasESD())
170         {
171                 AliESDEvent* esd = AliEveEventManager::AssertESD();
172                 esd->GetPrimaryVertex()->GetXYZ(x);
173
174                 TTimeStamp ts(esd->GetTimeStamp());
175                 TString win_title("Eve Main Window -- Timestamp: ");
176                 win_title += ts.AsString("s");
177                 win_title += "; Event # in ESD file: ";
178                 win_title += esd->GetEventNumberInFile();
179                 gEve->GetBrowser()->SetWindowName(win_title);
180         }
181
182         TEveElement* top = gEve->GetCurrentEvent();
183
184         AliEveMultiView *mv = AliEveMultiView::Instance();
185
186         //mv->DestroyEventRPhi();
187         if (gCenterProjectionsAtPrimaryVertex)
188                 mv->SetCenterRPhi(x[0], x[1], x[2]);
189         mv->ImportEventRPhi(top);
190
191         //mv->DestroyEventRhoZ();
192         if (gCenterProjectionsAtPrimaryVertex)
193                 mv->SetCenterRhoZ(x[0], x[1], x[2]);
194         mv->ImportEventRhoZ(top);
195
196         if (gCenterProjectionsAtPrimaryVertex)
197                 mv->SetCenterMuon(x[0], x[1], x[2]);
198         mv->ImportEventMuon(top);
199
200         AliSysInfo::AddStamp("on_new_event_end");
201 }
202
203 void alieve_init_import_macros()
204 {
205   // Put macros in the list of browsables, add a macro browser to
206   // top-level GUI.
207
208   TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
209   gSystem->ExpandPathName(macdir);
210
211   TFolder* f = gEve->GetMacroFolder();
212   void* dirhandle = gSystem->OpenDirectory(macdir.Data());
213   if (dirhandle != 0)
214   {
215     char* filename;
216     TPMERegexp re("\\.C$");
217     TObjArray names;
218     while ((filename = gSystem->GetDirEntry(dirhandle)) != 0)
219     {
220       if (re.Match(filename))
221         names.AddLast(new TObjString(filename));
222     }
223     names.Sort();
224
225     for (Int_t ii=0; ii<names.GetEntries(); ++ii)
226     {
227       TObjString * si = (TObjString*) names.At(ii);
228        f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data())));
229     }
230   }
231   gSystem->FreeDirectory(dirhandle);
232
233   gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
234
235   {
236     TEveBrowser   *br = gEve->GetBrowser();
237     TGFileBrowser *fb = 0;
238     fb = br->GetFileBrowser();
239     fb->GotoDir(macdir);
240     {
241       br->StartEmbedding(0);
242       fb = br->MakeFileBrowser();
243       fb->BrowseObj(f);
244       fb->Show();
245       br->StopEmbedding();
246       br->SetTabTitle("Macros", 0);
247       br->SetTab(0, 0);
248     }
249   }
250 }