ARA ROOT v3.10 Software

calibration/ATRI/voltageCalib/adcSample.cxx

00001 
00002 
00003 
00004 
00005 
00006 //AraRoot Includes
00007 #include "UsefulAtriStationEvent.h"
00008 #include "RawAtriStationEvent.h"
00009 #include "araSoft.h"
00010 
00011 
00012 //Root Includes
00013 #include "TTree.h"
00014 #include "TFile.h"
00015 #include "TH1.h"
00016 #include "TTree.h"
00017 #include "TMath.h"
00018 #include "TCanvas.h"
00019 
00020 
00021 //Standard Includes
00022 #include <iostream>
00023 #include <fstream>
00024 
00025 
00026 #define MAX_ADC 4096
00027 
00028 //Prototype Functions
00029 Int_t adcSample(char*, Int_t, Int_t, Double_t);
00030 
00031 
00032 int main(int argc, char **argv)
00033 {
00034   Int_t runNum=0, pedNum=0, dda=0, chan=0;
00035   char baseName[FILENAME_MAX];
00036 
00037   if(argc<5) {
00038     std::cerr << "Usage: " << argv[0] << " <baseDir> <runNum> <pedNum> <voltage> \n";
00039     return 1;
00040   }
00041   sprintf(baseName, argv[1]);
00042   runNum=atoi(argv[2]);
00043   pedNum=atoi(argv[3]);
00044   Double_t voltage = atof(argv[4]);
00045   return adcSample(baseName, runNum, pedNum, voltage);
00046   //return test(baseName, runNum, pedNum, voltage);
00047 
00048 }
00049 
00050 Int_t adcSample(char* baseDirName, Int_t runNum, Int_t pedNum, Double_t voltage){
00051   printf("%s\n", baseDirName);
00052   printf("%i %i %f\n", runNum, pedNum, voltage);
00053 
00054 
00055   char runFileName[FILENAME_MAX];
00056   char pedFileName[FILENAME_MAX];
00057   sprintf(runFileName, "%s/root/run%i/event%i.root", baseDirName, runNum, runNum);
00058   sprintf(pedFileName, "%s/raw_data/run_%06i/pedestalValues.run%06i.dat", baseDirName, pedNum, pedNum);
00059 
00060   fprintf(stderr, "%s\n", runFileName);
00061   fprintf(stderr, "%s\n", pedFileName);
00062   
00063   TFile *fp = new TFile(runFileName);
00064   if(!fp) {
00065     std::cerr << "Can't open file\n";
00066     return -1;
00067   }
00068   TTree *eventTree = (TTree*) fp->Get("eventTree");
00069   if(!eventTree) {
00070     std::cerr << "Can't find eventTree\n";
00071     return -1;
00072   }
00073   RawAtriStationEvent *evPtr=0;
00074   eventTree->SetBranchAddress("event",&evPtr);
00075   Long64_t numEntries=eventTree->GetEntries();
00076 
00077   Long64_t starEvery=numEntries/80;
00078   if(starEvery==0) starEvery++;
00079   
00080   Int_t stationId=0;
00081   eventTree->GetEntry(0);
00082   stationId= evPtr->stationId;
00083   AraEventCalibrator *calib = AraEventCalibrator::Instance();
00084   calib->setAtriPedFile(pedFileName, stationId);
00085   
00086   //General output stuff
00087   char outFileName[FILENAME_MAX];
00088   sprintf(outFileName, "%s/root/run%i/adcSample.root", baseDirName, runNum);
00089   TFile *outFile = new TFile(outFileName, "RECREATE");
00090 
00091    std::cout << "Output file " << outFileName << std::endl;
00092 
00093   //Variables what we need
00094   Int_t chanIndex;
00095   Int_t capArray;
00096   Int_t sample;
00097   Int_t thisCapArray=0;
00098   Int_t dda=0, chan=0;
00099   Int_t hasVoltCalib=0;
00100   Double_t ADC=0;
00101 
00102   TTree *voltageTree = new TTree("voltageTree", "Tree of voltages from run");
00103   voltageTree->Branch("dda", &dda, "dda/I");
00104   voltageTree->Branch("chan", &chan, "chan/I");
00105   voltageTree->Branch("sample", &sample, "sample/I");
00106   voltageTree->Branch("thisCapArray", &thisCapArray, "thisCapArray/I");
00107   voltageTree->Branch("ADC", &ADC, "ADC/D");
00108   voltageTree->Branch("hasVoltCalib", &hasVoltCalib, "hasVoltCalib/I");
00109 
00110 
00111   UsefulAtriStationEvent *realEvent=0;
00112   UsefulAtriStationEvent *realEventNoVoltCalib=0;
00113 
00114 
00115   // //  numEntries=1;//FIXME
00116   for(int entry=10;entry<numEntries;entry++){
00117     if(entry%starEvery==0) std::cerr <<"*";
00118     eventTree->GetEntry(entry);
00119 
00120     realEvent = new UsefulAtriStationEvent(evPtr, AraCalType::kVoltageTime);
00121     realEventNoVoltCalib = new UsefulAtriStationEvent(evPtr, AraCalType::kJustPed);
00122 
00123     capArray = evPtr->blockVec[0].getCapArray(); //capArray of first block
00124     
00125     for(dda=0;dda<DDA_PER_ATRI;dda++){
00126       for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00127         chanIndex=chan+RFCHAN_PER_DDA*dda;
00128 
00129 
00130         hasVoltCalib=1;
00131         TGraph *gr = realEvent->getGraphFromElecChan(chanIndex);
00132         Int_t numSamples = gr->GetN();
00133         Int_t numBlocks = numSamples/SAMPLES_PER_BLOCK;
00134         Double_t *yVals=gr->GetY();
00135 
00136         for(int block=0; block<numBlocks; block++){ 
00137           if(block%2) thisCapArray=1-capArray;
00138           else thisCapArray=capArray;
00139           
00140           
00141           for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){
00142             ADC = yVals[sample];
00143             
00144             voltageTree->Fill();
00145             
00146           }
00147         }//block
00148         delete gr;
00149 
00150         hasVoltCalib=0;
00151         gr = realEventNoVoltCalib->getGraphFromElecChan(chanIndex);
00152         numSamples = gr->GetN();
00153         numBlocks = numSamples/SAMPLES_PER_BLOCK;
00154         yVals=gr->GetY();
00155 
00156         for(int block=0; block<numBlocks; block++){ 
00157           if(block%2) thisCapArray=1-capArray;
00158           else thisCapArray=capArray;
00159           
00160           
00161           for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){
00162             ADC = yVals[sample];
00163             
00164             voltageTree->Fill();
00165             
00166           }
00167         }//block
00168         
00169         delete gr;
00170       }//chan
00171     }//dda
00172     delete realEvent;
00173     delete realEventNoVoltCalib;
00174 
00175 
00176   }//entry
00177   std::cerr << "\n";
00178 
00179 
00180   outFile->cd();
00181   voltageTree->Write();
00182 
00183   outFile->Write();
00184  
00185 
00186   return 0;
00187 }
00188 
00189 

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