]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/CALO/AliHLTCaloDigitMaker.cxx
- fixes to the geometry classes
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloDigitMaker.cxx
CommitLineData
ef44ec64 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
4f4b7ba4 34#include "AliHLTCaloConstantsHandler.h"\r
ef44ec64 35#include "AliHLTCaloMapper.h"\r
ef44ec64 36#include "AliHLTCaloChannelDataStruct.h"\r
37#include "AliHLTCaloChannelDataHeaderStruct.h"\r
38#include "AliHLTCaloDigitDataStruct.h"\r
f137c3c5 39#include "AliHLTCaloCoordinate.h"\r
ef44ec64 40#include "AliHLTCaloSharedMemoryInterfacev2.h" // added by PTH\r
41//#include "AliPHOSEMCAGeometry.h"\r
42#include "TH2F.h"\r
ef44ec64 43#include "AliHLTCaloConstants.h"\r
44\r
45ClassImp(AliHLTCaloDigitMaker);\r
46\r
47//using namespace CaloHLTConst;\r
48\r
49AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :\r
4f4b7ba4 50 AliHLTCaloConstantsHandler(det),\r
ef44ec64 51 fShmPtr(0),\r
52 fDigitStructPtr(0),\r
53 fDigitCount(0),\r
ef44ec64 54 fMapperPtr(0),\r
55 fHighGainFactors(0),\r
56 fLowGainFactors(0),\r
57 fBadChannelMask(0),\r
f137c3c5 58 fChannelBook(0),\r
59 fMaxEnergy(900)\r
ef44ec64 60{\r
ef44ec64 61 // See header file for documentation\r
62\r
4f4b7ba4 63 fShmPtr = new AliHLTCaloSharedMemoryInterfacev2(det);\r
ef44ec64 64\r
65 fHighGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];\r
66 fLowGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];\r
4f4b7ba4 67 \r
ef44ec64 68 fBadChannelMask = new Float_t**[fCaloConstants->GetNXCOLUMNSMOD()];\r
4f4b7ba4 69 \r
ef44ec64 70 fChannelBook= new AliHLTCaloDigitDataStruct**[fCaloConstants->GetNXCOLUMNSMOD()];\r
4f4b7ba4 71 \r
ef44ec64 72 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
73 {\r
74 fHighGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];\r
75 fLowGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];\r
76\r
77 fBadChannelMask[x] = new Float_t*[fCaloConstants->GetNZROWSMOD()];\r
78\r
79 fChannelBook[x] = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNZROWSMOD()];\r
80\r
81 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
82 {\r
83\r
84 fHighGainFactors[x][z] = 0.005;\r
85 fLowGainFactors[x][z] = 0.08;\r
86 \r
87 fBadChannelMask[x][z] = new Float_t[fCaloConstants->GetNGAINS()];\r
88 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 1;\r
89 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 1; \r
90 \r
91 fChannelBook[x][z] = 0;\r
92 \r
93 }\r
94 } \r
c375e15d 95}\r
96\r
ef44ec64 97AliHLTCaloDigitMaker::~AliHLTCaloDigitMaker() \r
98{\r
99 //See header file for documentation\r
100}\r
101\r
102Int_t\r
103AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)\r
104{\r
105 //See header file for documentation\r
106 \r
37616445 107 Reset();\r
ad44d760 108\r
ef44ec64 109 UInt_t totSize = sizeof(AliHLTCaloDigitDataStruct);\r
110 \r
111// Int_t xMod = -1;\r
112// Int_t zMod = -1;\r
113 \r
f137c3c5 114\r
115 AliHLTCaloCoordinate coord;\r
ef44ec64 116 \r
117 \r
118 AliHLTCaloChannelDataStruct* currentchannel = 0;\r
ef44ec64 119 \r
120 fShmPtr->SetMemory(channelDataHeader);\r
121 currentchannel = fShmPtr->NextChannel();\r
122\r
123 while(currentchannel != 0)\r
124 {\r
125 if(availableSize < totSize) return -1;\r
126\r
f137c3c5 127 fMapperPtr->ChannelId2Coordinate(currentchannel->fChannelID, coord);\r
ef44ec64 128 \r
f137c3c5 129 // fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
130 if(UseDigit(coord, currentchannel))\r
37616445 131 {\r
f137c3c5 132 AddDigit(currentchannel, coord);\r
ad44d760 133 // j++; \r
134 totSize += sizeof(AliHLTCaloDigitDataStruct);\r
37616445 135 }\r
37616445 136 currentchannel = fShmPtr->NextChannel(); // Get the next channel\r
ef44ec64 137 }\r
f137c3c5 138// if(currentchannel)\r
139// {\r
140// fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
141// if(UseDigit(coord1, currentchannel))\r
142// {\r
143// AddDigit(currentchannel, coord1, locCoord);\r
144// j++; \r
145// totSize += sizeof(AliHLTCaloDigitDataStruct);\r
146// }\r
147// currentchannel = fShmPtr->NextChannel(); // Get the next channel\r
148// }\r
149// }\r
37616445 150 \r
ad44d760 151// fDigitCount += j;\r
37616445 152 return fDigitCount; \r
ef44ec64 153}\r
154\r
155void \r
156AliHLTCaloDigitMaker::SetGlobalHighGainFactor(Float_t factor)\r
157{\r
158 //See header file for documentation\r
159 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
160 {\r
161 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
162 {\r
163 fHighGainFactors[x][z] = factor;\r
164 }\r
165 }\r
166}\r
167\r
168void\r
169AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)\r
170{\r
171 //See header file for documentation\r
172 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
173 {\r
174 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
175 {\r
176 fLowGainFactors[x][z] = factor;\r
177 }\r
178 }\r
179}\r
180\r
181void\r
182AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)\r
183{\r
184 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
185 {\r
186 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
187 {\r
188 if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)\r
189 {\r
190 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 1;\r
191 }\r
192 else\r
193 {\r
194 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 0;\r
195 }\r
196 if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)\r
197 {\r
198 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 0;\r
199 }\r
200 else\r
201 {\r
202 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 0;\r
203 }\r
204 }\r
205 }\r
206}\r
207\r
208void\r
209AliHLTCaloDigitMaker::Reset()\r
210{\r
211 fDigitCount = 0;\r
212 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)\r
213 {\r
214 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
215 {\r
216 fChannelBook[x][z] = 0;\r
217 }\r
218 } \r
219\r
220}\r
221\r
222\r
f137c3c5 223void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, AliHLTCaloCoordinate &coord)\r
ef44ec64 224{\r
225\r
ad44d760 226 AliHLTCaloDigitDataStruct *tmpDigit = fDigitStructPtr + 1;\r
227\r
228 if(fChannelBook[coord.fX][coord.fZ])\r
229 {\r
230 tmpDigit = fDigitStructPtr;\r
231 fDigitStructPtr = fChannelBook[coord.fX][coord.fZ];\r
232 fDigitCount--;\r
233 // printf("Going to overwrite digit: x = %d, z = %d, gain = %d, energy = %f\n", fDigitStructPtr->fX, fDigitStructPtr->fZ, fDigitStructPtr->fGain, fDigitStructPtr->fEnergy);\r
234 }\r
235 \r
f137c3c5 236 fChannelBook[coord.fX][coord.fZ] = fDigitStructPtr;\r
ef44ec64 237\r
7c80a370 238 \r
f137c3c5 239 fDigitStructPtr->fX = coord.fX;\r
240 fDigitStructPtr->fZ = coord.fZ;\r
ad44d760 241 fDigitStructPtr->fGain = coord.fGain;\r
f137c3c5 242 fDigitStructPtr->fOverflow = false;\r
7c80a370 243 \r
244 fDigitStructPtr->fID = fDigitStructPtr->fZ * fCaloConstants->GetNXCOLUMNSMOD() + fDigitStructPtr->fX;\r
245\r
f137c3c5 246 if(coord.fGain == fCaloConstants->GetHIGHGAIN() )\r
ef44ec64 247 {\r
f137c3c5 248 fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[coord.fX][coord.fZ];\r
249 if(channelData->fEnergy >= fMaxEnergy)\r
ef44ec64 250 {\r
251 fDigitStructPtr->fOverflow = true;\r
252 }\r
ad44d760 253 // printf("HG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f \n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy);\r
ef44ec64 254 }\r
255 else\r
256 {\r
f137c3c5 257 fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[coord.fX][coord.fZ];\r
ef44ec64 258 if(channelData->fEnergy >= 1023)\r
259 {\r
260 fDigitStructPtr->fOverflow = true;\r
261 }\r
ad44d760 262 // printf("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy); \r
ef44ec64 263 }\r
264 fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO\r
265 fDigitStructPtr->fCrazyness = channelData->fCrazyness;\r
f137c3c5 266 fDigitStructPtr->fModule = coord.fModuleId;\r
ad44d760 267 fDigitStructPtr = tmpDigit;\r
268 // fDigitStructPtr++;\r
269 fDigitCount++;\r
ef44ec64 270}\r
271\r
f137c3c5 272bool AliHLTCaloDigitMaker::UseDigit(AliHLTCaloCoordinate &channelCoordinates, AliHLTCaloChannelDataStruct *channel) \r
ef44ec64 273{\r
f137c3c5 274 AliHLTCaloDigitDataStruct *tmpDigit = fChannelBook[channelCoordinates.fX][channelCoordinates.fZ];\r
7c80a370 275 //printf("UseDigit: Got digit, x: %d, z: %d, gain: %d, amp: %f\n", channelCoordinates.fX, channelCoordinates.fZ, channelCoordinates.fGain, channel->fEnergy);\r
ef44ec64 276 if(tmpDigit)\r
277 {\r
f137c3c5 278 if(channelCoordinates.fGain == fCaloConstants->GetLOWGAIN())\r
ef44ec64 279 {\r
f137c3c5 280 // printf("UseDigit: Already have digit with, x: %d, z: %d, with high gain \n", channelCoordinates.fX, channelCoordinates.fZ);\r
ef44ec64 281 if(tmpDigit->fOverflow)\r
282 {\r
ad44d760 283 // printf("But it was in overflow! Let's use this low gain!\n");\r
ef44ec64 284 return true;\r
285 }\r
286 return false;\r
287 }\r
288 else\r
289 {\r
f137c3c5 290 // printf("UseDigit: Already have digit with, x: %d, z: %d, with low gain: %d\n", channelCoordinates.fX, channelCoordinates.fZ);\r
291 if(channel->fEnergy > fMaxEnergy )\r
ef44ec64 292 {\r
293 return false;\r
294 }\r
295 return true;\r
296 }\r
297 }\r
298 return true;\r
299}\r