]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGeometryTransformer.cxx
remove calls to AliMUONTriggerDecision
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryTransformer.cxx
index fbcdb921d154278461193d83e0a2688d6586890a..292c044b6eeba6fa74822a1de590f7118f8a9596 100644 (file)
 
 // $Id$
 //
+// ----------------------------
 // Class AliMUONGeometryTransformer
 // ----------------------------
 // Top container class for geometry transformations
-//
 // Author: Ivana Hrivnacova, IPN Orsay
 
 #include "AliMUONGeometryTransformer.h"
@@ -29,6 +29,7 @@
 
 #include "AliLog.h"
 #include "AliAlignObjMatrix.h"
+#include "AliAlignObj.h"
 
 #include <Riostream.h>
 #include <TSystem.h>
 
 #include <sstream>
 
+/// \cond CLASSIMP
 ClassImp(AliMUONGeometryTransformer)
+/// \endcond
  
 //______________________________________________________________________________
-AliMUONGeometryTransformer::AliMUONGeometryTransformer(Bool_t isOwner)
+AliMUONGeometryTransformer::AliMUONGeometryTransformer(Bool_t isOwner,
+                                          const TString& detectorName)
+
   : TObject(),
+    fDetectorName(detectorName),
     fModuleTransformers(0),
     fMisAlignArray(0)
 {
@@ -57,22 +63,13 @@ AliMUONGeometryTransformer::AliMUONGeometryTransformer(Bool_t isOwner)
 //______________________________________________________________________________
 AliMUONGeometryTransformer::AliMUONGeometryTransformer() 
   : TObject(),
+    fDetectorName(),
     fModuleTransformers(0),
     fMisAlignArray(0)
 {
 /// Default constructor
 } 
 
-//______________________________________________________________________________
-AliMUONGeometryTransformer::AliMUONGeometryTransformer(
-                                   const AliMUONGeometryTransformer& right) 
-  : TObject(right) 
-{  
-/// Copy constructor (not implemented)
-
-  AliFatal("Copy constructor not provided.");
-}
-
 //______________________________________________________________________________
 AliMUONGeometryTransformer::~AliMUONGeometryTransformer()
 {
@@ -82,20 +79,6 @@ AliMUONGeometryTransformer::~AliMUONGeometryTransformer()
   delete fMisAlignArray;
 }
 
-//______________________________________________________________________________
-AliMUONGeometryTransformer& 
-AliMUONGeometryTransformer::operator=(const AliMUONGeometryTransformer& right)
-{
-/// Assignement operator (not implemented)
-
-  // check assignement to self
-  if (this == &right) return *this;
-
-  AliFatal("Assignement operator not provided.");
-    
-  return *this;  
-}    
-
 //
 // private methods
 //
@@ -124,8 +107,7 @@ TGeoHMatrix AliMUONGeometryTransformer::GetTransform(
                  Double_t a1, Double_t a2, Double_t a3, 
                  Double_t a4, Double_t a5, Double_t a6) const
 {                
-// Builds the transformation from the given parameters
-// ---
+/// Build the transformation from the given parameters
 
   // Compose transform
   return TGeoCombiTrans(TGeoTranslation(x, y, z), 
@@ -137,8 +119,7 @@ TGeoHMatrix AliMUONGeometryTransformer::GetTransform(
 void AliMUONGeometryTransformer::FillModuleVolPath(Int_t moduleId,
                                            const TString& volPath) 
 {
-// Create module with the given moduleId and volPath
-// ---
+/// Create module with the given moduleId and volPath
 
   // Get/Create geometry module transformer
   AliMUONGeometryModuleTransformer* moduleTransformer
@@ -155,7 +136,7 @@ void AliMUONGeometryTransformer::FillModuleVolPath(Int_t moduleId,
 void AliMUONGeometryTransformer::FillDetElemVolPath(Int_t detElemId, 
                                            const TString& volPath) 
 {
-// Create detection element with the given detElemId and volPath
+/// Create detection element with the given detElemId and volPath
 
   // Module Id
   Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
@@ -177,8 +158,7 @@ void AliMUONGeometryTransformer::FillModuleTransform(Int_t moduleId,
                  Double_t a1, Double_t a2, Double_t a3,
                  Double_t a4, Double_t a5, Double_t a6) 
 {
-// Fill the transformation of the module.
-// ---
+/// Fill the transformation of the module.
 
   // Get/Create geometry module transformer
   moduleId--;
@@ -206,8 +186,7 @@ void AliMUONGeometryTransformer::FillDetElemTransform(
                  Double_t a1, Double_t a2, Double_t a3,
                  Double_t a4, Double_t a5, Double_t a6) 
 {
-// Fill the transformation of the detection element.
-// ---
+/// Fill the transformation of the detection element.
 
   // Module Id
   Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
@@ -247,8 +226,7 @@ void AliMUONGeometryTransformer::FillDetElemTransform(
 Bool_t  
 AliMUONGeometryTransformer::ReadVolPaths(ifstream& in)
 {
-// Reads modules and detection element volume paths from stream
-// ---
+/// Read modules and detection element volume paths from stream
 
   Int_t id;
   TString key, volumePath;
@@ -281,9 +259,8 @@ AliMUONGeometryTransformer::ReadVolPaths(ifstream& in)
 //______________________________________________________________________________
 TString  AliMUONGeometryTransformer::ReadModuleTransforms(ifstream& in)
 {
-// Reads and fills modules transformations from a file
-// Returns true, if reading finished correctly.
-// ---
+/// Read and fill modules transformations from the stream.
+/// Return true, if reading finished correctly.
 
   TString key("CH");
   while ( key == TString("CH") ) {
@@ -324,9 +301,8 @@ TString  AliMUONGeometryTransformer::ReadModuleTransforms(ifstream& in)
 //______________________________________________________________________________
 TString  AliMUONGeometryTransformer::ReadDetElemTransforms(ifstream& in)
 {
-// Reads detection elements transformations from a file
-// Returns true, if reading finished correctly.
-// ---
+/// Read detection elements transformations from the stream.
+/// Return true, if reading finished correctly.
 
   TString key("DE");
   while ( key == TString("DE") ) {
@@ -370,9 +346,14 @@ TString  AliMUONGeometryTransformer::ReadDetElemTransforms(ifstream& in)
 Bool_t  
 AliMUONGeometryTransformer::LoadTransforms(TGeoManager* tgeoManager)
 {
-/// Loads transformations for defined modules and detection elements
+/// Load transformations for defined modules and detection elements
 /// from the root file
 
+  if ( !tgeoManager) {
+    AliFatal("No TGeoManager defined.");
+    return false;
+  }   
+
   for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
     AliMUONGeometryModuleTransformer* moduleTransformer 
       = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
@@ -431,9 +412,8 @@ AliMUONGeometryTransformer::LoadTransforms(TGeoManager* tgeoManager)
 Bool_t  
 AliMUONGeometryTransformer::ReadVolPaths(const TString& fileName)
 {
-// Reads detection element volume paths from a file
-// Returns true, if reading finished correctly.
-// ---
+/// Read detection element volume paths from a file.
+/// Return true, if reading finished correctly.
 
   // File path
   TString filePath = gSystem->Getenv("ALICE_ROOT");
@@ -456,9 +436,8 @@ AliMUONGeometryTransformer::ReadVolPaths(const TString& fileName)
 Bool_t  
 AliMUONGeometryTransformer::ReadTransformations(const TString& fileName)
 {
-// Reads transformations from a file
-// Returns true, if reading finished correctly.
-// ---
+/// Read transformations from a file.
+/// Return true, if reading finished correctly.
 
   // File path
   TString filePath = gSystem->Getenv("ALICE_ROOT");
@@ -493,9 +472,8 @@ AliMUONGeometryTransformer::ReadTransformations(const TString& fileName)
 Bool_t  
 AliMUONGeometryTransformer::ReadTransformations2(const TString& fileName)
 {
-// Reads transformations from root geometry file
-// Returns true, if reading finished correctly.
-// ---
+/// Read transformations from root geometry file.
+/// Return true, if reading finished correctly.
 
   // File path
   TString filePath = gSystem->Getenv("ALICE_ROOT");
@@ -515,8 +493,7 @@ AliMUONGeometryTransformer::ReadTransformations2(const TString& fileName)
 void AliMUONGeometryTransformer::WriteTransform(ofstream& out,
                                    const TGeoMatrix* transform) const
 {
-// Writes the transformations 
-// ---
+/// Write given transformation 
 
   out << "   pos: ";
   const Double_t* xyz = transform->GetTranslation();
@@ -542,7 +519,7 @@ void AliMUONGeometryTransformer::WriteTransform(ofstream& out,
 //______________________________________________________________________________
 void AliMUONGeometryTransformer::WriteModuleVolPaths(ofstream& out) const
 {
-// Write modules volume paths
+/// Write module volume paths for all module transformers
 
   for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
     AliMUONGeometryModuleTransformer* moduleTransformer 
@@ -559,7 +536,8 @@ void AliMUONGeometryTransformer::WriteModuleVolPaths(ofstream& out) const
 //______________________________________________________________________________
 void AliMUONGeometryTransformer::WriteDetElemVolPaths(ofstream& out) const
 {
-// Write detection elements volume paths
+/// Write detection element volume paths for all detection elements in all 
+/// module transformers
 
   for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
     AliMUONGeometryModuleTransformer* moduleTransformer 
@@ -583,7 +561,7 @@ void AliMUONGeometryTransformer::WriteDetElemVolPaths(ofstream& out) const
 //______________________________________________________________________________
 void AliMUONGeometryTransformer::WriteModuleTransforms(ofstream& out) const
 {
-// Write modules transformations
+/// Write module transformations for all module transformers
 
   for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
     AliMUONGeometryModuleTransformer* moduleTransformer 
@@ -603,8 +581,8 @@ void AliMUONGeometryTransformer::WriteModuleTransforms(ofstream& out) const
 //______________________________________________________________________________
 void AliMUONGeometryTransformer::WriteDetElemTransforms(ofstream& out) const
 {
-// Writes detection elements transformations
-// ---
+/// Write detection element transformations for all detection elements in all 
+/// module transformers
 
   for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
     AliMUONGeometryModuleTransformer* moduleTransformer 
@@ -627,6 +605,38 @@ void AliMUONGeometryTransformer::WriteDetElemTransforms(ofstream& out) const
   }     
 }
 
+//______________________________________________________________________________
+TString AliMUONGeometryTransformer::GetModuleSymName(Int_t moduleId) const
+{
+/// Return the module symbolic name (use for alignment)
+
+  const AliMUONGeometryModuleTransformer* kTransformer 
+    = GetModuleTransformer(moduleId);
+  if ( ! kTransformer ) {
+    AliErrorStream() << "Module " << moduleId << " not found." << endl; 
+    return "";
+  }   
+  
+  return "/" + fDetectorName + "/" + kTransformer->GetModuleName();
+}  
+
+//______________________________________________________________________________
+TString AliMUONGeometryTransformer::GetDESymName(Int_t detElemId) const
+{
+
+  const AliMUONGeometryDetElement* kDetElement 
+    = GetDetElement(detElemId);
+  if ( ! kDetElement ) {
+    AliErrorStream() << "Det element " << detElemId << " not found." << endl; 
+    return "";
+  }   
+  
+  // Module Id
+  Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
+
+  return GetModuleSymName(moduleId) + "/" + kDetElement->GetDEName();
+}  
+
 //
 // public functions
 //
@@ -663,7 +673,7 @@ AliMUONGeometryTransformer::ReadGeometryData(
                                 TGeoManager* tgeoManager)
 {
 /// Load geometry data from root geometry using defined
-/// voluem paths from file
+/// volume paths from file
 
   Bool_t result1 = ReadVolPaths(volPathFileName);
 
@@ -695,9 +705,8 @@ AliMUONGeometryTransformer::WriteGeometryData(
 Bool_t  
 AliMUONGeometryTransformer::WriteVolumePaths(const TString& fileName) const
 {
-// Writes volume paths for modules and detection element volumes into a file
-// Returns true, if writing finished correctly.
-// ---
+/// Write volume paths for modules and detection element volumes into a file.
+/// Return true, if writing finished correctly.
 
   // No writing
   // if builder is not associated with any geometry module
@@ -728,9 +737,8 @@ AliMUONGeometryTransformer::WriteVolumePaths(const TString& fileName) const
 Bool_t  
 AliMUONGeometryTransformer::WriteTransformations(const TString& fileName) const
 {
-// Writes transformations into a file
-// Returns true, if writing finished correctly.
-// ---
+/// Write transformations into a file.
+/// Return true, if writing finished correctly.
 
   // No writing
   // if builder is not associated with any geometry module
@@ -761,9 +769,8 @@ AliMUONGeometryTransformer::WriteTransformations(const TString& fileName) const
 Bool_t  
 AliMUONGeometryTransformer::WriteMisAlignmentData(const TString& fileName) const
 {
-// Writes misalignment data into a file
-// Returns true, if writing finished correctly.
-// ---
+/// Write misalignment data into a file
+/// Return true, if writing finished correctly.
 
   // No writing
   // if builder is not associated with any geometry module
@@ -796,7 +803,7 @@ AliMUONGeometryTransformer::WriteMisAlignmentData(const TString& fileName) const
 void AliMUONGeometryTransformer::AddModuleTransformer(
                           AliMUONGeometryModuleTransformer* moduleTransformer)
 {
-/// Add the geometrymodule to the array
+/// Add the module transformer to the array
 
   fModuleTransformers->AddAt(moduleTransformer, 
                              moduleTransformer->GetModuleId());
@@ -806,7 +813,7 @@ void AliMUONGeometryTransformer::AddModuleTransformer(
 void  AliMUONGeometryTransformer::AddMisAlignModule(Int_t moduleId, 
                                               const TGeoHMatrix& matrix)
 {
-/// Build AliAlignObjMatrix with module ID, its volumePaths
+/// Build AliAlignObjMatrix with module ID, its volumePath
 /// and the given delta transformation matrix                                        
 
   if ( ! fMisAlignArray )
@@ -819,21 +826,21 @@ void  AliMUONGeometryTransformer::AddMisAlignModule(Int_t moduleId,
     return;
   }   
   
-  // Get path  
-  TString path = kTransformer->GetVolumePath(); 
-  
+  // Get unique align object ID
+  Int_t volId = AliAlignObj::LayerToVolUID(AliAlignObj::kMUON, moduleId); 
+
   // Create mis align matrix
   TClonesArray& refArray =*fMisAlignArray;
   Int_t pos = fMisAlignArray->GetEntriesFast();
-  new (refArray[pos]) AliAlignObjMatrix(path.Data(), moduleId, 
-                              const_cast<TGeoHMatrix&>(matrix));
+  new (refArray[pos]) AliAlignObjMatrix(GetModuleSymName(moduleId), volId, 
+                                       const_cast<TGeoHMatrix&>(matrix),kTRUE);
 }
 
 //_____________________________________________________________________________
 void  AliMUONGeometryTransformer::AddMisAlignDetElement(Int_t detElemId, 
                                               const TGeoHMatrix& matrix)
 {
-/// Build AliAlignObjMatrix with detection element ID, its volumePaths
+/// Build AliAlignObjMatrix with detection element ID, its volumePath
 /// and the given delta transformation matrix                                        
 
   if ( ! fMisAlignArray )
@@ -847,16 +854,107 @@ void  AliMUONGeometryTransformer::AddMisAlignDetElement(Int_t detElemId,
     return;
   }   
   
-  // Get path  
-  TString path = kDetElement->GetVolumePath(); 
-  
+  // Get unique align object ID
+  Int_t volId = AliAlignObj::LayerToVolUID(AliAlignObj::kMUON, detElemId); 
+
   // Create mis align matrix
   TClonesArray& refArray =*fMisAlignArray;
   Int_t pos = fMisAlignArray->GetEntriesFast();
-  new(refArray[pos]) AliAlignObjMatrix(path.Data(), detElemId, 
-                              const_cast<TGeoHMatrix&>(matrix));
+  new(refArray[pos]) AliAlignObjMatrix(GetDESymName(detElemId), volId, 
+                                      const_cast<TGeoHMatrix&>(matrix),kTRUE);
 }
 
+//_____________________________________________________________________________
+void AliMUONGeometryTransformer::AddAlignableVolumes() const
+{
+/// Set symbolic names to alignable objects to TGeo
+
+  if ( ! gGeoManager ) {
+    AliWarning("TGeoManager not defined.");
+    return;
+  }  
+
+  // Modules 
+  for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
+    AliMUONGeometryModuleTransformer* module 
+      = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
+
+    // Set module symbolic name
+    gGeoManager->SetAlignableEntry(GetModuleSymName(module->GetModuleId()), 
+                                   module->GetVolumePath());
+    //cout << "Module sym name: " << GetModuleSymName(module->GetModuleId()) 
+    //     << "  volPath: " << module->GetVolumePath() << endl;
+
+    // Detection elements
+    AliMUONGeometryStore* detElements 
+      = module->GetDetElementStore();    
+
+    for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
+      AliMUONGeometryDetElement* detElement
+        = (AliMUONGeometryDetElement*)detElements->GetEntry(j);
+       
+      // Set detection element symbolic name
+      gGeoManager->SetAlignableEntry(GetDESymName(detElement->GetId()), 
+                                     detElement->GetVolumePath());
+      //cout << "DE name: " << GetDESymName(detElement->GetId()) 
+      //     << "  volPath: " << detElement->GetVolumePath() << endl;
+    }  
+  }     
+}           
+    
+//_____________________________________________________________________________
+TClonesArray* AliMUONGeometryTransformer::CreateZeroAlignmentData() const
+{
+/// Create array with zero alignment data
+                              
+  // Create array for zero-alignment objects
+  TClonesArray* array = new TClonesArray("AliAlignObjMatrix", 200);
+  TClonesArray& refArray =*array;
+  array->SetOwner(true);
+
+  // Identity matrix
+  TGeoHMatrix matrix;
+
+  // Modules 
+  for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
+    AliMUONGeometryModuleTransformer* module 
+      = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
+
+    Int_t moduleId = module->GetModuleId();
+  
+    // Align object ID
+    Int_t volId = AliAlignObj::LayerToVolUID(AliAlignObj::kMUON, moduleId); 
+
+    // Create mis align matrix
+    Int_t pos = array->GetEntriesFast();
+    new (refArray[pos]) AliAlignObjMatrix(GetModuleSymName(moduleId), volId, matrix, kTRUE);
+  }     
+
+  // Detection elements
+  for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
+    AliMUONGeometryModuleTransformer* moduleTransformer 
+      = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
+    AliMUONGeometryStore* detElements 
+      = moduleTransformer->GetDetElementStore();    
+
+    for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
+      AliMUONGeometryDetElement* detElement
+        = (AliMUONGeometryDetElement*)detElements->GetEntry(j);
+       
+      Int_t detElemId = detElement->GetId();
+  
+      // Align object ID
+      Int_t volId = AliAlignObj::LayerToVolUID(AliAlignObj::kMUON, detElemId); 
+
+      // Create mis align matrix
+      Int_t pos = array->GetEntriesFast();
+      new (refArray[pos]) AliAlignObjMatrix(GetDESymName(detElemId), volId, matrix, kTRUE);
+    }
+  }
+  
+  return array;
+}       
+
 //_____________________________________________________________________________
 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
                  Float_t xg, Float_t yg, Float_t zg, 
@@ -865,7 +963,7 @@ void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
 /// Transform point from the global reference frame (ALIC)
 /// to the local reference frame of the detection element specified
 /// by detElemId.
-   
+
   const AliMUONGeometryModuleTransformer* kTransformer 
     = GetModuleTransformerByDEId(detElemId);
   
@@ -881,7 +979,7 @@ void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
 /// Transform point from the global reference frame (ALIC)
 /// to the local reference frame of the detection element specified
 /// by detElemId.
-   
+
   const AliMUONGeometryModuleTransformer* kTransformer 
     = GetModuleTransformerByDEId(detElemId);
   
@@ -923,7 +1021,7 @@ void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
 const AliMUONGeometryModuleTransformer* 
 AliMUONGeometryTransformer::GetModuleTransformer(Int_t index, Bool_t warn) const
 {
-/// Return the geometry module specified by index
+/// Return the geometry module transformer specified by index
 
   return GetModuleTransformerNonConst(index, warn);
 }    
@@ -933,7 +1031,7 @@ const AliMUONGeometryModuleTransformer*
 AliMUONGeometryTransformer::GetModuleTransformerByDEId(Int_t detElemId, 
                                                        Bool_t warn) const
 {
-/// Return the geometry module specified by index
+/// Return the geometry module transformer specified by detection element ID
 
   // Get module index
   Int_t index = AliMUONGeometryStore::GetModuleId(detElemId);
@@ -945,7 +1043,7 @@ AliMUONGeometryTransformer::GetModuleTransformerByDEId(Int_t detElemId,
 const AliMUONGeometryDetElement* 
 AliMUONGeometryTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
 {
-/// Return detection ellemnt with given detElemId                             
+/// Return detection element with given detElemId                             
 
   const AliMUONGeometryModuleTransformer* kTransformer 
     = GetModuleTransformerByDEId(detElemId, warn);