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