calibration/ATRI/voltageCalib/getADCmVConversion2.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 "TF1.h" 00017 #include "TTree.h" 00018 #include "TMath.h" 00019 #include "TCanvas.h" 00020 #include "TChain.h" 00021 #include "TGraph.h" 00022 #include "TMultiGraph.h" 00023 00024 00025 //Standard Includes 00026 #include <iostream> 00027 #include <fstream> 00028 00029 00030 #define MAX_ADC 4096 00031 00032 //Prototype Functions 00033 Int_t getADCmVConversion(char *baseName, Int_t runLow, Int_t runHigh, Int_t thisBlock); 00034 TGraph *getZeroSubGraph(TGraph *gr, Int_t factor); 00035 TGraph *addGraphs(TGraph *grOne, TGraph *grTwo); 00036 00037 00038 int main(int argc, char **argv) 00039 { 00040 Int_t runLow, runHigh, block; 00041 char baseName[FILENAME_MAX]; 00042 00043 if(argc<5){ 00044 std::cerr << "Usage: " << argv[0] << " <baseDir> <runLow> <runHigh> <block> \n"; 00045 return 1; 00046 } 00047 sprintf(baseName, argv[1]); 00048 runLow=atoi(argv[2]); 00049 runHigh=atoi(argv[3]); 00050 block=atoi(argv[4]); 00051 getADCmVConversion(baseName, runLow, runHigh, block); 00052 00053 } 00054 00055 00056 00057 00058 00059 00060 Int_t getADCmVConversion(char *baseName, Int_t runLow, Int_t runHigh, Int_t thisBlock){ 00061 00062 TChain *chain = new TChain("maxPosNegTree"); 00063 char runName[FILENAME_MAX]; 00064 for(int run=runLow; run<=runHigh;run++){ 00065 sprintf(runName, "%s/root/run%i/adcSampleBlockNoPed.root", baseName, run); 00066 chain->Add(runName); 00067 } 00068 char outFileName[FILENAME_MAX]; 00069 sprintf(outFileName, "%s/root/voltageCalib2/ADCmVConversion.root", baseName); 00070 00071 Double_t *****theADC = new Double_t****[DDA_PER_ATRI]; 00072 Double_t *****theVoltage = new Double_t****[DDA_PER_ATRI]; 00073 Int_t ****index = new Int_t***[DDA_PER_ATRI]; 00074 Double_t maxNegValue=0, maxPosValue=0, voltage=0; 00075 Int_t dda=0,chan=0,sample=0,block=0; 00076 Int_t numVoltages=60; 00077 00078 for(dda=0;dda<DDA_PER_ATRI;dda++){ 00079 theADC[dda] = new Double_t***[RFCHAN_PER_DDA]; 00080 theVoltage[dda] = new Double_t***[RFCHAN_PER_DDA]; 00081 index[dda] = new Int_t**[RFCHAN_PER_DDA]; 00082 for(chan=0;chan<RFCHAN_PER_DDA;chan++){ 00083 theADC[dda][chan] = new Double_t**[SAMPLES_PER_BLOCK]; 00084 theVoltage[dda][chan] = new Double_t**[SAMPLES_PER_BLOCK]; 00085 index[dda][chan] = new Int_t*[SAMPLES_PER_BLOCK]; 00086 for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){ 00087 theADC[dda][chan][sample] = new Double_t*[BLOCKS_PER_DDA]; 00088 theVoltage[dda][chan][sample] = new Double_t*[BLOCKS_PER_DDA]; 00089 index[dda][chan][sample] = new Int_t[BLOCKS_PER_DDA]; 00090 for(block=0;block<BLOCKS_PER_DDA;block++){ 00091 theADC[dda][chan][sample][block]= new Double_t[numVoltages]; 00092 theVoltage[dda][chan][sample][block]=new Double_t[numVoltages]; 00093 index[dda][chan][sample][block]=0; 00094 } 00095 } 00096 } 00097 } 00098 00099 00100 //The stuff we want from the tree 00101 00102 chain->SetBranchAddress("dda", &dda); 00103 chain->SetBranchAddress("chan", &chan); 00104 chain->SetBranchAddress("sample", &sample); 00105 chain->SetBranchAddress("block", &block); 00106 00107 chain->SetBranchAddress("maxPosValue", &maxPosValue); 00108 chain->SetBranchAddress("maxNegValue", &maxNegValue); 00109 chain->SetBranchAddress("voltage", &voltage); 00110 00111 Int_t numEntries = chain->GetEntries(); 00112 Int_t starEvery = numEntries/80; 00113 for(int entry=0;entry<numEntries;entry++){ 00114 if(entry%starEvery==0) std::cerr << "*"; 00115 chain->GetEntry(entry); 00116 theADC[dda][chan][sample][block][index[dda][chan][sample][block]]=maxPosValue; 00117 theVoltage[dda][chan][sample][block][index[dda][chan][sample][block]]=voltage/2.; 00118 index[dda][chan][sample][block]++; 00119 00120 theADC[dda][chan][sample][block][index[dda][chan][sample][block]]=maxNegValue; 00121 theVoltage[dda][chan][sample][block][index[dda][chan][sample][block]]=-1*voltage/2.; 00122 index[dda][chan][sample][block]++; 00123 00124 } 00125 std::cerr << "\n"; 00126 00127 TFile *fpOut = new TFile(outFileName, "RECREATE"); 00128 fpOut->cd(); 00129 TGraph *****grADCmV = new TGraph****[DDA_PER_ATRI]; 00130 char grName[FILENAME_MAX]; 00131 char grTitle[FILENAME_MAX]; 00132 Int_t entry=0; 00133 starEvery=(DDA_PER_ATRI*RFCHAN_PER_DDA*SAMPLES_PER_BLOCK*BLOCKS_PER_DDA)/80; 00134 for(dda=0;dda<DDA_PER_ATRI;dda++){ 00135 grADCmV[dda] = new TGraph***[RFCHAN_PER_DDA]; 00136 for(chan=0;chan<RFCHAN_PER_DDA;chan++){ 00137 grADCmV[dda][chan] = new TGraph**[SAMPLES_PER_BLOCK]; 00138 for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){ 00139 grADCmV[dda][chan][sample] = new TGraph*[BLOCKS_PER_DDA]; 00140 for(block=0;block<BLOCKS_PER_DDA;block++){ 00141 entry++; 00142 if(entry%starEvery==0) std::cerr << "*"; 00143 grADCmV[dda][chan][sample][block] = new TGraph(index[dda][chan][sample][block], 00144 theADC[dda][chan][sample][block], 00145 theVoltage[dda][chan][sample][block]); 00146 sprintf(grName, "grADCVolt_%i_%i_%i_%i", dda, chan,sample,block); 00147 sprintf(grTitle, "grADCVolt_%i_%i_%i_%i", dda, chan,sample,block); 00148 00149 grADCmV[dda][chan][sample][block]->SetName(grName); 00150 grADCmV[dda][chan][sample][block]->SetTitle(grTitle); 00151 grADCmV[dda][chan][sample][block]->Write(); 00152 00153 delete [] theADC[dda][chan][sample][block]; 00154 delete [] theVoltage[dda][chan][sample][block]; 00155 delete grADCmV[dda][chan][sample][block]; 00156 } 00157 } 00158 } 00159 } 00160 std::cerr << "\n"; 00161 00162 fpOut->Write(); 00163 00164 fprintf(stderr, "Deleting!\n"); 00165 for(dda=0;dda<DDA_PER_ATRI;dda++){ 00166 for(chan=0;chan<RFCHAN_PER_DDA;chan++){ 00167 for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){ 00168 00169 delete [] theADC[dda][chan][sample]; 00170 delete [] index[dda][chan][sample]; 00171 delete [] grADCmV[dda][chan][sample]; 00172 delete [] theVoltage[dda][chan][sample]; 00173 00174 } 00175 ; 00176 delete [] theADC[dda][chan]; 00177 delete [] index[dda][chan]; 00178 delete [] grADCmV[dda][chan]; 00179 delete [] theVoltage[dda][chan]; 00180 } 00181 ; 00182 delete [] theADC[dda]; 00183 delete [] index[dda]; 00184 delete [] grADCmV[dda]; 00185 delete [] theVoltage[dda]; 00186 } 00187 00188 delete [] theADC; 00189 delete [] index; 00190 delete [] grADCmV; 00191 delete [] theVoltage; 00192 00193 fprintf(stderr, "Done!\n"); 00194 return 0; 00195 00196 } 00197 00198 00199 00200 TGraph *getZeroSubGraph(TGraph *gr, Int_t factor){ 00201 Int_t numEntries = gr->GetN(); 00202 Double_t *yVals=gr->GetY(); 00203 Double_t *xVals=gr->GetX(); 00204 00205 if(numEntries<=0) return NULL; 00206 Double_t *xValsNew = new Double_t[numEntries]; 00207 Double_t xValZero=0; 00208 00209 for(int entry=0;entry<numEntries;entry++){ 00210 if(yVals[entry]==0){ 00211 xValZero=xVals[entry]; 00212 break; 00213 } 00214 } 00215 for(int entry=0;entry<numEntries;entry++){ 00216 Double_t newX = TMath::Sqrt( TMath::Power(xVals[entry],2) - TMath::Power(xValZero,2) ); 00217 xValsNew[entry] = factor*newX; 00218 } 00219 00220 TGraph *grNew = new TGraph(numEntries, xValsNew, yVals); 00221 00222 00223 delete [] xValsNew; 00224 00225 return grNew; 00226 00227 } 00228 00229 TGraph *addGraphs(TGraph *grOne, TGraph *grTwo){ 00230 Int_t numEntriesOne = grOne->GetN(); 00231 Int_t numEntriesTwo = grTwo->GetN(); 00232 Double_t *yVals1 = grOne->GetY(); 00233 Double_t *xVals1 = grOne->GetX(); 00234 Double_t *yVals2 = grTwo->GetY(); 00235 Double_t *xVals2 = grTwo->GetX(); 00236 00237 Double_t *yValsNew = new Double_t[numEntriesOne+numEntriesTwo]; 00238 Double_t *xValsNew = new Double_t[numEntriesOne+numEntriesTwo]; 00239 00240 for(int entry = 0;entry<numEntriesOne;entry++){ 00241 xValsNew[entry] = xVals1[entry]; 00242 yValsNew[entry] = yVals1[entry]; 00243 } 00244 for(int entry = 0;entry<numEntriesTwo;entry++){ 00245 xValsNew[entry+numEntriesOne] = xVals2[entry]; 00246 yValsNew[entry+numEntriesOne] = yVals2[entry]; 00247 } 00248 00249 TGraph *grNew = new TGraph(numEntriesOne+numEntriesTwo, xValsNew, yValsNew); 00250 00251 delete [] yValsNew; 00252 delete [] xValsNew; 00253 00254 return grNew; 00255 } 00256
Generated on Tue Jul 16 16:58:02 2013 for ARA ROOT v3.10 Software by
