default parameters are set for the clusterfinder
[u/mrichter/AliRoot.git] / HLT / TPCLib / HWCFemulator / AliHLTTPCHWCFProcessorUnit.cxx
CommitLineData
33861fe0 1// $Id$
c012881c 2//****************************************************************************
3//* This file is property of and copyright by the ALICE HLT Project *
4//* ALICE Experiment at CERN, All rights reserved. *
5//* *
6//* Primary Authors: Sergey Gorbunov, Torsten Alt *
7//* Developers: Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de> *
8//* Torsten Alt <talt@cern.ch> *
9//* for The ALICE HLT Project. *
10//* *
11//* Permission to use, copy, modify and distribute this software and its *
12//* documentation strictly for non-commercial purposes is hereby granted *
13//* without fee, provided that the above copyright notice appears in all *
14//* copies and that both the copyright notice and this permission notice *
15//* appear in the supporting documentation. The authors make no claims *
16//* about the suitability of this software for any purpose. It is *
17//* provided "as is" without express or implied warranty. *
18//****************************************************************************
19
20// @file AliHLTTPCHWCFProcessorUnit.cxx
21// @author Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de>
22// @author Torsten Alt <talt@cern.ch>
23// @date
24// @brief Channel Processor unit of FPGA ClusterFinder Emulator for TPC
25// @brief ( see AliHLTTPCHWCFEmulator class )
26// @note
27
28#include "AliHLTTPCHWCFProcessorUnit.h"
29#include <iostream>
a277d7d8 30#include <cstdio>
c012881c 31
32
33AliHLTTPCHWCFProcessorUnit::AliHLTTPCHWCFProcessorUnit()
34 :
35 fOutput(),
36 fkBunch(0),
37 fBunchIndex(0),
38 fDeconvolute(0),
31959cd6 39 fSingleSeqLimit(0),
b2d72465 40 fUseTimeBinWindow(0),
31959cd6 41 fDebug(0)
c012881c 42{
43 //constructor
44 Init();
45}
46
47
48AliHLTTPCHWCFProcessorUnit::~AliHLTTPCHWCFProcessorUnit()
49{
50 //destructor
51}
52
53AliHLTTPCHWCFProcessorUnit::AliHLTTPCHWCFProcessorUnit(const AliHLTTPCHWCFProcessorUnit&)
54 :
55 fOutput(),
56 fkBunch(0),
57 fBunchIndex(0),
58 fDeconvolute(0),
31959cd6 59 fSingleSeqLimit(0),
b2d72465 60 fUseTimeBinWindow(0),
31959cd6 61 fDebug(0)
c012881c 62{
63 // dummy
64 Init();
65}
66
67AliHLTTPCHWCFProcessorUnit& AliHLTTPCHWCFProcessorUnit::operator=(const AliHLTTPCHWCFProcessorUnit&)
68{
69 // dummy
70 return *this;
71}
72
73int AliHLTTPCHWCFProcessorUnit::Init()
74{
75 // initialise
76
77 fkBunch = 0;
25080052 78 fBunchIndex = 0;
c012881c 79 return 0;
80}
81
82int AliHLTTPCHWCFProcessorUnit::InputStream( const AliHLTTPCHWCFBunch *bunch )
83{
84 // input stream of data
85
31959cd6 86 if( bunch && fDebug ){
25080052 87 printf("\nHWCF Processor: input bunch F %1d R %3d P %3d NS %2ld:\n",
88 bunch->fFlag, bunch->fRow, bunch->fPad, bunch->fData.size());
31959cd6 89 for( unsigned int i=0; i<bunch->fData.size(); i++ ){
25080052 90 AliHLTTPCHWCFDigit d = bunch->fData[i];
4d67c3e3 91 printf(" q %2d t %3d peak %2d ", d.fQ, d.fTime, d.fPeak);
25080052 92 printf("(");
93 for( int j=0; j<3; j++ ) printf(" {%d,%2.0f}",d.fMC.fClusterID[j].fMCID, d.fMC.fClusterID[j].fWeight );
94 printf(" )\n");
31959cd6 95 }
96 }
97
c012881c 98 fkBunch = bunch;
99 fBunchIndex = 0;
100 return 0;
101}
102
103const AliHLTTPCHWCFClusterFragment *AliHLTTPCHWCFProcessorUnit::OutputStream()
104{
105 // output stream of data
106
25080052 107 //const AliHLTUInt32_t kTimeBinWindow = 5;
108 const AliHLTUInt32_t kHalfTimeBinWindow = 2;
109
c012881c 110 if( !fkBunch ) return 0;
111
112 fOutput.fFlag = fkBunch->fFlag;
113 fOutput.fRow = fkBunch->fRow;
114 fOutput.fPad = fkBunch->fPad;
115 fOutput.fBranch = fkBunch->fBranch;
ee4d1bf0 116 fOutput.fBorder = fkBunch->fBorder;
33861fe0 117 fOutput.fQmax = 0;
c012881c 118 fOutput.fQ = 0;
119 fOutput.fT = 0;
120 fOutput.fT2 = 0;
121 fOutput.fP = 0;
122 fOutput.fP2 = 0;
25080052 123 fOutput.fTMean = 0;
c012881c 124 fOutput.fMC.clear();
125
126 if( fkBunch->fFlag==2 && fkBunch->fData.size()==1 ){ // rcu trailer word, forward it
25080052 127 fOutput.fRow = fkBunch->fData[0].fQ;
128 }
c012881c 129
130 if( fkBunch->fFlag >1 ){
25080052 131 fkBunch = 0;
c012881c 132 return &fOutput;
133 }
134
135 if( fkBunch->fFlag < 1 ) return 0;
25080052 136
137 while( fBunchIndex<fkBunch->fData.size() ){
4d67c3e3 138
25080052 139 AliHLTUInt32_t iStart = fBunchIndex;
140 AliHLTUInt32_t iPeak = fBunchIndex;
141 AliHLTUInt32_t qPeak = 0;
4d67c3e3 142
25080052 143 // find next/best peak
ef19b824 144
25080052 145 for( ; fBunchIndex<fkBunch->fData.size(); fBunchIndex++ ){
146 const AliHLTTPCHWCFDigit &d = fkBunch->fData[fBunchIndex];
147 if( d.fPeak != 1 ) continue;
148 if( fDeconvolute ){
149 iPeak = fBunchIndex;
4d67c3e3 150 qPeak = d.fQ;
25080052 151 fBunchIndex++;
152 break;
153 } else {
154 if( d.fQ>qPeak ){
155 qPeak = d.fQ;
156 iPeak = fBunchIndex;
157 }
ef19b824 158 }
159 }
4d67c3e3 160
161 if( qPeak == 0 ) return 0;
25080052 162
4d67c3e3 163 // find next minimum !!! At the moment the minimum finder is on only when no timebin window set
164
165 if( !fUseTimeBinWindow ){
166 for( ; fBunchIndex<fkBunch->fData.size(); fBunchIndex++ ){
167 if( fDeconvolute ){
168 if( fkBunch->fData[fBunchIndex].fPeak != 0 ){
169 fBunchIndex++;
170 break;
171 }
172 }
173 }
174 } else{
175 if( !fDeconvolute ){
176 fBunchIndex = fkBunch->fData.size();
177 } else {
178 // find next peak
179 if( fBunchIndex+1<fkBunch->fData.size() && fkBunch->fData[fBunchIndex+1].fPeak==1 ){
180 fBunchIndex = fBunchIndex+1;
181 } else if( fBunchIndex+2<fkBunch->fData.size() && fkBunch->fData[fBunchIndex+2].fPeak==1 ){
182 fBunchIndex = fBunchIndex+1;
183 } else if( fBunchIndex+3<fkBunch->fData.size() && fkBunch->fData[fBunchIndex+3].fPeak==1 ){
184 fBunchIndex = fBunchIndex+2;
185 } else if( fBunchIndex+1<fkBunch->fData.size() ){
186 fBunchIndex = fBunchIndex+2;
187 } else if( fBunchIndex<fkBunch->fData.size() ){
188 fBunchIndex = fBunchIndex+1;
ef19b824 189 }
190 }
191 }
192
4d67c3e3 193 AliHLTUInt32_t iEnd = fBunchIndex;
194
25080052 195 if( fUseTimeBinWindow ){
196 if( iPeak > iStart + kHalfTimeBinWindow ) iStart = iPeak - kHalfTimeBinWindow;
4d67c3e3 197 if( iEnd > iPeak + kHalfTimeBinWindow + 1) iEnd = iPeak + kHalfTimeBinWindow + 1;
ee4d1bf0 198 }
25080052 199
4d67c3e3 200 fOutput.fQmax = qPeak*fkBunch->fGain;
25080052 201 fOutput.fQ = 0;
202 fOutput.fT = 0;
203 fOutput.fT2 = 0;
204 fOutput.fP = 0;
205 fOutput.fP2 = 0;
206 fOutput.fTMean = fkBunch->fData[iPeak].fTime;
207 fOutput.fMC.clear();
208
209 for( AliHLTUInt32_t i=iStart; i<iEnd; i++ ){
210 const AliHLTTPCHWCFDigit &d = fkBunch->fData[i];
4d67c3e3 211 AliHLTUInt64_t q = d.fQ*fkBunch->fGain;
25080052 212 fOutput.fQ += q;
213 fOutput.fT += q*d.fTime;
214 fOutput.fT2+= q*d.fTime*d.fTime;
215 fOutput.fP += q*fkBunch->fPad;
216 fOutput.fP2+= q*fkBunch->fPad*fkBunch->fPad;
217 fOutput.fMC.push_back(d.fMC);
c012881c 218 }
ef19b824 219
25080052 220 if( fkBunch->fData.size()==1 && fOutput.fQ < fSingleSeqLimit ) continue;
87e92eec 221
25080052 222 return &fOutput;
223 }
224 return 0;
c012881c 225}