ARA ROOT v3.9 Software

AraDisplay/AraWaveformGraph.cxx

00001 #include "AraWaveformGraph.h"
00002 #include "AraCorrelationFactory.h"
00003 #include "AraGeomTool.h"
00004 #include "TButton.h"
00005 #include "TList.h"
00006 #include "TCanvas.h"
00007 #include "TStyle.h"
00008 #include "TH1.h"
00009 #include "TAxis.h"
00010 #include <iostream>
00011 using namespace std;
00012 
00013 #include "FFTtools.h"
00014 
00015 
00016 ClassImp(AraWaveformGraph);
00017 
00018 AraWaveformGraph::AraWaveformGraph()
00019 
00020   : TGraph(),fElecChan(-1),fRFChan(-1),fNewCanvas(0)
00021     
00022 {
00023   this->SetEditable(kFALSE);
00024 }
00025 
00026 
00027 AraWaveformGraph::AraWaveformGraph(int N, const Int_t *x, const Int_t *y)
00028 
00029   : TGraph(N,x,y),fElecChan(-1),fRFChan(-1),fNewCanvas(0)
00030 {
00031   this->SetEditable(kFALSE);
00032 }
00033 
00034 AraWaveformGraph::AraWaveformGraph(int N, const Float_t *x, const Float_t *y)
00035 
00036   : TGraph(N,x,y),fElecChan(-1),fRFChan(-1),fNewCanvas(0)
00037 {
00038   this->SetEditable(kFALSE);
00039 }
00040 
00041 AraWaveformGraph::AraWaveformGraph(int N, const Double_t *x, const Double_t *y)
00042 
00043   : TGraph(N,x,y),fElecChan(-1),fRFChan(-1),fNewCanvas(0)
00044 {  
00045   this->SetEditable(kFALSE);
00046 }
00047 
00048 AraWaveformGraph::~AraWaveformGraph()
00049 {
00050    //   std::cout << "~AraWaveformGraph" << std::endl;
00051 }
00052 
00053 void AraWaveformGraph::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00054 {
00055   static int keyWasPressed=0;
00056    switch (event) {
00057    case kKeyPress:
00058      //     std::cout << "kKeyPress" << std::endl;
00059      keyWasPressed=1;
00060      break;
00061    case kButtonPress:
00062      //     cout << "kButtonPress" << endl;
00063      break;
00064      
00065    case kButton1Double:
00066      //     std::cout << "kButtonDoubleClick" << std::endl;
00067      //     new TCanvas();
00068      break;
00069 
00070    case kButton1Down:
00071      //     std::cout << "kButton1Down" << std::endl;
00072      if(!keyWasPressed) {
00073        if(!fNewCanvas) drawInNewCanvas();
00074        else this->TGraph::ExecuteEvent(event,px,py);
00075      }
00076      else {
00077        //       std::cout << "ctrl + click\n";
00078        AraCorrelationFactory::Instance()->addWaveformToCorrelation(this);
00079        keyWasPressed=0;
00080      }
00081 
00082      break;
00083           
00084    default:
00085        this->TGraph::ExecuteEvent(event,px,py);
00086        break;
00087    }
00088 }
00089 
00090 void AraWaveformGraph::setElecChan(int elecChan)
00091 {
00092   fElecChan=elecChan;
00093   char graphName[180];
00094   sprintf(graphName,"grElec%d",elecChan);
00095   this->SetName(graphName);
00096   char graphTitle[180];
00097   sprintf(graphTitle,"Raw Electronics Channel %d",elecChan+1);
00098   this->SetTitle(graphTitle);
00099   
00100 }
00101 
00102 void AraWaveformGraph::setRFChan(int rfChan, int stationId)
00103 {
00104   fRFChan=rfChan;
00105   char graphName[180];
00106   sprintf(graphName,"grRFChan%d",rfChan);
00107   this->SetName(graphName);
00108   char graphTitle[180];
00109   sprintf(graphTitle,"RF Channel %d (Ant %s)",rfChan+1,AraGeomTool::Instance()->getStationInfo(stationId)->getAntennaInfo(rfChan)->designator);
00110   this->SetTitle(graphTitle);
00111 }
00112   
00113   
00114 void AraWaveformGraph::drawInNewCanvas()
00115 {
00116   gStyle->SetTitleH(0.1);
00117   gStyle->SetOptTitle(1);
00118   gStyle->SetPadLeftMargin(0.15);
00119   gStyle->SetPadRightMargin(0.1);
00120   gStyle->SetPadTopMargin(0.1);
00121   gStyle->SetPadBottomMargin(0.1);
00122   gStyle->SetCanvasDefW(600);
00123   gStyle->SetCanvasDefH(400);
00124   //   gROOT->ForceStyle();
00125   AraWaveformGraph *thisCopy = (AraWaveformGraph*)this->Clone();
00126   thisCopy->GetXaxis()->SetLabelSize(0.06);
00127   thisCopy->GetXaxis()->SetTitleSize(0.06);
00128   thisCopy->GetYaxis()->SetLabelSize(0.06);
00129   thisCopy->GetYaxis()->SetTitleSize(0.06);
00130   thisCopy->GetXaxis()->SetTitle("Time (ns)");
00131   thisCopy->GetYaxis()->SetTitle("Voltage (mV-ish)");
00132 
00133 
00134   thisCopy->SetTitle(this->GetTitle());
00135   TCanvas *can = new TCanvas();
00136   can->SetLeftMargin(0.15);
00137   can->SetBottomMargin(0.15);
00138   can->SetTopMargin(0.1);
00139   can->SetRightMargin(0.1);
00140   thisCopy->Draw("al");
00141   //  fNewCanvas=1;
00142   
00143 }
00144 
00145 //______________________________________________________________________________
00146 void AraWaveformGraph::DrawFFT()
00147 {
00148   //  char graphTitle[180];
00149   gStyle->SetTitleH(0.1);
00150   gStyle->SetLabelSize(0.1,"xy");
00151   gStyle->SetTitleSize(0.1,"xy");
00152   gStyle->SetTitleOffset(0.5,"y");
00153   gStyle->SetOptTitle(1);
00154   gStyle->SetCanvasDefW(600);
00155   gStyle->SetCanvasDefH(400);
00156   //   gROOT->ForceStyle();
00157    
00158   TCanvas *can = new TCanvas();
00159   can->SetLeftMargin(0.15);
00160   can->SetBottomMargin(0.15);
00161   can->SetTopMargin(0.1);
00162   can->SetRightMargin(0.1);
00163 
00164   TGraph *grFFT  = this->getFFT();
00165   grFFT->GetXaxis()->SetLabelSize(0.06);
00166   grFFT->GetXaxis()->SetTitleSize(0.06);
00167   grFFT->GetYaxis()->SetLabelSize(0.06);
00168   grFFT->GetYaxis()->SetTitleSize(0.06);
00169   grFFT->GetXaxis()->SetTitle("Frequency (MHz)");
00170   grFFT->GetYaxis()->SetTitle("dB (m maybe)");
00171 
00172   
00173 
00174   grFFT->SetTitle(this->GetTitle());
00175   grFFT->Draw("al");
00176   
00177   //   printf("AraWaveformGraph::DrawFFT: not yet implemented\n");
00178 }
00179 
00180 //______________________________________________________________________________
00181 void AraWaveformGraph::DrawHilbert()
00182 {
00183   //  char graphTitle[180];
00184   gStyle->SetTitleH(0.1);
00185   gStyle->SetLabelSize(0.1,"xy");
00186   gStyle->SetTitleSize(0.1,"xy");
00187   gStyle->SetTitleOffset(0.5,"y");
00188   gStyle->SetOptTitle(1);
00189   gStyle->SetCanvasDefW(600);
00190   gStyle->SetCanvasDefH(400);
00191   //   gROOT->ForceStyle();
00192    
00193   TCanvas *can = new TCanvas();
00194   can->SetLeftMargin(0.15);
00195   can->SetBottomMargin(0.15);
00196   can->SetTopMargin(0.1);
00197   can->SetRightMargin(0.1);
00198 
00199   TGraph *grHilbert  = this->getHilbert();
00200   grHilbert->GetXaxis()->SetLabelSize(0.06);
00201   grHilbert->GetXaxis()->SetTitleSize(0.06);
00202   grHilbert->GetYaxis()->SetLabelSize(0.06);
00203   grHilbert->GetYaxis()->SetTitleSize(0.06);
00204   grHilbert->GetXaxis()->SetTitle("Time (ns)");
00205   grHilbert->GetYaxis()->SetTitle("Voltage^2 (mv^2) ");
00206  
00207   grHilbert->SetTitle(this->GetTitle());
00208   grHilbert->Draw("al");
00209   
00210   //   printf("AraWaveformGraph::DrawFFT: not yet implemented\n");
00211 }
00212 
00213 #define MAX_SAMPLE_VALS 20*64
00214 
00215 TGraph *AraWaveformGraph::getFFT()
00216 {
00217   Int_t numPoints=this->GetN();
00218   Double_t deltaT=this->GetX()[numPoints-1]-this->GetX()[0];
00219   deltaT/=(numPoints-1);
00220 
00221   Double_t newX[MAX_SAMPLE_VALS];
00222   Double_t newY[MAX_SAMPLE_VALS];
00223 
00224 
00225   TGraph *grInt = FFTtools::getInterpolatedGraph(this,deltaT);
00226   Int_t numSamps=grInt->GetN();
00227   Double_t *xVals=grInt->GetX();
00228   Double_t *yVals=grInt->GetY();
00229   for(int i=0;i<MAX_SAMPLE_VALS;i++) {
00230     if(i<numSamps) {
00231       newX[i]=xVals[i];
00232       newY[i]=yVals[i];
00233     }
00234     else {
00235       newX[i]=newX[i-1]+(1.);
00236       newY[i]=0;
00237     }      
00238   }
00239   TGraph *grNew = new TGraph(MAX_SAMPLE_VALS,newX,newY);
00240   TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew);
00241   delete grNew;
00242   delete grInt;
00243   return grFFT;
00244 }
00245 
00246 TH1D *AraWaveformGraph::getFFTHisto() {
00247   TGraph *grFFT =getFFT();
00248   Double_t *xVals=grFFT->GetX();
00249   Double_t *yVals=grFFT->GetY();
00250   Int_t numPoints=grFFT->GetN();
00251   Double_t binWidth=xVals[1]-xVals[0];
00252   char histName[180];
00253   sprintf(histName,"%s_ffthist",this->GetName());
00254   TH1D *histFFT = new TH1D(histName,histName,256,0,1000);
00255   for(int i=0;i<numPoints;i++) {    
00256     histFFT->Fill(xVals[i],yVals[i]);
00257   }
00258   delete grFFT;
00259   return histFFT;
00260 }
00261 
00262 
00263 
00264 
00265 TGraph *AraWaveformGraph::getHilbert()
00266 {
00267   TGraph *grInt = FFTtools::getInterpolatedGraph(this,1./2.6);
00268   TGraph *grHilbert = FFTtools::getHilbertEnvelope(grInt);
00269   delete grInt;
00270   return grHilbert;
00271 }
00272 
00273 void AraWaveformGraph::AddToCorrelation()
00274 {
00275   AraCorrelationFactory::Instance()->addWaveformToCorrelation(this);
00276 }

Generated on Mon Jun 3 16:10:04 2013 for ARA ROOT v3.9 Software by doxygen 1.4.7