]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerGUIbdmap.cxx
New files for trigger GUI (Bogdan)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerGUIbdmap.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 //////////////////////////////////////////////////////////////////////////
17 //                                                                      //
18 // Graphical User Interface utility class for the MUON trigger          //
19 // - single board map of the strips/digits                              //
20 //                                                                      //
21 //////////////////////////////////////////////////////////////////////////
22
23 #include <TPolyLine.h>
24 #include <TStyle.h>
25 #include <TGFrame.h>
26 #include <TGButton.h>
27 #include <TRootEmbeddedCanvas.h>
28 #include <TBox.h>
29 #include <TPaveText.h>
30 #include <TGTextEdit.h>
31 #include <TGText.h>
32 #include <TTimer.h>
33 #include <TObjArray.h>
34 #include <TCanvas.h>
35
36 #include "AliRun.h"
37 #include "AliMUON.h"
38 #include "AliMUONData.h"
39 #include "AliMUONDigit.h"
40 #include "AliMpVSegmentation.h"
41 #include "AliMpSegmentation.h"
42 #include "AliMUONGeometryTransformer.h"
43 #include "AliMpDEIterator.h"
44 #include "AliMUONLocalTrigger.h"
45 #include "AliMUONLocalTriggerBoard.h"
46 #include "AliMUONTriggerCrateStore.h"
47
48 #include "AliMUONTriggerGUIboard.h"
49 #include "AliMUONTriggerGUIbdmap.h"
50
51 /// \cond CLASSIMP
52 ClassImp(AliMUONTriggerGUIbdmap)
53 /// \endcond
54
55 //__________________________________________________________________________
56 AliMUONTriggerGUIbdmap::AliMUONTriggerGUIbdmap(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h)
57   : TObject(),
58     fQObject(),
59     fMain(0),
60     fLocTrigE(0),
61     fBoard(0),
62     fLoader(0),
63     fMUONData(0),
64     fXStrips(0),
65     fYStrips(0),
66     fEditStrips(0),
67     fXOn(0),
68     fYOn(0),
69     fLabelX(0),
70     fLabelY(0),
71     fIsEditable(0),
72     fCanvasSize(0),
73     fNStripX(0),
74     fNStripY(0),
75     fBoards(0)
76 {
77   /// frame constructor
78
79   gStyle->SetPadLeftMargin(0.05);
80   gStyle->SetPadRightMargin(0.05);
81   gStyle->SetPadTopMargin(0.05);
82   gStyle->SetPadBottomMargin(0.05);
83
84   fMain = new TGTransientFrame(p, main, w, h, kVerticalFrame);
85   fMain->Connect("CloseWindow()", "AliMUONTriggerGUIbdmap", this, "CloseWindow()");
86   fMain->DontCallClose(); // to avoid double deletions.
87   
88   // use hierarchical cleaning
89   fMain->SetCleanup(kDeepCleanup);
90
91   fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
92
93   // strips/digits canvases
94   
95   fCanvasSize = 200;
96
97   TRootEmbeddedCanvas *recanvas[4];
98   Char_t ecname[1];
99   for (Int_t i = 0; i < kNMT; i++) {
100
101     sprintf(ecname,"%1d",i+1);
102     recanvas[i] = new TRootEmbeddedCanvas(ecname,fMain,fCanvasSize,fCanvasSize);
103     
104     fCanvas[i] = recanvas[i]->GetCanvas();
105     
106     fCanvas[i]->SetBorderMode(0);
107     fCanvas[i]->SetBit(kNoContextMenu);
108     
109     fCanvas[i]->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
110                         "AliMUONTriggerGUIbdmap",this,
111                         "EditStrips(Int_t,Int_t,Int_t,TObject*)");
112
113     fMain->AddFrame(recanvas[i],
114                     /*
115                     new TGTableLayoutHints(2,5,2,6,
116                                            kLHintsExpandX|kLHintsExpandY |
117                                            kLHintsShrinkX|kLHintsShrinkY |
118                                            kLHintsFillX|kLHintsFillY)
119                     */
120                     new TGLayoutHints(kLHintsTop | 
121                                       kLHintsLeft, 
122                                       2, 2, 2, 2)
123                     );
124
125   }
126
127   //TGDimension size = fMain->GetDefaultSize();
128   //fMain->Resize(size);
129     
130   // the other frames
131
132   TGCompositeFrame *cf0 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame);
133
134   TGCompositeFrame *cf1 = new TGCompositeFrame(cf0, 60, 20, kVerticalFrame | kFixedWidth);
135
136   cf1->AddFrame(fXStrips = new TGCheckButton(cf1, "Draw X strips and digits", 1),
137                 new TGLayoutHints(kLHintsTop | 
138                                   kLHintsLeft, 
139                                   2, 2, 2, 2)
140                 );
141
142   cf1->Resize(fXStrips->GetDefaultWidth()+10, fMain->GetDefaultHeight());
143
144   cf1->AddFrame(fYStrips = new TGCheckButton(cf1, "Draw Y strips and digits", 2),
145                 new TGLayoutHints(kLHintsTop | 
146                                   kLHintsLeft, 
147                                   2, 2, 2, 2)          
148                 );
149
150   cf1->Resize(fYStrips->GetDefaultWidth()+10, fMain->GetDefaultHeight());
151
152   cf1->AddFrame(fEditStrips = new TGCheckButton(cf1, "Set/unset strips", 3),
153                 new TGLayoutHints(kLHintsTop | 
154                                   kLHintsLeft, 
155                                   2, 2, 2, 2)          
156                 );
157
158   fXStrips->Connect("Clicked()", "AliMUONTriggerGUIbdmap", this, "HandleButtons()");
159   fYStrips->Connect("Clicked()", "AliMUONTriggerGUIbdmap", this, "HandleButtons()");
160   fEditStrips->Connect("Clicked()", "AliMUONTriggerGUIbdmap", this, "HandleEditButton()");
161
162   cf0->AddFrame(cf1, 
163                 new TGLayoutHints(kLHintsTop | 
164                                   kLHintsExpandX, 
165                                   2, 2, 2, 2)          
166                 );
167   
168   TGCompositeFrame *cf2 = new TGCompositeFrame(cf0, 60, 20, kHorizontalFrame | kFixedWidth);
169
170   TGTextButton *digitsButton = new TGTextButton(cf2, "Digits", 4);
171   digitsButton->Connect("Clicked()", "AliMUONTriggerGUIbdmap", this, "DoDigits()");
172
173   //cf2->Resize(digitsButton->GetDefaultWidth()+40, fMain->GetDefaultHeight());
174
175   cf2->AddFrame(digitsButton, 
176                 new TGLayoutHints(kLHintsTop | 
177                                   kLHintsLeft |
178                                   kLHintsExpandX, 
179                                   2, 2, 5, 5)          
180                 );
181
182   TGTextButton *dresetButton = new TGTextButton(cf2, "Reset", 5);
183   dresetButton->Connect("Clicked()", "AliMUONTriggerGUIbdmap", this, "ResetDigits()");
184
185   //cf2->Resize(dresetButton->GetDefaultWidth()+40, fMain->GetDefaultHeight());
186
187   cf2->AddFrame(dresetButton, 
188                 new TGLayoutHints(kLHintsTop | 
189                                   kLHintsLeft |
190                                   kLHintsExpandX, 
191                                   2, 2, 5, 5)          
192                 );
193
194   TGTextButton *closeButton = new TGTextButton(cf2, "Close", 6);
195   closeButton->Connect("Clicked()", "AliMUONTriggerGUIbdmap", this, "DoClose()");
196
197   //cf2->Resize(closeButton->GetDefaultWidth()+40, fMain->GetDefaultHeight());
198
199   cf2->AddFrame(closeButton, 
200                 new TGLayoutHints(kLHintsTop | 
201                                   kLHintsLeft |
202                                   kLHintsExpandX, 
203                                   2, 2, 5, 5)          
204                 );
205
206   cf0->AddFrame(cf2, 
207                   new TGLayoutHints(kLHintsTop | 
208                                     kLHintsExpandX, 
209                                     2, 2, 2, 2)        
210                   );
211   
212   // editor window for the local trigger
213
214   TGCompositeFrame *cf3 = new TGCompositeFrame(cf0, 60, 20, kVerticalFrame | kFixedWidth);
215
216   fLocTrigE = new TGTextEdit(cf3, 100, 100, kSunkenFrame | kDoubleBorder);
217   cf3->AddFrame(fLocTrigE, 
218                 new TGLayoutHints(kLHintsExpandX | 
219                                   kLHintsExpandY, 
220                                   3, 3, 3, 3)
221                 );
222
223   cf0->AddFrame(cf3, 
224                   new TGLayoutHints(kLHintsTop | 
225                                     kLHintsExpandX, 
226                                     2, 2, 2, 2)        
227                   );
228   
229   fMain->AddFrame(cf0, 
230                   new TGLayoutHints(kLHintsTop | 
231                                     kLHintsExpandX, 
232                                     2, 2, 2, 2)        
233                   );
234   
235   fIsEditable = kFALSE;
236   fLabelX = kFALSE;
237   fLabelY = kFALSE;
238
239   fMain->MapSubwindows();
240   fMain->Resize();
241   
242   fMain->CenterOnParent();
243
244   //fMain->MapWindow();
245   //gClient->WaitFor(fMain);
246   
247 }
248
249 //__________________________________________________________________________
250 AliMUONTriggerGUIbdmap::~AliMUONTriggerGUIbdmap()
251 {
252   /// frame destructor
253
254   fMain->DeleteWindow();
255
256 }
257
258 //__________________________________________________________________________
259 AliMUONTriggerGUIbdmap::AliMUONTriggerGUIbdmap(const AliMUONTriggerGUIbdmap& bdmap)
260   : TObject(),
261     fQObject(),
262     fMain(0),
263     fLocTrigE(0),
264     fBoard(0),
265     fLoader(0),
266     fMUONData(0),
267     fXStrips(0),
268     fYStrips(0),
269     fEditStrips(0),
270     fXOn(0),
271     fYOn(0),
272     fLabelX(0),
273     fLabelY(0),
274     fIsEditable(0),
275     fCanvasSize(0),
276     fNStripX(0),
277     fNStripY(0),
278     fBoards(0)
279 {
280   /// copy constructor
281
282   bdmap.Dump();
283   Fatal("AliMUONTriggerGUIbdmap","copy constructor not implemented");
284
285 }
286
287 //__________________________________________________________________________
288 AliMUONTriggerGUIbdmap & AliMUONTriggerGUIbdmap::operator=(const AliMUONTriggerGUIbdmap& bdmap)
289 {
290   /// asignment operator
291
292   bdmap.Dump();
293   Fatal("AliMUONTriggerGUIbdmap","assignment operator not implemented");
294
295   return *this;
296
297 }
298
299 //__________________________________________________________________________
300 void AliMUONTriggerGUIbdmap::Show()
301 {
302   /// map the main frame
303
304   fMain->MapWindow();
305   LocalTriggerInfo();
306
307 }
308
309 //__________________________________________________________________________
310 void AliMUONTriggerGUIbdmap::LocalTriggerInfo()
311 {
312   /// print the local trigger
313   
314   AliMUONTriggerCrateStore* crateManager = new AliMUONTriggerCrateStore();
315   crateManager->ReadFromFile();
316
317   TGText txt;
318   Char_t buffer[20];
319
320   sprintf(buffer,"Local trigger info\n");
321   fLocTrigE->LoadBuffer(buffer);
322
323   AliRunLoader *runLoader = fLoader->GetRunLoader();
324   gAlice = runLoader->GetAliRun();
325
326   fMUONData->SetTreeAddress("GLT");
327   fMUONData->GetTriggerD();
328
329   Int_t circuitNumber = fBoard->GetIdCircuit();
330
331   TClonesArray *localTrigger = fMUONData->LocalTrigger();
332   if (localTrigger == 0) return;
333
334   Int_t nLocalTrigger = localTrigger->GetEntriesFast(); 
335
336   UShort_t x2m, x2u, x2d;
337
338   Int_t loStripX, loStripY, loDev, loCircuit, iStripX, iStripY, loLpt, loHpt;
339   AliMUONLocalTrigger *mlt;
340   
341   for (Int_t ilt = 0; ilt < nLocalTrigger; ilt++) {
342     mlt = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(ilt);
343     
344     loCircuit = mlt->LoCircuit();
345
346     if (loCircuit == circuitNumber) {
347
348       AliMUONLocalTriggerBoard* ltb = crateManager->LocalBoard(loCircuit);
349       x2d = ltb->GetSwitch(0);
350       x2m = ltb->GetSwitch(1);
351       x2u = ltb->GetSwitch(2);
352
353       loStripX = mlt->LoStripX();
354       loStripY = mlt->LoStripY();
355       loDev    = mlt->LoDev();
356       loLpt    = mlt->LoLpt();
357       loHpt    = mlt->LoHpt();
358
359       iStripX = loStripX/2;
360       if ((x2u == 1 || x2m == 1 || x2d == 1) && x2m == 1) {
361         iStripY = loStripY/2;
362       } else {
363         iStripY = loStripY;
364       }
365
366       sprintf(buffer,"Circuit = %03d",loCircuit);
367       txt.LoadBuffer(buffer);
368       fLocTrigE->AddText(&txt);
369
370       sprintf(buffer,"LoStripX = %2d",loStripX);
371       txt.LoadBuffer(buffer);
372       fLocTrigE->AddText(&txt);
373
374       sprintf(buffer,"LoStripY = %2d",loStripY);
375       txt.LoadBuffer(buffer);
376       fLocTrigE->AddText(&txt);
377
378       sprintf(buffer,"LoDev = %2d",loDev);
379       txt.LoadBuffer(buffer);
380       fLocTrigE->AddText(&txt);
381
382       sprintf(buffer,"--------------------");
383       txt.LoadBuffer(buffer);
384       fLocTrigE->AddText(&txt);
385
386       sprintf(buffer,"X-strip = %2d ( %2d )",iStripX,(loStripX+loDev+1)/2);
387       txt.LoadBuffer(buffer);
388       fLocTrigE->AddText(&txt);
389
390       sprintf(buffer,"Y-strip = %2d",iStripY);
391       txt.LoadBuffer(buffer);
392       fLocTrigE->AddText(&txt);
393
394       sprintf(buffer,"--------------------");
395       txt.LoadBuffer(buffer);
396       fLocTrigE->AddText(&txt);
397
398       sprintf(buffer,"LoLpt = %2d",loLpt);
399       txt.LoadBuffer(buffer);
400       fLocTrigE->AddText(&txt);
401
402       sprintf(buffer,"LoHpt = %2d",loHpt);
403       txt.LoadBuffer(buffer);
404       fLocTrigE->AddText(&txt);
405
406       break;
407
408     }
409
410   }
411   
412 }
413
414 //__________________________________________________________________________
415 void AliMUONTriggerGUIbdmap::Init()
416 {
417   /// initialize the boards in the four MT
418
419   TString mapspath = gSystem->Getenv("ALICE_ROOT");
420   mapspath.Append("/MUON/data");
421
422   fMUONData = new AliMUONData(fLoader,"MUON","MUON");
423   fMUONData->SetTreeAddress("D");
424
425   TString mapName[kNMT];
426   mapName[0] = TString(mapspath.Data());
427   mapName[1] = TString(mapspath.Data());
428   mapName[2] = TString(mapspath.Data());
429   mapName[3] = TString(mapspath.Data());
430   mapName[0].Append("/guimapp11.txt");
431   mapName[1].Append("/guimapp12.txt");
432   mapName[2].Append("/guimapp13.txt");
433   mapName[3].Append("/guimapp14.txt");
434
435   Int_t side, col, line, nbx;
436   Float_t xCenter, yCenter, zCenter, xWidth, yWidth;
437   Char_t name[8];
438
439   FILE *fmap;
440   for (Int_t i = 0; i < kNMT; i++) {
441
442     fmap = fopen(mapName[i].Data(),"r");
443
444     for (Int_t ib = 0; ib < kNBoards; ib++) {
445
446       fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
447
448       if (side == 0) {
449         sprintf(name,"LC%1dL%1dB%1d%1d",col,line,2*nbx-1,2*nbx);
450       }
451       if (side == 1) {
452         sprintf(name,"RC%1dL%1dB%1d%1d",col,line,2*nbx-1,2*nbx);
453       }
454
455       if (strncmp(name,fBoard->GetBoardName(),7) == 0) {
456         fXWidth[i]  = xWidth;
457         fYWidth[i]  = yWidth; 
458         fXCenter[i] = xCenter;
459         fYCenter[i] = yCenter; 
460
461         fclose(fmap);
462
463         break;
464       }
465
466     }
467
468   }
469
470   Float_t xw, yw;
471   for (Int_t i = 0; i < kNMT; i++) {
472     xw = 1.20*fXWidth[i];
473     yw = 1.20*fYWidth[i];
474     fCanvas[i]->Range(-xw/2,-yw/2,+xw/2,+yw/2);
475     for (Int_t is = 0; is < kNS; is++) {
476
477       fXDigPL[i][is] = new TPolyLine(5);
478       fYDigPL[i][is] = new TPolyLine(5);
479       fXDigPL[i][is]->SetBit(kCannotPick);
480       fYDigPL[i][is]->SetBit(kCannotPick);
481       fXDigPL[i][is]->SetLineColor(4);
482       fYDigPL[i][is]->SetLineColor(4);
483
484       fXDigBox[i][is] = new TBox(0,0,0,0);
485       fYDigBox[i][is] = new TBox(0,0,0,0);
486       fXDigBox[i][is]->SetBit(kCannotPick);
487       fYDigBox[i][is]->SetBit(kCannotPick);
488       fXDigBox[i][is]->SetFillStyle(0);
489       fYDigBox[i][is]->SetFillStyle(0);
490       fXDigBox[i][is]->SetLineColor(4);
491       fYDigBox[i][is]->SetLineColor(4);
492
493       fXLabelL[i][is] = 0;
494       fXLabelR[i][is] = 0;
495       fYLabelL[i][is] = 0;
496       fYLabelR[i][is] = 0;
497
498     }
499   }
500
501
502   fXOn = kFALSE;
503   fYOn = kFALSE;
504
505   fNStripX = fBoard->GetXSiy2() - fBoard->GetXSiy1() + 1;
506   fNStripY = fBoard->GetYSix2() - fBoard->GetYSix1() + 1;
507
508 }
509
510 //__________________________________________________________________________
511 void AliMUONTriggerGUIbdmap::HandleEditButton()
512 {
513   /// handle the editable check button
514
515   if (((fXOn && !fYOn) || (!fXOn && fYOn)) && 
516       (fEditStrips->GetState() == kButtonDown)) {
517     fIsEditable = kTRUE;
518   } else {
519     fIsEditable = kFALSE;
520   }
521
522 }
523
524 //__________________________________________________________________________
525 void AliMUONTriggerGUIbdmap::EditStrips(Int_t event, Int_t x, Int_t y, TObject *sel)
526 {
527   /// set/unset strips
528
529   TString cs;
530   Int_t iMT;
531   Double_t *px, *py;
532   Double_t xf1, yf1, xf2, yf2;
533   Int_t np = 5;
534   Double_t xMin, xMax, yMin, yMax;
535   Float_t xd, yd, fxDim, fyDim, cDim;
536   Char_t cln[2];
537
538   cDim = (Float_t)fCanvasSize;
539   
540   // the (x,y) event does not really go up to the canvas size...
541   cDim = 196.0;
542
543   if (fIsEditable) {
544
545     if (event == kButton1Down) {
546       
547       cs = TString(sel->GetName());
548       iMT = cs.Atoi()-1;
549
550       fCanvas[iMT]->cd();
551
552       fCanvas[iMT]->GetRange(xf1,yf1,xf2,yf2);      
553       fxDim = (Float_t)xf2;
554       fyDim = (Float_t)yf2;
555
556       //xd = fxDim*(+2.0*(Float_t)(x)/cDim - 1.0);
557       //yd = fyDim*(-2.0*(Float_t)(y)/cDim + 1.0);
558
559       xd = +(2.0*fxDim*(Float_t)(x))/cDim - fxDim;
560       yd = -(2.0*fyDim*(Float_t)(y))/cDim + fyDim;
561
562       if (fXOn) {
563
564         for (Int_t ix = 0; ix < fNStripX; ix++) {
565           
566           px = fXDigPL[iMT][ix]->GetX();
567           py = fXDigPL[iMT][ix]->GetY();
568
569           xMin = +9999.;
570           xMax = -9999.;
571           yMin = +9999.;
572           yMax = -9999.;
573           for (Int_t ip = 0; ip < np; ip++) {
574             xMin = TMath::Min(xMin,px[ip]);
575             xMax = TMath::Max(xMax,px[ip]);
576             yMin = TMath::Min(yMin,py[ip]);
577             yMax = TMath::Max(yMax,py[ip]);
578           }
579             
580           if (yd > (Float_t)yMin && yd < (Float_t)yMax) {
581
582             if (fXDigBox[iMT][ix]->GetFillStyle() == 0) {
583
584               fXDigBox[iMT][ix]->SetFillStyle(1001);
585               fXDigBox[iMT][ix]->SetFillColor(2);
586
587               sprintf(cln,"%2d",ix);
588
589               fXLabelL[iMT][ix]->Clear();
590               fXLabelL[iMT][ix]->AddText(cln);
591               fXLabelL[iMT][ix]->Draw();
592
593               fXLabelR[iMT][ix]->Clear();
594               fXLabelR[iMT][ix]->AddText(cln);
595               fXLabelR[iMT][ix]->Draw();
596
597               fXDigBox[iMT][ix]->SetX1(xMin);
598               fXDigBox[iMT][ix]->SetY1(yMin);
599               fXDigBox[iMT][ix]->SetX2(xMax);
600               fXDigBox[iMT][ix]->SetY2(yMax);
601
602               fXDigBox[iMT][ix]->Draw();
603
604             } else if (fXDigBox[iMT][ix]->GetFillStyle() == 1001) {
605
606               fXDigBox[iMT][ix]->SetFillStyle(0);
607
608               fXLabelL[iMT][ix]->Clear();
609               fXLabelL[iMT][ix]->Draw();
610
611               fXLabelR[iMT][ix]->Clear();
612               fXLabelR[iMT][ix]->Draw();
613
614               fXDigBox[iMT][ix]->SetX1(-fBoard->GetXCenter(iMT));
615               fXDigBox[iMT][ix]->SetY1(-fBoard->GetYCenter(iMT));
616               fXDigBox[iMT][ix]->SetX2(-fBoard->GetXCenter(iMT));
617               fXDigBox[iMT][ix]->SetY2(-fBoard->GetYCenter(iMT));
618
619               fXDigBox[iMT][ix]->Draw();
620
621             }
622
623             if (!fXDigBox[iMT][ix]->TestBit(kObjInCanvas))
624               fXDigBox[iMT][ix]->Draw();
625
626             fCanvas[iMT]->Modified();
627             fCanvas[iMT]->Update();
628
629             break;
630             
631           } 
632         }
633
634       }
635
636       if (fYOn) {
637
638         for (Int_t iy = 0; iy < fNStripY; iy++) {
639
640           px = fYDigPL[iMT][iy]->GetX();
641           py = fYDigPL[iMT][iy]->GetY();
642
643           xMin = +9999.;
644           xMax = -9999.;
645           yMin = +9999.;
646           yMax = -9999.;
647           for (Int_t ip = 0; ip < np; ip++) {
648             xMin = TMath::Min(xMin,px[ip]);
649             xMax = TMath::Max(xMax,px[ip]);
650             yMin = TMath::Min(yMin,py[ip]);
651             yMax = TMath::Max(yMax,py[ip]);
652           }
653
654           if (xd > (Float_t)xMin && xd < (Float_t)xMax) {
655
656             if (fYDigBox[iMT][iy]->GetFillStyle() == 0) {
657
658               fYDigBox[iMT][iy]->SetFillStyle(1001);
659               fYDigBox[iMT][iy]->SetFillColor(2);
660
661               sprintf(cln,"%2d",iy);
662
663               fYLabelL[iMT][iy]->Clear();
664               fYLabelL[iMT][iy]->AddText(cln);
665               fYLabelL[iMT][iy]->Draw();
666
667               fYLabelR[iMT][iy]->Clear();
668               fYLabelR[iMT][iy]->AddText(cln);
669               fYLabelR[iMT][iy]->Draw();
670
671               fYDigBox[iMT][iy]->SetX1(xMin);
672               fYDigBox[iMT][iy]->SetY1(yMin);
673               fYDigBox[iMT][iy]->SetX2(xMax);
674               fYDigBox[iMT][iy]->SetY2(yMax);
675               
676               //fYDigBox[iMT][iy]->Draw();
677
678             } else if (fYDigBox[iMT][iy]->GetFillStyle() == 1001) {
679
680               fYDigBox[iMT][iy]->SetFillStyle(0);
681
682               fYLabelL[iMT][iy]->Clear();
683               fYLabelL[iMT][iy]->Draw();
684
685               fYLabelR[iMT][iy]->Clear();
686               fYLabelR[iMT][iy]->Draw();
687
688               fYDigBox[iMT][iy]->SetX1(-fBoard->GetXCenter(iMT));
689               fYDigBox[iMT][iy]->SetY1(-fBoard->GetYCenter(iMT));
690               fYDigBox[iMT][iy]->SetX2(-fBoard->GetXCenter(iMT));
691               fYDigBox[iMT][iy]->SetY2(-fBoard->GetYCenter(iMT));
692
693               //fYDigBox[iMT][iy]->Draw();
694
695             }
696
697             if (!fYDigBox[iMT][iy]->TestBit(kObjInCanvas))
698               fYDigBox[iMT][iy]->Draw();
699
700             fCanvas[iMT]->Modified();
701             fCanvas[iMT]->Update();
702
703             break;
704             
705           } 
706         }
707
708       }
709
710     }  // end button event
711
712   }  // end IsEditable
713
714 }
715
716 //__________________________________________________________________________
717 void AliMUONTriggerGUIbdmap::DoDigits()
718 {
719   /// set the board digits from GUI input (set/unset)
720
721   Int_t amp = 0;
722   Int_t number = fBoard->GetNumber();
723   Int_t pos, over;
724   pos  = fBoard->GetPosition();
725   over = fBoard->GetYOver();
726   AliMUONTriggerGUIboard *board;
727
728   for (Int_t imt = 0; imt < kNMT; imt++) {
729
730     for (Int_t ix = 0; ix < fNStripX; ix++) {
731       if (fXDigBox[imt][ix]->GetFillStyle() ==    0) {
732         amp = 0;
733       }
734       if (fXDigBox[imt][ix]->GetFillStyle() == 1001) {
735         amp = 1;
736       }
737       fBoard->SetDigitX(imt,ix,amp);
738     }
739
740     for (Int_t iy = 0; iy < fNStripY; iy++) {
741       if (fYDigBox[imt][iy]->GetFillStyle() ==    0) {
742         amp = 0;
743       }
744       if (fYDigBox[imt][iy]->GetFillStyle() == 1001) {
745         amp = 1;
746       }
747       fBoard->SetDigitY(imt,iy,amp);
748
749       // extended y-strips
750       for (Int_t io = 1; io <= over; io++) {
751         if (io == pos) continue;
752         board = (AliMUONTriggerGUIboard*)fBoards->UncheckedAt(number+io-pos);
753         board->SetDigitY(imt,iy,amp);
754       }
755
756     }
757
758   }
759
760 }
761
762 //__________________________________________________________________________
763 void AliMUONTriggerGUIbdmap::ResetDigits()
764 {
765   /// set the board digits from GUI input (set/unset)
766
767   Int_t amp = 0;
768   Int_t number = fBoard->GetNumber();
769   AliMUONTriggerGUIboard *board;
770   Int_t pos, over;
771   pos  = fBoard->GetPosition();
772   over = fBoard->GetYOver();
773
774   for (Int_t imt = 0; imt < kNMT; imt++) {
775     for (Int_t ix = 0; ix < fNStripX; ix++) {
776       fXDigBox[imt][ix]->SetFillStyle(0);
777       fXDigBox[imt][ix]->SetX1(-fBoard->GetXCenter(imt));
778       fXDigBox[imt][ix]->SetY1(-fBoard->GetYCenter(imt));
779       fXDigBox[imt][ix]->SetX2(-fBoard->GetXCenter(imt));
780       fXDigBox[imt][ix]->SetY2(-fBoard->GetYCenter(imt));
781
782       fBoard->SetDigitX(imt,ix,amp);
783     }
784     for (Int_t iy = 0; iy < fNStripY; iy++) {
785       fYDigBox[imt][iy]->SetFillStyle(0);
786       fYDigBox[imt][iy]->SetX1(-fBoard->GetXCenter(imt));
787       fYDigBox[imt][iy]->SetY1(-fBoard->GetYCenter(imt));
788       fYDigBox[imt][iy]->SetX2(-fBoard->GetXCenter(imt));
789       fYDigBox[imt][iy]->SetY2(-fBoard->GetYCenter(imt));
790
791       fBoard->SetDigitY(imt,iy,amp);
792
793       // extended y-strips
794       for (Int_t io = 1; io <= over; io++) {
795         if (io == pos) continue;
796         board = (AliMUONTriggerGUIboard*)fBoards->UncheckedAt(number+io-pos);
797
798         board->SetDigitY(imt,iy,amp);
799
800       }
801
802     }
803   }
804
805   fBoard->ClearXDigits();
806   fBoard->ClearYDigits();
807
808   // extended y-strips
809   for (Int_t io = 1; io <= over; io++) {
810     if (io == pos) continue;
811     board = (AliMUONTriggerGUIboard*)fBoards->UncheckedAt(number+io-pos);
812     board->ClearYDigits();
813   }
814   
815   fXStrips->SetState(kButtonUp);
816   fYStrips->SetState(kButtonUp);
817   fEditStrips->SetState(kButtonUp);
818   fIsEditable = kFALSE;
819                       
820   DrawClear();
821   fXOn = kFALSE;
822   fYOn = kFALSE;
823
824 }
825
826 //__________________________________________________________________________
827 void AliMUONTriggerGUIbdmap::HandleButtons(Int_t id)
828 {
829   /// handle the check buttons
830
831   if (id == -1) {
832     TGButton *btn = (TGButton *) gTQSender;
833     id = btn->WidgetId();
834   }
835
836   // draw x and y 
837   if(fXStrips->GetState() == kButtonDown && 
838      fYStrips->GetState() == kButtonDown    ) {
839     
840     DrawClear();
841     DrawStrips(kTRUE,kTRUE);
842     DrawDigits(kTRUE,kTRUE);
843     fXOn = kTRUE;
844     fYOn = kTRUE;
845
846   }
847
848   // draw only x
849   if(fXStrips->GetState() == kButtonDown && 
850      fYStrips->GetState() == kButtonUp      ) {
851     
852     DrawClear();
853     DrawStrips(kTRUE,kFALSE);
854     DrawDigits(kTRUE,kFALSE);
855     fXOn = kTRUE;
856     fYOn = kFALSE;
857
858   }
859
860   // draw only y
861   if(fXStrips->GetState() == kButtonUp   && 
862      fYStrips->GetState() == kButtonDown    ) {
863     
864     DrawClear();
865     DrawStrips(kFALSE,kTRUE);
866     DrawDigits(kFALSE,kTRUE);
867     fXOn = kFALSE;
868     fYOn = kTRUE;
869
870   }
871
872   // clear
873   if(fXStrips->GetState() == kButtonUp   && 
874      fYStrips->GetState() == kButtonUp      ) {
875     
876     DrawClear();
877     fXOn = kFALSE;
878     fYOn = kFALSE;
879
880   }
881
882   HandleEditButton();
883
884 }
885
886 //__________________________________________________________________________
887 void AliMUONTriggerGUIbdmap::DrawClear()
888 {
889   /// draw the frame of the board image in the canvas
890   
891   for (Int_t i = 0; i < kNMT; i++) {
892
893     fCanvas[i]->cd();
894     fCanvas[i]->Clear();
895
896     fCanvas[i]->Modified();
897     fCanvas[i]->Update();
898
899   }
900
901 }
902
903 //__________________________________________________________________________
904 void AliMUONTriggerGUIbdmap::DrawDigits(Bool_t bx, Bool_t by)
905 {
906   /// draw the digits in "x" or/and "y"
907
908   AliRunLoader *runLoader = fLoader->GetRunLoader();
909   gAlice = runLoader->GetAliRun();
910   AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
911   const AliMUONGeometryTransformer* kGeomTransformer = pMUON->GetGeometryTransformer();
912   
913   AliMUONTriggerGUIboard *board;
914   TClonesArray *muonDigits;
915   Int_t nDigits, over, pos, number;
916   const AliMpVSegmentation* seg;
917   AliMUONDigit *mdig;
918   AliMpPad pad;
919   Int_t cathode, detElemId, ix, iy, charge;
920   Int_t chamber, np = 5;
921   AliMpDEIterator it;
922   Float_t xpmin, xpmax, ypmin, ypmax;
923   Float_t xg1, xg2, yg1, yg2, zg1;
924   Float_t xdw, ydw, xcw, ycw;
925   Double_t xc1, xc2, yc1, yc2;
926   Char_t cln[2];
927   TBox *boxd;
928   Double_t xMin, xMax, yMin, yMax;
929   Double_t *px, *py;
930
931   number = fBoard->GetNumber();
932   pos    = fBoard->GetPosition();
933   over   = fBoard->GetYOver();
934
935   for (Int_t i = 0; i < kNMT; i++) {
936
937     fCanvas[i]->cd();
938     
939     fCanvas[i]->GetRange(xc1,yc1,xc2,yc2);
940     xcw = (Float_t)(0.5*(xc2-xc1));
941     ycw = (Float_t)(0.5*(yc2-yc1));
942
943     chamber = 11+i;
944
945     muonDigits = fMUONData->Digits(chamber-1);
946     if (muonDigits == 0) { printf("No muonDigits \n"); return; }
947     gAlice->ResetDigits();
948     fMUONData->GetDigits();
949     nDigits = muonDigits->GetEntriesFast(); 
950
951     for (Int_t id = 0; id < nDigits; id++) {
952     
953       mdig  = (AliMUONDigit*)muonDigits->UncheckedAt(id);
954       
955       cathode = mdig->Cathode()+1;
956       
957       ix = mdig->PadX();
958       iy = mdig->PadY();
959       detElemId = mdig->DetElemId(); 
960       charge = (Int_t)mdig->Signal();
961
962       Bool_t triggerBgn = kFALSE;
963       Int_t schg = (Int_t)(charge + 0.5);
964       // APPLY CONDITION ON SOFT BACKGROUND     
965       Int_t tchg = schg - (Int_t(schg/10))*10;  
966       if (schg<=10 || tchg>0) {
967         triggerBgn = kFALSE;
968       } else {
969         triggerBgn = kTRUE;
970       }
971
972       if (detElemId%100 != fBoard->GetDetElemId()) continue;
973       
974       seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(cathode-1));  
975       
976       pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
977       
978       //if (cathode == 1) printf("GUI x:  ix %d iy %d \n",ix,iy);
979       //if (cathode == 2) printf("GUI y:  ix %d iy %d \n",ix,iy);
980
981       // get the pad position and dimensions
982       Float_t xlocal1 = pad.Position().X();
983       Float_t ylocal1 = pad.Position().Y();
984       Float_t xlocal2 = pad.Dimensions().X();
985       Float_t ylocal2 = pad.Dimensions().Y();
986       
987       kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
988       // (no transformation for pad dimensions)
989       xg2 = xlocal2;
990       yg2 = ylocal2;
991       
992       // transform in the monitor coordinate system
993       //xpmin = -(xg1+xg2);
994       //xpmax = -(xg1-xg2);
995       //ypmin = -(yg2-yg1);
996       //ypmax = +(yg2+yg1);
997       // ALICE SC
998       xpmin = +(xg1-xg2);
999       xpmax = +(xg1+xg2);
1000       ypmin = -(yg2-yg1);
1001       ypmax = +(yg2+yg1);
1002        
1003       xpmin -= fXCenter[i];
1004       xpmax -= fXCenter[i];
1005       ypmin -= fYCenter[i];
1006       ypmax -= fYCenter[i];
1007
1008       xdw = xpmax-xpmin;
1009       ydw = ypmax-ypmin;
1010
1011       // x-strips
1012       if ((xdw > ydw) && bx) {
1013
1014         //printf("X strips mdig->Cathode() = %1d \n",mdig->Cathode());
1015
1016         Int_t iX, iY1, iY2;
1017         iX  = fBoard->GetXSix();
1018         iY1 = fBoard->GetXSiy1();
1019         iY2 = fBoard->GetXSiy2();
1020         if (ix == iX && iy >= iY1 && iy <= iY2) {
1021           //printf("Digit indices (x-strip) ix = %3d iy = %3d board = %s %d chamber = %2d \n",ix,iy,fBoard->GetBoardName(),fBoard->GetNumber(),chamber); 
1022           /*
1023           xpmin += 0.01*fXWidth[i];
1024           xpmax -= 0.01*fXWidth[i];
1025           ypmin += 0.1*ydw;
1026           ypmax -= 0.1*ydw;
1027           */
1028           boxd = new TBox(xpmin,ypmin,xpmax,ypmax);
1029           boxd->SetFillStyle(1001);
1030           if (triggerBgn) boxd->SetFillColor(6);
1031           else boxd->SetFillColor(5);
1032           boxd->SetBit(kCannotPick);
1033           boxd->Draw();
1034           
1035           fXDigBox[i][iy-iY1]->SetFillStyle(1001);
1036           fXDigBox[i][iy-iY1]->SetFillColor(2);
1037           fXDigBox[i][iy-iY1]->SetX1(xpmin);
1038           fXDigBox[i][iy-iY1]->SetY1(ypmin);
1039           fXDigBox[i][iy-iY1]->SetX2(xpmax);
1040           fXDigBox[i][iy-iY1]->SetY2(ypmax);
1041           fXDigBox[i][iy-iY1]->Draw();
1042
1043           sprintf(cln,"%2d",(iy-iY1));
1044           fXLabelL[i][iy-iY1]->Clear();
1045           fXLabelL[i][iy-iY1]->AddText(cln);
1046           fXLabelL[i][iy-iY1]->Draw();
1047           fXLabelR[i][iy-iY1]->Clear();
1048           fXLabelR[i][iy-iY1]->AddText(cln);
1049           fXLabelR[i][iy-iY1]->Draw();
1050
1051           fBoard->SetDigitX(i,iy-iY1,charge);
1052
1053         }
1054
1055       }
1056
1057       // y-strips
1058       if ((xdw < ydw) && by) {
1059
1060         //printf("Y strips mdig->Cathode() = %1d \n",mdig->Cathode());
1061
1062         Int_t iX1, iX2, iY;
1063         iX1 = fBoard->GetYSix1();
1064         iX2 = fBoard->GetYSix2();
1065         iY  = fBoard->GetYSiy();
1066         if (ix >= iX1 && ix <= iX2 && iy == iY) {
1067           //printf("Digit indices (y-strip) ix = %3d iy = %3d board = %s chamber = %2d \n",ix,iy,fBoard->GetBoardName(),chamber); 
1068           ypmin = -0.5*fYWidth[i];
1069           ypmax = +0.5*fYWidth[i];
1070           /*
1071           ypmin = -0.5*fYWidth[i];
1072           ypmax = +0.5*fYWidth[i];
1073           ypmin += 0.01*fYWidth[i];
1074           ypmax -= 0.01*fYWidth[i];       
1075           xpmin += 0.1*xdw;
1076           xpmax -= 0.1*xdw;
1077           */
1078           boxd = new TBox(xpmin,ypmin,xpmax,ypmax);
1079           boxd->SetFillStyle(1001);
1080           if (triggerBgn) boxd->SetFillColor(6);
1081           else boxd->SetFillColor(5);
1082           boxd->SetBit(kCannotPick);
1083           boxd->Draw();
1084
1085           fYDigBox[i][ix-iX1]->SetFillStyle(1001);
1086           fYDigBox[i][ix-iX1]->SetFillColor(2);
1087           fYDigBox[i][ix-iX1]->SetX1(xpmin);
1088           fYDigBox[i][ix-iX1]->SetY1(ypmin);
1089           fYDigBox[i][ix-iX1]->SetX2(xpmax);
1090           fYDigBox[i][ix-iX1]->SetY2(ypmax);
1091           fYDigBox[i][ix-iX1]->Draw();
1092
1093           sprintf(cln,"%2d",(ix-iX1));
1094           fYLabelL[i][ix-iX1]->Clear();
1095           fYLabelL[i][ix-iX1]->AddText(cln);
1096           fYLabelL[i][ix-iX1]->Draw();
1097           fYLabelR[i][ix-iX1]->Clear();
1098           fYLabelR[i][ix-iX1]->AddText(cln);
1099           fYLabelR[i][ix-iX1]->Draw();
1100
1101           fBoard->SetDigitY(i,ix-iX1,charge);
1102
1103           // extended y-strips
1104           for (Int_t io = 1; io <= over; io++) {
1105             if (io == pos) continue;
1106             board = (AliMUONTriggerGUIboard*)fBoards->UncheckedAt(number+io-pos);
1107             board->SetDigitY(i,ix-iX1,charge);
1108           }
1109
1110         }
1111       }
1112       
1113     }  // end digits loop
1114     
1115     // x-strips DSET
1116     if (bx) {
1117       
1118       for (Int_t ix = 0; ix < fNStripX; ix++) {
1119         //if (fBoard->GetXDig(i,ix) > 0) {
1120         if (fXDigBox[i][ix]->GetFillStyle() == 1001 || 
1121             fBoard->GetXDig(i,ix) > 0) {
1122           
1123           px = fXDigPL[i][ix]->GetX();
1124           py = fXDigPL[i][ix]->GetY();
1125           
1126           xMin = +9999.;
1127           xMax = -9999.;
1128           yMin = +9999.;
1129           yMax = -9999.;
1130           for (Int_t ip = 0; ip < np; ip++) {
1131             xMin = TMath::Min(xMin,px[ip]);
1132             xMax = TMath::Max(xMax,px[ip]);
1133             yMin = TMath::Min(yMin,py[ip]);
1134             yMax = TMath::Max(yMax,py[ip]);
1135           }
1136           
1137           if (fXDigBox[i][ix]->GetFillStyle() == 0) {
1138             fXDigBox[i][ix]->SetFillStyle(1001);
1139             fXDigBox[i][ix]->SetFillColor(2);
1140             fXDigBox[i][ix]->SetX1(xMin);
1141             fXDigBox[i][ix]->SetY1(yMin);
1142             fXDigBox[i][ix]->SetX2(xMax);
1143             fXDigBox[i][ix]->SetY2(yMax);
1144           }
1145           
1146           sprintf(cln,"%2d",ix);
1147           
1148           fXLabelL[i][ix]->Clear();
1149           fXLabelL[i][ix]->AddText(cln);
1150           fXLabelL[i][ix]->Draw();
1151           
1152           fXLabelR[i][ix]->Clear();
1153           fXLabelR[i][ix]->AddText(cln);
1154           fXLabelR[i][ix]->Draw();
1155           
1156           fXDigBox[i][ix]->Draw();
1157           
1158         }
1159         
1160       }
1161
1162     }
1163       
1164     // y-strips DSET
1165     if (by) {
1166       
1167       for (Int_t iy = 0; iy < fNStripY; iy++) {
1168         //if (fBoard->GetYDig(i,iy) > 0) {
1169         if (fYDigBox[i][iy]->GetFillStyle() == 1001 || 
1170             fBoard->GetYDig(i,iy) > 0) {
1171           
1172           px = fYDigPL[i][iy]->GetX();
1173           py = fYDigPL[i][iy]->GetY();
1174           
1175           xMin = +9999.;
1176           xMax = -9999.;
1177           yMin = +9999.;
1178           yMax = -9999.;
1179           for (Int_t ip = 0; ip < np; ip++) {
1180             xMin = TMath::Min(xMin,px[ip]);
1181             xMax = TMath::Max(xMax,px[ip]);
1182             yMin = TMath::Min(yMin,py[ip]);
1183             yMax = TMath::Max(yMax,py[ip]);
1184           }
1185           
1186           if (fYDigBox[i][iy]->GetFillStyle() == 0) {
1187             fYDigBox[i][iy]->SetFillStyle(1001);
1188             fYDigBox[i][iy]->SetFillColor(2);
1189             fYDigBox[i][iy]->SetX1(xMin);
1190             fYDigBox[i][iy]->SetY1(yMin);
1191             fYDigBox[i][iy]->SetX2(xMax);
1192             fYDigBox[i][iy]->SetY2(yMax);
1193           }
1194           
1195           sprintf(cln,"%2d",iy);
1196           
1197           fYLabelL[i][iy]->Clear();
1198           fYLabelL[i][iy]->AddText(cln);
1199           fYLabelL[i][iy]->Draw();
1200           
1201           fYLabelR[i][iy]->Clear();
1202           fYLabelR[i][iy]->AddText(cln);
1203           fYLabelR[i][iy]->Draw();
1204           
1205           
1206           fYDigBox[i][iy]->Draw();
1207           
1208         }
1209         
1210       }
1211
1212     }
1213       
1214     fCanvas[i]->Modified();
1215     fCanvas[i]->Update();
1216       
1217   }  // end canvas loop
1218
1219   fMain->MapWindow();
1220
1221 }
1222
1223 //__________________________________________________________________________
1224 void AliMUONTriggerGUIbdmap::DrawStrips(Bool_t bx, Bool_t by)
1225 {
1226   /// draw the "x" or/and "y" strips
1227
1228   AliRunLoader *runLoader = fLoader->GetRunLoader();
1229   gAlice = runLoader->GetAliRun();
1230   AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
1231   const AliMUONGeometryTransformer* kGeomTransformer = pMUON->GetGeometryTransformer();
1232
1233   const AliMpVSegmentation* seg;
1234   AliMpPad pad;
1235   AliMpDEIterator it;
1236   Int_t chamber;
1237   Float_t xg1, xg2, yg1, yg2, zg1;
1238   Float_t xlocal1, xlocal2, ylocal1, ylocal2;
1239   Int_t detElemId, ic, maxX, maxY;
1240   Float_t xdw, ydw, xpmin, xpmax, ypmin, ypmax;
1241   Float_t ptx1, ptx2, pty1, pty2;
1242   Char_t cln[2];
1243   Double_t xc1, xc2, yc1, yc2;
1244   Float_t xcw, ycw;
1245
1246   Bool_t makeLabelsX = kFALSE;
1247   Bool_t makeLabelsY = kFALSE;
1248
1249   if (bx && !fLabelX) {
1250     makeLabelsX = kTRUE;
1251     fLabelX = kTRUE;
1252   }
1253
1254   if (by && !fLabelY) {
1255     makeLabelsY = kTRUE;
1256     fLabelY = kTRUE;
1257   }
1258
1259   for (Int_t i = 0; i < kNMT; i++) {
1260
1261     fCanvas[i]->cd();
1262     
1263     fCanvas[i]->GetRange(xc1,yc1,xc2,yc2);
1264     xcw = (Float_t)(0.5*(xc2-xc1));
1265     ycw = (Float_t)(0.5*(yc2-yc1));
1266
1267     chamber = 11+i;
1268
1269     for ( it.First(chamber-1); ! it.IsDone(); it.Next() ) {
1270     
1271       detElemId = it.CurrentDEId();
1272     
1273       if (detElemId%100 != fBoard->GetDetElemId()) continue;
1274
1275       /*---------- y-pads ic = 2 ----------*/
1276       ic = 2;
1277       
1278       seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(ic-1));  
1279
1280       maxX = seg->MaxPadIndexX();
1281       maxY = seg->MaxPadIndexY();
1282       
1283       for (Int_t ix = 0; ix <= maxX; ix++) {
1284         for (Int_t iy = 0; iy <= maxY; iy++) {
1285           
1286           pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
1287           
1288           if (!pad.IsValid()) continue;
1289           
1290           // get the pad position and dimensions
1291           xlocal1 = pad.Position().X();
1292           ylocal1 = pad.Position().Y();
1293           xlocal2 = pad.Dimensions().X();
1294           ylocal2 = pad.Dimensions().Y();
1295           
1296           kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
1297           // (no transformation for pad dimensions)
1298           xg2 = xlocal2;
1299           yg2 = ylocal2;
1300           
1301           // transform in the monitor coordinate system
1302           //xpmin = -(xg1+xg2);
1303           //xpmax = -(xg1-xg2);
1304           //ypmin = -(yg2-yg1);
1305           //ypmax = +(yg2+yg1);
1306           // ALICE SC
1307           xpmin = +(xg1-xg2);
1308           xpmax = +(xg1+xg2);
1309           ypmin = -(yg2-yg1);
1310           ypmax = +(yg2+yg1);
1311           
1312           xpmin -= fXCenter[i];
1313           xpmax -= fXCenter[i];
1314           ypmin -= fYCenter[i];
1315           ypmax -= fYCenter[i];
1316           
1317           xdw = xpmax-xpmin;
1318           ydw = ypmax-ypmin;
1319           
1320           // y-strips
1321           if (by) {
1322             
1323             Int_t iX1, iX2, iY, ixDig;
1324             iX1 = fBoard->GetYSix1();
1325             iX2 = fBoard->GetYSix2();
1326             iY  = fBoard->GetYSiy();
1327             if (ix >= iX1 && ix <= iX2 && iy == iY) {
1328               
1329               ypmin = -0.5*fYWidth[i];
1330               ypmax = +0.5*fYWidth[i];
1331               /*
1332               ypmin += 0.01*fYWidth[i];
1333               ypmax -= 0.01*fYWidth[i];
1334               xpmin += 0.1*xdw;
1335               xpmax -= 0.1*xdw;
1336               */
1337               ixDig = ix - iX1;
1338               fYDigPL[i][ixDig]->SetPoint(0,xpmin,ypmin);
1339               fYDigPL[i][ixDig]->SetPoint(1,xpmax,ypmin);
1340               fYDigPL[i][ixDig]->SetPoint(2,xpmax,ypmax);
1341               fYDigPL[i][ixDig]->SetPoint(3,xpmin,ypmax);
1342               fYDigPL[i][ixDig]->SetPoint(4,xpmin,ypmin);
1343               fYDigPL[i][ixDig]->Draw();
1344               /*
1345               fYDigBox[i][ixDig]->SetFillStyle(1001);
1346               fYDigBox[i][ixDig]->SetFillColor(5);
1347               fYDigBox[i][ixDig]->DrawBox(xpmin,ypmin,xpmax,ypmax);
1348               */
1349               if (makeLabelsY) {
1350                 sprintf(cln,"%2d",(ix-iX1));
1351                 ptx1 = xpmin;
1352                 ptx2 = xpmax;
1353                 
1354                 pty1 = 1.065*ypmin - 0.04*ycw;
1355                 pty2 = 1.065*ypmin + 0.04*ycw;
1356                 fYLabelL[i][ix-iX1] = new TPaveText(ptx1,pty1,ptx2,pty2);
1357                 fYLabelL[i][ix-iX1]->SetBorderSize(0);
1358                 fYLabelL[i][ix-iX1]->SetBit(kCannotPick);
1359                 
1360                 pty1 = 1.065*ypmax - 0.04*ycw;
1361                 pty2 = 1.065*ypmax + 0.04*ycw;
1362                 fYLabelR[i][ix-iX1] = new TPaveText(ptx1,pty1,ptx2,pty2);
1363                 fYLabelR[i][ix-iX1]->SetBorderSize(0);
1364                 fYLabelR[i][ix-iX1]->SetBit(kCannotPick);
1365               }
1366
1367             }
1368             
1369           }
1370           
1371         }  // end maxY
1372         
1373       }  // end maxX
1374       
1375       /*---------- x-pads ic = 1 ----------*/
1376       ic = 1;
1377       
1378       seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(ic-1)); 
1379
1380       maxX = seg->MaxPadIndexX();
1381       maxY = seg->MaxPadIndexY();
1382       
1383       for (Int_t ix = 0; ix <= maxX; ix++) {
1384         for (Int_t iy = 0; iy <= maxY; iy++) {
1385           
1386           pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
1387           
1388           if (!pad.IsValid()) continue;
1389           
1390           // get the pad position and dimensions
1391           xlocal1 = pad.Position().X();
1392           ylocal1 = pad.Position().Y();
1393           xlocal2 = pad.Dimensions().X();
1394           ylocal2 = pad.Dimensions().Y();
1395           
1396           kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
1397           // (no transformation for pad dimensions)
1398           xg2 = xlocal2;
1399           yg2 = ylocal2;
1400           
1401           // transform in the monitor coordinate system
1402           //xpmin = -(xg1+xg2);
1403           //xpmax = -(xg1-xg2);
1404           //ypmin = -(yg2-yg1);
1405           //ypmax = +(yg2+yg1);
1406           // ALICE SC
1407           xpmin = +(xg1-xg2);
1408           xpmax = +(xg1+xg2);
1409           ypmin = -(yg2-yg1);
1410           ypmax = +(yg2+yg1);
1411           
1412           xpmin -= fXCenter[i];
1413           xpmax -= fXCenter[i];
1414           ypmin -= fYCenter[i];
1415           ypmax -= fYCenter[i];
1416           xdw = xpmax-xpmin;
1417           ydw = ypmax-ypmin;
1418           
1419           // x-strips
1420           if (bx) {
1421             
1422             Int_t iX, iY1, iY2, iyDig;
1423             iX  = fBoard->GetXSix();
1424             iY1 = fBoard->GetXSiy1();
1425             iY2 = fBoard->GetXSiy2();
1426             if (ix == iX && iy >= iY1 && iy <= iY2) {
1427               /*                  
1428               xpmin += 0.01*fXWidth[i];
1429               xpmax -= 0.01*fXWidth[i];
1430               ypmin += 0.1*ydw;
1431               ypmax -= 0.1*ydw;
1432               */
1433               iyDig = iy - iY1;
1434               fXDigPL[i][iyDig]->SetPoint(0,xpmin,ypmin);
1435               fXDigPL[i][iyDig]->SetPoint(1,xpmax,ypmin);
1436               fXDigPL[i][iyDig]->SetPoint(2,xpmax,ypmax);
1437               fXDigPL[i][iyDig]->SetPoint(3,xpmin,ypmax);
1438               fXDigPL[i][iyDig]->SetPoint(4,xpmin,ypmin);
1439               fXDigPL[i][iyDig]->Draw();
1440               /*              
1441               fXDigBox[i][iyDig]->SetFillStyle(1001);
1442               fXDigBox[i][iyDig]->SetFillColor(5);
1443               fXDigBox[i][iyDig]->DrawBox(xpmin,ypmin,xpmax,ypmax);
1444               */
1445               if (makeLabelsX) {
1446                 sprintf(cln,"%2d",(iy-iY1));
1447                 pty1 = ypmin;
1448                 pty2 = ypmax;
1449                 
1450                 ptx1 = 1.065*xpmin - 0.04*xcw;
1451                 ptx2 = 1.065*xpmin + 0.04*xcw;
1452                 fXLabelL[i][iy-iY1] = new TPaveText(ptx1,pty1,ptx2,pty2);
1453                 fXLabelL[i][iy-iY1]->SetBorderSize(0);
1454                 fXLabelL[i][iy-iY1]->SetBit(kCannotPick);
1455                 
1456                 ptx1 = 1.065*xpmax - 0.04*xcw;
1457                 ptx2 = 1.065*xpmax + 0.04*xcw;
1458                 fXLabelR[i][iy-iY1] = new TPaveText(ptx1,pty1,ptx2,pty2);
1459                 fXLabelR[i][iy-iY1]->SetBorderSize(0);
1460                 fXLabelR[i][iy-iY1]->SetBit(kCannotPick);
1461               }
1462
1463             }
1464             
1465           }
1466           
1467         }  // end maxY
1468         
1469       }  // end maxX
1470       
1471     }  // end DEIterator
1472     
1473     fCanvas[i]->Modified();
1474     fCanvas[i]->Update();
1475
1476   }
1477
1478   fMain->MapWindow();
1479
1480 }
1481
1482 //__________________________________________________________________________
1483 void AliMUONTriggerGUIbdmap::CloseWindow()
1484 {
1485   /// close dialog in response to window manager close.
1486
1487   delete this;
1488
1489 }
1490
1491 //__________________________________________________________________________
1492 void AliMUONTriggerGUIbdmap::DoClose()
1493 {
1494   /// handle Close button.
1495
1496   fBoard->SetOpen(kFALSE);
1497   TTimer::SingleShot(150,"AliMUONTriggerGUIbdmap",this,"CloseWindow()");
1498
1499 }
1500
1501