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