]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/offline/AliHLTTPCOfflineTrackerComponent.cxx
work on the TPC offline wrappers (Jacek)
[u/mrichter/AliRoot.git] / HLT / TPCLib / offline / AliHLTTPCOfflineTrackerComponent.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: 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"
28 #include "AliVParticle.h"
29 #include "AliCDBManager.h"
30 #include "AliCDBEntry.h"
31 #include "AliGeomManager.h"
32 #include "AliMagFMaps.h"
33 #include "AliTPCParam.h"
34 #include "AliTPCParamSR.h"
35 #include "AliTPCtrackerMI.h"
36 #include "AliTPCClustersRow.h"
37 #include "AliESDEvent.h"
38 #include "AliESDfriend.h"
39 #include "AliHLTTPCDefinitions.h"
40
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTTPCOfflineTrackerComponent)
43
44 AliHLTTPCOfflineTrackerComponent::AliHLTTPCOfflineTrackerComponent() : AliHLTProcessor(),
45 fGeometryFileName(""),
46 fTPCGeomParam(0),
47 fTracker(0),
48 fESD(0),
49 fESDfriend(0)
50 {
51   // Default constructor
52   fGeometryFileName = getenv("ALICE_ROOT");
53   fGeometryFileName += "/HLT/TPCLib/offline/geometry.root";
54 }
55
56 AliHLTTPCOfflineTrackerComponent::~AliHLTTPCOfflineTrackerComponent()
57 {
58   // see header file for class documentation
59 }
60
61 const char* AliHLTTPCOfflineTrackerComponent::GetComponentID()
62 {
63   // see header file for class documentation
64   return "TPCOfflineTracker";
65 }
66
67 void AliHLTTPCOfflineTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
68 {
69   // get input data type
70   list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
71 }
72
73 AliHLTComponentDataType AliHLTTPCOfflineTrackerComponent::GetOutputDataType()
74 {
75   // create output data type
76   return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
77 }
78
79 void AliHLTTPCOfflineTrackerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
80 {
81   // get output data size
82   constBase = 2000000;
83   inputMultiplier = 1;
84 }
85
86 AliHLTComponent* AliHLTTPCOfflineTrackerComponent::Spawn()
87 {
88   // create instance of the component
89   return new AliHLTTPCOfflineTrackerComponent;
90 }
91
92 int AliHLTTPCOfflineTrackerComponent::DoInit( int argc, const char** argv )
93 {
94   // init configuration 
95   //
96   int iResult=0;
97 #ifdef HAVE_NOT_TPCOFFLINE_REC
98   HLTFatal("AliRoot version > v4-13-Release required");
99   return -ENOSYS;
100 #endif
101
102   TString argument="";
103   TString configuration=""; 
104   int bMissingParam=0;
105
106   // loop over input parameters
107   for (int i=0; i<argc && iResult>=0; i++) {
108     argument=argv[i];
109     if (argument.IsNull()) continue;
110
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
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
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  
148   // TPC geometry parameters
149   fTPCGeomParam = new AliTPCParamSR;
150   if (fTPCGeomParam) {
151     fTPCGeomParam->ReadGeoMatrices();
152   }
153
154   // Init tracker
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();
162
163     // add ESD friend
164     fESDfriend = new AliESDfriend();
165     if(fESDfriend) fESD->AddObject(fESDfriend);
166   }
167
168   if (!fTracker || !fESD || !fTPCGeomParam) {
169     HLTError("failed creating internal objects");
170     iResult=-ENOMEM;
171   }
172
173   if (iResult>=0) {
174     // read the default CDB entries
175     iResult=Reconfigure(NULL, NULL);
176   }
177
178   return iResult;
179 }
180
181 int AliHLTTPCOfflineTrackerComponent::DoDeinit()
182 {
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;
188   //Note: fESD is owner of fESDfriends
189
190   return 0;
191 }
192
193 int AliHLTTPCOfflineTrackerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
194 {
195   // tracker function
196   HLTInfo("DoEvent processing data");
197
198   int iResult=0;
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);  
211
212   if (fTracker && fESD) {
213       // loop over input data blocks: TObjArrays of clusters
214       for (TObject *pObj = (TObject *)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/,"TObjArray",0);
215          pObj !=0 && iResult>=0;
216          pObj = (TObject *)GetNextInputObject(0)) {
217       clusterArray = dynamic_cast<TObjArray*>(pObj);
218       if (!clusterArray) continue;
219
220       HLTInfo("load %d cluster rows from block %s 0x%08x", clusterArray->GetEntries(), DataType2Text(GetDataType(pObj)).c_str(), GetSpecification(pObj));
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;
228 #ifndef HAVE_NOT_TPCOFFLINE_REC
229       fTracker->LoadClusters(clusterArray);
230 #endif //HAVE_NOT_TPCOFFLINE_REC
231     }// end loop over input objects
232
233     // set magnetic field for the ESD, assumes correct initialization of
234     // the field map
235     fESD->SetMagneticField(AliTracker::GetBz());
236
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
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);
247
248     // send data
249     PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
250
251     // reset ESDs
252     fESD->Reset();
253
254   } else {
255     HLTError("component not initialized");
256     iResult=-ENOMEM;
257   }
258
259   return iResult;
260 }
261
262 int 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
278       if (argument.CompareTo("-solenoidBz")==0) {
279         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
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;
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
322 int AliHLTTPCOfflineTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
323 {
324   // see header file for class documentation
325   int iResult=0;
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   
348   return iResult;
349 }