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