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),
85 if ( AliCDBManager::Instance() != NULL &&
86 AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
87 AliFatal("CDB default storage not defined.");
93 if ( ! AliMpCDB::LoadMpSegmentation() ) {
94 AliFatal("Could not access mapping from OCDB !");
98 //_____________________________________________________________________________
99 AliMUONMCDataInterface::~AliMUONMCDataInterface()
104 delete fLoader->GetRunLoader();
109 //_____________________________________________________________________________
111 AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
113 /// Return the hitStore for a given track of one event
114 /// Return 0x0 if event and/or track not found
115 /// Returned pointer should not be deleted
117 if (not IsValid()) return 0x0;
119 if (event == fCurrentEvent)
121 if (track == fDataX and fHitStore != 0x0) // using fDataX as track number.
127 if ( not LoadEvent(event) ) return 0x0;
132 TTree* treeH = fLoader->TreeH();
135 AliError("Could not get treeH");
139 fHitStore = AliMUONVHitStore::Create(*treeH);
140 AliDebug(1,"Creating hitStore from treeH");
141 if ( fHitStore != 0x0 )
143 fHitStore->Connect(*treeH);
144 if ( treeH->GetEvent(track) == 0 )
146 AliError(Form("Could not read track %d",track));
150 fDataX = track; // using fDataX as track number.
153 fLoader->UnloadHits();
158 //_____________________________________________________________________________
160 AliMUONMCDataInterface::SDigitStore(Int_t event)
162 /// Return the SDigit store for a given event.
163 /// Return 0 if event not found
164 /// Returned pointer should not be deleted
166 if (not IsValid()) return 0x0;
168 if (event == fCurrentEvent)
170 if (fSDigitStore != 0x0)
176 if ( not LoadEvent(event) ) return 0x0;
179 fLoader->LoadSDigits();
181 TTree* treeS = fLoader->TreeS();
184 AliError("Could not get treeS");
188 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
189 if ( fSDigitStore != 0x0 )
191 fSDigitStore->Clear();
192 fSDigitStore->Connect(*treeS);
196 fLoader->UnloadSDigits();
201 //_____________________________________________________________________________
203 AliMUONMCDataInterface::DigitStore(Int_t event)
205 /// Return a pointer to the digitStore for a given event (or 0 if not found)
206 /// Returned pointer should not be deleted
208 if (not IsValid()) return 0x0;
210 if (event == fCurrentEvent)
212 if (fDigitStore != 0x0)
218 if ( not LoadEvent(event) ) return 0x0;
221 fLoader->LoadDigits();
223 TTree* treeD = fLoader->TreeD();
226 AliError("Could not get treeD");
230 fDigitStore = AliMUONVDigitStore::Create(*treeD);
231 if ( fDigitStore != 0x0 )
233 fDigitStore->Clear();
234 fDigitStore->Connect(*treeD);
238 fLoader->UnloadDigits();
243 //_____________________________________________________________________________
245 AliMUONMCDataInterface::Stack(Int_t event)
247 /// Get the Stack (list of generated particles) for one event
248 /// Returned pointer should not be deleted
250 if ( not IsValid() ) return 0x0;
252 if (event != fCurrentEvent)
255 if ( not LoadEvent(event) ) return 0x0;
258 fLoader->GetRunLoader()->LoadKinematics();
260 return fLoader->GetRunLoader()->Stack();
263 //_____________________________________________________________________________
265 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
267 /// Get the track references for a given (generated) track of one event
268 /// Returned pointer should not be deleted
270 if ( not IsValid() ) return 0x0;
272 if (event == fCurrentEvent)
274 if (track == fDataX and fTrackRefs != 0x0) // using fDataX as track number.
280 if ( not LoadEvent(event) ) return 0x0;
283 fLoader->GetRunLoader()->LoadTrackRefs();
285 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
287 if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
291 if ( treeTR->GetEvent(track) > 0 )
293 TBranch* branch = treeTR->GetBranch("TrackReferences");
294 branch->SetAddress(&fTrackRefs);
295 branch->GetEvent(track);
296 fDataX = track; // using fDataX as track number.
301 AliError("Could not get TreeTR");
304 fLoader->GetRunLoader()->UnloadTrackRefs();
309 //_____________________________________________________________________________
310 AliMUONVTriggerStore*
311 AliMUONMCDataInterface::TriggerStore(Int_t event)
313 /// Return the triggerStore for a given event.
314 /// Return 0x0 if event not found.
315 /// Returned pointer should not be deleted.
317 if (not IsValid()) return 0x0;
319 if (event == fCurrentEvent)
321 if (fTriggerStore != 0x0)
322 return fTriggerStore;
327 if ( not LoadEvent(event) ) return 0x0;
330 fLoader->LoadDigits();
332 TTree* treeD = fLoader->TreeD();
335 AliError("Could not get treeD");
339 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
340 if ( fTriggerStore != 0x0 )
342 fTriggerStore->Clear();
343 fTriggerStore->Connect(*treeD);
347 fLoader->UnloadDigits();
349 return fTriggerStore;
352 //_____________________________________________________________________________
354 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
356 /// Dump the digits for a given event, sorted if requested.
359 if ( fDigitStore != 0x0 )
363 DumpSorted(*fDigitStore);
367 fDigitStore->Print();
372 //_____________________________________________________________________________
374 AliMUONMCDataInterface::DumpHits(Int_t event)
376 /// Dump all the hits for one event
378 Int_t ntracks = NumberOfTracks(event);
380 for ( Int_t i = 0; i < ntracks; ++i )
382 cout << ">> Track " << i << endl;
386 fHitStore->Print("","full");
391 //_____________________________________________________________________________
393 AliMUONMCDataInterface::DumpKine(Int_t event)
395 /// Dump all generated particles for one event
396 AliStack* stack = Stack(event);
400 Int_t nparticles = (Int_t) stack->GetNtrack();
402 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
404 stack->Particle(iparticle)->Print("");
409 AliError("Could not get stack");
413 //_____________________________________________________________________________
415 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
417 /// Dump the SDigits for a given event, sorted if requested
420 if ( fSDigitStore != 0x0 )
424 DumpSorted(*fSDigitStore);
428 fSDigitStore->Print();
433 //_____________________________________________________________________________
435 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
437 /// Dump the given store in sorted order
439 TIter next(store.CreateIterator());
442 list.SetOwner(kFALSE);
444 while ( ( object = next() ) )
454 //_____________________________________________________________________________
456 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
458 /// Dump track references for one event
459 Int_t ntrackrefs = NumberOfTrackRefs(event);
461 for ( Int_t i = 0; i < ntrackrefs; ++i )
464 if ( fTrackRefs != 0x0 )
466 fTrackRefs->Print("","*");
471 //_____________________________________________________________________________
473 AliMUONMCDataInterface::DumpTrigger(Int_t event)
475 /// Dump trigger for a given event (trigger is read from TreeD)
479 if ( fTriggerStore != 0x0 )
481 fTriggerStore->Print();
485 //_____________________________________________________________________________
487 AliMUONMCDataInterface::LoadEvent(Int_t event)
489 /// Load event if different from the current one.
490 /// Returns kFALSE on error and kTRUE if the event was loaded.
494 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
495 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
497 fCurrentEvent = event;
505 //_____________________________________________________________________________
507 AliMUONMCDataInterface::NumberOfEvents() const
509 /// Number of events in the file we're connected to
510 if (not IsValid()) return -1;
511 return fLoader->GetRunLoader()->GetNumberOfEvents();
514 //_____________________________________________________________________________
516 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
518 /// Number of tracks in the event
519 if ( not IsValid()) return -1;
521 if (event != fCurrentEvent)
524 if ( not LoadEvent(event) ) return -1;
531 TTree* treeH = fLoader->TreeH();
534 rv = static_cast<Int_t>(treeH->GetEntries());
538 AliError("Could not get TreeH");
541 fLoader->UnloadHits();
546 //_____________________________________________________________________________
548 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
550 /// Number of track references in the event
551 if ( not IsValid()) return -1;
553 if (event != fCurrentEvent)
556 if ( not LoadEvent(event) ) return -1;
559 fLoader->GetRunLoader()->LoadTrackRefs();
563 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
566 rv = static_cast<Int_t>(treeTR->GetEntries());
570 AliError("Could not get TreeTR");
573 fLoader->GetRunLoader()->UnloadTrackRefs();
578 //_____________________________________________________________________________
580 AliMUONMCDataInterface::Open(const char* filename)
582 /// Connect to a given galice.root file
588 if ( fLoader != 0x0 )
590 delete fLoader->GetRunLoader();
597 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
599 while (AliRunLoader::GetRunLoader(foldername))
601 delete AliRunLoader::GetRunLoader(foldername);
604 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
605 if (runLoader == 0x0)
607 AliError(Form("Cannot open file %s",filename));
611 // Get run number and set it to CDB manager
612 runLoader->LoadHeader();
613 if ( ! runLoader->GetHeader() ) {
614 AliError("Cannot load header.");
618 Int_t runNumber = runLoader->GetHeader()->GetRun();
619 AliCDBManager::Instance()->SetRun(runNumber);
621 runLoader->UnloadHeader();
623 fLoader = runLoader->GetDetectorLoader("MUON");
626 AliError("Cannot get AliMUONLoader");
632 AliError(Form("Could not access %s filename. Object is unuseable",filename));
636 //_____________________________________________________________________________
637 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
639 /// Loads all simulated data for the given event.
641 if (HitStore(event, 0) == 0x0) return kFALSE;
642 if (SDigitStore(event) == 0x0) return kFALSE;
643 if (DigitStore(event) == 0x0) return kFALSE;
644 if (TriggerStore(event) == 0x0) return kFALSE;
645 if (TrackRefs(event, 0) == 0x0) return kFALSE;
649 //_____________________________________________________________________________
650 Int_t AliMUONMCDataInterface::NumberOfParticles()
652 /// Returns the total number of particles in the kinematics tree.
654 AliStack* stack = Stack(fCurrentEvent);
655 if ( stack == 0x0 ) return -1;
656 return (Int_t) stack->GetNtrack();
659 //_____________________________________________________________________________
660 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
662 /// Returns the index'th particle in the kinematics tree.
663 /// @param index The index number of the particle in the range [0 ... N-1]
664 /// where N = NumberOfParticles()
666 AliStack* stack = Stack(fCurrentEvent);
667 if ( stack == 0x0 ) return 0x0;
668 return static_cast<TParticle*>( stack->Particle(index) );
671 //_____________________________________________________________________________
672 Int_t AliMUONMCDataInterface::NumberOfTracks()
674 /// Returns the number of primary tracks (from primary particles) in the current event.
676 return NumberOfTracks(fCurrentEvent);
679 //_____________________________________________________________________________
680 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
682 /// Returns the number of hits for a given primary track/particle.
683 /// @param track The track number in the range [0 .. N-1]
684 /// where N = NumberOfTracks()
686 TIterator* iter = GetIterator(kHitIterator, track);
687 return CountObjects(iter);
690 //_____________________________________________________________________________
692 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
694 /// Returns a pointer to the index'th hit object.
695 /// @param track The track number in the range [0 .. N-1]
696 /// where N = NumberOfTracks()
697 /// @param index The index number of the hit in the range [0 ... M-1]
698 /// where M = NumberOfHits(track)
700 TIterator* iter = GetIterator(kHitIterator, track);
701 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
704 //_____________________________________________________________________________
705 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
707 /// Returns the number of summable digits to be found on a given detector element.
708 /// @param detElemId The detector element ID number to search on.
710 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
711 return CountObjects(iter);
714 //_____________________________________________________________________________
715 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
717 /// Returns the a pointer to the index'th summable digit on the specified detector element.
718 /// @param detElemId The detector element ID number to search on.
719 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
720 /// where N = NumberOfDigits(detElemId)
722 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
723 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
726 //_____________________________________________________________________________
727 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
729 /// Returns the number of summable digits to be found on a specific chamber and cathode.
730 /// @param chamber The chamber number in the range [0 .. 13].
731 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
732 /// 1 is the non-bending plane.
734 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
735 return CountObjects(iter);
738 //_____________________________________________________________________________
739 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
741 /// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
742 /// @param chamber The chamber number in the range [0 .. 13].
743 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
744 /// 1 is the non-bending plane.
745 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
746 /// where N = NumberOfDigits(chamber, cathode)
748 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
749 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
752 //_____________________________________________________________________________
753 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
755 /// Returns the number of simulated digits to be found on a given detector element.
756 /// @param detElemId The detector element ID number to search on.
758 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
759 return CountObjects(iter);
762 //_____________________________________________________________________________
763 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
765 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
766 /// @param detElemId The detector element ID number to search on.
767 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
768 /// where N = NumberOfDigits(detElemId)
770 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
771 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
774 //_____________________________________________________________________________
775 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
777 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
778 /// @param chamber The chamber number in the range [0 .. 13].
779 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
780 /// 1 is the non-bending plane.
782 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
783 return CountObjects(iter);
786 //_____________________________________________________________________________
787 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
789 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
790 /// @param chamber The chamber number in the range [0 .. 13].
791 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
792 /// 1 is the non-bending plane.
793 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
794 /// where N = NumberOfDigits(chamber, cathode)
796 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
797 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
800 //_____________________________________________________________________________
801 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
803 /// Returns the number of simulated local trigger objects.
805 TIterator* iter = GetIterator(kLocalTriggerIterator);
806 return CountObjects(iter);
809 //_____________________________________________________________________________
810 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
812 /// Returns a pointer to the index'th simulated local trigger object.
813 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
814 /// where N = NumberOfLocalTriggers()
816 TIterator* iter = GetIterator(kLocalTriggerIterator);
817 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
820 //_____________________________________________________________________________
821 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
823 /// Returns the number of simulated regional trigger objects.
825 TIterator* iter = GetIterator(kRegionalTriggerIterator);
826 return CountObjects(iter);
829 //_____________________________________________________________________________
830 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
832 /// Returns a pointer to the index'th simulated regional trigger object.
833 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
834 /// where N = NumberOfRegionalTriggers()
836 TIterator* iter = GetIterator(kRegionalTriggerIterator);
837 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
840 //_____________________________________________________________________________
841 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
843 /// Returns a pointer to the simulated global trigger object for the event.
845 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
846 if (store == 0x0) return 0x0;
847 return store->Global();
850 //_____________________________________________________________________________
851 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
853 /// Number of track references in the currently selected event.
855 return NumberOfTrackRefs(fCurrentEvent);
858 //_____________________________________________________________________________
859 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
861 /// Returns the track references for a given track in the current event.
862 /// @param track The track to returns track references for. In the range [0 .. N-1]
863 /// where N = NumberOfTrackRefs()
865 return TrackRefs(fCurrentEvent, track);
868 //_____________________________________________________________________________
869 void AliMUONMCDataInterface::ResetStores()
871 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
872 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
875 if (fHitStore != 0x0)
880 if (fSDigitStore != 0x0)
885 if (fDigitStore != 0x0)
890 if (fTrackRefs != 0x0)
895 if (fTriggerStore != 0x0)
897 delete fTriggerStore;
902 //_____________________________________________________________________________
903 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
905 /// Creates an appropriate iterator object and returns it.
906 /// If the iterator has already been created then that one is returned otherwise
907 /// a new object is created.
908 /// Depending on the value of 'type' the semantics of parameters x and y can change.
909 /// @param type The type of iterator to create.
910 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
911 /// or kSDigitIteratorByDetectorElement.
912 /// If type equals kDigitIteratorByChamberAndCathode or
913 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
914 /// For type == kHitIterator the parameter x is the track number.
915 /// In all other cases this parameter is ignored.
916 /// @param y If type equals kDigitIteratorByChamberAndCathode or
917 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
918 /// number. In all other cases this parameter is ignored.
920 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
923 if (fCurrentEvent == -1)
925 AliError("No event was selected. Try first using GetEvent().");
936 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
937 if (store == 0x0) return 0x0;
938 fIterator = store->CreateIterator();
939 if (fIterator == 0x0) return 0x0;
940 fCurrentIteratorType = kHitIterator;
944 case kSDigitIteratorByDetectorElement:
947 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
948 if (store == 0x0) return 0x0;
949 fIterator = store->CreateIterator(detElem, detElem, 2);
950 if (fIterator == 0x0) return 0x0;
951 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
956 case kSDigitIteratorByChamberAndCathode:
960 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
963 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
964 AliMpConstants::NofChambers() - 1,
969 if (cathode < 0 or 1 < cathode)
971 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
975 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
976 if (store == 0x0) return 0x0;
977 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
978 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
979 if (fIterator == 0x0) return 0x0;
980 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
986 case kDigitIteratorByDetectorElement:
989 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
990 if (store == 0x0) return 0x0;
991 fIterator = store->CreateIterator(detElem, detElem, 2);
992 if (fIterator == 0x0) return 0x0;
993 fCurrentIteratorType = kDigitIteratorByDetectorElement;
998 case kDigitIteratorByChamberAndCathode:
1002 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1005 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1006 AliMpConstants::NofChambers() - 1,
1011 if (cathode < 0 or 1 < cathode)
1013 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1017 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1018 if (store == 0x0) return 0x0;
1019 AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
1020 fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
1021 if (fIterator == 0x0) return 0x0;
1022 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
1028 case kLocalTriggerIterator:
1030 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1031 if (store == 0x0) return 0x0;
1032 fIterator = store->CreateLocalIterator();
1033 if (fIterator == 0x0) return 0x0;
1034 fCurrentIteratorType = kLocalTriggerIterator;
1038 case kRegionalTriggerIterator:
1040 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1041 if (store == 0x0) return 0x0;
1042 fIterator = store->CreateRegionalIterator();
1043 if (fIterator == 0x0) return 0x0;
1044 fCurrentIteratorType = kRegionalTriggerIterator;
1053 //_____________________________________________________________________________
1054 void AliMUONMCDataInterface::ResetIterator()
1056 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1057 /// The iterator type and temporary data indicating the state of the iterator are
1060 if (fIterator != 0x0) delete fIterator;
1061 fCurrentIteratorType = kNoIterator;
1062 fCurrentIndex = fDataX = fDataY = -1;
1066 //_____________________________________________________________________________
1067 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1069 /// Counts the number of objects in the iterator and resets it.
1070 /// @return The number of objects in 'iter'.
1072 if (iter == 0x0) return -1;
1075 while ( iter->Next() != 0x0 ) count++;
1081 //_____________________________________________________________________________
1082 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1084 /// Fetches the index'th object from the iterator counting the first object
1085 /// returned by iterator after it is reset as index == 0. The next object
1086 /// has index == 1 and so on where the last object returned by the iterator
1087 /// has index == N-1 where N = CountObjects(iter)
1088 /// This method will only reset the iterator if index is smaller than
1089 /// fCurrentIndex, which is used to track the iteration progress and is
1090 /// updated when a new object if returned by this method.
1091 /// @param iter The iterator to fetch an object from.
1092 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1093 /// where N = CountObjects(iter)
1097 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1101 if (iter == 0x0) return 0x0;
1102 if (index <= fCurrentIndex)
1108 TObject* object = 0x0;
1109 while (fCurrentIndex < index)
1111 object = iter->Next();
1114 AliError(Form("Index is out of bounds. Got a value of %d.", index));