mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-07 18:40:42 +02:00
some more untested methods for single photon filter
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@674 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
65748059cc
commit
fbf853ea20
@ -5,20 +5,18 @@
|
|||||||
#include "singlePhotonFilter.h"
|
#include "singlePhotonFilter.h"
|
||||||
|
|
||||||
|
|
||||||
/*#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00
|
|
||||||
#define MOENCH_PACKET_INDEX_MASK 0xFF
|
|
||||||
#define MOENCH_FRAME_INDEX_OFFSET 8
|
|
||||||
*/
|
|
||||||
|
|
||||||
singlePhotonFilter::singlePhotonFilter(int x, int y, vector <vector<int16_t> >m, vector <vector<int16_t> >s, int d):
|
singlePhotonFilter::singlePhotonFilter(int nx, int ny,
|
||||||
|
int fmask, int pmask, int foffset, int poffset, int pperf, int iValue,
|
||||||
|
vector <vector<int16_t> > m, vector <vector<int16_t> > s, int d):
|
||||||
#ifdef MYROOT
|
#ifdef MYROOT
|
||||||
myTree(NULL),
|
myTree(NULL),
|
||||||
myFile(NULL),
|
myFile(NULL),
|
||||||
#else
|
#else
|
||||||
myFile(NULL),
|
myFile(NULL),
|
||||||
#endif
|
#endif
|
||||||
nChannelsX(x),
|
nChannelsX(nx),
|
||||||
nChannelsY(y),
|
nChannelsY(ny),
|
||||||
nClusterX(CLUSTER_SIZE),
|
nClusterX(CLUSTER_SIZE),
|
||||||
nClusterY(CLUSTER_SIZE),
|
nClusterY(CLUSTER_SIZE),
|
||||||
map(m),
|
map(m),
|
||||||
@ -32,19 +30,25 @@ singlePhotonFilter::singlePhotonFilter(int x, int y, vector <vector<int16_t> >m,
|
|||||||
pnum(0),
|
pnum(0),
|
||||||
ptot(0),
|
ptot(0),
|
||||||
f0(0),
|
f0(0),
|
||||||
frame_index_mask(0x00000000),
|
frame_index_mask(fmask),
|
||||||
packet_index_mask(0x00000000),
|
packet_index_mask(pmask),
|
||||||
frame_index_offset(0),
|
frame_index_offset(foffset),
|
||||||
packet_index_offset(0),
|
packet_index_offset(poffset),
|
||||||
packets_per_frame(0){
|
packets_per_frame(pperf),
|
||||||
|
incrementValue(iValue),
|
||||||
|
enable(false),
|
||||||
|
firstTime(true),
|
||||||
|
ret(0),
|
||||||
|
pIndex(0),
|
||||||
|
fIndex(0){
|
||||||
|
|
||||||
|
|
||||||
if (x == 1)
|
if (nChannelsX)
|
||||||
nClusterX = 1;
|
nClusterX = 1;
|
||||||
|
|
||||||
stat.resize(x);
|
stat.resize(nChannelsX);
|
||||||
for(int i=0; i<x; i++)
|
for(int i=0; i<nChannelsX; i++)
|
||||||
stat[i].resize(y);
|
stat[i].resize(nChannelsY);
|
||||||
|
|
||||||
//struct
|
//struct
|
||||||
myPhotonHit.data.resize(nClusterX);
|
myPhotonHit.data.resize(nClusterX);
|
||||||
@ -61,12 +65,13 @@ singlePhotonFilter::singlePhotonFilter(int x, int y, vector <vector<int16_t> >m,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void singlePhotonFilter::initTree(char *outdir, char *fname){
|
void singlePhotonFilter::initTree(char *outfname){
|
||||||
//path
|
|
||||||
char outfname[MAX_STR_LENGTH];
|
|
||||||
sprintf(outfname, "%s/%s.root", outdir, fname);
|
|
||||||
|
|
||||||
#ifdef MYROOT
|
#ifdef MYROOT
|
||||||
|
outfname = string(outfname).replace(".raw",".root");
|
||||||
|
//fName.replace(".raw",".png");
|
||||||
|
//sprintf(outfname, "%s/%s.root", outdir, fname);
|
||||||
|
|
||||||
char c1[10],c2[10],cdata[100];
|
char c1[10],c2[10],cdata[100];
|
||||||
sprintf(c1,"%d",nClusterX);
|
sprintf(c1,"%d",nClusterX);
|
||||||
sprintf(c2,"%d",nClusterY);
|
sprintf(c2,"%d",nClusterY);
|
||||||
@ -82,7 +87,7 @@ void singlePhotonFilter::initTree(char *outdir, char *fname){
|
|||||||
myTree->Branch("pedestal",&myPhotonHit.ped,"pedestal/D");
|
myTree->Branch("pedestal",&myPhotonHit.ped,"pedestal/D");
|
||||||
myTree->Branch("rms",&myPhotonHit.rms,"rms/D");
|
myTree->Branch("rms",&myPhotonHit.rms,"rms/D");
|
||||||
#else
|
#else
|
||||||
myFile = fopen(outfname, "w");
|
;/*myFile = fopen(outfname, "w");*/
|
||||||
#endif
|
#endif
|
||||||
//initialize
|
//initialize
|
||||||
for (int ir=0; ir<nChannelsX; ir++){
|
for (int ir=0; ir<nChannelsX; ir++){
|
||||||
@ -105,12 +110,13 @@ int singlePhotonFilter::writeToFile(){
|
|||||||
delete myFile;
|
delete myFile;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if(myFile){ /*&& (number of structs?)*/
|
;
|
||||||
|
/*if(myFile){ //&& (number of structs?)
|
||||||
fwrite((void*)(&myPhotonHit), 1, sizeof(myPhotonHit), myFile);
|
fwrite((void*)(&myPhotonHit), 1, sizeof(myPhotonHit), myFile);
|
||||||
fclose(myFile);
|
fclose(myFile);
|
||||||
delete myFile;
|
delete myFile;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}*/
|
||||||
#endif
|
#endif
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -241,103 +247,105 @@ if(firstTimeHere){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
void singlePhotonFilter::initialize(int fmask, int pmask, int foffset, int poffset, int pperf){
|
void singlePhotonFilter::setupAcquisitionParameters(){
|
||||||
fnum = 0; pnum = 0; ptot = 0; f0 = 0;
|
fnum = 0; pnum = 0; ptot = 0; f0 = 0; firstTime = true;
|
||||||
frame_index_mask = fmask;
|
|
||||||
packet_index_mask = pmask;
|
|
||||||
frame_index_offset = foffset;
|
|
||||||
packet_index_offset = poffset;
|
|
||||||
packets_per_frame = pperf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int singlePhotonFilter::verifyFrame(char *inData, int inDataSize, int16_t* myData, int firstTime){
|
int singlePhotonFilter::verifyFrame(char *inData){
|
||||||
int offset = 0;
|
ret = 0;
|
||||||
int fIndex = 0;
|
pIndex = 0;
|
||||||
int pIndex = 0;
|
fIndex = 0;
|
||||||
|
fIndex = (((uint32_t)(*((uint32_t*)inData)))& frame_index_mask) >> frame_index_offset;
|
||||||
|
pIndex = (((uint32_t)(*((uint32_t*)inData)))& packet_index_mask) >> packet_index_offset;
|
||||||
|
|
||||||
|
//check validity of packet index
|
||||||
|
if ((pIndex < 0) && (pIndex >= packets_per_frame)){
|
||||||
|
cout << "cannot decode packet index:" << pIndex << endl;
|
||||||
|
//its already dealt with cuz this frame will be discarded in the end
|
||||||
|
}
|
||||||
|
pIndex += incrementValue;
|
||||||
|
|
||||||
|
//for moench, put first packet last
|
||||||
|
if (pIndex == 0)
|
||||||
|
pIndex = packets_per_frame;
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
|
cout<<"fi:"<<hex<<fIndex<< " pi:"<< pIndex << endl;
|
||||||
|
#endif
|
||||||
|
//firsttime
|
||||||
|
if (firstTime){
|
||||||
|
firstTime = false;
|
||||||
|
f0 = fIndex;
|
||||||
|
fnum = fIndex;
|
||||||
|
pnum = pIndex - 1; //should b 0 at first
|
||||||
|
ptot = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if it is not matching withthe frame number
|
||||||
|
if (fIndex != fnum){
|
||||||
|
/*cout << "**Frame number doesnt match:Missing Packet! " << fnum << " "
|
||||||
|
"Expected f " << fnum << " p " << pnum + 1 << " received f " << fIndex << " p " << pIndex << endl;*/
|
||||||
|
fnum = fIndex;
|
||||||
|
/* pnum = pIndex - 1;
|
||||||
|
ptot = 0;*/
|
||||||
|
pnum = pIndex;
|
||||||
|
ptot = 1;
|
||||||
|
ret = -2; //dont return here.. if is the end of packets, for gotthard uve toreturn -1
|
||||||
|
}
|
||||||
|
|
||||||
|
//if missing a packet, discard
|
||||||
|
else if (pIndex != pnum + 1){/**else */
|
||||||
|
/* cout << "**packet number doesnt match:Missing Packet! " << fnum << " "
|
||||||
|
"Expected f" << fnum << " p " << pnum + 1 << " received f " << fnum << " p " << pIndex << endl;*/
|
||||||
|
pnum = pIndex;
|
||||||
|
ptot++;/*ptot = 0;*/
|
||||||
|
}
|
||||||
|
//no missing packet
|
||||||
|
else{
|
||||||
|
pnum++;
|
||||||
|
ptot++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while(offset < inDataSize){
|
//copy packet to correct spot in outData
|
||||||
fIndex = ((((int)(*((int*)inData))) & (frame_index_mask)) >> frame_index_offset);
|
/*myData[pIndex-1] = inData;
|
||||||
pIndex = ((((int)(*((int*)inData))) & (packet_index_mask)) >> packet_index_offset);
|
cout<<"mydata["<<pIndex-1<<"]:"<<hex<<(uint32_t)(*((uint32_t*)inData))<<endl;*/
|
||||||
|
/*memcpy((myData+(pIndex-1)*inDataSize), inData, inDataSize);*/
|
||||||
offset += 4;
|
//memcpy(((char*)(myData+(pIndex-1)*640)), (inData + offset), 1280);
|
||||||
|
|
||||||
//check validity of packet index
|
|
||||||
if ((pIndex < 0) && (pIndex >= packets_per_frame)){
|
|
||||||
cout << "cannot decode packet index:" << pIndex << endl;
|
|
||||||
//its already dealt with cuz this frame will be discarded in the end
|
|
||||||
}
|
|
||||||
|
|
||||||
//put first packet last
|
|
||||||
if (pIndex == 0)
|
|
||||||
pIndex = packets_per_frame;
|
|
||||||
|
|
||||||
|
|
||||||
//copy packet to correct spot in outData
|
|
||||||
memcpy(((char*)(myData+(pIndex-1)*640)), (inData + offset), 1280);
|
|
||||||
offset += 1280 + 2;
|
|
||||||
|
|
||||||
//firsttime
|
//if its the last index
|
||||||
if (firstTime){
|
if (pIndex == packets_per_frame){
|
||||||
firstTime = 0;
|
//got all packets
|
||||||
f0 = fIndex;
|
if (ptot == packets_per_frame){
|
||||||
fnum = fIndex;
|
/*myPhotonHit.iframe = fnum - f0;//??
|
||||||
pnum = pIndex - 1; //should b 0 at first
|
if (enable)
|
||||||
|
;*//*findHits(myData,inDataSize * ptot);*/
|
||||||
|
fnum = fIndex + 1;
|
||||||
ptot = 0;
|
ptot = 0;
|
||||||
}
|
pnum = 0;
|
||||||
|
ret = 1;
|
||||||
//if it is not matching withthe frame number
|
}else{
|
||||||
if (fIndex != fnum){
|
/* cout << "* Some packets have been missed!*************************************" << fnum << " " << pnum<<" " << ptot<<endl;*/
|
||||||
cout << "Missing Packet! " << fnum << " "
|
|
||||||
"Expected f" << fnum << " p " << pnum + 1 << " received f " << fnum << " p " << pIndex << endl;
|
|
||||||
fnum = fIndex;
|
|
||||||
pnum = pIndex - 1;
|
|
||||||
ptot = 0;
|
ptot = 0;
|
||||||
}
|
pnum = 0;
|
||||||
|
fnum = fIndex + 1;
|
||||||
//if missing a packet, discard
|
ret = -1;
|
||||||
if (pIndex != pnum + 1){
|
|
||||||
cout << "Missing Packet! " << fnum << " "
|
|
||||||
"Expected f" << fnum << " p " << pnum + 1 << " received f " << fnum << " p " << pIndex << endl;
|
|
||||||
pnum = pIndex;
|
|
||||||
ptot = 0;/** should it be 0 or just not incrememnted */
|
|
||||||
}
|
|
||||||
//no missing packet
|
|
||||||
else{
|
|
||||||
pnum++;
|
|
||||||
ptot++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//if its the last index
|
|
||||||
if (pIndex == packets_per_frame){
|
|
||||||
//got all packets
|
|
||||||
if (ptot == packets_per_frame){
|
|
||||||
myPhotonHit.iframe = fnum - f0;/** ?? */
|
|
||||||
findHits(myData,nChannelsX*nChannelsY*2);
|
|
||||||
return 1;
|
|
||||||
}else{
|
|
||||||
cout << "* Some packets have been missed!" << fnum << endl;
|
|
||||||
ptot = 0;
|
|
||||||
pnum = 0;
|
|
||||||
fnum = fIndex + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//index not 40, but total is 40.. strange
|
|
||||||
else if (ptot == packets_per_frame){
|
|
||||||
cout << "** Some packets have been missed! " << fnum << endl;
|
|
||||||
ptot = 0;
|
|
||||||
pnum = pIndex - 1;
|
|
||||||
fnum = fIndex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete myData;
|
//index not 40, but total is 40.. strange
|
||||||
|
else if (ptot == packets_per_frame){
|
||||||
return 0;
|
cout << "***** Some packets have been missed! " << fnum << " " << pnum<< endl;
|
||||||
|
ptot = 0;
|
||||||
|
pnum = pIndex - 1;
|
||||||
|
fnum = fIndex;
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -68,44 +68,52 @@ class singlePhotonFilter{
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param nChannelsX Number of Channels in X direction
|
* @param nx Number of Channels in X direction
|
||||||
* @param nChannelsY Number of Channels in Y direction
|
* @param ny Number of Channels in Y direction
|
||||||
|
* @param fmask frame index mask
|
||||||
|
* @param pmask packet index mask
|
||||||
|
* @param foffset frame index offset
|
||||||
|
* @param poffset packet index offset
|
||||||
|
* @param pperf packets per frame
|
||||||
|
* @param iValue increment value (only for gotthard to increment index to have matching frame number)
|
||||||
* @param m Map to data without headers
|
* @param m Map to data without headers
|
||||||
* @param s mask as to which adcs are inverted
|
* @param s mask as to which adcs are inverted
|
||||||
* @param d Size of data with the headers
|
* @param d Size of data with the headers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** why is the datasize -1, you need to know the datasize with headers so that you dont go over the limits */
|
/** why is the datasize -1, you need to know the datasize with headers so that you dont go over the limits */
|
||||||
singlePhotonFilter(int x, int y, vector <vector<int16_t> >m, vector <vector<int16_t> >s, int d = -1);
|
singlePhotonFilter(
|
||||||
/*map[56][63]=656; data[map[56][63]] ^ 0x7fff*/
|
int nx,
|
||||||
|
int ny,
|
||||||
|
int fmask,
|
||||||
|
int pmask,
|
||||||
|
int foffset,
|
||||||
|
int poffset,
|
||||||
|
int pperf,
|
||||||
|
int iValue,
|
||||||
|
vector <vector<int16_t> > m,
|
||||||
|
vector <vector<int16_t> > s,
|
||||||
|
int d = -1);
|
||||||
|
|
||||||
/** virtual destructor */
|
/** virtual destructor */
|
||||||
virtual ~singlePhotonFilter(){};
|
virtual ~singlePhotonFilter(){};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a tree, populate struct for the single photon hit
|
* Construct a tree, populate struct for the single photon hit and provide all the masks and offsets
|
||||||
* @param outdir Output file directory
|
* @param outdir Output file directory/Output file name
|
||||||
* @param fname Output file name
|
|
||||||
*/
|
*/
|
||||||
void initTree(char *outdir, char *fname);
|
void initTree(char *outfname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset Indices before starting acquisition and provide all the masks and offsets
|
* Reset Indices before starting acquisition
|
||||||
* @param fmask frame index mask
|
|
||||||
* @param pmask packet index mask
|
|
||||||
* @param foffset frame index offset
|
|
||||||
* @param poffset packet index offset
|
|
||||||
* @param pperf packets per frame
|
|
||||||
*/
|
*/
|
||||||
void initialize(int fmask, int pmask, int foffset, int poffset, int pperf);
|
void setupAcquisitionParameters();
|
||||||
|
|
||||||
/** Verify if all packets exist for the frame
|
/** reconstruct the frame with all the right packets
|
||||||
* @param inData the data from socket to be verified
|
* @param inData the data from socket to be verified
|
||||||
* @param inDataSize datasize of packet
|
|
||||||
* @param myData frame with all the packets
|
|
||||||
* @param firstTime the first frame received from socket
|
|
||||||
* */
|
* */
|
||||||
int verifyFrame(char *inData, int inDataSize, int16_t* myData, int firstTime);
|
int verifyFrame(char *inData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes tree/struct to file
|
* Writes tree/struct to file
|
||||||
@ -121,6 +129,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
int findHits(int16_t *myData, int myDataSize);
|
int findHits(int16_t *myData, int myDataSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable Filter, This makes sure findHits() is called
|
||||||
|
*/
|
||||||
|
void enableFilter(bool r){enable = r;};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns packets per frame
|
||||||
|
*/
|
||||||
|
int getPacketsPerFrame(){ return packets_per_frame;};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef MYROOT
|
#ifdef MYROOT
|
||||||
@ -187,13 +205,13 @@ private:
|
|||||||
int nClusterY;
|
int nClusterY;
|
||||||
|
|
||||||
/** map to the data without headers */
|
/** map to the data without headers */
|
||||||
vector <vector<int16_t> >map;
|
vector <vector<int16_t> > map;
|
||||||
|
|
||||||
/** Size of data with headers */
|
/** Size of data with headers */
|
||||||
int dataSize;
|
int dataSize;
|
||||||
|
|
||||||
/** mask as to which adcs are inverted */
|
/** mask as to which adcs are inverted */
|
||||||
vector <vector<int16_t> >mask;
|
vector <vector<int16_t> > mask;
|
||||||
|
|
||||||
/** movingStat object */
|
/** movingStat object */
|
||||||
vector <vector<movingStat> > stat;
|
vector <vector<movingStat> > stat;
|
||||||
@ -255,6 +273,24 @@ private:
|
|||||||
/** number of packets per frame */
|
/** number of packets per frame */
|
||||||
int packets_per_frame;
|
int packets_per_frame;
|
||||||
|
|
||||||
|
/** increment value for index for gotthard */
|
||||||
|
int incrementValue;
|
||||||
|
|
||||||
|
/** filter enable */
|
||||||
|
bool enable;
|
||||||
|
|
||||||
|
/** first packet */
|
||||||
|
bool firstTime;
|
||||||
|
|
||||||
|
/** return status */
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/** current packet index */
|
||||||
|
int pIndex;
|
||||||
|
|
||||||
|
/** current frame index */
|
||||||
|
int fIndex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user