debugging/sample_lines/makeSampleLineHistos.cxx
00001 //makePedTree -- Run through a pedestal run and put the ADC values in a tree 00002 00003 #include "TFile.h" 00004 #include "TTree.h" 00005 #include "TGraph.h" 00006 #include "TH1.h" 00007 #include "TH2.h" 00008 #include "TH2D.h" 00009 #include "TCanvas.h" 00010 #include "RawAtriStationEvent.h" 00011 #include "UsefulAtriStationEvent.h" 00012 00013 #include <iostream> 00014 #include <stdio.h> 00015 #include <stdlib.h> 00016 00017 TGraph *getBlockGraph(TGraph*, Int_t); 00018 00019 int main(int argc, char **argv){ 00020 00021 if(argc<4){ 00022 00023 printf("Usage : %s <runFile> <outPutFile> <is mATRI>\n", argv[0]); 00024 return -1; 00025 00026 } 00027 00028 char runFileName[FILENAME_MAX]; 00029 sprintf(runFileName, "%s", argv[1]); 00030 char outFileName[FILENAME_MAX]; 00031 sprintf(outFileName, "%s", argv[2]); 00032 Int_t is_mATRI=atoi(argv[3]); 00033 Int_t no_ddas=4; 00034 if(is_mATRI) no_ddas=1; 00035 00036 00037 printf("inFileName %s\noutFileName %s\n", runFileName, outFileName); 00038 00039 TFile *fp = new TFile(runFileName); 00040 if(!fp) { 00041 std::cerr << "Can't open file\n"; 00042 return -1; 00043 } 00044 TTree *eventTree = (TTree*) fp->Get("eventTree"); 00045 if(!eventTree) { 00046 std::cerr << "Can't find eventTree\n"; 00047 return -1; 00048 } 00049 RawAtriStationEvent *evPtr=0; 00050 UsefulAtriStationEvent *realEvPtr=0; 00051 eventTree->SetBranchAddress("event",&evPtr); 00052 00053 TFile *outFile = new TFile(outFileName, "RECREATE"); 00054 Int_t blockId=0,channel=0,dda=0,sample=0, eventBlockNum=0, entry=0; 00055 Double_t adc=0; 00056 TH2D *hSampleLine[4][6]={{0}}; 00057 char histName[100]; 00058 char xAxisName[100]; 00059 char yAxisName[100]; 00060 for(dda=0;dda<no_ddas;dda++){ 00061 for(int i=0;i<6;i++){ 00062 sprintf(histName, "hSampleLine_bit%i_dda%i", i, dda); 00063 sprintf(xAxisName, "ADC Sample N"); 00064 sprintf(yAxisName, "ADC Sample N+%i", 1<<i); 00065 hSampleLine[dda][i] = new TH2D(histName, histName, 4096, 0, 4096, 4096, 0, 4096); 00066 hSampleLine[dda][i]->GetXaxis()->SetTitle(xAxisName); 00067 hSampleLine[dda][i]->GetYaxis()->SetTitle(yAxisName); 00068 // hSampleLine[dda][i]->SetOptStat(0); 00069 } 00070 } 00071 00072 00073 //Insert some large run and run start protection 00074 Int_t numEntries = eventTree->GetEntries(); 00075 if(numEntries>1000) numEntries=1000; 00076 Int_t starEvery = numEntries/80; 00077 if(!starEvery) starEvery = 1; 00078 00079 for(entry=100;entry<numEntries;entry++){ 00080 if((entry%starEvery)==0) fprintf(stderr, "*"); 00081 eventTree->GetEntry(entry); 00082 00083 realEvPtr = new UsefulAtriStationEvent(evPtr, AraCalType::kNoCalib); 00084 for(dda=0;dda<no_ddas;dda++){ 00085 for(channel=0;channel<1;channel++){ 00086 TGraph *grChannel = realEvPtr->getGraphFromElecChan(channel+dda*RFCHAN_PER_DDA); 00087 Int_t numBlocks = grChannel->GetN() / SAMPLES_PER_BLOCK; 00088 for(eventBlockNum=0;eventBlockNum<numBlocks;eventBlockNum++){ 00089 blockId = evPtr->blockVec[no_ddas*eventBlockNum+dda].getBlock(); 00090 Int_t dda_test = evPtr->blockVec[no_ddas*eventBlockNum+dda].getDda(); 00091 if(dda!=dda_test) fprintf(stderr, "wrong dda\n"); 00092 00093 TGraph *grBlock = getBlockGraph(grChannel, eventBlockNum); 00094 Double_t *yVals = grBlock->GetY(); 00095 uint32_t sample=0; 00096 for(sample=0;sample<SAMPLES_PER_BLOCK;sample++){ 00097 if(sample+1<SAMPLES_PER_BLOCK) hSampleLine[dda][0]->Fill(yVals[sample], yVals[sample+1], 1); 00098 if(sample+2<SAMPLES_PER_BLOCK) hSampleLine[dda][1]->Fill(yVals[sample], yVals[sample+2], 1); 00099 if(sample+4<SAMPLES_PER_BLOCK) hSampleLine[dda][2]->Fill(yVals[sample], yVals[sample+4], 1); 00100 if(sample+8<SAMPLES_PER_BLOCK) hSampleLine[dda][3]->Fill(yVals[sample], yVals[sample+8], 1); 00101 if(sample+16<SAMPLES_PER_BLOCK) hSampleLine[dda][4]->Fill(yVals[sample], yVals[sample+16], 1); 00102 if(sample+32<SAMPLES_PER_BLOCK) hSampleLine[dda][5]->Fill(yVals[sample], yVals[sample+32], 1); 00103 } 00104 00105 00106 if(grBlock) delete grBlock; 00107 }//block 00108 if(grChannel) delete grChannel; 00109 }//channel 00110 } 00111 00112 delete realEvPtr; 00113 00114 }//entry 00115 fprintf(stderr, "\n"); 00116 // for(dda=0;dda<no_ddas;dda++){ 00117 // for(int i=0;i<6;i++){ 00118 // hSampleLine[dda][i]->Write(); 00119 // } 00120 // } 00121 00122 //Make some canvases 00123 char canName[100]; 00124 char pdfName[200]; 00125 char pngName[200]; 00126 TCanvas *can[6]={0}; 00127 for(int i=0;i<6;i++){ 00128 sprintf(canName, "canBit%i", i); 00129 can[i]=new TCanvas(canName, canName); 00130 can[i]->Divide(2,2); 00131 can[i]->cd(1); 00132 hSampleLine[0][i]->Draw("COLZ"); 00133 can[i]->cd(2); 00134 hSampleLine[1][i]->Draw("COLZ"); 00135 can[i]->cd(3); 00136 hSampleLine[2][i]->Draw("COLZ"); 00137 can[i]->cd(4); 00138 hSampleLine[3][i]->Draw("COLZ"); 00139 sprintf(pdfName, "%s.bit%i.pdf", outFileName, i); 00140 sprintf(pngName, "%s.bit%i.png", outFileName, i); 00141 can[i]->SaveAs(pdfName); 00142 can[i]->SaveAs(pngName); 00143 // can[i]->Write(); 00144 00145 } 00146 00147 00148 00149 outFile->Write(); 00150 outFile->Close(); 00151 delete outFile; 00152 00153 return 0; 00154 } 00155 00156 TGraph *getBlockGraph(TGraph *fullEventGraph, Int_t block){ 00157 Int_t numSamples = fullEventGraph->GetN(); 00158 Int_t numBlocks = numSamples / SAMPLES_PER_BLOCK; 00159 if(block > numBlocks) return NULL; 00160 Double_t *fullX = fullEventGraph->GetX(); 00161 Double_t *fullY = fullEventGraph->GetY(); 00162 Double_t *blockX = new Double_t[SAMPLES_PER_BLOCK]; 00163 Double_t *blockY = new Double_t[SAMPLES_PER_BLOCK]; 00164 for(int sample=0;sample<SAMPLES_PER_BLOCK; sample++){ 00165 blockY[sample] = fullY[sample + block*SAMPLES_PER_BLOCK]; 00166 blockX[sample] = fullX[sample + block*SAMPLES_PER_BLOCK]; 00167 } 00168 TGraph *blockGraph = new TGraph(SAMPLES_PER_BLOCK, blockX, blockY); 00169 delete blockX; 00170 delete blockY; 00171 return blockGraph; 00172 } 00173
Generated on Tue Jul 16 16:58:02 2013 for ARA ROOT v3.10 Software by
