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