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 "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 /// \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));
647 // Get run number and set it to CDB manager
648 runLoader->LoadHeader();
649 if ( ! runLoader->GetHeader() ) {
650 AliError("Cannot load header.");
654 Int_t runNumber = runLoader->GetHeader()->GetRun();
655 AliCDBManager::Instance()->SetRun(runNumber);
657 runLoader->UnloadHeader();
659 fLoader = runLoader->GetDetectorLoader("MUON");
662 AliError("Cannot get AliMUONLoader");
668 AliError(Form("Could not access %s filename. Object is unuseable",filename));
672 //_____________________________________________________________________________
673 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
675 /// Loads all simulated data for the given event.
677 if (HitStore(event, 0) == 0x0) return kFALSE;
678 if (SDigitStore(event) == 0x0) return kFALSE;
679 if (DigitStore(event) == 0x0) return kFALSE;
680 if (TriggerStore(event) == 0x0) return kFALSE;
681 if (TrackRefs(event, 0) == 0x0) return kFALSE;
685 //_____________________________________________________________________________
686 Int_t AliMUONMCDataInterface::NumberOfParticles()
688 /// Returns the total number of particles in the kinematics tree.
690 AliStack* stack = Stack(fCurrentEvent);
691 if ( stack == 0x0 ) return -1;
692 return (Int_t) stack->GetNtrack();
695 //_____________________________________________________________________________
696 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
698 /// Returns the index'th particle in the kinematics tree.
699 /// @param index The index number of the particle in the range [0 ... N-1]
700 /// where N = NumberOfParticles()
702 AliStack* stack = Stack(fCurrentEvent);
703 if ( stack == 0x0 ) return 0x0;
704 return static_cast<TParticle*>( stack->Particle(index) );
707 //_____________________________________________________________________________
708 Int_t AliMUONMCDataInterface::NumberOfTracks()
710 /// Returns the number of primary tracks (from primary particles) in the current event.
712 return NumberOfTracks(fCurrentEvent);
715 //_____________________________________________________________________________
716 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
718 /// Returns the number of hits for a given primary track/particle.
719 /// @param track The track number in the range [0 .. N-1]
720 /// where N = NumberOfTracks()
722 TIterator* iter = GetIterator(kHitIterator, track);
723 return CountObjects(iter);
726 //_____________________________________________________________________________
728 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
730 /// Returns a pointer to the index'th hit object.
731 /// @param track The track number in the range [0 .. N-1]
732 /// where N = NumberOfTracks()
733 /// @param index The index number of the hit in the range [0 ... M-1]
734 /// where M = NumberOfHits(track)
736 TIterator* iter = GetIterator(kHitIterator, track);
737 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
740 //_____________________________________________________________________________
741 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
743 /// Returns the number of summable digits to be found on a given detector element.
744 /// @param detElemId The detector element ID number to search on.
746 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
747 return CountObjects(iter);
750 //_____________________________________________________________________________
751 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
753 /// Returns the a pointer to the index'th summable digit on the specified detector element.
754 /// @param detElemId The detector element ID number to search on.
755 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
756 /// where N = NumberOfDigits(detElemId)
758 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
759 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
762 //_____________________________________________________________________________
763 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
765 /// Returns the number of summable digits to be found on a specific chamber and cathode.
766 /// @param chamber The chamber number in the range [0 .. 13].
767 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
768 /// 1 is the non-bending plane.
770 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
771 return CountObjects(iter);
774 //_____________________________________________________________________________
775 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
777 /// Returns the a pointer to the index'th summable digit on the specified 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.
781 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
782 /// where N = NumberOfDigits(chamber, cathode)
784 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
785 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
788 //_____________________________________________________________________________
789 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
791 /// Returns the number of simulated digits to be found on a given detector element.
792 /// @param detElemId The detector element ID number to search on.
794 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
795 return CountObjects(iter);
798 //_____________________________________________________________________________
799 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
801 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
802 /// @param detElemId The detector element ID number to search on.
803 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
804 /// where N = NumberOfDigits(detElemId)
806 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
807 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
810 //_____________________________________________________________________________
811 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
813 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
814 /// @param chamber The chamber number in the range [0 .. 13].
815 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
816 /// 1 is the non-bending plane.
818 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
819 return CountObjects(iter);
822 //_____________________________________________________________________________
823 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
825 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
826 /// @param chamber The chamber number in the range [0 .. 13].
827 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
828 /// 1 is the non-bending plane.
829 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
830 /// where N = NumberOfDigits(chamber, cathode)
832 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
833 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
836 //_____________________________________________________________________________
837 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
839 /// Returns the number of simulated local trigger objects.
841 TIterator* iter = GetIterator(kLocalTriggerIterator);
842 return CountObjects(iter);
845 //_____________________________________________________________________________
846 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
848 /// Returns a pointer to the index'th simulated local trigger object.
849 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
850 /// where N = NumberOfLocalTriggers()
852 TIterator* iter = GetIterator(kLocalTriggerIterator);
853 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
856 //_____________________________________________________________________________
857 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
859 /// Returns the number of simulated regional trigger objects.
861 TIterator* iter = GetIterator(kRegionalTriggerIterator);
862 return CountObjects(iter);
865 //_____________________________________________________________________________
866 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
868 /// Returns a pointer to the index'th simulated regional trigger object.
869 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
870 /// where N = NumberOfRegionalTriggers()
872 TIterator* iter = GetIterator(kRegionalTriggerIterator);
873 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
876 //_____________________________________________________________________________
877 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
879 /// Returns a pointer to the simulated global trigger object for the event.
881 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
882 if (store == 0x0) return 0x0;
883 return store->Global();
886 //_____________________________________________________________________________
887 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
889 /// Number of track references in the currently selected event.
891 return NumberOfTrackRefs(fCurrentEvent);
894 //_____________________________________________________________________________
895 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
897 /// Returns the track references for a given track in the current event.
898 /// @param track The track to returns track references for. In the range [0 .. N-1]
899 /// where N = NumberOfTrackRefs()
901 return TrackRefs(fCurrentEvent, track);
904 //_____________________________________________________________________________
905 void AliMUONMCDataInterface::ResetStores()
907 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
908 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
911 if (fHitStore != 0x0)
916 if (fSDigitStore != 0x0)
921 if (fDigitStore != 0x0)
926 if (fTrackRefs != 0x0)
931 if (fTriggerStore != 0x0)
933 delete fTriggerStore;
938 //_____________________________________________________________________________
939 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
941 /// Creates an appropriate iterator object and returns it.
942 /// If the iterator has already been created then that one is returned otherwise
943 /// a new object is created.
944 /// Depending on the value of 'type' the semantics of parameters x and y can change.
945 /// @param type The type of iterator to create.
946 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
947 /// or kSDigitIteratorByDetectorElement.
948 /// If type equals kDigitIteratorByChamberAndCathode or
949 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
950 /// For type == kHitIterator the parameter x is the track number.
951 /// In all other cases this parameter is ignored.
952 /// @param y If type equals kDigitIteratorByChamberAndCathode or
953 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
954 /// number. In all other cases this parameter is ignored.
956 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
959 if (fCurrentEvent == -1)
961 AliError("No event was selected. Try first using GetEvent().");
972 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
973 if (store == 0x0) return 0x0;
974 fIterator = store->CreateIterator();
975 if (fIterator == 0x0) return 0x0;
976 fCurrentIteratorType = kHitIterator;
980 case kSDigitIteratorByDetectorElement:
983 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
984 if (store == 0x0) return 0x0;
985 fIterator = store->CreateIterator(detElem, detElem, 2);
986 if (fIterator == 0x0) return 0x0;
987 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
992 case kSDigitIteratorByChamberAndCathode:
996 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
999 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1000 AliMpConstants::NofChambers() - 1,
1005 if (cathode < 0 or 1 < cathode)
1007 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1011 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
1012 if (store == 0x0) return 0x0;
1013 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1014 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1015 if (fIterator == 0x0) return 0x0;
1016 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
1022 case kDigitIteratorByDetectorElement:
1025 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1026 if (store == 0x0) return 0x0;
1027 fIterator = store->CreateIterator(detElem, detElem, 2);
1028 if (fIterator == 0x0) return 0x0;
1029 fCurrentIteratorType = kDigitIteratorByDetectorElement;
1034 case kDigitIteratorByChamberAndCathode:
1038 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1041 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1042 AliMpConstants::NofChambers() - 1,
1047 if (cathode < 0 or 1 < cathode)
1049 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1053 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1054 if (store == 0x0) return 0x0;
1055 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1056 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1057 if (fIterator == 0x0) return 0x0;
1058 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
1064 case kLocalTriggerIterator:
1066 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1067 if (store == 0x0) return 0x0;
1068 fIterator = store->CreateLocalIterator();
1069 if (fIterator == 0x0) return 0x0;
1070 fCurrentIteratorType = kLocalTriggerIterator;
1074 case kRegionalTriggerIterator:
1076 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1077 if (store == 0x0) return 0x0;
1078 fIterator = store->CreateRegionalIterator();
1079 if (fIterator == 0x0) return 0x0;
1080 fCurrentIteratorType = kRegionalTriggerIterator;
1089 //_____________________________________________________________________________
1090 void AliMUONMCDataInterface::ResetIterator()
1092 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1093 /// The iterator type and temporary data indicating the state of the iterator are
1096 if (fIterator != 0x0) delete fIterator;
1097 fCurrentIteratorType = kNoIterator;
1098 fCurrentIndex = fDataX = fDataY = -1;
1102 //_____________________________________________________________________________
1103 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1105 /// Counts the number of objects in the iterator and resets it.
1106 /// @return The number of objects in 'iter'.
1108 if (iter == 0x0) return -1;
1111 while ( iter->Next() != 0x0 ) count++;
1117 //_____________________________________________________________________________
1118 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1120 /// Fetches the index'th object from the iterator counting the first object
1121 /// returned by iterator after it is reset as index == 0. The next object
1122 /// has index == 1 and so on where the last object returned by the iterator
1123 /// has index == N-1 where N = CountObjects(iter)
1124 /// This method will only reset the iterator if index is smaller than
1125 /// fCurrentIndex, which is used to track the iteration progress and is
1126 /// updated when a new object if returned by this method.
1127 /// @param iter The iterator to fetch an object from.
1128 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1129 /// where N = CountObjects(iter)
1133 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1137 if (iter == 0x0) return 0x0;
1138 if (index <= fCurrentIndex)
1144 TObject* object = 0x0;
1145 while (fCurrentIndex < index)
1147 object = iter->Next();
1150 AliError(Form("Index is out of bounds. Got a value of %d.", index));