]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryEnvelopeStore.cxx
01b66d99bf31b499c7c07755bf4b866a9225199c
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryEnvelopeStore.cxx
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 // 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"
32 #include "AliMUONGeometryEnvelope.h"
33 #include "AliMUONGeometryDetElement.h"
34 #include "AliMUONGeometryStore.h"
35 #include "AliMUONConstants.h"
36 #include "AliMUONGeometryBuilder.h"
37 #include "AliLog.h"
38
39 ClassImp(AliMUONGeometryEnvelopeStore)
40
41 //______________________________________________________________________________
42 AliMUONGeometryEnvelopeStore::AliMUONGeometryEnvelopeStore(
43                                  AliMUONGeometryStore* detElements)
44  : TObject(),
45    fEnvelopes(0),
46    fDetElements(detElements),
47    fReferenceFrame(),
48    fDebug(false),
49    fAlign(false)
50 {
51 /// Standard constructor
52
53   fEnvelopes = new TObjArray(100);
54 }
55
56
57 //______________________________________________________________________________
58 AliMUONGeometryEnvelopeStore::AliMUONGeometryEnvelopeStore()
59  : TObject(),
60    fEnvelopes(0),
61    fDetElements(0),
62    fReferenceFrame(),
63    fDebug(false),
64    fAlign(false)
65 {
66 /// Default constructor
67 }
68
69
70 //______________________________________________________________________________
71 AliMUONGeometryEnvelopeStore::AliMUONGeometryEnvelopeStore(const AliMUONGeometryEnvelopeStore& rhs)
72   : TObject(rhs)
73 {
74   AliFatal("Copy constructor is not implemented.");
75 }
76
77 //______________________________________________________________________________
78 AliMUONGeometryEnvelopeStore::~AliMUONGeometryEnvelopeStore() 
79 {
80 /// Destructor
81
82   // Add deleting rotation matrices 
83   
84   if (fEnvelopes) {
85     fEnvelopes->Delete();
86     delete fEnvelopes;
87   }  
88 }
89
90 //______________________________________________________________________________
91 AliMUONGeometryEnvelopeStore& 
92 AliMUONGeometryEnvelopeStore::operator = (const AliMUONGeometryEnvelopeStore& rhs) 
93 {
94 /// Protected assignement operator
95
96   // check assignement to self
97   if (this == &rhs) return *this;
98
99   AliFatal("Assignment operator is not implemented.");
100     
101   return *this;  
102 }
103
104 //
105 // private methods
106 //
107
108 //______________________________________________________________________________
109 TGeoHMatrix 
110 AliMUONGeometryEnvelopeStore::ConvertDETransform(const TGeoHMatrix& transform) const
111 {
112 // Convert transformation into the reference frame
113
114   if ( fReferenceFrame.IsIdentity() )
115     return transform;
116   else  {
117     return AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
118                                              transform );  
119   }                         
120 }
121
122 //______________________________________________________________________________
123 AliMUONGeometryEnvelope* 
124 AliMUONGeometryEnvelopeStore::FindEnvelope(const TString& name) const
125 {
126 /// Find the envelope specified by name.
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 //______________________________________________________________________________
139 Bool_t AliMUONGeometryEnvelopeStore::AlignEnvelope(
140                                           AliMUONGeometryEnvelope* envelope) const
141 {
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.
145
146   Int_t detElemId = envelope->GetUniqueID();
147   if (detElemId == 0) return false;
148   
149   AliMUONGeometryDetElement* detElement 
150     = (AliMUONGeometryDetElement*) fDetElements->Get(detElemId);
151   if (!detElement) {
152     AliWarning("Transformation not found.");
153     return false;
154   };
155
156   // Apply frame transform
157   TGeoHMatrix newTransform 
158     = ConvertDETransform(*(detElement->GetLocalTransformation()));
159
160   envelope->SetTransform(newTransform);
161   
162   return true;
163 }  
164
165 //
166 // public methods
167 //
168
169 //______________________________________________________________________________
170 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
171                                           Int_t id, 
172                                           Bool_t isVirtual,
173                                           const char* only) 
174 {
175 /// Add the volume with the specified name and transformation
176 /// to the list of envelopes.
177
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));
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 //______________________________________________________________________________
190 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
191                                           Int_t id, 
192                                           Bool_t isVirtual,
193                                           const TGeoTranslation& translation,
194                                           const char* only)
195 {
196 /// Add the volume with the specified name and transformation
197 /// to the list of envelopes.
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 //______________________________________________________________________________
220 void  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 {
227 /// Add the volume with the specified name and transformation
228 /// to the list of envelopes.
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 //______________________________________________________________________________
267 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
268                                           Int_t id, 
269                                           Bool_t isVirtual, 
270                                           const TGeoCombiTrans& transform,
271                                           const char* only)
272 {
273 /// Add the volume with the specified name and transformation
274 /// to the list of envelopes.
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 //______________________________________________________________________________
300 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
301                                           Int_t id, 
302                                           Int_t copyNo,
303                                           const char* only) 
304 {
305 /// Add the volume with the specified name and transformation
306 /// to the list of envelopes.
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 //______________________________________________________________________________
324 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
325                                           Int_t id, 
326                                           Int_t copyNo,
327                                           const TGeoTranslation& translation,
328                                           const char* only)
329 {
330 /// Add the volume with the specified name and transformation
331 /// to the list of envelopes.
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 //______________________________________________________________________________
354 void  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 {
361 /// Add the volume with the specified name and transformation
362 /// to the list of envelopes.
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 //______________________________________________________________________________
390 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
391                                           Int_t id, 
392                                           Int_t copyNo, 
393                                           const TGeoCombiTrans& transform,
394                                           const char* only)
395 {
396 /// Add the volume with the specified name and transformation
397 /// to the list of envelopes.
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 //______________________________________________________________________________
423 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
424                                          const TString& envName, Int_t copyNo) 
425 {
426 /// Add the volume with the specified name and transformation
427 /// to the list of envelopes.
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 //______________________________________________________________________________
446 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
447                                           const TString& envName, Int_t copyNo,
448                                           const TGeoTranslation& translation)
449 {
450 /// Add the volume with the specified name and transformation
451 /// to the list of envelopes.
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 //______________________________________________________________________________
471 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
472                                           const TString& envName, Int_t copyNo, 
473                                           const TGeoTranslation& translation,
474                                           const TGeoRotation& rotation)
475 {
476 /// Add the volume with the specified name and transformation
477 /// to the list of envelopes.
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 //______________________________________________________________________________
497 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
498                                           const TString& envName, Int_t copyNo, 
499                                           const TGeoCombiTrans& transform)
500 {
501 /// Add the volume with the specified name and transformation
502 /// to the list of envelopes.
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 //______________________________________________________________________________
522 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name, 
523                                          const TString& envName, Int_t copyNo,
524                                          Int_t npar, Double_t* param) 
525 {
526 /// Add the volume with the specified name and transformation
527 /// to the list of envelopes.
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 //______________________________________________________________________________
546 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name, 
547                                           const TString& envName, Int_t copyNo,
548                                           const TGeoTranslation& translation,
549                                           Int_t npar, Double_t* param)
550 {
551 /// Add the volume with the specified name and transformation
552 /// to the list of envelopes.
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 //______________________________________________________________________________
572 void  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 {
578 /// Add the volume with the specified name and transformation
579 /// to the list of envelopes.
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 //______________________________________________________________________________
599 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name, 
600                                           const TString& envName, Int_t copyNo, 
601                                           const TGeoCombiTrans& transform,
602                                           Int_t npar, Double_t* param)
603 {
604 /// Add the volume with the specified name and transformation
605 /// to the list of envelopes.
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
624 //______________________________________________________________________________
625 Int_t AliMUONGeometryEnvelopeStore::GetNofDetElements() const
626 {
627 /// Return the number od envelopes with detElemId>0.
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 }