]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/addObjectAndUpdateAOD.C
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / STEER / addObjectAndUpdateAOD.C
CommitLineData
a19c5742 1void addObjectAndUpdateAOD(const char *fileName = "AliAOD.root") {
2 // This little macro takes an already created AOD file and adds
3 // a new branch to it.
4 // Be aware that if something breaks, the content of the file will
5 // be essentially lost, meaning WITH THIS UPDATE PROCEDURE YOU
6 // HAVE THE POWER TO DESTROY DATA!
7 //
8 // To read back this data (including the newly updated branch), have
9 // a look at $ALICE_ROOT/STEER/ReadAOD.C and add one line
10 // TClonesArray *esdTracks =
11 // (TClonesArray*)ev->GetList()->FindObject("esdTracks");
12 // after
13 // ev->ReadFromTree(aodTree);
14 //
15 // esdTracks will be 'filled' correctly after each call of
16 // aodTree->GetEvent(nEv);
17 //
18
19
20 // open input file and get the TTree
21 TFile inFile(fileName, "UPDATE");
22
23 TTree *aodTree = (TTree*)inFile.Get("aodTree");
24 AliAODEvent *ev = new AliAODEvent();
25 ev->ReadFromTree(aodTree);
26
27 // add new information to the list (we use AliESDtracks as an example)
28 TClonesArray *tracks = new TClonesArray("AliESDtrack", 0);
29 ev->AddObject(tracks); // add new object to the list
30
31 // define a unique name
32 const char *name = "esdTracks";
33 tracks->SetName(name); // set this name to be the name of the TClonesArray
34 // create the new branch
35 TBranch *newBranch = aodTree->Branch(name, &tracks); // the branch gets the same name
36
37 // loop over events
38 Int_t nEvent = aodTree->GetEntries();
39
40 for(Int_t iEv = 0; iEv < nEvent; iEv++) {
41
42 /*
43 // read events (only necessary if you want to access the old data)
44 aodTree->GetEvent(nEv);
45 */
46
47 tracks->Delete(); // for each event delete old entries of new TClonesArray
48
49 Int_t nTracks = gRandom->Rndm() * 50; // randomize size of TClonesArray (just for this example)
50 tracks->Expand(nTracks); // expand container (just for speed)
51
52 // fill TClonesArray
53 TClonesArray &rTracks = *tracks;
54 for (Int_t iTr = 0; iTr< nTracks; iTr++) {
55 new(rTracks[iTr]) AliESDtrack();
56 }
57
58 // fill the new branch
59 newBranch->Fill();
60 }
61
62 // (over)write the tree (to the same file!)
63
64 aodTree->Write("", TObject::kOverwrite);
65 inFile.Close();
66
67 return;
68}