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