]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONVGeometryBuilder.cxx
added proper handling of EMCAL calibration events
[u/mrichter/AliRoot.git] / MUON / AliMUONVGeometryBuilder.cxx
index a36ed37e90ddb40d7ef3a9d178d812ce24aa1744..74f3538b363799a18459e60d0b611dacd2b79592 100644 (file)
  **************************************************************************/
 
 // $Id$
-//
+
+//-----------------------------------------------------------------------------
 // Class AliMUONVGeometryBuilder
 // -----------------------------
 // Abstract base class for geometry construction per geometry module(s).
 // Author: Ivana Hrivnacova, IPN Orsay
 // 23/01/2004
-
-#include <Riostream.h>
-#include <TObjArray.h>
-#include <TSystem.h>
-#include <TGeoMatrix.h>
-#include <TVirtualMC.h>
+//-----------------------------------------------------------------------------
 
 #include "AliMUONVGeometryBuilder.h"
 #include "AliMUONGeometryModule.h"
 #include "AliMUONGeometryDetElement.h"
-#include "AliMUONGeometryStore.h"
-#include "AliMUONGeometrySVMap.h"
 #include "AliMUONGeometryEnvelopeStore.h"
 #include "AliMUONGeometryEnvelope.h"
 #include "AliMUONGeometryConstituent.h"
 #include "AliMUONGeometryBuilder.h"
+#include "AliMUONStringIntMap.h"
+
+#include "AliMpDEManager.h"
+#include "AliMpExMap.h"
+
 #include "AliLog.h"
 
+#include <Riostream.h>
+#include <TObjArray.h>
+#include <TSystem.h>
+#include <TGeoMatrix.h>
+#include <TVirtualMC.h>
+
+/// \cond CLASSIMP
 ClassImp(AliMUONVGeometryBuilder)
+/// \endcond
 
 //______________________________________________________________________________
 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(
-                            Int_t moduleId1, Int_t moduleId2,
-                            Int_t moduleId3, Int_t moduleId4,
-                            Int_t moduleId5, Int_t moduleId6)
+                            Int_t firstModuleId, 
+                            Int_t nofModules)
  : TObject(),
    fGeometryModules(0),
    fReferenceFrame()
  {
-// Standard constructor
+/// Standard constructor
 
   // Create the module geometries array
   fGeometryModules = new TObjArray();
-  
-  if ( moduleId1 >= 0 ) 
-    fGeometryModules->Add(new AliMUONGeometryModule(moduleId1));
-  if ( moduleId2 >= 0 ) 
-    fGeometryModules->Add(new AliMUONGeometryModule(moduleId2));
-
-  if ( moduleId3 >= 0 ) 
-    fGeometryModules->Add(new AliMUONGeometryModule(moduleId3));
-
-  if ( moduleId4 >= 0 ) 
-    fGeometryModules->Add(new AliMUONGeometryModule(moduleId4));
-
-  if ( moduleId5 >= 0 ) 
-    fGeometryModules->Add(new AliMUONGeometryModule(moduleId5));
-
-  if ( moduleId6 >= 0 ) 
-    fGeometryModules->Add(new AliMUONGeometryModule(moduleId6));
+  fGeometryModules->SetOwner(kFALSE);
+     
+  for (Int_t i=0; i<nofModules; i++ )
+    fGeometryModules->Add(new AliMUONGeometryModule(firstModuleId++));
 }
 
 //______________________________________________________________________________
@@ -79,42 +71,20 @@ AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
    fGeometryModules(0),
    fReferenceFrame()
 {
-// Default constructor
+/// Default constructor
 }
 
-
 //______________________________________________________________________________
-AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
-  : TObject(rhs)
+AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() 
 {
-// Protected copy constructor
-
-  AliFatal("Copy constructor is not implemented.");
-}
+/// Destructor
 
-//______________________________________________________________________________
-AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
-//
   if (fGeometryModules) {
     fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
     delete fGeometryModules;
   }
 }
 
-//______________________________________________________________________________
-AliMUONVGeometryBuilder& 
-AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs) 
-{
-// Protected assignement operator
-
-  // check assignement to self
-  if (this == &rhs) return *this;
-
-  AliFatal("Assignment operator is not implemented.");
-    
-  return *this;  
-}
-
 //
 // private methods
 //
@@ -123,7 +93,7 @@ AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
 TGeoHMatrix 
 AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
 {
-// Convert transformation into the reference frame
+/// Convert transformation into the reference frame
 
   if ( fReferenceFrame.IsIdentity() )
     return transform;
@@ -138,7 +108,7 @@ AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
 TGeoHMatrix 
 AliMUONVGeometryBuilder::ConvertDETransform(const TGeoHMatrix& transform) const
 {
-// Convert transformation into the reference frame
+/// Convert DE transformation into the reference frame
 
   if ( fReferenceFrame.IsIdentity() )
     return transform;
@@ -149,14 +119,14 @@ AliMUONVGeometryBuilder::ConvertDETransform(const TGeoHMatrix& transform) const
 }
 
 //______________________________________________________________________________
-TString  AliMUONVGeometryBuilder::ComposePath(const TString& volName, 
-                                               Int_t copyNo) const
+TString  AliMUONVGeometryBuilder::ComposePath(const TString& volName,
+                                              Int_t copyNo) const
 {
-// Compose path from given volName and copyNo
-// ---
+/// Compose path from given volName and copyNo
 
-  TString path(volName);
-  path += ".";
+  TString path = "/";
+  path += volName;
+  path += '_';
   path += copyNo;
   
   return path;
@@ -166,26 +136,25 @@ TString  AliMUONVGeometryBuilder::ComposePath(const TString& volName,
 void AliMUONVGeometryBuilder::MapSV(const TString& path0, 
                                     const TString& volName, Int_t detElemId) const
 {
-// Update the path with all daughters volumes recursively
-// and map it to the detection element Id if it is a sensitive volume
-// ---
+/// Update the path with all daughters volumes recursively
+/// and map it to the detection element Id if it is a sensitive volume
 
   // Get module sensitive volumes map
-  Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
-  AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);     
+  Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
+  AliMUONStringIntMap* svMap = GetSVMap(moduleId);     
 
   Int_t nofDaughters = gMC->NofVolDaughters(volName);
   if (nofDaughters == 0) {
 
     // Get the name of the last volume in the path
     Ssiz_t npos1 = path0.Last('/')+1; 
-    Ssiz_t npos2 = path0.Last('.');
-    TString volName(path0(npos1, npos2-npos1));  
+    Ssiz_t npos2 = path0.Last('_');
+    TString volName0(path0(npos1, npos2-npos1));  
     
     // Check if it is sensitive volume
-    Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
     AliMUONGeometryModule* geometry = GetGeometry(moduleId);
-    if (geometry->IsSensitiveVolume(volName)) {
+    if (  geometry->IsSensitiveVolume(volName0) &&
+        ! svMap->Get(path0) ) {
       //cout << ".. adding to the map  " 
       //     <<  path0 << "  "  << detElemId << endl;
     
@@ -200,7 +169,6 @@ void AliMUONVGeometryBuilder::MapSV(const TString& path0,
     TString newName =  gMC->VolDaughterName(volName, i);
             
     TString path = path0;
-    path += "/";
     path += ComposePath(newName, copyNo);
 
     MapSV(path, newName, detElemId);
@@ -215,8 +183,7 @@ void AliMUONVGeometryBuilder::MapSV(const TString& path0,
 AliMUONGeometryModule*  
 AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
 {
-// Returns the module geometry specified by moduleId
-// ---
+/// Return the module geometry specified by moduleId
 
   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
 
@@ -233,8 +200,7 @@ AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
 AliMUONGeometryEnvelopeStore*  
 AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
 {
-// Returns the envelope store of the module geometry specified by moduleId
-// ---
+/// Return the envelope store of the module geometry specified by moduleId
 
   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
   
@@ -247,11 +213,10 @@ AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
 }  
 
 //______________________________________________________________________________
-AliMUONGeometrySVMap*  
+AliMUONStringIntMap*  
 AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
 {
-// Returns the transformation store of the module geometry specified by moduleId
-// ---
+/// Return the transformation store of the module geometry specified by moduleId
 
   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
   
@@ -263,13 +228,31 @@ AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
   return geometry->GetSVMap();
 }  
 
+//______________________________________________________________________________
+Int_t                          
+AliMUONVGeometryBuilder::GetModuleId(const TString& envName) const
+{
+/// Return module Id which has the envelope with given name
+
+  for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
+
+    AliMUONGeometryModule* geometry 
+      = (AliMUONGeometryModule*)fGeometryModules->At(i);
+      
+    if ( geometry->GetEnvelopeStore()->FindEnvelope(envName) ) 
+      return geometry->GetModuleId();
+  }   
+  
+  return -1;
+}  
+
+
 //______________________________________________________________________________
 void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId, 
                                   const TGeoTranslation& translation)
 {
-// Sets the translation to the geometry module given by moduleId,
-// applies reference frame transformation 
-// ---
+/// Set the translation to the geometry module given by moduleId,
+/// apply reference frame transformation 
 
   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
   
@@ -291,9 +274,8 @@ void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
                                   const TGeoTranslation& translation,
                                  const TGeoRotation& rotation)
 {
-// Sets the translation to the geometry module given by moduleId,
-// applies reference frame transformation 
-// ---
+/// Set the transformation to the geometry module given by moduleId,
+/// apply reference frame transformation 
 
   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
   
@@ -306,12 +288,45 @@ void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
     = TGeoCombiTrans(translation, rotation);
 
   // Apply frame transform
-  TGeoHMatrix newTransform = ConvertTransform(translation);
+  TGeoHMatrix newTransform = ConvertTransform(transformation);
 
   // Set new transformation
   geometry->SetTransformation(newTransform);
 }  
 
+//______________________________________________________________________________
+void AliMUONVGeometryBuilder::SetVolume(Int_t moduleId, 
+                                 const TString& volumeName, 
+                                Bool_t isVirtual)
+{
+/// Set volume name, virtuality
+
+  TString path = GetGeometry(moduleId)->GetVolumePath();
+  // cout << "in AliMUONVGeometryBuilder::SetVolume " << path.Data() << endl;
+  
+  if ( path == "" ) path = "/ALIC_1";
+  path += ComposePath(volumeName, 1);
+
+  GetGeometry(moduleId)->SetVolumePath(path);
+  GetGeometry(moduleId)->SetIsVirtual(isVirtual);
+  // cout << "... set " << path.Data() << endl;
+}                               
+
+//______________________________________________________________________________
+void AliMUONVGeometryBuilder::SetMotherVolume(Int_t moduleId, 
+                                 const TString& volumeName)
+{
+/// Set mother volume name
+
+  TString motherVolumeName = ComposePath(volumeName, 1);
+
+  TString path = GetGeometry(moduleId)->GetVolumePath();
+  if ( path == "" ) path = "/ALIC_1";
+  path.Insert(7, motherVolumeName);  
+  
+  GetGeometry(moduleId)->SetVolumePath(path);
+}                               
+
 //
 // public functions
 //
@@ -320,6 +335,9 @@ void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
 void  AliMUONVGeometryBuilder::SetReferenceFrame(
                                   const TGeoCombiTrans& referenceFrame)
 { 
+/// Set reference frame to builder and to all associated geometry 
+/// modules
+
   fReferenceFrame = referenceFrame; 
 
   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
@@ -332,20 +350,23 @@ void  AliMUONVGeometryBuilder::SetReferenceFrame(
   }          
 }
 
-
 //______________________________________________________________________________
-void  AliMUONVGeometryBuilder::FillTransformations() const
+void  AliMUONVGeometryBuilder::UpdateDetElements(Bool_t create) const
 {
-// Fills transformations store from defined geometry.
-// ---
+/// Create or update detection elements:
+/// - if parameter create is true: detection elements are
+/// created and their global and local transformations are filled from geometry.
+/// - otherwise: only the volume path is passed from geometry
+/// to detection elements
 
   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
     AliMUONGeometryModule* geometry 
       = (AliMUONGeometryModule*)fGeometryModules->At(i);
+      
     const TObjArray* envelopes 
       = geometry->GetEnvelopeStore()->GetEnvelopes();    
     
-    AliMUONGeometryStore* detElements 
+    AliMpExMap* detElements 
       = geometry->GetTransformer()->GetDetElementStore(); 
       
     for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
@@ -357,35 +378,48 @@ void  AliMUONVGeometryBuilder::FillTransformations() const
        
       // Get envelope data 
       Int_t detElemId = envelope->GetUniqueID();       
-      TString path = ComposePath(envelope->GetName(), 
-                                 envelope->GetCopyNo());
-      const TGeoCombiTrans* transform = envelope->GetTransformation(); 
-      
-      // Apply frame transform
-      TGeoHMatrix localTransform = ConvertDETransform(*transform);
 
-      // Add detection element transformation 
-      AliMUONGeometryDetElement* detElement
-        = new AliMUONGeometryDetElement(detElemId, path, localTransform);
-      detElements->Add(detElemId, detElement);
+      // Compose full volume path
+      TString volPath = geometry->GetVolumePath();
+      volPath += ComposePath(envelope->GetName(), envelope->GetCopyNo());
 
-      // Compose global transformation
-      TGeoHMatrix globalTransform 
-       = AliMUONGeometryBuilder::Multiply( 
+      if ( create ) {
+        // Create detection element 
+        AliMUONGeometryDetElement* detElement
+          = new AliMUONGeometryDetElement(detElemId, volPath);
+        detElements->Add(detElemId, detElement);
+      
+        // Compose  local transformation
+        const TGeoCombiTrans* transform = envelope->GetTransformation(); 
+        // Apply frame transform
+        TGeoHMatrix localTransform = ConvertDETransform(*transform);
+        detElement->SetLocalTransformation(localTransform);
+
+        // Compose global transformation
+        TGeoHMatrix globalTransform 
+         = AliMUONGeometryBuilder::Multiply( 
                    (*geometry->GetTransformer()->GetTransformation()),
                     localTransform );
                    ;
-      // Set the global transformation to detection element
-      detElement->SetGlobalTransformation(globalTransform);
-    }  
+        // Set the global transformation to detection element
+        detElement->SetGlobalTransformation(globalTransform);
+      }
+      else {
+        // Get existing det elements
+        AliMUONGeometryDetElement* detElement
+          = (AliMUONGeometryDetElement*)detElements->GetValue(detElemId);
+          
+        // Set volume path  
+        detElement->SetVolumePath(volPath); 
+      }
+    }    
   }
 }
 
 //_____ _________________________________________________________________________
-void  AliMUONVGeometryBuilder::RebuildSVMaps() const
+void  AliMUONVGeometryBuilder::RebuildSVMaps(Bool_t withEnvelopes) const
 {
-// Clear the SV maps in memory and fill them from defined geometry.
-// ---
+/// Clear the SV maps in memory and fill them from defined geometry.
 
   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
     AliMUONGeometryModule* geometry 
@@ -403,30 +437,36 @@ void  AliMUONVGeometryBuilder::RebuildSVMaps() const
         = (AliMUONGeometryEnvelope*)envelopes->At(j);
 
       // skip envelope not corresponding to detection element
-      if(envelope->GetUniqueID() == 0) continue;
-       
-      TString path0("/ALIC.1");
-      if (geometry->GetMotherVolume() != "ALIC") {
-        path0 += "/";
-       path0 += ComposePath(geometry->GetMotherVolume(), 1);
-      }  
-      if (! geometry->IsVirtual() ) {
-        path0 += "/";
-       path0 += ComposePath(geometry->GetVolume(), 1);
+      if ( envelope->GetUniqueID() == 0 ) continue;
+      
+      // Get volume path of detection element
+      AliMUONGeometryDetElement* detElement
+        = geometry->GetTransformer()->GetDetElement(envelope->GetUniqueID());
+      std::string path0 = detElement->GetVolumePath().Data();  
+       
+      if ( ! withEnvelopes && geometry->IsVirtual() ) {
+         std::string vName = geometry->GetTransformer()->GetVolumeName().Data();
+        std::string vPath = ComposePath(vName, 1).Data();
+         std::string::size_type vPathPos = path0.find(vPath);
+         if ( vPathPos != std::string::npos )
+           path0.erase(vPathPos, vPath.size());
       }  
        
-      if (!envelope->IsVirtual()) {
-         TString path = path0;
-         path += "/";
-        path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
-        MapSV(path, envelope->GetName(), envelope->GetUniqueID());
+      if ( ! withEnvelopes && envelope->IsVirtual()) {
+         std::string eName = envelope->GetName();
+        std::string ePath = ComposePath(eName, envelope->GetCopyNo()).Data();
+         std::string::size_type ePathPos = path0.find(ePath);
+         if ( ePathPos != std::string::npos )
+           path0.erase(ePathPos, ePath.size());
       }
-      else {    
+
+      if ( ! envelope->IsVirtual() )
+        MapSV(path0, envelope->GetName(), envelope->GetUniqueID());
+      else {   
         for  (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
           AliMUONGeometryConstituent* constituent
             = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
          TString path = path0;
-         path += "/";
         path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
         MapSV(path, constituent->GetName(), envelope->GetUniqueID());
         }