]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDataInterface.cxx
Initial version (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
CommitLineData
13985652 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
48b32e42 17
48b32e42 18#include "AliMUONDataInterface.h"
e9bef706 19#include "AliMUONGeometryTransformer.h"
e8636ba0 20#include "AliMUONVDigit.h"
2060b217 21#include "AliMUONVCluster.h"
554b38a6 22#include "AliMUONTrack.h"
e8636ba0 23#include "AliMUONLocalTrigger.h"
24#include "AliMUONRegionalTrigger.h"
25#include "AliMUONGlobalTrigger.h"
26#include "AliMUONTriggerTrack.h"
e9bef706 27#include "AliMUONTriggerCircuit.h"
a202c2d2 28#include "AliMUONVClusterStore.h"
e9bef706 29#include "AliMUONVDigitStore.h"
a202c2d2 30#include "AliMUONVTrackStore.h"
e9bef706 31#include "AliMUONVTriggerStore.h"
a202c2d2 32#include "AliMUONVTriggerTrackStore.h"
c074480f 33#include "AliMpCDB.h"
e9bef706 34
e8636ba0 35#include "AliMpIntPair.h"
36#include "AliMpDEManager.h"
37#include "AliMpConstants.h"
a55f49a0 38#include "AliMpCDB.h"
e8636ba0 39
e9bef706 40#include "AliLoader.h"
41#include "AliLog.h"
e9bef706 42#include "AliRunLoader.h"
43
44#include <TError.h>
45#include <TParticle.h>
46#include <Riostream.h>
47#include <TFile.h>
a202c2d2 48#include <TList.h>
e9bef706 49#include <TNtuple.h>
50#include <TSystem.h>
e8636ba0 51#include <TIterator.h>
52#include <cstdlib>
53#include <cassert>
6d149c9e 54
3d1463c8 55//-----------------------------------------------------------------------------
85fec35d 56/// \class AliMUONDataInterface
57///
a202c2d2 58/// An easy to use interface to the MUON data data stored in
59/// TreeS, TreeD, TreeR and TreeT.
60///
61/// For MC related information (i.e. TreeH, TreeK, TreeTR), see
62/// AliMUONMCDataInterface.
63///
85fec35d 64///
65/// This interface in not necessarily the fastest way to fetch the data but
66/// it is the easiest.
85fec35d 67///
e8636ba0 68/// \author Laurent Aphecetche, Subatech & Artur Szostak <artursz@iafrica.com> (University of Cape Town)
3d1463c8 69//-----------------------------------------------------------------------------
13985652 70
71/// \cond CLASSIMP
72ClassImp(AliMUONDataInterface)
73/// \endcond
48b32e42 74
e9bef706 75
76Int_t AliMUONDataInterface::fgInstanceCounter(0);
77
a202c2d2 78//______________________________________________________________________________
79AliMUONDataInterface::AliMUONDataInterface(const char* filename)
e9bef706 80: TObject(),
81fLoader(0x0),
82fDigitStore(0x0),
83fTriggerStore(0x0),
84fClusterStore(0x0),
85fTrackStore(0x0),
86fTriggerTrackStore(0x0),
87fCurrentEvent(-1),
e8636ba0 88fIsValid(kFALSE),
89fCurrentIteratorType(kNoIterator),
90fCurrentIndex(-1),
91fDataX(-1),
92fDataY(-1),
93fIterator(0x0)
48b32e42 94{
a202c2d2 95 /// ctor
96 /// @param filename should be the full path to a valid galice.root file
97
e9bef706 98 ++fgInstanceCounter;
99
100 Open(filename);
a55f49a0 101
102 // Load mapping
103 if ( ! AliMpCDB::LoadDDLStore() ) {
104 AliFatal("Could not access mapping from OCDB !");
105 }
925e6570 106}
48b32e42 107
a202c2d2 108//______________________________________________________________________________
48b32e42 109AliMUONDataInterface::~AliMUONDataInterface()
110{
a202c2d2 111 /// dtor
e8636ba0 112 ResetStores();
113 if ( fLoader != 0x0 )
e9bef706 114 {
115 delete fLoader->GetRunLoader();
116 }
117 --fgInstanceCounter;
a202c2d2 118}
48b32e42 119
e8636ba0 120//______________________________________________________________________________
121AliMUONVDigitStore*
122AliMUONDataInterface::DigitStore(Int_t event)
123{
124 /// Return digitStore for a given event.
125 /// Return 0x0 if event not found.
126 /// Returned pointer should not be deleted
127
128 if (not IsValid()) return 0x0;
129 if (event == fCurrentEvent and fDigitStore != 0x0) return fDigitStore;
130
131 ResetStores();
132 if (not LoadEvent(event)) return 0x0;
133
134 fLoader->LoadDigits();
135
136 TTree* treeD = fLoader->TreeD();
137 if (treeD == 0x0)
138 {
139 AliError("Could not get treeD");
140 return 0x0;
141 }
142
143 fDigitStore = AliMUONVDigitStore::Create(*treeD);
144 if ( fDigitStore != 0x0 )
145 {
146 fDigitStore->Clear();
147 fDigitStore->Connect(*treeD);
148 treeD->GetEvent(0);
149 }
150
151 fLoader->UnloadDigits();
152
153 return fDigitStore;
154}
155
a202c2d2 156//______________________________________________________________________________
157AliMUONVClusterStore*
e9bef706 158AliMUONDataInterface::ClusterStore(Int_t event)
a202c2d2 159{
e9bef706 160 /// Return clusterStore for a given event.
161 /// Return 0x0 if event not found.
162 /// Returned pointer should not be deleted
163
e8636ba0 164 if (not IsValid()) return 0x0;
165 if (event == fCurrentEvent and fClusterStore != 0x0) return fClusterStore;
166
167 ResetStores();
168 if (not LoadEvent(event)) return 0x0;
e9bef706 169
170 fLoader->LoadRecPoints();
171
172 TTree* treeR = fLoader->TreeR();
e8636ba0 173 if (treeR == 0x0)
e9bef706 174 {
175 AliError("Could not get treeR");
176 return 0x0;
177 }
178
e8636ba0 179 fClusterStore = AliMUONVClusterStore::Create(*treeR);
180 if ( fClusterStore != 0x0 )
e9bef706 181 {
182 fClusterStore->Clear();
183 fClusterStore->Connect(*treeR);
184 treeR->GetEvent(0);
185 }
186
187 fLoader->UnloadRecPoints();
188
189 return fClusterStore;
190}
3455463a 191
e9bef706 192//______________________________________________________________________________
e8636ba0 193AliMUONVTrackStore*
194AliMUONDataInterface::TrackStore(Int_t event)
e9bef706 195{
e8636ba0 196 /// Return the trackStore for a given event.
e9bef706 197 /// Return 0x0 if event not found.
198 /// Returned pointer should not be deleted
199
e8636ba0 200 if (not IsValid()) return 0x0;
201 if (event == fCurrentEvent and fTrackStore != 0x0) return fTrackStore;
e9bef706 202
e8636ba0 203 ResetStores();
204 if (not LoadEvent(event)) return 0x0;
e9bef706 205
e8636ba0 206 fLoader->LoadTracks();
e9bef706 207
e8636ba0 208 TTree* treeT = fLoader->TreeT();
209 if (treeT == 0x0)
e9bef706 210 {
e8636ba0 211 AliError("Could not get treeT");
e9bef706 212 return 0x0;
213 }
214
e8636ba0 215 fTrackStore = AliMUONVTrackStore::Create(*treeT);
216 if ( fTrackStore != 0x0 )
e9bef706 217 {
e8636ba0 218 fTrackStore->Clear();
219 fTrackStore->Connect(*treeT);
220 treeT->GetEvent(0);
e9bef706 221 }
222
e8636ba0 223 fLoader->UnloadTracks();
224
225 return fTrackStore;
226}
227
228//______________________________________________________________________________
229AliMUONVTriggerTrackStore*
230AliMUONDataInterface::TriggerTrackStore(Int_t event)
231{
232 /// Return the triggerTrackStore for a given event.
233 /// Return 0x0 if event not found.
234 /// Returned pointer should not be deleted
235
236 if (not IsValid()) return 0x0;
237 if (event == fCurrentEvent and fTriggerTrackStore != 0x0) return fTriggerTrackStore;
238
239 ResetStores();
240 if (not LoadEvent(event)) return 0x0;
241
242 fLoader->LoadTracks();
243
244 TTree* treeT = fLoader->TreeT();
245 if (treeT == 0x0)
e9bef706 246 {
e8636ba0 247 AliError("Could not get treeT");
248 return 0x0;
e9bef706 249 }
250
e8636ba0 251 fTriggerTrackStore = AliMUONVTriggerTrackStore::Create(*treeT);
252 if ( fTriggerTrackStore != 0x0 )
253 {
254 fTriggerTrackStore->Clear();
255 fTriggerTrackStore->Connect(*treeT);
256 treeT->GetEvent(0);
257 }
e9bef706 258
e8636ba0 259 fLoader->UnloadTracks();
260
261 return fTriggerTrackStore;
262}
263
264//_____________________________________________________________________________
265AliMUONVTriggerStore*
266AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
267{
268 /// Return the triggerStore for a given event.
269 /// Return 0x0 if event not found.
270 /// Returned pointer should not be deleted
271 /// treeLetter can be R or D to tell from which tree to read the information
272
273 if (not IsValid()) return 0x0;
274 if (event == fCurrentEvent and fTriggerStore != 0x0) return fTriggerStore;
275
276 ResetStores();
277 if (not LoadEvent(event)) return 0x0;
278
279 TTree* tree(0x0);
280
281 TString stree(treeLetter);
282 stree.ToUpper();
283
284 if ( stree == "D" )
285 {
286 fLoader->LoadDigits();
287 tree = fLoader->TreeD();
288 }
289 else if ( stree == "R" )
290 {
291 fLoader->LoadRecPoints();
292 tree = fLoader->TreeR();
293 }
294
295 if ( tree == 0x0 )
296 {
297 AliError(Form("Could not get tree%s",treeLetter));
298 return 0x0;
299 }
300
301 fTriggerStore = AliMUONVTriggerStore::Create(*tree);
302 if ( fTriggerStore != 0x0 )
303 {
304 fTriggerStore->Clear();
305 fTriggerStore->Connect(*tree);
306 tree->GetEvent(0);
307 }
308
309 if ( stree == "D" )
310 {
311 fLoader->UnloadDigits();
312 }
313 else if ( stree == "R" )
314 {
315 fLoader->UnloadRecPoints();
316 }
317
318 return fTriggerStore;
925e6570 319}
48b32e42 320
a202c2d2 321//______________________________________________________________________________
322void
e9bef706 323AliMUONDataInterface::DumpDigits(Int_t event, Bool_t sorted)
48b32e42 324{
e9bef706 325 /// Dump the digits for a given event, sorted if so required
326 DigitStore(event);
e8636ba0 327 if ( fDigitStore != 0x0 )
e9bef706 328 {
329 if ( sorted )
330 {
331 DumpSorted(*fDigitStore);
332 }
333 else
334 {
335 fDigitStore->Print();
336 }
337 }
925e6570 338}
48b32e42 339
a202c2d2 340//______________________________________________________________________________
e9bef706 341void
342AliMUONDataInterface::DumpRecPoints(Int_t event, Bool_t sorted)
6d149c9e 343{
e9bef706 344 /// Dump the recpoints for a given event, sorted if so required
345 ClusterStore(event);
e8636ba0 346 if ( fClusterStore != 0x0 )
e9bef706 347 {
348 if ( sorted )
349 {
350 DumpSorted(*fClusterStore);
351 }
352 else
353 {
354 fClusterStore->Print();
355 }
356 }
6d149c9e 357}
358
e9bef706 359//_____________________________________________________________________________
360void
361AliMUONDataInterface::DumpSorted(const AliMUONVStore& store) const
6d149c9e 362{
e9bef706 363 /// Dump the given store, in sorted order
a202c2d2 364
e9bef706 365 TIter next(store.CreateIterator());
a202c2d2 366 TObject* object;
e9bef706 367 TList list;
368 list.SetOwner(kFALSE);
a202c2d2 369
e9bef706 370 while ( ( object = next() ) )
a202c2d2 371 {
e9bef706 372 list.Add(object);
a202c2d2 373 }
374
e9bef706 375 list.Sort();
376
377 list.Print();
a202c2d2 378}
379
380//______________________________________________________________________________
381void
e9bef706 382AliMUONDataInterface::DumpTracks(Int_t event, Bool_t sorted)
a202c2d2 383{
e9bef706 384 /// Dump tracks for a given event, sorted if requested
385
386 TrackStore(event);
387
e8636ba0 388 if ( fTrackStore != 0x0 )
a202c2d2 389 {
e9bef706 390 if ( sorted )
391 {
392 DumpSorted(*fTrackStore);
393 }
394 else
395 {
396 fTrackStore->Print();
397 }
a202c2d2 398 }
e9bef706 399}
400
401//______________________________________________________________________________
402void
403AliMUONDataInterface::DumpTriggerTracks(Int_t event, Bool_t sorted)
404{
405 /// Dump trigger tracks for a given event, sorted if requested
406
407 TriggerTrackStore(event);
a202c2d2 408
e8636ba0 409 if ( fTriggerTrackStore != 0x0 )
a202c2d2 410 {
e9bef706 411 if ( sorted )
412 {
413 DumpSorted(*fTriggerTrackStore);
414 }
415 else
a202c2d2 416 {
e9bef706 417 fTriggerTrackStore->Print();
a202c2d2 418 }
e9bef706 419 }
420}
6d149c9e 421
e9bef706 422//_____________________________________________________________________________
423void
424AliMUONDataInterface::DumpTrigger(Int_t event, const char* treeLetter)
425{
426 /// Dump trigger for a given event from a given tree (if event>=0)
427 /// or loop over all events and build a trigger ntuple if event<0
428 /// treeLetter can be R or D to tell from which tree to read the information
a202c2d2 429
e9bef706 430 if ( event < 0 )
431 {
432 NtupleTrigger(treeLetter);
a202c2d2 433 }
434 else
435 {
e9bef706 436 TriggerStore(event,treeLetter);
a202c2d2 437
e8636ba0 438 if ( fTriggerStore != 0x0 )
e9bef706 439 {
440 fTriggerStore->Print();
441 }
442 }
a202c2d2 443}
6d149c9e 444
e9bef706 445//_____________________________________________________________________________
a202c2d2 446void
e9bef706 447AliMUONDataInterface::NtupleTrigger(const char* treeLetter)
48b32e42 448{
e9bef706 449 //// Loop over events to build trigger ntuples
450 ///
451
452 TString sTreeLetter(treeLetter);
453 sTreeLetter.ToUpper();
454
455 if ( sTreeLetter != "R" && sTreeLetter != "D" )
456 {
457 AliError(Form("Cannot handle tree%s. Use D or R",treeLetter));
458 return;
459 }
460
461 // book ntuples
462 TNtuple tupleGlo("TgtupleGlo","Global Trigger Ntuple",
463 "ev:slpt:shpt:uplpt:uphpt:lplpt:lplpt");
464 TNtuple tupleLoc("TgtupleLoc","Local Trigger Ntuple",
465 "ev:LoCircuit:LoStripX:LoDev:StripY:LoLpt:LoHpt:y11:y21:x11");
466
467 // initialize counters
468 Int_t sLowpt=0;
469 Int_t sHighpt=0;
470 Int_t uSLowpt=0;
471 Int_t uSHighpt=0;
472 Int_t lSLowpt=0;
473 Int_t lSHighpt=0;
474
d3acfadf 475 AliMUONGeometryTransformer transformer;
ef4cb4f1 476 transformer.LoadGeometryData(Form("%s/geometry.root",
e9bef706 477 gSystem->DirName(fLoader->GetRunLoader()->GetFileName())));
a55f49a0 478 AliMUONTriggerCircuit triggerCircuit(&transformer);
e9bef706 479
480 // select output file name from selected Tree
481 Char_t fileNameOut[30];
482 if (sTreeLetter == "D")
483 {
484 AliInfo(Form("reading from Digits\n"));
485 sprintf(fileNameOut,"TriggerCheckFromDigits.root");
486 }
487 else if (sTreeLetter == "R")
488 {
489 AliInfo(Form("reading from RecPoints\n"));
490 sprintf(fileNameOut,"TriggerCheckFromRP.root");
491 }
492
493 // loop on events
494 Int_t nevents = NumberOfEvents();
495
496 for (Int_t ievent=0; ievent<nevents; ++ievent)
497 {
498 if (ievent%100==0) AliInfo(Form("Processing event %d\n",ievent));
499
500 AliMUONVTriggerStore* triggerStore = TriggerStore(ievent);
501
502 if (!triggerStore)
503 {
504 AliError(Form("Could not read %s from tree%s","Trigger",treeLetter));
505 return;
506 }
507
508 // get global trigger info
509 AliMUONGlobalTrigger* gloTrg = triggerStore->Global();
510 sLowpt+=gloTrg->SingleLpt();
511 sHighpt+=gloTrg->SingleHpt();
512 uSLowpt+=gloTrg->PairUnlikeLpt();
513 uSHighpt+=gloTrg->PairUnlikeHpt();
514 lSLowpt+=gloTrg->PairLikeLpt();
515 lSHighpt+=gloTrg->PairLikeHpt();
516
517 // loop on local triggers
518 TIter next(triggerStore->CreateIterator());
519 AliMUONLocalTrigger* locTrg(0x0);
520 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
521 {
522 Bool_t xTrig=kFALSE;
523 Bool_t yTrig=kFALSE;
524
525 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
526 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
527 else xTrig=kTRUE; // trigger in X
528 if (locTrg->LoTrigY()==1 &&
529 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
530 else yTrig = kTRUE; // trigger in Y
531
532 if (xTrig && yTrig)
533 { // fill ntuple if trigger in X and Y
534 tupleLoc.Fill(ievent,locTrg->LoCircuit(),
535 locTrg->LoStripX(),
536 locTrg->LoDev(),
537 locTrg->LoStripY(),
538 locTrg->LoLpt(),
539 locTrg->LoHpt(),
540 triggerCircuit.GetY11Pos(locTrg->LoCircuit(),locTrg->LoStripX()),
541 triggerCircuit.GetY21Pos(locTrg->LoCircuit(),locTrg->LoStripX()+locTrg->LoDev()+1),
542 triggerCircuit.GetX11Pos(locTrg->LoCircuit(),locTrg->LoStripY()));
543 }
544 tupleGlo.Fill(ievent,gloTrg->SingleLpt(),gloTrg->SingleHpt(),
545 gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),
546 gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
547 } // end of loop on local triggers
548 } // end of loop on events
549
550 // print info and store ntuples
551 printf("\n");
552 printf("=============================================\n");
553 printf("================ SUMMARY ==================\n");
554 printf("\n");
555 printf("Total number of events processed %d \n",nevents);
556 printf("\n");
557 printf(" Global Trigger output Low pt High pt\n");
558 printf(" number of Single :\t");
559 printf("%i\t%i\t",sLowpt,sHighpt);
560 printf("\n");
561 printf(" number of UnlikeSign pair :\t");
562 printf("%i\t%i\t",uSLowpt,uSHighpt);
563 printf("\n");
564 printf(" number of LikeSign pair :\t");
565 printf("%i\t%i\t",lSLowpt,lSHighpt);
566 printf("\n");
567 printf("=============================================\n");
568 fflush(stdout);
569
570 TFile myFile(fileNameOut, "RECREATE");
571 tupleGlo.Write();
572 tupleLoc.Write();
573 myFile.Close();
925e6570 574}
48b32e42 575
e9bef706 576//_____________________________________________________________________________
e8636ba0 577Bool_t
e9bef706 578AliMUONDataInterface::LoadEvent(Int_t event)
48b32e42 579{
e9bef706 580 /// Load event if different from the current one.
e8636ba0 581 /// Returns kFALSE on error and kTRUE if the event was loaded.
582
583 assert( IsValid() );
584
585 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
586 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
e9bef706 587 {
588 fCurrentEvent = event;
e8636ba0 589 return kTRUE;
e9bef706 590 }
e8636ba0 591 else
592 return kFALSE;
925e6570 593}
48b32e42 594
a202c2d2 595//______________________________________________________________________________
e9bef706 596Int_t
597AliMUONDataInterface::NumberOfEvents() const
a202c2d2 598{
e9bef706 599 /// Number of events in the current galice.root file we're attached to
e8636ba0 600 if (not IsValid()) return -1;
e9bef706 601 return fLoader->GetRunLoader()->GetNumberOfEvents();
a202c2d2 602}
48b32e42 603
e9bef706 604//_____________________________________________________________________________
a202c2d2 605void
e9bef706 606AliMUONDataInterface::Open(const char* filename)
48b32e42 607{
e9bef706 608 /// Connect to a given galice.root file
609
e8636ba0 610 ResetStores();
e9bef706 611
612 fCurrentEvent=-1;
613
e8636ba0 614 if ( fLoader != 0x0 )
e9bef706 615 {
616 delete fLoader->GetRunLoader();
617 }
618
619 fLoader = 0x0;
620
621 fIsValid = kTRUE;
622
623 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
624
e8636ba0 625 while (AliRunLoader::GetRunLoader(foldername) != 0x0)
e9bef706 626 {
627 delete AliRunLoader::GetRunLoader(foldername);
628 }
629
630 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
e8636ba0 631 if (runLoader == 0x0)
e9bef706 632 {
633 AliError(Form("Cannot open file %s",filename));
634 fIsValid = kFALSE;
635 }
636 fLoader = runLoader->GetDetectorLoader("MUON");
e8636ba0 637 if (fLoader == 0x0)
e9bef706 638 {
639 AliError("Cannot get AliMUONLoader");
640 fIsValid = kFALSE;
641 }
642
e8636ba0 643 if (not IsValid())
e9bef706 644 {
645 AliError(Form("Could not access %s filename. Object is unuseable",filename));
646 }
925e6570 647}
48b32e42 648
e9bef706 649//_____________________________________________________________________________
e8636ba0 650Bool_t AliMUONDataInterface::GetEvent(Int_t event)
48b32e42 651{
e8636ba0 652/// Loads all reconstructed data for the given event.
653
654 if (DigitStore(event) == 0x0) return kFALSE;
655 if (ClusterStore(event) == 0x0) return kFALSE;
656 if (TrackStore(event) == 0x0) return kFALSE;
657 if (TriggerStore(event) == 0x0) return kFALSE;
658 if (TriggerTrackStore(event) == 0x0) return kFALSE;
659 return kTRUE;
925e6570 660}
48b32e42 661
e8636ba0 662//_____________________________________________________________________________
663Int_t AliMUONDataInterface::NumberOfDigits(Int_t detElemId)
48b32e42 664{
e8636ba0 665/// Returns the number of digits to be found on a given detector element.
666/// @param detElemId The detector element ID number to search on.
a202c2d2 667
e8636ba0 668 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
669 return CountObjects(iter);
925e6570 670}
48b32e42 671
e8636ba0 672//_____________________________________________________________________________
673AliMUONVDigit* AliMUONDataInterface::Digit(Int_t detElemId, Int_t index)
48b32e42 674{
e8636ba0 675/// Returns the a pointer to the index'th digit on the specified detector element.
676/// @param detElemId The detector element ID number to search on.
677/// @param index The index number of the digit to fetch in the range [0 .. N-1],
678/// where N = NumberOfDigits(detElemId)
a202c2d2 679
e8636ba0 680 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
681 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
925e6570 682}
48b32e42 683
e8636ba0 684//_____________________________________________________________________________
685Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
48b32e42 686{
e8636ba0 687/// Returns the number of digits to be found on a specific chamber and cathode.
688/// @param chamber The chamber number in the range [0 .. 13].
689/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
690/// 1 is the non-bending plane.
48b32e42 691
e8636ba0 692 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
693 return CountObjects(iter);
925e6570 694}
48b32e42 695
e8636ba0 696//_____________________________________________________________________________
697AliMUONVDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
48b32e42 698{
e8636ba0 699/// Returns the a pointer to the index'th digit on the specified chamber and cathode.
700/// @param chamber The chamber number in the range [0 .. 13].
701/// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
702/// 1 is the non-bending plane.
703/// @param index The index number of the digit to fetch in the range [0 .. N-1],
704/// where N = NumberOfDigits(chamber, cathode)
705
706 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
707 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
925e6570 708}
48b32e42 709
e8636ba0 710//_____________________________________________________________________________
711Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
48b32e42 712{
e8636ba0 713/// Returns the number of reconstructed raw clusters on the specified chamber.
714/// @param chamber The chamber number in the range [0 .. 13].
a202c2d2 715
e8636ba0 716 TIterator* iter = GetIterator(kRawClusterIterator, chamber);
717 return CountObjects(iter);
925e6570 718}
48b32e42 719
e8636ba0 720//_____________________________________________________________________________
2060b217 721AliMUONVCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t index)
48b32e42 722{
e8636ba0 723/// Returns a pointer to the index'th raw cluster on the specified chamber.
724/// @param chamber The chamber number in the range [0 .. 13].
725/// @param index The index number of the raw cluster to fetch in the range [0 .. N-1],
726/// where N = NumberOfRawClusters(chamber)
a202c2d2 727
e8636ba0 728 TIterator* iter = GetIterator(kRawClusterIterator, chamber);
2060b217 729 return static_cast<AliMUONVCluster*>( FetchObject(iter, index) );
925e6570 730}
48b32e42 731
e8636ba0 732//_____________________________________________________________________________
48b32e42 733Int_t AliMUONDataInterface::NumberOfTracks()
734{
e8636ba0 735/// Returns the number of reconstructed tracks.
a202c2d2 736
e8636ba0 737 TIterator* iter = GetIterator(kTrackIterator);
738 return CountObjects(iter);
925e6570 739}
48b32e42 740
e8636ba0 741//_____________________________________________________________________________
742AliMUONTrack* AliMUONDataInterface::Track(Int_t index)
48b32e42 743{
e8636ba0 744/// Returns a pointer to the index'th reconstructed track.
745/// @param index The index number of the track to fetch in the range [0 .. N-1],
746/// where N = NumberOfTracks()
a202c2d2 747
e8636ba0 748 TIterator* iter = GetIterator(kTrackIterator);
749 return static_cast<AliMUONTrack*>( FetchObject(iter, index) );
925e6570 750}
48b32e42 751
e8636ba0 752//_____________________________________________________________________________
753Int_t AliMUONDataInterface::NumberOfLocalTriggers()
48b32e42 754{
e8636ba0 755/// Returns the number of reconstructed local trigger objects.
a202c2d2 756
e8636ba0 757 TIterator* iter = GetIterator(kLocalTriggerIterator);
758 return CountObjects(iter);
925e6570 759}
48b32e42 760
e8636ba0 761//_____________________________________________________________________________
762AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t index)
48b32e42 763{
e8636ba0 764/// Returns a pointer to the index'th local trigger object.
765/// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
766/// where N = NumberOfLocalTriggers()
a202c2d2 767
e8636ba0 768 TIterator* iter = GetIterator(kLocalTriggerIterator);
769 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
925e6570 770}
48b32e42 771
e8636ba0 772//_____________________________________________________________________________
773Int_t AliMUONDataInterface::NumberOfRegionalTriggers()
48b32e42 774{
e8636ba0 775/// Returns the number of regional trigger objects reconstructed.
a202c2d2 776
e8636ba0 777 TIterator* iter = GetIterator(kRegionalTriggerIterator);
778 return CountObjects(iter);
925e6570 779}
48b32e42 780
e8636ba0 781//_____________________________________________________________________________
782AliMUONRegionalTrigger* AliMUONDataInterface::RegionalTrigger(Int_t index)
48b32e42 783{
e8636ba0 784/// Returns a pointer to the index'th regional trigger object.
785/// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
786/// where N = NumberOfRegionalTriggers()
a202c2d2 787
e8636ba0 788 TIterator* iter = GetIterator(kRegionalTriggerIterator);
789 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
925e6570 790}
48b32e42 791
e8636ba0 792//_____________________________________________________________________________
793AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger()
48b32e42 794{
e8636ba0 795/// Returns a pointer to the reconstructed global trigger object for the event.
a202c2d2 796
e8636ba0 797 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
798 if (store == 0x0) return 0x0;
799 return store->Global();
925e6570 800}
48b32e42 801
e8636ba0 802//_____________________________________________________________________________
803Int_t AliMUONDataInterface::NumberOfTriggerTracks()
48b32e42 804{
e8636ba0 805/// Returns the number of reconstructed tracks in the trigger chambers.
a202c2d2 806
e8636ba0 807 TIterator* iter = GetIterator(kTriggerTrackIterator);
808 return CountObjects(iter);
925e6570 809}
48b32e42 810
e8636ba0 811//_____________________________________________________________________________
812AliMUONTriggerTrack* AliMUONDataInterface::TriggerTrack(Int_t index)
48b32e42 813{
e8636ba0 814/// Returns a pointer to the index'th reconstructed trigger track object.
815/// @param index The index number of the trigger track to fetch in the range [0 .. N-1],
816/// where N = NumberOfTriggerTracks()
a202c2d2 817
e8636ba0 818 TIterator* iter = GetIterator(kTriggerTrackIterator);
819 return static_cast<AliMUONTriggerTrack*>( FetchObject(iter, index) );
925e6570 820}
48b32e42 821
e8636ba0 822//_____________________________________________________________________________
823void AliMUONDataInterface::ResetStores()
48b32e42 824{
e8636ba0 825/// Deletes all the store objects that have been created and resets the pointers to 0x0.
826/// The temporary iterator object is automatically reset. See ResetIterator for more details.
a202c2d2 827
e8636ba0 828 ResetIterator();
829 if (fDigitStore != 0x0)
830 {
831 delete fDigitStore;
832 fDigitStore = 0x0;
833 }
834 if (fTriggerStore != 0x0)
835 {
836 delete fTriggerStore;
837 fTriggerStore = 0x0;
838 }
839 if (fClusterStore != 0x0)
840 {
841 delete fClusterStore;
842 fClusterStore = 0x0;
843 }
844 if (fTrackStore != 0x0)
845 {
846 delete fTrackStore;
847 fTrackStore = 0x0;
848 }
849 if (fTriggerTrackStore != 0x0)
850 {
851 delete fTriggerTrackStore;
852 fTriggerTrackStore = 0x0;
853 }
925e6570 854}
554b38a6 855
e8636ba0 856//_____________________________________________________________________________
857TIterator* AliMUONDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
554b38a6 858{
e8636ba0 859/// Creates an appropriate iterator object and returns it.
860/// If the iterator has already been created then that one is returned otherwise
861/// a new object is created.
862/// Depending on the value of 'type' the semantics of parameters x and y can change.
863/// @param type The type of iterator to create.
864/// @param x This is the detector element ID if type == kDigitIteratorByDetectorElement
865/// If type equals kDigitIteratorByChamberAndCathode or kRawClusterIterator
866/// then this is the chamber number. In all other cases this parameter is
867/// ignored.
868/// @param y If type == kDigitIteratorByChamberAndCathode then this parameter is the
869/// cathode number. In all other cases this parameter is
870/// ignored.
871
872 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
873 return fIterator;
874
875 if (fCurrentEvent == -1)
876 {
877 AliError("No event was selected. Try first using GetEvent().");
878 return 0x0;
879 }
880
881 ResetIterator();
882
883 switch (type)
884 {
885 case kDigitIteratorByDetectorElement:
886 {
887 Int_t detElem = x;
888 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
889 if (store == 0x0) return 0x0;
e8636ba0 890 fIterator = store->CreateIterator(detElem, detElem, 2);
891 if (fIterator == 0x0) return 0x0;
892 fCurrentIteratorType = kDigitIteratorByDetectorElement;
893 fDataX = detElem;
894 return fIterator;
895 }
896
897 case kDigitIteratorByChamberAndCathode:
898 {
899 Int_t chamber = x;
900 Int_t cathode = y;
901 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
902 {
903 AliError(Form(
904 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
905 AliMpConstants::NofChambers() - 1,
906 chamber
907 ));
908 return 0x0;
909 }
910 if (cathode < 0 or 1 < cathode)
911 {
912 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
913 return 0x0;
914 }
915
916 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
917 if (store == 0x0) return 0x0;
e8636ba0 918 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
919 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
920 if (fIterator == 0x0) return 0x0;
921 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
922 fDataX = chamber;
923 fDataY = cathode;
924 return fIterator;
925 }
926
927 case kRawClusterIterator:
928 {
929 Int_t chamber = x;
930 AliMUONVClusterStore* store = ClusterStore(fCurrentEvent);
931 if (store == 0x0) return 0x0;
932 fIterator = store->CreateChamberIterator(chamber, chamber);
933 if (fIterator == 0x0) return 0x0;
934 fCurrentIteratorType = kRawClusterIterator;
935 fDataX = chamber;
936 return fIterator;
937 }
938
939 case kTrackIterator:
940 {
941 AliMUONVTrackStore* store = TrackStore(fCurrentEvent);
942 if (store == 0x0) return 0x0;
943 fIterator = store->CreateIterator();
944 if (fIterator == 0x0) return 0x0;
945 fCurrentIteratorType = kTrackIterator;
946 return fIterator;
947 }
948
949 case kLocalTriggerIterator:
950 {
951 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
952 if (store == 0x0) return 0x0;
953 fIterator = store->CreateLocalIterator();
954 if (fIterator == 0x0) return 0x0;
955 fCurrentIteratorType = kLocalTriggerIterator;
956 return fIterator;
957 }
958
959 case kRegionalTriggerIterator:
960 {
961 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
962 if (store == 0x0) return 0x0;
963 fIterator = store->CreateRegionalIterator();
964 if (fIterator == 0x0) return 0x0;
965 fCurrentIteratorType = kRegionalTriggerIterator;
966 return fIterator;
967 }
968
969 case kTriggerTrackIterator:
970 {
971 AliMUONVTriggerTrackStore* store = TriggerTrackStore(fCurrentEvent);
972 if (store == 0x0) return 0x0;
973 fIterator = store->CreateIterator();
974 if (fIterator == 0x0) return 0x0;
975 fCurrentIteratorType = kTriggerTrackIterator;
976 return fIterator;
977 }
978
979 default:
980 return 0x0;
981 }
554b38a6 982}
983
e8636ba0 984//_____________________________________________________________________________
985void AliMUONDataInterface::ResetIterator()
554b38a6 986{
e8636ba0 987/// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
988/// The iterator type and temporary data indicating the state of the iterator are
989/// also reset.
990
991 if (fIterator != 0x0) delete fIterator;
992 fCurrentIteratorType = kNoIterator;
993 fCurrentIndex = fDataX = fDataY = -1;
994 fIterator = 0x0;
554b38a6 995}
996
e8636ba0 997//_____________________________________________________________________________
998Int_t AliMUONDataInterface::CountObjects(TIterator* iter)
554b38a6 999{
e8636ba0 1000/// Counts the number of objects in the iterator and resets it.
1001/// @return The number of objects in 'iter'.
1002
1003 if (iter == 0x0) return -1;
1004 Int_t count = 0;
1005 iter->Reset();
1006 while ( iter->Next() != 0x0 ) count++;
1007 iter->Reset();
1008 fCurrentIndex = -1;
1009 return count;
554b38a6 1010}
1011
e8636ba0 1012//_____________________________________________________________________________
1013TObject* AliMUONDataInterface::FetchObject(TIterator* iter, Int_t index)
554b38a6 1014{
e8636ba0 1015/// Fetches the index'th object from the iterator counting the first object
1016/// returned by iterator after it is reset as index == 0. The next object
1017/// has index == 1 and so on where the last object returned by the iterator
1018/// has index == N-1 where N = CountObjects(iter)
1019/// This method will only reset the iterator if index is smaller than
1020/// fCurrentIndex, which is used to track the iteration progress and is
1021/// updated when a new object if returned by this method.
1022/// @param iter The iterator to fetch an object from.
1023/// @param index The index number of the object to fetch in the range [0 .. N-1]
1024/// where N = CountObjects(iter)
1025
1026 if (index < 0)
1027 {
1028 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1029 return 0x0;
1030 }
a202c2d2 1031
e8636ba0 1032 if (iter == 0x0) return 0x0;
1033 if (index <= fCurrentIndex)
1034 {
1035 iter->Reset();
1036 fCurrentIndex = -1;
1037 }
1038
1039 TObject* object = 0x0;
1040 while (fCurrentIndex < index)
1041 {
1042 object = iter->Next();
1043 if (object == 0x0)
1044 {
1045 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1046 iter->Reset();
1047 fCurrentIndex = -1;
1048 return 0x0;
1049 }
1050 fCurrentIndex++;
1051 }
1052 return object;
554b38a6 1053}