]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterHelper.cxx
Redefinition of macro to avoid warnings
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterHelper.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 #include <cstdlib>
19 #include "AliMUONPainterHelper.h"
20
21 #include "AliCodeTimer.h"
22 #include "AliLog.h"
23 #include "AliMUONContour.h"
24 #include "AliMUONContourHandler.h"
25 #include "AliMUONContourMaker.h"
26 #include "AliMUONGeometryDetElement.h"
27 #include "AliMUONGeometryTransformer.h"
28 #include "AliMUONManuContourMaker.h"
29 #include "AliMUONPainterEnv.h"
30 #include "AliMUONPainterMatrix.h"
31 #include "AliMUONPainterRegistry.h"
32 #include "AliMUONPadStatusMaker.h"
33 #include "AliMUONVCalibParam.h"
34 #include "AliMUONVDigit.h"
35 #include "AliMUONVTrackerData.h"
36 #include "AliMpCDB.h"
37 #include "AliMpConstants.h"
38 #include "AliMpDDLStore.h"
39 #include "AliMpDEIterator.h"
40 #include "AliMpDEManager.h"
41 #include "AliMpExMap.h"
42 #include "AliMpMotifMap.h"
43 #include "AliMpMotifPosition.h"
44 #include "AliMpPCB.h"
45 #include "AliMpPad.h"
46 #include "AliMpSector.h"
47 #include "AliMpSegmentation.h"
48 #include "AliMpSlat.h"
49 #include "AliMpStationType.h"
50 #include "AliMpVPadIterator.h"
51 #include <Riostream.h>
52 #include <TArrayI.h>
53 #include <TCanvas.h>
54 #include <TClass.h>
55 #include <TCollection.h>
56 #include <TFile.h>
57 #include <TGLabel.h>
58 #include <TGMsgBox.h>
59 #include <TGeoMatrix.h>
60 #include <TLine.h>
61 #include <TList.h>
62 #include <TMap.h>
63 #include <TObjArray.h>
64 #include <TObjString.h>
65 #include <TStyle.h>
66 #include <TSystem.h>
67 #include <TVector2.h>
68 #include <TVector3.h>
69 #include <TVirtualPad.h>
70 #include <TVirtualX.h>
71
72 #include "AliMUONChamberPainter.h"
73
74 ///\class AliMUONPainterHelper
75 ///
76 /// Helper class for painters
77 ///
78 ///\author Laurent Aphecetche, Subatech
79
80 ///\cond CLASSIMP
81 ClassImp(AliMUONPainterHelper)
82 ///\endcond
83
84 AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0);
85
86 //_____________________________________________________________________________
87 AliMUONPainterHelper::AliMUONPainterHelper() : 
88 TObject(),
89 fPainterMatrices(0x0),
90 fEnv(0x0),
91 fReal(0x0),
92 fExploded(0x0)
93 {
94   /// ctor
95   
96   if ( ! AliMpCDB::LoadMpSegmentation() ) 
97   {
98     AliFatal("Could not access mapping from OCDB !");
99   }
100   
101   // Load DDL store
102   if ( ! AliMpCDB::LoadDDLStore() ) 
103   {
104     AliFatal("Could not access DDL Store from OCDB !");
105   }
106   
107   fExploded = new AliMUONContourHandler(kTRUE);
108 }
109
110 //_____________________________________________________________________________
111 AliMUONPainterHelper::~AliMUONPainterHelper()
112 {
113   /// dtor
114   delete fPainterMatrices;
115   delete fReal;
116   delete fExploded;
117   fEnv->Save();
118   fgInstance = 0;
119 }
120
121 //_____________________________________________________________________________
122 AliMUONContour*
123 AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
124 {
125   /// Get a contour by name  
126   if (explodedView) 
127   {
128     return fExploded->GetContour(contourName);
129   }
130   else
131   {
132     if ( fReal ) 
133     {
134       return fReal->GetContour(contourName);
135     }
136   }
137   return 0x0;
138 }
139
140 //_____________________________________________________________________________
141 void
142 AliMUONPainterHelper::GenerateDefaultMatrices()
143 {
144   /// Kind of bootstrap method to trigger the generation of all contours
145   
146   AliCodeTimerAuto("",);
147   
148   fPainterMatrices = new TObjArray;
149   fPainterMatrices->SetOwner(kFALSE);
150   
151   TObjArray attributes;
152   
153   AliMUONAttPainter att;
154   
155   att.SetViewPoint(kTRUE,kFALSE);
156   att.SetCathode(kFALSE,kFALSE);
157   att.SetPlane(kTRUE,kFALSE);
158   attributes.Add(new AliMUONAttPainter(att));
159
160   TIter next(&attributes);
161   AliMUONAttPainter* a;
162   
163   while ( ( a = static_cast<AliMUONAttPainter*>(next()) ) )
164   {
165     AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
166     
167     for ( Int_t i = 0; i < 10; ++i )
168     {
169       AliMUONVPainter* painter = new AliMUONChamberPainter(*a,i);
170       
171       painter->SetResponder("Chamber");
172       
173       painter->SetOutlined("*",kFALSE);
174       
175       painter->SetOutlined("MANU",kTRUE);
176       
177       for ( Int_t j = 0; j < 3; ++j ) 
178       {
179         painter->SetLine(j,1,4-j);
180       }
181       
182       matrix->Adopt(painter);    
183     }
184     AliMUONPainterRegistry::Instance()->Register(matrix);
185     fPainterMatrices->Add(matrix);
186   }
187 }
188
189 //_____________________________________________________________________________
190 AliMp::CathodType
191 AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
192 {
193   /// Get the cathode type of a given manu
194   
195   AliMp::PlaneType planeType(AliMp::kBendingPlane);
196   if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
197   {
198     planeType = AliMp::kNonBendingPlane;
199   }
200   return AliMpDEManager::GetCathod(detElemId,planeType);
201 }
202
203
204 //_____________________________________________________________________________
205 AliMpMotifPosition* 
206 AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
207 {
208   /// Get a given motif position
209   const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
210   if (vseg)
211   {
212     return vseg->MotifPosition(manuId);
213   }
214   return 0x0;
215 }
216
217 //_____________________________________________________________________________
218 AliMpPCB*
219 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType, 
220                              Int_t pcbNumber) const
221 {
222   /// Get a given PCB
223   const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
224   if ( slat ) return slat->GetPCB(pcbNumber);
225   return 0x0;
226 }
227
228 //_____________________________________________________________________________
229 AliMpPCB*
230 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType, 
231                              Int_t pcbNumber) const
232 {
233   /// Get a given PCB
234   AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
235                                                             planeType);
236   return GetPCB(detElemId,cathodeType,pcbNumber);
237 }
238
239 //_____________________________________________________________________________
240 AliMp::PlaneType
241 AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
242 {
243   /// Get the planeType of a given manu
244   
245   if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
246   {
247     return AliMp::kNonBendingPlane;
248   }
249   return AliMp::kBendingPlane;
250 }
251
252 //_____________________________________________________________________________
253 const AliMpSlat*
254 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
255 {
256   /// Get a given slat
257   
258   AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
259                                                           planeType);
260
261   return GetSlat(detElemId,cathodeType);
262 }
263
264 //_____________________________________________________________________________
265 const AliMpSector*
266 AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
267 {
268   /// Get a given sector
269   AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
270   if ( stationType != AliMp::kStation12 ) return 0x0;
271   
272   AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
273   
274   return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
275 }
276
277 //_____________________________________________________________________________
278 const AliMpSlat*
279 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
280 {
281   /// Get a given slat
282   AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
283   if ( stationType != AliMp::kStation345 ) return 0x0;
284
285   return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
286 }
287
288 //_____________________________________________________________________________
289 const AliMpSlat*
290 AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
291 {
292   /// Get a given slat
293   AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
294   if ( stationType != AliMp::kStation345 ) return 0x0;
295
296   return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
297 }
298
299 //_____________________________________________________________________________
300 AliMUONPainterHelper*
301 AliMUONPainterHelper::Instance()
302 {
303   /// Return the global and unique instance of this class
304   
305   if (fgInstance) return fgInstance;
306
307   AliCodeTimerAutoClass("",);
308
309   fgInstance = new AliMUONPainterHelper;
310   fgInstance->fEnv = new AliMUONPainterEnv;
311   return fgInstance;
312 }
313
314 //_____________________________________________________________________________
315 void 
316 AliMUONPainterHelper::Global2Local(Int_t detElemId, 
317                                     Double_t xg, Double_t yg, Double_t zg,
318                                     Double_t& xl, Double_t& yl, Double_t& zl) const
319 {
320   /// Local to global transformation of coordinates
321   
322   TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExploded->GetTransformations()->GetValue(detElemId));
323   Double_t pg[3] = { xg, yg, zg };
324   Double_t pl[3] = { 0., 0., 0. };
325   matrix->MasterToLocal(pg, pl);
326   xl = pl[0];
327   yl = pl[1];
328   zl = pl[2];
329 }
330
331 //_____________________________________________________________________________
332 void 
333 AliMUONPainterHelper::Local2Global(Int_t detElemId, 
334                                    Double_t xl, Double_t yl, Double_t zl,
335                                    Double_t& xg, Double_t& yg, Double_t& zg) const
336 {
337   /// Local to (exploded) global transformation of coordinates
338   
339   TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExploded->GetTransformations()->GetValue(detElemId));
340   Double_t pl[3] = { xl, yl, zl };
341   Double_t pg[3] = { 0., 0., 0. };
342   matrix->LocalToMaster(pl, pg);
343   xg = pg[0];
344   yg = pg[1];
345   zg = pg[2];
346 }
347
348 //_____________________________________________________________________________
349 Int_t
350 AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
351
352   /// Convert a value into a color, fitting within a given range
353   
354   Int_t rv;
355   
356   if (value > max) rv = 1;
357   else if (value <= min) rv = 0;
358   else
359   {
360     if  ( max == min ) return gStyle->GetColorPalette(1);
361     Double_t range = max - min;
362     Double_t offset = value - min;
363     rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
364   }
365   return rv;
366 }
367
368 //_____________________________________________________________________________
369 AliMUONContour* 
370 AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
371 {
372   /// Merge a set of contours (delegating to the contour maker)
373   
374   AliMUONContourMaker maker;
375   
376   AliMUONContour* contour = maker.MergeContour(contours,contourName);
377   
378   if (contour) 
379   {
380     RegisterContour(contour,explodedGeometry);
381   }
382   return contour;
383 }
384
385
386 //_____________________________________________________________________________
387 void
388 AliMUONPainterHelper::Print(Option_t* opt) const
389 {
390   /// Printout
391   TString sopt(opt);
392   sopt.ToUpper();
393   
394   if ( sopt.Length() == 0 )
395   {
396     if ( fExploded ) fExploded->Print();
397     if ( fReal ) fReal->Print();
398   }
399   
400   if ( fPainterMatrices && ( sopt.Contains("MATRI") || sopt.Contains("FULL") ) )
401   {
402     fPainterMatrices->Print(opt);
403   }
404 }
405
406 //_____________________________________________________________________________
407 void
408 AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
409 {
410   /// contour is adopted by contourMaker
411   AliCodeTimerAuto("",)
412   AliDebug(1,contour->GetName());
413   AliMUONContourHandler* ch = fReal;
414   if ( explodedView ) 
415   {
416     ch = fExploded;
417   }
418   if (!ch)
419   {
420     AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
421   }
422   else
423   {
424     if ( ch->GetContour(contour->GetName()) )
425     {
426       AliError(Form("Contour with name %s is already there",contour->GetName()));
427       return;
428     }
429     ch->Adopt(contour);
430   }
431 }
432
433 //_____________________________________________________________________________
434 TString 
435 AliMUONPainterHelper::ChamberName(Int_t chamberId) const
436 {
437   /// Build a name for one chamber
438   return Form("Chamber%1d",chamberId+1);
439 }
440
441 //_____________________________________________________________________________
442 TString 
443 AliMUONPainterHelper::StationName(Int_t stationId) const
444 {
445   /// Build a name for one station
446   return Form("Station%1d",stationId+1);
447 }
448
449 //_____________________________________________________________________________
450 TString 
451 AliMUONPainterHelper::DEName(Int_t detElemId) const
452 {
453   /// Build a name for one detection element
454   return Form("DE%04d",detElemId);
455 }
456
457 //_____________________________________________________________________________
458 TString 
459 AliMUONPainterHelper::ManuName(Int_t manuId) const
460 {
461   /// Build a name for one manu
462   return Form("MANU%04d",manuId);
463 }
464
465 //_____________________________________________________________________________
466 TString 
467 AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
468 {
469   /// Build a name for one buspatch
470   return Form("BUSPATCH%04d",busPatchId);
471 }
472
473 //_____________________________________________________________________________
474 TString 
475 AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
476 {
477   /// Build a name for one pcb
478   return Form("PCB%1d",pcbNumber);
479 }
480
481 //_____________________________________________________________________________
482 TString 
483 AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
484 {
485   /// Build a name for one chamber
486   return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
487 }
488
489 //_____________________________________________________________________________
490 TString 
491 AliMUONPainterHelper::StationPathName(Int_t stationId) const
492 {
493   /// Build a name for one station
494   return StationName(stationId);
495 }
496
497 //_____________________________________________________________________________
498 TString 
499 AliMUONPainterHelper::DEPathName(Int_t detElemId) const
500 {
501   /// Build a name for one detection element
502   
503   Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
504   
505   return Form("%s/%s/%s",
506               StationName(chamberId/2).Data(),
507               ChamberName(chamberId).Data(),
508               DEName(detElemId).Data());
509 }
510
511 //_____________________________________________________________________________
512 TString 
513 AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
514 {
515   /// Build a name for one manu
516   return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
517 }
518
519 //_____________________________________________________________________________
520 TString 
521 AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
522 {
523   /// Build a name for one buspatch
524   Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
525   
526   return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
527 }
528
529 //_____________________________________________________________________________
530 TString 
531 AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
532 {
533   /// Build a name for one pcb
534   return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
535 }
536
537 //_____________________________________________________________________________
538 TString
539 AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
540 {
541   /// Format a double value to be displayed
542   /// FIXME: should insure we have the right number of significant digits here...
543   
544   TString sname(name);
545   
546   sname.ToUpper();
547   if (sname.Contains("BIT"))
548   {
549     Int_t i = (Int_t)(value);
550     TString rv = Form("%s = 0x%x",name,i);
551     cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
552     return rv;
553   }
554   else
555   {
556     return Form("%s = %e",name,value);
557   }
558 }
559
560 //_____________________________________________________________________________
561 TObjArray*
562 AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
563 {
564   /// Get the contours in a specially arranged array (orderer by hierarchy level)
565   
566   if ( explodedView ) return fExploded->AllContourArray(); // fExploded should always be created
567   
568   if (!fReal) fReal = new AliMUONContourHandler(kFALSE); // fReal might be first asked here.
569   
570   return fReal->AllContourArray();
571 }
572
573