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"
42 #include "AliMpSegmentation.h"
45 #include "AliRunLoader.h"
48 #include <Riostream.h>
49 #include <TClonesArray.h>
51 #include <TParticle.h>
52 #include <TIterator.h>
57 ClassImp(AliMUONMCDataInterface)
60 Int_t AliMUONMCDataInterface::fgInstanceCounter(0);
62 //_____________________________________________________________________________
63 AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
73 fCurrentIteratorType(kNoIterator),
86 //_____________________________________________________________________________
87 AliMUONMCDataInterface::~AliMUONMCDataInterface()
92 delete fLoader->GetRunLoader();
97 //_____________________________________________________________________________
99 AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
101 /// Return the hitStore for a given track of one event
102 /// Return 0x0 if event and/or track not found
103 /// Returned pointer should not be deleted
105 if (not IsValid()) return 0x0;
106 if (event == fCurrentEvent
107 and fDataX == track // using fDataX as track number.
113 if (not LoadEvent(event)) return 0x0;
117 TTree* treeH = fLoader->TreeH();
120 AliError("Could not get treeH");
124 fHitStore = AliMUONVHitStore::Create(*treeH);
125 AliDebug(1,"Creating hitStore from treeH");
126 if ( fHitStore != 0x0 )
128 fHitStore->Connect(*treeH);
129 if ( treeH->GetEvent(track) == 0 )
131 AliError(Form("Could not read track %d",track));
135 fDataX = track; // using fDataX as track number.
138 fLoader->UnloadHits();
143 //_____________________________________________________________________________
145 AliMUONMCDataInterface::SDigitStore(Int_t event)
147 /// Return the SDigit store for a given event.
148 /// Return 0 if event not found
149 /// Returned pointer should not be deleted
151 if (not IsValid()) return 0x0;
152 if (event == fCurrentEvent and fSDigitStore != 0x0) return fSDigitStore;
155 if (not LoadEvent(event)) return 0x0;
157 fLoader->LoadSDigits();
159 TTree* treeS = fLoader->TreeS();
162 AliError("Could not get treeS");
166 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
167 if ( fSDigitStore != 0x0 )
169 fSDigitStore->Clear();
170 fSDigitStore->Connect(*treeS);
174 fLoader->UnloadSDigits();
179 //_____________________________________________________________________________
181 AliMUONMCDataInterface::DigitStore(Int_t event)
183 /// Return a pointer to the digitStore for a given event (or 0 if not found)
184 /// Returned pointer should not be deleted
186 if (not IsValid()) return 0x0;
187 if (event == fCurrentEvent and fDigitStore != 0x0) return fDigitStore;
190 if (not LoadEvent(event)) return 0x0;
192 fLoader->LoadDigits();
194 TTree* treeD = fLoader->TreeD();
197 AliError("Could not get treeD");
201 fDigitStore = AliMUONVDigitStore::Create(*treeD);
202 if ( fDigitStore != 0x0 )
204 fDigitStore->Clear();
205 fDigitStore->Connect(*treeD);
209 fLoader->UnloadDigits();
214 //_____________________________________________________________________________
216 AliMUONMCDataInterface::Stack(Int_t event)
218 /// Get the Stack (list of generated particles) for one event
219 /// Returned pointer should not be deleted
221 if ( not IsValid() ) return 0x0;
223 if (event != fCurrentEvent)
226 if ( not LoadEvent(event) ) return 0x0;
229 fLoader->GetRunLoader()->LoadKinematics();
231 return fLoader->GetRunLoader()->Stack();
234 //_____________________________________________________________________________
236 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
238 /// Get the track references for a given (generated) track of one event
239 /// Returned pointer should not be deleted
241 if ( not IsValid() ) return 0x0;
243 if (event != fCurrentEvent)
246 if ( not LoadEvent(event) ) return 0x0;
249 if (track == fDataX) // using fDataX as track number.
252 fLoader->GetRunLoader()->LoadTrackRefs();
254 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
256 if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
260 if ( treeTR->GetEvent(track) > 0 )
262 TBranch* branch = treeTR->GetBranch("MUON");
263 branch->SetAddress(&fTrackRefs);
264 branch->GetEvent(track);
265 fDataX = track; // using fDataX as track number.
270 AliError("Could not get TreeTR");
273 fLoader->GetRunLoader()->UnloadTrackRefs();
278 //_____________________________________________________________________________
279 AliMUONVTriggerStore*
280 AliMUONMCDataInterface::TriggerStore(Int_t event)
282 /// Return the triggerStore for a given event.
283 /// Return 0x0 if event not found.
284 /// Returned pointer should not be deleted.
286 if (not IsValid()) return 0x0;
287 if (event == fCurrentEvent and fTriggerStore != 0x0) return fTriggerStore;
290 if (not LoadEvent(event)) return 0x0;
292 fLoader->LoadDigits();
294 TTree* treeD = fLoader->TreeD();
297 AliError("Could not get treeD");
301 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
302 if ( fTriggerStore != 0x0 )
304 fTriggerStore->Clear();
305 fTriggerStore->Connect(*treeD);
309 fLoader->UnloadDigits();
311 return fTriggerStore;
314 //_____________________________________________________________________________
316 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
318 /// Dump the digits for a given event, sorted if requested.
321 if ( fDigitStore != 0x0 )
325 DumpSorted(*fDigitStore);
329 fDigitStore->Print();
334 //_____________________________________________________________________________
336 AliMUONMCDataInterface::DumpHits(Int_t event)
338 /// Dump all the hits for one event
340 Int_t ntracks = NumberOfTracks(event);
342 for ( Int_t i = 0; i < ntracks; ++i )
344 cout << ">> Track " << i << endl;
348 fHitStore->Print("","full");
353 //_____________________________________________________________________________
355 AliMUONMCDataInterface::DumpKine(Int_t event)
357 /// Dump all generated particles for one event
358 AliStack* stack = Stack(event);
362 Int_t nparticles = (Int_t) stack->GetNtrack();
364 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
366 stack->Particle(iparticle)->Print("");
371 AliError("Could not get stack");
375 //_____________________________________________________________________________
377 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
379 /// Dump the SDigits for a given event, sorted if requested
382 if ( fSDigitStore != 0x0 )
386 DumpSorted(*fSDigitStore);
390 fSDigitStore->Print();
395 //_____________________________________________________________________________
397 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
399 /// Dump the given store in sorted order
401 TIter next(store.CreateIterator());
404 list.SetOwner(kFALSE);
406 while ( ( object = next() ) )
416 //_____________________________________________________________________________
418 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
420 /// Dump track references for one event
421 Int_t ntrackrefs = NumberOfTrackRefs(event);
423 for ( Int_t i = 0; i < ntrackrefs; ++i )
426 if ( fTrackRefs != 0x0 )
428 fTrackRefs->Print("","*");
433 //_____________________________________________________________________________
435 AliMUONMCDataInterface::DumpTrigger(Int_t event)
437 /// Dump trigger for a given event (trigger is read from TreeD)
441 if ( fTriggerStore != 0x0 )
443 fTriggerStore->Print();
447 //_____________________________________________________________________________
449 AliMUONMCDataInterface::LoadEvent(Int_t event)
451 /// Load event if different from the current one.
452 /// Returns kFALSE on error and kTRUE if the event was loaded.
456 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
457 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
459 fCurrentEvent = event;
467 //_____________________________________________________________________________
469 AliMUONMCDataInterface::NumberOfEvents() const
471 /// Number of events in the file we're connected to
472 if (not IsValid()) return -1;
473 return fLoader->GetRunLoader()->GetNumberOfEvents();
476 //_____________________________________________________________________________
478 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
480 /// Number of tracks in the event
481 if ( not IsValid()) return -1;
483 if (event != fCurrentEvent)
486 if ( not LoadEvent(event) ) return -1;
493 TTree* treeH = fLoader->TreeH();
496 rv = static_cast<Int_t>(treeH->GetEntries());
500 AliError("Could not get TreeH");
503 fLoader->UnloadHits();
508 //_____________________________________________________________________________
510 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
512 /// Number of track references in the event
513 if ( not IsValid()) return -1;
515 if (event != fCurrentEvent)
518 if ( not LoadEvent(event) ) return -1;
521 fLoader->GetRunLoader()->LoadTrackRefs();
525 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
528 rv = static_cast<Int_t>(treeTR->GetEntries());
532 AliError("Could not get TreeTR");
535 fLoader->GetRunLoader()->UnloadTrackRefs();
540 //_____________________________________________________________________________
542 AliMUONMCDataInterface::Open(const char* filename)
544 /// Connect to a given galice.root file
550 if ( fLoader != 0x0 )
552 delete fLoader->GetRunLoader();
559 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
561 while (AliRunLoader::GetRunLoader(foldername))
563 delete AliRunLoader::GetRunLoader(foldername);
566 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
567 if (runLoader == 0x0)
569 AliError(Form("Cannot open file %s",filename));
572 fLoader = runLoader->GetDetectorLoader("MUON");
575 AliError("Cannot get AliMUONLoader");
581 AliError(Form("Could not access %s filename. Object is unuseable",filename));
585 //_____________________________________________________________________________
586 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
588 /// Loads all simulated data for the given event.
590 if (HitStore(event, 0) == 0x0) return kFALSE;
591 if (SDigitStore(event) == 0x0) return kFALSE;
592 if (DigitStore(event) == 0x0) return kFALSE;
593 if (TriggerStore(event) == 0x0) return kFALSE;
594 if (TrackRefs(event, 0) == 0x0) return kFALSE;
598 //_____________________________________________________________________________
599 Int_t AliMUONMCDataInterface::NumberOfParticles()
601 /// Returns the total number of particles in the kinematics tree.
603 AliStack* stack = Stack(fCurrentEvent);
604 if ( stack == 0x0 ) return -1;
605 return (Int_t) stack->GetNtrack();
608 //_____________________________________________________________________________
609 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
611 /// Returns the index'th particle in the kinematics tree.
612 /// @param index The index number of the particle in the range [0 ... N-1]
613 /// where N = NumberOfParticles()
615 AliStack* stack = Stack(fCurrentEvent);
616 if ( stack == 0x0 ) return 0x0;
617 return static_cast<TParticle*>( stack->Particle(index) );
620 //_____________________________________________________________________________
621 Int_t AliMUONMCDataInterface::NumberOfTracks()
623 /// Returns the number of primary tracks (from primary particles) in the current event.
625 return NumberOfTracks(fCurrentEvent);
628 //_____________________________________________________________________________
629 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
631 /// Returns the number of hits for a given primary track/particle.
632 /// @param track The track number in the range [0 .. N-1]
633 /// where N = NumberOfTracks()
635 TIterator* iter = GetIterator(kHitIterator, track);
636 return CountObjects(iter);
639 //_____________________________________________________________________________
641 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
643 /// Returns a pointer to the index'th hit object.
644 /// @param track The track number in the range [0 .. N-1]
645 /// where N = NumberOfTracks()
646 /// @param index The index number of the hit in the range [0 ... M-1]
647 /// where M = NumberOfHits(track)
649 TIterator* iter = GetIterator(kHitIterator, track);
650 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
653 //_____________________________________________________________________________
654 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
656 /// Returns the number of summable digits to be found on a given detector element.
657 /// @param detElemId The detector element ID number to search on.
659 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
660 return CountObjects(iter);
663 //_____________________________________________________________________________
664 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
666 /// Returns the a pointer to the index'th summable digit on the specified detector element.
667 /// @param detElemId The detector element ID number to search on.
668 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
669 /// where N = NumberOfDigits(detElemId)
671 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
672 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
675 //_____________________________________________________________________________
676 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
678 /// Returns the number of summable digits to be found on a specific chamber and cathode.
679 /// @param chamber The chamber number in the range [0 .. 13].
680 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
681 /// 1 is the non-bending plane.
683 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
684 return CountObjects(iter);
687 //_____________________________________________________________________________
688 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
690 /// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
691 /// @param chamber The chamber number in the range [0 .. 13].
692 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
693 /// 1 is the non-bending plane.
694 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
695 /// where N = NumberOfDigits(chamber, cathode)
697 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
698 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
701 //_____________________________________________________________________________
702 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
704 /// Returns the number of simulated digits to be found on a given detector element.
705 /// @param detElemId The detector element ID number to search on.
707 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
708 return CountObjects(iter);
711 //_____________________________________________________________________________
712 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
714 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
715 /// @param detElemId The detector element ID number to search on.
716 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
717 /// where N = NumberOfDigits(detElemId)
719 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
720 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
723 //_____________________________________________________________________________
724 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
726 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
727 /// @param chamber The chamber number in the range [0 .. 13].
728 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
729 /// 1 is the non-bending plane.
731 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
732 return CountObjects(iter);
735 //_____________________________________________________________________________
736 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
738 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
739 /// @param chamber The chamber number in the range [0 .. 13].
740 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
741 /// 1 is the non-bending plane.
742 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
743 /// where N = NumberOfDigits(chamber, cathode)
745 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
746 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
749 //_____________________________________________________________________________
750 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
752 /// Returns the number of simulated local trigger objects.
754 TIterator* iter = GetIterator(kLocalTriggerIterator);
755 return CountObjects(iter);
758 //_____________________________________________________________________________
759 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
761 /// Returns a pointer to the index'th simulated local trigger object.
762 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
763 /// where N = NumberOfLocalTriggers()
765 TIterator* iter = GetIterator(kLocalTriggerIterator);
766 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
769 //_____________________________________________________________________________
770 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
772 /// Returns the number of simulated regional trigger objects.
774 TIterator* iter = GetIterator(kRegionalTriggerIterator);
775 return CountObjects(iter);
778 //_____________________________________________________________________________
779 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
781 /// Returns a pointer to the index'th simulated regional trigger object.
782 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
783 /// where N = NumberOfRegionalTriggers()
785 TIterator* iter = GetIterator(kRegionalTriggerIterator);
786 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
789 //_____________________________________________________________________________
790 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
792 /// Returns a pointer to the simulated global trigger object for the event.
794 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
795 if (store == 0x0) return 0x0;
796 return store->Global();
799 //_____________________________________________________________________________
800 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
802 /// Number of track references in the currently selected event.
804 return NumberOfTrackRefs(fCurrentEvent);
807 //_____________________________________________________________________________
808 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
810 /// Returns the track references for a given track in the current event.
811 /// @param track The track to returns track references for. In the range [0 .. N-1]
812 /// where N = NumberOfTrackRefs()
814 return TrackRefs(fCurrentEvent, track);
817 //_____________________________________________________________________________
818 void AliMUONMCDataInterface::ResetStores()
820 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
821 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
824 if (fHitStore != 0x0)
829 if (fSDigitStore != 0x0)
834 if (fDigitStore != 0x0)
839 if (fTrackRefs != 0x0)
844 if (fTriggerStore != 0x0)
846 delete fTriggerStore;
851 //_____________________________________________________________________________
852 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
854 /// Creates an appropriate iterator object and returns it.
855 /// If the iterator has already been created then that one is returned otherwise
856 /// a new object is created.
857 /// Depending on the value of 'type' the semantics of parameters x and y can change.
858 /// @param type The type of iterator to create.
859 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
860 /// or kSDigitIteratorByDetectorElement.
861 /// If type equals kDigitIteratorByChamberAndCathode or
862 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
863 /// For type == kHitIterator the parameter x is the track number.
864 /// In all other cases this parameter is ignored.
865 /// @param y If type equals kDigitIteratorByChamberAndCathode or
866 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
867 /// number. In all other cases this parameter is ignored.
869 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
872 if (fCurrentEvent == -1)
874 AliError("No event was selected. Try first using GetEvent().");
885 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
886 if (store == 0x0) return 0x0;
887 fIterator = store->CreateIterator();
888 if (fIterator == 0x0) return 0x0;
889 fCurrentIteratorType = kHitIterator;
893 case kSDigitIteratorByDetectorElement:
896 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
897 if (store == 0x0) return 0x0;
898 AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
899 fIterator = store->CreateIterator(detElem, detElem, 2);
900 if (fIterator == 0x0) return 0x0;
901 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
906 case kSDigitIteratorByChamberAndCathode:
910 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
913 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
914 AliMpConstants::NofChambers() - 1,
919 if (cathode < 0 or 1 < cathode)
921 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
925 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
926 if (store == 0x0) return 0x0;
927 AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
928 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
929 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
930 if (fIterator == 0x0) return 0x0;
931 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
937 case kDigitIteratorByDetectorElement:
940 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
941 if (store == 0x0) return 0x0;
942 AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
943 fIterator = store->CreateIterator(detElem, detElem, 2);
944 if (fIterator == 0x0) return 0x0;
945 fCurrentIteratorType = kDigitIteratorByDetectorElement;
950 case kDigitIteratorByChamberAndCathode:
954 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
957 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
958 AliMpConstants::NofChambers() - 1,
963 if (cathode < 0 or 1 < cathode)
965 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
969 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
970 if (store == 0x0) return 0x0;
971 AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
972 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
973 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
974 if (fIterator == 0x0) return 0x0;
975 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
981 case kLocalTriggerIterator:
983 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
984 if (store == 0x0) return 0x0;
985 fIterator = store->CreateLocalIterator();
986 if (fIterator == 0x0) return 0x0;
987 fCurrentIteratorType = kLocalTriggerIterator;
991 case kRegionalTriggerIterator:
993 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
994 if (store == 0x0) return 0x0;
995 fIterator = store->CreateRegionalIterator();
996 if (fIterator == 0x0) return 0x0;
997 fCurrentIteratorType = kRegionalTriggerIterator;
1006 //_____________________________________________________________________________
1007 void AliMUONMCDataInterface::ResetIterator()
1009 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1010 /// The iterator type and temporary data indicating the state of the iterator are
1013 if (fIterator != 0x0) delete fIterator;
1014 fCurrentIteratorType = kNoIterator;
1015 fCurrentIndex = fDataX = fDataY = -1;
1019 //_____________________________________________________________________________
1020 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1022 /// Counts the number of objects in the iterator and resets it.
1023 /// @return The number of objects in 'iter'.
1025 if (iter == 0x0) return -1;
1028 while ( iter->Next() != 0x0 ) count++;
1034 //_____________________________________________________________________________
1035 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1037 /// Fetches the index'th object from the iterator counting the first object
1038 /// returned by iterator after it is reset as index == 0. The next object
1039 /// has index == 1 and so on where the last object returned by the iterator
1040 /// has index == N-1 where N = CountObjects(iter)
1041 /// This method will only reset the iterator if index is smaller than
1042 /// fCurrentIndex, which is used to track the iteration progress and is
1043 /// updated when a new object if returned by this method.
1044 /// @param iter The iterator to fetch an object from.
1045 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1046 /// where N = CountObjects(iter)
1050 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1054 if (iter == 0x0) return 0x0;
1055 if (index <= fCurrentIndex)
1061 TObject* object = 0x0;
1062 while (fCurrentIndex < index)
1064 object = iter->Next();
1067 AliError(Form("Index is out of bounds. Got a value of %d.", index));