]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/calibration/AliHLTTPCCalibSeedMakerComponent.cxx
Fixing coverity defects 24797 and 24795
[u/mrichter/AliRoot.git] / HLT / TPCLib / calibration / 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 #include <map>
26
27 #include "AliHLTTPCCalibSeedMakerComponent.h"
28 #include "AliHLTTPCTransform.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include "AliHLTTPCOfflineCluster.h"
31 #include "AliHLTTPCSpacePointData.h"
32 #include "AliHLTTPCTrackletDataFormat.h"
33 #include "AliHLTExternalTrackParam.h"
34 #include "AliHLTGlobalBarrelTrack.h"
35 #include "AliHLTTrackMCLabel.h"
36
37 #include "AliTPCclusterMI.h"
38 #include "AliTPCseed.h"
39 #include "AliTPCcalibDB.h"
40 #include "AliTPCParam.h"
41
42 #include "AliRieman.h"
43
44 #include "AliCDBEntry.h"
45 #include "AliCDBManager.h"
46 #include "AliCDBStorage.h"
47
48 #include <cstdlib>
49 #include <cerrno>
50
51 #include "TObjArray.h"
52 #include "TClonesArray.h"
53 #include "TObject.h"
54 #include "TFile.h"
55 #include "TH2F.h"
56
57 #include <sys/time.h>
58
59 using namespace std;
60
61 ClassImp(AliHLTTPCCalibSeedMakerComponent) //ROOT macro for the implementation of ROOT specific class methods
62
63 AliHLTTPCCalibSeedMakerComponent::AliHLTTPCCalibSeedMakerComponent()
64     :    
65     fTPCGeomParam(0)
66    ,fSeedArray(0x0)
67    ,fdEdx(0x0)
68 {
69   // see header file for class documentation
70   // or
71   // refer to README to build package
72   // or
73   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt  
74   for( int i=0; i<fkNPartition; i++ ){
75        fPartitionClusters[i]  = 0;    
76        fNPartitionClusters[i] = 0;    
77   }
78 }
79
80 AliHLTTPCCalibSeedMakerComponent::~AliHLTTPCCalibSeedMakerComponent() { 
81 // see header file for class documentation  
82   
83   for( int i=0; i<fkNPartition; i++ ){
84        delete[] fPartitionClusters[i];
85   }
86 }
87
88 const char* AliHLTTPCCalibSeedMakerComponent::GetComponentID() { 
89 // see header file for class documentation
90
91   return "TPCCalibSeedMaker";
92 }
93
94 void AliHLTTPCCalibSeedMakerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
95 // see header file for class documentation
96
97   list.clear(); 
98   list.push_back( AliHLTTPCDefinitions::fgkClustersDataType   );
99   list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC   );
100   list.push_back( kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC );
101 }
102
103 AliHLTComponentDataType AliHLTTPCCalibSeedMakerComponent::GetOutputDataType(){ 
104 // see header file for class documentation
105
106   return kAliHLTMultipleDataType;
107   //return kAliHLTDataTypeTObjArray;
108 }
109
110 int AliHLTTPCCalibSeedMakerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){ 
111 // see header file for class documentation
112
113   tgtList.clear();
114   tgtList.push_back( kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC );
115   tgtList.push_back( kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC );
116   return tgtList.size();
117 }
118
119 void AliHLTTPCCalibSeedMakerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
120 // see header file for class documentation
121
122   constBase=2000;
123   inputMultiplier=2.0; // to be estimated
124 }
125
126 AliHLTComponent* AliHLTTPCCalibSeedMakerComponent::Spawn() { 
127 // see header file for class documentation
128
129   return new AliHLTTPCCalibSeedMakerComponent();
130 }
131         
132 int AliHLTTPCCalibSeedMakerComponent::DoInit( int /*argc*/, const char** /*argv*/ ) { 
133 // see header file for class documentation
134  
135   fTPCGeomParam = AliTPCcalibDB::Instance()->GetParameters();
136   if(!fTPCGeomParam) HLTError("TPC Parameters are not loaded.");
137   
138   fSeedArray = new TObjArray(10000);  
139   //fSeedArray->SetOwner(kTRUE);
140   
141   fdEdx = new TH2F("fdEdx","energy loss vs. momentum", 400, -200, 200, 300, 0, 300);
142   
143   return 0;
144
145 } // end DoInit()
146
147 int AliHLTTPCCalibSeedMakerComponent::DoDeinit() { 
148 // see header file for class documentation  
149   
150   if(fTPCGeomParam) delete fTPCGeomParam; fTPCGeomParam = NULL;   
151   if(fSeedArray)    delete fSeedArray;    fSeedArray    = NULL; 
152   if(fdEdx)         delete fdEdx;         fdEdx         = NULL;
153
154   return 0;
155 }
156
157 int AliHLTTPCCalibSeedMakerComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
158 // see header file for class documentation
159  
160   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR)) return 0;
161
162   int nInputClusters = 0;
163   fSeedArray->Clear();
164   
165   for(Int_t i=0; i<fkNPartition; i++){
166       delete[] fPartitionClusters[i];    
167       fPartitionClusters[i]  = 0;
168       fNPartitionClusters[i] = 0;    
169   }
170
171
172   // ---------- Access to clusters --------------------//
173   
174   for(const AliHLTComponentBlockData *iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
175       
176       if(iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType) continue;
177     
178       Int_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
179       Int_t partition = AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
180     
181       Int_t slicepartition = slice*6+partition;
182       
183       if(slicepartition > fkNPartition){
184          HLTWarning("Wrong header of TPC cluster data, slice %d, partition %d", slice, partition );
185          continue;
186       }
187       
188       AliHLTTPCClusterData *inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
189       nInputClusters += inPtrSP->fSpacePointCnt;
190
191       delete[] fPartitionClusters[slicepartition];
192       fPartitionClusters[slicepartition]  = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
193       fNPartitionClusters[slicepartition] = inPtrSP->fSpacePointCnt;
194     
195       // create  offline clusters out of the HLT clusters
196       // todo: check which cluster information is really needed for the dEdx
197
198     for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
199       AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
200       AliTPCclusterMI *c = fPartitionClusters[slicepartition]+i;
201       c->SetX(chlt->fX);
202       c->SetY(chlt->fY);
203       c->SetZ(chlt->fZ);
204       c->SetSigmaY2(chlt->fSigmaY2);
205       c->SetSigmaYZ( 0 );
206       c->SetSigmaZ2(chlt->fSigmaZ2);
207       c->SetQ( chlt->fCharge );
208       c->SetMax( chlt->fQMax );
209       Int_t sector, row;
210       Float_t padtime[3] = {0,chlt->fY,chlt->fZ};
211       AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
212       AliHLTTPCTransform::Local2Raw( padtime, sector, row);
213       c->SetDetector( sector );
214       c->SetRow( row );
215       c->SetPad( (Int_t) padtime[1] );
216       c->SetTimeBin( (Int_t) padtime[2] );
217     }      
218   } // end of loop over blocks of clusters
219
220  
221  
222   
223   // ------------ loop over the MC labels -----------------//
224   
225   std::map<int,int> mcLabels;
226   for(const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC); pBlock!=NULL; pBlock=GetNextInputBlock()){
227    
228       AliHLTTrackMCData *dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
229     
230       if(sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize){     
231         for(UInt_t il=0; il<dataPtr->fCount; il++){  
232             AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
233             mcLabels[lab.fTrackID]  = lab.fMCLabel;
234             HLTDebug("MC labels, track ID:  %d, %d\n", lab.fMCLabel, lab.fTrackID);
235         }
236       } 
237       else {
238         HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information", DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, 
239                    dataPtr->fCount, pBlock->fSize);
240       }
241   } // end of loop over MC label blocks
242   
243   
244   
245  
246  
247   //------------------ loop over track data blocks --------------------//
248
249   int nTracks = 0;
250   for(const AliHLTComponentBlockData *pBlock = GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); pBlock != NULL; pBlock = GetNextInputBlock()){
251       
252       AliHLTTracksData *dataPtr = (AliHLTTracksData*) pBlock->fPtr;
253       //int nTracks = dataPtr->fCount;
254       nTracks = dataPtr->fCount;
255     
256       AliHLTExternalTrackParam *currTrack = dataPtr->fTracklets;     
257       
258       for(Int_t itr=0; itr<nTracks && ( (AliHLTUInt8_t *)currTrack < ((AliHLTUInt8_t *) pBlock->fPtr)+pBlock->fSize); itr++){
259     
260          // create an offline track
261          AliHLTGlobalBarrelTrack gb(*currTrack);
262          AliTPCseed tTPC;
263          tTPC.Set( gb.GetX(), gb.GetAlpha(), gb.GetParameter(), gb.GetCovariance() );
264                     
265          Int_t mcLabel = -1;
266          if( mcLabels.find(gb.TrackID())!=mcLabels.end() ) mcLabel = mcLabels[gb.TrackID()];      
267          tTPC.SetLabel(mcLabel);
268             
269          // set the clusters 
270              
271          for(UInt_t ic=0; ic<currTrack->fNPoints; ic++){        
272             
273              tTPC.SetNumberOfClusters(currTrack->fNPoints);
274           
275              UInt_t id      = currTrack->fPointIDs[ic];      
276              int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
277              int iPartition = AliHLTTPCSpacePointData::GetPatch(id);
278              int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
279         
280              if(iSlice<0 || iSlice>36 || iPartition<0 || iPartition>5){
281                  HLTError("Corrupted TPC cluster Id: slice %d, partition %d, cluster %d", iSlice, iPartition, iCluster);
282                  continue;
283              }
284         
285              AliTPCclusterMI *patchClusters = fPartitionClusters[iSlice*6 + iPartition];
286              if(!patchClusters){
287                 HLTError("Clusters are missed for slice %d, partition %d", iSlice, iPartition );
288                 continue;
289              }
290         
291              if(iCluster >= fNPartitionClusters[iSlice*6 + iPartition]){
292                 HLTError("TPC slice %d, partition %d: ClusterID==%d >= N Cluaters==%d ", iSlice, iPartition,iCluster, fNPartitionClusters[iSlice*6 + iPartition] );
293                 continue;
294              }
295         
296              AliTPCclusterMI *c = &(patchClusters[iCluster]);           
297              int sec = c->GetDetector();
298              int row = c->GetRow();
299              if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
300         
301              tTPC.SetClusterPointer(row, c);    
302         
303              AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
304              //tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
305              Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
306              angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.; 
307              point.SetAngleY( angle2 );
308              point.SetAngleZ( tTPC.GetTgl() );
309          } // end of associated cluster loop
310
311       // Cook dEdx
312            
313       AliTPCseed *seed = &(tTPC);      
314       fSeedArray->AddAt( seed, TMath::Abs(seed->GetLabel()) );
315       fdEdx->Fill( seed->P()*seed->Charge(), seed->CookdEdx(0.02, 0.6) );
316           
317       unsigned int step = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
318       currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + step );  
319
320       }// end of vector track loop           
321   } // end of loop over blocks of merged tracks 
322   
323   HLTDebug("Number of reconstructed tracks %d, number of produced seeds %d\n", nTracks, fSeedArray->GetEntries());  
324   
325   PushBack((TObject*)fSeedArray, kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC, 0x0);
326   PushBack((TObject*)fdEdx, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC, 0x0);
327          
328   return 0;
329 } // end DoEvent()