]> git.uio.no Git - u/mrichter/AliRoot.git/blob - DISPLAY/AliDisplay2.cxx
Added sort method.
[u/mrichter/AliRoot.git] / DISPLAY / AliDisplay2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 /////////////////////////////////////////////////////////////////////////
16 // ALICE EVENT DISPLAY CLASS                                           //
17 // Author: Mayeul   ROUSSELET                                          //
18 // e-mail: Mayeul.Rousselet@cern.ch                                    //
19 // Last update:26/08/2003                                              //
20 /////////////////////////////////////////////////////////////////////////
21
22 #define do_mc
23
24 //standard modules
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <time.h>
28
29 //ROOT
30
31 #include <TTree.h>
32 #include <TGLayout.h>
33 #include <TObjArray.h>
34 #include <TSystem.h>
35 #include <TGWindow.h>
36 #include <TEnv.h>
37 #include <TPad.h>
38
39 //AliRoot Module
40 #include "AliModule.h"
41 #include "AliDetector.h"
42 #include "AliRun.h"
43 #include "AliMC.h"
44
45 #include "AliModuleInfo.h"
46 #include "AliSliderFrame.h"
47 #include "AliShutterFrame.h"
48 #include "AliDisplayFrame.h"
49 #include "AliInfoFrame.h"
50 #include "AliDetectorFrame.h"
51 #include "AliMenu.h"
52
53 #include "AliDisplay2.h"
54
55
56  AliDisplay2 *gAliDisplay2;
57
58
59 ClassImp(AliDisplay2);
60 //_____________________________________________________________
61 AliDisplay2::AliDisplay2(const TGWindow *p, UInt_t w, UInt_t h)
62                         :TObject()
63 {
64   //  Constructor
65   //gAlice->SetDisplay(this);
66   gAliDisplay2=this;
67   fSliderUpdate = kFALSE;
68   fZoomMode = kFALSE;
69   fZoomStep = 1.2;
70   fZoomFactor = 1.5;
71   fNbParticles = 0;
72   fEventNumber = 0;
73   fNbHits = 0;
74   fSliderStep = 0.01;
75   fClustersLoaded = kFALSE;
76   fHitsLoaded = kFALSE;
77   fHLTLoaded = kFALSE;
78   fTracksLoaded = kFALSE;
79   fMode =0;
80   FindModules();
81   
82   fIconsPath = new char[32];
83   strcpy(fIconsPath,gSystem->Getenv("ALICE_ROOT"));
84   strcat(fIconsPath,"/DISPLAY/icons/");
85   LoadFromRC();
86   fMainFrame = new TGMainFrame(p,w,h,kVerticalFrame);
87   fSubFrame = new TGCompositeFrame(fMainFrame,w,h,kHorizontalFrame);
88   fLeftFrame = new TGCompositeFrame(fSubFrame,150,h,kVerticalFrame|kFixedWidth);
89   fRightFrame = new TGCompositeFrame(fSubFrame,600,h,kVerticalFrame);
90   //fMainFrame->Connect("ProcessedEvent(Event_t*)", "AliDisplay2", this,"HandleMouseWheel(Event_t*)");
91   fMainFrame->Connect("ProcessedEvent(Event_t*)", "AliDisplay2",this,"HandleResize(Event_t*)");
92   //MenuBar
93   fMenu = new AliMenu(fMainFrame,1,1,kRaisedFrame|kHorizontalFrame);
94   
95   //Slider Frame
96   fSliderFrameLayout = new TGLayoutHints( kLHintsBottom| kLHintsRight| kLHintsExpandX | kLHintsCenterX, 2, 2, 2, 2);
97   fSliderFrame  = new AliSliderFrame(fRightFrame,600,150);
98   fRightFrame->AddFrame(fSliderFrame->GetSliderFrame(),fSliderFrameLayout);
99   
100   //Info Frame
101   fInfoFrameLayout = new TGLayoutHints( kLHintsTop | kLHintsLeft  | kLHintsExpandX  ,0,0,0,0);
102   fInfoFrame = new AliInfoFrame(fLeftFrame,150,200);
103   fLeftFrame->AddFrame(fInfoFrame->GetInfoFrame(),fInfoFrameLayout);
104   
105   
106   //Shutter Frame
107   fShutterFrameLayout = new TGLayoutHints( kLHintsTop | kLHintsLeft | kLHintsExpandY |kLHintsExpandX, 0, 0, 5, 0);
108   fShutterFrame = new AliShutterFrame(fLeftFrame,150,300);
109   fLeftFrame->AddFrame(fShutterFrame->GetShutterFrame(),fShutterFrameLayout);
110   
111   //Display Frame
112   fDisplayFrameLayout = new TGLayoutHints( kLHintsTop | kLHintsRight | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2); 
113   fDisplayFrame = new AliDisplayFrame(fRightFrame, w-150,w-110);
114   fRightFrame->AddFrame(fDisplayFrame->GetDisplayFrame(),fDisplayFrameLayout);
115   fDisplayFrame->GetDisplayFrame()->Connect("ProcessedEvent(Event_t*)", "AliDisplay2", this,"HandleMouseWheel(Event_t*)");
116   
117   
118   fLeftFrame->Layout();
119   
120   fSubFrame->AddFrame(fLeftFrame, new TGLayoutHints( kLHintsBottom | kLHintsLeft | kLHintsExpandY, 5, 5, 2, 2));
121   fSubFrame->AddFrame(fRightFrame, new TGLayoutHints( kLHintsBottom | kLHintsRight | kLHintsExpandX | kLHintsExpandY, 5, 5, 2, 2));
122   
123   Int_t parts[] = {45,45,10};
124   fStatusBar = new TGStatusBar(fMainFrame,50,10,kHorizontalFrame);
125   fStatusBar->SetParts(parts,3);
126   fStatusBar->SetText("AliDisplay v2.0",0);
127   fMainFrame->AddFrame(fStatusBar,new TGLayoutHints(kLHintsBottom | kLHintsExpandX,0,0,0,0));
128   
129   fMainFrame->AddFrame(fSubFrame,new TGLayoutHints( kLHintsBottom | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 2, 2));
130   fMainFrame->SetWindowName("Ali Display");
131   
132   fMainFrame->MapSubwindows();
133   fMainFrame->MapWindow();
134   LoadSettings();
135
136         
137   fMainFrame->Resize(w-10,h);
138   fMainFrame->Resize(w,h);
139   fMainFrame->SetWMSizeHints(500,500,1280, 1200,1,1);
140 }
141
142 //_____________________________________________________________
143 AliDisplay2::~AliDisplay2(void)
144 {
145   //Destructor
146   delete fModules;
147   delete [] fEnabledModules;
148   delete fModuleInfo;
149   
150   delete fSliderFrameLayout;
151   delete fSliderFrame;  
152   delete fDisplayFrameLayout;
153   delete fDisplayFrame;
154   //    delete fZoomFrameLayout;
155   //    delete fZoomFrame;
156   delete fShutterFrameLayout;
157   delete fShutterFrame;
158   delete fInfoFrameLayout;
159   delete fInfoFrame;
160   delete fDetectorFrameLayout;
161   delete fDetectorFrame;
162   
163   delete fSubFrame;
164   delete fLeftFrame;
165   delete fRightFrame;
166   delete fMainFrame;
167   delete fAliDisplay2rc;
168   
169   delete fMenu;
170   delete fStatusBar;
171 }
172
173 //_____________________________________________________________
174 void AliDisplay2::CloseWindow(void)
175 {
176   // Deletes the current display
177   delete this;
178 }
179
180 //_____________________________________________________________
181 void AliDisplay2::LoadFromRC()
182 {
183   // Load the environment settings from .alidisplayrc file
184   TEnv *rc=new TEnv(".alidisplayrc");
185   SetSliderUpdate(rc->GetValue("AliDisplay.SliderUpdate",kFALSE));
186   SetZoomStep(rc->GetValue("AliDisplay.ZoomStep",1.2));
187   SetSliderStep(rc->GetValue("AliDisplay.SliderStep",0.01));
188   char c[128];
189   fRawDataPath = new char[128];
190   strcpy(c,gSystem->Getenv("ALICE_ROOT"));
191   sprintf(fRawDataPath,"%s%s",c,rc->GetValue("AliDisplay.RawDataPath","/raw"));
192   printf("\nRaw data path %s",fRawDataPath);
193 }
194
195 //_____________________________________________________________
196 void AliDisplay2::SaveToRC() const
197 {
198   // Saves the environment settings in .alidisplayrc file
199   TEnv *rc=new TEnv(".alidisplayrc");
200   rc->SetValue("AliDisplay.SliderUpdate",GetSliderUpdate());
201   rc->SetValue("AliDisplay.ZoomStep",GetZoomStep());
202   rc->SetValue("AliDisplay.SliderStep",GetSliderStep());
203   rc->SetValue("AliDisplay.RawDataPath","/raw");
204   rc->SaveLevel(kEnvLocal);
205   rc->Save();
206 }
207
208 //_____________________________________________________________
209 void AliDisplay2::DoSaveSettings(void)
210 {
211   // Saves the environment settings for the slider frame and display
212   fSliderFrame->SaveToRC();
213   SaveToRC();
214 }
215
216 //_____________________________________________________________
217 void AliDisplay2::LoadSettings()
218 {
219   // Loads settings
220   LoadFromRC();
221 }
222
223 //_____________________________________________________________
224 void AliDisplay2::Draw(Option_t */*options*/)
225 {
226   // Draws display frame
227   fDisplayFrame->DoView(fCurrentView);
228 }
229
230 //_____________________________________________________________
231 void AliDisplay2::DrawX3d()
232 {
233   // Draws display frame using X3d
234   fDisplayFrame->DrawX3d();
235 }
236
237 //_____________________________________________________________
238 void AliDisplay2::DrawGL()
239 {
240   // Draws display frame using GL
241   fDisplayFrame->DrawGL();
242 }
243
244 //_____________________________________________________________
245 void AliDisplay2::ShowNextEvent(Int_t delta)
246 {
247   //Load the next event
248   clock_t t1,t2;
249   t1=clock();
250   Int_t newEvent=0;
251   if(delta!=0){
252     gAlice->Clear();
253     newEvent = fEventNumber + delta;
254     if( newEvent < 0) return;
255     gAlice->GetEvent(newEvent);
256     fEventNumber += delta;
257     //          if(!gAlice->TreeH()) return;
258   }
259   if(IsEnabled(kHits)) LoadHits();
260   if(IsEnabled(kClusters)) LoadClusters(newEvent);
261   if(IsEnabled(kHLT)) LoadHLTClusters(newEvent);
262   t2=clock();
263   //    printf("\nEvent loaded in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
264   Update(kmMODULES);
265 }
266
267 //_____________________________________________________________
268 void AliDisplay2::FindModules()
269 {
270   // Find the modules used for the simulation and assign 
271   // these modules to the array fModules
272   fModules = new TObjArray;
273   TObjArray *modules = gAlice->Modules();
274   AliModule *mod;
275   Int_t nbm = 0;
276   for(Int_t i=0;i<modules->GetEntriesFast();i++){
277     mod = (AliModule *) modules->At(i);
278     if(!mod) continue;
279     const char *avoid = strstr("BODY MAG ABSO DIPO HALL FRAME SHIL PIPE",mod->GetName());
280     if(avoid) continue;
281     fModules->AddLast(mod);
282     nbm++;
283   }
284   fEnabledModules = new Bool_t[nbm];
285   fNbModules = nbm;
286   fModuleInfo = new AliModuleInfo(nbm);
287   for(Int_t j=0;j<fModules->GetEntriesFast();j++){
288     fModuleInfo->Add(fModules->At(j)->GetName(),j);
289     fEnabledModules[j]=kTRUE;
290   }
291 }
292
293 //_____________________________________________________________
294 void AliDisplay2::LoadHits()
295 {
296   //Load the detected hits from each detector to memory
297   gAlice->ResetPoints();
298   TIter next(gAlice->Modules());
299   AliModule *module;
300   Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
301   while((module = (AliModule*)next())) 
302     {
303       AliDetector* detector = dynamic_cast<AliDetector*>(module);
304       if(detector) detector->SetTreeAddress();
305     }
306   next.Reset();
307   for (Int_t track=0; track<ntracks;track++) {
308     gAlice->ResetHits();
309     while((module = (AliModule*)next())) {
310       AliDetector* detector = dynamic_cast<AliDetector*>(module);
311       if(detector)
312         {
313           detector->TreeH()->GetEvent(track);
314           detector->LoadPoints(track);
315         }
316     }
317     next.Reset();
318   }
319   fHitsLoaded = kTRUE;
320 }
321
322 //_____________________________________________________________
323 void AliDisplay2::LoadClusters(Int_t nevent)
324 {
325   //clock_t t1,t2;
326   fDisplayFrame->LoadClusters(nevent);
327   fClustersLoaded = kTRUE;
328   //    printf("\nClusters loaded in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
329 }
330
331 //_____________________________________________________________
332 void AliDisplay2::LoadHLTClusters(Int_t nevent)
333 {
334   // Loads HLT clusters
335   fDisplayFrame->LoadHLTClusters(nevent);
336   fHLTLoaded = kTRUE;
337 }
338
339 //_____________________________________________________________
340 void AliDisplay2::Enable(Int_t m)
341 {
342   // Enables the given mode m
343   if(m==kHits){
344     if((fMode&kHits)==kHits) return;
345     fMode = kHits|fMode;
346     if(!fHitsLoaded) LoadHits();
347     Update(kmPOINTS);
348   }
349   if(m==kClusters){
350     if((fMode&kClusters)==kClusters) return;
351     fMode = kClusters|fMode;
352     if(!fClustersLoaded) LoadClusters(fEventNumber);
353     Update();
354   }
355   if(m==kHLT){
356     if((fMode&kHLT)==kHLT) return;
357     fMode = kHLT|fMode;
358     if(!fHLTLoaded) {
359       LoadHLTClusters(fEventNumber);
360     }
361     Update();
362   }
363   if(m==kTracks){
364     if((fMode&kTracks)==kTracks) return;
365     fMode = kTracks|fMode;
366     Update();
367   }
368 };    
369
370 //_____________________________________________________________
371 void AliDisplay2::Disable(Int_t m)
372 {
373   // Disables the given mode m
374   if(m==kHits){
375     fMode = fMode|kHits;
376     fMode = fMode^kHits;
377   }
378   if(m==kClusters){
379     fMode = fMode|kClusters;
380     fMode = fMode^kClusters;
381   }
382   if(m==kHLT){
383     fMode = fMode|kHLT;
384     fMode = fMode^kHLT;
385   }
386   if(m==kTracks){
387     fMode = fMode|kTracks;
388     fMode = fMode^kTracks;
389   }
390   Update();
391 }
392
393 //_____________________________________________________________
394 Bool_t AliDisplay2::IsEnabled(Int_t m) const
395 {
396   // Checks if the mode m is enabled
397   if(m==kHits){
398     if((fMode&kHits)==kHits) return kTRUE;
399     return kFALSE;
400   }
401   if(m==kClusters){
402     if((fMode&kClusters)==kClusters) return kTRUE;
403     return kFALSE;
404   }
405   if(m==kHLT){
406     if((fMode&kHLT)==kHLT) return kTRUE;
407     return kFALSE;
408   }
409   if(m==kTracks){
410     if((fMode&kTracks)==kTracks) return kTRUE;
411     return kFALSE;
412   }
413   return kFALSE;
414 }
415
416 //_____________________________________________________________
417 void AliDisplay2::HandleMouseWheel(Event_t *event)
418 {
419   //Handle mouve event, not working yet
420   if(event->fType != kButtonPress && event->fType != kButtonRelease) return;
421   
422   if(event->fCode == kButton4){
423     fZoomFactor *= fZoomStep;
424     Draw();
425   }
426   
427   if(event->fCode == kButton5){
428     fZoomFactor /= fZoomStep;
429     Draw();
430   }
431 }
432
433 //_____________________________________________________________
434 void AliDisplay2::HandleResize(Event_t *event)
435 {
436   // Handle resize event
437   switch(event->fType){
438   case kConfigureNotify:{
439     Draw();
440   }
441     break;
442   default:break;
443   }
444 }       
445
446 //_____________________________________________________________
447 void AliDisplay2::Update(Int_t tag)
448 {
449   // Update the view, if loading only the modified data from the previous
450   // changes, the integer tag indicates the kind of modification
451   if(tag==kmMODULES){
452     LoadEnabledModules();
453     if(((fMode)&kHits)==kHits){
454       LoadEnabledHits();
455       ApplyCuts();
456     }
457   }
458   if(tag==kmCUTS){
459     if(((fMode)&kHits)==kHits)ApplyCuts();
460   }
461   if(tag==kmPOINTS){
462     if(((fMode)&kHits)==kHits){
463       LoadEnabledHits();
464       ApplyCuts();
465     }
466   }
467   Draw();
468   fInfoFrame->Update();
469 }
470
471