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 !");
108 //_____________________________________________________________________________
109 AliMUONPainterHelper::~AliMUONPainterHelper()
112 delete fPainterMatrices;
119 //_____________________________________________________________________________
120 AliMUONContourHandler*
121 AliMUONPainterHelper::Exploded() const
123 /// Create exploded contour handler
124 if (!fExploded) fExploded = new AliMUONContourHandler(kTRUE);
128 //_____________________________________________________________________________
129 AliMUONContourHandler*
130 AliMUONPainterHelper::Real() const
132 /// Create real contour handler
133 if (!fReal) fReal = new AliMUONContourHandler(kFALSE);
137 //_____________________________________________________________________________
139 AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
141 /// Get a contour by name
144 return Exploded()->GetContour(contourName);
150 return fReal->GetContour(contourName);
156 //_____________________________________________________________________________
158 AliMUONPainterHelper::GenerateDefaultMatrices()
160 /// Kind of bootstrap method to trigger the generation of all contours
162 AliCodeTimerAuto("",0);
164 fPainterMatrices = new TObjArray;
165 fPainterMatrices->SetOwner(kFALSE);
167 TObjArray attributes;
169 AliMUONAttPainter att;
171 att.SetViewPoint(kTRUE,kFALSE);
172 att.SetCathode(kFALSE,kFALSE);
173 att.SetPlane(kTRUE,kFALSE);
174 attributes.Add(new AliMUONAttPainter(att));
176 TIter next(&attributes);
177 AliMUONAttPainter* a;
179 while ( ( a = static_cast<AliMUONAttPainter*>(next()) ) )
181 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
183 for ( Int_t i = 0; i < 10; ++i )
185 AliMUONVPainter* painter = new AliMUONChamberPainter(*a,i);
187 painter->SetResponder("Chamber");
189 painter->SetOutlined("*",kFALSE);
191 painter->SetOutlined("MANU",kTRUE);
193 for ( Int_t j = 0; j < 3; ++j )
195 painter->SetLine(j,1,4-j);
198 matrix->Adopt(painter);
200 AliMUONPainterRegistry::Instance()->Register(matrix);
201 fPainterMatrices->Add(matrix);
205 //_____________________________________________________________________________
207 AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
209 /// Get the cathode type of a given manu
211 AliMp::PlaneType planeType(AliMp::kBendingPlane);
212 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
214 planeType = AliMp::kNonBendingPlane;
216 return AliMpDEManager::GetCathod(detElemId,planeType);
220 //_____________________________________________________________________________
222 AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
224 /// Get a given motif position
225 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
228 return vseg->MotifPosition(manuId);
233 //_____________________________________________________________________________
235 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
236 Int_t pcbNumber) const
239 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
240 if ( slat ) return slat->GetPCB(pcbNumber);
244 //_____________________________________________________________________________
246 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
247 Int_t pcbNumber) const
250 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
252 return GetPCB(detElemId,cathodeType,pcbNumber);
255 //_____________________________________________________________________________
257 AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
259 /// Get the planeType of a given manu
261 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
263 return AliMp::kNonBendingPlane;
265 return AliMp::kBendingPlane;
268 //_____________________________________________________________________________
270 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
274 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
277 return GetSlat(detElemId,cathodeType);
280 //_____________________________________________________________________________
282 AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
284 /// Get a given sector
285 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
286 if ( stationType != AliMp::kStation12 ) return 0x0;
288 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
290 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
293 //_____________________________________________________________________________
295 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
298 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
299 if ( stationType != AliMp::kStation345 ) return 0x0;
301 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
304 //_____________________________________________________________________________
306 AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
309 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
310 if ( stationType != AliMp::kStation345 ) return 0x0;
312 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
315 //_____________________________________________________________________________
316 AliMUONPainterHelper*
317 AliMUONPainterHelper::Instance()
319 /// Return the global and unique instance of this class
321 if (fgInstance) return fgInstance;
323 AliCodeTimerAutoClass("",0);
325 fgInstance = new AliMUONPainterHelper;
326 fgInstance->fEnv = new AliMUONPainterEnv;
330 //_____________________________________________________________________________
332 AliMUONPainterHelper::Global2Local(Int_t detElemId,
333 Double_t xg, Double_t yg, Double_t zg,
334 Double_t& xl, Double_t& yl, Double_t& zl) const
336 /// Local to global transformation of coordinates
338 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
339 Double_t pg[3] = { xg, yg, zg };
340 Double_t pl[3] = { 0., 0., 0. };
341 matrix->MasterToLocal(pg, pl);
347 //_____________________________________________________________________________
349 AliMUONPainterHelper::Local2Global(Int_t detElemId,
350 Double_t xl, Double_t yl, Double_t zl,
351 Double_t& xg, Double_t& yg, Double_t& zg) const
353 /// Local to (exploded) global transformation of coordinates
355 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
356 Double_t pl[3] = { xl, yl, zl };
357 Double_t pg[3] = { 0., 0., 0. };
358 matrix->LocalToMaster(pl, pg);
364 //_____________________________________________________________________________
366 AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
368 /// Convert a value into a color, fitting within a given range
372 if (value > max) rv = 1;
373 else if (value <= min) rv = 0;
376 if ( max == min ) return gStyle->GetColorPalette(1);
377 Double_t range = max - min;
378 Double_t offset = value - min;
379 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
384 //_____________________________________________________________________________
386 AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
388 /// Merge a set of contours (delegating to the contour maker)
390 AliMUONContourMaker maker;
392 AliMUONContour* contour = maker.MergeContour(contours,contourName);
396 RegisterContour(contour,explodedGeometry);
402 //_____________________________________________________________________________
404 AliMUONPainterHelper::Print(Option_t* opt) const
410 if ( sopt.Length() == 0 )
412 if ( fExploded ) fExploded->Print();
413 if ( fReal ) fReal->Print();
416 if ( fPainterMatrices && ( sopt.Contains("MATRI") || sopt.Contains("FULL") ) )
418 fPainterMatrices->Print(opt);
422 //_____________________________________________________________________________
424 AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
426 /// contour is adopted by contourMaker
427 AliCodeTimerAuto("",0)
428 AliDebug(1,contour->GetName());
429 AliMUONContourHandler* ch = fReal;
436 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
440 if ( ch->GetContour(contour->GetName()) )
442 AliError(Form("Contour with name %s is already there",contour->GetName()));
449 //_____________________________________________________________________________
451 AliMUONPainterHelper::ChamberName(Int_t chamberId) const
453 /// Build a name for one chamber
454 return Form("Chamber%1d",chamberId+1);
457 //_____________________________________________________________________________
459 AliMUONPainterHelper::StationName(Int_t stationId) const
461 /// Build a name for one station
462 return Form("Station%1d",stationId+1);
465 //_____________________________________________________________________________
467 AliMUONPainterHelper::DEName(Int_t detElemId) const
469 /// Build a name for one detection element
470 return Form("DE%04d",detElemId);
473 //_____________________________________________________________________________
475 AliMUONPainterHelper::ManuName(Int_t manuId) const
477 /// Build a name for one manu
478 return Form("MANU%04d",manuId);
481 //_____________________________________________________________________________
483 AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
485 /// Build a name for one buspatch
486 return Form("BUSPATCH%04d",busPatchId);
489 //_____________________________________________________________________________
491 AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
493 /// Build a name for one pcb
494 return Form("PCB%1d",pcbNumber);
497 //_____________________________________________________________________________
499 AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
501 /// Build a name for one chamber
502 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
505 //_____________________________________________________________________________
507 AliMUONPainterHelper::StationPathName(Int_t stationId) const
509 /// Build a name for one station
510 return StationName(stationId);
513 //_____________________________________________________________________________
515 AliMUONPainterHelper::DEPathName(Int_t detElemId) const
517 /// Build a name for one detection element
519 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
521 return Form("%s/%s/%s",
522 StationName(chamberId/2).Data(),
523 ChamberName(chamberId).Data(),
524 DEName(detElemId).Data());
527 //_____________________________________________________________________________
529 AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
531 /// Build a name for one manu
532 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
535 //_____________________________________________________________________________
537 AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
539 /// Build a name for one buspatch
540 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
542 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
545 //_____________________________________________________________________________
547 AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
549 /// Build a name for one pcb
550 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
553 //_____________________________________________________________________________
555 AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
557 /// Format a double value to be displayed
558 /// FIXME: should insure we have the right number of significant digits here...
563 if (sname.Contains("BIT"))
565 Int_t i = (Int_t)(value);
566 TString rv = Form("%s = 0x%x",name,i);
567 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
572 return Form("%s = %e",name,value);
576 //_____________________________________________________________________________
578 AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
580 /// Get the contours in a specially arranged array (orderer by hierarchy level)
584 return Exploded()->AllContourArray();
588 return Real()->AllContourArray();