3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
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 //**************************************************************************
18 /** @file AliHLTTPCOfflineTrackerComponent.cxx
19 @author Matthias Richter
21 @brief Wrapper component to the TPC offline tracker
24 #include "AliHLTTPCOfflineTrackerComponent.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"
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTTPCOfflineTrackerComponent)
44 AliHLTTPCOfflineTrackerComponent::AliHLTTPCOfflineTrackerComponent() : AliHLTProcessor(),
45 fGeometryFileName(""),
51 // Default constructor
52 fGeometryFileName = getenv("ALICE_ROOT");
53 fGeometryFileName += "/HLT/TPCLib/offline/geometry.root";
56 AliHLTTPCOfflineTrackerComponent::~AliHLTTPCOfflineTrackerComponent()
58 // see header file for class documentation
61 const char* AliHLTTPCOfflineTrackerComponent::GetComponentID()
63 // see header file for class documentation
64 return "TPCOfflineTracker";
67 void AliHLTTPCOfflineTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
69 // get input data type
70 list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
73 AliHLTComponentDataType AliHLTTPCOfflineTrackerComponent::GetOutputDataType()
75 // create output data type
76 return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
79 void AliHLTTPCOfflineTrackerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
81 // get output data size
86 AliHLTComponent* AliHLTTPCOfflineTrackerComponent::Spawn()
88 // create instance of the component
89 return new AliHLTTPCOfflineTrackerComponent;
92 int AliHLTTPCOfflineTrackerComponent::DoInit( int argc, const char** argv )
97 #ifdef HAVE_NOT_TPCOFFLINE_REC
98 HLTFatal("AliRoot version > v4-13-Release required");
103 TString configuration="";
106 // loop over input parameters
107 for (int i=0; i<argc && iResult>=0; i++) {
109 if (argument.IsNull()) continue;
111 if (argument.CompareTo("-geometry")==0) {
112 if ((bMissingParam=(++i>=argc))) break;
114 HLTInfo("got \'-geometry\' argument: %s", argv[i]);
115 fGeometryFileName = argv[i];
116 HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
118 // the remaining arguments are treated as configuration
120 if (!configuration.IsNull()) configuration+=" ";
121 configuration+=argument;
126 HLTError("missing parameter for argument %s", argument.Data());
130 if (iResult>=0 && !configuration.IsNull()) {
131 iResult=Configure(configuration.Data());
133 iResult=Reconfigure(NULL, NULL);
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());
148 // TPC geometry parameters
149 fTPCGeomParam = new AliTPCParamSR;
151 fTPCGeomParam->ReadGeoMatrices();
155 fTracker = new AliTPCtrackerMI(fTPCGeomParam);
157 // AliESDEvent event needed by AliTPCtrackerMI
158 // output of the component
159 fESD = new AliESDEvent();
161 fESD->CreateStdContent();
164 fESDfriend = new AliESDfriend();
165 if(fESDfriend) fESD->AddObject(fESDfriend);
168 if (!fTracker || !fESD || !fTPCGeomParam) {
169 HLTError("failed creating internal objects");
174 // read the default CDB entries
175 iResult=Reconfigure(NULL, NULL);
181 int AliHLTTPCOfflineTrackerComponent::DoDeinit()
183 // deinit configuration
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
193 int AliHLTTPCOfflineTrackerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
196 HLTInfo("DoEvent processing data");
199 TObjArray *clusterArray=0;
202 const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC);
204 HLTError("Cannot get first data block 0x%08x ",pBlock);
205 iResult=-ENOMEM; return iResult;
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);
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;
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));
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
233 // set magnetic field for the ESD, assumes correct initialization of
235 fESD->SetMagneticField(AliTracker::GetBz());
238 fTracker->Clusters2Tracks(fESD);
239 fTracker->UnloadClusters();
241 Int_t nTracks = fESD->GetNumberOfTracks();
242 HLTInfo("Number of tracks %d", nTracks);
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);
249 PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
255 HLTError("component not initialized");
262 int AliHLTTPCOfflineTrackerComponent::Configure(const char* arguments)
264 // see header file for class documentation
266 if (!arguments) return iResult;
268 TString allArgs=arguments;
272 TObjArray* pTokens=allArgs.Tokenize(" ");
274 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
275 argument=((TObjString*)pTokens->At(i))->GetString();
276 if (argument.IsNull()) continue;
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;
284 int map=AliMagFMaps::k2kG;
286 map=AliMagFMaps::k2kG;
288 } else if (SolenoidBz>=3. && SolenoidBz<4.5) {
289 map=AliMagFMaps::k4kG;
292 map=AliMagFMaps::k5kG;
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();
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);
308 HLTError("unknown argument %s", argument.Data());
316 HLTError("missing parameter for argument %s", argument.Data());
322 int AliHLTTPCOfflineTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
324 // see header file for class documentation
326 const char* path=kAliHLTCDBSolenoidBz;
327 const char* defaultNotify="";
330 defaultNotify=" (default)";
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()*/);
336 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
338 HLTDebug("received configuration object string: \'%s\'", pString->GetString().Data());
339 iResult=Configure(pString->GetString().Data());
341 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
344 HLTError("can not fetch object \"%s\" from CDB", path);