PDE/PDT access for Pythia8 events loaded from TTree

Hi,

I’m saving Pythia8 events to a TTree according to the example in the Pythia8 distribution, which seems to work fine. When loading them from the file though, I get the standard event data, but not the extra information such as the name string or the charge. I understand these aren’t saved to the file since one just needs a pointer to the ParticleDataEntry/Table to access them, which sounds logical, but I can’t figure out how to restore this pointer for the saved events when I load them. I tried calling event.restorePtrs(), but I keep getting “” for the name and 0 for the charge.

I understand this is partly a Pythia8 problem, but since it appears when writing/loading a TTree, I hope someone around here might be able to help me. Below some code snippets so you might be able to follow the case.

Saving the events in test01 main:

Pythia pythia;

Event& event = pythia.event;
Event *event_forTree = &event;	
Info& info = pythia.info;
Info *info_forTree = &info;

TTree *t1 = new TTree("t1","tree of pythia8 events");
TBranch *b_event = t1->Branch("pythia8Event",&event_forTree);
TBranch *b_info = t1->Branch("pythia8Info",&info_forTree);

...

for (int i = 0; i < event.size(); ++i) if (event[i].isFinal()) {
	...
	t1->Fill();
}

Compiling including Dict:

test01 test02: \
	rootcint -f pythiaTreeDict.cc -c -I$(PYTHIA8)/include pythiaROOT.h pythiaLinkdef.h
	@mkdir -p $(BINDIR)
	$(CXX) $(CXXFLAGS) -I$(PYTHIA8LOCATION)/$(INCDIR) -I`root-config --incdir` \
	pythiaTreeDict.cc $@.cc -Wno-long-long -Wno-unused \
	-o $(BINDIR)/$@.exe \
	-L$(PYTHIA8LOCATION)/$(LIBDIRARCH) $(LIBGZIP) -lpythia8 -llhapdfdummy \
	`root-config --libs` 
	@ln -fs $(BINDIR)/$@.exe $@.exe

Loading the events later on in test02 main:

TFile *f1 = new TFile(argv[1],"READ");
TTree *t1 = (TTree*)f1->Get("t1");

TBranch *b_event = (TBranch*)t1->GetBranch("pythia8Event");
Event *event = new Event();
Event& eventCopy = *event;
b_event->SetAddress(&event);

TBranch *b_info = (TBranch*)t1->GetBranch("pythia8Info");
Info *info = new Info();
Info& infoCopy = *info;
b_info->SetAddress(&info);	

Int_t nEntries = t1->GetEntries();

for(Int_t i=0; i<nEntries; ++i) {
	t1->GetEvent(i);
	eventCopy = *event;
	infoCopy = *info;
	eventCopy.restorePtrs(); // <---- doesn't change anything as far as I can see

	...
}

If then in the event loop I print the info of the first Final particle, the ParticleDataEntry/Table pointer doesn’t seem to be working:

cout << endl << "name:" << eventCopy[j].name() << endl;
cout << "id:" << eventCopy[j].id() << endl;
cout << "px:" << eventCopy[j].px() << endl;
cout << "m:" << eventCopy[j].m() << endl;
cout << "e:" << eventCopy[j].e() << endl;
cout << "charge:" << eventCopy[j].charge() << endl;

In the original event loop (stdout):

name:pi-
id:-211
px:-0.183
m:0.140
e:1.843
charge:-1.000

In the loop where I load the events (stdout):

name:  
id:-211
px:-0.183166
m:0.13957
e:1.84302
charge:0

Hi,

What is you intent in using the syntax:Event *event = new Event(); Event& eventCopy = *event; .... eventCopy = *event; .... eventCopy.restorePtrs(); // <---- doesn't change anything as far as I can seeIn most case ‘eventCopy = *event;’ will copy the data to and from the same memory location … What about using:vent *event = new Event(); ... event->restorePtrs();.

For restorePtrs to work, the event->ParticleData pointer needs to be initialized. And I think you need to do:event->init("",pythia.particleData);
Also you could simply do: Int_t pdg = part->GetPdgCode(); Float_t charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();

Cheers,
Philippe.