ARA ROOT v3.8 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   //sprintf(graphTitle,"RF Channel %d (Ant %d)",rfChan+1,rfChan+1);//FIXME
00111   this->SetTitle(graphTitle);
00112 }
00113   
00114   
00115 void AraWaveformGraph::drawInNewCanvas()
00116 {
00117   gStyle->SetTitleH(0.1);
00118   gStyle->SetOptTitle(1);
00119   gStyle->SetPadLeftMargin(0.15);
00120   gStyle->SetPadRightMargin(0.1);
00121   gStyle->SetPadTopMargin(0.1);
00122   gStyle->SetPadBottomMargin(0.1);
00123   gStyle->SetCanvasDefW(600);
00124   gStyle->SetCanvasDefH(400);
00125   //   gROOT->ForceStyle();
00126   AraWaveformGraph *thisCopy = (AraWaveformGraph*)this->Clone();
00127   thisCopy->GetXaxis()->SetLabelSize(0.06);
00128   thisCopy->GetXaxis()->SetTitleSize(0.06);
00129   thisCopy->GetYaxis()->SetLabelSize(0.06);
00130   thisCopy->GetYaxis()->SetTitleSize(0.06);
00131   thisCopy->GetXaxis()->SetTitle("Time (ns)");
00132   thisCopy->GetYaxis()->SetTitle("Voltage (mV-ish)");
00133 
00134 
00135   thisCopy->SetTitle(this->GetTitle());
00136   TCanvas *can = new TCanvas();
00137   can->SetLeftMargin(0.15);
00138   can->SetBottomMargin(0.15);
00139   can->SetTopMargin(0.1);
00140   can->SetRightMargin(0.1);
00141   thisCopy->Draw("al");
00142   //  fNewCanvas=1;
00143   
00144 }
00145 
00146 //______________________________________________________________________________
00147 void AraWaveformGraph::DrawFFT()
00148 {
00149   //  char graphTitle[180];
00150   gStyle->SetTitleH(0.1);
00151   gStyle->SetLabelSize(0.1,"xy");
00152   gStyle->SetTitleSize(0.1,"xy");
00153   gStyle->SetTitleOffset(0.5,"y");
00154   gStyle->SetOptTitle(1);
00155   gStyle->SetCanvasDefW(600);
00156   gStyle->SetCanvasDefH(400);
00157   //   gROOT->ForceStyle();
00158    
00159   TCanvas *can = new TCanvas();
00160   can->SetLeftMargin(0.15);
00161   can->SetBottomMargin(0.15);
00162   can->SetTopMargin(0.1);
00163   can->SetRightMargin(0.1);
00164 
00165   TGraph *grFFT  = this->getFFT();
00166   grFFT->GetXaxis()->SetLabelSize(0.06);
00167   grFFT->GetXaxis()->SetTitleSize(0.06);
00168   grFFT->GetYaxis()->SetLabelSize(0.06);
00169   grFFT->GetYaxis()->SetTitleSize(0.06);
00170   grFFT->GetXaxis()->SetTitle("Frequency (MHz)");
00171   grFFT->GetYaxis()->SetTitle("dB (m maybe)");
00172 
00173   
00174 
00175   grFFT->SetTitle(this->GetTitle());
00176   grFFT->Draw("al");
00177   
00178   //   printf("AraWaveformGraph::DrawFFT: not yet implemented\n");
00179 }
00180 
00181 //______________________________________________________________________________
00182 void AraWaveformGraph::DrawHilbert()
00183 {
00184   //  char graphTitle[180];
00185   gStyle->SetTitleH(0.1);
00186   gStyle->SetLabelSize(0.1,"xy");
00187   gStyle->SetTitleSize(0.1,"xy");
00188   gStyle->SetTitleOffset(0.5,"y");
00189   gStyle->SetOptTitle(1);
00190   gStyle->SetCanvasDefW(600);
00191   gStyle->SetCanvasDefH(400);
00192   //   gROOT->ForceStyle();
00193    
00194   TCanvas *can = new TCanvas();
00195   can->SetLeftMargin(0.15);
00196   can->SetBottomMargin(0.15);
00197   can->SetTopMargin(0.1);
00198   can->SetRightMargin(0.1);
00199 
00200   TGraph *grHilbert  = this->getHilbert();
00201   grHilbert->GetXaxis()->SetLabelSize(0.06);
00202   grHilbert->GetXaxis()->SetTitleSize(0.06);
00203   grHilbert->GetYaxis()->SetLabelSize(0.06);
00204   grHilbert->GetYaxis()->SetTitleSize(0.06);
00205   grHilbert->GetXaxis()->SetTitle("Time (ns)");
00206   grHilbert->GetYaxis()->SetTitle("Voltage^2 (mv^2) ");
00207  
00208   grHilbert->SetTitle(this->GetTitle());
00209   grHilbert->Draw("al");
00210   
00211   //   printf("AraWaveformGraph::DrawFFT: not yet implemented\n");
00212 }
00213 
00214 #define MAX_SAMPLE_VALS 20*64
00215 
00216 TGraph *AraWaveformGraph::getFFT()
00217 {
00218   Int_t numPoints=this->GetN();
00219   Double_t deltaT=this->GetX()[numPoints-1]-this->GetX()[0];
00220   deltaT/=(numPoints-1);
00221 
00222   Double_t newX[MAX_SAMPLE_VALS];
00223   Double_t newY[MAX_SAMPLE_VALS];
00224 
00225 
00226   TGraph *grInt = FFTtools::getInterpolatedGraph(this,deltaT);
00227   Int_t numSamps=grInt->GetN();
00228   Double_t *xVals=grInt->GetX();
00229   Double_t *yVals=grInt->GetY();
00230   for(int i=0;i<MAX_SAMPLE_VALS;i++) {
00231     if(i<numSamps) {
00232       newX[i]=xVals[i];
00233       newY[i]=yVals[i];
00234     }
00235     else {
00236       newX[i]=newX[i-1]+(1.);
00237       newY[i]=0;
00238     }      
00239   }
00240   TGraph *grNew = new TGraph(MAX_SAMPLE_VALS,newX,newY);
00241   TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew);
00242   delete grNew;
00243   delete grInt;
00244   return grFFT;
00245 }
00246 
00247 TH1D *AraWaveformGraph::getFFTHisto() {
00248   TGraph *grFFT =getFFT();
00249   Double_t *xVals=grFFT->GetX();
00250   Double_t *yVals=grFFT->GetY();
00251   Int_t numPoints=grFFT->GetN();
00252   Double_t binWidth=xVals[1]-xVals[0];
00253   char histName[180];
00254   sprintf(histName,"%s_ffthist",this->GetName());
00255   TH1D *histFFT = new TH1D(histName,histName,256,0,1000);
00256   for(int i=0;i<numPoints;i++) {    
00257     histFFT->Fill(xVals[i],yVals[i]);
00258   }
00259   delete grFFT;
00260   return histFFT;
00261 }
00262 
00263 
00264 
00265 
00266 TGraph *AraWaveformGraph::getHilbert()
00267 {
00268   TGraph *grInt = FFTtools::getInterpolatedGraph(this,1./2.6);
00269   TGraph *grHilbert = FFTtools::getHilbertEnvelope(grInt);
00270   delete grInt;
00271   return grHilbert;
00272 }
00273 
00274 void AraWaveformGraph::AddToCorrelation()
00275 {
00276   AraCorrelationFactory::Instance()->addWaveformToCorrelation(this);
00277 }

Generated on Mon Jun 3 14:59:45 2013 for ARA ROOT v3.8 Software by doxygen 1.4.7