]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALTracker.cxx
Eliminating gsi specific lines
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTracker.cxx
index d0b459948d1c02cf557c5e91c5a7ba3e73cc074f..99ec18eb52316efdcb324839f7c2b13da0b0b86f 100644 (file)
 #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)
+
 //
 //------------------------------------------------------------------------------
 //
@@ -66,7 +71,9 @@ AliEMCALTracker::AliEMCALTracker()
     fCutAlphaMin(-200.0),
     fCutAlphaMax(200.0),
     fCutAngle(100.0),
-    fMaxDist(100.0),
+    fMaxDist(10.0),
+    fCutNITS(3.0),
+    fCutNTPC(20.0),
     fRho(1.0),
     fX0(1.0),
     fTracks(0),
@@ -80,6 +87,7 @@ AliEMCALTracker::AliEMCALTracker()
        // and all collections to NULL.
        // Output file name is set to a default value.
        //
+  InitParameters();
 }
 //
 //------------------------------------------------------------------------------
@@ -95,6 +103,8 @@ AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
     fCutAlphaMax(copy.fCutAlphaMax),
     fCutAngle(copy.fCutAngle),
     fMaxDist(copy.fMaxDist),
+    fCutNITS(copy.fCutNITS),
+    fCutNTPC(copy.fCutNTPC),
     fRho(copy.fRho),
     fX0(copy.fX0),
     fTracks((TObjArray*)copy.fTracks->Clone()),
@@ -124,6 +134,8 @@ AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
        fCutAlphaMax = copy.fCutAlphaMax;
        fCutAngle = copy.fCutAngle;
        fMaxDist = copy.fMaxDist;
+       fCutNITS = copy.fCutNITS;
+       fCutNTPC = copy.fCutNTPC;
        
        fTracks = (TObjArray*)copy.fTracks->Clone();
        fClusters = (TObjArray*)copy.fClusters->Clone();
@@ -136,8 +148,40 @@ AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
 //
 //------------------------------------------------------------------------------
 //
+void AliEMCALTracker::InitParameters()
+{
+       //
+       // Retrieve initialization parameters
+       //
+       
+  // Check if the instance of AliEMCALRecParam exists, 
+  const AliEMCALRecParam* recParam = new AliEMCALRecParam();
+
+  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();
+  fCutNITS = recParam->GetTrkCutNITS();
+  fCutNTPC = recParam->GetTrkCutNTPC();
+
+}
+//
+//------------------------------------------------------------------------------
+//
 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;
@@ -177,11 +221,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");
@@ -192,34 +235,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;
        }
 }
 //
@@ -250,20 +278,18 @@ Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
        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;
-       }
-       
+
        branch->SetAddress(0);
         clusters->Delete();
         delete clusters;
+        if (fClusters->IsEmpty())
+           AliWarning("No clusters collected");
 
-       AliInfo(Form("Collected %d clusters", fClusters->GetEntries()));
+       AliInfo(Form("Collected %d clusters (RecPoints)", fClusters->GetEntries()));
 
        return 0;
 }
@@ -280,8 +306,8 @@ Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
        // make sure that tracks/clusters collections are empty
        Clear("CLUSTERS");
        
-       Int_t start = esd->GetFirstEMCALCluster();
-       Int_t nClustersEMC = esd->GetNumberOfEMCALClusters();
+       Int_t start = 0;
+       Int_t nClustersEMC = esd->GetNumberOfCaloClusters();
        Int_t end = start + nClustersEMC;
        
        fClusters = new TObjArray(0);
@@ -290,16 +316,14 @@ Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
        for (i = start; i < end; i++) {
                AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
                if (!cluster) continue;
-               if (cluster->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
+        if (!cluster->IsEMCAL()) 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;
 }
@@ -348,8 +372,7 @@ Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
                fTracks->AddLast(track);
        }
        if (fTracks->IsEmpty()) {
-               AliError("No tracks collected");
-               return 1;
+               AliWarning("No tracks collected");
        }
        
        AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
@@ -367,7 +390,10 @@ Int_t AliEMCALTracker::PropagateBack(AliESDEvent* 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;
@@ -379,7 +405,6 @@ Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
        Int_t okLoadClusters, nClusters;
        if (!fClusters || (fClusters && fClusters->IsEmpty())) {
                okLoadClusters = LoadClusters(esd);
-               if (okLoadClusters) return 2;
        }
        nClusters = fClusters->GetEntries();
        
@@ -396,7 +421,7 @@ Int_t AliEMCALTracker::PropagateBack(AliESDEvent* 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));
@@ -423,6 +448,11 @@ Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
                trackID = track->GetSeedIndex();
                AliESDtrack *esdTrack = esd->GetTrack(trackID);
                if (!esdTrack) continue;
+
+               // cut on its and tpc track hits
+               if(esdTrack->GetNcls(0)<=fCutNITS)continue;
+               if(esdTrack->GetNcls(1)<=fCutNTPC)continue;
+
                if (TMath::Abs(esdTrack->GetLabel()) == cluster->Label()) {
                        esdTrack->SetEMCALcluster(cluster->Index());
                        nGood++;
@@ -543,7 +573,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)
@@ -581,7 +614,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;
                }
@@ -590,7 +626,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;
@@ -626,6 +665,7 @@ Double_t AliEMCALTracker::CheckPair
        
        if (angle > fCutAngle) {
                //cout << "angle" << endl;
+         delete tr;
                return distance;
        }
                
@@ -633,16 +673,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;
        }
        
@@ -758,6 +801,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;
@@ -1001,6 +1045,9 @@ Int_t AliEMCALTracker::SolveCompetitions()
        }
        */
        
+       delete [] usedC;
+       delete [] usedT;
+
        return count;
 }
 //
@@ -1009,17 +1056,19 @@ 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();
 }
 //
 //------------------------------------------------------------------------------
 //
 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
   : fIndex(index),
-    fLabel(recPoint->GetPrimaryIndex()),
+    fLabel(recPoint->GetPrimaryIndex()), //wrong!  fixed below
     fX(0.),
     fY(0.),
     fZ(0.)
@@ -1034,6 +1083,17 @@ AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCA
        fX = clpos.X();
        fY = clpos.Y();
        fZ = clpos.Z();
+
+       //AliEMCALRecPoint stores the track labels in the parents
+       //list, sorted according to the fractional contribution to the
+       //RecPoint.  The zeroth parent gave the highest contribution
+       Int_t multparent = 0;
+        Int_t *parents = recPoint->GetParents(multparent);
+        if(multparent > 0)
+          fLabel = parents[0];
+        else
+          fLabel = -1;
+
 }
 //
 //------------------------------------------------------------------------------