4feb9ac125e124d2fd0d5e2952be7490d2ce2818
[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   
98   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG EMCAL",   "emcal_digits.C",   "emcal_digits"));
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
108   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks",             "", kFALSE));
109   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_MI",          "", kFALSE));
110   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track MUON", "esd_muon_tracks.C", "esd_muon_tracks",        "kTRUE,kFALSE", kTRUE));
111
112     
113     // these macros were leaking:
114   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_by_category", "", kTRUE));// just a little
115   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC FMD",        "fmd_esd.C",           "fmd_esd",                "", kTRUE));//huge leak
116     //
117     
118     
119     
120   // ???
121   // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C", "trd_detectors",         "", kFALSE));
122   // trd_tracks disabled due to memory leaks
123
124   //----------------------------------------------------------------------------
125
126   slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
127   slot->StartEmbedding();
128   AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);
129   slot->StopEmbedding("DataSelection");
130   exewin->PopulateMacros();
131
132   //============================================================================
133   // Final GUI setup
134   //============================================================================
135
136   browser->GetTabRight()->SetTab(1);
137
138   browser->StartEmbedding(TRootBrowser::kBottom);
139   new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
140   browser->StopEmbedding("EventCtrl");
141
142   browser->MoveResize(0, 0, gClient->GetDisplayWidth(),
143                       gClient->GetDisplayHeight() - 32);
144
145   gEve->GetViewers()->SwitchColorSet();
146   gEve->FullRedraw3D(kTRUE);
147         gSystem->ProcessEvents();
148
149   TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();
150   TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();
151   TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();
152
153   glv1->CurrentCamera().RotateRad(-0.4, -1.8);
154   glv2->CurrentCamera().Dolly(450, kFALSE, kFALSE);
155   glv3->CurrentCamera().Dolly(1500, kFALSE, kFALSE);
156
157 //////
158   AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");
159    ///////
160   gEve->FullRedraw3D();
161   gSystem->ProcessEvents();
162   gEve->Redraw3D(kTRUE);
163 }
164
165
166 Int_t      g_pic_id  = 0;
167 Int_t      g_pic_max = 100;
168 TTimeStamp g_pic_prev(0, 0);
169
170 void alieve_online_on_new_event()
171 {
172         AliSysInfo::AddStamp("on_new_event_start");
173
174         Double_t x[3] = { 0, 0, 0 };
175
176         if (AliEveEventManager::HasESD())
177         {
178                 AliESDEvent* esd = AliEveEventManager::AssertESD();
179                 esd->GetPrimaryVertex()->GetXYZ(x);
180
181                 TTimeStamp ts(esd->GetTimeStamp());
182                 TString win_title("Eve Main Window -- Timestamp: ");
183                 win_title += ts.AsString("s");
184                 win_title += "; Event # in ESD file: ";
185                 win_title += esd->GetEventNumberInFile();
186                 gEve->GetBrowser()->SetWindowName(win_title);
187         }
188
189         TEveElement* top = gEve->GetCurrentEvent();
190
191         AliEveMultiView *mv = AliEveMultiView::Instance();
192
193         //mv->DestroyEventRPhi();
194         if (gCenterProjectionsAtPrimaryVertex)
195                 mv->SetCenterRPhi(x[0], x[1], x[2]);
196         mv->ImportEventRPhi(top);
197
198         //mv->DestroyEventRhoZ();
199         if (gCenterProjectionsAtPrimaryVertex)
200                 mv->SetCenterRhoZ(x[0], x[1], x[2]);
201         mv->ImportEventRhoZ(top);
202
203         if (gCenterProjectionsAtPrimaryVertex)
204                 mv->SetCenterMuon(x[0], x[1], x[2]);
205         mv->ImportEventMuon(top);
206
207         AliSysInfo::AddStamp("on_new_event_end");
208 }
209
210 void alieve_init_import_macros()
211 {
212   // Put macros in the list of browsables, add a macro browser to
213   // top-level GUI.
214
215   TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
216   gSystem->ExpandPathName(macdir);
217
218   TFolder* f = gEve->GetMacroFolder();
219   void* dirhandle = gSystem->OpenDirectory(macdir.Data());
220   if (dirhandle != 0)
221   {
222     char* filename;
223     TPMERegexp re("\\.C$");
224     TObjArray names;
225     while ((filename = gSystem->GetDirEntry(dirhandle)) != 0)
226     {
227       if (re.Match(filename))
228         names.AddLast(new TObjString(filename));
229     }
230     names.Sort();
231
232     for (Int_t ii=0; ii<names.GetEntries(); ++ii)
233     {
234       TObjString * si = (TObjString*) names.At(ii);
235        f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data())));
236     }
237   }
238   gSystem->FreeDirectory(dirhandle);
239
240   gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
241
242   {
243     TEveBrowser   *br = gEve->GetBrowser();
244     TGFileBrowser *fb = 0;
245     fb = br->GetFileBrowser();
246     fb->GotoDir(macdir);
247     {
248       br->StartEmbedding(0);
249       fb = br->MakeFileBrowser();
250       fb->BrowseObj(f);
251       fb->Show();
252       br->StopEmbedding();
253       br->SetTabTitle("Macros", 0);
254       br->SetTab(0, 0);
255     }
256   }
257 }