1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 #include "AliMUONPainterHelper.h"
21 #include "AliCodeTimer.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"
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"
46 #include "AliMpSector.h"
47 #include "AliMpSegmentation.h"
48 #include "AliMpSlat.h"
49 #include "AliMpStationType.h"
50 #include "AliMpVPadIterator.h"
51 #include <Riostream.h>
55 #include <TCollection.h>
59 #include <TGeoMatrix.h>
63 #include <TObjArray.h>
64 #include <TObjString.h>
69 #include <TVirtualPad.h>
70 #include <TVirtualX.h>
72 #include "AliMUONChamberPainter.h"
74 ///\class AliMUONPainterHelper
76 /// Helper class for painters
78 ///\author Laurent Aphecetche, Subatech
81 ClassImp(AliMUONPainterHelper)
84 AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0);
86 //_____________________________________________________________________________
87 AliMUONPainterHelper::AliMUONPainterHelper() :
89 fPainterMatrices(0x0),
96 if ( ! AliMpCDB::LoadMpSegmentation() )
98 AliFatal("Could not access mapping from OCDB !");
102 if ( ! AliMpCDB::LoadDDLStore() )
104 AliFatal("Could not access DDL Store from OCDB !");
107 fExploded = new AliMUONContourHandler(kTRUE);
110 //_____________________________________________________________________________
111 AliMUONPainterHelper::~AliMUONPainterHelper()
114 delete fPainterMatrices;
121 //_____________________________________________________________________________
123 AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
125 /// Get a contour by name
128 return fExploded->GetContour(contourName);
134 return fReal->GetContour(contourName);
140 //_____________________________________________________________________________
142 AliMUONPainterHelper::GenerateDefaultMatrices()
144 /// Kind of bootstrap method to trigger the generation of all contours
146 AliCodeTimerAuto("",);
148 fPainterMatrices = new TObjArray;
149 fPainterMatrices->SetOwner(kFALSE);
151 TObjArray attributes;
153 AliMUONAttPainter att;
155 att.SetViewPoint(kTRUE,kFALSE);
156 att.SetCathode(kFALSE,kFALSE);
157 att.SetPlane(kTRUE,kFALSE);
158 attributes.Add(new AliMUONAttPainter(att));
160 TIter next(&attributes);
161 AliMUONAttPainter* a;
163 while ( ( a = static_cast<AliMUONAttPainter*>(next()) ) )
165 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
167 for ( Int_t i = 0; i < 10; ++i )
169 AliMUONVPainter* painter = new AliMUONChamberPainter(*a,i);
171 painter->SetResponder("Chamber");
173 painter->SetOutlined("*",kFALSE);
175 painter->SetOutlined("MANU",kTRUE);
177 for ( Int_t j = 0; j < 3; ++j )
179 painter->SetLine(j,1,4-j);
182 matrix->Adopt(painter);
184 AliMUONPainterRegistry::Instance()->Register(matrix);
185 fPainterMatrices->Add(matrix);
189 //_____________________________________________________________________________
191 AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
193 /// Get the cathode type of a given manu
195 AliMp::PlaneType planeType(AliMp::kBendingPlane);
196 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
198 planeType = AliMp::kNonBendingPlane;
200 return AliMpDEManager::GetCathod(detElemId,planeType);
204 //_____________________________________________________________________________
206 AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
208 /// Get a given motif position
209 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
212 return vseg->MotifPosition(manuId);
217 //_____________________________________________________________________________
219 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
220 Int_t pcbNumber) const
223 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
224 if ( slat ) return slat->GetPCB(pcbNumber);
228 //_____________________________________________________________________________
230 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
231 Int_t pcbNumber) const
234 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
236 return GetPCB(detElemId,cathodeType,pcbNumber);
239 //_____________________________________________________________________________
241 AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
243 /// Get the planeType of a given manu
245 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
247 return AliMp::kNonBendingPlane;
249 return AliMp::kBendingPlane;
252 //_____________________________________________________________________________
254 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
258 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
261 return GetSlat(detElemId,cathodeType);
264 //_____________________________________________________________________________
266 AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
268 /// Get a given sector
269 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
270 if ( stationType != AliMp::kStation12 ) return 0x0;
272 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
274 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
277 //_____________________________________________________________________________
279 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
282 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
283 if ( stationType != AliMp::kStation345 ) return 0x0;
285 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
288 //_____________________________________________________________________________
290 AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
293 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
294 if ( stationType != AliMp::kStation345 ) return 0x0;
296 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
299 //_____________________________________________________________________________
300 AliMUONPainterHelper*
301 AliMUONPainterHelper::Instance()
303 /// Return the global and unique instance of this class
305 if (fgInstance) return fgInstance;
307 AliCodeTimerAutoClass("",);
309 fgInstance = new AliMUONPainterHelper;
310 fgInstance->fEnv = new AliMUONPainterEnv;
314 //_____________________________________________________________________________
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
320 /// Local to global transformation of coordinates
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);
331 //_____________________________________________________________________________
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
337 /// Local to (exploded) global transformation of coordinates
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);
348 //_____________________________________________________________________________
350 AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
352 /// Convert a value into a color, fitting within a given range
356 if (value > max) rv = 1;
357 else if (value <= min) rv = 0;
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 ) );
368 //_____________________________________________________________________________
370 AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
372 /// Merge a set of contours (delegating to the contour maker)
374 AliMUONContourMaker maker;
376 AliMUONContour* contour = maker.MergeContour(contours,contourName);
380 RegisterContour(contour,explodedGeometry);
386 //_____________________________________________________________________________
388 AliMUONPainterHelper::Print(Option_t* opt) const
394 if ( sopt.Length() == 0 )
396 if ( fExploded ) fExploded->Print();
397 if ( fReal ) fReal->Print();
400 if ( fPainterMatrices && ( sopt.Contains("MATRI") || sopt.Contains("FULL") ) )
402 fPainterMatrices->Print(opt);
406 //_____________________________________________________________________________
408 AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
410 /// contour is adopted by contourMaker
411 AliCodeTimerAuto("",)
412 AliDebug(1,contour->GetName());
413 AliMUONContourHandler* ch = fReal;
420 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
424 if ( ch->GetContour(contour->GetName()) )
426 AliError(Form("Contour with name %s is already there",contour->GetName()));
433 //_____________________________________________________________________________
435 AliMUONPainterHelper::ChamberName(Int_t chamberId) const
437 /// Build a name for one chamber
438 return Form("Chamber%1d",chamberId+1);
441 //_____________________________________________________________________________
443 AliMUONPainterHelper::StationName(Int_t stationId) const
445 /// Build a name for one station
446 return Form("Station%1d",stationId+1);
449 //_____________________________________________________________________________
451 AliMUONPainterHelper::DEName(Int_t detElemId) const
453 /// Build a name for one detection element
454 return Form("DE%04d",detElemId);
457 //_____________________________________________________________________________
459 AliMUONPainterHelper::ManuName(Int_t manuId) const
461 /// Build a name for one manu
462 return Form("MANU%04d",manuId);
465 //_____________________________________________________________________________
467 AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
469 /// Build a name for one buspatch
470 return Form("BUSPATCH%04d",busPatchId);
473 //_____________________________________________________________________________
475 AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
477 /// Build a name for one pcb
478 return Form("PCB%1d",pcbNumber);
481 //_____________________________________________________________________________
483 AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
485 /// Build a name for one chamber
486 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
489 //_____________________________________________________________________________
491 AliMUONPainterHelper::StationPathName(Int_t stationId) const
493 /// Build a name for one station
494 return StationName(stationId);
497 //_____________________________________________________________________________
499 AliMUONPainterHelper::DEPathName(Int_t detElemId) const
501 /// Build a name for one detection element
503 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
505 return Form("%s/%s/%s",
506 StationName(chamberId/2).Data(),
507 ChamberName(chamberId).Data(),
508 DEName(detElemId).Data());
511 //_____________________________________________________________________________
513 AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
515 /// Build a name for one manu
516 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
519 //_____________________________________________________________________________
521 AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
523 /// Build a name for one buspatch
524 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
526 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
529 //_____________________________________________________________________________
531 AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
533 /// Build a name for one pcb
534 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
537 //_____________________________________________________________________________
539 AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
541 /// Format a double value to be displayed
542 /// FIXME: should insure we have the right number of significant digits here...
547 if (sname.Contains("BIT"))
549 Int_t i = (Int_t)(value);
550 TString rv = Form("%s = 0x%x",name,i);
551 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
556 return Form("%s = %e",name,value);
560 //_____________________________________________________________________________
562 AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
564 /// Get the contours in a specially arranged array (orderer by hierarchy level)
566 if ( explodedView ) return fExploded->AllContourArray(); // fExploded should always be created
568 if (!fReal) fReal = new AliMUONContourHandler(kFALSE); // fReal might be first asked here.
570 return fReal->AllContourArray();