//-------------------------------------------------------- // tscalroc11_main.C // // Test of the ROC10/11 scalers which are read in the datastream // typically every 100 events. As of Aug 2002 this is a new // readout. (Actually there was also a similar ROC11 since // Aug 2001, but the data format has changed due to G0 mode.) // The focus is on the ring buffer data. // R. Michaels, Oct 2002 //-------------------------------------------------------- // The ROC to find scalers (10/11 are R/L). #define MYROC 11 // To printout (1) or not (0) #define PRINTOUT 0 #define NBCM 6 #define MAXRING 20 #include #include "THaCodaFile.h" #include "THaEvData.h" #ifndef __CINT__ #include "TROOT.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include "TProfile.h" #include "TNtuple.h" #include "TRandom.h" #endif using namespace std; int loadHelicity(); int ranBit(unsigned int& seed); unsigned int getSeed(); // Global variables -------------------------------------- #define NBIT 24 int hbits[NBIT]; // The NBIT shift register int present_reading; // present reading of helicity int predicted_reading; // prediction of present reading (should = present_reading) int present_helicity; // present helicity (using prediction) #define NDELAY 2 // number of quartets between // present reading and present helicity // (i.e. the delay in reporting the helicity) int recovery_flag = 0; // flag to determine if we need to recover // from an error (1) or not (0) unsigned int iseed; // value of iseed for present_helicity unsigned int iseed_earlier; // iseed for predicted_reading int main(int argc, char* argv[]) { int helicity, qrt, gate, timestamp; int len, data, status, nscaler, header; int numread, badread, i, found, index; int ring_clock, ring_qrt, ring_helicity; int ring_trig, ring_bcm, ring_l1a, ring_v2fh; int sum_clock, sum_trig, sum_bcm, sum_l1a; int inquad, nrread, q1_helicity; int ring_data[MAXRING], rloc; if (argc < 2) { cout << "You made a mistake... bye bye !\n" << endl; cout << "Usage: 'tscalroc" << MYROC << " filename'" << endl; cout << " where 'filename' is the CODA file."<codaRead(); if (status != 0) break; evdata.LoadEvent(coda->getEvBuffer()); len = evdata.GetRocLength(MYROC); if (len <= 4) continue; data = evdata.GetRawData(MYROC,3); helicity = (data & 0x10) >> 4; qrt = (data & 0x20) >> 5; gate = (data & 0x40) >> 6; timestamp = evdata.GetRawData(MYROC,4); found = 0; index = 5; while ( !found ) { data = evdata.GetRawData(MYROC,index++); if ( (data & 0xffff0000) == 0xfb0b0000) found = 1; if (index >= len) break; } if (!found) break; nscaler = data & 0x7; if (PRINTOUT) { cout << hex << "helicity " << helicity << " qrt " << qrt; cout << " gate " << gate << " time stamp " << timestamp << endl; cout << "nscaler in this event " << nscaler << endl; } if (nscaler <= 0) continue; if (nscaler > 2) nscaler = 2; // shouldn't be necessary // 32 channels of scaler data for two helicities. if (PRINTOUT) cout << "Synch event ----> " << endl; for (int ihel = 0; ihel < nscaler; ihel++) { header = evdata.GetRawData(MYROC,index++); if (PRINTOUT) { cout << "Scaler for helicity = " << dec << ihel; cout << " unique header = " << hex << header << endl; } for (int ichan = 0; ichan < 32; ichan++) { data = evdata.GetRawData(MYROC,index++); if (PRINTOUT) { cout << "channel # " << dec << ichan+1; cout << " (hex) data = " << hex << data << endl; } } } numread = evdata.GetRawData(MYROC,index++); badread = evdata.GetRawData(MYROC,index++); if (PRINTOUT) cout << "FIFO num of last good read " << dec << numread << endl; if (badread != 0) { cout << "DISASTER: There are bad readings " << endl; cout << "FIFO num of last bad read " << endl; } // Subset of scaler channels stored in a 30 Hz ring buffer. int nring = 0; while (index < len && nring == 0) { header = evdata.GetRawData(MYROC,index++); if ((header & 0xffff0000) == 0xfb1b0000) { nring = header & 0x3ff; } } if (PRINTOUT) cout << "Num in ring buffer = " << dec << nring << endl; // The following assumes three are 6 pieces of data per 'iring' // This was true after Jan 10, 2003. for (int iring = 0; iring < nring; iring++) { ring_clock = evdata.GetRawData(MYROC,index++); data = evdata.GetRawData(MYROC,index++); ring_qrt = (data & 0x10) >> 4; ring_helicity = (data & 0x1); present_reading = ring_helicity; if (ring_qrt) { inquad = 1; if (loadHelicity()) { if (present_reading != predicted_reading) { cout << "DISASTER: The helicity is wrong !!"< 12) { farray_ntup[0] = (float)nrread; farray_ntup[1] = ring_clock; farray_ntup[2] = ring_trig; farray_ntup[3] = ring_bcm; farray_ntup[4] = ring_l1a; farray_ntup[5] = (float)present_reading; farray_ntup[6] = (float)present_helicity; for (int ishift = 3; ishift <= 12; ishift++) { Float_t pdat = ring_data[(rloc-ishift)%MAXRING]; Float_t mdat = ring_data[(rloc-ishift+1)%MAXRING]; Float_t sum = pdat + mdat; Float_t asy = 99999; if (sum != 0) { if (present_reading == 1) { asy = (pdat - mdat)/sum; } else { asy = (mdat - pdat)/sum; } } farray_ntup[4+ishift] = asy; } ntup->Fill(farray_ntup); } rloc++; if (PRINTOUT) { cout << "buff [" << dec << iring << "] "; cout << " clock " << ring_clock << " qrt " << ring_qrt; cout << " helicity " << ring_helicity; cout << " trigger " << ring_trig << " bcm " << ring_bcm; cout << " L1a "<= 0; i--) ranseed = ranseed<<1|(seedbits[i]&1); ranseed = ranseed&0xFFFFFF; return ranseed; }