AIDA GELINA BRIKEN nToF CRIB ISOLDE CIRCE nTOFCapture DESPEC DTAS EDI_PSA 179Ta CARME StellarModelling DCF K40
  BRIKEN  ELOG logo
Message ID: 150     Entry time: Fri Nov 11 08:07:18 2016
Author: BCR SG NTB 
Subject: BRIKEN Hit Visualization 

These are the files used to create and visualize the hit patterns of the BRIKEN detector.

There are three files needed plus one input data file. The three files are "HybridBRIKENPhysicalHistogram.hpp", "HybridBRIKENPhysicalHistogram.cpp", and "HybryidBRIKEN_Tube_Info_1.txt". These files are attached to this eLog entry.

In order to run this type in a terminal

root -l HybidBRIKENPhysicalHistogram.cpp+

The plus is important, it tells ROOT to compile this with the gcc compiler and then run that compiled version of the code. It runs slow, if at all, in the ROOT C++ interpreter CINT.

The code has been tested with ROOT v5.32 and v5.34, not version 6.

At the bottom of the HybidBRIKENPhysicalHistogram.cpp file is the "main program". In it you can set the input data file, which should be a BRIKEN online root output file, and the 3He energy cuts. It is easiest if all the files are in the same folder. If there are any questions please feel free to email B. Charles (Charlie) Rasco.

Attachment 1: HybridBRIKENPhysicalHistogram.cpp  8 kB  | Hide | Hide all | Show all
//
//  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");  
}
Attachment 2: HybridBRIKENPhysicalHistogram.hpp  1 kB  | Hide | Hide all | Show all
//
//  HybridBRIKENPhysicalHistogram.hpp
//  
//
//  Created by Bertis Charles Rasco on 11/4/16.
//
//

#ifndef HybridBRIKENPhysicalHistogram_hpp
#define HybridBRIKENPhysicalHistogram_hpp

#include <vector>

#include "TFile.h"
#include "TH2Poly.h"
#include "TObject.h"
#include "TString.h"

//class TFile;

class HeTube
{
public:
 HeTube( Double_t r, Double_t x, Double_t y, Int_t tID, Int_t rID, char tubeTypeChars[2] )
  { radius = r; pos[0] = x; pos[1] = y; tubeID = tID; ringID = rID; 
    tubeType[0] = tubeTypeChars[0]; tubeType[1] = tubeTypeChars[1]; }

//private:
  Double_t radius;
  Double_t pos[2];
  Int_t tubeID;
  Int_t ringID;
  Char_t tubeType[2]; // RI (RIKEN), UP (UPC), O1 (ORNL1), O2 (ORNL2)
};


class HybridBRIKENHistogram : public TH2Poly
{
public:
  HybridBRIKENHistogram();// ROOT needs this to be defined if it is inherited from a ROOT class.
  HybridBRIKENHistogram( const char *name, const char *title, Double_t xlow, Double_t xup, Double_t ylow, Double_t yup );
  HybridBRIKENHistogram( const char *name, const char *title, Double_t xlow, Double_t xup, Double_t ylow, Double_t yup,
    TString inputFileName );

  ~HybridBRIKENHistogram();
  
  ClassDef(HybridBRIKENHistogram,1);// ROOT also needs this if it is inherited from a ROOT class. Not sure what the 1 means.
private:

  void ReadinTubes( void );
  void SetupTubes( void );
  void ReadInDataFromFile( void );

  void FillTubeCountsRandom( void );

  Int_t AddCircularBin( Int_t tubeID );
  
  TString m_InputFileName;
  TFile *m_InputFile;
  
  std::vector<HeTube*> m_Tubes;
};

#endif /* HybridBRIKENPhysicalHistogram_hpp */
Attachment 3: HybridBRIKEN_Tube_Info_1.txt  4 kB  | Show | Hide all | Show all
ELOG V3.1.4-unknown