My Project
EventDataToHistogramBase.hh
00001 /*
00002 $Id: EventDataToHistogramBase.hh 2110 2010-04-07 04:35:47Z jisuzuki $
00003  */
00004 
00005 #ifndef EVENTDATATOHISTOGRAMBASE
00006 #define EVENTDATATOHISTOGRAMBASE
00007 
00008 #include "Header.hh"
00009 #include "GslHistogram.hh"
00010 #include "ElementContainer.hh"
00011 #include "ElementContainerMatrix.hh"
00012 #include "ElementContainerArray.hh"
00013 
00014 class EventDataToHistogramBase{
00015 private:
00016 
00017 protected:
00018   UInt4 NumOfPixel;
00019   UInt4 NumOfPsd;
00020   UInt4 CheckFlag;
00021 
00022   vector<Double> *a, *b, *c;
00023   vector<GslHistogram*> *gslhist;
00024   unsigned long long int CurrentPulseId, StartPulseId, EndPulseId;
00025   Double *Range;
00026   Double ClockToMicrosec( UInt4 Clock );
00027   void Decode_T0Data( const UChar *data, UInt4 *CrateId, UInt4 *ModuleId,
00028                       UInt8 *PulseId );
00029   void Decode_EventData( const UChar *data, UInt4 *psd_num, UInt4 *k, 
00030                          UInt4 *ph_l, UInt4 *ph_r, UInt4 *tof );
00031   void Decode_TimeStampData( const UChar *data, UInt4 *t1, UInt4 *t2, UInt4 *t3,
00032                              UInt4 *t4, UInt4 *t5, Double *t6 );
00033   
00034 
00035 public:
00036   EventDataToHistogramBase( );
00037   EventDataToHistogramBase( UInt4 _NumOfPsd, UInt4 _NumOfPixel );
00038   // Set the number of psd-s and pixels.
00039   // The second argument is total number 
00040   // of pixels handled by this class.
00041 
00042   virtual ~EventDataToHistogramBase();
00043 
00044   UInt4 _CrateId, _ModuleId, _psd_num, _ph_l, _ph_r, _tof;
00045   UInt8 _PulseId;
00046   UInt4 _k, _t1, _t2, _t3, _t4, _t5;
00047   Double _t6;
00048 
00049   void Allocate( UInt4 _NumOfPsd, UInt4 _NumOfPixel );
00050 
00051   virtual UInt4 PutPsdId( UInt4 DaqChannel, UInt4 module, UInt4 psd )=0;
00052   // Returns PSD-ID
00053 
00054   virtual UInt4 PutPixelId( UInt4 PsdId, UInt4 PixelPosition )=0;
00055   // Returns pixel-id.
00056   // The first and second arguments are the return value of
00057   // PutPsdId(...) and PutPixelPosition(...).
00058 
00059   UInt4 PutPixelPosition( UInt4 PsdId, UInt4 pl, UInt4 pr );
00060   // Returns pixel position. 
00061   // This method will be implemented or improved by DAQ-team.
00062 
00063   void SetPsdParam( UInt4 PsdId, Double A, Double B, Double C );
00064   // Set psd parameters used in PutPixelPosition(...).
00065 
00066   void SetTofBin( UInt4 PixelId, vector<Double> tof );
00067   void SetTofBin( UInt4 PixelId, Double *tof, UInt4 Size );
00068   // Set bin widths of histograms.
00069 
00070   void SetTofBin_DeltaT_Const( UInt4 PixelId, 
00071                                Double Ini, Double Fin, 
00072                                Double DeltaT );
00073   // Set bin widths of histograms.
00074   // Histogram bins are defined with the relationship dt = DeltaT.
00075 
00076   void SetTofBin_DeltaToverT_Const( UInt4 PixelId, 
00077                                     Double Ini, Double Fin, 
00078                                     Double DeltaToverT );
00079   // Set bin widths of histograms.
00080   // The second and fourth argument should not be 0.0 and 2.0.
00081   // Histogram bins are defined with the relationship dT/T = DeltaToverT.
00082 
00083   void Increment( UInt4 DaqChannel, UChar* data, UInt4 size );
00084   // Event data is input and histogram will be updated with this method.
00085 
00086   GslHistogram *PutGslHistogram( UInt4 PixelId ){ return (*gslhist)[ PixelId ]; }
00087   // Histogram data will be extracted with this method.
00088 
00089   vector<GslHistogram*> *PutGslHistogramVec(){ return gslhist; }
00090 
00091   vector<Double> PutHist( UInt4 PixelId )
00092     { return (*gslhist)[ PixelId ]->PutHistogram(); }
00093 
00094   Double PutSum( UInt4 PixelId )
00095   { return PutGslHistogram(PixelId)->PutHistogramSum();}
00096 
00097   vector<Double> PutBin( UInt4 PixelId ){ return (*gslhist)[ PixelId ]->PutBin(); }
00098   void Reset();
00099   
00100   virtual Double TimeFocParamC0( UInt4 _pixelid ){ return 0.0; }
00101   virtual Double TimeFocParamC1( UInt4 _pixelid ){ return 1.0; }
00102 
00103   //unsigned long long int PutStartPulseId(){   return StartPulseId; }
00104   //unsigned long long int PutEndPulseId(){     return EndPulseId; }
00105   //unsigned long long int PutCurrentPulseId(){ return CurrentPulseId; }
00106   
00107   ElementContainerMatrix  PutElementContainerMatrix(  vector<UInt4> NumObElements );
00108   ElementContainerMatrix *PutElementContainerMatrixP( vector<UInt4> NumObElements );
00109   
00110 };
00111 
00112 #endif
00113 
00114 
00115 /*
00116 #include <stdlib.h>
00117 #include <iostream>
00118 #include <cstdlib>
00119 #include <vector>
00120 #include <list>
00121 #include <string>
00122 #include <math.h>
00123 #include <fstream>
00124 #include <stdio.h>
00125 #include <stdarg.h>
00126 #include <ctype.h>
00127 
00128 using namespace std;
00129 
00130 typedef char               Char;
00131 typedef unsigned char      UChar;
00132 typedef short              Int2;
00133 typedef unsigned short     UInt2;
00134 typedef int                Int4;
00135 typedef unsigned int       UInt4;
00136 typedef long long          Int8;
00137 typedef unsigned long long UInt8;
00138 typedef double             Double;
00139 typedef float              Float;
00140 typedef bool               Bool;
00141 
00142 int main(){
00143 
00144   UInt4 Number = 100000;
00145   UChar *array = new UChar [ Number ];
00146 
00147   FILE *fin;
00148   fin = fopen( "121410/run071214102418/psdsitcp16.dat", "r" );
00149   fread( array, sizeof(Char), Number, fin ); 
00150   fclose( fin );
00151 
00152   for( UInt4 i=0; i<1000; i++ ){
00153 
00154     UInt4 index = i * 8;
00155 
00156     if( *( array + index ) == 91 ){ // if T0 data
00157 
00158       UInt4 ModuleId = (UInt4)( array[index+4] );
00159       unsigned long long int PulseId = ( array[index+5] ) * 256 * 256 +
00160                                        ( array[index+6] ) * 256 +
00161                                        ( array[index+7] );
00162         
00163       printf( "%d\t%d\t%d\n", i, ModuleId, PulseId );
00164     }
00165 
00166 
00167     if( *( array + index ) == 90 ){ // if event data
00168 
00169       UInt4 psd_num = (UInt4)( array[index+1] & 0x7 );
00170       UInt4 k = (UInt4)( array[index+6] )/16;
00171       UInt4 ph_l = (UInt4)( array[index+5] ) * 16 + k;
00172       UInt4 ph_r = (UInt4)( array[index+7] ) 
00173         + 256 * ( (UInt4( array[index+6] ) )-k*16 );
00174 
00175       UInt4 tof = (UInt4)( array[index+2] << 16 ) 
00176         + (UInt4)( array[index+3] << 8 ) 
00177         + (UInt4)( array[index+4]);
00178       
00179       
00180       //printf( "%d\t%d\t%d\t%d\t%d\n", index, psd_num, ph_l, ph_r, tof );
00181     }
00182 
00183     if( *( array + index ) == 92 ){ // if time data
00184       UInt4 t1 = (UInt4)( array[index+1] );
00185       UInt4 t2 = (UInt4)( array[index+2] );
00186       UInt4 t3 = (UInt4)( array[index+3] );
00187       UInt4 t4 = (UInt4)( array[index+4] );
00188       UInt4 t5 = (UInt4)( array[index+5] );
00189       UInt4 t6 = (UInt4)( array[index+6] );
00190       UInt4 t7 = (UInt4)( array[index+7] );
00191       printf( "%d\t%d\t%d\t%d\t%d\t%d\t%f\n", 
00192               i, t1, t2, t3, t4, t5,(float)t6 + (float)t7/256.0);
00193     }
00194   }
00195 
00196   return 0;
00197 }
00198 
00199  */
00200 
 All Classes Functions