]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MakeMUONZeroMisAlignment.C
Create the magnetic field map in the reconstruction macros (Yuri)
[u/mrichter/AliRoot.git] / MUON / MakeMUONZeroMisAlignment.C
index e4dbe03bb3ef7d1caa40f979e2ff61902a6180ba..3ac1c37b9affc2e468b2305839f32cf965334c54 100644 (file)
-void MakeMUONZeroMisAlignment(Bool_t volpaths = false,
-                             Bool_t transforms = false, 
-                             Bool_t svmaps = false)
-// Macro for generating the geometry data files:
-// (volpath.dat, transform.dat, svmap.dat)
-// and local CDB storage with zero, residual and full misalignment
-//
-// The generated files do not replace the existing ones
-// but have different names (with extension ".out").
-//
-//  Author: I. Hrivnacova, IPN Orsay
-//
-{
-  // Initialize
-  gAlice->Init("$ALICE_ROOT/MUON/Config.C");
-  cout << "Init done " << endl;
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
 
-  // Get MUON detector
-  AliMUON* muon = (AliMUON*)gAlice->GetModule("MUON");
-  if (!muon) {
-    AliFatal("MUON detector not defined.");
-    return 0;
-  }  
+// $Id$
 
-  // Get geometry builder
-  AliMUONGeometryBuilder* builder = muon ->GetGeometryBuilder();
-  
-  if (volpaths) {
-    cout << "Generating volpath file ..." << endl;
-    builder->GetTransformer()->WriteVolumePaths("volpath.dat.out");
-  }  
+/// \ingroup macros
+/// \file MakeMUONZeroMisAlignment.C
+/// \brief Macro for generating the zero misalignment data.
+///
+/// \author: I. Hrivnacova, IPN Orsay
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
 
-  if (transforms) {
-    cout << "Generating transformation file ..." << endl;
-    builder->GetTransformer()->WriteTransformations("transform.dat.out");
-  }  
+#include "AliMUONGeometryTransformer.h"
 
-  if (svmaps) {
-    cout << "Generating svmaps file ..." << endl;
-    builder->WriteSVMaps();
-  }  
+#include "AliGeomManager.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
+#include "AliCDBId.h"
 
-  cout << "Generating zero misalignment data in  MUON/ZeroMisAlignCDB/Data..." << endl;
+#include <TSystem.h>
+#include <TError.h>
+#include <TClonesArray.h>
+#include <TString.h>
+#include <TFile.h>
+#include <Riostream.h>
+
+#endif
+
+void MakeMUONZeroMisAlignment()
+{
+  const char* macroname = "MakeMUONZeroMisAlignment.C";
+  // Activate CDB storage and load geometry from CDB
+  AliCDBManager* cdb = AliCDBManager::Instance();
+  if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
+  cdb->SetRun(0);
   
-  AliMUONGeometryMisAligner misAligner(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
-  AliMUONGeometryTransformer* newTransform 
-    = misAligner.MisAlign(builder->GetTransformer(), true);
-  TClonesArray* array = newTransform->GetMisAlignmentData();
+  AliCDBStorage* storage = 0;
+  
+  if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
+    TString Storage = gSystem->Getenv("STORAGE");
+    if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
+      Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
+      return;
+    }
+    storage = cdb->GetStorage(Storage.Data());
+    if(!storage){
+      Error(macroname,"Unable to open storage %s\n",Storage.Data());
+      return;
+    }
+    AliCDBPath path("GRP","Geometry","Data");
+    AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
+    if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
+    entry->SetOwner(0);
+    TGeoManager* geom = (TGeoManager*) entry->GetObject();
+    AliGeomManager::SetGeometry(geom);
+  }else{
+    AliGeomManager::LoadGeometry(); //load geom from default CDB storage
+  }    
+
+  AliMUONGeometryTransformer transformer;
+  transformer.LoadGeometryData();
+  TClonesArray* array = transformer.CreateZeroAlignmentData();;
 
-  if( gSystem->Getenv("TOCDB") != TString("kTRUE") ){
-    // Create a File to store the alignment data
-    TFile f("MUONzeroMisalignment.root","RECREATE");
-    if(!f) {cerr<<"cannot open file for output\n";}
-    
+  if ( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ) {
+    // Create a file to store the alignment data
+    const char* filename = "MUONZeroMisalignment.root";
+    TFile f(filename,"RECREATE");
+    if(!f.IsOpen()){
+      Error(macroname,"cannot open file for output\n");
+      return;
+    }
+    Info(macroname,"Saving alignment objects to the file %s", filename);
     f.cd();
-    f.WriteObject(array,"MUONAlignObjs ","kSingleKey");
+    f.WriteObject(array,"MUONAlignObjs","kSingleKey");
     f.Close();
-  }else{
+  } else {
     // save in CDB storage
-    const char* Storage = gSystem->Getenv("STORAGE");
-    AliCDBManager* cdbManager = AliCDBManager::Instance();
-    AliCDBStorage* storage = cdbManager->GetStorage(Storage);
     AliCDBMetaData* cdbData = new AliCDBMetaData();
     cdbData->SetResponsible("Dimuon Offline project");
     cdbData->SetComment("MUON alignment objects with zero misalignment");
     cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
-    AliCDBId id("MUON/Align/Data", 0, 9999999); 
+    AliCDBId id("MUON/Align/Data", 0, AliCDBRunRange::Infinity()); 
     storage->Put(array, id, cdbData);
   }
-  
-  delete newTransform;
 }