]>
Commit | Line | Data |
---|---|---|
a1408c4b | 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 | //* 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 AliHLTGlobalEsdConverterComponent.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief Global ESD converter component. | |
23 | */ | |
24 | ||
25 | // see header file for class documentation | |
26 | // or | |
27 | // refer to README to build package | |
28 | // or | |
29 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
30 | ||
31 | #include <cassert> | |
32 | #include "AliHLTGlobalEsdConverterComponent.h" | |
33 | #include "AliHLTGlobalBarrelTrack.h" | |
34 | #include "AliHLTExternalTrackParam.h" | |
093b64dc | 35 | #include "AliHLTTrackMCLabel.h" |
a1408c4b | 36 | #include "AliESDEvent.h" |
37 | #include "AliESDtrack.h" | |
38 | #include "AliCDBEntry.h" | |
39 | #include "AliCDBManager.h" | |
40 | #include "TTree.h" | |
41 | #include "TList.h" | |
42 | ||
43 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
44 | ClassImp(AliHLTGlobalEsdConverterComponent) | |
45 | ||
46 | AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent() | |
47 | : AliHLTProcessor() | |
48 | , fESD(NULL) | |
49 | , fSolenoidBz(5) | |
50 | , fWriteTree(0) | |
093b64dc | 51 | , fVerbosity(0) |
a1408c4b | 52 | { |
53 | // see header file for class documentation | |
54 | // or | |
55 | // refer to README to build package | |
56 | // or | |
57 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
58 | } | |
59 | ||
60 | AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent() | |
61 | { | |
62 | // see header file for class documentation | |
63 | if (fESD) delete fESD; | |
64 | fESD=NULL; | |
65 | } | |
66 | ||
67 | int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments) | |
68 | { | |
69 | // see header file for class documentation | |
70 | int iResult=0; | |
71 | if (!arguments) return iResult; | |
72 | ||
73 | TString allArgs=arguments; | |
74 | TString argument; | |
75 | int bMissingParam=0; | |
76 | ||
77 | TObjArray* pTokens=allArgs.Tokenize(" "); | |
78 | if (pTokens) { | |
79 | for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) { | |
80 | argument=((TObjString*)pTokens->At(i))->GetString(); | |
81 | if (argument.IsNull()) continue; | |
82 | ||
83 | if (argument.CompareTo("-solenoidBz")==0) { | |
84 | if ((bMissingParam=(++i>=pTokens->GetEntries()))) break; | |
85 | HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data()); | |
86 | fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof(); | |
87 | continue; | |
88 | } else { | |
89 | HLTError("unknown argument %s", argument.Data()); | |
90 | iResult=-EINVAL; | |
91 | break; | |
92 | } | |
93 | } | |
94 | delete pTokens; | |
95 | } | |
96 | if (bMissingParam) { | |
97 | HLTError("missing parameter for argument %s", argument.Data()); | |
98 | iResult=-EINVAL; | |
99 | } | |
100 | ||
101 | return iResult; | |
102 | } | |
103 | ||
104 | int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId) | |
105 | { | |
106 | // see header file for class documentation | |
107 | int iResult=0; | |
108 | const char* path=kAliHLTCDBSolenoidBz; | |
109 | const char* defaultNotify=""; | |
110 | if (cdbEntry) { | |
111 | path=cdbEntry; | |
112 | defaultNotify=" (default)"; | |
113 | } | |
114 | if (path) { | |
115 | HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>"); | |
116 | AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/); | |
117 | if (pEntry) { | |
118 | TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject()); | |
119 | if (pString) { | |
120 | HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data()); | |
121 | iResult=Configure(pString->GetString().Data()); | |
122 | } else { | |
123 | HLTError("configuration object \"%s\" has wrong type, required TObjString", path); | |
124 | } | |
125 | } else { | |
126 | HLTError("can not fetch object \"%s\" from CDB", path); | |
127 | } | |
128 | } | |
129 | ||
130 | return iResult; | |
131 | } | |
132 | ||
133 | void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) | |
134 | { | |
135 | // see header file for class documentation | |
136 | list.push_back(kAliHLTDataTypeTrack); | |
137 | list.push_back(kAliHLTDataTypeTrackMC); | |
138 | } | |
139 | ||
140 | AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType() | |
141 | { | |
142 | // see header file for class documentation | |
7a9de6d1 | 143 | return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut; |
a1408c4b | 144 | } |
145 | ||
146 | void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier) | |
147 | { | |
148 | // see header file for class documentation | |
149 | constBase=2000000; | |
150 | inputMultiplier=10.0; | |
151 | } | |
152 | ||
153 | int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv) | |
154 | { | |
155 | // see header file for class documentation | |
156 | int iResult=0; | |
157 | TString argument=""; | |
158 | int bMissingParam=0; | |
159 | for (int i=0; i<argc && iResult>=0; i++) { | |
160 | argument=argv[i]; | |
161 | if (argument.IsNull()) continue; | |
162 | ||
163 | // -notree | |
164 | if (argument.CompareTo("-notree")==0) { | |
165 | fWriteTree=0; | |
166 | ||
167 | // -tree | |
168 | } else if (argument.CompareTo("-tree")==0) { | |
169 | fWriteTree=1; | |
170 | ||
171 | } else { | |
172 | HLTError("unknown argument %s", argument.Data()); | |
173 | break; | |
174 | } | |
175 | } | |
176 | if (bMissingParam) { | |
177 | HLTError("missing parameter for argument %s", argument.Data()); | |
178 | iResult=-EINVAL; | |
179 | } | |
180 | ||
181 | if (iResult>=0) { | |
182 | iResult=Reconfigure(NULL, NULL); | |
183 | } | |
184 | ||
185 | if (iResult>=0) { | |
186 | fESD = new AliESDEvent; | |
187 | if (fESD) { | |
188 | fESD->CreateStdContent(); | |
189 | } else { | |
190 | iResult=-ENOMEM; | |
191 | } | |
192 | } | |
193 | ||
194 | return iResult; | |
195 | } | |
196 | ||
197 | int AliHLTGlobalEsdConverterComponent::DoDeinit() | |
198 | { | |
199 | // see header file for class documentation | |
200 | if (fESD) delete fESD; | |
201 | fESD=NULL; | |
202 | ||
203 | return 0; | |
204 | } | |
205 | ||
206 | int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, | |
207 | AliHLTComponentTriggerData& /*trigData*/) | |
208 | { | |
209 | // see header file for class documentation | |
210 | int iResult=0; | |
211 | if (!fESD) return -ENODEV; | |
212 | ||
213 | AliESDEvent* pESD = fESD; | |
214 | ||
215 | pESD->Reset(); | |
216 | pESD->SetMagneticField(fSolenoidBz); | |
217 | ||
218 | TTree* pTree = NULL; | |
219 | if (fWriteTree) | |
220 | pTree = new TTree("esdTree", "Tree with HLT ESD objects"); | |
221 | ||
222 | if (pTree) { | |
223 | pTree->SetDirectory(0); | |
224 | } | |
225 | ||
226 | if ((iResult=ProcessBlocks(pTree, pESD))>0) { | |
227 | // TODO: set the specification correctly | |
228 | if (pTree) { | |
229 | // the esd structure is written to the user info and is | |
230 | // needed in te ReadFromTree method to read all objects correctly | |
231 | pTree->GetUserInfo()->Add(pESD); | |
232 | pESD->WriteToTree(pTree); | |
7a9de6d1 | 233 | iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0); |
a1408c4b | 234 | } else { |
7a9de6d1 | 235 | iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0); |
a1408c4b | 236 | } |
237 | } | |
238 | if (pTree) { | |
239 | // clear user info list to prevent objects from being deleted | |
240 | pTree->GetUserInfo()->Clear(); | |
241 | delete pTree; | |
242 | } | |
243 | return iResult; | |
244 | } | |
245 | ||
246 | int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD) | |
247 | { | |
248 | // see header file for class documentation | |
249 | ||
250 | int iResult=0; | |
251 | int iAddedDataBlocks=0; | |
252 | ||
253 | // Barrel tracking | |
254 | ||
255 | // in the first attempt this component reads the TPC tracks and updates in the | |
256 | // second step from the ITS tracks | |
093b64dc | 257 | |
258 | ||
259 | // first read MC information (if present) | |
260 | std::map<int,int> mcLabels; | |
261 | ||
262 | for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC); | |
263 | pBlock!=NULL; pBlock=GetNextInputBlock()) { | |
264 | AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr ); | |
265 | if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) { | |
266 | for( unsigned int il=0; il<dataPtr->fCount; il++ ){ | |
267 | AliHLTTrackMCLabel &lab = dataPtr->fLabels[il]; | |
268 | mcLabels[lab.fTrackID] = lab.fMCLabel; | |
269 | } | |
270 | } else { | |
271 | HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information", | |
272 | DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, | |
273 | dataPtr->fCount, pBlock->fSize); | |
274 | } | |
275 | } | |
276 | ||
a1408c4b | 277 | std::vector<int> trackIdESD2TPCmap; // map esd index -> tpc index |
278 | ||
279 | for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); | |
280 | pBlock!=NULL; pBlock=GetNextInputBlock()) { | |
281 | vector<AliHLTGlobalBarrelTrack> tracks; | |
282 | if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) { | |
283 | for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin(); | |
284 | element!=tracks.end(); element++) { | |
285 | Float_t points[4] = { | |
286 | element->GetX(), | |
287 | element->GetY(), | |
288 | element->GetLastPointX(), | |
289 | element->GetLastPointY() | |
290 | }; | |
093b64dc | 291 | |
292 | Int_t mcLabel = -1; | |
293 | if( mcLabels.find(element->TrackID())!=mcLabels.end() ) | |
294 | mcLabel = mcLabels[element->TrackID()]; | |
295 | element->SetLabel( mcLabel ); | |
296 | ||
a1408c4b | 297 | AliESDtrack iotrack; |
298 | iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin); | |
299 | iotrack.SetTPCPoints(points); | |
300 | ||
301 | pESD->AddTrack(&iotrack); | |
093b64dc | 302 | if (fVerbosity>0) element->Print(); |
a1408c4b | 303 | } |
093b64dc | 304 | HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size()); |
a1408c4b | 305 | iAddedDataBlocks++; |
306 | } else if (iResult<0) { | |
093b64dc | 307 | HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d", |
308 | DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult); | |
a1408c4b | 309 | } |
310 | } | |
311 | ||
312 | // ITS updated tracks | |
313 | /* | |
314 | int nESDTracks = pESD->GetNumberOfTracks(); | |
315 | ||
316 | // create map of tpc->esd track indices | |
317 | ||
318 | int *trackIdTPC2ESDmap = new int[ nTPCTracks ]; | |
319 | { | |
320 | for( int i=0; i<nTPCTracks; i++ ) trackIdTPC2ESDmap[i] = -1; | |
321 | for( unsigned int i=0; i<trackIdESD2TPCmap.size(); i++ ){ | |
322 | int tpcId = trackIdESD2TPCmap[i]; | |
323 | if( tpcId>=0 && tpcId<nTPCTracks ) trackIdTPC2ESDmap[tpcId] = i; | |
324 | } | |
325 | } | |
326 | ||
327 | for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) { | |
328 | iter = blocks+ndx; | |
329 | if(iter->fDataType == fgkITSTracksDataType ) { | |
330 | AliHLTITSTrackDataHeader *inPtr = reinterpret_cast<AliHLTITSTrackDataHeader*>( iter->fPtr ); | |
331 | int nTracks = inPtr->fTrackletCnt; | |
332 | for( int itr=0; itr<nTracks; itr++ ){ | |
333 | AliHLTITSTrackData &tr = inPtr->fTracks[itr]; | |
334 | AliHLTITSTrack tITS( tr.fTrackParam ); | |
335 | int ncl=0; | |
336 | for( int il=0; il<6; il++ ){ | |
337 | if( tr.fClusterIds[il]>=0 ) tITS.SetClusterIndex(ncl++, tr.fClusterIds[il]); | |
338 | } | |
339 | tITS.SetNumberOfClusters( ncl ); | |
340 | int tpcId = tr.fTPCId; | |
341 | if( tpcId<0 || tpcId>=nTPCTracks ) continue; | |
342 | int esdID = trackIdTPC2ESDmap[tpcId]; | |
343 | if( esdID<0 || esdID>=nESDTracks ) continue; | |
344 | AliESDtrack *tESD = pESD->GetTrack( esdID ); | |
345 | if( tESD ) tESD->UpdateTrackParams( &tITS, AliESDtrack::kITSin ); | |
346 | } | |
347 | } | |
348 | } | |
349 | delete[] trackIdTPC2ESDmap; | |
350 | ||
351 | // primary vertex & V0's | |
352 | ||
353 | //AliHLTVertexer vertexer; | |
354 | //vertexer.SetESD( pESD ); | |
355 | //vertexer.FindPrimaryVertex(); | |
356 | //vertexer.FindV0s(); | |
357 | */ | |
358 | if (iAddedDataBlocks>0 && pTree) { | |
359 | pTree->Fill(); | |
360 | } | |
361 | ||
362 | if (iResult>=0) iResult=iAddedDataBlocks; | |
363 | return iResult; | |
364 | } |