1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
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 **************************************************************************/
20 /// @file AliHLTMUONRootifierComponent.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
23 /// @brief Implementation of the AliHLTMUONRootifierComponent component.
26 #include "AliHLTMUONRootifierComponent.h"
27 #include "AliHLTMUONEvent.h"
28 #include "AliHLTMUONConstants.h"
29 #include "AliHLTMUONUtils.h"
30 #include "AliHLTMUONDataBlockReader.h"
31 #include "AliHLTMUONRecHit.h"
32 #include "AliHLTMUONTriggerRecord.h"
33 #include "AliHLTMUONMansoTrack.h"
34 #include "AliHLTMUONDecision.h"
35 #include "TClonesArray.h"
38 ClassImp(AliHLTMUONRootifierComponent);
41 AliHLTMUONRootifierComponent::AliHLTMUONRootifierComponent() :
43 fWarnForUnexpecedBlock(false)
46 /// Default constructor.
51 AliHLTMUONRootifierComponent::~AliHLTMUONRootifierComponent()
54 /// Default destructor.
59 int AliHLTMUONRootifierComponent::DoInit(int argc, const char** argv)
62 /// Inherited from AliHLTComponent.
63 /// Parses the command line parameters and initialises the component.
66 HLTInfo("Initialising dHLT rootifier component.");
68 fWarnForUnexpecedBlock = false;
70 for (int i = 0; i < argc; i++)
72 if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
74 fWarnForUnexpecedBlock = true;
78 HLTError("Unknown option '%s'.", argv[i]);
86 int AliHLTMUONRootifierComponent::DoDeinit()
89 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
92 HLTInfo("Deinitialising dHLT rootifier component.");
97 const char* AliHLTMUONRootifierComponent::GetComponentID()
100 /// Inherited from AliHLTComponent. Returns the component ID.
103 return AliHLTMUONConstants::RootifierComponentId();
107 AliHLTComponentDataType AliHLTMUONRootifierComponent::GetOutputDataType()
109 /// Inherited from AliHLTComponent. Returns kAliHLTMultipleDataType
110 /// refer to GetOutputDataTypes for all returned data types.
112 return kAliHLTMultipleDataType;
116 int AliHLTMUONRootifierComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
118 /// Inherited from AliHLTComponent. Returns the output data types.
120 tgtList.push_back(kAliHLTAnyDataType);
125 void AliHLTMUONRootifierComponent::GetInputDataTypes(
126 vector<AliHLTComponentDataType>& list
130 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
133 list.push_back(kAliHLTAnyDataType);
137 void AliHLTMUONRootifierComponent::GetOutputDataSize(
138 unsigned long& constBase, double& inputMultiplier
142 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
145 constBase = 1024*1024;
146 inputMultiplier = 100;
150 AliHLTComponent* AliHLTMUONRootifierComponent::Spawn()
153 /// Inherited from AliHLTComponent. Creates a new object instance.
156 return new AliHLTMUONRootifierComponent();
160 int AliHLTMUONRootifierComponent::DoEvent(
161 const AliHLTComponentEventData& evtData,
162 AliHLTComponentTriggerData& /*trigData*/
166 /// Inherited from AliHLTProcessor. Processes the new event data.
169 AliHLTMUONEvent event(evtData.fEventID);
170 const AliHLTComponentBlockData* block = NULL;
172 // First process the blocks of reconstructed hits and trigger records.
173 for (int i = 0; i < GetNumberOfInputBlocks(); i++)
175 block = GetInputBlock(i);
176 assert( block != NULL );
178 HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
179 n, DataType2Text(block->fDataType).c_str(), block->fPtr, block->fSize
182 if (block->fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
184 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
185 ptr += block->fOffset;
186 AliHLTMUONRecHitsBlockReader inblock(ptr, block->fSize);
187 if (not inblock.BufferSizeOk())
189 size_t headerSize = sizeof(AliHLTMUONRecHitsBlockReader::HeaderType);
190 if (block->fSize < headerSize)
192 HLTError("Received a reconstructed hits data block with a size of %d bytes,"
193 " which is smaller than the minimum valid header size of %d bytes."
194 " The block must be corrupt.",
195 block->fSize, headerSize
200 size_t expectedWidth = sizeof(AliHLTMUONRecHitsBlockReader::ElementType);
201 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
203 HLTError("Received a reconstructed hits data block with a record"
204 " width of %d bytes, but the expected value is %d bytes."
205 " The block might be corrupt.",
206 block->fSize, headerSize
211 HLTError("Received a reconstructed hits data block with a size of %d bytes,"
212 " but the block header claims the block should be %d bytes."
213 " The block might be corrupt.",
214 block->fSize, inblock.BytesUsed()
219 // Decode the source DDL from the specification bits.
220 Int_t sourceDDL = -1;
222 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
223 for (int k = 0; k < 22; k++)
233 HLTWarning("The input data block %d contains"
234 " data from multiple DDL sources.", i
241 HLTWarning("The source DDL for input data block %d is %d."
242 " The expected range for the DDL is [1..20].",
247 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
249 const AliHLTMUONRecHitStruct& h = inblock[n];
250 event.Add(new AliHLTMUONRecHit(h.fX, h.fY, h.fZ, sourceDDL));
253 else if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
255 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
256 ptr += block->fOffset;
257 AliHLTMUONTriggerRecordsBlockReader inblock(ptr, block->fSize);
258 if (not inblock.BufferSizeOk())
260 size_t headerSize = sizeof(AliHLTMUONTriggerRecordsBlockReader::HeaderType);
261 if (block->fSize < headerSize)
263 HLTError("Received a trigger records data block with a size of %d bytes,"
264 " which is smaller than the minimum valid header size of %d bytes."
265 " The block must be corrupt.",
266 block->fSize, headerSize
271 size_t expectedWidth = sizeof(AliHLTMUONTriggerRecordsBlockReader::ElementType);
272 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
274 HLTError("Received a trigger records data block with a record"
275 " width of %d bytes, but the expected value is %d bytes."
276 " The block might be corrupt.",
277 block->fSize, headerSize
282 HLTError("Received a trigger records data block with a size of %d bytes,"
283 " but the block header claims the block should be %d bytes."
284 " The block might be corrupt.",
285 block->fSize, inblock.BytesUsed()
290 // Decode the source DDL from the specification bits.
291 Int_t sourceDDL = -1;
293 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
294 for (int k = 0; k < 22; k++)
304 HLTWarning("The input data block %d contains"
305 " data from multiple DDL sources.", i
310 if (sourceDDL != -1 and (sourceDDL < 21 or sourceDDL > 22))
312 HLTWarning("The source DDL for input data block %d is %d."
313 " The expected range for the DDL is [21..22].",
318 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
320 const AliHLTMUONTriggerRecordStruct& t = inblock[n];
322 AliHLTMUONParticleSign sign;
324 AliHLTMUONUtils::UnpackTriggerRecordFlags(
325 t.fFlags, sign, hitset
328 AliHLTMUONTriggerRecord* tr = new AliHLTMUONTriggerRecord(
329 t.fId, sign, t.fPx, t.fPy, t.fPz, sourceDDL
331 for (int k = 0; k < 4; k++)
332 tr->SetHit(k+11, t.fHit[k].fX, t.fHit[k].fY, t.fHit[k].fZ);
338 if (block->fDataType != AliHLTMUONConstants::MansoTracksBlockDataType() and
339 block->fDataType != AliHLTMUONConstants::SinglesDecisionBlockDataType() and
340 block->fDataType != AliHLTMUONConstants::PairsDecisionBlockDataType()
343 // Log a message indicating that we got a data block that we
344 // do not know how to handle.
345 if (fWarnForUnexpecedBlock)
346 HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
347 DataType2Text(block->fDataType).c_str(), block->fSpecification
350 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
351 DataType2Text(block->fDataType).c_str(), block->fSpecification
357 // Now we can look for tracks to add. We needed the ROOT trigger records
358 // and reco hits created before we can create track objects.
359 for (block = GetFirstInputBlock(AliHLTMUONConstants::MansoTracksBlockDataType());
361 block = GetNextInputBlock()
364 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
365 ptr += block->fOffset;
366 AliHLTMUONMansoTracksBlockReader inblock(ptr, block->fSize);
367 if (not inblock.BufferSizeOk())
369 size_t headerSize = sizeof(AliHLTMUONMansoTracksBlockReader::HeaderType);
370 if (block->fSize < headerSize)
372 HLTError("Received a Manso tracks data block with a size of %d bytes,"
373 " which is smaller than the minimum valid header size of %d bytes."
374 " The block must be corrupt.",
375 block->fSize, headerSize
380 size_t expectedWidth = sizeof(AliHLTMUONMansoTracksBlockReader::ElementType);
381 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
383 HLTError("Received a Manso tracks data block with a record"
384 " width of %d bytes, but the expected value is %d bytes."
385 " The block might be corrupt.",
386 block->fSize, headerSize
391 HLTError("Received a Manso tracks data block with a size of %d bytes,"
392 " but the block header claims the block should be %d bytes."
393 " The block might be corrupt.",
394 block->fSize, inblock.BytesUsed()
399 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
401 const AliHLTMUONMansoTrackStruct& t = inblock[n];
403 AliHLTMUONParticleSign sign;
405 AliHLTMUONUtils::UnpackMansoTrackFlags(
406 t.fFlags, sign, hitset
409 // Try find the trigger record in 'event'.
410 const AliHLTMUONTriggerRecord* trigrec = NULL;
411 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
413 if (event.Array()[k]->IsA() != AliHLTMUONTriggerRecord::Class())
415 const AliHLTMUONTriggerRecord* tk =
416 static_cast<const AliHLTMUONTriggerRecord*>(event.Array()[k]);
417 if (tk->Id() == t.fTrigRec)
424 // Now try find the hits in 'event'.
425 // If they cannot be found then create new ones.
426 const AliHLTMUONRecHit* hit7 = NULL;
427 const AliHLTMUONRecHit* hit8 = NULL;
428 const AliHLTMUONRecHit* hit9 = NULL;
429 const AliHLTMUONRecHit* hit10 = NULL;
430 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
432 if (event.Array()[k]->IsA() != AliHLTMUONRecHit::Class())
434 const AliHLTMUONRecHit* h =
435 static_cast<const AliHLTMUONRecHit*>(event.Array()[k]);
437 if (hitset[0] and h->X() == t.fHit[0].fX and h->Y() == t.fHit[0].fY
438 and h->Z() == t.fHit[0].fZ)
442 if (hitset[1] and h->X() == t.fHit[1].fX and h->Y() == t.fHit[1].fY
443 and h->Z() == t.fHit[1].fZ)
447 if (hitset[2] and h->X() == t.fHit[2].fX and h->Y() == t.fHit[2].fY
448 and h->Z() == t.fHit[2].fZ)
452 if (hitset[3] and h->X() == t.fHit[3].fX and h->Y() == t.fHit[3].fY
453 and h->Z() == t.fHit[3].fZ)
458 AliHLTMUONRecHit* newhit;
459 if (hitset[0] and hit7 == NULL)
461 newhit = new AliHLTMUONRecHit(t.fHit[0].fX, t.fHit[0].fY, t.fHit[0].fZ);
465 if (hitset[1] and hit8 == NULL)
467 newhit = new AliHLTMUONRecHit(t.fHit[1].fX, t.fHit[1].fY, t.fHit[1].fZ);
471 if (hitset[2] and hit9 == NULL)
473 newhit = new AliHLTMUONRecHit(t.fHit[2].fX, t.fHit[2].fY, t.fHit[2].fZ);
477 if (hitset[3] and hit10 == NULL)
479 newhit = new AliHLTMUONRecHit(t.fHit[3].fX, t.fHit[3].fY, t.fHit[3].fZ);
484 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(
485 t.fId, sign, t.fPx, t.fPy, t.fPz, t.fChi2,
486 trigrec, hit7, hit8, hit9, hit10
493 UInt_t numHighPt = 0;
494 TClonesArray singlesDecisions("AliHLTMUONDecision::AliTrackDecision");
496 // Find the single tracks decision blocks and add their information.
497 // We just sum the trigger scalars and single decisions.
498 for (block = GetFirstInputBlock(AliHLTMUONConstants::SinglesDecisionBlockDataType());
500 block = GetNextInputBlock()
503 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
504 ptr += block->fOffset;
505 AliHLTMUONSinglesDecisionBlockReader inblock(ptr, block->fSize);
506 if (not inblock.BufferSizeOk())
508 size_t headerSize = sizeof(AliHLTMUONSinglesDecisionBlockReader::HeaderType);
509 if (block->fSize < headerSize)
511 HLTError("Received a single tracks trigger decision data block with a size of %d bytes,"
512 " which is smaller than the minimum valid header size of %d bytes."
513 " The block must be corrupt.",
514 block->fSize, headerSize
519 size_t expectedWidth = sizeof(AliHLTMUONSinglesDecisionBlockReader::ElementType);
520 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
522 HLTError("Received a single tracks trigger decision data block with a record"
523 " width of %d bytes, but the expected value is %d bytes."
524 " The block might be corrupt.",
525 block->fSize, headerSize
530 HLTError("Received a single tracks trigger decision data block with a size of %d bytes,"
531 " but the block header claims the block should be %d bytes."
532 " The block might be corrupt.",
533 block->fSize, inblock.BytesUsed()
538 numLowPt += inblock.BlockHeader().fNlowPt;
539 numHighPt += inblock.BlockHeader().fNhighPt;
541 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
543 const AliHLTMUONTrackDecisionStruct& t = inblock[n];
546 AliHLTMUONUtils::UnpackTrackDecisionBits(t.fTriggerBits, highPt, lowPt);
548 // Try find the corresponding track in the 'event'.
549 const AliHLTMUONMansoTrack* track = NULL;
550 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
552 if (event.Array()[k]->IsA() != AliHLTMUONMansoTrack::Class())
554 const AliHLTMUONMansoTrack* tk =
555 static_cast<const AliHLTMUONMansoTrack*>(event.Array()[k]);
556 if (tk->Id() == t.fTrackId)
563 // If the track was not found then create a dummy one.
566 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackId);
571 new (singlesDecisions[singlesDecisions.GetEntriesFast()])
572 AliHLTMUONDecision::AliTrackDecision(t.fPt, lowPt, highPt, track);
576 UInt_t numUnlikeAnyPt = 0;
577 UInt_t numUnlikeLowPt = 0;
578 UInt_t numUnlikeHighPt = 0;
579 UInt_t numLikeAnyPt = 0;
580 UInt_t numLikeLowPt = 0;
581 UInt_t numLikeHighPt = 0;
582 UInt_t numAnyMass = 0;
583 UInt_t numLowMass = 0;
584 UInt_t numHighMass = 0;
585 TClonesArray pairsDecisions("AliHLTMUONDecision::AliPairDecision");
587 // Find the track pairs decision blocks and add their information.
588 // We just sum the trigger scalars and track pair decisions.
589 for (block = GetFirstInputBlock(AliHLTMUONConstants::PairsDecisionBlockDataType());
591 block = GetNextInputBlock()
594 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
595 ptr += block->fOffset;
596 AliHLTMUONPairsDecisionBlockReader inblock(ptr, block->fSize);
597 if (not inblock.BufferSizeOk())
599 size_t headerSize = sizeof(AliHLTMUONPairsDecisionBlockReader::HeaderType);
600 if (block->fSize < headerSize)
602 HLTError("Received a track pairs trigger decision data block with a size of %d bytes,"
603 " which is smaller than the minimum valid header size of %d bytes."
604 " The block must be corrupt.",
605 block->fSize, headerSize
610 size_t expectedWidth = sizeof(AliHLTMUONPairsDecisionBlockReader::ElementType);
611 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
613 HLTError("Received a track pairs trigger decision data block with a record"
614 " width of %d bytes, but the expected value is %d bytes."
615 " The block might be corrupt.",
616 block->fSize, headerSize
621 HLTError("Received a track pairs trigger decision data block with a size of %d bytes,"
622 " but the block header claims the block should be %d bytes."
623 " The block might be corrupt.",
624 block->fSize, inblock.BytesUsed()
629 numUnlikeAnyPt += inblock.BlockHeader().fNunlikeAnyPt;
630 numUnlikeLowPt += inblock.BlockHeader().fNunlikeLowPt;
631 numUnlikeHighPt += inblock.BlockHeader().fNunlikeHighPt;
632 numLikeAnyPt += inblock.BlockHeader().fNlikeAnyPt;
633 numLikeLowPt += inblock.BlockHeader().fNlikeLowPt;
634 numLikeHighPt += inblock.BlockHeader().fNlikeHighPt;
635 numAnyMass += inblock.BlockHeader().fNmassAny;
636 numLowMass += inblock.BlockHeader().fNmassLow;
637 numHighMass += inblock.BlockHeader().fNmassHigh;
639 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
641 const AliHLTMUONPairDecisionStruct& t = inblock[n];
643 bool highMass, lowMass, unlike;
644 AliHLTUInt8_t highPtCount, lowPtCount;
645 AliHLTMUONUtils::UnpackPairDecisionBits(
646 t.fTriggerBits, highMass, lowMass, unlike,
647 highPtCount, lowPtCount
650 // Try find the corresponding tracks in the 'event'.
651 const AliHLTMUONMansoTrack* trackA = NULL;
652 const AliHLTMUONMansoTrack* trackB = NULL;
653 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
655 if (event.Array()[k]->IsA() != AliHLTMUONMansoTrack::Class())
657 const AliHLTMUONMansoTrack* tk =
658 static_cast<const AliHLTMUONMansoTrack*>(event.Array()[k]);
659 if (tk->Id() == t.fTrackAId) trackA = tk;
660 if (tk->Id() == t.fTrackBId) trackB = tk;
661 if (trackA != NULL and trackB != NULL) break;
664 // If either of the tracks was not found then create a dummy one.
667 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackAId);
673 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackBId);
678 new (pairsDecisions[pairsDecisions.GetEntriesFast()])
679 AliHLTMUONDecision::AliPairDecision(
680 t.fInvMass, lowMass, highMass, unlike,
681 lowPtCount, highPtCount, trackA, trackB
686 AliHLTMUONDecision* triggerDecision = new AliHLTMUONDecision(
687 numLowPt, numHighPt, numUnlikeAnyPt, numUnlikeLowPt,
688 numUnlikeHighPt, numLikeAnyPt, numLikeLowPt,
689 numLikeHighPt, numAnyMass, numLowMass, numHighMass
691 for (Int_t i = 0; i < singlesDecisions.GetEntriesFast(); i++)
693 AliHLTMUONDecision::AliTrackDecision* decision =
694 static_cast<AliHLTMUONDecision::AliTrackDecision*>( singlesDecisions[i] );
695 triggerDecision->AddDecision(decision);
697 for (Int_t j = 0; j < pairsDecisions.GetEntriesFast(); j++)
699 AliHLTMUONDecision::AliPairDecision* decision =
700 static_cast<AliHLTMUONDecision::AliPairDecision*>( pairsDecisions[j] );
701 triggerDecision->AddDecision(decision);
703 event.Add(triggerDecision);
705 PushBack(&event, "ROOTEVNT", "MUON");