]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/HWCFemulator/AliHLTTPCHWCFDivisionUnit.cxx
Update to allow check per chamber
[u/mrichter/AliRoot.git] / HLT / TPCLib / HWCFemulator / AliHLTTPCHWCFDivisionUnit.cxx
1 // $Id$
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   AliHLTTPCHWCFDivisionUnit.cxx
21 //  @author Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de>
22 //  @author Torsten Alt <talt@cern.ch> 
23 //  @date   
24 //  @brief  Division unit of FPGA ClusterFinder Emulator for TPC
25 //  @brief  ( see AliHLTTPCHWCFEmulator class )
26 //  @note 
27
28 #include "AliHLTTPCHWCFDivisionUnit.h"
29 #include <iostream>
30 #include <algorithm>
31
32
33 AliHLTTPCHWCFDivisionUnit::AliHLTTPCHWCFDivisionUnit()
34   : 
35   fSinglePadSuppression(1), fClusterLowerLimit(0), fkInput(0),fOutput(), fDebug(0)
36 {
37   //constructor 
38 }
39
40
41 AliHLTTPCHWCFDivisionUnit::~AliHLTTPCHWCFDivisionUnit()
42 {   
43   //destructor 
44 }
45
46 AliHLTTPCHWCFDivisionUnit::AliHLTTPCHWCFDivisionUnit(const AliHLTTPCHWCFDivisionUnit&)
47   : 
48   fSinglePadSuppression(1),fClusterLowerLimit(0),fkInput(0),fOutput(), fDebug(0)
49 {
50 }
51
52
53 AliHLTTPCHWCFDivisionUnit& AliHLTTPCHWCFDivisionUnit::operator=(const AliHLTTPCHWCFDivisionUnit&)
54 {
55   // dummy  
56   return *this;
57 }
58
59 int AliHLTTPCHWCFDivisionUnit::Init()
60 {
61   // initialise
62   fkInput = 0;
63   return 0;
64 }
65   
66
67 int AliHLTTPCHWCFDivisionUnit::InputStream( const AliHLTTPCHWCFClusterFragment *fragment )
68 {
69   // input stream of data
70   fkInput = fragment;
71   if( fkInput && fDebug ){
72     std::cout<<"HWCF Division: input Br: "<<fragment->fBranch<<" F: "<<fragment->fFlag<<" R: "<<fragment->fRow
73              <<" Q: "<<(fragment->fQ>>AliHLTTPCHWCFDefinitions::kFixedPoint)
74              <<" P: "<<fragment->fPad<<" Tmean: "<<fragment->fTMean;            
75     if( fragment->fFlag==1 && fragment->fQ > 0 ){
76       std::cout<<" Pw: "<<((float)fragment->fP)/fragment->fQ
77                <<" Tw: "<<((float)fragment->fT)/fragment->fQ;
78       std::cout<<"   MC: ";
79       for( unsigned int j=0; j<fragment->fMC.size(); j++ ){
80         for( int k=0; k<3; k++ ){
81           std::cout<<"("<<fragment->fMC[j].fClusterID[k].fMCID<<" "<<fragment->fMC[j].fClusterID[k].fWeight<<") ";
82         }
83       }
84       std::cout<<std::endl;
85     }
86     else std::cout<<std::endl;      
87   }
88
89   return 0;
90 }
91
92 const AliHLTTPCHWCFCluster *AliHLTTPCHWCFDivisionUnit::OutputStream()
93
94   // output stream of data
95
96   if( !fkInput ) return 0;
97
98   if( fkInput->fFlag==2 ){ // RCU trailer word
99     fOutput.fFlag = 2;
100     fOutput.fRowQ = fkInput->fRow; // rcu word
101     fkInput = 0;
102     return &fOutput;;
103   }
104
105   if( fkInput->fFlag!=1 ) return 0;
106   
107   if( fkInput->fQ==0 ) return 0;
108   if( fSinglePadSuppression && fkInput->fQ==fkInput->fLastQ && !fkInput->fBorder ) return 0;
109   if( fkInput->fQ < fClusterLowerLimit ) return 0;
110
111   AliHLTFloat32_t q = fkInput->fQ;
112   
113   fOutput.fFlag = 1;
114   fOutput.fRowQ = (((AliHLTUInt32_t) 0x3)<<30) + ((fkInput->fRow &0x3f)<<24) + ((fkInput->fQmax)&0xFFFFFF);
115   fOutput.fQ = fkInput->fQ;
116   *((AliHLTFloat32_t*)&fOutput.fP) = (float)fkInput->fP/q;
117   *((AliHLTFloat32_t*)&fOutput.fT) = (float)fkInput->fT/q;
118   *((AliHLTFloat32_t*)&fOutput.fP2) = (float)fkInput->fP2/q;
119   *((AliHLTFloat32_t*)&fOutput.fT2) = (float)fkInput->fT2/q;
120  
121   // MC part
122
123   AliHLTTPCClusterMCWeight emptyWeight;
124
125   fOutput.fMC.fClusterID[0] = emptyWeight;
126   fOutput.fMC.fClusterID[1] = emptyWeight;
127   fOutput.fMC.fClusterID[2] = emptyWeight;
128   
129   vector<AliHLTTPCClusterMCWeight> labels;
130   for( unsigned i=0; i<fkInput->fMC.size(); i++){
131     labels.push_back(fkInput->fMC[i].fClusterID[0]);
132     labels.push_back(fkInput->fMC[i].fClusterID[1]);
133     labels.push_back(fkInput->fMC[i].fClusterID[2]);
134   }
135   sort(labels.begin(), labels.end(), CompareMCLabels);
136   for( unsigned int i=1; i<labels.size(); i++ ){
137     if(labels[i-1].fMCID==labels[i].fMCID ){
138       labels[i].fWeight+=labels[i-1].fWeight;
139       labels[i-1].fWeight = 0;
140     }
141   }
142
143   sort(labels.begin(), labels.end(), CompareMCWeights );
144     
145   for( unsigned int i=0; i<3 && i<labels.size(); i++ ){
146     if( labels[i].fMCID <0 ) continue;
147     fOutput.fMC.fClusterID[i] = labels[i];
148   }
149
150   fkInput = 0;
151
152   return &fOutput;
153 }
154