+
+ Bool_t result = GetEvent(entry);
+
+ if (fSubsidiaryHandlers) {
+ TIter next(fSubsidiaryHandlers);
+ AliMCEventHandler *handler;
+ while((handler = (AliMCEventHandler*)next())) {
+ handler->BeginEvent(entry);
+ }
+ next.Reset();
+ while((handler = (AliMCEventHandler*)next())) {
+ fMCEvent->AddSubsidiaryEvent(handler->MCEvent());
+ }
+ fMCEvent->InitEvent();
+ }
+
+ if (fPreReadMode == kLmPreRead) {
+ fMCEvent->PreReadAll();
+ }
+
+ return result;
+
+}
+
+void AliMCEventHandler::SelectParticle(Int_t i){
+ // taking the absolute values here, need to take care
+ // of negative daughter and mother
+ // IDs when setting!
+ if (TMath::Abs(i) >= AliMCEvent::BgLabelOffset()) i = fMCEvent->BgLabelToIndex(TMath::Abs(i));
+ if(!IsParticleSelected(TMath::Abs(i)))fParticleSelected.Add(TMath::Abs(i),1);
+}
+
+Bool_t AliMCEventHandler::IsParticleSelected(Int_t i) {
+ // taking the absolute values here, need to take
+ // care with negative daughter and mother
+ // IDs when setting!
+ return (fParticleSelected.GetValue(TMath::Abs(i))==1);
+}
+
+
+void AliMCEventHandler::CreateLabelMap(){
+
+ //
+ // this should be called once all selections where done
+ //
+
+ fLabelMap.Delete();
+ if(!fMCEvent){
+ fParticleSelected.Delete();
+ return;
+ }
+
+ VerifySelectedParticles();
+
+ Int_t iNew = 0;
+ for(int i = 0;i < fMCEvent->GetNumberOfTracks();++i){
+ if(IsParticleSelected(i)){
+ fLabelMap.Add(i,iNew);
+ iNew++;
+ }
+ }
+}
+
+Int_t AliMCEventHandler::GetNewLabel(Int_t i) {
+ // Gets the label from the new created Map
+ // Call CreatLabelMap before
+ // otherwise only 0 returned
+ return fLabelMap.GetValue(TMath::Abs(i));
+}
+
+void AliMCEventHandler::VerifySelectedParticles(){
+
+ //
+ // Make sure that each particle has at least it's predecessors
+ // selected so that we have the complete ancestry tree
+ // Private, should be only called by CreateLabelMap
+
+ if(!fMCEvent){
+ fParticleSelected.Delete();
+ return;
+ }
+
+ Int_t nprim = fMCEvent->GetNumberOfPrimaries();
+
+ for(int i = 0;i < fMCEvent->GetNumberOfTracks(); ++i){
+ if(i < nprim){
+ SelectParticle(i);// take all primaries
+ continue;
+ }
+
+ if(!IsParticleSelected(i))continue;
+
+ AliMCParticle* mcpart = (AliMCParticle*) fMCEvent->GetTrack(i);
+ Int_t imo = mcpart->GetMother();
+ while((imo >= nprim)&&!IsParticleSelected(imo)){
+ // Mother not yet selected
+ SelectParticle(imo);
+ mcpart = (AliMCParticle*) fMCEvent->GetTrack(imo);
+ imo = mcpart->GetMother();
+ }
+ // after last step we may have an unselected primary
+ // mother
+ if(imo>=0){
+ if(!IsParticleSelected(imo))
+ SelectParticle(imo);
+ }
+ }// loop over all tracks