]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h
9d9fa53fe8090119aac45f493beec5ccd0cebb31
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONHitReconstructor.h
1 #ifndef ALIHLTMUONHITRECONSTRUCTOR_H
2 #define ALIHLTMUONHITRECONSTRUCTOR_H
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                               */
6
7 /* $Id$ */
8
9 ///////////////////////////////////////////////
10 //Author : Indranil Das, SINP, INDIA
11 //         Sukalyan Chattopadhyay, SINP, INDIA
12 //         
13 //Email :  indra.das@saha.ac.in
14 //         sukalyan.chattopadhyay@saha.ac.in 
15 ///////////////////////////////////////////////
16
17 #include <iostream>
18 #include <cstdio>
19 #include <fstream>
20 #include <cstring>
21 #include <cmath>
22 #include <map>
23 #include <cassert>
24
25 #include "TString.h"
26 #include "AliHLTLogging.h"
27 #include "AliMUONTrackerDDLDecoder.h"
28 #include "AliMUONTrackerDDLDecoderEventHandler.h"
29 #include "AliHLTMUONDataTypes.h"
30
31 #include "AliRawDataHeader.h"
32
33 #if __GNUC__ && __GNUC__ < 3
34 #define std
35 #endif
36
37
38 extern "C" struct AliHLTMUONRecHitStruct;
39
40 //TODO: Change code to not use std::map to avoid too many AliRoot coding rule violations.
41 typedef std::map<AliHLTInt32_t, AliHLTInt32_t> IdManuChannelToEntry;
42
43
44 class AliHLTMUONHitReconstructor : public AliHLTLogging
45 {
46 public:
47         
48         AliHLTMUONHitReconstructor();
49         virtual ~AliHLTMUONHitReconstructor(void);
50         
51         void SetLookUpTable(
52                         const AliHLTMUONHitRecoLutRow* lookupTable,
53                         const IdManuChannelToEntry* idToEntry
54                 );
55         
56         void SetDCCut(AliHLTInt32_t dcCut) { fDCCut = dcCut; }
57         
58         bool Run(
59                         const AliHLTUInt32_t* rawData,
60                         AliHLTUInt32_t rawDataSize,
61                         AliHLTMUONRecHitStruct* recHit,
62                         AliHLTUInt32_t& nofHit
63                 );
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
70 private:
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
77
78 protected:
79
80         AliHLTMUONHitReconstructor(const AliHLTMUONHitReconstructor& rhs); // copy constructor
81         AliHLTMUONHitReconstructor& operator=(const AliHLTMUONHitReconstructor& rhs); // assignment operator
82
83 private:
84
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;}
128                 void SetLookUpTable(const AliHLTMUONHitRecoLutRow* lookUpTableData) {fLookUpTableData = lookUpTableData;}
129                 void SetNofFiredDetElemId(AliHLTInt32_t& nofFiredDetElem) {fNofFiredDetElem = &nofFiredDetElem;}
130                 void SetIdManuChannelToEntry(const IdManuChannelToEntry* idToEntry) {fIdToEntry = idToEntry;}
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.
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;
150                 
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
157         };
158
159         AliMUONTrackerDDLDecoder<AliHLTMUONRawDecoder> fHLTMUONDecoder; // robust HLTMUON Decoder
160         
161         AliHLTInt32_t fkBlockHeaderSize;      // Block header size
162         AliHLTInt32_t fkDspHeaderSize;        // DSP header size
163         AliHLTInt32_t fkBuspatchHeaderSize;   // buspatch header size
164         
165         AliHLTInt32_t fDCCut;                 // DC Cut value
166         
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).
169         
170         AliHLTMUONRecHitStruct* fRecPoints;      // Reconstructed hits
171         AliHLTUInt32_t *fRecPointsCount;         // nof reconstructed hit.
172         AliHLTUInt32_t fMaxRecPointsCount;       // max nof reconstructed hit.
173         
174         AliHLTInt32_t fCentralCountB, fCentralCountNB;   // centeral hits.
175         AliHLTInt32_t fDigitPerDDL;                      // Total nof Digits perDDL.
176         
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).
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
193 };
194
195 #endif // ALIHLTMUONHITRECONSTRUCTOR_H