]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerGUIdimap.cxx
Class version increased
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerGUIdimap.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 //-----------------------------------------------------------------------------
19 /// \class AliMUONTriggerGUIdimap
20 ///
21 /// The digit maps of the four trigger chambers, all boards
22 ///
23 /// \author Bogdan Vulpescu, LPC Clermont-Ferrand
24 //-----------------------------------------------------------------------------
25
26 #include <TCanvas.h>
27 #include <TGButton.h>
28 #include <TGTab.h>
29 #include <TRootEmbeddedCanvas.h>
30 #include <TBox.h>
31 #include <TClonesArray.h>
32 #include <TPave.h>
33 #include <TPaveText.h>
34 #include <TStyle.h>
35 #include <TObjArray.h>
36
37 #include "AliRun.h"
38
39 #include "AliMUON.h"
40 #include "AliMUONVDigit.h"
41 #include "AliMpSegmentation.h"
42 #include "AliMpVSegmentation.h"
43 #include "AliMUONGeometryTransformer.h"
44 #include "AliMUONMCDataInterface.h"
45
46 #include "AliMUONTriggerGUIboard.h"
47 #include "AliMUONTriggerGUIdimap.h"
48
49 #include "AliMUONVDigitStore.h"
50
51 /// \cond CLASSIMP
52 ClassImp(AliMUONTriggerGUIdimap)
53 /// \endcond
54
55 //__________________________________________________________________________
56 AliMUONTriggerGUIdimap::AliMUONTriggerGUIdimap(TObjArray *boards, const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h)
57   : TGFrame(0),
58     fMain(0),
59     fLoader(0),
60     fMCDataInterface(0),
61     fBoards(0),
62     fIsOn(0)
63 {
64   /// frame constructor
65
66   fIsOn   = kTRUE;
67   fBoards = boards;
68
69   gStyle->SetPadLeftMargin(0.05);
70   gStyle->SetPadRightMargin(0.05);
71   gStyle->SetPadTopMargin(0.05);
72   gStyle->SetPadBottomMargin(0.05);
73
74   gStyle->SetOptDate(0);
75   gStyle->SetOptTitle(0);
76   gStyle->SetOptStat(0);
77
78   fMain = new TGTransientFrame(p, main, w, h, kVerticalFrame);
79   fMain->Connect("CloseWindow()", "AliMUONTriggerGUIdimap", this, "DoClose()");
80   fMain->DontCallClose(); // to avoid double deletions.
81   
82   // use hierarchical cleaning
83   fMain->SetCleanup(kDeepCleanup);
84
85   TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
86
87   TGTextButton *closeButton = new TGTextButton(hframe, "Close", 1);
88   closeButton->Connect("Clicked()", "AliMUONTriggerGUIdimap", this, "DoClose()");
89
90   hframe->AddFrame(closeButton, 
91                    new TGLayoutHints(kLHintsTop | 
92                                      kLHintsLeft,
93                                      2, 2, 2, 2)
94                    );
95
96   hframe->Resize(150, closeButton->GetDefaultHeight());
97
98   TGTextButton *updateButton = new TGTextButton(hframe, "Update", 2);
99   updateButton->Connect("Clicked()", "AliMUONTriggerGUIdimap", this, "DoUpdate()");
100   updateButton->SetToolTipText("Read the digits for the current event");
101
102   hframe->AddFrame(updateButton, 
103                    new TGLayoutHints(kLHintsTop | 
104                                      kLHintsLeft,
105                                      2, 2, 2, 2)
106                    );
107
108   hframe->Resize(150, updateButton->GetDefaultHeight());
109   /*
110   TGTextButton *resetButton = new TGTextButton(hframe, "Reset", 3);
111   resetButton->Connect("Clicked()", "AliMUONTriggerGUIdimap", this, "DoReset()");
112   resetButton->SetToolTipText("Redraw unselected boards");
113
114   hframe->AddFrame(resetButton, 
115                    new TGLayoutHints(kLHintsTop | 
116                                      kLHintsLeft,
117                                      2, 2, 2, 2)
118                    );
119
120   hframe->Resize(150, resetButton->GetDefaultHeight());
121   */
122   fMain->AddFrame(hframe, 
123                   new TGLayoutHints(kLHintsBottom | 
124                                     kLHintsLeft, 
125                                     2, 2, 2, 2)
126                   );
127   
128   TGTab *tab = new TGTab(fMain, 300, 300);
129   //tab->Connect("Selected(Int_t)", "AliMUONTriggerGUIdimap", this, "DoTab(Int_t)");
130
131   // Tabs for MT11, MT12, MT21, MT22
132   TGLayoutHints *lot = new TGLayoutHints(kLHintsTop | 
133                                          kLHintsLeft | 
134                                          kLHintsExpandX |
135                                          kLHintsExpandY, 
136                                          5, 5, 5, 5);
137   
138   TGCompositeFrame *tf = 0;
139
140   // Tab for MT11
141   tf = tab->AddTab("MT11");
142
143   TGCompositeFrame *cf1 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
144   fEc[0] = new TRootEmbeddedCanvas("ec1", cf1, 500, 500);
145   cf1->AddFrame(fEc[0], lot);
146
147   tf->AddFrame(cf1, lot);
148   fEc[0]->GetCanvas()->SetBorderMode(0);
149   fEc[0]->GetCanvas()->SetBit(kNoContextMenu);
150   
151   // Tab for MT12
152   tf = tab->AddTab("MT12");
153
154   TGCompositeFrame *cf2 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
155   fEc[1] = new TRootEmbeddedCanvas("ec2", cf2, 500, 500);
156   cf2->AddFrame(fEc[1], lot);
157
158   tf->AddFrame(cf2, lot);
159   fEc[1]->GetCanvas()->SetBorderMode(0);
160   fEc[1]->GetCanvas()->SetBit(kNoContextMenu);
161   
162   // Tab for MT21
163   tf = tab->AddTab("MT21");
164
165   TGCompositeFrame *cf3 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
166   fEc[2] = new TRootEmbeddedCanvas("ec3", cf3, 500, 500);
167   cf3->AddFrame(fEc[2], lot);
168
169   tf->AddFrame(cf3, lot);
170   fEc[2]->GetCanvas()->SetBorderMode(0);
171   fEc[2]->GetCanvas()->SetBit(kNoContextMenu);
172   
173   // Tab for MT22
174   tf = tab->AddTab("MT22");
175
176   TGCompositeFrame *cf4 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
177   fEc[3] = new TRootEmbeddedCanvas("ec4", cf4, 500, 500);
178   cf4->AddFrame(fEc[3], lot);
179
180   tf->AddFrame(cf4, lot);
181   fEc[3]->GetCanvas()->SetBorderMode(0);
182   fEc[3]->GetCanvas()->SetBit(kNoContextMenu);
183   
184   fMain->AddFrame(tab, 
185                   new TGLayoutHints(kLHintsBottom | 
186                                     kLHintsExpandX |
187                                     kLHintsExpandY, 
188                                     2, 2, 2, 2)
189                   );
190   
191   fMain->MapSubwindows();
192   fMain->Resize();
193   
194   fMain->CenterOnParent();
195   
196   fMain->SetWindowName("Chambers digit maps");
197   
198   fMain->MapWindow();
199
200 }
201
202 //__________________________________________________________________________
203 AliMUONTriggerGUIdimap::~AliMUONTriggerGUIdimap()
204 {
205   /// destructor
206
207   for (Int_t it = 0; it < kNMT; it++) {
208     for (Int_t ib = 0; ib < kNBoards; ib++) {
209       delete fPaveBoard[it][ib];
210     }
211   }
212
213   fMain->DeleteWindow();
214
215 }
216
217 //__________________________________________________________________________
218 void AliMUONTriggerGUIdimap::DrawAllMaps()
219 {
220   /// draw maps 
221
222   if (fLoader == 0x0) {
223     return;
224   }
225   if (fMCDataInterface == 0x0) {
226     return;
227   }
228
229   DrawMaps(11);
230   DrawMaps(12);
231   DrawMaps(13);
232   DrawMaps(14);
233
234 }
235
236 //__________________________________________________________________________
237 void AliMUONTriggerGUIdimap::DrawMaps(Int_t chamber)
238 {
239   /// draw the digits map for chamber-
240
241   TString mapspath = gSystem->Getenv("ALICE_ROOT");
242   mapspath.Append("/MUON/data");
243
244   TCanvas *canvas = fEc[chamber-11]->GetCanvas();
245   canvas->cd();
246   canvas->Clear();
247
248   AliRunLoader *runLoader = fLoader->GetRunLoader();
249   gAlice = runLoader->GetAliRun();
250   AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
251   const AliMUONGeometryTransformer* kGeomTransformer = pMUON->GetGeometryTransformer();
252   
253   AliMUONVDigitStore *digitStore = fMCDataInterface->DigitStore(runLoader->GetEventNumber());
254
255   TPaveText *label;
256   TBox *boxd;
257
258   Char_t fntxt[256], name[8], cln[2];
259   Int_t detElemId, cathode, ix, iy, charge, color;
260   Int_t side, col, line, nbx;
261   Int_t holdS, holdL, holdC;
262   Float_t xCenter, yCenter, zCenter, xWidth, yWidth, holdXC, holdYC;
263   Float_t xMin, xMax, yMin, yMax;
264   Float_t ptx1, ptx2, pty1, pty2;
265   Float_t xpmin, xpmax, ypmin, ypmax;
266   Float_t xg1, xg2, yg1, yg2, zg1;
267     
268   Float_t frameXmax = 0., frameYmax = 0.;
269
270   switch(chamber) {
271   case 11:
272     frameXmax = 257.0;
273     frameYmax = 306.6;
274     break;
275   case 12:
276     frameXmax = 259.7;
277     frameYmax = 309.9;
278     break;
279   case 13:
280     frameXmax = 273.0;
281     frameYmax = 325.7;
282     break;
283   case 14:
284     frameXmax = 275.7;
285     frameYmax = 329.0;
286     break;
287   }
288
289   canvas->Range(
290                 -(1.15*frameXmax),
291                 -(1.15*frameYmax),
292                 +(1.15*frameXmax),
293                 +(1.15*frameYmax)
294                 );
295
296   // draw the boards
297   
298   sprintf(fntxt,"%s/guimapp%2d.txt",mapspath.Data(),chamber);
299   FILE *ftxt = fopen(fntxt,"r");
300   
301   for (Int_t ib = 0; ib < kNBoards; ib++) {
302     
303     fscanf(ftxt,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",
304            &side,&col,&line,&nbx,
305            &xCenter,&yCenter,&xWidth,&yWidth,&zCenter,
306            &name[0]);
307
308     //printf("%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",side,col,line,nbx,xCenter,yCenter,xWidth,yWidth,zCenter,name);
309
310     holdS = side;
311     holdC = col;
312     holdL = line;
313
314     holdXC = xCenter;
315     holdYC = yCenter;
316
317     xMin = xCenter - xWidth/2;
318     xMax = xCenter + xWidth/2;
319     yMin = yCenter - yWidth/2;
320     yMax = yCenter + yWidth/2;
321     
322     fPaveBoard[chamber-11][ib] = new TPave(xMin,yMin,xMax,yMax,1);
323     fPaveBoard[chamber-11][ib]->SetBit(kCannotPick);
324     fPaveBoard[chamber-11][ib]->SetFillStyle(0);
325     fPaveBoard[chamber-11][ib]->Draw();
326
327     Float_t lWidth = 12.0;
328
329     if (holdL == 9) {
330
331       sprintf(cln,"C%1d",holdC);
332
333       ptx1 = holdXC - lWidth;
334       ptx2 = holdXC + lWidth;
335       pty1 = +1.065*frameYmax - lWidth;
336       pty2 = +1.065*frameYmax + lWidth;
337
338       label = new TPaveText(ptx1,pty1,ptx2,pty2,cln);
339       label->AddText(cln);
340       label->SetBorderSize(0);
341       label->SetBit(kCannotPick);
342       label->Draw();
343     }
344     if (holdL == 1) {
345
346       sprintf(cln,"C%1d",holdC);
347
348       ptx1 = holdXC - lWidth;
349       ptx2 = holdXC + lWidth;
350       pty1 = -1.065*frameYmax - lWidth;
351       pty2 = -1.065*frameYmax + lWidth;
352
353       label = new TPaveText(ptx1,pty1,ptx2,pty2,cln);
354       label->AddText(cln);
355       label->SetBorderSize(0);
356       label->SetBit(kCannotPick);
357       label->Draw();
358     }
359     if (holdS == 0 && holdC == 7) {
360
361       sprintf(cln,"L%1d",holdL);
362
363       ptx1 = -1.07*frameXmax - lWidth;
364       ptx2 = -1.07*frameXmax + lWidth;
365       pty1 = holdYC - lWidth;
366       pty2 = holdYC + lWidth;
367
368       label = new TPaveText(ptx1,pty1,ptx2,pty2,cln);
369       label->AddText(cln);
370       label->SetBorderSize(0);
371       label->SetBit(kCannotPick);
372       label->Draw();
373     }
374     if (holdS == 1 && holdC == 7) {
375
376       sprintf(cln,"L%1d",holdL);
377
378       ptx1 = +1.07*frameXmax - lWidth;
379       ptx2 = +1.07*frameXmax + lWidth;
380       pty1 = holdYC - lWidth;
381       pty2 = holdYC + lWidth;
382
383       label = new TPaveText(ptx1,pty1,ptx2,pty2,cln);
384       label->AddText(cln);
385       label->SetBorderSize(0);
386       label->SetBit(kCannotPick);
387       label->Draw();
388    }
389     
390   }
391
392   fclose(ftxt);
393
394   // draw digits set from the board GUI
395
396   AliMUONTriggerGUIboard *board;
397   Int_t imt = chamber -11;
398   Int_t nStripX, nStripY;
399   TBox *box;
400   for (Int_t ib = 0; ib < kNBoards; ib++) {
401
402     board = (AliMUONTriggerGUIboard*)fBoards->At(ib);
403
404     xCenter = board->GetXCenter(imt);
405     yCenter = board->GetYCenter(imt);
406
407     nStripX = board->GetXSiy2() - board->GetXSiy1() + 1;
408     nStripY = board->GetYSix2() - board->GetYSix1() + 1 ;
409
410     for (Int_t is = 0; is < nStripX; is++) {
411
412       if (board->GetXDig(imt,is) == 0) continue;
413
414       box = board->GetXDigBox(imt,is);
415
416       xpmin = box->GetX1();
417       xpmax = box->GetX2();
418       ypmin = box->GetY1();
419       ypmax = box->GetY2();
420
421       xpmin += xCenter;
422       xpmax += xCenter;
423       ypmin += yCenter;
424       ypmax += yCenter;
425
426       box->DrawBox(xpmin,ypmin,xpmax,ypmax);
427
428     }
429
430     for (Int_t is = 0; is < nStripY; is++) {
431
432       if (board->GetYDig(imt,is) == 0) continue;
433
434       box = board->GetYDigBox(imt,is);
435
436       xpmin = box->GetX1();
437       xpmax = box->GetX2();
438       ypmin = box->GetY1();
439       ypmax = box->GetY2();
440
441       xpmin += xCenter;
442       xpmax += xCenter;
443       ypmin += yCenter;
444       ypmax += yCenter;
445
446       box->DrawBox(xpmin,ypmin,xpmax,ypmax);
447
448     }
449
450   }
451   
452   // draw the digits
453
454   TIter next(digitStore->CreateIterator());
455   AliMUONVDigit* mdig;
456   
457   while ( ( mdig = static_cast<AliMUONVDigit*>(next()) ) ) 
458   {
459     cathode = mdig->Cathode()+1;
460     
461     ix=mdig->PadX();
462     iy=mdig->PadY();
463     detElemId=mdig->DetElemId();      
464     charge = (Int_t)mdig->Charge();
465     color  = 261+5*(charge-1);
466     if (color > 282) color = 282;
467
468     if (detElemId/100 != chamber) continue;
469
470     const AliMpVSegmentation* seg2 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode-1));
471     
472     AliMpPad mpad = seg2->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
473     
474     // get the pad position and dimensions
475     Float_t xlocal1 = mpad.Position().X();
476     Float_t ylocal1 = mpad.Position().Y();
477     Float_t xlocal2 = mpad.Dimensions().X();
478     Float_t ylocal2 = mpad.Dimensions().Y();
479     
480     kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
481     // (no transformation for pad dimensions)
482     xg2 = xlocal2;
483     yg2 = ylocal2;
484
485     // transform in the monitor coordinate system
486     //xpmin = -(xg1+xg2);
487     //xpmax = -(xg1-xg2);
488     //ypmin = -(yg2-yg1);
489     //ypmax = +(yg2+yg1);
490     // ALICE SC
491     xpmin = +(xg1-xg2);
492     xpmax = +(xg1+xg2);
493     ypmin = -(yg2-yg1);
494     ypmax = +(yg2+yg1);
495               
496     boxd = new TBox(xpmin,ypmin,xpmax,ypmax);
497     boxd->SetBit(kCannotPick);
498     boxd->SetFillStyle(1001);
499     boxd->SetFillColor(2);
500     boxd->Draw();
501     
502   }  // end digits loop
503
504   canvas->Modified();
505   canvas->Update();
506
507 }
508
509 //__________________________________________________________________________
510 void AliMUONTriggerGUIdimap::DoTab(Int_t id) const
511 {
512   /// some action when chamber tab is selected...
513
514   switch (id) {
515   case 0:
516     break;
517   case 1:
518     break;
519   case 2:
520     break;
521   case 3:
522     break;
523   default:
524     break;
525   }
526
527 }
528
529 //__________________________________________________________________________
530 void AliMUONTriggerGUIdimap::DoClose()
531 {
532   /// close the main frame
533
534   fIsOn = kFALSE;
535   CloseWindow();
536
537 }
538
539 //__________________________________________________________________________
540 void AliMUONTriggerGUIdimap::DoUpdate()
541 {
542   /// update maps for another run/event
543
544   for (Int_t it = 0; it < kNMT; it++) {
545     for (Int_t ib = 0; ib < kNBoards; ib++) {
546       delete fPaveBoard[it][ib];
547     }
548   }
549
550   DrawMaps(11);
551   DrawMaps(12);
552   DrawMaps(13);
553   DrawMaps(14);
554
555   AliMUONTriggerGUIboard *board;
556   for (Int_t ib = 0; ib < kNBoards; ib++) {
557     board = (AliMUONTriggerGUIboard*)fBoards->At(ib);
558     if (board->IsOpen()) SelectBoard(ib);
559   }
560
561 }
562
563 //__________________________________________________________________________
564 void AliMUONTriggerGUIdimap::DoReset()
565 {
566   /// draw unselected boards
567
568   for (Int_t it = 0; it < kNMT; it++) {
569
570     TCanvas *canvas = fEc[it]->GetCanvas();
571     canvas->cd();
572     
573     for (Int_t ib = 0; ib < kNBoards; ib++) { 
574       fPaveBoard[it][ib]->SetFillStyle(0);
575     }
576
577     canvas->Modified();
578     canvas->Update();
579
580   }
581
582 }
583
584 //__________________________________________________________________________
585 void AliMUONTriggerGUIdimap::SelectBoard(Int_t id)
586 {
587   /// highlight on the map the open board
588
589   for (Int_t it = 0; it < kNMT; it++) {
590
591     TCanvas *canvas = fEc[it]->GetCanvas();
592     canvas->cd();
593     
594     fPaveBoard[it][id]->SetFillStyle(4020);
595     fPaveBoard[it][id]->SetFillColor(7);
596
597     canvas->Modified();
598     canvas->Update();
599
600   }
601
602 }
603
604 //__________________________________________________________________________
605 void AliMUONTriggerGUIdimap::CloseWindow()
606 {
607   /// called when window is closed via the window manager.
608
609   fMain->CloseWindow();
610
611 }
612
613