{
gSystem->Load("libFWCoreFWLite.so");
AutoLibraryLoader::enable();
gSystem->Load("libDataFormatsFWLite.so"); // Load the DataFormat about FWLite.
#include "DataFormats/FWLite/interface/Handle.h" // Include a handler about FWLite
TFile file("PythiaH190ZZ4mu_cfi_py_GEN.root");
TH1F* hist_muPt = new TH1F("hist_muPt","Genparticle p_{T}",100,0,100);
fwlite::Event ev(&file); // Get the event 'ev' using file. ( & means itself<no copy>. )
// `ev.toBegin()` means `ev=*ev[0]`, `!ev.atEnd()` means ev<ev[last]
for( ev.toBegin(); ! ev.atEnd(); ++ev)
{
fwlite::Handle<std::vector<reco::GenParticle> > objs; // Using handler as reco::GenParticle
objs.getByLabel(ev,"genParticles");
for ( int i =0 ; i< objs.ptr()->size(); ++i)
{
std::vector<reco::GenParticle> const & genparticle = *objs;
hist_muPt->Fill( genparticle[i].pt() );
}
//now can access data
}
hist_muPt->Draw();
}
-- GunmoRyu - 13 Mar 2009