1 /**************************************************************************
2 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /////////////////////////////////////////////////////////////////////////
17 // ALICE DISPLAY FRAME CLASS //
18 // Author: Mayeul ROUSSELET //
19 // e-mail: Mayeul.Rousselet@cern.ch //
20 // Last update:26/08/2003 //
21 /////////////////////////////////////////////////////////////////////////
27 #include <TObjArray.h>
28 #include <TStopwatch.h>
30 #include <TVirtualX.h>
33 #include <TParticle.h>
34 #include <TGeometry.h>
36 #include "AliModuleInfo.h"
37 #include "AliDisplayHLT.h"
38 #include "AliDisplay2.h"
39 #include "AliModule.h"
40 #include "AliDetector.h"
41 #include "AliPoints.h"
45 ClassImp(AliDisplayFrame);
47 //_____________________________________________________________
48 AliDisplayFrame::AliDisplayFrame(const TGWindow *p, UInt_t w, UInt_t h)
56 fPolyMarkers = new TObjArray(1000);
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);
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);
72 gAliDisplay2->SetCurrentView(kIdbFRONTVIEW);
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));
83 fMainFrame->MapSubwindows();
84 fMainFrame->MapWindow();
87 //_____________________________________________________________
88 AliDisplayFrame::~AliDisplayFrame(void)
92 delete fSelectionEmbeddedCanvas;
93 delete fMainEmbeddedCanvas;
97 delete fSelectionCanvas;
102 delete [] fActivePoints;
103 delete [] fClustersPos;
106 //_____________________________________________________________
107 void AliDisplayFrame::DoView(Int_t view)
109 // Draws selected view
112 y=fMainFrame->GetDefaultHeight();
113 x=fMainFrame->GetDefaultWidth();
114 gAliDisplay2->SetCurrentView(view);
118 strcpy(vname,"All views");
121 fMainCanvas->SetFillColor(15);
122 fMainCanvas->Divide(2,2,0.005,0.005,1);
127 gAliDisplay2->SetCurrentView(kIdbTOPVIEW);
131 gAliDisplay2->SetCurrentView(kIdbSIDEVIEW);
135 gAliDisplay2->SetCurrentView(kIdbFRONTVIEW);
144 strcpy(vname,"Top view ");
147 gPad->SetFillColor(1);
154 strcpy(vname,"Side view");
157 gPad->SetFillColor(1);
164 strcpy(vname,"Front view");
167 gPad->SetFillColor(1);
176 (fMainTab->GetTabTab(0))->SetText(new TGString(vname));
179 //_____________________________________________________________
180 void AliDisplayFrame::DrawDetector(const char *name)
183 (fMainTab->GetTabTab(1))->SetText(new TGString(name));
186 //_____________________________________________________________
187 void AliDisplayFrame::EnableDetector(const char *name)
190 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
192 gAliDisplay2->GetModuleInfo()->Enable((char*)name);
196 //_____________________________________________________________
197 void AliDisplayFrame::DisableDetector(const char *name)
200 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
202 gAliDisplay2->GetModuleInfo()->Disable((char*)name);
206 //_____________________________________________________________
207 void AliDisplayFrame::Draw(Float_t theta, Float_t phi, Float_t psi)
209 // Draws everything???
216 gPad->SetCursor(kWatch);
217 gPad->SetEditable(kTRUE);
218 gPad->SetFillColor(1);
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);
230 if(gAliDisplay2->GetCurrentView()==kIdbTOPVIEW){
231 view->SetRange(-fRange,-fRange,-fRange*aspectRatio,fRange,fRange,fRange*aspectRatio);
233 if(gAliDisplay2->GetCurrentView()==kIdbSIDEVIEW){
234 view->SetRange(-fRange,-fRange,-fRange*aspectRatio,fRange,fRange,fRange*aspectRatio);
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();
242 gAliDisplay2->AppendPad();
243 view->SetView(phi,theta,psi,iret);
245 view->ZoomView(gPad,gAliDisplay2->GetZoomFactor());
248 // printf("\nDrawn in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
249 printf("\nDrawn in....%f sec", difftime(t2,t1));
254 //_____________________________________________________________
255 void AliDisplayFrame::DrawHits()
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));
269 //_____________________________________________________________
270 void AliDisplayFrame::LoadEnabledModules()
272 // Loads enabled modules
275 TIter next(gAlice->Modules());
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);
284 fNbModules = fModules->GetEntriesFast();
285 // printf("\nModules loaded in.....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
288 //_____________________________________________________________
289 void AliDisplayFrame::LoadClusters(Int_t nevent)
292 fClusters = new AliDisplayClusters();
293 fClusters->LoadClusters("ITS TPC",nevent);
296 //_____________________________________________________________
297 void AliDisplayFrame::LoadHLTClusters(Int_t nevent)
299 // Loads HLT clusters
300 fHLT = new AliDisplayHLT();
301 fHLT->LoadHLT("TPC",nevent);
304 //_____________________________________________________________
305 void AliDisplayFrame::LoadHits()
311 fPoints2 = new TObjArray(0,1000);
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();
321 for(Int_t j=0;j<points->GetEntriesFast();j++){
322 if(!points->UncheckedAt(j)) continue;
323 fPoints2->AddLast((points->UncheckedAt(j)));
326 fActivePoints = new Bool_t[fPoints2->GetEntries()];
327 for(Int_t k=0;k<fPoints2->GetEntriesFast();k++){
328 fActivePoints[k]=kTRUE;
330 printf("\n nb hits %d",fPoints2->GetEntries());
332 // printf("\nPoints loaded in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
335 //_____________________________________________________________
336 void AliDisplayFrame::ApplyCuts()
343 Float_t r,theta,eta,cutmin,cutmax,etamin,etamax,pmom,smin,smax;
349 smin = gAliDisplay2->GetMomentumMin();
350 smax = gAliDisplay2->GetMomentumMax();
352 if(smax<0.98) cutmax = 2.0*smax;
353 else cutmax = 100000;
356 smax = gAliDisplay2->GetRapidityMax();
357 smin = gAliDisplay2->GetRapidityMin();
358 //etamin = 1.5*(2*smin-1);
359 //etamax = 1.5*(2*smax-1);
362 if(smin<-1.46) etamin = -1000;
363 if(smax>1.46) etamax = 1000;
366 if(!fPoints2) return;
367 for(Int_t i=0;i<fPoints2->GetEntries();i++){
368 pm = dynamic_cast<AliPoints*>(fPoints2->UncheckedAt(i));
370 fActivePoints[i]=kFALSE;
373 particle = pm->GetParticle();
375 fActivePoints[i]=kFALSE;
378 pmom = particle->P();
380 fActivePoints[i]=kFALSE;
384 fActivePoints[i]=kFALSE;
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)));
392 if(pxyz[2] < 0) eta = -eta;
393 if((eta < etamin) || (eta > etamax)) {
394 fActivePoints[i]=kFALSE;
397 fActivePoints[i]=kTRUE;
399 nbhits += pm->GetN();
401 gAliDisplay2->SetNbHits(nbhits);
403 // printf("\nCuts applied in....%f sec", ((double)t2-t1)/(10000*CLK_TCK));
404 gAliDisplay2->SetNbParticles(GetNbActivePoints());
407 //_____________________________________________________________
408 Int_t AliDisplayFrame::GetNbActivePoints() const
410 // Returns the number of active points
412 for(Int_t i=0;i<fPoints2->GetEntries();i++){
413 if(fActivePoints[i]) ans++;
417 //_____________________________________________________________
418 void AliDisplayFrame::DrawX3d()
421 TPad *pad = dynamic_cast<TPad*>(gPad);
423 TView *view = pad->GetView();
428 //_____________________________________________________________
429 void AliDisplayFrame::SavePadGIF(const char *file)
431 // Save the current pad in a GIF file
433 printf("\nThere is no active pad");
439 //_____________________________________________________________
440 void AliDisplayFrame::DrawGL()
443 TPad *pad = dynamic_cast<TPad*>(gPad);
445 TView *view = pad->GetView();
450 //_____________________________________________________________
451 void AliDisplayFrame::ExecuteEvent(Int_t event, Int_t px,Int_t py,TObject *)
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;
463 AliPoints *p=dynamic_cast<AliPoints*> (gPad->GetSelected());
465 gAliDisplay2->SetStatusBar(p->GetName(),1);
466 gAliDisplay2->SetStatusBar(p->GetDetector()->GetName(),2);
473 if((!gAliDisplay2->GetZoomMode())&&(gPad->GetView())){
474 gPad->GetView()->ExecuteRotateView(event,px,py);
480 if(gAliDisplay2->GetZoomMode()==kTRUE){
484 gVirtualX->SetLineColor(-1);
485 gPad->TAttLine::Modify();
486 x0 = gPad->AbsPixeltoX(px);
487 y0 = gPad->AbsPixeltoY(py);
495 case kButton1Motion:{
496 if(linedrawn) gVirtualX->DrawBox(px0,py0,pxold,pyold,TVirtualX::kHollow);
500 gVirtualX->DrawBox(px0,py0,pxold,pyold,TVirtualX::kHollow);
505 gPad->GetCanvas()->FeedbackMode(kFALSE);
508 x1 = gPad->AbsPixeltoX(px);
509 y1 = gPad->AbsPixeltoY(py);
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);