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;
113 if (event == fCurrentEvent
114 and fDataX == track // using fDataX as track number.
120 if (not LoadEvent(event)) return 0x0;
124 TTree* treeH = fLoader->TreeH();
127 AliError("Could not get treeH");
131 fHitStore = AliMUONVHitStore::Create(*treeH);
132 AliDebug(1,"Creating hitStore from treeH");
133 if ( fHitStore != 0x0 )
135 fHitStore->Connect(*treeH);
136 if ( treeH->GetEvent(track) == 0 )
138 AliError(Form("Could not read track %d",track));
142 fDataX = track; // using fDataX as track number.
145 fLoader->UnloadHits();
150 //_____________________________________________________________________________
152 AliMUONMCDataInterface::SDigitStore(Int_t event)
154 /// Return the SDigit store for a given event.
155 /// Return 0 if event not found
156 /// Returned pointer should not be deleted
158 if (not IsValid()) return 0x0;
159 if (event == fCurrentEvent and fSDigitStore != 0x0) return fSDigitStore;
162 if (not LoadEvent(event)) return 0x0;
164 fLoader->LoadSDigits();
166 TTree* treeS = fLoader->TreeS();
169 AliError("Could not get treeS");
173 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
174 if ( fSDigitStore != 0x0 )
176 fSDigitStore->Clear();
177 fSDigitStore->Connect(*treeS);
181 fLoader->UnloadSDigits();
186 //_____________________________________________________________________________
188 AliMUONMCDataInterface::DigitStore(Int_t event)
190 /// Return a pointer to the digitStore for a given event (or 0 if not found)
191 /// Returned pointer should not be deleted
193 if (not IsValid()) return 0x0;
194 if (event == fCurrentEvent and fDigitStore != 0x0) return fDigitStore;
197 if (not LoadEvent(event)) return 0x0;
199 fLoader->LoadDigits();
201 TTree* treeD = fLoader->TreeD();
204 AliError("Could not get treeD");
208 fDigitStore = AliMUONVDigitStore::Create(*treeD);
209 if ( fDigitStore != 0x0 )
211 fDigitStore->Clear();
212 fDigitStore->Connect(*treeD);
216 fLoader->UnloadDigits();
221 //_____________________________________________________________________________
223 AliMUONMCDataInterface::Stack(Int_t event)
225 /// Get the Stack (list of generated particles) for one event
226 /// Returned pointer should not be deleted
228 if ( not IsValid() ) return 0x0;
230 if (event != fCurrentEvent)
233 if ( not LoadEvent(event) ) return 0x0;
236 fLoader->GetRunLoader()->LoadKinematics();
238 return fLoader->GetRunLoader()->Stack();
241 //_____________________________________________________________________________
243 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
245 /// Get the track references for a given (generated) track of one event
246 /// Returned pointer should not be deleted
248 if ( not IsValid() ) return 0x0;
250 if (event != fCurrentEvent)
253 if ( not LoadEvent(event) ) return 0x0;
256 if (track == fDataX) // using fDataX as track number.
259 fLoader->GetRunLoader()->LoadTrackRefs();
261 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
263 if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
267 if ( treeTR->GetEvent(track) > 0 )
269 TBranch* branch = treeTR->GetBranch("TrackReferences");
270 branch->SetAddress(&fTrackRefs);
271 branch->GetEvent(track);
272 fDataX = track; // using fDataX as track number.
277 AliError("Could not get TreeTR");
280 fLoader->GetRunLoader()->UnloadTrackRefs();
285 //_____________________________________________________________________________
286 AliMUONVTriggerStore*
287 AliMUONMCDataInterface::TriggerStore(Int_t event)
289 /// Return the triggerStore for a given event.
290 /// Return 0x0 if event not found.
291 /// Returned pointer should not be deleted.
293 if (not IsValid()) return 0x0;
294 if (event == fCurrentEvent and fTriggerStore != 0x0) return fTriggerStore;
297 if (not LoadEvent(event)) return 0x0;
299 fLoader->LoadDigits();
301 TTree* treeD = fLoader->TreeD();
304 AliError("Could not get treeD");
308 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
309 if ( fTriggerStore != 0x0 )
311 fTriggerStore->Clear();
312 fTriggerStore->Connect(*treeD);
316 fLoader->UnloadDigits();
318 return fTriggerStore;
321 //_____________________________________________________________________________
323 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
325 /// Dump the digits for a given event, sorted if requested.
328 if ( fDigitStore != 0x0 )
332 DumpSorted(*fDigitStore);
336 fDigitStore->Print();
341 //_____________________________________________________________________________
343 AliMUONMCDataInterface::DumpHits(Int_t event)
345 /// Dump all the hits for one event
347 Int_t ntracks = NumberOfTracks(event);
349 for ( Int_t i = 0; i < ntracks; ++i )
351 cout << ">> Track " << i << endl;
355 fHitStore->Print("","full");
360 //_____________________________________________________________________________
362 AliMUONMCDataInterface::DumpKine(Int_t event)
364 /// Dump all generated particles for one event
365 AliStack* stack = Stack(event);
369 Int_t nparticles = (Int_t) stack->GetNtrack();
371 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
373 stack->Particle(iparticle)->Print("");
378 AliError("Could not get stack");
382 //_____________________________________________________________________________
384 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
386 /// Dump the SDigits for a given event, sorted if requested
389 if ( fSDigitStore != 0x0 )
393 DumpSorted(*fSDigitStore);
397 fSDigitStore->Print();
402 //_____________________________________________________________________________
404 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
406 /// Dump the given store in sorted order
408 TIter next(store.CreateIterator());
411 list.SetOwner(kFALSE);
413 while ( ( object = next() ) )
423 //_____________________________________________________________________________
425 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
427 /// Dump track references for one event
428 Int_t ntrackrefs = NumberOfTrackRefs(event);
430 for ( Int_t i = 0; i < ntrackrefs; ++i )
433 if ( fTrackRefs != 0x0 )
435 fTrackRefs->Print("","*");
440 //_____________________________________________________________________________
442 AliMUONMCDataInterface::DumpTrigger(Int_t event)
444 /// Dump trigger for a given event (trigger is read from TreeD)
448 if ( fTriggerStore != 0x0 )
450 fTriggerStore->Print();
454 //_____________________________________________________________________________
456 AliMUONMCDataInterface::LoadEvent(Int_t event)
458 /// Load event if different from the current one.
459 /// Returns kFALSE on error and kTRUE if the event was loaded.
463 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
464 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
466 fCurrentEvent = event;
474 //_____________________________________________________________________________
476 AliMUONMCDataInterface::NumberOfEvents() const
478 /// Number of events in the file we're connected to
479 if (not IsValid()) return -1;
480 return fLoader->GetRunLoader()->GetNumberOfEvents();
483 //_____________________________________________________________________________
485 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
487 /// Number of tracks in the event
488 if ( not IsValid()) return -1;
490 if (event != fCurrentEvent)
493 if ( not LoadEvent(event) ) return -1;
500 TTree* treeH = fLoader->TreeH();
503 rv = static_cast<Int_t>(treeH->GetEntries());
507 AliError("Could not get TreeH");
510 fLoader->UnloadHits();
515 //_____________________________________________________________________________
517 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
519 /// Number of track references in the event
520 if ( not IsValid()) return -1;
522 if (event != fCurrentEvent)
525 if ( not LoadEvent(event) ) return -1;
528 fLoader->GetRunLoader()->LoadTrackRefs();
532 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
535 rv = static_cast<Int_t>(treeTR->GetEntries());
539 AliError("Could not get TreeTR");
542 fLoader->GetRunLoader()->UnloadTrackRefs();
547 //_____________________________________________________________________________
549 AliMUONMCDataInterface::Open(const char* filename)
551 /// Connect to a given galice.root file
557 if ( fLoader != 0x0 )
559 delete fLoader->GetRunLoader();
566 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
568 while (AliRunLoader::GetRunLoader(foldername))
570 delete AliRunLoader::GetRunLoader(foldername);
573 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
574 if (runLoader == 0x0)
576 AliError(Form("Cannot open file %s",filename));
580 // Get run number and set it to CDB manager
581 runLoader->LoadHeader();
582 if ( ! runLoader->GetHeader() ) {
583 AliError("Cannot load header.");
587 Int_t runNumber = runLoader->GetHeader()->GetRun();
588 AliCDBManager::Instance()->SetRun(runNumber);
590 runLoader->UnloadHeader();
592 fLoader = runLoader->GetDetectorLoader("MUON");
595 AliError("Cannot get AliMUONLoader");
601 AliError(Form("Could not access %s filename. Object is unuseable",filename));
605 //_____________________________________________________________________________
606 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
608 /// Loads all simulated data for the given event.
610 if (HitStore(event, 0) == 0x0) return kFALSE;
611 if (SDigitStore(event) == 0x0) return kFALSE;
612 if (DigitStore(event) == 0x0) return kFALSE;
613 if (TriggerStore(event) == 0x0) return kFALSE;
614 if (TrackRefs(event, 0) == 0x0) return kFALSE;
618 //_____________________________________________________________________________
619 Int_t AliMUONMCDataInterface::NumberOfParticles()
621 /// Returns the total number of particles in the kinematics tree.
623 AliStack* stack = Stack(fCurrentEvent);
624 if ( stack == 0x0 ) return -1;
625 return (Int_t) stack->GetNtrack();
628 //_____________________________________________________________________________
629 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
631 /// Returns the index'th particle in the kinematics tree.
632 /// @param index The index number of the particle in the range [0 ... N-1]
633 /// where N = NumberOfParticles()
635 AliStack* stack = Stack(fCurrentEvent);
636 if ( stack == 0x0 ) return 0x0;
637 return static_cast<TParticle*>( stack->Particle(index) );
640 //_____________________________________________________________________________
641 Int_t AliMUONMCDataInterface::NumberOfTracks()
643 /// Returns the number of primary tracks (from primary particles) in the current event.
645 return NumberOfTracks(fCurrentEvent);
648 //_____________________________________________________________________________
649 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
651 /// Returns the number of hits for a given primary track/particle.
652 /// @param track The track number in the range [0 .. N-1]
653 /// where N = NumberOfTracks()
655 TIterator* iter = GetIterator(kHitIterator, track);
656 return CountObjects(iter);
659 //_____________________________________________________________________________
661 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
663 /// Returns a pointer to the index'th hit object.
664 /// @param track The track number in the range [0 .. N-1]
665 /// where N = NumberOfTracks()
666 /// @param index The index number of the hit in the range [0 ... M-1]
667 /// where M = NumberOfHits(track)
669 TIterator* iter = GetIterator(kHitIterator, track);
670 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
673 //_____________________________________________________________________________
674 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
676 /// Returns the number of summable digits to be found on a given detector element.
677 /// @param detElemId The detector element ID number to search on.
679 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
680 return CountObjects(iter);
683 //_____________________________________________________________________________
684 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
686 /// Returns the a pointer to the index'th summable digit on the specified detector element.
687 /// @param detElemId The detector element ID number to search on.
688 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
689 /// where N = NumberOfDigits(detElemId)
691 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
692 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
695 //_____________________________________________________________________________
696 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
698 /// Returns the number of summable digits to be found on a specific chamber and cathode.
699 /// @param chamber The chamber number in the range [0 .. 13].
700 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
701 /// 1 is the non-bending plane.
703 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
704 return CountObjects(iter);
707 //_____________________________________________________________________________
708 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
710 /// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
711 /// @param chamber The chamber number in the range [0 .. 13].
712 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
713 /// 1 is the non-bending plane.
714 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
715 /// where N = NumberOfDigits(chamber, cathode)
717 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
718 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
721 //_____________________________________________________________________________
722 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
724 /// Returns the number of simulated digits to be found on a given detector element.
725 /// @param detElemId The detector element ID number to search on.
727 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
728 return CountObjects(iter);
731 //_____________________________________________________________________________
732 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
734 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
735 /// @param detElemId The detector element ID number to search on.
736 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
737 /// where N = NumberOfDigits(detElemId)
739 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
740 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
743 //_____________________________________________________________________________
744 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
746 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
747 /// @param chamber The chamber number in the range [0 .. 13].
748 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
749 /// 1 is the non-bending plane.
751 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
752 return CountObjects(iter);
755 //_____________________________________________________________________________
756 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
758 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
759 /// @param chamber The chamber number in the range [0 .. 13].
760 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
761 /// 1 is the non-bending plane.
762 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
763 /// where N = NumberOfDigits(chamber, cathode)
765 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
766 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
769 //_____________________________________________________________________________
770 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
772 /// Returns the number of simulated local trigger objects.
774 TIterator* iter = GetIterator(kLocalTriggerIterator);
775 return CountObjects(iter);
778 //_____________________________________________________________________________
779 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
781 /// Returns a pointer to the index'th simulated local trigger object.
782 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
783 /// where N = NumberOfLocalTriggers()
785 TIterator* iter = GetIterator(kLocalTriggerIterator);
786 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
789 //_____________________________________________________________________________
790 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
792 /// Returns the number of simulated regional trigger objects.
794 TIterator* iter = GetIterator(kRegionalTriggerIterator);
795 return CountObjects(iter);
798 //_____________________________________________________________________________
799 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
801 /// Returns a pointer to the index'th simulated regional trigger object.
802 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
803 /// where N = NumberOfRegionalTriggers()
805 TIterator* iter = GetIterator(kRegionalTriggerIterator);
806 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
809 //_____________________________________________________________________________
810 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
812 /// Returns a pointer to the simulated global trigger object for the event.
814 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
815 if (store == 0x0) return 0x0;
816 return store->Global();
819 //_____________________________________________________________________________
820 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
822 /// Number of track references in the currently selected event.
824 return NumberOfTrackRefs(fCurrentEvent);
827 //_____________________________________________________________________________
828 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
830 /// Returns the track references for a given track in the current event.
831 /// @param track The track to returns track references for. In the range [0 .. N-1]
832 /// where N = NumberOfTrackRefs()
834 return TrackRefs(fCurrentEvent, track);
837 //_____________________________________________________________________________
838 void AliMUONMCDataInterface::ResetStores()
840 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
841 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
844 if (fHitStore != 0x0)
849 if (fSDigitStore != 0x0)
854 if (fDigitStore != 0x0)
859 if (fTrackRefs != 0x0)
864 if (fTriggerStore != 0x0)
866 delete fTriggerStore;
871 //_____________________________________________________________________________
872 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
874 /// Creates an appropriate iterator object and returns it.
875 /// If the iterator has already been created then that one is returned otherwise
876 /// a new object is created.
877 /// Depending on the value of 'type' the semantics of parameters x and y can change.
878 /// @param type The type of iterator to create.
879 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
880 /// or kSDigitIteratorByDetectorElement.
881 /// If type equals kDigitIteratorByChamberAndCathode or
882 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
883 /// For type == kHitIterator the parameter x is the track number.
884 /// In all other cases this parameter is ignored.
885 /// @param y If type equals kDigitIteratorByChamberAndCathode or
886 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
887 /// number. In all other cases this parameter is ignored.
889 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
892 if (fCurrentEvent == -1)
894 AliError("No event was selected. Try first using GetEvent().");
905 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
906 if (store == 0x0) return 0x0;
907 fIterator = store->CreateIterator();
908 if (fIterator == 0x0) return 0x0;
909 fCurrentIteratorType = kHitIterator;
913 case kSDigitIteratorByDetectorElement:
916 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
917 if (store == 0x0) return 0x0;
918 fIterator = store->CreateIterator(detElem, detElem, 2);
919 if (fIterator == 0x0) return 0x0;
920 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
925 case kSDigitIteratorByChamberAndCathode:
929 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
932 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
933 AliMpConstants::NofChambers() - 1,
938 if (cathode < 0 or 1 < cathode)
940 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
944 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
945 if (store == 0x0) return 0x0;
946 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
947 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
948 if (fIterator == 0x0) return 0x0;
949 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
955 case kDigitIteratorByDetectorElement:
958 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
959 if (store == 0x0) return 0x0;
960 fIterator = store->CreateIterator(detElem, detElem, 2);
961 if (fIterator == 0x0) return 0x0;
962 fCurrentIteratorType = kDigitIteratorByDetectorElement;
967 case kDigitIteratorByChamberAndCathode:
971 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
974 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
975 AliMpConstants::NofChambers() - 1,
980 if (cathode < 0 or 1 < cathode)
982 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
986 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
987 if (store == 0x0) return 0x0;
988 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
989 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
990 if (fIterator == 0x0) return 0x0;
991 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
997 case kLocalTriggerIterator:
999 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1000 if (store == 0x0) return 0x0;
1001 fIterator = store->CreateLocalIterator();
1002 if (fIterator == 0x0) return 0x0;
1003 fCurrentIteratorType = kLocalTriggerIterator;
1007 case kRegionalTriggerIterator:
1009 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1010 if (store == 0x0) return 0x0;
1011 fIterator = store->CreateRegionalIterator();
1012 if (fIterator == 0x0) return 0x0;
1013 fCurrentIteratorType = kRegionalTriggerIterator;
1022 //_____________________________________________________________________________
1023 void AliMUONMCDataInterface::ResetIterator()
1025 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1026 /// The iterator type and temporary data indicating the state of the iterator are
1029 if (fIterator != 0x0) delete fIterator;
1030 fCurrentIteratorType = kNoIterator;
1031 fCurrentIndex = fDataX = fDataY = -1;
1035 //_____________________________________________________________________________
1036 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1038 /// Counts the number of objects in the iterator and resets it.
1039 /// @return The number of objects in 'iter'.
1041 if (iter == 0x0) return -1;
1044 while ( iter->Next() != 0x0 ) count++;
1050 //_____________________________________________________________________________
1051 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1053 /// Fetches the index'th object from the iterator counting the first object
1054 /// returned by iterator after it is reset as index == 0. The next object
1055 /// has index == 1 and so on where the last object returned by the iterator
1056 /// has index == N-1 where N = CountObjects(iter)
1057 /// This method will only reset the iterator if index is smaller than
1058 /// fCurrentIndex, which is used to track the iteration progress and is
1059 /// updated when a new object if returned by this method.
1060 /// @param iter The iterator to fetch an object from.
1061 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1062 /// where N = CountObjects(iter)
1066 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1070 if (iter == 0x0) return 0x0;
1071 if (index <= fCurrentIndex)
1077 TObject* object = 0x0;
1078 while (fCurrentIndex < index)
1080 object = iter->Next();
1083 AliError(Form("Index is out of bounds. Got a value of %d.", index));