]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloDigitMaker.cxx
- removing obsolete file
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloDigitMaker.cxx
1 // $Id$\r
2 \r
3 /**************************************************************************\r
4  * This file is property of and copyright by the ALICE HLT Project        * \r
5  * All rights reserved.                                                   *\r
6  *                                                                        *\r
7  * Primary Authors: Oystein Djuvsland                                     *\r
8  *                                                                        *\r
9  * Permission to use, copy, modify and distribute this software and its   *\r
10  * documentation strictly for non-commercial purposes is hereby granted   *\r
11  * without fee, provided that the above copyright notice appears in all   *\r
12  * copies and that both the copyright notice and this permission notice   *\r
13  * appear in the supporting documentation. The authors make no claims     *\r
14  * about the suitability of this software for any purpose. It is          * \r
15  * provided "as is" without express or implied warranty.                  *\r
16  **************************************************************************/\r
17  /** \r
18  * @file   AliHLTCALOClusterizer.cxx\r
19  * @author Oystein Djuvsland\r
20  * @date \r
21  * @brief  Digit maker for CALO HLT  \r
22  */\r
23   \r
24 \r
25     \r
26 \r
27 // see header file for class documentation\r
28 // or\r
29 // refer to README to build package\r
30 // or\r
31 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt\r
32 \r
33 #include "AliHLTCaloDigitMaker.h"\r
34 #include "AliHLTCaloConstantsHandler.h"\r
35 #include "AliHLTCaloMapper.h"\r
36 #include "AliHLTCaloChannelDataStruct.h"\r
37 #include "AliHLTCaloChannelDataHeaderStruct.h"\r
38 #include "AliHLTCaloDigitDataStruct.h"\r
39 #include "AliHLTCaloCoordinate.h"\r
40 #include "AliHLTCaloSharedMemoryInterfacev2.h" // added by PTH\r
41 //#include "AliPHOSEMCAGeometry.h"\r
42 #include "TH2F.h"\r
43 #include "AliHLTCaloConstants.h"\r
44 #include "AliHLTLogging.h"\r
45 \r
46 ClassImp(AliHLTCaloDigitMaker);\r
47 \r
48 //using namespace CaloHLTConst;\r
49 \r
50 AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :\r
51   AliHLTCaloConstantsHandler(det),\r
52   AliHLTLogging(),\r
53   fShmPtr(0),\r
54   fDigitStructPtr(0),\r
55   fDigitCount(0),\r
56   fMapperPtr(0),\r
57   fHighGainFactors(0),\r
58   fLowGainFactors(0),\r
59   fBadChannelMask(0),\r
60   fChannelBook(0),\r
61   fMaxEnergy(900),\r
62   fMinTime(0.0),\r
63   fMaxTime(1008.0)\r
64 {\r
65   // See header file for documentation\r
66 \r
67   fShmPtr = new AliHLTCaloSharedMemoryInterfacev2(det);\r
68 \r
69   fHighGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];\r
70   fLowGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];\r
71   \r
72   fBadChannelMask = new Bool_t**[fCaloConstants->GetNXCOLUMNSMOD()];\r
73   \r
74   fChannelBook= new AliHLTCaloDigitDataStruct**[fCaloConstants->GetNXCOLUMNSMOD()];\r
75   \r
76   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
77     {\r
78       fHighGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];\r
79       fLowGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];\r
80 \r
81       fBadChannelMask[x] = new Bool_t*[fCaloConstants->GetNZROWSMOD()];\r
82 \r
83       fChannelBook[x] = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNZROWSMOD()];\r
84 \r
85       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
86         {\r
87 \r
88           fHighGainFactors[x][z] = 0.0153;\r
89           fLowGainFactors[x][z] = 0.245;\r
90          \r
91           fBadChannelMask[x][z] = new Bool_t[fCaloConstants->GetNGAINS()];\r
92           fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;\r
93           fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false; \r
94           \r
95           fChannelBook[x][z] = 0;\r
96           \r
97         }\r
98     }     \r
99 }\r
100 \r
101 AliHLTCaloDigitMaker::~AliHLTCaloDigitMaker() \r
102 {\r
103   //See header file for documentation\r
104 }\r
105 \r
106 Int_t\r
107 AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)\r
108 {\r
109   //See header file for documentation\r
110   \r
111   Reset();\r
112 \r
113   UInt_t totSize = sizeof(AliHLTCaloDigitDataStruct);\r
114   \r
115 //   Int_t xMod = -1;\r
116 //   Int_t zMod = -1;\r
117   \r
118 \r
119   AliHLTCaloCoordinate coord;\r
120   \r
121   \r
122   AliHLTCaloChannelDataStruct* currentchannel = 0;\r
123   \r
124   fShmPtr->SetMemory(channelDataHeader);\r
125   currentchannel = fShmPtr->NextChannel();\r
126 \r
127   while(currentchannel != 0)\r
128     {\r
129       if(availableSize < totSize) return -1;\r
130 \r
131       fMapperPtr->ChannelId2Coordinate(currentchannel->fChannelID, coord);\r
132       \r
133       //      fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
134       if(UseDigit(coord, currentchannel))\r
135       {\r
136         AddDigit(currentchannel, coord);\r
137         //      j++;          \r
138         totSize += sizeof(AliHLTCaloDigitDataStruct);\r
139       }\r
140       currentchannel = fShmPtr->NextChannel(); // Get the next channel\r
141     }\r
142 //       if(currentchannel)\r
143 //      {\r
144 //        fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
145 //        if(UseDigit(coord1, currentchannel))\r
146 //          {\r
147 //            AddDigit(currentchannel, coord1, locCoord);\r
148 //            j++;            \r
149 //            totSize += sizeof(AliHLTCaloDigitDataStruct);\r
150 //          }\r
151 //        currentchannel = fShmPtr->NextChannel(); // Get the next channel\r
152 //      }\r
153 //     }\r
154    \r
155 //   fDigitCount += j;\r
156    return fDigitCount; \r
157 }\r
158 \r
159 void \r
160 AliHLTCaloDigitMaker::SetGlobalHighGainFactor(Float_t factor)\r
161 {\r
162   //See header file for documentation\r
163   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
164     {\r
165       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
166         {\r
167           fHighGainFactors[x][z] = factor;\r
168         }\r
169     }\r
170 }\r
171 \r
172 \r
173 void\r
174 AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)\r
175 {\r
176   //See header file for documentation\r
177   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
178     {\r
179       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
180         {\r
181           fLowGainFactors[x][z] = factor;\r
182         }\r
183     }\r
184 }\r
185 \r
186 \r
187 void\r
188 AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)\r
189 {\r
190  for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
191     {\r
192       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
193         {\r
194           if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)\r
195             {\r
196               fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = true;\r
197             }\r
198           else\r
199             {\r
200               fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;\r
201             }\r
202           if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)\r
203             {\r
204               fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;\r
205             }\r
206           else\r
207             {\r
208               fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;\r
209             }\r
210         }\r
211     }\r
212 }\r
213 \r
214 void\r
215 AliHLTCaloDigitMaker::Reset()\r
216 {\r
217   fDigitCount = 0;\r
218   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
219     {\r
220       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
221         {\r
222           fChannelBook[x][z] = 0;\r
223         }\r
224     }     \r
225 \r
226 }\r
227 \r
228 \r
229 void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, AliHLTCaloCoordinate &coord)\r
230 {\r
231 \r
232   AliHLTCaloDigitDataStruct *tmpDigit = fDigitStructPtr + 1;\r
233 \r
234   if(fChannelBook[coord.fX][coord.fZ])\r
235     {\r
236       tmpDigit = fDigitStructPtr;\r
237       fDigitStructPtr = fChannelBook[coord.fX][coord.fZ];\r
238       fDigitCount--;\r
239       //      printf("Going to overwrite digit: x = %d, z = %d, gain = %d, energy = %f\n", fDigitStructPtr->fX, fDigitStructPtr->fZ, fDigitStructPtr->fGain, fDigitStructPtr->fEnergy);\r
240     }\r
241   \r
242   fChannelBook[coord.fX][coord.fZ] = fDigitStructPtr;\r
243 \r
244  \r
245   fDigitStructPtr->fX = coord.fX;\r
246   fDigitStructPtr->fZ = coord.fZ;\r
247   fDigitStructPtr->fGain = coord.fGain;\r
248   fDigitStructPtr->fOverflow = false;\r
249   \r
250   fDigitStructPtr->fID = fDigitStructPtr->fZ * fCaloConstants->GetNXCOLUMNSMOD() + fDigitStructPtr->fX;\r
251   \r
252   if(coord.fGain == fCaloConstants->GetHIGHGAIN() )\r
253     {\r
254       fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[coord.fX][coord.fZ];\r
255       if(channelData->fEnergy >= fMaxEnergy)\r
256         {\r
257           fDigitStructPtr->fOverflow = true;\r
258         }\r
259             HLTDebug("HG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f \n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy);\r
260     }\r
261   else\r
262     {\r
263       fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[coord.fX][coord.fZ];\r
264       if(channelData->fEnergy >= fMaxEnergy)\r
265         {\r
266           fDigitStructPtr->fOverflow = true;\r
267         }\r
268             HLTDebug("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy); \r
269     }\r
270   fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO\r
271   fDigitStructPtr->fCrazyness = channelData->fCrazyness;\r
272   fDigitStructPtr->fModule = coord.fModuleId;\r
273   fDigitStructPtr = tmpDigit;\r
274   //  fDigitStructPtr++;\r
275   fDigitCount++;\r
276 }\r
277 \r
278 bool AliHLTCaloDigitMaker::UseDigit(AliHLTCaloCoordinate &channelCoordinates, AliHLTCaloChannelDataStruct *channel) \r
279 {\r
280    \r
281    if(fBadChannelMask[channelCoordinates.fX][channelCoordinates.fZ][0] == true) return false;\r
282    if(channel->fTime < fMinTime || channel->fTime > fMaxTime) return false;\r
283    \r
284   AliHLTCaloDigitDataStruct *tmpDigit = fChannelBook[channelCoordinates.fX][channelCoordinates.fZ];\r
285   //printf("UseDigit: Got digit, x: %d, z: %d, gain: %d, amp: %f\n", channelCoordinates.fX, channelCoordinates.fZ, channelCoordinates.fGain, channel->fEnergy);\r
286   if(tmpDigit)\r
287     {\r
288       if(channelCoordinates.fGain == fCaloConstants->GetLOWGAIN())\r
289         {\r
290                   //printf("UseDigit: Already have digit with, x: %d, z: %d, with high gain \n", channelCoordinates.fX, channelCoordinates.fZ);\r
291           if(tmpDigit->fOverflow)\r
292             {\r
293                      // printf("But it was in overflow! Let's use this low gain!\n");\r
294               return true;\r
295             }\r
296           return false;\r
297         }\r
298       else\r
299         {\r
300                   //printf("UseDigit: Already have digit with, x: %d, z: %d, with low gain: %d\n", channelCoordinates.fX, channelCoordinates.fZ);\r
301           if(channel->fEnergy > fMaxEnergy )\r
302             {\r
303               return false;\r
304             }\r
305           return true;\r
306         }\r
307     }\r
308   return true;\r
309 }\r
310 \r
311 void AliHLTCaloDigitMaker::SetBadChannel(Int_t x, Int_t z, Bool_t bad)\r
312 {\r
313    // See header file for class documentation\r
314    fBadChannelMask[x][z][0] = bad;\r
315    fBadChannelMask[x][z][1] = bad;\r
316 }\r
317 \r
318 void AliHLTCaloDigitMaker::SetGain(Int_t x, Int_t z, Float_t ratio, Float_t gain)\r
319 {\r
320    // See header file for class documentation\r
321    \r
322    fHighGainFactors[x][z] = gain;\r
323    fLowGainFactors[x][z] = gain * ratio;\r
324    \r
325 }\r