1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONMCDataInterface
21 /// Easy to use MC data accessor
23 /// \author Laurent Aphecetche, Subatech
25 // Moved parts of old AliMUONDataInterface interface to AliMUONMCDataInterface
26 // Artur Szostak <artursz@iafrica.com> (University of Cape Town)
27 //-----------------------------------------------------------------------------
29 #include "AliMUONMCDataInterface.h"
30 #include "AliMUONVDigitStore.h"
31 #include "AliMUONVHitStore.h"
32 #include "AliMUONVTriggerStore.h"
33 #include "AliMUONHit.h"
34 #include "AliMUONVDigit.h"
35 #include "AliMUONLocalTrigger.h"
36 #include "AliMUONRegionalTrigger.h"
37 #include "AliMUONGlobalTrigger.h"
39 #include "AliMpIntPair.h"
40 #include "AliMpDEManager.h"
41 #include "AliMpConstants.h"
45 #include "AliRunLoader.h"
46 #include "AliHeader.h"
48 #include "AliCDBManager.h"
50 #include <Riostream.h>
51 #include <TClonesArray.h>
53 #include <TParticle.h>
54 #include <TIterator.h>
59 ClassImp(AliMUONMCDataInterface)
62 Int_t AliMUONMCDataInterface::fgInstanceCounter(0);
64 //_____________________________________________________________________________
65 AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
75 fCurrentIteratorType(kNoIterator),
88 if ( ! AliMpCDB::LoadMpSegmentation() ) {
89 AliFatal("Could not access mapping from OCDB !");
93 //_____________________________________________________________________________
94 AliMUONMCDataInterface::~AliMUONMCDataInterface()
99 delete fLoader->GetRunLoader();
104 //_____________________________________________________________________________
106 AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
108 /// Return the hitStore for a given track of one event
109 /// Return 0x0 if event and/or track not found
110 /// Returned pointer should not be deleted
112 if (not IsValid()) return 0x0;
114 if (event == fCurrentEvent)
116 if (track == fDataX and fHitStore != 0x0) // using fDataX as track number.
122 if ( not LoadEvent(event) ) return 0x0;
127 TTree* treeH = fLoader->TreeH();
130 AliError("Could not get treeH");
134 fHitStore = AliMUONVHitStore::Create(*treeH);
135 AliDebug(1,"Creating hitStore from treeH");
136 if ( fHitStore != 0x0 )
138 fHitStore->Connect(*treeH);
139 if ( treeH->GetEvent(track) == 0 )
141 AliError(Form("Could not read track %d",track));
145 fDataX = track; // using fDataX as track number.
148 fLoader->UnloadHits();
153 //_____________________________________________________________________________
155 AliMUONMCDataInterface::SDigitStore(Int_t event)
157 /// Return the SDigit store for a given event.
158 /// Return 0 if event not found
159 /// Returned pointer should not be deleted
161 if (not IsValid()) return 0x0;
163 if (event == fCurrentEvent)
165 if (fSDigitStore != 0x0)
171 if ( not LoadEvent(event) ) return 0x0;
174 fLoader->LoadSDigits();
176 TTree* treeS = fLoader->TreeS();
179 AliError("Could not get treeS");
183 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
184 if ( fSDigitStore != 0x0 )
186 fSDigitStore->Clear();
187 fSDigitStore->Connect(*treeS);
191 fLoader->UnloadSDigits();
196 //_____________________________________________________________________________
198 AliMUONMCDataInterface::DigitStore(Int_t event)
200 /// Return a pointer to the digitStore for a given event (or 0 if not found)
201 /// Returned pointer should not be deleted
203 if (not IsValid()) return 0x0;
205 if (event == fCurrentEvent)
207 if (fDigitStore != 0x0)
213 if ( not LoadEvent(event) ) return 0x0;
216 fLoader->LoadDigits();
218 TTree* treeD = fLoader->TreeD();
221 AliError("Could not get treeD");
225 fDigitStore = AliMUONVDigitStore::Create(*treeD);
226 if ( fDigitStore != 0x0 )
228 fDigitStore->Clear();
229 fDigitStore->Connect(*treeD);
233 fLoader->UnloadDigits();
238 //_____________________________________________________________________________
240 AliMUONMCDataInterface::Stack(Int_t event)
242 /// Get the Stack (list of generated particles) for one event
243 /// Returned pointer should not be deleted
245 if ( not IsValid() ) return 0x0;
247 if (event != fCurrentEvent)
250 if ( not LoadEvent(event) ) return 0x0;
253 fLoader->GetRunLoader()->LoadKinematics();
255 return fLoader->GetRunLoader()->Stack();
258 //_____________________________________________________________________________
260 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
262 /// Get the track references for a given (generated) track of one event
263 /// Returned pointer should not be deleted
265 if ( not IsValid() ) return 0x0;
267 if (event == fCurrentEvent)
269 if (track == fDataX and fTrackRefs != 0x0) // using fDataX as track number.
275 if ( not LoadEvent(event) ) return 0x0;
278 fLoader->GetRunLoader()->LoadTrackRefs();
280 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
282 if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
286 if ( treeTR->GetEvent(track) > 0 )
288 TBranch* branch = treeTR->GetBranch("TrackReferences");
289 branch->SetAddress(&fTrackRefs);
290 branch->GetEvent(track);
291 fDataX = track; // using fDataX as track number.
296 AliError("Could not get TreeTR");
299 fLoader->GetRunLoader()->UnloadTrackRefs();
304 //_____________________________________________________________________________
305 AliMUONVTriggerStore*
306 AliMUONMCDataInterface::TriggerStore(Int_t event)
308 /// Return the triggerStore for a given event.
309 /// Return 0x0 if event not found.
310 /// Returned pointer should not be deleted.
312 if (not IsValid()) return 0x0;
314 if (event == fCurrentEvent)
316 if (fTriggerStore != 0x0)
317 return fTriggerStore;
322 if ( not LoadEvent(event) ) return 0x0;
325 fLoader->LoadDigits();
327 TTree* treeD = fLoader->TreeD();
330 AliError("Could not get treeD");
334 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
335 if ( fTriggerStore != 0x0 )
337 fTriggerStore->Clear();
338 fTriggerStore->Connect(*treeD);
342 fLoader->UnloadDigits();
344 return fTriggerStore;
347 //_____________________________________________________________________________
349 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
351 /// Dump the digits for a given event, sorted if requested.
354 if ( fDigitStore != 0x0 )
358 DumpSorted(*fDigitStore);
362 fDigitStore->Print();
367 //_____________________________________________________________________________
369 AliMUONMCDataInterface::DumpHits(Int_t event)
371 /// Dump all the hits for one event
373 Int_t ntracks = NumberOfTracks(event);
375 for ( Int_t i = 0; i < ntracks; ++i )
377 cout << ">> Track " << i << endl;
381 fHitStore->Print("","full");
386 //_____________________________________________________________________________
388 AliMUONMCDataInterface::DumpKine(Int_t event)
390 /// Dump all generated particles for one event
391 AliStack* stack = Stack(event);
395 Int_t nparticles = (Int_t) stack->GetNtrack();
397 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
399 stack->Particle(iparticle)->Print("");
404 AliError("Could not get stack");
408 //_____________________________________________________________________________
410 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
412 /// Dump the SDigits for a given event, sorted if requested
415 if ( fSDigitStore != 0x0 )
419 DumpSorted(*fSDigitStore);
423 fSDigitStore->Print();
428 //_____________________________________________________________________________
430 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
432 /// Dump the given store in sorted order
434 TIter next(store.CreateIterator());
437 list.SetOwner(kFALSE);
439 while ( ( object = next() ) )
449 //_____________________________________________________________________________
451 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
453 /// Dump track references for one event
454 Int_t ntrackrefs = NumberOfTrackRefs(event);
456 for ( Int_t i = 0; i < ntrackrefs; ++i )
459 if ( fTrackRefs != 0x0 )
461 fTrackRefs->Print("","*");
466 //_____________________________________________________________________________
468 AliMUONMCDataInterface::DumpTrigger(Int_t event)
470 /// Dump trigger for a given event (trigger is read from TreeD)
474 if ( fTriggerStore != 0x0 )
476 fTriggerStore->Print();
480 //_____________________________________________________________________________
482 AliMUONMCDataInterface::LoadEvent(Int_t event)
484 /// Load event if different from the current one.
485 /// Returns kFALSE on error and kTRUE if the event was loaded.
489 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
490 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
492 fCurrentEvent = event;
500 //_____________________________________________________________________________
502 AliMUONMCDataInterface::NumberOfEvents() const
504 /// Number of events in the file we're connected to
505 if (not IsValid()) return -1;
506 return fLoader->GetRunLoader()->GetNumberOfEvents();
509 //_____________________________________________________________________________
511 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
513 /// Number of tracks in the event
514 if ( not IsValid()) return -1;
516 if (event != fCurrentEvent)
519 if ( not LoadEvent(event) ) return -1;
526 TTree* treeH = fLoader->TreeH();
529 rv = static_cast<Int_t>(treeH->GetEntries());
533 AliError("Could not get TreeH");
536 fLoader->UnloadHits();
541 //_____________________________________________________________________________
543 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
545 /// Number of track references in the event
546 if ( not IsValid()) return -1;
548 if (event != fCurrentEvent)
551 if ( not LoadEvent(event) ) return -1;
554 fLoader->GetRunLoader()->LoadTrackRefs();
558 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
561 rv = static_cast<Int_t>(treeTR->GetEntries());
565 AliError("Could not get TreeTR");
568 fLoader->GetRunLoader()->UnloadTrackRefs();
573 //_____________________________________________________________________________
575 AliMUONMCDataInterface::Open(const char* filename)
577 /// Connect to a given galice.root file
583 if ( fLoader != 0x0 )
585 delete fLoader->GetRunLoader();
592 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
594 while (AliRunLoader::GetRunLoader(foldername))
596 delete AliRunLoader::GetRunLoader(foldername);
599 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
600 if (runLoader == 0x0)
602 AliError(Form("Cannot open file %s",filename));
606 // Get run number and set it to CDB manager
607 runLoader->LoadHeader();
608 if ( ! runLoader->GetHeader() ) {
609 AliError("Cannot load header.");
613 Int_t runNumber = runLoader->GetHeader()->GetRun();
614 AliCDBManager::Instance()->SetRun(runNumber);
616 runLoader->UnloadHeader();
618 fLoader = runLoader->GetDetectorLoader("MUON");
621 AliError("Cannot get AliMUONLoader");
627 AliError(Form("Could not access %s filename. Object is unuseable",filename));
631 //_____________________________________________________________________________
632 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
634 /// Loads all simulated data for the given event.
636 if (HitStore(event, 0) == 0x0) return kFALSE;
637 if (SDigitStore(event) == 0x0) return kFALSE;
638 if (DigitStore(event) == 0x0) return kFALSE;
639 if (TriggerStore(event) == 0x0) return kFALSE;
640 if (TrackRefs(event, 0) == 0x0) return kFALSE;
644 //_____________________________________________________________________________
645 Int_t AliMUONMCDataInterface::NumberOfParticles()
647 /// Returns the total number of particles in the kinematics tree.
649 AliStack* stack = Stack(fCurrentEvent);
650 if ( stack == 0x0 ) return -1;
651 return (Int_t) stack->GetNtrack();
654 //_____________________________________________________________________________
655 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
657 /// Returns the index'th particle in the kinematics tree.
658 /// @param index The index number of the particle in the range [0 ... N-1]
659 /// where N = NumberOfParticles()
661 AliStack* stack = Stack(fCurrentEvent);
662 if ( stack == 0x0 ) return 0x0;
663 return static_cast<TParticle*>( stack->Particle(index) );
666 //_____________________________________________________________________________
667 Int_t AliMUONMCDataInterface::NumberOfTracks()
669 /// Returns the number of primary tracks (from primary particles) in the current event.
671 return NumberOfTracks(fCurrentEvent);
674 //_____________________________________________________________________________
675 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
677 /// Returns the number of hits for a given primary track/particle.
678 /// @param track The track number in the range [0 .. N-1]
679 /// where N = NumberOfTracks()
681 TIterator* iter = GetIterator(kHitIterator, track);
682 return CountObjects(iter);
685 //_____________________________________________________________________________
687 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
689 /// Returns a pointer to the index'th hit object.
690 /// @param track The track number in the range [0 .. N-1]
691 /// where N = NumberOfTracks()
692 /// @param index The index number of the hit in the range [0 ... M-1]
693 /// where M = NumberOfHits(track)
695 TIterator* iter = GetIterator(kHitIterator, track);
696 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
699 //_____________________________________________________________________________
700 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
702 /// Returns the number of summable digits to be found on a given detector element.
703 /// @param detElemId The detector element ID number to search on.
705 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
706 return CountObjects(iter);
709 //_____________________________________________________________________________
710 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
712 /// Returns the a pointer to the index'th summable digit on the specified detector element.
713 /// @param detElemId The detector element ID number to search on.
714 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
715 /// where N = NumberOfDigits(detElemId)
717 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
718 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
721 //_____________________________________________________________________________
722 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
724 /// Returns the number of summable digits to be found on a specific chamber and cathode.
725 /// @param chamber The chamber number in the range [0 .. 13].
726 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
727 /// 1 is the non-bending plane.
729 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
730 return CountObjects(iter);
733 //_____________________________________________________________________________
734 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
736 /// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
737 /// @param chamber The chamber number in the range [0 .. 13].
738 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
739 /// 1 is the non-bending plane.
740 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
741 /// where N = NumberOfDigits(chamber, cathode)
743 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
744 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
747 //_____________________________________________________________________________
748 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
750 /// Returns the number of simulated digits to be found on a given detector element.
751 /// @param detElemId The detector element ID number to search on.
753 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
754 return CountObjects(iter);
757 //_____________________________________________________________________________
758 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
760 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
761 /// @param detElemId The detector element ID number to search on.
762 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
763 /// where N = NumberOfDigits(detElemId)
765 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
766 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
769 //_____________________________________________________________________________
770 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
772 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
773 /// @param chamber The chamber number in the range [0 .. 13].
774 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
775 /// 1 is the non-bending plane.
777 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
778 return CountObjects(iter);
781 //_____________________________________________________________________________
782 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
784 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
785 /// @param chamber The chamber number in the range [0 .. 13].
786 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
787 /// 1 is the non-bending plane.
788 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
789 /// where N = NumberOfDigits(chamber, cathode)
791 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
792 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
795 //_____________________________________________________________________________
796 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
798 /// Returns the number of simulated local trigger objects.
800 TIterator* iter = GetIterator(kLocalTriggerIterator);
801 return CountObjects(iter);
804 //_____________________________________________________________________________
805 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
807 /// Returns a pointer to the index'th simulated local trigger object.
808 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
809 /// where N = NumberOfLocalTriggers()
811 TIterator* iter = GetIterator(kLocalTriggerIterator);
812 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
815 //_____________________________________________________________________________
816 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
818 /// Returns the number of simulated regional trigger objects.
820 TIterator* iter = GetIterator(kRegionalTriggerIterator);
821 return CountObjects(iter);
824 //_____________________________________________________________________________
825 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
827 /// Returns a pointer to the index'th simulated regional trigger object.
828 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
829 /// where N = NumberOfRegionalTriggers()
831 TIterator* iter = GetIterator(kRegionalTriggerIterator);
832 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
835 //_____________________________________________________________________________
836 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
838 /// Returns a pointer to the simulated global trigger object for the event.
840 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
841 if (store == 0x0) return 0x0;
842 return store->Global();
845 //_____________________________________________________________________________
846 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
848 /// Number of track references in the currently selected event.
850 return NumberOfTrackRefs(fCurrentEvent);
853 //_____________________________________________________________________________
854 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
856 /// Returns the track references for a given track in the current event.
857 /// @param track The track to returns track references for. In the range [0 .. N-1]
858 /// where N = NumberOfTrackRefs()
860 return TrackRefs(fCurrentEvent, track);
863 //_____________________________________________________________________________
864 void AliMUONMCDataInterface::ResetStores()
866 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
867 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
870 if (fHitStore != 0x0)
875 if (fSDigitStore != 0x0)
880 if (fDigitStore != 0x0)
885 if (fTrackRefs != 0x0)
890 if (fTriggerStore != 0x0)
892 delete fTriggerStore;
897 //_____________________________________________________________________________
898 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
900 /// Creates an appropriate iterator object and returns it.
901 /// If the iterator has already been created then that one is returned otherwise
902 /// a new object is created.
903 /// Depending on the value of 'type' the semantics of parameters x and y can change.
904 /// @param type The type of iterator to create.
905 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
906 /// or kSDigitIteratorByDetectorElement.
907 /// If type equals kDigitIteratorByChamberAndCathode or
908 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
909 /// For type == kHitIterator the parameter x is the track number.
910 /// In all other cases this parameter is ignored.
911 /// @param y If type equals kDigitIteratorByChamberAndCathode or
912 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
913 /// number. In all other cases this parameter is ignored.
915 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
918 if (fCurrentEvent == -1)
920 AliError("No event was selected. Try first using GetEvent().");
931 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
932 if (store == 0x0) return 0x0;
933 fIterator = store->CreateIterator();
934 if (fIterator == 0x0) return 0x0;
935 fCurrentIteratorType = kHitIterator;
939 case kSDigitIteratorByDetectorElement:
942 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
943 if (store == 0x0) return 0x0;
944 fIterator = store->CreateIterator(detElem, detElem, 2);
945 if (fIterator == 0x0) return 0x0;
946 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
951 case kSDigitIteratorByChamberAndCathode:
955 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
958 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
959 AliMpConstants::NofChambers() - 1,
964 if (cathode < 0 or 1 < cathode)
966 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
970 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
971 if (store == 0x0) return 0x0;
972 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
973 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
974 if (fIterator == 0x0) return 0x0;
975 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
981 case kDigitIteratorByDetectorElement:
984 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
985 if (store == 0x0) return 0x0;
986 fIterator = store->CreateIterator(detElem, detElem, 2);
987 if (fIterator == 0x0) return 0x0;
988 fCurrentIteratorType = kDigitIteratorByDetectorElement;
993 case kDigitIteratorByChamberAndCathode:
997 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1000 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1001 AliMpConstants::NofChambers() - 1,
1006 if (cathode < 0 or 1 < cathode)
1008 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1012 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1013 if (store == 0x0) return 0x0;
1014 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
1015 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
1016 if (fIterator == 0x0) return 0x0;
1017 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
1023 case kLocalTriggerIterator:
1025 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1026 if (store == 0x0) return 0x0;
1027 fIterator = store->CreateLocalIterator();
1028 if (fIterator == 0x0) return 0x0;
1029 fCurrentIteratorType = kLocalTriggerIterator;
1033 case kRegionalTriggerIterator:
1035 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1036 if (store == 0x0) return 0x0;
1037 fIterator = store->CreateRegionalIterator();
1038 if (fIterator == 0x0) return 0x0;
1039 fCurrentIteratorType = kRegionalTriggerIterator;
1048 //_____________________________________________________________________________
1049 void AliMUONMCDataInterface::ResetIterator()
1051 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1052 /// The iterator type and temporary data indicating the state of the iterator are
1055 if (fIterator != 0x0) delete fIterator;
1056 fCurrentIteratorType = kNoIterator;
1057 fCurrentIndex = fDataX = fDataY = -1;
1061 //_____________________________________________________________________________
1062 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1064 /// Counts the number of objects in the iterator and resets it.
1065 /// @return The number of objects in 'iter'.
1067 if (iter == 0x0) return -1;
1070 while ( iter->Next() != 0x0 ) count++;
1076 //_____________________________________________________________________________
1077 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1079 /// Fetches the index'th object from the iterator counting the first object
1080 /// returned by iterator after it is reset as index == 0. The next object
1081 /// has index == 1 and so on where the last object returned by the iterator
1082 /// has index == N-1 where N = CountObjects(iter)
1083 /// This method will only reset the iterator if index is smaller than
1084 /// fCurrentIndex, which is used to track the iteration progress and is
1085 /// updated when a new object if returned by this method.
1086 /// @param iter The iterator to fetch an object from.
1087 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1088 /// where N = CountObjects(iter)
1092 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1096 if (iter == 0x0) return 0x0;
1097 if (index <= fCurrentIndex)
1103 TObject* object = 0x0;
1104 while (fCurrentIndex < index)
1106 object = iter->Next();
1109 AliError(Form("Index is out of bounds. Got a value of %d.", index));