AraEvent/UsefulAtriStationEvent.cxx
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 #include "UsefulAtriStationEvent.h" 00011 #include "AraEventCalibrator.h" 00012 #include "FFTtools.h" 00013 #include "AraGeomTool.h" 00014 #include "TH1.h" 00015 #include <iostream> 00016 #include <fstream> 00017 #include <cstring> 00018 ClassImp(UsefulAtriStationEvent); 00019 00020 AraEventCalibrator *fCalibrator; 00021 00022 UsefulAtriStationEvent::UsefulAtriStationEvent() 00023 { 00024 //Default Constructor 00025 fNumChannels=0; 00026 fCalibrator=0; 00027 } 00028 00029 UsefulAtriStationEvent::~UsefulAtriStationEvent() { 00030 //Default Destructor 00031 fNumChannels=0; 00032 fCalibrator=0; 00033 } 00034 00035 UsefulAtriStationEvent::UsefulAtriStationEvent(RawAtriStationEvent *rawEvent, AraCalType::AraCalType_t calType) 00036 :RawAtriStationEvent(*rawEvent) 00037 { 00038 fCalibrator=AraEventCalibrator::Instance(); 00039 fNumChannels=0; 00040 fCalibrator->calibrateEvent(this,calType); 00041 // fprintf(stderr, "UsefulAtriStationEvent::UsefulAtriStationEvent() -- finished constructing event\n"); //DEBUG 00042 00043 } 00044 00045 00046 TGraph *UsefulAtriStationEvent::getGraphFromElecChan(int chanId) 00047 { 00048 std::map< Int_t, std::vector <Double_t> >::iterator timeMapIt; 00049 timeMapIt=fTimes.find(chanId); 00050 if(timeMapIt==fTimes.end()) { 00051 // This channel doesn't exist. We don't return a null pointer, 00052 // we return an empty graph. 00053 // RJN should fix this as it is a silly id 00054 return new TGraph; 00055 } 00056 00057 TGraph *gr = new TGraph(fTimes[chanId].size(),&(fTimes[chanId][0]),&(fVolts[chanId][0])); 00058 00059 //Why do we need to sort the array. Shouldn't this be done in AraEventCalibrator?? 00060 gr->Sort(); 00061 00062 return gr; 00063 } 00064 00065 TGraph *UsefulAtriStationEvent::getGraphFromRFChan(int chan) 00066 { 00067 Int_t rfChan = AraGeomTool::Instance()->getElecChanFromRFChan(chan,stationId); 00068 if(rfChan < 0){ 00069 return NULL; 00070 } 00071 00072 return getGraphFromElecChan(rfChan); 00073 } 00074 00075 00076 TGraph *UsefulAtriStationEvent::getFFTForRFChan(int chan) 00077 { 00078 00079 // static AraGeomTool *fGeomTool = AraGeomTool::Instance(); 00080 TGraph *gr = getGraphFromRFChan(chan); 00081 if(!gr) return NULL; 00082 Double_t newX[512],newY[512]; 00083 Double_t intSample=1; 00084 Int_t maxSamps=256; 00085 // if(fGeomTool->getNumLabChansForChan(chan)==2) { 00086 intSample=0.5; 00087 maxSamps=512; 00088 // } 00089 00090 00091 TGraph *grInt = FFTtools::getInterpolatedGraph(gr,intSample); 00092 00093 00094 Int_t numSamps = grInt->GetN(); 00095 Double_t *xVals = grInt->GetX(); 00096 Double_t *yVals = grInt->GetY(); 00097 for(int i=0;i<maxSamps;i++) { 00098 if(i<numSamps) { 00099 newX[i]=xVals[i]; 00100 newY[i]=yVals[i]; 00101 } 00102 else { 00103 newX[i]=newX[i-1]+intSample; 00104 newY[i]=0; 00105 } 00106 } 00107 TGraph *grNew = new TGraph(maxSamps,newX,newY); 00108 TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew); 00109 delete gr; 00110 delete grNew; 00111 delete grInt; 00112 return grFFT; 00113 } 00114 00115 00116 TH1D *UsefulAtriStationEvent::getFFTHistForRFChan(int chan) 00117 { 00118 00119 Int_t numBins=256; 00120 Double_t minX=0.0; 00121 Double_t maxX=1000.0; 00122 minX = minX - ( (maxX-minX)/numBins/2.0 ); // adjust histogram edges so that the bin centers 00123 maxX = maxX + ( (maxX-minX)/numBins/2.0 ); // of the histograms are aligned with graph [add bdf] 00124 numBins++; 00125 char histName[180]; 00126 sprintf(histName,"%s_ffthist",this->GetName()); 00127 TH1D *histFFT = new TH1D(histName,histName,numBins,minX,maxX); 00128 if(fillFFTHistoForRFChan(chan,histFFT)==0) 00129 return histFFT; 00130 return NULL; 00131 00132 } 00133 00134 int UsefulAtriStationEvent::fillFFTHistoForRFChan(int chan, TH1D *histFFT) 00135 { 00136 00137 TGraph *grFFT =getFFTForRFChan(chan); 00138 if(!grFFT) return -1; 00139 Double_t *xVals=grFFT->GetX(); 00140 Double_t *yVals=grFFT->GetY(); 00141 Int_t numPoints=grFFT->GetN(); 00142 for(int i=0;i<numPoints;i++) { 00143 histFFT->Fill(xVals[i],yVals[i]); 00144 } 00145 delete grFFT; 00146 return 0; 00147 00148 } 00149
Generated on Mon Jun 3 14:59:46 2013 for ARA ROOT v3.8 Software by
