ARA ROOT Test BEd Software

analysis/combineFFTHistos.cxx

00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 //Includes
00010 #include <iostream>
00011 
00012 #include "TFile.h"
00013 #include "TTree.h"
00014 #include "TH1.h"
00015 #include "TH1D.h"
00016 #include "TH2.h"
00017 #include "TH2D.h"
00018 #include "TCanvas.h"
00019 
00020 #include "araDefines.h"
00021 
00022 //Global variabls
00023 TH2D *fftAvTime[RFCHANS_PER_STATION];
00024 
00025 int main(int argc, char **argv){
00026 
00027   if(argc<2) {
00028     std::cout << "Usage\n" << argv[0] << " <input file> \n";
00029     std::cout << "e.g.\n" << argv[0] << " L2Histos.root summaryHisto.root\n";
00030     return 0;
00031   }
00032 
00033   TFile *fpIn = TFile::Open(argv[1], "UPDATE");
00034   
00035   //  fpIn->ls();
00036 
00037   TTree *mapTree = (TTree*) fpIn->Get("mapTimes");
00038   if(!mapTree) {
00039     std::cerr << "Can't find map Tree\n";
00040     return -1;
00041   }
00042 
00043   Long64_t histoTime=0;
00044   mapTree->SetBranchAddress("histoTime", &histoTime);
00045   Long64_t numEntries = mapTree->GetEntries();
00046   Long64_t minT=0, maxT=0;
00047   mapTree->GetEntry(0);
00048   minT=histoTime;
00049   mapTree->GetEntry(numEntries-1);
00050   maxT=histoTime;
00051 
00052   TH1D *tempHisto;
00053 
00054   //Create the output histogram
00055 
00056   char outHistoName[260];
00057   Int_t numBinsF=256;
00058   Double_t minF=0.0;
00059   Double_t maxF=1000.0;
00060   minF = minF - ( (maxF-minF)/numBinsF/2.0 ); // adjust histogram edges so that the bin centers
00061   maxF = maxF + ( (maxF-minF)/numBinsF/2.0 ); // of the histograms are aligned with graph [add bdf]
00062   numBinsF++;
00063   
00064   Long64_t numBinsT=numEntries;
00065     
00066   //  printf("minT %llu maxT %llu numBinsT %llu\n", minT, maxT, numBinsT);
00067 
00068   //  TFile *fpOut = new TFile(argv[2], "RECREATE");
00069 
00070   for(int antenna=0;antenna<RFCHANS_PER_STATION;antenna++){
00071     sprintf(outHistoName, "average_vTime_fft_antenna_%i", antenna);
00072     //    printf("average_vTime_fft_antenna_%i\n", antenna);
00073     
00074     fftAvTime[antenna] = new TH2D(outHistoName, outHistoName, numBinsT, minT, maxT, numBinsF, minF, maxF);
00075     
00076   }
00077 
00078 
00079 
00080   for(int entry=0; entry < numEntries; entry++){
00081 
00082     mapTree->GetEntry(entry);
00083     //    printf("entry %i histoTime %llu\n", entry, histoTime);
00084     for(int antenna=0; antenna<RFCHANS_PER_STATION; antenna++){
00085       char histoDir[260];
00086       char histoName[260];
00087       sprintf(histoDir, "time_%llu", histoTime);
00088       // sprintf(histoName, "average_fft_antenna_%i", antenna );
00089 
00090       sprintf(histoName, "time_%llu/average_fft_antenna_%i", histoTime, antenna );
00091       //      tempHisto = (TH1D*) fpIn->GetDirectory(histoDir)->Get(histoName);
00092       tempHisto = (TH1D*) fpIn->Get(histoName);
00093       if(tempHisto){
00094 
00095         //      std::cerr << "A\n";
00096         //process the histo
00097         for(int bin=2; bin<tempHisto->GetNbinsX()+1;bin++){
00098           Double_t binContent = tempHisto->GetBinContent(bin);
00099           Double_t binCenter =  tempHisto->GetBinCenter(bin);
00100           //      printf("histoTime %llu binContent %e binCenter %e\n",histoTime, binCenter, binContent);
00101 
00102           fftAvTime[antenna]->Fill(histoTime, binCenter, binContent);
00103         }
00104           
00105       }
00106 
00107     }
00108   }
00109 
00110  for(int antenna=0;antenna<RFCHANS_PER_STATION;antenna++){
00111     if(fftAvTime[antenna]){
00112       //      printf("%s\n", fftAvTime[antenna]->GetName());
00113       fftAvTime[antenna]->Write();
00114       fftAvTime[antenna]->GetXaxis()->SetTimeDisplay(1);
00115   }
00116     else printf("histo not present\n");
00117   }
00118 
00119   
00120   TCanvas *canHPol= new TCanvas("HPolSummary", "HPolSummary");
00121   TCanvas *canVPol=new TCanvas("VPolSummary", "VPolSummary");
00122 
00123   canHPol->Divide(4,2);
00124   canVPol->Divide(4,2);
00125 
00126   canHPol->cd(1);
00127   fftAvTime[0]->Draw("COLZ");
00128   canHPol->cd(2);
00129   fftAvTime[1]->Draw("COLZ");
00130   canHPol->cd(3);
00131   fftAvTime[5]->Draw("COLZ");
00132   canHPol->cd(4);
00133   fftAvTime[7]->Draw("COLZ");
00134   canHPol->cd(5);
00135   fftAvTime[9]->Draw("COLZ");
00136   canHPol->cd(6);
00137   fftAvTime[11]->Draw("COLZ");
00138   canHPol->cd(7);
00139   fftAvTime[12]->Draw("COLZ");
00140   canHPol->cd(8);
00141   fftAvTime[13]->Draw("COLZ");
00142   canVPol->cd(1);
00143   fftAvTime[2]->Draw("COLZ");
00144   canVPol->cd(2);
00145   fftAvTime[3]->Draw("COLZ");
00146   canVPol->cd(3);
00147   fftAvTime[4]->Draw("COLZ");
00148   canVPol->cd(4);
00149   fftAvTime[6]->Draw("COLZ");
00150   canVPol->cd(5);
00151   fftAvTime[8]->Draw("COLZ");
00152   canVPol->cd(6);
00153   fftAvTime[10]->Draw("COLZ");
00154   canVPol->Write();  
00155   canHPol->Write();  
00156 
00157 
00158 
00159  
00160 
00161    fpIn->Close();
00162 
00163 
00164 
00165 
00166   return 0;
00167 }

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