// 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) { string titleString; int fileLineCount=0; int nRunNumber, runType, nEventCount, bufferSequenceNumber, nRealTimeLR1, nRealTimeHR1; int nADC1time, nADC2time, nADC3time, nADC2ph, nADC3ph, nScalerValue[4]; int ntupleCount; int eventCount; int ntupleInCount=0; int ntupleOutCount=0; int scaler1Total[4]={0,0,0,0}; int nScaler1Old[4]={0,0,0,0}; int i; 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("inNtuple"); 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.output"); if(!nout) { cout << "Cannot open output file.\n"; return 1; } // output column names nout << "RunNum"<> nRunNumber >> runType >> nEventCount >> bufferSequenceNumber >> nRealTimeLR1 >> nRealTimeHR1 >> slowRampValue >> fastRampValue >> nADC1time >> nADC2time >> nADC3time >> nADC2ph >> nADC3ph >> nScalerValue[1] >> nScalerValue[2] >> nScalerValue[3] ; // detect an EOF if ( in.eof() != 0 ) { cout << "Found end of file..." << endl; break; } ntupleInCount++; for ( i=1; i<4; i++ ){ if ( nScalerValue[i] != nScaler1Old[i] ) { scaler1Total[i] = scaler1Total[i] + nScalerValue[i]; nScaler1Old[i]= nScalerValue[i]; } } fileLineCount++; if ( fileLineCount < 100 ) { cout << nRunNumber <update( (float) fastRampValue ); // make selection on ntuple read in if ( nADC1time != 0 && nADC2time != 0 && nADC3time != 0 ) { nout << nRunNumber <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 << "fileLineCount = " << fileLineCount << endl; cout << "ntupleInCount = " << ntupleInCount << endl; cout << "ntupleOutCount = " << ntupleOutCount << 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 << "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 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; }