ARA ROOT v3.13 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 
00037 TGraph *UsefulIcrrStationEvent::getGraphFromElecChan(int chan)
00038 {
00039   if(chan<0 || chan>=NUM_DIGITIZED_ICRR_CHANNELS)
00040     return NULL;
00041   return new TGraph(fNumPoints[chan],fTimes[chan],fVolts[chan]);
00042 }
00043 
00044 TGraph *UsefulIcrrStationEvent::getGraphFromRFChan(int chan)
00045 {
00046   if(chan<0 || chan>=numRFChans)
00047     return NULL;
00048 
00049   // printf("UsefulIcrrStationEvent::getGraphFromRFChan(int chan) - creating graph ");
00050   // printf("fNumPointsRF[%i] %i, fTimesRF[%i] %i, fVoltsRF[%i] %i\n", chan,fNumPointsRF[chan], chan, fTimesRF[chan], chan, fVoltsRF[chan]);
00051   return new TGraph(fNumPointsRF[chan],fTimesRF[chan],fVoltsRF[chan]);
00052 }
00053 
00054 TGraph *UsefulIcrrStationEvent::getFFTForRFChan(int chan)
00055 {
00056 
00057    //   static AraGeomTool *fGeomTool = AraGeomTool::Instance();
00058    TGraph *gr = getGraphFromRFChan(chan);
00059    if(!gr) return NULL;
00060    Double_t newX[512],newY[512];
00061    Double_t intSample=1;
00062    Int_t maxSamps=256;
00063    // if(fGeomTool->getNumLabChansForChan(chan)==2) {
00064    intSample=0.5;
00065    maxSamps=512;
00066    //   }
00067    
00068 
00069    TGraph *grInt = FFTtools::getInterpolatedGraph(gr,intSample);
00070    
00071 
00072    Int_t numSamps  = grInt->GetN();
00073    Double_t *xVals = grInt->GetX();
00074    Double_t *yVals = grInt->GetY();
00075    for(int i=0;i<maxSamps;i++) {
00076       if(i<numSamps) {
00077          newX[i]=xVals[i];
00078          newY[i]=yVals[i];
00079       }
00080       else {
00081          newX[i]=newX[i-1]+intSample;  
00082          newY[i]=0;
00083       }      
00084   }
00085    TGraph *grNew = new TGraph(maxSamps,newX,newY);
00086    TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew);
00087    delete gr;
00088    delete grNew;
00089    delete grInt;
00090    return grFFT;
00091 }
00092 
00093 TH1D *UsefulIcrrStationEvent::getFFTHistForRFChan(int chan)
00094 {
00095 
00096    Int_t numBins=256;
00097    Double_t minX=0.0;
00098    Double_t maxX=1000.0;
00099    minX = minX - ( (maxX-minX)/numBins/2.0 ); // adjust histogram edges so that the bin centers
00100    maxX = maxX + ( (maxX-minX)/numBins/2.0 ); // of the histograms are aligned with graph [add bdf]
00101    numBins++;
00102    char histName[180];
00103    sprintf(histName,"%s_ffthist",this->GetName());
00104    TH1D *histFFT = new TH1D(histName,histName,numBins,minX,maxX);
00105    if(fillFFTHistoForRFChan(chan,histFFT)==0)
00106       return histFFT;
00107    return NULL;
00108 
00109 }
00110       
00111 int UsefulIcrrStationEvent::fillFFTHistoForRFChan(int chan, TH1D *histFFT) 
00112 {
00113 
00114    TGraph *grFFT =getFFTForRFChan(chan);
00115    if(!grFFT) return -1;
00116    Double_t *xVals=grFFT->GetX();
00117    Double_t *yVals=grFFT->GetY();
00118    Int_t numPoints=grFFT->GetN();
00119    for(int i=0;i<numPoints;i++) {    
00120       histFFT->Fill(xVals[i],yVals[i]);
00121    }
00122    delete grFFT;
00123    return 0;
00124 
00125 }
00126 
00127 int UsefulIcrrStationEvent::guessRCO(int chanIndex)
00128 {
00130   int chip=chanIndex/CHANNELS_PER_LAB3;
00131   if(chip<0 || chip>=LAB3_PER_ICRR) return -1;
00132   static int firstTime=1;
00133   static unsigned int lastEventNumber=0; //random number
00134   static unsigned int lastUnixTimeUs=0; //random number
00135   static int fRcoGuess[LAB3_PER_ICRR]={0};
00136   fCalibrator=AraEventCalibrator::Instance();
00137   if(lastEventNumber!=this->head.eventNumber || firstTime || lastUnixTimeUs!=this->head.unixTimeUs) {
00138     fCalibrator->fillRCOGuessArray(this,fRcoGuess);
00139     lastEventNumber=this->head.eventNumber;
00140     lastUnixTimeUs=this->head.unixTimeUs;
00141     firstTime=0;
00142   }
00143   return fRcoGuess[chip];    
00144 }
00145 
00146 TGraph *UsefulIcrrStationEvent::getFFTForClock(int clock_number)
00147 {
00148 
00149    if ( (clock_number<0) || ( clock_number>2) ) {
00150       return NULL;
00151    }
00152 
00153    int channel_number = clock_number*9+8;
00154    //   static AraGeomTool *fGeomTool = AraGeomTool::Instance();
00155    TGraph *gr = getGraphFromElecChan(channel_number);
00156    if(!gr) return NULL;
00157    Double_t newX[512],newY[512];
00158    Double_t intSample=1.0;
00159    Int_t maxSamps=256;
00160    intSample = 0.5;                   /* interpolation spacing in ns                */
00161    maxSamps  = 512;                   /* number of samples in interpolated waveform */
00162 
00163    TGraph *grInt = FFTtools::getInterpolatedGraph(gr,intSample);
00164 
00165    Int_t numSamps  = grInt->GetN();
00166    Double_t *xVals = grInt->GetX();
00167    Double_t *yVals = grInt->GetY();
00168 // printf("UsefulIcrrStationEvent::getFFTForClock() - intSample = %f - maxSamps = %d - numSamps = %d [%d]\n",intSample,maxSamps,numSamps,grInt->GetN());
00169    for(int i=0;i<maxSamps;i++) {
00170 //    if ( i<numSamps ) {
00171 //       printf("UsefulIcrrStationEvent::getFFTForClock() - i = %d - (x,y) = %.2f,%.2f",i,xVals[i],yVals[i]);
00172 //    } else {
00173 //       printf("UsefulIcrrStationEvent::getFFTForClock() - i = %d - i>numSamps ",i);
00174 //    }
00175       if( i<numSamps ) {
00176 //       printf(" - use point\n");
00177          newX[i]=xVals[i];
00178          newY[i]=yVals[i];
00179       }
00180       else {
00181          newX[i]=newX[i-1]+intSample; 
00182          newY[i]=0;
00183 //       printf(" - zero fill - (x,y) = %.2f,%.2f - previous_x = %.2f\n",newX[i],newY[i],newX[i-1]);
00184       }
00185    }
00186    TGraph *grNew = new TGraph(maxSamps,newX,newY);
00187    TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew);
00188    delete gr;
00189    delete grNew;
00190    delete grInt;
00191    return grFFT;
00192 
00193 } // end of function UsefulIcrrStationEvent::getFFTForClock()
00194 
00195 TH1D *UsefulIcrrStationEvent::getFFTHistForClock(int clock_number)
00196 {
00197 
00198    Int_t numBins=256;
00199    Double_t minX=0.0;
00200    Double_t maxX=1000.0;   
00201    minX = minX - ( (maxX-minX)/numBins/2.0 ); // adjust histogram edges so that the bin centers
00202    maxX = maxX + ( (maxX-minX)/numBins/2.0 ); // of the histograms are aligned with graph [add bdf]
00203    numBins++;
00204    char histName[180];
00205    sprintf(histName,"%s_clock_%2.2dffthist",this->GetName(),clock_number);
00206    TH1D *histFFT = new TH1D(histName,histName,numBins,minX,maxX);
00207    if(fillFFTHistoForClock(clock_number,histFFT)==0)
00208       return histFFT;
00209    return NULL;
00210   
00211 }
00212       
00213 int UsefulIcrrStationEvent::fillFFTHistoForClock(int clock_number, TH1D *histFFT) 
00214 {
00215    TGraph *grFFT = getFFTForClock(clock_number);
00216    if(!grFFT) return -1;
00217    Double_t *xVals=grFFT->GetX();
00218    Double_t *yVals=grFFT->GetY();
00219    Int_t numPoints=grFFT->GetN();
00220    for(int i=0;i<numPoints;i++) {    
00221       histFFT->Fill(xVals[i],yVals[i]);
00222    }
00223    delete grFFT;
00224    return 0;
00225 }
00226 
00227 bool UsefulIcrrStationEvent::isCalPulserEvent( )
00228 {
00229 
00230    bool retcode = false;
00231 
00232    IcrrTriggerMonitor *trig = &(this->trig);
00233    unsigned short msw_clock_counter = trig->rovdd[0];
00234    unsigned short lsw_clock_counter = trig->rovdd[1];
00235 
00236 // printf("UsefulIcrrStationEvent::isCalPulserEvent() - DEBUG - %d %d",msw_clock_counter,lsw_clock_counter);
00237    if ( ( msw_clock_counter == 0 ) &&                                                                /* Rb peak is at msw=0 && lsw=5801+/-5 */
00238         ( TMath::Abs(lsw_clock_counter-5801) < 25 ) ) {
00239 //    printf(" <- is cal pulser\n");
00240       retcode = true;
00241    } else {
00242 //    printf(" <- is *not* cal pulser\n");
00243       retcode = false;
00244    }
00245 
00246    return retcode;
00247 
00248 } // end of UsefulIcrrStationEvent::isCalPulserEvent() member function
00249 
00250 bool UsefulIcrrStationEvent::shortWaveform()
00251 {
00252 
00253   //Check to see if the hitbus is OK
00254   for(int chip=0; chip<LAB3_PER_ICRR; chip++){
00255     Int_t firstHitBus = this->getFirstHitBus(chip*CHANNELS_PER_LAB3+8);
00256     Int_t lastHitBus = this->getLastHitBus(chip*CHANNELS_PER_LAB3+8);
00257 
00258     if(this->getWrappedHitBus(chip*CHANNELS_PER_LAB3+8)){
00259       if(lastHitBus - firstHitBus < 246)
00260         {
00261           return true;
00262         }
00263     }
00264     else{
00265       if(lastHitBus - firstHitBus > 10)
00266         {
00267           return true;
00268         }
00269 
00270     }//if-else wrapped
00271 
00272   }//chip
00273 
00274   return false;
00275 
00276 }
00277 
00278 bool UsefulIcrrStationEvent::shortWaveform(Int_t labChip)
00279 {
00280 
00281   //Check to see if the hitbus is OK
00282   Int_t firstHitBus = this->getFirstHitBus(labChip*CHANNELS_PER_LAB3+8);
00283   Int_t lastHitBus = this->getLastHitBus(labChip*CHANNELS_PER_LAB3+8);
00284   bool isShort=false;
00285   if(this->getWrappedHitBus(labChip*CHANNELS_PER_LAB3+8)){
00286     if(lastHitBus - firstHitBus < 246)
00287       {
00288         //      std::cerr << "UsefulIcrrStationEvent::shortWaveform(Int_t labChip = " << labChip << ") : bad hit bus\n";
00289         isShort = true;
00290       }
00291   }
00292   else{
00293     if(lastHitBus - firstHitBus > 10)
00294       {
00295         //      std::cerr << "UsefulIcrrStationEvent::shortWaveform(Int_t labChip = " << labChip << ") : bad hit bus\n";
00296         isShort = true;
00297       }
00298     
00299   }//if-else wrapped
00300   
00301 
00302   return isShort;
00303 
00304 }
00305 

Generated on Mon Dec 9 13:20:21 2013 for ARA ROOT v3.13 Software by doxygen 1.4.7