]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/calibration/AliHLTTPCCalibTimeComponent.cxx
using one instance of decoder for all events
[u/mrichter/AliRoot.git] / HLT / TPCLib / calibration / AliHLTTPCCalibTimeComponent.cxx
index fe54089faeebf28c45161889bca8f7e95b85138d..60f810703b308f76445d2ec77a5076989f77622e 100644 (file)
@@ -46,6 +46,13 @@ using namespace std;
 #include "AliTPCcalibDB.h"
 #include "AliTPCClusterParam.h"
 
+#include "AliHLTTPCOfflineCluster.h"
+#include "AliHLTTPCSpacePointData.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTExternalTrackParam.h"
+#include "AliHLTGlobalBarrelTrack.h"
+#include "AliHLTTPCTransform.h"
+
 #include "TObjArray.h"
 #include "TString.h"
 #include "TFile.h"
@@ -74,51 +81,60 @@ AliHLTTPCCalibTimeComponent::AliHLTTPCCalibTimeComponent()
   // or
   // refer to README to build package
   // or
-  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt  
+  
+  for(int i=0; i<fkNPartition; i++){
+      fPartitionClusters[i]  = 0;    
+      fNPartitionClusters[i] = 0;    
+  }
 }
 
 const char* AliHLTTPCCalibTimeComponent::fgkOCDBEntry="HLT/ConfigTPC/TPCCalibTime";
 
-AliHLTTPCCalibTimeComponent::~AliHLTTPCCalibTimeComponent() {
-// see header file for class documentation
+AliHLTTPCCalibTimeComponent::~AliHLTTPCCalibTimeComponent(){
+// see header file for class documentation 
+  for(int i=0; i<fkNPartition; i++){
+      delete[] fPartitionClusters[i];
+  }
 }
 
-
 const char* AliHLTTPCCalibTimeComponent::GetComponentID() {
 // see header file for class documentation
-
   return "TPCCalibTime";
 }
 
-void AliHLTTPCCalibTimeComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
+void AliHLTTPCCalibTimeComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list){
 // see header file for class documentation
 
   list.clear(); 
   list.push_back( kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC ); // output of TPCCalibSeedMaker
+  list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );     // output of the TPC CF
+  list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );     // output of the global merger
   list.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut ); // output of global esd converter
 }
 
 AliHLTComponentDataType AliHLTTPCCalibTimeComponent::GetOutputDataType() {
 // see header file for class documentation
 
-  return AliHLTTPCDefinitions::fgkCalibCEDataType|kAliHLTDataOriginOut;
+  return AliHLTTPCDefinitions::CalibCEDataType()|kAliHLTDataOriginOut;
 }
 
-void AliHLTTPCCalibTimeComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
+void AliHLTTPCCalibTimeComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ){
 // see header file for class documentation
 
   constBase = fOutputSize;
   inputMultiplier = 0; // to be estimated
 }
 
-AliHLTComponent* AliHLTTPCCalibTimeComponent::Spawn() {
+AliHLTComponent* AliHLTTPCCalibTimeComponent::Spawn(){
 // see header file for class documentation
 
   return new AliHLTTPCCalibTimeComponent();
 }  
 
 
-Int_t AliHLTTPCCalibTimeComponent::ScanConfigurationArgument( Int_t argc, const char** argv ) {
+Int_t AliHLTTPCCalibTimeComponent::ScanConfigurationArgument( Int_t argc, const char** argv ){
 // see header file for class documentation
  
   if (argc<=0) return 0;
@@ -129,16 +145,15 @@ Int_t AliHLTTPCCalibTimeComponent::ScanConfigurationArgument( Int_t argc, const
   if (argument.CompareTo("-output-size")==0) {
     if (++i>=argc) return -EPROTO;
     argument=argv[i];
-    fOutputSize=argument.Atof();
+    fOutputSize=argument.Atoi();
     return 2;
   }
   return -EINVAL;
 }
 
-Int_t AliHLTTPCCalibTimeComponent::InitCalibration() {
+Int_t AliHLTTPCCalibTimeComponent::InitCalibration(){
 // see header file for class documentation
   
-  //AliTPCcalibDB::Instance()->SetRun(84714);
   AliTPCcalibDB::Instance()->SetRun(AliHLTMisc::Instance().GetCDBRunNo());
   AliTPCcalibDB::Instance()->GetClusterParam()->SetInstance(AliTPCcalibDB::Instance()->GetClusterParam());
   
@@ -159,13 +174,12 @@ Int_t AliHLTTPCCalibTimeComponent::InitCalibration() {
   // first configure the default
   int iResult=0;
   if (iResult>=0) iResult=ConfigureFromCDBTObjString(fgkOCDBEntry);
-
-  // configure from the command line parameters if specified
-  //if (iResult>=0 && argc>0)  iResult=ConfigureFromArgumentString(argc, argv);
     
   if(fCalibTime) return EINPROGRESS;
   fCal = new AliTPCcalibCalib();
   
+  fSeedArray = new TObjArray();
+  
   return iResult;
  
 }
@@ -175,8 +189,12 @@ Int_t AliHLTTPCCalibTimeComponent::DeinitCalibration() {
 
   if(fCalibTime) delete fCalibTime; fCalibTime = NULL;
   if(fCal)       delete fCal;      fCal       = NULL;
+  if(fSeedArray) delete fSeedArray; fSeedArray = NULL;
+
   //if(fESDfriend) delete fESDfriend; fESDfriend = NULL;
   
+  //if(arr) delete arr; arr = NULL;
+  
   return 0;
 }
 
@@ -185,7 +203,7 @@ int AliHLTTPCCalibTimeComponent::Reconfigure(const char* cdbEntry, const char* /
 
   // configure from the specified antry or the default one
   const char* entry=cdbEntry;
-  if (!entry || entry[0]==0) {
+  if(!entry || entry[0]==0){
      entry=fgkOCDBEntry;
   }
 
@@ -197,18 +215,155 @@ Int_t AliHLTTPCCalibTimeComponent::ProcessCalibration( const AliHLTComponentEven
 
   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
 
-  TObject *iter = NULL;
+  const AliHLTComponentBlockData *iter = NULL;      
 
   //--------------- output over TObjArray of AliTPCseed objects (output of TPCSeedMaker) -------------------//
   
-  // A previous component in the chain (TPCSeedMaker) has processed the TPC clusters and tracks and created a TObjArray of AliTPCseed objects
+  // A previous component in the chain (TPCSeedMaker) has processed the TPC clusters and tracks and created a TClonesArray of AliTPCseed objects
   // In this loop the iterator accesses this array stored in memory, in order to use it in the next loop over the AliESDevent of the HLT
   
-  for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC); iter != NULL; iter = (TObject*)GetNextInputObject()){  
-              
-      if(GetDataType(iter) != (kAliHLTDataTypeTObjArray | kAliHLTDataOriginTPC)) continue;      
-      fSeedArray = dynamic_cast<TObjArray*>(iter);      
-   }
+//   for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC); iter != NULL; iter = (TObject*)GetNextInputObject()){  
+//               
+//       if(GetDataType(iter) != (kAliHLTDataTypeTObjArray | kAliHLTDataOriginTPC)) continue;      
+//       fSeedArray = dynamic_cast<TClonesArray*>(iter);      
+//    }
+ // int nInputClusters = 0;
+ // int nInputTracks = 0;
+
+  //TObjArray *arr = new TObjArray(1000);
+  //arr->SetOwner(kTRUE);
+  fSeedArray->Clear();
+
+  
+  for( int i=0; i<fkNPartition; i++ ){
+    delete[] fPartitionClusters[i];    
+    fPartitionClusters[i] = 0;
+    fNPartitionClusters[i] = 0;    
+  }
+
+  
+  
+  //------------------- loop over clusters -------------//
+  
+  for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
+      
+      if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
+    
+      Int_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
+      Int_t partition = AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
+       
+      Int_t slicepartition = slice*6+partition;
+      
+      if(slicepartition > fkNPartition){
+         HLTWarning("Wrong header of TPC cluster data, slice %d, partition %d", slice, partition );
+         continue;
+      }
+      
+      AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
+      // nInputClusters += inPtrSP->fSpacePointCnt;
+
+      delete[] fPartitionClusters[slicepartition];
+      fPartitionClusters[slicepartition]  = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
+      fNPartitionClusters[slicepartition] = inPtrSP->fSpacePointCnt;
+    
+      // create  offline clusters out of the HLT clusters
+      // todo: check which cluster information is really needed for the dEdx
+      for(unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++){          
+         AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
+          AliTPCclusterMI *c = fPartitionClusters[slicepartition]+i;
+          c->SetX(chlt->fX);
+          c->SetY(chlt->fY);
+          c->SetZ(chlt->fZ);
+          c->SetSigmaY2(chlt->fSigmaY2);
+          c->SetSigmaYZ( 0 );
+          c->SetSigmaZ2(chlt->fSigmaZ2);
+          c->SetQ( chlt->fCharge );
+          c->SetMax( chlt->fQMax );
+          Int_t sector, row;
+          Float_t padtime[3] = {0,chlt->fY,chlt->fZ};
+          AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
+          AliHLTTPCTransform::Local2Raw( padtime, sector, row);
+          c->SetDetector( sector );
+          c->SetRow( row );
+          c->SetPad( (Int_t) padtime[1] );
+          c->SetTimeBin( (Int_t) padtime[2] );
+      }      
+  } // end of loop over blocks of clusters
+  
+  
+  
+  
+  //---------- loop over merged tracks ------------------ //
+  int nTracks = 0;
+  for(const AliHLTComponentBlockData *pBlock = GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); pBlock != NULL; pBlock = GetNextInputBlock()){
+      AliHLTTracksData *dataPtr = (AliHLTTracksData*) pBlock->fPtr;
+      nTracks = dataPtr->fCount;
+    
+      AliHLTExternalTrackParam *currTrack = dataPtr->fTracklets;
+      
+      //nInputTracks += nTracks;
+    
+      for(int itr=0;  itr<nTracks && ( (AliHLTUInt8_t *)currTrack < ((AliHLTUInt8_t *) pBlock->fPtr)+pBlock->fSize); itr++){    
+          
+         // create an offline track
+          AliHLTGlobalBarrelTrack gb(*currTrack);
+          AliTPCseed tTPC;
+          tTPC.Set(gb.GetX(), gb.GetAlpha(), gb.GetParameter(), gb.GetCovariance());
+            
+          // set the cluster pointers     
+          for(UInt_t ic=0; ic<currTrack->fNPoints; ic++){      
+      
+              tTPC.SetNumberOfClusters(currTrack->fNPoints);
+          
+             UInt_t id = currTrack->fPointIDs[ic];
+             int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
+             int iPartition = AliHLTTPCSpacePointData::GetPatch(id);
+             int iCluster = AliHLTTPCSpacePointData::GetNumber(id);    
+       
+             if(iSlice<0 || iSlice>36 || iPartition<0 || iPartition>5){
+                HLTError("Corrupted TPC cluster Id: slice %d, partition %d, cluster %d", iSlice, iPartition, iCluster);
+                continue;
+             }
+       
+             AliTPCclusterMI *partitionClusters = fPartitionClusters[iSlice*6 + iPartition];
+             
+             if(!partitionClusters){
+                 HLTError("Clusters are missed for slice %d, partition %d", iSlice, iPartition );
+                 continue;
+             }
+       
+             if(iCluster >= fNPartitionClusters[iSlice*6 + iPartition]){
+                HLTError("TPC slice %d, partition %d: ClusterID==%d >= N Clusters==%d ", iSlice, iPartition,iCluster, fNPartitionClusters[iSlice*6 + iPartition]);
+                continue;
+             }
+       
+             AliTPCclusterMI *c = &(partitionClusters[iCluster]);              
+             int sec = c->GetDetector();
+             int row = c->GetRow();
+             if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
+       
+             tTPC.SetClusterPointer(row, c);   
+       
+             AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
+             //tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
+             Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
+             angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.; 
+             point.SetAngleY( angle2 );
+             point.SetAngleZ( tTPC.GetTgl() );
+          } // end of associated cluster loop
+       
+      AliTPCseed *seed = &(tTPC);
+      fSeedArray->Add(seed);
+     
+      unsigned int step = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
+      currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + step );  
+
+      }// end of vector track loop           
+  } // end of loop over blocks of merged tracks  
+  
+  HLTInfo("Number of reconstructed tracks %d, number of produced seeds %d\n", nTracks, fSeedArray->GetEntries());
 
  
   //----------- loop over output of global esd converter ----------------//
@@ -216,61 +371,58 @@ Int_t AliHLTTPCCalibTimeComponent::ProcessCalibration( const AliHLTComponentEven
   // In this loop we access the AliESDevent that was produced by the HLT and is stored in memory. There should exist 1 object 
   // of type kAliHLTDataTypeESDObject per event.
  
-  for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iter != NULL; iter = (TObject*)GetNextInputObject()){   
+  TObject *iterOb = NULL; 
+  for(iterOb = (TObject*)GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iterOb != NULL; iterOb = (TObject*)GetNextInputObject()){   
       
-    if(GetDataType(iter) != (kAliHLTDataTypeESDObject | kAliHLTDataOriginOut)) continue;
+      if(GetDataType(iterOb) != (kAliHLTDataTypeESDObject | kAliHLTDataOriginOut)) continue;
             
-    fESDevent = dynamic_cast<AliESDEvent*>(iter);
-    fESDevent->GetStdContent();
-    
-    //fESDevent->SetTimeStamp(1256910155);
-              
-    HLTDebug("# Seeds: %i\n", fSeedArray->GetEntriesFast()); // access of the info from the previous loop over the AliTPCseed array
-    
-    fCal->UpdateEventInfo(fESDevent);  
-        
-    for(Int_t i=0; i<fSeedArray->GetEntriesFast(); i++){  // loop over TClonesArray    
-        
-       AliTPCseed *seed = (AliTPCseed*)fSeedArray->UncheckedAt(i);                    
-        fESDtrack = fESDevent->GetTrack(i);
-       if(!fESDtrack || !seed) continue; 
-
-       if(fESDtrack->GetID() != seed->GetLabel()) { 
-          HLTWarning("Mismatch of track id between seed and ESD track: %i, %i\n", fESDtrack->GetID(), seed->GetLabel());
-          continue;            
-       }
-       
-       //printf("kelly time calib dedx before update: %f, P: %f\n", seed->CookdEdx(0.02,0.6), seed->P());
-        
-       fCal->RefitTrack(fESDtrack, seed, GetBz()); // update AliESDtrack and AliTPCseed info, acccording to Marian's request
-       
-       //printf("kelly time calib dedx after update: %f\n", seed->CookdEdx(0.02,0.6)); 
-        
-       AliTPCseed *seedCopy = new AliTPCseed(*seed, kTRUE); 
-       fESDtrack->AddCalibObject(seedCopy);  // add the AliTPCseed as a friend track to the AliESDtrack (to be accessed in TPC/AliTPCcalibTime.cxx)              
+      fESDevent = dynamic_cast<AliESDEvent*>(iterOb);
+      fESDevent->GetStdContent();    
+                 
+      HLTInfo("Number of seeds: %i\n", fSeedArray->GetEntriesFast()); // access of the info from the previous loop over the AliTPCseed array        
+   
+      fCal->UpdateEventInfo(fESDevent);     
+      for(Int_t i=0; i<fSeedArray->GetEntriesFast(); i++){  // loop over TObjArray with seeds
+        
+         AliTPCseed *seed = (AliTPCseed*)fSeedArray->UncheckedAt(i);                    
+          fESDtrack = fESDevent->GetTrack(i);
+         if(!fESDtrack || !seed) continue; 
+
+          //if(fESDtrack->GetID() != seed->GetLabel()) { 
+          //   HLTWarning("Mismatch of track id between seed and ESD track: %i, %i\n", fESDtrack->GetID(), seed->GetLabel());
+          //   continue;           
+          //}
+         
+         if(seed->GetNumberOfClusters()==0) continue;      
+         fCal->RefitTrack(fESDtrack, seed, GetBz()); // update AliESDtrack and AliTPCseed info, acccording to Marian's request
+              
+         AliTPCseed *seedCopy = new AliTPCseed(*seed, kTRUE); 
+         fESDtrack->AddCalibObject(seedCopy);  // add the AliTPCseed as a friend track to the AliESDtrack (to be accessed in TPC/AliTPCcalibTime.cxx)              
        
-       //fESDfriendTrack = const_cast<AliESDfriendTrack*>(fESDtrack->GetFriendTrack());        
-   }
+         //fESDfriendTrack = const_cast<AliESDfriendTrack*>(fESDtrack->GetFriendTrack());        
+      }
   } 
   
-  if(!fCalibTime){ // create the calibration object that will call the offline functions
-  
-     Int_t startTime = fESDevent->GetTimeStamp()-60*60*1;  //Start time one hour before first event, will make precise cuts later.
-     Int_t   endTime = fESDevent->GetTimeStamp()+60*60*23; //End time 23 hours after first event.
-     fCalibTime = new AliTPCcalibTime("calibTime","time dependent Vdrift calibration", startTime, endTime, 20*60);
-     fCalibTime->SetStreamLevel(20);
-     fCalibTime->SetDebugLevel(20);
-     printf("fCalibTime = %i, startTime = %i, endTime = %i \n", fCalibTime!=0, startTime, endTime);
+  Int_t startTime = fESDevent->GetTimeStamp()-60*60*1;  //Start time one hour before first event, will make precise cuts later.
+  Int_t   endTime = fESDevent->GetTimeStamp()+60*60*23; //End time 23 hours after first event.
+  // create the calibration object that will call the offline functions
+  fCalibTime = new AliTPCcalibTime("calibTime","time dependent Vdrift calibration", startTime, endTime, 20*60);
+  if(!fCalibTime){
+     printf("fCalibTime pointer is NULL\n");
+     return 0;
   }
   
+  fCalibTime->SetStreamLevel(20);
+  fCalibTime->SetDebugLevel(20);
+  printf("fCalibTime = %i, startTime = %i, endTime = %i \n", fCalibTime!=0, startTime, endTime);
   fESDfriend = new AliESDfriend();
   fESDevent->GetESDfriend(fESDfriend);
   fESDevent->SetESDfriend(fESDfriend);
   fESDevent->AddObject(fESDfriend); 
-  // create the AliESDfriend and add it to the event, now both the friend tracks and the friends are available for the offline functions to be called
+   // create the AliESDfriend and add it to the event, now both the friend tracks and the friends are available for the offline functions to be called
 
   fCalibTime->UpdateEventInfo(fESDevent); // needed for getting the run number and time stamp information correct on the offline side
-  fCalibTime->Process(fESDevent);         // first offline function called
+  fCalibTime->Process(fESDevent);         // first offline function called
   
   // delete fESDfriend;
   
@@ -356,7 +508,7 @@ Int_t AliHLTTPCCalibTimeComponent::ShipDataToFXS( const AliHLTComponentEventData
   THnSparse *hist = NULL;
   while((hist = (THnSparseF*)iterator->Next())){
        
-         if(!hist) continue;
+         //if(!hist) continue;
          hist->Print();
          hist->GetAxis(0)->SetRange(startTimeBin, endTimeBin);
          hist->GetAxis(1)->SetRange(startPtBin,   endPtBin);
@@ -454,10 +606,6 @@ Int_t AliHLTTPCCalibTimeComponent::ShipDataToFXS( const AliHLTComponentEventData
 
   static AliHLTReadoutList rdList(AliHLTReadoutList::kTPC);
   
-  // the vdriftArray is pushed to the HLT-FXSsubscriber 
-  PushToFXS( (TObject*)vdriftArray, "TPC", "TIMEDRIFT", rdList.Buffer() );
-  //PushToFXS( (TObject*)vdriftArray, "TPC", "Time");
 
   TFile *file = TFile::Open("vdrift.root", "RECREATE");
   vdriftArray->Write();
@@ -468,7 +616,10 @@ Int_t AliHLTTPCCalibTimeComponent::ShipDataToFXS( const AliHLTComponentEventData
   fCalibTime->Write();
   file->Close();
   delete file;
-
+  // the vdriftArray is pushed to the HLT-FXSsubscriber 
+  PushToFXS( (TObject*)vdriftArray, "TPC", "TIMEDRIFT", &rdList );
   //Should array be deleted now?
   //  if(vdriftArray){
   //      vdriftArray.Clear();