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