]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONMchViewApplication.cxx
Fixes in reconstruction:
[u/mrichter/AliRoot.git] / MUON / AliMUONMchViewApplication.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 // $Id$
17
18 #include "AliMUONMchViewApplication.h"
19
20 #include "AliCDBManager.h"
21 #include "AliCodeTimer.h"
22 #include "AliLog.h"
23 #include "AliMUONChamberPainter.h"
24 #include "AliMUONDEPainter.h"
25 #include "AliMUONPainterDataRegistry.h"
26 #include "AliMUONPainterDataSourceFrame.h"
27 #include "AliMUONPainterEnv.h"
28 #include "AliMUONPainterHelper.h"
29 #include "AliMUONPainterMasterFrame.h"
30 #include "AliMUONPainterRegistry.h"
31 #include "AliMUONTrackerDataCompareDialog.h"
32 #include "AliMUONTrackerDataWrapper.h"
33 #include "AliMUONVTrackerData.h"
34 #include "AliMUONVTrackerDataMaker.h"
35 #include <Riostream.h>
36 #include <TCanvas.h>
37 #include <TEnv.h>
38 #include <TFile.h>
39 #include <TGClient.h>
40 #include <TGFileDialog.h>
41 #include <TGMenu.h>
42 #include <TGTab.h>
43 #include <TGTextView.h>
44 #include <TGrid.h>
45 #include <TKey.h>
46 #include <TList.h>
47 #include <TRegexp.h>
48 #include <TString.h>
49 #include <TSystem.h>
50
51 /// \class AliMUONMchViewApplication
52 ///
53 /// Main class for the mchview program
54 ///
55 ///\author Laurent Aphecetche, Subatech
56
57 /// \cond CLASSIMP
58 ClassImp(AliMUONMchViewApplication)
59 /// \endcond CLASSIMP
60
61 const Int_t AliMUONMchViewApplication::fgkFILESAVEAS(1);
62 const Int_t AliMUONMchViewApplication::fgkFILEOPEN(2);
63 const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
64 const Int_t AliMUONMchViewApplication::fgkFILEPRINTAS(4);
65 const Int_t AliMUONMchViewApplication::fgkABOUT(5);
66 const Int_t AliMUONMchViewApplication::fgkCOMPAREDATA(6);
67
68 const char* AliMUONMchViewApplication::fgkFileTypes[] = { 
69   "ROOT files",    "*.root", 
70   "All files",     "*", 
71   0,               0 }; 
72
73 //______________________________________________________________________________
74 AliMUONMchViewApplication::AliMUONMchViewApplication(const char* name,
75                                                      int* argc, char** argv,
76                                                      UInt_t w, UInt_t h,
77                                                      UInt_t ox, UInt_t oy) 
78 : TRint(name,argc,argv),
79   fMainFrame(0x0),
80   fPainterMasterFrame(0x0)
81 {
82
83   /// ctor
84   /// (w,h) is the size in pixel (if 0,0 it will be computed as 70%,90% of display size)
85   /// (ox,oy) is the offset from the top-left of the display
86
87   if (!w | !h)
88   {
89     w = (UInt_t)(gClient->GetDisplayWidth()*0.7);
90     h = (UInt_t)(gClient->GetDisplayHeight()*0.9); 
91   }
92
93   fMainFrame = new TGMainFrame(gClient->GetRoot(),w,h);
94
95   AliMUONPainterHelper::Instance()->GenerateDefaultMatrices();
96
97   CreateMenuBar(w);
98
99   const Int_t kbs = 2;
100   
101 //  h -= 60; // menubar
102   
103   TGTab* tabs = new TGTab(fMainFrame,w,h);
104   
105   TGCompositeFrame* t = tabs->AddTab("Painter Master Frame");
106
107   fPainterMasterFrame =
108     new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
109   
110   t->AddFrame(fPainterMasterFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
111
112   t = tabs->AddTab("Data Sources");
113   
114   AliMUONPainterDataSourceFrame* dsf = 
115     new AliMUONPainterDataSourceFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
116   
117   t->AddFrame(dsf,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
118   
119   fMainFrame->AddFrame(tabs,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,0,0,0,0));
120
121   fMainFrame->SetWindowName("mchview - Visualization of MUON Tracker detector");
122
123   fMainFrame->MapSubwindows();
124   fMainFrame->Resize();
125   
126   fPainterMasterFrame->Update();
127   
128   fMainFrame->MapWindow();
129   
130   fMainFrame->Connect("CloseWindow()","AliMUONMchViewApplication",this,"Terminate()");
131
132   fMainFrame->MoveResize(ox,oy, w, h); 
133   fMainFrame->SetWMPosition(ox, oy);
134   fMainFrame->SetWMSizeHints(w,h,w,h,0,0);
135   
136   cout << "***************************************************" << endl;
137   cout << "   Welcome to mchview" << endl;
138   cout << "   " << FullVersion() << endl;
139   cout << "***************************************************" << endl;
140   
141   // Trying to see if we're requested to draw something specific instead
142   // of the global view of all the chambers
143   
144   AliMUONVPainter* painter(0x0);
145   TObjArray args;
146   args.SetOwner(kTRUE);
147   
148   for ( int i = 1; i < argc[0]; ++i ) 
149   {
150     args.Add(new TObjString(argv[i]));
151   }
152   
153   for ( Int_t i = 0; i <= args.GetLast(); ++i ) 
154   {
155     TString a(static_cast<TObjString*>(args.At(i))->String());
156
157     AliMUONAttPainter att;
158     
159     att.SetPlane(kTRUE,kFALSE);
160     att.SetCathode(kFALSE,kFALSE);
161     att.SetViewPoint(kTRUE,kFALSE);
162         
163     if ( a == "--de" )
164     {
165       Int_t detElemId = static_cast<TObjString*>(args.At(i+1))->String().Atoi();
166       
167       painter = new AliMUONDEPainter(att,detElemId);
168       
169       painter->SetOutlined("*",kFALSE);      
170       painter->SetOutlined("BUSPATCH",kTRUE);
171
172       painter->SetLine(1,4,3);      
173       ++i;
174     }
175
176     if ( a == "--chamber" )
177     {
178       Int_t chamberId = static_cast<TObjString*>(args.At(i+1))->String().Atoi();
179       
180       painter = new AliMUONChamberPainter(att,chamberId-1);
181       
182       painter->SetOutlined("*",kFALSE);      
183       painter->SetOutlined("DE",kTRUE);
184       
185       painter->SetLine(1,4,3);      
186       ++i;
187     }
188     
189   }
190   
191   if ( painter ) 
192   {
193     fPainterMasterFrame->ShiftClicked(painter,0x0);
194     
195     fPainterMasterFrame->Update();
196   }
197       
198 }
199
200 //______________________________________________________________________________
201 AliMUONMchViewApplication::~AliMUONMchViewApplication()
202 {
203   /// dtor
204 }
205
206 //______________________________________________________________________________
207 void
208 AliMUONMchViewApplication::CompareData()
209 {
210   /// Launch compare data dialog
211   TGTransientFrame* t = new AliMUONTrackerDataCompareDialog(gClient->GetRoot(),
212                                                             gClient->GetRoot(),
213                                                             400,400);
214
215   t->MapSubwindows();
216   t->Resize();
217   t->MapWindow();
218   t->CenterOnParent();
219   
220   // set names
221   
222   t->SetWindowName("mchview compare data tool");
223   t->SetIconName("mchview compare data tool");
224   
225   t->MapRaised();
226   
227 }
228
229 //______________________________________________________________________________
230 void
231 AliMUONMchViewApplication::CreateMenuBar(UInt_t w)
232 {
233   /// Create the application menu bar
234   
235   TGPopupMenu* file = new TGPopupMenu(gClient->GetRoot());
236   
237   file->AddEntry("&Open...",fgkFILEOPEN);
238   file->AddEntry("&Save As...",fgkFILESAVEAS);
239   file->AddEntry("&Print As...",fgkFILEPRINTAS);
240   file->AddEntry("&Exit",fgkFILEEXIT);
241   
242   TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
243   
244   TGPopupMenu* tools = new TGPopupMenu(gClient->GetRoot());
245   tools->AddEntry("&Compare data",fgkCOMPAREDATA);
246   
247   TGPopupMenu* about = new TGPopupMenu(gClient->GetRoot());  
248   about->AddEntry(FullVersion(),fgkABOUT);
249
250   file->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
251   about->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
252   tools->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
253   
254   bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
255   bar->AddPopup("&Tools",tools,new TGLayoutHints(kLHintsLeft|kLHintsTop));
256   bar->AddPopup("&About",about,new TGLayoutHints(kLHintsRight|kLHintsTop));
257   
258   fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
259   
260   AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
261 }
262
263 //______________________________________________________________________________
264 void
265 AliMUONMchViewApplication::HandleMenu(Int_t i)
266 {
267   /// Handle the click of one menu item
268
269   switch (i)
270     {
271     case fgkFILEEXIT:
272       Terminate(1);
273       break;
274     case fgkFILEOPEN:
275       Open();
276       break;
277     case fgkFILESAVEAS:
278       Save();
279       break;
280     case fgkFILEPRINTAS:
281       PrintAs();
282       break;
283     case fgkABOUT:
284       ReleaseNotes();
285       break;
286     case fgkCOMPAREDATA:
287       CompareData();
288       break;
289     default:
290       break;
291     }
292 }
293
294 //______________________________________________________________________________
295 void
296 AliMUONMchViewApplication::Open()
297 {
298   /// Open file dialog
299   
300   TGFileInfo fileInfo;
301   
302   fileInfo.fFileTypes = fgkFileTypes;
303   
304   delete[] fileInfo.fIniDir;
305   
306   AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
307   
308   fileInfo.fIniDir = StrDup(env->String("LastOpenDir","."));
309   
310   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
311                    kFDOpen,&fileInfo);
312
313   env->Set("LastOpenDir",fileInfo.fIniDir);
314   env->Save();  
315     
316   Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
317 }  
318
319 //______________________________________________________________________________
320 void
321 AliMUONMchViewApplication::Open(const char* filename)
322 {
323   /// Open a given file containing saved VTrackerDataMaker objects
324   
325   TString sfilename(gSystem->ExpandPathName(filename));
326   
327   if ( sfilename.Contains(TRegexp("^alien")) )
328   {
329     // insure we've initialized the grid...
330     if (!gGrid)
331     {
332       TGrid::Connect("alien://");
333     }
334   }
335   
336   TFile* f = TFile::Open(filename);
337   
338         ReadDir(*f);
339         
340         delete f;
341 }
342
343 //______________________________________________________________________________
344 void
345 AliMUONMchViewApplication::ReadDir(TDirectory& dir)
346 {
347   /// Read the given directory and import VTrackerData objects found
348   
349   TList* keys = dir.GetListOfKeys();
350   TIter next(keys);
351   
352   TKey* k;
353   
354   while ( ( k = static_cast<TKey*>(next()) ) )
355   {
356     TObject* object = k->ReadObj();
357
358                 if ( object->InheritsFrom("TDirectory") )
359                 {
360                         TDirectory* d = static_cast<TDirectory*>(object);
361                         ReadDir(*d);
362                         continue;
363                 }
364                 
365     if ( object->InheritsFrom("AliMUONVTrackerDataMaker") )
366     {
367       AliMUONVTrackerDataMaker* maker = dynamic_cast<AliMUONVTrackerDataMaker*>(object);
368       if ( maker ) 
369       {
370         AliMUONPainterDataRegistry::Instance()->Register(maker);
371       }
372     }
373     
374     if ( object->InheritsFrom("AliMUONVTrackerData") )
375     {
376       // this is for backward compatibility. Early versions of mchview 
377       // wrote VTrackerData objects, and not VTrackerDataMaker ones.
378       
379       AliMUONVTrackerData* data = dynamic_cast<AliMUONVTrackerData*>(object);
380       if ( data ) 
381       {
382         AliMUONVTrackerDataMaker* maker = new AliMUONTrackerDataWrapper(data);
383         AliMUONPainterDataRegistry::Instance()->Register(maker);
384       }
385     }
386   }
387   
388
389
390 //______________________________________________________________________________
391 void
392 AliMUONMchViewApplication::PrintAs()
393 {
394   /// Print as...
395   
396   TGFileInfo fileInfo;
397   
398   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
399                    kFDSave,&fileInfo);
400   
401   fPainterMasterFrame->SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
402 }
403
404 //______________________________________________________________________________
405 void
406 AliMUONMchViewApplication::ReleaseNotes()
407 {
408   /// Display release notes
409   
410   UInt_t width = 600;
411   UInt_t height = 400;
412   
413   TGTransientFrame* t = new TGTransientFrame(gClient->GetRoot(),gClient->GetRoot(),width,height);
414   
415   TGTextView* rn = new TGTextView(t);
416
417   rn->AddLine("1.01");
418   rn->AddLine("");
419   rn->AddLine("Added the configuration as a possible OCDB data source");
420   rn->AddLine("");
421   
422   rn->AddLine("1.00");
423   rn->AddLine("");
424   rn->AddLine("Added the Status and StatusMap as a possible OCDB data source");
425   rn->AddLine("");
426   rn->AddLine("Added one (computed) dimension to the Gains data source = 1/a1/0.2 (mV/fC)");
427   rn->AddLine("");
428     
429   rn->AddLine("0.99a");
430   rn->AddLine("");
431   rn->AddLine("Added the --de and --chamber options");
432   rn->AddLine("");
433   
434   rn->AddLine("0.99");
435   rn->AddLine("");
436   rn->AddLine("The chamberid in the label (top right of panel) is now starting at 1 as in common usage");  
437   rn->AddLine("");
438   
439   rn->AddLine("0.98");
440   rn->AddLine("");
441   rn->AddLine("Added --asciimapping option");
442   rn->AddLine("");
443   
444   rn->AddLine("0.97");
445   rn->AddLine("");
446   rn->AddLine("Adding calibration option with Emelec (aka injection) gain");
447   rn->AddLine("");
448   
449   rn->AddLine("0.96a");
450   rn->AddLine("");
451   rn->AddLine("Internal reorganization of the contour computations, that lead to improved performance. ");
452   rn->AddLine("Improved enough to be able to remove completely the usage of the padstore.root file with precomputed contours.");
453   rn->AddLine("");
454   
455   rn->AddLine("0.96");
456   rn->AddLine("");
457   rn->AddLine("New features");
458   rn->AddLine("");
459   rn->AddLine("- Can now read raw data from memory (using the mem://@gdc: syntax)");
460   rn->AddLine("- Raw data decoder now automatically skips buspatches with parity errors");
461   rn->AddLine("");
462   
463   rn->AddLine("0.95");
464   rn->AddLine("");
465   rn->AddLine("New features");
466   rn->AddLine("");
467   rn->AddLine("- Can now read and display HV values from OCDB");
468   rn->AddLine("- New program option --geometry to force geometry of the window");
469   rn->AddLine("- Added possibility, in painters' context menu, to include or exclude part of the detector");
470   rn->AddLine("  (which will be used later on to communicate with LC2 which parts should be read out or not)");
471   rn->AddLine("");
472   rn->AddLine("Improvement");
473   rn->AddLine("");
474   rn->AddLine("- When displaying Gains, the quality information is now decoded");
475   rn->AddLine("");
476   
477   rn->AddLine("0.94");
478   rn->AddLine("");
479   rn->AddLine("New features");
480   rn->AddLine("");
481   rn->AddLine("Can now read ASCII calibration files produced by the DA");
482   rn->AddLine("");
483   
484   rn->AddLine("0.93");
485   rn->AddLine("");
486   rn->AddLine("New features");
487   rn->AddLine("");
488   rn->AddLine("- Adding a Lock button under the color slider to lock the range shown");
489   rn->AddLine("  when switching between views");
490   rn->AddLine("- Default display now shows bending plane (instead of cathode 0 before)");
491   rn->AddLine("- If pad is responder and there's some histo for that pad, ");
492   rn->AddLine("  clicking on it will display an histo");
493   rn->AddLine("- Right-click on a painter will now display several histogram options");
494   rn->AddLine("  (e.g. raw charge as before, but also simple distributions of mean");
495   rn->AddLine("  and sigma");
496   rn->AddLine("- In the Data Sources Tab, each data source can now be removed and saved");
497   rn->AddLine("- There's a new Tool menu which allow to produce a TrackerData from two others");
498   rn->AddLine("  in order to compare data.");
499   rn->AddLine("  - The --use option can now reference alien files");
500   rn->AddLine("");    
501   rn->AddLine("Bug fixes");
502   rn->AddLine("");    
503   rn->AddLine("- Can now read Capacitances from OCDB");
504     
505   rn->Resize(width,height);
506   
507   t->AddFrame(rn, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
508   
509   t->MapSubwindows();
510   t->Resize();
511   t->MapWindow();
512   t->CenterOnParent();
513     
514   // set names
515   
516   t->SetWindowName("mchview release notes");
517   t->SetIconName("mchview release notes");
518   
519 //  t->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
520 //              kMWMDecorMinimize | kMWMDecorMenu,
521 //              kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
522 //              kMWMFuncMinimize,
523 //              kMWMInputModeless);
524   
525   t->MapRaised();
526 //  gClient->WaitFor(t);
527 }
528
529 //______________________________________________________________________________
530 void
531 AliMUONMchViewApplication::Save()
532 {
533   /// Open "Save VTrackerData objects to file" dialog
534   
535   TGFileInfo fileInfo;
536   
537   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
538                    kFDSave,&fileInfo);
539   
540   Save(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
541 }  
542
543 //______________________________________________________________________________
544 void
545 AliMUONMchViewApplication::Save(const char* filename)
546 {
547   /// Save VTrackerDataMaker objects into file of given name
548   
549   AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
550
551   TFile f(filename,"RECREATE");
552   
553   for ( Int_t i = 0; i < reg->NumberOfDataMakers(); ++i )
554   {
555     AliMUONVTrackerDataMaker* maker = reg->DataMaker(i);
556     maker->Write();
557   }
558   
559   f.Close();
560 }