00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "TSoftwareAdcModule.hh"
00020 #include "TDataSegment.hh"
00021 #include "TDataElement.hh"
00022
00023 Tint TSoftwareAdcModule::theSeed = (Tint)time( 0 );
00024 TRandomEngine TSoftwareAdcModule::theRandomEngine( (Tlong)(TSoftwareAdcModule::theSeed) );
00025
00026 TSoftwareAdcModule::TSoftwareAdcModule( Tint nchannel, Tint scale, Trandom_t randtype )
00027 : TSoftwareModule( nchannel ), theScale( scale ),
00028 theMean( nchannel, 0 ), theSigma( nchannel, 0 ), theChannel( nchannel, 0 ),
00029 theRandomType( randtype )
00030 {
00031 setParameters();
00032 Update();
00033 }
00034
00035 TSoftwareAdcModule::TSoftwareAdcModule( const TSoftwareAdcModule& right )
00036 : TSoftwareModule( right ), theMean( right.theMean ),
00037 theSigma( right.theSigma ), theChannel( right.theChannel ),
00038 theRandomType( right.theRandomType )
00039 {
00040 SetSeed( right.GetSeed() );
00041 SetRandomEngine( right.GetRandomEngine() );
00042 }
00043
00044 TSoftwareAdcModule::~TSoftwareAdcModule()
00045 {;}
00046
00047 Tint TSoftwareAdcModule::Clear()
00048 {
00049 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) {
00050 theChannel[ i ] = 0;
00051 }
00052 return theStatus = tStatusSuccess;
00053 }
00054
00055 Tint TSoftwareAdcModule::Update()
00056 {
00057 switch ( theRandomType ) {
00058 case tRandomLandau:
00059 case tRandomExponential:
00060 case tRandomGaussian:
00061 case tRandomChiSquare:
00062 case tRandomGamma:
00063 case tRandomPoisson:
00064 case tRandomUnknown:
00065 default:
00066 fillGaussian();
00067 break;
00068 }
00069
00070 return theStatus;
00071 }
00072
00073 Tint TSoftwareAdcModule::Initialize()
00074 {
00075 Clear();
00076 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) {
00077 theMean[ i ] = 0;
00078 theSigma[ i ] = 0;
00079 }
00080 setParameters();
00081 return theStatus = tStatusSuccess;
00082 }
00083
00084 Tvoid TSoftwareAdcModule::FillData( TDataElement& element, Tint channel )
00085 {
00086 if ( channel < 0 || channel >= theNumberOfChannels ) {
00087 Tcerr << "TSoftwareAdcModule::FillData: invalid ID " << channel << Tendl;
00088 theStatus = -EFAULT;
00089 element.FillData( &theStatus, tTypeInt, 1 );
00090 } else {
00091 element.FillData( &theChannel[ channel ], tTypeInt, 1 );
00092 }
00093 return;
00094 }
00095
00096 const TSoftwareAdcModule& TSoftwareAdcModule::operator=( const TSoftwareAdcModule& right )
00097 {
00098 *( (TSoftwareModule*)this ) = *( (TSoftwareModule*)(&right) );
00099 theMean = right.theMean;
00100 theSigma = right.theSigma;
00101 theChannel = right.theChannel;
00102 theRandomType = right.theRandomType;
00103 SetSeed( right.GetSeed() );
00104 SetRandomEngine( right.GetRandomEngine() );
00105 return *this;
00106 }
00107
00108 Tbool TSoftwareAdcModule::operator==( const TSoftwareAdcModule& right ) const
00109 {
00110 Tbool ret = Ttrue;
00111 ret &= ( *( (TSoftwareModule*)this ) == *( (TSoftwareModule*)(&right) ) );
00112 ret &= ( theMean == right.theMean );
00113 ret &= ( theSigma == right.theSigma );
00114 ret &= ( theChannel == right.theChannel );
00115 ret &= ( theRandomType == right.theRandomType );
00116 return ret;
00117 }
00118
00119 Tbool TSoftwareAdcModule::operator!=( const TSoftwareAdcModule& right ) const
00120 {
00121 Tbool ret = Tfalse;
00122 ret |= ( *( (TSoftwareModule*)this ) != *( (TSoftwareModule*)(&right) ) );
00123 ret |= ( theMean != right.theMean );
00124 ret |= ( theSigma != right.theSigma );
00125 ret |= ( theChannel != right.theChannel );
00126 ret |= ( theRandomType != right.theRandomType );
00127 return ret;
00128 }
00129
00130 Tvoid TSoftwareAdcModule::setParameters()
00131 {
00132 TRandomFlat randomFlat( TSoftwareAdcModule::theRandomEngine );
00133
00134 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) {
00135 theMean[ i ] = randomFlat.fireInt( theScale );
00136 Tdouble distance = (Tdouble)theMean[ i ];
00137 if ( (Tdouble)theScale / 2.0 < distance )
00138 distance = theScale - distance;
00139
00140
00141 theSigma[ i ] = randomFlat.fireInt( (Tint)( distance / 3.0 ) );
00142 }
00143
00144 return;
00145 }
00146
00147 Tvoid TSoftwareAdcModule::fillGaussian()
00148 {
00149 TRandomGaussian randomGaussian( TSoftwareAdcModule::theRandomEngine );
00150 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) {
00151 Tint idata = (Tint)( randomGaussian.fire( (Tdouble)theMean[ i ], (Tdouble)theSigma[ i ] ) );
00152 if ( idata > theScale || idata < 0 ) {
00153 idata = tDataOverFlow;
00154 theStatus = -EFAULT;
00155 }
00156 theChannel[ i ] = idata;
00157 }
00158 return;
00159 }
00160
00161 #ifdef __CLDAQ_ROOT_DLL
00162 ClassImp(TSoftwareAdcModule)
00163 #endif