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 : //-----------------------------------------------------------------------------
19 : // Class AliMUONGeometryEnvelopeStore
20 : // ----------------------------------
21 : // Class for definititon of the temporary volume envelopes
22 : // used in geometry construction
23 : // Author: Ivana Hrivnacova, IPN Orsay
24 : //-----------------------------------------------------------------------------
25 :
26 : #include "AliMUONGeometryEnvelopeStore.h"
27 : #include "AliMUONGeometryEnvelope.h"
28 : #include "AliMUONGeometryDetElement.h"
29 : #include "AliMUONGeometryBuilder.h"
30 :
31 : #include "AliMpExMap.h"
32 :
33 : #include "AliLog.h"
34 :
35 : #include <TGeoMatrix.h>
36 : #include <TObjArray.h>
37 : #include <Riostream.h>
38 : #include <TString.h>
39 :
40 : using std::cout;
41 : using std::endl;
42 : /// \cond CLASSIMP
43 18 : ClassImp(AliMUONGeometryEnvelopeStore)
44 : /// \endcond
45 :
46 : //______________________________________________________________________________
47 : AliMUONGeometryEnvelopeStore::AliMUONGeometryEnvelopeStore(
48 : AliMpExMap* detElements)
49 20 : : TObject(),
50 20 : fEnvelopes(0),
51 20 : fDetElements(detElements),
52 20 : fReferenceFrame(),
53 20 : fDebug(false),
54 20 : fAlign(false)
55 100 : {
56 : /// Standard constructor
57 :
58 60 : fEnvelopes = new TObjArray(100);
59 40 : }
60 :
61 :
62 : //______________________________________________________________________________
63 : AliMUONGeometryEnvelopeStore::AliMUONGeometryEnvelopeStore()
64 240 : : TObject(),
65 240 : fEnvelopes(0),
66 240 : fDetElements(0),
67 240 : fReferenceFrame(),
68 240 : fDebug(false),
69 240 : fAlign(false)
70 1200 : {
71 : /// Default constructor
72 480 : }
73 :
74 :
75 : //______________________________________________________________________________
76 : AliMUONGeometryEnvelopeStore::~AliMUONGeometryEnvelopeStore()
77 1560 : {
78 : /// Destructor
79 :
80 : // Add deleting rotation matrices
81 :
82 260 : if (fEnvelopes) {
83 260 : fEnvelopes->Delete();
84 520 : delete fEnvelopes;
85 : }
86 780 : }
87 :
88 : //
89 : // private methods
90 : //
91 :
92 : //______________________________________________________________________________
93 : TGeoHMatrix
94 : AliMUONGeometryEnvelopeStore::ConvertDETransform(const TGeoHMatrix& transform) const
95 : {
96 : /// Convert transformation into the reference frame
97 :
98 0 : if ( fReferenceFrame.IsIdentity() )
99 0 : return transform;
100 : else {
101 0 : return AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
102 0 : transform );
103 : }
104 0 : }
105 :
106 : //______________________________________________________________________________
107 : AliMUONGeometryEnvelope*
108 : AliMUONGeometryEnvelopeStore::FindEnvelope(const TString& name) const
109 : {
110 : /// Find the envelope specified by name.
111 :
112 405456 : for (Int_t i=0; i<fEnvelopes->GetEntriesFast(); i++) {
113 : AliMUONGeometryEnvelope* envelope
114 199334 : = (AliMUONGeometryEnvelope*)fEnvelopes->At(i);
115 :
116 202786 : if (envelope->GetName() == name) return envelope;
117 195882 : }
118 :
119 834 : return 0;
120 4286 : }
121 :
122 : //______________________________________________________________________________
123 : Bool_t AliMUONGeometryEnvelopeStore::AlignEnvelope(
124 : AliMUONGeometryEnvelope* envelope) const
125 : {
126 : /// Find transformation by the detection element Id (if not 0)
127 : /// (= unique ID of enevelope) and set it to the envelope.
128 : /// Return true if transformation is applied, false otherwise.
129 :
130 0 : Int_t detElemId = envelope->GetUniqueID();
131 0 : if (detElemId == 0) return false;
132 :
133 : AliMUONGeometryDetElement* detElement
134 0 : = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
135 0 : if (!detElement) {
136 0 : AliWarning("Transformation not found.");
137 0 : return false;
138 : };
139 :
140 : // Apply frame transform
141 0 : TGeoHMatrix newTransform
142 0 : = ConvertDETransform(*(detElement->GetLocalTransformation()));
143 :
144 0 : envelope->SetTransform(newTransform);
145 :
146 : return true;
147 0 : }
148 :
149 : //
150 : // public methods
151 : //
152 :
153 : //______________________________________________________________________________
154 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
155 : Int_t id,
156 : Bool_t isVirtual,
157 : const char* only)
158 : {
159 : /// Add the volume with the specified name and transformation
160 : /// to the list of envelopes.
161 :
162 0 : if (!isVirtual) AliDebug(1,Form("Adding non-virtual envelope %s id %d",name.Data(),id));
163 : // else AliDebug(1,Form("Adding virtual envelope %s id %d",name.Data(),id));
164 :
165 : AliMUONGeometryEnvelope* envelope
166 0 : = new AliMUONGeometryEnvelope(name, id, isVirtual, only);
167 :
168 0 : if (fAlign) AlignEnvelope(envelope);
169 :
170 0 : fEnvelopes->Add(envelope);
171 0 : }
172 :
173 : //______________________________________________________________________________
174 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
175 : Int_t id,
176 : Bool_t isVirtual,
177 : const TGeoTranslation& translation,
178 : const char* only)
179 : {
180 : /// Add the volume with the specified name and transformation
181 : /// to the list of envelopes.
182 :
183 504 : if (fDebug) {
184 0 : cout << "... Adding ";
185 0 : if (!isVirtual) cout << " non-";
186 0 : cout << "virtual envelope " << name
187 0 : << " id " << id
188 0 : << " with translation" << endl;
189 0 : }
190 :
191 : AliMUONGeometryEnvelope* envelope
192 504 : = new AliMUONGeometryEnvelope(name, id, isVirtual, only);
193 :
194 : Bool_t aligned = false;
195 504 : if (fAlign) aligned = AlignEnvelope(envelope);
196 :
197 504 : if (!aligned)
198 504 : envelope->SetTranslation(translation);
199 :
200 504 : fEnvelopes->Add(envelope);
201 504 : }
202 :
203 : //______________________________________________________________________________
204 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
205 : Int_t id,
206 : Bool_t isVirtual,
207 : const TGeoTranslation& translation,
208 : const TGeoRotation& rotation,
209 : const char* only)
210 : {
211 : /// Add the volume with the specified name and transformation
212 : /// to the list of envelopes.
213 :
214 828 : if (fDebug) {
215 0 : cout << "... Adding ";
216 0 : if (!isVirtual) cout << " non-";
217 0 : cout << "virtual envelope " << name
218 0 : << " id " << id
219 0 : << " with translation and rotation" << endl;
220 0 : }
221 :
222 : /*
223 : cout << "Adding env... name: " << name;
224 :
225 : const Double_t* xyz = translation.GetTranslation();
226 : cout << " translation: " << xyz[0] << ", " << xyz[1] << ", " << xyz[2]
227 : << " rotation: ";
228 :
229 : Double_t a1, a2, a3, a4, a5, a6;
230 : rotation.GetAngles(a1, a2, a3, a4, a5, a6);
231 : cout << a1 << ", " << a2 << ", " << a3 << ", " << a4 << ", " << a5 << ", " << a6 << endl;
232 : */
233 : // fEnvelopes->Add(new TGeoCombiTrans(name, translation, rotation));
234 : // would be nice to be so simple
235 :
236 : AliMUONGeometryEnvelope* envelope
237 828 : = new AliMUONGeometryEnvelope(name, id, isVirtual, only);
238 :
239 : Bool_t aligned = false;
240 828 : if (fAlign) aligned = AlignEnvelope(envelope);
241 :
242 828 : if (!aligned) {
243 828 : envelope->SetRotation(rotation);
244 828 : envelope->SetTranslation(translation);
245 828 : }
246 :
247 828 : fEnvelopes->Add(envelope);
248 828 : }
249 :
250 : //______________________________________________________________________________
251 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
252 : Int_t id,
253 : Bool_t isVirtual,
254 : const TGeoCombiTrans& transform,
255 : const char* only)
256 : {
257 : /// Add the volume with the specified name and transformation
258 : /// to the list of envelopes.
259 :
260 0 : if (fDebug) {
261 0 : cout << "... Adding ";
262 0 : if (!isVirtual) cout << " non-";
263 0 : cout << "virtual envelope " << name
264 0 : << " id " << id
265 0 : << " with transformation" << endl;
266 0 : }
267 :
268 : // fEnvelopes->Add(new TGeoCombiTrans(name, translation, rotation));
269 : // would be nice to be so simple
270 :
271 : AliMUONGeometryEnvelope* envelope
272 0 : = new AliMUONGeometryEnvelope(name, id, isVirtual, only);
273 :
274 : Bool_t aligned = false;
275 0 : if (fAlign) aligned = AlignEnvelope(envelope);
276 :
277 0 : if (!aligned)
278 0 : envelope->SetTransform(transform);
279 :
280 0 : fEnvelopes->Add(envelope);
281 0 : }
282 :
283 : //______________________________________________________________________________
284 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
285 : Int_t id,
286 : Int_t copyNo,
287 : const char* only)
288 : {
289 : /// Add the volume with the specified name and transformation
290 : /// to the list of envelopes.
291 :
292 0 : if (fDebug) {
293 0 : cout << "... Adding "
294 0 : << " non-virtual envelope " << name
295 0 : << " id " << id
296 0 : << " with copyNo " << copyNo << endl;
297 0 : }
298 :
299 : AliMUONGeometryEnvelope* envelope
300 0 : = new AliMUONGeometryEnvelope(name, id, copyNo, only);
301 :
302 0 : if (fAlign) AlignEnvelope(envelope);
303 :
304 0 : fEnvelopes->Add(envelope);
305 0 : }
306 :
307 : //______________________________________________________________________________
308 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
309 : Int_t id,
310 : Int_t copyNo,
311 : const TGeoTranslation& translation,
312 : const char* only)
313 : {
314 : /// Add the volume with the specified name and transformation
315 : /// to the list of envelopes.
316 :
317 16 : if (fDebug) {
318 0 : cout << "... Adding "
319 0 : << " non-virtual envelope " << name
320 0 : << " id " << id
321 0 : << " with copyNo " << copyNo
322 0 : << " with translation " << endl;
323 0 : }
324 :
325 : AliMUONGeometryEnvelope* envelope
326 8 : = new AliMUONGeometryEnvelope(name, id, copyNo, only);
327 :
328 : Bool_t aligned = false;
329 8 : if (fAlign) aligned = AlignEnvelope(envelope);
330 :
331 8 : if (!aligned)
332 8 : envelope->SetTranslation(translation);
333 :
334 8 : fEnvelopes->Add(envelope);
335 8 : }
336 :
337 : //______________________________________________________________________________
338 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
339 : Int_t id,
340 : Int_t copyNo,
341 : const TGeoTranslation& translation,
342 : const TGeoRotation& rotation,
343 : const char* only)
344 : {
345 : /// Add the volume with the specified name and transformation
346 : /// to the list of envelopes.
347 :
348 12 : if (fDebug) {
349 0 : cout << "... Adding "
350 0 : << " non-virtual envelope " << name
351 0 : << " id " << id
352 0 : << " with copyNo " << copyNo
353 0 : << " with translation and rotation" << endl;
354 0 : }
355 :
356 : // fEnvelopes->Add(new TGeoCombiTrans(name, translation, rotation));
357 : // would be nice to be so simple
358 :
359 : AliMUONGeometryEnvelope* envelope
360 6 : = new AliMUONGeometryEnvelope(name, id, copyNo, only);
361 :
362 : Bool_t aligned = false;
363 6 : if (fAlign) aligned = AlignEnvelope(envelope);
364 :
365 6 : if (!aligned) {
366 6 : envelope->SetRotation(rotation);
367 6 : envelope->SetTranslation(translation);
368 6 : }
369 :
370 6 : fEnvelopes->Add(envelope);
371 6 : }
372 :
373 : //______________________________________________________________________________
374 : void AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name,
375 : Int_t id,
376 : Int_t copyNo,
377 : const TGeoCombiTrans& transform,
378 : const char* only)
379 : {
380 : /// Add the volume with the specified name and transformation
381 : /// to the list of envelopes.
382 :
383 12 : if (fDebug) {
384 0 : cout << "... Adding "
385 0 : << " non-virtual envelope " << name
386 0 : << " id " << id
387 0 : << " with copyNo " << copyNo
388 0 : << " with translation and rotation" << endl;
389 0 : }
390 :
391 : // fEnvelopes->Add(new TGeoCombiTrans(name, translation, rotation));
392 : // would be nice to be so simple
393 :
394 : AliMUONGeometryEnvelope* envelope
395 6 : = new AliMUONGeometryEnvelope(name, id, copyNo, only);
396 :
397 : Bool_t aligned = false;
398 6 : if (fAlign) aligned = AlignEnvelope(envelope);
399 :
400 6 : if (!aligned)
401 6 : envelope->SetTransform(transform);
402 :
403 6 : fEnvelopes->Add(envelope);
404 6 : }
405 :
406 : //______________________________________________________________________________
407 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name,
408 : const TString& envName, Int_t copyNo)
409 : {
410 : /// Add the volume with the specified name and transformation
411 : /// as a constituent of the envelope envName.
412 :
413 0 : if (fDebug) {
414 0 : cout << "... Adding constituent " << name
415 0 : << " to envelope " << envName
416 0 : << " with copyNo " << copyNo << endl;
417 0 : }
418 :
419 0 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
420 :
421 0 : if (!envelope) {
422 : // add warning
423 0 : return;
424 : }
425 :
426 0 : envelope->AddConstituent(name, copyNo);
427 0 : }
428 :
429 : //______________________________________________________________________________
430 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name,
431 : const TString& envName, Int_t copyNo,
432 : const TGeoTranslation& translation)
433 : {
434 : /// Add the volume with the specified name and transformation
435 : /// as a constituent of the envelope envName.
436 :
437 3288 : if (fDebug) {
438 0 : cout << "... Adding constituent " << name
439 0 : << " to envelope " << envName
440 0 : << " with copyNo " << copyNo
441 0 : << " with translation" << endl;
442 0 : }
443 :
444 1644 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
445 :
446 1644 : if (!envelope) {
447 : // add warning
448 0 : return;
449 : }
450 :
451 1644 : envelope->AddConstituent(name, copyNo, translation);
452 3288 : }
453 :
454 : //______________________________________________________________________________
455 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name,
456 : const TString& envName, Int_t copyNo,
457 : const TGeoTranslation& translation,
458 : const TGeoRotation& rotation)
459 : {
460 : /// Add the volume with the specified name and transformation
461 : /// as a constituent of the envelope envName.
462 :
463 936 : if (fDebug) {
464 0 : cout << "... Adding constituent " << name
465 0 : << " to envelope " << envName
466 0 : << " with copyNo " << copyNo
467 0 : << " with translation and rotation" << endl;
468 0 : }
469 :
470 468 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
471 :
472 468 : if (!envelope) {
473 : // add warning
474 0 : return;
475 : }
476 :
477 468 : envelope->AddConstituent(name, copyNo, translation, rotation);
478 936 : }
479 :
480 : //______________________________________________________________________________
481 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name,
482 : const TString& envName, Int_t copyNo,
483 : const TGeoCombiTrans& transform)
484 : {
485 : /// Add the volume with the specified name and transformation
486 : /// as a constituent of the envelope envName.
487 :
488 0 : if (fDebug) {
489 0 : cout << "... Adding constituent " << name
490 0 : << " to envelope " << envName
491 0 : << " with copyNo " << copyNo
492 0 : << " with translation and rotation" << endl;
493 0 : }
494 :
495 0 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
496 :
497 0 : if (!envelope) {
498 : // add warning
499 0 : return;
500 : }
501 :
502 0 : envelope->AddConstituent(name, copyNo, transform);
503 0 : }
504 :
505 : //______________________________________________________________________________
506 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name,
507 : const TString& envName, Int_t copyNo,
508 : Int_t npar, Double_t* param)
509 : {
510 : /// Add the volume with the specified name and transformation
511 : /// as a constituent of the envelope envName.
512 :
513 2336 : if (fDebug) {
514 0 : cout << "... Adding parameterised constituent " << name
515 0 : << " to envelope " << envName
516 0 : << " with copyNo " << copyNo << endl;
517 0 : }
518 :
519 1168 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
520 :
521 1168 : if (!envelope) {
522 : // add warning
523 0 : return;
524 : }
525 :
526 1168 : envelope->AddConstituentParam(name, copyNo, npar, param);
527 2336 : }
528 :
529 : //______________________________________________________________________________
530 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name,
531 : const TString& envName, Int_t copyNo,
532 : const TGeoTranslation& translation,
533 : Int_t npar, Double_t* param)
534 : {
535 : /// Add the volume with the specified name and transformation
536 : /// as a constituent of the envelope envName.
537 :
538 64 : if (fDebug) {
539 0 : cout << "... Adding parameterised constituent " << name
540 0 : << " to envelope " << envName
541 0 : << " with copyNo " << copyNo
542 0 : << " with translation" << endl;
543 0 : }
544 :
545 32 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
546 :
547 32 : if (!envelope) {
548 : // add warning
549 0 : return;
550 : }
551 :
552 32 : envelope->AddConstituentParam(name, copyNo, translation, npar, param);
553 64 : }
554 :
555 : //______________________________________________________________________________
556 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name,
557 : const TString& envName, Int_t copyNo,
558 : const TGeoTranslation& translation,
559 : const TGeoRotation& rotation,
560 : Int_t npar, Double_t* param)
561 : {
562 : /// Add the volume with the specified name and transformation
563 : /// as a constituent of the envelope envName.
564 :
565 0 : if (fDebug) {
566 0 : cout << "... Adding parameterised constituent " << name
567 0 : << " to envelope " << envName
568 0 : << " with copyNo " << copyNo
569 0 : << " with translation and rotation" << endl;
570 0 : }
571 :
572 0 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
573 :
574 0 : if (!envelope) {
575 : // add warning
576 0 : return;
577 : }
578 :
579 0 : envelope->AddConstituentParam(name, copyNo, translation, rotation, npar, param);
580 0 : }
581 :
582 : //______________________________________________________________________________
583 : void AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name,
584 : const TString& envName, Int_t copyNo,
585 : const TGeoCombiTrans& transform,
586 : Int_t npar, Double_t* param)
587 : {
588 : /// Add the volume with the specified name and transformation
589 : /// as a constituent of the envelope envName.
590 :
591 0 : if (fDebug) {
592 0 : cout << "... Adding parameterised constituent " << name
593 0 : << " to envelope " << envName
594 0 : << " with copyNo " << copyNo
595 0 : << " with translation and rotation" << endl;
596 0 : }
597 :
598 0 : AliMUONGeometryEnvelope* envelope = FindEnvelope(envName);
599 :
600 0 : if (!envelope) {
601 : // add warning
602 0 : return;
603 : }
604 :
605 0 : envelope->AddConstituentParam(name, copyNo, transform, npar, param);
606 0 : }
607 :
608 : //______________________________________________________________________________
609 : Int_t AliMUONGeometryEnvelopeStore::GetNofDetElements() const
610 : {
611 : /// Return the number od envelopes with detElemId>0.
612 :
613 : Int_t nofDetElems = 0;
614 :
615 0 : for(Int_t i=0; i<fEnvelopes->GetEntriesFast(); i++)
616 0 : if ( fEnvelopes->At(i)->GetUniqueID() > 0 ) nofDetElems++;
617 :
618 0 : return nofDetElems;
619 : }
|