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