]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGeometryTransformer.cxx
Update of ACORDE-QA-Raw data histograms (now they go from -0.5 to 59.5)
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryTransformer.cxx
index 4555490685f7bac7eb630b554df1bcef7e514657..8979695c45ac34e8a723baf11e0ce6e3aa441871 100644 (file)
  **************************************************************************/
 
 // $Id$
-//
-// ----------------------------
+
+//-----------------------------------------------------------------------------
 // Class AliMUONGeometryTransformer
 // ----------------------------
 // Top container class for geometry transformations
 // Author: Ivana Hrivnacova, IPN Orsay
+//-----------------------------------------------------------------------------
 
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONGeometryModuleTransformer.h"
 #include "AliMpDEManager.h"
 #include "AliMpConstants.h"
 #include "AliMpExMap.h"
-
+#include "AliMpCDB.h"
+#include "AliMpArea.h"
+#include <float.h>
+#include "AliMpVPadIterator.h"
+#include "AliMpPad.h"
+#include "AliMpDEIterator.h"
+#include <TVector2.h>
+#include "AliMpVSegmentation.h"
+#include "AliMpSegmentation.h"
+#include "AliMpExMapIterator.h"
 #include "AliLog.h"
 #include "AliAlignObjMatrix.h"
 #include "AliAlignObj.h"
@@ -56,7 +66,8 @@ AliMUONGeometryTransformer::AliMUONGeometryTransformer()
   : TObject(),
     fDetectorName(fgkDefaultDetectorName),
     fModuleTransformers(0),
-    fMisAlignArray(0)
+    fMisAlignArray(0),
+    fDEAreas(0x0)
 {
 /// Standard constructor
 
@@ -70,7 +81,8 @@ AliMUONGeometryTransformer::AliMUONGeometryTransformer(TRootIOCtor* /*ioCtor*/)
   : TObject(),
     fDetectorName(),
     fModuleTransformers(0),
-    fMisAlignArray(0)
+    fMisAlignArray(0),
+    fDEAreas(0x0)
 {
 /// Default constructor
 } 
@@ -82,12 +94,119 @@ AliMUONGeometryTransformer::~AliMUONGeometryTransformer()
 
   delete fModuleTransformers;
   delete fMisAlignArray;
+  delete fDEAreas;
 }
 
 //
 // private methods
 //
 
+
+//_____________________________________________________________________________
+AliMpArea*
+AliMUONGeometryTransformer::GetDEArea(Int_t detElemId) const
+{
+  /// Get area (in global coordinates) covered by a given detection element
+  if (!fDEAreas)
+  {
+    CreateDEAreas();
+  }
+  return static_cast<AliMpArea*>(fDEAreas->GetValue(detElemId));
+}
+
+//_____________________________________________________________________________
+void
+AliMUONGeometryTransformer::CreateDEAreas() const
+{
+  /// Create DE areas
+  
+  fDEAreas = new AliMpExMap;
+  
+  AliMpDEIterator it;
+
+  it.First();
+
+  /// Generate the DE areas in global coordinates
+
+  while ( !it.IsDone() )
+  {
+    Int_t detElemId = it.CurrentDEId();
+    
+    if ( !HasDE(detElemId) ) continue;
+    
+    const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0);
+    
+    Double_t xg,yg,zg;
+    
+    AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
+    
+    Double_t xl(0.0), yl(0.0), zl(0.0);
+    Double_t dx(seg->GetDimensionX());
+    Double_t dy(seg->GetDimensionY());
+    
+    if ( stationType == AliMp::kStation12 ) 
+    {
+      Double_t xmin(FLT_MAX);
+      Double_t xmax(-FLT_MAX);
+      Double_t ymin(FLT_MAX);
+      Double_t ymax(-FLT_MAX);
+      
+      for ( Int_t icathode = 0; icathode < 2; ++icathode ) 
+      {
+        const AliMpVSegmentation* cathode 
+        = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(icathode));
+        
+        AliMpVPadIterator* itp = cathode->CreateIterator();
+        
+        itp->First();
+        
+        while ( !itp->IsDone() ) 
+        {
+          AliMpPad pad = itp->CurrentItem();
+          AliMpArea a(pad.GetPositionX(),pad.GetPositionY(),
+                      pad.GetDimensionX(), pad.GetDimensionY());
+          xmin = TMath::Min(xmin,a.LeftBorder());
+          xmax = TMath::Max(xmax,a.RightBorder());
+          ymin = TMath::Min(ymin,a.DownBorder());
+          ymax = TMath::Max(ymax,a.UpBorder());
+          itp->Next();
+        }
+        
+        delete itp;
+      }
+      
+      xl = (xmin+xmax)/2.0;
+      yl = (ymin+ymax)/2.0;
+      dx = (xmax-xmin)/2.0;
+      dy = (ymax-ymin)/2.0;
+      
+      Local2Global(detElemId,xl,yl,zl,xg,yg,zg);
+    }
+    else
+    {
+      Local2Global(detElemId,xl,yl,zl,xg,yg,zg);
+    }
+    
+    fDEAreas->Add(detElemId,new AliMpArea(xg,yg,dx,dy));
+    
+    it.Next();
+  }
+}
+
+//_____________________________________________________________________________
+Bool_t AliMUONGeometryTransformer::LoadMapping() const
+{
+/// Load mapping from CDB
+
+  if ( ! AliMpCDB::LoadMpSegmentation() ) 
+  {
+    AliFatal("Could not access mapping from OCDB !");
+    return false;
+  }
+  
+  return true;
+}  
+
 //_____________________________________________________________________________
 AliMUONGeometryModuleTransformer* 
 AliMUONGeometryTransformer::GetModuleTransformerNonConst(
@@ -308,61 +427,6 @@ AliMUONGeometryTransformer::ReadTransformations(const TString& fileName)
   return true;
 }
 
-//______________________________________________________________________________
-Bool_t  
-AliMUONGeometryTransformer::LoadTransformations()
-{
-/// Load transformations for defined modules and detection elements
-/// using AliGeomManager
-
-  if ( ! AliGeomManager::GetGeometry() ) {
-    AliFatal("Geometry has to be laoded in AliGeomManager first.");
-    return false;
-  }   
-
-  for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
-    AliMUONGeometryModuleTransformer* moduleTransformer 
-      = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
-
-    // Module symbolic name
-    TString symname = GetModuleSymName(moduleTransformer->GetModuleId());
-    
-    // Set matrix from physical node
-    TGeoHMatrix* matrix = AliGeomManager::GetMatrix(symname);
-    if ( !matrix ) {
-      AliErrorStream() << "Geometry module matrix not found." << endl;
-      return false;
-    }  
-    moduleTransformer->SetTransformation(*matrix);
-    
-    // Loop over detection elements
-    AliMpExMap* detElements = moduleTransformer->GetDetElementStore();    
-   
-    for (Int_t j=0; j<detElements->GetSize(); j++) {
-      AliMUONGeometryDetElement* detElement
-        = (AliMUONGeometryDetElement*)detElements->GetObject(j);
-
-      // Det element  symbolic name
-      TString symname = GetDESymName(detElement->GetId());
-    
-      // Set global matrix from physical node
-      TGeoHMatrix* globalMatrix = AliGeomManager::GetMatrix(symname);
-      if ( !matrix ) {
-        AliErrorStream() << "Detection element matrix not found." << endl;
-        return false;
-      }  
-      detElement->SetGlobalTransformation(*globalMatrix);
-
-      // Set local matrix
-      TGeoHMatrix localMatrix = 
-        AliMUONGeometryBuilder::Multiply(
-          (*matrix).Inverse(), (*globalMatrix) );
-      detElement->SetLocalTransformation(localMatrix);
-    }  
-  } 
-  return true;    
-}  
-
 //______________________________________________________________________________
 void AliMUONGeometryTransformer::WriteTransform(ofstream& out,
                                    const TGeoMatrix* transform) const
@@ -420,10 +484,10 @@ void AliMUONGeometryTransformer::WriteDetElemTransforms(ofstream& out) const
     AliMUONGeometryModuleTransformer* moduleTransformer 
       = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
     AliMpExMap* detElements = moduleTransformer->GetDetElementStore();    
-
-    for (Int_t j=0; j<detElements->GetSize(); j++) {
-      AliMUONGeometryDetElement* detElement
-        = (AliMUONGeometryDetElement*)detElements->GetObject(j);
+    TIter next(detElements->CreateIterator());
+    AliMUONGeometryDetElement* detElement;
+    while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
+    {
       const TGeoMatrix* transform 
         = detElement->GetLocalTransformation(); 
        
@@ -462,6 +526,61 @@ TString AliMUONGeometryTransformer::GetDESymName(Int_t detElemId) const
 // public functions
 //
 
+//______________________________________________________________________________
+Bool_t  
+AliMUONGeometryTransformer::LoadTransformations()
+{
+/// Load transformations for defined modules and detection elements
+/// using AliGeomManager
+
+  if ( ! AliGeomManager::GetGeometry() ) {
+    AliFatal("Geometry has to be laoded in AliGeomManager first.");
+    return false;
+  }   
+
+  for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
+    AliMUONGeometryModuleTransformer* moduleTransformer 
+      = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
+
+    // Module symbolic name
+    TString symname = GetModuleSymName(moduleTransformer->GetModuleId());
+    
+    // Set matrix from physical node
+    TGeoHMatrix* matrix = AliGeomManager::GetMatrix(symname);
+    if ( ! matrix ) {
+      AliErrorStream() << "Geometry module matrix not found." << endl;
+      return false;
+    }  
+    moduleTransformer->SetTransformation(*matrix);
+    
+    // Loop over detection elements
+    AliMpExMap* detElements = moduleTransformer->GetDetElementStore();    
+    TIter next(detElements->CreateIterator());    
+    AliMUONGeometryDetElement* detElement;
+    
+    while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
+    {
+      // Det element  symbolic name
+      TString symnameDE = GetDESymName(detElement->GetId());
+    
+      // Set global matrix from physical node
+      TGeoHMatrix* globalMatrix = AliGeomManager::GetMatrix(symnameDE);
+      if ( ! globalMatrix ) {
+        AliErrorStream() << "Detection element matrix not found." << endl;
+        return false;
+      }  
+      detElement->SetGlobalTransformation(*globalMatrix, false);
+
+      // Set local matrix
+      TGeoHMatrix localMatrix = 
+        AliMUONGeometryBuilder::Multiply(
+          (*matrix).Inverse(), (*globalMatrix) );
+      detElement->SetLocalTransformation(localMatrix, false);
+    }  
+  } 
+  return true;    
+}  
+
 //______________________________________________________________________________
 Bool_t  
 AliMUONGeometryTransformer::LoadGeometryData(const TString& fileName)
@@ -641,15 +760,21 @@ void AliMUONGeometryTransformer::CreateModules()
 /// Create modules and their detection elements using info from mapping;
 /// but do not fill matrices
 
+  // Load mapping as its info is used to define modules & DEs
+  LoadMapping();
+
+  if ( fModuleTransformers->GetEntriesFast() == 0 ) {
+    // Create modules only if they do not yet exist
 
-  // Loop over geometry module
-  for (Int_t moduleId = 0; moduleId < AliMpConstants::NofGeomModules(); ++moduleId ) {
+    // Loop over geometry module
+    for (Int_t moduleId = 0; moduleId < AliMpConstants::NofGeomModules(); ++moduleId ) {
     
-    // Create geometry module transformer
-    AliMUONGeometryModuleTransformer* moduleTransformer
-      = new AliMUONGeometryModuleTransformer(moduleId);
-    AddModuleTransformer(moduleTransformer);
-  }   
+      // Create geometry module transformer
+      AliMUONGeometryModuleTransformer* moduleTransformer
+        = new AliMUONGeometryModuleTransformer(moduleId);
+      AddModuleTransformer(moduleTransformer);
+    }
+  }     
     
   // Loop over detection elements
   AliMpDEIterator it;
@@ -690,8 +815,8 @@ void AliMUONGeometryTransformer::AddAlignableVolumes() const
                                        module->GetVolumePath());
     if ( ! pnEntry ) {
       AliErrorStream() 
-        << "Volume path for geometry module "
-        << module->GetModuleId()
+        << "Volume path " << module->GetVolumePath().Data()
+        << " for geometry module " << module->GetModuleId() << " " << module
         << " not found in geometry." << endl;
     }
     else {
@@ -702,24 +827,25 @@ void AliMUONGeometryTransformer::AddAlignableVolumes() const
 
     // Detection elements
     AliMpExMap* detElements = module->GetDetElementStore();    
-
-    for (Int_t j=0; j<detElements->GetSize(); j++) {
-      AliMUONGeometryDetElement* detElement
-        = (AliMUONGeometryDetElement*)detElements->GetObject(j);
-       
+    TIter next(detElements->CreateIterator());    
+    AliMUONGeometryDetElement* detElement;
+    
+    while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
+    {
       // Set detection element symbolic name
-      TGeoPNEntry* pnEntry
+      TGeoPNEntry* pnEntryDE
         = gGeoManager->SetAlignableEntry(GetDESymName(detElement->GetId()), 
                                          detElement->GetVolumePath());
-      if ( ! pnEntry ) {
+      if ( ! pnEntryDE ) {
         AliErrorStream() 
-          << "Volume path for detection element "
-          << detElement->GetId()
+          << "Volume path " 
+          << detElement->GetVolumePath().Data() 
+          << " for detection element " << detElement->GetId()
           << " not found in geometry." << endl;
       }
       else {
         // Set detection element matrix
-        pnEntry->SetMatrix(new TGeoHMatrix(*detElement->GetGlobalTransformation()));                                      
+        pnEntryDE->SetMatrix(new TGeoHMatrix(*detElement->GetGlobalTransformation()));                                      
          // the matrix will be deleted via TGeoManager 
       }                                      
     }  
@@ -758,12 +884,13 @@ TClonesArray* AliMUONGeometryTransformer::CreateZeroAlignmentData() const
   for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
     AliMUONGeometryModuleTransformer* moduleTransformer 
       = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
-    AliMpExMap* detElements = moduleTransformer->GetDetElementStore();    
 
-    for (Int_t j=0; j<detElements->GetSize(); j++) {
-      AliMUONGeometryDetElement* detElement
-        = (AliMUONGeometryDetElement*)detElements->GetObject(j);
-       
+    AliMpExMap* detElements = moduleTransformer->GetDetElementStore();    
+    TIter next(detElements->CreateIterator());    
+    AliMUONGeometryDetElement* detElement;
+    
+    while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
+    {
       Int_t detElemId = detElement->GetId();
   
       // Align object ID