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 "AliMUONContourMaker.h"
25 #include "AliMUONGeometryDetElement.h"
26 #include "AliMUONGeometryTransformer.h"
27 #include "AliMUONManuContourMaker.h"
28 #include "AliMUONPainterEnv.h"
29 #include "AliMUONPainterMatrix.h"
30 #include "AliMUONPainterRegistry.h"
31 #include "AliMUONVCalibParam.h"
32 #include "AliMUONVDigit.h"
33 #include "AliMUONVTrackerData.h"
35 #include "AliMpConstants.h"
36 #include "AliMpDDLStore.h"
37 #include "AliMpDEIterator.h"
38 #include "AliMpDEManager.h"
39 #include "AliMpExMap.h"
40 #include "AliMpMotifMap.h"
41 #include "AliMpMotifPosition.h"
44 #include "AliMpSector.h"
45 #include "AliMpSegmentation.h"
46 #include "AliMpSlat.h"
47 #include "AliMpStationType.h"
48 #include "AliMpVPadIterator.h"
49 #include <Riostream.h>
53 #include <TCollection.h>
57 #include <TGeoMatrix.h>
61 #include <TObjArray.h>
62 #include <TObjString.h>
67 #include <TVirtualPad.h>
68 #include <TVirtualX.h>
70 #include "AliMUONChamberPainter.h"
72 ///\class AliMUONPainterHelper
74 /// Helper class for painters
76 ///\author Laurent Aphecetche, Subatech
79 ClassImp(AliMUONPainterHelper)
82 AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0);
84 //_____________________________________________________________________________
85 AliMUONPainterHelper::AliMUONPainterHelper() :
87 fExplodedGlobalTransformations(0x0),
88 fRealGlobalTransformations(0x0),
89 fPainterMatrices(0x0),
95 fAllContours.SetOwnerKeyValue(kTRUE,kTRUE);
97 fExplodeFactor[0] = 1.00;
98 fExplodeFactor[1] = 1.50;
100 if ( ! AliMpCDB::LoadMpSegmentation() )
102 AliFatal("Could not access mapping from OCDB !");
106 if ( ! AliMpCDB::LoadDDLStore() )
108 AliFatal("Could not access DDL Store from OCDB !");
112 //_____________________________________________________________________________
113 AliMUONPainterHelper::~AliMUONPainterHelper()
116 delete fExplodedGlobalTransformations;
117 delete fRealGlobalTransformations;
118 delete fPainterMatrices;
123 //_____________________________________________________________________________
125 AliMUONPainterHelper::GetContour(const char* contourName) const
127 /// Get a contour by name
128 return static_cast<AliMUONContour*>(fAllContours.GetValue(contourName));
131 //_____________________________________________________________________________
133 AliMUONPainterHelper::GenerateDefaultMatrices()
135 /// Kind of bootstrap method to trigger the generation of all contours
137 AliCodeTimerAuto("");
139 fPainterMatrices = new TObjArray;
140 fPainterMatrices->SetOwner(kFALSE);
142 TObjArray attributes;
144 AliMUONAttPainter att;
146 att.SetViewPoint(kTRUE,kFALSE);
147 att.SetPlane(kFALSE,kFALSE);
148 att.SetCathode(kTRUE,kFALSE);
150 att.SetCathode(kFALSE,kFALSE);
151 att.SetPlane(kTRUE,kFALSE);
152 attributes.Add(new AliMUONAttPainter(att));
154 // commented the lines below, as it's now fast enough to be created on the fly,
155 // only when requested by the user
157 // attributes.Add(new AliMUONAttPainter(att));
158 // att.SetCathode(kFALSE,kTRUE);
159 // attributes.Add(new AliMUONAttPainter(att));
160 // att.SetPlane(kFALSE,kTRUE);
161 // attributes.Add(new AliMUONAttPainter(att));
163 TIter next(&attributes);
164 AliMUONAttPainter* a;
166 while ( ( a = static_cast<AliMUONAttPainter*>(next()) ) )
168 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
170 for ( Int_t i = 0; i < 10; ++i )
172 AliMUONVPainter* painter = new AliMUONChamberPainter(*a,i);
174 painter->SetResponder("Chamber");
176 painter->SetOutlined("*",kFALSE);
178 painter->SetOutlined("MANU",kTRUE);
180 for ( Int_t j = 0; j < 3; ++j )
182 painter->SetLine(j,1,4-j);
185 matrix->Adopt(painter);
187 AliMUONPainterRegistry::Instance()->Register(matrix);
188 fPainterMatrices->Add(matrix);
192 //_____________________________________________________________________________
194 AliMUONPainterHelper::GenerateGeometry()
196 /// Generate the geometry (FIXME: using transform.dat for the moment)
197 /// The geometry is not the "normal" one as we "explode" it to avoid
198 /// having overlapping detection elements as in the reality, which
199 /// would be inconvenient for a display ;-)
201 AliCodeTimerAuto("");
203 AliMUONGeometryTransformer transformer;
204 transformer.LoadGeometryData("transform.dat");
205 fExplodedGlobalTransformations = new AliMpExMap;
206 fRealGlobalTransformations = new AliMpExMap;
207 AliMpDEIterator deIt;
209 while ( !deIt.IsDone() )
211 Int_t detElemId = deIt.CurrentDEId();
212 const AliMUONGeometryDetElement* de = transformer.GetDetElement(detElemId);
214 fRealGlobalTransformations->Add(detElemId,de->GetGlobalTransformation()->Clone());
216 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(de->GetGlobalTransformation()->Clone());
217 Double_t* translation = matrix->GetTranslation();
219 AliDebug(1,Form("Initial translation for DE %04d is %7.3f, %7.3f",
220 detElemId,translation[0],translation[1]));
222 if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345 )
224 translation[0] *= fExplodeFactor[0];
225 translation[1] *= fExplodeFactor[1];
229 Double_t shift = 5; // cm
230 Double_t xshift[] = { shift, -shift, -shift, shift };
231 Double_t yshift[] = { shift, shift, -shift, -shift };
232 Int_t ishift = detElemId % 100;
234 translation[0] += xshift[ishift];
235 translation[1] += yshift[ishift];
237 matrix->SetTranslation(translation);
238 fExplodedGlobalTransformations->Add(detElemId,matrix);
243 //_____________________________________________________________________________
245 AliMUONPainterHelper::GenerateManuContour(Int_t detElemId,
247 AliMUONAttPainter viewType,
248 const char* contourName)
250 /// Generate the contour of the list of pads
252 static AliMUONManuContourMaker maker(fExplodedGlobalTransformations);
254 if ( viewType.IsBackView() )
256 AliError("Backview not implemented yet (and will probably never be, after all...)");
260 AliMUONContour* contour = maker.CreateManuContour(detElemId,manuId,contourName);
262 if ( !contour ) return 0x0;
264 AliMUONContour* pContour = new AliMUONContour(*contour);
268 RegisterContour(pContour);
274 //_____________________________________________________________________________
276 AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
278 /// Get the cathode type of a given manu
280 AliMp::PlaneType planeType(AliMp::kBendingPlane);
281 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
283 planeType = AliMp::kNonBendingPlane;
285 return AliMpDEManager::GetCathod(detElemId,planeType);
289 //_____________________________________________________________________________
291 AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
293 /// Get a given motif position
294 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
295 if ( stationType == AliMp::kStation345 )
297 AliMp::PlaneType planeType(AliMp::kBendingPlane);
298 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
300 planeType = AliMp::kNonBendingPlane;
302 const AliMpSlat* slat = GetSlat(detElemId,planeType);
303 return slat->FindMotifPosition(manuId);
305 else if ( stationType != AliMp::kStationTrigger )
307 AliMp::PlaneType planeType(AliMp::kBendingPlane);
308 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
310 planeType = AliMp::kNonBendingPlane;
312 const AliMpSector* sector = GetSector(detElemId,planeType);
313 return sector->GetMotifMap()->FindMotifPosition(manuId);
315 AliFatalClass("Not supposed to work with trigger");
320 //_____________________________________________________________________________
322 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
323 Int_t pcbNumber) const
326 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
327 if ( slat ) return slat->GetPCB(pcbNumber);
331 //_____________________________________________________________________________
333 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
334 Int_t pcbNumber) const
337 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
339 return GetPCB(detElemId,cathodeType,pcbNumber);
342 //_____________________________________________________________________________
344 AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
346 /// Get the planeType of a given manu
348 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
350 return AliMp::kNonBendingPlane;
352 return AliMp::kBendingPlane;
355 //_____________________________________________________________________________
357 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
361 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
364 return GetSlat(detElemId,cathodeType);
367 //_____________________________________________________________________________
369 AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
371 /// Get a given sector
372 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
373 if ( stationType != AliMp::kStation12 ) return 0x0;
375 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
377 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
380 //_____________________________________________________________________________
382 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
385 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
386 if ( stationType != AliMp::kStation345 ) return 0x0;
388 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
391 //_____________________________________________________________________________
393 AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
396 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
397 if ( stationType != AliMp::kStation345 ) return 0x0;
399 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
402 //_____________________________________________________________________________
403 AliMUONPainterHelper*
404 AliMUONPainterHelper::Instance()
406 /// Return the global and unique instance of this class
408 if (fgInstance) return fgInstance;
410 AliCodeTimerAutoClass("");
412 fgInstance = new AliMUONPainterHelper;
413 fgInstance->GenerateGeometry();
414 fgInstance->GenerateDefaultMatrices();
415 fgInstance->fEnv = new AliMUONPainterEnv;
419 //_____________________________________________________________________________
421 AliMUONPainterHelper::Global2Local(Int_t detElemId,
422 Double_t xg, Double_t yg, Double_t zg,
423 Double_t& xl, Double_t& yl, Double_t& zl) const
425 /// Local to global transformation of coordinates
427 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExplodedGlobalTransformations->GetValue(detElemId));
428 Double_t pg[3] = { xg, yg, zg };
429 Double_t pl[3] = { 0., 0., 0. };
430 matrix->MasterToLocal(pg, pl);
436 //_____________________________________________________________________________
438 AliMUONPainterHelper::Global2LocalReal(Int_t detElemId,
439 Double_t xg, Double_t yg, Double_t zg,
440 Double_t& xl, Double_t& yl, Double_t& zl) const
442 /// Local to global transformation of coordinates
444 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fRealGlobalTransformations->GetValue(detElemId));
445 Double_t pg[3] = { xg, yg, zg };
446 Double_t pl[3] = { 0., 0., 0. };
447 matrix->MasterToLocal(pg, pl);
453 //_____________________________________________________________________________
455 AliMUONPainterHelper::Local2Global(Int_t detElemId,
456 Double_t xl, Double_t yl, Double_t zl,
457 Double_t& xg, Double_t& yg, Double_t& zg) const
459 /// Local to (exploded) global transformation of coordinates
461 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExplodedGlobalTransformations->GetValue(detElemId));
462 Double_t pl[3] = { xl, yl, zl };
463 Double_t pg[3] = { 0., 0., 0. };
464 matrix->LocalToMaster(pl, pg);
470 //_____________________________________________________________________________
472 AliMUONPainterHelper::Local2GlobalReal(Int_t detElemId,
473 Double_t xl, Double_t yl, Double_t zl,
474 Double_t& xg, Double_t& yg, Double_t& zg) const
476 /// Local to (real) global transformation of coordinates
478 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fRealGlobalTransformations->GetValue(detElemId));
479 Double_t pl[3] = { xl, yl, zl };
480 Double_t pg[3] = { 0., 0., 0. };
481 matrix->LocalToMaster(pl, pg);
487 //_____________________________________________________________________________
489 AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
491 /// Convert a value into a color, fitting within a given range
495 if (value > max) rv = 1;
496 else if (value <= min) rv = 0;
499 if ( max == min ) return gStyle->GetColorPalette(1);
500 Double_t range = max - min;
501 Double_t offset = value - min;
502 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
507 //_____________________________________________________________________________
509 AliMUONPainterHelper::MergeContours(const TObjArray& contours,
510 const char* contourName)
512 /// Merge a set of contours (delegating to the contour maker)
514 AliMUONContourMaker maker;
516 AliMUONContour* contour = maker.MergeContour(contours,contourName);
520 RegisterContour(contour);
526 //_____________________________________________________________________________
528 AliMUONPainterHelper::Print(Option_t* opt) const
534 if ( sopt.Length() == 0 )
536 cout << Form("ExplodeFactor=%e,%e",fExplodeFactor[0],fExplodeFactor[1]) << endl;
538 cout << Form("GlobalTransformations=%x",fExplodedGlobalTransformations);
539 if ( fExplodedGlobalTransformations ) cout << Form(" with %d transformations",fExplodedGlobalTransformations->GetSize());
541 cout << Form("Contour map : collisions = %5.3f size = %d capacity = %d",
542 fAllContours.AverageCollisions(),
543 fAllContours.GetSize(),
544 fAllContours.Capacity()) << endl;
548 if ( sopt.Contains("MATRI") || sopt.Contains("FULL") )
550 fPainterMatrices->Print(opt);
554 //_____________________________________________________________________________
556 AliMUONPainterHelper::RegisterContour(AliMUONContour* contour)
558 /// contour is adopted by contourMaker
560 AliDebug(1,contour->GetName());
561 if ( fAllContours.GetValue(contour->GetName()) )
563 AliError(Form("Contour with name %s is already there",contour->GetName()));
567 fAllContours.Add(new TObjString(contour->GetName()),contour);
570 //_____________________________________________________________________________
572 AliMUONPainterHelper::PadByExplodedPosition(Int_t detElemId, Int_t manuId,
573 Double_t x, Double_t y) const
575 /// Find a pad by exploded position. FIXME: not really used nor tested !
579 // Local2Global(detElemId,0.0,0.0,0.0,dummy,dummy,z); // to find z
581 AliDebug(1,Form("DE %04d ManuID %04d x %7.3f y %7.3f",detElemId,manuId,x,y));
583 Exploded2Real(detElemId,x,y,0,xr,yr,zr);
585 AliDebug(1,Form("xr %7.3f yr %7.3f zr %7.3f",xr,yr,zr));
589 Global2LocalReal(detElemId,xr,yr,zr,xl,yl,zl);
591 AliDebug(1,Form("xl %7.3f yl %7.3f zl %7.3f",xl,yl,zl));
593 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
595 AliDebug(1,Form("dx,dy=%7.3f,%7.3f",seg->GetDimensionX(),seg->GetDimensionY()));
597 return seg->PadByPosition(xl,yl);
600 //_____________________________________________________________________________
602 AliMUONPainterHelper::Exploded2Real(Int_t detElemId,
603 Double_t xe, Double_t ye, Double_t ze,
604 Double_t& xr, Double_t& yr, Double_t& zr) const
606 /// Convert exploded coordinates into real ones. FIXME: not really used nor tested !
608 // first go back to local
612 Global2Local(detElemId,xe,ye,ze,xl,yl,zl);
614 // and then back to global but not exploded
616 Local2GlobalReal(detElemId,xl,yl,zl,xr,yr,zr);
619 //_____________________________________________________________________________
621 AliMUONPainterHelper::ChamberName(Int_t chamberId) const
623 /// Build a name for one chamber
624 return Form("Chamber%1d",chamberId);
627 //_____________________________________________________________________________
629 AliMUONPainterHelper::StationName(Int_t stationId) const
631 /// Build a name for one station
632 return Form("Station%1d",stationId+1);
635 //_____________________________________________________________________________
637 AliMUONPainterHelper::DEName(Int_t detElemId) const
639 /// Build a name for one detection element
640 return Form("DE%04d",detElemId);
643 //_____________________________________________________________________________
645 AliMUONPainterHelper::ManuName(Int_t manuId) const
647 /// Build a name for one manu
648 return Form("MANU%04d",manuId);
651 //_____________________________________________________________________________
653 AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
655 /// Build a name for one buspatch
656 return Form("BUSPATCH%04d",busPatchId);
659 //_____________________________________________________________________________
661 AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
663 /// Build a name for one pcb
664 return Form("PCB%1d",pcbNumber);
667 //_____________________________________________________________________________
669 AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
671 /// Build a name for one chamber
672 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
675 //_____________________________________________________________________________
677 AliMUONPainterHelper::StationPathName(Int_t stationId) const
679 /// Build a name for one station
680 return StationName(stationId);
683 //_____________________________________________________________________________
685 AliMUONPainterHelper::DEPathName(Int_t detElemId) const
687 /// Build a name for one detection element
689 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
691 return Form("%s/%s/%s",
692 StationName(chamberId/2).Data(),
693 ChamberName(chamberId).Data(),
694 DEName(detElemId).Data());
697 //_____________________________________________________________________________
699 AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
701 /// Build a name for one manu
702 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
705 //_____________________________________________________________________________
707 AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
709 /// Build a name for one buspatch
710 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
712 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
715 //_____________________________________________________________________________
717 AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
719 /// Build a name for one pcb
720 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
723 //_____________________________________________________________________________
725 AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
727 /// Format a double value to be displayed
728 /// FIXME: should insure we have the right number of significant digits here...
730 return Form("%s = %e",name,value);