void RootTutorial2() { cout << "[root_tutorial_2] Hello intern!" << endl; cout << "[root_tutorial_2] This Macro will walk you through looping a TTree and making your own plot." << endl; cout << "[root_tutorial_2] Reading ROOT file." << endl; TFile *f = new TFile("./zjet.root"); cout << "[root_tutorial_2] Geting TTree from root file." << endl; TTree *t = (TTree*) f -> Get( "Tdata" ); cout << "[root_tutorial_2] Declaring TH1D (your plot object)." << endl; TH1D *h = new TH1D( "h", "Z mass (GeV)", 100, 50, 150 ); // These are the variables that will receive the data in the TTree vector *id = 0; vector *m = 0; // This is how you say to the TTree that these are the variables taking in the information t->SetBranchAddress("id",&id); t->SetBranchAddress("m",&m); // Now will make a for loop on the TTree entries cout << "[root_tutorial_2] Looping on the TTree." << endl; for (int iEnt = 0; iEnt < t->GetEntries(); ++iEnt) { // This is how you get an entry from the TTree, i.e. this is how you load the values from a given entry to your variables t->GetEntry(iEnt); // We now loop on the objects of the event which are encoded in the vectors: for (int iObj = 0; iObj < (*id).size(); ++iObj) { // We want the Z boson, which in this case as id 0 (these id's are different from Pythia's) if ((*id)[iObj] == 0 ) h->Fill((*m)[iObj] , 1); } } // Now we wanna draw our object. You can create a TCanvas for this where you can control the width and the height, but for this demonstration it's not necessary cout << "[root_tutorial_2] Drawing your plot." << endl; h->Draw(); cout << "[root_tutorial_2] Next macro you'll reconstruct the Z and the jet from particles a detector could find and try to write the objects to a file this macro can read." << endl; }