]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/HWCFemulator/AliHLTTPCHWCFPeakFinderUnit.cxx
HWCF emulator update according to the new hardware clusterfinder
[u/mrichter/AliRoot.git] / HLT / TPCLib / HWCFemulator / AliHLTTPCHWCFPeakFinderUnit.cxx
1 // $Id: AliHLTTPCHWCFPeakFinderUnit.cxx 51236 2011-08-22 16:01:48Z sgorbuno $
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   AliHLTTPCHWCFPeakFinderUnit.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 "AliHLTTPCHWCFPeakFinderUnit.h"
29 #include <iostream>
30 #include <cstdio>
31
32
33 AliHLTTPCHWCFPeakFinderUnit::AliHLTTPCHWCFPeakFinderUnit()
34   :
35   fOutput(),
36   fkBunch(0),
37   fChargeFluctuation(0),
38   fDebug(0)
39 {
40   //constructor 
41   Init();
42 }
43
44
45 AliHLTTPCHWCFPeakFinderUnit::~AliHLTTPCHWCFPeakFinderUnit()
46 {   
47   //destructor 
48 }
49
50 AliHLTTPCHWCFPeakFinderUnit::AliHLTTPCHWCFPeakFinderUnit(const AliHLTTPCHWCFPeakFinderUnit&)
51   :
52   fOutput(),
53   fkBunch(0),
54   fChargeFluctuation(0),
55   fDebug(0)
56 {
57   // dummy
58   Init();
59 }
60
61 AliHLTTPCHWCFPeakFinderUnit& AliHLTTPCHWCFPeakFinderUnit::operator=(const AliHLTTPCHWCFPeakFinderUnit&)
62 {
63   // dummy  
64   return *this;
65 }
66
67 int AliHLTTPCHWCFPeakFinderUnit::Init()
68 {
69   // initialise  
70
71   fkBunch = 0;
72   return 0;
73 }
74
75 int AliHLTTPCHWCFPeakFinderUnit::InputStream( const AliHLTTPCHWCFBunch *bunch )
76 {
77   // input stream of data 
78   
79   if( bunch && fDebug ){
80     printf("\nHWCF Processor: input bunch F %1d R %3d P %3d  NS %2ld:\n",
81            bunch->fFlag, bunch->fRow, bunch->fPad, bunch->fData.size());
82     for( unsigned int i=0; i<bunch->fData.size(); i++ ){
83       const AliHLTTPCHWCFDigit &d = bunch->fData[i];
84       printf("   q %2d t %3d ", d.fQ, d.fTime);
85       printf("(");
86       for( int j=0; j<3; j++ ) printf(" {%d,%2.0f}",d.fMC.fClusterID[j].fMCID, d.fMC.fClusterID[j].fWeight );
87       printf(" )\n");      
88     }
89   }
90
91   fkBunch = bunch;
92   return 0;
93 }
94
95 const AliHLTTPCHWCFBunch *AliHLTTPCHWCFPeakFinderUnit::OutputStream()
96
97   // output stream of data 
98
99   if( !fkBunch ) return 0;
100
101   fOutput.fFlag = fkBunch->fFlag;
102   fOutput.fRow = fkBunch->fRow;
103   fOutput.fPad = fkBunch->fPad;
104   fOutput.fBranch = fkBunch->fBranch;
105   fOutput.fBorder = fkBunch->fBorder;
106   fOutput.fGain = fkBunch->fGain;
107   fOutput.fData.clear();
108   fOutput.fData.insert(fOutput.fData.end(),fkBunch->fData.begin(), fkBunch->fData.end());
109   fkBunch = 0;
110
111   if( fOutput.fFlag !=1 ){ // rcu trailer word, forward it 
112     return &fOutput;
113   }
114
115   bool slope = 0;
116   AliHLTUInt32_t qLast = 0;
117   AliHLTUInt32_t n = fOutput.fData.size();
118   
119   for( AliHLTUInt32_t i=0; i<n; i++ ){
120     AliHLTUInt32_t q = fOutput.fData[i].fQ;
121     if( !slope && q + fChargeFluctuation < qLast   ){ // peak
122       slope = 1;
123       if( i>0 ) fOutput.fData[i-1].fPeak = 1;
124     }
125     if( slope && q > qLast + fChargeFluctuation ){ // minimum
126       slope = 0;
127       if( i>0 ) fOutput.fData[i-1].fPeak = 2;
128     }
129     qLast = q;
130   }
131   
132   if( n>0 ){
133     if( !slope ) fOutput.fData[n-1].fPeak = 1;
134     else fOutput.fData[n-1].fPeak = 2;
135   }
136   
137   return &fOutput;
138 }