]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerGUI.cxx
mixing example
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerGUI.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 AliMUONTriggerGUI
20 /// Graphical User Interface utility class for the MUON trigger detector
21 /// It creates, after initialisation with a data file, a sensitive map
22 /// of the trigger boards
23 /// \author Bogdan Vulpescu, LPC Clermont-Ferrand
24 //-----------------------------------------------------------------------------
25
26 #include "AliMUONTriggerGUI.h"
27 #include "AliMUONTriggerGUIboard.h"
28 #include "AliMUONTriggerGUIdimap.h"
29 #include "AliMUONTriggerGUIbdmap.h"
30
31 #include "AliMpSegmentation.h"
32 #include "AliMpVSegmentation.h"
33 #include "AliMpPad.h"
34 #include "AliMpIntPair.h"
35 #include "AliMpCDB.h"
36 #include "AliMUON.h"
37 #include "AliMpDEIterator.h"
38 #include "AliMUONGeometryTransformer.h"
39 #include "AliMUONTriggerCrateStore.h"
40 #include "AliMUONLocalTriggerBoard.h"
41 #include "AliMUONTriggerElectronics.h"
42 #include "AliMUONCalibrationData.h"
43 #include "AliMUONMCDataInterface.h"
44
45 #include "AliRun.h"
46 #include "AliRunLoader.h"
47 #include "AliCDBManager.h"
48
49 #include <TSystem.h>
50 #include <TGLabel.h>
51 #include <TGFrame.h>
52 #include <TApplication.h>
53 #include <TGDimension.h>
54 #include <TString.h>
55 #include <TGMenu.h>
56 #include <TGTextEntry.h>
57 #include <TGButton.h>
58 #include <TFile.h>
59 #include <TGImageMap.h>
60 #include <TGTextBuffer.h>
61
62 /// \cond CLASSIMP
63 ClassImp(AliMUONTriggerGUI)
64 /// \endcond
65
66 //__________________________________________________________________________
67 AliMUONTriggerGUI::AliMUONTriggerGUI(Int_t runNumber)
68   : TObject(),
69     fMain(0),
70     fImageMap(0),
71     fTxtBuffer1(0),
72     fTxtBuffer2(0),
73     fTxtCircuit(0),
74     fRunInput(0),
75     fError(0),
76     fControl(0),
77     fCircuit(0),
78     fSkipToEventTxt(0),
79     fFileName(0),
80     fPath(0),
81     fEvString(0),
82     fChamber(0),
83     fEvent(0),
84     fEventsPerRun(0),
85     fLoader(0),
86     fRunLoader(0),
87     fCDBManager(0),
88     fCalibrationData(0),
89     fCrateManager(0),
90     fMCDataInterface(0),
91     fBoardsInit(0),
92     fDiMap(0),
93     fTriggerProcessor(0),
94     fBoards(0)
95 {
96   /// main GUI frame of the trigger monitor
97
98   fChamber = 0;
99   fEvent   = 0;
100   fEventsPerRun = 0;
101   fRunLoader = 0;
102   fDiMap = 0;
103
104   fBoards = 0;
105   fFileName = new TString("");
106   fEvString = new TString("");
107   fPath = new TString("");
108
109   fTriggerProcessor = 0;
110
111   fCDBManager = AliCDBManager::Instance();
112   fCDBManager->SetDefaultStorage("local://$ALICE_ROOT");
113   fCDBManager->SetRun(runNumber);
114   AliMpCDB::LoadDDLStore();
115   fCalibrationData = new AliMUONCalibrationData(runNumber);
116   
117   // Main frame
118
119   fMain = new TGMainFrame(gClient->GetRoot(), 750, 420);
120   fMain->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseWindow()");
121
122   // Menu bar
123   
124   TGMenuBar *menuBar = new TGMenuBar(fMain);
125   
126   // File menu
127
128   TGPopupMenu *menuFile = new TGPopupMenu(gClient->GetRoot());
129   //menuFile->AddLabel("");
130
131   menuFile->AddEntry("Run",     kMFILERUN);
132   menuFile->AddEntry("Control", kMFILECNTRL);
133   menuFile->AddEntry("Exit",    kMFILEEXIT);
134
135   menuFile->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this, "HandleMenu(Int_t)");
136
137   // Circuit menu
138
139   TGPopupMenu *menuCircuit = new TGPopupMenu(gClient->GetRoot());
140   //menuCircuit->AddLabel("");
141
142   menuCircuit->AddEntry("Open",     kMCIRCUITOPEN);
143
144   menuCircuit->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this, "HandleMenu(Int_t)");
145
146   // Digits map menu
147
148   TGPopupMenu *menuMap = new TGPopupMenu(gClient->GetRoot());
149   //menuMap->AddLabel("");
150
151   menuMap->AddEntry("Digits map",   kMMAPDIGITS);
152   menuMap->AddEntry("Reset digits", kMRESETDIGITS);
153
154   menuMap->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this,
155                     "HandleMenu(Int_t)");
156
157   // Trigger menu
158
159   TGPopupMenu *menuTrigger = new TGPopupMenu(gClient->GetRoot());
160   //menuTrigger->AddLabel("");
161
162   menuTrigger->AddEntry("Trigger DSET",     kMTRIGGERDSET);
163
164   menuTrigger->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this, "HandleMenu(Int_t)");
165
166   // Add menus to the menu bar
167
168   menuBar->AddPopup("File", menuFile, 
169                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
170                     );
171
172   menuBar->AddPopup("Maps", menuMap, 
173                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
174                     );
175
176   menuBar->AddPopup("Circuit", menuCircuit, 
177                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
178                     );
179
180   menuBar->AddPopup("Trigger", menuTrigger, 
181                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
182                     );
183
184   // Add menu bar to the main frame
185
186   fMain->AddFrame(menuBar,
187                   new TGLayoutHints(kLHintsTop | 
188                                     kLHintsLeft | 
189                                     kLHintsExpandX, 
190                                     0, 0, 1, 1)
191                   );
192  
193   // The image map
194
195   fImageMap = new TGImageMap(fMain,"$ALICE_ROOT/MUON/data/guimap.gif");
196   
197   fImageMap->Connect("RegionClicked(Int_t)", "AliMUONTriggerGUI", this, "OpenBoard(Int_t)");
198
199   fImageMap->SetToolTipText("Map of the local boards as seen from the I.P.");
200
201   // Add image map to the main frame
202
203   fMain->AddFrame(fImageMap);
204   fMain->SetWindowName("Map of the local boards as seen from the I.P.");
205
206   // Resize the main frame
207   
208   TGDimension size = fMain->GetDefaultSize();
209   fMain->Resize(size);
210
211   fMain->MapSubwindows();
212
213   fMain->MapWindow();
214
215   fBoardsInit = kFALSE;
216
217   //HandleMenu(kMFILERUN);  // temporary
218
219   //InitBoards();
220   //Init();
221   
222 }
223
224 //__________________________________________________________________________
225 void AliMUONTriggerGUI::HandleMenu(Int_t id)
226 {
227   /// handles entry numbers in the available menus (EMenuIdentifiers)
228
229   TGCompositeFrame *runInput1, *runInput2, *runInput3;
230   TGCompositeFrame *control1, *control2, *circuit1, *circuit2;
231   TGLabel *runL1, *runL2, *circuitL1;
232   TGTextEntry *runText1, *runText2, *circuitText1;
233   TGTextButton *runApply, *runCancel; 
234   TGTextButton *controlClose, *nextEvent, *previousEvent, *skipToEvent;
235   TGTextButton *circuitCancel, *circuitOpen;
236
237   //Int_t trigInfo[kNBoards*6] = {-1};
238   //Int_t nLocalTrigger = 0;
239
240   TString error = TString("");
241   if (id != kMFILEEXIT && id != kMFILERUN && fRunLoader == 0) {
242     error.Append("Run not initialized (Menu: File/Run)");
243     DoErrorGUI(error.Data());
244     return;
245   }
246
247   switch (id) {
248
249   case kMFILEEXIT:
250
251     printf("\nBye. \n");
252     CloseWindow();
253     break;
254     
255   case kMFILERUN:
256     
257     // input main frame
258
259     fRunInput = new TGTransientFrame(gClient->GetRoot(), fMain, 400, 200);
260     fRunInput->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseRunInput()");
261     fRunInput->DontCallClose(); // to avoid double deletions.
262
263     // use hierarchical cleaning
264     fRunInput->SetCleanup(kDeepCleanup);
265
266     fRunInput->SetWindowName("Input file and event number");
267
268     // input galice and event number frames
269
270     runInput1 = new TGCompositeFrame(fRunInput, 400, 200, kHorizontalFrame);
271     runInput2 = new TGCompositeFrame(fRunInput, 400, 200, kHorizontalFrame);
272
273     // .. with labels
274
275     runL1 = new TGLabel(runInput1, new TGString("Path to gAlice:"));
276     runL2 = new TGLabel(runInput2, new TGString("Event number:"));
277
278     // galice text entry
279
280     runText1 = new TGTextEntry(runInput1, fTxtBuffer1 = new TGTextBuffer(100));
281
282     //fPath->Append("dset");                 // temporary
283     //fTxtBuffer1->AddText(0,fPath->Data());  // temporary
284
285     runText1->SetToolTipText("Enter the path to galice.root");
286     runText1->Resize(300, runText1->GetDefaultHeight());
287
288     // event number text entry
289
290     runText2 = new TGTextEntry(runInput2, fTxtBuffer2 = new TGTextBuffer(5));
291
292     fEvString->Form("%d",0);               
293     fTxtBuffer2->AddText(0,fEvString->Data());
294
295     runText2->SetToolTipText("Enter the first event number to start with");
296     runText2->Resize(300, runText2->GetDefaultHeight());
297
298     // add to galice frame
299
300     runInput1->AddFrame(runL1,
301                          new TGLayoutHints(kLHintsLeft | 
302                                            kLHintsCenterY, 
303                                            3, 5, 0, 0)
304                         );
305
306     runInput1->AddFrame(runText1, 
307                         new TGLayoutHints(kLHintsRight | 
308                                           kLHintsCenterY, 
309                                           0, 2, 0, 0)
310                         );
311
312     // add to event number frame
313
314     runInput2->AddFrame(runL2,
315                          new TGLayoutHints(kLHintsLeft | 
316                                            kLHintsCenterY, 
317                                            3, 5, 0, 0)
318                         );
319
320     runInput2->AddFrame(runText2, 
321                         new TGLayoutHints(kLHintsRight | 
322                                           kLHintsCenterY, 
323                                           0, 2, 0, 0)
324                         );
325
326     // add input frames to main input frame
327
328     fRunInput->AddFrame(runInput1, 
329                         new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
330     
331     fRunInput->AddFrame(runInput2, 
332                         new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
333     
334     // frame with buttons
335
336     runInput3 = new TGCompositeFrame(fRunInput, 400, 200, kHorizontalFrame);
337
338     // buttons
339
340     runApply = new TGTextButton(runInput3, "Apply", 1);
341     runApply->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoRunApply()");
342     runApply->SetToolTipText("Apply changes");
343
344     runCancel = new TGTextButton(runInput3, "Cancel", 2);
345     runCancel->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoRunCancel()");    runCancel->SetToolTipText("Cancel changes");
346
347     // add buttons
348
349     runInput3->AddFrame(runApply, 
350                          new TGLayoutHints(kLHintsTop | 
351                                            kLHintsLeft, 
352                                            3, 3, 2, 2)
353                         );
354     
355     runInput3->AddFrame(runCancel, 
356                          new TGLayoutHints(kLHintsTop | 
357                                            kLHintsLeft, 
358                                            3, 3, 2, 2)
359                         );
360     
361     // add to the main input frame
362
363     fRunInput->AddFrame(runInput3, 
364                         new TGLayoutHints(kLHintsTop | 
365                                           kLHintsExpandX, 
366                                           2, 2, 3, 0)
367                         );
368     
369     fRunInput->MapSubwindows();
370     fRunInput->Resize();
371     fRunInput->MapWindow();
372
373     //DoRunApply();   // temporary
374
375     break;
376     
377   case kMFILECNTRL:
378
379     // control main frame
380
381     fControl = new TGTransientFrame(gClient->GetRoot(), fMain, 50, 50);
382     fControl->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseControl()");
383     fControl->DontCallClose(); // to avoid double deletions.
384   
385     // use hierarchical cleaning
386     fControl->SetCleanup(kDeepCleanup);
387   
388     fControl->SetWindowName("Run controls");
389
390     // frame to hold buttons
391
392     control1 = new TGCompositeFrame(fControl, 50, 50, kVerticalFrame);
393   
394     // buttons
395
396     controlClose = new TGTextButton(control1, "Close", 1);
397     controlClose->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoControlClose()");
398     //controlClose->Resize(300, controlClose->GetDefaultHeight());  
399
400     nextEvent = new TGTextButton(control1, "Next event", 2);
401     nextEvent->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoNextEvent()");
402
403     previousEvent = new TGTextButton(control1, "Previous event", 3);
404     previousEvent->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoPreviousEvent()");
405   
406     // frame to hold event skip
407
408     control2 = new TGCompositeFrame(fControl, 50, 50, kHorizontalFrame);
409   
410     // skip to event text field
411
412     fSkipToEventTxt = new TGTextEntry(control2, fTxtBuffer2 = new TGTextBuffer(5));
413
414     fTxtBuffer2->AddText(0,fEvString->Data());
415
416     // skip to event button
417
418     skipToEvent = new TGTextButton(control2, "Skip to event", 1);
419     skipToEvent->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoSkipToEvent()");
420
421     // add to event skip frame
422
423     control2->AddFrame(fSkipToEventTxt, 
424                        new TGLayoutHints(kLHintsTop | 
425                                          kLHintsRight, 
426                                          10, 10, 5, 5)
427                        );
428   
429     control2->AddFrame(skipToEvent, 
430                        new TGLayoutHints(kLHintsTop | 
431                                          kLHintsRight, 
432                                          10, 10, 5, 5)
433                        );
434   
435     // add buttons
436   
437     control1->AddFrame(controlClose, 
438                  new TGLayoutHints(kLHintsBottom | 
439                                    kLHintsExpandX, 
440                                    10, 10, 5, 5)
441                  );
442   
443     control1->AddFrame(nextEvent, 
444                  new TGLayoutHints(kLHintsBottom | 
445                                    kLHintsExpandX, 
446                                    10, 10, 5, 5)
447                  );
448   
449     control1->AddFrame(previousEvent, 
450                  new TGLayoutHints(kLHintsBottom | 
451                                    kLHintsExpandX, 
452                                    10, 10, 5, 5)
453                  );
454   
455     // add to the main frame
456
457     fControl->AddFrame(control1,
458                        new TGLayoutHints(kLHintsBottom |
459                                          kLHintsLeft | 
460                                          kLHintsCenterY, 
461                                          3, 5, 0, 0)
462                        );
463     
464     fControl->AddFrame(control2,
465                        new TGLayoutHints(kLHintsTop | 
466                                          kLHintsCenterX, 
467                                          3, 5, 0, 0)
468                        );
469     
470     fControl->MapSubwindows();
471     fControl->Resize();
472     fControl->MapWindow();
473    
474     break;
475
476   case kMMAPDIGITS:
477     
478     if (fDiMap == 0) {
479       fDiMap = new AliMUONTriggerGUIdimap(fBoards,gClient->GetRoot(), fMain, 400, 200);
480       fDiMap->SetLoader(fLoader);
481       fDiMap->SetMCDataInterface(fMCDataInterface);
482       fDiMap->DrawAllMaps();
483     } else if (!fDiMap->IsOn()) {
484       fDiMap = new AliMUONTriggerGUIdimap(fBoards,gClient->GetRoot(), fMain, 400, 200);
485       fDiMap->SetLoader(fLoader);
486       fDiMap->SetMCDataInterface(fMCDataInterface);
487       fDiMap->DrawAllMaps();
488     }
489
490     break;
491     
492   case kMRESETDIGITS:
493     
494     Int_t number, over, pos;
495     for (Int_t ib = 0; ib < kNBoards; ib++) {
496       AliMUONTriggerGUIboard *board = GetBoard(ib);
497       board->ClearXDigits();
498       board->ClearYDigits();
499       // extended y-strips
500       number = board->GetNumber();
501       pos    = board->GetPosition();
502       over   = board->GetYOver();
503       for (Int_t io = 1; io <= over; io++) {
504         if (io == pos) continue;
505         board = GetBoard(number+io-pos);
506         board->ClearYDigits();
507       }
508     }
509
510     break;
511     
512   case kMCIRCUITOPEN:
513
514     fCircuit = new TGTransientFrame(gClient->GetRoot(), fMain, 50, 50);
515     fCircuit->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseCircuit()");
516     fCircuit->DontCallClose(); // to avoid double deletions.
517   
518     // use hierarchical cleaning
519     fCircuit->SetCleanup(kDeepCleanup);
520   
521     fCircuit->SetWindowName("Board circuit");
522
523     // sub-frames
524
525     circuit1 = new TGCompositeFrame(fCircuit, 400, 200, kHorizontalFrame);
526     circuit2 = new TGCompositeFrame(fCircuit, 400, 200, kHorizontalFrame);
527
528     // labels
529
530     circuitL1 = new TGLabel(circuit1, new TGString("Circuit number:"));
531     
532     // text entry
533     
534     circuitText1 = new TGTextEntry(circuit1, fTxtCircuit = new TGTextBuffer(10));
535     // buttons
536
537     circuitCancel = new TGTextButton(circuit2, "Cancel", 1);
538     circuitCancel->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoCircuitCancel()");
539     //circuitCancel->Resize(100, circuitCancel->GetDefaultHeight());  
540
541     circuitOpen = new TGTextButton(circuit2, "Open", 2);
542     circuitOpen->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoCircuitOpen()");
543     //circuitOpen->Resize(100, circuitOpen->GetDefaultHeight());  
544
545     // adding
546
547     circuit1->AddFrame(circuitL1,
548                        new TGLayoutHints(kLHintsLeft | 
549                                          kLHintsCenterY, 
550                                          5, 5, 2, 2)
551                        );
552     
553     circuit1->AddFrame(circuitText1, 
554                        new TGLayoutHints(kLHintsRight | 
555                                          kLHintsCenterY, 
556                                          0, 2, 2, 2)
557                        );
558     
559     circuit2->AddFrame(circuitCancel, 
560                  new TGLayoutHints(kLHintsBottom | 
561                                    kLHintsCenterY, 
562                                    5, 5, 2, 2)
563                  );
564   
565     circuit2->AddFrame(circuitOpen, 
566                  new TGLayoutHints(kLHintsBottom | 
567                                    kLHintsCenterY, 
568                                    5, 5, 2, 2)
569                  );
570   
571     fCircuit->AddFrame(circuit1, 
572                        new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
573     
574     fCircuit->AddFrame(circuit2, 
575                        new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
576     
577     fCircuit->MapSubwindows();
578     fCircuit->Resize();
579     fCircuit->MapWindow();
580
581     break;
582
583   case kMTRIGGERDSET:
584     /*
585     cout << "Trigger with boards digits....." << endl;
586     fTriggerProcessor->FeedBoardsGUI(Boards());
587
588     nLocalTrigger = fTriggerProcessor->TriggerGUI(trigInfo,kTRUE);
589
590     cout << "Trigger done with " << nLocalTrigger << " local decisions !" << endl;
591
592     for (Int_t ilo = 0; ilo < nLocalTrigger; ilo++) {
593
594       cout << "Local decision " << ilo << endl;
595       cout << "Circuit = "  << trigInfo[6*ilo+0] << endl;
596       cout << "LoStripX = " << trigInfo[6*ilo+1] << endl;
597       cout << "LoStripY = " << trigInfo[6*ilo+2] << endl;
598       cout << "LoDev = "    << trigInfo[6*ilo+3] << endl;
599       cout << "LoLpt = "    << trigInfo[6*ilo+4] << endl;
600       cout << "LoHpt = "    << trigInfo[6*ilo+5] << endl;
601       cout                                       << endl;
602     }
603     */
604     break;
605
606   default:
607     printf("Menu item %d selected\n", id);
608     break;
609     
610   }
611
612 }
613
614 //__________________________________________________________________________
615 void AliMUONTriggerGUI::CloseRunInput() const
616 {
617   /// close the run input frame
618
619   delete fRunInput;
620
621 }
622
623 //__________________________________________________________________________
624 void AliMUONTriggerGUI::CloseError() const
625 {
626   /// close the error frame
627
628   delete fError;
629
630 }
631
632 //__________________________________________________________________________
633 void AliMUONTriggerGUI::CloseControl() const
634 {
635   /// close the event control frame
636
637   delete fControl;
638
639   //gSystem->Exec("cd $PWD/mtrun; aliroot -b -q mtsim.C");
640
641 }
642
643 //__________________________________________________________________________
644 void AliMUONTriggerGUI::CloseCircuit() const
645 {
646   /// close the circuit frame
647
648   delete fCircuit;
649
650 }
651
652 //__________________________________________________________________________
653 void AliMUONTriggerGUI::CloseWindow() 
654 {
655   /// close the main frame and exit aplication
656
657   delete fRunLoader;
658   delete fMCDataInterface;
659   printf("\n"); 
660   gApplication->Terminate(); 
661
662 }
663
664 //__________________________________________________________________________
665 void AliMUONTriggerGUI::DoRunApply()
666 {
667   /// apply changes in the run control frame
668
669   printf("Input 1 = %s \n",fTxtBuffer1->GetString());
670
671   TString es = TString(fTxtBuffer2->GetString());
672   fEvent = es.Atoi();
673
674   printf("Input 2 = %s event = %d \n",fTxtBuffer2->GetString(),fEvent);
675
676   TString error = TString("");;
677
678   fPath->Form("%s",fTxtBuffer1->GetString());
679   fFileName->Form("%s",fTxtBuffer1->GetString());
680   printf("File location: %s \n",fFileName->Data());
681
682   if (gSystem->AccessPathName(fFileName->Data()) || !fFileName->EndsWith(".root")) {
683
684     error.Append("No galice file: ");
685     error.Append(fFileName->Data());
686     DoErrorGUI(error.Data());
687
688   } else {
689
690     TFile *ftest = new TFile(fFileName->Data(),"READ");
691     AliRun *galice = (AliRun*)ftest->Get("gAlice");
692     if (galice == 0) {
693
694       ftest->Close();
695       delete ftest;
696       
697       error.Append("No gAlice in file: ");
698       error.Append(fFileName->Data());
699       DoErrorGUI(error.Data());
700
701       return;
702
703     } else {
704       ftest->Close();
705       delete ftest;
706     }
707
708     if (fRunLoader) {
709       delete fRunLoader;
710       delete fMCDataInterface;
711     }
712
713     fRunLoader = AliRunLoader::Open(fFileName->Data(),"MUONFolder","READ");
714
715     if (fRunLoader == 0x0) {
716
717       DoErrorGUI("No run loader !");
718
719     } else {
720       
721       fRunLoader->LoadgAlice();
722       gAlice = fRunLoader->GetAliRun();
723       fEventsPerRun = gAlice->GetEventsPerRun();
724       
725       fLoader = fRunLoader->GetLoader("MUONLoader");
726       fRunLoader->GetEvent(fEvent);
727            
728       fMCDataInterface = new AliMUONMCDataInterface(fFileName->Data());
729
730       fRunInput->SendCloseMessage();
731       
732       if (!fBoardsInit) {
733         InitBoards();
734       }
735       
736       if (fDiMap) {
737         if (fDiMap->IsOn()) {
738           fDiMap->SetLoader(fLoader);
739           fDiMap->SetMCDataInterface(fMCDataInterface);
740         }
741       }
742       
743       //fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
744     }
745
746   }
747
748 }
749
750 //__________________________________________________________________________
751 void AliMUONTriggerGUI::DoRunCancel()
752 {
753   /// cancel the changes in the run control frame
754
755   printf("Input 1 = %s \n",fTxtBuffer1->GetString());
756
757   TString es = TString(fTxtBuffer2->GetString());
758   fEvent = es.Atoi();
759
760   printf("Input 2 = %s event = %d \n",fTxtBuffer2->GetString(),fEvent);
761
762   fRunInput->SendCloseMessage();
763
764 }
765
766 //__________________________________________________________________________
767 void AliMUONTriggerGUI::DoErrorGUI(const Char_t *wt)
768 {
769   /// show an error message in a new frame
770
771   fError = new TGTransientFrame(gClient->GetRoot(), fMain, 50, 50);
772   fError->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseError()");
773   fError->DontCallClose(); // to avoid double deletions.
774   
775   // use hierarchical cleaning
776   fError->SetCleanup(kDeepCleanup);
777   
778   fError->SetWindowName("Error !");
779
780   TGCompositeFrame *fW = new TGCompositeFrame(fError, 50, 50, kVerticalFrame);
781   
782   TGTextButton *fErrorOK = new TGTextButton(fW, "&Ok", 1);
783   fErrorOK->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoErrorOK()");
784   
785   fW->AddFrame(fErrorOK, 
786                new TGLayoutHints(kLHintsBottom | 
787                                  kLHintsCenterX, 
788                                  5, 5, 5, 5)
789                );
790   
791   TGLabel *fWL = new TGLabel(fW, new TGString(wt));
792   
793   fW->AddFrame(fWL,
794                new TGLayoutHints(kLHintsTop | 
795                                  kLHintsCenterX, 
796                                  5, 5, 5, 5)
797                );
798   
799   fError->AddFrame(fW,
800                    new TGLayoutHints(kLHintsLeft | 
801                                      kLHintsCenterY, 
802                                      5, 5, 5, 5)
803                    );
804   
805   fError->MapSubwindows();
806   fError->Resize();
807   fError->MapWindow();
808    
809 }
810
811 //__________________________________________________________________________
812 void AliMUONTriggerGUI::DoNextEvent()
813 {
814   /// load next event from the file
815
816   TString error = TString("");
817
818   if (fEvent < (fEventsPerRun-1)) {
819     fEvent++;
820     fRunLoader->GetEvent(fEvent);
821
822     fEvString->Form("%d",fEvent);               
823     fTxtBuffer2->RemoveText(0,5);
824     fTxtBuffer2->AddText(0,fEvString->Data());
825     fSkipToEventTxt->SetFocus();
826
827   } else {
828     error.Form("Only %d event(s) in the run !",fEventsPerRun);
829     DoErrorGUI(error.Data());
830   }
831
832 }
833
834 //__________________________________________________________________________
835 void AliMUONTriggerGUI::DoPreviousEvent()
836 {
837   /// load previous event from the input file
838
839   TString error = TString("");
840
841   if (fEvent > 0) {
842     fEvent--;
843     fRunLoader->GetEvent(fEvent);
844
845     fEvString->Form("%d",fEvent);               
846     fTxtBuffer2->RemoveText(0,5);
847     fTxtBuffer2->AddText(0,fEvString->Data());
848     fSkipToEventTxt->SetFocus();
849
850   } else {
851     error.Form("Already at event 0 !");
852     DoErrorGUI(error.Data());
853   }
854
855 }
856
857 //__________________________________________________________________________
858 void AliMUONTriggerGUI::DoSkipToEvent()
859 {
860   /// skip to event -input- from the input file
861
862   TString error = TString("");
863
864   TString es = TString(fTxtBuffer2->GetString());
865   fEvent = es.Atoi();
866
867   if (fEvent < 0 || fEvent > (fEventsPerRun-1)) {
868     error.Form("Event number out of range !");
869     DoErrorGUI(error.Data());
870   } else {
871     fRunLoader->GetEvent(fEvent);
872     /*
873     fRunLoader->LoadKinematics();
874
875     AliStack* stack = gAlice->Stack();
876     Int_t nParticles = stack->GetNtrack();
877     Int_t nPrimaries = stack->GetNprimary();
878     
879     TParticle *part;
880     Int_t nMuons = 0;
881     Int_t pdgCode;
882     Double_t px, py, pz, theta, phi;
883     for (Int_t i = 0; i < nPrimaries; i++) {
884       part = stack->Particle(i);
885       if (!part) continue;
886       if (TMath::Abs(part->GetPdgCode()) == 13) {
887         nMuons++;
888         pdgCode = part->GetPdgCode();
889         px = part->Px();
890         py = part->Py();
891         pz = part->Pz();
892         theta = part->Theta();
893         phi = part->Phi();
894         printf("Kine %d px %f py %f pz %f th %f ph %f \n",pdgCode,px,py,pz,theta,phi); 
895       }
896     }
897     */    
898   }
899
900 }
901
902 //__________________________________________________________________________
903 void AliMUONTriggerGUI::DoErrorOK()
904 {
905   /// close the error frame
906
907   fError->SendCloseMessage();
908
909 }
910
911 //__________________________________________________________________________
912 void AliMUONTriggerGUI::DoControlClose()
913 {
914   /// close the event control frame
915
916   fControl->SendCloseMessage();
917
918 }
919
920 //__________________________________________________________________________
921 void AliMUONTriggerGUI::DoCircuitCancel()
922 {
923   /// close the circuit frame
924
925   fCircuit->SendCloseMessage();
926
927 }
928
929 //__________________________________________________________________________
930 void AliMUONTriggerGUI::DoCircuitOpen()
931 {
932   /// open a circuit
933
934   TString cs = TString(fTxtCircuit->GetString());
935   Int_t icirc = cs.Atoi();
936
937   AliMUONTriggerGUIboard *board;
938
939   for (Int_t ib = 0; ib < kNBoards; ib++) {
940
941     board = GetBoard(ib);
942
943     if (board->GetIdCircuit() == icirc) {
944
945       OpenBoard(ib);
946
947       if (fDiMap) {
948         if (fDiMap->IsOn()) {
949           fDiMap->SelectBoard(ib);
950         }
951       }
952       
953       fCircuit->SendCloseMessage();
954       return;
955     }
956
957   }
958
959 }
960
961 //__________________________________________________________________________
962 AliMUONTriggerGUIboard* AliMUONTriggerGUI::GetBoard(Int_t id) const
963 {
964   /// return board with "id"
965
966   if (fBoards == 0) return 0;
967   void * b = fBoards->UncheckedAt(id);
968   if (b == 0) return 0;
969
970   return (AliMUONTriggerGUIboard*)b;
971
972 }
973
974 //__________________________________________________________________________
975 void AliMUONTriggerGUI::OpenBoard(Int_t id)
976 {
977   /// open board with "id" in a new frame
978    
979   AliMUONTriggerGUIboard *board = GetBoard(id);
980   UShort_t status = board->GetStatus();
981   board->SetOpen(kTRUE);
982
983   AliMUONTriggerGUIbdmap *bf;
984   Char_t text[200];
985
986   bf = new AliMUONTriggerGUIbdmap(gClient->GetRoot(), fMain, 400, 200);
987
988   if (status & kGood) {
989     sprintf(text,"%s (Circuit %4d) status : working",
990             board->GetBoardName(),board->GetIdCircuit());
991   }
992
993   if (status & kWithProblems) {
994     sprintf(text,"%s (Circuit %4d)  status : has problems...",
995             board->GetBoardName(),board->GetIdCircuit());
996   }
997
998   if (status & kNotWorking) {
999     sprintf(text,"%s (Circuit %4d)  status : not working",
1000             board->GetBoardName(),board->GetIdCircuit());
1001   }
1002
1003   if (status & kUnknown) {
1004     sprintf(text,"%s (Circuit %4d)  status : unknown",
1005             board->GetBoardName(),board->GetIdCircuit());
1006   }
1007
1008   bf->SetName(text);
1009   bf->SetBoard(Boards(),id);
1010   bf->SetLoader(fLoader);
1011   bf->SetCrateManager(fCrateManager);
1012   bf->SetMCDataInterface(fMCDataInterface);
1013   bf->Init();
1014
1015   bf->Show();
1016
1017   if (fDiMap) {
1018     if (fDiMap->IsOn()) {
1019       fDiMap->SelectBoard(id);
1020     }
1021   }
1022
1023 }
1024
1025 //__________________________________________________________________________
1026 void AliMUONTriggerGUI::Init()
1027 {
1028   /// initialize the main GUI frame
1029   
1030   if (!fBoardsInit) {
1031     InitBoards();
1032   }
1033
1034   /*
1035   AliMUONTriggerGUIboard *board;
1036   for (Int_t ib = 0; ib < kNBoards; ib++) {
1037     board = GetBoard(ib);
1038     board->Dump();
1039   }
1040   */
1041 }
1042
1043 //__________________________________________________________________________
1044 void AliMUONTriggerGUI::InitBoards()
1045 {
1046   /// create board objects and define the sensitive regions in the image map
1047   
1048   fBoardsInit = kTRUE;
1049
1050   if (fCrateManager == 0x0) {
1051     fCrateManager = new AliMUONTriggerCrateStore();
1052     fCrateManager->ReadFromFile(fCalibrationData);
1053   }
1054
1055   Int_t nPixelX = 700;
1056   Int_t nPixelY = 676;
1057
1058   Int_t nPixelBorderX = 40;  // to guess...
1059   Int_t nPixelBorderY = 40;  // to guess...
1060
1061   Float_t boardsX = 2*257.00;  // cm
1062   Float_t boardsY = 2*306.61;  // cm
1063
1064   FILE *fmap;
1065
1066   Int_t side, col, line, nbx, detElemId = 0;
1067   UShort_t status = 1;
1068   Float_t xCenter, yCenter, zCenter, xWidth, yWidth;
1069   Float_t xc, yc;
1070   Char_t name[8], text[200];
1071   Int_t x, y;
1072   UInt_t w, h;
1073   Int_t xp[5];
1074   Int_t yp[5];
1075   TString mapspath = gSystem->Getenv("ALICE_ROOT");
1076   mapspath.Append("/MUON/data");
1077
1078   TGRegion *reg;
1079   AliMUONTriggerGUIboard *board;
1080
1081   // regions for the image map
1082
1083   sprintf(text,"%s/guimapp11.txt",mapspath.Data());
1084   fmap = fopen(text,"r");
1085
1086   for (Int_t ib = 0; ib < kNBoards; ib++) {
1087
1088     fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
1089
1090     //printf("%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",side,col,line,nbx,xCenter,yCenter,xWidth,yWidth,zCenter,name);
1091
1092     board = new AliMUONTriggerGUIboard(ib,name);
1093
1094     status = 1;
1095     board->SetStatus(status);
1096
1097     // calculate detElemId%100
1098     // side=0 left
1099     // side=1 right
1100     // ALICE SC
1101     if (side == 0)              detElemId = 14 - line;
1102     if (side == 1 && line <  5) detElemId = 13 + line;
1103     if (side == 1 && line >= 5) detElemId = line - 5;
1104     
1105     board->SetDetElemId(detElemId);
1106
1107     Boards()->Add(board);
1108
1109     xc = xCenter;
1110     yc = yCenter;
1111
1112     x = (Int_t)(nPixelX/2 + xc * (nPixelX - 2*nPixelBorderX)/boardsX);
1113     y = (Int_t)(nPixelY/2 - yc * (nPixelY - 2*nPixelBorderY)/boardsY);
1114
1115     if (x < 0) x = 0;
1116     if (y < 0) y = 0;
1117
1118     w = (UInt_t)(xWidth*(nPixelX-2*nPixelBorderX)/boardsX);
1119     h = (UInt_t)(yWidth*(nPixelY-2*nPixelBorderY)/boardsY);
1120     
1121     xp[0] = x-w/2;
1122     xp[1] = x+w/2;
1123     xp[2] = x+w/2;
1124     xp[3] = x-w/2;
1125     xp[4] = x-w/2;
1126     
1127     yp[0] = y-h/2;
1128     yp[1] = y-h/2;
1129     yp[2] = y+h/2;
1130     yp[3] = y+h/2;
1131     yp[4] = y-h/2;
1132
1133     reg = new TGRegion(5,xp,yp);
1134     fImageMap->AddRegion(*reg, ib);
1135
1136     if (status & kGood) {
1137       sprintf(text,"%s working",name);
1138     }
1139     if (status & kWithProblems) {
1140       sprintf(text,"%s has problems...",name);
1141     }
1142     if (status & kNotWorking) {
1143       sprintf(text,"%s not working",name);
1144     }
1145     if (status & kUnknown) {
1146       sprintf(text,"%s status unknown",name);
1147     }
1148     
1149     //fImageMap->SetToolTipText(ib, text);
1150     
1151   }
1152
1153   fclose(fmap);
1154   
1155   // MT position and dimension in board
1156   
1157   for (Int_t imt = 0; imt < kNMT; imt++) {
1158
1159     sprintf(text,"%s/guimapp%2d.txt",mapspath.Data(),11+imt);
1160
1161     fmap = fopen(text,"r");
1162
1163     for (Int_t ib = 0; ib < kNBoards; ib++) {
1164
1165       fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
1166
1167       board = GetBoard(ib);
1168       board->SetDimensions(imt,xCenter,yCenter,zCenter,xWidth,yWidth);
1169
1170     }
1171
1172     fclose(fmap);
1173
1174   }
1175
1176   // MT x-strips indices and circuit number
1177   Int_t ix, iy1, iy2, sIx, sIy1, cathode, icirc;
1178   sprintf(text,"%s/guimapix11.txt",mapspath.Data());
1179
1180   fmap = fopen(text,"r");
1181   
1182   for (Int_t ib = 0; ib < kNBoards; ib++) {
1183     
1184     fscanf(fmap,"%d   %d   %d   %d   %d   %d   %d   %s   \n",&side,&col,&line,&nbx,&ix,&iy1,&iy2,&name[0]);
1185     
1186     board = GetBoard(ib);
1187     board->SetXSindex(ix,iy1,iy2);
1188
1189     // set the circuit number
1190     detElemId = board->GetDetElemId();
1191     detElemId += 100 * 11;
1192     cathode = 0;
1193     sIx  = board->GetXSix();
1194     sIy1 = board->GetXSiy1();
1195     const AliMpVSegmentation* seg = 
1196       AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
1197     
1198     AliMpPad pad = seg->PadByIndices(AliMpIntPair(sIx,sIy1),kTRUE);
1199     AliMpIntPair location = pad.GetLocation(0);
1200
1201     Int_t nboard = location.GetFirst();
1202     AliMUONLocalTriggerBoard* b = fCrateManager->LocalBoard(nboard);
1203     icirc = b->GetNumber();
1204     board->SetBoardName((Char_t*)b->GetName());
1205     board->SetIdCircuit(icirc);
1206
1207     TString crateName = b->GetCrate();
1208     
1209     sprintf(text,"%s (crate %s circuit %3d, number %3d)",board->GetBoardName(),crateName.Data(),icirc,ib);
1210     fImageMap->SetToolTipText(ib, text);
1211         
1212   }
1213   
1214   fclose(fmap);
1215
1216   // MT y-strips indices
1217   Int_t ix1, ix2, iy;
1218
1219   sprintf(text,"%s/guimapiy11.txt",mapspath.Data());
1220   
1221   fmap = fopen(text,"r");
1222   
1223   for (Int_t ib = 0; ib < kNBoards; ib++) {
1224     
1225     fscanf(fmap,"%d   %d   %d   %d   %d   %d   %d   %s   \n",&side,&col,&line,&nbx,&ix1,&ix2,&iy,&name[0]);
1226     
1227     board = GetBoard(ib);
1228     board->SetYSindex(ix1,ix2,iy);
1229     
1230   }
1231   
1232   fclose(fmap);
1233
1234   // Extended y-strips over neighbouring boards
1235
1236   sprintf(text,"%s/guimapp11.txt",mapspath.Data());
1237   
1238   fmap = fopen(text,"r");
1239   
1240   for (Int_t ib = 0; ib < kNBoards; ib++) {
1241     
1242     fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
1243     
1244     board = GetBoard(ib);
1245
1246     board->SetPosition(nbx);
1247     
1248     if ((col == 2 || col == 3) && (line >= 4 && line <= 6)) {
1249       board->SetYOver(4);
1250     } else
1251       
1252     if (col == 1 && (line == 4 || line == 6)) {
1253       board->SetYOver(3);
1254     } else
1255         
1256     if (col == 7 || line == 1 || line == 9) {
1257       board->SetYOver(1);
1258     } else
1259           
1260     {
1261       board->SetYOver(2);
1262     }
1263     
1264   }
1265   
1266   fclose(fmap);
1267
1268   // Set coordinates of strips boxes
1269
1270   for (Int_t ib = 0; ib < kNBoards; ib++) {
1271     
1272     board = GetBoard(ib);
1273     SetStripBoxes(board);
1274
1275   }
1276
1277 }
1278
1279 //__________________________________________________________________________
1280 void AliMUONTriggerGUI::SetStripBoxes(AliMUONTriggerGUIboard *board) 
1281 {
1282   /// set coordinates of strip boxes
1283
1284   gAlice = fRunLoader->GetAliRun();
1285   AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
1286   const AliMUONGeometryTransformer* kGeomTransformer = pMUON->GetGeometryTransformer();
1287
1288   const AliMpVSegmentation* seg;
1289   AliMpPad pad;
1290   AliMpDEIterator it;
1291
1292   Int_t chamber, detElemId, maxX, maxY, ic;
1293   Float_t xpmin, xpmax, ypmin, ypmax;
1294   Float_t xg1, xg2, yg1, yg2, zg1;
1295   Float_t xlocal1, xlocal2, ylocal1, ylocal2;
1296   Float_t xCenter, yCenter, xWidth, yWidth;
1297
1298   for (Int_t i = 0; i < kNMT; i++) {
1299
1300     chamber = 11+i;
1301
1302     xCenter = board->GetXCenter(i);
1303     yCenter = board->GetYCenter(i);
1304     xWidth  = board->GetXWidth(i);
1305     yWidth  = board->GetYWidth(i);
1306
1307     for ( it.First(chamber-1); ! it.IsDone(); it.Next() ) {
1308     
1309       detElemId = it.CurrentDEId();
1310     
1311       if (detElemId%100 != board->GetDetElemId()) continue;
1312
1313       /*---------- y-pads ic = 2 ----------*/
1314       ic = 2;
1315       
1316       seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(ic-1));
1317
1318       maxX = seg->MaxPadIndexX();
1319       maxY = seg->MaxPadIndexY();
1320       
1321       for (Int_t ix = 0; ix <= maxX; ix++) {
1322         for (Int_t iy = 0; iy <= maxY; iy++) {
1323           
1324           pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
1325           
1326           if (!pad.IsValid()) continue;
1327           
1328           // get the pad position and dimensions
1329           xlocal1 = pad.Position().X();
1330           ylocal1 = pad.Position().Y();
1331           xlocal2 = pad.Dimensions().X();
1332           ylocal2 = pad.Dimensions().Y();
1333           
1334           kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
1335           // (no transformation for pad dimensions)
1336           xg2 = xlocal2;
1337           yg2 = ylocal2;
1338           
1339           // transform in the monitor coordinate system
1340           //xpmin = -(xg1+xg2);
1341           //xpmax = -(xg1-xg2);
1342           //ypmin = -(yg2-yg1);
1343           //ypmax = +(yg2+yg1);
1344           // ALICE SC
1345           xpmin = +(xg1-xg2);
1346           xpmax = +(xg1+xg2);
1347           ypmin = -(yg2-yg1);
1348           ypmax = +(yg2+yg1);
1349           
1350           xpmin -= xCenter;
1351           xpmax -= xCenter;
1352           ypmin -= yCenter;
1353           ypmax -= yCenter;
1354           
1355           Int_t iX1, iX2, iY, ixDig;
1356           iX1 = board->GetYSix1();
1357           iX2 = board->GetYSix2();
1358           iY  = board->GetYSiy();
1359           if (ix >= iX1 && ix <= iX2 && iy == iY) {
1360             
1361             ypmin = -0.5*yWidth;
1362             ypmax = +0.5*yWidth;
1363
1364             ixDig = ix - iX1;
1365
1366             board->SetYDigBox(i,ixDig,(Double_t)xpmin,(Double_t)ypmin,
1367                                       (Double_t)xpmax,(Double_t)ypmax);
1368
1369           }
1370
1371         }  // end maxY
1372       }  // end maxX
1373
1374       /*---------- x-pads ic = 1 ----------*/
1375       ic = 1;
1376       
1377       seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(ic-1));
1378
1379       maxX = seg->MaxPadIndexX();
1380       maxY = seg->MaxPadIndexY();
1381             
1382       for (Int_t ix = 0; ix <= maxX; ix++) {
1383         for (Int_t iy = 0; iy <= maxY; iy++) {
1384           
1385           pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
1386           
1387           if (!pad.IsValid()) continue;
1388           
1389           // get the pad position and dimensions
1390           xlocal1 = pad.Position().X();
1391           ylocal1 = pad.Position().Y();
1392           xlocal2 = pad.Dimensions().X();
1393           ylocal2 = pad.Dimensions().Y();
1394           
1395           kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
1396           // (no transformation for pad dimensions)
1397           xg2 = xlocal2;
1398           yg2 = ylocal2;
1399           
1400           // transform in the monitor coordinate system
1401           //xpmin = -(xg1+xg2);
1402           //xpmax = -(xg1-xg2);
1403           //ypmin = -(yg2-yg1);
1404           //ypmax = +(yg2+yg1);
1405           // ALICE SC
1406           xpmin = +(xg1+xg2);
1407           xpmax = +(xg1-xg2);
1408           ypmin = -(yg2-yg1);
1409           ypmax = +(yg2+yg1);
1410           
1411           xpmin -= xCenter;
1412           xpmax -= xCenter;
1413           ypmin -= yCenter;
1414           ypmax -= yCenter;
1415
1416           Int_t iX, iY1, iY2, iyDig;
1417           iX  = board->GetXSix();
1418           iY1 = board->GetXSiy1();
1419           iY2 = board->GetXSiy2();
1420           if (ix == iX && iy >= iY1 && iy <= iY2) {
1421
1422             iyDig = iy - iY1;
1423
1424             board->SetXDigBox(i,iyDig,(Double_t)xpmin,(Double_t)ypmin,
1425                                       (Double_t)xpmax,(Double_t)ypmax);
1426
1427           }
1428
1429         }  // end maxY
1430       }  // end maxX
1431
1432     }  // end detElemId
1433
1434   }  // end kNMT loop
1435         
1436 }
1437