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