00001 #ifndef RawDataUtil_H 00002 #define RawDataUtil_H 00003 #include <iostream> 00004 00005 class RawDataUtil { 00006 public: 00007 00008 static double MdcTime(int timeChannel) { return ((double)timeChannel)*MDC_TIME_FACTOR; } 00009 static int MdcTimeChannel (double time) { return (int)(time/MDC_TIME_FACTOR); } 00010 00011 static double MdcCharge(int chargeChannel) { return ((double)chargeChannel)*MDC_CHARGE_FACTOR; } 00012 static int MdcChargeChannel (double charge) { return (int)(charge/MDC_CHARGE_FACTOR); } 00013 00014 static double EmcTime(int timeChannel) { return ((double)timeChannel)/EMC_TIME_FACTOR; } 00015 static int EmcTimeChannel (double time) { return (int)(time*EMC_TIME_FACTOR); } 00016 00017 static double EmcCharge(int measure, int chargeChannel) 00018 { 00019 switch(measure) { 00020 case 3: //saturation of high measure 00021 return ((double)chargeChannel)*EMC_CHARGE_HIGH_MEASURE/EMC_CHARGE_FACTOR; 00022 break; 00023 case 2: 00024 return ((double)chargeChannel)*EMC_CHARGE_HIGH_MEASURE/EMC_CHARGE_FACTOR; 00025 break; 00026 case 1: 00027 return ((double)chargeChannel)*EMC_CHARGE_MID_MEASURE/EMC_CHARGE_FACTOR; 00028 break; 00029 case 0: 00030 return ((double)chargeChannel)*EMC_CHARGE_LOW_MEASURE/EMC_CHARGE_FACTOR; 00031 break; 00032 default: 00033 std::cout<<"Wrong measure of EMC charge channel!"<<std::endl; 00034 } 00035 } 00036 00037 static int EmcChargeChannel(double charge) 00038 { 00039 if(charge>EMC_CHARGE_HIGH_MEASURE) { 00040 return (int)(EMC_CHARGE_FACTOR-1); 00041 } else if(charge>EMC_CHARGE_MID_MEASURE) { 00042 return (int)(charge/(EMC_CHARGE_HIGH_MEASURE/EMC_CHARGE_FACTOR)); 00043 } else if(charge>EMC_CHARGE_LOW_MEASURE) { 00044 return (int)(charge/(EMC_CHARGE_MID_MEASURE/EMC_CHARGE_FACTOR)); 00045 } else { 00046 return (int)(charge/(EMC_CHARGE_LOW_MEASURE/EMC_CHARGE_FACTOR)); 00047 } 00048 } 00049 00050 static int EmcChargeMeasure(double charge) 00051 { 00052 if(charge>EMC_CHARGE_HIGH_MEASURE) { 00053 return 3; 00054 } else if(charge>EMC_CHARGE_MID_MEASURE) { 00055 return 2; 00056 } else if(charge>EMC_CHARGE_LOW_MEASURE) { 00057 return 1; 00058 } else { 00059 return 0; 00060 } 00061 } 00062 00063 static double TofTime(unsigned int timeChannel) { return ((double)timeChannel)*TOF_TIME_FACTOR; } 00064 static unsigned int TofTimeChannel (double time) { return (unsigned int)(time/TOF_TIME_FACTOR); } 00065 00066 static double TofCharge(unsigned int chargeChannel) 00067 { 00068 double ADC = chargeChannel & 0x1fff ; 00069 return ADC*TOF_CHARGE_FACTOR; 00070 } 00071 00072 static unsigned int TofChargeChannel (double charge, double time) 00073 { 00074 unsigned int ADC = (unsigned) (charge/TOF_CHARGE_FACTOR); 00075 unsigned int TDC = (unsigned) (time/TOF_TIME_FACTOR); 00076 if(ADC>=8192) 00077 { 00078 ADC = (ADC | 0x080000); // if ADC_channel>=8192, set overflow flag = 1. 00079 // The overlow flag is the 20th bit of the ADC_channel. 00080 } 00081 ADC = ( (TDC & 0x07e000) | ADC) ; // Store tclock into ADC_channel as qclock 00082 //std::cout<<"ADC: "<<ADC<<std::endl; 00083 //std::cout<<"TDC: "<<TDC<<std::endl; 00084 //std::cout<<"qclock: "<<( ( ADC & 0x7e000 ) >> 13 ); 00085 //std::cout<<" tclock: "<<( ( TDC & 0x7e000 ) >> 13 )<<std::endl; 00086 //if ( ( ( ADC & 0x7e000 ) >> 13 ) != (( TDC & 0x7e000 ) >> 13 ) ) 00087 // std::cout<<"qclock!=tclock"<<std::endl; 00088 return ADC; 00089 } 00090 00091 private: 00092 static const double MDC_TIME_FACTOR; 00093 static const double MDC_CHARGE_FACTOR; 00094 00095 static const double TOF_TIME_FACTOR; 00096 static const double TOF_CHARGE_FACTOR; 00097 00098 static const double EMC_CHARGE_HIGH_MEASURE; 00099 static const double EMC_CHARGE_MID_MEASURE; 00100 static const double EMC_CHARGE_LOW_MEASURE; 00101 static const double EMC_TIME_FACTOR; 00102 static const double EMC_CHARGE_FACTOR; 00103 }; 00104 00105 #endif