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