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