ARA ROOT v3.10 Software

calibration/ATRI/voltageCalib/getADCmVConversion.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 int main(int argc, char **argv)
00038 {
00039   Int_t runLow, runHigh, block;
00040   char baseName[FILENAME_MAX];
00041 
00042   if(argc<5){
00043     std::cerr << "Usage: " << argv[0] << " <baseDir> <runLow> <runHigh> <block>  \n";
00044     return 1;
00045   }
00046   sprintf(baseName, argv[1]);
00047   runLow=atoi(argv[2]);
00048   runHigh=atoi(argv[3]);
00049   block=atoi(argv[4]);
00050   getADCmVConversion(baseName, runLow, runHigh, block);
00051 
00052 }
00053 
00054 
00055 
00056 
00057 
00058 
00059 Int_t getADCmVConversion(char *baseName, Int_t runLow, Int_t runHigh, Int_t thisBlock){
00060 
00061   TChain *chain = new TChain("maxPosNegTree");
00062   char runName[FILENAME_MAX];
00063   for(int run=runLow; run<=runHigh;run++){
00064     sprintf(runName, "%s/root/run%i/adcSampleBlock.root", baseName, run);
00065     chain->Add(runName);
00066   }
00067   char outFileName[FILENAME_MAX];
00068   sprintf(outFileName, "%s/root/voltageCalibThursdayPM/ADCmVConversion_block%i.root", baseName, thisBlock);
00069   
00070   TFile *outFile = new TFile(outFileName, "RECREATE");
00071 
00072   Int_t dda=0, chan=0, sample=0, block=0, posNeg=0, ndf=0;
00073   Double_t maxPosValue=0, maxNegValue=0, voltage=0;
00074   Double_t p0=0, p1=0, p2=0, p3=0, p4=0, chiSq=0;
00075   
00076 
00077   
00078   char exp[100];
00079   char cut[100];
00080   char grName[100];
00081   TGraph *grTemp;
00082   TCanvas *tempCan;
00083 
00084   TF1* funcPos = new TF1("myPosPol3", "pol3");
00085   TF1* funcNeg = new TF1("myNegPol1", "pol1");
00086   funcPos->SetParLimits(1, 0,2);
00087   funcPos->SetParLimits(2, -1,+1);
00088   funcPos->SetParLimits(3, -1,+1);
00089   funcNeg->SetParLimits(1, 0,+2);
00090   funcPos->FixParameter(0,0);
00091   funcNeg->FixParameter(0,0);
00092         
00093 
00094   TTree *fitTree = new TTree("fitTree", "Tree of fit parameters");
00095   fitTree->Branch("dda", &dda, "dda/I");
00096   fitTree->Branch("chan", &chan, "chan/I");
00097   fitTree->Branch("sample", &sample, "sample/I");
00098   fitTree->Branch("block", &block, "block/I");
00099   fitTree->Branch("ndf", &ndf, "ndf/I");
00100   fitTree->Branch("posNeg", &posNeg, "posNeg/I");
00101 
00102   fitTree->Branch("p0", &p0, "p0/D");
00103   fitTree->Branch("p1", &p1, "p1/D");
00104   fitTree->Branch("p2", &p2, "p2/D");
00105   fitTree->Branch("p3", &p3, "p3/D");
00106   fitTree->Branch("chiSq", &chiSq, "chiSq/D");
00107 
00108 
00109 
00110   block=thisBlock;
00111 
00112   for(dda=0;dda<DDA_PER_ATRI;dda++){
00113     for(chan=0;chan<RFCHAN_PER_DDA;chan++){
00114       fprintf(stderr, "dda %i chan %i ", dda, chan);
00115       for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){
00116         if(chan>5) continue;
00117         if((dda==1 || dda==2)&&(chan>3)) continue;
00118 
00119         //Reset starting point of parameters
00120         funcPos->SetParameter(1, 1.0);
00121         funcPos->SetParameter(2, -0.001);
00122         funcPos->SetParameter(3, 0);
00123         funcNeg->SetParameter(1, 0.55);
00124 
00125         fprintf(stderr, "%i ", sample);
00126         sprintf(exp, "voltage/2:maxPosValue");
00127         sprintf(cut, "dda==%i&&chan==%i&&block==%i&&sample==%i", dda, chan, block, sample);
00128         sprintf(grName, "grPos_%i_%i_%i_%i", dda, chan, block, sample);
00129         tempCan = new TCanvas();
00130         chain->Draw(exp, cut);
00131         grTemp = (TGraph*)tempCan->GetPrimitive("Graph");
00132         TGraph *grPosTemp = getZeroSubGraph(grTemp, +1);
00133 
00134         grPosTemp->SetName(grName);
00135         grPosTemp->Fit("myPosPol3", "QBW");
00136         p0=funcPos->GetParameter(0);
00137         p1=funcPos->GetParameter(1);
00138         p2=funcPos->GetParameter(2);
00139         p3=funcPos->GetParameter(3);
00140         chiSq =funcPos->GetChisquare();
00141         ndf = funcPos->GetNDF();
00142         p4=0;
00143         posNeg=+1;
00144         //      printf("%i %i %i %i %f %f\n", dda, chan, block, sample, p1, p2);
00145         fitTree->Fill();
00146         delete tempCan;
00147         
00148         
00149         tempCan = new TCanvas();
00150         sprintf(exp, "-1*voltage/2:maxNegValue");
00151         sprintf(grName, "grNeg_%i_%i_%i_%i", dda, chan, block, sample);   
00152         chain->Draw(exp, cut);
00153         grTemp = (TGraph*)tempCan->GetPrimitive("Graph");
00154         TGraph *grNegTemp = getZeroSubGraph(grTemp, -1);
00155 
00156         grNegTemp->SetName(grName);
00157         grNegTemp->Fit("myNegPol1", "QBW");
00158         p0=funcNeg->GetParameter(0);
00159         p1=funcNeg->GetParameter(1);
00160         chiSq=funcNeg->GetChisquare();
00161         p2=0;
00162         p3=0;
00163         p4=0;
00164 
00165         posNeg=-1;
00166         //      printf("%i %i %i %i %f %f\n", dda, chan, block, sample, p1, p2);
00167         fitTree->Fill();
00168         delete tempCan;
00169         
00170 
00171         outFile->cd();
00172         grPosTemp->Write();
00173         grNegTemp->Write();
00174         delete grNegTemp;       
00175         delete grPosTemp;
00176 
00177 
00178       }
00179       fprintf(stderr, "\n");
00180     }
00181   }
00182 
00183   outFile->cd();
00184   fitTree->Write();
00185 
00186   fprintf(stderr, "Done!\n");
00187 
00188   delete funcPos;
00189   delete funcNeg;
00190 
00191 
00192   return 0;
00193 
00194 }
00195 
00196 
00197 
00198 TGraph *getZeroSubGraph(TGraph *gr, Int_t factor){
00199   Int_t numEntries = gr->GetN();
00200   Double_t *yVals=gr->GetY();
00201   Double_t *xVals=gr->GetX();
00202   
00203   if(numEntries<=0) return NULL;
00204   Double_t *xValsNew = new Double_t[numEntries];
00205   Double_t xValZero=0;
00206 
00207   for(int entry=0;entry<numEntries;entry++){
00208     if(yVals[entry]==0){
00209       xValZero=xVals[entry];
00210       break;
00211     }
00212   }
00213   for(int entry=0;entry<numEntries;entry++){
00214     Double_t newX = TMath::Sqrt( TMath::Power(xVals[entry],2) - TMath::Power(xValZero,2) );
00215     xValsNew[entry] = factor*newX;
00216   }
00217 
00218   TGraph *grNew = new TGraph(numEntries, xValsNew, yVals);
00219 
00220 
00221   delete [] xValsNew;
00222 
00223   return grNew;
00224 
00225 }
00226 
00227 TGraph *addGraphs(TGraph *grOne, TGraph *grTwo){
00228   Int_t numEntriesOne = grOne->GetN();
00229   Int_t numEntriesTwo = grTwo->GetN();
00230   Double_t *yVals1 = grOne->GetY();
00231   Double_t *xVals1 = grOne->GetX();
00232   Double_t *yVals2 = grTwo->GetY();
00233   Double_t *xVals2 = grTwo->GetX();
00234 
00235   Double_t *yValsNew = new Double_t[numEntriesOne+numEntriesTwo];
00236   Double_t *xValsNew = new Double_t[numEntriesOne+numEntriesTwo];
00237 
00238   for(int entry = 0;entry<numEntriesOne;entry++){
00239     xValsNew[entry] = xVals1[entry];
00240     yValsNew[entry] = yVals1[entry];
00241   }
00242   for(int entry = 0;entry<numEntriesTwo;entry++){
00243     xValsNew[entry+numEntriesOne] = xVals2[entry];
00244     yValsNew[entry+numEntriesOne] = yVals2[entry];
00245   }
00246 
00247   TGraph *grNew = new TGraph(numEntriesOne+numEntriesTwo, xValsNew, yValsNew);
00248 
00249   delete [] yValsNew;
00250   delete [] xValsNew;
00251 
00252   return grNew;
00253 }

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