]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCclustererMI.cxx
Disable use of HLT one pad clusters for tracking
[u/mrichter/AliRoot.git] / TPC / AliTPCclustererMI.cxx
index b006ec8effd97ba505e8b4765b46380208cee22d..ecfad37cd71f0df786b9d237dfbf9459afa8680f 100644 (file)
 //  1. The Input data for reconstruction - Options
 //      1.a Simulated data  - TTree - invoked Digits2Clusters()
 //      1.b Raw data        - Digits2Clusters(AliRawReader* rawReader); 
+//      1.c HLT clusters    - Digits2Clusters and Digits2Clusters(AliRawReader* rawReader)
+//                            invoke ReadHLTClusters()
+//
+//      fUseHLTClusters     - switches between different inputs
+//                            1 -> only TPC raw/sim data
+//                            2 -> if present TPC raw/sim data, otherwise HLT clusters
+//                            3 -> only HLT clusters
+//                            4 -> if present HLT clusters, otherwise TPC raw/sim data
 //
 //  2. The Output data
 //      2.a TTree with clusters - if  SetOutput(TTree * tree) invoked
@@ -48,6 +56,8 @@
 #include <TRandom.h>
 #include <TTree.h>
 #include <TTreeStream.h>
+#include "TSystem.h"
+#include "TClass.h"
 
 #include "AliDigits.h"
 #include "AliLoader.h"
@@ -108,6 +118,7 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoPar
   fRecoParam(0),
   fBDumpSignal(kFALSE),
   fBClonesArray(kFALSE),
+  fUseHLTClusters(1),
   fAllBins(NULL),
   fAllSigBins(NULL),
   fAllNSigBins(NULL)
@@ -188,6 +199,7 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCclustererMI &param)
   fRecoParam(0),
   fBDumpSignal(kFALSE),
   fBClonesArray(kFALSE),
+  fUseHLTClusters(1),
   fAllBins(NULL),
   fAllSigBins(NULL),
   fAllNSigBins(NULL)
@@ -258,8 +270,8 @@ void AliTPCclustererMI::SetOutput(TTree * tree)
   //
   if (!tree) return;
   fOutput= tree;
-  AliTPCClustersRow clrow, *pclrow=&clrow;  
-  pclrow = new AliTPCClustersRow("AliTPCclusterMI");
+  AliTPCClustersRow clrow("AliTPCclusterMI");
+  AliTPCClustersRow *pclrow=&clrow;  
   fOutput->Branch("Segment","AliTPCClustersRow",&pclrow,32000,200);    
 }
 
@@ -632,6 +644,7 @@ void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c, Float_t * /*matrix*/, Int
   AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
   if (!transform) {
     AliFatal("Tranformations not in calibDB");    
+    return;
   }
   transform->SetCurrentRecoParam((AliTPCRecoParam*)fRecoParam);
   Double_t x[3]={c.GetRow(),c.GetPad(),c.GetTimeBin()};
@@ -709,6 +722,42 @@ void AliTPCclustererMI::Digits2Clusters()
     fRecoParam->Dump();
   }
 
+  //-----------------------------------------------------------------
+  // Use HLT clusters
+  //-----------------------------------------------------------------
+  fUseHLTClusters = fRecoParam->GetUseHLTClusters();
+
+  AliInfo(Form("Usage of HLT clusters in TPC reconstruction : %d",fUseHLTClusters));
+
+  if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+    AliInfo("Using HLT clusters for TPC off-line reconstruction");
+    fZWidth = fParam->GetZWidth();
+    Int_t iResult = ReadHLTClusters();
+
+    // HLT clusters present
+    if (iResult >= 0 && fNclusters > 0)
+      return; 
+
+    // HLT clusters not present
+    if (iResult < 0 || fNclusters == 0) {
+      if (fUseHLTClusters == 3) { 
+       AliError("No HLT clusters present, but requested.");
+       return;
+      }
+      else {
+       AliInfo("Now trying to read TPC RAW");
+      }
+    }
+    // Some other problem during cluster reading
+    else {
+      AliWarning("Some problem while unpacking of HLT clusters.");
+      return;
+    }
+  } // if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+
+  //-----------------------------------------------------------------
+  // Run TPC off-line clusterer
+  //-----------------------------------------------------------------
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
   AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
   AliSimDigits digarr, *dummy=&digarr;
@@ -740,7 +789,7 @@ void AliTPCclustererMI::Digits2Clusters()
     fZWidth = fParam->GetZWidth();
     if (fSector < kNIS) {
       fMaxPad = fParam->GetNPadsLow(row);
-      fSign = (fSector < kNIS/2) ? 1 : -1;
+      fSign =  (fSector < kNIS/2) ? 1 : -1;
       fPadLength = fParam->GetPadPitchLength(fSector,row);
       fPadWidth = fParam->GetPadPitchWidth();
     } else {
@@ -783,6 +832,13 @@ void AliTPCclustererMI::Digits2Clusters()
   }  
  
   Info("Digits2Clusters", "Number of found clusters : %d", nclusters);
+
+  if (fUseHLTClusters == 2 && nclusters == 0) {
+    AliInfo("No clusters from TPC Raw data, now trying to read HLT clusters.");
+
+    fZWidth = fParam->GetZWidth();
+    ReadHLTClusters();
+  }
 }
 
 void AliTPCclustererMI::ProcessSectorData(){
@@ -938,6 +994,42 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
   }
   fRowDig = NULL;
 
+  //-----------------------------------------------------------------
+  // Use HLT clusters
+  //-----------------------------------------------------------------
+  fUseHLTClusters = fRecoParam->GetUseHLTClusters();
+
+  AliInfo(Form("Usage of HLT clusters in TPC reconstruction : %d",fUseHLTClusters));
+
+  if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+    AliInfo("Using HLT clusters for TPC off-line reconstruction");
+    fZWidth = fParam->GetZWidth();
+    Int_t iResult = ReadHLTClusters();
+
+    // HLT clusters present
+    if (iResult >= 0 && fNclusters > 0)
+      return;
+
+    // HLT clusters not present
+    if (iResult < 0 || fNclusters == 0) {
+      if (fUseHLTClusters == 3) { 
+       AliError("No HLT clusters present, but requested.");
+       return;
+      }
+      else {
+       AliInfo("Now trying to read TPC RAW");
+      }
+    }
+    // Some other problem during cluster reading
+    else {
+      AliWarning("Some problem while unpacking of HLT clusters.");
+      return;
+    }
+  } // if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+   
+  //-----------------------------------------------------------------
+  // Run TPC off-line clusterer
+  //-----------------------------------------------------------------
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
   AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
   //
@@ -1095,16 +1187,23 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
   }
   
   if (rawReader->GetEventId() && fOutput ){
-    Info("Digits2Clusters", "File  %s Event\t%d\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), fNclusters);
+    Info("Digits2Clusters", "File  %s Event\t%u\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), fNclusters);
   }
   
   if(rawReader->GetEventId()) {
-    Info("Digits2Clusters", "Event\t%d\tNumber of found clusters : %d\n",*(rawReader->GetEventId()), fNclusters);
+    Info("Digits2Clusters", "Event\t%u\tNumber of found clusters : %d\n",*(rawReader->GetEventId()), fNclusters);
   }
   
   if(fBClonesArray) {
     //Info("Digits2Clusters", "Number of found clusters : %d\n",fOutputClonesArray->GetEntriesFast());
   }
+
+  if (fUseHLTClusters == 2 && fNclusters == 0) {
+    AliInfo("No clusters from TPC Raw data, now trying to read HLT clusters.");
+
+    fZWidth = fParam->GetZWidth();
+    ReadHLTClusters();
+  }
 }
 
 
@@ -1190,7 +1289,7 @@ void AliTPCclustererMI::Digits2ClustersOld
     rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
 
     // select only good sector 
-    input.Next();
+    if (!input.Next()) continue;
     if(input.GetSector() != fSector) continue;
 
     AliTPCCalROC * gainROC    = gainTPC->GetCalROC(fSector);  // pad gains per given sector
@@ -1493,7 +1592,6 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
     dsignal[i] = signal[i];
   }
 
-  TGraph * graph=0;
   //
   // Big signals dumping
   //    
@@ -1505,7 +1603,7 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
       "Sector="<<uid[0]<<
       "Row="<<uid[1]<<
       "Pad="<<uid[2]<<
-      "Graph="<<graph<<
+      //      "Graph="<<graph<<
       "Max="<<max<<
       "MaxPos="<<maxPos<<      
       //
@@ -1517,7 +1615,6 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
       "Mean09="<<mean09<<
       "RMS09="<<rms09<<
       "\n";
-  delete graph;  
   }
 
   delete [] dsignal;
@@ -1529,7 +1626,108 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
   return median;
 }
 
+Int_t AliTPCclustererMI::ReadHLTClusters()
+{
+  //
+  // read HLT clusters instead of off line custers, 
+  // used in Digits2Clusters
+  //
 
+  TObject* pClusterAccess=NULL;
+  TClass* pCl=NULL;
+  ROOT::NewFunc_t pNewFunc=NULL;
+  do {
+    pCl=TClass::GetClass("AliHLTTPCClusterAccessHLTOUT");
+  } while (!pCl && gSystem->Load("libAliHLTTPC.so")==0);
+  if (!pCl || (pNewFunc=pCl->GetNew())==NULL) {
+    AliError("can not load class description of AliHLTTPCClusterAccessHLTOUT, aborting ...");
+    return -1;
+  }
+  
+  void* p=(*pNewFunc)(NULL);
+  if (!p) {
+    AliError("unable to create instance of AliHLTTPCClusterAccessHLTOUT");
+    return -2;
+  }
+  pClusterAccess=reinterpret_cast<TObject*>(p);
+  if (!pClusterAccess) {
+    AliError("instance not of type TObject");
+    return -3 ;
+  }
 
+  const Int_t kNIS = fParam->GetNInnerSector();
+  const Int_t kNOS = fParam->GetNOuterSector();
+  const Int_t kNS = kNIS + kNOS;
+  fNclusters  = 0;
+  
+  for(fSector = 0; fSector < kNS; fSector++) {
 
+    Int_t iResult = 1;
+    TString param("sector="); param+=fSector;
+    pClusterAccess->Clear();
+    pClusterAccess->Execute("read", param, &iResult);
+    if (iResult < 0) {
+      return iResult;
+      AliError("HLT Clusters can not be found");
+    }
 
+    if (pClusterAccess->FindObject("clusterarray")==NULL) {
+      AliError("HLT clusters requested, but not cluster array not present");
+      return -4;
+    }
+
+    TClonesArray* clusterArray=dynamic_cast<TClonesArray*>(pClusterAccess->FindObject("clusterarray"));
+    if (!clusterArray) {
+      AliError("HLT cluster array is not of class type TClonesArray");
+      return -5;
+    }
+
+    AliDebug(4,Form("Reading %d clusters from HLT for sector %d", clusterArray->GetEntriesFast(), fSector));
+
+    Int_t nClusterSector=0;
+    Int_t nRows=fParam->GetNRow(fSector);
+
+    for (fRow = 0; fRow < nRows; fRow++) {
+      fRowCl->SetID(fParam->GetIndex(fSector, fRow));
+      if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
+      fNcluster=0; // reset clusters per row
+      
+      fRx = fParam->GetPadRowRadii(fSector, fRow);
+      fPadLength = fParam->GetPadPitchLength(fSector, fRow);
+      fPadWidth  = fParam->GetPadPitchWidth();
+      fMaxPad = fParam->GetNPads(fSector,fRow);
+      fMaxBin = fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
+      
+      fBins = fAllBins[fRow];
+      fSigBins = fAllSigBins[fRow];
+      fNSigBins = fAllNSigBins[fRow];
+      
+      for (Int_t i=0; i<clusterArray->GetEntriesFast(); i++) {
+       if (!clusterArray->At(i)) 
+         continue;
+       
+       AliTPCclusterMI* cluster=dynamic_cast<AliTPCclusterMI*>(clusterArray->At(i));
+       if (!cluster) continue;
+       if (cluster->GetRow()!=fRow) continue;
+       nClusterSector++;
+       AddCluster(*cluster, NULL, 0);
+      }
+      
+      FillRow();
+      fRowCl->GetArray()->Clear("c");
+      
+    } // for (fRow = 0; fRow < nRows; fRow++) {
+    if (nClusterSector!=clusterArray->GetEntriesFast()) {
+      AliError(Form("Failed to read %d out of %d HLT clusters", 
+                   clusterArray->GetEntriesFast()-nClusterSector, 
+                   clusterArray->GetEntriesFast()));
+    }
+    fNclusters+=nClusterSector;
+  } // for(fSector = 0; fSector < kNS; fSector++) {
+
+  delete pClusterAccess;
+
+  Info("Digits2Clusters", "Number of converted HLT clusters : %d", fNclusters);
+  
+  return 0;
+}