ARA ROOT Test BEd Software

analysis/pulserResponse.cxx

00001 //pulserResponse.cxx - Make histos of peak cross corr time between pairs of channels for pulser events
00002 
00003 //Includes
00004 #include <iostream>
00005 #include <fstream>
00006 #include <cmath>
00007 
00008 //AraRoot Includes
00009 #include "UsefulAraEvent.h"
00010 #include "RawAraEvent.h"
00011 #include "AraEventCalibrator.h"
00012 #include "FFTtools.h"
00013 
00014 
00015 //ROOT Includes
00016 #include "TTree.h"
00017 #include "TFile.h"
00018 #include "TGraph.h"
00019 #include "TF1.h"
00020 #include "TH1.h"
00021 #include "TH2.h"
00022 #include "TCanvas.h"
00023 #include "TChain.h"
00024 
00025 
00026 using namespace std;
00027 
00028 
00029 int pulserResponse(char rootDir[260], int minRun, int maxRun, char outDir[260], char nameOptions[260], int calibType)
00030 {
00031 
00032   char outName[260];
00033   if(calibType==0)
00034     sprintf(outName, "%s/pulserResponse_%s_kLatestCalib.root", outDir, nameOptions);
00035   if(calibType==1)
00036     sprintf(outName, "%s/pulserResponse_%s_kFirstCalibPlusCables.root", outDir, nameOptions);
00037   if(calibType==2)
00038     sprintf(outName, "%s/pulserResponse_%s_kFirstCalib.root", outDir, nameOptions);
00039   if(calibType==3)
00040     sprintf(outName, "%s/pulserResponse_%s_kVoltageTime.root", outDir, nameOptions);
00041   
00042   TFile *fOut = TFile::Open(outName, "RECREATE");
00043 
00044   TH1D *histCorrelation = new TH1D("pulserCrossCorr", "pulserCrossCorr", 1000, -100, 0);
00045 
00046   TTree *correlationTree = new TTree("correlationTree", "correlationTree");
00047 
00048   Double_t deltaT=0;
00049   correlationTree->Branch("deltaT", &deltaT, "deltaT/D");
00050 
00051   TChain *eventTree = new TChain("eventTree");
00052   
00053   for(int i=minRun; i<maxRun+1; i++){
00054     char inName[260];
00055     
00056     sprintf(inName, "%s/run%06d/event%06d.root", rootDir, i, i);
00057     eventTree->Add(inName);
00058   }
00059   
00060   RawAraEvent *evPtr=0;
00061    
00062   eventTree->SetBranchAddress("event",&evPtr); 
00063     
00064   Long64_t numEntries=eventTree->GetEntries();
00065   Long64_t starEvery=numEntries/80;
00066   if(starEvery==0) starEvery++;
00067   UsefulAraEvent *realEvent;
00068   
00069   cout << numEntries << endl;
00070   for(Long64_t entry=0; entry<numEntries; entry++){
00071    
00072     if(entry%starEvery==0){
00073       cerr << "*";
00074     }
00075     eventTree->GetEntry(entry);
00076 
00077 
00078     
00079     if(calibType==0)
00080       realEvent = new UsefulAraEvent(evPtr, AraCalType::kLatestCalib);  
00081     else if(calibType==1)
00082       realEvent = new UsefulAraEvent(evPtr, AraCalType::kFirstCalibPlusCables);  
00083     else if(calibType==2)
00084       realEvent = new UsefulAraEvent(evPtr, AraCalType::kFirstCalib);  
00085     else if(calibType==3)
00086       realEvent = new UsefulAraEvent(evPtr, AraCalType::kVoltageTime);
00087     else
00088       continue;
00089 
00090  if(realEvent->isCalPulserEvent()==0)
00091       {
00092         delete realEvent;
00093         continue;
00094       }
00095 
00096       TGraph *chanA = realEvent->getGraphFromRFChan(2);
00097       TGraph *chanB = realEvent->getGraphFromRFChan(4);
00098 
00099       double *fvoltsA=chanA->GetY();
00100       double *fvoltsB=chanB->GetY();    
00101   
00102     //zero mean the waveform
00103     //check that the waveforms are sizeable i.e. peak > 300mV
00104 
00105       double maxA=0, maxB=0;
00106 
00107       int nSamples = chanA->GetN();
00108       double offset=0;
00109       for(int i=0; i<nSamples; i++){
00110         offset+=fvoltsA[i]/nSamples;
00111       }
00112       for(int i=0; i<nSamples; i++){
00113         fvoltsA[i]-=offset;
00114         if(fvoltsA[i]>maxA){
00115           maxA=fvoltsA[i];
00116         }
00117       }
00118 
00119       nSamples=chanB->GetN();
00120       offset=0;
00121       for(int i=0; i<nSamples;i++){
00122         offset+=fvoltsB[i]/nSamples;
00123       }
00124       for(int i=0; i<nSamples; i++){
00125         fvoltsB[i]-=offset;
00126         if(fvoltsB[i]>maxB){
00127           maxB=fvoltsB[i];
00128         }
00129       }
00130       if(maxB<300||maxA<300){
00131         delete realEvent;
00132         continue;
00133       }
00134 
00135       //zero mean waveform
00136 
00137       //interpolate the graphs
00138       //pad to length
00139 
00140       TGraph *chanAint = FFTtools::getInterpolatedGraph(chanA, 0.05);
00141       TGraph *chanBint = FFTtools::getInterpolatedGraph(chanB, 0.05);
00142 
00143       //correlate the graphs
00144 
00145       TGraph *correlTemp = FFTtools::getCorrelationGraph(chanAint, chanBint);
00146 
00147       double *xCorrel = correlTemp->GetX();
00148       double *yCorrel = correlTemp->GetY();
00149 
00150       double xMax = 0, yMax = 0;
00151 
00152       //find max correlation value and add to array
00153       //made some changes to what is stored in histogram
00154       //now stores entire correlated waveform
00155 
00156       nSamples = correlTemp->GetN();
00157       for(int i=0; i<nSamples; i++){
00158 
00159         //      histCorrelation->Fill(xCorrel[i], yCorrel[i]);
00160 
00161         if(yCorrel[i]>yMax){
00162           yMax=yCorrel[i];
00163           xMax=xCorrel[i];
00164         }
00165       }
00166 
00167       deltaT=xMax;
00168       histCorrelation->Fill(xMax);
00169       correlationTree->Fill();
00170 
00171       delete chanA;
00172       delete chanB;
00173       delete chanAint;
00174       delete chanBint;
00175       delete correlTemp;     
00176       delete realEvent;
00177       
00178   }
00179   //fOut->cd();
00180   //  histCorrelation->Write();
00181   fOut->WriteTObject(histCorrelation);
00182   fOut->WriteTObject(correlationTree);
00183   fOut->Close();
00184 
00185   
00186   std::cerr << "\n";
00187   return 0;
00188   
00189 }
00190 
00191 int main(int argc, char** argv){
00192 
00193   if(argc<7){
00194     cout << "Incorrect usage\n";
00195     cout << argv[0] << " <rootDir> <minRun> <maxRun> <outDir> <nameOptions> <calibType 0=kLatestCalib 1=kFirstCalibPlusCables 2=kFirstCalib 3=kVoltageTime>\n";
00196     return -1;
00197   }
00198 
00199   if(atoi(argv[6])<0||atoi(argv[6])>3)
00200     {
00201       cout << "Incorrect usage\n";
00202       cout << argv[0] << " <rootDir> <minRun> <maxRun> <outDir> <nameOptions> <calibType 0=kLatestCalib 1=kFirstCalibPlusCables 2=kFirstCalib 3=kVoltageTime>\n";      
00203       return -1;
00204     }
00205 
00206   
00207 
00208   pulserResponse(argv[1], atoi(argv[2]), atoi(argv[3]), argv[4], argv[5], atoi(argv[6]));
00209 
00210   return 0;
00211 }

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