]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/HWCFemulator/AliHLTTPCHWCFDivisionUnit.cxx
Emulation of FPGA clusterfinder
[u/mrichter/AliRoot.git] / HLT / TPCLib / HWCFemulator / AliHLTTPCHWCFDivisionUnit.cxx
1 //****************************************************************************
2 //* This file is property of and copyright by the ALICE HLT Project          * 
3 //* ALICE Experiment at CERN, All rights reserved.                           *
4 //*                                                                          *
5 //* Primary Authors: Sergey Gorbunov, Torsten Alt                            *
6 //* Developers:      Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de> *
7 //*                  Torsten Alt <talt@cern.ch>                              *
8 //*                  for The ALICE HLT Project.                              *
9 //*                                                                          *
10 //* Permission to use, copy, modify and distribute this software and its     *
11 //* documentation strictly for non-commercial purposes is hereby granted     *
12 //* without fee, provided that the above copyright notice appears in all     *
13 //* copies and that both the copyright notice and this permission notice     *
14 //* appear in the supporting documentation. The authors make no claims       *
15 //* about the suitability of this software for any purpose. It is            *
16 //* provided "as is" without express or implied warranty.                    *
17 //****************************************************************************
18
19 //  @file   AliHLTTPCHWCFDivisionUnit.cxx
20 //  @author Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de>
21 //  @author Torsten Alt <talt@cern.ch> 
22 //  @date   
23 //  @brief  Division unit of FPGA ClusterFinder Emulator for TPC
24 //  @brief  ( see AliHLTTPCHWCFEmulator class )
25 //  @note 
26
27 #include "AliHLTTPCHWCFDivisionUnit.h"
28 #include <iostream>
29 #include <algorithm>
30
31
32 AliHLTTPCHWCFDivisionUnit::AliHLTTPCHWCFDivisionUnit()
33   : 
34   fSinglePadSuppression(1), fClusterLowerLimit(0), fkInput(0),fOutput()
35 {
36   //constructor 
37 }
38
39
40 AliHLTTPCHWCFDivisionUnit::~AliHLTTPCHWCFDivisionUnit()
41 {   
42   //destructor 
43 }
44
45 AliHLTTPCHWCFDivisionUnit::AliHLTTPCHWCFDivisionUnit(const AliHLTTPCHWCFDivisionUnit&)
46   : 
47   fSinglePadSuppression(1),fClusterLowerLimit(0),fkInput(0),fOutput()
48 {
49 }
50
51
52 AliHLTTPCHWCFDivisionUnit& AliHLTTPCHWCFDivisionUnit::operator=(const AliHLTTPCHWCFDivisionUnit&)
53 {
54   // dummy  
55   return *this;
56 }
57
58 int AliHLTTPCHWCFDivisionUnit::Init()
59 {
60   // initialise
61   fkInput = 0;
62   return 0;
63 }
64   
65
66 int AliHLTTPCHWCFDivisionUnit::InputStream( const AliHLTTPCHWCFClusterFragment *fragment )
67 {
68   // input stream of data
69   fkInput = fragment;
70   if( fkInput ){
71     //if( fInput->fFlag==1 && fInput->fQ>0 ){
72     //std::cout<<"Division: input F "<<fInput->fFlag<<" R "<<fInput->fRow
73     //       <<" C "<<(fInput->fQ>>12)
74     //       <<" P "<<fInput->fPad
75     //       <<" T "<<fInput->fTMean
76     //       <<" CoGPad "<<((float)fInput->fP)/fInput->fQ
77     //       <<" CoGTime "<<((float)fInput->fT)/fInput->fQ
78     //       <<std::endl;
79     //} else std::cout<<"Division: input F "<<fInput->fFlag<<" R "<<fInput->fRow<<" P "<<fInput->fPad
80     //      <<" Q "<<(fInput->fQ>>12)<<std::endl;
81   }
82   return 0;
83 }
84
85 const AliHLTTPCHWCFCluster *AliHLTTPCHWCFDivisionUnit::OutputStream()
86
87   // output stream of data
88
89   if( !fkInput ) return 0;
90
91   if( fkInput->fFlag==2 ){ // RCU trailer word
92     fOutput.fFlag = 2;
93     fOutput.fRowQ = fkInput->fRow; // rcu word
94     fkInput = 0;
95     return &fOutput;;
96   }
97
98   if( fkInput->fFlag!=1 ) return 0;
99   
100   if( fkInput->fQ==0 ) return 0;
101   if( fSinglePadSuppression && fkInput->fQ==fkInput->fLastQ && !fkInput->fBorder ) return 0;
102   if( fkInput->fQ < fClusterLowerLimit ) return 0;
103
104   AliHLTFloat32_t q = fkInput->fQ;
105   
106   fOutput.fFlag = 1;
107   fOutput.fRowQ = (((AliHLTUInt32_t) 0x3)<<30) + ((fkInput->fRow &0x3f)<<24) + ((fkInput->fQ>>(AliHLTTPCHWCFDefinitions::kFixedPoint-6))&0xFFFFFF);               
108   *((AliHLTFloat32_t*)&fOutput.fP) = (float)fkInput->fP/q;
109   *((AliHLTFloat32_t*)&fOutput.fT) = (float)fkInput->fT/q;
110   *((AliHLTFloat32_t*)&fOutput.fP2) = (float)fkInput->fP2/q;
111   *((AliHLTFloat32_t*)&fOutput.fT2) = (float)fkInput->fT2/q;
112  
113   // MC part
114
115   AliHLTTPCClusterMCWeight emptyWeight = {-1,0};
116
117   fOutput.fMC.fClusterID[0] = emptyWeight;
118   fOutput.fMC.fClusterID[1] = emptyWeight;
119   fOutput.fMC.fClusterID[2] = emptyWeight;
120   
121   vector<AliHLTTPCClusterMCWeight> labels = fkInput->fMC;
122   sort(labels.begin(), labels.end(), CompareMCLabels);
123   for( unsigned int i=1; i<labels.size(); i++ ){
124     if(labels[i-1].fMCID==labels[i].fMCID ){
125       labels[i-1].fWeight+=labels[i].fWeight;
126       labels[i].fWeight = 0;
127     }
128   }
129
130   sort(labels.begin(), labels.end(), CompareMCWeights );
131     
132   for( unsigned int i=0; i<3 && i<labels.size(); i++ ){
133     if( labels[i].fMCID <0 ) continue;
134     fOutput.fMC.fClusterID[i] = labels[i];
135   }
136
137   fkInput = 0;
138
139   return &fOutput;
140 }
141