]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MUONAlignment.C
Fixes for #86059: Install data when ALICE_ROOT does not point to source (Christian)
[u/mrichter/AliRoot.git] / MUON / MUONAlignment.C
index 250ec5cb78bd63f1587b46d5f3e31c91114a726f..862b4f7e5105d8c83623ec91506300ae86f892c5 100644 (file)
 
 /* $Id$ */
 
-// ---
-// Macro for MUON alignment using physics tracks. The macro uses AliMUONAlignment
-// class to calculate the alignment parameters.
-// An array for the alignment parameters is created and can be filled with
-// initial values that will be used as starting values by the alignment
-// algorithm.
-// Ny default the macro run over galice.root in the working directory. If a file list
-// of galice.root is provided as third argument the macro will run over all files.
-// The macro loop over the files, events and tracks. For each track
-// AliMUONAlignment::ProcessTrack(AliMUONTrack * track) and then
-// AliMUONAlignment::LocalFit(Int_t iTrack, Double_t *lTrackParam, Int_t
-// lSingleFit) are called. After all tracks have been procesed and fitted
-// AliMUONAlignment::GlobalFit(Double_t *parameters,Double_t *errors,Double_t *pulls)
-// is called. The array parameters contains the obatained misalignement parameters.
-// A realigned geometry is generated in a local CDB.
-//
-// Authors: B. Becker and J. Castillo
-// ---
+/// \ingroup macros
+/// \file MUONAlignment.C
+/// \brief Macro for MUON alignment using physics tracks. 
+///
+/// The macro uses the AliMUONAlignment class to calculate the alignment parameters.
+/// An array for the alignment parameters is created and can be filled with
+/// initial values that will be used as starting values by the alignment
+/// algorithm.
+///
+/// By default the macro run over galice.root in the working directory. If a file list
+/// of galice.root is provided as third argument the macro will run over all files.
+/// The macro loop over the files, events and tracks. For each track
+/// AliMUONAlignment::ProcessTrack(AliMUONTrack * track) and then
+/// AliMUONAlignment::LocalFit(Int_t iTrack, Double_t *lTrackParam, Int_t
+/// lSingleFit) are called. After all tracks have been procesed and fitted
+/// AliMUONAlignment::GlobalFit(Double_t *parameters,Double_t *errors,Double_t *pulls)
+/// is called. The array parameters contains the obatained misalignement parameters.
+/// A realigned geometry is generated in a local CDB.
+///
+/// \author: B. Becker and J. Castillo
 
 #if !defined(__CINT__) || defined(__MAKECINT__)
 
 #include "AliMUONAlignment.h"
 #include "AliMUONTrack.h"
-#include "AliMUONTrackExtrap.h"
+#include "AliMUONRecoParam.h"
 #include "AliMUONTrackParam.h"
 #include "AliMUONGeometryTransformer.h"
-#include "AliMUONDataInterface.h"
-#include "AliMUONVTrackStore.h"
+#include "AliMUONESDInterface.h"
+#include "AliMUONCDB.h"
 
-#include "AliMagFMaps.h"
-#include "AliTracker.h"
+#include "AliESDEvent.h"
+#include "AliESDMuonTrack.h"
 #include "AliCDBManager.h"
 #include "AliCDBMetaData.h"
 #include "AliCDBId.h"
@@ -56,6 +58,7 @@
 #include <TH1.h>
 #include <TGraphErrors.h>
 #include <TFile.h>
+#include <TTree.h>
 #include <TClonesArray.h>
 #include <Riostream.h>
 
@@ -63,7 +66,7 @@
 
 #endif
 
-void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root", TString fileName = "galice.root", TString fileList = "")
+void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root", TString esdFileName = "AliESDs.root", TString fileList = "")
 {
  
   // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
@@ -75,18 +78,21 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
     }
   }
   
-  // set  mag field 
-  // waiting for mag field in CDB 
-  printf("Loading field map...\n");
-  AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
-  AliTracker::SetFieldMap(field, kFALSE);
-  // set the magnetic field for track extrapolations
-  AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
-
-  Double_t parameters[3*156];
-  Double_t errors[3*156];
-  Double_t pulls[3*156];
-  for(Int_t k=0;k<3*156;k++) {
+  // load necessary data from OCDB
+  AliCDBManager* cdbManager = AliCDBManager::Instance();
+  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  cdbManager->SetRun(0);
+  if (!AliMUONCDB::LoadField()) return;
+  AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
+  if (!recoParam) return;
+  
+  // reset tracker for restoring initial track parameters at cluster
+  AliMUONESDInterface::ResetTracker(recoParam);
+
+  Double_t parameters[4*156];
+  Double_t errors[4*156];
+  Double_t pulls[4*156];
+  for(Int_t k=0;k<4*156;k++) {
     parameters[k]=0.;
     errors[k]=0.;
     pulls[k]=0.;
@@ -126,26 +132,36 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
   
   // Set tracking station to use
   Bool_t bStOnOff[5] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
+  Bool_t bChOnOff[10] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
+
+  // Set degrees of freedom to align (see AliMUONAlignment)
+  alig->AllowVariations(bChOnOff);
 
   // Fix parameters or add constraints here
-  for (Int_t iSt=0; iSt<5; iSt++)
-    if (!bStOnOff[iSt]) alig->FixStation(iSt+1);
+//   for (Int_t iSt=0; iSt<5; iSt++)
+//     if (!bStOnOff[iSt]) alig->FixStation(iSt+1);
+  for (Int_t iCh=0; iCh<10; iCh++)
+    if (!bChOnOff[iCh]) alig->FixChamber(iCh+1);
 
   // Left and right sides of the detector are independent, one can choose to align 
   // only one side
   Bool_t bSpecLROnOff[2] = {kTRUE,kTRUE};
-  alig->FixHalfSpectrometer(bStOnOff,bSpecLROnOff);
+  alig->FixHalfSpectrometer(bChOnOff,bSpecLROnOff);
+
+  alig->SetChOnOff(bChOnOff);
+  alig->SetSpecLROnOff(bChOnOff);
+
+  // Here we can fix some detection elements
+  alig->FixDetElem(908);
+  alig->FixDetElem(1020);
 
   // Set predifined global constrains: X, Y, P, XvsZ, YvsZ, PvsZ, XvsY, YvsY, PvsY
   Bool_t bVarXYT[9] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
   Bool_t bDetTLBR[4] = {kFALSE,kTRUE,kFALSE,kTRUE};
-  alig->AddConstraints(bStOnOff,bVarXYT,bDetTLBR,bSpecLROnOff);
+  //  alig->AddConstraints(bChOnOff,bVarXYT,bDetTLBR,bSpecLROnOff);
 
 
   char cFileName[100];  
-  AliMUONDataInterface *amdi =0x0;
-  AliMUONVTrackStore *trackStore =0x0;
-  AliMUONTrack* track =0x0;  
     
   Int_t lMaxFile = 1000;
   Int_t iFile = 0;
@@ -161,16 +177,28 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
       if (sFileList.eof()) bKeepLoop = kFALSE;
     }
     else {
-      sprintf(cFileName,fileName.Data());
+      sprintf(cFileName,esdFileName.Data());
       bKeepLoop = kFALSE;
     }
-    if (!strstr(cFileName,"galice.root")) continue;      
+    if (!strstr(cFileName,"AliESDs")) continue;      
     cout << "Using file: " << cFileName << endl;
+    
+    // load ESD event
+    TFile* esdFile = TFile::Open(cFileName); // open the file
+    if (!esdFile || !esdFile->IsOpen()) {
+      cout << "opening ESD file " << cFileName << "failed" << endl;
+      continue;
+    }
+    TTree* esdTree = (TTree*) esdFile->Get("esdTree"); // get the tree
+    if (!esdTree) {
+      cout << "no ESD tree found" << endl;
+      esdFile->Close();
+      continue;
+    }
+    AliESDEvent* esdEvent = new AliESDEvent(); // link ESD event to the tree
+    esdEvent->ReadFromTree(esdTree);
 
-    if (!amdi) amdi = new AliMUONDataInterface(cFileName);
-    else amdi->Open(cFileName);
-
-    Int_t nevents = amdi->NumberOfEvents();
+    Int_t nevents = esdTree->GetEntries();
     cout << "... with " << nevents << endl;
     for(Int_t event = 0; event < nevents; event++) {
       if (iEvent >= nEvents){
@@ -179,25 +207,30 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
       }
       iEvent++;
 
-      trackStore = amdi->TrackStore(event);
+      if (esdTree->GetEvent(event) <= 0) {
+       cout << "fails to read ESD object for event " << event << endl;
+       continue;
+      }
 
-      Int_t ntracks = trackStore->GetSize();
-      if (!event%100)
-       cout << " there are " << ntracks << " tracks in event " << event << endl;
-      TIter next(trackStore->CreateIterator());
-      while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
-       AliMUONTrackParam trackParam(*((AliMUONTrackParam*)(track->GetTrackParamAtCluster()->First())));
-       AliMUONTrackExtrap::ExtrapToVertex(&trackParam,0.,0.,0.,0.,0.);
-       Double_t invBenMom = trackParam.GetInverseBendingMomentum();
+      Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks());
+      if (!event%100) cout << " there are " << nTracks << " tracks in event " << event << endl;
+      for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
+       AliESDMuonTrack* esdTrack = esdEvent->GetMuonTrack(iTrack);
+       if (!esdTrack->ClustersStored()) continue;
+       Double_t invBenMom = esdTrack->GetInverseBendingMomentum();
        fInvBenMom->Fill(invBenMom);
        fBenMom->Fill(1./invBenMom);
        if (TMath::Abs(invBenMom)<=1.04) {
-         alig->ProcessTrack(track);
+         AliMUONTrack track;
+         AliMUONESDInterface::ESDToMUON(*esdTrack, track);
+         alig->ProcessTrack(&track);
          alig->LocalFit(iTrackOk++,trackParams,0);
        }
        iTrackTot++;
       }
     }
+    delete esdEvent;
+    esdFile->Close();
     cout << "Processed " << iTrackTot << " Tracks so far." << endl;
   }
   alig->GlobalFit(parameters,errors,pulls);
@@ -208,13 +241,13 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
   Double_t DEid[156] = {0};
   Double_t MSDEx[156] = {0};
   Double_t MSDEy[156] = {0};
-  Double_t MSDExt[156] = {0};
-  Double_t MSDEyt[156] = {0};
+  Double_t MSDEz[156] = {0};
+  Double_t MSDEp[156] = {0};
   Double_t DEidErr[156] = {0};
   Double_t MSDExErr[156] = {0};
   Double_t MSDEyErr[156] = {0};
-  Double_t MSDExtErr[156] = {0};
-  Double_t MSDEytErr[156] = {0};
+  Double_t MSDEzErr[156] = {0};
+  Double_t MSDEpErr[156] = {0};
   Int_t lNDetElem = 4*2+4*2+18*2+26*2+26*2;
   Int_t lNDetElemCh[10] = {4,4,4,4,18,18,26,26,26,26};
   // Int_t lSNDetElemCh[10] = {4,8,12,16,34,52,78,104,130,156};
@@ -232,22 +265,22 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
        DEid[iDE] -= lNDetElemCh[iCh];
       }
     }
-    MSDEx[iDE]=parameters[3*iDE+0];
-    MSDEy[iDE]=parameters[3*iDE+1];
-    MSDExt[iDE]=parameters[3*iDE+2];
-    MSDEyt[iDE]=parameters[3*iDE+2];
-    MSDExErr[iDE]=(Double_t)alig->GetParError(3*iDE+0);
-    MSDEyErr[iDE]=(Double_t)alig->GetParError(3*iDE+1);
-    MSDExtErr[iDE]=(Double_t)alig->GetParError(3*iDE+2);
-    MSDEytErr[iDE]=(Double_t)alig->GetParError(3*iDE+2);
+    MSDEx[iDE]=parameters[4*iDE+0];
+    MSDEy[iDE]=parameters[4*iDE+1];
+    MSDEz[iDE]=parameters[4*iDE+3];
+    MSDEp[iDE]=parameters[4*iDE+2];
+    MSDExErr[iDE]=(Double_t)alig->GetParError(4*iDE+0);
+    MSDEyErr[iDE]=(Double_t)alig->GetParError(4*iDE+1);
+    MSDEzErr[iDE]=(Double_t)alig->GetParError(4*iDE+3);
+    MSDEpErr[iDE]=(Double_t)alig->GetParError(4*iDE+2);
   }
 
   cout << "Let's create graphs ...  " << endl;
 
   TGraphErrors *gMSDEx = new TGraphErrors(lNDetElem,DEid,MSDEx,DEidErr,MSDExErr); 
   TGraphErrors *gMSDEy = new TGraphErrors(lNDetElem,DEid,MSDEy,DEidErr,MSDEyErr); 
-  TGraphErrors *gMSDExt = new TGraphErrors(lNDetElem,DEid,MSDExt,DEidErr,MSDExtErr); 
-  TGraphErrors *gMSDEyt = new TGraphErrors(lNDetElem,DEid,MSDEyt,DEidErr,MSDEytErr); 
+  TGraphErrors *gMSDEz = new TGraphErrors(lNDetElem,DEid,MSDEz,DEidErr,MSDEzErr); 
+  TGraphErrors *gMSDEp = new TGraphErrors(lNDetElem,DEid,MSDEp,DEidErr,MSDEpErr); 
 
   cout << "... graphs created, open file ...  " << endl;
 
@@ -257,8 +290,8 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
 
   gMSDEx->Write("gMSDEx");
   gMSDEy->Write("gMSDEy");
-  gMSDExt->Write("gMSDExt");
-  gMSDEyt->Write("gMSDEyt");
+  gMSDEz->Write("gMSDEz");
+  gMSDEp->Write("gMSDEp");
   fInvBenMom->Write();
   fBenMom->Write();
   hFile->Close();
@@ -270,15 +303,17 @@ void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root",
   
   // Generate realigned data in local cdb
   const TClonesArray* array = newTransform->GetMisAlignmentData();
-   
-  // CDB manager
-  AliCDBManager* cdbManager = AliCDBManager::Instance();
-  cdbManager->SetDefaultStorage("local://ReAlignCDB");
+
+  // 100 mum residual resolution for chamber misalignments?
+  alig->SetAlignmentResolution(array,-1,0.01,0.01,0.004,0.003);
+
+  cdbManager->SetSpecificStorage("MUON/Align/Data","local://ReAlignCDB");
   
   AliCDBMetaData* cdbData = new AliCDBMetaData();
   cdbData->SetResponsible("Dimuon Offline project");
   cdbData->SetComment("MUON alignment objects with residual misalignment");
-  AliCDBId id("MUON/Align/Data", 0, 0); 
+  AliCDBId id("MUON/Align/Data", 0, AliCDBRunRange::Infinity()); 
   cdbManager->Put(const_cast<TClonesArray*>(array), id, cdbData);
 
-} 
+}
+