]>
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 | ||
21 | #include "AliMUONGeometryDetElement.h" | |
22 | #include "AliMUONGeometryTransformer.h" | |
23 | #include "AliMUONPainterContour.h" | |
24 | #include "AliMUONPainterContourMaker.h" | |
25 | #include "AliMUONPainterEnv.h" | |
26 | #include "AliMUONPainterMatrix.h" | |
27 | #include "AliMUONPainterPadStore.h" | |
28 | #include "AliMUONPainterRegistry.h" | |
29 | #include "AliMUONVCalibParam.h" | |
30 | #include "AliMUONVDigit.h" | |
31 | #include "AliMUONVTrackerData.h" | |
32 | #include "AliMpCDB.h" | |
33 | #include "AliMpConstants.h" | |
34 | #include "AliMpDDLStore.h" | |
35 | #include "AliMpDEIterator.h" | |
36 | #include "AliMpDEManager.h" | |
37 | #include "AliMpExMap.h" | |
38 | #include "AliMpMotifMap.h" | |
39 | #include "AliMpMotifPosition.h" | |
40 | #include "AliMpPCB.h" | |
41 | #include "AliMpPad.h" | |
42 | #include "AliMpSector.h" | |
0145e89a | 43 | #include "AliMpSegmentation.h" |
44 | #include "AliMpSlat.h" | |
0145e89a | 45 | #include "AliMpStationType.h" |
46 | #include "AliMpVPadIterator.h" | |
47 | #include "AliCodeTimer.h" | |
48 | #include "AliLog.h" | |
49 | #include <Riostream.h> | |
50 | #include <TArrayI.h> | |
51 | #include <TCanvas.h> | |
52 | #include <TClass.h> | |
53 | #include <TCollection.h> | |
54 | #include <TFile.h> | |
55 | #include <TGLabel.h> | |
56 | #include <TGeoMatrix.h> | |
57 | #include <TGMsgBox.h> | |
58 | #include <TLine.h> | |
59 | #include <TList.h> | |
60 | #include <TMap.h> | |
61 | #include <TObjArray.h> | |
62 | #include <TObjString.h> | |
63 | #include <TStyle.h> | |
64 | #include <TSystem.h> | |
65 | #include <TVector2.h> | |
66 | #include <TVector3.h> | |
67 | #include <TVirtualPad.h> | |
68 | #include <TVirtualX.h> | |
69 | ||
70 | ///\class AliMUONPainterHelper | |
71 | /// | |
72 | /// Helper class for painters | |
73 | /// | |
74 | ///\author Laurent Aphecetche, Subatech | |
75 | ||
76 | ///\cond CLASSIMP | |
77 | ClassImp(AliMUONPainterHelper) | |
78 | ///\endcond | |
79 | ||
80 | AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0); | |
81 | ||
82 | //_____________________________________________________________________________ | |
83 | AliMUONPainterHelper::AliMUONPainterHelper() : | |
84 | TObject(), | |
85 | fPadStore(0x0), | |
86 | fExplodedGlobalTransformations(0x0), | |
87 | fRealGlobalTransformations(0x0), | |
88 | fIsModified(kFALSE), | |
89 | fContourMaker(0x0), | |
90 | fPainterMatrices(0x0), | |
91 | fEnv(0x0) | |
92 | { | |
93 | /// ctor | |
94 | fExplodeFactor[0] = 1.00; | |
95 | fExplodeFactor[1] = 1.50; | |
96 | ||
97 | if ( ! AliMpCDB::LoadMpSegmentation() ) | |
98 | { | |
99 | AliFatal("Could not access mapping from OCDB !"); | |
100 | } | |
101 | ||
102 | // Load DDL store | |
103 | if ( ! AliMpCDB::LoadDDLStore() ) | |
104 | { | |
105 | AliFatal("Could not access DDL Store from OCDB !"); | |
106 | } | |
107 | } | |
108 | ||
109 | //_____________________________________________________________________________ | |
110 | AliMUONPainterHelper::~AliMUONPainterHelper() | |
111 | { | |
112 | /// dtor | |
113 | if ( fIsModified ) Save(); | |
114 | delete fExplodedGlobalTransformations; | |
115 | delete fRealGlobalTransformations; | |
116 | delete fPadStore; | |
117 | delete fContourMaker; | |
118 | delete fPainterMatrices; | |
119 | fgInstance = 0; | |
120 | } | |
121 | ||
122 | //_____________________________________________________________________________ | |
123 | AliMUONPainterContour* | |
124 | AliMUONPainterHelper::GetContour(const char* contourName) const | |
125 | { | |
126 | /// Get a contour by name | |
127 | ||
128 | AliCodeTimerAuto("") | |
129 | ||
130 | if ( fContourMaker ) | |
131 | { | |
132 | return fContourMaker->GetContour(contourName); | |
133 | } | |
134 | return 0x0; | |
135 | } | |
136 | ||
137 | //_____________________________________________________________________________ | |
138 | Int_t | |
139 | AliMUONPainterHelper::FindPadID(const TArrayI& pads, Double_t x, Double_t y) const | |
140 | { | |
141 | /// Find a pad by position | |
142 | ||
143 | return fPadStore->FindPadID(pads,x,y); | |
144 | } | |
145 | ||
146 | //_____________________________________________________________________________ | |
147 | void | |
148 | AliMUONPainterHelper::GenerateDefaultMatrices() | |
149 | { | |
150 | /// Kind of bootstrap method to trigger the generation of all contours | |
151 | ||
152 | fPainterMatrices = new TObjArray; | |
153 | fPainterMatrices->SetOwner(kFALSE); | |
154 | ||
155 | TObjArray attributes; | |
156 | ||
157 | AliMUONAttPainter att; | |
158 | ||
159 | att.SetViewPoint(kTRUE,kFALSE); | |
160 | att.SetPlane(kFALSE,kFALSE); | |
161 | att.SetCathode(kTRUE,kFALSE); | |
162 | ||
163 | AliWarningClass("Should generate back views as well here"); | |
164 | ||
165 | attributes.Add(new AliMUONAttPainter(att)); | |
166 | att.SetCathode(kFALSE,kTRUE); | |
167 | attributes.Add(new AliMUONAttPainter(att)); | |
168 | att.SetCathode(kFALSE,kFALSE); | |
169 | att.SetPlane(kTRUE,kFALSE); | |
170 | attributes.Add(new AliMUONAttPainter(att)); | |
171 | att.SetPlane(kFALSE,kTRUE); | |
172 | attributes.Add(new AliMUONAttPainter(att)); | |
173 | ||
174 | TIter next(&attributes); | |
175 | AliMUONAttPainter* a; | |
176 | ||
177 | while ( ( a = static_cast<AliMUONAttPainter*>(next()) ) ) | |
178 | { | |
179 | AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2); | |
180 | ||
181 | for ( Int_t i = 0; i < 10; ++i ) | |
182 | { | |
183 | AliMUONVPainter* painter = AliMUONVPainter::CreatePainter("AliMUONChamberPainter",*a,i,-1); | |
184 | ||
185 | painter->SetResponder("Chamber"); | |
186 | ||
187 | painter->SetOutlined("*",kFALSE); | |
188 | ||
189 | painter->SetOutlined("MANU",kTRUE); | |
190 | ||
191 | for ( Int_t j = 0; j < 3; ++j ) | |
192 | { | |
193 | painter->SetLine(j,1,4-j); | |
194 | } | |
195 | ||
196 | matrix->Adopt(painter); | |
197 | } | |
198 | AliMUONPainterRegistry::Instance()->Register(matrix); | |
199 | fPainterMatrices->Add(matrix); | |
200 | } | |
201 | } | |
202 | ||
203 | //_____________________________________________________________________________ | |
204 | void | |
205 | AliMUONPainterHelper::GenerateGeometry() | |
206 | { | |
207 | /// Generate the geometry (FIXME: using transform.dat for the moment) | |
208 | /// The geometry is not the "normal" one as we "explode" it to avoid | |
209 | /// having overlapping detection elements as in the reality, which | |
210 | /// would be inconvenient for a display ;-) | |
211 | ||
212 | AliDebug(1,Form(" with explodeFactor=%e,%e",fExplodeFactor[0],fExplodeFactor[1])); | |
213 | ||
214 | AliMUONGeometryTransformer transformer; | |
215 | transformer.LoadGeometryData("transform.dat"); | |
216 | // transformer.LoadGeometryData("geometry.root"); //FIXME: add a protection if geometry.root file does not exist | |
630711ed | 217 | fExplodedGlobalTransformations = new AliMpExMap; |
218 | fRealGlobalTransformations = new AliMpExMap; | |
0145e89a | 219 | AliMpDEIterator deIt; |
220 | deIt.First(); | |
221 | while ( !deIt.IsDone() ) | |
222 | { | |
223 | Int_t detElemId = deIt.CurrentDEId(); | |
224 | const AliMUONGeometryDetElement* de = transformer.GetDetElement(detElemId); | |
225 | ||
226 | fRealGlobalTransformations->Add(detElemId,de->GetGlobalTransformation()->Clone()); | |
227 | ||
228 | TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(de->GetGlobalTransformation()->Clone()); | |
229 | Double_t* translation = matrix->GetTranslation(); | |
230 | ||
231 | AliDebug(1,Form("Initial translation for DE %04d is %7.3f, %7.3f", | |
232 | detElemId,translation[0],translation[1])); | |
233 | ||
234 | if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345 ) | |
235 | { | |
236 | translation[0] *= fExplodeFactor[0]; | |
237 | translation[1] *= fExplodeFactor[1]; | |
238 | } | |
239 | else | |
240 | { | |
241 | Double_t shift = 5; // cm | |
242 | Double_t xshift[] = { shift, -shift, -shift, shift }; | |
243 | Double_t yshift[] = { shift, shift, -shift, -shift }; | |
244 | Int_t ishift = detElemId % 100; | |
245 | ||
246 | translation[0] += xshift[ishift]; | |
247 | translation[1] += yshift[ishift]; | |
248 | } | |
249 | matrix->SetTranslation(translation); | |
250 | fExplodedGlobalTransformations->Add(detElemId,matrix); | |
251 | deIt.Next(); | |
252 | } | |
253 | } | |
254 | ||
255 | //_____________________________________________________________________________ | |
256 | AliMUONPainterContour* | |
257 | AliMUONPainterHelper::GenerateManuContour(Int_t detElemId, | |
258 | Int_t manuId, | |
259 | AliMUONAttPainter viewType, | |
260 | const char* contourName) | |
261 | { | |
262 | /// Generate the contour of the list of pads | |
263 | ||
264 | if (!fContourMaker) fContourMaker = new AliMUONPainterContourMaker(fExplodedGlobalTransformations); | |
265 | ||
266 | AliMUONPainterContour* contour = | |
267 | fContourMaker->GenerateManuContour(contourName,detElemId,manuId,viewType); | |
268 | ||
269 | if (contour) | |
270 | { | |
271 | RegisterContour(contour); | |
272 | } | |
273 | ||
274 | return contour; | |
275 | } | |
276 | ||
277 | //_____________________________________________________________________________ | |
278 | void | |
279 | AliMUONPainterHelper::GeneratePadStore() | |
280 | { | |
281 | /// Generate the pad store | |
282 | ||
283 | AliCodeTimerAuto("") | |
284 | AliDebugClass(1,"Generating pad store"); | |
285 | fPadStore = new AliMUONPainterPadStore(); | |
286 | ||
287 | AliMpDEIterator deIt; | |
288 | ||
289 | deIt.First(); | |
290 | while ( !deIt.IsDone() ) | |
291 | { | |
292 | Int_t detElemId = deIt.CurrentDEId(); | |
293 | if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger ) | |
294 | { | |
295 | GeneratePadStore(detElemId); | |
296 | } | |
297 | deIt.Next(); | |
298 | } | |
299 | } | |
300 | ||
301 | //_____________________________________________________________________________ | |
302 | void | |
303 | AliMUONPainterHelper::GeneratePadStore(Int_t detElemId) | |
304 | { | |
305 | /// Generate part of the padstore for one detection element | |
306 | ||
307 | AliMp::CathodType cathode[] = { AliMp::kCath0, AliMp::kCath1 }; | |
308 | ||
309 | for ( Int_t i = 0; i < 2; ++i ) | |
310 | { | |
311 | const AliMpVSegmentation* seg = | |
312 | AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,cathode[i]); | |
313 | AliMpVPadIterator* it = seg->CreateIterator(); | |
314 | it->First(); | |
315 | ||
316 | while ( !it->IsDone() ) | |
317 | { | |
318 | AliMpPad pad = it->CurrentItem(); | |
319 | ||
0145e89a | 320 | Double_t x,y,z; |
6e97fbb8 | 321 | Local2Global(detElemId,pad.GetPositionX(),pad.GetPositionY(),0, |
0145e89a | 322 | x,y,z); |
168e9c4d | 323 | Int_t manuId = pad.GetManuId(); |
324 | Int_t manuChannel = pad.GetManuChannel(); | |
0145e89a | 325 | AliMUONVCalibParam* param = fPadStore->Get(detElemId,manuId); |
326 | param->SetValueAsDouble(manuChannel,0,x); | |
327 | param->SetValueAsDouble(manuChannel,1,y); | |
6e97fbb8 | 328 | param->SetValueAsDouble(manuChannel,2,pad.GetDimensionX()); |
329 | param->SetValueAsDouble(manuChannel,3,pad.GetDimensionY()); | |
0145e89a | 330 | it->Next(); |
331 | } | |
332 | delete it; | |
333 | } | |
334 | } | |
335 | ||
336 | //_____________________________________________________________________________ | |
337 | void | |
338 | AliMUONPainterHelper::GetBoundaries(const TArrayI& pads, Double_t& xmin, Double_t& ymin, | |
339 | Double_t& xmax, Double_t& ymax) const | |
340 | { | |
341 | /// Get the area covered by an array of pads | |
342 | ||
343 | return fPadStore->GetBoundaries(pads,xmin,ymin,xmax,ymax); | |
344 | } | |
345 | ||
346 | //_____________________________________________________________________________ | |
347 | AliMp::CathodType | |
348 | AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const | |
349 | { | |
350 | /// Get the cathode type of a given manu | |
351 | ||
352 | AliMp::PlaneType planeType(AliMp::kBendingPlane); | |
353 | if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) | |
354 | { | |
355 | planeType = AliMp::kNonBendingPlane; | |
356 | } | |
357 | return AliMpDEManager::GetCathod(detElemId,planeType); | |
358 | } | |
359 | ||
360 | //_____________________________________________________________________________ | |
361 | AliMUONPainterContour* | |
362 | AliMUONPainterHelper::GetLocalManuContour(Int_t detElemId, Int_t manuId) const | |
363 | { | |
364 | /// Retrieve a manu contour (in local coordinates) | |
365 | return fContourMaker->FindLocalManuContour(detElemId,manuId); | |
366 | } | |
367 | ||
368 | //_____________________________________________________________________________ | |
369 | AliMpMotifPosition* | |
370 | AliMUONPainterHelper::GetMotifPosition(Int_t detElemId, Int_t manuId) const | |
371 | { | |
372 | /// Get a given motif position | |
373 | AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId); | |
374 | if ( stationType == AliMp::kStation345 ) | |
375 | { | |
376 | AliMp::PlaneType planeType(AliMp::kBendingPlane); | |
377 | if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) | |
378 | { | |
379 | planeType = AliMp::kNonBendingPlane; | |
380 | } | |
381 | const AliMpSlat* slat = GetSlat(detElemId,planeType); | |
382 | return slat->FindMotifPosition(manuId); | |
383 | } | |
384 | else if ( stationType != AliMp::kStationTrigger ) | |
385 | { | |
386 | AliMp::PlaneType planeType(AliMp::kBendingPlane); | |
387 | if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) | |
388 | { | |
389 | planeType = AliMp::kNonBendingPlane; | |
390 | } | |
391 | const AliMpSector* sector = GetSector(detElemId,planeType); | |
392 | return sector->GetMotifMap()->FindMotifPosition(manuId); | |
393 | } | |
394 | AliFatalClass("Not supposed to work with trigger"); | |
395 | return 0x0; | |
396 | } | |
397 | ||
398 | ||
399 | //_____________________________________________________________________________ | |
400 | AliMpPCB* | |
401 | AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::CathodType cathodeType, | |
402 | Int_t pcbNumber) const | |
403 | { | |
404 | /// Get a given PCB | |
405 | const AliMpSlat* slat = GetSlat(detElemId,cathodeType); | |
406 | if ( slat ) return slat->GetPCB(pcbNumber); | |
407 | return 0x0; | |
408 | } | |
409 | ||
410 | //_____________________________________________________________________________ | |
411 | AliMpPCB* | |
412 | AliMUONPainterHelper::GetPCB(Int_t detElemId, AliMp::PlaneType planeType, | |
413 | Int_t pcbNumber) const | |
414 | { | |
415 | /// Get a given PCB | |
416 | AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId, | |
417 | planeType); | |
418 | return GetPCB(detElemId,cathodeType,pcbNumber); | |
419 | } | |
420 | ||
421 | //_____________________________________________________________________________ | |
422 | AliMp::PlaneType | |
423 | AliMUONPainterHelper::GetPlaneType(Int_t manuId) const | |
424 | { | |
425 | /// Get the planeType of a given manu | |
426 | ||
427 | if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) | |
428 | { | |
429 | return AliMp::kNonBendingPlane; | |
430 | } | |
431 | return AliMp::kBendingPlane; | |
432 | } | |
433 | ||
434 | //_____________________________________________________________________________ | |
435 | const AliMpSlat* | |
436 | AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::PlaneType planeType) const | |
437 | { | |
438 | /// Get a given slat | |
439 | ||
440 | AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId, | |
441 | planeType); | |
442 | ||
443 | return GetSlat(detElemId,cathodeType); | |
444 | } | |
445 | ||
446 | //_____________________________________________________________________________ | |
447 | const AliMpSector* | |
448 | AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) const | |
449 | { | |
450 | /// Get a given sector | |
451 | AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId); | |
4e51cfd2 | 452 | if ( stationType != AliMp::kStation12 ) return 0x0; |
0145e89a | 453 | |
454 | AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType); | |
455 | ||
f3ed9a44 | 456 | return AliMpSegmentation::Instance()->GetSector(detElemId,cathodeType); |
0145e89a | 457 | } |
458 | ||
459 | //_____________________________________________________________________________ | |
460 | const AliMpSlat* | |
461 | AliMUONPainterHelper::GetSlat(Int_t detElemId, AliMp::CathodType cathodeType) const | |
462 | { | |
463 | /// Get a given slat | |
464 | AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId); | |
465 | if ( stationType != AliMp::kStation345 ) return 0x0; | |
466 | ||
f3ed9a44 | 467 | return AliMpSegmentation::Instance()->GetSlat(detElemId,cathodeType); |
0145e89a | 468 | } |
469 | ||
470 | //_____________________________________________________________________________ | |
471 | const AliMpSlat* | |
472 | AliMUONPainterHelper::GetSlat(Int_t detElemId, Int_t manuId) const | |
473 | { | |
474 | /// Get a given slat | |
f3ed9a44 | 475 | AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId); |
476 | if ( stationType != AliMp::kStation345 ) return 0x0; | |
477 | ||
478 | return AliMpSegmentation::Instance()->GetSlatByElectronics(detElemId,manuId); | |
0145e89a | 479 | } |
480 | ||
481 | //_____________________________________________________________________________ | |
482 | AliMUONPainterHelper* | |
483 | AliMUONPainterHelper::Instance() | |
484 | { | |
485 | /// Return the global and unique instance of this class | |
486 | ||
487 | if (fgInstance) return fgInstance; | |
488 | ||
489 | AliMUONPainterEnv env; | |
490 | ||
49419555 | 491 | TString fileName(gSystem->ExpandPathName(env.String("PadStoreFileName","$HOME/padstore.root"))); |
0145e89a | 492 | |
493 | if ( gSystem->AccessPathName(fileName.Data(),kFileExists) ) // mind the strange return value of that method... | |
494 | { | |
495 | // file does NOT exist yet. Create it | |
496 | AliDebugClass(1,"Generating instance"); | |
497 | ||
498 | Int_t ret; | |
499 | ||
500 | new TGMsgBox(gClient->GetRoot(),gClient->GetRoot(),"", | |
501 | Form("File %s not found.\nI will generate it, and this will take a while.\n" | |
502 | "Click OK (and grab a cup of coffee ;-) ) to proceed,\n or Cancel to quit.",fileName.Data()), | |
503 | kMBIconQuestion, | |
504 | kMBOk | kMBCancel, | |
505 | &ret); | |
506 | if ( ret == kMBCancel ) exit(1); | |
507 | ||
508 | fgInstance = new AliMUONPainterHelper; | |
509 | fgInstance->GenerateGeometry(); | |
510 | fgInstance->GeneratePadStore(); | |
511 | fgInstance->GenerateDefaultMatrices(); | |
512 | fgInstance->Modified(kTRUE); | |
513 | fgInstance->fEnv = new AliMUONPainterEnv; | |
49419555 | 514 | fgInstance->fEnv->Set("PadStoreFileName",fileName.Data()); |
0145e89a | 515 | fgInstance->Save(); |
516 | ||
517 | } | |
518 | else | |
519 | { | |
520 | AliDebugClass(1,"Reading instance"); | |
521 | TFile f(fileName.Data()); | |
522 | fgInstance = static_cast<AliMUONPainterHelper*>(f.Get("AliMUONPainterHelper")); | |
523 | ||
524 | TIter next(fgInstance->fPainterMatrices); | |
525 | AliMUONPainterMatrix* matrix; | |
526 | while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) ) | |
527 | { | |
528 | AliMUONPainterRegistry::Instance()->Register(matrix); | |
529 | } | |
530 | fgInstance->fPainterMatrices->SetOwner(kFALSE); | |
531 | fgInstance->fEnv = new AliMUONPainterEnv; | |
532 | } | |
533 | return fgInstance; | |
534 | } | |
535 | ||
536 | //_____________________________________________________________________________ | |
537 | void | |
538 | AliMUONPainterHelper::Global2Local(Int_t detElemId, | |
539 | Double_t xg, Double_t yg, Double_t zg, | |
540 | Double_t& xl, Double_t& yl, Double_t& zl) const | |
541 | { | |
542 | /// Local to global transformation of coordinates | |
543 | ||
544 | TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExplodedGlobalTransformations->GetValue(detElemId)); | |
545 | Double_t pg[3] = { xg, yg, zg }; | |
546 | Double_t pl[3] = { 0., 0., 0. }; | |
547 | matrix->MasterToLocal(pg, pl); | |
548 | xl = pl[0]; | |
549 | yl = pl[1]; | |
550 | zl = pl[2]; | |
551 | } | |
552 | ||
553 | //_____________________________________________________________________________ | |
554 | void | |
555 | AliMUONPainterHelper::Global2LocalReal(Int_t detElemId, | |
556 | Double_t xg, Double_t yg, Double_t zg, | |
557 | Double_t& xl, Double_t& yl, Double_t& zl) const | |
558 | { | |
559 | /// Local to global transformation of coordinates | |
560 | ||
561 | TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fRealGlobalTransformations->GetValue(detElemId)); | |
562 | Double_t pg[3] = { xg, yg, zg }; | |
563 | Double_t pl[3] = { 0., 0., 0. }; | |
564 | matrix->MasterToLocal(pg, pl); | |
565 | xl = pl[0]; | |
566 | yl = pl[1]; | |
567 | zl = pl[2]; | |
568 | } | |
569 | ||
570 | //_____________________________________________________________________________ | |
571 | void | |
572 | AliMUONPainterHelper::Local2Global(Int_t detElemId, | |
573 | Double_t xl, Double_t yl, Double_t zl, | |
574 | Double_t& xg, Double_t& yg, Double_t& zg) const | |
575 | { | |
576 | /// Local to (exploded) global transformation of coordinates | |
577 | ||
578 | TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fExplodedGlobalTransformations->GetValue(detElemId)); | |
579 | Double_t pl[3] = { xl, yl, zl }; | |
580 | Double_t pg[3] = { 0., 0., 0. }; | |
581 | matrix->LocalToMaster(pl, pg); | |
582 | xg = pg[0]; | |
583 | yg = pg[1]; | |
584 | zg = pg[2]; | |
585 | } | |
586 | ||
587 | //_____________________________________________________________________________ | |
588 | void | |
589 | AliMUONPainterHelper::Local2GlobalReal(Int_t detElemId, | |
590 | Double_t xl, Double_t yl, Double_t zl, | |
591 | Double_t& xg, Double_t& yg, Double_t& zg) const | |
592 | { | |
593 | /// Local to (real) global transformation of coordinates | |
594 | ||
595 | TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(fRealGlobalTransformations->GetValue(detElemId)); | |
596 | Double_t pl[3] = { xl, yl, zl }; | |
597 | Double_t pg[3] = { 0., 0., 0. }; | |
598 | matrix->LocalToMaster(pl, pg); | |
599 | xg = pg[0]; | |
600 | yg = pg[1]; | |
601 | zg = pg[2]; | |
602 | } | |
603 | ||
604 | //_____________________________________________________________________________ | |
605 | Int_t | |
606 | AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max) const | |
607 | { | |
608 | /// Convert a value into a color, fitting within a given range | |
609 | ||
610 | Int_t rv; | |
611 | ||
612 | if (value > max) rv = 1; | |
613 | else if (value <= min) rv = 0; | |
614 | else | |
615 | { | |
616 | if ( max == min ) return gStyle->GetColorPalette(1); | |
617 | Double_t range = max - min; | |
618 | Double_t offset = value - min; | |
619 | rv = gStyle->GetColorPalette( 1 + int( offset*(gStyle->GetNumberOfColors()-2)/range - 0.5 ) ); | |
620 | } | |
621 | return rv; | |
622 | } | |
623 | ||
624 | //_____________________________________________________________________________ | |
625 | AliMUONPainterContour* | |
626 | AliMUONPainterHelper::MergeContours(const TObjArray& contours, | |
627 | const char* contourName) | |
628 | { | |
629 | /// Merge a set of contours (delegating to the contour maker) | |
630 | if (!fContourMaker) | |
631 | { | |
632 | fContourMaker = new AliMUONPainterContourMaker(fExplodedGlobalTransformations); | |
633 | } | |
634 | ||
635 | AliMUONPainterContour* contour = fContourMaker->MergeContours(contours, | |
636 | contourName); | |
637 | ||
638 | if (contour) | |
639 | { | |
640 | RegisterContour(contour); | |
641 | } | |
642 | return contour; | |
643 | } | |
644 | ||
645 | ||
646 | //_____________________________________________________________________________ | |
647 | void | |
648 | AliMUONPainterHelper::Print(Option_t* opt) const | |
649 | { | |
650 | /// Printout | |
651 | TString sopt(opt); | |
652 | sopt.ToUpper(); | |
653 | ||
654 | if ( sopt.Length() == 0 ) | |
655 | { | |
656 | cout << Form("ExplodeFactor=%e,%e",fExplodeFactor[0],fExplodeFactor[1]) << endl; | |
657 | cout << Form("PadStore=%x",fPadStore); | |
658 | if ( fPadStore ) cout << Form(" with %d pads",fPadStore->GetSize()); | |
659 | cout << endl; | |
660 | cout << Form("GlobalTransformations=%x",fExplodedGlobalTransformations); | |
661 | if ( fExplodedGlobalTransformations ) cout << Form(" with %d transformations",fExplodedGlobalTransformations->GetSize()); | |
662 | cout << endl; | |
663 | if ( fContourMaker ) | |
664 | { | |
665 | cout << Form(" with %d contours",fContourMaker->Size()); | |
666 | } | |
667 | else | |
668 | { | |
669 | cout << "No contour"; | |
670 | } | |
671 | cout << endl; | |
672 | cout << "Modified="; | |
673 | if ( IsModified() ) | |
674 | { | |
675 | cout << "YES"; | |
676 | } | |
677 | else | |
678 | { | |
679 | cout << "NO"; | |
680 | } | |
681 | cout << endl; | |
682 | } | |
683 | ||
684 | if ( sopt.Contains("CONTOUR") || sopt.Contains("FULL") ) | |
685 | { | |
686 | fContourMaker->Print(opt); | |
687 | } | |
688 | ||
689 | if ( sopt.Contains("MATRI") || sopt.Contains("FULL") ) | |
690 | { | |
691 | fPainterMatrices->Print(opt); | |
692 | } | |
693 | } | |
694 | ||
695 | //_____________________________________________________________________________ | |
696 | void | |
697 | AliMUONPainterHelper::RegisterContour(AliMUONPainterContour* contour) | |
698 | { | |
699 | /// contour is adopted by contourMaker | |
700 | AliCodeTimerAuto("") | |
701 | AliDebug(1,contour->GetName()); | |
702 | if ( fContourMaker->HasContour(contour->GetName()) ) | |
703 | { | |
704 | AliError(Form("Contour with name %s is already there",contour->GetName())); | |
705 | // Print("CONTOUR"); | |
706 | return; | |
707 | } | |
708 | fContourMaker->Add(contour); | |
709 | Modified(kTRUE); | |
710 | } | |
711 | ||
712 | //_____________________________________________________________________________ | |
713 | void | |
714 | AliMUONPainterHelper::Save() | |
715 | { | |
716 | /// Save to disk | |
717 | ||
718 | if (!IsModified()) return; | |
719 | ||
720 | Modified(kFALSE); | |
721 | ||
722 | AliInfo(""); | |
723 | ||
724 | fgInstance->Print(); | |
725 | ||
49419555 | 726 | fgInstance->Env()->Save(); |
727 | ||
728 | TString fileName(gSystem->ExpandPathName(fgInstance->Env()->String("PadStoreFileName"))); | |
0145e89a | 729 | |
730 | AliInfo(Form("Saving to %s",fileName.Data())); | |
731 | ||
732 | TFile f(fileName,"RECREATE"); | |
733 | ||
734 | fgInstance->Write(""); | |
735 | ||
736 | f.Close(); | |
737 | } | |
738 | ||
739 | //_____________________________________________________________________________ | |
740 | AliMpPad | |
741 | AliMUONPainterHelper::PadByExplodedPosition(Int_t detElemId, Int_t manuId, | |
742 | Double_t x, Double_t y) const | |
743 | { | |
744 | /// Find a pad by exploded position. FIXME: not really used nor tested ! | |
745 | ||
746 | Double_t xr, yr, zr; | |
747 | ||
748 | // Local2Global(detElemId,0.0,0.0,0.0,dummy,dummy,z); // to find z | |
749 | ||
750 | AliDebug(1,Form("DE %04d ManuID %04d x %7.3f y %7.3f",detElemId,manuId,x,y)); | |
751 | ||
752 | Exploded2Real(detElemId,x,y,0,xr,yr,zr); | |
753 | ||
754 | AliDebug(1,Form("xr %7.3f yr %7.3f zr %7.3f",xr,yr,zr)); | |
755 | ||
756 | Double_t xl,yl,zl; | |
757 | ||
758 | Global2LocalReal(detElemId,xr,yr,zr,xl,yl,zl); | |
759 | ||
760 | AliDebug(1,Form("xl %7.3f yl %7.3f zl %7.3f",xl,yl,zl)); | |
761 | ||
762 | const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId); | |
763 | ||
6e97fbb8 | 764 | AliDebug(1,Form("dx,dy=%7.3f,%7.3f",seg->GetDimensionX(),seg->GetDimensionY())); |
0145e89a | 765 | |
6e97fbb8 | 766 | return seg->PadByPosition(xl,yl); |
0145e89a | 767 | } |
768 | ||
769 | //_____________________________________________________________________________ | |
770 | void | |
771 | AliMUONPainterHelper::Exploded2Real(Int_t detElemId, | |
772 | Double_t xe, Double_t ye, Double_t ze, | |
773 | Double_t& xr, Double_t& yr, Double_t& zr) const | |
774 | { | |
775 | /// Convert exploded coordinates into real ones. FIXME: not really used nor tested ! | |
776 | ||
777 | // first go back to local | |
778 | ||
779 | Double_t xl,yl,zl; | |
780 | ||
781 | Global2Local(detElemId,xe,ye,ze,xl,yl,zl); | |
782 | ||
783 | // and then back to global but not exploded | |
784 | ||
785 | Local2GlobalReal(detElemId,xl,yl,zl,xr,yr,zr); | |
786 | } | |
787 | ||
788 | //_____________________________________________________________________________ | |
789 | TString | |
790 | AliMUONPainterHelper::ChamberName(Int_t chamberId) const | |
791 | { | |
792 | /// Build a name for one chamber | |
793 | return Form("Chamber%1d",chamberId); | |
794 | } | |
795 | ||
796 | //_____________________________________________________________________________ | |
797 | TString | |
798 | AliMUONPainterHelper::StationName(Int_t stationId) const | |
799 | { | |
800 | /// Build a name for one station | |
801 | return Form("Station%1d",stationId+1); | |
802 | } | |
803 | ||
804 | //_____________________________________________________________________________ | |
805 | TString | |
806 | AliMUONPainterHelper::DEName(Int_t detElemId) const | |
807 | { | |
808 | /// Build a name for one detection element | |
809 | return Form("DE%04d",detElemId); | |
810 | } | |
811 | ||
812 | //_____________________________________________________________________________ | |
813 | TString | |
814 | AliMUONPainterHelper::ManuName(Int_t manuId) const | |
815 | { | |
816 | /// Build a name for one manu | |
817 | return Form("MANU%04d",manuId); | |
818 | } | |
819 | ||
820 | //_____________________________________________________________________________ | |
821 | TString | |
822 | AliMUONPainterHelper::BusPatchName(Int_t busPatchId) const | |
823 | { | |
824 | /// Build a name for one buspatch | |
825 | return Form("BUSPATCH%04d",busPatchId); | |
826 | } | |
827 | ||
828 | //_____________________________________________________________________________ | |
829 | TString | |
830 | AliMUONPainterHelper::PCBName(Int_t pcbNumber) const | |
831 | { | |
832 | /// Build a name for one pcb | |
833 | return Form("PCB%1d",pcbNumber); | |
834 | } | |
835 | ||
836 | //_____________________________________________________________________________ | |
837 | TString | |
838 | AliMUONPainterHelper::ChamberPathName(Int_t chamberId) const | |
839 | { | |
840 | /// Build a name for one chamber | |
841 | return Form("%s/%s",StationName(chamberId/2).Data(),ChamberName(chamberId).Data()); | |
842 | } | |
843 | ||
844 | //_____________________________________________________________________________ | |
845 | TString | |
846 | AliMUONPainterHelper::StationPathName(Int_t stationId) const | |
847 | { | |
848 | /// Build a name for one station | |
849 | return StationName(stationId); | |
850 | } | |
851 | ||
852 | //_____________________________________________________________________________ | |
853 | TString | |
854 | AliMUONPainterHelper::DEPathName(Int_t detElemId) const | |
855 | { | |
856 | /// Build a name for one detection element | |
857 | ||
858 | Int_t chamberId = AliMpDEManager::GetChamberId(detElemId); | |
859 | ||
860 | return Form("%s/%s/%s", | |
861 | StationName(chamberId/2).Data(), | |
862 | ChamberName(chamberId).Data(), | |
863 | DEName(detElemId).Data()); | |
864 | } | |
865 | ||
866 | //_____________________________________________________________________________ | |
867 | TString | |
868 | AliMUONPainterHelper::ManuPathName(Int_t detElemId, Int_t manuId) const | |
869 | { | |
870 | /// Build a name for one manu | |
871 | return Form("%s/%s",DEPathName(detElemId).Data(),ManuName(manuId).Data()); | |
872 | } | |
873 | ||
874 | //_____________________________________________________________________________ | |
875 | TString | |
876 | AliMUONPainterHelper::BusPatchPathName(Int_t busPatchId) const | |
877 | { | |
878 | /// Build a name for one buspatch | |
879 | Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId); | |
880 | ||
881 | return Form("%s/%s",DEPathName(detElemId).Data(),BusPatchName(busPatchId).Data()); | |
882 | } | |
883 | ||
884 | //_____________________________________________________________________________ | |
885 | TString | |
886 | AliMUONPainterHelper::PCBPathName(Int_t detElemId, Int_t pcbNumber) const | |
887 | { | |
888 | /// Build a name for one pcb | |
889 | return Form("%s/%s",DEPathName(detElemId).Data(),PCBName(pcbNumber).Data()); | |
890 | } | |
891 | ||
892 | //_____________________________________________________________________________ | |
893 | TString | |
894 | AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const | |
895 | { | |
896 | /// Format a double value to be displayed | |
897 | /// FIXME: should insure we have the right number of significant digits here... | |
898 | ||
899 | return Form("%s = %e",name,value); | |
900 | } |