/************************************************************************** Ovcharenko Egor, march 2016 evovch@gmail.com **************************************************************************/ // ROOT classes #include #include #include #include #include struct data_from_file { unsigned int second_count; unsigned int pc_counter_1; }; int main(int argc, char** argv) { if (argc != 2) { printf ("Incorrect number of arguments. Usage: ./readRootFile.exe \n"); return 1; } TApplication theApp("Analysis", &argc, argv); // Get the file TFile* dataFile = new TFile(theApp.Argv(1), "READ"); // Get the only tree of the file TTree* dataTree = (TTree*)dataFile->Get("dataTree"); // Get the only branch of the tree and map the branch to the structure struct data_from_file dataObject; TBranch* recDataBranch = dataTree->GetBranch("recordedData"); recDataBranch->SetAddress(&dataObject); // Get the number of entries in the tree unsigned int numOfEntries = dataTree->GetEntries(); // Search for min and max values //TODO optimize - there must be a dedicated method for that unsigned int col1_min, col1_max; unsigned int col2_min, col2_max; recDataBranch->GetEntry(0); col1_min = dataObject.second_count; col1_max = dataObject.second_count; col2_min = dataObject.pc_counter_1; col2_max = dataObject.pc_counter_1; for (unsigned int i=1; iGetEntry(i); if (dataObject.second_count < col1_min) col1_min = dataObject.second_count; if (dataObject.second_count > col1_max) col1_max = dataObject.second_count; if (dataObject.pc_counter_1 < col2_min) col2_min = dataObject.pc_counter_1; if (dataObject.pc_counter_1 > col2_max) col2_max = dataObject.pc_counter_1; } printf ("col1_min=%u\ncol1_max=%u\ncol2_min=%u\ncol2_max=%u\n\n", col1_min, col1_max, col2_min, col2_max); // Prepare histograms TH1D* histo1 = new TH1D("second_count", "second_count;;Entries", 1000, (Double_t)col1_min, (Double_t)col1_max); TH1D* histo2 = new TH1D("pc_counter_1", "pc_counter_1;;Entries", 1000, (Double_t)col2_min, (Double_t)col2_max); for (unsigned int i=0; iGetEntry(i); printf ("%u\t-\t%u\n", dataObject.second_count, dataObject.pc_counter_1); histo1->Fill(dataObject.second_count); histo2->Fill(dataObject.pc_counter_1); } printf ("\n"); TCanvas* canv = new TCanvas("canv", "canv"); canv->Divide(1, 2); histo1->Rebin(10); histo2->Rebin(10); canv->cd(1); histo1->Draw(); canv->cd(2); histo2->Draw(); theApp.Run(); return 0; }