track number and pid propagated to clusters
[u/mrichter/AliRoot.git] / HLT / MUON / OfflineInterface / AliHLTMUONRootifierComponent.cxx
CommitLineData
9acda34c 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
17/* $Id$ */
18
cb35e21b 19///
20/// @file AliHLTMUONRootifierComponent.cxx
21/// @author Artur Szostak <artursz@iafrica.com>
450e0b36 22/// @date 29 Sep 2007
cb35e21b 23/// @brief Implementation of the AliHLTMUONRootifierComponent component.
24///
9acda34c 25
26#include "AliHLTMUONRootifierComponent.h"
450e0b36 27#include "AliHLTMUONEvent.h"
9acda34c 28#include "AliHLTMUONConstants.h"
29#include "AliHLTMUONUtils.h"
9acda34c 30#include "AliHLTMUONRecHit.h"
31#include "AliHLTMUONTriggerRecord.h"
32#include "AliHLTMUONMansoTrack.h"
450e0b36 33#include "AliHLTMUONDecision.h"
34#include "TClonesArray.h"
9acda34c 35#include <cassert>
36
9acda34c 37ClassImp(AliHLTMUONRootifierComponent);
38
39
40AliHLTMUONRootifierComponent::AliHLTMUONRootifierComponent() :
154cba94 41 AliHLTMUONProcessor(),
450e0b36 42 fWarnForUnexpecedBlock(false)
9acda34c 43{
6253e09b 44 ///
45 /// Default constructor.
46 ///
9acda34c 47}
48
49
50AliHLTMUONRootifierComponent::~AliHLTMUONRootifierComponent()
51{
6253e09b 52 ///
53 /// Default destructor.
54 ///
9acda34c 55}
56
57
ffb64d3e 58bool AliHLTMUONRootifierComponent::IgnoreArgument(const char* arg) const
59{
60 /// Return true if the argument is one of -cdbpath -run or -delaysetup
61 /// to prevent the parent class from parsing these arguments in DoInit.
62
558cf470 63 if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
64 strcmp(arg, "-delaysetup") == 0)
ffb64d3e 65 {
66 return true;
67 }
68 else
69 {
70 return false;
71 }
72}
73
74
450e0b36 75int AliHLTMUONRootifierComponent::DoInit(int argc, const char** argv)
9acda34c 76{
6253e09b 77 ///
78 /// Inherited from AliHLTComponent.
79 /// Parses the command line parameters and initialises the component.
80 ///
81
450e0b36 82 HLTInfo("Initialising dHLT rootifier component.");
ffb64d3e 83
84 // Inherit the parents functionality.
85 int result = AliHLTMUONProcessor::DoInit(argc, argv);
86 if (result != 0) return result;
450e0b36 87
88 fWarnForUnexpecedBlock = false;
89
90 for (int i = 0; i < argc; i++)
91 {
ffb64d3e 92 if (ArgumentAlreadyHandled(i, argv[i])) continue;
93
450e0b36 94 if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
95 {
96 fWarnForUnexpecedBlock = true;
97 continue;
98 }
99
100 HLTError("Unknown option '%s'.", argv[i]);
101 return -EINVAL;
102 }
103
9acda34c 104 return 0;
105}
106
107
108int AliHLTMUONRootifierComponent::DoDeinit()
109{
6253e09b 110 ///
111 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
112 ///
113
450e0b36 114 HLTInfo("Deinitialising dHLT rootifier component.");
9acda34c 115 return 0;
116}
117
118
119const char* AliHLTMUONRootifierComponent::GetComponentID()
120{
6253e09b 121 ///
122 /// Inherited from AliHLTComponent. Returns the component ID.
123 ///
124
450e0b36 125 return AliHLTMUONConstants::RootifierComponentId();
9acda34c 126}
127
128
129AliHLTComponentDataType AliHLTMUONRootifierComponent::GetOutputDataType()
130{
bb14e9db 131 /// Inherited from AliHLTComponent. Returns kAliHLTMultipleDataType
132 /// refer to GetOutputDataTypes for all returned data types.
133
134 return kAliHLTMultipleDataType;
135}
136
137
138int AliHLTMUONRootifierComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
139{
140 /// Inherited from AliHLTComponent. Returns the output data types.
6253e09b 141
bb14e9db 142 tgtList.push_back(kAliHLTAnyDataType);
62a08849 143 return tgtList.size();
9acda34c 144}
145
146
ffb64d3e 147void AliHLTMUONRootifierComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
9acda34c 148{
6253e09b 149 ///
150 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
151 ///
152
9acda34c 153 list.push_back(kAliHLTAnyDataType);
154}
155
156
157void AliHLTMUONRootifierComponent::GetOutputDataSize(
158 unsigned long& constBase, double& inputMultiplier
159 )
160{
6253e09b 161 ///
162 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
163 ///
164
477135e2 165 constBase = 1024*1024;
166 inputMultiplier = 100;
9acda34c 167}
168
169
170AliHLTComponent* AliHLTMUONRootifierComponent::Spawn()
171{
6253e09b 172 ///
173 /// Inherited from AliHLTComponent. Creates a new object instance.
174 ///
175
9acda34c 176 return new AliHLTMUONRootifierComponent();
177}
178
179
180int AliHLTMUONRootifierComponent::DoEvent(
181 const AliHLTComponentEventData& evtData,
ffb64d3e 182 AliHLTComponentTriggerData& trigData
9acda34c 183 )
184{
6253e09b 185 ///
186 /// Inherited from AliHLTProcessor. Processes the new event data.
187 ///
188
9acda34c 189 AliHLTMUONEvent event(evtData.fEventID);
450e0b36 190 const AliHLTComponentBlockData* block = NULL;
649ab027 191 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
9acda34c 192
193 // First process the blocks of reconstructed hits and trigger records.
194 for (int i = 0; i < GetNumberOfInputBlocks(); i++)
195 {
450e0b36 196 block = GetInputBlock(i);
9acda34c 197 assert( block != NULL );
450e0b36 198
199 HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
a62ffb4d 200 i, DataType2Text(block->fDataType).c_str(), block->fPtr, block->fSize
450e0b36 201 );
202
9acda34c 203 if (block->fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
204 {
649ab027 205 specification |= block->fSpecification;
3240b3ce 206 AliHLTMUONRecHitsBlockReader inblock(block->fPtr, block->fSize);
ffb64d3e 207 if (not BlockStructureOk(inblock))
208 {
209 if (DumpDataOnError()) DumpEvent(evtData, trigData);
210 continue;
211 }
9acda34c 212
213 // Decode the source DDL from the specification bits.
214 Int_t sourceDDL = -1;
215 bool ddl[22];
216 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
217 for (int k = 0; k < 22; k++)
218 {
219 if (ddl[k])
220 {
221 if (sourceDDL == -1)
222 {
223 sourceDDL = k+1;
224 }
225 else
226 {
227 HLTWarning("The input data block %d contains"
228 " data from multiple DDL sources.", i
229 );
230 }
231 }
232 }
233 if (sourceDDL > 20)
234 {
235 HLTWarning("The source DDL for input data block %d is %d."
236 " The expected range for the DDL is [1..20].",
237 i, sourceDDL
238 );
239 }
240
241 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
242 {
243 const AliHLTMUONRecHitStruct& h = inblock[n];
cdd0c63d 244 AliHLTUInt8_t chamber;
245 AliHLTUInt16_t detElemId;
246 AliHLTMUONUtils::UnpackRecHitFlags(h.fFlags, chamber, detElemId);
247 event.Add(new AliHLTMUONRecHit(h.fX, h.fY, h.fZ, sourceDDL, detElemId, chamber));
9acda34c 248 }
249 }
250 else if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
251 {
649ab027 252 specification |= block->fSpecification;
3240b3ce 253 AliHLTMUONTriggerRecordsBlockReader inblock(block->fPtr, block->fSize);
ffb64d3e 254 if (not BlockStructureOk(inblock))
255 {
256 if (DumpDataOnError()) DumpEvent(evtData, trigData);
257 continue;
258 }
9acda34c 259
260 // Decode the source DDL from the specification bits.
261 Int_t sourceDDL = -1;
262 bool ddl[22];
263 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
264 for (int k = 0; k < 22; k++)
265 {
266 if (ddl[k])
267 {
268 if (sourceDDL == -1)
269 {
270 sourceDDL = k+1;
271 }
272 else
273 {
274 HLTWarning("The input data block %d contains"
275 " data from multiple DDL sources.", i
276 );
277 }
278 }
279 }
bb14e9db 280 if (sourceDDL != -1 and (sourceDDL < 21 or sourceDDL > 22))
9acda34c 281 {
282 HLTWarning("The source DDL for input data block %d is %d."
283 " The expected range for the DDL is [21..22].",
284 i, sourceDDL
285 );
286 }
287
288 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
289 {
290 const AliHLTMUONTriggerRecordStruct& t = inblock[n];
291
292 AliHLTMUONParticleSign sign;
293 bool hitset[4];
294 AliHLTMUONUtils::UnpackTriggerRecordFlags(
295 t.fFlags, sign, hitset
296 );
297
298 AliHLTMUONTriggerRecord* tr = new AliHLTMUONTriggerRecord(
299 t.fId, sign, t.fPx, t.fPy, t.fPz, sourceDDL
300 );
301 for (int k = 0; k < 4; k++)
302 tr->SetHit(k+11, t.fHit[k].fX, t.fHit[k].fY, t.fHit[k].fZ);
303 event.Add(tr);
304 }
305 }
306 else
307 {
450e0b36 308 if (block->fDataType != AliHLTMUONConstants::MansoTracksBlockDataType() and
309 block->fDataType != AliHLTMUONConstants::SinglesDecisionBlockDataType() and
310 block->fDataType != AliHLTMUONConstants::PairsDecisionBlockDataType()
311 )
312 {
313 // Log a message indicating that we got a data block that we
314 // do not know how to handle.
315 if (fWarnForUnexpecedBlock)
316 HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
317 DataType2Text(block->fDataType).c_str(), block->fSpecification
318 );
4e22efc4 319#ifdef __DEBUG
450e0b36 320 else
321 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
322 DataType2Text(block->fDataType).c_str(), block->fSpecification
323 );
4e22efc4 324#endif
450e0b36 325 }
9acda34c 326 }
327 }
328
329 // Now we can look for tracks to add. We needed the ROOT trigger records
330 // and reco hits created before we can create track objects.
450e0b36 331 for (block = GetFirstInputBlock(AliHLTMUONConstants::MansoTracksBlockDataType());
332 block != NULL;
333 block = GetNextInputBlock()
334 )
9acda34c 335 {
649ab027 336 specification |= block->fSpecification;
3240b3ce 337 AliHLTMUONMansoTracksBlockReader inblock(block->fPtr, block->fSize);
ffb64d3e 338 if (not BlockStructureOk(inblock))
339 {
340 if (DumpDataOnError()) DumpEvent(evtData, trigData);
341 continue;
342 }
450e0b36 343
344 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
345 {
346 const AliHLTMUONMansoTrackStruct& t = inblock[n];
347
348 AliHLTMUONParticleSign sign;
349 bool hitset[4];
350 AliHLTMUONUtils::UnpackMansoTrackFlags(
351 t.fFlags, sign, hitset
352 );
353
354 // Try find the trigger record in 'event'.
355 const AliHLTMUONTriggerRecord* trigrec = NULL;
356 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
9acda34c 357 {
450e0b36 358 if (event.Array()[k]->IsA() != AliHLTMUONTriggerRecord::Class())
359 continue;
360 const AliHLTMUONTriggerRecord* tk =
361 static_cast<const AliHLTMUONTriggerRecord*>(event.Array()[k]);
362 if (tk->Id() == t.fTrigRec)
9acda34c 363 {
450e0b36 364 trigrec = tk;
365 break;
9acda34c 366 }
450e0b36 367 }
368
369 // Now try find the hits in 'event'.
370 // If they cannot be found then create new ones.
371 const AliHLTMUONRecHit* hit7 = NULL;
372 const AliHLTMUONRecHit* hit8 = NULL;
373 const AliHLTMUONRecHit* hit9 = NULL;
374 const AliHLTMUONRecHit* hit10 = NULL;
375 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
376 {
377 if (event.Array()[k]->IsA() != AliHLTMUONRecHit::Class())
378 continue;
379 const AliHLTMUONRecHit* h =
380 static_cast<const AliHLTMUONRecHit*>(event.Array()[k]);
9acda34c 381
450e0b36 382 if (hitset[0] and h->X() == t.fHit[0].fX and h->Y() == t.fHit[0].fY
383 and h->Z() == t.fHit[0].fZ)
9acda34c 384 {
450e0b36 385 hit7 = h;
9acda34c 386 }
450e0b36 387 if (hitset[1] and h->X() == t.fHit[1].fX and h->Y() == t.fHit[1].fY
388 and h->Z() == t.fHit[1].fZ)
9acda34c 389 {
450e0b36 390 hit8 = h;
9acda34c 391 }
450e0b36 392 if (hitset[2] and h->X() == t.fHit[2].fX and h->Y() == t.fHit[2].fY
393 and h->Z() == t.fHit[2].fZ)
9acda34c 394 {
450e0b36 395 hit9 = h;
9acda34c 396 }
450e0b36 397 if (hitset[3] and h->X() == t.fHit[3].fX and h->Y() == t.fHit[3].fY
398 and h->Z() == t.fHit[3].fZ)
9acda34c 399 {
450e0b36 400 hit10 = h;
9acda34c 401 }
450e0b36 402 }
403 AliHLTMUONRecHit* newhit;
404 if (hitset[0] and hit7 == NULL)
405 {
406 newhit = new AliHLTMUONRecHit(t.fHit[0].fX, t.fHit[0].fY, t.fHit[0].fZ);
407 event.Add(newhit);
408 hit7 = newhit;
409 }
410 if (hitset[1] and hit8 == NULL)
411 {
412 newhit = new AliHLTMUONRecHit(t.fHit[1].fX, t.fHit[1].fY, t.fHit[1].fZ);
413 event.Add(newhit);
414 hit8 = newhit;
415 }
416 if (hitset[2] and hit9 == NULL)
417 {
418 newhit = new AliHLTMUONRecHit(t.fHit[2].fX, t.fHit[2].fY, t.fHit[2].fZ);
419 event.Add(newhit);
420 hit9 = newhit;
421 }
422 if (hitset[3] and hit10 == NULL)
423 {
424 newhit = new AliHLTMUONRecHit(t.fHit[3].fX, t.fHit[3].fY, t.fHit[3].fZ);
425 event.Add(newhit);
426 hit10 = newhit;
427 }
428
429 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(
430 t.fId, sign, t.fPx, t.fPy, t.fPz, t.fChi2,
431 trigrec, hit7, hit8, hit9, hit10
432 );
433 event.Add(tr);
434 }
435 }
436
8e0220c2 437 bool decisionBlockFound = false;
450e0b36 438 UInt_t numLowPt = 0;
439 UInt_t numHighPt = 0;
440 TClonesArray singlesDecisions("AliHLTMUONDecision::AliTrackDecision");
441
442 // Find the single tracks decision blocks and add their information.
443 // We just sum the trigger scalars and single decisions.
444 for (block = GetFirstInputBlock(AliHLTMUONConstants::SinglesDecisionBlockDataType());
445 block != NULL;
446 block = GetNextInputBlock()
447 )
448 {
8e0220c2 449 decisionBlockFound = true;
649ab027 450 specification |= block->fSpecification;
3240b3ce 451 AliHLTMUONSinglesDecisionBlockReader inblock(block->fPtr, block->fSize);
ffb64d3e 452 if (not BlockStructureOk(inblock))
453 {
454 if (DumpDataOnError()) DumpEvent(evtData, trigData);
455 continue;
456 }
450e0b36 457
458 numLowPt += inblock.BlockHeader().fNlowPt;
459 numHighPt += inblock.BlockHeader().fNhighPt;
460
461 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
462 {
463 const AliHLTMUONTrackDecisionStruct& t = inblock[n];
464
465 bool highPt, lowPt;
466 AliHLTMUONUtils::UnpackTrackDecisionBits(t.fTriggerBits, highPt, lowPt);
467
468 // Try find the corresponding track in the 'event'.
469 const AliHLTMUONMansoTrack* track = NULL;
470 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
471 {
472 if (event.Array()[k]->IsA() != AliHLTMUONMansoTrack::Class())
473 continue;
474 const AliHLTMUONMansoTrack* tk =
475 static_cast<const AliHLTMUONMansoTrack*>(event.Array()[k]);
476 if (tk->Id() == t.fTrackId)
9acda34c 477 {
450e0b36 478 track = tk;
479 break;
9acda34c 480 }
450e0b36 481 }
9acda34c 482
450e0b36 483 // If the track was not found then create a dummy one.
484 if (track == NULL)
485 {
486 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackId);
9acda34c 487 event.Add(tr);
450e0b36 488 track = tr;
9acda34c 489 }
450e0b36 490
491 new (singlesDecisions[singlesDecisions.GetEntriesFast()])
492 AliHLTMUONDecision::AliTrackDecision(t.fPt, lowPt, highPt, track);
9acda34c 493 }
450e0b36 494 }
495
496 UInt_t numUnlikeAnyPt = 0;
497 UInt_t numUnlikeLowPt = 0;
498 UInt_t numUnlikeHighPt = 0;
499 UInt_t numLikeAnyPt = 0;
500 UInt_t numLikeLowPt = 0;
501 UInt_t numLikeHighPt = 0;
502 UInt_t numAnyMass = 0;
503 UInt_t numLowMass = 0;
504 UInt_t numHighMass = 0;
505 TClonesArray pairsDecisions("AliHLTMUONDecision::AliPairDecision");
506
507 // Find the track pairs decision blocks and add their information.
508 // We just sum the trigger scalars and track pair decisions.
509 for (block = GetFirstInputBlock(AliHLTMUONConstants::PairsDecisionBlockDataType());
510 block != NULL;
511 block = GetNextInputBlock()
512 )
513 {
8e0220c2 514 decisionBlockFound = true;
649ab027 515 specification |= block->fSpecification;
3240b3ce 516 AliHLTMUONPairsDecisionBlockReader inblock(block->fPtr, block->fSize);
ffb64d3e 517 if (not BlockStructureOk(inblock))
518 {
519 if (DumpDataOnError()) DumpEvent(evtData, trigData);
520 continue;
521 }
450e0b36 522
523 numUnlikeAnyPt += inblock.BlockHeader().fNunlikeAnyPt;
524 numUnlikeLowPt += inblock.BlockHeader().fNunlikeLowPt;
525 numUnlikeHighPt += inblock.BlockHeader().fNunlikeHighPt;
526 numLikeAnyPt += inblock.BlockHeader().fNlikeAnyPt;
527 numLikeLowPt += inblock.BlockHeader().fNlikeLowPt;
528 numLikeHighPt += inblock.BlockHeader().fNlikeHighPt;
529 numAnyMass += inblock.BlockHeader().fNmassAny;
530 numLowMass += inblock.BlockHeader().fNmassLow;
531 numHighMass += inblock.BlockHeader().fNmassHigh;
532
533 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
534 {
535 const AliHLTMUONPairDecisionStruct& t = inblock[n];
536
537 bool highMass, lowMass, unlike;
538 AliHLTUInt8_t highPtCount, lowPtCount;
539 AliHLTMUONUtils::UnpackPairDecisionBits(
540 t.fTriggerBits, highMass, lowMass, unlike,
541 highPtCount, lowPtCount
542 );
543
544 // Try find the corresponding tracks in the 'event'.
545 const AliHLTMUONMansoTrack* trackA = NULL;
546 const AliHLTMUONMansoTrack* trackB = NULL;
547 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
548 {
549 if (event.Array()[k]->IsA() != AliHLTMUONMansoTrack::Class())
550 continue;
551 const AliHLTMUONMansoTrack* tk =
552 static_cast<const AliHLTMUONMansoTrack*>(event.Array()[k]);
553 if (tk->Id() == t.fTrackAId) trackA = tk;
554 if (tk->Id() == t.fTrackBId) trackB = tk;
555 if (trackA != NULL and trackB != NULL) break;
556 }
557
558 // If either of the tracks was not found then create a dummy one.
559 if (trackA == NULL)
560 {
561 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackAId);
562 event.Add(tr);
563 trackA = tr;
564 }
565 if (trackB == NULL)
566 {
567 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackBId);
568 event.Add(tr);
569 trackB = tr;
570 }
571
572 new (pairsDecisions[pairsDecisions.GetEntriesFast()])
573 AliHLTMUONDecision::AliPairDecision(
574 t.fInvMass, lowMass, highMass, unlike,
575 lowPtCount, highPtCount, trackA, trackB
576 );
577 }
578 }
579
8e0220c2 580
581 // Do not add the decision if no decision blocks were found.
582 if (decisionBlockFound)
450e0b36 583 {
8e0220c2 584 AliHLTMUONDecision* triggerDecision = new AliHLTMUONDecision(
585 numLowPt, numHighPt, numUnlikeAnyPt, numUnlikeLowPt,
586 numUnlikeHighPt, numLikeAnyPt, numLikeLowPt,
587 numLikeHighPt, numAnyMass, numLowMass, numHighMass
588 );
589 for (Int_t i = 0; i < singlesDecisions.GetEntriesFast(); i++)
590 {
591 AliHLTMUONDecision::AliTrackDecision* decision =
592 static_cast<AliHLTMUONDecision::AliTrackDecision*>( singlesDecisions[i] );
593 triggerDecision->AddDecision(decision);
594 }
595 for (Int_t j = 0; j < pairsDecisions.GetEntriesFast(); j++)
596 {
597 AliHLTMUONDecision::AliPairDecision* decision =
598 static_cast<AliHLTMUONDecision::AliPairDecision*>( pairsDecisions[j] );
599 triggerDecision->AddDecision(decision);
600 }
601
602 event.Add(triggerDecision);
450e0b36 603 }
9acda34c 604
73ed798e 605 PushBack(&event, AliHLTMUONConstants::RootifiedEventDataType(), specification);
9acda34c 606
607 return 0;
608}
6253e09b 609