#include <cmath>
#include "THaEvData.h"
#include "TClonesArray.h"
#include "TDatime.h"
#include "THaScintPlane.h"
#include "VarType.h"
#include "VarDef.h"
#include "TMath.h"
#include "THaScintHit.h"
#include "THaScintBar.h"
#include "THaScintPMT.h"
#include "THaTrackProj.h"
#include "THaTrack.h"
#include "THaTimingPlane.h"
using namespace std;
ClassImp(THaTimingPlane)
THaTimingPlane::THaTimingPlane( const char* name, const char* description, THaApparatus* a) :
THaNonTrackingDetector(name,description,a),
fEplane(NULL), fdEplane(NULL)
{
DEBUG_LEVEL_RELATED_PERFORMACE_CHECKER;
DEBUG_HALL_A_ANALYZER_DEBUGER_INIT;
Setup( name, "e", "de", description, false );
}
void THaTimingPlane::Setup( const char* name,
const char* eplane_name,
const char* deplane_name,
const char* description,
bool subnames )
{
static const char* const here = "Setup()";
static const char* const message =
"Must construct %s detector with valid name! Object construction failed.";
if( IsZombie()) return;
size_t e, de;
if( !eplane_name || (e = strlen(eplane_name)) == 0 ) {
Error( Here(here), message, "Eplane" );
MakeZombie();
return;
}
if( !deplane_name || (de = strlen(deplane_name)) == 0 ) {
Error( Here(here), message, "dEplane" );
MakeZombie();
return;
}
size_t nlen = strlen(name);
size_t slen = TMath::Max(e,de);
size_t len = slen;
if( subnames )
len += nlen+1;
char* subname = new char[ len+1 ];
const char* sname;
if( subnames ) {
strcpy( subname, name );
strcat( subname, "." );
strcat( subname, eplane_name );
sname = subname;
} else
sname = eplane_name;
char* desc = new char[ 50+strlen(description) ];
if( description && strlen(description)>0 )
strcpy( desc, description );
else {
strcpy( desc, "BigBite Trigger Plane" );
SetTitle( desc );
}
size_t dlen = strlen(desc);
strcat( desc, " E-plane subdetector" );
#if DEBUG_LEVEL>=3//start show info
Info(Here(here),"\tConstruct subdetector Name=%s, Desc=%s", sname,desc);
#endif//#if DEBUG_LEVEL>=3
fEplane = new THaScintPlane( sname, desc , this);
if( !fEplane || fEplane->IsZombie() ) {
Error( Here(here), "Fail to initiate %s", "Eplane" );
MakeZombie();
goto exit;
}
if( subnames )
strcpy( subname+nlen+1, deplane_name );
else
sname = deplane_name;
strcpy( desc+dlen, " dE-plane subdetector" );
#if DEBUG_LEVEL>=3//start show info
Info(Here(here),"\tConstruct subdetector Name=%s, Desc=%s", sname,desc);
#endif//#if DEBUG_LEVEL>=3
fdEplane = new THaScintPlane( sname, desc , this);
if( !fdEplane && fdEplane->IsZombie() ) {
Error( Here(here), "Fail to initiate %s", "dEplane" );
MakeZombie();
goto exit;
}
exit:
delete [] subname;
delete [] desc;
return;
}
THaTimingPlane::~THaTimingPlane()
{
delete fEplane;
delete fdEplane;
if( fIsSetup )
RemoveVariables();
}
THaDetectorBase::EStatus THaTimingPlane::Init( const TDatime& run_time )
{
if( IsZombie() || !fEplane || !fdEplane )
return fStatus = kInitError;
MakePrefix();
EStatus status;
if( (status = THaNonTrackingDetector::Init( run_time )) ||
(status = fEplane->Init( run_time )) ||
(status = fdEplane->Init( run_time )) )
return fStatus = status;
return fStatus;
}
Int_t THaTimingPlane::DefineVariables( EMode mode )
{
if( mode == kDefine && fIsSetup ) return kOK;
fIsSetup = ( mode == kDefine );
THaNonTrackingDetector::DefineVariables(mode);
RVarDef vars[] = {
{0}
};
Int_t value = DefineVarsFromList( vars, mode );
return value;
}
Int_t THaTimingPlane::ReadDatabase( const TDatime& date )
{
static const char* here = "ReadDatabase()";
static const Int_t LEN=300;
char buff[LEN];
char cbuff[LEN];
FILE* file = OpenFile( date );
if( !file )
{
#if DEBUG_LEVEL>=1//start show warning
Warning(Here(here),"\tTHaTimingPlane(%s) ReadDatabase file open failed.",GetName());
#endif//#if DEBUG_LEVEL>=1
return kFileError;
}
#if DEBUG_LEVEL>=3//start show info
Info(Here(here),"\tStart reading Database");
#endif//#if DEBUG_LEVEL>=3
TString line;
TString prefix=fPrefix;
prefix.Chop();
TString tag = Form("[%s.%s]",prefix.Data(), "geometry" );
#if DEBUG_LEVEL>=3//start show info
Info(Here(here),"\tTrying to read in database section %s", tag.Data());
#endif
tag.ToLower();
bool found = false;
while (!found && fgets (buff, LEN, file) != NULL) {
char* buf = ::Compress(buff);
line = buf;
delete [] buf;
#if DEBUG_LEVEL>=5//start show info
Info(Here(here),"\tTrying to search line <%s>", line.Data());
#endif
if( line.EndsWith("\n") ) line.Chop();
#if DEBUG_LEVEL>=5//start show info
Info(Here(here),"\tafter line.Chop() <%s>", line.Data());
#endif
line.ToLower();
if ( tag == line )
found = true;
}
if( !found ) {
Error(Here(here), "Database entry \"%s\" not found!", tag.Data() );
fclose(file);
return kInitError;
}
while ( ReadNumberSignStartComment( file, cbuff, LEN ));
Double_t xtmp,ytmp,ztmp;
fgets( buff, LEN, file );
if( sscanf( buff, "%lg%lg%lg",&xtmp,&ytmp,&ztmp) != 3 ) {
if( *buff ) buff[strlen(buff)-1] = 0;
Error( Here(here), "Error 4 reading %s (fOrigin): %s", tag.Data(), buff );
fclose(file);
return kInitError;
}
fOrigin.SetXYZ(xtmp,ytmp,ztmp);
while ( ReadNumberSignStartComment( file, cbuff, LEN ));
fgets( buff, LEN, file );
if( sscanf( buff, "%lg%lg%lg",&xtmp,&ytmp,&ztmp) != 3 ) {
if( *buff ) buff[strlen(buff)-1] = 0;
Error( Here(here), "Error 4 reading %s (fXax): %s", tag.Data(), buff );
fclose(file);
return kInitError;
}
fXax.SetXYZ( xtmp,ytmp,ztmp );
while ( ReadNumberSignStartComment( file, cbuff, LEN ));
fgets( buff, LEN, file );
if( sscanf( buff, "%lg%lg%lg",&xtmp,&ytmp,&ztmp) != 3 ) {
if( *buff ) buff[strlen(buff)-1] = 0;
Error( Here(here), "Error 4 reading %s (fZax): %s", tag.Data(), buff );
fclose(file);
return kInitError;
}
fYax.SetXYZ( xtmp,ytmp,ztmp );
fZax = fXax.Cross(fYax);
#if DEBUG_LEVEL>=3//start show info
Info(Here(here),"Printing Origin and x,y,z axis vector:");
fOrigin.Print();
fXax.Print();
fYax.Print();
fZax.Print();
#endif
fclose(file);
return kOK;
}
Int_t THaTimingPlane::Decode( const THaEvData& evdata )
{
if( !IsOK() )
return -1;
return fEplane->Decode( evdata )+fdEplane->Decode( evdata );
}
void THaTimingPlane::SetApparatus( THaApparatus* app )
{
THaNonTrackingDetector::SetApparatus( app );
return;
}
Int_t THaTimingPlane::FineProcess( TClonesArray& tracks )
{
fEplane->FineProcess(tracks);
fdEplane->FineProcess(tracks);
return kOK;
}
Int_t THaTimingPlane::CoarseProcess( TClonesArray& tracks )
{
fEplane->CoarseProcess(tracks);
fdEplane->CoarseProcess(tracks);
return kOK;
}
char* THaTimingPlane::ReadNumberSignStartComment( FILE* fp, char *buf, const int len )
{
int ch = fgetc(fp);
ungetc(ch,fp);
if(ch=='#' || ch=='\n')
return fgets(buf,len,fp);
else
return NULL;
}
Last update: Tue Jul 7 19:26:18 2009
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.