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 Jacek Otwinowski & Matthias Richter
21 @brief Wrapper component to the TPC offline tracker
24 #include "AliHLTTPCOfflineTrackerComponent.h"
26 #include "TClonesArray.h"
27 #include "TObjArray.h"
28 #include "TObjString.h"
29 #include "AliVParticle.h"
30 #include "AliCDBManager.h"
31 #include "AliCDBEntry.h"
32 #include "AliGeomManager.h"
34 #include "AliTPCReconstructor.h"
35 #include "AliTPCParam.h"
36 #include "AliTPCRecoParam.h"
37 #include "AliTPCParamSR.h"
38 #include "AliTPCtrackerMI.h"
39 #include "AliTPCClustersRow.h"
40 #include "AliTPCseed.h"
41 #include "AliESDEvent.h"
42 #include "AliHLTTPCDefinitions.h"
44 /** ROOT macro for the implementation of ROOT specific class methods */
45 ClassImp(AliHLTTPCOfflineTrackerComponent)
47 AliHLTTPCOfflineTrackerComponent::AliHLTTPCOfflineTrackerComponent() : AliHLTProcessor(),
48 fGeometryFileName(""),
53 // Default constructor
54 fGeometryFileName = getenv("ALICE_ROOT");
55 fGeometryFileName += "/HLT/TPCLib/offline/geometry.root";
58 AliHLTTPCOfflineTrackerComponent::~AliHLTTPCOfflineTrackerComponent()
60 // see header file for class documentation
63 const char* AliHLTTPCOfflineTrackerComponent::GetComponentID()
65 // see header file for class documentation
66 return "TPCOfflineTracker";
69 void AliHLTTPCOfflineTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
71 // get input data type
72 list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
75 AliHLTComponentDataType AliHLTTPCOfflineTrackerComponent::GetOutputDataType()
77 // create output data type
78 return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
81 void AliHLTTPCOfflineTrackerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
83 // get output data size
88 AliHLTComponent* AliHLTTPCOfflineTrackerComponent::Spawn()
90 // create instance of the component
91 return new AliHLTTPCOfflineTrackerComponent;
94 int AliHLTTPCOfflineTrackerComponent::DoInit( int argc, const char** argv )
99 #ifdef HAVE_NOT_TPCOFFLINE_REC
100 HLTFatal("AliRoot version > v4-13-Release required");
105 TString configuration="";
108 // loop over input parameters
109 for (int i=0; i<argc && iResult>=0; i++) {
111 if (argument.IsNull()) continue;
113 if (argument.CompareTo("-geometry")==0) {
114 if ((bMissingParam=(++i>=argc))) break;
116 HLTInfo("got \'-geometry\' argument: %s", argv[i]);
117 fGeometryFileName = argv[i];
118 HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
120 // the remaining arguments are treated as configuration
122 if (!configuration.IsNull()) configuration+=" ";
123 configuration+=argument;
128 HLTError("missing parameter for argument %s", argument.Data());
132 if (iResult>=0 && !configuration.IsNull()) {
133 iResult=Configure(configuration.Data());
135 iResult=Reconfigure(NULL, NULL);
143 AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
144 if((AliGeomManager::GetGeometry()) == 0) {
145 HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
149 // TPC reconstruction parameters
150 AliTPCRecoParam * tpcRecoParam = AliTPCRecoParam::GetHLTParam();
152 tpcRecoParam->SetClusterSharing(kTRUE);
154 AliTPCReconstructor tpcReconstructor;
155 tpcReconstructor.SetRecoParam(tpcRecoParam);
158 // TPC geometry parameters
159 fTPCGeomParam = new AliTPCParamSR;
161 fTPCGeomParam->ReadGeoMatrices();
165 fTracker = new AliTPCtrackerMI(fTPCGeomParam);
167 // AliESDEvent event needed by AliTPCtrackerMI
168 // output of the component
169 fESD = new AliESDEvent();
171 fESD->CreateStdContent();
174 if (!fTracker || !fESD || !fTPCGeomParam) {
175 HLTError("failed creating internal objects");
180 // read the default CDB entries
181 iResult=Reconfigure(NULL, NULL);
187 int AliHLTTPCOfflineTrackerComponent::DoDeinit()
189 // deinit configuration
191 if(fTPCGeomParam) delete fTPCGeomParam; fTPCGeomParam = 0;
192 if(fTracker) delete fTracker; fTracker = 0;
193 if(fESD) delete fESD; fESD = 0;
198 int AliHLTTPCOfflineTrackerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
201 HLTInfo("DoEvent processing data");
204 TClonesArray *clusterArray=0;
207 const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC);
209 HLTError("Cannot get first data block 0x%08x ",pBlock);
210 iResult=-ENOMEM; return iResult;
212 int minSlice=AliHLTTPCDefinitions::GetMinSliceNr(pBlock->fSpecification);
213 int maxSlice=AliHLTTPCDefinitions::GetMaxSliceNr(pBlock->fSpecification);
214 int minPatch=AliHLTTPCDefinitions::GetMinPatchNr(pBlock->fSpecification);
215 int maxPatch=AliHLTTPCDefinitions::GetMaxPatchNr(pBlock->fSpecification);
217 if (fTracker && fESD) {
218 // loop over input data blocks: TClonesArrays of clusters
219 for (TObject *pObj = (TObject *)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/,"TClonesArray",0);
220 pObj !=0 && iResult>=0;
221 pObj = (TObject *)GetNextInputObject(0)) {
222 clusterArray = dynamic_cast<TClonesArray*>(pObj);
223 if (!clusterArray) continue;
225 HLTInfo("load %d clusters from block %s 0x%08x", clusterArray->GetEntries(), DataType2Text(GetDataType(pObj)).c_str(), GetSpecification(pObj));
226 slice=AliHLTTPCDefinitions::GetMinSliceNr(GetSpecification(pObj));
227 patch=AliHLTTPCDefinitions::GetMinPatchNr(GetSpecification(pObj));
229 if(slice < minSlice) minSlice=slice;
230 if(slice > maxSlice) maxSlice=slice;
231 if(patch < minPatch) minPatch=patch;
232 if(patch > maxPatch) maxPatch=patch;
233 #ifndef HAVE_NOT_TPCOFFLINE_REC
234 fTracker->LoadClusters(clusterArray);
235 #endif //HAVE_NOT_TPCOFFLINE_REC
237 clusterArray->Delete();
238 }// end loop over input objects
240 #ifndef HAVE_NOT_TPCOFFLINE_REC
241 // Load outer sectors
242 fTracker->LoadOuterSectors();
243 // Load inner sectors
244 fTracker->LoadInnerSectors();
247 // set magnetic field for the ESD, assumes correct initialization of
249 fESD->SetMagneticField(AliTracker::GetBz());
252 fTracker->Clusters2Tracks(fESD);
255 fTracker->UnloadClusters();
257 Int_t nTracks = fESD->GetNumberOfTracks();
258 HLTInfo("Number TPC tracks %d", nTracks);
260 // calculate specification from the specification of input data blocks
261 AliHLTUInt32_t iSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
262 HLTInfo("minSlice %d, maxSlice %d, minPatch %d, maxPatch %d", minSlice, maxSlice, minPatch, maxPatch);
265 PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
267 // reset ESDs and ESDs friends
271 HLTError("component not initialized");
278 int AliHLTTPCOfflineTrackerComponent::Configure(const char* arguments)
280 // see header file for class documentation
282 if (!arguments) return iResult;
284 TString allArgs=arguments;
288 TObjArray* pTokens=allArgs.Tokenize(" ");
290 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
291 argument=((TObjString*)pTokens->At(i))->GetString();
292 if (argument.IsNull()) continue;
294 if (argument.CompareTo("-solenoidBz")==0) {
295 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
296 // TODO: check if there is common functionality in the AliMagF* classes
297 float SolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
298 if (SolenoidBz<kAlmost0Field) SolenoidBz=kAlmost0Field;
299 float factor=SolenoidBz/5;
301 AliMagF::BMap_t map = AliMagF::k5kG;
305 } /*else if (SolenoidBz>=3. && SolenoidBz<4.5) {
306 map=AliMagFMaps::k4kG;
310 map=AliMagFMaps::k5kG;
313 // the magnetic field map is not supposed to change
314 // field initialization should be done once in the beginning
315 // TODO: does the factor need adjustment?
316 const AliMagF* currentMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
318 AliMagF* field = new AliMagF("MagneticFieldMap", "BMap", 2, 1., 1., 10., map);
319 TGeoGlobalMagField::Instance()->SetField(field);
320 HLTInfo("Solenoid Field set to: %f map %d", SolenoidBz, map);
321 } else if (currentMap->GetMapType()!=map) {
322 HLTWarning("omitting request to override field map %d with %d", currentMap->GetMapType(), map);
326 HLTError("unknown argument %s", argument.Data());
334 HLTError("missing parameter for argument %s", argument.Data());
340 int AliHLTTPCOfflineTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
342 // see header file for class documentation
344 const char* path=kAliHLTCDBSolenoidBz;
345 const char* defaultNotify="";
348 defaultNotify=" (default)";
351 if (chainId) {} // just to get rid of warning, can not comment argument due to debug message
352 HLTDebug("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
353 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
355 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
357 HLTDebug("received configuration object string: \'%s\'", pString->GetString().Data());
358 iResult=Configure(pString->GetString().Data());
360 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
363 HLTError("can not fetch object \"%s\" from CDB", path);