//
// HybridBRIKENPhysicalHistogram.cpp
//
//
// Created by Bertis Charles Rasco on 11/4/16.
//
//
#include "HybridBRIKENPhysicalHistogram.hpp"
#include <cmath>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <stdio.h>
//#include <stdlib.h>
#include "TH1F.h"
#include "TRandom3.h"
#include "TFile.h"
// ROOT Needs this for some reason.
HybridBRIKENHistogram::HybridBRIKENHistogram(): TH2Poly()
{
}
HybridBRIKENHistogram::HybridBRIKENHistogram( const char *name, const char *title, Double_t xlow, Double_t xup, Double_t ylow, Double_t yup ):
TH2Poly( name, title, xlow, xup, ylow, yup )
{
this->ReadinTubes();
this->FillTubeCountsRandom();
// this->SetupTubes();
// this->Draw();
}
HybridBRIKENHistogram::HybridBRIKENHistogram( const char *name, const char *title, Double_t xlow, Double_t xup, Double_t ylow, Double_t yup, TString inputFileName ):
TH2Poly( name, title, xlow, xup, ylow, yup )
{
m_InputFileName = inputFileName;
this->ReadinTubes();
this->ReadInDataFromFile();
// this->SetupTubes();
// this->Draw();
}
HybridBRIKENHistogram::~HybridBRIKENHistogram()
{
}
void HybridBRIKENHistogram::ReadinTubes( void )
{
std::ifstream file("HybridBRIKEN_Tube_Info_1.txt");
std::string str;
Int_t lineCount = 0;
Int_t tubeCount = 0;
Double_t rad;
Double_t pos[2];
Int_t tubeID;
Int_t ringID;
Char_t tubeType[20];
// std::stringstream ss;
// std::string::size_type sz;
while ( std::getline(file, str) )
{
// Process str
std::stringstream ss( str);
if( lineCount > 0 )
{
tubeType[0] = 'X';
ss >> tubeID >> tubeType >> rad >> pos[0] >> pos[1] >> ringID;
rad *= 0.5;// 2R is what is in file.
// tubeID = std::stoi( str, &sz );
if( tubeID > 0 && (tubeType[0]=='R' || tubeType[0]=='U' || tubeType[0]=='O' ) )
{
if( tubeType[0] != 'O' ) m_Tubes.push_back( new HeTube( rad, pos[0], pos[1], tubeID, ringID, tubeType ) );
else if( tubeType[0] == 'O' )
{
tubeType[1] = tubeType[4];
m_Tubes.push_back( new HeTube( rad, pos[0], pos[1], tubeID, ringID, tubeType ) );
}
tubeCount++;
}
}
// if( lineCount < 11 )
// {
// std::cout << str << std::endl;
// std::cout << tubeID << ", " << tubeType[0] << tubeType[1] << ", " << rad << ", " << pos[0] << ", " << pos[1] << ", " << ringID << std::endl;
// ss >> tubeID >> tubeType >> rad >> pos[0] >> pos[1] >> ringID;
// }
lineCount++;
}
Int_t binID;
// Double_t minX = m_Tubes[0]->pos[0] - m_Tubes[0]->radius;
// Double_t maxX = m_Tubes[0]->pos[0] + m_Tubes[0]->radius;
// Double_t minY = m_Tubes[0]->pos[1] - m_Tubes[0]->radius;
// Double_t maxY = m_Tubes[0]->pos[1] + m_Tubes[0]->radius;
// Fix
// binID = this->AddBin( minX, minY, maxX, maxY );
binID = this->AddCircularBin( 0 );
// std::cout << "X: " << this->GetNbinsX() << std::endl;
// std::cout << "Y: " << this->GetNbinsY() << std::endl;
// std::cout << "Z: " << this->GetNbinsZ() << std::endl;
// std::cout << "BinID: " << binID << std::endl;
// this->SetBinContent( binID, 9);
for( Int_t i = 1; i < (Int_t) m_Tubes.size(); i++ )
{
// minX = m_Tubes[i]->pos[0] - m_Tubes[i]->radius;
// maxX = m_Tubes[i]->pos[0] + m_Tubes[i]->radius;
// minY = m_Tubes[i]->pos[1] - m_Tubes[i]->radius;
// maxY = m_Tubes[i]->pos[1] + m_Tubes[i]->radius;
// Fix AddCircularBin
// binID = this->AddBin( minX, minY, maxX, maxY );
binID = this->AddCircularBin( i );
// std::cout << "BinID: " << binID << std::endl;
// this->SetBinContent( binID, 15 + binID * 11);
}
std::cout << "Number of Lines: " << lineCount << std::endl;// = How many tubes in total?
std::cout << "Number of Tubes: " << binID << std::endl;// = How many tubes in total?
// std::cout << "Number of Bins: " << this->GetNcells() << std::endl;// = How many tubes in total?
}
void HybridBRIKENHistogram::SetupTubes( void )
{
// 1" tubes
const Int_t maxN1 = 8;
for( Int_t i = 0; i < maxN1; i++ )
{
m_Tubes.push_back( new HeTube(0.5, 2.0 * cos( i * 6.28 / maxN1 ), 2.0 * sin(i * 6.28 / maxN1 ), i, 1, "RI" ) );
}
// 2" tube at 14" radius
const Int_t maxN = 3;
for( Int_t i = 0; i < maxN; i++ )
{
m_Tubes.push_back( new HeTube(1.0, 14.0 * cos( i * 6.28 / maxN ), 14.0 * sin(i * 6.28 / maxN ), i, 2, "O2" ) );
}
Int_t binID;
Double_t minX = m_Tubes[0]->pos[0] - m_Tubes[0]->radius;
Double_t maxX = m_Tubes[0]->pos[0] + m_Tubes[0]->radius;
Double_t minY = m_Tubes[0]->pos[1] - m_Tubes[0]->radius;
Double_t maxY = m_Tubes[0]->pos[1] + m_Tubes[0]->radius;
// Fix this
binID = this->AddBin( minX, minY, maxX, maxY );
// std::cout << binID << std::endl;
// this->SetBinContent( binID, 9);
for( Int_t i = 0; i < (Int_t) m_Tubes.size(); i++ )
{
minX = m_Tubes[i]->pos[0] - m_Tubes[i]->radius;
maxX = m_Tubes[i]->pos[0] + m_Tubes[i]->radius;
minY = m_Tubes[i]->pos[1] - m_Tubes[i]->radius;
maxY = m_Tubes[i]->pos[1] + m_Tubes[i]->radius;
// Fix this
binID = this->AddBin( minX, minY, maxX, maxY );
// std::cout << binID << std::endl;
// this->SetBinContent( binID, 15 + binID * 11);
}
}
void HybridBRIKENHistogram::ReadInDataFromFile( void )
{
const Int_t lowHeCut = 600;//20;// Cut is by bin not by energy. But for 1 keV per bin they are the same.
const Int_t highHeCut = 900;//200;// Cut is by bin not by energy. But for 1 keV per bin they are the same.
m_InputFile = new TFile( m_InputFileName );
Int_t binID;
Double_t counts;
char tempCh[20];
for( Int_t i = 0; i < m_Tubes.size(); i++ )
{
binID = i + 1;
TString histName("He");
if( binID < 10 )
{
histName.Append("00");
}
else if( binID < 100 )
{
histName.Append("0");
}
// else if( binID < 1000 )
// {
// }
// histName.Append( TString::Itoa( (Int_t) binID, 10 ) );// Works for ROOT 5.34, but not for 5.32
// itoa(binID,tempCh,10);// Does not work for 5.32 unkown if works for 5.34
sprintf (tempCh, "%d", binID);// works for 5.32
histName.Append( TString( tempCh ) );
// std::cout << histName << std::endl;
TH1F *histogram = (TH1F*)m_InputFile->Get( histName.Data() );
counts = histogram->Integral( lowHeCut, highHeCut );
this->SetBinContent( binID, counts);
}
}
void HybridBRIKENHistogram::FillTubeCountsRandom( void )
{
TRandom3 rand;
// for( Int_t i = 0; i < this->GetNbins() ; i++)
// {
// hist->Fill( rand.Uniform(1.0,140.0) );
// }
for( Int_t i = 1; i <= (Int_t) m_Tubes.size(); i++ )
{
this->SetBinContent(i, rand.Gaus(1000., 50.0) );
}
}
Int_t HybridBRIKENHistogram::AddCircularBin( Int_t tubeID )
{
Int_t binID;
Double_t r = m_Tubes[tubeID]->radius;
Double_t theta;
const Int_t N = 16;
Double_t* x;
Double_t* y;
x = new Double_t[N];
y = new Double_t[N];
for( Int_t i = 0; i < N; i++ )
{
theta = i * 2.0 * 3.1415 / N;
x[i] = m_Tubes[tubeID]->pos[0] + r * cos( theta );
y[i] = m_Tubes[tubeID]->pos[1] + r * sin( theta );
}
binID = this->AddBin( N, x, y );
// Double_t minX = m_Tubes[tubeID]->pos[0] - m_Tubes[tubeID]->radius;
// Double_t maxX = m_Tubes[tubeID]->pos[0] + m_Tubes[tubeID]->radius;
// Double_t minY = m_Tubes[tubeID]->pos[1] - m_Tubes[tubeID]->radius;
// Double_t maxY = m_Tubes[tubeID]->pos[1] + m_Tubes[tubeID]->radius;
//
////
// binID = this->AddBin( minX, minY, maxX, maxY );
return binID;
}
//***************************************************************************************
// Main Program...
void HybridBRIKENPhysicalHistogram( void )
{
Double_t halfHDPEWidth = 500.0;// mm
// TString inputFileName( "161103_1426_152Eu.root" );
// TString inputFileName( "161103_1319_252Cf.root" );
// TString inputFileName( "161107_0833_Overnight.root" );
// TString inputFileName( "161108_1609_ShortBackground.root" );
// TString inputFileName( "161013_1518_137Cs60Co.root" );
TString inputFileName( "161108_2323_717273Ni.root" );
HybridBRIKENHistogram *hist = new HybridBRIKENHistogram("hBR", "HybridBRIKEN", -halfHDPEWidth, halfHDPEWidth, -halfHDPEWidth, halfHDPEWidth, inputFileName );
// HybridBRIKENHistogram *hist = new HybridBRIKENHistogram("hBR", "HybridBRIKEN", -halfHDPEWidth, halfHDPEWidth, -halfHDPEWidth, halfHDPEWidth );
hist->Draw("COLZ");
}
|