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