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