/*************************************************************************** AkSltPattern.h - description begin : Tue Sep 27 2001 copyright : (C) 2001 by Andreas Kopmann email : kopmann@ipe.fzk.de ***************************************************************************/ #ifndef AKSLTPATTERN_H #define AKSLTPATTERN_H #include #include /** @file AkSltPattern.cc * Declaration of the class Ak::SltPattern. * @author A.Kopmann, IPE */ namespace Ak { /** The class sltpattern contains methods * to decode the pattern generated by the * second level trigger system. * * @todo Determine the number of triggered pixel * from the trigger memory! If the number is small * it is more likely to skip a whole event with * a muon pattern in. */ class SltPattern { public: virtual ~SltPattern() { } /** Display the trigger information. * * @param mem Pointer to the trigger memory. * The memory is asumed to start always * with data for the first column * @param n Number of lines to be analysed. * Every 20 lines a new image starts. * @param iFirst Index of the first trigger line * @param fout Output stream * @param fLen Number of characters in one line * */ void display(uint32_t *mem, int n, int iFirst=0, FILE *fout=stdout, int fLen=150); /** Return the id of the pattern stored with this * column * @param mem One column / word of the trigger memory */ int getPatternId(uint32_t mem); /** Get the number of triggered pixel from the * trigger memory. The number does not necessarily * correspond with the number of pixel that * show ADC data. To analyse a smaller range of * the data, increase the pointer to the memory * and decrease the given lenght * * @param mem Pointer to the trigger memory. * The memory is asumed to start always * with data for the first column * @param n number of lines to be analysed. * Every 20 lines a new image starts. * */ int getTriggered(uint32_t *mem, int n); /** Get the position of the first second level trigger * that occured in this event. * * @param mem Trigger memory * @param n Lenght of the trigger memory * */ int getFirstTrigger(uint32_t *mem, int n); /** Return a list of the time intervalls for every * pixel with the first level trigger. * @param mem Trigger memory * @param n Length of the trigger memory * @param t0 Matrix of the first triggered bin * @param t1 Matrix of the last triggered bin */ void getFltIntervall(uint32_t *mem, int n, int t0[][22], int t1[][22]); /** Return the time intervall with the second level * trigger. * @param mem Trigger memory * @param n Length of the trigger memory * @param t0 First triggered bin * @param t1 Last triggered bin */ void getSltIntervall(uint32_t *mem, int n, int *t0, int *t1); /** Return the relative address of * the pixel belonging to the pattern. * * @param patternId The id of the pattern * @param col coordinate of the reference pixel * @param row coordinate of the reference pixel * @param colList array of at least four elements to * store the coordinates of the pixel belonging to * the track. The reference pixel is always the * first entry * @param rowList array of at least four elements to * store the coordinates of the pixel belonging to * the track. The reference pixel is always the * first entry * @param nList Elements available in the rowList parameter * * @return The index of the trigger memory 0..n-1. * If no trigger is found -1 is returned. */ void getPixelList(int patternId, int col, int row, int *colList, int *rowList, int nList=4); /** Return the relative address of * the pixel belonging to the pattern. * * @param mem Trigger memory as returned * by the class SltMemory. The pointer does * not necessarily needs to point to the beginning * of the data. Every offset coresponding to 1us * is allowed. * @param n Length of the given memory data. The length * of the memory has to be at least 20 to cover * one complete image of the camera. * @param iTrigger Number of the found SLT pattern. * Refer to the SLT documentation for the pattern numbers. * @param colList array of at least four elements to * store the coordinates of the pixel belonging to * the track. The reference pixel is always the * first entry * @param rowList array of at least four elements to * store the coordinates of the pixel belonging to * the track. The reference pixel is always the * first entry * @param nList Elements available in the rowList parameter * */ int getPixelList(uint32_t *mem, int n, int *iTrigger, int *colList, int *rowList, int nList=4); /** Check if all pixel in the list show a valid * first level trigger in this image * * @return The first pixel in the list that has * no trigger flag (0..len-1). */ int checkPixelList(uint32_t *mem, int n, int *colList, int *rowList, int nList = 4); /** Find the pixel of that are not given by * the pattern number of the second level trigger */ int findPixelList(uint32_t *mem, int n, int iPattern, int patternId, int firstRow, int *colList, int *rowList, int nList = 4); /** Insert a new pixel in a pixel list * building a near to linear track. The new pixel * has to be added to the list in order to * give the best possible track afterwards. * (May be more CPU time consuming than other * algorithma?!) * */ int insertByProjection(int col, int row, int *colList, int *rowList, int nList); /** Insert a new pixel in a pixel list * building a near to linear track. * Use only the distance from the first pixel * to order the list. */ int insertByDistance(int col, int row, int *colList, int *rowList, int nList); /** Calculate the center of the pixel * where the axis of the coordinate system * lays in the most left pixel of the first column * and the first row. Range [0,39] * */ int getX(int col, int row); int getY(int col, int row); /** Calculate the difference between two pixel * based of the coordinates introduced by * getX and getY. */ float getR(int colRef, int rowRef, int col, int row); /** Calculate the square of difference between * two pixel. */ int getR2(int colRef, int rowRef, int col, int row); /** This is a simple algorithm to calculate * the length of a vector without multiplication * and square root. Here the pixel are considered * as "circles" around the reference pixel. * The result is also given in means of the * coordinates given by getX and getY. * */ int getCircle(int colRef, int rowRef, int col, int row); /** Skalar product between two vectors */ int getScalarProd(int colRef, int rowRef, int col1, int row1, int col2, int row2); private: /** Pattern as given in the description of the * control FPGA at the Slt board. */ static int track[128][3]; /** Vectors needed to decode the pixel coordinates * for a pixel in a even row (0 .. 18). */ static int vectorEvenRow[19][2]; /** Vectors needed to decode the pixel coordinates * for a pixel in a odd row (1 .. 19). */ static int vectorOddRow[19][2]; }; } // namespace Ak #endif // AKSLTPATTERN_H