]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONRefitter.cxx
add pt spectra histograms for different pile-up event definition
[u/mrichter/AliRoot.git] / MUON / AliMUONRefitter.cxx
index a592a2a1bd923b734c6342e5dfc95c38498eb0ae..448769a2648e809a9a634a74e86ffc780555cc01 100644 (file)
@@ -69,7 +69,8 @@ AliMUONRefitter::AliMUONRefitter(const AliMUONRecoParam* recoParam)
   fkESDInterface(0x0),
   fGeometryTransformer(0x0),
   fClusterServer(0x0),
-  fTracker(0x0)
+  fTracker(0x0),
+  nextClusterIndex(0)
 {
   /// Default constructor
   CreateGeometryTransformer();
@@ -110,7 +111,7 @@ AliMUONVTrackStore* AliMUONRefitter::ReconstructFromDigits()
   TIter next(fkESDInterface->CreateTrackIterator());
   while ((track = static_cast<AliMUONTrack*>(next()))) {
     AliMUONTrack *newTrack = RetrackFromDigits(*track);
-    newTrackStore->Add(newTrack);
+    if (newTrack) newTrackStore->Add(newTrack);
     delete newTrack;
   }
   
@@ -216,6 +217,12 @@ AliMUONVClusterStore* AliMUONRefitter::ReClusterize(UInt_t trackId, UInt_t clust
   fClusterServer->UseDigits(next,fkESDInterface->GetDigits());
   fClusterServer->Clusterize(cluster->GetChamberId(),*clusterStore,AliMpArea(),fkRecoParam);
   
+  // set the uniqueID of the new clusters
+  TIter nextCl(clusterStore->CreateIterator());
+  AliMUONVCluster* newCluster = 0x0;
+  while ((newCluster = static_cast<AliMUONVCluster*>(nextCl())))
+    newCluster->SetUniqueID(AliMUONVCluster::BuildUniqueID(cluster->GetChamberId(), cluster->GetDetElemId(), nextClusterIndex++));
+  
   return clusterStore;
 }
 
@@ -250,6 +257,12 @@ AliMUONVClusterStore* AliMUONRefitter::ReClusterize(UInt_t clusterId)
   fClusterServer->UseDigits(next,fkESDInterface->GetDigits());
   fClusterServer->Clusterize(cluster->GetChamberId(),*clusterStore,AliMpArea(),fkRecoParam);
   
+  // set the uniqueID of the new clusters
+  TIter nextCl(clusterStore->CreateIterator());
+  AliMUONVCluster* newCluster = 0x0;
+  while ((newCluster = static_cast<AliMUONVCluster*>(nextCl())))
+    newCluster->SetUniqueID(AliMUONVCluster::BuildUniqueID(cluster->GetChamberId(), cluster->GetDetElemId(), nextClusterIndex++));
+  
   return clusterStore;
 }
 
@@ -280,7 +293,7 @@ AliMUONTrack* AliMUONRefitter::RetrackFromDigits(const AliMUONTrack& track)
   
   // check if digits exist
   UInt_t trackId = track.GetUniqueID();
-  if (fkESDInterface->GetNDigits(trackId) == 0) {
+  if (!fkESDInterface->DigitsStored(trackId)) {
     AliError(Form("no digit attached to track #%d",trackId));
     return 0x0;
   }
@@ -318,11 +331,23 @@ AliMUONTrack* AliMUONRefitter::RetrackFromDigits(const AliMUONTrack& track)
       continue;
     }
     
+    // set the uniqueID of the new clusters
+    TIter nextCl(newClusterStore->CreateIterator());
+    AliMUONVCluster* newCluster = 0x0;
+    while ((newCluster = static_cast<AliMUONVCluster*>(nextCl())))
+      newCluster->SetUniqueID(AliMUONVCluster::BuildUniqueID(cluster->GetChamberId(), cluster->GetDetElemId(), nextClusterIndex++));
+    
     // add the new cluster(s) to the tracks
-    AddClusterToTracks(*newClusterStore, *newTrackStore);
+    if (!AddClusterToTracks(*newClusterStore, *newTrackStore)) {
+      delete newClusterStore;
+      delete newTrackStore;
+      return 0x0;
+    }
     
   }
   
+  if (newTrackStore->GetSize() > 1000) AliInfo(Form("%d tracks to refit... be patient!!",newTrackStore->GetSize()));
+                                              
   // refit the tracks and pick up the best one
   AliMUONTrack *currentTrack, *bestTrack = 0x0;
   Double_t currentChi2, bestChi2 = AliMUONTrack::MaxChi2();
@@ -335,9 +360,12 @@ AliMUONTrack* AliMUONRefitter::RetrackFromDigits(const AliMUONTrack& track)
     if (param) *param = *((AliMUONTrackParam*) track.GetTrackParamAtCluster()->First());
     
     // refit the track
-    if (!fTracker->RefitTrack(*currentTrack)) break;
+    if (!fTracker->RefitTrack(*currentTrack)) continue;
     
-    // find best track (the one with the higher number of cluster or the best chi2 in case of equality)
+    // check the status of the improvement if enabled
+    if (fkRecoParam->ImproveTracks() && !currentTrack->IsImproved()) continue;
+    
+    // find best track (the one with the highest number of cluster or the best chi2 in case of equality)
     currentNCluster = currentTrack->GetNClusters();
     currentChi2 = currentTrack->GetGlobalChi2();
     if (currentNCluster > bestNClusters || (currentNCluster == bestNClusters && currentChi2 < bestChi2)) {
@@ -357,14 +385,20 @@ AliMUONTrack* AliMUONRefitter::RetrackFromDigits(const AliMUONTrack& track)
 }
 
 //_____________________________________________________________________________
-void AliMUONRefitter::AddClusterToTracks(const AliMUONVClusterStore &clusterStore, AliMUONVTrackStore &trackStore)
+Bool_t AliMUONRefitter::AddClusterToTracks(const AliMUONVClusterStore &clusterStore, AliMUONVTrackStore &trackStore)
 {
   /// add clusters to each of the given tracks
   /// duplicate the tracks if there are several clusters and add one cluster per copy
   
   // create new track store if there are more than 1 cluster to add per track
   Int_t nClusters = clusterStore.GetSize();
-  if (nClusters < 1) return;
+  if (nClusters < 1) return kTRUE;
+  
+  // check if we will exceed the maximum allowed number of tracks
+  if (nClusters * trackStore.GetSize() > fkRecoParam->GetMaxTrackCandidates()) {
+    AliError(Form("Too many track candidates (%d tracks). Stop refitting.", nClusters * trackStore.GetSize()));
+    return kFALSE;
+  }
   
   AliMUONTrackParam dummyParam;
   AliMUONTrack *currentTrack, *track;
@@ -381,7 +415,7 @@ void AliMUONRefitter::AddClusterToTracks(const AliMUONVClusterStore &clusterStor
     
     // add the new cluster(s) to the tracks
     // duplicate the tracks if there are several clusters
-    // the loop after loading the last cluster which is added to the current track
+    // stop the loop after loading the last cluster which is added to the current track
     iCluster = 0;
     TIter nextCluster(clusterStore.CreateIterator());
     while ((newCluster = static_cast<AliMUONVCluster*>(nextCluster())) && (iCluster < nClusters - 1)) {
@@ -409,5 +443,7 @@ void AliMUONRefitter::AddClusterToTracks(const AliMUONVClusterStore &clusterStor
     
   }
   
+  return kTRUE;
+  
 }