From 0150ac7a1f009668527d1f7e421854593ea8a5b0 Mon Sep 17 00:00:00 2001 From: David Baranyai Date: Fri, 14 Sep 2018 11:34:16 +0200 Subject: [PATCH] First version --- include/DetectorData.hpp | 65 +++++++++++++++++++++++ sipm.cpp | 112 +++++++++++++++++++++++++++++++++++++++ src/DetectorData.cpp | 67 +++++++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 include/DetectorData.hpp create mode 100644 sipm.cpp create mode 100644 src/DetectorData.cpp diff --git a/include/DetectorData.hpp b/include/DetectorData.hpp new file mode 100644 index 0000000..cbaefea --- /dev/null +++ b/include/DetectorData.hpp @@ -0,0 +1,65 @@ +// +// DetectorData.hpp +// sipm_root +// +// Created by Baranyai David on 2018. 09. 10.. +// + +#ifndef DetectorData_hpp +#define DetectorData_hpp + +#include +#include +#include + +struct position +{ + unsigned int x; + unsigned int y; +}; + +struct Data +{ + double x; + double y; + double e; + int sipm; + double time; + + std::istream& operator >> (std::istream& is) + { + is >> x >> y >> e >> sipm >> time; + return is; + } +}; + +std::istream& operator >> (std::istream& is, Data &d); + +class DetectorData +{ +private: + std::string name; + std::vector data; + + unsigned int dSize; + +public: + DetectorData(); + DetectorData(std::string name1); + ~DetectorData(); + + void AddData(const Data&); + void SetName(std::string); + + int GetSipm(unsigned int); + + Data GetHit(unsigned int) const; + std::string GetName(); + unsigned int Size(); + + const std::vector* GetDataPointer() const; + + void Clear(); +}; + +#endif /* DetectorData_hpp */ diff --git a/sipm.cpp b/sipm.cpp new file mode 100644 index 0000000..67dc1ee --- /dev/null +++ b/sipm.cpp @@ -0,0 +1,112 @@ +#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(); +} diff --git a/src/DetectorData.cpp b/src/DetectorData.cpp new file mode 100644 index 0000000..37783e8 --- /dev/null +++ b/src/DetectorData.cpp @@ -0,0 +1,67 @@ +// +// DetectorData.cpp +// sipm_root +// +// Created by Baranyai David on 2018. 09. 10.. +// + +#include "DetectorData.hpp" + +DetectorData::DetectorData() +{ + +} + +DetectorData::DetectorData(std::string name1) +{ + name = name1; + dSize = 0; +} + +DetectorData::~DetectorData() +{ + +} + +void DetectorData::AddData(const Data& d) +{ + data.push_back(d); + dSize++; +} + +void DetectorData::SetName(std::string name1) +{ + name = name1; +} + +Data DetectorData::GetHit(unsigned int n) const +{ + return data[n]; +} + +std::string DetectorData::GetName() +{ + return name; +} + +unsigned int DetectorData::Size() +{ + return dSize; +} + +void DetectorData::Clear() +{ + dSize = 0; + name.clear(); + data.clear(); +} + +int DetectorData::GetSipm(unsigned int num) +{ + return data[num].sipm; +} + +const std::vector* DetectorData::GetDataPointer() const +{ + return &data; +}