// $Id: BrDetectorVolume.cxx,v 1.4 1998/07/03 16:07:22 hagel Exp $
// $Log: BrDetectorVolume.cxx,v $
// Revision 1.4 1998/07/03 16:07:22 hagel
// Clean up g++ warnings
//
// Revision 1.3 1998/06/20 23:20:39 hagel
// Add basic ostream support to BrDetectorVolume
//
// Revision 1.2 1998/04/29 02:15:36 hagel
// Added GlobalToLocal and LocalToGlobal
//
// Revision 1.1.1.1 1998/03/04 21:32:48 brahmlib
// Brat base
//
//
#include <stdio.h>
#include <iostream.h>
//
// Brat Classes
#include "BrDetectorVolume.h"
#include "BrDataObject.h"
ClassImp(BrDetectorVolume)
////////////////////////////////////////////////////////////
//
// BrDetectorVolume is a BRAHMS data class providing storage and
// access function for event data information. The data
// is stored in TPhObject objects that are kept inside
// a THashList.
// This allows modification of the BrDetectorVolume content by the
// user, with the BrOject providing a standard interface
// for information retrieval, bookkeeping and I/O selection.
//
////////////////////////////////////////////////////////////
BrDetectorVolume::BrDetectorVolume()
{
// Constructor. Set counter and list data members to zero.
// Don't use this constructor unless you have to and know
// what you are doing
// Use BrDetectorVolume(Int_t run, Int_t event) instead
}
BrDetectorVolume::BrDetectorVolume(Char_t *name, Char_t *title,Char_t *ASCIIFileName,Int_t fspec,Int_t mids)
{
SetName(name);
SetTitle(title);
ReadASCIIFile(ASCIIFileName,name,fspec,mids);
}
BrDetectorVolume::BrDetectorVolume(Char_t *name, Char_t *title)
{
SetName(name);
SetTitle(title);
// set some default parameters (close to T1)
fSize[0]=(float)30.;
fSize[1]=(float)20.;
fSize[2]=(float)80.;
fAngle = (float)4.2;
fPos[0] = (float)500.*(float)sin(fAngle*0.0174533);
fPos[1] = (float)0.;
fPos[2] = (float)500.*(float)cos(fAngle*0.0174533);
//Generate rotation matrix from angle
Float_t cs = (float)cos(fAngle*(float).0174533);
Float_t si = (float)sin(fAngle*(float).0174533);
fRotm[0][0] = cs;
fRotm[0][1] = (float)0.0;
fRotm[0][2] = si;
fRotm[1][0] = (float)0.0;
fRotm[1][1] = (float)1.0;
fRotm[1][2] = (float)0.0;
fRotm[2][0] = -si;
fRotm[2][1] = (float)0.0;
fRotm[2][2] = cs;
}
BrDetectorVolume::~BrDetectorVolume()
{
}
void BrDetectorVolume::SetVolumeParameters(float xl, float yl, float zl, float angle,
float xl_center, float yl_center, float zl_center, char *type)
{
fSize[0] = xl;
fSize[1] = yl;
fSize[2] = zl;
fAngle = angle;
fPos[0] = xl_center;
fPos[1] = yl_center;
fPos[2] = zl_center;
strcpy(fType,type);
//Generate rotation matrix from angle
Float_t cs = (float)cos(angle*.0174533);
Float_t si = (float)sin(angle*.0174533);
fRotm[0][0] = cs;
fRotm[0][1] = (float)0.0;
fRotm[0][2] = si;
fRotm[1][0] = (float)0.0;
fRotm[1][1] = (float)1.0;
fRotm[1][2] = (float)0.0;
fRotm[2][0] = -si;
fRotm[2][1] = (float)0.0;
fRotm[2][2] = cs;
}
void BrDetectorVolume::ListParameters()
{
printf("Detector Name is %s, Type is %s positioned at %f degreesn",
GetName(),fType,fAngle);
printf("Size: %f %f %fn",fSize[0],fSize[1],fSize[2]);
printf("Position %f %f %fn",fPos[0],fPos[1],fPos[2]);
}
void BrDetectorVolume::ReadASCIIFile(Char_t *ASCIIFileName,Char_t *DetectorName,Int_t fspec,Int_t mids)
{
FILE *GeoFile;
#define maxgeoline 80
Char_t geo_line[maxgeoline];
Char_t det_name[5],det_type[5];
Float_t xl,yl,zl,angle,xl_center,yl_center,zl_center;
Char_t *c;
Int_t imag,idet;
printf("Opening Volume file %s\n",ASCIIFileName);
if( !(GeoFile = fopen( ASCIIFileName,"r"))){
cout << "File not present " << endl;
return;
}
while(( c = fgets(geo_line,maxgeoline,GeoFile))) {
imag = strncmp(geo_line,"MAGNET",6);
idet = strncmp(geo_line,"DETECTOR=",8);
if( !imag | !idet ) {
if( !imag ) {
strcpy(det_type," ");
sscanf(geo_line,"MAGNET= %s",&det_name);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," gap x = %f",&xl);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," gap y = %f",&yl);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," gap z = %f",&zl);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," rotation ang = %f",&angle);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," gap center x = %f",&xl_center);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," gap center y = %f",&yl_center);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," gap center z = %f",&zl_center);
if(!strcasecmp(DetectorName,det_name)) {
SetVolumeParameters(xl,yl,zl,angle,
xl_center,yl_center,zl_center,det_type);
fclose(GeoFile);
return;
}
}
else if( !idet ) {
// We have found a detector, so process as such.
sscanf(geo_line,"DETECTOR= %s TYPE: %s",&det_name,&det_type);
// Convert names depending on mode of spectrometer
if( fspec ) {
if( !strcasecmp(det_name,"TPC1") ) strcpy(det_name,"T1");
if( !strcasecmp(det_name,"TPC2") ) strcpy(det_name,"T2");
}
else if( mids ) {
if( !strcasecmp(det_name,"T1") ) strcpy(det_name,"FT1");
if( !strcasecmp(det_name,"T2") ) strcpy(det_name,"Ft2");
if( !strcasecmp(det_name,"TPM1") ) strcpy(det_name,"T1");
if( !strcasecmp(det_name,"TPM2") ) strcpy(det_name,"T2");
}
else printf("Spectrometer mode does not existn");
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," Det size x = %f",&xl);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," Det size y = %f",&yl);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," Det size z = %f",&zl);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," rotation ang = %f",&angle);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," Det center x = %f",&xl_center);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," Det center y = %f",&yl_center);
fgets(geo_line,maxgeoline,GeoFile);
sscanf(geo_line," Det center z = %f",&zl_center);
if(!strcasecmp(DetectorName,det_name)) {
SetVolumeParameters(xl,yl,zl,angle,
xl_center,yl_center,zl_center,det_type);
fclose(GeoFile);
return;
}
if( !strncasecmp(det_type,"TOF",3) ) {
// cout<<"Found TOF Detector "<<det_name<<endl;
}
else if( !strncasecmp(det_type,"TRAK",4) ) {
// cout<<"Found TRAK Detector "<<det_name<<endl;
}
else if( !strncasecmp(det_type,"CHKV",4) ) {
// cout<<"Found CHKV Detector "<<det_name<<endl;
}
else {
printf("Found no Detectorn");
}
}
}
}
}
void BrDetectorVolume::GlobalToLocal(float xg[3],float xl[3],int iflag)
{
int i,j;
float xd[3];
float xim;
if( iflag == 1 ) {
for(i=0;i<3;i++) xd[i] = xg[i];
}
else {
for(i=0;i<3;i++) xd[i] = xg[i] - fPos[i];
}
for(i=0;i<3;i++) {
xim = (float)0.0;
for(j=0;j<3;j++) xim += xd[j] * fRotm[j][i];
xl[i] = xim;
}
}
void BrDetectorVolume::LocalToGlobal(float xl[3],float xg[3],int iflag)
{
//flag = 1 transform direction cosines
//flag = 0 transform coordinates
int i,j;
for(i=0;i<3;i++) {
if( iflag == 1 ) {
xg[i] = (float)0.0;
}
else {
xg[i] = fPos[i];
}
for(j=0;j<3;j++) xg[i] += xl[j]* fRotm[i][j];
}
}
ostream& operator<< (ostream & os,BrDetectorVolume *volume_p)
{
//this is a test; can be made more sophisticated as needed
printf("Inside ostream");
os<<"Volume Name is "<<volume_p->GetName()<<endl;
return os;
}
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.