ARA ROOT v3.10 Software

calibration/ATRI/fourthCalibTry.cxx

00001 
00002 
00003 
00004 
00005 
00006 
00009 
00010 
00011 //AraRoot Includes
00012 #include "UsefulAtriStationEvent.h"
00013 #include "RawAtriStationEvent.h"
00014 #include "araSoft.h"
00015 
00016 
00017 //Root Includes
00018 #include "TTree.h"
00019 #include "TFile.h"
00020 #include "TH1.h"
00021 #include "TTree.h"
00022 #include "TMath.h"
00023 #include "TCanvas.h"
00024 
00025 
00026 //Standard Includes
00027 #include <iostream>
00028 #include <fstream>
00029 
00030 
00031 //Global Variables
00032 Double_t inter_sample_times[DDA_PER_ATRI][RFCHAN_PER_DDA][2][SAMPLES_PER_BLOCK]={{{{0}}}}; //[dda][chan][capArray][sample]
00033 Double_t times_two_blocks_one_half[DDA_PER_ATRI][RFCHAN_PER_DDA][2][SAMPLES_PER_BLOCK]={{{{0}}}}; //[dda][chan][half][sample]
00034 Double_t times_one_block_one_half[DDA_PER_ATRI][RFCHAN_PER_DDA][2][2][SAMPLES_PER_BLOCK/2]={{{{{0}}}}}; //[dda][chan][half][capArray][sample]
00035 Double_t epsilon_times[DDA_PER_ATRI][RFCHAN_PER_DDA][2]={{{0}}}; //[dda][chan][capArray] capArray = 0 is cap1 -> cap0
00036 
00037 
00038 //Prototype Functions
00039 TGraph* zeroMean(TGraph*);
00040 Int_t estimate_phase(TGraph*, Double_t, Double_t*, Int_t*);
00041 Int_t estimate_phase_two_blocks(TGraph*, Double_t, Double_t*, Int_t*);
00042 TGraph *getBlockGraph(TGraph*, Int_t);
00043 TGraph *getTwoBlockGraph(TGraph*, Int_t);
00044 
00045 Int_t findLastZC(TGraph*, Double_t, Double_t*);
00046 Int_t findFirstZC(TGraph*, Double_t, Double_t*);
00047 
00048 TGraph* getHalfGraph(TGraph*, Int_t);
00049 TGraph* getHalfGraphTwoBlocks(TGraph*, Int_t);
00050 
00051 TGraph *applyCalibToHalfGraphTwoBlocks(TGraph*, Int_t, Int_t, Int_t);
00052 TGraph *applyCalibToHalfGraphOneBlock(TGraph*, Int_t, Int_t, Int_t, Int_t);
00053 
00054 Int_t calibrate(char*, Int_t, Int_t, Double_t, bool);
00055 
00056 
00057 int main(int argc, char **argv)
00058 {
00059   Int_t runNum=0, pedNum=0;
00060   Double_t freq=0;
00061   char baseName[FILENAME_MAX];
00062   bool debug=false;
00063 
00064   if(argc<5) {
00065     std::cerr << "Usage: " << argv[0] << " <baseDir> <runNum> <pedNum> <freq in GHz>\n";
00066     return 1;
00067   }
00068   sprintf(baseName, "%s", argv[1]);
00069   runNum=atoi(argv[2]);
00070   pedNum=atoi(argv[3]);
00071   freq=atof(argv[4]);
00072   if(argc>5){
00073     if(atoi(argv[5])) debug=true;
00074   }
00075 
00076   return calibrate(baseName, runNum, pedNum, freq, debug);
00077 
00078 }
00079 
00080 
00081 Int_t calibrate(char* baseDirName, Int_t runNum, Int_t pedNum, Double_t freq, bool debug=false){
00082   Double_t period=1./freq;
00083   Int_t chanIndex=0;
00084   Int_t dda=0, chan=0;
00085   char runFileName[FILENAME_MAX];
00086   char pedFileName[FILENAME_MAX];
00087   sprintf(runFileName, "%s/root/run%i/event%i.root", baseDirName, runNum, runNum);
00088   sprintf(pedFileName, "%s/raw_data/run_%06i/pedestalValues.run%06d.dat", baseDirName, pedNum, pedNum);
00089 
00090   printf("runFileName %s\npedFileName %s\nfreq %f GHz\n", runFileName, pedFileName, freq);
00091   
00092   TFile *fp = new TFile(runFileName);
00093   if(!fp) {
00094     std::cerr << "Can't open file\n";
00095     return -1;
00096   }
00097   TTree *eventTree = (TTree*) fp->Get("eventTree");
00098   if(!eventTree) {
00099     std::cerr << "Can't find eventTree\n";
00100     return -1;
00101   }
00102   RawAtriStationEvent *evPtr=0;
00103   eventTree->SetBranchAddress("event",&evPtr);
00104   Long64_t numEntries=eventTree->GetEntries();
00105 
00106   if(debug)  std::cout << "Number of entries in file is " << numEntries << std::endl;
00107 
00108   Long64_t starEvery=numEntries/80;
00109   if(starEvery==0) starEvery++;
00110   
00111   Int_t stationId=0;
00112   eventTree->GetEntry(0);
00113   stationId= evPtr->stationId;
00114   if(debug)  std::cerr << "stationId " << stationId << "\n";
00115   AraEventCalibrator *calib = AraEventCalibrator::Instance();
00116   calib->setAtriPedFile(pedFileName, 2);
00117   
00118   //General output stuff
00119   char outFileName[FILENAME_MAX];
00120   sprintf(outFileName, "%s/root/run%i/calibFourthTry.root", baseDirName, runNum);
00121   TFile *outFile = new TFile(outFileName, "RECREATE");
00122   Int_t capArray=0,thisCapArray=0, block=0,half=0,sample=0;
00123   Int_t numEventsCap0[DDA_PER_ATRI][RFCHAN_PER_DDA]={{0}};
00124   Int_t numEventsCap1[DDA_PER_ATRI][RFCHAN_PER_DDA]={{0}};
00125   Double_t epsilonEstCap1Cap0[DDA_PER_ATRI][RFCHAN_PER_DDA]={{0}};
00126 
00127   //BinWidth Histos
00128   TH1D *histBinWidth[DDA_PER_ATRI][RFCHAN_PER_DDA][2]; 
00129   char histName[FILENAME_MAX];
00130   for(half=0;half<2;half++) {
00131     for(dda=0;dda<DDA_PER_ATRI;dda++){
00132       for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00133         sprintf(histName,"histBinWidth_dda%d_chan%d_%d",dda, chan,half);
00134         histBinWidth[dda][chan][half] = new TH1D(histName,histName,SAMPLES_PER_BLOCK,-0.5,SAMPLES_PER_BLOCK-0.5);
00135       }
00136     }
00137   }
00138 
00139   //Interleave Histos
00140   TTree *lagTree = new TTree("lagTree","lagTree");
00141   Int_t noZCs[2]={0};
00142   Double_t lag1,lag0,deltaLag;
00143   lagTree->Branch("dda",&dda,"dda/I");
00144   lagTree->Branch("chan",&chan,"chan/I");
00145   lagTree->Branch("block",&block,"block/I");
00146   lagTree->Branch("noZCs", &noZCs, "noZCs[2]/I");
00147   lagTree->Branch("lag1",&lag1,"lag1/D");
00148   lagTree->Branch("lag0",&lag0,"lag0/D");
00149   lagTree->Branch("deltaLag",&deltaLag,"deltaLag/D");
00150   Double_t lag[DDA_PER_ATRI][RFCHAN_PER_DDA] = {{0}};
00151   TH1F *lagHist[DDA_PER_ATRI][RFCHAN_PER_DDA]={{0}};
00152   for(dda=0;dda<DDA_PER_ATRI;dda++){
00153     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00154       sprintf(histName,"lag_hist_dda%i_chan%i",dda, chan);
00155       lagHist[dda][chan] = new TH1F(histName,histName,200,-1.0,1.0);
00156     }
00157   }
00158 
00159   //Epsilon Histos
00160   TTree *epsilonTree = new TTree("epsilonTree", "epsilonTree");
00161   Double_t epsilon=0;
00162   Double_t epsilon_corrected=0;
00163   Double_t firstZC=0, lastZC=0;
00164   Double_t oneZCLast=0, oneZCFirst=0;
00165   Int_t firstZCCount=0, lastZCCount=0;
00166   Double_t epsilon2=0;
00167   Int_t atriBlock=0;
00168   TH1* histEpsilon[DDA_PER_ATRI][RFCHAN_PER_DDA]={{0}}; //[dda][chan];
00169   epsilonTree->Branch("dda",&dda,"dda/I");
00170   epsilonTree->Branch("chan",&chan,"chan/I");
00171   epsilonTree->Branch("block",&block,"block/I");
00172   epsilonTree->Branch("epsilon",&epsilon,"epsilon/D");
00173   epsilonTree->Branch("epsilon2",&epsilon2,"epsilon2/D");
00174   epsilonTree->Branch("epsilon_corrected",&epsilon_corrected,"epsilon_corrected/D");
00175   epsilonTree->Branch("firstZC",&firstZC,"firstZC/D");
00176   epsilonTree->Branch("lastZC",&lastZC,"lastZC/D");
00177   epsilonTree->Branch("oneZCLast",&oneZCLast,"oneZCLast/D");
00178   epsilonTree->Branch("oneZCFirst",&oneZCFirst,"oneZCFirst/D");
00179 
00180 
00181   epsilonTree->Branch("lastZCCount",&lastZCCount,"lastZCCount/I");
00182   epsilonTree->Branch("firstZCCount",&firstZCCount,"firstZCCount/I");
00183   epsilonTree->Branch("half", &half, "half/I");
00184   epsilonTree->Branch("atriBlock", &atriBlock, "atriBlock/I");
00185   for(dda=0;dda<DDA_PER_ATRI;dda++){
00186     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00187       sprintf(histName,"epsilon_hist_dda%i_chan%i",dda, chan);
00188       histEpsilon[dda][chan] = new TH1F(histName,histName,600,-3.0,3.0);
00189     }
00190   }
00191 
00192   //Check Epsilon Tree
00193   TTree *checkEpsilonTree = new TTree("checkEpsilonTree", "checkEpsilonTree");
00194   Double_t zcEst=0;
00195   Double_t zcMeas=0;
00196   Int_t firstBlock=0;
00197   Int_t zcNo=0;
00198   Int_t missedOne=0;
00199   Int_t firstBadZC=0;
00200   checkEpsilonTree->Branch("dda", &dda, "dda/I");
00201   checkEpsilonTree->Branch("chan", &chan, "chan/I");
00202   checkEpsilonTree->Branch("block", &block, "block/I");
00203   checkEpsilonTree->Branch("firstBlock", &firstBlock, "firstBlock/I");
00204   checkEpsilonTree->Branch("zcNo", &zcNo, "zcNo/I");
00205   checkEpsilonTree->Branch("capArray", &capArray, "capArray/I");
00206   checkEpsilonTree->Branch("sample", &sample, "sample/I");
00207   checkEpsilonTree->Branch("firstBadZC", &firstBadZC, "firstBadZC/I");
00208 
00209   checkEpsilonTree->Branch("zcEst", &zcEst ,"zcEst/D");
00210   checkEpsilonTree->Branch("zcMeas", &zcMeas ,"zcMeas/D");
00211   checkEpsilonTree->Branch("firstZC", &firstZC ,"firstZC/D");
00212 
00213   
00214 
00215 
00216   //BinWidth Calibration
00217   //numEntries=1;//FIXME
00218   for(int entry=0;entry<numEntries;entry++){
00219     if(entry%starEvery==0) std::cerr <<"*";
00220     eventTree->GetEntry(entry);
00221     //    UsefulAtriStationEvent realEvent(evPtr, AraCalType::kJustPed);
00222     UsefulAtriStationEvent realEvent(evPtr, AraCalType::kVoltageTime); //jpd - this has the voltage calib but no timing calib
00223 
00224     
00225     for(dda=0;dda<DDA_PER_ATRI;dda++){
00226       capArray = evPtr->blockVec[dda].getCapArray(); //capArray of first block
00227       for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00228         chanIndex=chan+RFCHAN_PER_DDA*dda;
00229         TGraph *gr = realEvent.getGraphFromElecChan(chanIndex);
00230         TGraph *grZeroMean = zeroMean(gr);
00231         Int_t numSamples = grZeroMean->GetN();
00232         Int_t numBlocks = numSamples/SAMPLES_PER_BLOCK;
00233                 
00234         for(block=0; block<numBlocks-1; block++){ 
00235           if(block%2) thisCapArray=1-capArray;
00236           else thisCapArray=capArray;
00237           if(thisCapArray==0){
00238             TGraph *grTwoBlock = getTwoBlockGraph(grZeroMean, block);
00239             numEventsCap0[dda][chan]++;
00240             for(half=0;half<2;half++){
00241               TGraph *grHalf = getHalfGraphTwoBlocks(grTwoBlock, half);
00242               Double_t *yVals = grHalf->GetY();
00243               for(sample=0;sample<SAMPLES_PER_BLOCK-1;sample++){
00244                 Double_t val1 = yVals[sample];
00245                 Double_t val2 = yVals[sample+1];
00246                 if(val1<0 && val2>0){
00247                   histBinWidth[dda][chan][half]->Fill(sample);
00248                 }
00249                 else if(val1>0 && val2<0){
00250                   histBinWidth[dda][chan][half]->Fill(sample);
00251                 }
00252                 // else if(val1==0 || val2==0){
00253                 //   histBinWidth[dda][chan][half]->Fill(sample, 0.5);
00254                 // }
00255               }//sample
00256               if(grHalf) delete grHalf;
00257             }//half      
00258             if(grTwoBlock) delete grTwoBlock;
00259           }
00260           // else{//thisCapArray==1 //This is sanity check for the epsilon calculation
00261           //   numEventsCap1[dda][chan]++;
00262           //   TGraph *grTwoBlock = getTwoBlockGraph(grZeroMean, block);            
00263           //   TGraph *grHalf = getHalfGraphTwoBlocks(grTwoBlock, 0);
00264           //   Double_t *yVals = grHalf->GetY();
00265           //   Double_t val1 = yVals[SAMPLES_PER_BLOCK/2-1];//last sample not necessarily before first one use sample 30 to 0 not 31 to 0
00266           //   Double_t val2 = yVals[SAMPLES_PER_BLOCK/2];
00267           //   if(val1<0 && val2>0){
00268           //     epsilonEstCap1Cap0[dda][chan]+=1;
00269           //   }
00270           //   else if(val1>0 && val2<0){
00271           //     epsilonEstCap1Cap0[dda][chan]+=1;
00272           //   }
00273           //   else if(val1==0 || val2==0){
00274           //     epsilonEstCap1Cap0[dda][chan]+=0.5;
00275           //   }
00276           //   if(grHalf) delete grHalf;
00277           //   if(grTwoBlock) delete grTwoBlock;
00278           // }
00279         }//block
00280         
00281         delete gr;
00282         delete grZeroMean;
00283       }//chan
00284     }//dda
00285 
00286   }//entry
00287   std::cerr << "\n";
00288 
00289   //Scale the ZC and calculate the bin widths
00290 
00291   for(dda=0;dda<DDA_PER_ATRI;dda++){
00292     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00293       for(half=0;half<2;half++){
00294         histBinWidth[dda][chan][half]->Scale(1./numEventsCap0[dda][chan]);
00295         histBinWidth[dda][chan][half]->Scale(0.5*period);
00296         histBinWidth[dda][chan][half]->Write();
00297       }//half
00298       Double_t numZCs=epsilonEstCap1Cap0[dda][chan];
00299       epsilonEstCap1Cap0[dda][chan]=(numZCs / numEventsCap1[dda][chan])*(0.5*period);
00300       //      epsilonEstCap1Cap0[dda][chan]-=histBinWidth[dda][chan][0]->GetBinContent(SAMPLES_PER_BLOCK-2+1);//Take off the gap from sample 30 to 31
00301       //      printf("%f\n",  epsilonEstCap1Cap0[dda][chan]);
00302 
00303     }//chan
00304   }//dda
00305 
00306   for(dda=0;dda<DDA_PER_ATRI;dda++){
00307     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00308       for(half=0;half<2;half++){
00309         Double_t time=0;
00310         for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){
00311           times_two_blocks_one_half[dda][chan][half][sample]=time;
00312           time+=histBinWidth[dda][chan][half]->GetBinContent(sample+1);
00313           // if(chan==0){
00314           //   printf("%i %i %i %f %f\n", dda, chan, half, times_two_blocks_one_half[dda][chan][half][sample], time);
00315           // }
00316         }//sample
00317       }//half
00318     }//chan
00319   }//dda
00320 
00321   Int_t goodSampleTiming[DDA_PER_ATRI][RFCHAN_PER_DDA]={{1,1,1,1,1,1,0,0},{1,1,1,1,0,0,0,0},{1,1,1,1,0,0,0,0},{1,1,1,1,1,1,0,0}};
00322 
00323   //CheckBinWidths
00324   //numEntries=1;//FIXME
00325   for(int entry=0;entry<numEntries;entry++){
00326     if(entry%starEvery==0) std::cerr <<"*";
00327     eventTree->GetEntry(entry);
00328     //    UsefulAtriStationEvent realEvent(evPtr, AraCalType::kJustPed);
00329     UsefulAtriStationEvent realEvent(evPtr, AraCalType::kVoltageTime);
00330     for(dda=0;dda<DDA_PER_ATRI;dda++){
00331       capArray = evPtr->blockVec[dda].getCapArray(); //capArray of first block
00332       for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00333         chanIndex=chan+RFCHAN_PER_DDA*dda;
00334         TGraph *gr = realEvent.getGraphFromElecChan(chanIndex);
00335         TGraph *grZeroMean = zeroMean(gr);
00336         Int_t numSamples = grZeroMean->GetN();
00337         Int_t numBlocks = numSamples/SAMPLES_PER_BLOCK;
00338         
00339         for(block=0; block<numBlocks-1; block++){ 
00340           if(block%2) thisCapArray=1-capArray;
00341           else thisCapArray=capArray;
00342           if(thisCapArray!=0) continue;
00343           TGraph *grTwoBlock = getTwoBlockGraph(grZeroMean, block);
00344           TGraph *grTwoBlockHalf = getHalfGraphTwoBlocks(grTwoBlock, 0);
00345           Double_t *yVals = grTwoBlockHalf->GetY();
00346           zcNo=0;
00347 
00348           for(sample=0;sample<SAMPLES_PER_BLOCK-1;sample++){
00349             Double_t y1=yVals[sample];
00350             Double_t y2=yVals[sample+1];
00351             Double_t x1=times_two_blocks_one_half[dda][chan][0][sample];
00352             Double_t x2=times_two_blocks_one_half[dda][chan][0][sample+1];
00353             if((y1<0 && y2>0)){
00354               if(zcNo==0){
00355                 firstZC=((0-y1)/(y2-y1))*(x2-x1)+x1;
00356               }
00357               zcMeas=((0-y1)/(y2-y1))*(x2-x1)+x1;
00358               zcEst=firstZC+period*1.*zcNo;
00359               checkEpsilonTree->Fill();
00360               zcNo++;
00361             }
00362           }
00363 
00364 
00365 
00366           if(grTwoBlockHalf) delete grTwoBlockHalf;
00367           if(grTwoBlock) delete grTwoBlock;
00368         }//block
00369         
00370         
00371         if(grZeroMean) delete grZeroMean;
00372         if(gr) delete gr;
00373       }//chan
00374     }//dda
00375   }
00376   std::cout << std::endl;
00377 
00378 
00379 
00380 
00381 
00382   //Interleave
00383   //  numEntries=1;//FIXME
00384   // for(int entry=0;entry<numEntries;entry++){
00385   //   if(entry%starEvery==0) std::cerr <<"*";
00386   //   eventTree->GetEntry(entry);
00387   //   UsefulAtriStationEvent realEvent(evPtr, AraCalType::kJustPed);
00388 
00389     
00390   //   for(dda=0;dda<DDA_PER_ATRI;dda++){
00391   //     capArray = evPtr->blockVec[dda].getCapArray(); //capArray of first block
00392   //     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00393   //    chanIndex=chan+RFCHAN_PER_DDA*dda;
00394   //    TGraph *gr = realEvent.getGraphFromElecChan(chanIndex);
00395   //    TGraph *grZeroMean = zeroMean(gr);
00396   //    Int_t numSamples = grZeroMean->GetN();
00397   //    Int_t numBlocks = numSamples/SAMPLES_PER_BLOCK;
00398   //    for(block=0; block<numBlocks-1; block++){
00399   //      if(block%2) thisCapArray=1-capArray;
00400   //      else thisCapArray=capArray;
00401   //      if(thisCapArray==1) continue;
00402   //      TGraph *grTwoBlocks = getTwoBlockGraph(grZeroMean, block);
00403   //      TGraph *grTwoBlocksEvenHalf = getHalfGraphTwoBlocks(grTwoBlocks, 0);
00404   //      TGraph *grTwoBlocksOddHalf = getHalfGraphTwoBlocks(grTwoBlocks, 1);
00405 
00406   //      //Now apply the bin calib to produce calibrated TGraphs
00407   //      TGraph *grCalibEven = applyCalibToHalfGraphTwoBlocks(grTwoBlocksEvenHalf, dda, chan, 0);
00408   //      TGraph *grCalibOdd = applyCalibToHalfGraphTwoBlocks(grTwoBlocksOddHalf, dda, chan, 1);
00409 
00410   //      //Estimate phase
00411   //      Int_t retVal = estimate_phase_two_blocks(grCalibEven, period, &lag0, &noZCs[0]);
00412   //      if(retVal==0){
00413   //        retVal = estimate_phase_two_blocks(grCalibOdd, period, &lag1, &noZCs[1]);
00414   //        if(retVal==0){
00415   //          deltaLag = lag0-lag1;//With no interleave done the half that is later in time has a smaller lag
00416   //          while(TMath::Abs(deltaLag-period)<TMath::Abs(deltaLag))
00417   //            deltaLag-=period;
00418   //          while(TMath::Abs(deltaLag+period)<TMath::Abs(deltaLag))
00419   //            deltaLag+=period;
00420   //          lagTree->Fill();
00421   //          if(TMath::Abs(noZCs[0]-noZCs[1])==0) lagHist[dda][chan]->Fill(deltaLag);
00422   //        }
00423   //      }
00424   //      if(grCalibEven) delete grCalibEven;
00425   //      if(grCalibOdd) delete grCalibOdd;
00426   //      if(grTwoBlocks) delete  grTwoBlocks;
00427   //      if(grTwoBlocksEvenHalf) delete grTwoBlocksEvenHalf;
00428   //      if(grTwoBlocksOddHalf) delete grTwoBlocksOddHalf;
00429   //    }//block
00430   //    if(grZeroMean) delete grZeroMean;
00431   //    if(gr) delete gr;
00432   //     }//chan
00433   //   }//dda
00434   // }//entry
00435   // std::cerr << "\n";
00436 
00437   // //Calculate lag
00438 
00439   // Int_t useAllSamples[DDA_PER_ATRI][RFCHAN_PER_DDA]={{0}};
00440   // for(dda=0;dda<DDA_PER_ATRI;dda++){
00441   //   for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00442   //     if(chan<2) useAllSamples[dda][chan]=1;
00443   //     lag[dda][chan] = lagHist[dda][chan]->GetMean(1);
00444   //     if((lagHist[dda][chan]->GetRMS())>0.1&&chan<6) {
00445   //    printf("dda %i chan %i rms %f\n", dda, chan, lagHist[dda][chan]->GetRMS());
00446   //    goodSampleTiming[dda][chan]=0;
00447   //     }    
00448   //     else {
00449   //    goodSampleTiming[dda][chan]=1;
00450   //     }
00451   //     //printf("dda %i chan %i lag %f\n", dda, chan ,lag[dda][chan]);        
00452   //   }//chan
00453   // }//dda
00454 
00455   // //Now adjust the sample timing with the calculated lag
00456   // for(dda=0;dda<DDA_PER_ATRI;dda++){
00457   //   for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00458   //     for(half=0;half<2;half++){
00459   //    for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){
00460   //      // if(lag[dda][chan]>0) {
00461   //      //   Double_t time=times_two_blocks_one_half[dda][chan][half][sample];
00462   //      //   times_two_blocks_one_half[dda][chan][half][sample]=time+(lag[dda][chan])*half;
00463   //      // }
00464   //      // else {
00465   //      //   Double_t time=times_two_blocks_one_half[dda][chan][half][sample];
00466   //      //   times_two_blocks_one_half[dda][chan][half][sample]=time-(lag[dda][chan])*(1-half);
00467   //      // }
00468   //      times_two_blocks_one_half[dda][chan][half][sample]+=half*lag[dda][chan];
00469 
00470 
00471   //    }//sample
00472   //     }//half
00473   //   }//chan
00474   // }//dda
00475   
00476   // //Now make sample timing for each cap Array
00477   // for(dda=0;dda<DDA_PER_ATRI;dda++){
00478   //   for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00479   //     for(half=0;half<2;half++){
00480   //    for(capArray=0;capArray<2;capArray++){
00481   //      Double_t offset=0;
00482   //      // if(capArray==1){
00483   //      //   offset=-1.*(times_two_blocks_one_half[dda][chan][half][SAMPLES_PER_BLOCK/2]);
00484   //      // }
00485   //      for(sample=0;sample<SAMPLES_PER_BLOCK/2;sample++){
00486   //        times_one_block_one_half[dda][chan][half][capArray][sample]=times_two_blocks_one_half[dda][chan][half][sample+(capArray*SAMPLES_PER_BLOCK/2)]+offset;
00487   //      }//sample
00488   //    }//capArray
00489   //     }//half
00490   //   }//chan
00491   // }//dda
00492   
00493 
00494   // //Epsilon
00495   // //  numEntries=1;//FIXME
00496   // for(int entry=0;entry<numEntries;entry++){
00497   //   if(entry%starEvery==0) std::cerr <<"*";
00498   //   eventTree->GetEntry(entry);
00499   //   UsefulAtriStationEvent realEvent(evPtr, AraCalType::kJustPed);
00500 
00501   //   for(dda=0;dda<DDA_PER_ATRI;dda++){
00502   //     capArray = evPtr->blockVec[dda].getCapArray(); //capArray of first block
00503   //     atriBlock = evPtr->blockVec[dda].getBlock();
00504 
00505   //     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00506   //    chanIndex=chan+RFCHAN_PER_DDA*dda;
00507         
00508   //    TGraph *gr = realEvent.getGraphFromElecChan(chanIndex);
00509   //    TGraph *grZeroMean = zeroMean(gr);
00510   //    Int_t numSamples = grZeroMean->GetN();
00511   //    Int_t numBlocks = numSamples/SAMPLES_PER_BLOCK;
00512         
00513   //    for(block=0; block<numBlocks-1; block++){ 
00514   //      if(block%2) thisCapArray=1-capArray;
00515   //      else thisCapArray=capArray;
00516   //      if(thisCapArray==0) continue; //We've already done this one -- it was done as part of the binWidths
00517   //      TGraph *grBlockOne = getBlockGraph(grZeroMean, block);
00518   //      TGraph *grBlockTwo = getBlockGraph(grZeroMean, block+1);
00519   //      TGraph *grBlockOneEven = getHalfGraph(grBlockOne, 0);
00520   //      TGraph *grBlockTwoEven = getHalfGraph(grBlockTwo, 0);
00521   //      TGraph *grBlockOneEvenCalib = applyCalibToHalfGraphOneBlock(grBlockOneEven, dda, chan, 1, 0); //block one is capArray 1
00522   //      TGraph *grBlockTwoEvenCalib = applyCalibToHalfGraphOneBlock(grBlockTwoEven, dda, chan, 0, 0); //block two is capArray 0
00523           
00524   //      lastZCCount = findLastZC(grBlockOneEvenCalib, period, &lastZC);
00525   //      firstZCCount = findFirstZC(grBlockTwoEvenCalib, period, &firstZC);
00526   //      Double_t *tVals = grBlockOneEvenCalib->GetX(); 
00527   //      Double_t lastSample = tVals[SAMPLES_PER_BLOCK/2-1];
00528   //      //epsilon = (firstZC+lastSample)-lastZC-period;//jpd - surely this is correct? -ve epsilon means first sample before last
00529   //      epsilon = -1.*((firstZC+lastSample)-lastZC-period);
00530   //      epsilon_corrected=epsilon;
00531   //      while(epsilon_corrected < -0.5*period) epsilon_corrected+=period;
00532   //      while(epsilon_corrected > +0.5*period) epsilon_corrected-=period;
00533   //      epsilonTree->Fill();
00534   //      if(TMath::Abs(lastZCCount-firstZCCount)==0) histEpsilon[dda][chan]->Fill(epsilon_corrected);
00535   //      /*
00536             
00537   //       */
00538 
00539 
00540 
00541   //      if(grBlockOne) delete grBlockOne;
00542   //      if(grBlockTwo) delete grBlockTwo;
00543   //      if(grBlockOneEven) delete grBlockOneEven;
00544   //      if(grBlockTwoEven) delete grBlockTwoEven;
00545   //      if(grBlockOneEvenCalib) delete grBlockOneEvenCalib;
00546   //      if(grBlockTwoEvenCalib) delete grBlockTwoEvenCalib;
00547 
00548   //    }//block
00549   //    if(gr) delete gr;
00550   //    if(grZeroMean) delete grZeroMean;
00551   //     }//chan
00552   //   }//dda
00553   // }//entry
00554   // std::cout << std::endl;
00555 
00556   // //Calculate Epsilon
00557   // for(dda=0;dda<DDA_PER_ATRI;dda++){
00558   //   for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00559   //     if(goodSampleTiming[dda][chan]==1){
00560   //    Double_t lastTime=times_two_blocks_one_half[dda][chan][0][31];
00561   //    Double_t firstTime=times_two_blocks_one_half[dda][chan][0][32];
00562   //    epsilon_times[dda][chan][1]=firstTime-lastTime;
00563   //    epsilon_times[dda][chan][0]=histEpsilon[dda][chan]->GetMean(1);
00564   //    printf("dda %i chan %i epsilon %f %f %f\n", dda, chan, epsilon_times[dda][chan][0], epsilon_times[dda][chan][1],epsilonEstCap1Cap0[dda][chan] );
00565   //     }
00566   //   }//chan
00567   // }//dda
00568   
00569   // //Check Calibration
00570   // for(int entry=0;entry<numEntries;entry++){
00571   //   if(entry%starEvery==0) std::cerr <<"*";
00572   //   eventTree->GetEntry(entry);
00573   //   UsefulAtriStationEvent realEvent(evPtr, AraCalType::kJustPed);
00574 
00575   //   for(dda=0;dda<DDA_PER_ATRI;dda++){
00576   //     capArray = evPtr->blockVec[dda].getCapArray(); //capArray of first block
00577   //     atriBlock = evPtr->blockVec[dda].getBlock();
00578   //     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00579   //    chanIndex=chan+RFCHAN_PER_DDA*dda;
00580   //    TGraph *gr = realEvent.getGraphFromElecChan(chanIndex);
00581   //    TGraph *grZeroMean = zeroMean(gr);
00582   //    Int_t numSamples = grZeroMean->GetN();
00583   //    Int_t numBlocks = numSamples/SAMPLES_PER_BLOCK;
00584   //    Int_t gotFirstBlock=0;
00585   //    zcNo=0;
00586   //    missedOne=0;
00587   //    firstBadZC=0;
00588   //    Double_t lastSampleVal=0;
00589 
00590   //    for(block=0; block<numBlocks-1; block++){ 
00591   //      if(block%2) thisCapArray=1-capArray;
00592   //      else thisCapArray=capArray;
00593   //      if(thisCapArray==1) continue;
00594   //      TGraph *grTwoBlocks = getTwoBlockGraph(grZeroMean, block);
00595   //      TGraph *grHalf = getHalfGraphTwoBlocks(grTwoBlocks, 0);
00596   //      Double_t *yVals = grHalf->GetY();
00597   //      if(!gotFirstBlock){
00598   //        gotFirstBlock=1;
00599   //        firstBlock=block;
00600   //        for(sample=0;sample<SAMPLES_PER_BLOCK-1;sample++){
00601   //          Double_t y1=yVals[sample];
00602   //          Double_t y2=yVals[sample+1];
00603   //          Double_t x1=times_two_blocks_one_half[dda][chan][0][sample];
00604   //          Double_t x2=times_two_blocks_one_half[dda][chan][0][sample+1];
00605   //          if((y1<0 && y2>0)){//|| (y1>0 && y2<0) || (y1==0 || y2==0)){
00606   //            firstZC=((0-y1)/(y2-y1))*(x2-x1)+x1;
00607   //            break;//FIXME does this actually break?
00608   //          }
00609   //        }//sample
00610   //      }
00611   //      // if(lastSampleVal<0 && yVals[0]>0){
00612   //      //   zcNo++; //~64th of the time we miss a zc between end of last "double-block" and begninig of next
00613   //      //   missedOne=1;
00614   //      // }
00615   //      for(sample=0;sample<SAMPLES_PER_BLOCK-1;sample++){//FIXME start at second sample
00616   //        Double_t offset=(times_two_blocks_one_half[dda][chan][0][SAMPLES_PER_BLOCK-1]+epsilon_times[dda][chan][0])*((block-firstBlock)/2);
00617   //        Double_t y1=yVals[sample];
00618   //        Double_t y2=yVals[sample+1];
00619   //        Double_t x1=times_two_blocks_one_half[dda][chan][0][sample]+offset;
00620   //        Double_t x2=times_two_blocks_one_half[dda][chan][0][sample+1]+offset;
00621             
00622   //        if((y1<0 && y2>0)){// || (y1>0 && y2<0) || (y1==0 |y2==0)){
00623   //          zcMeas=((0-y1)/(y2-y1))*(x2-x1)+x1;
00624   //          //              zcEst=firstZC+period*0.5*zcNo;
00625   //          zcEst=firstZC+period*1*zcNo;
00626   //          if(TMath::Abs(zcMeas-zcEst) > 0.5*period&&firstBadZC==0){
00627   //            firstBadZC=zcNo;
00628   //          }
00629               
00630   //          checkEpsilonTree->Fill();
00631   //          zcNo++;
00632               
00633   //        }
00634   //      }//sample
00635   //      lastSampleVal=yVals[SAMPLES_PER_BLOCK-1];
00636   //      if(grHalf) delete grHalf;
00637   //      if(grTwoBlocks) delete grTwoBlocks;
00638   //    }//block
00639   //    if(grZeroMean) delete grZeroMean;
00640   //    if(gr) delete gr;
00641   //     }//chan
00642   //   }//dda
00643   // }//entry
00644   // std::cout << std::endl;
00645   
00646 
00647   
00648   char interSampleTimes[200];
00649   sprintf(interSampleTimes, "%s_interSampleTimes.txt", outFileName);
00650   std::ofstream interSampleTimesFile(interSampleTimes);
00651   int lastGoodChan=0;
00652   for(dda=0;dda<DDA_PER_ATRI;dda++){
00653     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00654       for(half=0;half<2;half++){
00655         interSampleTimesFile << dda << "\t" << chan << "\t" << half << "\t"  << SAMPLES_PER_BLOCK << "\t";   
00656         int useDda=dda;
00657         int useChan=chan;
00658 
00659         if(goodSampleTiming[dda][chan]) lastGoodChan=chan;
00660         else {
00661           useChan=lastGoodChan;
00662           std::cout << "Replacing " << dda << "," << chan << " with " << useDda << "," << useChan << "\n";
00663         }
00664 
00665         for(sample=0;sample<SAMPLES_PER_BLOCK;sample++) {
00666           //Index values
00667           interSampleTimesFile << sample*2+half << " ";
00668         }
00669         interSampleTimesFile << "\n";
00670         interSampleTimesFile << dda << "\t" << chan << "\t" << half << "\t"  << SAMPLES_PER_BLOCK << "\t";   
00671         for(int sample=0;sample<SAMPLES_PER_BLOCK;sample++) {
00672           //time values
00673           interSampleTimesFile << times_two_blocks_one_half[dda][chan][half][sample] << " ";
00674         }
00675         interSampleTimesFile << "\n";
00676       }
00677     }
00678   }
00679   interSampleTimesFile.close();
00680 
00681   
00682   
00683   
00684   
00685   
00686   
00687   outFile->Write();
00688 
00689   return 0;
00690 }
00691 
00692 
00693 
00694 TGraph* zeroMean(TGraph* gr){
00695   Double_t *xVals=gr->GetX();
00696   Double_t *yVals=gr->GetY();
00697   Int_t maxN = gr->GetN();
00698 
00699   if(maxN<1) return NULL;
00700 
00701   Double_t mean=0;
00702   for(int i=0;i<maxN; i++){
00703     mean+=yVals[i]/maxN;
00704   }
00705   Double_t *yValsNew = new Double_t[maxN];
00706   for(int i=0;i<maxN; i++){
00707     yValsNew[i]=yVals[i]-mean;
00708   }
00709   TGraph *grZeroMeaned = new TGraph(maxN, xVals, yValsNew);
00710   
00711   delete yValsNew;
00712   return grZeroMeaned;
00713   
00714 }
00715 
00716 TGraph *getBlockGraph(TGraph *fullEventGraph, Int_t block){
00717   Int_t numSamples = fullEventGraph->GetN();
00718   Int_t numBlocks = numSamples / SAMPLES_PER_BLOCK;
00719   if(block > numBlocks) return NULL;
00720   Double_t *fullX = fullEventGraph->GetX();
00721   Double_t *fullY = fullEventGraph->GetY();  
00722   Double_t *blockX = new Double_t[SAMPLES_PER_BLOCK];
00723   Double_t *blockY = new Double_t[SAMPLES_PER_BLOCK];
00724   for(int sample=0;sample<SAMPLES_PER_BLOCK; sample++){
00725     blockY[sample] = fullY[sample + block*SAMPLES_PER_BLOCK];
00726     blockX[sample] = fullX[sample + block*SAMPLES_PER_BLOCK];
00727   }
00728   TGraph *blockGraph = new TGraph(SAMPLES_PER_BLOCK, blockX, blockY);
00729   delete blockX;
00730   delete blockY;
00731   return blockGraph;
00732 }
00733 
00734 TGraph *getTwoBlockGraph(TGraph *fullEventGraph, Int_t block){
00735   Int_t numSamples = fullEventGraph->GetN();
00736   Int_t numBlocks = numSamples / SAMPLES_PER_BLOCK;
00737   if(block >= numBlocks-1) return NULL;
00738   Double_t *fullX = fullEventGraph->GetX();
00739   Double_t *fullY = fullEventGraph->GetY();  
00740   Double_t *blockX = new Double_t[SAMPLES_PER_BLOCK*2];
00741   Double_t *blockY = new Double_t[SAMPLES_PER_BLOCK*2];
00742   for(int sample=0;sample<SAMPLES_PER_BLOCK*2; sample++){
00743     blockY[sample] = fullY[sample + block*SAMPLES_PER_BLOCK];
00744     blockX[sample] = fullX[sample + block*SAMPLES_PER_BLOCK];
00745   }
00746   TGraph *blockGraph = new TGraph(SAMPLES_PER_BLOCK*2, blockX, blockY);
00747   delete blockX;
00748   delete blockY;
00749   return blockGraph;
00750 }
00751 
00752 
00753 TGraph *getHalfGraph(TGraph *fullGraph, Int_t half){
00754   Int_t numSamples = fullGraph->GetN();
00755   Double_t *xFull  = fullGraph->GetX();
00756   Double_t *yFull  = fullGraph->GetY();
00757   Double_t *newX = new Double_t[numSamples/2];
00758   Double_t *newY = new Double_t[numSamples/2];
00759 
00760   for(Int_t sample=0;sample<numSamples;sample++){
00761     if(sample%2!=half) continue;
00762     newX[sample/2]=xFull[sample];
00763     newY[sample/2]=yFull[sample];
00764   }
00765   TGraph *halfGraph = new TGraph(numSamples/2, newX, newY);
00766    
00767   delete newX;
00768   delete newY;
00769   return halfGraph;
00770   
00771 }
00772 
00773 TGraph *getHalfGraphTwoBlocks(TGraph *fullGraph, Int_t half){
00774   Int_t numSamples = fullGraph->GetN();
00775   Double_t *xFull  = fullGraph->GetX();
00776   Double_t *yFull  = fullGraph->GetY();
00777 
00778   if(numSamples != 2*SAMPLES_PER_BLOCK){
00779     fprintf(stderr, "Wrong number of samples got %d expected %d\n", numSamples, SAMPLES_PER_BLOCK);
00780     return NULL;
00781   }
00782 
00783   Double_t *newX = new Double_t[SAMPLES_PER_BLOCK];
00784   Double_t *newY = new Double_t[SAMPLES_PER_BLOCK];
00785 
00786   for(Int_t sample=0;sample<2*SAMPLES_PER_BLOCK;sample++){
00787     if(sample%2!=half) continue;
00788     newX[sample/2]=xFull[sample];
00789     newY[sample/2]=yFull[sample];
00790   }
00791   TGraph *halfGraph = new TGraph(SAMPLES_PER_BLOCK, newX, newY);
00792    
00793   delete newX;
00794   delete newY;
00795   return halfGraph;
00796   
00797 }
00798 
00799 Int_t estimate_phase_two_blocks(TGraph *gr, Double_t period, Double_t *meanPhase, Int_t *totalZCs){
00800   Double_t *yVals = gr->GetY();
00801   Double_t *xVals = gr->GetX();
00802   Int_t numSamples = gr->GetN();
00803   Double_t phase=0;
00804   Int_t numZCs=0;
00805 
00806 
00807   Double_t zcArray[1000]={0};
00808   Int_t countZC=0;
00809   
00810   for(int sample=0;sample<numSamples-1;sample++){
00811     Double_t y1=yVals[sample];
00812     Double_t y2=yVals[sample+1];
00813     if(y1<0 && y2>0){
00814       Double_t x1=xVals[sample]; 
00815       Double_t x2=xVals[sample+1]; 
00816       Double_t zc=((0-y1)/(y2-y1))*(x2-x1)+x1;
00817       //      if(zc<0.6) //printf("sample %i y1 %f y2 %f x1 %f x2 %f\n", sample, y1, y2, x1, x2);
00818       zcArray[countZC]=zc;
00819       countZC++;
00820       phase+=zc-numZCs*period;
00821       //printf("zc num %i val %f adjusted val %f\n", numZCs, zc, zc-numZCs*period);
00822       numZCs++;
00823       //return zc;
00824     }
00825   }//sample
00826 
00827 
00828   Double_t meanZC=0;
00829   
00830   if(countZC>0) {
00831     Double_t firstZC=zcArray[0];
00832     while(firstZC>period) firstZC-=period;
00833     for(int i=0;i<countZC;i++) {
00834       while((zcArray[i]-firstZC)>period) zcArray[i]-=period;
00835       if(TMath::Abs((zcArray[i]-period)-firstZC)<TMath::Abs(zcArray[i]-firstZC))
00836         zcArray[i]-=period;
00837       meanZC+=zcArray[i];
00838       //     std::cout << i << "\t" << zc[i] << "\n";     
00839     }
00840     meanZC/=countZC;
00841   }
00842   *totalZCs = countZC;
00843   *meanPhase = meanZC;
00844   return 0;
00845 }
00846 
00847 
00848 Int_t findFirstZC(TGraph *grIn, Double_t period, Double_t *firstAvZC){
00849 
00850 
00851   Int_t numPoints=grIn->GetN();
00852   if(numPoints<3) return 0;
00853   Double_t *tVals=grIn->GetX();
00854   Double_t *vVals=grIn->GetY();
00855 
00856   Double_t zc[1000]={0};
00857   Double_t rawZc[1000]={0};
00858   int countZC=0;
00859   for(int i=1;i<numPoints;i++) {
00860     if(vVals[i-1]<0 && vVals[i]>0) {
00861       Double_t x1=tVals[i-1];
00862       Double_t x2=tVals[i];
00863       Double_t y1=vVals[i-1];
00864       Double_t y2=vVals[i];      
00865       //      std::cout << i << "\t" << y2 << "\t" << y1 << "\t" << (y2-y1) << "\n";
00866       zc[countZC]=(((0-y1)/(y2-y1))*(x2-x1))+x1;
00867       rawZc[countZC]=zc[countZC];
00868       countZC++;
00869       //      if(countZC==1)
00870       //      break;
00871     }
00872   }
00873 
00874   Double_t firstZC=zc[0];
00875   while(firstZC>period) firstZC-=period;
00876   Double_t meanZC=0;
00877   for(int i=0;i<countZC;i++) {
00878      while((zc[i]-firstZC)>period) zc[i]-=period;
00879      if(TMath::Abs((zc[i]-period)-firstZC)<TMath::Abs(zc[i]-firstZC))
00880        zc[i]-=period;
00881      meanZC+=zc[i];
00882      //std::cout << i << "\t" << zc[i] << "\n";     
00883   }
00884   //  TCanvas *can = new TCanvas();
00885   //  TGraph *gr = new TGraph(countZC,rawZc,zc);
00886   //  gr->Draw("ap");
00887 
00888   //  std::cout << "\n";
00889   meanZC/=countZC;
00890   
00891   //  std::cout << zc << "\n";
00892   
00893   *firstAvZC=meanZC;
00894   return countZC;
00895 
00896 }
00897 
00898 Int_t findLastZC(TGraph *grIn, Double_t period, Double_t *lastAvZC){
00899 
00900  // This funciton estimates the lag by just using all the negative-positive zero crossing
00901  
00902   Int_t numPoints=grIn->GetN();
00903   if(numPoints<3) return 0;
00904   Double_t *tVals=grIn->GetX();
00905   Double_t *vVals=grIn->GetY();
00906 
00907   Double_t zc[1000]={0};
00908   Double_t rawZc[1000]={0};
00909   int countZC=0;
00910   for(int i=numPoints-1;i>1;i--) {
00911     if(vVals[i-1]<0 && vVals[i]>0) {
00912       Double_t x1=tVals[i-1];
00913       Double_t x2=tVals[i];
00914       Double_t y1=vVals[i-1];
00915       Double_t y2=vVals[i];      
00916       //      std::cout << i << "\t" << y2 << "\t" << y1 << "\t" << (y2-y1) << "\n";
00917       zc[countZC]=(((0-y1)/(y2-y1))*(x2-x1))+x1;
00918       rawZc[countZC]=zc[countZC];
00919       countZC++;
00920       //      if(countZC==1)
00921       //      break;
00922     }
00923   }
00924 
00925   Double_t lastZC=zc[0];
00926   while(lastZC<(tVals[numPoints-1]-period)) lastZC+=period;
00927   Double_t meanZC=0;
00928   for(int i=0;i<countZC;i++) {
00929      while((lastZC-zc[i])>period) zc[i]+=period;
00930      // if(TMath::Abs((zc[i]-period)-firstZC)<TMath::Abs(zc[i]-firstZC))
00931      //   zc[i]-=period;]
00932      if((zc[i]+period-lastZC)<(lastZC-zc[i]))
00933        zc[i]+=period;
00934     
00935      meanZC+=zc[i];
00936      //     std::cout << i << "\t" << zc[i] << "\n";     
00937   }
00938   //  TCanvas *can = new TCanvas();
00939   //  TGraph *gr = new TGraph(countZC,rawZc,zc);
00940   //  gr->Draw("ap");
00941 
00942   //  std::cout << "\n";
00943   meanZC/=countZC;
00944   *lastAvZC=meanZC;
00945 
00946   //  std::cout << lastZC << "\t" << meanZC << "\n";
00947   return countZC;
00948   
00949 }
00950 
00951 TGraph *applyCalibToHalfGraphTwoBlocks(TGraph* gr, Int_t dda, Int_t chan, Int_t half){
00952 
00953   if(half<0 || half >1){
00954 
00955     fprintf(stderr, "%s : half invalid %i \n", __FUNCTION__, half);
00956     return NULL;
00957 
00958   }
00959 
00960   Int_t numSamples = gr->GetN();
00961   if(numSamples!=SAMPLES_PER_BLOCK){
00962 
00963     fprintf(stderr, "%s : wrong number of samples %i expected %i\n", __FUNCTION__, numSamples, SAMPLES_PER_BLOCK);
00964     return NULL;
00965 
00966   }
00967   
00968   Double_t *yVals = gr->GetY();
00969   Double_t *xVals = new Double_t[SAMPLES_PER_BLOCK];
00970   
00971   for(Int_t sample=0;sample<SAMPLES_PER_BLOCK;sample++){
00972     xVals[sample] = times_two_blocks_one_half[dda][chan][half][sample];
00973   }//sample
00974   
00975   TGraph *grHalfCalibrated = new TGraph(SAMPLES_PER_BLOCK, xVals, yVals);
00976   delete xVals;
00977 
00978   return grHalfCalibrated;
00979 }
00980 
00981  TGraph *applyCalibToHalfGraphOneBlock(TGraph* gr, Int_t dda, Int_t chan, Int_t capArray, Int_t half){
00982 
00983    if(half<0 || half >1){
00984 
00985      fprintf(stderr, "%s : half invalid %i \n", __FUNCTION__, half);
00986      return NULL;
00987 
00988    }
00989 
00990    Int_t numSamples = gr->GetN();
00991    if(numSamples!=SAMPLES_PER_BLOCK/2){
00992 
00993      fprintf(stderr, "%s : wrong number of samples %i expected %i\n", __FUNCTION__, numSamples, SAMPLES_PER_BLOCK/2);
00994      return NULL;
00995 
00996    }
00997   
00998    Double_t *yVals = gr->GetY();
00999    Double_t *xVals = new Double_t[SAMPLES_PER_BLOCK/2];
01000   
01001    for(Int_t sample=0;sample<SAMPLES_PER_BLOCK/2;sample++){
01002      xVals[sample] = times_one_block_one_half[dda][chan][half][capArray][sample];
01003    }//sample
01004   
01005    TGraph *grHalfCalibrated = new TGraph(SAMPLES_PER_BLOCK/2, xVals, yVals);
01006    delete xVals;
01007 
01008    return grHalfCalibrated;
01009  }
01010 
01011 
01012 
01013 
01014 
01015 

Generated on Tue Jul 16 16:58:02 2013 for ARA ROOT v3.10 Software by doxygen 1.4.7