]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryEnvelopeStore.cxx
Extended include path to cover all directories needed by all
[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 "AliMUONGeometryBuilder.h"
29
30 #include "AliMpExMap.h"
31
32 #include "AliLog.h"
33
34 #include <TGeoMatrix.h>
35 #include <TObjArray.h>
36 #include <Riostream.h>
37 #include <TString.h>
38
39 /// \cond CLASSIMP
40 ClassImp(AliMUONGeometryEnvelopeStore)
41 /// \endcond
42
43 //______________________________________________________________________________
44 AliMUONGeometryEnvelopeStore::AliMUONGeometryEnvelopeStore(
45                                     AliMpExMap* detElements)
46  : TObject(),
47    fEnvelopes(0),
48    fDetElements(detElements),
49    fReferenceFrame(),
50    fDebug(false),
51    fAlign(false)
52 {
53 /// Standard constructor
54
55   fEnvelopes = new TObjArray(100);
56 }
57
58
59 //______________________________________________________________________________
60 AliMUONGeometryEnvelopeStore::AliMUONGeometryEnvelopeStore()
61  : TObject(),
62    fEnvelopes(0),
63    fDetElements(0),
64    fReferenceFrame(),
65    fDebug(false),
66    fAlign(false)
67 {
68 /// Default constructor
69 }
70
71
72 //______________________________________________________________________________
73 AliMUONGeometryEnvelopeStore::~AliMUONGeometryEnvelopeStore() 
74 {
75 /// Destructor
76
77   // Add deleting rotation matrices 
78   
79   if (fEnvelopes) {
80     fEnvelopes->Delete();
81     delete fEnvelopes;
82   }  
83 }
84
85 //
86 // private methods
87 //
88
89 //______________________________________________________________________________
90 TGeoHMatrix 
91 AliMUONGeometryEnvelopeStore::ConvertDETransform(const TGeoHMatrix& transform) const
92 {
93 /// Convert transformation into the reference frame
94
95   if ( fReferenceFrame.IsIdentity() )
96     return transform;
97   else  {
98     return AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
99                                              transform );  
100   }                         
101 }
102
103 //______________________________________________________________________________
104 AliMUONGeometryEnvelope* 
105 AliMUONGeometryEnvelopeStore::FindEnvelope(const TString& name) const
106 {
107 /// Find the envelope specified by name.
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 //______________________________________________________________________________
120 Bool_t AliMUONGeometryEnvelopeStore::AlignEnvelope(
121                                           AliMUONGeometryEnvelope* envelope) const
122 {
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.
126
127   Int_t detElemId = envelope->GetUniqueID();
128   if (detElemId == 0) return false;
129   
130   AliMUONGeometryDetElement* detElement 
131     = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
132   if (!detElement) {
133     AliWarning("Transformation not found.");
134     return false;
135   };
136
137   // Apply frame transform
138   TGeoHMatrix newTransform 
139     = ConvertDETransform(*(detElement->GetLocalTransformation()));
140
141   envelope->SetTransform(newTransform);
142   
143   return true;
144 }  
145
146 //
147 // public methods
148 //
149
150 //______________________________________________________________________________
151 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
152                                           Int_t id, 
153                                           Bool_t isVirtual,
154                                           const char* only) 
155 {
156 /// Add the volume with the specified name and transformation
157 /// to the list of envelopes.
158
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));
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 //______________________________________________________________________________
171 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
172                                           Int_t id, 
173                                           Bool_t isVirtual,
174                                           const TGeoTranslation& translation,
175                                           const char* only)
176 {
177 /// Add the volume with the specified name and transformation
178 /// to the list of envelopes.
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 //______________________________________________________________________________
201 void  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 {
208 /// Add the volume with the specified name and transformation
209 /// to the list of envelopes.
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 //______________________________________________________________________________
248 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
249                                           Int_t id, 
250                                           Bool_t isVirtual, 
251                                           const TGeoCombiTrans& transform,
252                                           const char* only)
253 {
254 /// Add the volume with the specified name and transformation
255 /// to the list of envelopes.
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 //______________________________________________________________________________
281 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
282                                           Int_t id, 
283                                           Int_t copyNo,
284                                           const char* only) 
285 {
286 /// Add the volume with the specified name and transformation
287 /// to the list of envelopes.
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 //______________________________________________________________________________
305 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
306                                           Int_t id, 
307                                           Int_t copyNo,
308                                           const TGeoTranslation& translation,
309                                           const char* only)
310 {
311 /// Add the volume with the specified name and transformation
312 /// to the list of envelopes.
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 //______________________________________________________________________________
335 void  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 {
342 /// Add the volume with the specified name and transformation
343 /// to the list of envelopes.
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 //______________________________________________________________________________
371 void  AliMUONGeometryEnvelopeStore::AddEnvelope(const TString& name, 
372                                           Int_t id, 
373                                           Int_t copyNo, 
374                                           const TGeoCombiTrans& transform,
375                                           const char* only)
376 {
377 /// Add the volume with the specified name and transformation
378 /// to the list of envelopes.
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 //______________________________________________________________________________
404 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
405                                          const TString& envName, Int_t copyNo) 
406 {
407 /// Add the volume with the specified name and transformation
408 /// as a constituent of the envelope envName.
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 //______________________________________________________________________________
427 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
428                                           const TString& envName, Int_t copyNo,
429                                           const TGeoTranslation& translation)
430 {
431 /// Add the volume with the specified name and transformation
432 /// as a constituent of the envelope envName.
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 //______________________________________________________________________________
452 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
453                                           const TString& envName, Int_t copyNo, 
454                                           const TGeoTranslation& translation,
455                                           const TGeoRotation& rotation)
456 {
457 /// Add the volume with the specified name and transformation
458 /// as a constituent of the envelope envName.
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 //______________________________________________________________________________
478 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituent(const TString& name, 
479                                           const TString& envName, Int_t copyNo, 
480                                           const TGeoCombiTrans& transform)
481 {
482 /// Add the volume with the specified name and transformation
483 /// as a constituent of the envelope envName.
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 //______________________________________________________________________________
503 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name, 
504                                          const TString& envName, Int_t copyNo,
505                                          Int_t npar, Double_t* param) 
506 {
507 /// Add the volume with the specified name and transformation
508 /// as a constituent of the envelope envName.
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 //______________________________________________________________________________
527 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name, 
528                                           const TString& envName, Int_t copyNo,
529                                           const TGeoTranslation& translation,
530                                           Int_t npar, Double_t* param)
531 {
532 /// Add the volume with the specified name and transformation
533 /// as a constituent of the envelope envName.
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 //______________________________________________________________________________
553 void  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 {
559 /// Add the volume with the specified name and transformation
560 /// as a constituent of the envelope envName.
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 //______________________________________________________________________________
580 void  AliMUONGeometryEnvelopeStore::AddEnvelopeConstituentParam(const TString& name, 
581                                           const TString& envName, Int_t copyNo, 
582                                           const TGeoCombiTrans& transform,
583                                           Int_t npar, Double_t* param)
584 {
585 /// Add the volume with the specified name and transformation
586 /// as a constituent of the envelope envName.
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
605 //______________________________________________________________________________
606 Int_t AliMUONGeometryEnvelopeStore::GetNofDetElements() const
607 {
608 /// Return the number od envelopes with detElemId>0.
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 }