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"
24 #include "AliMUONContour.h"
25 #include "AliMUONContourHandler.h"
26 #include "AliMUONContourMaker.h"
27 #include "AliMUONGeometryDetElement.h"
28 #include "AliMUONGeometryTransformer.h"
29 #include "AliMUONManuContourMaker.h"
30 #include "AliMUONPainterEnv.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 "AliMpDetElement.h"
42 #include "AliMpExMap.h"
43 #include "AliMpMotifMap.h"
44 #include "AliMpMotifPosition.h"
47 #include "AliMpSector.h"
48 #include "AliMpSegmentation.h"
49 #include "AliMpSlat.h"
50 #include "AliMpStationType.h"
51 #include "AliMpVPadIterator.h"
52 #include <Riostream.h>
56 #include <TCollection.h>
60 #include <TGeoMatrix.h>
65 #include <TObjArray.h>
66 #include <TObjString.h>
71 #include <TVirtualPad.h>
72 #include <TVirtualX.h>
74 #include "AliMUONChamberPainter.h"
76 ///\class AliMUONPainterHelper
78 /// Helper class for painters
80 ///\author Laurent Aphecetche, Subatech
85 ClassImp(AliMUONPainterHelper)
88 AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0);
90 //_____________________________________________________________________________
91 AliMUONPainterHelper::AliMUONPainterHelper() :
99 if ( ! AliMpCDB::LoadMpSegmentation() )
101 AliFatal("Could not access mapping from OCDB !");
105 if ( ! AliMpCDB::LoadDDLStore() )
107 AliFatal("Could not access DDL Store from OCDB !");
111 //_____________________________________________________________________________
112 AliMUONPainterHelper::~AliMUONPainterHelper()
121 //_____________________________________________________________________________
122 AliMUONContourHandler*
123 AliMUONPainterHelper::Exploded() const
125 /// Create exploded contour handler
126 if (!fExploded) fExploded = new AliMUONContourHandler(kTRUE);
130 //_____________________________________________________________________________
131 AliMUONContourHandler*
132 AliMUONPainterHelper::Real() const
134 /// Create real contour handler
135 if (!fReal) fReal = new AliMUONContourHandler(kFALSE);
139 //_____________________________________________________________________________
141 AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
143 /// Get a contour by name
146 return Exploded()->GetContour(contourName);
152 return fReal->GetContour(contourName);
159 //_____________________________________________________________________________
161 AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
163 /// Get the cathode type of a given manu
165 AliMp::PlaneType planeType(AliMp::kBendingPlane);
166 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
168 planeType = AliMp::kNonBendingPlane;
170 return AliMpDEManager::GetCathod(detElemId,planeType);
174 //_____________________________________________________________________________
176 AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
178 /// Get a given motif position
179 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
182 return vseg->MotifPosition(manuId);
187 //_____________________________________________________________________________
189 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
190 Int_t pcbNumber) const
193 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
194 if ( slat ) return slat->GetPCB(pcbNumber);
198 //_____________________________________________________________________________
200 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
201 Int_t pcbNumber) const
204 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
206 return GetPCB(detElemId,cathodeType,pcbNumber);
209 //_____________________________________________________________________________
211 AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
213 /// Get the planeType of a given manu
215 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
217 return AliMp::kNonBendingPlane;
219 return AliMp::kBendingPlane;
222 //_____________________________________________________________________________
224 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
228 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
231 return GetSlat(detElemId,cathodeType);
234 //_____________________________________________________________________________
236 AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
238 /// Get a given sector
239 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
240 if ( stationType != AliMp::kStation12 ) return 0x0;
242 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
244 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
247 //_____________________________________________________________________________
249 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
252 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
253 if ( stationType != AliMp::kStation345 ) return 0x0;
255 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
258 //_____________________________________________________________________________
260 AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
263 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
264 if ( stationType != AliMp::kStation345 ) return 0x0;
266 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
269 //_____________________________________________________________________________
270 AliMUONPainterHelper*
271 AliMUONPainterHelper::Instance()
273 /// Return the global and unique instance of this class
275 if (fgInstance) return fgInstance;
277 AliCodeTimerAutoClass("",0);
279 fgInstance = new AliMUONPainterHelper;
280 fgInstance->fEnv = new AliMUONPainterEnv;
284 //_____________________________________________________________________________
286 AliMUONPainterHelper::Global2Local(Int_t detElemId,
287 Double_t xg, Double_t yg, Double_t zg,
288 Double_t& xl, Double_t& yl, Double_t& zl) const
290 /// Local to global transformation of coordinates
292 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
293 Double_t pg[3] = { xg, yg, zg };
294 Double_t pl[3] = { 0., 0., 0. };
295 matrix->MasterToLocal(pg, pl);
301 //_____________________________________________________________________________
303 AliMUONPainterHelper::Local2Global(Int_t detElemId,
304 Double_t xl, Double_t yl, Double_t zl,
305 Double_t& xg, Double_t& yg, Double_t& zg) const
307 /// Local to (exploded) global transformation of coordinates
309 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
310 Double_t pl[3] = { xl, yl, zl };
311 Double_t pg[3] = { 0., 0., 0. };
312 matrix->LocalToMaster(pl, pg);
318 //_____________________________________________________________________________
320 AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
322 /// Convert a value into a color, fitting within a given range
326 if (value > max) rv = 1;
327 else if (value <= min) rv = 0;
330 if ( TMath::AreEqualRel(max,min,1E-6) ) return gStyle->GetColorPalette(1);
331 Double_t range = max - min;
332 Double_t offset = value - min;
333 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
338 //_____________________________________________________________________________
340 AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
342 /// Merge a set of contours (delegating to the contour maker)
344 AliMUONContourMaker maker;
346 AliMUONContour* contour = maker.MergeContour(contours,contourName);
350 RegisterContour(contour,explodedGeometry);
356 //_____________________________________________________________________________
358 AliMUONPainterHelper::Print(Option_t* opt) const
364 if ( sopt.Length() == 0 )
366 if ( fExploded ) fExploded->Print();
367 if ( fReal ) fReal->Print();
371 //_____________________________________________________________________________
373 AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
375 /// contour is adopted by contourMaker
376 AliCodeTimerAuto("",0)
377 AliDebug(1,contour->GetName());
378 AliMUONContourHandler* ch = fReal;
385 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
389 if ( ch->GetContour(contour->GetName()) )
391 AliError(Form("Contour with name %s is already there",contour->GetName()));
398 //_____________________________________________________________________________
400 AliMUONPainterHelper::ChamberName(Int_t chamberId) const
402 /// Build a name for one chamber
403 return Form("Chamber%1d",chamberId+1);
406 //_____________________________________________________________________________
408 AliMUONPainterHelper::StationName(Int_t stationId) const
410 /// Build a name for one station
411 return Form("Station%1d",stationId+1);
414 //_____________________________________________________________________________
416 AliMUONPainterHelper::DEName(Int_t detElemId) const
418 /// Build a name for one detection element
419 return Form("DE%04d",detElemId);
422 //_____________________________________________________________________________
424 AliMUONPainterHelper::ManuName(Int_t manuId) const
426 /// Build a name for one manu
427 return Form("MANU%04d",manuId);
430 //_____________________________________________________________________________
432 AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
434 /// Build a name for one buspatch
435 return Form("BUSPATCH%04d",busPatchId);
438 //_____________________________________________________________________________
440 AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
442 /// Build a name for one pcb
443 return Form("PCB%1d",pcbNumber);
446 //_____________________________________________________________________________
448 AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
450 /// Build a name for one chamber
451 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
454 //_____________________________________________________________________________
456 AliMUONPainterHelper::StationPathName(Int_t stationId) const
458 /// Build a name for one station
459 return StationName(stationId);
462 //_____________________________________________________________________________
464 AliMUONPainterHelper::DEPathName(Int_t detElemId) const
466 /// Build a name for one detection element
468 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
472 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
476 ddl = AliDAQ::DdlIDOffset("MUONTRK") + de->GetDdlId();
479 return Form("%s/%s/%s(DDL%4d)",
480 StationName(chamberId/2).Data(),
481 ChamberName(chamberId).Data(),
482 DEName(detElemId).Data(),
486 //_____________________________________________________________________________
488 AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
490 /// Build a name for one manu
491 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
494 //_____________________________________________________________________________
496 AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
498 /// Build a name for one buspatch
499 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
501 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
504 //_____________________________________________________________________________
506 AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
508 /// Build a name for one pcb
509 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
512 //_____________________________________________________________________________
514 AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
516 /// Format a double value to be displayed
517 /// FIXME: should insure we have the right number of significant digits here...
522 if (sname.Contains("BIT"))
524 Int_t i = (Int_t)(value);
525 TString rv = Form("%s = 0x%x",name,i);
526 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
531 return Form("%s = %e",name,value);
535 //_____________________________________________________________________________
537 AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
539 /// Get the contours in a specially arranged array (orderer by hierarchy level)
543 return Exploded()->AllContourArray();
547 return Real()->AllContourArray();