]> git.uio.no Git - u/mrichter/AliRoot.git/blob - DISPLAY/AliDisplayFrame.cxx
Commenting out unused variables (FedoraCore3, gcc 3.4.2)
[u/mrichter/AliRoot.git] / DISPLAY / AliDisplayFrame.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 /////////////////////////////////////////////////////////////////////////
17 // ALICE DISPLAY FRAME CLASS                                           //
18 // Author: Mayeul   ROUSSELET                                          //
19 // e-mail: Mayeul.Rousselet@cern.ch                                    //
20 // Last update:26/08/2003                                              //
21 /////////////////////////////////////////////////////////////////////////
22
23 #include <time.h>
24
25 #include <TGFrame.h>
26 #include <TGTab.h>
27 #include <TObjArray.h>
28 #include <TStopwatch.h>
29 #include <TPad.h>
30 #include <TVirtualX.h>
31 #include <TCanvas.h>
32 #include <TView.h>
33 #include <TParticle.h>
34 #include <TGeometry.h>
35
36 #include "AliModuleInfo.h"
37 #include "AliDisplayHLT.h"
38 #include "AliDisplay2.h"
39 #include "AliModule.h"
40 #include "AliDetector.h"
41 #include "AliPoints.h"
42 #include "AliRun.h"
43
44
45 ClassImp(AliDisplayFrame);
46
47 //_____________________________________________________________
48 AliDisplayFrame::AliDisplayFrame(const TGWindow *p, UInt_t w, UInt_t h)
49 {
50   // Constructor
51   fClipMin=-20;
52   fClipMax=20;
53   fPreviousW=0;
54   fPreviousH=0;
55   fRange = 500;
56   fPolyMarkers = new TObjArray(1000);
57   
58   fMainFrame = new TGCompositeFrame(p,w,h);
59   fMainTab = new TGTab(fMainFrame, w, h);
60   fFrame1 = fMainTab->AddTab("Main View");
61   fMainEmbeddedCanvas = new TRootEmbeddedCanvas("Main12",fFrame1,w,h,kFixedWidth);
62   fFrame1->AddFrame(fMainEmbeddedCanvas,new TGLayoutHints( kLHintsTop | kLHintsLeft|kLHintsExpandX| kLHintsExpandY, 0, 0, 0, 0));
63   fMainCanvas = fMainEmbeddedCanvas->GetCanvas();
64   fMainCanvas->SetFillColor(1);
65   fMainCanvas->SetBorderMode(0);
66   fMainCanvas->cd();
67   fMainCanvas->SetFixedAspectRatio();
68   fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","AliDisplayFrame",this,"ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");
69   //fView = new TView(1);
70   //DoView(kIdbFRONTVIEW);
71   
72   gAliDisplay2->SetCurrentView(kIdbFRONTVIEW);  
73   
74   fFrame2 = fMainTab->AddTab("No detector");
75   fSelectionEmbeddedCanvas = new TRootEmbeddedCanvas("Selection",fFrame2,w,h);
76   fSelectionCanvas = fSelectionEmbeddedCanvas->GetCanvas();
77   fSelectionCanvas->SetFillColor(1);
78   fSelectionCanvas->SetBorderMode(0);
79   fSelectionCanvas->cd();
80   fFrame2->AddFrame(fSelectionEmbeddedCanvas,new TGLayoutHints( kLHintsTop | kLHintsLeft|kLHintsExpandX| kLHintsExpandY, 0, 0, 0, 0));
81   fMainFrame->AddFrame(fMainTab,new TGLayoutHints( kLHintsTop | kLHintsLeft|kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
82   fAllViews = kFALSE;
83   fMainFrame->MapSubwindows();
84   fMainFrame->MapWindow();
85 }
86
87 //_____________________________________________________________
88 AliDisplayFrame::~AliDisplayFrame(void)
89 {
90   // Destructor
91   delete fMainTab;
92   delete fSelectionEmbeddedCanvas;
93   delete fMainEmbeddedCanvas;
94   delete fFrame1;
95   delete fFrame2;
96   delete fMainCanvas;
97   delete fSelectionCanvas;
98   delete fPoints2;
99   delete fPoints;
100   delete fModules;
101   delete fMainFrame;
102   delete [] fActivePoints;
103   delete [] fClustersPos;
104 }
105
106 //_____________________________________________________________
107 void AliDisplayFrame::DoView(Int_t view)
108 {
109   // Draws selected view
110   Int_t x,y;
111   char vname[16];
112   y=fMainFrame->GetDefaultHeight();
113   x=fMainFrame->GetDefaultWidth();
114   gAliDisplay2->SetCurrentView(view);
115   switch(view){
116   case kIdbALLVIEW:{
117     fAllViews=kTRUE;
118     strcpy(vname,"All views");  
119     fMainCanvas->cd();
120     gPad->Clear();
121     fMainCanvas->SetFillColor(15);
122     fMainCanvas->Divide(2,2,0.005,0.005,1);
123     
124     fMainCanvas->cd(1);
125     Draw(30,30,0);
126     
127     gAliDisplay2->SetCurrentView(kIdbTOPVIEW);
128     fMainCanvas->cd(2);
129     Draw(90,-90,90);
130     
131     gAliDisplay2->SetCurrentView(kIdbSIDEVIEW);
132     fMainCanvas->cd(3);         
133     Draw(90,0,-90);
134     
135     gAliDisplay2->SetCurrentView(kIdbFRONTVIEW);
136     fMainCanvas->cd(4);
137     Draw(0,-90,0);
138     
139     //fMainCanvas->cd();
140     
141   }
142     break;
143   case kIdbTOPVIEW:{
144     strcpy(vname,"Top view  ");
145     fAllViews=kFALSE;   
146     fMainCanvas->cd();                                                                                  
147     gPad->SetFillColor(1);
148     gPad->Clear();
149     gPad->Draw();
150     Draw(90,-90,90);
151   }
152     break;
153   case kIdbSIDEVIEW:{
154     strcpy(vname,"Side view");
155     fAllViews=kFALSE;   
156     fMainCanvas->cd();          
157     gPad->SetFillColor(1);
158     gPad->Clear();
159     gPad->Draw();
160     Draw(90,0,-90);
161   }
162     break;
163   case kIdbFRONTVIEW:{
164     strcpy(vname,"Front view");
165     fAllViews=kFALSE;   
166     fMainCanvas->cd();
167     gPad->SetFillColor(1);
168     gPad->Clear();
169     gPad->Draw();
170     
171     Draw(0,-90,0);
172   }
173     break;
174   default: break;
175   }
176   (fMainTab->GetTabTab(0))->SetText(new TGString(vname));
177 }
178
179 //_____________________________________________________________
180 void AliDisplayFrame::DrawDetector(const char *name)
181 {
182   // Draws detector
183   (fMainTab->GetTabTab(1))->SetText(new TGString(name));
184 }
185
186 //_____________________________________________________________
187 void AliDisplayFrame::EnableDetector(const char *name)
188 {
189   // Enables detector
190   AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
191   if(!module) return;
192   gAliDisplay2->GetModuleInfo()->Enable((char*)name);
193   module->Enable();
194 }
195
196 //_____________________________________________________________
197 void AliDisplayFrame::DisableDetector(const char *name)
198 {
199   // Disables detector
200   AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
201   if(!module) return;
202   gAliDisplay2->GetModuleInfo()->Disable((char*)name);
203   module->Disable();
204 }
205
206 //_____________________________________________________________
207 void AliDisplayFrame::Draw(Float_t theta, Float_t phi, Float_t psi)
208 {
209   // Draws everything???
210   //clock_t t1,t2;
211   time_t t1,t2;
212   //t1 = clock();
213   TStopwatch timer;
214   timer.Start();
215   time(&t1);
216   gPad->SetCursor(kWatch);
217   gPad->SetEditable(kTRUE);
218   gPad->SetFillColor(1);
219   gPad->Clear();
220   
221   Int_t iret;
222   
223   TView *view = new TView(1);
224   TGDimension dim=((TGCanvas*)fMainEmbeddedCanvas)->GetViewPort()->GetDefaultSize();
225   Float_t aspectRatio = dim.fWidth/(Float_t) dim.fHeight;
226   //printf("Dimension %d %d",dim.fWidth,dim.fHeight);
227   if(gAliDisplay2->GetCurrentView()==kIdbFRONTVIEW){
228     view->SetRange(-fRange*aspectRatio,-fRange,-fRange,fRange*aspectRatio,fRange,fRange);
229   }
230   if(gAliDisplay2->GetCurrentView()==kIdbTOPVIEW){
231     view->SetRange(-fRange,-fRange,-fRange*aspectRatio,fRange,fRange,fRange*aspectRatio);
232   }
233   if(gAliDisplay2->GetCurrentView()==kIdbSIDEVIEW){
234     view->SetRange(-fRange,-fRange,-fRange*aspectRatio,fRange,fRange,fRange*aspectRatio);
235   }
236   
237   gAlice->GetGeometry()->Draw("same");
238   if(gAliDisplay2->IsEnabled(kHits)) DrawHits();
239   if(gAliDisplay2->IsEnabled(kClusters)) fClusters->Draw();
240   if(gAliDisplay2->IsEnabled(kHLT)) fHLT->Draw();
241   
242   gAliDisplay2->AppendPad();
243   view->SetView(phi,theta,psi,iret);
244   
245   view->ZoomView(gPad,gAliDisplay2->GetZoomFactor());
246   //t2 = clock();
247   time(&t2);
248   //    printf("\nDrawn in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
249   printf("\nDrawn in....%f sec", difftime(t2,t1));
250   timer.Stop();
251   timer.Print("m");
252 }
253
254 //_____________________________________________________________
255 void AliDisplayFrame::DrawHits()
256 {
257   // Draws hits
258   AliPoints *p;
259   if(!fPoints2) return;
260   for(Int_t i=0;i<fPoints2->GetEntries();i++){
261     if(fActivePoints[i]){
262       p=dynamic_cast<AliPoints *>(fPoints2->UncheckedAt(i));    
263       if(!p) continue;
264       p->Draw();
265     }
266   }
267 }
268
269 //_____________________________________________________________
270 void AliDisplayFrame::LoadEnabledModules()
271 {
272   // Loads enabled modules
273   clock_t t1,t2;
274   t1=clock(); 
275   TIter next(gAlice->Modules());
276   AliModule *module;
277   fModules = new TObjArray(0,32);
278   while((module = dynamic_cast <AliModule*> (next()))){
279     if(!module) continue;
280     if(!module->IsActive()) continue;
281     fModules->AddLast(module);
282   }
283   t2=clock();
284   fNbModules = fModules->GetEntriesFast();
285   //    printf("\nModules loaded in.....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
286 }
287
288 //_____________________________________________________________
289 void AliDisplayFrame::LoadClusters(Int_t nevent)
290 {
291   // Loads clusters
292   fClusters = new AliDisplayClusters();
293   fClusters->LoadClusters("ITS TPC",nevent);
294 }
295
296 //_____________________________________________________________
297 void AliDisplayFrame::LoadHLTClusters(Int_t nevent)
298 {
299   // Loads HLT clusters
300   fHLT = new AliDisplayHLT();
301   fHLT->LoadHLT("TPC",nevent);
302 }
303         
304 //_____________________________________________________________
305 void AliDisplayFrame::LoadHits()
306 {
307   // Loads hits
308   clock_t t1,t2;
309
310   t1=clock(); 
311   fPoints2 = new TObjArray(0,1000);
312   AliModule *module;
313   TObjArray *points;
314   for(Int_t i=0;i<fNbModules;i++){
315     module = dynamic_cast<AliModule*>(fModules->UncheckedAt(i));
316     if(!module) continue;
317     points = module->Points();
318     if(!points) {
319       continue;
320     }
321     for(Int_t j=0;j<points->GetEntriesFast();j++){
322       if(!points->UncheckedAt(j)) continue;
323       fPoints2->AddLast((points->UncheckedAt(j)));
324     }   
325   }
326   fActivePoints = new Bool_t[fPoints2->GetEntries()];
327   for(Int_t k=0;k<fPoints2->GetEntriesFast();k++){
328     fActivePoints[k]=kTRUE;
329   }
330   printf("\n nb hits %d",fPoints2->GetEntries());
331   t2=clock();
332   //    printf("\nPoints loaded in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
333 }
334
335 //_____________________________________________________________
336 void AliDisplayFrame::ApplyCuts()
337 {
338   // Applies cuts
339   clock_t t1,t2;
340   t1=clock();
341   
342   Float_t               *pxyz;
343   Float_t               r,theta,eta,cutmin,cutmax,etamin,etamax,pmom,smin,smax;
344   Int_t         nbhits=0;
345   AliPoints *pm;
346   TParticle *particle;
347   
348   //Get momentum cut
349   smin = gAliDisplay2->GetMomentumMin();
350   smax = gAliDisplay2->GetMomentumMax();
351   cutmin = 2.0*smin;
352   if(smax<0.98)         cutmax = 2.0*smax;
353   else                  cutmax = 100000;
354   
355   //Get rapidity cut
356   smax = gAliDisplay2->GetRapidityMax();
357   smin = gAliDisplay2->GetRapidityMin();
358   //etamin = 1.5*(2*smin-1);
359   //etamax = 1.5*(2*smax-1);
360   etamin = smin;
361   etamax = smax;
362   if(smin<-1.46) etamin = -1000;
363   if(smax>1.46) etamax = 1000;
364   
365   
366   if(!fPoints2) return;
367   for(Int_t i=0;i<fPoints2->GetEntries();i++){
368     pm = dynamic_cast<AliPoints*>(fPoints2->UncheckedAt(i));
369     if(!pm) {
370       fActivePoints[i]=kFALSE;
371       continue;
372     }
373     particle = pm->GetParticle();
374     if(!particle) {
375       fActivePoints[i]=kFALSE;
376       continue;
377     }
378     pmom = particle->P();
379     if(pmom < cutmin) {
380       fActivePoints[i]=kFALSE;
381       continue;
382     }
383     if(pmom > cutmax) {
384       fActivePoints[i]=kFALSE;
385       continue;
386     }
387     pxyz = pm->GetP();
388     r = TMath::Sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]);
389     theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
390     if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta)));
391     else eta = 1e10;
392     if(pxyz[2] < 0) eta = -eta;
393     if((eta < etamin) || (eta > etamax)) {
394       fActivePoints[i]=kFALSE;
395       continue;
396     }
397     fActivePoints[i]=kTRUE;
398     //pm->Draw();
399     nbhits += pm->GetN();
400   }
401   gAliDisplay2->SetNbHits(nbhits);
402   t2=clock();
403   //    printf("\nCuts applied in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
404   gAliDisplay2->SetNbParticles(GetNbActivePoints()); 
405 }
406
407 //_____________________________________________________________
408 Int_t AliDisplayFrame::GetNbActivePoints() const
409 {
410   // Returns the number of active points
411   Int_t ans=0;
412   for(Int_t i=0;i<fPoints2->GetEntries();i++){
413     if(fActivePoints[i]) ans++;
414   }
415   return ans;
416 }
417 //_____________________________________________________________
418 void AliDisplayFrame::DrawX3d()
419 {
420   // Draws using X3d
421   TPad *pad = dynamic_cast<TPad*>(gPad);
422   pad->cd();
423   TView *view = pad->GetView();
424   if(!view) return;
425   pad->x3d();
426 }
427
428 //_____________________________________________________________
429 void AliDisplayFrame::SavePadGIF(const char *file)
430 {
431   // Save the current pad in a GIF file
432   if(!gPad){
433     printf("\nThere is no active pad");
434     return;
435   }
436   gPad->SaveAs(file);
437 }
438
439 //_____________________________________________________________
440 void AliDisplayFrame::DrawGL()
441 {
442   // Draws using GL
443   TPad *pad = dynamic_cast<TPad*>(gPad);
444   pad->cd();
445   TView *view = pad->GetView();
446   if(!view) return;
447   pad->x3d("OPENGL");
448 }
449
450 //_____________________________________________________________
451 void AliDisplayFrame::ExecuteEvent(Int_t event, Int_t px,Int_t py,TObject *)
452 {
453   static Float_t x0,y0,x1,y1;
454   static Int_t pxold,pyold;
455   static Int_t px0,py0;
456   static Int_t linedrawn;
457   Float_t temp;
458   
459   
460   switch(event){
461   case kMouseMotion:{
462     
463     AliPoints *p=dynamic_cast<AliPoints*> (gPad->GetSelected());
464     if(p){
465       gAliDisplay2->SetStatusBar(p->GetName(),1);
466       gAliDisplay2->SetStatusBar(p->GetDetector()->GetName(),2);
467     }
468   }
469     break;
470   default:break;
471   }     
472   
473   if((!gAliDisplay2->GetZoomMode())&&(gPad->GetView())){
474     gPad->GetView()->ExecuteRotateView(event,px,py);
475     return;
476   }
477   
478   
479   
480   if(gAliDisplay2->GetZoomMode()==kTRUE){
481     switch(event){
482       
483     case kButton1Down:{
484       gVirtualX->SetLineColor(-1);
485       gPad->TAttLine::Modify();
486       x0 = gPad->AbsPixeltoX(px);
487       y0 = gPad->AbsPixeltoY(py);
488       px0 = px;
489       py0 = py;
490       pxold = px;
491       pyold = py;
492       linedrawn = 0;
493     }
494       break;
495     case kButton1Motion:{
496       if(linedrawn) gVirtualX->DrawBox(px0,py0,pxold,pyold,TVirtualX::kHollow);
497       pxold = px;
498       pyold = py;
499       linedrawn = 1;
500       gVirtualX->DrawBox(px0,py0,pxold,pyold,TVirtualX::kHollow);
501     }
502       break;
503       
504     case kButton1Up:{
505       gPad->GetCanvas()->FeedbackMode(kFALSE);
506       if(px == px0) break;
507       if(py == py0) break;
508       x1 = gPad->AbsPixeltoX(px);
509       y1 = gPad->AbsPixeltoY(py);
510       if(x1<x0) { 
511         temp = x0;
512         x0 = x1;
513         x1 = temp;
514       }
515       if(y1<y0) {
516         temp = y0;
517         y0 = y1;
518         y1 = temp;
519       }
520       printf("\nBox (%f,%f)-(%f,%f)",x0,y0,x1,y1);
521       gPad->SetEditable(kTRUE);
522       //gPad->Range(x0,y0,x1,y1);
523       gPad->SetEditable(kFALSE);
524       //gPad->Range(0.5,0.5,1,1);
525       //gAliDisplay2->SetZoomFactor(1);
526       gPad->Modified(kTRUE);
527       gAliDisplay2->Draw();     
528       gAliDisplay2->SetZoomMode(kFALSE);
529       gPad->SetEditable(kTRUE);
530     }
531       break; 
532     default: break;             
533     }           
534   }
535 }