#include #include "centroid.h" #define MINPRESEL 10 /* desired minimum number of preselected hits */ #define MINHIT 3 /* required minimum number of hits */ #define MAXRAW 2000 /* maximum number of raw hits */ #define MAXSTOSIZE 500000000 /* maximal storage size for clusters*/ #define ALLOWED_SIZE_FRACTION 1.0 #define ARRAYSIZE MAXRAW*(MAXRAW-1)/2 // ********************************************** // does hit selection, wenn needed // ********************************************** // ********************************************** // free hit selection array // ********************************************** hitsel::~hitsel(void) { delete selected; } // ------------------------------------------------------------------- // make table of causally related PMTs // ------------------------------------------------------------------- short int hitsel::make_causal_table(short int *&related, short int *&relations, float twin, float resolution, float tcoincidence) { short int row,column,pmt,pmt2,n_cl,high,low; short int *nr_rel,curnrel,*new_index,*select; short int *relp,*relp1,*relp2; short int removed_pmt; /*------------------------------------------------------------------- mark all relations as valid -------------------------------------------------------------------*/ related=new short int[nsel*(nsel-1)/2]; nr_rel=new short int[nsel]; for(row=0,relp=related; row0)) { removed_pmt=1; if (row>0) { relp=related+row-1; for(column=0; column=MINHIT) { pmt=selected[row]; if (n_cl==0) pmt2=n_cl; else { if ( (curnrel>*relations) || ( (curnrel==*relations) && (hitcharge(pmt)>hitcharge(*select)) ) ) pmt2=0; else { if ( (curnrel1; pmt2=(low+high)/2) if ( (curnrel>relations[pmt2]) || ( (curnrel==relations[pmt2]) && (hitcharge(pmt)>hitcharge(select[pmt2])) ) ) high=pmt2; else low=pmt2; pmt2=high; } } } for(high=n_cl-1; high>=pmt2; high--) { select[high+1]=select[high]; relations[high+1]=relations[high]; } select[pmt2]=pmt; relations[pmt2]=curnrel; n_cl++; } delete(nr_rel); delete(relations); if (n_cl<=MINHIT) { delete select; delete related; return(-2); // error: too few clean hits } new_index=new short int[nsel]; for(pmt=0; pmt=0) && (*relp2)) { pmt2=new_index[column]; if (pmt2>=0) { related[pmt*n_cl+pmt2]=*(relp2); related[pmt+n_cl*pmt2]=*(relp2); } } } delete new_index; delete relp1; relp=related; nsel=n_cl+2; for(row=0; rowrow) { relp[-1]=column; break; } nsel=n_cl; //for(row=0; row=0) && (sumhits(s)<=MINPRESEL); s--); if (s<0) s=0; do { nsel=sumhits(s); selected=new short int[nsel]; for(i=0; i=0)); if (n<=0) { nsel=ntot(); selected=new short int[nsel]; for(i=0; i error status for the selection >0: selection o.k.; # of selected hits -1: too few raw hits -2: too few preselected hits -3: too few selected hits -5: no cluster found -6: time sorting error -7: double hit error -8: cluster storage overflow -9: too many raw hits */ /*=================================================================== function begin: -------------------------------------------------------------------*/ { short int row,column,pmt1,pmt2,pmt1_index,pmt2_index; int n_gd,ntest,n_bd,n_clus,min_size,max_size,clus_size,size; int max_index; short int new_pmt; short int *related,*relations,*cluster,**clusterp,*joined,*occur; short int *max_clus=NULL,*clus,*max_end,*select; short int *relp,*relp1,*relp2; if (nsel>MAXRAW) { delete selected; return(-9); // error: too many raw hits } if (nsel0) && (tlim>0)) if ((n_gd=mrclean(dlim,tlim))<0) return(n_gd); n_gd=make_causal_table(related,relations,twin,resolution,tcoincidence); if (n_gd<0) return(n_gd); /*------------------------------------------------------------------- cluster finding algorithm -------------------------------------------------------------------*/ max_size=n_gd*(n_gd-1); clusterp=new short int *[max_size]; if (n_gd<=1000) max_size=max_size/2*n_gd; else max_size=MAXSTOSIZE; cluster=new short int[max_size]; clus=cluster; max_end=cluster+max_size; n_clus=0; min_size=MINHIT; max_size=0; /*------------------------------------------------------------------- now loop through the entire matrix of active relations, using each relation as a seed for a cluster -------------------------------------------------------------------*/ relp=related; max_index=0; for(ntest=n_gd,row=0; row=min_size) && (new_pmt=min_size) { /*short int temp[clus_size],i,j; for(i=0; imax_size) { max_size=clus_size; max_clus=clusterp[n_clus]; max_index=n_clus; min_size=(short int) ALLOWED_SIZE_FRACTION*max_size; while(relations[(ntest-1)*(n_gd+2)]+1=max_size);/* || ((occur[pmt1]>=min_size) && (chg[pmt1]>=0.5) && (chg[pmt1]<=2.))*/ nsel=0; for(nsel=pmt1=0; pmt1