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