]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCCalibSeedMakerComponent.cxx
- correct the number of points added to the Riemann fit
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCCalibSeedMakerComponent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        *
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no>          *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTTPCCalibSeedMakerComponent.cxx
20     @author Kalliopi Kanaki
21     @date   2009-07-08
22     @brief  
23 */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28
29 #include "AliHLTTPCCalibSeedMakerComponent.h"
30 #include "AliHLTTPCTransform.h"
31 #include "AliHLTTPCDefinitions.h"
32 #include "AliHLTTPCOfflineCluster.h"
33 #include "AliHLTTPCSpacePointData.h"
34 #include "AliHLTTPCTrackletDataFormat.h"
35 #include "AliHLTExternalTrackParam.h"
36 #include "AliHLTGlobalBarrelTrack.h"
37
38 #include "AliTPCclusterMI.h"
39 #include "AliTPCseed.h"
40 #include "AliTPCcalibDB.h"
41 #include "AliTPCParamSR.h"
42
43 #include "AliRieman.h"
44
45 #include "AliCDBEntry.h"
46 #include "AliCDBManager.h"
47 #include "AliCDBStorage.h"
48
49 #include <cstdlib>
50 #include <cerrno>
51
52 #include "TObjArray.h"
53 #include "TObject.h"
54 #include <sys/time.h>
55
56 ClassImp(AliHLTTPCCalibSeedMakerComponent) //ROOT macro for the implementation of ROOT specific class methods
57
58 AliHLTTPCCalibSeedMakerComponent::AliHLTTPCCalibSeedMakerComponent()
59     :    
60     fSpecification(0),
61     fMinSlice(35),
62     fMaxSlice(0),
63     fMinPartition(5),
64     fMaxPartition(0),
65     fTPCGeomParam(0),
66     fSeedArray(0)
67 {
68   // see header file for class documentation
69   // or
70   // refer to README to build package
71   // or
72   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 }
74
75 AliHLTTPCCalibSeedMakerComponent::~AliHLTTPCCalibSeedMakerComponent() { 
76 // see header file for class documentation
77
78 }
79
80 // Public functions to implement AliHLTComponent's interface.
81 // These functions are required for the registration process
82
83 const char* AliHLTTPCCalibSeedMakerComponent::GetComponentID() { 
84 // see header file for class documentation
85
86   return "TPCCalibSeedMaker";
87 }
88
89 void AliHLTTPCCalibSeedMakerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
90 // see header file for class documentation
91
92   list.clear(); 
93   list.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
94   //list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
95   list.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
96
97 }
98
99 AliHLTComponentDataType AliHLTTPCCalibSeedMakerComponent::GetOutputDataType(){ 
100 // see header file for class documentation
101
102   //return kAliHLTMultipleDataType;
103   return kAliHLTDataTypeTObjArray;
104 }
105
106 int AliHLTTPCCalibSeedMakerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){ 
107 // see header file for class documentation
108
109   tgtList.clear();
110   //tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeTPCSeed);
111   tgtList.push_back(kAliHLTDataTypeTObjArray);
112   return tgtList.size();
113 }
114
115 void AliHLTTPCCalibSeedMakerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
116 // see header file for class documentation
117
118   constBase=0;
119   inputMultiplier=2.0; // to be estimated
120 }
121
122 AliHLTComponent* AliHLTTPCCalibSeedMakerComponent::Spawn() { 
123 // see header file for class documentation
124
125   return new AliHLTTPCCalibSeedMakerComponent();
126 }
127         
128 int AliHLTTPCCalibSeedMakerComponent::DoInit( int /*argc*/, const char** /*argv*/ ) { 
129 // see header file for class documentation
130  
131   fTPCGeomParam = new AliTPCParamSR;
132   if(fTPCGeomParam) fTPCGeomParam->ReadGeoMatrices();  
133   
134   fSeedArray = new TObjArray;
135   fSeedArray->SetOwner(kTRUE);
136   return 0;
137
138 } // end DoInit()
139
140 int AliHLTTPCCalibSeedMakerComponent::DoDeinit() { 
141 // see header file for class documentation  
142   
143   if(fTPCGeomParam) delete fTPCGeomParam; fTPCGeomParam = NULL;          
144   if(fSeedArray)    delete fSeedArray;    fSeedArray    = NULL;          
145   return 0;
146 }
147
148 int AliHLTTPCCalibSeedMakerComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
149 // see header file for class documentation
150  
151   const AliHLTComponentBlockData *iter = NULL;      
152   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR)) return 0;
153
154   Int_t totalSpacePoints = 0;
155   Int_t usedSpacePoints  = 0;   
156   
157  
158   // ---------- Access to clusters --------------------//
159   
160   for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
161   
162       if(iter->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType) continue;
163
164       AliHLTUInt8_t minSlice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
165       AliHLTUInt8_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
166       
167       const AliHLTTPCClusterData *clusterData = (const AliHLTTPCClusterData*)iter->fPtr;
168       Int_t nSpacepoint = (Int_t)clusterData->fSpacePointCnt;   
169       
170       totalSpacePoints += nSpacepoint;
171       
172       AliHLTTPCSpacePointData *clusters = (AliHLTTPCSpacePointData*)clusterData->fSpacePoints; 
173       
174       if(fClustersArray[minSlice][minPartition] != NULL){
175          //delete(fClustersArray[minSlice][minPartition]);
176          fClustersArray[minSlice][minPartition] = NULL;
177       }
178       
179       // fill the array with AliHLTTPCSpacePointData pointers
180       // it will be used in the track loop to access information
181       // for the used clusters only
182       fClustersArray[minSlice][minPartition] = clusters;
183       fNSpacePoints[minSlice][minPartition]  = nSpacepoint;
184       
185       if(nSpacepoint==0) fClustersArray[minSlice][minPartition] = NULL;
186       
187   } // end of loop over blocks of clusters
188
189   HLTDebug("Total space points: %d", totalSpacePoints);
190    
191   
192   //------------------ Access to track data blocks --------------------//
193   
194   //TObjArray *offClusterArray = new TObjArray;
195   //offClusterArray->SetOwner(kTRUE);
196   //offClusterArray->Clear();
197   
198   fSeedArray->Clear();
199   
200   for(iter = GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputBlock()){ 
201   
202       if(iter->fDataType != (kAliHLTDataTypeTrack|kAliHLTDataOriginTPC)) continue; 
203      
204       AliHLTUInt8_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
205       AliHLTUInt8_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
206       
207       if( slice     < fMinSlice )     fMinSlice     = slice;
208       if( slice     > fMaxSlice )     fMaxSlice     = slice;
209       if( partition < fMinPartition ) fMinPartition = partition;
210       if( partition > fMaxPartition ) fMaxPartition = partition;
211       
212       
213       // create a vector of AliHLTGlobalBarrelTrack tracks from AliHLTTracksData
214       vector<AliHLTGlobalBarrelTrack> tracks;
215       AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(iter->fPtr), iter->fSize, tracks);      
216     
217       // loop over the elements(tracks) of the AliHLTGlobalBarrelTrack vector
218
219       for(vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();  element!=tracks.end(); element++){
220           
221           AliRieman rieman(element->GetNumberOfPoints());
222           rieman.Reset();    
223           AliTPCseed *seed = 0x0;
224           Double_t param[5]; for(Int_t i=0; i<5;  i++) param[i] = 0.;
225           Double_t cov[15];  for(Int_t i=0; i<15; i++) cov[i]   = 0.;
226           Double_t xmin  = 1000.;
227           Double_t alpha = 0.;
228
229           // calculate padrow radius (x - radius)
230           Double_t xrow[160]; for(Int_t i=0; i<160; i++) xrow[i] = 0.;
231           Int_t nrowlow = fTPCGeomParam->GetNRowLow();
232           Int_t nrowup  = fTPCGeomParam->GetNRowUp();
233
234           for (Int_t i=0;i<nrowlow;i++) xrow[i]         = fTPCGeomParam->GetPadRowRadiiLow(i);
235           for (Int_t i=0;i<nrowup;i++)  xrow[i+nrowlow] = fTPCGeomParam->GetPadRowRadiiUp(i);
236
237           // sector rotation angles
238           Double_t angle_in        = fTPCGeomParam->GetInnerAngle();
239           Double_t angle_shift_in  = fTPCGeomParam->GetInnerAngleShift();
240           Double_t angle_out       = fTPCGeomParam->GetOuterAngle();
241           Double_t angle_shift_out = fTPCGeomParam->GetOuterAngleShift();
242           
243           //offClusterArray->Clear();
244           
245           const UInt_t *hitnum = element->GetPoints(); // store the clusters on each track in an array and loop over them
246           for(UInt_t i=0; i<element->GetNumberOfPoints(); i++){
247               
248               // the id of the cluster contains information about the slice and partition it belongs too
249               // as well as its index (pos)          
250               UInt_t idTrack   = hitnum[i];
251               Int_t sliceTrack = (idTrack>>25) & 0x7f;
252               Int_t patchTrack = (idTrack>>22) & 0x7;
253               UInt_t pos       = idTrack&0x3fffff;
254               
255               // use the fClustersArray that was filled in the cluster loop
256               if( !fClustersArray[sliceTrack][patchTrack]    ) continue;
257               if(  fNSpacePoints[sliceTrack][patchTrack]<pos ) HLTError("Space point array out of boundaries!");
258               
259               // get the sector(detector) information
260               Int_t sector, row = -99;
261               AliHLTTPCTransform::Slice2Sector(sliceTrack, (fClustersArray[sliceTrack][patchTrack])[pos].fPadRow, sector, row);
262                        
263               // next line recalculates rows in the sector(ROC) system
264               //if(patchTrack>1) (fClustersArray[sliceTrack][patchTrack])[pos].fPadRow -= 63;//(Int_t)AliHLTTPCTransform::GetFirstRow(2);
265               
266               HLTDebug("slice %d, partition :%d, sector row: %d", sliceTrack, patchTrack, (fClustersArray[sliceTrack][patchTrack])[pos].fPadRow);
267                
268               // convert the HTL clusters to AliTPCclusterMI                  
269               AliHLTTPCOfflineCluster pConv;
270               AliTPCclusterMI *offClus = pConv.ConvertHLTToOffline((fClustersArray[sliceTrack][patchTrack])[pos]);            
271               offClus->SetDetector(sector);
272               usedSpacePoints++;
273               
274               //offClusterArray->Add(offClus);
275               
276               // the clusters are not sorted from max to min X              
277               rieman.AddPoint( offClus->GetX(),offClus->GetY(),offClus->GetZ(),TMath::Sqrt(offClus->GetSigmaY2()),TMath::Sqrt(offClus->GetSigmaZ2()) );    
278               
279               xmin = TMath::Min(xmin,xrow[offClus->GetRow()]); // min pad-row radius
280                       
281               if(sector<36){ 
282                  //xmin = TMath::Min(xmin,xrow[offClus->GetRow()]); // min pad-row radius
283                  alpha = angle_shift_in+angle_in*(sector%18);
284               } else {
285                  //xmin = TMath::Min(xmin,xrow[nrowlow+offClus->GetRow()]); // min pad-row radius
286                  alpha = angle_shift_out+angle_out*(sector%18);
287               }
288               //if(sector<36) HLTInfo("detector: %d, row: %d, xrow[row]: %f", sector, offClus->GetRow(), xrow[offClus->GetRow()]);
289               //else          HLTInfo("detector: %d, row: %d, xrow[row]: %f", sector, offClus->GetRow(), xrow[nrowlow+offClus->GetRow()]);
290           } // end of cluster loop
291
292           // creation of AliTPCseed by means of a Riemann fit
293           rieman.Update();
294           rieman.GetExternalParameters(xmin,param,cov);  
295           seed = new AliTPCseed(xmin,alpha,param,cov,0);
296          
297           // is it necessay to set the cluster pointers inside the seed??
298 //        for(Int_t j=0; j<offClusterArray->GetEntries(); j++)  { 
299 //                AliTPCclusterMI *cl = (AliTPCclusterMI*)offClusterArray->At(j);
300 //                if(cl) seed->SetClusterPointer(cl->GetRow(),cl);
301 //            }
302
303
304           HLTInfo("External track parameters: seed: 0x%08x, xmin: %f, alpha: %f, param[0]: %f, cov[0]: %f", seed, xmin, alpha, param[0], cov[0]);
305           fSeedArray->Add(seed);
306
307       }// end of vector track loop        
308   } // end of loop over blocks of merged tracks  
309   
310   HLTDebug("Used space points: %d", usedSpacePoints);
311   HLTDebug("Number of entries in fSeedArray: %d", fSeedArray->GetEntries());
312
313
314   fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( fMinSlice, fMaxSlice, fMinPartition, fMaxPartition );
315   //PushBack((TObject*)offClusterArray, kAliHLTDataTypeTObjArray, fSpecification);
316   PushBack((TObject*)fSeedArray,       kAliHLTDataTypeTObjArray, fSpecification);
317  
318   return 0;
319 } // end DoEvent()