+ if (fIsStandard) fAODEvent->CreateStdContent();
+ }
+ //
+ // File opening according to execution mode
+ TString option(opt);
+ option.ToLower();
+ if (option.Contains("proof")) {
+ // proof
+ if (option.Contains("special")) {
+ // File for tree already opened on slave -> merging via files
+ fFileA = gFile;
+ CreateTree(1);
+ } else {
+ // Merging in memory
+ CreateTree(0);
+ }
+ } else {
+ // local and grid
+ TDirectory *owd = gDirectory;
+ fFileA = new TFile(fFileName.Data(), "RECREATE");
+ CreateTree(1);
+ owd->cd();
+ }
+ return kTRUE;
+}
+
+
+void AliAODHandler::StoreMCParticles(){
+
+ //
+ // Remap the labels from ESD stack and store
+ // the AODMCParticles, makes only sense if we have
+ // the mcparticles branch
+ // has to be done here since we cannot know in advance
+ // which particles are needed (e.g. by the tracks etc.)
+ //
+ // Particles have been selected by AliMCEventhanlder->SelectParticle()
+ // To use the MCEventhandler here we need to set it from the outside
+ // can vanish when Handler go to the ANALYSISalice library
+
+ TClonesArray *mcarray = (TClonesArray*)fAODEvent->FindListObject(AliAODMCParticle::StdBranchName());
+ if(!mcarray)return;
+ mcarray->Delete();
+
+ // Get the MC Infos.. Handler needs to be set before
+ // while adding the branch
+ // This needs to be done, not to depend on the AnalysisManager
+
+ if(!fMCEventH)return;
+ if(!fMCEventH->MCEvent())return;
+ AliStack *pStack = fMCEventH->MCEvent()->Stack();
+ if(!pStack)return;
+
+ fMCEventH->CreateLabelMap();
+
+ // First store the AliAODParticlesMC
+
+ Int_t np = pStack->GetNtrack();
+ Int_t nprim = pStack->GetNprimary();
+
+
+ Int_t j = 0;
+ TClonesArray& l = *mcarray;
+
+ for(int i = 0;i < np;++i){
+ if(fMCEventH->IsParticleSelected(i)){
+
+ Int_t flag = 0;
+ TParticle *part = pStack->Particle(i);
+ if(i<nprim)flag |= AliAODMCParticle::kPrimary;
+ if(pStack->IsPhysicalPrimary(i))flag |= AliAODMCParticle::kPhysicalPrim;
+
+ if(fMCEventH->GetNewLabel(i)!=j){
+ AliError(Form("MISMATCH New label %d j: %d",fMCEventH->GetNewLabel(i),j));
+ }
+ AliAODMCParticle mcpart_tmp(part,i,flag);
+
+ //
+ Int_t d0 = mcpart_tmp.GetDaughter(0);
+ Int_t d1 = mcpart_tmp.GetDaughter(1);
+ Int_t m = mcpart_tmp.GetMother();
+
+ // other than for the track labels, negative values mean
+ // no daughter/mother so preserve it
+
+ if(d0<0 && d1<0){
+ // no first daughter -> no second daughter
+ // nothing to be done
+ // second condition not needed just for sanity check at the end
+ mcpart_tmp.SetDaughter(0,d0);
+ mcpart_tmp.SetDaughter(1,d1);
+ }
+ else if(d1 < 0 && d0 >= 0){
+ // Only one daughter
+ // second condition not needed just for sanity check at the end
+ if(fMCEventH->IsParticleSelected(d0)){
+ mcpart_tmp.SetDaughter(0,fMCEventH->GetNewLabel(d0));
+ }
+ else{
+ mcpart_tmp.SetDaughter(0,-1);
+ }
+ mcpart_tmp.SetDaughter(1,d1);
+ }
+ else if (d0 > 0 && d1 > 0 ){
+ // we have two or more daughters loop on the stack to see if they are
+ // selected
+ Int_t d0_tmp = -1;
+ Int_t d1_tmp = -1;
+ for(int id = d0; id<=d1;++id){
+ if(fMCEventH->IsParticleSelected(id)){
+ if(d0_tmp==-1){
+ // first time
+ d0_tmp = fMCEventH->GetNewLabel(id);
+ d1_tmp = d0_tmp; // this is to have the same schema as on the stack i.e. with one daugther d0 and d1 are the same
+ }
+ else d1_tmp = fMCEventH->GetNewLabel(id);
+ }
+ }
+ mcpart_tmp.SetDaughter(0,d0_tmp);
+ mcpart_tmp.SetDaughter(1,d1_tmp);
+ }
+ else{
+ AliError(Form("Unxpected indices %d %d",d0,d1));
+ }
+
+ if(m<0){
+ mcpart_tmp.SetMother(m);
+ }
+ else{
+ if(fMCEventH->IsParticleSelected(m))mcpart_tmp.SetMother(fMCEventH->GetNewLabel(m));
+ else AliError("PROBLEM Mother not selected");
+ }
+
+ new (l[j++]) AliAODMCParticle(mcpart_tmp);
+