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