addObjectDuringAODCreation() { // add an object to an aod and write it TFile *aodFile = TFile::Open("addAOD.root", "RECREATE"); // create an IlcAOD object IlcAODEvent *aod = new IlcAODEvent(); aod->CreateStdContent(); // add new information, we use IlcESDtracks for now TClonesArray *tracks = new TClonesArray("IlcESDtrack", 0); aod->AddObject(tracks); // go to the file aodFile->cd(); // create the tree TTree *aodTree = new TTree("aodTree", "IlcAOD tree"); aodTree->Branch(aod->GetList()); for (Int_t iEvent = 0; iEvent < 10; ++iEvent) { // add (part of) standard information IlcAODHeader *header = aod->GetHeader(); tracks->Delete(); // delete old objects tracks->Expand(iEvent+5/* just to make it a different number each time*/); // expand container (just for speed) // fill TClonesArray TClonesArray &rTracks = *tracks; for (Int_t i = 0; i< iEvent+5; i++) { new(rTracks[i]) IlcESDtrack(); } // fill the tree for this event aodTree->Fill(); } // end of event loop aodTree->GetUserInfo()->Add(aod); // write the tree to the specified file aodFile = aodTree->GetCurrentFile(); aodFile->cd(); aodTree->Write(); }
void ReadAOD(const char *fileName = "IlcAOD.root") { // open input file and get the TTree TFile inFile(fileName, "READ"); if (!inFile.IsOpen()) return; TTree *aodTree = (TTree*)inFile.Get("aodTree"); IlcAODEvent *ev = new IlcAODEvent(); ev->ReadFromTree(aodTree); // loop over events Int_t nEvents = aodTree->GetEntries(); for (Int_t nEv = 0; nEv < nEvents; nEv++) { cout << "Event: " << nEv+1 << "/" << nEvents << endl; // read events aodTree->GetEvent(nEv); //print event info ev->GetHeader()->Print(); // loop over tracks Int_t nTracks = ev->GetNTracks(); for (Int_t nTr = 0; nTr < nTracks; nTr++) { IlcAODTrack *tr = ev->GetTrack(nTr); // print track info cout << nTr+1 << "/" << nTracks << ": track pt: " << tr->Pt(); if (tr->GetProdVertex()) { cout << ", vertex z of this track: " << tr->GetProdVertex()->GetZ(); } cout << endl; } // loop over vertices Int_t nVtxs = ev->GetNVertices(); for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { // print track info cout << nVtx+1 << "/" << nVtxs << ": vertex z position: " << ev->GetVertex(nVtx)->GetZ() << endl; } } return; }