Cleaning up generation and reading back of lookup tables. Also moved core generation...
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONHitReconstructor.h
CommitLineData
b12fe461 1#ifndef ALIHLTMUONHITRECONSTRUCTOR_H
2#define ALIHLTMUONHITRECONSTRUCTOR_H
ee3678d3 3/* This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
b12fe461 6
7/* $Id$ */
8
9///////////////////////////////////////////////
10//Author : Indranil Das, SINP, INDIA
11// Sukalyan Chattopadhyay, SINP, INDIA
12//
b12fe461 13//Email : indra.das@saha.ac.in
14// sukalyan.chattopadhyay@saha.ac.in
15///////////////////////////////////////////////
16
b12fe461 17#include <iostream>
18#include <cstdio>
19#include <fstream>
20#include <cstring>
21#include <cmath>
22#include <map>
ee3678d3 23#include <cassert>
b12fe461 24
ee3678d3 25#include "TString.h"
26#include "AliHLTLogging.h"
27#include "AliMUONTrackerDDLDecoder.h"
28#include "AliMUONTrackerDDLDecoderEventHandler.h"
29#include "AliHLTMUONDataTypes.h"
960d54ad 30
ee3678d3 31#include "AliRawDataHeader.h"
b12fe461 32
e29a165d 33#if __GNUC__ && __GNUC__ < 3
960d54ad 34#define std
35#endif
b12fe461 36
960d54ad 37
960d54ad 38extern "C" struct AliHLTMUONRecHitStruct;
b12fe461 39
a6b16447 40//TODO: Change code to not use std::map to avoid too many AliRoot coding rule violations.
ee3678d3 41typedef std::map<AliHLTInt32_t, AliHLTInt32_t> IdManuChannelToEntry;
42
b12fe461 43
44class AliHLTMUONHitReconstructor : public AliHLTLogging
45{
46public:
ee3678d3 47
48 AliHLTMUONHitReconstructor();
49 virtual ~AliHLTMUONHitReconstructor(void);
ee3678d3 50
93a75941 51 void SetLookUpTable(
52 const AliHLTMUONHitRecoLutRow* lookupTable,
53 const IdManuChannelToEntry* idToEntry
54 );
55
56 void SetDCCut(AliHLTInt32_t dcCut) { fDCCut = dcCut; }
ee3678d3 57
58 bool Run(
59 const AliHLTUInt32_t* rawData,
60 AliHLTUInt32_t rawDataSize,
61 AliHLTMUONRecHitStruct* recHit,
62 AliHLTUInt32_t& nofHit
63 );
ee3678d3 64
65 static AliHLTInt32_t GetkDetectorId() { return fgkDetectorId; }
66 static AliHLTInt32_t GetkDDLOffSet() { return fgkDDLOffSet; }
67 static AliHLTInt32_t GetkNofDDL() { return fgkNofDDL; }
68 static AliHLTInt32_t GetkDDLHeaderSize() { return fgkDDLHeaderSize; }
69
70private:
71
72 static const AliHLTInt32_t fgkDetectorId; // DDL Offset
73 static const AliHLTInt32_t fgkDDLOffSet; // DDL Offset
74 static const AliHLTInt32_t fgkNofDDL; // Number of DDL
75 static const AliHLTInt32_t fgkDDLHeaderSize; // DDL header size
76 static const AliHLTInt32_t fgkLutLine; // nof Line in LookupTable
b12fe461 77
b12fe461 78protected:
ee3678d3 79
80 AliHLTMUONHitReconstructor(const AliHLTMUONHitReconstructor& rhs); // copy constructor
81 AliHLTMUONHitReconstructor& operator=(const AliHLTMUONHitReconstructor& rhs); // assignment operator
82
960d54ad 83private:
b12fe461 84
ee3678d3 85 struct AliHLTMUONPad
86 {
87 AliHLTInt32_t fDetElemId; // The detector element ID of the pad.
88 AliHLTInt32_t fIX, fIY; // The X,Y number of the pad.
89 AliHLTFloat32_t fRealX, fRealY, fRealZ; // The real coordinate of the pad.
90 AliHLTFloat32_t fHalfPadSize; // half padsize in X and Y
91 AliHLTInt32_t fPlane; // The plane and PCB zone ID numbers.
92 AliHLTFloat32_t fCharge; // The charge measured on the pad.
93 };
94
95
96 class AliHLTMUONRawDecoder : public AliMUONTrackerDDLDecoderEventHandler, public AliHLTLogging
97 {
98 public:
99
100 AliHLTMUONRawDecoder();
101 virtual ~AliHLTMUONRawDecoder();
102
103 void OnData(UInt_t dataWord, bool /*parityError*/);
104 void OnNewBusPatch(const AliMUONBusPatchHeaderStruct* header, const void* /*data*/)
105 {
106 fBusPatchId = int(header->fBusPatchId);
107 };
108
109 void OnNewBuffer(const void* buffer, UInt_t /*bufferSize*/)
110 {
111 assert( buffer != NULL );
112 fBufferStart = buffer;
113 fDataCount = 1; // dataCount starts from 1 because the 0-th element of fPadData is used as null value.
114 *fNofFiredDetElem = 0;
115 fPrevDetElemId = 0 ;
116 };
117
118 void OnError(ErrorCode code, const void* location)
119 {
120 long bytepos = long(location) - long(fBufferStart) + sizeof(AliRawDataHeader);
121 HLTError("There is a problem with decoding the raw data. %s (Error code: %d, at byte %d)",
122 ErrorCodeToMessage(code), code, bytepos
123 );
124 };
125
126 void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
127 void SetPadData(AliHLTMUONPad* padData) {fPadData = padData;}
93a75941 128 void SetLookUpTable(const AliHLTMUONHitRecoLutRow* lookUpTableData) {fLookUpTableData = lookUpTableData;}
ee3678d3 129 void SetNofFiredDetElemId(AliHLTInt32_t& nofFiredDetElem) {fNofFiredDetElem = &nofFiredDetElem;}
93a75941 130 void SetIdManuChannelToEntry(const IdManuChannelToEntry* idToEntry) {fIdToEntry = idToEntry;}
ee3678d3 131 void SetMaxFiredPerDetElem(AliHLTInt32_t* maxFiredPerDetElem) {fMaxFiredPerDetElem = maxFiredPerDetElem;}
132
133 AliHLTInt32_t GetDataCount() {return fDataCount;}
134
135 private:
136 // Do not allow copying of this class.
137 /// Not implemented
138 AliHLTMUONRawDecoder(const AliHLTMUONRawDecoder& rhs); // copy constructor
139 /// Not implemented
140 AliHLTMUONRawDecoder& operator=(const AliHLTMUONRawDecoder& rhs); // assignment operator
141
142 const void* fBufferStart; // Pointer to the start of the current DDL payload buffer.
93a75941 143 AliHLTInt32_t fBusPatchId; // buspatchId
144 AliHLTInt32_t fDCCut; // DC Cut value
145 AliHLTMUONPad* fPadData; // pointer to the array containing the information of each padhits
146 const AliHLTMUONHitRecoLutRow* fLookUpTableData; // pointer to the array of Lookuptable data
147 AliHLTInt32_t* fNofFiredDetElem; // counter for detector elements that are fired
148 AliHLTInt32_t* fMaxFiredPerDetElem; // array for detector elements that are fired
149 const IdManuChannelToEntry* fIdToEntry; // Mapping between Linenumber to IdManuChannel;
ee3678d3 150
93a75941 151 AliHLTInt32_t fDataCount; // Data Counter
152 AliHLTInt32_t fPrevDetElemId; // previous detection elementId
153 AliHLTInt32_t fPadCharge; // pedestal subtracted pad charge
154 AliHLTFloat32_t fCharge; //calibrated pad charge
155 AliHLTInt32_t fIdManuChannel; // id manu channel
156 AliHLTInt32_t fLutEntry; // i-th entry in lookuptable
ee3678d3 157 };
158
159 AliMUONTrackerDDLDecoder<AliHLTMUONRawDecoder> fHLTMUONDecoder; // robust HLTMUON Decoder
160
93a75941 161 AliHLTInt32_t fkBlockHeaderSize; // Block header size
162 AliHLTInt32_t fkDspHeaderSize; // DSP header size
163 AliHLTInt32_t fkBuspatchHeaderSize; // buspatch header size
ee3678d3 164
93a75941 165 AliHLTInt32_t fDCCut; // DC Cut value
ee3678d3 166
93a75941 167 AliHLTMUONPad* fPadData; // pointer to the array containing the information of each padhits
168 const AliHLTMUONHitRecoLutRow* fLookUpTableData; // pointer to the array of Lookuptable data (The memory is not owned by this component).
ee3678d3 169
93a75941 170 AliHLTMUONRecHitStruct* fRecPoints; // Reconstructed hits
171 AliHLTUInt32_t *fRecPointsCount; // nof reconstructed hit.
172 AliHLTUInt32_t fMaxRecPointsCount; // max nof reconstructed hit.
ee3678d3 173
93a75941 174 AliHLTInt32_t fCentralCountB, fCentralCountNB; // centeral hits.
175 AliHLTInt32_t fDigitPerDDL; // Total nof Digits perDDL.
ee3678d3 176
93a75941 177 AliHLTInt32_t *fCentralChargeB, *fCentralChargeNB; // pointer to an array of central hit
178 AliHLTFloat32_t *fRecX, *fRecY; // pointer to an array of reconstructed hit
179 AliHLTFloat32_t *fAvgChargeX, *fAvgChargeY; // average charge on central pad found using CG method
180 AliHLTInt32_t *fNofBChannel, *fNofNBChannel; // number of channels bending and non-bending.
181 AliHLTInt32_t fGetIdTotalData[336][237][2]; // an array of idManuChannel with argument of centralX, centralY and planeType.
182 AliHLTInt32_t fNofFiredDetElem,fMaxFiredPerDetElem[13]; // counter for detector elements that are fired
183 const IdManuChannelToEntry* fIdToEntry; // Mapping between Linenumber to IdManuChannel (The object is not owned by this component).
ee3678d3 184
185 //bool ReadDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
186 bool DecodeDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
187 void FindCentralHits(AliHLTInt32_t minPadId, AliHLTInt32_t maxPadId);
188 bool FindRecHits();
189 bool RecXRecY();
190 bool MergeRecHits();
191 void Clear();
192
b12fe461 193};
194
b12fe461 195#endif // ALIHLTMUONHITRECONSTRUCTOR_H