1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONMCDataInterface
21 /// Easy to use MC data accessor
23 /// \author Laurent Aphecetche, Subatech
25 // Moved parts of old AliMUONDataInterface interface to AliMUONMCDataInterface
26 // Artur Szostak <artursz@iafrica.com> (University of Cape Town)
27 //-----------------------------------------------------------------------------
29 #include "AliMUONMCDataInterface.h"
30 #include "AliMUONVDigitStore.h"
31 #include "AliMUONVHitStore.h"
32 #include "AliMUONVTriggerStore.h"
33 #include "AliMUONHit.h"
34 #include "AliMUONVDigit.h"
35 #include "AliMUONLocalTrigger.h"
36 #include "AliMUONRegionalTrigger.h"
37 #include "AliMUONGlobalTrigger.h"
39 #include "AliMpEncodePair.h"
40 #include "AliMpDEManager.h"
41 #include "AliMpConstants.h"
45 #include "AliLoader.h"
46 #include "AliRunLoader.h"
47 #include "AliHeader.h"
49 #include "AliCDBManager.h"
52 #include <Riostream.h>
53 #include <TClonesArray.h>
55 #include <TParticle.h>
56 #include <TIterator.h>
61 ClassImp(AliMUONMCDataInterface)
64 Int_t AliMUONMCDataInterface::fgInstanceCounter(0);
66 //_____________________________________________________________________________
67 AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
77 fCurrentIteratorType(kNoIterator),
87 if ( AliCDBManager::Instance() != NULL &&
88 AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
89 AliFatal("CDB default storage not defined.");
95 if ( ! AliMpCDB::LoadMpSegmentation() ) {
96 AliFatal("Could not access mapping from OCDB !");
100 //_____________________________________________________________________________
101 AliMUONMCDataInterface::~AliMUONMCDataInterface()
106 delete fLoader->GetRunLoader();
111 //_____________________________________________________________________________
113 AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
115 /// Return the hitStore for a given track of one event
116 /// Return 0x0 if event and/or track not found
117 /// Returned pointer should not be deleted
119 /// \note If a previous store has been retrieved by one of the methods of
120 /// this class, but for a different event number, then those stores will
121 /// be deleted and no longer valid.
122 /// If you require access to the data for the earlier retrieved store,
123 /// but for different events, then you should deep copy / clone the object.
125 if (not IsValid()) return 0x0;
127 if (event == fCurrentEvent)
129 if (track == fDataX and fHitStore != 0x0) // using fDataX as track number.
135 if ( not LoadEvent(event) ) return 0x0;
140 TTree* treeH = fLoader->TreeH();
143 AliError("Could not get treeH");
147 fHitStore = AliMUONVHitStore::Create(*treeH);
148 AliDebug(1,"Creating hitStore from treeH");
149 if ( fHitStore != 0x0 )
151 fHitStore->Connect(*treeH);
152 if ( treeH->GetEvent(track) == 0 )
154 AliError(Form("Could not read track %d",track));
158 fDataX = track; // using fDataX as track number.
161 fLoader->UnloadHits();
166 //_____________________________________________________________________________
168 AliMUONMCDataInterface::SDigitStore(Int_t event)
170 /// Return the SDigit store for a given event.
171 /// Return 0 if event not found
172 /// Returned pointer should not be deleted
174 /// \note If a previous store has been retrieved by one of the methods of
175 /// this class, but for a different event number, then those stores will
176 /// be deleted and no longer valid.
177 /// If you require access to the data for the earlier retrieved store,
178 /// but for different events, then you should deep copy / clone the object.
180 if (not IsValid()) return 0x0;
182 if (event == fCurrentEvent)
184 if (fSDigitStore != 0x0)
190 if ( not LoadEvent(event) ) return 0x0;
193 fLoader->LoadSDigits();
195 TTree* treeS = fLoader->TreeS();
198 AliError("Could not get treeS");
202 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
203 if ( fSDigitStore != 0x0 )
205 fSDigitStore->Clear();
206 fSDigitStore->Connect(*treeS);
210 fLoader->UnloadSDigits();
215 //_____________________________________________________________________________
217 AliMUONMCDataInterface::DigitStore(Int_t event)
219 /// Return a pointer to the digitStore for a given event (or 0 if not found)
220 /// Returned pointer should not be deleted
222 /// \note If a previous store has been retrieved by one of the methods of
223 /// this class, but for a different event number, then those stores will
224 /// be deleted and no longer valid.
225 /// If you require access to the data for the earlier retrieved store,
226 /// but for different events, then you should deep copy / clone the object.
228 if (not IsValid()) return 0x0;
230 if (event == fCurrentEvent)
232 if (fDigitStore != 0x0)
238 if ( not LoadEvent(event) ) return 0x0;
241 fLoader->LoadDigits();
243 TTree* treeD = fLoader->TreeD();
246 AliError("Could not get treeD");
250 fDigitStore = AliMUONVDigitStore::Create(*treeD);
251 if ( fDigitStore != 0x0 )
253 fDigitStore->Clear();
254 fDigitStore->Connect(*treeD);
258 fLoader->UnloadDigits();
263 //_____________________________________________________________________________
265 AliMUONMCDataInterface::Stack(Int_t event)
267 /// Get the Stack (list of generated particles) for one event
268 /// Returned pointer should not be deleted
270 /// \note If a previous store has been retrieved by one of the methods of
271 /// this class, but for a different event number, then those stores will
272 /// be deleted and no longer valid.
273 /// If you require access to the data for the earlier retrieved store,
274 /// but for different events, then you should deep copy / clone the object.
276 if ( not IsValid() ) return 0x0;
278 if (event != fCurrentEvent)
281 if ( not LoadEvent(event) ) return 0x0;
284 fLoader->GetRunLoader()->LoadKinematics();
286 return fLoader->GetRunLoader()->Stack();
289 //_____________________________________________________________________________
291 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
293 /// Get the track references for a given (generated) track of one event
294 /// Returned pointer should not be deleted
296 /// \note If a previous store has been retrieved by one of the methods of
297 /// this class, but for a different event number, then those stores will
298 /// be deleted and no longer valid.
299 /// If you require access to the data for the earlier retrieved store,
300 /// but for different events, then you should deep copy / clone the object.
302 if ( not IsValid() ) return 0x0;
304 if (event == fCurrentEvent)
306 if (track == fDataX and fTrackRefs != 0x0) // using fDataX as track number.
312 if ( not LoadEvent(event) ) return 0x0;
315 fLoader->GetRunLoader()->LoadTrackRefs();
317 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
319 if ( fTrackRefs != 0x0 ) fTrackRefs->Clear("C");
323 if ( treeTR->GetEvent(track) > 0 )
325 TBranch* branch = treeTR->GetBranch("TrackReferences");
326 branch->SetAddress(&fTrackRefs);
327 branch->GetEvent(track);
328 fDataX = track; // using fDataX as track number.
333 AliError("Could not get TreeTR");
336 fLoader->GetRunLoader()->UnloadTrackRefs();
341 //_____________________________________________________________________________
342 AliMUONVTriggerStore*
343 AliMUONMCDataInterface::TriggerStore(Int_t event)
345 /// Return the triggerStore for a given event.
346 /// Return 0x0 if event not found.
347 /// Returned pointer should not be deleted.
349 /// \note If a previous store has been retrieved by one of the methods of
350 /// this class, but for a different event number, then those stores will
351 /// be deleted and no longer valid.
352 /// If you require access to the data for the earlier retrieved store,
353 /// but for different events, then you should deep copy / clone the object.
355 if (not IsValid()) return 0x0;
357 if (event == fCurrentEvent)
359 if (fTriggerStore != 0x0)
360 return fTriggerStore;
365 if ( not LoadEvent(event) ) return 0x0;
368 fLoader->LoadDigits();
370 TTree* treeD = fLoader->TreeD();
373 AliError("Could not get treeD");
377 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
378 if ( fTriggerStore != 0x0 )
380 fTriggerStore->Clear();
381 fTriggerStore->Connect(*treeD);
385 fLoader->UnloadDigits();
387 return fTriggerStore;
390 //_____________________________________________________________________________
392 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
394 /// Dump the digits for a given event, sorted if requested.
397 if ( fDigitStore != 0x0 )
401 DumpSorted(*fDigitStore);
405 fDigitStore->Print();
410 //_____________________________________________________________________________
412 AliMUONMCDataInterface::DumpHits(Int_t event)
414 /// Dump all the hits for one event
416 Int_t ntracks = NumberOfTracks(event);
418 for ( Int_t i = 0; i < ntracks; ++i )
420 cout << ">> Track " << i << endl;
424 fHitStore->Print("","full");
429 //_____________________________________________________________________________
431 AliMUONMCDataInterface::DumpKine(Int_t event)
433 /// Dump all generated particles for one event
434 AliStack* stack = Stack(event);
438 Int_t nparticles = (Int_t) stack->GetNtrack();
440 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
442 stack->Particle(iparticle)->Print("");
447 AliError("Could not get stack");
451 //_____________________________________________________________________________
453 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
455 /// Dump the SDigits for a given event, sorted if requested
458 if ( fSDigitStore != 0x0 )
462 DumpSorted(*fSDigitStore);
466 fSDigitStore->Print();
471 //_____________________________________________________________________________
473 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
475 /// Dump the given store in sorted order
477 TIter next(store.CreateIterator());
480 list.SetOwner(kFALSE);
482 while ( ( object = next() ) )
492 //_____________________________________________________________________________
494 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
496 /// Dump track references for one event
497 Int_t ntrackrefs = NumberOfTrackRefs(event);
499 for ( Int_t i = 0; i < ntrackrefs; ++i )
502 if ( fTrackRefs != 0x0 )
504 fTrackRefs->Print("","*");
509 //_____________________________________________________________________________
511 AliMUONMCDataInterface::DumpTrigger(Int_t event)
513 /// Dump trigger for a given event (trigger is read from TreeD)
517 if ( fTriggerStore != 0x0 )
519 fTriggerStore->Print();
523 //_____________________________________________________________________________
525 AliMUONMCDataInterface::LoadEvent(Int_t event)
527 /// Load event if different from the current one.
528 /// Returns kFALSE on error and kTRUE if the event was loaded.
532 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
533 if (fLoader->GetRunLoader()->GetEvent(event) == 0)
535 fCurrentEvent = event;
543 //_____________________________________________________________________________
545 AliMUONMCDataInterface::NumberOfEvents() const
547 /// Number of events in the file we're connected to
548 if (not IsValid()) return -1;
549 return fLoader->GetRunLoader()->GetNumberOfEvents();
552 //_____________________________________________________________________________
554 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
556 /// Number of tracks in the event
557 if ( not IsValid()) return -1;
559 if (event != fCurrentEvent)
562 if ( not LoadEvent(event) ) return -1;
569 TTree* treeH = fLoader->TreeH();
572 rv = static_cast<Int_t>(treeH->GetEntries());
576 AliError("Could not get TreeH");
579 fLoader->UnloadHits();
584 //_____________________________________________________________________________
586 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
588 /// Number of track references in the event
589 if ( not IsValid()) return -1;
591 if (event != fCurrentEvent)
594 if ( not LoadEvent(event) ) return -1;
597 fLoader->GetRunLoader()->LoadTrackRefs();
601 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
604 rv = static_cast<Int_t>(treeTR->GetEntries());
608 AliError("Could not get TreeTR");
611 fLoader->GetRunLoader()->UnloadTrackRefs();
616 //_____________________________________________________________________________
618 AliMUONMCDataInterface::Open(const char* filename)
620 /// Connect to a given galice.root file
626 if ( fLoader != 0x0 )
628 delete fLoader->GetRunLoader();
635 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
637 while (AliRunLoader::GetRunLoader(foldername))
639 delete AliRunLoader::GetRunLoader(foldername);
642 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
643 if (runLoader == 0x0)
645 AliError(Form("Cannot open file %s",filename));
650 // Get run number and set it to CDB manager
651 runLoader->LoadHeader();
652 if ( ! runLoader->GetHeader() ) {
653 AliError("Cannot load header.");
657 Int_t runNumber = runLoader->GetHeader()->GetRun();
658 AliCDBManager::Instance()->SetRun(runNumber);
660 runLoader->UnloadHeader();
662 fLoader = runLoader->GetDetectorLoader("MUON");
665 AliError("Cannot get AliMUONLoader");
671 AliError(Form("Could not access %s filename. Object is unuseable",filename));
675 //_____________________________________________________________________________
676 Bool_t AliMUONMCDataInterface::GetEvent(Int_t event)
678 /// Loads all simulated data for the given event.
680 if (HitStore(event, 0) == 0x0) return kFALSE;
681 if (SDigitStore(event) == 0x0) return kFALSE;
682 if (DigitStore(event) == 0x0) return kFALSE;
683 if (TriggerStore(event) == 0x0) return kFALSE;
684 if (TrackRefs(event, 0) == 0x0) return kFALSE;
688 //_____________________________________________________________________________
689 Int_t AliMUONMCDataInterface::NumberOfParticles()
691 /// Returns the total number of particles in the kinematics tree.
693 AliStack* stack = Stack(fCurrentEvent);
694 if ( stack == 0x0 ) return -1;
695 return (Int_t) stack->GetNtrack();
698 //_____________________________________________________________________________
699 TParticle* AliMUONMCDataInterface::Particle(Int_t index)
701 /// Returns the index'th particle in the kinematics tree.
702 /// @param index The index number of the particle in the range [0 ... N-1]
703 /// where N = NumberOfParticles()
705 AliStack* stack = Stack(fCurrentEvent);
706 if ( stack == 0x0 ) return 0x0;
707 return static_cast<TParticle*>( stack->Particle(index) );
710 //_____________________________________________________________________________
711 Int_t AliMUONMCDataInterface::NumberOfTracks()
713 /// Returns the number of primary tracks (from primary particles) in the current event.
715 return NumberOfTracks(fCurrentEvent);
718 //_____________________________________________________________________________
719 Int_t AliMUONMCDataInterface::NumberOfHits(Int_t track)
721 /// Returns the number of hits for a given primary track/particle.
722 /// @param track The track number in the range [0 .. N-1]
723 /// where N = NumberOfTracks()
725 TIterator* iter = GetIterator(kHitIterator, track);
726 return CountObjects(iter);
729 //_____________________________________________________________________________
731 AliMUONMCDataInterface::Hit(Int_t track, Int_t index)
733 /// Returns a pointer to the index'th hit object.
734 /// @param track The track number in the range [0 .. N-1]
735 /// where N = NumberOfTracks()
736 /// @param index The index number of the hit in the range [0 ... M-1]
737 /// where M = NumberOfHits(track)
739 TIterator* iter = GetIterator(kHitIterator, track);
740 return static_cast<AliMUONHit*>( FetchObject(iter, index) );
743 //_____________________________________________________________________________
744 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t detElemId)
746 /// Returns the number of summable digits to be found on a given detector element.
747 /// @param detElemId The detector element ID number to search on.
749 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
750 return CountObjects(iter);
753 //_____________________________________________________________________________
754 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t detElemId, Int_t index)
756 /// Returns the a pointer to the index'th summable digit on the specified detector element.
757 /// @param detElemId The detector element ID number to search on.
758 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
759 /// where N = NumberOfDigits(detElemId)
761 TIterator* iter = GetIterator(kSDigitIteratorByDetectorElement, detElemId);
762 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
765 //_____________________________________________________________________________
766 Int_t AliMUONMCDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
768 /// Returns the number of summable digits to be found on a specific chamber and cathode.
769 /// @param chamber The chamber number in the range [0 .. 13].
770 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
771 /// 1 is the non-bending plane.
773 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
774 return CountObjects(iter);
777 //_____________________________________________________________________________
778 AliMUONVDigit* AliMUONMCDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t index)
780 /// Returns the a pointer to the index'th summable digit on the specified chamber and cathode.
781 /// @param chamber The chamber number in the range [0 .. 13].
782 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
783 /// 1 is the non-bending plane.
784 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
785 /// where N = NumberOfDigits(chamber, cathode)
787 TIterator* iter = GetIterator(kSDigitIteratorByChamberAndCathode, chamber, cathode);
788 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
791 //_____________________________________________________________________________
792 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t detElemId)
794 /// Returns the number of simulated digits to be found on a given detector element.
795 /// @param detElemId The detector element ID number to search on.
797 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
798 return CountObjects(iter);
801 //_____________________________________________________________________________
802 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t detElemId, Int_t index)
804 /// Returns the a pointer to the index'th simulated digit on the specified detector element.
805 /// @param detElemId The detector element ID number to search on.
806 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
807 /// where N = NumberOfDigits(detElemId)
809 TIterator* iter = GetIterator(kDigitIteratorByDetectorElement, detElemId);
810 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
813 //_____________________________________________________________________________
814 Int_t AliMUONMCDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
816 /// Returns the number of simulated digits to be found on a specific chamber and cathode.
817 /// @param chamber The chamber number in the range [0 .. 13].
818 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
819 /// 1 is the non-bending plane.
821 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
822 return CountObjects(iter);
825 //_____________________________________________________________________________
826 AliMUONVDigit* AliMUONMCDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t index)
828 /// Returns the a pointer to the index'th simulated digit on the specified chamber and cathode.
829 /// @param chamber The chamber number in the range [0 .. 13].
830 /// @param cathode The cathode in the range [0 .. 1], where 0 is the bending and
831 /// 1 is the non-bending plane.
832 /// @param index The index number of the digit to fetch in the range [0 .. N-1],
833 /// where N = NumberOfDigits(chamber, cathode)
835 TIterator* iter = GetIterator(kDigitIteratorByChamberAndCathode, chamber, cathode);
836 return static_cast<AliMUONVDigit*>( FetchObject(iter, index) );
839 //_____________________________________________________________________________
840 Int_t AliMUONMCDataInterface::NumberOfLocalTriggers()
842 /// Returns the number of simulated local trigger objects.
844 TIterator* iter = GetIterator(kLocalTriggerIterator);
845 return CountObjects(iter);
848 //_____________________________________________________________________________
849 AliMUONLocalTrigger* AliMUONMCDataInterface::LocalTrigger(Int_t index)
851 /// Returns a pointer to the index'th simulated local trigger object.
852 /// @param index The index number of the local trigger object to fetch in the range [0 .. N-1],
853 /// where N = NumberOfLocalTriggers()
855 TIterator* iter = GetIterator(kLocalTriggerIterator);
856 return static_cast<AliMUONLocalTrigger*>( FetchObject(iter, index) );
859 //_____________________________________________________________________________
860 Int_t AliMUONMCDataInterface::NumberOfRegionalTriggers()
862 /// Returns the number of simulated regional trigger objects.
864 TIterator* iter = GetIterator(kRegionalTriggerIterator);
865 return CountObjects(iter);
868 //_____________________________________________________________________________
869 AliMUONRegionalTrigger* AliMUONMCDataInterface::RegionalTrigger(Int_t index)
871 /// Returns a pointer to the index'th simulated regional trigger object.
872 /// @param index The index number of the regional trigger object to fetch in the range [0 .. N-1],
873 /// where N = NumberOfRegionalTriggers()
875 TIterator* iter = GetIterator(kRegionalTriggerIterator);
876 return static_cast<AliMUONRegionalTrigger*>( FetchObject(iter, index) );
879 //_____________________________________________________________________________
880 AliMUONGlobalTrigger* AliMUONMCDataInterface::GlobalTrigger()
882 /// Returns a pointer to the simulated global trigger object for the event.
884 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
885 if (store == 0x0) return 0x0;
886 return store->Global();
889 //_____________________________________________________________________________
890 Int_t AliMUONMCDataInterface::NumberOfTrackRefs()
892 /// Number of track references in the currently selected event.
894 return NumberOfTrackRefs(fCurrentEvent);
897 //_____________________________________________________________________________
898 TClonesArray* AliMUONMCDataInterface::TrackRefs(Int_t track)
900 /// Returns the track references for a given track in the current event.
901 /// @param track The track to returns track references for. In the range [0 .. N-1]
902 /// where N = NumberOfTrackRefs()
904 return TrackRefs(fCurrentEvent, track);
907 //_____________________________________________________________________________
908 void AliMUONMCDataInterface::ResetStores()
910 /// Deletes all the store objects that have been created and resets the pointers to 0x0.
911 /// The temporary iterator object is automatically reset. See ResetIterator for more details.
914 if (fHitStore != 0x0)
919 if (fSDigitStore != 0x0)
924 if (fDigitStore != 0x0)
929 if (fTrackRefs != 0x0)
934 if (fTriggerStore != 0x0)
936 delete fTriggerStore;
941 //_____________________________________________________________________________
942 TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y)
944 /// Creates an appropriate iterator object and returns it.
945 /// If the iterator has already been created then that one is returned otherwise
946 /// a new object is created.
947 /// Depending on the value of 'type' the semantics of parameters x and y can change.
948 /// @param type The type of iterator to create.
949 /// @param x This is the detector element ID if type equals kDigitIteratorByDetectorElement
950 /// or kSDigitIteratorByDetectorElement.
951 /// If type equals kDigitIteratorByChamberAndCathode or
952 /// kSDigitIteratorByChamberAndCathode then this is the chamber number.
953 /// For type == kHitIterator the parameter x is the track number.
954 /// In all other cases this parameter is ignored.
955 /// @param y If type equals kDigitIteratorByChamberAndCathode or
956 /// kSDigitIteratorByChamberAndCathode then this parameter is the cathode
957 /// number. In all other cases this parameter is ignored.
959 if (type == fCurrentIteratorType and fDataX == x and fDataY == y)
962 if (fCurrentEvent == -1)
964 AliError("No event was selected. Try first using GetEvent().");
975 AliMUONVHitStore* store = HitStore(fCurrentEvent, track);
976 if (store == 0x0) return 0x0;
977 fIterator = store->CreateIterator();
978 if (fIterator == 0x0) return 0x0;
979 fCurrentIteratorType = kHitIterator;
983 case kSDigitIteratorByDetectorElement:
986 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
987 if (store == 0x0) return 0x0;
988 fIterator = store->CreateIterator(detElem, detElem, 2);
989 if (fIterator == 0x0) return 0x0;
990 fCurrentIteratorType = kSDigitIteratorByDetectorElement;
995 case kSDigitIteratorByChamberAndCathode:
999 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1002 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1003 AliMpConstants::NofChambers() - 1,
1008 if (cathode < 0 or 1 < cathode)
1010 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1014 AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
1015 if (store == 0x0) return 0x0;
1016 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1017 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1018 if (fIterator == 0x0) return 0x0;
1019 fCurrentIteratorType = kSDigitIteratorByChamberAndCathode;
1025 case kDigitIteratorByDetectorElement:
1028 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1029 if (store == 0x0) return 0x0;
1030 fIterator = store->CreateIterator(detElem, detElem, 2);
1031 if (fIterator == 0x0) return 0x0;
1032 fCurrentIteratorType = kDigitIteratorByDetectorElement;
1037 case kDigitIteratorByChamberAndCathode:
1041 if (chamber < 0 or AliMpConstants::NofChambers() <= chamber)
1044 "Must have give a chamber value in the range [0..%d], but got a value of: %d",
1045 AliMpConstants::NofChambers() - 1,
1050 if (cathode < 0 or 1 < cathode)
1052 AliError(Form("Must have give a cathode value in the range [0..1], but got a value of: %d", cathode));
1056 AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
1057 if (store == 0x0) return 0x0;
1058 MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
1059 fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
1060 if (fIterator == 0x0) return 0x0;
1061 fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
1067 case kLocalTriggerIterator:
1069 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1070 if (store == 0x0) return 0x0;
1071 fIterator = store->CreateLocalIterator();
1072 if (fIterator == 0x0) return 0x0;
1073 fCurrentIteratorType = kLocalTriggerIterator;
1077 case kRegionalTriggerIterator:
1079 AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
1080 if (store == 0x0) return 0x0;
1081 fIterator = store->CreateRegionalIterator();
1082 if (fIterator == 0x0) return 0x0;
1083 fCurrentIteratorType = kRegionalTriggerIterator;
1092 //_____________________________________________________________________________
1093 void AliMUONMCDataInterface::ResetIterator()
1095 /// The temporary iterator object is deleted if it exists and the pointer reset to 0x0.
1096 /// The iterator type and temporary data indicating the state of the iterator are
1099 if (fIterator != 0x0) delete fIterator;
1100 fCurrentIteratorType = kNoIterator;
1101 fCurrentIndex = fDataX = fDataY = -1;
1105 //_____________________________________________________________________________
1106 Int_t AliMUONMCDataInterface::CountObjects(TIterator* iter)
1108 /// Counts the number of objects in the iterator and resets it.
1109 /// @return The number of objects in 'iter'.
1111 if (iter == 0x0) return -1;
1114 while ( iter->Next() != 0x0 ) count++;
1120 //_____________________________________________________________________________
1121 TObject* AliMUONMCDataInterface::FetchObject(TIterator* iter, Int_t index)
1123 /// Fetches the index'th object from the iterator counting the first object
1124 /// returned by iterator after it is reset as index == 0. The next object
1125 /// has index == 1 and so on where the last object returned by the iterator
1126 /// has index == N-1 where N = CountObjects(iter)
1127 /// This method will only reset the iterator if index is smaller than
1128 /// fCurrentIndex, which is used to track the iteration progress and is
1129 /// updated when a new object if returned by this method.
1130 /// @param iter The iterator to fetch an object from.
1131 /// @param index The index number of the object to fetch in the range [0 .. N-1]
1132 /// where N = CountObjects(iter)
1136 AliError(Form("Index is out of bounds. Got a value of %d.", index));
1140 if (iter == 0x0) return 0x0;
1141 if (index <= fCurrentIndex)
1147 TObject* object = 0x0;
1148 while (fCurrentIndex < index)
1150 object = iter->Next();
1153 AliError(Form("Index is out of bounds. Got a value of %d.", index));