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 "AliMpEncodePair.h"
40 #include "AliMpDEManager.h"
41 #include "AliMpConstants.h"
45 #include "AliLoader.h"
46 #include "AliRunLoader.h"
47 #include "AliHeader.h"
49 #include "AliCDBManager.h"
52 #include <Riostream.h>
53 #include <TClonesArray.h>
55 #include <TParticle.h>
56 #include <TIterator.h>
61 ClassImp(AliMUONMCDataInterface)
64 Int_t AliMUONMCDataInterface::fgInstanceCounter(0);
66 //_____________________________________________________________________________
67 AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
77 fCurrentIteratorType(kNoIterator),
87 if ( AliCDBManager::Instance() != NULL &&
88 AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
89 AliFatal("CDB default storage not defined.");
95 if ( ! AliMpCDB::LoadMpSegmentation() ) {
96 AliFatal("Could not access mapping from OCDB !");
100 //_____________________________________________________________________________
101 AliMUONMCDataInterface::~AliMUONMCDataInterface()
107 //_____________________________________________________________________________
109 AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
111 /// Return the hitStore for a given track of one event
112 /// Return 0x0 if event and/or track not found
113 /// Returned pointer should not be deleted
115 /// \note If a previous store has been retrieved by one of the methods of
116 /// this class, but for a different event number, then those stores will
117 /// be deleted and no longer valid.
118 /// If you require access to the data for the earlier retrieved store,
119 /// but for different events, then you should deep copy / clone the object.
121 if (not IsValid()) return 0x0;
123 if (event == fCurrentEvent)
125 if (track == fDataX and fHitStore != 0x0) // using fDataX as track number.
131 if ( not LoadEvent(event) ) return 0x0;
136 TTree* treeH = fLoader->TreeH();
139 AliError("Could not get treeH");
143 fHitStore = AliMUONVHitStore::Create(*treeH);
144 AliDebug(1,"Creating hitStore from treeH");
145 if ( fHitStore != 0x0 )
147 fHitStore->Connect(*treeH);
148 if ( treeH->GetEvent(track) == 0 )
150 AliError(Form("Could not read track %d",track));
154 fDataX = track; // using fDataX as track number.
157 fLoader->UnloadHits();
162 //_____________________________________________________________________________
164 AliMUONMCDataInterface::SDigitStore(Int_t event)
166 /// Return the SDigit store for a given event.
167 /// Return 0 if event not found
168 /// Returned pointer should not be deleted
170 /// \note If a previous store has been retrieved by one of the methods of
171 /// this class, but for a different event number, then those stores will
172 /// be deleted and no longer valid.
173 /// If you require access to the data for the earlier retrieved store,
174 /// but for different events, then you should deep copy / clone the object.
176 if (not IsValid()) return 0x0;
178 if (event == fCurrentEvent)
180 if (fSDigitStore != 0x0)
186 if ( not LoadEvent(event) ) return 0x0;
189 fLoader->LoadSDigits();
191 TTree* treeS = fLoader->TreeS();
194 AliError("Could not get treeS");
198 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
199 if ( fSDigitStore != 0x0 )
201 fSDigitStore->Clear();
202 fSDigitStore->Connect(*treeS);
206 fLoader->UnloadSDigits();
211 //_____________________________________________________________________________
213 AliMUONMCDataInterface::DigitStore(Int_t event)
215 /// Return a pointer to the digitStore for a given event (or 0 if not found)
216 /// Returned pointer should not be deleted
218 /// \note If a previous store has been retrieved by one of the methods of
219 /// this class, but for a different event number, then those stores will
220 /// be deleted and no longer valid.
221 /// If you require access to the data for the earlier retrieved store,
222 /// but for different events, then you should deep copy / clone the object.
224 if (not IsValid()) return 0x0;
226 if (event == fCurrentEvent)
228 if (fDigitStore != 0x0)
234 if ( not LoadEvent(event) ) return 0x0;
237 fLoader->LoadDigits();
239 TTree* treeD = fLoader->TreeD();
242 AliError("Could not get treeD");
246 fDigitStore = AliMUONVDigitStore::Create(*treeD);
247 if ( fDigitStore != 0x0 )
249 fDigitStore->Clear();
250 fDigitStore->Connect(*treeD);
254 fLoader->UnloadDigits();
259 //_____________________________________________________________________________
261 AliMUONMCDataInterface::Stack(Int_t event)
263 /// Get the Stack (list of generated particles) for one event
264 /// Returned pointer should not be deleted
266 /// \note If a previous store has been retrieved by one of the methods of
267 /// this class, but for a different event number, then those stores will
268 /// be deleted and no longer valid.
269 /// If you require access to the data for the earlier retrieved store,
270 /// but for different events, then you should deep copy / clone the object.
272 if ( not IsValid() ) return 0x0;
274 if (event != fCurrentEvent)
277 if ( not LoadEvent(event) ) return 0x0;
280 fLoader->GetRunLoader()->LoadKinematics();
282 return fLoader->GetRunLoader()->Stack();
285 //_____________________________________________________________________________
287 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
289 /// Get the track references for a given (generated) track of one event
290 /// Returned pointer should not be deleted
292 /// \note If a previous store has been retrieved by one of the methods of
293 /// this class, but for a different event number, then those stores will
294 /// be deleted and no longer valid.
295 /// If you require access to the data for the earlier retrieved store,
296 /// but for different events, then you should deep copy / clone the object.
298 if ( not IsValid() ) return 0x0;
300 if (event == fCurrentEvent)
302 if (track == fDataX and fTrackRefs != 0x0) // using fDataX as track number.
308 if ( not LoadEvent(event) ) return 0x0;
311 fLoader->GetRunLoader()->LoadTrackRefs();
313 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
315 if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
319 if ( treeTR->GetEvent(track) > 0 )
321 TBranch* branch = treeTR->GetBranch("TrackReferences");
322 branch->SetAddress(&fTrackRefs);
323 branch->GetEvent(track);
324 fDataX = track; // using fDataX as track number.
329 AliError("Could not get TreeTR");
332 fLoader->GetRunLoader()->UnloadTrackRefs();
337 //_____________________________________________________________________________
338 AliMUONVTriggerStore*
339 AliMUONMCDataInterface::TriggerStore(Int_t event)
341 /// Return the triggerStore for a given event.
342 /// Return 0x0 if event not found.
343 /// Returned pointer should not be deleted.
345 /// \note If a previous store has been retrieved by one of the methods of
346 /// this class, but for a different event number, then those stores will
347 /// be deleted and no longer valid.
348 /// If you require access to the data for the earlier retrieved store,
349 /// but for different events, then you should deep copy / clone the object.
351 if (not IsValid()) return 0x0;
353 if (event == fCurrentEvent)
355 if (fTriggerStore != 0x0)
356 return fTriggerStore;
361 if ( not LoadEvent(event) ) return 0x0;
364 fLoader->LoadDigits();
366 TTree* treeD = fLoader->TreeD();
369 AliError("Could not get treeD");
373 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
374 if ( fTriggerStore != 0x0 )
376 fTriggerStore->Clear();
377 fTriggerStore->Connect(*treeD);
381 fLoader->UnloadDigits();
383 return fTriggerStore;
386 //_____________________________________________________________________________
388 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
390 /// Dump the digits for a given event, sorted if requested.
393 if ( fDigitStore != 0x0 )
397 DumpSorted(*fDigitStore);
401 fDigitStore->Print();
406 //_____________________________________________________________________________
408 AliMUONMCDataInterface::DumpHits(Int_t event)
410 /// Dump all the hits for one event
412 Int_t ntracks = NumberOfTracks(event);
414 for ( Int_t i = 0; i < ntracks; ++i )
416 cout << ">> Track " << i << endl;
420 fHitStore->Print("","full");
425 //_____________________________________________________________________________
427 AliMUONMCDataInterface::DumpKine(Int_t event)
429 /// Dump all generated particles for one event
430 AliStack* stack = Stack(event);
434 Int_t nparticles = (Int_t) stack->GetNtrack();
436 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
438 stack->Particle(iparticle)->Print("");
443 AliError("Could not get stack");
447 //_____________________________________________________________________________
449 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
451 /// Dump the SDigits for a given event, sorted if requested
454 if ( fSDigitStore != 0x0 )
458 DumpSorted(*fSDigitStore);
462 fSDigitStore->Print();
467 //_____________________________________________________________________________
469 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
471 /// Dump the given store in sorted order
473 TIter next(store.CreateIterator());
476 list.SetOwner(kFALSE);
478 while ( ( object = next() ) )
488 //_____________________________________________________________________________
490 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
492 /// Dump track references for one event
493 Int_t ntrackrefs = NumberOfTrackRefs(event);
495 for ( Int_t i = 0; i < ntrackrefs; ++i )
498 if ( fTrackRefs != 0x0 )
500 fTrackRefs->Print("","*");
505 //_____________________________________________________________________________
507 AliMUONMCDataInterface::DumpTrigger(Int_t event)
509 /// Dump trigger for a given event (trigger is read from TreeD)
513 if ( fTriggerStore != 0x0 )
515 fTriggerStore->Print();
519 //_____________________________________________________________________________
521 AliMUONMCDataInterface::LoadEvent(Int_t event)
523 /// Load event if different from the current one.
524 /// Returns kFALSE on error and kTRUE if the event was loaded.
528 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
529 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
531 fCurrentEvent = event;
539 //_____________________________________________________________________________
541 AliMUONMCDataInterface::NumberOfEvents() const
543 /// Number of events in the file we're connected to
544 if (not IsValid()) return -1;
545 return fLoader->GetRunLoader()->GetNumberOfEvents();
548 //_____________________________________________________________________________
550 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
552 /// Number of tracks in the event
553 if ( not IsValid()) return -1;
555 if (event != fCurrentEvent)
558 if ( not LoadEvent(event) ) return -1;
565 TTree* treeH = fLoader->TreeH();
568 rv = static_cast<Int_t>(treeH->GetEntries());
572 AliError("Could not get TreeH");
575 fLoader->UnloadHits();
580 //_____________________________________________________________________________
582 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
584 /// Number of track references in the event
585 if ( not IsValid()) return -1;
587 if (event != fCurrentEvent)
590 if ( not LoadEvent(event) ) return -1;
593 fLoader->GetRunLoader()->LoadTrackRefs();
597 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
600 rv = static_cast<Int_t>(treeTR->GetEntries());
604 AliError("Could not get TreeTR");
607 fLoader->GetRunLoader()->UnloadTrackRefs();
612 //_____________________________________________________________________________
614 AliMUONMCDataInterface::Open(const char* filename)
616 /// Connect to a given galice.root file
622 if ( fLoader != 0x0 )
624 delete fLoader->GetRunLoader();
631 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
633 while (AliRunLoader::GetRunLoader(foldername))
635 delete AliRunLoader::GetRunLoader(foldername);
638 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
639 if (runLoader == 0x0)
641 AliError(Form("Cannot open file %s",filename));
646 // Get run number and set it to CDB manager
647 runLoader->LoadHeader();
648 if ( ! runLoader->GetHeader() ) {
649 AliError("Cannot load header.");
653 Int_t runNumber = runLoader->GetHeader()->GetRun();
654 AliCDBManager::Instance()->SetRun(runNumber);
656 runLoader->UnloadHeader();
658 fLoader = runLoader->GetDetectorLoader("MUON");
661 AliError("Cannot get AliMUONLoader");
667 AliError(Form("Could not access %s filename. Object is unuseable",filename));
671 //_____________________________________________________________________________
672 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
674 /// Loads all simulated data for the given event.
676 if (HitStore(event, 0) == 0x0) return kFALSE;
677 if (SDigitStore(event) == 0x0) return kFALSE;
678 if (DigitStore(event) == 0x0) return kFALSE;
679 if (TriggerStore(event) == 0x0) return kFALSE;
680 if (TrackRefs(event, 0) == 0x0) return kFALSE;
684 //_____________________________________________________________________________
685 Int_t AliMUONMCDataInterface::NumberOfParticles()
687 /// Returns the total number of particles in the kinematics tree.
689 AliStack* stack = Stack(fCurrentEvent);
690 if ( stack == 0x0 ) return -1;
691 return (Int_t) stack->GetNtrack();
694 //_____________________________________________________________________________
695 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
697 /// Returns the index'th particle in the kinematics tree.
698 /// @param index The index number of the particle in the range [0 ... N-1]
699 /// where N = NumberOfParticles()
701 AliStack* stack = Stack(fCurrentEvent);
702 if ( stack == 0x0 ) return 0x0;
703 return static_cast<TParticle*>( stack->Particle(index) );
706 //_____________________________________________________________________________
707 Int_t AliMUONMCDataInterface::NumberOfTracks()
709 /// Returns the number of primary tracks (from primary particles) in the current event.
711 return NumberOfTracks(fCurrentEvent);
714 //_____________________________________________________________________________
715 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
717 /// Returns the number of hits for a given primary track/particle.
718 /// @param track The track number in the range [0 .. N-1]
719 /// where N = NumberOfTracks()
721 TIterator* iter = GetIterator(kHitIterator, track);
722 return CountObjects(iter);
725 //_____________________________________________________________________________
727 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
729 /// Returns a pointer to the index'th hit object.
730 /// @param track The track number in the range [0 .. N-1]
731 /// where N = NumberOfTracks()
732 /// @param index The index number of the hit in the range [0 ... M-1]
733 /// where M = NumberOfHits(track)
735 TIterator* iter = GetIterator(kHitIterator, track);
736 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
739 //_____________________________________________________________________________
740 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
742 /// Returns the number of summable digits to be found on a given detector element.
743 /// @param detElemId The detector element ID number to search on.
745 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
746 return CountObjects(iter);
749 //_____________________________________________________________________________
750 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
752 /// Returns the a pointer to the index'th summable digit on the specified detector element.
753 /// @param detElemId The detector element ID number to search on.
754 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
755 /// where N = NumberOfDigits(detElemId)
757 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
758 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
761 //_____________________________________________________________________________
762 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
764 /// Returns the number of summable digits to be found on a specific chamber and cathode.
765 /// @param chamber The chamber number in the range [0 .. 13].
766 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
767 /// 1 is the non-bending plane.
769 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
770 return CountObjects(iter);
773 //_____________________________________________________________________________
774 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
776 /// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
777 /// @param chamber The chamber number in the range [0 .. 13].
778 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
779 /// 1 is the non-bending plane.
780 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
781 /// where N = NumberOfDigits(chamber, cathode)
783 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
784 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
787 //_____________________________________________________________________________
788 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
790 /// Returns the number of simulated digits to be found on a given detector element.
791 /// @param detElemId The detector element ID number to search on.
793 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
794 return CountObjects(iter);
797 //_____________________________________________________________________________
798 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
800 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
801 /// @param detElemId The detector element ID number to search on.
802 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
803 /// where N = NumberOfDigits(detElemId)
805 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
806 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
809 //_____________________________________________________________________________
810 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
812 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
813 /// @param chamber The chamber number in the range [0 .. 13].
814 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
815 /// 1 is the non-bending plane.
817 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
818 return CountObjects(iter);
821 //_____________________________________________________________________________
822 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
824 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
825 /// @param chamber The chamber number in the range [0 .. 13].
826 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
827 /// 1 is the non-bending plane.
828 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
829 /// where N = NumberOfDigits(chamber, cathode)
831 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
832 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
835 //_____________________________________________________________________________
836 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
838 /// Returns the number of simulated local trigger objects.
840 TIterator* iter = GetIterator(kLocalTriggerIterator);
841 return CountObjects(iter);
844 //_____________________________________________________________________________
845 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
847 /// Returns a pointer to the index'th simulated local trigger object.
848 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
849 /// where N = NumberOfLocalTriggers()
851 TIterator* iter = GetIterator(kLocalTriggerIterator);
852 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
855 //_____________________________________________________________________________
856 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
858 /// Returns the number of simulated regional trigger objects.
860 TIterator* iter = GetIterator(kRegionalTriggerIterator);
861 return CountObjects(iter);
864 //_____________________________________________________________________________
865 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
867 /// Returns a pointer to the index'th simulated regional trigger object.
868 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
869 /// where N = NumberOfRegionalTriggers()
871 TIterator* iter = GetIterator(kRegionalTriggerIterator);
872 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
875 //_____________________________________________________________________________
876 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
878 /// Returns a pointer to the simulated global trigger object for the event.
880 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
881 if (store == 0x0) return 0x0;
882 return store->Global();
885 //_____________________________________________________________________________
886 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
888 /// Number of track references in the currently selected event.
890 return NumberOfTrackRefs(fCurrentEvent);
893 //_____________________________________________________________________________
894 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
896 /// Returns the track references for a given track in the current event.
897 /// @param track The track to returns track references for. In the range [0 .. N-1]
898 /// where N = NumberOfTrackRefs()
900 return TrackRefs(fCurrentEvent, track);
903 //_____________________________________________________________________________
904 void AliMUONMCDataInterface::ResetStores()
906 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
907 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
910 if (fHitStore != 0x0)
915 if (fSDigitStore != 0x0)
920 if (fDigitStore != 0x0)
925 if (fTrackRefs != 0x0)
930 if (fTriggerStore != 0x0)
932 delete fTriggerStore;
937 //_____________________________________________________________________________
938 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
940 /// Creates an appropriate iterator object and returns it.
941 /// If the iterator has already been created then that one is returned otherwise
942 /// a new object is created.
943 /// Depending on the value of 'type' the semantics of parameters x and y can change.
944 /// @param type The type of iterator to create.
945 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
946 /// or kSDigitIteratorByDetectorElement.
947 /// If type equals kDigitIteratorByChamberAndCathode or
948 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
949 /// For type == kHitIterator the parameter x is the track number.
950 /// In all other cases this parameter is ignored.
951 /// @param y If type equals kDigitIteratorByChamberAndCathode or
952 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
953 /// number. In all other cases this parameter is ignored.
955 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
958 if (fCurrentEvent == -1)
960 AliError("No event was selected. Try first using GetEvent().");
971 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
972 if (store == 0x0) return 0x0;
973 fIterator = store->CreateIterator();
974 if (fIterator == 0x0) return 0x0;
975 fCurrentIteratorType = kHitIterator;
979 case kSDigitIteratorByDetectorElement:
982 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
983 if (store == 0x0) return 0x0;
984 fIterator = store->CreateIterator(detElem, detElem, 2);
985 if (fIterator == 0x0) return 0x0;
986 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
991 case kSDigitIteratorByChamberAndCathode:
995 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
998 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
999 AliMpConstants::NofChambers() - 1,
1004 if (cathode < 0 or 1 < cathode)
1006 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1010 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
1011 if (store == 0x0) return 0x0;
1012 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1013 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1014 if (fIterator == 0x0) return 0x0;
1015 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
1021 case kDigitIteratorByDetectorElement:
1024 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1025 if (store == 0x0) return 0x0;
1026 fIterator = store->CreateIterator(detElem, detElem, 2);
1027 if (fIterator == 0x0) return 0x0;
1028 fCurrentIteratorType = kDigitIteratorByDetectorElement;
1033 case kDigitIteratorByChamberAndCathode:
1037 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1040 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1041 AliMpConstants::NofChambers() - 1,
1046 if (cathode < 0 or 1 < cathode)
1048 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1052 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1053 if (store == 0x0) return 0x0;
1054 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1055 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1056 if (fIterator == 0x0) return 0x0;
1057 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
1063 case kLocalTriggerIterator:
1065 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1066 if (store == 0x0) return 0x0;
1067 fIterator = store->CreateLocalIterator();
1068 if (fIterator == 0x0) return 0x0;
1069 fCurrentIteratorType = kLocalTriggerIterator;
1073 case kRegionalTriggerIterator:
1075 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1076 if (store == 0x0) return 0x0;
1077 fIterator = store->CreateRegionalIterator();
1078 if (fIterator == 0x0) return 0x0;
1079 fCurrentIteratorType = kRegionalTriggerIterator;
1088 //_____________________________________________________________________________
1089 void AliMUONMCDataInterface::ResetIterator()
1091 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1092 /// The iterator type and temporary data indicating the state of the iterator are
1095 if (fIterator != 0x0) delete fIterator;
1096 fCurrentIteratorType = kNoIterator;
1097 fCurrentIndex = fDataX = fDataY = -1;
1101 //_____________________________________________________________________________
1102 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1104 /// Counts the number of objects in the iterator and resets it.
1105 /// @return The number of objects in 'iter'.
1107 if (iter == 0x0) return -1;
1110 while ( iter->Next() != 0x0 ) count++;
1116 //_____________________________________________________________________________
1117 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1119 /// Fetches the index'th object from the iterator counting the first object
1120 /// returned by iterator after it is reset as index == 0. The next object
1121 /// has index == 1 and so on where the last object returned by the iterator
1122 /// has index == N-1 where N = CountObjects(iter)
1123 /// This method will only reset the iterator if index is smaller than
1124 /// fCurrentIndex, which is used to track the iteration progress and is
1125 /// updated when a new object if returned by this method.
1126 /// @param iter The iterator to fetch an object from.
1127 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1128 /// where N = CountObjects(iter)
1132 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1136 if (iter == 0x0) return 0x0;
1137 if (index <= fCurrentIndex)
1143 TObject* object = 0x0;
1144 while (fCurrentIndex < index)
1146 object = iter->Next();
1149 AliError(Form("Index is out of bounds. Got a value of %d.", index));