ROOT Version: 5.34/36
Platform, compiler: Ubuntu 16.04.9, gcc5.4
I am trying to get the values stored in a root tree with a structure I don’t quite understand. I am able to successfully draw a histogram with the code below:
run = 1049;
TFile *file = new TFile(Form("./rootfiles/GEMclusters%d.root", run));
TFile *file2 = new TFile(Form("./rootfiles/GEMtracks%d.root", run));
TFile *file_PID = new TFile(Form("./rootfiles/run%d_cooked_PID.root", run));
TTree *lumigemcooked = (TTree*)file->Get("lumigemcooked");
TTree *tracks = (TTree*)file2->Get("MUSEteleTracks");
lumigemcooked->AddFriend("MUSEteleTracks",file2);
lumigemcooked->AddFriend("PID", file_PID);
lumigemcooked->SetAlias("xtarget", "MUSEteleTracks.teletracks.mx*50.0+MUSEteleTracks.teletracks.x0");
lumigemcooked->SetAlias("ytarget", "MUSEteleTracks.teletracks.my*50.0+MUSEteleTracks.teletracks.y0");
TH2F *xytarg = new TH2F("xytarg","xytarg",100,-100,100,100,-100,100);
TCanvas *c1 = new TCanvas("c1",Form("Run %d", run),600,600);
//Draw YvsX
lumigemcooked->Draw("xtarget:ytarget>>xytarg","MUSEteleTracks.teletracks.telescope==1","colz");
This works as I want it to, plots a histogram of the y vs x coordinates with the Draw() function. However I would like to be able to read in the data, manipulate it, and then plot it later. I am trying to read in the x and y coords being plotted in the Draw() function above and store them in an array but I am struggling to work with the tree structure. The code I’m trying looks like this:
run = 1049;
TFile *file = new TFile(Form("./rootfiles/GEMclusters%d.root", run));
TFile *file2 = new TFile(Form("./rootfiles/GEMtracks%d.root", run));
TFile *file_PID = new TFile(Form("./rootfiles/run%d_cooked_PID.root", run));
TTree *lumigemcooked = (TTree*)file->Get("lumigemcooked");
TTree *tracks = (TTree*)file2->Get("MUSEteleTracks");
lumigemcooked->AddFriend("MUSEteleTracks",file2);
lumigemcooked->AddFriend("PID", file_PID);
lumigemcooked->SetAlias("xtarget", "MUSEteleTracks.teletracks.mx*50.0+MUSEteleTracks.teletracks.x0");
lumigemcooked->SetAlias("ytarget", "MUSEteleTracks.teletracks.my*50.0+MUSEteleTracks.teletracks.y0");
//----------------------------------------------------------------------------------------------
Long64_t nentries = lumigemcooked->GetEntries();
Double_t *xcoords = new Double_t[nentries]; //Where I want to store the coordinates
Double_t *ycoords = new Double_t[nentries];
for(Long64_t jj=0; jj<nentries; jj++){
lumigemcooked->GetEntry(jj);
//I know the lines below are wrong, and this is where I'm not sure what to do
xcoords[jj] = lumigemcooked->xtarget;
ycoords[jj] = lumigemcooked->ytarget;
}
In short, I am trying to take the successful Draw() function from the first chunk of code but instead store the data in arrays xcoords and ycoords to work with later. Thanks in advance for any help, I have not been able to find much about getting tree entries that are set up like this.