]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDclusterizerV1.cxx
Split DAQ DA into two tasks
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizerV1.cxx
index c7d1e2fb0a9fd56449cabfc391789909a07fa159..9c91861400c20666eeac91512ae2f2eb76c5f814 100644 (file)
@@ -31,6 +31,7 @@
 #include "AliLoader.h"
 #include "AliRawReader.h"
 #include "AliLog.h"
+#include "AliAlignObj.h"
 
 #include "AliTRDclusterizerV1.h"
 #include "AliTRDgeometry.h"
 #include "AliTRDcalibDB.h"
 #include "AliTRDSimParam.h"
 #include "AliTRDRecParam.h"
-#include "AliTRDCommonParam.h"
 #include "AliTRDcluster.h"
 
+#include "Cal/AliTRDCalROC.h"
+#include "Cal/AliTRDCalDet.h"
+
 ClassImp(AliTRDclusterizerV1)
 
 //_____________________________________________________________________________
@@ -143,6 +146,18 @@ Bool_t AliTRDclusterizerV1::ReadDigits()
 
 }
 
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizerV1::ReadDigits(TTree *digitsTree)
+{
+  //
+  // Reads the digits arrays from the input tree
+  //
+
+  // Read in the digit arrays
+  return (fDigitsManager->ReadDigits(digitsTree));
+
+}
+
 //_____________________________________________________________________________
 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader *rawReader)
 {
@@ -175,12 +190,11 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
   AliTRDdataArrayI *digitsIn;
   AliTRDdataArrayI *tracksIn;
 
-  // Get the geometry
-  AliTRDgeometry *geo            = AliTRDgeometry::GetGeometry(fRunLoader);  
+  AliTRDgeometry geo;
 
   AliTRDcalibDB  *calibration    = AliTRDcalibDB::Instance();
   if (!calibration) {
-    AliError("No AliTRDcalibDB instance available\n");
+    AliFatal("No AliTRDcalibDB instance available\n");
     return kFALSE;  
   }
   
@@ -195,20 +209,19 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
     AliError("No AliTRDRecParam instance available\n");
     return kFALSE;  
   }
-  
-  AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
-  if (!commonParam) {
-    AliError("Could not get common parameters\n");
-    return kFALSE;
-  }
 
-  // ADC threshols
+  // ADC thresholds
   Float_t ADCthreshold   = simParam->GetADCthreshold();
   // Threshold value for the maximum
   Float_t maxThresh      = recParam->GetClusMaxThresh();
   // Threshold value for the digit signal
   Float_t sigThresh      = recParam->GetClusSigThresh();
 
+  // Detector wise calibration object for t0
+  const AliTRDCalDet *calT0Det         = calibration->GetT0Det();
+  // Detector wise calibration object for the gain factors
+  const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
+
   // Iteration limit for unfolding procedure
   const Float_t kEpsilon = 0.01;             
   const Int_t   kNclus   = 3;  
@@ -216,7 +229,6 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
   const Int_t   kNdict   = AliTRDdigitsManager::kNDict;
   const Int_t   kNtrack  = kNdict * kNclus;
 
-  Int_t    iType         = 0;
   Int_t    iUnfold       = 0;  
   Double_t ratioLeft     = 1.0;
   Double_t ratioRight    = 1.0;
@@ -235,8 +247,6 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
   Int_t    sectEnd    = AliTRDgeometry::Nsect();
   Int_t    nTimeTotal = calibration->GetNumberOfTimeBins();
 
-  Int_t    dummy[9]   = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
   AliDebug(1,Form("Number of Time Bins = %d.\n",nTimeTotal));
 
   // Start clustering in every chamber
@@ -244,7 +254,10 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
     for (iplan = planBeg; iplan < planEnd; iplan++) {
       for (isect = sectBeg; isect < sectEnd; isect++) {
 
-        Int_t idet = geo->GetDetector(iplan,icham,isect);
+        Int_t    idet    = geo.GetDetector(iplan,icham,isect);
+        Int_t    ilayer  = AliGeomManager::kTRD1 + iplan;
+        Int_t    imodule = icham + chamEnd * isect;
+        UShort_t volid   = AliGeomManager::LayerToVolUID(ilayer,imodule); 
 
         // Get the digits
         digitsIn = fDigitsManager->GetDigits(idet);
@@ -256,23 +269,32 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
         AliTRDdataArrayI *tracksTmp = fDigitsManager->GetDictionary(idet,0);
         tracksTmp->Expand();
 
-       Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
-       Int_t nColMax = commonParam->GetColMax(iplan);
+       Int_t nRowMax = geo.GetRowMax(iplan,icham,isect);
+       Int_t nColMax = geo.GetColMax(iplan);
+
+        AliTRDpadPlane *padPlane = geo.GetPadPlane(iplan,icham);
 
-        AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
+       // Calibration object with pad wise values for t0
+        AliTRDCalROC *calT0ROC              = calibration->GetT0ROC(idet);
+       // Calibration object with pad wise values for the gain factors
+        AliTRDCalROC *calGainFactorROC      = calibration->GetGainFactorROC(idet);
+        // Calibration value for chamber wise t0
+        Float_t       calT0DetValue         = calT0Det->GetValue(idet);
+        // Calibration value for chamber wise gain factor
+        Float_t       calGainFactorDetValue = calGainFactorDet->GetValue(idet);
 
         Int_t nClusters      = 0;
-        Int_t nClusters2pad  = 0;
-        Int_t nClusters3pad  = 0;
-        Int_t nClusters4pad  = 0;
-        Int_t nClusters5pad  = 0;
-        Int_t nClustersLarge = 0;
 
        // Apply the gain and the tail cancelation via digital filter
         AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
                                                           ,digitsIn->GetNcol()
-                                                          ,digitsIn->GetNtime());
-        Transform(digitsIn,digitsOut,idet,nRowMax,nColMax,nTimeTotal,ADCthreshold);
+                                                          ,digitsIn->GetNtime()); 
+        Transform(digitsIn
+                 ,digitsOut
+                 ,nRowMax,nColMax,nTimeTotal
+                 ,ADCthreshold
+                 ,calGainFactorROC
+                 ,calGainFactorDetValue);
 
        // Input digits are not needed any more
         digitsIn->Compress(1,0);
@@ -282,20 +304,23 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
          for ( col = 2;  col <  nColMax;    col++) {
             for (time = 0; time < nTimeTotal; time++) {
 
-              Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col  ,time));
               Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
-              Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
  
              // Look for the maximum
               if (signalM >= maxThresh) {
+
+                Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col  ,time));
+                Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
+
                 if ((TMath::Abs(signalL) <= signalM) && 
-                    (TMath::Abs(signalR) <= signalM)) {
+                    (TMath::Abs(signalR) <  signalM)) {
                  if ((TMath::Abs(signalL) >= sigThresh) ||
                      (TMath::Abs(signalR) >= sigThresh)) {
                     // Maximum found, mark the position by a negative signal
                     digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
                  }
                }
+
              }
 
             }
@@ -340,28 +365,6 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
                   if (col+ii+1 >= nColMax) break;
                }
                 nClusters++;
-                switch (nPadCount) {
-                case 2:
-                  iType = 0;
-                  nClusters2pad++;
-                  break;
-                case 3:
-                  iType = 1;
-                  nClusters3pad++;
-                  break;
-                case 4:
-                  iType = 2;
-                  nClusters4pad++;
-                  break;
-                case 5:
-                  iType = 3;
-                  nClusters5pad++;
-                  break;
-                default:
-                  iType = 4;
-                  nClustersLarge++;
-                  break;
-               };
 
                // Look for 5 pad cluster with minimum in the middle
                 Bool_t fivePadCluster = kFALSE;
@@ -386,7 +389,6 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
                // of the cluster which remains from a previous unfolding
                 if (iUnfold) {
                   clusterSignal[0] *= ratioLeft;
-                  iType   = 5;
                   iUnfold = 0;
                }
 
@@ -402,7 +404,6 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
                   ratioRight        = Unfold(kEpsilon,iplan,padSignal);
                   ratioLeft         = 1.0 - ratioRight; 
                   clusterSignal[2] *= ratioRight;
-                  iType   = 5;
                   iUnfold = 1;
                 }
 
@@ -452,30 +453,20 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
                 // Calculate the position and the error
                //              
 
-                // Correct for t0
-               Int_t    clusterTimeBin = TMath::Nint(time - calibration->GetT0(idet,col,row));
+                // Correct for t0 (sum of chamber and pad wise values !!!)
+                Float_t  calT0ROCValue  = calT0ROC->GetValue(col,row);
+               Char_t   clusterTimeBin = ((Char_t) TMath::Nint(time - (calT0DetValue + calT0ROCValue)));
                 Double_t colSize        = padPlane->GetColSize(col);
                 Double_t rowSize        = padPlane->GetRowSize(row);
 
-                Double_t clusterPos[3];
+                Float_t clusterPos[3];
                clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1] + 0.5) * colSize;
                clusterPos[1] = padPlane->GetRowPos(row) - 0.5                    * rowSize;
                 clusterPos[2] = CalcXposFromTimebin(clusterPads[2],idet,col,row);
-                Double_t clusterSig[2];
+                Float_t clusterSig[2];
                 clusterSig[0] = (clusterSigmaY2 + 1.0/12.0) * colSize*colSize;
                 clusterSig[1] = rowSize * rowSize / 12.0;                                       
-                
-                // Add the cluster to the output array
-               // The track indices will be stored later 
-                AliTRDcluster *cluster = AddCluster(clusterPos
-                                                   ,clusterTimeBin
-                                                   ,idet
-                                                  ,clusterCharge
-                                                  ,dummy
-                                                  ,clusterSig
-                                                  ,iType
-                                                   ,clusterPads[1]);
-
+               
                // Store the amplitudes of the pads in the cluster for later analysis
                Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
                for (Int_t jPad = col-3; jPad <= col+3; jPad++) {
@@ -485,13 +476,26 @@ Bool_t AliTRDclusterizerV1::MakeClusters()
                  }
                  signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
                }
-               cluster->SetSignals(signals);
 
+                // Add the cluster to the output array
+               // The track indices will be stored later 
+                AliTRDcluster *cluster = new AliTRDcluster(idet
+                                                          ,clusterCharge
+                                                          ,clusterPos
+                                                          ,clusterSig
+                                                          ,0x0
+                                                         ,((Char_t) nPadCount)
+                                                          ,signals
+                                                         ,((UChar_t) col)
+                                                          ,clusterTimeBin
+                                                          ,clusterPads[1]
+                                                          ,volid);
                // Temporarily store the row, column and time bin of the center pad
                // Used to later on assign the track indices
                 cluster->SetLabel( row,0);
                 cluster->SetLabel( col,1);
                 cluster->SetLabel(time,2);
+                RecPoints()->Add(cluster);
 
                // Store the index of the first cluster in the current ROC
                 if (firstClusterROC < 0) {
@@ -654,9 +658,10 @@ Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t *padSig
 //_____________________________________________________________________________
 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
                                  , AliTRDdataArrayF *digitsOut
-                                 , Int_t idet, Int_t nRowMax
-                                 , Int_t nColMax, Int_t nTimeTotal
-                                 , Float_t ADCthreshold)
+                                 , Int_t nRowMax, Int_t nColMax, Int_t nTimeTotal
+                                 , Float_t ADCthreshold
+                                 , AliTRDCalROC *calGainFactorROC
+                                 , Float_t calGainFactorDetValue)
 {
   //
   // Apply gain factor
@@ -672,30 +677,22 @@ void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
     AliError("No AliTRDRecParam instance available\n");
     return;
   }
-  AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
-  if (!calibration) {
-    AliError("No AliTRDcalibDB instance available\n");
-    return;  
-  }
 
   Double_t *inADC  = new Double_t[nTimeTotal];  // ADC data before tail cancellation
   Double_t *outADC = new Double_t[nTimeTotal];  // ADC data after tail cancellation
 
-  AliDebug(1,Form("Tail cancellation (nExp = %d) for detector %d.\n"
-                ,recParam->GetTCnexp(),idet));
-
   for (iRow  = 0; iRow  <  nRowMax;   iRow++ ) {
     for (iCol  = 0; iCol  <  nColMax;   iCol++ ) {
 
+      Float_t  calGainFactorROCValue = calGainFactorROC->GetValue(iCol,iRow);
+      Double_t gain                  = calGainFactorDetValue 
+                                     * calGainFactorROCValue;
+
       for (iTime = 0; iTime < nTimeTotal; iTime++) {
 
        //
        // Add gain
        //
-       Double_t gain = calibration->GetGainFactor(idet,iCol,iRow);
-       if (gain == 0.0) {
-         AliError("Not a valid gain\n");
-       }
        inADC[iTime]   = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
         inADC[iTime]  /= gain;
         outADC[iTime]  = inADC[iTime];