]>
Commit | Line | Data |
---|---|---|
649ab027 | 1 | /************************************************************************** |
2 | * This file is property of and copyright by the ALICE HLT Project * | |
3 | * All rights reserved. * | |
4 | * * | |
5 | * Primary Authors: * | |
6 | * Artur Szostak <artursz@iafrica.com> * | |
7 | * * | |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
1d8ae082 | 17 | // $Id: $ |
649ab027 | 18 | |
19 | /// | |
20 | /// @file AliHLTMUONESDMaker.cxx | |
21 | /// @author Artur Szostak <artursz@iafrica.com> | |
22 | /// @date 30 June 2008 | |
23 | /// @brief Implementation of the AliHLTMUONESDMaker component. | |
24 | /// | |
25 | /// The ESD maker component converts dHLT raw internal reconstructed information | |
26 | /// into AliESDEvent objects. | |
27 | /// | |
28 | ||
29 | #include "AliHLTMUONESDMaker.h" | |
30 | #include "AliHLTMUONEvent.h" | |
31 | #include "AliHLTMUONConstants.h" | |
32 | #include "AliHLTMUONUtils.h" | |
33 | #include "AliHLTMUONRecHit.h" | |
34 | #include "AliHLTMUONTriggerRecord.h" | |
35 | #include "AliHLTMUONMansoTrack.h" | |
36 | #include "AliHLTMUONDecision.h" | |
37 | #include "AliMUONConstants.h" | |
38 | #include "AliMUONVCluster.h" | |
39 | #include "AliESDEvent.h" | |
40 | #include "AliESDRun.h" | |
41 | #include "AliESDMuonTrack.h" | |
42 | #include "AliESDMuonCluster.h" | |
43 | #include "TClonesArray.h" | |
f064ef44 | 44 | #include "TList.h" |
649ab027 | 45 | #include <cmath> |
46 | #include <cassert> | |
47 | ||
48 | ||
49 | ClassImp(AliHLTMUONESDMaker); | |
50 | ||
51 | ||
52 | AliHLTMUONESDMaker::AliHLTMUONESDMaker() : | |
53 | AliHLTMUONProcessor(), | |
54 | fWarnForUnexpecedBlock(false), | |
73ed798e | 55 | fMakeMinimalESD(false), |
f064ef44 | 56 | fAddCustomData(false), |
57 | fMakeClonesArray(false), | |
58 | fMakeESDDataBlock(true) | |
649ab027 | 59 | { |
60 | /// Default constructor. | |
61 | } | |
62 | ||
63 | ||
64 | AliHLTMUONESDMaker::~AliHLTMUONESDMaker() | |
65 | { | |
66 | /// Default destructor. | |
67 | } | |
68 | ||
69 | ||
ffb64d3e | 70 | bool AliHLTMUONESDMaker::IgnoreArgument(const char* arg) const |
71 | { | |
72 | /// Return true if the argument is one of -cdbpath -run or -delaysetup | |
73 | /// to prevent the parent class from parsing these arguments in DoInit. | |
74 | ||
558cf470 | 75 | if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or |
76 | strcmp(arg, "-delaysetup") == 0) | |
ffb64d3e | 77 | { |
78 | return true; | |
79 | } | |
80 | else | |
81 | { | |
82 | return false; | |
83 | } | |
84 | } | |
85 | ||
86 | ||
649ab027 | 87 | int AliHLTMUONESDMaker::DoInit(int argc, const char** argv) |
88 | { | |
89 | /// Inherited from AliHLTComponent. | |
90 | /// Parses the command line parameters and initialises the component. | |
91 | ||
92 | HLTInfo("Initialising dHLT ESD maker component."); | |
ffb64d3e | 93 | |
94 | // Inherit the parents functionality. | |
95 | int result = AliHLTMUONProcessor::DoInit(argc, argv); | |
96 | if (result != 0) return result; | |
649ab027 | 97 | |
98 | fWarnForUnexpecedBlock = false; | |
99 | fMakeMinimalESD = false; | |
f064ef44 | 100 | fMakeClonesArray = false; |
101 | fMakeESDDataBlock = true; | |
649ab027 | 102 | |
103 | for (int i = 0; i < argc; i++) | |
104 | { | |
ffb64d3e | 105 | if (ArgumentAlreadyHandled(i, argv[i])) continue; |
106 | ||
649ab027 | 107 | if (strcmp(argv[i], "-make_minimal_esd") == 0) |
108 | { | |
109 | fMakeMinimalESD = true; | |
110 | continue; | |
111 | } | |
112 | ||
113 | if (strcmp(argv[i], "-warn_on_unexpected_block") == 0) | |
114 | { | |
115 | fWarnForUnexpecedBlock = true; | |
116 | continue; | |
117 | } | |
73ed798e | 118 | |
119 | if (strcmp(argv[i], "-add_rootified_objects") == 0) | |
120 | { | |
121 | fAddCustomData = true; | |
122 | continue; | |
123 | } | |
649ab027 | 124 | |
f064ef44 | 125 | if (strcmp(argv[i], "-makeclonesarray") == 0) |
126 | { | |
127 | fMakeClonesArray = true; | |
128 | continue; | |
129 | } | |
130 | ||
131 | if (strcmp(argv[i], "-makeonlyclonesarray") == 0) | |
132 | { | |
133 | fMakeMinimalESD = true; | |
134 | fMakeClonesArray = true; | |
135 | fMakeESDDataBlock = false; | |
136 | continue; | |
137 | } | |
138 | ||
649ab027 | 139 | HLTError("Unknown option '%s'.", argv[i]); |
140 | return -EINVAL; | |
141 | } | |
142 | ||
143 | return 0; | |
144 | } | |
145 | ||
146 | ||
147 | int AliHLTMUONESDMaker::DoDeinit() | |
148 | { | |
149 | /// Inherited from AliHLTComponent. Performs a cleanup of the component. | |
150 | ||
151 | HLTInfo("Deinitialising dHLT ESD maker component."); | |
152 | return 0; | |
153 | } | |
154 | ||
155 | ||
156 | const char* AliHLTMUONESDMaker::GetComponentID() | |
157 | { | |
158 | /// Inherited from AliHLTComponent. Returns the component ID. | |
159 | ||
160 | return AliHLTMUONConstants::ESDMakerId(); | |
161 | } | |
162 | ||
163 | ||
164 | AliHLTComponentDataType AliHLTMUONESDMaker::GetOutputDataType() | |
f064ef44 | 165 | { |
166 | /// Inherited from AliHLTComponent. Returns kAliHLTMultipleDataType. | |
167 | /// Refer to GetOutputDataTypes for all returned data types. | |
168 | ||
169 | return kAliHLTMultipleDataType; | |
170 | } | |
171 | ||
172 | ||
173 | int AliHLTMUONESDMaker::GetOutputDataTypes(AliHLTComponentDataTypeList& list) | |
649ab027 | 174 | { |
175 | /// Inherited from AliHLTComponent. | |
f064ef44 | 176 | /// Returns the ESD object and kAliHLTDataTypeTObject data type with MUON origin. |
649ab027 | 177 | |
f064ef44 | 178 | list.push_back(AliHLTMUONConstants::ESDDataType()); |
179 | list.push_back(kAliHLTDataTypeTObject | kAliHLTDataOriginMUON); | |
180 | return list.size(); | |
649ab027 | 181 | } |
182 | ||
183 | ||
ffb64d3e | 184 | void AliHLTMUONESDMaker::GetInputDataTypes(AliHLTComponentDataTypeList& list) |
649ab027 | 185 | { |
186 | /// Inherited from AliHLTProcessor. | |
187 | /// Returns the list of expected input data types. | |
188 | ||
189 | list.push_back(AliHLTMUONConstants::TriggerRecordsBlockDataType()); | |
190 | list.push_back(AliHLTMUONConstants::MansoTracksBlockDataType()); | |
191 | } | |
192 | ||
193 | ||
194 | void AliHLTMUONESDMaker::GetOutputDataSize( | |
195 | unsigned long& constBase, double& inputMultiplier | |
196 | ) | |
197 | { | |
198 | /// Inherited from AliHLTComponent. | |
199 | /// Returns an estimate of the expected output data size. | |
200 | ||
94135365 | 201 | constBase = sizeof(AliESDEvent) + 1024*1024; // The extra 1 MByte is for auxilary objects created in AliESDEvent. |
649ab027 | 202 | inputMultiplier = 10; |
203 | } | |
204 | ||
205 | ||
206 | AliHLTComponent* AliHLTMUONESDMaker::Spawn() | |
207 | { | |
208 | /// Inherited from AliHLTComponent. Creates a new object instance. | |
209 | ||
210 | return new AliHLTMUONESDMaker(); | |
211 | } | |
212 | ||
213 | ||
214 | int AliHLTMUONESDMaker::DoEvent( | |
ffb64d3e | 215 | const AliHLTComponentEventData& evtData, |
216 | AliHLTComponentTriggerData& trigData | |
649ab027 | 217 | ) |
218 | { | |
219 | /// Inherited from AliHLTProcessor. Processes the new event data. | |
220 | ||
221 | AliESDEvent event; | |
222 | AliHLTUInt32_t clusterIndex = 0; // for the cluster unique ID. | |
223 | ||
224 | // Create and fill in the standard ESD objects or just create the muon | |
225 | // tracks array if so requested. | |
226 | if (fMakeMinimalESD) | |
227 | { | |
f064ef44 | 228 | TClonesArray* muonTracks = new TClonesArray("AliESDMuonTrack",2); |
649ab027 | 229 | muonTracks->SetName("MuonTracks"); |
230 | event.AddObject(muonTracks); | |
231 | event.GetStdContent(); | |
232 | } | |
233 | else | |
234 | { | |
235 | event.CreateStdContent(); | |
236 | event.SetRunNumber(GetRunNo()); | |
237 | } | |
238 | ||
239 | const AliHLTComponentBlockData* block = NULL; | |
240 | AliHLTUInt32_t specification = 0; // Contains the output data block spec bits. | |
241 | std::vector<const AliHLTMUONTriggerRecordStruct*> triggerRecords; | |
242 | ||
243 | // First process the blocks of trigger records. We simply mark each trigger | |
244 | // record in the triggerRecords array. | |
245 | for (int i = 0; i < GetNumberOfInputBlocks(); i++) | |
246 | { | |
247 | block = GetInputBlock(i); | |
248 | assert( block != NULL ); | |
249 | ||
250 | HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.", | |
251 | i, DataType2Text(block->fDataType).c_str(), block->fPtr, block->fSize | |
252 | ); | |
253 | ||
254 | if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType()) | |
255 | { | |
256 | specification |= block->fSpecification; | |
3240b3ce | 257 | AliHLTMUONTriggerRecordsBlockReader inblock(block->fPtr, block->fSize); |
ffb64d3e | 258 | if (not BlockStructureOk(inblock)) |
259 | { | |
260 | if (DumpDataOnError()) DumpEvent(evtData, trigData); | |
261 | continue; | |
262 | } | |
649ab027 | 263 | |
264 | for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++) | |
265 | { | |
266 | triggerRecords.push_back(&inblock[n]); | |
267 | } | |
268 | } | |
73ed798e | 269 | else if (block->fDataType == AliHLTMUONConstants::RootifiedEventDataType() and fAddCustomData) |
270 | { | |
271 | // Do nothing for now, will handle this later. | |
272 | } | |
649ab027 | 273 | else |
274 | { | |
275 | if (block->fDataType != AliHLTMUONConstants::MansoTracksBlockDataType()) | |
276 | { | |
277 | // Log a message indicating that we got a data block that we | |
278 | // do not know how to handle. | |
279 | if (fWarnForUnexpecedBlock) | |
280 | HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X", | |
281 | DataType2Text(block->fDataType).c_str(), block->fSpecification | |
282 | ); | |
4e22efc4 | 283 | #ifdef __DEBUG |
649ab027 | 284 | else |
285 | HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X", | |
286 | DataType2Text(block->fDataType).c_str(), block->fSpecification | |
287 | ); | |
4e22efc4 | 288 | #endif |
649ab027 | 289 | } |
290 | } | |
291 | } | |
292 | ||
73ed798e | 293 | // If we were requested to add all dHLT rootified data objects then do so. |
294 | if (fAddCustomData) | |
295 | { | |
296 | const AliHLTComponentDataType& type = AliHLTMUONConstants::RootifiedEventDataType(); | |
297 | const char* classname = AliHLTMUONEvent::Class_Name(); | |
298 | const TObject* obj = NULL; | |
299 | for (obj = GetFirstInputObject(type, classname); obj != NULL; obj = GetNextInputObject()) | |
300 | { | |
301 | // Clone the object since the ESD takes ownership of it. | |
302 | event.AddObject(obj->Clone()); | |
303 | } | |
304 | } | |
305 | ||
649ab027 | 306 | // Now we can look for tracks to add. We needed the ROOT trigger records |
307 | // and reco hits created before we can create track objects. | |
308 | for (block = GetFirstInputBlock(AliHLTMUONConstants::MansoTracksBlockDataType()); | |
309 | block != NULL; | |
310 | block = GetNextInputBlock() | |
311 | ) | |
312 | { | |
313 | specification |= block->fSpecification; | |
3240b3ce | 314 | AliHLTMUONMansoTracksBlockReader inblock(block->fPtr, block->fSize); |
ffb64d3e | 315 | if (not BlockStructureOk(inblock)) |
316 | { | |
317 | if (DumpDataOnError()) DumpEvent(evtData, trigData); | |
318 | continue; | |
319 | } | |
649ab027 | 320 | |
321 | for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++) | |
322 | { | |
323 | const AliHLTMUONMansoTrackStruct& t = inblock[n]; | |
324 | AliESDMuonTrack muTrack; | |
325 | ||
326 | AliHLTMUONParticleSign sign; | |
327 | bool hitset[4]; | |
328 | AliHLTMUONUtils::UnpackMansoTrackFlags( | |
329 | t.fFlags, sign, hitset | |
330 | ); | |
331 | ||
332 | double signVal = 0; | |
333 | switch (sign) | |
334 | { | |
335 | case kSignMinus: signVal = +1.; break; | |
336 | case kSignUnknown: signVal = 0.; break; | |
337 | case kSignPlus: signVal = -1.; break; | |
338 | default: | |
339 | HLTWarning("Got a track with an invalid sign value: %d", int(sign)); | |
340 | } | |
341 | ||
342 | TVector3 mom(t.fPx, t.fPy, t.fPz); | |
343 | if (mom.Mag() != 0) | |
344 | muTrack.SetInverseBendingMomentum(signVal/mom.Mag()); | |
345 | else | |
346 | muTrack.SetInverseBendingMomentum(0.); | |
347 | muTrack.SetThetaX(atan2(t.fPx, t.fPz)); | |
348 | muTrack.SetThetaY(atan2(t.fPy, t.fPz)); | |
349 | muTrack.SetZ(0.); | |
350 | muTrack.SetBendingCoor(0.); | |
351 | muTrack.SetNonBendingCoor(0.); | |
352 | ||
353 | // The Manso algorithm assumes the information at the | |
354 | // Distance of Closest Approach and chamber 1 is the same | |
355 | // as the vertex. | |
356 | if (mom.Mag() != 0) | |
357 | muTrack.SetInverseBendingMomentumAtDCA(1./mom.Mag()); | |
358 | else | |
359 | muTrack.SetInverseBendingMomentumAtDCA(0.); | |
360 | muTrack.SetThetaXAtDCA(atan2(t.fPx, t.fPz)); | |
361 | muTrack.SetThetaYAtDCA(atan2(t.fPy, t.fPz)); | |
362 | muTrack.SetBendingCoorAtDCA(0.); | |
363 | muTrack.SetNonBendingCoorAtDCA(0.); | |
364 | ||
365 | if (mom.Mag() != 0) | |
366 | muTrack.SetInverseBendingMomentumUncorrected(1./mom.Mag()); | |
367 | else | |
368 | muTrack.SetInverseBendingMomentumUncorrected(0.); | |
369 | muTrack.SetThetaXUncorrected(atan2(t.fPx, t.fPz)); | |
370 | muTrack.SetThetaYUncorrected(atan2(t.fPy, t.fPz)); | |
371 | muTrack.SetZUncorrected(0.); | |
372 | muTrack.SetBendingCoorUncorrected(0.); | |
373 | muTrack.SetNonBendingCoorUncorrected(0.); | |
374 | ||
375 | muTrack.SetChi2(t.fChi2); | |
376 | ||
377 | // Fill in the track hit points. | |
378 | Int_t nHits = 0; | |
379 | for (int i = 0; i < 4; i++) | |
380 | { | |
381 | if (not hitset[i]) continue; | |
382 | ||
383 | AliHLTUInt8_t chamber; | |
384 | AliHLTUInt16_t detElemId; | |
385 | AliHLTMUONUtils::UnpackRecHitFlags(t.fHit[i].fFlags, chamber, detElemId); | |
386 | ||
387 | AliESDMuonCluster cluster; | |
388 | cluster.SetUniqueID(AliMUONVCluster::BuildUniqueID(chamber, detElemId, clusterIndex++)); | |
389 | cluster.SetXYZ(t.fHit[i].fX, t.fHit[i].fY, t.fHit[i].fZ); | |
390 | cluster.SetErrXY( // Use nominal values. | |
c6bc1026 | 391 | AliHLTMUONConstants::DefaultNonBendingReso(), |
392 | AliHLTMUONConstants::DefaultBendingReso() | |
649ab027 | 393 | ); |
394 | cluster.SetCharge(-1.); // Indicate no total charge calculated. | |
395 | cluster.SetChi2(-1.); // Indicate no fit made. | |
396 | muTrack.AddCluster(cluster); | |
397 | nHits++; | |
398 | muTrack.AddInMuonClusterMap(i+6); | |
399 | } | |
400 | ||
401 | // Find the corresponding trigger record. | |
402 | const AliHLTMUONTriggerRecordStruct* trigrec = NULL; | |
403 | for (size_t k = 0; k < triggerRecords.size(); k++) | |
404 | { | |
405 | if (triggerRecords[k]->fId == t.fTrigRec) | |
406 | { | |
407 | trigrec = triggerRecords[k]; | |
408 | break; | |
409 | } | |
410 | } | |
411 | // If the trigger record was found then fill its hit information also. | |
412 | if (trigrec != NULL) | |
413 | { | |
414 | AliHLTMUONParticleSign trsign; | |
415 | bool trhitset[4]; | |
416 | AliHLTMUONUtils::UnpackTriggerRecordFlags( | |
417 | trigrec->fFlags, trsign, trhitset | |
418 | ); | |
419 | ||
420 | for (int i = 0; i < 4; i++) | |
421 | { | |
422 | if (not trhitset[i]) continue; | |
423 | ||
424 | AliHLTUInt8_t chamber; | |
425 | AliHLTUInt16_t detElemId; | |
426 | AliHLTMUONUtils::UnpackRecHitFlags(trigrec->fHit[i].fFlags, chamber, detElemId); | |
427 | ||
428 | AliESDMuonCluster cluster; | |
429 | cluster.SetUniqueID(AliMUONVCluster::BuildUniqueID(chamber, detElemId, clusterIndex++)); | |
430 | cluster.SetXYZ( | |
431 | trigrec->fHit[i].fX, | |
432 | trigrec->fHit[i].fY, | |
433 | trigrec->fHit[i].fZ | |
434 | ); | |
435 | cluster.SetErrXY( // Use nominal values. | |
436 | AliMUONConstants::TriggerNonBendingReso(), | |
437 | AliMUONConstants::TriggerBendingReso() | |
438 | ); | |
439 | cluster.SetCharge(-1.); // Indicate no total charge calculated. | |
440 | cluster.SetChi2(-1.); // Indicate no fit made. | |
441 | muTrack.AddCluster(cluster); | |
442 | nHits++; | |
443 | muTrack.AddInMuonClusterMap(i+10); | |
444 | } | |
445 | } | |
446 | else | |
447 | { | |
448 | HLTWarning("Trigger record (ID = %d) not found for track ID = %d.", | |
449 | t.fTrigRec, t.fId | |
450 | ); | |
451 | } | |
452 | ||
453 | muTrack.SetNHit(nHits); | |
454 | event.AddMuonTrack(&muTrack); | |
455 | } | |
456 | } | |
457 | ||
f064ef44 | 458 | if (fMakeClonesArray and event.GetList() != NULL) |
459 | { | |
460 | PushBack( | |
461 | event.GetList()->FindObject("MuonTracks"), | |
462 | kAliHLTDataTypeTObject | kAliHLTDataOriginMUON, | |
463 | specification | |
464 | ); | |
465 | } | |
466 | if (fMakeESDDataBlock) | |
467 | { | |
468 | PushBack(&event, AliHLTMUONConstants::ESDDataType(), specification); | |
469 | } | |
649ab027 | 470 | return 0; |
471 | } | |
472 |