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 "AliMUONPainterRegistry.h"
31 #include "AliMUONPadStatusMaker.h"
32 #include "AliMUONVCalibParam.h"
33 #include "AliMUONVDigit.h"
34 #include "AliMUONVTrackerData.h"
36 #include "AliMpConstants.h"
37 #include "AliMpDDLStore.h"
38 #include "AliMpDEIterator.h"
39 #include "AliMpDEManager.h"
40 #include "AliMpExMap.h"
41 #include "AliMpMotifMap.h"
42 #include "AliMpMotifPosition.h"
45 #include "AliMpSector.h"
46 #include "AliMpSegmentation.h"
47 #include "AliMpSlat.h"
48 #include "AliMpStationType.h"
49 #include "AliMpVPadIterator.h"
50 #include <Riostream.h>
54 #include <TCollection.h>
58 #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() :
95 if ( ! AliMpCDB::LoadMpSegmentation() )
97 AliFatal("Could not access mapping from OCDB !");
101 if ( ! AliMpCDB::LoadDDLStore() )
103 AliFatal("Could not access DDL Store from OCDB !");
107 //_____________________________________________________________________________
108 AliMUONPainterHelper::~AliMUONPainterHelper()
117 //_____________________________________________________________________________
118 AliMUONContourHandler*
119 AliMUONPainterHelper::Exploded() const
121 /// Create exploded contour handler
122 if (!fExploded) fExploded = new AliMUONContourHandler(kTRUE);
126 //_____________________________________________________________________________
127 AliMUONContourHandler*
128 AliMUONPainterHelper::Real() const
130 /// Create real contour handler
131 if (!fReal) fReal = new AliMUONContourHandler(kFALSE);
135 //_____________________________________________________________________________
137 AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
139 /// Get a contour by name
142 return Exploded()->GetContour(contourName);
148 return fReal->GetContour(contourName);
155 //_____________________________________________________________________________
157 AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
159 /// Get the cathode type of a given manu
161 AliMp::PlaneType planeType(AliMp::kBendingPlane);
162 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
164 planeType = AliMp::kNonBendingPlane;
166 return AliMpDEManager::GetCathod(detElemId,planeType);
170 //_____________________________________________________________________________
172 AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
174 /// Get a given motif position
175 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
178 return vseg->MotifPosition(manuId);
183 //_____________________________________________________________________________
185 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
186 Int_t pcbNumber) const
189 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
190 if ( slat ) return slat->GetPCB(pcbNumber);
194 //_____________________________________________________________________________
196 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
197 Int_t pcbNumber) const
200 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
202 return GetPCB(detElemId,cathodeType,pcbNumber);
205 //_____________________________________________________________________________
207 AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
209 /// Get the planeType of a given manu
211 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
213 return AliMp::kNonBendingPlane;
215 return AliMp::kBendingPlane;
218 //_____________________________________________________________________________
220 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
224 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
227 return GetSlat(detElemId,cathodeType);
230 //_____________________________________________________________________________
232 AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
234 /// Get a given sector
235 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
236 if ( stationType != AliMp::kStation12 ) return 0x0;
238 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
240 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
243 //_____________________________________________________________________________
245 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
248 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
249 if ( stationType != AliMp::kStation345 ) return 0x0;
251 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
254 //_____________________________________________________________________________
256 AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
259 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
260 if ( stationType != AliMp::kStation345 ) return 0x0;
262 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
265 //_____________________________________________________________________________
266 AliMUONPainterHelper*
267 AliMUONPainterHelper::Instance()
269 /// Return the global and unique instance of this class
271 if (fgInstance) return fgInstance;
273 AliCodeTimerAutoClass("",0);
275 fgInstance = new AliMUONPainterHelper;
276 fgInstance->fEnv = new AliMUONPainterEnv;
280 //_____________________________________________________________________________
282 AliMUONPainterHelper::Global2Local(Int_t detElemId,
283 Double_t xg, Double_t yg, Double_t zg,
284 Double_t& xl, Double_t& yl, Double_t& zl) const
286 /// Local to global transformation of coordinates
288 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
289 Double_t pg[3] = { xg, yg, zg };
290 Double_t pl[3] = { 0., 0., 0. };
291 matrix->MasterToLocal(pg, pl);
297 //_____________________________________________________________________________
299 AliMUONPainterHelper::Local2Global(Int_t detElemId,
300 Double_t xl, Double_t yl, Double_t zl,
301 Double_t& xg, Double_t& yg, Double_t& zg) const
303 /// Local to (exploded) global transformation of coordinates
305 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
306 Double_t pl[3] = { xl, yl, zl };
307 Double_t pg[3] = { 0., 0., 0. };
308 matrix->LocalToMaster(pl, pg);
314 //_____________________________________________________________________________
316 AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
318 /// Convert a value into a color, fitting within a given range
322 if (value > max) rv = 1;
323 else if (value <= min) rv = 0;
326 // if ( TMath::AreEqualRel(max,min,1E-6) ) return gStyle->GetColorPalette(1);
327 if ( TMath::Abs(max-min) < 0.5*1E-6*TMath::Abs(max)+TMath::Abs(min) ) return gStyle->GetColorPalette(1);
328 Double_t range = max - min;
329 Double_t offset = value - min;
330 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
335 //_____________________________________________________________________________
337 AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
339 /// Merge a set of contours (delegating to the contour maker)
341 AliMUONContourMaker maker;
343 AliMUONContour* contour = maker.MergeContour(contours,contourName);
347 RegisterContour(contour,explodedGeometry);
353 //_____________________________________________________________________________
355 AliMUONPainterHelper::Print(Option_t* opt) const
361 if ( sopt.Length() == 0 )
363 if ( fExploded ) fExploded->Print();
364 if ( fReal ) fReal->Print();
368 //_____________________________________________________________________________
370 AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
372 /// contour is adopted by contourMaker
373 AliCodeTimerAuto("",0)
374 AliDebug(1,contour->GetName());
375 AliMUONContourHandler* ch = fReal;
382 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
386 if ( ch->GetContour(contour->GetName()) )
388 AliError(Form("Contour with name %s is already there",contour->GetName()));
395 //_____________________________________________________________________________
397 AliMUONPainterHelper::ChamberName(Int_t chamberId) const
399 /// Build a name for one chamber
400 return Form("Chamber%1d",chamberId+1);
403 //_____________________________________________________________________________
405 AliMUONPainterHelper::StationName(Int_t stationId) const
407 /// Build a name for one station
408 return Form("Station%1d",stationId+1);
411 //_____________________________________________________________________________
413 AliMUONPainterHelper::DEName(Int_t detElemId) const
415 /// Build a name for one detection element
416 return Form("DE%04d",detElemId);
419 //_____________________________________________________________________________
421 AliMUONPainterHelper::ManuName(Int_t manuId) const
423 /// Build a name for one manu
424 return Form("MANU%04d",manuId);
427 //_____________________________________________________________________________
429 AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
431 /// Build a name for one buspatch
432 return Form("BUSPATCH%04d",busPatchId);
435 //_____________________________________________________________________________
437 AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
439 /// Build a name for one pcb
440 return Form("PCB%1d",pcbNumber);
443 //_____________________________________________________________________________
445 AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
447 /// Build a name for one chamber
448 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
451 //_____________________________________________________________________________
453 AliMUONPainterHelper::StationPathName(Int_t stationId) const
455 /// Build a name for one station
456 return StationName(stationId);
459 //_____________________________________________________________________________
461 AliMUONPainterHelper::DEPathName(Int_t detElemId) const
463 /// Build a name for one detection element
465 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
467 return Form("%s/%s/%s",
468 StationName(chamberId/2).Data(),
469 ChamberName(chamberId).Data(),
470 DEName(detElemId).Data());
473 //_____________________________________________________________________________
475 AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
477 /// Build a name for one manu
478 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
481 //_____________________________________________________________________________
483 AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
485 /// Build a name for one buspatch
486 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
488 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
491 //_____________________________________________________________________________
493 AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
495 /// Build a name for one pcb
496 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
499 //_____________________________________________________________________________
501 AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
503 /// Format a double value to be displayed
504 /// FIXME: should insure we have the right number of significant digits here...
509 if (sname.Contains("BIT"))
511 Int_t i = (Int_t)(value);
512 TString rv = Form("%s = 0x%x",name,i);
513 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
518 return Form("%s = %e",name,value);
522 //_____________________________________________________________________________
524 AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
526 /// Get the contours in a specially arranged array (orderer by hierarchy level)
530 return Exploded()->AllContourArray();
534 return Real()->AllContourArray();