]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONAlignmentTask.cxx
In AliMUONReconstructor:
[u/mrichter/AliRoot.git] / MUON / AliMUONAlignmentTask.cxx
index a3253daac8427ba48daebb12678de6ddf7b5cdca..bbc0a99417db158e78c5273cf103922ef58c3206 100644 (file)
@@ -1,3 +1,20 @@
+/**************************************************************************
+* 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.                  *
+**************************************************************************/
+
+// $Id$
+
 //-----------------------------------------------------------------------------
 /// \class AliMUONAlignmentTask
 /// AliAnalysisTask to align the MUON spectrometer.
@@ -18,6 +35,7 @@
 #include <TChain.h>
 #include <TClonesArray.h>
 #include <TGeoGlobalMagField.h>
+#include <TGeoManager.h>
 #include <Riostream.h>
 
 #include "AliAnalysisTask.h"
@@ -27,6 +45,7 @@
 #include "AliESDMuonTrack.h"
 #include "AliMagF.h"
 #include "AliCDBManager.h"
+#include "AliGRPManager.h"
 #include "AliCDBMetaData.h"
 #include "AliCDBId.h"
 #include "AliGeomManager.h"
@@ -79,14 +98,17 @@ ClassImp(AliMUONAlignmentTask)
 // }
 
 //________________________________________________________________________
-AliMUONAlignmentTask::AliMUONAlignmentTask(const char *name, const char *geofilename) 
+AliMUONAlignmentTask::AliMUONAlignmentTask(const char *name, const char *geofilename, const char *defaultocdb, const char *misalignocdb
   : AliAnalysisTask(name, ""),
     fESD(0x0),
     fAlign(0x0),
     fGeoFilename(geofilename),
+    fMisAlignOCDB(misalignocdb),
+    fDefaultOCDB(defaultocdb),
     fTransform(0x0),
     fTrackTot(0),
     fTrackOk(0),
+    fLastRunNumber(-1),
     fMSDEx(0x0), 
     fMSDEy(0x0), 
     fMSDEz(0x0),
@@ -118,9 +140,12 @@ AliMUONAlignmentTask::AliMUONAlignmentTask(const AliMUONAlignmentTask& obj)
     fESD(0x0),
     fAlign(0x0),
     fGeoFilename(""),
+    fMisAlignOCDB(""),
+    fDefaultOCDB(""),
     fTransform(0x0),
     fTrackTot(0),
     fTrackOk(0),
+    fLastRunNumber(-1),
     fMSDEx(0x0), 
     fMSDEy(0x0), 
     fMSDEz(0x0),
@@ -134,6 +159,7 @@ AliMUONAlignmentTask::AliMUONAlignmentTask(const AliMUONAlignmentTask& obj)
   fTransform = obj.fTransform;
   fTrackTot = obj.fTrackTot;  
   fTrackOk = obj.fTrackOk;  
+  fLastRunNumber = obj.fLastRunNumber;
   fMSDEx = obj.fMSDEx; 
   fMSDEy = obj.fMSDEy; 
   fMSDEz = obj.fMSDEz;
@@ -149,9 +175,12 @@ AliMUONAlignmentTask& AliMUONAlignmentTask::operator=(const AliMUONAlignmentTask
   fESD = other.fESD;
   fAlign = other.fAlign;
   fGeoFilename = other.fGeoFilename;
+  fMisAlignOCDB = other.fMisAlignOCDB;
+  fDefaultOCDB = other.fDefaultOCDB;
   fTransform = other.fTransform;
   fTrackTot = other.fTrackTot;  
   fTrackOk = other.fTrackOk;  
+  fLastRunNumber = other.fLastRunNumber;
   fMSDEx = other.fMSDEx; 
   fMSDEy = other.fMSDEy; 
   fMSDEz = other.fMSDEz;
@@ -174,26 +203,10 @@ void AliMUONAlignmentTask::LocalInit()
 {
   /// Local initialization, called once per task on the client machine 
   /// where the analysis train is assembled
-  AliMpCDB::LoadMpSegmentation();
-
-  // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
-  if ( ! AliGeomManager::GetGeometry() ) {
-    AliGeomManager::LoadGeometry(fGeoFilename.Data());
-    if (! AliGeomManager::GetGeometry() ) {
-      Error("MUONAlignment", "getting geometry from file %s failed", fGeoFilename.Data());
-      return;
-    }
-  }
-  
-  // set  mag field 
-  // waiting for mag field in CDB 
-  if (!TGeoGlobalMagField::Instance()->GetField()) {
-    printf("Loading field map...\n");
-    AliMagF* field = new AliMagF("Maps","Maps",2,0.,0., 10.,AliMagF::k5kG);
-    TGeoGlobalMagField::Instance()->SetField(field);
-  }
-  // set the magnetic field for track extrapolations
-  AliMUONTrackExtrap::SetField();
+  fLastRunNumber = 0; 
+  //  Prepare(fGeoFilename.Data(),fDefaultOCDB.Data(),fMisAlignOCDB.Data());
+  Prepare(fGeoFilename.Data(),"local://$ALICE_ROOT/OCDB",fMisAlignOCDB.Data());
+  fLastRunNumber = -1;
 
   // Set initial values here, good guess may help convergence
   // St 1 
@@ -298,8 +311,11 @@ void AliMUONAlignmentTask::Exec(Option_t *)
   }
 
   Double_t trackParams[8] = {0.,0.,0.,0.,0.,0.,0.,0.};
-
-
+  printf("ESD RunNumber %d , fLastRunNumber %d\n",fESD->GetRunNumber(),fLastRunNumber);
+  if (fESD->GetRunNumber()!=fLastRunNumber){
+    fLastRunNumber = fESD->GetRunNumber();
+    Prepare(fGeoFilename.Data(),fDefaultOCDB.Data(),fMisAlignOCDB.Data());
+  }
  
   Int_t nTracks = Int_t(fESD->GetNumberOfMuonTracks());
   //  if (!event%100) cout << " there are " << nTracks << " tracks in event " << event << endl;
@@ -311,11 +327,16 @@ void AliMUONAlignmentTask::Exec(Option_t *)
 //     fBenMom->Fill(1./invBenMom);
     if (TMath::Abs(invBenMom)<=1.04) {
       AliMUONTrack track;
+      printf("cero\n");
       AliMUONESDInterface::ESDToMUON(*esdTrack, track);
+      printf("uno %p\n", fAlign);
       fAlign->ProcessTrack(&track);
+      printf("dos\n");
       fAlign->LocalFit(fTrackOk++,trackParams,0);
+      printf("tres\n");
     }
     fTrackTot++;
+    cout << "Processed " << fTrackTot << " Tracks." << endl;
   }
   
   // Post final data. Write histo list to a file with option "RECREATE"
@@ -323,7 +344,7 @@ void AliMUONAlignmentTask::Exec(Option_t *)
 }      
 
 //________________________________________________________________________
-void AliMUONAlignmentTask::Terminate(const Option_t*)
+void AliMUONAlignmentTask::FinishTaskOutput()
 {
   /// Called once per task on the client machine at the end of the analysis.
 
@@ -333,12 +354,12 @@ void AliMUONAlignmentTask::Terminate(const Option_t*)
 
   cout << "Done with GlobalFit " << endl;
 
-  // Update pointers reading them from the output slot
-  fList = (TList*)GetOutputData(0);
-  fMSDEx = (TGraphErrors*)fList->At(0);
-  fMSDEy = (TGraphErrors*)fList->At(1);
-  fMSDEz = (TGraphErrors*)fList->At(2);
-  fMSDEp = (TGraphErrors*)fList->At(3);
+//   // Update pointers reading them from the output slot
+//   fList = (TList*)GetOutputData(0);
+//   fMSDEx = (TGraphErrors*)fList->At(0);
+//   fMSDEy = (TGraphErrors*)fList->At(1);
+//   fMSDEz = (TGraphErrors*)fList->At(2);
+//   fMSDEp = (TGraphErrors*)fList->At(3);
 
   // Store results
   Double_t DEid[156] = {0};
@@ -389,7 +410,6 @@ void AliMUONAlignmentTask::Terminate(const Option_t*)
   // Post final data. Write histo list to a file with option "RECREATE"
   PostData(0,fList);
 
-
   // Re Align
   AliMUONGeometryTransformer *newTransform = fAlign->ReAlign(fTransform,fParameters,true); 
   newTransform->WriteTransformations("transform2ReAlign.dat");
@@ -402,7 +422,8 @@ void AliMUONAlignmentTask::Terminate(const Option_t*)
    
   // CDB manager
   AliCDBManager* cdbManager = AliCDBManager::Instance();
-  cdbManager->SetDefaultStorage("local://ReAlignCDB");
+  cdbManager->SetDefaultStorage(fDefaultOCDB.Data());
+  cdbManager->SetSpecificStorage("MUON/Align/Data",fMisAlignOCDB.Data());
   
   AliCDBMetaData* cdbData = new AliCDBMetaData();
   cdbData->SetResponsible("Dimuon Offline project");
@@ -412,3 +433,47 @@ void AliMUONAlignmentTask::Terminate(const Option_t*)
 
 }
 
+//________________________________________________________________________
+void AliMUONAlignmentTask::Terminate(const Option_t*)
+{
+  /// Called once per task on the client machine at the end of the analysis.
+
+}
+
+//-----------------------------------------------------------------------
+void AliMUONAlignmentTask::Prepare(const char* geoFilename, const char* defaultOCDB, const char* misAlignOCDB)
+{
+  /// Set the geometry, the magnetic field, the mapping and the reconstruction parameters
+      
+  // Load mapping
+  AliCDBManager* man = AliCDBManager::Instance();
+  man->SetDefaultStorage(defaultOCDB);
+  man->SetSpecificStorage("MUON/Align/Data",misAlignOCDB);
+  man->Print();
+  man->SetRun(fLastRunNumber);
+  if ( ! AliMpCDB::LoadDDLStore() ) {
+    Error("MUONRefit","Could not access mapping from OCDB !");
+    exit(-1);
+  }
+
+  // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
+  if (!gGeoManager) {
+    AliGeomManager::LoadGeometry(geoFilename);
+    if (!gGeoManager) {
+      Error("AliMUONReAlignTask", "getting geometry from file %s failed", "generated/galice.root");
+      return;
+    }
+  }
+
+  // set mag field
+  if (!TGeoGlobalMagField::Instance()->GetField()) {
+    printf("Loading field map...\n");
+    AliGRPManager *grpMan = new AliGRPManager();
+    grpMan->ReadGRPEntry();
+    grpMan->SetMagField();
+    delete grpMan;
+  }
+  // set the magnetic field for track extrapolations
+  AliMUONTrackExtrap::SetField();
+  
+}