AliGenEventHeader* gh=(AliGenEventHeader*)lh->At(i);
TString genname=gh->GetName();
Int_t npart=gh->NProduced();
- if(index>=nsumpart && index<(nsumpart+npart)) return genname;
- nsumpart+=npart;
+ if (i == 0) npart = nsumpart;
+ if(index < nsumpart && index >= (nsumpart-npart)) return genname;
+ nsumpart-=npart;
+ }
+ TString empty="";
+ return empty;
+}
+
+void AliMCEvent::AssignGeneratorIndex() {
+ //
+ // Assign the generator index to each particle
+ //
+ TList* list = GetCocktailList();
+ if (fNprimaries <= 0) {
+ AliWarning(Form("AliMCEvent::AssignGeneratorIndex: no primaries %10d\n", fNprimaries));
+ return;
+}
+ if (!list) {
+ return;
+ } else {
+ Int_t nh = list->GetEntries();
+ Int_t nsumpart = fNprimaries;
+ for(Int_t i = nh-1; i >= 0; i--){
+ AliGenEventHeader* gh = (AliGenEventHeader*)list->At(i);
+ Int_t npart = gh->NProduced();
+ if (i==0) {
+ if (npart != nsumpart) {
+ // printf("Header inconsistent ! %5d %5d \n", npart, nsumpart);
+ }
+ npart = nsumpart;
+ }
+ //
+ // Loop over primary particles for generator i
+ for (Int_t j = nsumpart-1; j >= nsumpart-npart; j--) {
+ AliVParticle* part = GetTrack(j);
+ if (!part) {
+ AliWarning(Form("AliMCEvent::AssignGeneratorIndex: 0-pointer to particle j %8d npart %8d nsumpart %8d Nprimaries %8d\n",
+ j, npart, nsumpart, fNprimaries));
+ break;
+ }
+ part->SetGeneratorIndex(i);
+ Int_t dmin = part->GetFirstDaughter();
+ Int_t dmax = part->GetLastDaughter();
+ if (dmin == -1) continue;
+ AssignGeneratorIndex(i, dmin, dmax);
+ }
+ nsumpart -= npart;
}
- TString empty="";
- return empty;
-
+ }
+}
+void AliMCEvent::AssignGeneratorIndex(Int_t index, Int_t dmin, Int_t dmax) {
+ for (Int_t k = dmin; k <= dmax; k++) {
+ AliVParticle* dpart = GetTrack(k);
+ dpart->SetGeneratorIndex(index);
+ Int_t d1 = dpart->GetFirstDaughter();
+ Int_t d2 = dpart->GetLastDaughter();
+ if (d1 > -1) {
+ AssignGeneratorIndex(index, d1, d2);
+ }
+ }
}
-Bool_t AliMCEvent::GetCocktailGenerator(Int_t index,TString &nameGen){
- //method that gives the generator for a given particle with label index (or that of the corresponding primary)
- nameGen=GetGenerator(index);
- if(nameGen.Contains("nococktailheader") )return 0;
+ Bool_t AliMCEvent::GetCocktailGenerator(Int_t index,TString &nameGen){
+ //method that gives the generator for a given particle with label index (or that of the corresponding primary)
+ AliVParticle* mcpart0 = (AliVParticle*) (GetTrack(index));
+ if(!mcpart0){
+ printf("AliMCEvent-BREAK: No valid AliMCParticle at label %i\n",index);
+ return 0;
+ }
+ /*
+ Int_t ig = mcpart0->GetGeneratorIndex();
+ if (ig != -1) {
+ nameGen = ((AliGenEventHeader*)GetCocktailList()->At(ig))->GetName();
+ return 1;
+ }
+ */
+ nameGen=GetGenerator(index);
+ if(nameGen.Contains("nococktailheader") )return 0;
+ Int_t lab=index;
+
+ while(nameGen.IsWhitespace()){
+
+
+ AliVParticle* mcpart = (AliVParticle*) (GetTrack(lab));
+
+ if(!mcpart){
+ printf("AliMCEvent-BREAK: No valid AliMCParticle at label %i\n",lab);
+ break;}
+ Int_t mother=0;
+ mother = mcpart->GetMother();
+ while(nameGen.IsWhitespace()){
+
+ AliMCParticle* mcpart = (AliMCParticle*) (GetTrack(index));
+
+ if(!mcpart){
+ printf("AliMCEvent-BREAK: No valid AliMCParticle at label %i\n",index);
+ break;
+ }
+ Int_t mother = mcpart->GetMother();
if(mother<0){
printf("AliMCEvent - BREAK: Reached primary particle without valid mother\n");
break;
}
return 1;
- }
+ }
-AliVEvent::EDataLayoutType AliMCEvent::GetDataLayoutType() const {return AliVEvent::kMC;}
+void AliMCEvent::SetParticleArray(TClonesArray* mcParticles)
+ {
+ fMCParticles = mcParticles;
+ fNparticles = fMCParticles->GetEntries();
+ fExternal = kTRUE;
+ fNprimaries = 0;
+ struct Local {
+ static Int_t binaryfirst(TClonesArray* a, Int_t low, Int_t high)
+ {
+ Int_t mid = low + (high - low)/2;
+ if (low > a->GetEntries()-1) return (a->GetEntries()-1);
+ if (!((AliVParticle*) a->At(mid))->IsPrimary()) {
+ if (mid > 1 && !((AliVParticle*) a->At(mid-1))->IsPrimary()) {
+ return binaryfirst(a, low, mid-1);
+ } else {
+ return mid;
+ }
+ } else {
+ return binaryfirst(a, mid+1, high);
+ }
+ }
+ };
+ fNprimaries = Local::binaryfirst(mcParticles, 0, mcParticles->GetEntries()-1);
+ AssignGeneratorIndex();
+ }
+
ClassImp(AliMCEvent)