First version
This commit is contained in:
		
							parent
							
								
									fd95f64811
								
							
						
					
					
						commit
						0150ac7a1f
					
				| 
						 | 
					@ -0,0 +1,65 @@
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//  DetectorData.hpp
 | 
				
			||||||
 | 
					//  sipm_root
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//  Created by Baranyai David on 2018. 09. 10..
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef DetectorData_hpp
 | 
				
			||||||
 | 
					#define DetectorData_hpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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> 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<Data>* GetDataPointer() const;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    void Clear();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* DetectorData_hpp */
 | 
				
			||||||
| 
						 | 
					@ -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<int> non_null_tree_indexes;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    std::vector<TH1D*> histo;
 | 
				
			||||||
 | 
					    std::vector<TCanvas*> canvas;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int counter = 0;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    std::vector<DetectorData> 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> 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();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -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<Data>* DetectorData::GetDataPointer() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return &data;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue