-// $Id$
-
-// Author: Constantin Loizides <mailto:loizides@ikf.physik.uni-frankfurt.de>
-//*-- Copyright & copy CL
-
-#include <math.h>
-#include <time.h>
-#include <iostream.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "AliL3VHDLClusterFinder.h"
+// @(#) $Id$
+// Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
+//*-- Copyright & copy ALICE HLT Group
/** \class AliL3VHDLClusterFinder
-//<pre>
+<pre>
//____________________________________________________
// AliL3VHDLClusterFinder
//
// Most important parameters:
// fThreshold - threshold for noise clusters
// fMatch - length in time for overlapping sequences
-//</pre>
+</pre>
*/
+#include "AliL3StandardIncludes.h"
+#include "AliL3RootTypes.h"
+#include "AliL3Logging.h"
+#include "AliL3AltroMemHandler.h"
+
+//#define VHDLDEBUG
+#include "AliL3VHDLClusterFinder.h"
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+
ClassImp(AliL3VHDLClusterFinder)
AliL3VHDLClusterFinder::AliL3VHDLClusterFinder()
{
+ // default constructor
fMatch = 4;
fThreshold = 10;
fMinMerge = 1;
fcalcerr = kTRUE;
Clear();
-#ifdef DEBUG
+#ifdef VHDLDEBUG
fdeb=fopen("vhdlclusterfinder.debug","w");
//fdeb=stderr;
#endif
AliL3VHDLClusterFinder::~AliL3VHDLClusterFinder()
{
-#ifdef DEBUG
+ // destructor
+#ifdef VHDLDEBUG
fclose(fdeb);
#endif
}
void AliL3VHDLClusterFinder::ProcessDigits()
{
//Loop over data like the analyzer of the VHDL code
- const UChar_t n=255;
+ const UChar_t kn=255;
UShort_t rrow=0,rtime=0;
- UChar_t rpad=0,i=n;
- UShort_t *charges=new UShort_t[n];
- Int_t tc=0,mp=0,mt=0,sp=0,st=0;
+ UChar_t rpad=0,i=kn;
+ UShort_t *charges=new UShort_t[kn];
fNClusters=0;
fRow=0;
//loop over input data
while(fAltromem.ReadSequence(rrow,rpad,rtime,i,&charges)){
- tc=0;mp=0;mt=0;sp=0;st=0;
#if 0
cout << "Padrow " << (int)rrow << " pad " << (int)rpad << " time " <<(int)rtime << " charges ";
for(UChar_t ii=0;ii<i;ii++) cout << (int)charges[ii] << " ";
cout << endl;
#endif
-#ifdef DEBUG
+#ifdef VHDLDEBUG
fprintf(fdeb,"ProcessDigits: Input Data: %d %d %d charges:",(int)rrow,(int)rpad,(int)rtime);
for(UChar_t ii=0;ii<i;ii++) fprintf(fdeb," %d",(int)charges[ii]);
fprintf(fdeb,"\n");
fNRow=rrow;
fNPad=rpad;
+ fTC=0,fMT=0,fST=0;
//calculate sequence values
- //no deconvulution so far
- for(UChar_t ii=0;ii<i;ii++){
- tc+=charges[ii];
- mt+=(rtime-ii)*charges[ii];
- st+=(rtime-ii)*(rtime-ii)*charges[ii];
+ if(fDeconvTime){
+ UChar_t ii=0;
+ Int_t sl=0;
+ Int_t charge=0,lcharge=0;
+ Bool_t falling=kFALSE;
+ while(ii<i){
+ charge=charges[ii];
+ if((falling)&&(charge>lcharge)){
+ fSM=rtime-sl/2;
+ MakeSequence();
+ ProcessSequence();
+ OutputMemory();
+
+ rtime=rtime-sl;
+ falling=kFALSE;
+ sl=0;
+ fTC=0,fMT=0,fST=0;
+ } else if(charge<lcharge) falling=kTRUE;
+
+ fTC+=charge;
+ fMT+=(rtime-sl)*charge;
+ fST+=(rtime-sl)*(rtime-sl)*charge;
+ sl++;
+ ii++;
+ lcharge=charge;
+ } //end loop over sequence
+ fSM=rtime-sl/2;
+ } else { /* no deconvolution */
+ for(UChar_t ii=0;ii<i;ii++){
+ fTC+=charges[ii];
+ fMT+=(rtime-ii)*charges[ii];
+ fST+=(rtime-ii)*(rtime-ii)*charges[ii];
+ }
+ fSM=rtime-i/2;
}
- mp=rpad*tc;
- sp=rpad*rpad*tc;
-
- fSeq.fTotalCharge=tc;
- fSeq.fPad=mp;
- fSeq.fTime=mt;
- fSeq.fPad2=sp;
- fSeq.fTime2=st;
- fSeq.fMean=0;
- //if(tc!=0) fSeq.fMean=mt/tc;
- if(tc!=0) fSeq.fMean=rtime-i/2;
- fSeq.fMerge=0;
- fSeq.fRow=rrow;
- fSeq.fLastPad=rpad;
-
- //work on this sequence
+
+ MakeSequence();
ProcessSequence();
- //output one cluster
- OutputMemory();
+ OutputMemory();
-#ifdef DEBUG
+#ifdef VHDLDEBUG
fflush(fdeb);
#endif
- i=n; //store size of charges array
+ i=kn; //store size of charges array
} //loop over data
//flush everything left
while(fOP!=fFP) OutputMemory();
}
+void AliL3VHDLClusterFinder::MakeSequence(){
+ // makes the sequence
+ if(!fTC) return;
+
+ Int_t mp=fNPad*fTC;
+ Int_t sp=fNPad*fNPad*fTC;
+
+ fSeq.fTotalCharge=fTC;
+ fSeq.fPad=mp;
+ fSeq.fTime=fMT;
+ fSeq.fPad2=sp;
+ fSeq.fTime2=fST;
+ fSeq.fMean=0;
+ fSeq.fMean=fSM;
+ fSeq.fMerge=0;
+ fSeq.fRow=fNRow;
+ fSeq.fLastPad=fNPad;
+ fSeq.fChargeFalling=0;
+ if(fDeconvPad) fSeq.fLastCharge=fTC;
+ else fSeq.fLastCharge=0;
+}
+
void AliL3VHDLClusterFinder::ProcessSequence()
{
+ // processes the sequence
if(fNRow!=fRow) FlushMemory();
else if(fNPad==fPad+1) PrepareMemory();
else if(fNPad!=fPad) FlushMemory();
fRow=fNRow;
fPad=fNPad;
-#ifdef DEBUG
+#ifdef VHDLDEBUG
fprintf(fdeb,"ProcessSequence: Mean=%d TC=%d ",fSeq.fMean,fSeq.fTotalCharge);
#endif
void AliL3VHDLClusterFinder::PrepareMemory()
{
-#ifdef DEBUG
+ // prepares the memory
+#ifdef VHDLDEBUG
fprintf(fdeb,"PrepareMemory %d %d %d\n",fRP,fEP,fWP);
#endif
fRP=fEP;
void AliL3VHDLClusterFinder::FlushMemory()
{
-#ifdef DEBUG
+ // flushes the memory
+#ifdef VHDLDEBUG
fprintf(fdeb,"FlushMemory %d %d %d %d\n",fFP,fRP,fEP,fWP);
#endif
fFP=fWP;
void AliL3VHDLClusterFinder::CompareSeq()
{
-
+ // compares sequences
while(fRP!=fEP){
Int_t diff=fSeqs[fPList[fRP]].fMean-fSeq.fMean;
continue;
} else if(diff<-fMatch){ //no match
break; //insert new cluster
- }
- else { //match found, merge it
+ } else { //match found, merge it
MergeSeq();
return;
}
void AliL3VHDLClusterFinder::MergeSeq()
{
-#ifdef DEBUG
+ // merges sequences
+#ifdef VHDLDEBUG
fprintf(fdeb,"merged with Mean=%d TC=%d (new Merge=%d) %d %d\n",fSeqs[fPList[fRP]].fMean,fSeqs[fPList[fRP]].fTotalCharge,fSeqs[fPList[fRP]].fMerge+1,fRow,fPad);
#endif
- if(fSeqs[fPList[fRP]].fRow==fSeq.fRow){
+ if(fSeqs[fPList[fRP]].fRow!=fSeq.fRow){
LOG(AliL3Log::kWarning,"AliL3VHDLClusterFinder::","Memory Check")
<<"Sequences can be merged on the same rows only."<<ENDLOG;
}
LOG(AliL3Log::kWarning,"AliL3VHDLClusterFinder::","Memory Check")
<<"Sequences can be merged on consecutive pads only."<<ENDLOG;
}
+
+ if(fDeconvPad){
+ if(fSeq.fTotalCharge > fSeqs[fPList[fRP]].fLastCharge){
+ if(fSeqs[fPList[fRP]].fChargeFalling){ //The previous pad was falling
+ IncRPointer();
+ InsertSeq(); //start a new cluster
+ return;
+ }
+ }
+ else fSeqs[fPList[fRP]].fChargeFalling = 1;
+ fSeqs[fPList[fRP]].fLastCharge = fSeq.fTotalCharge;
+ }
+
fSeqs[fPList[fRP]].fMean=fSeq.fMean; //take the new mean
fSeqs[fPList[fRP]].fLastPad=fSeq.fLastPad;
fSeqs[fPList[fRP]].fTotalCharge+=fSeq.fTotalCharge;
void AliL3VHDLClusterFinder::InsertSeq()
{
-#ifdef DEBUG
+ // inserts sequence
+#ifdef VHDLDEBUG
fprintf(fdeb,"inserted %d %d\n",fRow,fPad);
#endif
NextFreeIndex(); //get next index
void AliL3VHDLClusterFinder::OutputMemory()
{
+ // output memory?
Float_t mtime=0,mpad=0;
Float_t mtime2=0,mpad2=0;
UInt_t tc,row,mno;
}
if(mno<fMinMerge){ //noise cluster
-#ifdef DEBUG
+#ifdef VHDLDEBUG
fprintf(fdeb,"OutputMemory %d %d: noise cluster (merge): Row %d Pad %.3f Time %.3f TC %d Merge %d\n",fOP,fFP,row,mpad,mtime,tc,mno);
#endif
FreeSeq(index);
}
if(tc<fThreshold){ //total charge below threshold
-#ifdef DEBUG
+#ifdef VHDLDEBUG
fprintf(fdeb,"OutputMemory %d %d: noise cluster (threshold): Row %d Pad %.3f Time %.3f TC %d Merge %d\n",fOP,fFP,row,mpad,mtime,tc,mno);
#endif
FreeSeq(index);
//continue;
}
-#ifdef DEBUG
+#ifdef VHDLDEBUG
fprintf(fdeb,"OutputMemory %d: Row %d Pad %.3f Time %.3f TC %d Merge %d\n",fNClusters,row,mpad,mtime,tc,mno);
#endif
- if(stdout)
- cout<<"WriteCluster: padrow "<<row<<" pad "<<mpad<< " +- "<<mpad2<<" time "<<mtime<<" +- "<<mtime2<<" charge "<<tc<<endl;
+ // if(stdout)
+ // cout<<"WriteCluster: padrow "<<row<<" pad "<<mpad<< " +- "<<mpad2<<" time "<<mtime<<" +- "<<mtime2<<" charge "<<tc<<endl;
fNClusters++;
FreeSeq(index);
}
}
-inline void AliL3VHDLClusterFinder::FreeSeq(UShort_t i)
+void AliL3VHDLClusterFinder::FreeSeq(UShort_t i)
{
+ // frees the sequence
ClearSeq(i);
IncPointer(fLast,1,N_clmem);
}
void AliL3VHDLClusterFinder::Clear()
{
+ // clears everything
fFirst=0; //first list pointer
fLast=0; //last list pointer
}
void AliL3VHDLClusterFinder::ClearSeq(UShort_t i){
+ // clears a sequence
fSeqs[i].fRow=0;
fSeqs[i].fLastPad=0;
fSeqs[i].fTotalCharge=0;
}
void AliL3VHDLClusterFinder::IncPointer(UShort_t &p, Short_t add, UShort_t N){
+ // increments pointer by 'add' in a circular buffer
Short_t pp=p;
pp+=add;
if(pp>=N) p=UShort_t(pp-N);
else p=UShort_t(pp);
}
-inline void AliL3VHDLClusterFinder::IncRPointer(){
+void AliL3VHDLClusterFinder::IncRPointer(){
+ // increments pointer fRP
IncPointer(fRP);
}
-inline void AliL3VHDLClusterFinder::IncWPointer(){
+void AliL3VHDLClusterFinder::IncWPointer(){
+ // increments pointer fWP
IncPointer(fWP);
if(fWP==fOP){
}
}
-inline void AliL3VHDLClusterFinder::NextFreeIndex(){
+void AliL3VHDLClusterFinder::NextFreeIndex(){
+ // finds next free index
IncPointer(fFirst,1,N_clmem);
if(fFirst==fLast) {
LOG(AliL3Log::kFatal,"AliL3VHDLClusterFinder::GetFreeIndex","Memory Check")
#if 0
void AliL3ClustFinderNew::WriteClusters(Int_t n_clusters,ClusterData *list)
{
+ // writes clusters
Int_t thisrow,thissector;
UInt_t counter = fNClusters;