ARA ROOT Test BEd Software

AraEvent/UsefulAraEvent.cxx

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

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