]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALTracker.cxx
standardizing access to AliEMCALRecParams through AliEMCALReconstructor
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTracker.cxx
index c93948387e4e15080fd4a61456ac52f35e6318eb..eea5888a210cf3d1161d741dc749754a46c12a91 100644 (file)
@@ -34,7 +34,6 @@
 
 #include <TFile.h>
 #include <TTree.h>
-#include <TMath.h>
 #include <TList.h>
 #include <TString.h>
 #include <TVector3.h>
 #include <TGeoMatrix.h>
 
 #include "AliLog.h"
-#include "AliESD.h"
+#include "AliESDEvent.h"
 #include "AliESDtrack.h"
-#include "AliKalmanTrack.h"
+#include "AliESDCaloCluster.h"
 #include "AliEMCALRecPoint.h"
 #include "AliRunLoader.h"
 #include "AliEMCALTrack.h"
 #include "AliEMCALLoader.h"
 #include "AliEMCALGeometry.h"
+#include "AliEMCALReconstructor.h"
+#include "AliEMCALRecParam.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
 
 #include "AliEMCALTracker.h"
 
 ClassImp(AliEMCALTracker)
+
 //
 //------------------------------------------------------------------------------
 //
@@ -67,7 +71,7 @@ AliEMCALTracker::AliEMCALTracker()
     fCutAlphaMin(-200.0),
     fCutAlphaMax(200.0),
     fCutAngle(100.0),
-    fMaxDist(100.0),
+    fMaxDist(10.0),
     fRho(1.0),
     fX0(1.0),
     fTracks(0),
@@ -81,6 +85,8 @@ AliEMCALTracker::AliEMCALTracker()
        // and all collections to NULL.
        // Output file name is set to a default value.
        //
+       
+       InitParameters();
 }
 //
 //------------------------------------------------------------------------------
@@ -137,8 +143,37 @@ AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
 //
 //------------------------------------------------------------------------------
 //
+void AliEMCALTracker::InitParameters()
+{
+       //
+       // Retrieve initialization parameters
+       //
+       
+  // Check if the instance of AliEMCALRecParam exists, 
+  const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
+  if(!recParam){
+    AliFatal("Reconstruction parameters for EMCAL not set!");
+  }
+  
+  fCutX =  recParam->GetTrkCutX();
+  fCutY =  recParam->GetTrkCutY();
+  fCutZ =  recParam->GetTrkCutZ();
+  fMaxDist =  recParam->GetTrkCutR();
+  fCutAngle =  recParam->GetTrkCutAngle();
+  fCutAlphaMin =  recParam->GetTrkCutAlphaMin();
+  fCutAlphaMax =  recParam->GetTrkCutAlphaMax();
+  
+}
+//
+//------------------------------------------------------------------------------
+//
 TTree* AliEMCALTracker::SearchTrueMatches()
 {
+  //Search through the list of
+  //track match candidates and clusters
+  //and look for true matches
+  //
+  //
        if (!fClusters) return 0;
        if (fClusters->IsEmpty()) return 0;
        if (!fTracks) return 0;
@@ -178,11 +213,10 @@ void AliEMCALTracker::Clear(Option_t* option)
 {
        //
        // Clearing method
-       // Clears all specified arrays and the containers themselves.
+        // Deletes all objects in arrays and the arrays themselves
        //
 
        TString opt(option);
-       Bool_t doDelete = opt.Contains("DELETE");
        Bool_t clearTracks = opt.Contains("TRACKS");
        Bool_t clearClusters = opt.Contains("CLUSTERS");
        Bool_t clearMatches = opt.Contains("MATCHES");
@@ -193,34 +227,19 @@ void AliEMCALTracker::Clear(Option_t* option)
        }
        
        if (fTracks != 0x0 && clearTracks) {
-               if (!doDelete) {
-                       fTracks->Clear();
-               }
-               else {
-                       if (!fTracks->IsEmpty()) fTracks->Delete();
-                       delete fTracks;
-                       fTracks = 0;
-               }
+          fTracks->Delete();
+          delete fTracks;
+           fTracks = 0;
        }
        if (fClusters != 0x0 && clearClusters) {
-               if (!doDelete) {
-                       fClusters->Clear();
-               }
-               else {
-                       if (!fClusters->IsEmpty()) fClusters->Delete();
-                       delete fClusters;
-                       fClusters = 0;
-               }
+          fClusters->Delete();
+          delete fClusters;
+          fClusters = 0;
        }
        if (fMatches != 0x0 && clearMatches) {
-               if (!doDelete) {
-                       fMatches->Clear();
-               }
-               else {
-                       if (!fMatches->IsEmpty()) fMatches->Delete();
-                       delete fMatches;
-                       fMatches = 0;
-               }
+          fMatches->Delete();
+          delete fMatches;
+           fMatches = 0;
        }
 }
 //
@@ -242,33 +261,34 @@ Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
                return 1;
        }
        
-       TClonesArray dummy("AliEMCALRecPoint", 10000);
-       TClonesArray *clusters = &dummy;
+       TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
        branch->SetAddress(&clusters);
-       Int_t nClusters = (Int_t)clusters->GetEntries();
        
        cTree->GetEvent(0);
+       Int_t nClusters = (Int_t)clusters->GetEntries();
        fClusters = new TObjArray(0);
        for (Int_t i = 0; i < nClusters; i++) {
                AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
                if (!cluster) continue;
-               if (cluster->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
+               if (cluster->GetClusterType() != AliESDCaloCluster::kEMCALClusterv1) continue;
                AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
                fClusters->AddLast(matchCluster);
        }
-       if (fClusters->IsEmpty()) {
-               AliError("No clusters collected");
-               return 1;
-       }
-       
-       AliInfo(Form("Collected %d clusters", fClusters->GetEntries()));
+
+       branch->SetAddress(0);
+        clusters->Delete();
+        delete clusters;
+        if (fClusters->IsEmpty())
+           AliWarning("No clusters collected");
+
+       AliInfo(Form("Collected %d clusters (RecPoints)", fClusters->GetEntries()));
 
        return 0;
 }
 //
 //------------------------------------------------------------------------------
 //
-Int_t AliEMCALTracker::LoadClusters(AliESD *esd) 
+Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd) 
 {
        //
        // Load EMCAL clusters in the form of AliESDCaloClusters,
@@ -288,23 +308,21 @@ Int_t AliEMCALTracker::LoadClusters(AliESD *esd)
        for (i = start; i < end; i++) {
                AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
                if (!cluster) continue;
-               if (cluster->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
+               if (cluster->GetClusterType() != AliESDCaloCluster::kEMCALClusterv1) continue;
                AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
                fClusters->AddLast(matchCluster);
        }
-       if (fClusters->IsEmpty()) {
-               AliError("No clusters collected");
-               return 1;
-       }
+        if (fClusters->IsEmpty())
+           AliWarning("No clusters collected");
        
-       AliInfo(Form("Collected %d clusters", fClusters->GetEntries()));
+       AliInfo(Form("Collected %d clusters from ESD", fClusters->GetEntries()));
 
        return 0;
 }
 //
 //------------------------------------------------------------------------------
 //
-Int_t AliEMCALTracker::LoadTracks(AliESD *esd)
+Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
 {
        //
        // Load ESD tracks.
@@ -346,8 +364,7 @@ Int_t AliEMCALTracker::LoadTracks(AliESD *esd)
                fTracks->AddLast(track);
        }
        if (fTracks->IsEmpty()) {
-               AliError("No tracks collected");
-               return 1;
+               AliWarning("No tracks collected");
        }
        
        AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
@@ -357,7 +374,7 @@ Int_t AliEMCALTracker::LoadTracks(AliESD *esd)
 //
 //------------------------------------------------------------------------------
 //
-Int_t AliEMCALTracker::PropagateBack(AliESD* esd)
+Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
 {
        //
        // Main operation method.
@@ -365,7 +382,10 @@ Int_t AliEMCALTracker::PropagateBack(AliESD* esd)
        // After executing match finding, stores in the same ESD object all infos
        // and releases the object for further reconstruction steps.
        //
-       
+        //
+        // Note: should always return 0=OK, because otherwise all tracking
+        // is aborted for this event
+
        if (!esd) {
                AliError("NULL ESD passed");
                return 1;
@@ -377,7 +397,6 @@ Int_t AliEMCALTracker::PropagateBack(AliESD* esd)
        Int_t okLoadClusters, nClusters;
        if (!fClusters || (fClusters && fClusters->IsEmpty())) {
                okLoadClusters = LoadClusters(esd);
-               if (okLoadClusters) return 2;
        }
        nClusters = fClusters->GetEntries();
        
@@ -394,7 +413,7 @@ Int_t AliEMCALTracker::PropagateBack(AliESD* esd)
        Int_t nMatches = CreateMatches();
        if (!nMatches) {
                AliInfo(Form("#clusters = %d -- #tracks = %d --> No good matches found.", nClusters, nTracks));
-               return 4;
+               return 0;
        }
        else {
                AliInfo(Form("#clusters = %d -- #tracks = %d --> Found %d matches.", nClusters, nTracks, nMatches));
@@ -541,7 +560,10 @@ Double_t AliEMCALTracker::CheckPair
        // check against cut on difference 'alpha - phi'
        Double_t phi = TMath::ATan2(cl->Y(), cl->X());
        phi = AngleDiff(phi, tr->GetAlpha());
-       if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
+       if (phi < fCutAlphaMin || phi > fCutAlphaMax){
+         delete tr;
+         return distance;
+       }
        
        // try to propagate to cluster radius
        // (return the 'distance' value if it fails)
@@ -559,8 +581,8 @@ Double_t AliEMCALTracker::CheckPair
                pos2[0] = cl->X();
                pos2[1] = cl->Y();
                pos2[2] = cl->Z();
-               AliKalmanTrack::MeanMaterialBudget(pos1, pos2, param);
-               rho = param[0];
+               MeanMaterialBudget(pos1, pos2, param);
+               rho = param[0]*param[4];
                x0 = param[1];
        }
        else if (fTrackCorrMode == kTrackCorrFixed) {
@@ -579,7 +601,10 @@ Double_t AliEMCALTracker::CheckPair
                if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
                for (i = 0; i < fNPropSteps; i++) {
                        r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
-                       if (!tr->PropagateTo(r, x0, rho)) return distance;
+                       if (!tr->PropagateTo(r, x0, rho)){
+                         delete tr;
+                         return distance;
+                       }
                        tr->GetXYZ(pos);
                        if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
                }
@@ -588,7 +613,10 @@ Double_t AliEMCALTracker::CheckPair
        else {
                // when no steps are used, no correction makes sense
                //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
-               if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)) return distance;
+               if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)){
+                 delete tr;
+                 return distance;
+               }
                /*
                Bool_t propOK = kFALSE;
                cout << "START" << endl;
@@ -624,6 +652,7 @@ Double_t AliEMCALTracker::CheckPair
        
        if (angle > fCutAngle) {
                //cout << "angle" << endl;
+         delete tr;
                return distance;
        }
                
@@ -631,16 +660,19 @@ Double_t AliEMCALTracker::CheckPair
        x -= cl->X();
        if (TMath::Abs(x) > fCutX) {
                //cout << "cut X" << endl;
+         delete tr;
                return distance;
        }
        y -= cl->Y();
        if (TMath::Abs(y) > fCutY) {
                //cout << "cut Y" << endl;
+         delete tr;
                return distance;
        }
        z -= cl->Z();
        if (TMath::Abs(z) > fCutZ) {
                //cout << "cut Z" << endl;
+         delete tr;
                return distance;
        }
        
@@ -688,8 +720,8 @@ Double_t AliEMCALTracker::CheckPairV2
                pos2[0] = cl->X();
                pos2[1] = cl->Y();
                pos2[2] = cl->Z();
-               AliKalmanTrack::MeanMaterialBudget(pos1, pos2, param);
-               rho = param[0];
+               MeanMaterialBudget(pos1, pos2, param);
+               rho = param[0]*param[4];
                x0 = param[1];
        }
        else if (fTrackCorrMode == kTrackCorrFixed) {
@@ -756,6 +788,7 @@ Double_t AliEMCALTracker::CheckPairV2
        TVector3 vdiff = vt-vc;
                
        // compute differences wr to each coordinate
+       delete track;
        if (vdiff.X() > fCutX) return distance;
        if (vdiff.Y() > fCutY) return distance;
        if (vdiff.Z() > fCutZ) return distance;
@@ -785,7 +818,7 @@ Double_t AliEMCALTracker::CheckPairV3
        Double_t distance = 2.0 * fMaxDist;
        Double_t dx, dy, dz;
        Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
-       Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, d, x0, rho, bz;
+       Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, x0, rho, bz;
        Double_t x[3], x1[3], x2[3];
        
        // get initial track position
@@ -807,10 +840,9 @@ Double_t AliEMCALTracker::CheckPairV3
        bz = tr.GetBz();
        if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
        //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
-       d = param[4];
-       rho = param[0];
+       rho = param[0]*param[4];
        x0 = param[1];
-       if (!tr.PropagateTo(xprop, d*rho/x0, x0)) return distance;
+       if (!tr.PropagateTo(xprop, x0, rho)) return distance;
        //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
        
        // get propagated position at the end
@@ -833,7 +865,7 @@ Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
        // Propagates the track to the proximity of the EMCAL surface
        //
        
-       Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], d, x0, rho, bz;
+       Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], x0, rho, bz;
        Double_t x1[3], x2[3];
        
        // get initial track position
@@ -846,11 +878,10 @@ Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
                tr->GetXYZ(x1);
                bz = tr->GetBz();
                if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
-               AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
-               d = param[4];
-               rho = param[0];
+               MeanMaterialBudget(x1, x2, param);
+               rho = param[0]*param[4];
                x0 = param[1];
-               if (!tr->PropagateTo(xtemp, d*rho/x0, x0)) return kFALSE;
+               if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
        }
        
        return kTRUE;
@@ -895,7 +926,7 @@ Int_t AliEMCALTracker::CreateMatches()
                                candidate->SetIndexT(it);
                                candidate->SetIndexC(ic);
                                candidate->SetDistance(dist);
-                               candidate->SetPt(track->GetPt());
+                               candidate->SetPt(track->GetSignedPt());
                                fMatches->Add(candidate);
                                count++;
                        }
@@ -1001,6 +1032,9 @@ Int_t AliEMCALTracker::SolveCompetitions()
        }
        */
        
+       delete [] usedC;
+       delete [] usedT;
+
        return count;
 }
 //
@@ -1009,10 +1043,12 @@ Int_t AliEMCALTracker::SolveCompetitions()
 void AliEMCALTracker::UnloadClusters() 
 {
        //
-       // Free memory from clusters
+       // Free memory from all arrays
+        // This method is called after the local tracking step
+        // so we can safely delete everything 
        //
        
-       Clear("CLUSTERS");
+       Clear();
 }
 //
 //------------------------------------------------------------------------------
@@ -1040,7 +1076,7 @@ AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCA
 //
 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
   : fIndex(index),
-    fLabel(caloCluster->GetPrimaryIndex()),
+    fLabel(caloCluster->GetLabel()),
     fX(0.),
     fY(0.),
     fZ(0.)
@@ -1050,7 +1086,7 @@ AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDC
        // Index of passed cluster in its native array must be specified.
        //
        Float_t clpos[3];
-       caloCluster->GetGlobalPosition(clpos);
+       caloCluster->GetPosition(clpos);
        
        fX = (Double_t)clpos[0];
        fY = (Double_t)clpos[1];