]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h
ALIROOT-5433 Transition to CDHv3 in HLT
[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
1d8ae082 7// $Id$
b12fe461 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 <map>
18
ee3678d3 19#include "AliHLTLogging.h"
20#include "AliMUONTrackerDDLDecoder.h"
21#include "AliMUONTrackerDDLDecoderEventHandler.h"
22#include "AliHLTMUONDataTypes.h"
960d54ad 23
e29a165d 24#if __GNUC__ && __GNUC__ < 3
960d54ad 25#define std
26#endif
b12fe461 27
960d54ad 28
960d54ad 29extern "C" struct AliHLTMUONRecHitStruct;
83d66053 30extern "C" struct AliHLTMUONClusterStruct;
31extern "C" struct AliHLTMUONChannelStruct;
ee3678d3 32typedef std::map<AliHLTInt32_t, AliHLTInt32_t> IdManuChannelToEntry;
83d66053 33typedef IdManuChannelToEntry MaxEntryPerBusPatch;
b12fe461 34
35class AliHLTMUONHitReconstructor : public AliHLTLogging
36{
37public:
ee3678d3 38
39 AliHLTMUONHitReconstructor();
40 virtual ~AliHLTMUONHitReconstructor(void);
ee3678d3 41
93a75941 42 void SetLookUpTable(
43 const AliHLTMUONHitRecoLutRow* lookupTable,
83d66053 44 const IdManuChannelToEntry* idToEntry,
45 const MaxEntryPerBusPatch* maxEntryPerBP
93a75941 46 );
47
48 void SetDCCut(AliHLTInt32_t dcCut) { fDCCut = dcCut; }
ffc1a6f6 49 AliHLTInt32_t GetDCCut() const { return fDCCut; }
ee3678d3 50
51 bool Run(
daab896b 52 AliHLTUInt32_t* rawData,
ee3678d3 53 AliHLTUInt32_t rawDataSize,
40e6993e 54 AliHLTMUONRecHitStruct* const recHit,
ee3678d3 55 AliHLTUInt32_t& nofHit
56 );
ee3678d3 57
83d66053 58 /**
59 * Fills the output clusters array with the extra cluster information generated.
60 * If the method GenerateClusterInfo(true) was not called, then no cluster information
61 * is generated and this method will not do anything.
8984a6aa 62 * \param [out] clusters This is the output array that will be filled.
63 * \param [in,out] nofClusters Initially this contains the maximum number of elements
83d66053 64 * that can be stored in the clusters array. The method will fill this with
65 * the actual number of elements stored.
66 * \returns true if all elements were copied and false if there is not enough space in
67 * the output array.
68 */
69 bool FillClusterData(AliHLTMUONClusterStruct* clusters, AliHLTUInt32_t& nofClusters);
70
71 /**
72 * Fills the output channels array with the extra channel information generated.
73 * If the method GenerateChannelInfo(true) was not called, then no extra channel
74 * information is generated and this method will not do anything.
8984a6aa 75 * \param [out] channels This is the output array that will be filled.
76 * \param [in,out] nofChannels Initially this contains the maximum number of elements
83d66053 77 * that can be stored in the channels array. The method will fill this with
78 * the actual number of elements stored.
79 * \returns true if all elements were copied and false if there is not enough space in
80 * the output array.
81 */
82 bool FillChannelData(AliHLTMUONChannelStruct* channels, AliHLTUInt32_t& nofChannels);
83
ee3678d3 84 static AliHLTInt32_t GetkDetectorId() { return fgkDetectorId; }
85 static AliHLTInt32_t GetkDDLOffSet() { return fgkDDLOffSet; }
86 static AliHLTInt32_t GetkNofDDL() { return fgkNofDDL; }
87 static AliHLTInt32_t GetkDDLHeaderSize() { return fgkDDLHeaderSize; }
9f56f264 88 static AliHLTInt32_t GetkNofDetElemInDDL(Int_t iDDL);
89 static AliHLTInt32_t GetkMinDetElemIdInDDL(Int_t iDDL);
a5d4696f 90
a9afae73 91 /// The error recovery mode used for TryRecover.
92 enum ERecoveryMode
93 {
94 kDontTryRecover = 0, /// Will not try recover from errors.
95 kRecoverFull, /// Try recover from all errors.
96 kRecoverJustSkip, /// Just skip any corrupt structures.
97 kRecoverFromParityErrorsOnly /// Recover only from parity errors.
98 };
99
100 /// Returns the recovery mode used for the TryRecover option.
101 /// This controls if the decoder is set to enable recovery logic if
a5d4696f 102 /// raw data errors are found.
a9afae73 103 ERecoveryMode TryRecover() const { return fRecoveryMode; }
104
105 /// Sets if the decoder should enable the error recovery logic and how.
106 void TryRecover(ERecoveryMode mode);
a5d4696f 107
a9afae73 108 /// Returns true if ADC digits with parity errors are skipped.
109 bool SkipParityErrors() const { return fHLTMUONDecoder.GetHandler().SkipParityErrors(); }
110
111 /// Sets the flag indicating if ADC digits with parity errors are skipped.
112 void SkipParityErrors(bool value) { fHLTMUONDecoder.GetHandler().SkipParityErrors(value); }
113
114 /// Returns true if messages about parity errors are not printed.
115 bool DontPrintParityErrors() const { return fHLTMUONDecoder.GetHandler().DontPrintParityErrors(); }
116
117 /// Sets the flag indicating if messages about parity errors are not printed.
118 void DontPrintParityErrors(bool value) { fHLTMUONDecoder.GetHandler().DontPrintParityErrors(value); }
83d66053 119
120 /// Returns true if the extra cluster information should be generated.
121 bool GenerateClusterInfo() const { return fGenerateClusterInfo; }
122
123 /// Sets the flag to indicate if the extra cluster information should be generated.
124 void GenerateClusterInfo(bool value) { fGenerateClusterInfo = value; }
125
126 /// Returns true if the extra channel information should be generated.
127 bool GenerateChannelInfo() const { return fGenerateChannelInfo; }
128
129 /// Sets the flag to indicate if the extra channel information should be generated.
130 void GenerateChannelInfo(bool value) { fGenerateChannelInfo = value; }
131
132 /// Returns the maximum channel multiplicity allowed per cluster.
133 bool MaxChannelMultiplicity() const { return fMaxChannelMult; }
134
135 /// Sets the maximum channel multiplicity allowed per cluster.
136 /// \note This effects the memory allocation required. Generally M*N number of
137 /// channel structures will be allocated, where M = fMaxChannelMult and
138 /// N = the maximum number of hits that can be filled into the output buffers.
139 void MaxChannelMultiplicity(bool value) { fMaxChannelMult = value; }
140
141 /// Returns the DDL number the component expects data to be received from.
142 AliHLTInt32_t DDLNumber() const { return fDDL; }
143
144 /// Sets the DDL number the component expects data to be received from.
145 void DDLNumber(AliHLTInt32_t value) { fDDL = (value & 0x1F); } // 0x1F forces value into our required range.
ee3678d3 146
fd5b812e 147 bool InitDetElemInDDLArray();
148 bool DeInitDetElemInDDLArray();
149
ee3678d3 150private:
151
152 static const AliHLTInt32_t fgkDetectorId; // DDL Offset
153 static const AliHLTInt32_t fgkDDLOffSet; // DDL Offset
154 static const AliHLTInt32_t fgkNofDDL; // Number of DDL
155 static const AliHLTInt32_t fgkDDLHeaderSize; // DDL header size
156 static const AliHLTInt32_t fgkLutLine; // nof Line in LookupTable
fd5b812e 157 static const AliHLTInt32_t fgkMaxNofDataPerDetElem; // maximum allowed data points per detlem
158 static const AliHLTInt32_t fgkNofDetElemInDDL[20] ; // nof Detelem in a given ddl
159 static const AliHLTInt32_t fgkMinDetElemIdInDDL[20] ; // the detelem which has minimum value in ddl
b12fe461 160
ee3678d3 161 AliHLTMUONHitReconstructor(const AliHLTMUONHitReconstructor& rhs); // copy constructor
162 AliHLTMUONHitReconstructor& operator=(const AliHLTMUONHitReconstructor& rhs); // assignment operator
163
ee3678d3 164 struct AliHLTMUONPad
165 {
166 AliHLTInt32_t fDetElemId; // The detector element ID of the pad.
167 AliHLTInt32_t fIX, fIY; // The X,Y number of the pad.
168 AliHLTFloat32_t fRealX, fRealY, fRealZ; // The real coordinate of the pad.
169 AliHLTFloat32_t fHalfPadSize; // half padsize in X and Y
fd5b812e 170 AliHLTFloat32_t fPadSizeXY; // padsize in Y for bending plane and X for nonbending
ee3678d3 171 AliHLTInt32_t fPlane; // The plane and PCB zone ID numbers.
172 AliHLTFloat32_t fCharge; // The charge measured on the pad.
66622a82 173 AliHLTInt32_t fBusPatch; // The bus patch of the raw data word from the DDL stream.
174 AliHLTUInt32_t fRawData; // The raw data word from the DDL stream.
ee3678d3 175 };
176
177
178 class AliHLTMUONRawDecoder : public AliMUONTrackerDDLDecoderEventHandler, public AliHLTLogging
179 {
180 public:
181
182 AliHLTMUONRawDecoder();
183 virtual ~AliHLTMUONRawDecoder();
184
fd5b812e 185 void OnData(UInt_t dataWord, bool parityError);
186 void OnNewBusPatch(const AliMUONBusPatchHeaderStruct* header, const void* data) ;
ee3678d3 187
878cb83d 188 void OnNewBuffer(const void* buffer, UInt_t bufferSize);
189 void OnError(ErrorCode code, const void* location);
ee3678d3 190
191 void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
40e6993e 192 void SetPadData(AliHLTMUONPad* const padData) {fPadData = padData;}
fd5b812e 193 void SetLookUpTable(const AliHLTMUONHitRecoLutRow* lookUpTableData) {fkLookUpTableData = lookUpTableData;}
194
195 void SetIdManuChannelToEntry(const IdManuChannelToEntry* idToEntry) {fkIdToEntry = idToEntry;}
196 void SetMaxEntryPerBusPatch(const MaxEntryPerBusPatch* maxEntryPerBP) {fkMaxEntryPerBusPatch = maxEntryPerBP;}
197
198 AliHLTInt32_t DDLNumber() const { return fDDL; }
199 void DDLNumber(AliHLTInt32_t value) { fDDL = (value & 0x1F); } // 0x1F forces value into our required range.
200 // The following two methods have to called after set the ddl
40e6993e 201 void SetNofFiredDetElemId(AliHLTUInt16_t* const nofDataInDetElem) {fNofDataInDetElem = nofDataInDetElem;}
202 void SetMaxFiredPerDetElem(AliHLTUInt16_t** const dataCountListPerDetElem) {fDataCountListPerDetElem = dataCountListPerDetElem;}
fd5b812e 203
204
205 AliHLTInt32_t GetDataCount() const {return fDataCount;}
a5d4696f 206
207 /**
208 * Returns true if the OnError handler method will only generate warning
209 * messages and rather than error messages.
210 */
211 bool WarnOnly() const { return fWarnOnly; }
212
213 /**
214 * Sets the flag indicating if the OnError method should only generate
215 * warnings rather than error messages.
216 */
217 void WarnOnly(bool value) { fWarnOnly = value; }
a9afae73 218
219 /**
220 * Returns true if ADC digits with parity errors are skipped.
221 */
222 bool SkipParityErrors() const { return fSkipParityErrors; }
223
224 /**
225 * Sets the flag indicating if ADC digits with parity errors are skipped.
226 */
227 void SkipParityErrors(bool value) { fSkipParityErrors = value; }
228
229 /**
230 * Returns true if messages about parity errors are not printed.
231 */
232 bool DontPrintParityErrors() const { return fDontPrintParityErrors; }
233
234 /**
235 * Sets the flag indicating if messages about parity errors are not printed.
236 */
237 void DontPrintParityErrors(bool value) { fDontPrintParityErrors = value; }
238
239 /**
240 * Returns true if parity error messages are printed as warnings.
241 */
242 bool PrintParityErrorAsWarning() const { return fPrintParityErrorAsWarning; }
243
244 /**
245 * Sets the flag indicating if parity error messages are printed as warnings.
246 */
247 void PrintParityErrorAsWarning(bool value) { fPrintParityErrorAsWarning = value; }
248
aae30cc5 249 /**
250 * Returns true if a parity error was found during the last call to Decode.
251 */
252 bool ParityErrorFound() const { return fParityErrorFound; }
253
a9afae73 254 /**
255 * Returns true if a non-parity error was found during the last call to Decode.
256 */
257 bool NonParityErrorFound() const { return fNonParityErrorFound; }
ee3678d3 258
259 private:
260 // Do not allow copying of this class.
261 /// Not implemented
262 AliHLTMUONRawDecoder(const AliHLTMUONRawDecoder& rhs); // copy constructor
263 /// Not implemented
264 AliHLTMUONRawDecoder& operator=(const AliHLTMUONRawDecoder& rhs); // assignment operator
265
fd5b812e 266 const void* fkBufferStart; // Pointer to the start of the current DDL payload buffer.
93a75941 267 AliHLTInt32_t fBusPatchId; // buspatchId
268 AliHLTInt32_t fDCCut; // DC Cut value
269 AliHLTMUONPad* fPadData; // pointer to the array containing the information of each padhits
fd5b812e 270 const AliHLTMUONHitRecoLutRow* fkLookUpTableData; // pointer to the array of Lookuptable data
271 /* AliHLTInt32_t* fNofFiredDetElem; // counter for detector elements that are fired */
272 /* AliHLTInt32_t* fMaxFiredPerDetElem; // array for detector elements that are fired */
273 const IdManuChannelToEntry* fkIdToEntry; // Mapping between Linenumber to IdManuChannel;
274 const MaxEntryPerBusPatch* fkMaxEntryPerBusPatch; // Maximum allowed entry per Buspatch.
ee3678d3 275
fd5b812e 276 AliHLTInt32_t fDDL; // DDL number
93a75941 277 AliHLTInt32_t fDataCount; // Data Counter
278 AliHLTInt32_t fPrevDetElemId; // previous detection elementId
279 AliHLTInt32_t fPadCharge; // pedestal subtracted pad charge
280 AliHLTFloat32_t fCharge; //calibrated pad charge
281 AliHLTInt32_t fIdManuChannel; // id manu channel
282 AliHLTInt32_t fLutEntry; // i-th entry in lookuptable
a5d4696f 283
fd5b812e 284 AliHLTUInt16_t **fDataCountListPerDetElem; ///< List of datacounts associated with given ddl
285 AliHLTUInt16_t *fNofDataInDetElem; ///< Nof datacount in a ddl
a5d4696f 286 bool fWarnOnly; ///< Flag indicating if the OnError method should generate warnings rather than error messages.
a9afae73 287 bool fSkipParityErrors; ///< Flag indicating if ADC digits with parity errors should be skipped.
288 bool fDontPrintParityErrors; ///< Flag for controlling if messages about parity errors should be printed.
289 bool fPrintParityErrorAsWarning; ///< Flag for controlling if parity error messages are printed as warnings.
aae30cc5 290 bool fParityErrorFound; ///< Flag if a parity error was found after a decoding pass.
a9afae73 291 bool fNonParityErrorFound; ///< Flag which indicates if a non parity error code was found after a decoding pass.
aae30cc5 292 bool fIsMuchNoisy; ///< tag for noisy buspatch.
ee3678d3 293 };
294
295 AliMUONTrackerDDLDecoder<AliHLTMUONRawDecoder> fHLTMUONDecoder; // robust HLTMUON Decoder
296
93a75941 297 AliHLTInt32_t fkBlockHeaderSize; // Block header size
298 AliHLTInt32_t fkDspHeaderSize; // DSP header size
299 AliHLTInt32_t fkBuspatchHeaderSize; // buspatch header size
ee3678d3 300
93a75941 301 AliHLTInt32_t fDCCut; // DC Cut value
ee3678d3 302
93a75941 303 AliHLTMUONPad* fPadData; // pointer to the array containing the information of each padhits
fd5b812e 304 const AliHLTMUONHitRecoLutRow* fkLookUpTableData; // pointer to the array of Lookuptable data (The memory is not owned by this component).
ee3678d3 305
93a75941 306 AliHLTMUONRecHitStruct* fRecPoints; // Reconstructed hits
307 AliHLTUInt32_t *fRecPointsCount; // nof reconstructed hit.
308 AliHLTUInt32_t fMaxRecPointsCount; // max nof reconstructed hit.
ee3678d3 309
83d66053 310 AliHLTMUONClusterStruct* fClusters; // Array of output cluster infromation.
311 AliHLTUInt32_t fClusterCount; // Number of elemenets in fClusters.
312 AliHLTUInt32_t fMaxClusters; // Maximum number of clusters in fClusters.
313 bool fGenerateClusterInfo; // Flag indicating if extra cluster information should be generated.
314 AliHLTInt32_t fNewClusterId; // The ID to use for a new cluster structure.
315 AliHLTInt32_t fDDL; // The source DDL number of the raw data.
316
317 AliHLTMUONChannelStruct* fChannels; // Array of output channel infromation.
318 AliHLTUInt32_t fChannelCount; // Number of elemenets in fChannels.
319 AliHLTUInt32_t fMaxChannels; // Maximum number of channels in fChannels.
320 bool fGenerateChannelInfo; // Flag indicating if extra channel information should be generated.
321 AliHLTUInt32_t fMaxChannelMult; // Indicates the maximum channel multiplicity per cluster allowed.
322
93a75941 323 AliHLTInt32_t fCentralCountB, fCentralCountNB; // centeral hits.
324 AliHLTInt32_t fDigitPerDDL; // Total nof Digits perDDL.
fd5b812e 325
326 AliHLTUInt16_t **fDataCountListPerDetElem; // List of datacounts associated with given ddl
327 AliHLTUInt16_t *fNofDataInDetElem; // Nof datacount in a ddl
93a75941 328 AliHLTInt32_t *fCentralChargeB, *fCentralChargeNB; // pointer to an array of central hit
329 AliHLTFloat32_t *fRecX, *fRecY; // pointer to an array of reconstructed hit
330 AliHLTFloat32_t *fAvgChargeX, *fAvgChargeY; // average charge on central pad found using CG method
83d66053 331 AliHLTFloat32_t *fTotChargeX, *fTotChargeY; // Total charge in bending and nonbending direction
93a75941 332 AliHLTInt32_t *fNofBChannel, *fNofNBChannel; // number of channels bending and non-bending.
aa1eea98 333 AliHLTInt32_t *fNofYNeighbour; // number of neighbour pad in y direction, needed for y-resolution correction
93a75941 334 AliHLTInt32_t fGetIdTotalData[336][237][2]; // an array of idManuChannel with argument of centralX, centralY and planeType.
fd5b812e 335 //AliHLTInt32_t fNofFiredDetElem,fMaxFiredPerDetElem[130]; // counter for detector elements that are fired
336 const IdManuChannelToEntry* fkIdToEntry; // Mapping between Linenumber to IdManuChannel (The object is not owned by this component).
337 const MaxEntryPerBusPatch* fkMaxEntryPerBusPatch; // Maximum allowed entry per Buspatch.
ee3678d3 338
a9afae73 339 ERecoveryMode fRecoveryMode; ///< The recovery mode for the decoder.
340
daab896b 341 bool DecodeDDL(AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
fd5b812e 342 void FindCentralHits(AliHLTInt32_t iDet);
ee3678d3 343 bool FindRecHits();
878cb83d 344 void RecXRecY();
fd5b812e 345 bool MergeSlatRecHits();
346 bool MergeQuadRecHits();
ee3678d3 347 void Clear();
348
b12fe461 349};
350
b12fe461 351#endif // ALIHLTMUONHITRECONSTRUCTOR_H