2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
7 * Artur Szostak <artursz@iafrica.com> *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
18 /// @file AliHLTMuonSpectroTriggerComponent.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @brief Implementation of the muon spectrometer trigger component.
23 /// The AliHLTMuonSpectroTriggerComponent component is used to generate the HLT
24 /// trigger for the muon spectrometer.
26 #include "AliHLTMuonSpectroTriggerComponent.h"
27 #include "AliHLTTriggerDecision.h"
28 #include "AliHLTMuonSpectroScalars.h"
29 #include "AliHLTMUONDataBlockReader.h"
30 #include "AliHLTMUONConstants.h"
31 #include "AliHLTMUONUtils.h"
32 #include "AliMUONTriggerDDLDecoderEventHandler.h"
34 ClassImp(AliHLTMuonSpectroTriggerComponent);
37 AliHLTMuonSpectroTriggerComponent::AliHLTMuonSpectroTriggerComponent() :
39 fBufferSizeConst(1024*16),
40 fBufferSizeMultiplier(1),
44 fTriggerTrigRecs(false),
48 // Default constructor.
52 AliHLTMuonSpectroTriggerComponent::~AliHLTMuonSpectroTriggerComponent()
54 // Default destructor.
58 void AliHLTMuonSpectroTriggerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) const
60 // Returns the list of input types expected.
61 list.push_back(AliHLTMUONConstants::DDLRawDataType());
62 list.push_back(AliHLTMUONConstants::TriggerRecordsBlockDataType());
63 list.push_back(AliHLTMUONConstants::RecHitsBlockDataType());
64 list.push_back(AliHLTMUONConstants::MansoTracksBlockDataType());
65 list.push_back(AliHLTMUONConstants::TracksBlockDataType());
66 list.push_back(AliHLTMUONConstants::SinglesDecisionBlockDataType());
67 list.push_back(AliHLTMUONConstants::PairsDecisionBlockDataType());
71 void AliHLTMuonSpectroTriggerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& list) const
73 // Return the output data types generated.
75 list.push_back(kAliHLTDataTypeTriggerDecision);
76 list.push_back(kAliHLTDataTypeEventStatistics|kAliHLTDataOriginHLT);
80 void AliHLTMuonSpectroTriggerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
82 // Returns the output data size estimate.
84 constBase = fBufferSizeConst;
85 inputMultiplier = fBufferSizeMultiplier;
89 AliHLTComponent* AliHLTMuonSpectroTriggerComponent::Spawn()
91 // Creates and returns a new instance.
93 return new AliHLTMuonSpectroTriggerComponent;
97 Int_t AliHLTMuonSpectroTriggerComponent::DoInit(int argc, const char** argv)
99 // Initialise the component.
102 fTriggerDDLs = false;
103 fTriggerHits = false;
104 fTriggerTrigRecs = false;
105 fTriggerTracks = false;
106 fTriggerDimuons = false;
108 for (int i = 0; i < argc; i++)
110 if (strcmp(argv[i], "-makestats") == 0)
115 if (strcmp(argv[i], "-triggerddls") == 0)
120 if (strcmp(argv[i], "-triggerhits") == 0)
125 if (strcmp(argv[i], "-triggertrigrecs") == 0)
127 fTriggerTrigRecs = true;
130 if (strcmp(argv[i], "-triggertracks") == 0)
132 fTriggerTracks = true;
135 if (strcmp(argv[i], "-triggerdimuons") == 0)
137 fTriggerDimuons = true;
140 if (strcmp(argv[i], "-triggerany") == 0)
143 fTriggerTrigRecs = true;
144 fTriggerTracks = true;
145 fTriggerDimuons = true;
149 HLTError("Unknown option '%s'.", argv[i]);
153 // If nothing was turned on to trigger then turn everything on by default.
154 if (fTriggerHits == false and fTriggerTrigRecs == false
155 and fTriggerTracks == false and fTriggerDimuons == false
158 fTriggerTracks = true;
159 fTriggerDimuons = true;
166 Int_t AliHLTMuonSpectroTriggerComponent::DoDeinit()
168 // Cleans up the component.
174 int AliHLTMuonSpectroTriggerComponent::DoTrigger()
176 // Applies the trigger for the HLT.
180 bool gotddls = false;
181 bool gothits = false;
182 bool gottrigrecs = false;
183 bool gottracks = false;
184 bool gotsingles = false;
185 bool gotpairs = false;
190 UInt_t nhitsCh[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
191 UInt_t ntrigrecs = 0;
194 UInt_t ntracksT = 0; // from track blocks.
195 UInt_t ntracksSD = 0; // from singles decision blocks
204 UInt_t nlikehigh = 0;
205 UInt_t nunlikeany = 0;
206 UInt_t nunlikelow = 0;
207 UInt_t nunlikehigh = 0;
209 UInt_t nhighmass = 0;
210 Double_t minmass = -1;
211 Double_t maxmass = -1;
213 AliHLTComponentDataType blockType = AliHLTMUONConstants::DDLRawDataType();
214 for (const AliHLTComponentBlockData* block = GetFirstInputBlock(blockType);
216 block = GetNextInputBlock()
223 blockType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
224 for (const AliHLTComponentBlockData* block = GetFirstInputBlock(blockType);
226 block = GetNextInputBlock()
229 AliHLTMUONTriggerRecordsBlockReader trigRecsBlock(block->fPtr, block->fSize);
230 if (not IsBlockOk(trigRecsBlock, blockType))
232 HLTWarning("Skipping problematic block '%s'", DataType2Text(blockType).c_str());
237 ntrigrecs += trigRecsBlock.Nentries();
238 for (AliHLTUInt32_t i = 0; i < trigRecsBlock.Nentries(); ++i)
240 AliHLTMUONParticleSign sign;
242 AliHLTMUONUtils::UnpackTriggerRecordFlags(trigRecsBlock[i].fFlags, sign, hitset);
245 case kSignPlus: ++nL0plus; break;
246 case kSignMinus: ++nL0minus; break;
249 for (int j = 0; j < 4; ++j)
261 blockType = AliHLTMUONConstants::RecHitsBlockDataType();
262 for (const AliHLTComponentBlockData* block = GetFirstInputBlock(blockType);
264 block = GetNextInputBlock()
267 AliHLTMUONRecHitsBlockReader hitsBlock(block->fPtr, block->fSize);
268 if (not IsBlockOk(hitsBlock, blockType))
270 HLTWarning("Skipping problematic block '%s'", DataType2Text(blockType).c_str());
275 nhits += hitsBlock.Nentries();
276 nhitsMCH += hitsBlock.Nentries();
277 for (AliHLTUInt32_t i = 0; i < hitsBlock.Nentries(); ++i)
279 AliHLTUInt8_t chamber;
280 AliHLTUInt16_t detElemId;
281 AliHLTMUONUtils::UnpackRecHitFlags(hitsBlock[i].fFlags, chamber, detElemId);
288 HLTWarning("Received a reconstructed hit which indicates"
289 " an invalid chamber number of %d. The expected"
290 " range is [0..9]. The data block is probably corrupt.",
297 blockType = AliHLTMUONConstants::MansoTracksBlockDataType();
298 for (const AliHLTComponentBlockData* block = GetFirstInputBlock(blockType);
300 block = GetNextInputBlock()
303 AliHLTMUONMansoTracksBlockReader tracksBlock(block->fPtr, block->fSize);
304 if (not IsBlockOk(tracksBlock, blockType))
306 HLTWarning("Skipping problematic block '%s'", DataType2Text(blockType).c_str());
311 ntracksT += tracksBlock.Nentries();
312 for (AliHLTUInt32_t i = 0; i < tracksBlock.Nentries(); ++i)
314 AliHLTMUONParticleSign sign;
316 AliHLTMUONUtils::UnpackMansoTrackFlags(tracksBlock[i].fFlags, sign, hitset);
319 case kSignPlus: ++nplus; break;
320 case kSignMinus: ++nminus; break;
326 blockType = AliHLTMUONConstants::TracksBlockDataType();
327 for (const AliHLTComponentBlockData* block = GetFirstInputBlock(blockType);
329 block = GetNextInputBlock()
332 AliHLTMUONTracksBlockReader tracksBlock(block->fPtr, block->fSize);
333 if (not IsBlockOk(tracksBlock, blockType))
335 HLTWarning("Skipping problematic block '%s'", DataType2Text(blockType).c_str());
340 ntracksT += tracksBlock.Nentries();
341 for (AliHLTUInt32_t i = 0; i < tracksBlock.Nentries(); ++i)
343 AliHLTMUONParticleSign sign;
345 AliHLTMUONUtils::UnpackTrackFlags(tracksBlock[i].fFlags, sign, hitset);
348 case kSignPlus: ++nplus; break;
349 case kSignMinus: ++nminus; break;
355 blockType = AliHLTMUONConstants::SinglesDecisionBlockDataType();
356 for (const AliHLTComponentBlockData* block = GetFirstInputBlock(blockType);
358 block = GetNextInputBlock()
361 AliHLTMUONSinglesDecisionBlockReader singlesBlock(block->fPtr, block->fSize);
362 if (not IsBlockOk(singlesBlock, blockType))
364 HLTWarning("Skipping problematic block '%s'", DataType2Text(blockType).c_str());
369 ntracksSD += singlesBlock.Nentries();
370 nlowpt += singlesBlock.BlockHeader().fNlowPt;
371 nhighpt += singlesBlock.BlockHeader().fNhighPt;
372 for (AliHLTUInt32_t i = 0; i < singlesBlock.Nentries(); ++i)
374 if (singlesBlock[i].fPt < minpt or minpt == -1) minpt = singlesBlock[i].fPt;
375 if (singlesBlock[i].fPt > maxpt or maxpt == -1) maxpt = singlesBlock[i].fPt;
379 blockType = AliHLTMUONConstants::PairsDecisionBlockDataType();
380 for (const AliHLTComponentBlockData* block = GetFirstInputBlock(blockType);
382 block = GetNextInputBlock()
385 AliHLTMUONPairsDecisionBlockReader pairsBlock(block->fPtr, block->fSize);
386 if (not IsBlockOk(pairsBlock, blockType))
388 HLTWarning("Skipping problematic block '%s'", DataType2Text(blockType).c_str());
393 nunlikeany += pairsBlock.BlockHeader().fNunlikeAnyPt;
394 nlikeany += pairsBlock.BlockHeader().fNlikeAnyPt;
395 // Dont use the other scalars from the pair decisions block header because
396 // they are much more restrictive. They count pairs where both tracks pass
397 // the low or high pT cut. But we want to relax this to just one track needs
398 // to pass the pT cut.
399 for (AliHLTUInt32_t i = 0; i < pairsBlock.Nentries(); ++i)
401 if (pairsBlock[i].fInvMass < minmass or minmass == -1) minmass = pairsBlock[i].fInvMass;
402 if (pairsBlock[i].fInvMass > maxmass or maxmass == -1) maxmass = pairsBlock[i].fInvMass;
403 bool highMass, lowMass, unlike;
404 AliHLTUInt8_t highPtCount, lowPtCount;
405 AliHLTMUONUtils::UnpackPairDecisionBits(
406 pairsBlock[i].fTriggerBits, highMass, lowMass, unlike,
407 highPtCount, lowPtCount
411 if (lowPtCount >= 1) ++nunlikelow;
412 if (highPtCount >= 1) ++nunlikehigh;
413 if (lowMass) ++nlowmass;
414 if (highMass) ++nhighmass;
418 if (lowPtCount >= 1) ++nlikelow;
419 if (highPtCount >= 1) ++nlikehigh;
424 // Select the largest value for nTracks since we might only get this information
425 // from singles decision blocks.
426 UInt_t ntracks = ntracksSD > ntracksT ? ntracksSD : ntracksT;
428 bool triggeredOnDDLs = fTriggerDDLs and nL0 > 0;
429 bool triggeredOnHits = fTriggerHits and nhitsMCH > 0;
430 bool triggeredOnTrigRecs = fTriggerTrigRecs and ntrigrecs > 0;
431 bool triggeredOnTracks = fTriggerTracks and ntracks > 0;
432 bool triggeredOnDimuons = fTriggerDimuons and (nunlikeany > 0
433 or nunlikelow > 0 or nunlikehigh > 0 or nlowmass > 0 or nhighmass > 0);
435 if (triggeredOnDimuons)
437 SetDescription("Dimuon in muon spectrometer");
438 SetTriggerDomain(AliHLTTriggerDomain("*******:MUON"));
440 else if (triggeredOnTracks)
442 SetDescription("Tracks in muon spectrometer");
443 SetTriggerDomain(AliHLTTriggerDomain("*******:MUON"));
445 else if (triggeredOnTrigRecs)
447 SetDescription("Muon trigger chambers triggered");
450 SetReadoutList(AliHLTReadoutList(AliHLTReadoutList::kMUONTRG | AliHLTReadoutList::kMUONTRK));
451 SetTriggerDomain(AliHLTTriggerDomain("TRIGRECS:MUON,RECHITS :MUON"));
455 SetReadoutList(AliHLTReadoutList(AliHLTReadoutList::kMUONTRG));
456 SetTriggerDomain(AliHLTTriggerDomain("TRIGRECS:MUON"));
459 else if (triggeredOnHits)
461 SetDescription("Hits in muon tracking chambers");
462 SetReadoutList(AliHLTReadoutList(AliHLTReadoutList::kMUONTRK));
463 SetTriggerDomain(AliHLTTriggerDomain("RECHITS :MUON"));
465 else if (triggeredOnDDLs)
467 SetDescription("DDL in muon tracking chambers");
468 SetReadoutList(AliHLTReadoutList(AliHLTReadoutList::kMUONTRG | AliHLTReadoutList::kMUONTRK));
469 SetTriggerDomain(AliHLTTriggerDomain("DDL_RAW :MUON"));
473 SetDescription("Not triggered");
474 SetTriggerDomain(AliHLTTriggerDomain());
477 if (triggeredOnDimuons or triggeredOnTracks or triggeredOnTrigRecs or triggeredOnHits or triggeredOnDDLs)
479 result = TriggerEvent();
480 if (result == -ENOSPC) goto increaseBuffer;
481 if (result != 0) return result;
486 AliHLTMuonSpectroScalars scalars;
487 if (gotddls) scalars.Add("NL0", "Number of L0 triggered event", nL0);
488 if (gothits and gottrigrecs) scalars.Add("NHits", "Total number of hits", nhits);
489 if (gottrigrecs) scalars.Add("NHitsMTR", "Number of hits in trigger chambers", nhitsMTR);
492 scalars.Add("NHitsMCH", "Number of hits in tracking chambers", nhitsMCH);
493 for (int i = 0; i < 10; i++)
495 scalars.Add(Form("NHitsCh%d", i+1), Form("Number of hits in chamber %d", i+1), nhitsCh[i]);
500 for (int i = 10; i < 14; i++)
502 scalars.Add(Form("NHitsCh%d", i+1), Form("Number of hits in chamber %d", i+1), nhitsCh[i]);
504 scalars.Add("NTrigRecs", "Total number of trigger records", ntrigrecs);
505 scalars.Add("NL0+", "Number of positive sign tracks in L0", nL0plus);
506 scalars.Add("NL0-", "Number of negative sign tracks in L0", nL0minus);
508 if (gottracks or gotsingles) scalars.Add("NTracks", "Total number of tracks", ntracks);
511 scalars.Add("N+", "Number of positive sign tracks", nplus);
512 scalars.Add("N-", "Number of negative sign tracks", nminus);
516 scalars.Add("NLowPt", "Number of low pT tracks", nlowpt);
517 scalars.Add("NHighPt", "Number of high pT tracks", nhighpt);
518 scalars.Add("MinPt", "Minimum pT found (GeV/c)", minpt);
519 scalars.Add("MaxPt", "Maximum pT found (GeV/c)", maxpt);
523 scalars.Add("NLikeAny", "Number of like sign track pairs", nlikeany);
524 scalars.Add("NLikeLow", "Number of like sign pairs with at least 1 low pT track.", nlikelow);
525 scalars.Add("NLikeHigh", "Number of like sign pairs with at least 1 high pT track.", nlikehigh);
526 scalars.Add("NUnlikeAny", "Number of unlike sign track pairs", nunlikeany);
527 scalars.Add("NUnlikeLow", "Number of unlike sign pairs with at least 1 low pT track.", nunlikelow);
528 scalars.Add("NUnlikeHigh", "Number of unlike sign pairs with at least 1 high pT track.", nunlikehigh);
529 scalars.Add("NLowMass", "Number of low mass dimuons", nlowmass);
530 scalars.Add("NHighMass", "Number of high mass dimuons", nhighmass);
531 scalars.Add("MinMass", "Minimum invariant mass found for dimuon (GeV/c^2)", minmass);
532 scalars.Add("MaxMass", "Maximum invariant mass found for dimuon (GeV/c^2)", maxmass);
535 result = PushBack(&scalars, kAliHLTDataTypeEventStatistics|kAliHLTDataOriginHLT);
536 if (result == -ENOSPC) goto increaseBuffer;
541 // Increase the estimated buffer space required since the PushBack
542 // or TriggerEvent methods indicate that they ran out of buffer space.
543 fBufferSizeConst += 1024*1024;
544 fBufferSizeMultiplier *= 2.;
549 template <typename BlockReader>
550 bool AliHLTMuonSpectroTriggerComponent::IsBlockOk(
551 const BlockReader& reader, const AliHLTComponentDataType& type
554 // Method for checking the block structure.
556 if (not reader.BufferSizeOk())
558 string name = DataType2Text(type).c_str();
559 size_t headerSize = sizeof(typename BlockReader::HeaderType);
560 if (reader.BufferSize() < headerSize)
562 HLTError("Received a '%s' data block with a size of %d bytes,"
563 " which is smaller than the minimum valid size of %d bytes."
564 " The block must be corrupt.",
565 name.c_str(), reader.BufferSize(), headerSize
569 size_t expectedWidth = sizeof(typename BlockReader::ElementType);
570 if (reader.CommonBlockHeader().fRecordWidth != expectedWidth)
572 HLTError("Received a '%s' data block with a record"
573 " width of %d bytes, but the expected value is %d bytes."
574 " The block might be corrupt.",
576 reader.CommonBlockHeader().fRecordWidth,
581 HLTError("Received a '%s' data block with a size of %d bytes,"
582 " but the block header claims the block should be %d bytes."
583 " The block might be corrupt.",
584 name.c_str(), reader.BufferSize(), reader.BytesUsed()