]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MFT/AliMFTClusterFinder.cxx
MFT track shift tool added
[u/mrichter/AliRoot.git] / MFT / AliMFTClusterFinder.cxx
index 11ecb667283e9f7a23d05ff31a9c86ea6c1da4fc..c56361ecdf07267463a945efd5f4df89f902c595 100644 (file)
 #include "TMath.h"
 #include "AliMFTConstants.h"
 #include "AliMFTClusterFinder.h"
+#include "TRandom.h"
 
 const Double_t AliMFTClusterFinder::fCutForAvailableDigits = AliMFTConstants::fCutForAvailableDigits;
 const Double_t AliMFTClusterFinder::fCutForAttachingDigits = AliMFTConstants::fCutForAttachingDigits;
-
+const Double_t AliMFTClusterFinder::fMisalignmentMagnitude = AliMFTConstants::fMisalignmentMagnitude;
 
 ClassImp(AliMFTClusterFinder)
 
@@ -46,7 +47,9 @@ AliMFTClusterFinder::AliMFTClusterFinder() :
   fCurrentDigit(0),
   fCurrentCluster(0),
   fSegmentation(0),
-  fNPlanes(0)
+  fNPlanes(0),
+  fApplyMisalignment(kFALSE),
+  fStopWatch(0)
 {
 
   // Default constructor
@@ -54,6 +57,8 @@ AliMFTClusterFinder::AliMFTClusterFinder() :
   for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) fClustersPerPlane[iPlane] = NULL;
   fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
   fDigitsInCluster -> SetOwner(kTRUE);
+  fStopWatch = new TStopwatch();
+  fStopWatch -> Reset();
 
 }
 
@@ -68,6 +73,8 @@ AliMFTClusterFinder::~AliMFTClusterFinder() {
   }
   if (fDigitsInCluster) fDigitsInCluster->Delete(); delete fDigitsInCluster; fDigitsInCluster = NULL;
   delete fSegmentation; fSegmentation=NULL;
+
+  delete fStopWatch;
   
   AliDebug(1, "... done!");
   
@@ -123,6 +130,9 @@ void AliMFTClusterFinder::DigitsToClusters(const TObjArray *pDigitList) {
   AliInfo("Starting Clusterization for MFT");
   AliDebug(1, Form("nPlanes = %d", fNPlanes));
 
+  if (!fStopWatch) fStopWatch = new TStopwatch();
+  fStopWatch -> Reset();
+
   StartEvent(); 
   Bool_t isDigAvailableForNewCluster = kTRUE;
   
@@ -132,25 +142,53 @@ void AliMFTClusterFinder::DigitsToClusters(const TObjArray *pDigitList) {
 
     AliDebug(1, Form("Plane %02d", iPlane));
 
+    Int_t nDetElem = fSegmentation->GetPlane(iPlane)->GetNActiveElements();
+    TClonesArray *clustersPerDetElem[fNMaxDetElemPerPlane] = {0};
+    for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) clustersPerDetElem[iDetElem] = new TClonesArray("AliMFTCluster");
+
     myDigitList = (TClonesArray*) pDigitList->At(iPlane);
 
     AliDebug(1, Form("myDigitList->GetEntries() = %d", myDigitList->GetEntries()));
 
     Int_t cycleOverDigits = 0;
-    Double_t myCutForAvailableDigits = fCutForAvailableDigits;
+    Double_t myCutForAvailableDigits = 0;
     
+    Int_t currentDetElem = -1;
+    Int_t currentDetElemLocal = -1;
+    Bool_t areThereSkippedDigits = kFALSE;
+
+    fStopWatch -> Start();
+
     while (myDigitList->GetEntries()) {
 
       for (Int_t iDig=0; iDig<myDigitList->GetEntries(); iDig++) {
 
-       AliDebug(1, Form("Check %d: Digit %5d of %5d", cycleOverDigits, iDig, myDigitList->GetEntries()));
-
        fCurrentDigit = (AliMFTDigit*) myDigitList->At(iDig);
+
+       if (!iDig) {
+         if (fCurrentDigit->GetDetElemID() != currentDetElem) {      
+           // first iteration over the digits of a specific detection element
+           currentDetElem = fCurrentDigit->GetDetElemID();
+           currentDetElemLocal = fSegmentation->GetDetElemLocalID(currentDetElem);
+           cycleOverDigits = 0;
+           myCutForAvailableDigits = fCutForAvailableDigits;
+         }
+         else if (fCurrentDigit->GetDetElemID()==currentDetElem && areThereSkippedDigits) {
+           // second (or further) iteration over the digits of a specific detection element
+           cycleOverDigits++;
+           myCutForAvailableDigits -= 0.5;
+         }
+         areThereSkippedDigits = kFALSE;
+       }
+       else {
+         areThereSkippedDigits = kTRUE;
+         if (fCurrentDigit->GetDetElemID() != currentDetElem) break;
+       }
+
        isDigAvailableForNewCluster = kTRUE;
 
-       for (Int_t iCluster=0; iCluster<fClustersPerPlane[iPlane]->GetEntries(); iCluster++) {
-         fCurrentCluster = (AliMFTCluster*) fClustersPerPlane[iPlane]->At(iCluster);
-         AliDebug(2, Form("Distance between cluster and digit = %f",fCurrentCluster->GetDistanceFromPixel(fCurrentDigit))); 
+       for (Int_t iCluster=0; iCluster<clustersPerDetElem[currentDetElemLocal]->GetEntries(); iCluster++) {
+         fCurrentCluster = (AliMFTCluster*) clustersPerDetElem[currentDetElemLocal]->At(iCluster);
          if (fCurrentCluster->GetDistanceFromPixel(fCurrentDigit) < fCutForAttachingDigits) { 
            fCurrentCluster->AddPixel(fCurrentDigit); 
            myDigitList->Remove(fCurrentDigit);
@@ -168,23 +206,49 @@ void AliMFTClusterFinder::DigitsToClusters(const TObjArray *pDigitList) {
          myDigitList->Remove(fCurrentDigit);
          myDigitList->Compress();
          iDig--;
-         new ((*fClustersPerPlane[iPlane])[fClustersPerPlane[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
-               delete newCluster;
+         new ((*clustersPerDetElem[currentDetElemLocal])[clustersPerDetElem[currentDetElemLocal]->GetEntries()]) AliMFTCluster(*newCluster);
+         delete newCluster;
        }
-
+       
       }   // end of cycle over the digits
 
-      if (cycleOverDigits) myCutForAvailableDigits -= 0.5;
-      cycleOverDigits++;
-
     }   // no more digits to check in current plane!
 
-    for (Int_t iCluster=0; iCluster<fClustersPerPlane[iPlane]->GetEntries(); iCluster++) {
-      fCurrentCluster = (AliMFTCluster*) fClustersPerPlane[iPlane]->At(iCluster);
-      fCurrentCluster -> TerminateCluster();
+    fStopWatch -> Print("m");
+
+    printf("Plane %d: clusters found in %f seconds\n",iPlane,fStopWatch->CpuTime());
+    fStopWatch->Start();
+
+    // Now we merge the cluster lists coming from each detection element, to build the cluster list of the plane
+
+    Double_t misalignmentPhi = 2.*TMath::Pi()*gRandom->Rndm();
+    Double_t misalignmentX   = fMisalignmentMagnitude*TMath::Cos(misalignmentPhi);
+    Double_t misalignmentY   = fMisalignmentMagnitude*TMath::Sin(misalignmentPhi);
+
+    AliMFTCluster *newCluster = NULL;
+    for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
+      for (Int_t iCluster=0; iCluster<clustersPerDetElem[iDetElem]->GetEntries(); iCluster++) {
+       newCluster = (AliMFTCluster*) (clustersPerDetElem[iDetElem]->At(iCluster));
+       newCluster -> TerminateCluster();
+       newCluster -> SetClusterEditable(kTRUE);
+       if (TMath::Abs(newCluster->GetZ())<TMath::Abs(fSegmentation->GetPlane(iPlane)->GetZCenter())) newCluster->SetClusterFront(kTRUE);
+       else                                                                                          newCluster->SetClusterFront(kFALSE);
+       if (fApplyMisalignment) {
+         newCluster -> SetX(newCluster->GetX()+misalignmentX);
+         newCluster -> SetY(newCluster->GetY()+misalignmentY);
+       }
+       newCluster -> SetClusterEditable(kFALSE);
+
+       new ((*fClustersPerPlane[iPlane])[fClustersPerPlane[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
+      }
     }
 
-    AliDebug(1, Form("Found %d clusters in plane %02d", fClustersPerPlane[iPlane]->GetEntries(), iPlane));
+    printf("%d Clusters in plane %02d merged in %f seconds\n", fClustersPerPlane[iPlane]->GetEntries(), iPlane, fStopWatch->CpuTime());
+
+    for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
+      clustersPerDetElem[iDetElem] -> Delete();
+      delete clustersPerDetElem[iDetElem];
+    }
 
     myDigitList -> Delete();