]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/src/AliRoot/TriggerSource.cxx
Removing warnings related to -Weffc++ flag.
[u/mrichter/AliRoot.git] / HLT / MUON / src / AliRoot / TriggerSource.cxx
CommitLineData
8356cc1d 1////////////////////////////////////////////////////////////////////////////////
2//
3// Author: Artur Szostak
4// Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
5//
6////////////////////////////////////////////////////////////////////////////////
7
3a682eae 8/* AliHLTMUONTriggerSource is used to extract L0 trigger information for
9 the muon spectrometer from a simulated event stored in .root files by AliRoot.
10 It is used by the AliHLTMUONMicrodHLT class as a input data set for the
11 dHLT algorithm.
12 */
13
8356cc1d 14#include "AliRoot/TriggerSource.hpp"
15#include "AliRoot/Base.hpp"
16#include "Tracking/Calculations.hpp"
17#include "AliRun.h"
18#include "AliRunLoader.h"
19#include "AliModule.h"
20#include "AliMUON.h"
21#include "AliMUONConstants.h"
22#include "AliMUONHit.h"
23#include "AliMUONLocalTrigger.h"
24#include "AliMUONTriggerCircuit.h"
25#include "AliMUONDataInterface.h"
26#include "TDatabasePDG.h"
98af1577 27#ifndef __alpha
28#include <math.h>
29#else
30#include <float.h>
31#endif
8356cc1d 32
69d7cf2e 33ClassImp(AliHLTMUONTriggerSource)
3a682eae 34ClassImp(AliHLTMUONTriggerSource::AliEventData)
8356cc1d 35
8356cc1d 36
69d7cf2e 37AliHLTMUONTriggerSource::AliHLTMUONTriggerSource()
77650318 38 : TObject(),
39 fAreaToUse(kFromWholePlane), fDataToUse(kFromLocalTriggers),
40 fMaxBlockSize(0xFFFFFFFF), fUseLookupTable(kTRUE),
41 fFilename(""), fFoldername(""),
42 fEventIndex(-1), fCurrentEvent(NULL),
43 fBlockIndex(-1), fCurrentBlock(NULL),
44 fTriggerIndex(-1), fCurrentTrigger(NULL),
45 fEventList(AliHLTMUONTriggerSource::AliEventData::Class()),
46 fHadToLoadgAlice(kFALSE)
8356cc1d 47{
3a682eae 48// Default constructor.
49
50 fAreaToUse = kFromWholePlane;
51 fDataToUse = kFromLocalTriggers;
8356cc1d 52 fMaxBlockSize = 0xFFFFFFFF;
53 fUseLookupTable = kTRUE;
54 fFilename = "";
55 fFoldername = "";
56 ResetAllPointers();
57 fHadToLoadgAlice = kFALSE;
cbee67e7 58}
8356cc1d 59
60
69d7cf2e 61AliHLTMUONTriggerSource::AliHLTMUONTriggerSource(AliMUONDataInterface* data)
77650318 62 : TObject(),
63 fAreaToUse(kFromWholePlane), fDataToUse(kFromLocalTriggers),
64 fMaxBlockSize(0xFFFFFFFF), fUseLookupTable(kTRUE),
65 fFilename(""), fFoldername(""),
66 fEventIndex(-1), fCurrentEvent(NULL),
67 fBlockIndex(-1), fCurrentBlock(NULL),
68 fTriggerIndex(-1), fCurrentTrigger(NULL),
69 fEventList(AliHLTMUONTriggerSource::AliEventData::Class()),
70 fHadToLoadgAlice(kFALSE)
8356cc1d 71{
3a682eae 72// Creates a new trigger source object by filling data from the data interface.
73
74 fAreaToUse = kFromWholePlane;
75 fDataToUse = kFromLocalTriggers;
8356cc1d 76 fMaxBlockSize = 0xFFFFFFFF;
77 fUseLookupTable = kTRUE;
78 fFilename = "";
79 fFoldername = "";
80 ResetAllPointers();
81 fHadToLoadgAlice = kFALSE;
82 FillFrom(data);
cbee67e7 83}
8356cc1d 84
85
69d7cf2e 86AliHLTMUONTriggerSource::~AliHLTMUONTriggerSource()
8356cc1d 87{
12ab84fc 88 fEventList.Delete();
cbee67e7 89}
8356cc1d 90
91
69d7cf2e 92void AliHLTMUONTriggerSource::FillFrom(AliMUONDataInterface* data)
8356cc1d 93{
3a682eae 94// Fills the internal data structures from the specified data interface
95// for all the events found in AliMUONDataInterface.
96
8356cc1d 97 DebugMsg(1, "FillFrom(AliMUONDataInterface*)");
98
99 if (FileAndFolderOk(data))
100 {
101 AliMUON* module = NULL;
f086c81b 102 if ( ! FetchAliMUON(module) ) return;
8356cc1d 103
104 for (Int_t i = 0; i < data->NumberOfEvents(); i++)
105 {
106 AddEventFrom(data, module, i);
cbee67e7 107 }
8356cc1d 108
109 FinishedWithAliMUON();
cbee67e7 110 }
111}
8356cc1d 112
113
69d7cf2e 114void AliHLTMUONTriggerSource::FillFrom(AliMUONDataInterface* data, Int_t event)
8356cc1d 115{
3a682eae 116// Fills the internal data structures from the specified data interface
117// for the given event.
118
8356cc1d 119 DebugMsg(1, "FillFrom(AliMUONDataInterface*, Int_t)");
120
121 if (FileAndFolderOk(data))
122 {
123 AliMUON* module = NULL;
f086c81b 124 if ( ! FetchAliMUON(module) ) return;
8356cc1d 125 AddEventFrom(data, module, event);
126 FinishedWithAliMUON();
cbee67e7 127 }
128}
8356cc1d 129
130
69d7cf2e 131void AliHLTMUONTriggerSource::FillFrom(
8356cc1d 132 AliMUONDataInterface* data,
e33f3609 133 Int_t event, Int_t trigger, Bool_t newblock
8356cc1d 134 )
135{
3a682eae 136// Fills the internal data structures from the specified data interface
137// for the given event and trigger number.
138// If 'newblock' is set to true then the new trigger record is added to
139// a new block. Otherwise the point is added to the current block.
140// Note: This method ignores the fAreaToUse and fMaxBlockSize flags.
141// This is very usefull for custom trigger source filling.
142// For the case of adding data from AliMUONHit objects the 'trigger'
143// parameter becomes the track number in TreeH and not the index of the
144// AliMUONLocalTrigger object.
145
8356cc1d 146 DebugMsg(1, "FillFrom(AliMUONDataInterface*, Int_t, Int_t, Bool_t)");
147
148 if (FileAndFolderOk(data))
149 {
150 data->GetEvent(event);
151 AliMUON* module = NULL;
f086c81b 152 if ( ! FetchAliMUON(module) ) return;
8356cc1d 153
154 // Check if the current event corresponds to the event number we are
155 // attempting to add to. If they do not or no event is selected then
156 // try find the event or create a new one.
157 if ( fCurrentEvent == NULL )
158 {
159 Bool_t found = GetEvent(event);
f086c81b 160 if ( ! found) AddEvent(event);
8356cc1d 161 }
162 else
163 {
3a682eae 164 if (fCurrentEvent->EventNumber() != event)
8356cc1d 165 {
166 Bool_t found = GetEvent(event);
f086c81b 167 if ( ! found) AddEvent(event);
168 }
169 }
8356cc1d 170
171 if ( fCurrentBlock != NULL )
172 {
173 Assert( fCurrentEvent != NULL );
174 // If the newblock flag is set then force a new block.
175 if (newblock) AddBlock();
176 }
177 else
178 AddBlock(); // No block selected so we need to create a new block.
179
180 AddTriggerFrom(data, module, trigger);
181 FinishedWithAliMUON();
cbee67e7 182 }
183}
8356cc1d 184
185
69d7cf2e 186void AliHLTMUONTriggerSource::Clear(Option_t* /*option*/)
8356cc1d 187{
3a682eae 188// Clears all the internal arrays.
189
8356cc1d 190 fFilename = "";
191 fFoldername = "";
192 ResetAllPointers();
193 fEventList.Clear("C");
cbee67e7 194}
8356cc1d 195
196
69d7cf2e 197Bool_t AliHLTMUONTriggerSource::GetEvent(Int_t eventnumber) const
8356cc1d 198{
3a682eae 199// Fetches the specified event number stored in this AliHLTMUONTriggerSource.
200// Sets the current block and trigger to the first block and trigger record in
201// the event. If there are no blocks or trigger records then these pointers are
202// set to NULL. kTRUE is returned if the event was found, kFALSE otherwise.
203
69d7cf2e 204 DebugMsg(1, "AliHLTMUONTriggerSource::GetEvent(" << eventnumber << ")" );
8356cc1d 205
206 // Try find the corresponding event in the list of events.
207 for (Int_t i = 0; i < fEventList.GetEntriesFast(); i++)
208 {
3a682eae 209 AliEventData* current = (AliEventData*) fEventList[i];
210 if (current->EventNumber() == eventnumber)
8356cc1d 211 {
212 fEventIndex = i;
213 fCurrentEvent = current;
214 GetFirstBlock();
215 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
216 << " , fTriggerIndex = " << fTriggerIndex
217 );
218 return kTRUE;
f086c81b 219 }
220 }
8356cc1d 221 return kFALSE;
cbee67e7 222}
8356cc1d 223
224
69d7cf2e 225Bool_t AliHLTMUONTriggerSource::GetFirstEvent() const
8356cc1d 226{
3a682eae 227// Fetches the first event stored in this AliHLTMUONTriggerSource.
228// Sets the current block and trigger record to the first block and trigger
229// in the event. If there are no blocks or trigger records then these pointers
230// are set to NULL. kTRUE is returned if the event was found, kFALSE otherwise.
231
69d7cf2e 232 DebugMsg(1, "AliHLTMUONTriggerSource::GetFirstEvent()");
8356cc1d 233 if (fEventList.GetEntriesFast() > 0)
234 {
235 fEventIndex = 0;
3a682eae 236 fCurrentEvent = (AliEventData*) fEventList[0];
8356cc1d 237 GetFirstBlock();
238 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
239 << " , fTriggerIndex = " << fTriggerIndex
240 );
241 return kTRUE;
242 }
243 else
244 {
245 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
246 << " , fTriggerIndex = " << fTriggerIndex
247 );
248 return kFALSE;
cbee67e7 249 }
250}
8356cc1d 251
252
69d7cf2e 253Bool_t AliHLTMUONTriggerSource::MoreEvents() const
8356cc1d 254{
3a682eae 255// Returns kTRUE if there are more events to iterate over.
256
f086c81b 257 return 0 <= fEventIndex && fEventIndex < fEventList.GetEntriesFast();
cbee67e7 258}
8356cc1d 259
260
69d7cf2e 261Bool_t AliHLTMUONTriggerSource::GetNextEvent() const
8356cc1d 262{
3a682eae 263// Fetches the next event stored following the currently selected one.
264// kTRUE is returned if the event was found, kFALSE otherwise.
265// The internal pointers are reset if we reached the last event.
266
69d7cf2e 267 DebugMsg(1, "AliHLTMUONTriggerSource::GetNextEvent()");
8356cc1d 268 if (fEventIndex < fEventList.GetEntriesFast() - 1)
269 {
3a682eae 270 fCurrentEvent = (AliEventData*) fEventList[ ++fEventIndex ];
8356cc1d 271 GetFirstBlock();
272 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
273 << " , fTriggerIndex = " << fTriggerIndex
274 );
275 return kTRUE;
276 }
277 else
278 {
279 ResetAllPointers();
280 return kFALSE;
cbee67e7 281 }
282}
8356cc1d 283
284
69d7cf2e 285Int_t AliHLTMUONTriggerSource::CurrentEvent() const
8356cc1d 286{
3a682eae 287// Returns the corresponding AliRoot event number for the current event.
288// -1 is returned if no event is selected.
289
8356cc1d 290 if (fCurrentEvent != NULL)
3a682eae 291 return fCurrentEvent->EventNumber();
8356cc1d 292 else
293 return -1;
cbee67e7 294}
8356cc1d 295
296
69d7cf2e 297Int_t AliHLTMUONTriggerSource::NumberOfBlocks() const
8356cc1d 298{
3a682eae 299// Returns the number of trigger record blocks in the current event.
300// -1 is returned if no event is selected.
301
69d7cf2e 302 DebugMsg(1, "AliHLTMUONTriggerSource::NumberOfBlocks()");
8356cc1d 303 if (fCurrentEvent == NULL)
304 {
305 Error("NumberOfBlocks", "No event selected.");
306 return -1;
307 }
308 else
3a682eae 309 return fCurrentEvent->Blocks().GetEntriesFast();
cbee67e7 310}
8356cc1d 311
312
69d7cf2e 313Bool_t AliHLTMUONTriggerSource::GetBlock(Int_t index) const
8356cc1d 314{
3a682eae 315// Fetches the index'th block in the current event.
316// Sets the current trigger record to the first trigger in the block.
317// If there are no trigger records then this pointer is set to NULL.
318// kTRUE is returned if the block was found, kFALSE otherwise.
319
69d7cf2e 320 DebugMsg(1, "AliHLTMUONTriggerSource::GetBlock(" << index << ")");
8356cc1d 321
322 // Note NumberOfBlocks() also checks if the event was selected.
323 Int_t numberofblocks = NumberOfBlocks();
324 if (numberofblocks < 0) return kFALSE;
325
f086c81b 326 if ( 0 <= index && index < numberofblocks )
8356cc1d 327 {
328 fBlockIndex = index;
3a682eae 329 fCurrentBlock = (TClonesArray*) fCurrentEvent->Blocks()[index];
8356cc1d 330 GetFirstTrigger();
331 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
332 << " , fTriggerIndex = " << fTriggerIndex
333 );
334 return kTRUE;
335 }
336 else
337 {
338 // The index is out of bounds so inform the user.
339 if (numberofblocks > 0)
340 Error( "GetBlock",
341 "The block index (%d) is out of bounds. Valid range is [0, %d]",
342 index, numberofblocks - 1
343 );
344 else
345 Error( "GetBlock",
346 "The block index (%d) is out of bounds. No blocks found.",
347 index
348 );
349 return kFALSE;
cbee67e7 350 }
351}
8356cc1d 352
353
69d7cf2e 354Bool_t AliHLTMUONTriggerSource::GetFirstBlock() const
8356cc1d 355{
3a682eae 356// Fetches the first block in the current event.
357// Sets the current trigger record to the first trigger in the block.
358// If there are no trigger records then this pointer is set to NULL.
359// kTRUE is returned if the block was found, kFALSE otherwise.
360
69d7cf2e 361 DebugMsg(1, "AliHLTMUONTriggerSource::GetFirstBlock()");
8356cc1d 362 // Note: NumberOfBlocks() also checks if fCurrentEvent != NULL.
363 if (NumberOfBlocks() > 0)
364 {
365 fBlockIndex = 0;
3a682eae 366 fCurrentBlock = (TClonesArray*) fCurrentEvent->Blocks()[fBlockIndex];
8356cc1d 367 GetFirstTrigger();
368 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
369 << " , fTriggerIndex = " << fTriggerIndex
370 );
371 return kTRUE;
372 }
373 else
374 return kFALSE;
cbee67e7 375}
8356cc1d 376
377
69d7cf2e 378Bool_t AliHLTMUONTriggerSource::MoreBlocks() const
8356cc1d 379{
3a682eae 380// Returns kTRUE if there are more blocks to be traversed.
381
f086c81b 382 return 0 <= fBlockIndex && fBlockIndex < NumberOfBlocks();
cbee67e7 383}
8356cc1d 384
385
69d7cf2e 386Bool_t AliHLTMUONTriggerSource::GetNextBlock() const
8356cc1d 387{
3a682eae 388// Fetches the next block in the current event.
389// kTRUE is returned if the block was found, kFALSE otherwise.
390
69d7cf2e 391 DebugMsg(1, "AliHLTMUONTriggerSource::GetNextBlock()");
8356cc1d 392
393 // Note: NumberOfBlocks() checks if fCurrentEvent != NULL. If it is then it returns -1
394 // and since fBlockIndex is always >= -1 the if statement must go to the else part.
395 if (fBlockIndex < NumberOfBlocks() - 1)
396 {
3a682eae 397 fCurrentBlock = (TClonesArray*) fCurrentEvent->Blocks()[ ++fBlockIndex ];
8356cc1d 398 GetFirstTrigger();
399 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
400 << " , fTriggerIndex = " << fTriggerIndex
401 );
402 return kTRUE;
403 }
404 else
405 {
406 ResetBlockPointers();
407 return kFALSE;
cbee67e7 408 }
409}
8356cc1d 410
411
69d7cf2e 412Int_t AliHLTMUONTriggerSource::NumberOfTriggers() const
8356cc1d 413{
3a682eae 414// Returns the number of trigger records in the current block.
415// -1 is returned if no block is selected.
416
69d7cf2e 417 DebugMsg(1, "AliHLTMUONTriggerSource::NumberOfTriggers()");
8356cc1d 418 if (fCurrentBlock == NULL)
419 {
420 Error("NumberOfTriggers", "No block selected.");
421 return -1;
422 }
423 else
424 return fCurrentBlock->GetEntriesFast();
cbee67e7 425}
8356cc1d 426
427
69d7cf2e 428const AliHLTMUONTriggerRecord* AliHLTMUONTriggerSource::GetTrigger(Int_t triggernumber) const
8356cc1d 429{
3a682eae 430// Fetches the trigger record with the specified trigger number from
431// the current block.
432// NULL is returned if the record was not found.
433
69d7cf2e 434 DebugMsg(1, "AliHLTMUONTriggerSource::GetTrigger(" << triggernumber << ")");
8356cc1d 435
436 if (fCurrentBlock == NULL)
437 {
438 Error("GetTrigger", "No block selected.");
439 return NULL;
f086c81b 440 }
8356cc1d 441
442 // Try find the corresponding trigger record in the list of events.
443 for (Int_t i = 0; i < fCurrentBlock->GetEntriesFast(); i++)
444 {
69d7cf2e 445 AliHLTMUONTriggerRecord* current = (AliHLTMUONTriggerRecord*) fCurrentBlock->At(i);
8356cc1d 446 if (current->TriggerNumber() == triggernumber)
447 {
448 fTriggerIndex = i;
449 fCurrentTrigger = current;
450 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
451 << " , fTriggerIndex = " << fTriggerIndex
452 );
453 return current;
cbee67e7 454 }
455 }
8356cc1d 456 return NULL;
cbee67e7 457}
8356cc1d 458
459
69d7cf2e 460const AliHLTMUONTriggerRecord* AliHLTMUONTriggerSource::GetFirstTrigger() const
8356cc1d 461{
3a682eae 462// Fetches the first trigger record in the current block.
463// NULL is returned if the record was not found.
464
69d7cf2e 465 DebugMsg(1, "AliHLTMUONTriggerSource::GetFirstTrigger()");
8356cc1d 466 // Note: NumberOfTriggers() also checks if fCurrentBlock != NULL.
467 if (NumberOfTriggers() > 0)
468 {
469 fTriggerIndex = 0;
69d7cf2e 470 fCurrentTrigger = (AliHLTMUONTriggerRecord*) fCurrentBlock->At(0);
8356cc1d 471 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
472 << " , fTriggerIndex = " << fTriggerIndex
473 );
474 return fCurrentTrigger;
475 }
476 else
477 return NULL;
f086c81b 478}
8356cc1d 479
480
69d7cf2e 481Bool_t AliHLTMUONTriggerSource::MoreTriggers() const
8356cc1d 482{
3a682eae 483// Returns kTRUE if there are more triggers to iterate over.
484
f086c81b 485 return 0 <= fTriggerIndex && fTriggerIndex < NumberOfTriggers();
cbee67e7 486}
8356cc1d 487
488
69d7cf2e 489const AliHLTMUONTriggerRecord* AliHLTMUONTriggerSource::GetNextTrigger() const
8356cc1d 490{
3a682eae 491// Fetches the next trigger record in the current block.
492// NULL is returned if the record was not found.
493
69d7cf2e 494 DebugMsg(1, "AliHLTMUONTriggerSource::GetNextTrigger()");
8356cc1d 495
496 // Note: NumberOfTriggers() checks if fCurrentBlock != NULL. If it is then it returns -1
497 // and since fTriggerIndex is always >= -1 the if statement must go to the else part.
498 if (fTriggerIndex < NumberOfTriggers() - 1)
499 {
69d7cf2e 500 fCurrentTrigger = (AliHLTMUONTriggerRecord*) fCurrentBlock->At( ++fTriggerIndex );
8356cc1d 501 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
502 << " , fTriggerIndex = " << fTriggerIndex
503 );
504 return fCurrentTrigger;
505 }
506 else
507 {
508 ResetTriggerPointers();
509 return NULL;
f086c81b 510 }
511}
8356cc1d 512
513
69d7cf2e 514Int_t AliHLTMUONTriggerSource::CurrentTrigger() const
8356cc1d 515{
3a682eae 516// Returns the trigger record number for the currently selected trigger record.
517// This number corresponds to the index'th AliMUONLocalTrigger object for the
518// current event.
519// -1 is returned if no trigger record is selected.
520
8356cc1d 521 if (fCurrentTrigger != NULL)
522 {
523 return fCurrentTrigger->TriggerNumber();
524 }
525 else
526 {
527 Error("CurrentTrigger", "No trigger record selected.");
528 return -1;
cbee67e7 529 }
530}
8356cc1d 531
532
69d7cf2e 533void AliHLTMUONTriggerSource::AddEvent(Int_t eventnumber)
8356cc1d 534{
3a682eae 535// Adds a new AliEventData block to the fEventList and updates the fCurrentEvent,
536// fCurrentBlock and fCurrentTrigger pointers.
537
69d7cf2e 538 DebugMsg(1, "AliHLTMUONTriggerSource::AddEvent(" << eventnumber << ")");
8356cc1d 539 Assert( eventnumber >= 0 );
540
541 // Assume the eventnumber does not already exist in the event list.
542 fEventIndex = fEventList.GetEntriesFast();
3a682eae 543 new ( fEventList[fEventIndex] ) AliEventData(eventnumber);
544 fCurrentEvent = (AliEventData*) fEventList[fEventIndex];
8356cc1d 545
546 // Remember to reset the other pointers because the new event is empty.
547 ResetBlockPointers();
548
549 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
550 << " , fTriggerIndex = " << fTriggerIndex
551 );
cbee67e7 552}
8356cc1d 553
554
69d7cf2e 555void AliHLTMUONTriggerSource::AddBlock()
8356cc1d 556{
3a682eae 557// Adds a new block to the current event and updates fCurrentBlock and fCurrentTrigger.
558
69d7cf2e 559 DebugMsg(1, "AliHLTMUONTriggerSource::AddBlock()");
8356cc1d 560
561 if (fCurrentEvent == NULL)
562 {
563 Error("AddBlock", "No event selected.");
564 return;
f086c81b 565 }
8356cc1d 566
3a682eae 567 fBlockIndex = fCurrentEvent->Blocks().GetEntriesFast();
568 new ( fCurrentEvent->Blocks()[fBlockIndex] ) TClonesArray(AliHLTMUONTriggerRecord::Class());
569 fCurrentBlock = (TClonesArray*) fCurrentEvent->Blocks()[fBlockIndex];
8356cc1d 570
571 // Remember to reset the trigger pointer because the new block is empty.
572 ResetTriggerPointers();
573
574 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
575 << " , fTriggerIndex = " << fTriggerIndex
576 );
cbee67e7 577}
8356cc1d 578
579
69d7cf2e 580void AliHLTMUONTriggerSource::AddTrigger(const AliHLTMUONTriggerRecord& data)
8356cc1d 581{
3a682eae 582// Adds a new trigger record to the current event and block.
583// The fCurrentTrigger is updated appropriately.
584
69d7cf2e 585 DebugMsg(1, "AliHLTMUONTriggerSource::AddTrigger(" << (void*)&data << ")");
8356cc1d 586
587 if (fCurrentBlock == NULL)
588 {
589 Error("AddTrigger", "No block selected.");
590 return;
cbee67e7 591 }
8356cc1d 592
593 fTriggerIndex = fCurrentBlock->GetEntriesFast();
69d7cf2e 594 new ( (*fCurrentBlock)[fTriggerIndex] ) AliHLTMUONTriggerRecord(data);
595 fCurrentTrigger = (AliHLTMUONTriggerRecord*) (*fCurrentBlock)[fTriggerIndex];
8356cc1d 596
597 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
598 << " , fTriggerIndex = " << fTriggerIndex
599 );
cbee67e7 600}
8356cc1d 601
602
69d7cf2e 603Bool_t AliHLTMUONTriggerSource::FileAndFolderOk(AliMUONDataInterface* data)
8356cc1d 604{
3a682eae 605// Checks if the file and folder names correspond to this AliHLTMUONTriggerSource's
606// file and folder names. kTRUE is returned if they do.
607// If the file and folder names are empty then they are assigned the names
608// as found in the data interface and kTRUE is returned.
609
8356cc1d 610 if (fFilename == "")
611 {
612 // Nothing filled yet so set the file and folder names.
613 fFilename = data->CurrentFile();
614 fFoldername = data->CurrentFolder();
615 return kTRUE;
f086c81b 616 }
8356cc1d 617
618 if ( fFilename != data->CurrentFile() )
619 {
620 Error( "FileAndFolderOk",
621 "The Trigger source already contains data from file '%s', cannot add data from file '%s'",
622 fFilename.Data(), data->CurrentFile().Data()
623 );
624 return kFALSE;
f086c81b 625 }
8356cc1d 626
627 if ( fFoldername != data->CurrentFolder() )
628 {
629 Error( "FileAndFolderOk",
630 "The Trigger source already contains data from folder '%s', cannot add data from folder '%s'",
631 fFoldername.Data(), data->CurrentFolder().Data()
632 );
633 return kFALSE;
f086c81b 634 }
8356cc1d 635
636 return kTRUE;
cbee67e7 637}
8356cc1d 638
639
69d7cf2e 640void AliHLTMUONTriggerSource::AddEventFrom(AliMUONDataInterface* data, AliMUON* module, Int_t event)
8356cc1d 641{
3a682eae 642// Adds the whole event from the data interface to the internal data structures.
643// It is assumed that FileAndFolderOk(data) returns true just before calling
644// this method.
645
8356cc1d 646 if ( data->GetEvent(event) )
647 {
648 AddEvent(event);
649
650 AddBlock();
651 UInt_t currentblocksize = 0;
69d7cf2e 652 AliHLTMUONTriggerRecord trigdata;
8356cc1d 653
654 switch (fDataToUse)
655 {
3a682eae 656 case kFromHits:
8356cc1d 657 for (Int_t track = 0; track < data->NumberOfTracks(); track++)
658 {
f086c81b 659 if ( ! FillTriggerFromHits(data, track, trigdata) )
8356cc1d 660 continue; // Continue if unable to find hits.
661
662 if (InFillRegion(trigdata))
663 {
664 AddTrigger(trigdata);
665
666 // Create a new block if we reached the maximum block size.
667 if ( ++currentblocksize == fMaxBlockSize )
668 {
669 AddBlock();
670 currentblocksize = 0;
f086c81b 671 }
672 }
673 }
8356cc1d 674 break;
675
3a682eae 676 case kFromLocalTriggers:
8356cc1d 677 Assert( module != NULL );
3a682eae 678 DebugMsg(4, "Taking kFromLocalTriggers branch...");
8356cc1d 679 for (Int_t i = 0; i < data->NumberOfLocalTriggers(); i++)
680 {
681 DebugMsg(4, "for loop: i = " << i);
682 AliMUONLocalTrigger* lt = data->LocalTrigger(i);
683 FillTriggerFromLocalTrigger(lt, module, trigdata);
684 trigdata.TriggerNumber(i);
685
686 if (InFillRegion(trigdata))
687 {
688 AddTrigger(trigdata);
689
690 // Create a new block if we reached the maximum block size.
691 if ( ++currentblocksize == fMaxBlockSize )
692 {
693 AddBlock();
694 currentblocksize = 0;
f086c81b 695 }
696 }
697 }
8356cc1d 698 break;
699
700 default:
701 Error("AddChamberFrom", "fDataToUse is not set to a valid value.");
cbee67e7 702 }
703 } // Loop on events.
704}
8356cc1d 705
706
69d7cf2e 707void AliHLTMUONTriggerSource::AddTriggerFrom(AliMUONDataInterface* data, AliMUON* module, Int_t trigger)
8356cc1d 708{
3a682eae 709// Adds the specified trigger record from the given data interface.
710// The data interface should be initialised correctly, that is the event
711// should already be selected before calling this method.
712
8356cc1d 713 DebugMsg(1, "Entering AddTriggerFrom");
714
69d7cf2e 715 AliHLTMUONTriggerRecord trigdata;
8356cc1d 716
717 switch (fDataToUse)
718 {
3a682eae 719 case kFromHits:
8356cc1d 720 {
721 // Note: in this case we treat the trigger parameter as a track number.
f086c81b 722 if ( ! FillTriggerFromHits(data, trigger, trigdata) )
8356cc1d 723 return; // Continue if unable to find hits.
724 }
725 break;
726
3a682eae 727 case kFromLocalTriggers:
8356cc1d 728 {
729 Assert( module != NULL );
730 AliMUONLocalTrigger* lt = data->LocalTrigger(trigger);
731 FillTriggerFromLocalTrigger(lt, module, trigdata);
732 trigdata.TriggerNumber(trigger);
733 }
734 break;
735
736 default:
737 Error("AddTriggerFrom", "fDataToUse is not set to a valid value.");
738 return;
f086c81b 739 }
8356cc1d 740
741 AddTrigger(trigdata);
742
743 DebugMsg(1, "Leaving AddTriggerFrom");
cbee67e7 744}
8356cc1d 745
746
3a682eae 747Bool_t AliHLTMUONTriggerSource::InFillRegion(const AliHLTMUONTriggerRecord& data) const
8356cc1d 748{
3a682eae 749// Checks to see if the specified trigger record is in the chamber region
750// we want to fill from.
751// kTRUE is returned if (x, y) is in the region, and kFALSE otherwise.
752
8356cc1d 753 switch (fAreaToUse)
754 {
3a682eae 755 case kFromWholePlane: return kTRUE;
26538635 756 case kFromLeftHalfPlane: return data.Station1Point().X() <= 0;
757 case kFromRightHalfPlane: return data.Station1Point().X() > 0;
8356cc1d 758
759 default:
760 Error("InFillRegion", "fAreaToUse is not set to a valid value.");
761 return kFALSE;
cbee67e7 762 }
763}
8356cc1d 764
765
69d7cf2e 766void AliHLTMUONTriggerSource::FillTriggerFromLocalTrigger(
767 AliMUONLocalTrigger* trigger, AliMUON* module, AliHLTMUONTriggerRecord& record
8356cc1d 768 )
769{
3a682eae 770// Fills the trigger data from the AliMUONLocalTrigger object.
771// if the fUseLookupTable is set to true then we use the L0 lookup table to
772// fill the Pt value otherwise we use the PtCal method in AliMUONTriggerCircuit.
773// Note the fTriggerNumber parameter is not filled in to 'record'.
774
8356cc1d 775 DebugMsg(2, "Creating TriggerRecord from AliMUONLocalTrigger object: " << (void*)trigger );
776 AliMUONTriggerCircuit& circuit = module->TriggerCircuit(trigger->LoCircuit());
777
778 // Get the sign of the particle the sign of the muon.
779 if (trigger->LoLpt() == 1 || trigger->LoHpt() == 1 || trigger->LoApt() == 1)
780 {
781 record.ParticleSign(-1);
782 }
783 else
784 if (trigger->LoLpt() == 2 || trigger->LoHpt() == 2 || trigger->LoApt() == 2)
785 {
786 record.ParticleSign(+1);
787 }
788 else
789 {
790 record.ParticleSign(0);
f086c81b 791 }
8356cc1d 792 DebugMsg(2, "Particle sign = " << record.ParticleSign() );
793
794 // Compute the transverse momentum.
795 if (fUseLookupTable)
796 {
797 // TODO: implement use of the L0 lookup table.
798 Error("FillTriggerFromLocalTrigger", "Use of L0 lookup table is not yet implemented!");
799 }
800 else
801 {
802 Float_t pt = circuit.PtCal( trigger->LoStripX(), trigger->LoDev(), trigger->LoStripY() );
803 record.Pt(pt);
f086c81b 804 }
8356cc1d 805 DebugMsg(2, "Pt = " << record.Pt() );
806
807 // Build the impact points.
26538635 808 record.Station1Point().X() = circuit.GetX11Pos(trigger->LoStripY());
809 record.Station1Point().Y() = circuit.GetY11Pos(trigger->LoStripX());
810 record.Station2Point().Y() = circuit.GetY21Pos(trigger->LoStripX() + trigger->LoDev() + 1); // Why + 1?
811 record.Station2Point().X() = AliMUONConstants::DefaultChamberZ(12) * record.Station1Point().X() / AliMUONConstants::DefaultChamberZ(10);
812 DebugMsg(2, "fStation1x = " << record.Station1Point().X());
813 DebugMsg(2, "fStation1y = " << record.Station1Point().Y());
814 DebugMsg(2, "fStation2x = " << record.Station2Point().X());
815 DebugMsg(2, "fStation2y = " << record.Station2Point().Y());
cbee67e7 816}
8356cc1d 817
818
69d7cf2e 819Bool_t AliHLTMUONTriggerSource::FillTriggerFromHits(
820 AliMUONDataInterface* data, Int_t track, AliHLTMUONTriggerRecord& record
821 )
8356cc1d 822{
3a682eae 823// Fills the TriggerRecord structure from AliMUONHit objects.
824// The hits on the last 4 chambers are used (i.e. chambers 11 to 14).
825// kTRUE is returned if the structure was filled successfully.
826
8356cc1d 827 DebugMsg(2, "Creating TriggerRecord from hits on track: " << track );
828
829 Float_t x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;
98af1577 830#ifndef __alpha
8f6d5890 831#ifndef __sun
f086c81b 832 x1 = y1 = z1 = x2 = y2 = z2 = x3 = y3 = z3 = x4 = y4 = z4 = nanf("");
cbee67e7 833#else
834 x1 = y1 = z1 = x2 = y2 = z2 = x3 = y3 = z3 = x4 = y4 = z4 = 0;
835#endif
98af1577 836#else
837 x1 = y1 = z1 = x2 = y2 = z2 = x3 = y3 = z3 = x4 = y4 = z4 = FLT_QNAN;
838#endif
8356cc1d 839 // Find the hit that corresponds to chambers. 11 to 14. We can ignore any
840 // hits above the first 14. If there are that many it means the particle
841 // is cycling in the detector.
f086c81b 842 for (Int_t i = 0; i < data->NumberOfHits(track) && i < 14; i++)
8356cc1d 843 {
844 AliMUONHit* h = data->Hit(track, i);
845
846 // Note AliMUONHit::Chamber() returns a value in the range 1..14
847 // It is also important to have positive Z coordinates and under the
848 // new version of Aliroot we use GEANT coordinates which return
849 // negatives. So we use the fabs routine.
850 switch ( h->Chamber() )
851 {
852 case 11: x1 = h->X(); y1 = h->Y(); z1 = (Float_t)fabs(h->Z()); break;
853 case 12: x2 = h->X(); y2 = h->Y(); z2 = (Float_t)fabs(h->Z()); break;
854 case 13: x3 = h->X(); y3 = h->Y(); z3 = (Float_t)fabs(h->Z()); break;
855 case 14: x4 = h->X(); y4 = h->Y(); z4 = (Float_t)fabs(h->Z()); break;
f086c81b 856 }
857 }
8356cc1d 858 DebugMsg(4, "Found: x1 = " << x1 << ", y1 = " << y1 << ", z1 = " << z1);
859 DebugMsg(4, "Found: x2 = " << x2 << ", y2 = " << y2 << ", z2 = " << z2);
860 DebugMsg(4, "Found: x3 = " << x3 << ", y3 = " << y3 << ", z3 = " << z3);
861 DebugMsg(4, "Found: x4 = " << x4 << ", y4 = " << y4 << ", z4 = " << z4);
862
863 // Get a coordinate for station 1, perferably from chamber 11 otherwise
864 // use hits from chamber 12.
f086c81b 865 if ( ! TMath::IsNaN(x1))
8356cc1d 866 {
26538635 867 record.Station1Point().X() = x1;
868 record.Station1Point().Y() = y1;
8356cc1d 869 DebugMsg(3, "Using value from chamber 11: x1 = " << x1 << ", y1 = " << y1 << ", z1 = " << z1 );
870 }
f086c81b 871 else if ( ! TMath::IsNaN(x2))
8356cc1d 872 {
26538635 873 record.Station1Point().X() = x2;
874 record.Station1Point().Y() = y2;
8356cc1d 875 z1 = z2;
876 DebugMsg(3, "Using value from chamber 12: x2 = " << x2 << ", y2 = " << y2 << ", z2 = " << z2 );
877 }
878 else
879 {
880 // Return false if we could not find any hits on chambers 11 or 12.
881 Warning("FillTriggerFromHits", "Could not find any hits on chambers 11 and 12.");
882 return kFALSE;
f086c81b 883 }
8356cc1d 884
885 // Get a coordinate for station 2, perferably from chamber 13 otherwise
886 // use hits from chamber 14.
f086c81b 887 if ( ! TMath::IsNaN(x3))
8356cc1d 888 {
26538635 889 record.Station2Point().X() = x3;
890 record.Station2Point().Y() = y3;
8356cc1d 891 z2 = z3;
892 DebugMsg(3, "Using value from chamber 13: x3 = " << x3 << ", y3 = " << y3 << ", z3 = " << z3 );
893 }
f086c81b 894 else if ( ! TMath::IsNaN(x4))
8356cc1d 895 {
26538635 896 record.Station2Point().X() = x4;
897 record.Station2Point().Y() = y4;
8356cc1d 898 z2 = z4;
899 DebugMsg(3, "Using value from chamber 14: x4 = " << x4 << ", y4 = " << y4 << ", z4 = " << z4 );
900 }
901 else
902 {
903 // Return false if we could not find any hits on chambers 13 or 14.
904 Warning("FillTriggerFromHits", "Could not find any hits on chambers 13 and 14.");
905 return kFALSE;
f086c81b 906 }
8356cc1d 907
908 record.TriggerNumber(track);
909
910 // Get the sign of the particle.
911 Int_t particlecode = (Int_t) data->Hit(track, 0)->Particle();
912 DebugMsg(3, "particle code = " << particlecode);
913 TDatabasePDG* pdb = TDatabasePDG::Instance();
914 TParticlePDG* pdata = pdb->GetParticle(particlecode);
915 if (pdata->Charge() < 0)
916 record.ParticleSign(-1);
917 else if (pdata->Charge() > 0)
918 record.ParticleSign(+1);
919 else
920 record.ParticleSign(0);
921 DebugMsg(3, "Particle sign = " << record.ParticleSign());
922
26538635 923 DebugMsg(3, "Calculating Pt: x1 = " << record.Station1Point().X()
924 << ", y1 = " << record.Station1Point().Y()
925 << ", y2 = " << record.Station2Point().Y()
8356cc1d 926 << ", z1 = " << z1
927 << ", z2 = " << z2
928 );
929 // Calculate and assign the transverse momentum.
69d7cf2e 930 Float_t pt = AliHLTMUONCoreCalculatePt(
26538635 931 record.Station1Point().X(),
932 record.Station1Point().Y(), record.Station2Point().Y(),
8356cc1d 933 z1, z2
934 );
935 record.Pt(pt);
936
937 DebugMsg(3, "Pt = " << record.Pt());
938
939 return kTRUE;
cbee67e7 940}
8356cc1d 941
942
69d7cf2e 943Bool_t AliHLTMUONTriggerSource::FetchAliMUON(AliMUON*& module)
8356cc1d 944{
3a682eae 945// Fetches the AliMUON module from the AliRun global object. AliRun will be loaded
946// by the runloader if it has not yet been loaded. In such a case the AliRun object
947// will also we unloaded when we are done with it.
948// kTRUE is returned if no error occured and kFALSE otherwise.
949// Note that if fDataToUse is set to kFromHits then gAlice is not loaded and 'module'
950// will be left untouched. The method will still return kTRUE however since this is
951// not an error. We do not need the AliMUON module when filling from hits.
952
8356cc1d 953 // Check if we even need the MUON module. Not having to load it will
954 // save a lot of loading time for AliRoot.
3a682eae 955 if (fDataToUse == kFromHits)
8356cc1d 956 {
957 // Make sure we do not attempt to unload gAlice in FinishedWithAliMUON,
958 // by setting the fHadToLoadgAlice to false.
959 fHadToLoadgAlice = kFALSE;
960 return kTRUE;
f086c81b 961 }
8356cc1d 962
963 AliRunLoader* runloader = AliRunLoader::GetRunLoader();
964 if ( runloader == NULL )
965 {
966 Error("FetchAliMUON", "AliRunLoader not initialised!");
967 return kFALSE;
f086c81b 968 }
8356cc1d 969
970 // Try fetch the AliRun object. If it is not found then try load it using
971 // the runloader.
972 AliRun* alirun = runloader->GetAliRun();
973 if (alirun == NULL)
974 {
975 if (runloader->LoadgAlice() != 0)
976 {
977 // Error.
978 DebugMsg(1, "Leaving FillFrom(AliMUONDataInterface*)");
979 return kFALSE;
f086c81b 980 }
8356cc1d 981 fHadToLoadgAlice = kTRUE;
982 alirun = runloader->GetAliRun();
983 }
984 else
985 fHadToLoadgAlice = kFALSE;
986
987 // Get the MUON module pointer and return it.
988 module = dynamic_cast<AliMUON*>( alirun->GetModule("MUON") );
989 return kTRUE;
cbee67e7 990}
8356cc1d 991
992
69d7cf2e 993void AliHLTMUONTriggerSource::FinishedWithAliMUON()
8356cc1d 994{
3a682eae 995// After one is finished with the AliMUON object returned by GetAliMUON, one
996// should call this method.
997// If the gAlice object was loaded by GetAliMUON then it will be unloaded at
998// this point, otherwise nothing is done.
999
8356cc1d 1000 // Only unload the gAlice object if we had to load it ourselves.
1001 if (fHadToLoadgAlice)
1002 AliRunLoader::GetRunLoader()->UnloadgAlice();
cbee67e7 1003}
8356cc1d 1004
1005
69d7cf2e 1006void AliHLTMUONTriggerSource::ResetAllPointers() const
8356cc1d 1007{
3a682eae 1008// Sets all the current pointers to NULL and indices to -1.
1009
8356cc1d 1010 fEventIndex = -1;
1011 fCurrentEvent = NULL;
1012 fBlockIndex = -1;
1013 fCurrentBlock = NULL;
1014 fTriggerIndex = -1;
1015 fCurrentTrigger = NULL;
1016 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
1017 << " , fTriggerIndex = " << fTriggerIndex
1018 );
cbee67e7 1019}
8356cc1d 1020
1021
69d7cf2e 1022void AliHLTMUONTriggerSource::ResetBlockPointers() const
8356cc1d 1023{
3a682eae 1024// Sets the block and trigger pointers to NULL and indices to -1.
1025
8356cc1d 1026 fBlockIndex = -1;
1027 fCurrentBlock = NULL;
1028 fTriggerIndex = -1;
1029 fCurrentTrigger = NULL;
1030 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
1031 << " , fTriggerIndex = " << fTriggerIndex
1032 );
cbee67e7 1033}
8356cc1d 1034
1035
69d7cf2e 1036void AliHLTMUONTriggerSource::ResetTriggerPointers() const
8356cc1d 1037{
3a682eae 1038// Sets just the current trigger record pointer to NULL and index to -1.
1039
8356cc1d 1040 fTriggerIndex = -1;
1041 fCurrentTrigger = NULL;
1042 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
1043 << " , fTriggerIndex = " << fTriggerIndex
1044 );
cbee67e7 1045}
8356cc1d 1046
1047
77650318 1048AliHLTMUONTriggerSource::AliEventData::AliEventData() :
1049 fEventNumber(-1), fBlocks(TClonesArray::Class())
8356cc1d 1050{
1051 fEventNumber = -1;
cbee67e7 1052}
8356cc1d 1053
1054
3a682eae 1055AliHLTMUONTriggerSource::AliEventData::AliEventData(Int_t eventnumber)
77650318 1056 : fEventNumber(eventnumber), fBlocks(TClonesArray::Class())
8356cc1d 1057{
3a682eae 1058// Create a new event data block with specified event number.
1059
8356cc1d 1060 fEventNumber = eventnumber;
1061
1062 // If the following is not set then we do not write the fBlocks properly.
1063 fBlocks.BypassStreamer(kFALSE);
cbee67e7 1064}
8356cc1d 1065
1066
3a682eae 1067AliHLTMUONTriggerSource::AliEventData::~AliEventData()
8356cc1d 1068{
12ab84fc 1069 //fBlocks.Clear("C"); // Done in fBlocks destructor
cbee67e7 1070}
8356cc1d 1071