Adding MUONChamberMaterialBudget.C:
[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 !");
e937ba7c 105 }
0145e89a 106}
107
108//_____________________________________________________________________________
109AliMUONPainterHelper::~AliMUONPainterHelper()
110{
111 /// dtor
0145e89a 112 delete fPainterMatrices;
fef32488 113 delete fReal;
114 delete fExploded;
8f0acce4 115 fEnv->Save();
0145e89a 116 fgInstance = 0;
117}
118
119//_____________________________________________________________________________
e937ba7c 120AliMUONContourHandler*
121AliMUONPainterHelper::Exploded() const
122{
123 /// Create exploded contour handler
124 if (!fExploded) fExploded = new AliMUONContourHandler(kTRUE);
125 return fExploded;
126}
127
128//_____________________________________________________________________________
129AliMUONContourHandler*
130AliMUONPainterHelper::Real() const
131{
132 /// Create real contour handler
133 if (!fReal) fReal = new AliMUONContourHandler(kFALSE);
134 return fReal;
135}
136
137//_____________________________________________________________________________
8f0acce4 138AliMUONContour*
fef32488 139AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
0145e89a 140{
8f0acce4 141 /// Get a contour by name
fef32488 142 if (explodedView)
143 {
e937ba7c 144 return Exploded()->GetContour(contourName);
fef32488 145 }
146 else
147 {
148 if ( fReal )
149 {
150 return fReal->GetContour(contourName);
151 }
152 }
153 return 0x0;
0145e89a 154}
155
156//_____________________________________________________________________________
157void
158AliMUONPainterHelper::GenerateDefaultMatrices()
159{
160 /// Kind of bootstrap method to trigger the generation of all contours
161
99c136e1 162 AliCodeTimerAuto("",0);
8f0acce4 163
0145e89a 164 fPainterMatrices = new TObjArray;
165 fPainterMatrices->SetOwner(kFALSE);
166
167 TObjArray attributes;
168
169 AliMUONAttPainter att;
170
171 att.SetViewPoint(kTRUE,kFALSE);
0145e89a 172 att.SetCathode(kFALSE,kFALSE);
173 att.SetPlane(kTRUE,kFALSE);
174 attributes.Add(new AliMUONAttPainter(att));
8f0acce4 175
0145e89a 176 TIter next(&attributes);
177 AliMUONAttPainter* a;
178
179 while ( ( a = static_cast<AliMUONAttPainter*>(next()) ) )
180 {
181 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
182
183 for ( Int_t i = 0; i < 10; ++i )
184 {
8f0acce4 185 AliMUONVPainter* painter = new AliMUONChamberPainter(*a,i);
0145e89a 186
187 painter->SetResponder("Chamber");
188
189 painter->SetOutlined("*",kFALSE);
190
191 painter->SetOutlined("MANU",kTRUE);
192
193 for ( Int_t j = 0; j < 3; ++j )
194 {
195 painter->SetLine(j,1,4-j);
196 }
197
198 matrix->Adopt(painter);
199 }
200 AliMUONPainterRegistry::Instance()->Register(matrix);
201 fPainterMatrices->Add(matrix);
202 }
203}
204
205//_____________________________________________________________________________
0145e89a 206AliMp::CathodType
207AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
208{
209 /// Get the cathode type of a given manu
210
211 AliMp::PlaneType planeType(AliMp::kBendingPlane);
212 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
213 {
214 planeType = AliMp::kNonBendingPlane;
215 }
216 return AliMpDEManager::GetCathod(detElemId,planeType);
217}
218
0145e89a 219
220//_____________________________________________________________________________
221AliMpMotifPosition*
222AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
223{
224 /// Get a given motif position
fef32488 225 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
226 if (vseg)
0145e89a 227 {
fef32488 228 return vseg->MotifPosition(manuId);
0145e89a 229 }
0145e89a 230 return 0x0;
231}
232
0145e89a 233//_____________________________________________________________________________
234AliMpPCB*
235AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
236 Int_t pcbNumber) const
237{
238 /// Get a given PCB
239 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
240 if ( slat ) return slat->GetPCB(pcbNumber);
241 return 0x0;
242}
243
244//_____________________________________________________________________________
245AliMpPCB*
246AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
247 Int_t pcbNumber) const
248{
249 /// Get a given PCB
250 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
251 planeType);
252 return GetPCB(detElemId,cathodeType,pcbNumber);
253}
254
255//_____________________________________________________________________________
256AliMp::PlaneType
257AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
258{
259 /// Get the planeType of a given manu
260
261 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
262 {
263 return AliMp::kNonBendingPlane;
264 }
265 return AliMp::kBendingPlane;
266}
267
268//_____________________________________________________________________________
269const AliMpSlat*
270AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
271{
272 /// Get a given slat
273
274 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
275 planeType);
276
277 return GetSlat(detElemId,cathodeType);
278}
279
280//_____________________________________________________________________________
281const AliMpSector*
282AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
283{
284 /// Get a given sector
285 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
4e51cfd2 286 if ( stationType != AliMp::kStation12 ) return 0x0;
0145e89a 287
288 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
289
f3ed9a44 290 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
0145e89a 291}
292
293//_____________________________________________________________________________
294const AliMpSlat*
295AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
296{
297 /// Get a given slat
298 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
299 if ( stationType != AliMp::kStation345 ) return 0x0;
300
f3ed9a44 301 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
0145e89a 302}
303
304//_____________________________________________________________________________
305const AliMpSlat*
306AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
307{
308 /// Get a given slat
f3ed9a44 309 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
310 if ( stationType != AliMp::kStation345 ) return 0x0;
311
312 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
0145e89a 313}
314
315//_____________________________________________________________________________
316AliMUONPainterHelper*
317AliMUONPainterHelper::Instance()
318{
319 /// Return the global and unique instance of this class
320
321 if (fgInstance) return fgInstance;
0145e89a 322
99c136e1 323 AliCodeTimerAutoClass("",0);
8f0acce4 324
325 fgInstance = new AliMUONPainterHelper;
8f0acce4 326 fgInstance->fEnv = new AliMUONPainterEnv;
0145e89a 327 return fgInstance;
328}
329
330//_____________________________________________________________________________
331void
332AliMUONPainterHelper::Global2Local(Int_t detElemId,
333 Double_t xg, Double_t yg, Double_t zg,
334 Double_t& xl, Double_t& yl, Double_t& zl) const
335{
336 /// Local to global transformation of coordinates
337
e937ba7c 338 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
0145e89a 339 Double_t pg[3] = { xg, yg, zg };
340 Double_t pl[3] = { 0., 0., 0. };
341 matrix->MasterToLocal(pg, pl);
342 xl = pl[0];
343 yl = pl[1];
344 zl = pl[2];
345}
346
347//_____________________________________________________________________________
348void
349AliMUONPainterHelper::Local2Global(Int_t detElemId,
350 Double_t xl, Double_t yl, Double_t zl,
351 Double_t& xg, Double_t& yg, Double_t& zg) const
352{
353 /// Local to (exploded) global transformation of coordinates
354
e937ba7c 355 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
0145e89a 356 Double_t pl[3] = { xl, yl, zl };
357 Double_t pg[3] = { 0., 0., 0. };
358 matrix->LocalToMaster(pl, pg);
359 xg = pg[0];
360 yg = pg[1];
361 zg = pg[2];
362}
363
364//_____________________________________________________________________________
365Int_t
366AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
367{
368 /// Convert a value into a color, fitting within a given range
369
370 Int_t rv;
371
372 if (value > max) rv = 1;
373 else if (value <= min) rv = 0;
374 else
375 {
376 if ( max == min ) return gStyle->GetColorPalette(1);
377 Double_t range = max - min;
378 Double_t offset = value - min;
379 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
380 }
381 return rv;
382}
383
384//_____________________________________________________________________________
8f0acce4 385AliMUONContour*
fef32488 386AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
0145e89a 387{
388 /// Merge a set of contours (delegating to the contour maker)
0145e89a 389
8f0acce4 390 AliMUONContourMaker maker;
391
392 AliMUONContour* contour = maker.MergeContour(contours,contourName);
0145e89a 393
394 if (contour)
395 {
fef32488 396 RegisterContour(contour,explodedGeometry);
0145e89a 397 }
398 return contour;
399}
400
401
402//_____________________________________________________________________________
403void
404AliMUONPainterHelper::Print(Option_t* opt) const
405{
406 /// Printout
407 TString sopt(opt);
408 sopt.ToUpper();
409
410 if ( sopt.Length() == 0 )
411 {
fef32488 412 if ( fExploded ) fExploded->Print();
413 if ( fReal ) fReal->Print();
0145e89a 414 }
415
fef32488 416 if ( fPainterMatrices && ( sopt.Contains("MATRI") || sopt.Contains("FULL") ) )
0145e89a 417 {
418 fPainterMatrices->Print(opt);
419 }
420}
421
422//_____________________________________________________________________________
423void
fef32488 424AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
0145e89a 425{
426 /// contour is adopted by contourMaker
99c136e1 427 AliCodeTimerAuto("",0)
0145e89a 428 AliDebug(1,contour->GetName());
fef32488 429 AliMUONContourHandler* ch = fReal;
430 if ( explodedView )
0145e89a 431 {
e937ba7c 432 ch = Exploded();
fef32488 433 }
434 if (!ch)
435 {
436 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
437 }
438 else
439 {
440 if ( ch->GetContour(contour->GetName()) )
441 {
442 AliError(Form("Contour with name %s is already there",contour->GetName()));
443 return;
444 }
445 ch->Adopt(contour);
0145e89a 446 }
0145e89a 447}
448
449//_____________________________________________________________________________
450TString
451AliMUONPainterHelper::ChamberName(Int_t chamberId) const
452{
453 /// Build a name for one chamber
dc9bb08e 454 return Form("Chamber%1d",chamberId+1);
0145e89a 455}
456
457//_____________________________________________________________________________
458TString
459AliMUONPainterHelper::StationName(Int_t stationId) const
460{
461 /// Build a name for one station
462 return Form("Station%1d",stationId+1);
463}
464
465//_____________________________________________________________________________
466TString
467AliMUONPainterHelper::DEName(Int_t detElemId) const
468{
469 /// Build a name for one detection element
470 return Form("DE%04d",detElemId);
471}
472
473//_____________________________________________________________________________
474TString
475AliMUONPainterHelper::ManuName(Int_t manuId) const
476{
477 /// Build a name for one manu
478 return Form("MANU%04d",manuId);
479}
480
481//_____________________________________________________________________________
482TString
483AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
484{
485 /// Build a name for one buspatch
486 return Form("BUSPATCH%04d",busPatchId);
487}
488
489//_____________________________________________________________________________
490TString
491AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
492{
493 /// Build a name for one pcb
494 return Form("PCB%1d",pcbNumber);
495}
496
497//_____________________________________________________________________________
498TString
499AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
500{
501 /// Build a name for one chamber
502 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
503}
504
505//_____________________________________________________________________________
506TString
507AliMUONPainterHelper::StationPathName(Int_t stationId) const
508{
509 /// Build a name for one station
510 return StationName(stationId);
511}
512
513//_____________________________________________________________________________
514TString
515AliMUONPainterHelper::DEPathName(Int_t detElemId) const
516{
517 /// Build a name for one detection element
518
519 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
520
521 return Form("%s/%s/%s",
522 StationName(chamberId/2).Data(),
523 ChamberName(chamberId).Data(),
524 DEName(detElemId).Data());
525}
526
527//_____________________________________________________________________________
528TString
529AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
530{
531 /// Build a name for one manu
532 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
533}
534
535//_____________________________________________________________________________
536TString
537AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
538{
539 /// Build a name for one buspatch
540 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
541
542 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
543}
544
545//_____________________________________________________________________________
546TString
547AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
548{
549 /// Build a name for one pcb
550 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
551}
552
553//_____________________________________________________________________________
554TString
555AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
556{
557 /// Format a double value to be displayed
558 /// FIXME: should insure we have the right number of significant digits here...
559
fef32488 560 TString sname(name);
561
562 sname.ToUpper();
563 if (sname.Contains("BIT"))
564 {
565 Int_t i = (Int_t)(value);
566 TString rv = Form("%s = 0x%x",name,i);
567 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
568 return rv;
569 }
570 else
571 {
572 return Form("%s = %e",name,value);
573 }
574}
575
576//_____________________________________________________________________________
577TObjArray*
578AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
579{
580 /// Get the contours in a specially arranged array (orderer by hierarchy level)
581
e937ba7c 582 if ( explodedView )
583 {
584 return Exploded()->AllContourArray();
585 }
586 else
587 {
588 return Real()->AllContourArray();
589 }
0145e89a 590}
8f0acce4 591
fef32488 592