8 #include <TClonesArray.h>
11 #include "AliJFMixEvent.h"
13 AliJFMixEvent::AliJFMixEvent(Char_t *file1, Char_t *file2) :
14 fStatus(-1),fEvent1(-1),fEvent2(-1),fMaxEvent1(-1),fMaxEvent2(-1),
15 fMarkPythia(0),fTree1(0),fTree2(0),fFile1(0),
16 fFile2(0),fBranch1(0),fBranch2(0),
17 fParticles1(0),fParticles2(0),fMixedParticles(0)
22 AliJFMixEvent::AliJFMixEvent(Char_t *files1, Char_t *tname1, Char_t *files2=0, Char_t *tname2=0) :
23 fStatus(-1),fEvent1(-1),fEvent2(-1),fMaxEvent1(-1),fMaxEvent2(-1),
24 fMarkPythia(0),fTree1(0),fTree2(0),fFile1(0),
25 fFile2(0),fBranch1(0),fBranch2(0),
26 fParticles1(0),fParticles2(0),fMixedParticles(0)
28 InitChains(files1,tname1,files2,tname2);
31 AliJFMixEvent::~AliJFMixEvent()
36 void AliJFMixEvent::Init(Char_t *file1, Char_t *file2)
41 cerr << "Error AliJFMixEvent:: Must give at least one filename!" << endl;
46 fFile1 = new TFile(file1,"READ");
47 if (!fFile1 || !(fFile1->IsOpen())) {
48 cerr << "Error AliJFMixEvent:: Couldn't open input file " << file1 << endl;
54 fFile2 = new TFile(file2,"READ");
55 if (!fFile2 || !(fFile2->IsOpen())) {
56 cerr << "Error AliJFMixEvent:: Couldn't open input file " << file2 << endl;
61 Int_t prealloc1=100000;
63 fTree1 = (TTree *)fFile1->Get("hijing");
65 fTree1 = (TTree *)fFile1->Get("pythia");
69 cerr << "Error AliJFMixEvent:: Didn't find a TParticle tree for " << file1 << endl;
72 fMaxEvent1=(Int_t)fTree1->GetEntries();
78 fTree2 = (TTree *)fFile2->Get("hijing");
80 fTree2 = (TTree *)fFile2->Get("pythia");
84 cerr << "Error AliJFMixEvent:: Didn't find a TParticle tree for " << file2 << endl;
87 fMaxEvent2=(Int_t)fTree2->GetEntries();
90 fParticles1=new TClonesArray("TParticle",prealloc1);
91 if(file2!=0) fParticles2=new TClonesArray("TParticle",prealloc2);
92 fMixedParticles=new TClonesArray("TParticle",prealloc1+prealloc2);
94 fBranch1=fTree1->GetBranch("particles");
95 fBranch1->SetAddress(&fParticles1);
98 fBranch2=fTree2->GetBranch("particles");
99 fBranch2->SetAddress(&fParticles2);
105 void AliJFMixEvent::InitChains(Char_t *files1, Char_t *tname1, Char_t *files2, Char_t *tname2)
109 if (!files1 || !tname1) {
110 cerr << "Error AliJFMixEvent:: Must give at least one file/tree name!" << endl;
114 Int_t prealloc1=100000;
117 fTree1=new TChain(tname1);
118 ((TChain*)fTree1)->Add(files1);
119 fParticles1=new TClonesArray("TParticle",prealloc1);
120 fTree1->SetBranchAddress("particles",&fParticles1);
121 fMaxEvent1=(Int_t)fTree1->GetEntries();
123 if (files2 && tname2) {
125 fTree2=new TChain(tname2);
126 ((TChain*)fTree2)->Add(files2);
127 fParticles2=new TClonesArray("TParticle",prealloc2);
128 fTree2->SetBranchAddress("particles",&fParticles2);
129 fMaxEvent2=(Int_t)fTree2->GetEntries();
132 fMixedParticles=new TClonesArray("TParticle",prealloc1+prealloc2);
136 void AliJFMixEvent::Clean()
138 fStatus=-1; //not initialized!
145 if(fParticles1) delete fParticles1;
148 if(fParticles2) delete fParticles2;
151 if(fMixedParticles) delete fMixedParticles;
152 fMixedParticles=NULL;
154 if(fTree1) delete fTree1;
157 if(fTree2) delete fTree2;
160 if(fFile1) delete fFile1;
163 if(fFile2) delete fFile2;
167 Int_t AliJFMixEvent::CreateMixedEvent(Int_t i,Int_t j)
169 if(fStatus<0) return -1;
170 if(i<0 || j<0) return -1;
171 if((i>=fMaxEvent1)||((fTree2)&&(j>=fMaxEvent2))) return -1;
187 Int_t AliJFMixEvent::CreateNextMixedEvent()
189 if(fStatus<0) return -1;
191 if(fStatus==0) { //load first data samples
195 if(fTree2) fTree2->GetEvent(0);
196 } else { //continue loading
198 if(fEvent1==fMaxEvent1){
203 if(fEvent2==fMaxEvent2)
205 fTree2->GetEvent(fEvent2);
209 fTree1->GetEvent(fEvent1);
215 Int_t AliJFMixEvent::MixEvent()
217 Int_t n1=fParticles1->GetEntries();
219 if(fTree2) n2=fParticles2->GetEntries();
221 fMixedParticles->ExpandCreateFast(n1+n2);
224 TIterator *i=fParticles1->MakeIterator();
225 while ((particle = (TParticle *) i->Next()) != NULL) {
227 particle->SetWeight(-123); //mark pythia particles
229 new ((*fMixedParticles)[n]) TParticle(*particle);
233 i=fParticles2->MakeIterator();
234 while ((particle = (TParticle *) i->Next()) != NULL) {
235 new((*fMixedParticles)[n]) TParticle(*particle);
244 void AliJFMixEvent::Debug()
246 if(!fMixedParticles) return;
249 TIterator *iter=fMixedParticles->MakeIterator();
250 while ((p = (TParticle *) iter->Next()) != NULL) {