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>
63 ClassImp(AliMUONMCDataInterface)
66 Int_t AliMUONMCDataInterface::fgInstanceCounter(0);
68 //_____________________________________________________________________________
69 AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
79 fCurrentIteratorType(kNoIterator),
89 if ( AliCDBManager::Instance() != NULL &&
90 AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
91 AliFatal("CDB default storage not defined.");
97 if ( ! AliMpCDB::LoadMpSegmentation() ) {
98 AliFatal("Could not access mapping from OCDB !");
102 //_____________________________________________________________________________
103 AliMUONMCDataInterface::~AliMUONMCDataInterface()
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 /// \note If a previous store has been retrieved by one of the methods of
118 /// this class, but for a different event number, then those stores will
119 /// be deleted and no longer valid.
120 /// If you require access to the data for the earlier retrieved store,
121 /// but for different events, then you should deep copy / clone the object.
123 if (not IsValid()) return 0x0;
125 if (event == fCurrentEvent)
127 if (track == fDataX and fHitStore != 0x0) // using fDataX as track number.
133 if ( not LoadEvent(event) ) return 0x0;
138 TTree* treeH = fLoader->TreeH();
141 AliError("Could not get treeH");
145 fHitStore = AliMUONVHitStore::Create(*treeH);
146 AliDebug(1,"Creating hitStore from treeH");
147 if ( fHitStore != 0x0 )
149 fHitStore->Connect(*treeH);
150 if ( treeH->GetEvent(track) == 0 )
152 AliError(Form("Could not read track %d",track));
156 fDataX = track; // using fDataX as track number.
159 fLoader->UnloadHits();
164 //_____________________________________________________________________________
166 AliMUONMCDataInterface::SDigitStore(Int_t event)
168 /// Return the SDigit store for a given event.
169 /// Return 0 if event not found
170 /// Returned pointer should not be deleted
172 /// \note If a previous store has been retrieved by one of the methods of
173 /// this class, but for a different event number, then those stores will
174 /// be deleted and no longer valid.
175 /// If you require access to the data for the earlier retrieved store,
176 /// but for different events, then you should deep copy / clone the object.
178 if (not IsValid()) return 0x0;
180 if (event == fCurrentEvent)
182 if (fSDigitStore != 0x0)
188 if ( not LoadEvent(event) ) return 0x0;
191 fLoader->LoadSDigits();
193 TTree* treeS = fLoader->TreeS();
196 AliError("Could not get treeS");
200 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
201 if ( fSDigitStore != 0x0 )
203 fSDigitStore->Clear();
204 fSDigitStore->Connect(*treeS);
208 fLoader->UnloadSDigits();
213 //_____________________________________________________________________________
215 AliMUONMCDataInterface::DigitStore(Int_t event)
217 /// Return a pointer to the digitStore for a given event (or 0 if not found)
218 /// Returned pointer should not be deleted
220 /// \note If a previous store has been retrieved by one of the methods of
221 /// this class, but for a different event number, then those stores will
222 /// be deleted and no longer valid.
223 /// If you require access to the data for the earlier retrieved store,
224 /// but for different events, then you should deep copy / clone the object.
226 if (not IsValid()) return 0x0;
228 if (event == fCurrentEvent)
230 if (fDigitStore != 0x0)
236 if ( not LoadEvent(event) ) return 0x0;
239 fLoader->LoadDigits();
241 TTree* treeD = fLoader->TreeD();
244 AliError("Could not get treeD");
248 fDigitStore = AliMUONVDigitStore::Create(*treeD);
249 if ( fDigitStore != 0x0 )
251 fDigitStore->Clear();
252 fDigitStore->Connect(*treeD);
256 fLoader->UnloadDigits();
261 //_____________________________________________________________________________
263 AliMUONMCDataInterface::Stack(Int_t event)
265 /// Get the Stack (list of generated particles) for one event
266 /// Returned pointer should not be deleted
268 /// \note If a previous store has been retrieved by one of the methods of
269 /// this class, but for a different event number, then those stores will
270 /// be deleted and no longer valid.
271 /// If you require access to the data for the earlier retrieved store,
272 /// but for different events, then you should deep copy / clone the object.
274 if ( not IsValid() ) return 0x0;
276 if (event != fCurrentEvent)
279 if ( not LoadEvent(event) ) return 0x0;
282 fLoader->GetRunLoader()->LoadKinematics();
284 return fLoader->GetRunLoader()->Stack();
287 //_____________________________________________________________________________
289 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
291 /// Get the track references for a given (generated) track of one event
292 /// Returned pointer should not be deleted
294 /// \note If a previous store has been retrieved by one of the methods of
295 /// this class, but for a different event number, then those stores will
296 /// be deleted and no longer valid.
297 /// If you require access to the data for the earlier retrieved store,
298 /// but for different events, then you should deep copy / clone the object.
300 if ( not IsValid() ) return 0x0;
302 if (event == fCurrentEvent)
304 if (track == fDataX and fTrackRefs != 0x0) // using fDataX as track number.
310 if ( not LoadEvent(event) ) return 0x0;
313 fLoader->GetRunLoader()->LoadTrackRefs();
315 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
317 if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
321 if ( treeTR->GetEvent(track) > 0 )
323 TBranch* branch = treeTR->GetBranch("TrackReferences");
324 branch->SetAddress(&fTrackRefs);
325 branch->GetEvent(track);
326 fDataX = track; // using fDataX as track number.
331 AliError("Could not get TreeTR");
334 fLoader->GetRunLoader()->UnloadTrackRefs();
339 //_____________________________________________________________________________
340 AliMUONVTriggerStore*
341 AliMUONMCDataInterface::TriggerStore(Int_t event)
343 /// Return the triggerStore for a given event.
344 /// Return 0x0 if event not found.
345 /// Returned pointer should not be deleted.
347 /// \note If a previous store has been retrieved by one of the methods of
348 /// this class, but for a different event number, then those stores will
349 /// be deleted and no longer valid.
350 /// If you require access to the data for the earlier retrieved store,
351 /// but for different events, then you should deep copy / clone the object.
353 if (not IsValid()) return 0x0;
355 if (event == fCurrentEvent)
357 if (fTriggerStore != 0x0)
358 return fTriggerStore;
363 if ( not LoadEvent(event) ) return 0x0;
366 fLoader->LoadDigits();
368 TTree* treeD = fLoader->TreeD();
371 AliError("Could not get treeD");
375 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
376 if ( fTriggerStore != 0x0 )
378 fTriggerStore->Clear();
379 fTriggerStore->Connect(*treeD);
383 fLoader->UnloadDigits();
385 return fTriggerStore;
388 //_____________________________________________________________________________
390 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
392 /// Dump the digits for a given event, sorted if requested.
395 if ( fDigitStore != 0x0 )
399 DumpSorted(*fDigitStore);
403 fDigitStore->Print();
408 //_____________________________________________________________________________
410 AliMUONMCDataInterface::DumpHits(Int_t event)
412 /// Dump all the hits for one event
414 Int_t ntracks = NumberOfTracks(event);
416 for ( Int_t i = 0; i < ntracks; ++i )
418 cout << ">> Track " << i << endl;
422 fHitStore->Print("","full");
427 //_____________________________________________________________________________
429 AliMUONMCDataInterface::DumpKine(Int_t event)
431 /// Dump all generated particles for one event
432 AliStack* stack = Stack(event);
436 Int_t nparticles = (Int_t) stack->GetNtrack();
438 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
440 stack->Particle(iparticle)->Print("");
445 AliError("Could not get stack");
449 //_____________________________________________________________________________
451 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
453 /// Dump the SDigits for a given event, sorted if requested
456 if ( fSDigitStore != 0x0 )
460 DumpSorted(*fSDigitStore);
464 fSDigitStore->Print();
469 //_____________________________________________________________________________
471 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
473 /// Dump the given store in sorted order
475 TIter next(store.CreateIterator());
478 list.SetOwner(kFALSE);
480 while ( ( object = next() ) )
490 //_____________________________________________________________________________
492 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
494 /// Dump track references for one event
495 Int_t ntrackrefs = NumberOfTrackRefs(event);
497 for ( Int_t i = 0; i < ntrackrefs; ++i )
500 if ( fTrackRefs != 0x0 )
502 fTrackRefs->Print("","*");
507 //_____________________________________________________________________________
509 AliMUONMCDataInterface::DumpTrigger(Int_t event)
511 /// Dump trigger for a given event (trigger is read from TreeD)
515 if ( fTriggerStore != 0x0 )
517 fTriggerStore->Print();
521 //_____________________________________________________________________________
523 AliMUONMCDataInterface::LoadEvent(Int_t event)
525 /// Load event if different from the current one.
526 /// Returns kFALSE on error and kTRUE if the event was loaded.
530 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
531 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
533 fCurrentEvent = event;
541 //_____________________________________________________________________________
543 AliMUONMCDataInterface::NumberOfEvents() const
545 /// Number of events in the file we're connected to
546 if (not IsValid()) return -1;
547 return fLoader->GetRunLoader()->GetNumberOfEvents();
550 //_____________________________________________________________________________
552 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
554 /// Number of tracks in the event
555 if ( not IsValid()) return -1;
557 if (event != fCurrentEvent)
560 if ( not LoadEvent(event) ) return -1;
567 TTree* treeH = fLoader->TreeH();
570 rv = static_cast<Int_t>(treeH->GetEntries());
574 AliError("Could not get TreeH");
577 fLoader->UnloadHits();
582 //_____________________________________________________________________________
584 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
586 /// Number of track references in the event
587 if ( not IsValid()) return -1;
589 if (event != fCurrentEvent)
592 if ( not LoadEvent(event) ) return -1;
595 fLoader->GetRunLoader()->LoadTrackRefs();
599 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
602 rv = static_cast<Int_t>(treeTR->GetEntries());
606 AliError("Could not get TreeTR");
609 fLoader->GetRunLoader()->UnloadTrackRefs();
614 //_____________________________________________________________________________
616 AliMUONMCDataInterface::Open(const char* filename)
618 /// Connect to a given galice.root file
624 if ( fLoader != 0x0 )
626 delete fLoader->GetRunLoader();
633 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
635 while (AliRunLoader::GetRunLoader(foldername))
637 delete AliRunLoader::GetRunLoader(foldername);
640 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
641 if (runLoader == 0x0)
643 AliError(Form("Cannot open file %s",filename));
648 // Get run number and set it to CDB manager
649 runLoader->LoadHeader();
650 if ( ! runLoader->GetHeader() ) {
651 AliError("Cannot load header.");
655 Int_t runNumber = runLoader->GetHeader()->GetRun();
656 AliCDBManager::Instance()->SetRun(runNumber);
658 runLoader->UnloadHeader();
660 fLoader = runLoader->GetDetectorLoader("MUON");
663 AliError("Cannot get AliMUONLoader");
669 AliError(Form("Could not access %s filename. Object is unuseable",filename));
673 //_____________________________________________________________________________
674 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
676 /// Loads all simulated data for the given event.
678 if (HitStore(event, 0) == 0x0) return kFALSE;
679 if (SDigitStore(event) == 0x0) return kFALSE;
680 if (DigitStore(event) == 0x0) return kFALSE;
681 if (TriggerStore(event) == 0x0) return kFALSE;
682 if (TrackRefs(event, 0) == 0x0) return kFALSE;
686 //_____________________________________________________________________________
687 Int_t AliMUONMCDataInterface::NumberOfParticles()
689 /// Returns the total number of particles in the kinematics tree.
691 AliStack* stack = Stack(fCurrentEvent);
692 if ( stack == 0x0 ) return -1;
693 return (Int_t) stack->GetNtrack();
696 //_____________________________________________________________________________
697 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
699 /// Returns the index'th particle in the kinematics tree.
700 /// @param index The index number of the particle in the range [0 ... N-1]
701 /// where N = NumberOfParticles()
703 AliStack* stack = Stack(fCurrentEvent);
704 if ( stack == 0x0 ) return 0x0;
705 return static_cast<TParticle*>( stack->Particle(index) );
708 //_____________________________________________________________________________
709 Int_t AliMUONMCDataInterface::NumberOfTracks()
711 /// Returns the number of primary tracks (from primary particles) in the current event.
713 return NumberOfTracks(fCurrentEvent);
716 //_____________________________________________________________________________
717 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
719 /// Returns the number of hits for a given primary track/particle.
720 /// @param track The track number in the range [0 .. N-1]
721 /// where N = NumberOfTracks()
723 TIterator* iter = GetIterator(kHitIterator, track);
724 return CountObjects(iter);
727 //_____________________________________________________________________________
729 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
731 /// Returns a pointer to the index'th hit object.
732 /// @param track The track number in the range [0 .. N-1]
733 /// where N = NumberOfTracks()
734 /// @param index The index number of the hit in the range [0 ... M-1]
735 /// where M = NumberOfHits(track)
737 TIterator* iter = GetIterator(kHitIterator, track);
738 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
741 //_____________________________________________________________________________
742 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
744 /// Returns the number of summable digits to be found on a given detector element.
745 /// @param detElemId The detector element ID number to search on.
747 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
748 return CountObjects(iter);
751 //_____________________________________________________________________________
752 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
754 /// Returns the a pointer to the index'th summable digit on the specified detector element.
755 /// @param detElemId The detector element ID number to search on.
756 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
757 /// where N = NumberOfDigits(detElemId)
759 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
760 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
763 //_____________________________________________________________________________
764 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
766 /// Returns the number of summable digits to be found on a specific chamber and cathode.
767 /// @param chamber The chamber number in the range [0 .. 13].
768 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
769 /// 1 is the non-bending plane.
771 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
772 return CountObjects(iter);
775 //_____________________________________________________________________________
776 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
778 /// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
779 /// @param chamber The chamber number in the range [0 .. 13].
780 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
781 /// 1 is the non-bending plane.
782 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
783 /// where N = NumberOfDigits(chamber, cathode)
785 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
786 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
789 //_____________________________________________________________________________
790 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
792 /// Returns the number of simulated digits to be found on a given detector element.
793 /// @param detElemId The detector element ID number to search on.
795 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
796 return CountObjects(iter);
799 //_____________________________________________________________________________
800 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
802 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
803 /// @param detElemId The detector element ID number to search on.
804 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
805 /// where N = NumberOfDigits(detElemId)
807 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
808 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
811 //_____________________________________________________________________________
812 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
814 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
815 /// @param chamber The chamber number in the range [0 .. 13].
816 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
817 /// 1 is the non-bending plane.
819 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
820 return CountObjects(iter);
823 //_____________________________________________________________________________
824 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
826 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
827 /// @param chamber The chamber number in the range [0 .. 13].
828 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
829 /// 1 is the non-bending plane.
830 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
831 /// where N = NumberOfDigits(chamber, cathode)
833 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
834 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
837 //_____________________________________________________________________________
838 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
840 /// Returns the number of simulated local trigger objects.
842 TIterator* iter = GetIterator(kLocalTriggerIterator);
843 return CountObjects(iter);
846 //_____________________________________________________________________________
847 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
849 /// Returns a pointer to the index'th simulated local trigger object.
850 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
851 /// where N = NumberOfLocalTriggers()
853 TIterator* iter = GetIterator(kLocalTriggerIterator);
854 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
857 //_____________________________________________________________________________
858 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
860 /// Returns the number of simulated regional trigger objects.
862 TIterator* iter = GetIterator(kRegionalTriggerIterator);
863 return CountObjects(iter);
866 //_____________________________________________________________________________
867 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
869 /// Returns a pointer to the index'th simulated regional trigger object.
870 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
871 /// where N = NumberOfRegionalTriggers()
873 TIterator* iter = GetIterator(kRegionalTriggerIterator);
874 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
877 //_____________________________________________________________________________
878 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
880 /// Returns a pointer to the simulated global trigger object for the event.
882 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
883 if (store == 0x0) return 0x0;
884 return store->Global();
887 //_____________________________________________________________________________
888 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
890 /// Number of track references in the currently selected event.
892 return NumberOfTrackRefs(fCurrentEvent);
895 //_____________________________________________________________________________
896 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
898 /// Returns the track references for a given track in the current event.
899 /// @param track The track to returns track references for. In the range [0 .. N-1]
900 /// where N = NumberOfTrackRefs()
902 return TrackRefs(fCurrentEvent, track);
905 //_____________________________________________________________________________
906 void AliMUONMCDataInterface::ResetStores()
908 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
909 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
912 if (fHitStore != 0x0)
917 if (fSDigitStore != 0x0)
922 if (fDigitStore != 0x0)
927 if (fTrackRefs != 0x0)
932 if (fTriggerStore != 0x0)
934 delete fTriggerStore;
939 //_____________________________________________________________________________
940 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
942 /// Creates an appropriate iterator object and returns it.
943 /// If the iterator has already been created then that one is returned otherwise
944 /// a new object is created.
945 /// Depending on the value of 'type' the semantics of parameters x and y can change.
946 /// @param type The type of iterator to create.
947 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
948 /// or kSDigitIteratorByDetectorElement.
949 /// If type equals kDigitIteratorByChamberAndCathode or
950 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
951 /// For type == kHitIterator the parameter x is the track number.
952 /// In all other cases this parameter is ignored.
953 /// @param y If type equals kDigitIteratorByChamberAndCathode or
954 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
955 /// number. In all other cases this parameter is ignored.
957 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
960 if (fCurrentEvent == -1)
962 AliError("No event was selected. Try first using GetEvent().");
973 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
974 if (store == 0x0) return 0x0;
975 fIterator = store->CreateIterator();
976 if (fIterator == 0x0) return 0x0;
977 fCurrentIteratorType = kHitIterator;
981 case kSDigitIteratorByDetectorElement:
984 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
985 if (store == 0x0) return 0x0;
986 fIterator = store->CreateIterator(detElem, detElem, 2);
987 if (fIterator == 0x0) return 0x0;
988 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
993 case kSDigitIteratorByChamberAndCathode:
997 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1000 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1001 AliMpConstants::NofChambers() - 1,
1006 if (cathode < 0 or 1 < cathode)
1008 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1012 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
1013 if (store == 0x0) return 0x0;
1014 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1015 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1016 if (fIterator == 0x0) return 0x0;
1017 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
1023 case kDigitIteratorByDetectorElement:
1026 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1027 if (store == 0x0) return 0x0;
1028 fIterator = store->CreateIterator(detElem, detElem, 2);
1029 if (fIterator == 0x0) return 0x0;
1030 fCurrentIteratorType = kDigitIteratorByDetectorElement;
1035 case kDigitIteratorByChamberAndCathode:
1039 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1042 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1043 AliMpConstants::NofChambers() - 1,
1048 if (cathode < 0 or 1 < cathode)
1050 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1054 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1055 if (store == 0x0) return 0x0;
1056 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1057 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1058 if (fIterator == 0x0) return 0x0;
1059 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
1065 case kLocalTriggerIterator:
1067 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1068 if (store == 0x0) return 0x0;
1069 fIterator = store->CreateLocalIterator();
1070 if (fIterator == 0x0) return 0x0;
1071 fCurrentIteratorType = kLocalTriggerIterator;
1075 case kRegionalTriggerIterator:
1077 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1078 if (store == 0x0) return 0x0;
1079 fIterator = store->CreateRegionalIterator();
1080 if (fIterator == 0x0) return 0x0;
1081 fCurrentIteratorType = kRegionalTriggerIterator;
1090 //_____________________________________________________________________________
1091 void AliMUONMCDataInterface::ResetIterator()
1093 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1094 /// The iterator type and temporary data indicating the state of the iterator are
1097 if (fIterator != 0x0) delete fIterator;
1098 fCurrentIteratorType = kNoIterator;
1099 fCurrentIndex = fDataX = fDataY = -1;
1103 //_____________________________________________________________________________
1104 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1106 /// Counts the number of objects in the iterator and resets it.
1107 /// @return The number of objects in 'iter'.
1109 if (iter == 0x0) return -1;
1112 while ( iter->Next() != 0x0 ) count++;
1118 //_____________________________________________________________________________
1119 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1121 /// Fetches the index'th object from the iterator counting the first object
1122 /// returned by iterator after it is reset as index == 0. The next object
1123 /// has index == 1 and so on where the last object returned by the iterator
1124 /// has index == N-1 where N = CountObjects(iter)
1125 /// This method will only reset the iterator if index is smaller than
1126 /// fCurrentIndex, which is used to track the iteration progress and is
1127 /// updated when a new object if returned by this method.
1128 /// @param iter The iterator to fetch an object from.
1129 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1130 /// where N = CountObjects(iter)
1134 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1138 if (iter == 0x0) return 0x0;
1139 if (index <= fCurrentIndex)
1145 TObject* object = 0x0;
1146 while (fCurrentIndex < index)
1148 object = iter->Next();
1151 AliError(Form("Index is out of bounds. Got a value of %d.", index));