LCOV - code coverage report
Current view: top level - MUON/MUONgeometry - AliMUONGeometryBuilder.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 148 278 53.2 %
Date: 2016-06-14 17:26:59 Functions: 20 26 76.9 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *      SigmaEffect_thetadegrees                                                                  *
       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 purpeateose. It is      *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : // $Id$
      17             : 
      18             : //-----------------------------------------------------------------------------
      19             : // Class AliMUONGeometryBuilder
      20             : // ----------------------------
      21             : // Manager class for geometry construction via geometry builders.
      22             : // Author: Ivana Hrivnacova, IPN Orsay
      23             : //-----------------------------------------------------------------------------
      24             : 
      25             : #include "AliMUONGeometryBuilder.h"
      26             : #include "AliMUONVGeometryBuilder.h"  
      27             : #include "AliMUONGeometry.h"
      28             : #include "AliMUONGeometryTransformer.h"
      29             : #include "AliMUONGeometryModule.h"    
      30             : #include "AliMUONGeometryModuleTransformer.h" 
      31             : #include "AliMUONGeometryEnvelope.h"  
      32             : #include "AliMUONGeometryEnvelopeStore.h"
      33             : #include "AliMUONGeometryDetElement.h"
      34             : #include "AliMUONGeometryConstituent.h"
      35             : 
      36             : #include "AliMpDEManager.h"
      37             : 
      38             : #include "AliModule.h"
      39             : #include "AliSimulation.h"
      40             : #include "AliLog.h"
      41             : #include "AliRun.h"
      42             : 
      43             : #include <TObjArray.h>
      44             : #include <TVirtualMC.h>
      45             : #include <TGeoManager.h>
      46             : 
      47             : using std::endl;
      48             : /// \cond CLASSIMP
      49          18 : ClassImp(AliMUONGeometryBuilder)
      50             : /// \endcond
      51             : 
      52             : //
      53             : // static functions
      54             : //
      55             : 
      56             : //______________________________________________________________________________
      57             : const TString& AliMUONGeometryBuilder::GetDefaultTransformFileName()
      58             : {
      59             :   ///< default transformations file name                                     
      60           5 :   static const TString kDefaultTransformFileName = "transform.dat";   
      61           1 :   return kDefaultTransformFileName;
      62           0 : }    
      63             : 
      64             : //______________________________________________________________________________
      65             : const TString& AliMUONGeometryBuilder::GetDefaultSVMapFileName() 
      66             : {
      67             :   ///< default svmaps file name                                      
      68           5 :   static const TString kDefaultSVMapFileName = "svmap.dat";    
      69           1 :   return kDefaultSVMapFileName;
      70           0 : }    
      71             : 
      72             : //______________________________________________________________________________
      73             : const TString& AliMUONGeometryBuilder::GetOutFileNameExtension()
      74             : {
      75             :   ///< default output file name extension                                    
      76           0 :   static const TString kOutFileNameExtension = ".out";    
      77           0 :   return kOutFileNameExtension;
      78           0 : }    
      79             : 
      80             : 
      81             : //______________________________________________________________________________
      82             : TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, 
      83             :                                              const TGeoMatrix& m2)
      84             : {
      85             : /// Temporary fix for problem with matrix multiplication in Root 5.02/00
      86             : 
      87        6024 :   if (m1.IsIdentity() && m2.IsIdentity()) return TGeoHMatrix();
      88             :   
      89        3604 :   if (m1.IsIdentity()) return m2;
      90             :   
      91        1236 :   if (m2.IsIdentity()) return m1;
      92             :   
      93        1236 :   return m1 * m2;
      94        2420 : }
      95             : 
      96             : //______________________________________________________________________________
      97             : TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, 
      98             :                                              const TGeoMatrix& m2,
      99             :                                              const TGeoMatrix& m3)
     100             : {                                            
     101             : /// Temporary fix for problem with matrix multiplication in Root 5.02/00
     102             : 
     103          32 :   if (m1.IsIdentity() && m2.IsIdentity() & m3.IsIdentity())  
     104           0 :     return TGeoHMatrix();
     105             :   
     106          16 :   if (m1.IsIdentity()) return Multiply(m2, m3);
     107             :   
     108          16 :   if (m2.IsIdentity()) return Multiply(m1, m3);
     109             :   
     110          16 :   if (m3.IsIdentity()) return Multiply(m1, m2);
     111             :   
     112          16 :   return m1 * m2 * m3;
     113          16 : }
     114             : 
     115             : //______________________________________________________________________________
     116             : TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, 
     117             :                                              const TGeoMatrix& m2,
     118             :                                              const TGeoMatrix& m3,
     119             :                                              const TGeoMatrix& m4)
     120             : {                                            
     121             : /// Temporary fix for problem with matrix multiplication in Root 5.02/00
     122             : 
     123           0 :   if (m1.IsIdentity() && m2.IsIdentity() & m3.IsIdentity() & m4.IsIdentity())  
     124           0 :     return TGeoHMatrix();
     125             :   
     126           0 :   if (m1.IsIdentity()) return Multiply(m2, m3, m4);
     127             :   
     128           0 :   if (m2.IsIdentity()) return Multiply(m1, m3, m4);
     129             :   
     130           0 :   if (m3.IsIdentity()) return Multiply(m1, m2, m4);
     131             :   
     132           0 :   if (m4.IsIdentity()) return Multiply(m1, m2, m3);
     133             :   
     134           0 :   return m1 * m2 * m3 * m4;
     135           0 : }
     136             : 
     137             : //
     138             : // ctors, dtor
     139             : //
     140             : 
     141             : //______________________________________________________________________________
     142             : AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliModule* module)
     143           1 :   : TObject(),
     144           1 :     fModule(module),
     145           1 :     fAlign(false),
     146           2 :     fTransformFileName(GetDefaultTransformFileName()),
     147           2 :     fSVMapFileName(GetDefaultSVMapFileName()),
     148           1 :     fGlobalTransformation(), 
     149           1 :     fGeometryBuilders(0),
     150           1 :     fGeometry(0)
     151           5 : {
     152             : /// Standard constructor
     153             : 
     154           3 :   fGeometryBuilders = new TObjArray();
     155           1 :   fGeometryBuilders->SetOwner(true);
     156             :   
     157           3 :   fGeometry = new AliMUONGeometry(true);
     158             : 
     159             :   // Define the global transformation:
     160             :   // Transformation from the old ALICE coordinate system to a new one:
     161             :   // x->-x, z->-z 
     162             :   TGeoRotation* rotGlobal 
     163           2 :     = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
     164           3 :   fGlobalTransformation = TGeoCombiTrans(0., 0., 0., rotGlobal);
     165           2 : }
     166             : 
     167             : //______________________________________________________________________________
     168             : AliMUONGeometryBuilder::AliMUONGeometryBuilder() 
     169          12 :   : TObject(),
     170          12 :     fModule(0),
     171          12 :     fAlign(false),
     172          12 :     fTransformFileName(),
     173          12 :     fSVMapFileName(),
     174          12 :     fGlobalTransformation(),
     175          12 :     fGeometryBuilders(0),
     176          12 :     fGeometry(0)
     177          60 : {
     178             : /// Default constructor
     179          24 : } 
     180             : 
     181             : //______________________________________________________________________________
     182             : AliMUONGeometryBuilder::~AliMUONGeometryBuilder()
     183          78 : {
     184             : /// Destructor
     185             :   
     186          26 :   delete fGeometryBuilders;
     187          26 :   delete fGeometry;
     188          39 : }
     189             : 
     190             : //
     191             : // private functions
     192             : //
     193             : 
     194             : //______________________________________________________________________________
     195             : void AliMUONGeometryBuilder::PlaceVolume(const TString& name, const TString& mName, 
     196             :                             Int_t copyNo, const TGeoHMatrix& matrix, 
     197             :                             Int_t npar, Double_t* param, const char* only,
     198             :                             Bool_t makeAssembly) const
     199             : {
     200             : /// Place the volume specified by name with the given transformation matrix
     201             : 
     202        4684 :   if (makeAssembly)
     203        1348 :     gGeoManager->MakeVolumeAssembly(name.Data());
     204             : 
     205        4684 :   TGeoHMatrix transform(matrix);
     206             :   // Do not apply global transformation 
     207             :   // if mother volume was already placed in 
     208             :   // the new system of coordinates (that is MUON in negative Z)
     209             :   // (as it is applied on the mother volume)
     210       14052 :   if (mName == TString("DDIP"))
     211          12 :     transform = fGlobalTransformation.Inverse() * transform;
     212             :      
     213             :   // Decompose transformation
     214        4684 :   const Double_t* xyz = transform.GetTranslation();
     215        4684 :   const Double_t* rm = transform.GetRotationMatrix();
     216             :         
     217             :   //cout << "Got translation: "
     218             :   //     << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl;
     219             :         
     220             :   //cout << "Got rotation: "
     221             :   //     << rm[0] << " " << rm[1] << " " << rm[2] << endl
     222             :   //     << rm[3] << " " << rm[4] << " " << rm[5] << endl
     223             :   //     << rm[6] << " " << rm[7] << " " << rm[8] << endl;
     224             : 
     225             :   // Check for presence of rotation
     226             :   // (will be nice to be available in TGeo)
     227             :   const Double_t kTolerance = 1e-04;
     228             :   Bool_t isRotation = true; 
     229        8074 :   if (TMath::Abs(rm[0] - 1.) < kTolerance &&
     230        3480 :       TMath::Abs(rm[1] - 0.) < kTolerance &&
     231        3480 :       TMath::Abs(rm[2] - 0.) < kTolerance &&
     232        3480 :       TMath::Abs(rm[3] - 0.) < kTolerance &&
     233        3480 :       TMath::Abs(rm[4] - 1.) < kTolerance &&
     234        3402 :       TMath::Abs(rm[5] - 0.) < kTolerance &&
     235        3390 :       TMath::Abs(rm[6] - 0.) < kTolerance &&
     236        3390 :       TMath::Abs(rm[7] - 0.) < kTolerance &&
     237        6780 :       TMath::Abs(rm[8] - 1.) < kTolerance) isRotation = false; 
     238             : 
     239        4684 :   Int_t krot = 0;
     240        4684 :   if (isRotation) {
     241        1294 :     TGeoRotation rot;
     242        1294 :     rot.SetMatrix(const_cast<Double_t*>(transform.GetRotationMatrix()));
     243        1294 :     Double_t theta1, phi1, theta2, phi2, theta3, phi3;
     244        1294 :     rot.GetAngles(theta1, phi1, theta2, phi2, theta3, phi3);
     245             :         
     246             :     //cout << "angles: " 
     247             :     //     << theta1 << " " << phi1 << " "
     248             :     //     << theta2 << " " << phi2 << " "
     249             :     //     << theta3 << " " << phi3 << endl;
     250             :         
     251        1294 :     fModule->AliMatrix(krot, theta1, phi1, theta2, phi2, theta3, phi3);
     252        1294 :   }     
     253             :         
     254             :   // Place the volume
     255        4684 :   if (npar == 0)
     256       13936 :     TVirtualMC::GetMC()->Gspos(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only);
     257             :   else 
     258        4800 :     TVirtualMC::GetMC()->Gsposp(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only,
     259             :                 param, npar);
     260        4684 : } 
     261             : 
     262             : //______________________________________________________________________________
     263             : void AliMUONGeometryBuilder::CreateGeometryWithTGeo()
     264             : {
     265             : /// Construct geometry using geometry builders.
     266             : /// Virtual modules/envelopes are placed as TGeoVolume assembly
     267             : 
     268           2 :   if (fAlign) {
     269             :     // Read transformations from ASCII data file  
     270           0 :     fGeometry->GetTransformer()
     271           0 :       ->LoadGeometryData(fTransformFileName);
     272           0 :   }    
     273             :  
     274          13 :   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     275             : 
     276             :     // Get the builder
     277             :     AliMUONVGeometryBuilder* builder
     278           5 :       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     279             : 
     280             :     // Create geometry + envelopes
     281             :     //
     282           5 :     builder->CreateGeometry();
     283           5 :     builder->SetVolumes();
     284          10 :     if (!fAlign) builder->SetTransformations();
     285             :     
     286             :     // Place module volumes and envelopes
     287             :     //
     288          55 :     for (Int_t j=0; j<builder->NofGeometries(); j++) {
     289             : 
     290          20 :       AliMUONGeometryModule* geometry = builder->Geometry(j);
     291          20 :       AliMUONGeometryModuleTransformer* transformer= geometry->GetTransformer();
     292          20 :       const TGeoHMatrix* kModuleTransform = transformer->GetTransformation();
     293          20 :       TString volName       = transformer->GetVolumeName(); 
     294          20 :       TString motherVolName = transformer->GetMotherVolumeName(); 
     295             :       
     296             :       // Place the module volume
     297          20 :       PlaceVolume(volName, motherVolName, 
     298          20 :                   1, *kModuleTransform, 0, 0, "ONLY", geometry->IsVirtual());
     299             :   
     300          20 :       TGeoCombiTrans appliedGlobalTransform;
     301          40 :       if (builder->ApplyGlobalTransformation())
     302          16 :         appliedGlobalTransform = fGlobalTransformation;
     303             : 
     304             :       // Loop over envelopes
     305             :       const TObjArray* kEnvelopes 
     306          20 :         = geometry->GetEnvelopeStore()->GetEnvelopes();
     307        4136 :       for (Int_t k=0; k<kEnvelopes->GetEntriesFast(); k++) {
     308             : 
     309             :         // Get envelope
     310             :         AliMUONGeometryEnvelope* env 
     311        2704 :           = (AliMUONGeometryEnvelope*)kEnvelopes->At(k);
     312             :           
     313             :         // Check consistency of detElemId and module Id
     314        2932 :         if ( env->GetUniqueID() > 0 && 
     315         456 :              AliMpDEManager::GetGeomModuleId(env->GetUniqueID()) 
     316         456 :              != geometry->GetModuleId() ) {
     317             :              
     318           0 :           AliErrorStream() 
     319           0 :             << "Detection element " << env->GetUniqueID() 
     320           0 :             << " is being placed in geometry module " << geometry->GetModuleId()
     321           0 :             << " but should go in " 
     322           0 :             << AliMpDEManager::GetGeomModuleId(env->GetUniqueID())
     323           0 :             <<  endl;
     324           0 :           AliFatal("Inconsistent IDs");
     325             :         }          
     326             :           
     327        1352 :         const TGeoCombiTrans* kEnvTrans = env->GetTransformation();
     328             :         const char* only = "ONLY";
     329        1352 :         if (env->IsMANY()) only = "MANY";
     330             : 
     331        4016 :         if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
     332             :           // virtual envelope + nof constituents = 0 
     333             :           //         => not allowed;
     334             :           //            empty virtual envelope has no sense 
     335           0 :           AliFatal("Virtual envelope must have constituents.");
     336           0 :           return;
     337             :         }
     338             : 
     339        1392 :         if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
     340             :           // non virtual envelope + nof constituents > 0 
     341             :           //        => not allowed;
     342             :           //           use VMC to place constituents
     343           0 :           AliFatal("Non virtual envelope cannot have constituents.");
     344           0 :           return;
     345             :         }
     346             : 
     347             :         // Place envelope in geometry module by composed transformation:
     348             :         // [Tglobal] * Tenv
     349        1352 :         TGeoHMatrix total 
     350        2704 :           = Multiply( appliedGlobalTransform, 
     351        1352 :                      (*kEnvTrans) );
     352        5408 :         PlaceVolume(env->GetName(), volName,
     353        1352 :                     env->GetCopyNo(), total, 0, 0, only, env->IsVirtual());
     354             :         
     355        1352 :         if ( env->IsVirtual() )  {
     356             :           //  Place constituents in the envelope
     357       13932 :           for  (Int_t l=0; l<env->GetConstituents()->GetEntriesFast(); l++) {
     358             :             AliMUONGeometryConstituent* constituent
     359        6624 :               = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l);
     360             :  
     361       19872 :             PlaceVolume(constituent->GetName(), env->GetName(),
     362        3312 :                         constituent->GetCopyNo(),
     363        3312 :                         *constituent->GetTransformation() ,
     364        3312 :                         constituent->GetNpar(), constituent->GetParam(), only);
     365             :           }
     366        1332 :         }
     367        1352 :       } // end of loop over envelopes
     368          40 :     } // end of loop over builder geometries
     369           5 :   } // end of loop over builders
     370           1 : }
     371             : 
     372             : //______________________________________________________________________________
     373             : void AliMUONGeometryBuilder::CreateGeometryWithoutTGeo()
     374             : {
     375             : /// Construct geometry using geometry builders.
     376             : /// Virtual modules/envelopes are not placed
     377             : 
     378           0 :   if (fAlign) {
     379             :     // Read transformations from ASCII data file  
     380           0 :     fGeometry->GetTransformer()->LoadGeometryData(fTransformFileName);
     381           0 :   }     
     382             : 
     383           0 :   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     384             : 
     385             :     // Get the builder
     386             :     AliMUONVGeometryBuilder* builder
     387           0 :       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     388             : 
     389             :     // Create geometry + envelopes
     390             :     //
     391           0 :     builder->CreateGeometry();
     392           0 :     if (!fAlign) builder->SetTransformations();
     393             :     
     394             :     // Place module volumes and envelopes
     395             :     //
     396           0 :     for (Int_t j=0; j<builder->NofGeometries(); j++) {
     397             : 
     398           0 :       AliMUONGeometryModule* geometry = builder->Geometry(j);
     399           0 :       AliMUONGeometryModuleTransformer* transformer= geometry->GetTransformer();
     400           0 :       const TGeoHMatrix* kModuleTransform = transformer->GetTransformation();
     401           0 :       TString volName       = transformer->GetVolumeName(); 
     402           0 :       TString motherVolName = transformer->GetMotherVolumeName(); 
     403             :       
     404             :       // Place the module volume
     405           0 :       if ( !geometry->IsVirtual() ) {
     406           0 :           PlaceVolume(volName, motherVolName, 
     407             :                       1, *kModuleTransform, 0, 0, "ONLY");
     408             :       }               
     409             :   
     410           0 :       TGeoCombiTrans appliedGlobalTransform;
     411           0 :       if (builder->ApplyGlobalTransformation())
     412           0 :         appliedGlobalTransform = fGlobalTransformation;
     413             : 
     414             :       // Loop over envelopes
     415             :       const TObjArray* kEnvelopes 
     416           0 :         = geometry->GetEnvelopeStore()->GetEnvelopes();
     417           0 :       for (Int_t k=0; k<kEnvelopes->GetEntriesFast(); k++) {
     418             : 
     419             :         // Get envelope
     420             :         AliMUONGeometryEnvelope* env 
     421           0 :           = (AliMUONGeometryEnvelope*)kEnvelopes->At(k);
     422             :           
     423             :         // Check consistency of detElemId and module Id
     424           0 :         if ( env->GetUniqueID() > 0 && 
     425           0 :              AliMpDEManager::GetGeomModuleId(env->GetUniqueID()) 
     426           0 :              != geometry->GetModuleId() ) {
     427             :              
     428           0 :           AliErrorStream() 
     429           0 :             << "Detection element " << env->GetUniqueID() 
     430           0 :             << " is being placed in geometry module " << geometry->GetModuleId()
     431           0 :             << " but should go in " 
     432           0 :             << AliMpDEManager::GetGeomModuleId(env->GetUniqueID())
     433           0 :             <<  endl;
     434           0 :           AliFatal("Inconsistent IDs");
     435             :         }          
     436             :           
     437           0 :         const TGeoCombiTrans* kEnvTrans = env->GetTransformation();
     438             :         const char* only = "ONLY";
     439           0 :         if (env->IsMANY()) only = "MANY";
     440             : 
     441           0 :         if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
     442             :           // virtual envelope + nof constituents = 0 
     443             :           //         => not allowed;
     444             :           //            empty virtual envelope has no sense 
     445           0 :           AliFatal("Virtual envelope must have constituents.");
     446           0 :           return;
     447             :         }
     448             : 
     449           0 :         if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
     450             :           // non virtual envelope + nof constituents > 0 
     451             :           //        => not allowed;
     452             :           //           use VMC to place constituents
     453           0 :           AliFatal("Non virtual envelope cannot have constituents.");
     454           0 :           return;
     455             :         }
     456             : 
     457           0 :         if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
     458             :           // non virtual envelope + nof constituents = 0 
     459             :           //        => place envelope by composed transformation:
     460             :           //           Tch * [Tglobal] * Tenv
     461             : 
     462             :           // Compound chamber transformation with the envelope one
     463           0 :           if (geometry->IsVirtual()) {
     464           0 :              TGeoHMatrix total 
     465           0 :                = Multiply( (*kModuleTransform), 
     466           0 :                             appliedGlobalTransform, 
     467           0 :                            (*kEnvTrans) );
     468           0 :              PlaceVolume(env->GetName(), motherVolName,
     469           0 :                          env->GetCopyNo(), total, 0, 0, only);
     470           0 :           }
     471             :           else {
     472           0 :              TGeoHMatrix total 
     473           0 :                = Multiply( appliedGlobalTransform, 
     474           0 :                            (*kEnvTrans) );
     475           0 :              PlaceVolume(env->GetName(), volName,
     476           0 :                          env->GetCopyNo(), total, 0, 0, only);
     477           0 :           }                      
     478             :         }
     479             : 
     480           0 :         if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
     481             :           // virtual envelope + nof constituents > 0 
     482             :           //         => do not place envelope and place constituents
     483             :           //            by composed transformation:
     484             :           //            Tch * [Tglobal] * Tenv * Tconst   
     485             : 
     486           0 :           for  (Int_t l=0; l<env->GetConstituents()->GetEntriesFast(); l++) {
     487             :             AliMUONGeometryConstituent* constituent
     488           0 :               = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l);
     489             :  
     490             :             // Compound chamber transformation with the envelope one + the constituent one
     491           0 :             if (geometry->IsVirtual()) {
     492           0 :               TGeoHMatrix total 
     493           0 :                 = Multiply ( (*kModuleTransform),
     494           0 :                              appliedGlobalTransform, 
     495           0 :                              (*kEnvTrans), 
     496           0 :                              (*constituent->GetTransformation()) );
     497             : 
     498           0 :               PlaceVolume(constituent->GetName(), motherVolName,
     499           0 :                           constituent->GetCopyNo(), total,
     500           0 :                           constituent->GetNpar(), constituent->GetParam(), only);
     501           0 :             }
     502             :             else {                        
     503           0 :               TGeoHMatrix total 
     504           0 :                 = Multiply ( appliedGlobalTransform, 
     505           0 :                              (*kEnvTrans),
     506           0 :                              (*constituent->GetTransformation()) );
     507             : 
     508           0 :               PlaceVolume(constituent->GetName(), volName,
     509           0 :                           constituent->GetCopyNo(), total,
     510           0 :                           constituent->GetNpar(), constituent->GetParam(), only);
     511           0 :             }                     
     512             :           }
     513           0 :         }
     514           0 :       } // end of loop over envelopes
     515           0 :     } // end of loop over builder geometries
     516           0 :   } // end of loop over builders
     517           0 : }
     518             : 
     519             : //_____________________________________________________________________________
     520             : void AliMUONGeometryBuilder::SetAlignToBuilder(AliMUONVGeometryBuilder* builder) const
     521             : {
     522             : /// Set align option to all geometry modules associated with the builder
     523             : 
     524          55 :   for (Int_t j=0; j<builder->NofGeometries(); j++) {
     525             : 
     526          20 :     AliMUONGeometryModule* geometry = builder->Geometry(j);
     527             :   
     528          20 :     geometry->SetAlign(fAlign);
     529             :   }       
     530           5 : }            
     531             : 
     532             : //
     533             : // public functions
     534             : //
     535             : 
     536             : //_____________________________________________________________________________
     537             : void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder)
     538             : {
     539             : /// Add the geometry builder to the list
     540             : 
     541          10 :   fGeometryBuilders->Add(geomBuilder);
     542             :   
     543             :   // Pass geometry modules created in the to the geometry parametrisation
     544          50 :   for (Int_t i=0; i<geomBuilder->NofGeometries(); i++) {
     545          20 :     fGeometry->AddModule(geomBuilder->Geometry(i));
     546             :   }  
     547             :   
     548           5 :   if (geomBuilder->ApplyGlobalTransformation())
     549           4 :     geomBuilder->SetReferenceFrame(fGlobalTransformation);
     550             :   
     551           5 :   SetAlignToBuilder(geomBuilder);
     552           5 : }
     553             : 
     554             : //______________________________________________________________________________
     555             : void AliMUONGeometryBuilder::CreateGeometry()
     556             : {
     557             : /// Construct geometry using geometry builders.
     558             : 
     559           2 :   if ( TVirtualMC::GetMC()->IsRootGeometrySupported() ) {
     560             :        
     561           1 :    CreateGeometryWithTGeo();
     562           1 :   } 
     563             :   else
     564           0 :    CreateGeometryWithoutTGeo();
     565             : 
     566          12 :   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     567             : 
     568             :     // Get the builder
     569             :     AliMUONVGeometryBuilder* builder
     570           5 :       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     571             :  
     572             :     // Update detection elements from built geometry
     573           5 :     Bool_t create = ! fAlign;
     574           5 :     builder->UpdateDetElements(create);
     575             :   }
     576           1 : }
     577             : 
     578             : //_____________________________________________________________________________
     579             : void AliMUONGeometryBuilder::CreateMaterials()
     580             : {
     581             : /// Construct materials specific to modules via builders
     582             :   
     583          13 :   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     584             : 
     585             :     // Get the builder
     586             :     AliMUONVGeometryBuilder* builder
     587           5 :       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     588             : 
     589             :     // Create materials with each builder
     590          10 :     if (builder) builder->CreateMaterials();
     591             :   }
     592           1 : }
     593             : 
     594             : //______________________________________________________________________________
     595             : void AliMUONGeometryBuilder::InitGeometry(const TString& svmapFileName)
     596             : {
     597             : /// Initialize geometry
     598             : 
     599             :   // Load alignement data from geometry if geometry is read from Root file
     600           2 :   if ( AliSimulation::Instance()->IsGeometryFromFile() ) {
     601           0 :     fAlign = true;
     602           0 :     fGeometry->GetTransformer()->LoadGeometryData();
     603           0 :  }    
     604             : 
     605             :   // Read sensitive volume map from a file
     606           1 :   fGeometry->ReadSVMap(svmapFileName);
     607             : 
     608             :   // Set the chamber (sensitive region) GEANT identifier
     609             :   //
     610          12 :   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     611             : 
     612             :     // Get the builder
     613             :     AliMUONVGeometryBuilder* builder
     614           5 :       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     615             : 
     616             :     // Set sensitive volumes with each builder
     617           5 :     builder->SetSensitiveVolumes();
     618             :   }  
     619           1 : }
     620             : 
     621             : //________________________________________________________________
     622             : void AliMUONGeometryBuilder::UpdateInternalGeometry()
     623             : {
     624             : /// Update geometry after applying mis-alignment:
     625             : /// reload transformations in geometry builder.
     626             : 
     627           2 :   fGeometry->GetTransformer()->LoadTransformations();
     628           1 : }
     629             : 
     630             : //______________________________________________________________________________
     631             : void AliMUONGeometryBuilder::WriteSVMaps(const TString& fileName, 
     632             :                                          Bool_t rebuild, Bool_t writeEnvelopes)
     633             : {
     634             : /// Write sensitive volume maps into files per builder
     635             : 
     636             :   // Rebuild sv maps
     637             :   //
     638           0 :   if (rebuild) 
     639           0 :     for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     640             : 
     641             :       AliMUONVGeometryBuilder* builder
     642           0 :         = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     643             : 
     644           0 :       builder->RebuildSVMaps(writeEnvelopes);
     645           0 :     }  
     646             :     
     647             :   // Write maps in file
     648           0 :   fGeometry->WriteSVMap(fileName);
     649           0 : }
     650             : 
     651             : //_____________________________________________________________________________
     652             : void AliMUONGeometryBuilder::SetAlign(Bool_t align)
     653             : { 
     654             : /// Set the option for alignement
     655             : 
     656           0 :   fAlign = align; 
     657             : 
     658           0 :   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     659             : 
     660             :     AliMUONVGeometryBuilder* builder
     661           0 :       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     662             :     
     663           0 :     SetAlignToBuilder(builder); 
     664             :   }   
     665           0 : }
     666             : 
     667             : //_____________________________________________________________________________
     668             : void AliMUONGeometryBuilder::SetAlign(const TString& fileName, Bool_t align)
     669             : { 
     670             : /// Set the option for alignement and the transformations file name
     671             : 
     672           0 :   fTransformFileName = fileName;
     673           0 :   fAlign = align; 
     674             : 
     675           0 :   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
     676             : 
     677             :     AliMUONVGeometryBuilder* builder
     678           0 :       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
     679             :     
     680           0 :     SetAlignToBuilder(builder); 
     681             :   }   
     682           0 : }

Generated by: LCOV version 1.11