]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSClusterFinderV2SPD.cxx
Stupid bug fix in new superlight mode (from Zurich airport)
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SPD.cxx
index 3fe8cb9941f2b7f771f754db2bb8bec0473fa780..135e11574fcfbccea40911d2bfea591c887a2558 100644 (file)
 //            Implementation of the ITS clusterer V2 class                //
 //                                                                        //
 //          Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch            //
+//          Unfolding switch from AliITSRecoParam: D. Elia, INFN Bari     //
 //                                                                        //
-///////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////
 
 
+#include <TGeoGlobalMagField.h>
+#include "AliITSCalibrationSPD.h"
 #include "AliITSClusterFinderV2SPD.h"
 #include "AliITSRecPoint.h"
 #include "AliITSgeomTGeo.h"
 #include "AliITSDetTypeRec.h"
+#include "AliITSReconstructor.h"
 #include "AliRawReader.h"
 #include "AliITSRawStreamSPD.h"
 #include <TClonesArray.h>
 #include "AliITSdigitSPD.h"
+#include "AliITSFOSignalsSPD.h"
+#include "AliITSRecPointContainer.h"
+#include "AliMagF.h"
+#include "AliITSsegmentationSPD.h"
 
 ClassImp(AliITSClusterFinderV2SPD)
 
-AliITSClusterFinderV2SPD::AliITSClusterFinderV2SPD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp),
+//__________________________________________________________________________
+AliITSClusterFinderV2SPD::AliITSClusterFinderV2SPD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
 fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
 fNySPD(256),
 fNzSPD(160),
@@ -60,34 +69,100 @@ fHlSPD(3.48){
   }
 
 }
-
+//__________________________________________________________________________
 void AliITSClusterFinderV2SPD::FindRawClusters(Int_t mod){
-
   //Find clusters V2
   SetModule(mod);
   FindClustersSPD(fDigits);
 
 }
-
-void AliITSClusterFinderV2SPD::RawdataToClusters(AliRawReader* rawReader, TClonesArray** clusters){
-    //------------------------------------------------------------
+//__________________________________________________________________________
+void AliITSClusterFinderV2SPD::RawdataToClusters(AliRawReader* rawReader){
+  //------------------------------------------------------------
   // This function creates ITS clusters from raw data
   //------------------------------------------------------------
   rawReader->Reset();
+  fNClusters = 0; //RS
   AliITSRawStreamSPD inputSPD(rawReader);
-  FindClustersSPD(&inputSPD, clusters);
+  FindClustersSPD(&inputSPD);
 
 }
-
+//__________________________________________________________________________
 Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,TClonesArray* clusters,Int_t maxBins,Int_t nzbins,Int_t iModule,Bool_t rawdata){
   
   //Cluster finder for SPD (from digits and from rawdata)
+  const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+  const Double_t defaultField = 5.0; // default Bz value at which Tan(theta_Lorentz) is given in RecoParam
+
+  static AliITSRecoParam *repa = NULL;
+  if(!repa){
+    repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
+    if(!repa){
+      repa = AliITSRecoParam::GetHighFluxParam();
+      AliWarning("Using default AliITSRecoParam class");
+    }
+  }
+  const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(iModule);
+
+  // Lorentz angle correction
+  Double_t tanLorentzAngle=0; 
+  AliITSsegmentationSPD *seg = (AliITSsegmentationSPD*)(GetDetTypeRec()->GetSegmentationModel(0));
+  Double_t thick = 0.5*kmictocm*seg->Dy();  // Half Thickness in cm
+  if(repa->GetCorrectLorentzAngleSPD()) { // only if CorrectLorentzAngleSPD required
+    // here retrieve the value of the field
+    AliMagF* field = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField());
+    if (field == 0) {
+      AliError("Cannot get magnetic field from TGeoGlobalMagField");
+    }
+    else {
+      Float_t magField = field->SolenoidField();
+      tanLorentzAngle=repa->GetTanLorentzAngleHolesSPD() * magField / defaultField ;
+    }
+  }
+  //
+
+   if (repa->GetSPDRemoveNoisyFlag()) {
+    // Loop on noisy pixels and reset them
+    AliITSCalibrationSPD *cal =  
+      (AliITSCalibrationSPD*) fDetTypeRec->GetCalibrationModel(iModule);
+    for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
+      Int_t row, col;
+      cal->GetBadPixel(ipix,row,col);
+      //PH      printf(" module %d   row %d  col %d \n",iModule,row,col);
+      Int_t index = (row+1) * nzbins + (col+1);
+      
+      bins[index].SetQ(0);
+      bins[index].SetMask(0xFFFFFFFE);
+    }
+  }
+  
+    if (repa->GetSPDRemoveDeadFlag()) {
+    // Loop on dead pixels and reset them
+    AliITSCalibrationSPD *cal =  
+      (AliITSCalibrationSPD*) fDetTypeRec->GetSPDDeadModel(iModule); 
+    if (cal->IsBad()) return 0; // if all ladder is dead, return to save time
+    for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
+      Int_t row, col;
+      cal->GetBadPixel(ipix,row,col);
+      Int_t index = (row+1) * nzbins + (col+1);
+      bins[index].SetQ(0);
+      bins[index].SetMask(0xFFFFFFFE);
+    }
+    AliITSCalibrationSPD *calSparse = (AliITSCalibrationSPD*) fDetTypeRec->GetSPDSparseDeadModel(iModule);
+    for(Int_t ipix = 0; ipix<calSparse->GetNrBad(); ipix++){
+      Int_t row, col;
+      calSparse->GetBadPixel(ipix,row,col);
+      Int_t index = (row+1) * nzbins + (col+1);
+      bins[index].SetQ(0);
+      bins[index].SetMask(0xFFFFFFFE);
+    }
 
+  }
+  
   Int_t nclu=0;
   for(Int_t iBin =0; iBin < maxBins;iBin++){
     if(bins[iBin].IsUsed()) continue;
-    Int_t nBins = 0;
+    Int_t nBins = 0; 
     Int_t idxBins[200];
     FindCluster(iBin,nzbins,bins,nBins,idxBins);
     if (nBins == 200){
@@ -115,6 +190,7 @@ Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,T
       zmin=dig->GetCoord1();
       zmax=zmin;
     }
+    //PH     if(iModule == 24 || iModule == 25)  printf("\n");
     for (Int_t idx = 0; idx < nBins; idx++) {
       Int_t iy;
       Int_t iz; 
@@ -126,6 +202,7 @@ Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,T
        AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
        iy = dig->GetCoord2();
        iz = dig->GetCoord1();
+        //if(iModule == 24 || iModule == 25) printf(" ||  iy %d   iz %d  in Module %d \n",iy,iz,iModule);
       }
       if (ymin > iy) ymin = iy;
       if (ymax < iy) ymax = iy;
@@ -150,6 +227,13 @@ Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,T
     if((iModule <= fLastSPD1) &&idy<3) idy=3;
     if((iModule > fLastSPD1) &&idy<4) idy=4;
     Int_t idz=3;
+
+    // Switch the unfolding OFF/ON
+    if(!repa->GetUseUnfoldingInClusterFinderSPD()) {
+      idy=ymax-ymin+1;
+      idz=zmax-zmin+1;
+    }
+    //
     for(Int_t iiz=zmin; iiz<=zmax;iiz+=idz){
       for(Int_t iiy=ymin;iiy<=ymax;iiy+=idy){
 
@@ -172,8 +256,15 @@ Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,T
            if(TMath::Abs(iz-iiz)>0.75*idz) continue;
          }
          ndigits++;
-         Float_t qBin;
-         if(rawdata) qBin = bins[idxBins[idx]].GetQ();
+         Float_t qBin=0.;
+         if(rawdata) {
+           qBin = bins[idxBins[idx]].GetQ();
+           if (fRawID2ClusID) { // RS: Register cluster id in raw words list
+             int rwid = bins[idxBins[idx]].GetRawID();
+             if (fRawID2ClusID->GetSize()<=rwid) fRawID2ClusID->Set( (rwid+10)<<1 );         
+             (*fRawID2ClusID)[rwid] = milab[0] = fNClusters+1; // RS: store clID+1 as a reference to the cluster
+           }
+         }
          if(!rawdata){
            AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
            qBin = (Float_t)dig->GetSignal();
@@ -183,47 +274,59 @@ Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,T
          q+= qBin;     
        }// for idx
        if(ndigits==0) continue;
+         
        y /= q;
        z /= q;
        y -= fHwSPD;
        z -= fHlSPD;
-       Float_t hit[5]; //y,z,sigma(y)^2, sigma(z)^2, charge
 
-       if (iModule <= fLastSPD1) hit[0] = -y+fYshift[iModule];
-        else hit[0] = y+fYshift[iModule];
+        // Lorentz drift effect in local y
+        y -= tanLorentzAngle*thick;
+        //
 
-       hit[1] = -z+fZshift[iModule];
+       Float_t hit[6]; //y,z,sigma(y)^2, sigma(z)^2, charge
+        {
+        Double_t loc[3]={y,0.,z},trk[3]={0.,0.,0.};
+        mT2L->MasterToLocal(loc,trk);
+        hit[0]=trk[1];
+        hit[1]=trk[2];
+       }
        hit[2] = fYpitchSPD*fYpitchSPD/12.;
        hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
        hit[4] = 1.;
+       hit[5] = 0.;
+
        if(!rawdata) milab[3]=fNdet[iModule];
        Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
        if(!rawdata){
-        AliITSRecPoint cl(iModule,fDetTypeRec->GetITSgeom(),milab,hit,info);
+        AliITSRecPoint cl(milab,hit,info);
+         cl.SetType(nBins);
         fDetTypeRec->AddRecPoint(cl);
        }
         else{
          Int_t label[4]={milab[0],milab[1],milab[2],milab[3]};
+          AliITSRecPoint cl(label, hit,info);
+          cl.SetType(nBins);
          new (clusters->AddrAt(nclu)) 
-               AliITSRecPoint(iModule,fDetTypeRec->GetITSgeom(),label, hit,info);
+         AliITSRecPoint(cl);
        } 
        nclu++;
+       fNClusters++;
       }// for iiy
     }// for iiz
   }//end for iBin
   return nclu;
   
 }
-
-
-
-
-void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStream* input, 
-                                       TClonesArray** clusters) 
+//__________________________________________________________________________
+void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStreamSPD* input) 
 {
   //------------------------------------------------------------
-  // Actual SPD cluster finder for raw data
+  // SPD cluster finder for raw data (this method is called once per event)
+  // Now also fills fast-or fired map
   //------------------------------------------------------------
+
+  AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();  
   Int_t nClustersSPD = 0;
   Int_t kNzBins = fNzSPD + 2;
   Int_t kNyBins = fNySPD + 2;
@@ -233,6 +336,9 @@ void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStream* input,
   AliBin* bins = NULL;
 
   // read raw data input stream
+  int countRW = 0; //RS
+  if (fRawID2ClusID) fRawID2ClusID->Reset(); //RS if array was provided, we shall store the rawID -> ClusterID
+  //
   while (kTRUE) {
     Bool_t next = input->Next();
     if (!next || input->IsNewModule()) {
@@ -240,8 +346,8 @@ void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStream* input,
 
       // when all data from a module was read, search for clusters
       if (bins) { 
-       clusters[iModule] = new TClonesArray("AliITSRecPoint");
-       Int_t nClusters = ClustersSPD(bins,0,clusters[iModule],kMaxBin,kNzBins,iModule,kTRUE);
+       TClonesArray* clusters = rpc->UncheckedGetClusters(iModule);
+       Int_t nClusters = ClustersSPD(bins,0,clusters,kMaxBin,kNzBins,iModule,kTRUE);
        nClustersSPD += nClusters;
        bins = NULL;
       }
@@ -251,24 +357,40 @@ void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStream* input,
       memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
     }
 
-    // fill the current digit into the bins array
-    Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
-    bins[index].SetIndex(index);
-    bins[index].SetMask(1);
-    bins[index].SetQ(1);
+    if (next && bins) {      
+      // fill the current digit into the bins array
+      Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
+      bins[index].SetIndex(index);
+      bins[index].SetQ(1);
+      bins[index].SetMask(1);
+      bins[index].SetRawID(countRW); //RS register raw id
+    }
+    countRW++; //RS
   }
 
   delete [] binsSPDInit;
   delete [] binsSPD;
   
-  Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
+  AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD));
+  
+    // Fill the FastOr fired map
+  for (UInt_t eq=0; eq<20; eq++) {
+    for (UInt_t hs=0; hs<6; hs++) {
+      for (UInt_t chip=0; chip<10; chip++) {
+        if (input->GetFastOrSignal(eq,hs,chip)) {
+         fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip);
+        }
+      }
+    }
+  }
+  
 }
-
-
-
+//__________________________________________________________________________
 void AliITSClusterFinderV2SPD::FindClustersSPD(TClonesArray *digits) {
   //------------------------------------------------------------
-  // Actual SPD cluster finder
+  // SPD cluster finder for digits (this method is called for each module)
+  // Now also fills the fast-or fired map
   //------------------------------------------------------------
 
 
@@ -278,19 +400,36 @@ void AliITSClusterFinderV2SPD::FindClustersSPD(TClonesArray *digits) {
   Int_t ndigits=digits->GetEntriesFast();
   AliBin *bins=new AliBin[kMAXBIN];
 
-  Int_t k;
-  AliITSdigitSPD *d=0;
-  for (k=0; k<ndigits; k++) {
-     d=(AliITSdigitSPD*)digits->UncheckedAt(k);
-     Int_t i=d->GetCoord2()+1;   //y
-     Int_t j=d->GetCoord1()+1;
-     Int_t index=i*kNzBins+j;
-     bins[index].SetIndex(k);
-     bins[index].SetMask(1);
+  Int_t idig;
+  AliITSdigitSPD *digit=0;
+  for (idig=0; idig<ndigits; idig++) {
+    digit=(AliITSdigitSPD*)digits->UncheckedAt(idig);
+    Int_t i=digit->GetCoord2()+1;   //y
+    Int_t j=digit->GetCoord1()+1;
+    Int_t index=i*kNzBins+j;
+
+    bins[index].SetIndex(idig);
+    bins[index].SetQ(1);
+    bins[index].SetMask(1);
   }
+
    
-  ClustersSPD(bins,digits,0,kMAXBIN,kNzBins,fModule,kFALSE); 
+  Int_t nClustersSPD = ClustersSPD(bins,digits,0,kMAXBIN,kNzBins,fModule,kFALSE); 
   delete [] bins;
-}
-
 
+  AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD));
+  
+    //  Fill the FastOr fired map
+  AliITSFOSignalsSPD* foSignals = fDetTypeRec->GetFOSignals();
+  if (foSignals) {
+    UInt_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(fModule);
+    UInt_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(fModule);
+    for(UInt_t ch=0; ch<5; ch++) {
+      UInt_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(fModule,ch*32);
+      if (foSignals->GetSignal(eq,hs,chip)) {
+       fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip);
+      }
+    }
+  }
+  
+}