X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONGeometryTransformer.cxx;h=0f81ee8a29d0ee6a706f050163b5729cdd651440;hb=d1f9a8ab3a5b4a639ed45a698f799480db221f72;hp=3f3c9e7b08f5e758228d30db51027114160bb652;hpb=a7d4e65bb71da259b58c97936e5fab145b704295;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONGeometryTransformer.cxx b/MUON/AliMUONGeometryTransformer.cxx index 3f3c9e7b08f..0f81ee8a29d 100644 --- a/MUON/AliMUONGeometryTransformer.cxx +++ b/MUON/AliMUONGeometryTransformer.cxx @@ -14,64 +14,79 @@ **************************************************************************/ // $Id$ -// + +//----------------------------------------------------------------------------- // Class AliMUONGeometryTransformer // ---------------------------- // Top container class for geometry transformations -// // Author: Ivana Hrivnacova, IPN Orsay +//----------------------------------------------------------------------------- #include "AliMUONGeometryTransformer.h" #include "AliMUONGeometryModuleTransformer.h" #include "AliMUONGeometryDetElement.h" -#include "AliMUONGeometryStore.h" #include "AliMUONGeometryBuilder.h" +#include "AliMpDEManager.h" +#include "AliMpConstants.h" +#include "AliMpExMap.h" +#include "AliMpCDB.h" +#include "AliMpArea.h" +#include +#include "AliMpVPadIterator.h" +#include "AliMpPad.h" +#include "AliMpDEIterator.h" +#include +#include "AliMpVSegmentation.h" +#include "AliMpSegmentation.h" + #include "AliLog.h" #include "AliAlignObjMatrix.h" +#include "AliAlignObj.h" #include #include #include #include #include +#include +#include #include +/// \cond CLASSIMP ClassImp(AliMUONGeometryTransformer) +/// \endcond + +const TString AliMUONGeometryTransformer::fgkDefaultDetectorName = "MUON"; //______________________________________________________________________________ -AliMUONGeometryTransformer::AliMUONGeometryTransformer(Bool_t isOwner) +AliMUONGeometryTransformer::AliMUONGeometryTransformer() + : TObject(), + fDetectorName(fgkDefaultDetectorName), fModuleTransformers(0), - fMisAlignArray(0) + fMisAlignArray(0), + fDEAreas(0x0) { /// Standard constructor // Create array for geometry modules - fModuleTransformers = new TObjArray(); - fModuleTransformers->SetOwner(isOwner); + fModuleTransformers = new TObjArray(100); + fModuleTransformers->SetOwner(true); } //______________________________________________________________________________ -AliMUONGeometryTransformer::AliMUONGeometryTransformer() +AliMUONGeometryTransformer::AliMUONGeometryTransformer(TRootIOCtor* /*ioCtor*/) : TObject(), + fDetectorName(), fModuleTransformers(0), - fMisAlignArray(0) + fMisAlignArray(0), + fDEAreas(0x0) { /// Default constructor } -//______________________________________________________________________________ -AliMUONGeometryTransformer::AliMUONGeometryTransformer( - const AliMUONGeometryTransformer& right) - : TObject(right) -{ -/// Copy constructor (not implemented) - - AliFatal("Copy constructor not provided."); -} - //______________________________________________________________________________ AliMUONGeometryTransformer::~AliMUONGeometryTransformer() { @@ -79,25 +94,117 @@ AliMUONGeometryTransformer::~AliMUONGeometryTransformer() delete fModuleTransformers; delete fMisAlignArray; + delete fDEAreas; } -//______________________________________________________________________________ -AliMUONGeometryTransformer& -AliMUONGeometryTransformer::operator=(const AliMUONGeometryTransformer& right) +// +// private methods +// + + +//_____________________________________________________________________________ +AliMpArea* +AliMUONGeometryTransformer::GetDEArea(Int_t detElemId) const { -/// Assignement operator (not implemented) + /// Get area (in global coordinates) covered by a given detection element + if (!fDEAreas) + { + CreateDEAreas(); + } + return static_cast(fDEAreas->GetValue(detElemId)); +} - // check assignement to self - if (this == &right) return *this; +//_____________________________________________________________________________ +void +AliMUONGeometryTransformer::CreateDEAreas() const +{ + /// Create DE areas + + fDEAreas = new AliMpExMap(true); + + AliMpDEIterator it; + + it.First(); - AliFatal("Assignement operator not provided."); + /// Generate the DE areas in global coordinates + + while ( !it.IsDone() ) + { + Int_t detElemId = it.CurrentDEId(); - return *this; -} + 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->Dimensions().X()); + Double_t dy(seg->Dimensions().Y()); + + if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) + { + 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* it = cathode->CreateIterator(); + + it->First(); + + while ( !it->IsDone() ) + { + AliMpPad pad = it->CurrentItem(); + AliMpArea a(pad.Position(),pad.Dimensions()); + xmin = TMath::Min(xmin,a.LeftBorder()); + xmax = TMath::Max(xmax,a.RightBorder()); + ymin = TMath::Min(ymin,a.DownBorder()); + ymax = TMath::Max(ymax,a.UpBorder()); + it->Next(); + } + + delete it; + } + + 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(TVector2(xg,yg),TVector2(dx,dy))); + + it.Next(); + } +} -// -// private methods -// +//_____________________________________________________________________________ +Bool_t AliMUONGeometryTransformer::LoadMapping() const +{ +/// Load mapping from CDB + + if ( ! AliMpCDB::LoadMpSegmentation() ) + { + AliFatal("Could not access mapping from OCDB !"); + return false; + } + + return true; +} //_____________________________________________________________________________ AliMUONGeometryModuleTransformer* @@ -123,8 +230,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), @@ -132,56 +238,13 @@ TGeoHMatrix AliMUONGeometryTransformer::GetTransform( } -//______________________________________________________________________________ -void AliMUONGeometryTransformer::FillModuleVolPath(Int_t moduleId, - const TString& volPath) -{ -// Create module with the given moduleId and volPath -// --- - - // Get/Create geometry module transformer - AliMUONGeometryModuleTransformer* moduleTransformer - = GetModuleTransformerNonConst(moduleId, false); - - if ( !moduleTransformer ) { - moduleTransformer = new AliMUONGeometryModuleTransformer(moduleId); - AddModuleTransformer(moduleTransformer); - } - moduleTransformer->SetVolumePath(volPath); -} - -//______________________________________________________________________________ -void AliMUONGeometryTransformer::FillDetElemVolPath(Int_t detElemId, - const TString& volPath) -{ -// Create detection element with the given detElemId and volPath - - // Module Id - Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId); - - // Get detection element store - AliMUONGeometryStore* detElements = - GetModuleTransformer(moduleId)->GetDetElementStore(); - - // Add detection element - AliMUONGeometryDetElement* detElement - = new AliMUONGeometryDetElement(detElemId, volPath); - detElements->Add(detElemId, detElement); -} - - //______________________________________________________________________________ void AliMUONGeometryTransformer::FillModuleTransform(Int_t moduleId, Double_t x, Double_t y, Double_t z, Double_t a1, Double_t a2, Double_t a3, Double_t a4, Double_t a5, Double_t a6) { -// Fill the transformation of the module. -// --- - - // Get/Create geometry module transformer - moduleId--; - // Modules numbers in the file are starting from 1 +/// Fill the transformation of the module. AliMUONGeometryModuleTransformer* moduleTransformer = GetModuleTransformerNonConst(moduleId, false); @@ -205,11 +268,10 @@ 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); + Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId); // Get module transformer const AliMUONGeometryModuleTransformer* kModuleTransformer @@ -242,50 +304,14 @@ void AliMUONGeometryTransformer::FillDetElemTransform( detElement->SetGlobalTransformation(globalTransform); } -//______________________________________________________________________________ -Bool_t -AliMUONGeometryTransformer::ReadVolPaths(ifstream& in) -{ -// Reads modules and detection element volume paths from stream -// --- - - Int_t id; - TString key, volumePath; - in >> key; - - while ( !in.eof() ) { - - in >> id >> volumePath; - - // cout << "id=" << id << " " - // << "volPath= " << volumePath - // << endl; - - if ( key == TString("CH") ) - FillModuleVolPath(id, volumePath); - - else if ( key == TString("DE") ) - FillDetElemVolPath(id, volumePath); - - else { - AliFatal(Form("%s key not recognized", key.Data())); - return false; - } - in >> key; - } - - return true; -} - //______________________________________________________________________________ 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") ) { + TString key(AliMUONGeometryModuleTransformer::GetModuleNamePrefix()); + while ( key == AliMUONGeometryModuleTransformer::GetModuleNamePrefix() ) { Int_t id; Double_t x, y, z; Double_t a1, a2, a3, a4, a5, a6; @@ -323,12 +349,11 @@ 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") ) { + TString key(AliMUONGeometryDetElement::GetDENamePrefix()); + while ( key == AliMUONGeometryDetElement::GetDENamePrefix() ) { // Input data Int_t detElemId; @@ -365,99 +390,12 @@ TString AliMUONGeometryTransformer::ReadDetElemTransforms(ifstream& in) return key; } -//______________________________________________________________________________ -Bool_t -AliMUONGeometryTransformer::LoadTransforms(TGeoManager* tgeoManager) -{ -/// Loads transformations for defined modules and detection elements -/// from the root file - - for (Int_t i=0; iGetEntriesFast(); i++) { - AliMUONGeometryModuleTransformer* moduleTransformer - = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); - - // Module path - TString path = moduleTransformer->GetVolumePath(); - - // Make physical node - TGeoPhysicalNode* moduleNode = tgeoManager->MakePhysicalNode(path); - if ( ! moduleNode ) { - AliErrorStream() - << "Module id: " << moduleTransformer->GetModuleId() - << " volume path: " << path << " not found in geometry." << endl; - return false; - } - - // Set matrix from physical node - TGeoHMatrix matrix = *moduleNode->GetMatrix(); - moduleTransformer->SetTransformation(matrix); - - // Loop over detection elements - AliMUONGeometryStore* detElements - = moduleTransformer->GetDetElementStore(); - - for (Int_t j=0; jGetNofEntries(); j++) { - AliMUONGeometryDetElement* detElement - = (AliMUONGeometryDetElement*)detElements->GetEntry(j); - - // Det element path - TString dePath = detElement->GetVolumePath(); - - // Make physical node - TGeoPhysicalNode* deNode = tgeoManager->MakePhysicalNode(dePath); - if ( ! deNode ) { - AliErrorStream() - << "Det element id: " << detElement->GetId() - << " volume path: " << path << " not found in geometry." << endl; - return false; - } - - // Set global matrix from physical node - TGeoHMatrix globalMatrix = *deNode->GetMatrix(); - detElement->SetGlobalTransformation(globalMatrix); - - // Set local matrix - TGeoHMatrix localMatrix = - AliMUONGeometryBuilder::Multiply( - matrix.Inverse(), globalMatrix ); - detElement->SetLocalTransformation(localMatrix); - } - } - return true; -} - -//______________________________________________________________________________ -Bool_t -AliMUONGeometryTransformer::ReadVolPaths(const TString& fileName) -{ -// Reads detection element volume paths from a file -// Returns true, if reading finished correctly. -// --- - - // File path - TString filePath = gSystem->Getenv("ALICE_ROOT"); - filePath += "/MUON/data/"; - filePath += fileName; - - // Open input file - ifstream in(filePath, ios::in); - if (!in) { - cerr << filePath << endl; - AliFatal("File not found."); - return false; - } - - ReadVolPaths(in); - return true; -} - //______________________________________________________________________________ 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"); @@ -475,9 +413,9 @@ AliMUONGeometryTransformer::ReadTransformations(const TString& fileName) TString key; in >> key; while ( !in.eof() ) { - if (key == TString("CH")) + if ( key == AliMUONGeometryModuleTransformer::GetModuleNamePrefix() ) key = ReadModuleTransforms(in); - else if (key == TString("DE")) + else if ( key == AliMUONGeometryDetElement::GetDENamePrefix() ) key = ReadDetElemTransforms(in); else { AliFatal(Form("%s key not recognized", key.Data())); @@ -490,32 +428,64 @@ AliMUONGeometryTransformer::ReadTransformations(const TString& fileName) //______________________________________________________________________________ Bool_t -AliMUONGeometryTransformer::ReadTransformations2(const TString& fileName) +AliMUONGeometryTransformer::LoadTransformations() { -// Reads transformations from root geometry file -// Returns true, if reading finished correctly. -// --- +/// Load transformations for defined modules and detection elements +/// using AliGeomManager - // File path - TString filePath = gSystem->Getenv("ALICE_ROOT"); - filePath += "/MUON/data/"; - filePath += fileName; - - // Load root geometry - TGeoManager* tgeoManager = TGeoManager::Import(fileName); + if ( ! AliGeomManager::GetGeometry() ) { + AliFatal("Geometry has to be laoded in AliGeomManager first."); + return false; + } - // Retrieve matrices - LoadTransforms(tgeoManager); + for (Int_t i=0; iGetEntriesFast(); i++) { + AliMUONGeometryModuleTransformer* moduleTransformer + = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); - return true; -} + // 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; jGetSize(); 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 ( ! globalMatrix ) { + 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 { -// Writes the transformations -// --- +/// Write given transformation out << " pos: "; const Double_t* xyz = transform->GetTranslation(); @@ -538,51 +508,10 @@ void AliMUONGeometryTransformer::WriteTransform(ofstream& out, << setw(8) << setprecision(4) << a6 << " " << endl; } -//______________________________________________________________________________ -void AliMUONGeometryTransformer::WriteModuleVolPaths(ofstream& out) const -{ -// Write modules volume paths - - for (Int_t i=0; iGetEntriesFast(); i++) { - AliMUONGeometryModuleTransformer* moduleTransformer - = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); - - // Write data on out - out << "CH " - << setw(4) << moduleTransformer->GetModuleId() << " " - << moduleTransformer->GetVolumePath() << endl; - } - out << endl; -} - -//______________________________________________________________________________ -void AliMUONGeometryTransformer::WriteDetElemVolPaths(ofstream& out) const -{ -// Write detection elements volume paths - - for (Int_t i=0; iGetEntriesFast(); i++) { - AliMUONGeometryModuleTransformer* moduleTransformer - = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); - AliMUONGeometryStore* detElements - = moduleTransformer->GetDetElementStore(); - - for (Int_t j=0; jGetNofEntries(); j++) { - AliMUONGeometryDetElement* detElement - = (AliMUONGeometryDetElement*)detElements->GetEntry(j); - - // Write data on out - out << "DE " - << setw(4) << detElement->GetId() << " " - << detElement->GetVolumePath() << endl; - } - out << endl; - } -} - //______________________________________________________________________________ void AliMUONGeometryTransformer::WriteModuleTransforms(ofstream& out) const { -// Write modules transformations +/// Write module transformations for all module transformers for (Int_t i=0; iGetEntriesFast(); i++) { AliMUONGeometryModuleTransformer* moduleTransformer @@ -591,8 +520,8 @@ void AliMUONGeometryTransformer::WriteModuleTransforms(ofstream& out) const = moduleTransformer->GetTransformation(); // Write data on out - out << "CH " - << setw(4) << moduleTransformer->GetModuleId() + 1; + out << AliMUONGeometryModuleTransformer::GetModuleNamePrefix() << " " + << setw(4) << moduleTransformer->GetModuleId(); WriteTransform(out, transform); } @@ -602,23 +531,23 @@ 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; iGetEntriesFast(); i++) { AliMUONGeometryModuleTransformer* moduleTransformer = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); - AliMUONGeometryStore* detElements - = moduleTransformer->GetDetElementStore(); + AliMpExMap* detElements = moduleTransformer->GetDetElementStore(); - for (Int_t j=0; jGetNofEntries(); j++) { + for (Int_t j=0; jGetSize(); j++) { AliMUONGeometryDetElement* detElement - = (AliMUONGeometryDetElement*)detElements->GetEntry(j); + = (AliMUONGeometryDetElement*)detElements->GetObject(j); const TGeoMatrix* transform = detElement->GetLocalTransformation(); // Write data on out - out << "DE " << setw(4) << detElement->GetId(); + out << AliMUONGeometryDetElement::GetDENamePrefix() << " " + << setw(4) << detElement->GetId(); WriteTransform(out, transform); } @@ -626,110 +555,75 @@ void AliMUONGeometryTransformer::WriteDetElemTransforms(ofstream& out) const } } -// -// public functions -// - //______________________________________________________________________________ -Bool_t -AliMUONGeometryTransformer::ReadGeometryData( - const TString& volPathFileName, - const TString& transformFileName) +TString AliMUONGeometryTransformer::GetModuleSymName(Int_t moduleId) const { -/// Read geometry data from given files; -/// if transformFileName has ".root" extension, the transformations -/// are loaded from root geometry file, otherwise ASCII file -/// format is supposed - - Bool_t result1 = ReadVolPaths(volPathFileName); +/// Return the module symbolic name (use for alignment) - // Get file extension - std::string fileName = transformFileName.Data(); - std::string rootExt = fileName.substr(fileName.size()-5, fileName.size()); - Bool_t result2; - if ( rootExt != ".root" ) - result2 = ReadTransformations(transformFileName); - else - result2 = ReadTransformations2(transformFileName); - - return result1 && result2; + return "/" + fDetectorName + "/" + + AliMUONGeometryModuleTransformer::GetModuleName(moduleId); } //______________________________________________________________________________ -Bool_t -AliMUONGeometryTransformer::ReadGeometryData( - const TString& volPathFileName, - TGeoManager* tgeoManager) +TString AliMUONGeometryTransformer::GetDESymName(Int_t detElemId) const { -/// Load geometry data from root geometry using defined -/// voluem paths from file +/// Return the detection element symbolic name (used for alignment) - Bool_t result1 = ReadVolPaths(volPathFileName); + // Module Id + Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId); - Bool_t result2 = LoadTransforms(tgeoManager); - - return result1 && result2; + return GetModuleSymName(moduleId) + "/" + + AliMUONGeometryDetElement::GetDEName(detElemId); } +// +// public functions +// + //______________________________________________________________________________ Bool_t -AliMUONGeometryTransformer::WriteGeometryData( - const TString& volPathFileName, - const TString& transformFileName, - const TString& misalignFileName) const +AliMUONGeometryTransformer::LoadGeometryData(const TString& fileName) { -/// Write geometry data into given files +/// Read geometry data either from ASCII file with transformations or +/// from root geometry file (if fileName has ".root" extension) - Bool_t result1 = WriteVolumePaths(volPathFileName); - Bool_t result2 = WriteTransformations(transformFileName); - - Bool_t result3 = true; - if ( misalignFileName != "" ) - result3 = WriteMisAlignmentData(misalignFileName); + CreateModules(); + + // Get file extension + std::string fileName2 = fileName.Data(); + std::string rootExt = fileName2.substr(fileName2.size()-5, fileName2.size()); - return result1 && result2 && result3; -} - + if ( rootExt != ".root" ) + return ReadTransformations(fileName); + else { + // Load root geometry + AliGeomManager::LoadGeometry(fileName.Data()); + return LoadTransformations(); + } +} + //______________________________________________________________________________ Bool_t -AliMUONGeometryTransformer::WriteVolumePaths(const TString& fileName) const +AliMUONGeometryTransformer::LoadGeometryData() { -// Writes volume paths for modules and detection element volumes into a file -// Returns true, if writing finished correctly. -// --- +/// Load geometry data from already loaded Root geometry using AliGeomManager - // No writing - // if builder is not associated with any geometry module - if (fModuleTransformers->GetEntriesFast() == 0) return false; - - // File path - TString filePath = gSystem->Getenv("ALICE_ROOT"); - filePath += "/MUON/data/"; - filePath += fileName; - - // Open output file - ofstream out(filePath, ios::out); - if (!out) { - cerr << filePath << endl; - AliError("File not found."); + if ( ! AliGeomManager::GetGeometry() ) { + AliErrorStream() << "Geometry has not been loaded in AliGeomManager" << endl; return false; - } -#if !defined (__DECCXX) - out.setf(std::ios::fixed); -#endif - WriteModuleVolPaths(out); - WriteDetElemVolPaths(out); - - return true; + } + + CreateModules(); + + return LoadTransformations(); } //______________________________________________________________________________ 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 @@ -760,9 +654,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 @@ -795,17 +688,21 @@ AliMUONGeometryTransformer::WriteMisAlignmentData(const TString& fileName) const void AliMUONGeometryTransformer::AddModuleTransformer( AliMUONGeometryModuleTransformer* moduleTransformer) { -/// Add the geometrymodule to the array +/// Add the module transformer to the array + + // Expand the size if not sufficient + Int_t moduleId = moduleTransformer->GetModuleId(); + if ( moduleId >= fModuleTransformers->GetSize() ) + fModuleTransformers->Expand(moduleId+1); - fModuleTransformers->AddAt(moduleTransformer, - moduleTransformer->GetModuleId()); + fModuleTransformers->AddAt(moduleTransformer, moduleId); } //_____________________________________________________________________________ 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 ) @@ -818,21 +715,21 @@ void AliMUONGeometryTransformer::AddMisAlignModule(Int_t moduleId, return; } - // Get path - TString path = kTransformer->GetVolumePath(); - + // Get unique align object ID + Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::kMUON, moduleId); + // Create mis align matrix TClonesArray& refArray =*fMisAlignArray; Int_t pos = fMisAlignArray->GetEntriesFast(); - new (refArray[pos]) AliAlignObjMatrix(path.Data(), moduleId, - const_cast(matrix)); + new (refArray[pos]) AliAlignObjMatrix(GetModuleSymName(moduleId), volId, + const_cast(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 ) @@ -846,16 +743,171 @@ void AliMUONGeometryTransformer::AddMisAlignDetElement(Int_t detElemId, return; } - // Get path - TString path = kDetElement->GetVolumePath(); - + // Get unique align object ID + Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::kMUON, detElemId); + // Create mis align matrix TClonesArray& refArray =*fMisAlignArray; Int_t pos = fMisAlignArray->GetEntriesFast(); - new(refArray[pos]) AliAlignObjMatrix(path.Data(), detElemId, - const_cast(matrix)); + new(refArray[pos]) AliAlignObjMatrix(GetDESymName(detElemId), volId, + const_cast(matrix),kTRUE); +} + +//______________________________________________________________________________ +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(); + + // Loop over geometry module + for (Int_t moduleId = 0; moduleId < AliMpConstants::NofGeomModules(); ++moduleId ) { + + // Create geometry module transformer + AliMUONGeometryModuleTransformer* moduleTransformer + = new AliMUONGeometryModuleTransformer(moduleId); + AddModuleTransformer(moduleTransformer); + } + + // Loop over detection elements + AliMpDEIterator it; + for ( it.First(); ! it.IsDone(); it.Next() ) { + + Int_t detElemId = it.CurrentDEId(); + Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId); + + // Get detection element store + AliMpExMap* detElements = + GetModuleTransformer(moduleId)->GetDetElementStore(); + + // Add detection element + AliMUONGeometryDetElement* detElement + = new AliMUONGeometryDetElement(detElemId); + detElements->Add(detElemId, detElement); + } } +//_____________________________________________________________________________ +void AliMUONGeometryTransformer::AddAlignableVolumes() const +{ +/// Set symbolic names and matrices to alignable objects to TGeo + + if ( ! gGeoManager ) { + AliWarning("TGeoManager not defined."); + return; + } + + // Modules + for (Int_t i=0; iGetEntriesFast(); i++) { + AliMUONGeometryModuleTransformer* module + = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); + + // Set module symbolic name + TGeoPNEntry* pnEntry + = gGeoManager->SetAlignableEntry(GetModuleSymName(module->GetModuleId()), + module->GetVolumePath()); + if ( ! pnEntry ) { + AliErrorStream() + << "Volume path for geometry module " + << module->GetModuleId() + << " not found in geometry." << endl; + } + else { + // Set module matrix + pnEntry->SetMatrix(new TGeoHMatrix(*module->GetTransformation())); + // the matrix will be deleted via TGeoManager + } + + // Detection elements + AliMpExMap* detElements = module->GetDetElementStore(); + + for (Int_t j=0; jGetSize(); j++) { + AliMUONGeometryDetElement* detElement + = (AliMUONGeometryDetElement*)detElements->GetObject(j); + + // Set detection element symbolic name + TGeoPNEntry* pnEntry + = gGeoManager->SetAlignableEntry(GetDESymName(detElement->GetId()), + detElement->GetVolumePath()); + if ( ! pnEntry ) { + AliErrorStream() + << "Volume path for detection element " + << detElement->GetId() + << " not found in geometry." << endl; + } + else { + // Set detection element matrix + pnEntry->SetMatrix(new TGeoHMatrix(*detElement->GetGlobalTransformation())); + // the matrix will be deleted via TGeoManager + } + } + } +} + +//_____________________________________________________________________________ +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; iGetEntriesFast(); i++) { + AliMUONGeometryModuleTransformer* module + = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); + + Int_t moduleId = module->GetModuleId(); + + // Align object ID + Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::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; iGetEntriesFast(); i++) { + AliMUONGeometryModuleTransformer* moduleTransformer + = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); + AliMpExMap* detElements = moduleTransformer->GetDetElementStore(); + + for (Int_t j=0; jGetSize(); j++) { + AliMUONGeometryDetElement* detElement + = (AliMUONGeometryDetElement*)detElements->GetObject(j); + + Int_t detElemId = detElement->GetId(); + + // Align object ID + Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::kMUON, detElemId); + + // Create mis align matrix + Int_t pos = array->GetEntriesFast(); + new (refArray[pos]) AliAlignObjMatrix(GetDESymName(detElemId), volId, matrix, kTRUE); + } + } + + return array; +} + +//_____________________________________________________________________________ +void AliMUONGeometryTransformer::ClearMisAlignmentData() +{ +/// Clear the array of misalignment data + + if ( ! fMisAlignArray ) return; + + fMisAlignArray->Delete(); +} + //_____________________________________________________________________________ void AliMUONGeometryTransformer::Global2Local(Int_t detElemId, Float_t xg, Float_t yg, Float_t zg, @@ -864,7 +916,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); @@ -880,7 +932,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); @@ -922,7 +974,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); } @@ -932,10 +984,10 @@ 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); + Int_t index = AliMpDEManager::GetGeomModuleId(detElemId); return GetModuleTransformer(index, warn); } @@ -944,7 +996,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);