]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMergerComponent.cxx
adding new library libAliHLTGlobal for global HLT components; adding global track...
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalTrackMergerComponent.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: Jacek Otwinowski <Jacek.Otwinowski@gsi.de>            *
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   AliHLTGlobalTrackMergerComponent.cxx
20     @author Jacek Otwinowski
21     @date   
22     @brief  HLT global track merger component.
23 */
24
25 using namespace std;
26 #include <climits>
27 #include <cassert>
28 #include "AliHLTTPCTransform.h"
29 #include "AliHLTTPCGlobalMerger.h"
30 #include "AliHLTTPCVertex.h"
31 #include "AliHLTTPCVertexData.h"
32 #include "AliHLTTPCTrack.h"
33
34 //#include "AliHLTTPCSpacePointData.h"
35 //#include "AliHLTTPCClusterDataFormat.h"
36 #include "AliHLTTPCTrackletDataFormat.h"
37 #include "AliHLTTPCTrackSegmentData.h"
38 #include "AliHLTTPCTrackArray.h"
39 #include "AliHLTTPCDefinitions.h"
40 #include "AliHLTTRDDefinitions.h"
41 #include <cstdlib>
42 #include <cerrno>
43
44 #include "AliESDEvent.h"
45 #include "AliTracker.h"
46 #include "AliTRDtrackV1.h"
47 #include "AliHLTGlobalTrackMerger.h"
48
49 #include "AliHLTGlobalTrackMergerComponent.h"
50
51 /** ROOT macro for the implementation of ROOT specific class methods */
52 ClassImp(AliHLTGlobalTrackMergerComponent);
53
54 //_____________________________________________________________________________
55 AliHLTGlobalTrackMergerComponent::AliHLTGlobalTrackMergerComponent() : AliHLTProcessor(), 
56   fGlobalTrackMerger(0), 
57   fESD(0)
58 {
59 }
60
61 //_____________________________________________________________________________
62 AliHLTGlobalTrackMergerComponent::~AliHLTGlobalTrackMergerComponent()
63 {
64   // see header file for class documentation
65 }
66
67 //_____________________________________________________________________________
68 const char* AliHLTGlobalTrackMergerComponent::GetComponentID()
69 {
70   // see header file for class documentation
71   return "GlobalTrackMerger";
72 }
73
74 //_____________________________________________________________________________
75 void AliHLTGlobalTrackMergerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
76 {
77   // see header file for class documentation
78   list.clear();
79   list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
80   list.push_back( AliHLTTRDDefinitions::fgkTRDSATracksDataType );
81 }
82
83 //_____________________________________________________________________________
84 AliHLTComponentDataType AliHLTGlobalTrackMergerComponent::GetOutputDataType()
85 {
86   // see header file for class documentation
87   return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC;
88 }
89
90 //_____________________________________________________________________________
91 void AliHLTGlobalTrackMergerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
92 {
93   // see header file for class documentation
94   // XXX TODO: Find more realistic values.
95   constBase = 20000;
96   inputMultiplier = 1.0;
97 }
98
99 //_____________________________________________________________________________
100 AliHLTComponent* AliHLTGlobalTrackMergerComponent::Spawn()
101 {
102   // see header file for class documentation
103   return new AliHLTGlobalTrackMergerComponent;
104 }
105
106 //_____________________________________________________________________________
107 void AliHLTGlobalTrackMergerComponent::SetMergerParameters(Double_t maxy,Double_t maxz,Double_t maxkappa,Double_t maxpsi,Double_t maxtgl)
108 {
109   // see header file for class documentation
110   fGlobalTrackMerger->SetParameter( maxy, maxz, maxkappa, maxpsi, maxtgl );
111 }
112
113 //_____________________________________________________________________________
114 int AliHLTGlobalTrackMergerComponent::DoInit( int /*argc*/, const char** /*argv*/ )
115 {
116   // see header file for class documentation
117   int iResult = 0;
118   
119   // Init merger
120   fGlobalTrackMerger = new AliHLTGlobalTrackMerger();
121   
122   // output of the component
123   fESD = new AliESDEvent();
124   if (fESD) {
125      fESD->CreateStdContent();
126   }
127
128   if (!fGlobalTrackMerger || !fESD ) {
129      HLTError("failed creating internal objects");
130      iResult=-ENOMEM;
131      return iResult;
132   }
133
134   SetMergerParameters();
135
136   return iResult;
137 }
138
139 //_____________________________________________________________________________
140 int AliHLTGlobalTrackMergerComponent::DoDeinit()
141 {
142   // see header file for class documentation
143   if(fGlobalTrackMerger) delete fGlobalTrackMerger; fGlobalTrackMerger =0;
144   if(fESD) delete fESD; fESD = 0;
145   return 0;
146 }
147
148 //_____________________________________________________________________________
149 int AliHLTGlobalTrackMergerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
150                                               AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* /*outputPtr*/, 
151                                               AliHLTUInt32_t& /*size*/, AliHLTComponentBlockDataList& /*outputBlocks*/ )
152 {
153   //
154   // global track merger function
155   // takes TRD and TPC tracks and merges them
156   //
157   HLTInfo("DoEvent processing data");
158
159   // see header file for class documentation
160   int iResult=0;
161
162   if(!fGlobalTrackMerger || !fESD) {
163     HLTError("component not initialized");
164     iResult=-ENOMEM;
165     return iResult;
166   }
167
168   if(!blocks) {
169     HLTError("no blocks");
170     iResult=-EINVAL;
171     return iResult;
172   }
173
174   const AliHLTComponentBlockData* iter=0;
175   AliHLTTPCTrackletData* inPtr=0;
176   Bool_t bIsTRDTrackDataBlock=kFALSE;
177   Bool_t bIsTPCTrackDataBlock=kFALSE;
178   TClonesArray *aTRDTracks=0;
179   Int_t minSlice = INT_MAX, maxSlice = 0;
180   Int_t slice;
181
182   unsigned long ndx;
183   for ( ndx = 0; ndx < evtData.fBlockCnt && iResult>=0; ndx++ )
184   {
185       iter = blocks+ndx;
186       bIsTRDTrackDataBlock=kFALSE;
187       bIsTPCTrackDataBlock=kFALSE;
188
189       // check if TPC or TRD tracks
190       if(!(bIsTRDTrackDataBlock=(iter->fDataType==AliHLTTRDDefinitions::fgkTRDSATracksDataType)) &&
191          !(bIsTPCTrackDataBlock=(iter->fDataType==AliHLTTPCDefinitions::fgkTracksDataType))) {
192         continue;
193       }
194
195       // collect TRD tracks from all SM
196       // one TClonesArray of tracks per SM
197       if(bIsTRDTrackDataBlock) 
198       {
199         for (TObject *pObj = (TObject *)GetFirstInputObject(AliHLTTRDDefinitions::fgkTRDSATracksDataType,"TClonesArray",0);
200           pObj !=0 && iResult>=0;
201           pObj = (TObject *)GetNextInputObject(0)) {
202           aTRDTracks = dynamic_cast<TClonesArray*>(pObj);
203           if (!aTRDTracks) continue;
204
205           HLTDebug("reading block %d, trdTracks %d", ndx, aTRDTracks->GetEntriesFast());
206
207           // load TRD tracks by global track merger 
208           if (fGlobalTrackMerger->LoadTracks(aTRDTracks,fESD) == kFALSE) {
209              HLTError("Cannot load TRD tracks");
210              iResult=-ENOMEM;
211              return iResult;
212           }
213         }
214         aTRDTracks->Delete();
215       } 
216       
217       // collect TPC tracks from whole TPC
218       if (bIsTPCTrackDataBlock) 
219       {
220         slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
221         if(slice<minSlice) minSlice = slice;
222         if(slice>maxSlice) maxSlice = slice;
223         
224         //minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
225         //maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
226
227         AliHLTTPCTrackArray tracks;
228         inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
229
230         HLTDebug("reading block %d (slice %d): %d tracklets", ndx, slice, inPtr->fTrackletCnt);
231
232         // read TPC track segments from memory
233         if((iResult=tracks.FillTracksChecked(inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, -1/*global track*/, 0/*don't rotate*/))>=0) {
234
235           // load TPC tracks by  global track merger
236           if (fGlobalTrackMerger->LoadTracks(&tracks,fESD) == kFALSE) {
237              HLTError("Cannot load TPC tracks");
238              iResult=-ENOMEM;
239              return iResult;
240           }
241        }
242      }
243    }
244
245    // set magnetic field 
246    fESD->SetMagneticField(AliTracker::GetBz());
247
248    // merge tracks
249    Bool_t isMerged = fGlobalTrackMerger->Merge(fESD);
250    if(!isMerged) {
251      HLTWarning("No merged tracks");
252    }
253
254    // try to propagate all tracks to DCA to primary vertex
255    fGlobalTrackMerger->PropagateTracksToDCA(fESD);
256
257    // calculate specification
258    // AliHLTUInt32_t iSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, 0, 5 );
259    // HLTInfo("minSlice %d, maxSlice %d", minSlice, maxSlice);
260
261    // send output data
262    //PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
263    PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC);
264
265    // reset fESD
266    fESD->Reset();
267   
268 return iResult;
269 }
270
271