]>
Commit | Line | Data |
---|---|---|
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 | |
83 | ClassImp(AliMUONPainterHelper) | |
84 | ///\endcond | |
85 | ||
86 | AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0); | |
87 | ||
88 | //_____________________________________________________________________________ | |
89 | AliMUONPainterHelper::AliMUONPainterHelper() : | |
8f0acce4 | 90 | TObject(), |
8f0acce4 | 91 | fEnv(0x0), |
fef32488 | 92 | fReal(0x0), |
93 | fExploded(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 | //_____________________________________________________________________________ | |
110 | AliMUONPainterHelper::~AliMUONPainterHelper() | |
111 | { | |
112 | /// dtor | |
fef32488 | 113 | delete fReal; |
114 | delete fExploded; | |
8f0acce4 | 115 | fEnv->Save(); |
0145e89a | 116 | fgInstance = 0; |
117 | } | |
118 | ||
e937ba7c | 119 | //_____________________________________________________________________________ |
120 | AliMUONContourHandler* | |
121 | AliMUONPainterHelper::Exploded() const | |
122 | { | |
123 | /// Create exploded contour handler | |
124 | if (!fExploded) fExploded = new AliMUONContourHandler(kTRUE); | |
125 | return fExploded; | |
126 | } | |
127 | ||
128 | //_____________________________________________________________________________ | |
129 | AliMUONContourHandler* | |
130 | AliMUONPainterHelper::Real() const | |
131 | { | |
132 | /// Create real contour handler | |
133 | if (!fReal) fReal = new AliMUONContourHandler(kFALSE); | |
134 | return fReal; | |
135 | } | |
136 | ||
0145e89a | 137 | //_____________________________________________________________________________ |
8f0acce4 | 138 | AliMUONContour* |
fef32488 | 139 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ |
158 | AliMp::CathodType | |
159 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
173 | AliMpMotifPosition* | |
174 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ |
186 | AliMpPCB* | |
187 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
197 | AliMpPCB* | |
198 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
208 | AliMp::PlaneType | |
209 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
221 | const AliMpSlat* | |
222 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
233 | const AliMpSector* | |
234 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
246 | const AliMpSlat* | |
247 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
257 | const AliMpSlat* | |
258 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
268 | AliMUONPainterHelper* | |
269 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
283 | void | |
284 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
300 | void | |
301 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
317 | Int_t | |
318 | AliMUONPainterHelper::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 | 337 | AliMUONContour* |
fef32488 | 338 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
355 | void | |
356 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
370 | void | |
fef32488 | 371 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
397 | TString | |
398 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
405 | TString | |
406 | AliMUONPainterHelper::StationName(Int_t stationId) const | |
407 | { | |
408 | /// Build a name for one station | |
409 | return Form("Station%1d",stationId+1); | |
410 | } | |
411 | ||
412 | //_____________________________________________________________________________ | |
413 | TString | |
414 | AliMUONPainterHelper::DEName(Int_t detElemId) const | |
415 | { | |
416 | /// Build a name for one detection element | |
417 | return Form("DE%04d",detElemId); | |
418 | } | |
419 | ||
420 | //_____________________________________________________________________________ | |
421 | TString | |
422 | AliMUONPainterHelper::ManuName(Int_t manuId) const | |
423 | { | |
424 | /// Build a name for one manu | |
425 | return Form("MANU%04d",manuId); | |
426 | } | |
427 | ||
428 | //_____________________________________________________________________________ | |
429 | TString | |
430 | AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const | |
431 | { | |
432 | /// Build a name for one buspatch | |
433 | return Form("BUSPATCH%04d",busPatchId); | |
434 | } | |
435 | ||
436 | //_____________________________________________________________________________ | |
437 | TString | |
438 | AliMUONPainterHelper::PCBName(Int_t pcbNumber) const | |
439 | { | |
440 | /// Build a name for one pcb | |
441 | return Form("PCB%1d",pcbNumber); | |
442 | } | |
443 | ||
444 | //_____________________________________________________________________________ | |
445 | TString | |
446 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
453 | TString | |
454 | AliMUONPainterHelper::StationPathName(Int_t stationId) const | |
455 | { | |
456 | /// Build a name for one station | |
457 | return StationName(stationId); | |
458 | } | |
459 | ||
460 | //_____________________________________________________________________________ | |
461 | TString | |
462 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
485 | TString | |
486 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
493 | TString | |
494 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
503 | TString | |
504 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
511 | TString | |
512 | AliMUONPainterHelper::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 | //_____________________________________________________________________________ | |
534 | TObjArray* | |
535 | AliMUONPainterHelper::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 |