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