]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/offline/AliHLTTPCOfflineTrackerComponent.cxx
work on the TPC offline wrappers (Jacek)
[u/mrichter/AliRoot.git] / HLT / TPCLib / offline / AliHLTTPCOfflineTrackerComponent.cxx
CommitLineData
1ac82ce6 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: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* *
9//* Permission to use, copy, modify and distribute this software and its *
10//* documentation strictly for non-commercial purposes is hereby granted *
11//* without fee, provided that the above copyright notice appears in all *
12//* copies and that both the copyright notice and this permission notice *
13//* appear in the supporting documentation. The authors make no claims *
14//* about the suitability of this software for any purpose. It is *
15//* provided "as is" without express or implied warranty. *
16//**************************************************************************
17
18/** @file AliHLTTPCOfflineTrackerComponent.cxx
19 @author Matthias Richter
20 @date
21 @brief Wrapper component to the TPC offline tracker
22*/
23
24#include "AliHLTTPCOfflineTrackerComponent.h"
25#include "TString.h"
26#include "TObjArray.h"
27#include "TObjString.h"
e642ae99 28#include "AliVParticle.h"
29#include "AliCDBManager.h"
30#include "AliCDBEntry.h"
31#include "AliGeomManager.h"
32#include "AliMagFMaps.h"
aa40a4a1 33#include "AliTPCParam.h"
34#include "AliTPCParamSR.h"
35#include "AliTPCtrackerMI.h"
36#include "AliTPCClustersRow.h"
37#include "AliESDEvent.h"
e642ae99 38#include "AliESDfriend.h"
aa40a4a1 39#include "AliHLTTPCDefinitions.h"
1ac82ce6 40
41/** ROOT macro for the implementation of ROOT specific class methods */
42ClassImp(AliHLTTPCOfflineTrackerComponent)
43
aa40a4a1 44AliHLTTPCOfflineTrackerComponent::AliHLTTPCOfflineTrackerComponent() : AliHLTProcessor(),
e642ae99 45fGeometryFileName(""),
aa40a4a1 46fTPCGeomParam(0),
47fTracker(0),
e642ae99 48fESD(0),
49fESDfriend(0)
1ac82ce6 50{
e642ae99 51 // Default constructor
52 fGeometryFileName = getenv("ALICE_ROOT");
53 fGeometryFileName += "/HLT/TPCLib/offline/geometry.root";
1ac82ce6 54}
55
56AliHLTTPCOfflineTrackerComponent::~AliHLTTPCOfflineTrackerComponent()
57{
58 // see header file for class documentation
59}
60
61const char* AliHLTTPCOfflineTrackerComponent::GetComponentID()
62{
63 // see header file for class documentation
64 return "TPCOfflineTracker";
65}
66
67void AliHLTTPCOfflineTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
68{
aa40a4a1 69 // get input data type
70 list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
1ac82ce6 71}
72
73AliHLTComponentDataType AliHLTTPCOfflineTrackerComponent::GetOutputDataType()
74{
aa40a4a1 75 // create output data type
76 return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
1ac82ce6 77}
78
79void AliHLTTPCOfflineTrackerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
80{
aa40a4a1 81 // get output data size
82 constBase = 2000000;
e642ae99 83 inputMultiplier = 1;
1ac82ce6 84}
85
86AliHLTComponent* AliHLTTPCOfflineTrackerComponent::Spawn()
87{
aa40a4a1 88 // create instance of the component
1ac82ce6 89 return new AliHLTTPCOfflineTrackerComponent;
90}
91
92int AliHLTTPCOfflineTrackerComponent::DoInit( int argc, const char** argv )
93{
aa40a4a1 94 // init configuration
95 //
1ac82ce6 96 int iResult=0;
c03e064d 97#ifdef HAVE_NOT_TPCOFFLINE_REC
98 HLTFatal("AliRoot version > v4-13-Release required");
99 return -ENOSYS;
aa40a4a1 100#endif
1ac82ce6 101
102 TString argument="";
103 TString configuration="";
104 int bMissingParam=0;
e642ae99 105
106 // loop over input parameters
1ac82ce6 107 for (int i=0; i<argc && iResult>=0; i++) {
108 argument=argv[i];
109 if (argument.IsNull()) continue;
110
e642ae99 111 if (argument.CompareTo("-geometry")==0) {
112 if ((bMissingParam=(++i>=argc))) break;
113
114 HLTInfo("got \'-geometry\' argument: %s", argv[i]);
115 fGeometryFileName = argv[i];
116 HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
117
118 // the remaining arguments are treated as configuration
119 } else {
120 if (!configuration.IsNull()) configuration+=" ";
121 configuration+=argument;
122 }
123 } // end loop
124
1ac82ce6 125 if (bMissingParam) {
126 HLTError("missing parameter for argument %s", argument.Data());
127 iResult=-EINVAL;
128 }
129
130 if (iResult>=0 && !configuration.IsNull()) {
131 iResult=Configure(configuration.Data());
132 } else {
133 iResult=Reconfigure(NULL, NULL);
134 }
135
e642ae99 136 //
137 // initialisation
138 //
139
140 // Load geometry
141 HLTInfo("Geometry file %s",fGeometryFileName.c_str());
142 AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
143 if((AliGeomManager::GetGeometry()) == 0) {
144 HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
145 iResult=-EINVAL;
146 }
147
aa40a4a1 148 // TPC geometry parameters
149 fTPCGeomParam = new AliTPCParamSR;
150 if (fTPCGeomParam) {
151 fTPCGeomParam->ReadGeoMatrices();
152 }
153
e642ae99 154 // Init tracker
aa40a4a1 155 fTracker = new AliTPCtrackerMI(fTPCGeomParam);
156
157 // AliESDEvent event needed by AliTPCtrackerMI
158 // output of the component
159 fESD = new AliESDEvent();
160 if (fESD) {
161 fESD->CreateStdContent();
aa40a4a1 162
e642ae99 163 // add ESD friend
164 fESDfriend = new AliESDfriend();
165 if(fESDfriend) fESD->AddObject(fESDfriend);
488581c1 166 }
167
aa40a4a1 168 if (!fTracker || !fESD || !fTPCGeomParam) {
169 HLTError("failed creating internal objects");
170 iResult=-ENOMEM;
171 }
172
e642ae99 173 if (iResult>=0) {
174 // read the default CDB entries
175 iResult=Reconfigure(NULL, NULL);
176 }
177
1ac82ce6 178 return iResult;
179}
180
181int AliHLTTPCOfflineTrackerComponent::DoDeinit()
182{
aa40a4a1 183 // deinit configuration
184
185 if(fTPCGeomParam) delete fTPCGeomParam; fTPCGeomParam = 0;
186 if(fTracker) delete fTracker; fTracker = 0;
187 if(fESD) delete fESD; fESD = 0;
e642ae99 188 //Note: fESD is owner of fESDfriends
aa40a4a1 189
1ac82ce6 190 return 0;
191}
192
193int AliHLTTPCOfflineTrackerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
194{
aa40a4a1 195 // tracker function
196 HLTInfo("DoEvent processing data");
1ac82ce6 197
aa40a4a1 198 int iResult=0;
e642ae99 199 TObjArray *clusterArray=0;
200 int slice, patch;
201
202 const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC);
203 if(!pBlock) {
204 HLTError("Cannot get first data block 0x%08x ",pBlock);
205 iResult=-ENOMEM; return iResult;
206 }
207 int minSlice=AliHLTTPCDefinitions::GetMinSliceNr(pBlock->fSpecification);
208 int maxSlice=AliHLTTPCDefinitions::GetMaxSliceNr(pBlock->fSpecification);
209 int minPatch=AliHLTTPCDefinitions::GetMinPatchNr(pBlock->fSpecification);
210 int maxPatch=AliHLTTPCDefinitions::GetMaxPatchNr(pBlock->fSpecification);
aa40a4a1 211
212 if (fTracker && fESD) {
e642ae99 213 // loop over input data blocks: TObjArrays of clusters
214 for (TObject *pObj = (TObject *)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/,"TObjArray",0);
aa40a4a1 215 pObj !=0 && iResult>=0;
216 pObj = (TObject *)GetNextInputObject(0)) {
217 clusterArray = dynamic_cast<TObjArray*>(pObj);
218 if (!clusterArray) continue;
aa40a4a1 219
220 HLTInfo("load %d cluster rows from block %s 0x%08x", clusterArray->GetEntries(), DataType2Text(GetDataType(pObj)).c_str(), GetSpecification(pObj));
e642ae99 221 slice=AliHLTTPCDefinitions::GetMinSliceNr(GetSpecification(pObj));
222 patch=AliHLTTPCDefinitions::GetMinPatchNr(GetSpecification(pObj));
223
224 if(slice < minSlice) minSlice=slice;
225 if(slice > maxSlice) maxSlice=slice;
226 if(patch < minPatch) minPatch=patch;
227 if(patch > maxPatch) maxPatch=patch;
c03e064d 228#ifndef HAVE_NOT_TPCOFFLINE_REC
aa40a4a1 229 fTracker->LoadClusters(clusterArray);
c03e064d 230#endif //HAVE_NOT_TPCOFFLINE_REC
aa40a4a1 231 }// end loop over input objects
232
488581c1 233 // set magnetic field for the ESD, assumes correct initialization of
234 // the field map
235 fESD->SetMagneticField(AliTracker::GetBz());
236
aa40a4a1 237 // run tracker
238 fTracker->Clusters2Tracks(fESD);
239 fTracker->UnloadClusters();
240
241 Int_t nTracks = fESD->GetNumberOfTracks();
242 HLTInfo("Number of tracks %d", nTracks);
243
e642ae99 244 // calculate specification from the specification of input data blocks
245 AliHLTUInt32_t iSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
246 HLTInfo("minSlice %d, maxSlice %d, minPatch %d, maxPatch %d", minSlice, maxSlice, minPatch, maxPatch);
aa40a4a1 247
e642ae99 248 // send data
249 PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
aa40a4a1 250
251 // reset ESDs
252 fESD->Reset();
e642ae99 253
aa40a4a1 254 } else {
255 HLTError("component not initialized");
256 iResult=-ENOMEM;
257 }
258
259 return iResult;
1ac82ce6 260}
261
262int AliHLTTPCOfflineTrackerComponent::Configure(const char* arguments)
263{
264 // see header file for class documentation
265 int iResult=0;
266 if (!arguments) return iResult;
267
268 TString allArgs=arguments;
269 TString argument;
270 int bMissingParam=0;
271
272 TObjArray* pTokens=allArgs.Tokenize(" ");
273 if (pTokens) {
274 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
275 argument=((TObjString*)pTokens->At(i))->GetString();
276 if (argument.IsNull()) continue;
277
e642ae99 278 if (argument.CompareTo("-solenoidBz")==0) {
1ac82ce6 279 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
e642ae99 280 // TODO: check if there is common functionality in the AliMagF* classes
281 float SolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
282 if (SolenoidBz<kAlmost0Field) SolenoidBz=kAlmost0Field;
283 float factor=1.;
284 int map=AliMagFMaps::k2kG;
285 if (SolenoidBz<3.) {
286 map=AliMagFMaps::k2kG;
287 factor=SolenoidBz/2;
288 } else if (SolenoidBz>=3. && SolenoidBz<4.5) {
289 map=AliMagFMaps::k4kG;
290 factor=SolenoidBz/4;
291 } else {
292 map=AliMagFMaps::k5kG;
293 factor=SolenoidBz/5;
294 }
295 // the magnetic field map is not supposed to change
296 // field initialization should be done once in the beginning
297 // TODO: does the factor need adjustment?
298 const AliMagF* currentMap=AliTracker::GetFieldMap();
299 if (!currentMap) {
300 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 2, 1., 10., map);
301 AliTracker::SetFieldMap(field,kTRUE);
302 HLTInfo("Solenoid Field set to: %f map %d", SolenoidBz, map);
303 } else if (currentMap->Map()!=map) {
304 HLTWarning("omitting request to override field map %s with %s", currentMap->Map(), map);
305 }
306 continue;
1ac82ce6 307 } else {
308 HLTError("unknown argument %s", argument.Data());
309 iResult=-EINVAL;
310 break;
311 }
312 }
313 delete pTokens;
314 }
315 if (bMissingParam) {
316 HLTError("missing parameter for argument %s", argument.Data());
317 iResult=-EINVAL;
318 }
319 return iResult;
320}
321
e642ae99 322int AliHLTTPCOfflineTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
1ac82ce6 323{
324 // see header file for class documentation
325 int iResult=0;
e642ae99 326 const char* path=kAliHLTCDBSolenoidBz;
327 const char* defaultNotify="";
328 if (cdbEntry) {
329 path=cdbEntry;
330 defaultNotify=" (default)";
331 }
332 if (path) {
333 HLTDebug("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
334 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
335 if (pEntry) {
336 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
337 if (pString) {
338 HLTDebug("received configuration object string: \'%s\'", pString->GetString().Data());
339 iResult=Configure(pString->GetString().Data());
340 } else {
341 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
342 }
343 } else {
344 HLTError("can not fetch object \"%s\" from CDB", path);
345 }
346 }
347
1ac82ce6 348 return iResult;
349}