]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPC.cxx
Replacing the friend declarations by setters and getters (Federico)
[u/mrichter/AliRoot.git] / TPC / AliTPC.cxx
index ed18e4b47d057715abda51432c3521e5f14483ef..fd11f41d0c7af43193ae54ce9410db1c3ed5afde 100644 (file)
@@ -76,7 +76,8 @@
 #include "AliTPCBuffer.h"
 #include "AliTPCDDLRawData.h"
 #include "AliLog.h"
-
+#include "AliRawReader.h"
+#include "AliTPCRawStream.h"
 
 ClassImp(AliTPC) 
 //_____________________________________________________________________________
@@ -101,6 +102,7 @@ AliTPC::AliTPC()
   fTPCParam = 0;    
   fNoiseTable = 0;
   fActiveSectors =0;
+  fSens = 0;
 
 }
  
@@ -158,6 +160,7 @@ AliTPC::AliTPC(const char *name, const char *title)
     AliWarning("In Config.C you must set non-default parameters.");
     fTPCParam=0;
   }
+  fSens = 0;
 
 }
 
@@ -179,7 +182,10 @@ AliTPC::~AliTPC()
   delete fTPCParam;
   delete fTrackHits; //MI 15.09.2000
   //  delete fTrackHitsOld; //MI 10.12.2001
-  if (fNoiseTable) delete [] fNoiseTable;
+  
+  fDigitsArray = 0x0;
+  delete [] fNoiseTable;
+  delete [] fActiveSectors;
 
 }
 
@@ -778,7 +784,6 @@ void AliTPC::Digits2Raw()
 // convert digits of the current event to raw data
 
   static const Int_t kThreshold = 0;
-  static const Bool_t kCompress = kTRUE;
 
   fLoader->LoadDigits();
   TTree* digits = fLoader->TreeD();
@@ -864,14 +869,145 @@ void AliTPC::Digits2Raw()
   rawWriter.RawData(fileName);
   gSystem->Unlink(fileName);
 
-  if (kCompress) {
-    AliInfo("Compressing raw data");
-    rawWriter.RawDataCompDecompress(kTRUE);
-    gSystem->Unlink("Statistics");
-  }
 }
 
 
+//_____________________________________________________________________________
+Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
+  // Converts the TPC raw data into summable digits
+  // The method is used for merging simulated and
+  // real data events
+  if (fLoader->TreeS() == 0x0 ) {
+    fLoader->MakeTree("S");
+  }
+
+  if(fDefaults == 0) SetDefaults();  // check if the parameters are set
+
+  //setup TPCDigitsArray 
+  if(GetDigitsArray()) delete GetDigitsArray();
+
+  AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
+  arr->SetClass("AliSimDigits");
+  arr->Setup(fTPCParam);
+  arr->MakeTree(fLoader->TreeS());
+
+  SetDigitsArray(arr);
+
+  // set zero suppression to "0"
+  fTPCParam->SetZeroSup(0);
+
+  // Loop over sectors
+  const Int_t kmaxTime = fTPCParam->GetMaxTBin();
+  const Int_t kNIS = fTPCParam->GetNInnerSector();
+  const Int_t kNOS = fTPCParam->GetNOuterSector();
+  const Int_t kNS = kNIS + kNOS;
+
+  Short_t** allBins = NULL; //array which contains the data for one sector
+  
+  for(Int_t iSector = 0; iSector < kNS; iSector++) {
+    
+    Int_t nRows = fTPCParam->GetNRow(iSector);
+    Int_t nDDLs = 0, indexDDL = 0;
+    if (iSector < kNIS) {
+      nDDLs = 2;
+      indexDDL = iSector * 2;
+    }
+    else {
+      nDDLs = 4;
+      indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
+    }
+
+    // Loas the raw data for corresponding DDLs
+    rawReader->Reset();
+    AliTPCRawStream input(rawReader);
+    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
+
+    // Alocate and init the array with the sector data
+    allBins = new Short_t*[nRows];
+    for (Int_t iRow = 0; iRow < nRows; iRow++) {
+      Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
+      Int_t maxBin = kmaxTime*maxPad;
+      allBins[iRow] = new Short_t[maxBin];
+      memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
+    }
+
+    // Begin loop over altro data
+    while (input.Next()) {
+
+      if (input.GetSector() != iSector)
+       AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
+
+      Int_t iRow = input.GetRow();
+      if (iRow < 0 || iRow >= nRows)
+       AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
+                     iRow, 0, nRows -1));
+      Int_t iPad = input.GetPad();
+
+      Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
+
+      if (iPad < 0 || iPad >= maxPad)
+       AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
+                     iPad, 0, maxPad -1));
+
+      Int_t iTimeBin = input.GetTime();
+      if ( iTimeBin < 0 || iTimeBin >= kmaxTime)
+       AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
+                     iTimeBin, 0, kmaxTime -1));
+      
+      Int_t maxBin = kmaxTime*maxPad;
+
+      if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
+         ((iPad*kmaxTime+iTimeBin) < 0))
+       AliFatal(Form("Index outside the allowed range"
+                     " Sector=%d Row=%d Pad=%d Timebin=%d"
+                     " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
+
+      allBins[iRow][iPad*kmaxTime+iTimeBin] = input.GetSignal();
+
+    } // End loop over altro data
+    
+    // Now fill the digits array
+    if (fDigitsArray->GetTree()==0) {
+      AliFatal("Tree not set in fDigitsArray");
+    }
+
+    for (Int_t iRow = 0; iRow < nRows; iRow++) {
+      AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
+
+      Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
+      for(Int_t iPad = 0; iPad < maxPad; iPad++) {
+       for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
+         Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
+         if (q <= 0) continue;
+         q *= 16;
+         dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
+       }
+      }
+      fDigitsArray->StoreRow(iSector,iRow);
+      Int_t ndig = dig->GetDigitSize(); 
+       
+      AliDebug(10,
+              Form("*** Sector, row, compressed digits %d %d %d ***\n",
+                   iSector,iRow,ndig));        
+       
+      fDigitsArray->ClearRow(iSector,iRow);  
+
+    } // end of the sector digitization
+
+    for (Int_t iRow = 0; iRow < nRows; iRow++)
+      delete [] allBins[iRow];
+
+    delete [] allBins;
+
+  }
+
+  fLoader->WriteSDigits("OVERWRITE");
+
+  if(GetDigitsArray()) delete GetDigitsArray();
+  SetDigitsArray(0x0);
+
+  return kTRUE;
+}
 
 //______________________________________________________________________
 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
@@ -952,7 +1088,7 @@ void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
     Short_t * pamp1 = digrow->GetDigits();
     Int_t   * ptracks1 = digrow->GetTracks();
     Int_t  nelems =nrows*ncols;
-    Int_t saturation = fTPCParam->GetADCSat();
+    Int_t saturation = fTPCParam->GetADCSat() - 1;
     //use internal structure of the AliDigits - for speed reason
     //if you cahnge implementation
     //of the Alidigits - it must be rewriten -
@@ -1059,6 +1195,12 @@ void AliTPC::Hits2Digits()
   //
   // creates digits from hits
   //
+  if (!fTPCParam->IsGeoRead()){
+    //
+    // read transformation matrices for gGeoManager
+    //
+    fTPCParam->ReadGeoMatrices();
+  }
 
   fLoader->LoadHits("read");
   fLoader->LoadDigits("recreate");
@@ -1204,6 +1346,13 @@ void AliTPC::Hits2SDigits()
   //   summable digits - 16 bit "ADC", no noise, no saturation
   //-----------------------------------------------------------
 
+  if (!fTPCParam->IsGeoRead()){
+    //
+    // read transformation matrices for gGeoManager
+    //
+    fTPCParam->ReadGeoMatrices();
+  }
+  
   fLoader->LoadHits("read");
   fLoader->LoadSDigits("recreate");
   AliRunLoader* runLoader = fLoader->GetRunLoader(); 
@@ -1376,7 +1525,7 @@ void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
        q+=GetNoise();
         if(q <=fzerosup) continue; // do not fill zeros
         q = TMath::Nint(q);
-        if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat();  // saturation
+        if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1;  // saturation
 
       }
 
@@ -1449,7 +1598,7 @@ Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
   TVector &v = *tv;
   
   Float_t label = v(0);
-  Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1)-1)/2;
+  Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
 
   Int_t nElectrons = (tv->GetNrows()-1)/5;
   indexRange[0]=9999; // min pad
@@ -1659,6 +1808,13 @@ void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
        continue; 
       }
 
+      // Remove hits which arrive before the TPC opening gate signal
+      if(((fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
+         /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
+       tpcHit = (AliTPChit*) NextHit();
+       continue;
+      }
+
       currentTrack = tpcHit->Track(); // track number
 
       if(currentTrack != previousTrack){
@@ -2127,7 +2283,7 @@ void AliTPC::RemapTrackHitIDs(Int_t *map)
     TClonesArray * arr = fTrackHits->GetArray();;
     for (Int_t i=0;i<arr->GetEntriesFast();i++){
       AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
-      info->fTrackID = map[info->fTrackID];
+      info->SetTrackID(map[info->GetTrackID()]);
     }
   }
 }