Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:32

0001 #include <iostream>
0002 #include <iomanip>
0003 #include <fstream>
0004 
0005 #include "caen_correction.h"
0006 #include "packet.h"
0007 
0008 using namespace std;
0009 
0010 caen_correction::caen_correction ( const char *calibdata) 
0011 { 
0012 
0013   int nsample[9];
0014 
0015   _broken = 0;
0016   _samples = 1024;
0017   
0018   int index;
0019   ifstream IN;
0020 
0021   int adccorr[9];
0022   float timecorr;
0023 
0024   IN.open(calibdata,ios_base::in);
0025 
0026   int chip;
0027   int i;
0028   if ( ! IN.is_open())
0029     {
0030       _broken = 1;
0031     }
0032   else 
0033     {
0034       for  ( chip = 0; chip < 4; chip++)
0035     {
0036       for ( i = 0; i < 1024; i++)
0037         {
0038           IN >> index
0039             >> adccorr[0]
0040             >> adccorr[1]
0041             >> adccorr[2]
0042             >> adccorr[3]
0043             >> adccorr[4]
0044             >> adccorr[5]
0045             >> adccorr[6]
0046             >> adccorr[7]
0047             >> adccorr[8]
0048             >> timecorr
0049             >> nsample[0]
0050             >> nsample[1]
0051             >> nsample[2]
0052             >> nsample[3]
0053             >> nsample[4]
0054             >> nsample[5]
0055             >> nsample[6]
0056             >> nsample[7]
0057           >> nsample[8];
0058           
0059           base [index][chip*9 + 0] = adccorr[0];
0060           base [index][chip*9 + 1]= adccorr[1];
0061           base [index][chip*9 + 2]= adccorr[2];
0062           base [index][chip*9 + 3]= adccorr[3];
0063           base [index][chip*9 + 4]= adccorr[4];
0064           base [index][chip*9 + 5]= adccorr[5];
0065           base [index][chip*9 + 6]= adccorr[6];
0066           base [index][chip*9 + 7]= adccorr[7];
0067           base [index][chip*9 + 8]= adccorr[8];
0068           timevec[index][chip] = timecorr;
0069         }
0070     }
0071       IN.close();
0072     }
0073 }
0074 
0075 int caen_correction::init (Packet *p)
0076 {
0077   int chip,c,i,idx;
0078 
0079   for ( chip = 0; chip < 4; chip++)
0080     {
0081 
0082       _samples = p->iValue(chip,"SAMPLES");
0083       int cell = p->iValue(chip,"INDEXCELL");
0084 
0085       //correct time for each chip
0086       idx = cell;
0087       for ( i = 0; i < _samples; i++)
0088     {
0089       current_time[i][chip] = timevec[idx][chip];
0090       idx++;
0091       if (idx >=1024) idx=0;
0092     }
0093 
0094       // the adc samples
0095       for ( c = 0; c < 8; c++)  
0096     {
0097       idx = cell;
0098       for ( i = 0; i < _samples; i++)
0099         {
0100           current_wave[i][chip*8+c] = p->iValue(i,chip*8+c) - base[idx][chip*9+c];
0101           idx++;
0102           if (idx >=1024) idx=0;
0103         }
0104     }
0105 
0106       // Trigger cells;
0107       {
0108     idx = cell;
0109     for ( i = 0; i < _samples; i++)
0110       {
0111         current_wave[i][32+chip] = p->iValue(i,32+chip) - base[idx][chip*9+8];
0112         idx++;
0113         if (idx >=1024) idx=0;
0114       }
0115       }
0116     }
0117   return 0;
0118 }
0119       
0120 float caen_correction::caen_corrected(const int sample, const int channel) const
0121 {
0122   if ( sample < 0 || sample >=_samples || channel < 0 || channel > 35) return 0;
0123   return current_wave[sample][channel];
0124 }
0125 
0126 float caen_correction::caen_time(const int sample, const int channel) const
0127 {
0128   //if ( sample < 0 || sample >1023 || channel < 0 || channel > 31) return 0;
0129   //return current_time[sample][channel/8];
0130   if ( sample < 0 || sample >1023 || channel < 0 || channel > 35) return 0;
0131   return current_time[sample][channel < 32 ? channel/8 : channel-32];
0132 }