ARA ROOT Test BEd Software

AraEvent/UsefulIcrrStationEvent.cxx

00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 #include "UsefulIcrrStationEvent.h"
00011 #include "FFTtools.h"
00012 #include "AraGeomTool.h"
00013 #include "TH1.h"
00014 #include <iostream>
00015 #include <fstream>
00016 #include <cstring>
00017 ClassImp(UsefulIcrrStationEvent);
00018 
00019 UsefulIcrrStationEvent::UsefulIcrrStationEvent() 
00020 {
00021    //Default Constructor
00022   fCalibrator=0;
00023 }
00024 
00025 UsefulIcrrStationEvent::~UsefulIcrrStationEvent() {
00026    //Default Destructor
00027 }
00028 
00029 UsefulIcrrStationEvent::UsefulIcrrStationEvent(RawIcrrStationEvent *rawEvent, AraCalType::AraCalType_t calType)
00030   :RawIcrrStationEvent(*rawEvent)
00031 {
00032   fCalibrator=AraEventCalibrator::Instance();
00033   fCalibrator->calibrateEvent(this,calType);  
00034 }
00035 
00036 TGraph *UsefulIcrrStationEvent::getGraphFromElecChan(int chan)
00037 {
00038   if(chan<0 || chan>=NUM_DIGITIZED_ICRR_CHANNELS)
00039     return NULL;
00040   return new TGraph(fNumPoints[chan],fTimes[chan],fVolts[chan]);
00041 }
00042 
00043 TGraph *UsefulIcrrStationEvent::getGraphFromRFChan(int chan)
00044 {
00045   if(chan<0 || chan>=numRFChans)
00046     return NULL;
00047 
00048   // printf("UsefulIcrrStationEvent::getGraphFromRFChan(int chan) - creating graph ");
00049   // printf("fNumPointsRF[%i] %i, fTimesRF[%i] %i, fVoltsRF[%i] %i\n", chan,fNumPointsRF[chan], chan, fTimesRF[chan], chan, fVoltsRF[chan]);
00050   return new TGraph(fNumPointsRF[chan],fTimesRF[chan],fVoltsRF[chan]);
00051 }
00052 
00053 TGraph *UsefulIcrrStationEvent::getFFTForRFChan(int chan)
00054 {
00055 
00056    //   static AraGeomTool *fGeomTool = AraGeomTool::Instance();
00057    TGraph *gr = getGraphFromRFChan(chan);
00058    if(!gr) return NULL;
00059    Double_t newX[512],newY[512];
00060    Double_t intSample=1;
00061    Int_t maxSamps=256;
00062    // if(fGeomTool->getNumLabChansForChan(chan)==2) {
00063    intSample=0.5;
00064    maxSamps=512;
00065    //   }
00066    
00067 
00068    TGraph *grInt = FFTtools::getInterpolatedGraph(gr,intSample);
00069    
00070 
00071    Int_t numSamps  = grInt->GetN();
00072    Double_t *xVals = grInt->GetX();
00073    Double_t *yVals = grInt->GetY();
00074    for(int i=0;i<maxSamps;i++) {
00075       if(i<numSamps) {
00076          newX[i]=xVals[i];
00077          newY[i]=yVals[i];
00078       }
00079       else {
00080          newX[i]=newX[i-1]+intSample;  
00081          newY[i]=0;
00082       }      
00083   }
00084    TGraph *grNew = new TGraph(maxSamps,newX,newY);
00085    TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew);
00086    delete gr;
00087    delete grNew;
00088    delete grInt;
00089    return grFFT;
00090 }
00091 
00092 TH1D *UsefulIcrrStationEvent::getFFTHistForRFChan(int chan)
00093 {
00094 
00095    Int_t numBins=256;
00096    Double_t minX=0.0;
00097    Double_t maxX=1000.0;
00098    minX = minX - ( (maxX-minX)/numBins/2.0 ); // adjust histogram edges so that the bin centers
00099    maxX = maxX + ( (maxX-minX)/numBins/2.0 ); // of the histograms are aligned with graph [add bdf]
00100    numBins++;
00101    char histName[180];
00102    sprintf(histName,"%s_ffthist",this->GetName());
00103    TH1D *histFFT = new TH1D(histName,histName,numBins,minX,maxX);
00104    if(fillFFTHistoForRFChan(chan,histFFT)==0)
00105       return histFFT;
00106    return NULL;
00107 
00108 }
00109       
00110 int UsefulIcrrStationEvent::fillFFTHistoForRFChan(int chan, TH1D *histFFT) 
00111 {
00112 
00113    TGraph *grFFT =getFFTForRFChan(chan);
00114    if(!grFFT) return -1;
00115    Double_t *xVals=grFFT->GetX();
00116    Double_t *yVals=grFFT->GetY();
00117    Int_t numPoints=grFFT->GetN();
00118    for(int i=0;i<numPoints;i++) {    
00119       histFFT->Fill(xVals[i],yVals[i]);
00120    }
00121    delete grFFT;
00122    return 0;
00123 
00124 }
00125 
00126 int UsefulIcrrStationEvent::guessRCO(int chanIndex)
00127 {
00129   int chip=chanIndex/CHANNELS_PER_LAB3;
00130   if(chip<0 || chip>=LAB3_PER_ICRR) return -1;
00131   static int firstTime=1;
00132   static unsigned int lastEventNumber=0; //random number
00133   static unsigned int lastUnixTimeUs=0; //random number
00134   static int fRcoGuess[LAB3_PER_ICRR]={0};
00135   fCalibrator=AraEventCalibrator::Instance();
00136   if(lastEventNumber!=this->head.eventNumber || firstTime || lastUnixTimeUs!=this->head.unixTimeUs) {
00137     fCalibrator->fillRCOGuessArray(this,fRcoGuess);
00138     lastEventNumber=this->head.eventNumber;
00139     lastUnixTimeUs=this->head.unixTimeUs;
00140     firstTime=0;
00141   }
00142   return fRcoGuess[chip];    
00143 }
00144 
00145 TGraph *UsefulIcrrStationEvent::getFFTForClock(int clock_number)
00146 {
00147 
00148    if ( (clock_number<0) || ( clock_number>2) ) {
00149       return NULL;
00150    }
00151 
00152    int channel_number = clock_number*9+8;
00153    //   static AraGeomTool *fGeomTool = AraGeomTool::Instance();
00154    TGraph *gr = getGraphFromElecChan(channel_number);
00155    if(!gr) return NULL;
00156    Double_t newX[512],newY[512];
00157    Double_t intSample=1.0;
00158    Int_t maxSamps=256;
00159    intSample = 0.5;                   /* interpolation spacing in ns                */
00160    maxSamps  = 512;                   /* number of samples in interpolated waveform */
00161 
00162    TGraph *grInt = FFTtools::getInterpolatedGraph(gr,intSample);
00163 
00164    Int_t numSamps  = grInt->GetN();
00165    Double_t *xVals = grInt->GetX();
00166    Double_t *yVals = grInt->GetY();
00167 // printf("UsefulIcrrStationEvent::getFFTForClock() - intSample = %f - maxSamps = %d - numSamps = %d [%d]\n",intSample,maxSamps,numSamps,grInt->GetN());
00168    for(int i=0;i<maxSamps;i++) {
00169 //    if ( i<numSamps ) {
00170 //       printf("UsefulIcrrStationEvent::getFFTForClock() - i = %d - (x,y) = %.2f,%.2f",i,xVals[i],yVals[i]);
00171 //    } else {
00172 //       printf("UsefulIcrrStationEvent::getFFTForClock() - i = %d - i>numSamps ",i);
00173 //    }
00174       if( i<numSamps ) {
00175 //       printf(" - use point\n");
00176          newX[i]=xVals[i];
00177          newY[i]=yVals[i];
00178       }
00179       else {
00180          newX[i]=newX[i-1]+intSample; 
00181          newY[i]=0;
00182 //       printf(" - zero fill - (x,y) = %.2f,%.2f - previous_x = %.2f\n",newX[i],newY[i],newX[i-1]);
00183       }
00184    }
00185    TGraph *grNew = new TGraph(maxSamps,newX,newY);
00186    TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew);
00187    delete gr;
00188    delete grNew;
00189    delete grInt;
00190    return grFFT;
00191 
00192 } // end of function UsefulIcrrStationEvent::getFFTForClock()
00193 
00194 TH1D *UsefulIcrrStationEvent::getFFTHistForClock(int clock_number)
00195 {
00196 
00197    Int_t numBins=256;
00198    Double_t minX=0.0;
00199    Double_t maxX=1000.0;   
00200    minX = minX - ( (maxX-minX)/numBins/2.0 ); // adjust histogram edges so that the bin centers
00201    maxX = maxX + ( (maxX-minX)/numBins/2.0 ); // of the histograms are aligned with graph [add bdf]
00202    numBins++;
00203    char histName[180];
00204    sprintf(histName,"%s_clock_%2.2dffthist",this->GetName(),clock_number);
00205    TH1D *histFFT = new TH1D(histName,histName,numBins,minX,maxX);
00206    if(fillFFTHistoForClock(clock_number,histFFT)==0)
00207       return histFFT;
00208    return NULL;
00209   
00210 }
00211       
00212 int UsefulIcrrStationEvent::fillFFTHistoForClock(int clock_number, TH1D *histFFT) 
00213 {
00214    TGraph *grFFT = getFFTForClock(clock_number);
00215    if(!grFFT) return -1;
00216    Double_t *xVals=grFFT->GetX();
00217    Double_t *yVals=grFFT->GetY();
00218    Int_t numPoints=grFFT->GetN();
00219    for(int i=0;i<numPoints;i++) {    
00220       histFFT->Fill(xVals[i],yVals[i]);
00221    }
00222    delete grFFT;
00223    return 0;
00224 }
00225 
00226 bool UsefulIcrrStationEvent::isCalPulserEvent( )
00227 {
00228 
00229    bool retcode = false;
00230 
00231    IcrrTriggerMonitor *trig = &(this->trig);
00232    unsigned short msw_clock_counter = trig->rovdd[0];
00233    unsigned short lsw_clock_counter = trig->rovdd[1];
00234 
00235 // printf("UsefulIcrrStationEvent::isCalPulserEvent() - DEBUG - %d %d",msw_clock_counter,lsw_clock_counter);
00236    if ( ( msw_clock_counter == 0 ) &&                                                                /* Rb peak is at msw=0 && lsw=5801+/-5 */
00237         ( TMath::Abs(lsw_clock_counter-5801) < 5 ) ) {
00238 //    printf(" <- is cal pulser\n");
00239       retcode = true;
00240    } else {
00241 //    printf(" <- is *not* cal pulser\n");
00242       retcode = false;
00243    }
00244 
00245    return retcode;
00246 
00247 } // end of UsefulIcrrStationEvent::isCalPulserEvent() member function
00248 

Generated on Wed Aug 8 16:20:07 2012 for ARA ROOT Test Bed Software by doxygen 1.4.7