]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPainterHelper.cxx
Adding ruleckecher files into the distribbution
[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"
0145e89a 30#include "AliMUONPainterRegistry.h"
fef32488 31#include "AliMUONPadStatusMaker.h"
0145e89a 32#include "AliMUONVCalibParam.h"
33#include "AliMUONVDigit.h"
34#include "AliMUONVTrackerData.h"
35#include "AliMpCDB.h"
36#include "AliMpConstants.h"
37#include "AliMpDDLStore.h"
38#include "AliMpDEIterator.h"
39#include "AliMpDEManager.h"
40#include "AliMpExMap.h"
41#include "AliMpMotifMap.h"
42#include "AliMpMotifPosition.h"
43#include "AliMpPCB.h"
44#include "AliMpPad.h"
45#include "AliMpSector.h"
0145e89a 46#include "AliMpSegmentation.h"
47#include "AliMpSlat.h"
0145e89a 48#include "AliMpStationType.h"
49#include "AliMpVPadIterator.h"
0145e89a 50#include <Riostream.h>
51#include <TArrayI.h>
52#include <TCanvas.h>
53#include <TClass.h>
54#include <TCollection.h>
55#include <TFile.h>
56#include <TGLabel.h>
0145e89a 57#include <TGMsgBox.h>
8f0acce4 58#include <TGeoMatrix.h>
0145e89a 59#include <TLine.h>
60#include <TList.h>
61#include <TMap.h>
fcabdc0c 62#include <TMath.h>
0145e89a 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 89fEnv(0x0),
fef32488 90fReal(0x0),
91fExploded(0x0)
0145e89a 92{
fef32488 93 /// ctor
8f0acce4 94
fef32488 95 if ( ! AliMpCDB::LoadMpSegmentation() )
96 {
97 AliFatal("Could not access mapping from OCDB !");
98 }
8f0acce4 99
fef32488 100 // Load DDL store
101 if ( ! AliMpCDB::LoadDDLStore() )
102 {
103 AliFatal("Could not access DDL Store from OCDB !");
e937ba7c 104 }
0145e89a 105}
106
107//_____________________________________________________________________________
108AliMUONPainterHelper::~AliMUONPainterHelper()
109{
110 /// dtor
fef32488 111 delete fReal;
112 delete fExploded;
8f0acce4 113 fEnv->Save();
0145e89a 114 fgInstance = 0;
115}
116
e937ba7c 117//_____________________________________________________________________________
118AliMUONContourHandler*
119AliMUONPainterHelper::Exploded() const
120{
121 /// Create exploded contour handler
122 if (!fExploded) fExploded = new AliMUONContourHandler(kTRUE);
123 return fExploded;
124}
125
126//_____________________________________________________________________________
127AliMUONContourHandler*
128AliMUONPainterHelper::Real() const
129{
130 /// Create real contour handler
131 if (!fReal) fReal = new AliMUONContourHandler(kFALSE);
132 return fReal;
133}
134
0145e89a 135//_____________________________________________________________________________
8f0acce4 136AliMUONContour*
fef32488 137AliMUONPainterHelper::GetContour(const char* contourName, Bool_t explodedView) const
0145e89a 138{
8f0acce4 139 /// Get a contour by name
fef32488 140 if (explodedView)
141 {
e937ba7c 142 return Exploded()->GetContour(contourName);
fef32488 143 }
144 else
145 {
146 if ( fReal )
147 {
148 return fReal->GetContour(contourName);
149 }
150 }
151 return 0x0;
0145e89a 152}
153
0145e89a 154
0145e89a 155//_____________________________________________________________________________
156AliMp::CathodType
157AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
158{
159 /// Get the cathode type of a given manu
160
161 AliMp::PlaneType planeType(AliMp::kBendingPlane);
162 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
163 {
164 planeType = AliMp::kNonBendingPlane;
165 }
166 return AliMpDEManager::GetCathod(detElemId,planeType);
167}
168
0145e89a 169
170//_____________________________________________________________________________
171AliMpMotifPosition*
172AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const
173{
174 /// Get a given motif position
fef32488 175 const AliMpVSegmentation* vseg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
176 if (vseg)
0145e89a 177 {
fef32488 178 return vseg->MotifPosition(manuId);
0145e89a 179 }
0145e89a 180 return 0x0;
181}
182
0145e89a 183//_____________________________________________________________________________
184AliMpPCB*
185AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType,
186 Int_t pcbNumber) const
187{
188 /// Get a given PCB
189 const AliMpSlat* slat = GetSlat(detElemId,cathodeType);
190 if ( slat ) return slat->GetPCB(pcbNumber);
191 return 0x0;
192}
193
194//_____________________________________________________________________________
195AliMpPCB*
196AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType,
197 Int_t pcbNumber) const
198{
199 /// Get a given PCB
200 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
201 planeType);
202 return GetPCB(detElemId,cathodeType,pcbNumber);
203}
204
205//_____________________________________________________________________________
206AliMp::PlaneType
207AliMUONPainterHelper::GetPlaneType(Int_t manuId) const
208{
209 /// Get the planeType of a given manu
210
211 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
212 {
213 return AliMp::kNonBendingPlane;
214 }
215 return AliMp::kBendingPlane;
216}
217
218//_____________________________________________________________________________
219const AliMpSlat*
220AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const
221{
222 /// Get a given slat
223
224 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
225 planeType);
226
227 return GetSlat(detElemId,cathodeType);
228}
229
230//_____________________________________________________________________________
231const AliMpSector*
232AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const
233{
234 /// Get a given sector
235 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
4e51cfd2 236 if ( stationType != AliMp::kStation12 ) return 0x0;
0145e89a 237
238 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
239
f3ed9a44 240 return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType);
0145e89a 241}
242
243//_____________________________________________________________________________
244const AliMpSlat*
245AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const
246{
247 /// Get a given slat
248 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
249 if ( stationType != AliMp::kStation345 ) return 0x0;
250
f3ed9a44 251 return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType);
0145e89a 252}
253
254//_____________________________________________________________________________
255const AliMpSlat*
256AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const
257{
258 /// Get a given slat
f3ed9a44 259 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
260 if ( stationType != AliMp::kStation345 ) return 0x0;
261
262 return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId);
0145e89a 263}
264
265//_____________________________________________________________________________
266AliMUONPainterHelper*
267AliMUONPainterHelper::Instance()
268{
269 /// Return the global and unique instance of this class
270
271 if (fgInstance) return fgInstance;
0145e89a 272
99c136e1 273 AliCodeTimerAutoClass("",0);
8f0acce4 274
275 fgInstance = new AliMUONPainterHelper;
8f0acce4 276 fgInstance->fEnv = new AliMUONPainterEnv;
0145e89a 277 return fgInstance;
278}
279
280//_____________________________________________________________________________
281void
282AliMUONPainterHelper::Global2Local(Int_t detElemId,
283 Double_t xg, Double_t yg, Double_t zg,
284 Double_t& xl, Double_t& yl, Double_t& zl) const
285{
286 /// Local to global transformation of coordinates
287
e937ba7c 288 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
0145e89a 289 Double_t pg[3] = { xg, yg, zg };
290 Double_t pl[3] = { 0., 0., 0. };
291 matrix->MasterToLocal(pg, pl);
292 xl = pl[0];
293 yl = pl[1];
294 zl = pl[2];
295}
296
297//_____________________________________________________________________________
298void
299AliMUONPainterHelper::Local2Global(Int_t detElemId,
300 Double_t xl, Double_t yl, Double_t zl,
301 Double_t& xg, Double_t& yg, Double_t& zg) const
302{
303 /// Local to (exploded) global transformation of coordinates
304
e937ba7c 305 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(Exploded()->GetTransformations()->GetValue(detElemId));
0145e89a 306 Double_t pl[3] = { xl, yl, zl };
307 Double_t pg[3] = { 0., 0., 0. };
308 matrix->LocalToMaster(pl, pg);
309 xg = pg[0];
310 yg = pg[1];
311 zg = pg[2];
312}
313
314//_____________________________________________________________________________
315Int_t
316AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const
317{
318 /// Convert a value into a color, fitting within a given range
319
320 Int_t rv;
321
322 if (value > max) rv = 1;
323 else if (value <= min) rv = 0;
324 else
325 {
28382e06 326 if ( TMath::AreEqualRel(max,min,1E-6) ) return gStyle->GetColorPalette(1);
0145e89a 327 Double_t range = max - min;
328 Double_t offset = value - min;
329 rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) );
330 }
331 return rv;
332}
333
334//_____________________________________________________________________________
8f0acce4 335AliMUONContour*
fef32488 336AliMUONPainterHelper::MergeContours(const TObjArray& contours, const char* contourName, Bool_t explodedGeometry)
0145e89a 337{
338 /// Merge a set of contours (delegating to the contour maker)
0145e89a 339
8f0acce4 340 AliMUONContourMaker maker;
341
342 AliMUONContour* contour = maker.MergeContour(contours,contourName);
0145e89a 343
344 if (contour)
345 {
fef32488 346 RegisterContour(contour,explodedGeometry);
0145e89a 347 }
348 return contour;
349}
350
351
352//_____________________________________________________________________________
353void
354AliMUONPainterHelper::Print(Option_t* opt) const
355{
356 /// Printout
357 TString sopt(opt);
358 sopt.ToUpper();
359
360 if ( sopt.Length() == 0 )
361 {
fef32488 362 if ( fExploded ) fExploded->Print();
363 if ( fReal ) fReal->Print();
fcabdc0c 364 }
0145e89a 365}
366
367//_____________________________________________________________________________
368void
fef32488 369AliMUONPainterHelper::RegisterContour(AliMUONContour* contour, Bool_t explodedView)
0145e89a 370{
371 /// contour is adopted by contourMaker
99c136e1 372 AliCodeTimerAuto("",0)
0145e89a 373 AliDebug(1,contour->GetName());
fef32488 374 AliMUONContourHandler* ch = fReal;
375 if ( explodedView )
0145e89a 376 {
e937ba7c 377 ch = Exploded();
fef32488 378 }
379 if (!ch)
380 {
381 AliError(Form("ContourHandler for %s view is not created yet !",explodedView ? "EXPLODED" : "REAL"));
382 }
383 else
384 {
385 if ( ch->GetContour(contour->GetName()) )
386 {
387 AliError(Form("Contour with name %s is already there",contour->GetName()));
388 return;
389 }
390 ch->Adopt(contour);
0145e89a 391 }
0145e89a 392}
393
394//_____________________________________________________________________________
395TString
396AliMUONPainterHelper::ChamberName(Int_t chamberId) const
397{
398 /// Build a name for one chamber
dc9bb08e 399 return Form("Chamber%1d",chamberId+1);
0145e89a 400}
401
402//_____________________________________________________________________________
403TString
404AliMUONPainterHelper::StationName(Int_t stationId) const
405{
406 /// Build a name for one station
407 return Form("Station%1d",stationId+1);
408}
409
410//_____________________________________________________________________________
411TString
412AliMUONPainterHelper::DEName(Int_t detElemId) const
413{
414 /// Build a name for one detection element
415 return Form("DE%04d",detElemId);
416}
417
418//_____________________________________________________________________________
419TString
420AliMUONPainterHelper::ManuName(Int_t manuId) const
421{
422 /// Build a name for one manu
423 return Form("MANU%04d",manuId);
424}
425
426//_____________________________________________________________________________
427TString
428AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const
429{
430 /// Build a name for one buspatch
431 return Form("BUSPATCH%04d",busPatchId);
432}
433
434//_____________________________________________________________________________
435TString
436AliMUONPainterHelper::PCBName(Int_t pcbNumber) const
437{
438 /// Build a name for one pcb
439 return Form("PCB%1d",pcbNumber);
440}
441
442//_____________________________________________________________________________
443TString
444AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const
445{
446 /// Build a name for one chamber
447 return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data());
448}
449
450//_____________________________________________________________________________
451TString
452AliMUONPainterHelper::StationPathName(Int_t stationId) const
453{
454 /// Build a name for one station
455 return StationName(stationId);
456}
457
458//_____________________________________________________________________________
459TString
460AliMUONPainterHelper::DEPathName(Int_t detElemId) const
461{
462 /// Build a name for one detection element
463
464 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
465
466 return Form("%s/%s/%s",
467 StationName(chamberId/2).Data(),
468 ChamberName(chamberId).Data(),
469 DEName(detElemId).Data());
470}
471
472//_____________________________________________________________________________
473TString
474AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const
475{
476 /// Build a name for one manu
477 return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data());
478}
479
480//_____________________________________________________________________________
481TString
482AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const
483{
484 /// Build a name for one buspatch
485 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
486
487 return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data());
488}
489
490//_____________________________________________________________________________
491TString
492AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const
493{
494 /// Build a name for one pcb
495 return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data());
496}
497
498//_____________________________________________________________________________
499TString
500AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
501{
502 /// Format a double value to be displayed
503 /// FIXME: should insure we have the right number of significant digits here...
504
fef32488 505 TString sname(name);
506
507 sname.ToUpper();
508 if (sname.Contains("BIT"))
509 {
510 Int_t i = (Int_t)(value);
511 TString rv = Form("%s = 0x%x",name,i);
512 cout << rv << ":" << AliMUONPadStatusMaker::AsString(i) << endl;
513 return rv;
514 }
515 else
516 {
517 return Form("%s = %e",name,value);
518 }
519}
520
521//_____________________________________________________________________________
522TObjArray*
523AliMUONPainterHelper::GetAllContoursAsArray(Bool_t explodedView) const
524{
525 /// Get the contours in a specially arranged array (orderer by hierarchy level)
526
e937ba7c 527 if ( explodedView )
528 {
529 return Exploded()->AllContourArray();
530 }
531 else
532 {
533 return Real()->AllContourArray();
534 }
0145e89a 535}
8f0acce4 536
fef32488 537