// tup formated ascii data is "adc1 adc2 tac1 tac2 tac3" // reads tup data from link inTup using instream=in // writes ascii tup file to file: tup.ascii.output using outstram=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 ntupleCount; int eventCount; int ntupleInCount=0; int ntupleOutCount=0; int i; int adc1, adc2, tac1, tac2, tac3; float alim=0.0, blim=16384.0; // alim= 0.0; blim = 4000; histogram *htac1 = new histogram( alim, blim, "h time ADC TAC 1 data "); histogram *htac2 = new histogram( alim, blim, "h time ADC TAC 2 data "); histogram *htac3 = new histogram( alim, blim, "h time ADC TAC 3 data "); histogram *hTAC1fs = new histogram( 2000.0, 4000.0, "h TAC 1 fine scale for pulser data "); histogram *hTAC2fs = new histogram( 6000.0, 8000.0, "h TAC 2 fine scale for pulser data "); histogram *hTAC3fs = new histogram( 6000.0, 8000.0, "h TAC 3 fine scale for pulser data "); alim=0.0; blim=1000.; histogram *hADCpm1 = new histogram(alim, blim, "h ph ADC 1 data "); histogram *hADCpm2 = new histogram(alim, blim, "h ph ADC 2 data "); ifstream in("inTup"); 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("tup.ascii.output"); if(!nout) { cout << "Cannot open output file.\n"; return 1; } // output column names nout << "adc1"<> adc1 >> adc2 >> tac1 >> tac2 >> tac3; // detect an EOF if ( in.eof() != 0 ) { cout << "Found end of file..." << endl; break; } ntupleInCount++; fileLineCount++; if ( fileLineCount < 100 ) { cout << adc1 <update( (float) adc1 ); hADCpm2->update( (float) adc2 ); htac1->update( (float) tac1 ); htac2->update( (float) tac2 ); htac3->update( (float) tac3 ); hTAC1fs->update( (float) tac1 ); hTAC2fs->update( (float) tac2 ); hTAC3fs->update( (float) tac3 ); // make selection on ntuple read in if ( tac1 != 0 && tac2 != 0 && tac3 != 0 ) { nout << adc1 <printLong(); htac2->printLong(); htac3->printLong(); hTAC1fs->printLong(); hTAC2fs->printLong(); hTAC3fs->printLong(); hADCpm1->printLong(); hADCpm2->printLong(); cout << endl; cout << "fileLineCount = " << fileLineCount << endl; cout << "ntupleInCount = " << ntupleInCount << endl; cout << "ntupleOutCount = " << ntupleOutCount << endl; cout << "TAC1 count/mean/stdev = " << hTAC1fs->get_sumIn() << TAB << hTAC1fs->mean() << TAB << hTAC1fs->stdev() << endl; cout << "TAC2 count/mean/stdev = " << hTAC2fs->get_sumIn() << TAB << hTAC2fs->mean() << TAB << hTAC2fs->stdev() << endl; cout << "TAC3 count/mean/stdev = " << hTAC3fs->get_sumIn() << TAB << hTAC3fs->mean() << TAB << hTAC3fs->stdev() << endl; cout << "TAC1 efficiency fraction = " << ( (float) hTAC1fs->get_sumIn())/ntupleInCount << endl; cout << "TAC2 efficiency fraction = " << ( (float) hTAC2fs->get_sumIn())/ntupleInCount << endl; cout << "TAC3 efficiency fraction = " << ( (float) hTAC3fs->get_sumIn())/ntupleInCount << endl; cout << "End of event builder and tup writer." << endl; cout << endl; nout.close(); return 0; }