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