]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGMSSubprocessor.cxx
Reading PMT gains from an external file
[u/mrichter/AliRoot.git] / MUON / AliMUONGMSSubprocessor.cxx
index 0ac04540f2c0fe91c71112ac7d438a2d0e0279ab..8eca844f2451ae48ee525e3b8b061ed9c65f31f9 100644 (file)
@@ -28,6 +28,7 @@
 #include "AliMpConstants.h"
 
 #include "AliAlignObjMatrix.h"
+#include "AliGeomManager.h"
 #include "AliCDBMetaData.h"
 #include "AliCDBEntry.h"
 
@@ -35,6 +36,7 @@
 #include <TFile.h>
 #include <TArrayI.h>
 #include <TClonesArray.h>
+#include <TGeoManager.h>
 #include <TObjString.h>
 #include <Riostream.h>
 
 ClassImp(AliMUONGMSSubprocessor)
 /// \endcond
 
-const Int_t    AliMUONGMSSubprocessor::fgkSystem = AliPreprocessor::kDCS;
-const TString  AliMUONGMSSubprocessor::fgkDataId = "GMS";
-const TString  AliMUONGMSSubprocessor::fgkMatrixArrayName = "GMSarray";
+const Int_t AliMUONGMSSubprocessor::fgkSystem = AliPreprocessor::kDCS;
+
+//
+// static methods
+//
+
+//______________________________________________________________________________
+const TString& AliMUONGMSSubprocessor::GetDataId()
+{
+  /// The data Id
+  static const TString kDataId = "GMS";
+  return kDataId;
+}  
+  
+//______________________________________________________________________________
+const TString& AliMUONGMSSubprocessor::GetMatrixArrayName()
+{
+  /// The fixed matrix array name
+  static const TString kMatrixArrayName = "GMSarray";
+  return kMatrixArrayName;
+}  
+
+//
+// ctor, dtor
+//
 
 //______________________________________________________________________________
 AliMUONGMSSubprocessor::AliMUONGMSSubprocessor(AliMUONPreprocessor* master) 
@@ -67,9 +91,8 @@ AliMUONGMSSubprocessor::~AliMUONGMSSubprocessor()
 // private methods
 //
 
-
 //______________________________________________________________________________
-void  AliMUONGMSSubprocessor::Initialize(Int_t /*run*/, 
+Bool_t  AliMUONGMSSubprocessor::Initialize(Int_t /*run*/, 
                                          UInt_t /*startTime*/, UInt_t /*endTime*/)
 {
 /// Instantiate geometry transformer
@@ -78,6 +101,7 @@ void  AliMUONGMSSubprocessor::Initialize(Int_t /*run*/,
     fTransformer = new AliMUONGeometryTransformer();
     fTransformer->CreateModules();
   }  
+  return kTRUE;
 }                                           
 
 //______________________________________________________________________________
@@ -95,7 +119,7 @@ UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
   }  
   
   // Get array with matrices
-  TClonesArray* array = (TClonesArray*)f.Get(fgkMatrixArrayName);
+  TClonesArray* array = (TClonesArray*)f.Get(GetMatrixArrayName());
   if ( ! array ) {
     Master()->Log(Form("TClonesArray not found in file %s",fileName.Data()));
     return 2;
@@ -109,13 +133,45 @@ UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
     moduleIdToGMSIndex[i]=-1;
   }
   
+  Bool_t useGlobalDelta = kTRUE;
+  // Get geometry from OCDB
+  AliCDBEntry* geoEntry = Master()->GetGeometryFromOCDB();
+  TGeoManager *lGeometry = 0x0;
+  if (geoEntry) {
+    lGeometry = (TGeoManager*) geoEntry->GetObject();
+    if (lGeometry) {
+      // Set Geometry
+      AliGeomManager::SetGeometry(lGeometry);
+      useGlobalDelta = kFALSE;
+    }
+  }
+
+  // Second transformer to convert GMS matrices local delta-transformation into 
+  // ALICE alignment objects in the global delta convention
+  AliMUONGeometryTransformer *lTransformer = new AliMUONGeometryTransformer();
+
+  // Get mis alignment from reference run for GMS  
+  AliCDBEntry* cdbEntry = Master()->GetFromOCDB("Align", "Baseline");
+  TClonesArray* refArray = 0x0;
+  if (cdbEntry) {
+    refArray = (TClonesArray*)cdbEntry->GetObject();
+    if (lGeometry && refArray) {      
+      AliGeomManager::ApplyAlignObjsToGeom(*refArray);
+      lTransformer->LoadGeometryData();
+    }
+  }
+  
   // Convert matrices into Alice alignment objects
   for (Int_t i=0; i<array->GetEntriesFast(); i++ ) {
     TGeoHMatrix* matrix = (TGeoHMatrix*)array->At(i);
-    fTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix);
+    printf("GMS local %i at %i \n",matrix->GetUniqueID(),i);
+    matrix->Print();
+    fTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, kTRUE);
+    lTransformer->AddMisAlignModule(matrix->GetUniqueID(), *matrix, useGlobalDelta);
     moduleIdToGMSIndex[matrix->GetUniqueID()]=i;
   }
-  TObject* data = const_cast< TClonesArray*>(fTransformer->GetMisAlignmentData());
+  // Store the GMS local delta-transformation 
+  TClonesArray* data = const_cast< TClonesArray*>(fTransformer->GetMisAlignmentData());
   
   //Now we have to store the final CDB file
   Master()->Log("Storing GMS");
@@ -124,40 +180,78 @@ UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
   metaData.SetResponsible("");
   metaData.SetComment("This preprocessor fills GMS alignment objects.");
   
-  Bool_t result = Master()->Store("Align", "GMS", data, &metaData, 0, 0);
+  Bool_t result = Master()->Store("Align", "GMS", (TObject*)data, &metaData, 0, 0);
   
   // This section apply the GMS misalignments on top of the misalignments 
   // of the GMS reference run and stores the new misalignment array in the OCDB
+
+  // Reset the geoemtry.
+  if (geoEntry) {
+    lGeometry = (TGeoManager*) geoEntry->GetObject();
+  }
+
+  if (lGeometry) {
+    TGeoManager::UnlockGeometry();
+    // Set Geometry
+    AliGeomManager::SetGeometry(lGeometry);
+    useGlobalDelta = kFALSE;
+  }
+
+  AliAlignObjMatrix* refAOMat = 0x0;
+  // First we need to get a copy of the local delta-transformations
+  TClonesArray* matLocalArray = new TClonesArray("TGeoHMatrix",200);
+  if (lGeometry && refArray) {      
+    refArray->Sort(); // All Modules will be first then the DE
+    // Create new misalignment array
+    for (Int_t i=0; i<refArray->GetEntriesFast(); i++) {
+      refAOMat = (AliAlignObjMatrix*)refArray->At(i);      
+      refAOMat->Print("");
+      TGeoHMatrix* reflMat = new((*matLocalArray)[i]) TGeoHMatrix(); 
+      refAOMat->GetLocalMatrix(*reflMat);
+      printf("ref misalignment local \n");
+      reflMat->Print();
+    }
+  }
   
-  // Get mis alignment from reference run for GMS
-  AliCDBEntry* cdbEntry = Master()->GetFromOCDB("Align", "Baseline");
-  if (cdbEntry) {
-    TClonesArray* refArray = (TClonesArray*)cdbEntry->GetObject();
-    if (refArray) {
+  AliAlignObjMatrix* newAOMat = 0x0;
+  // Get the GMS global delta-transformation 
+  data = const_cast< TClonesArray*>(lTransformer->GetMisAlignmentData());
+  if (geoEntry && cdbEntry) {
+    if (lGeometry && refArray) {      
       // Create new misalignment array
-      TClonesArray* newArray = new TClonesArray("AliAlignObjMatrix", 200);
+      TClonesArray* newArray = new TClonesArray("AliAlignObjMatrix", 200);      
       for (Int_t i=0; i<refArray->GetEntriesFast(); i++) {
-        AliAlignObjMatrix* refAOMat = (AliAlignObjMatrix*)refArray->At(i);      
+        refAOMat = (AliAlignObjMatrix*)refArray->At(i);      
         TGeoHMatrix refMat;
         refAOMat->GetMatrix(refMat);
+       newAOMat = new((*newArray)[i]) AliAlignObjMatrix(*refAOMat); // Copy the reference misalignment object to the new array ...
         // Need the module containing this module or detection element
         TString sName = refAOMat->GetSymName(); //Format "/MUON/GMx" or "/MUON/GMx/DEy"
         Int_t iGM = sName.Index("GM");
         Int_t iLS = sName.Last('/');
-        if (iLS>iGM) { // This is a detection element
-          sName.Remove(iLS,sName.Sizeof());
-        }
-        sName.Remove(0,iGM+2);
-        Int_t iMod = sName.Atoi();
-        if (moduleIdToGMSIndex[iMod]>=0) {
-          TGeoHMatrix* gmsMat = (TGeoHMatrix*)array->At(moduleIdToGMSIndex[iMod]);
-          refMat.MultiplyLeft(gmsMat);
-        }
-        else {
-          Master()->Log(Form("Missing GMS entry for module %d",iMod));
-        }
-        AliAlignObjMatrix* newAOMat = new((*newArray)[i]) AliAlignObjMatrix(*refAOMat); // Copy the reference misalignment object to the new array ...
-        newAOMat->SetMatrix(refMat); // ... and set its matrix
+        if (iLS<iGM) { // This is a module
+         sName.Remove(0,iGM+2);
+         Int_t iMod = sName.Atoi();
+         if (moduleIdToGMSIndex[iMod]>=0) {
+           AliAlignObjMatrix* gmsAOMat = (AliAlignObjMatrix*)data->At(moduleIdToGMSIndex[iMod]);
+           TGeoHMatrix gmsMat;
+           gmsAOMat->GetMatrix(gmsMat);
+           printf("GMS global delta %i %i\n",iMod,moduleIdToGMSIndex[iMod]);
+           gmsMat.Print();
+           printf("ref misalignment \n");
+           refMat.Print();
+           refMat.MultiplyLeft(&gmsMat);
+           printf("new misalignment gms*ref\n");
+           refMat.Print();
+         }
+         else {            
+           Master()->Log(Form("Missing GMS entry for module %d",iMod));
+         }
+         newAOMat->SetMatrix(refMat); // ... and set its matrix        
+       }
+       else { // This is a module
+         newAOMat->SetLocalMatrix(*(TGeoHMatrix*)matLocalArray->At(i)); // ... and set its matrix
+       }
       }
       
       //Now we have also to store this CDB file
@@ -169,16 +263,22 @@ UInt_t AliMUONGMSSubprocessor::ProcessFile(const TString& fileName)
       result = result && Master()->Store("Align", "Data", newArray, &metaData, 0, 1);
     }
     else {
-      Master()->Log("Empty entry?");
+      if (!refArray)
+       Master()->Log("Empty entry?");
+      if (!lGeometry)
+       Master()->Log("Couldn't find TGeoManager in the specified CDB entry?");
     }
   }
   else {
-    Master()->Log("Could not get GMS reference misalignment from OCDB! Will not add a new MUON/Align/Data entry!");    
+    if (!geoEntry)
+      Master()->Log("Could not get Geometry from OCDB! Will not add a new MUON/Align/Data entry!");    
+    if (!cdbEntry)
+      Master()->Log("Could not get GMS reference misalignment from OCDB! Will not add a new MUON/Align/Data entry!");    
   }
   // Done with applying GMS misalignments on top of misalignment of reference run
   
   // Clear MisAlignArray in transformer
-  fTransformer->ClearMisAlignmentData();
+  fTransformer->ClearMisAlignmentData(); 
   
   return (result!=kTRUE);
 }  
@@ -195,11 +295,11 @@ UInt_t AliMUONGMSSubprocessor::Process(TMap* /*dcsAliasMap*/)
 /// Return failure (0) in case procession of some file has failed
 
   UInt_t result = 1;
-  TList* sources = Master()->GetFileSources(fgkSystem, fgkDataId);
+  TList* sources = Master()->GetFileSources(fgkSystem, GetDataId());
   TIter next(sources);
   TObjString* o(0x0);
   while ( ( o = static_cast<TObjString*>(next()) ) ) {
-    TString fileName(Master()->GetFile(fgkSystem, fgkDataId, o->GetName()));
+    TString fileName(Master()->GetFile(fgkSystem, GetDataId(), o->GetName()));
     result *= ProcessFile(fileName);
   }
   delete sources;