]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h
3af34be61f751efffe929d252962b73f3818a6c0
[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         bool LoadLookUpTable(AliHLTMUONHitRecoLutRow* lookUpTableData, AliHLTInt32_t lookUpTableId);
52         bool SetIdManuChannelToEntry(IdManuChannelToEntry lineToId);
53         
54         
55         bool Run(
56                         const AliHLTUInt32_t* rawData,
57                         AliHLTUInt32_t rawDataSize,
58                         AliHLTMUONRecHitStruct* recHit,
59                         AliHLTUInt32_t& nofHit
60                 );
61         void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
62         
63         static AliHLTInt32_t GetkDetectorId() { return fgkDetectorId; }
64         static AliHLTInt32_t GetkDDLOffSet() { return fgkDDLOffSet; }
65         static AliHLTInt32_t GetkNofDDL() { return fgkNofDDL; }
66         static AliHLTInt32_t GetkDDLHeaderSize() { return fgkDDLHeaderSize; }
67
68 private:
69
70         static const AliHLTInt32_t fgkDetectorId;      // DDL Offset
71         static const AliHLTInt32_t fgkDDLOffSet;       // DDL Offset
72         static const AliHLTInt32_t fgkNofDDL;          // Number of DDL 
73         static const AliHLTInt32_t fgkDDLHeaderSize;   // DDL header size
74         static const AliHLTInt32_t fgkLutLine;         // nof Line in LookupTable
75
76 protected:
77
78         AliHLTMUONHitReconstructor(const AliHLTMUONHitReconstructor& rhs); // copy constructor
79         AliHLTMUONHitReconstructor& operator=(const AliHLTMUONHitReconstructor& rhs); // assignment operator
80
81 private:
82
83         struct AliHLTMUONPad
84         {
85                 AliHLTInt32_t fDetElemId;  // The detector element ID of the pad.
86                 AliHLTInt32_t fIX, fIY;  // The X,Y number of the pad.
87                 AliHLTFloat32_t fRealX, fRealY, fRealZ;   // The real coordinate of the pad.
88                 AliHLTFloat32_t fHalfPadSize; // half padsize in X and Y
89                 AliHLTInt32_t fPlane;   // The plane and PCB zone ID numbers.
90                 AliHLTFloat32_t fCharge;  // The charge measured on the pad.
91         };
92         
93
94         class AliHLTMUONRawDecoder : public AliMUONTrackerDDLDecoderEventHandler, public AliHLTLogging
95         {
96         public:
97         
98                 AliHLTMUONRawDecoder();
99                 virtual ~AliHLTMUONRawDecoder();
100                 
101                 void OnData(UInt_t dataWord, bool /*parityError*/);
102                 void OnNewBusPatch(const AliMUONBusPatchHeaderStruct* header, const void* /*data*/) 
103                 {
104                         fBusPatchId = int(header->fBusPatchId);
105                 };
106                 
107                 void OnNewBuffer(const void* buffer, UInt_t /*bufferSize*/) 
108                 {
109                         assert( buffer != NULL );
110                         fBufferStart = buffer;
111                         fDataCount = 1;  // dataCount starts from 1 because the 0-th element of fPadData is used as null value.
112                         *fNofFiredDetElem = 0;
113                         fPrevDetElemId = 0 ;
114                 };
115                 
116                 void OnError(ErrorCode code, const void* location)
117                 {
118                         long bytepos = long(location) - long(fBufferStart) + sizeof(AliRawDataHeader);
119                         HLTError("There is a problem with decoding the raw data. %s (Error code: %d, at byte %d)",
120                                 ErrorCodeToMessage(code), code, bytepos
121                         );
122                 };
123                 
124                 void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
125                 void SetPadData(AliHLTMUONPad* padData) {fPadData = padData;}
126                 void SetLookUpTable(AliHLTMUONHitRecoLutRow* lookUpTableData) {fLookUpTableData = lookUpTableData;}
127                 void SetNofFiredDetElemId(AliHLTInt32_t& nofFiredDetElem) {fNofFiredDetElem = &nofFiredDetElem;}
128                 void SetIdManuChannelToEntry(IdManuChannelToEntry idToEntry) {fIdToEntry = idToEntry;}
129                 void SetMaxFiredPerDetElem(AliHLTInt32_t* maxFiredPerDetElem) {fMaxFiredPerDetElem = maxFiredPerDetElem;}
130                 
131                 AliHLTInt32_t GetDataCount() {return fDataCount;}
132         
133         private:
134                 // Do not allow copying of this class.
135                 /// Not implemented
136                 AliHLTMUONRawDecoder(const AliHLTMUONRawDecoder& rhs); // copy constructor
137                 /// Not implemented
138                 AliHLTMUONRawDecoder& operator=(const AliHLTMUONRawDecoder& rhs); // assignment operator
139         
140                 const void* fBufferStart;   // Pointer to the start of the current DDL payload buffer.
141                 AliHLTInt32_t fBusPatchId;                                                // buspatchId
142                 AliHLTInt32_t fDCCut;                                                     // DC Cut value
143                 AliHLTMUONPad* fPadData;                  // pointer to the array containing the information of each padhits
144                 AliHLTMUONHitRecoLutRow* fLookUpTableData;          // pointer to the array of Lookuptable data
145                 AliHLTInt32_t* fNofFiredDetElem;                                          // counter for detector elements that are fired 
146                 AliHLTInt32_t* fMaxFiredPerDetElem;                                       // array for detector elements that are fired 
147                 IdManuChannelToEntry fIdToEntry;                                // Mapping between Linenumber to IdManuChannel;
148                 
149                 AliHLTInt32_t fDataCount;                                                 // Data Counter
150                 AliHLTInt32_t fPrevDetElemId;                                             // previous detection elementId
151                 AliHLTInt32_t fPadCharge;                                                 // pedestal subtracted pad charge
152                 AliHLTFloat32_t fCharge;                                                  //calibrated pad charge 
153                 AliHLTInt32_t fIdManuChannel;                                             // id manu channel
154                 AliHLTInt32_t fLutEntry;                                                  // i-th entry in lookuptable
155         };
156
157         AliMUONTrackerDDLDecoder<AliHLTMUONRawDecoder> fHLTMUONDecoder; // robust HLTMUON Decoder
158         
159         AliHLTInt32_t fkBlockHeaderSize;                     // Block header size
160         AliHLTInt32_t fkDspHeaderSize;                       // DSP header size
161         AliHLTInt32_t fkBuspatchHeaderSize;                  // buspatch header size
162         
163         AliHLTInt32_t fDCCut;                                // DC Cut value
164         
165         AliHLTMUONPad* fPadData;                         // pointer to the array containing the information of each padhits
166         AliHLTMUONHitRecoLutRow* fLookUpTableData;                 // pointer to the array of Lookuptable data
167         
168         AliHLTMUONRecHitStruct* fRecPoints;       // Reconstructed hits
169         AliHLTUInt32_t *fRecPointsCount;                      // nof reconstructed hit  
170         AliHLTUInt32_t fMaxRecPointsCount;                    // max nof reconstructed hit  
171         
172         AliHLTInt32_t fCentralCountB, fCentralCountNB;        // centeral hits 
173         AliHLTInt32_t fDDLId;                                 // DDLId
174         AliHLTInt32_t fDigitPerDDL;                           // Total nof Digits perDDL 
175         
176         AliHLTInt32_t *fCentralChargeB, *fCentralChargeNB;           // pointer to an array of central hit
177         AliHLTFloat32_t *fRecX, *fRecY;                              // pointer to an array of reconstructed hit
178         AliHLTFloat32_t *fAvgChargeX, *fAvgChargeY;                  // average charge on central pad found using CG method
179         AliHLTInt32_t *fNofBChannel, *fNofNBChannel;                 // number of channels bending and non-bending.
180         AliHLTInt32_t fGetIdTotalData[336][237][2];                  // an array of idManuChannel with argument of centralX, centralY and planeType.
181         AliHLTInt32_t fNofFiredDetElem,fMaxFiredPerDetElem[13];      // counter for detector elements that are fired
182         IdManuChannelToEntry fIdToEntry;       // Mapping between Linenumber to IdManuChannel;
183         
184         //bool ReadDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
185         bool DecodeDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
186         void FindCentralHits(AliHLTInt32_t minPadId, AliHLTInt32_t maxPadId);
187         bool FindRecHits();
188         bool RecXRecY();
189         bool MergeRecHits();
190         void Clear();
191
192 };
193
194 #endif // ALIHLTMUONHITRECONSTRUCTOR_H