// reads raw data from run_xxx.txt assigned to link indata // writes ascii tuple file: ntuple.ascii using nout #include #include #include // needed by ofstream to open output file #include "histogram.h" #include #include #define DEBUG 0 #define DEBUG2 1 #define TAB '\t' using namespace std; unsigned getbits( unsigned x, unsigned p, unsigned n) { /* get n bits from position p */ return (( x >> (p+1-n)) & ~(~0 << n)); } int main(int argc, char** argv) { int i,j,k; int lineID, hdata1, ddata1, hdata2, ddata2; int feraID; int lineTotalLineCount = 0; int blockCount = 0; int fileLineCount = 0; int linesInChunk=0; int bufferNumber=0, bufferCount=0; string titleString; int ptrToNext=1; bool notTheFirst=false, ptrData=false, firstTime = true ; bool ad114Header1 = false; bool ad114Header2 = false; bool ad114Header3 = false; bool ad114Header4 = false; int ad114Header1Count=0; int ad114Header2Count=0; int ad114Header3Count=0; int ad114Header4Count=0; int ntupleCount=0; //unsigned int event[18]; unsigned int event[28]; int errorType1count = 0; int nRunNumber=0, nEventCount=0; int runType=0; int bufferSequenceNumber=0; int bufferStartTimeLR=0, bufferStartTimeHR=0, bufferEndTimeLR=0, bufferEndTimeHR=0; int slowRampTimeAdc=0, fastRampTimeAdc=0, nRampTimeAdc=0; int trig1TimeTdc=0, trig2TimeTdc=0, cherenkov=0; int nADC1time = 0, nADC2time = 0; int nADC3time = 0, nADC4time = 0; int nADC0ph = 0, nADC1ph = 0, nADC2ph = 0, nADC3ph = 0, nADC4ph = 0; //note adc ch addresess int nRealTimeLR1 =0, nRealTimeHR1=0; int nRealTimeLR2 =0, nRealTimeHR2=0; int nCherenkovADC=0; float clockTime=0; int initTime = 0; int scalerPointer=0; int nScalerValue[4]; #define N21 #define EVSIZE 23 #define ADCLOC 0 #define AD1LOC 17 #define AD2LOC 19 #define AD3LOC 21 /* definintions for N21 0 ladc header 8005 1 adc channel 0 ... 15 adc channel 14 16 adc channel 15 17 AD114 header 8801 18 AD114 data 19 AD114 header 8802 20 AD114 data 21 AD114 header 8803 22 AD114 data */ /* -5 0 0 0 0 ScalerData Pointer -4 11 17 11 17 RealTime LR - Offset -3 79ff1 499697 86be7 551911 RealTime HR -2 4 4 5 5 CrateID -1 3e04 15876 3e04 15876 mPointers 0 8005 32773 8006 32774 header 1 c9 201 2e 46 2 81a 2074 828 2088 3 101a 4122 102b 4139 4 1813 6163 181e 6174 5 201a 8218 202d 8237 6 281c 10268 2825 10277 7 301c 12316 3030 12336 8 3819 14361 382b 14379 9 4020 16416 402c 16428 10 481d 18461 4826 18470 11 501b 20507 502a 20522 12 5820 22560 5824 22564 13 601e 24606 6029 24617 14 681b 26651 682d 26669 15 701e 28702 7027 28711 16 7869 30825 79c8 31176 */ int inHexData=0, inDecData=0; int Mindex1=0, Mindex2=0; int data1H[16100], data1D[16100], data2H[16100], data2D[16100]; int scaler1[3], scaler1Total[4]={0,0,0,0}; int realTimeLRc1=0, realTimeHRc1=0, realTimeLRc2=0, realTimeHRc2=0; int crateIDc1=0, crateIDc2=0; int memoryPointer=0, memoryPointer1=0, memoryPointer2=0; int memoryIndex1=0, memoryIndex2=0; int inIndex[EVSIZE], inHdata1[EVSIZE], inDdata1[EVSIZE]; int inIndexM=0; int indexEv=0; int countADCheader1=0, countADCheader2=0; int countAD114header1=0, countAD114header2=0; int countAD114header3=0, countAD114header4=0; int lineCount=0, eventCount=0; int lAdc1ChAddr[16], lAdc2ChAddr[16]; int lAdc1ChData[16], lAdc2ChData[16]; int missingOrtecHeaderCount[4] = {0,0,0,0}; int offSet1, offSet2; bool flag1, flag2, flag3, flag4; int evCountHdr=0; int evCountHdr1=0, evCountHdr2=0; int LadcHeader1counter=0, LadcHeader2counter=0; int correctedLadcHeader; int correctedOadcHeader1, correctedOadcData1; int correctedOadcHeader2, correctedOadcData2; int correctedOadcHeader3, correctedOadcData3; int correctedOadcHeader4, correctedOadcData4; int ptr1LadcHdr, ptr1OadcHdr1, ptr1OadcHdr2, ptr1OadcHdr3; //int ptr2LadcHdr, ptr2OadcHdr1, ptr2OadcHdr2; int channelCount1=0, channelCount2=0; int channelAddr = 0; unsigned int retest=0; float alim=0.0, blim=16384.0; // alim= 0.0; blim = 4000; // alim=3000.0, blim=7000.0; // trigger1 // alim=2060.0; blim=2100.0; histogram *hADCtime1 = new histogram( alim, blim, "h time ADC TAC 1 data "); // alim=1850.0; blim=1890.0; histogram *hADCtime2 = new histogram( alim, blim, "h time ADC TAC 2 data "); histogram *hADCtime3 = new histogram( alim, blim, "h time ADC TAC 3 data "); blim=20.0; histogram *hADC3minus2 = new histogram (-blim,blim,"h time difference mcp 3 - mcp 4 "); histogram *hTAC1fs = new histogram( 2130.0, 2150.0, "h TAC 1 fine scale for pulser data "); histogram *hTAC2fs = new histogram( 2810.0, 2830.0, "h TAC 2 fine scale for pulser data "); histogram *hTAC3fs = new histogram( 2815.0, 2835.0, "h TAC 3 fine scale for pulser data "); alim=0.0; blim=200.; histogram *hADCpm1 = new histogram(alim, blim, "h ph ADC 1 data "); histogram *hADCpm2 = new histogram(alim, blim, "h ph ADC 2 data "); histogram *hADCpm3 = new histogram(alim, blim, "h ph ADC 3 data "); int slowRampValue, fastRampValue; // adc is 10 bits so max is 1024 histogram *hSlowRamp = new histogram(0.0, 600.0 , "h Slow Ramp data "); histogram *hFastRamp = new histogram(0.0, 600.0 , "h Fast Ramp data "); //cout << "Enter Run Description parameters: " << endl; //cout <<"runNumber pulserDelay pulserPeriod " << endl; //cin >> runNumber >> pulserDelay >> pulserPeriod; ifstream in("indata"); if ( !in ) { cout << "Cannot open input file. Exit with error. \n"; return 1; } // 1st line is text not data //getline(in,titleString); //fileLineCount++; cout << "Title: " << titleString << endl; cout << "DEBUG:\tLine\tlineID\thdata\tddata" << endl; // open an output stream to make file of ascii nutples for ROOT ofstream nout("ntuple.ascii"); if(!nout) { cout << "Cannot open output file.\n"; return 1; } // output column names nout << "RunNum"<> inIndexM >> hex >> inHexData >> dec >> inDecData; lineCount++; if (DEBUG ) cout << inIndexM << TAB << hex << inHexData << TAB << dec << inDecData << endl; if ( inIndexM == -7 ) { scalerPointer = inDecData; if ( scalerPointer != 0) { for ( k=0; k< scalerPointer; k++) { in >> inIndexM >> hex >> inHexData >> dec >> inDecData; if (DEBUG) cout << inIndexM << TAB << hex << inHexData << TAB << dec << inDecData< 15 ) { cout << "Error extracting Channel address from 4300" << endl; return 1; } lAdc1ChAddr[channelAddr] = channelAddr; lAdc1ChData[channelAddr] = getbits(inHdata1[ADCLOC+1+i],10,10); } if ( inHdata1[AD1LOC+1] > 0 ) hADCtime1->update( (float) inHdata1[AD1LOC+1] ); if ( inHdata1[AD2LOC+1] > 0 ) hADCtime2->update( (float) inHdata1[AD2LOC+1] ); if ( inHdata1[AD3LOC+1] > 0 ) hADCtime3->update( (float) inHdata1[AD3LOC+1] ); if ( nADC1time > 0 ) hTAC1fs->update( (float) nADC1time ); if ( nADC2time > 0 ) hTAC2fs->update( (float) nADC2time ); if ( nADC3time > 0 ) hTAC3fs->update( (float) nADC3time ); int timeDiff = nADC3time - nADC2time; if ( timeDiff != 0 ) hADC3minus2->update ( (float) timeDiff ); hADCpm1->update( (float) lAdc1ChData[2] ); hADCpm2->update( (float) lAdc1ChData[3] ); hADCpm3->update( (float) lAdc1ChData[4] ); slowRampValue = lAdc1ChData[0]; fastRampValue = lAdc1ChData[1]; nRampTimeAdc = slowRampValue; /* choose only one for current ntuple */ hSlowRamp->update( (float) slowRampValue ); hFastRamp->update( (float) fastRampValue ); if ( DEBUG && (eventCount < 10) ) { for ( i=0; i<16; i++ ) { cout << " " << lAdc1ChAddr[i] << ":" << " " << lAdc1ChData[i] << endl; } cout << endl; cout << "nADC1time="<printLong(); hADCtime2->printLong(); hADCtime3->printLong(); hADC3minus2->printLong(); hTAC1fs->printLong(); hTAC2fs->printLong(); hTAC3fs->printLong(); hADCpm1->printLong(); hADCpm2->printLong(); hADCpm3->printLong(); hSlowRamp->printLong(); hFastRamp->printLong(); cout << endl; cout << "Found " << lineCount << " lines." << endl; cout << "eventCount = " << eventCount << endl; cout << "errorType1count = " << errorType1count << endl; cout << "countADCheader1 = " << countADCheader1 << endl; cout << "countAD114header1 = " << countAD114header1 << endl; cout << "countAD114header2 = " << countAD114header2 << endl; cout << "countAD114header3 = " << countAD114header3 << endl; cout << "ntupleCount = " << ntupleCount << endl; cout << "ADCtime1 count/mean/stdev = " << hADCtime1->get_sumIn() << TAB << hADCtime1->mean() << TAB << hADCtime1->stdev() << endl; cout << "ADCtime2 count/mean/stdev = " << hADCtime2->get_sumIn() << TAB << hADCtime2->mean() << TAB << hADCtime2->stdev() << endl; cout << "ADCtime3 count/mean/stdev = " << hADCtime3->get_sumIn() << TAB << hADCtime3->mean() << TAB << hADCtime3->stdev() << endl; cout << "Missing Ortec Header counts: "; for ( i=0;i<4;i++) cout << missingOrtecHeaderCount[i] << TAB; cout << endl; cout << "TAC1 efficiency fraction = " << ( (float) hADCtime1->get_sumIn())/eventCount << endl; cout << "TAC2 efficiency fraction = " << ( (float) hADCtime2->get_sumIn())/eventCount << endl; cout << "TAC3 efficiency fraction = " << ( (float) hADCtime3->get_sumIn())/eventCount << endl; cout << "Scaler ch 0 (spill stop) = " << scaler1Total[0] << endl; cout << "Scaler ch 1 (raw trigger) = " << scaler1Total[1] << endl; cout << "Scaler ch 2 (master trigger) = " << scaler1Total[2] << endl; cout << "Scaler ch 3 (FERA tokens) = " << scaler1Total[3] << endl; cout << "End of event builder and ntuple writer." << endl; cout << endl; nout.close(); return 0; }