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
83 ClassImp(AliMUONPainterHelper)
86 AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0);
88 //_____________________________________________________________________________
89 AliMUONPainterHelper::AliMUONPainterHelper() :
97 if ( ! AliMpCDB::LoadMpSegmentation() )
99 AliFatal("Could not access mapping from OCDB !");
103 if ( ! AliMpCDB::LoadDDLStore() )
105 AliFatal("Could not access DDL Store from OCDB !");
109 //_____________________________________________________________________________
110 AliMUONPainterHelper::~AliMUONPainterHelper()
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);
157 //_____________________________________________________________________________
159 AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
161 /// Get the cathode type of a given manu
163 AliMp::PlaneType planeType(AliMp::kBendingPlane);
164 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
166 planeType = AliMp::kNonBendingPlane;
168 return AliMpDEManager::GetCathod(detElemId,planeType);
172 //_____________________________________________________________________________
174 AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
176 /// Get a given motif position
177 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
180 return vseg->MotifPosition(manuId);
185 //_____________________________________________________________________________
187 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
188 Int_t pcbNumber) const
191 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
192 if ( slat ) return slat->GetPCB(pcbNumber);
196 //_____________________________________________________________________________
198 AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
199 Int_t pcbNumber) const
202 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
204 return GetPCB(detElemId,cathodeType,pcbNumber);
207 //_____________________________________________________________________________
209 AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
211 /// Get the planeType of a given manu
213 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
215 return AliMp::kNonBendingPlane;
217 return AliMp::kBendingPlane;
220 //_____________________________________________________________________________
222 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
226 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
229 return GetSlat(detElemId,cathodeType);
232 //_____________________________________________________________________________
234 AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
236 /// Get a given sector
237 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
238 if ( stationType != AliMp::kStation12 ) return 0x0;
240 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
242 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
245 //_____________________________________________________________________________
247 AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
250 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
251 if ( stationType != AliMp::kStation345 ) return 0x0;
253 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
256 //_____________________________________________________________________________
258 AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
261 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
262 if ( stationType != AliMp::kStation345 ) return 0x0;
264 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
267 //_____________________________________________________________________________
268 AliMUONPainterHelper*
269 AliMUONPainterHelper::Instance()
271 /// Return the global and unique instance of this class
273 if (fgInstance) return fgInstance;
275 AliCodeTimerAutoClass("",0);
277 fgInstance = new AliMUONPainterHelper;
278 fgInstance->fEnv = new AliMUONPainterEnv;
282 //_____________________________________________________________________________
284 AliMUONPainterHelper::Global2Local(Int_t detElemId,
285 Double_t xg, Double_t yg, Double_t zg,
286 Double_t& xl, Double_t& yl, Double_t& zl) const
288 /// Local to global transformation of coordinates
290 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
291 Double_t pg[3] = { xg, yg, zg };
292 Double_t pl[3] = { 0., 0., 0. };
293 matrix->MasterToLocal(pg, pl);
299 //_____________________________________________________________________________
301 AliMUONPainterHelper::Local2Global(Int_t detElemId,
302 Double_t xl, Double_t yl, Double_t zl,
303 Double_t& xg, Double_t& yg, Double_t& zg) const
305 /// Local to (exploded) global transformation of coordinates
307 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
308 Double_t pl[3] = { xl, yl, zl };
309 Double_t pg[3] = { 0., 0., 0. };
310 matrix->LocalToMaster(pl, pg);
316 //_____________________________________________________________________________
318 AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
320 /// Convert a value into a color, fitting within a given range
324 if (value > max) rv = 1;
325 else if (value <= min) rv = 0;
328 if ( TMath::AreEqualRel(max,min,1E-6) ) return gStyle->GetColorPalette(1);
329 Double_t range = max - min;
330 Double_t offset = value - min;
331 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
336 //_____________________________________________________________________________
338 AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
340 /// Merge a set of contours (delegating to the contour maker)
342 AliMUONContourMaker maker;
344 AliMUONContour* contour = maker.MergeContour(contours,contourName);
348 RegisterContour(contour,explodedGeometry);
354 //_____________________________________________________________________________
356 AliMUONPainterHelper::Print(Option_t* opt) const
362 if ( sopt.Length() == 0 )
364 if ( fExploded ) fExploded->Print();
365 if ( fReal ) fReal->Print();
369 //_____________________________________________________________________________
371 AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
373 /// contour is adopted by contourMaker
374 AliCodeTimerAuto("",0)
375 AliDebug(1,contour->GetName());
376 AliMUONContourHandler* ch = fReal;
383 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
387 if ( ch->GetContour(contour->GetName()) )
389 AliError(Form("Contour with name %s is already there",contour->GetName()));
396 //_____________________________________________________________________________
398 AliMUONPainterHelper::ChamberName(Int_t chamberId) const
400 /// Build a name for one chamber
401 return Form("Chamber%1d",chamberId+1);
404 //_____________________________________________________________________________
406 AliMUONPainterHelper::StationName(Int_t stationId) const
408 /// Build a name for one station
409 return Form("Station%1d",stationId+1);
412 //_____________________________________________________________________________
414 AliMUONPainterHelper::DEName(Int_t detElemId) const
416 /// Build a name for one detection element
417 return Form("DE%04d",detElemId);
420 //_____________________________________________________________________________
422 AliMUONPainterHelper::ManuName(Int_t manuId) const
424 /// Build a name for one manu
425 return Form("MANU%04d",manuId);
428 //_____________________________________________________________________________
430 AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
432 /// Build a name for one buspatch
433 return Form("BUSPATCH%04d",busPatchId);
436 //_____________________________________________________________________________
438 AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
440 /// Build a name for one pcb
441 return Form("PCB%1d",pcbNumber);
444 //_____________________________________________________________________________
446 AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
448 /// Build a name for one chamber
449 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
452 //_____________________________________________________________________________
454 AliMUONPainterHelper::StationPathName(Int_t stationId) const
456 /// Build a name for one station
457 return StationName(stationId);
460 //_____________________________________________________________________________
462 AliMUONPainterHelper::DEPathName(Int_t detElemId) const
464 /// Build a name for one detection element
466 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
470 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
474 ddl = AliDAQ::DdlIDOffset("MUONTRK") + de->GetDdlId();
477 return Form("%s/%s/%s(DDL%4d)",
478 StationName(chamberId/2).Data(),
479 ChamberName(chamberId).Data(),
480 DEName(detElemId).Data(),
484 //_____________________________________________________________________________
486 AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
488 /// Build a name for one manu
489 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
492 //_____________________________________________________________________________
494 AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
496 /// Build a name for one buspatch
497 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
499 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
502 //_____________________________________________________________________________
504 AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
506 /// Build a name for one pcb
507 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
510 //_____________________________________________________________________________
512 AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
514 /// Format a double value to be displayed
515 /// FIXME: should insure we have the right number of significant digits here...
520 if (sname.Contains("BIT"))
522 Int_t i = (Int_t)(value);
523 TString rv = Form("%s = 0x%x",name,i);
524 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
529 return Form("%s = %e",name,value);
533 //_____________________________________________________________________________
535 AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
537 /// Get the contours in a specially arranged array (orderer by hierarchy level)
541 return Exploded()->AllContourArray();
545 return Real()->AllContourArray();