#include "iostream" #include "TH1D.h" #include "TFile.h" #include "TTree.h" #include "TCanvas.h" #include "TApplication.h" #include "TTreeReader.h" #include "TList.h" #include "DetectorData.hpp" #include "TCanvas.h" int main(int argc, char* argv[]) { TApplication App("tapp", &argc, argv); TFile *inFile = new TFile("data.root"); std::vector non_null_tree_indexes; std::vector histo; std::vector canvas; int counter = 0; std::vector data; if(inFile -> IsOpen()) { std::cout << "File opened successfully" << std::endl; } TList *list = inFile -> GetListOfKeys(); TIter iterator(list -> MakeIterator()); while(TObject * obj = iterator()) { TTree *ttreeHelper; Data dataHelper; TKey * theKey = (TKey*)obj; ttreeHelper = (TTree*)inFile -> Get(theKey -> GetName()); std::cout << "TTree name: " << theKey -> GetName() << std::endl; ttreeHelper -> SetBranchAddress("x", &dataHelper.x); ttreeHelper -> SetBranchAddress("y", &dataHelper.y); ttreeHelper -> SetBranchAddress("e", &dataHelper.e); ttreeHelper -> SetBranchAddress("sipm", &dataHelper.sipm); ttreeHelper -> SetBranchAddress("time", &dataHelper.time); unsigned int entryNumber = ttreeHelper -> GetEntries(); if (entryNumber != 0) { /* * SiPM Tree - Name * - Data - Hits 0 * - Hits 1 ... */ DetectorData detectorDataHelper(theKey -> GetName()); data.push_back(detectorDataHelper); for(int i = 0; i < entryNumber; i++) { ttreeHelper -> GetEntry(i); std::cout << "x = " << dataHelper.x << std::endl << "y = " << dataHelper.y << std::endl << "e = " << dataHelper.e << std::endl << "sipm = " << dataHelper.sipm << std::endl << "time = " << dataHelper.time << std::endl; data[counter].AddData(dataHelper); } counter++; } } for(int i = 0; i < data.size(); i++) { const char * c = data[i].GetName().c_str(); //histo.push_back(new TH2D(c, c, 100, 0, 5, 100, 0, 0.000015)); //histo.push_back(new TH2D(c, c, 100, 0, 5, 100, 0, 0.000015)); histo.push_back(new TH1D(c, c, 100, 0, 5)); histo.push_back(new TH1D(c, c, 100, 0, 5)); canvas.push_back(new TCanvas(c, c, 800, 600)); std::vector data_helper = *data[i].GetDataPointer(); for(int j = 0; j < data_helper.size(); j++) { if(data_helper[j].sipm == 1) { histo[i*2] -> Fill(data_helper[j].time); } else if(data_helper[j].sipm == 2) { histo[i*2 + 1] -> Fill(data_helper[j].time); } } canvas[i] -> Divide(2,1); canvas[i] -> cd(1); histo[i*2] -> Draw("colz"); canvas[i] -> cd(2); histo[i*2+1] -> Draw("colz"); } App.Run(); }