Reverting previous commit as it breaks compilation
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterHelper.cxx
CommitLineData
0145e89a 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
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**************************************************************************/
15
16// $Id$
17
b09247a2 18#include <cstdlib>
0145e89a 19#include "AliMUONPainterHelper.h"
20
8f0acce4 21#include "AliCodeTimer.h"
22#include "AliLog.h"
23#include "AliMUONContour.h"
fef32488 24#include "AliMUONContourHandler.h"
8f0acce4 25#include "AliMUONContourMaker.h"
0145e89a 26#include "AliMUONGeometryDetElement.h"
27#include "AliMUONGeometryTransformer.h"
8f0acce4 28#include "AliMUONManuContourMaker.h"
0145e89a 29#include "AliMUONPainterEnv.h"
30#include "AliMUONPainterMatrix.h"
0145e89a 31#include "AliMUONPainterRegistry.h"
fef32488 32#include "AliMUONPadStatusMaker.h"
0145e89a 33#include "AliMUONVCalibParam.h"
34#include "AliMUONVDigit.h"
35#include "AliMUONVTrackerData.h"
36#include "AliMpCDB.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"
44#include "AliMpPCB.h"
45#include "AliMpPad.h"
46#include "AliMpSector.h"
0145e89a 47#include "AliMpSegmentation.h"
48#include "AliMpSlat.h"
0145e89a 49#include "AliMpStationType.h"
50#include "AliMpVPadIterator.h"
0145e89a 51#include <Riostream.h>
52#include <TArrayI.h>
53#include <TCanvas.h>
54#include <TClass.h>
55#include <TCollection.h>
56#include <TFile.h>
57#include <TGLabel.h>
0145e89a 58#include <TGMsgBox.h>
8f0acce4 59#include <TGeoMatrix.h>
0145e89a 60#include <TLine.h>
61#include <TList.h>
62#include <TMap.h>
63#include <TObjArray.h>
64#include <TObjString.h>
65#include <TStyle.h>
66#include <TSystem.h>
67#include <TVector2.h>
68#include <TVector3.h>
69#include <TVirtualPad.h>
70#include <TVirtualX.h>
71
8f0acce4 72#include "AliMUONChamberPainter.h"
73
0145e89a 74///\class AliMUONPainterHelper
75///
76/// Helper class for painters
77///
78///\author Laurent Aphecetche, Subatech
79
80///\cond CLASSIMP
81ClassImp(AliMUONPainterHelper)
82///\endcond
83
84AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0);
85
86//_____________________________________________________________________________
87AliMUONPainterHelper::AliMUONPainterHelper() :
8f0acce4 88TObject(),
8f0acce4 89fPainterMatrices(0x0),
90fEnv(0x0),
fef32488 91fReal(0x0),
92fExploded(0x0)
0145e89a 93{
fef32488 94 /// ctor
8f0acce4 95
fef32488 96 if ( ! AliMpCDB::LoadMpSegmentation() )
97 {
98 AliFatal("Could not access mapping from OCDB !");
99 }
8f0acce4 100
fef32488 101 // Load DDL store
102 if ( ! AliMpCDB::LoadDDLStore() )
103 {
104 AliFatal("Could not access DDL Store from OCDB !");
105 }
106
107 fExploded = new AliMUONContourHandler(kTRUE);
0145e89a 108}
109
110//_____________________________________________________________________________
111AliMUONPainterHelper::~AliMUONPainterHelper()
112{
113 /// dtor
0145e89a 114 delete fPainterMatrices;
fef32488 115 delete fReal;
116 delete fExploded;
8f0acce4 117 fEnv->Save();
0145e89a 118 fgInstance = 0;
119}
120
121//_____________________________________________________________________________
8f0acce4 122AliMUONContour*
fef32488 123AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
0145e89a 124{
8f0acce4 125 /// Get a contour by name
fef32488 126 if (explodedView)
127 {
128 return fExploded->GetContour(contourName);
129 }
130 else
131 {
132 if ( fReal )
133 {
134 return fReal->GetContour(contourName);
135 }
136 }
137 return 0x0;
0145e89a 138}
139
140//_____________________________________________________________________________
141void
142AliMUONPainterHelper::GenerateDefaultMatrices()
143{
144 /// Kind of bootstrap method to trigger the generation of all contours
145
70d92702 146 AliCodeTimerAuto("",);
8f0acce4 147
0145e89a 148 fPainterMatrices = new TObjArray;
149 fPainterMatrices->SetOwner(kFALSE);
150
151 TObjArray attributes;
152
153 AliMUONAttPainter att;
154
155 att.SetViewPoint(kTRUE,kFALSE);
0145e89a 156 att.SetCathode(kFALSE,kFALSE);
157 att.SetPlane(kTRUE,kFALSE);
158 attributes.Add(new AliMUONAttPainter(att));
8f0acce4 159
0145e89a 160 TIter next(&attributes);
161 AliMUONAttPainter* a;
162
163 while ( ( a = static_cast<AliMUONAttPainter*>(next()) ) )
164 {
165 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
166
167 for ( Int_t i = 0; i < 10; ++i )
168 {
8f0acce4 169 AliMUONVPainter* painter = new AliMUONChamberPainter(*a,i);
0145e89a 170
171 painter->SetResponder("Chamber");
172
173 painter->SetOutlined("*",kFALSE);
174
175 painter->SetOutlined("MANU",kTRUE);
176
177 for ( Int_t j = 0; j < 3; ++j )
178 {
179 painter->SetLine(j,1,4-j);
180 }
181
182 matrix->Adopt(painter);
183 }
184 AliMUONPainterRegistry::Instance()->Register(matrix);
185 fPainterMatrices->Add(matrix);
186 }
187}
188
189//_____________________________________________________________________________
0145e89a 190AliMp::CathodType
191AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
192{
193 /// Get the cathode type of a given manu
194
195 AliMp::PlaneType planeType(AliMp::kBendingPlane);
196 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
197 {
198 planeType = AliMp::kNonBendingPlane;
199 }
200 return AliMpDEManager::GetCathod(detElemId,planeType);
201}
202
0145e89a 203
204//_____________________________________________________________________________
205AliMpMotifPosition*
206AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
207{
208 /// Get a given motif position
fef32488 209 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
210 if (vseg)
0145e89a 211 {
fef32488 212 return vseg->MotifPosition(manuId);
0145e89a 213 }
0145e89a 214 return 0x0;
215}
216
0145e89a 217//_____________________________________________________________________________
218AliMpPCB*
219AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
220 Int_t pcbNumber) const
221{
222 /// Get a given PCB
223 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
224 if ( slat ) return slat->GetPCB(pcbNumber);
225 return 0x0;
226}
227
228//_____________________________________________________________________________
229AliMpPCB*
230AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
231 Int_t pcbNumber) const
232{
233 /// Get a given PCB
234 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
235 planeType);
236 return GetPCB(detElemId,cathodeType,pcbNumber);
237}
238
239//_____________________________________________________________________________
240AliMp::PlaneType
241AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
242{
243 /// Get the planeType of a given manu
244
245 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
246 {
247 return AliMp::kNonBendingPlane;
248 }
249 return AliMp::kBendingPlane;
250}
251
252//_____________________________________________________________________________
253const AliMpSlat*
254AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
255{
256 /// Get a given slat
257
258 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
259 planeType);
260
261 return GetSlat(detElemId,cathodeType);
262}
263
264//_____________________________________________________________________________
265const AliMpSector*
266AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
267{
268 /// Get a given sector
269 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
4e51cfd2 270 if ( stationType != AliMp::kStation12 ) return 0x0;
0145e89a 271
272 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
273
f3ed9a44 274 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
0145e89a 275}
276
277//_____________________________________________________________________________
278const AliMpSlat*
279AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
280{
281 /// Get a given slat
282 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
283 if ( stationType != AliMp::kStation345 ) return 0x0;
284
f3ed9a44 285 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
0145e89a 286}
287
288//_____________________________________________________________________________
289const AliMpSlat*
290AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
291{
292 /// Get a given slat
f3ed9a44 293 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
294 if ( stationType != AliMp::kStation345 ) return 0x0;
295
296 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
0145e89a 297}
298
299//_____________________________________________________________________________
300AliMUONPainterHelper*
301AliMUONPainterHelper::Instance()
302{
303 /// Return the global and unique instance of this class
304
305 if (fgInstance) return fgInstance;
0145e89a 306
70d92702 307 AliCodeTimerAutoClass("",);
8f0acce4 308
309 fgInstance = new AliMUONPainterHelper;
8f0acce4 310 fgInstance->fEnv = new AliMUONPainterEnv;
0145e89a 311 return fgInstance;
312}
313
314//_____________________________________________________________________________
315void
316AliMUONPainterHelper::Global2Local(Int_t detElemId,
317 Double_t xg, Double_t yg, Double_t zg,
318 Double_t& xl, Double_t& yl, Double_t& zl) const
319{
320 /// Local to global transformation of coordinates
321
fef32488 322 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExploded->GetTransformations()->GetValue(detElemId));
0145e89a 323 Double_t pg[3] = { xg, yg, zg };
324 Double_t pl[3] = { 0., 0., 0. };
325 matrix->MasterToLocal(pg, pl);
326 xl = pl[0];
327 yl = pl[1];
328 zl = pl[2];
329}
330
331//_____________________________________________________________________________
332void
333AliMUONPainterHelper::Local2Global(Int_t detElemId,
334 Double_t xl, Double_t yl, Double_t zl,
335 Double_t& xg, Double_t& yg, Double_t& zg) const
336{
337 /// Local to (exploded) global transformation of coordinates
338
fef32488 339 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExploded->GetTransformations()->GetValue(detElemId));
0145e89a 340 Double_t pl[3] = { xl, yl, zl };
341 Double_t pg[3] = { 0., 0., 0. };
342 matrix->LocalToMaster(pl, pg);
343 xg = pg[0];
344 yg = pg[1];
345 zg = pg[2];
346}
347
348//_____________________________________________________________________________
349Int_t
350AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
351{
352 /// Convert a value into a color, fitting within a given range
353
354 Int_t rv;
355
356 if (value > max) rv = 1;
357 else if (value <= min) rv = 0;
358 else
359 {
360 if ( max == min ) return gStyle->GetColorPalette(1);
361 Double_t range = max - min;
362 Double_t offset = value - min;
363 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
364 }
365 return rv;
366}
367
368//_____________________________________________________________________________
8f0acce4 369AliMUONContour*
fef32488 370AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
0145e89a 371{
372 /// Merge a set of contours (delegating to the contour maker)
0145e89a 373
8f0acce4 374 AliMUONContourMaker maker;
375
376 AliMUONContour* contour = maker.MergeContour(contours,contourName);
0145e89a 377
378 if (contour)
379 {
fef32488 380 RegisterContour(contour,explodedGeometry);
0145e89a 381 }
382 return contour;
383}
384
385
386//_____________________________________________________________________________
387void
388AliMUONPainterHelper::Print(Option_t* opt) const
389{
390 /// Printout
391 TString sopt(opt);
392 sopt.ToUpper();
393
394 if ( sopt.Length() == 0 )
395 {
fef32488 396 if ( fExploded ) fExploded->Print();
397 if ( fReal ) fReal->Print();
0145e89a 398 }
399
fef32488 400 if ( fPainterMatrices && ( sopt.Contains("MATRI") || sopt.Contains("FULL") ) )
0145e89a 401 {
402 fPainterMatrices->Print(opt);
403 }
404}
405
406//_____________________________________________________________________________
407void
fef32488 408AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
0145e89a 409{
410 /// contour is adopted by contourMaker
70d92702 411 AliCodeTimerAuto("",)
0145e89a 412 AliDebug(1,contour->GetName());
fef32488 413 AliMUONContourHandler* ch = fReal;
414 if ( explodedView )
0145e89a 415 {
fef32488 416 ch = fExploded;
417 }
418 if (!ch)
419 {
420 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
421 }
422 else
423 {
424 if ( ch->GetContour(contour->GetName()) )
425 {
426 AliError(Form("Contour with name %s is already there",contour->GetName()));
427 return;
428 }
429 ch->Adopt(contour);
0145e89a 430 }
0145e89a 431}
432
433//_____________________________________________________________________________
434TString
435AliMUONPainterHelper::ChamberName(Int_t chamberId) const
436{
437 /// Build a name for one chamber
dc9bb08e 438 return Form("Chamber%1d",chamberId+1);
0145e89a 439}
440
441//_____________________________________________________________________________
442TString
443AliMUONPainterHelper::StationName(Int_t stationId) const
444{
445 /// Build a name for one station
446 return Form("Station%1d",stationId+1);
447}
448
449//_____________________________________________________________________________
450TString
451AliMUONPainterHelper::DEName(Int_t detElemId) const
452{
453 /// Build a name for one detection element
454 return Form("DE%04d",detElemId);
455}
456
457//_____________________________________________________________________________
458TString
459AliMUONPainterHelper::ManuName(Int_t manuId) const
460{
461 /// Build a name for one manu
462 return Form("MANU%04d",manuId);
463}
464
465//_____________________________________________________________________________
466TString
467AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
468{
469 /// Build a name for one buspatch
470 return Form("BUSPATCH%04d",busPatchId);
471}
472
473//_____________________________________________________________________________
474TString
475AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
476{
477 /// Build a name for one pcb
478 return Form("PCB%1d",pcbNumber);
479}
480
481//_____________________________________________________________________________
482TString
483AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
484{
485 /// Build a name for one chamber
486 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
487}
488
489//_____________________________________________________________________________
490TString
491AliMUONPainterHelper::StationPathName(Int_t stationId) const
492{
493 /// Build a name for one station
494 return StationName(stationId);
495}
496
497//_____________________________________________________________________________
498TString
499AliMUONPainterHelper::DEPathName(Int_t detElemId) const
500{
501 /// Build a name for one detection element
502
503 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
504
505 return Form("%s/%s/%s",
506 StationName(chamberId/2).Data(),
507 ChamberName(chamberId).Data(),
508 DEName(detElemId).Data());
509}
510
511//_____________________________________________________________________________
512TString
513AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
514{
515 /// Build a name for one manu
516 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
517}
518
519//_____________________________________________________________________________
520TString
521AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
522{
523 /// Build a name for one buspatch
524 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
525
526 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
527}
528
529//_____________________________________________________________________________
530TString
531AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
532{
533 /// Build a name for one pcb
534 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
535}
536
537//_____________________________________________________________________________
538TString
539AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
540{
541 /// Format a double value to be displayed
542 /// FIXME: should insure we have the right number of significant digits here...
543
fef32488 544 TString sname(name);
545
546 sname.ToUpper();
547 if (sname.Contains("BIT"))
548 {
549 Int_t i = (Int_t)(value);
550 TString rv = Form("%s = 0x%x",name,i);
551 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
552 return rv;
553 }
554 else
555 {
556 return Form("%s = %e",name,value);
557 }
558}
559
560//_____________________________________________________________________________
561TObjArray*
562AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
563{
564 /// Get the contours in a specially arranged array (orderer by hierarchy level)
565
566 if ( explodedView ) return fExploded->AllContourArray(); // fExploded should always be created
567
568 if (!fReal) fReal = new AliMUONContourHandler(kFALSE); // fReal might be first asked here.
569
570 return fReal->AllContourArray();
0145e89a 571}
8f0acce4 572
fef32488 573