3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
7 * Primary Authors: Oystein Djuvsland *
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 **************************************************************************/
18 * @file AliHLTPHOSDigitMaker.cxx
19 * @author Oystein Djuvsland
21 * @brief Digit maker for PHOS HLT
27 // see header file for class documentation
29 // refer to README to build package
31 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
33 #include "AliHLTPHOSDigitMaker.h"
34 #include "AliHLTLogging.h"
36 #include "AliHLTPHOSConstant.h"
37 #include "AliHLTPHOSMapper.h"
39 #include "AliHLTPHOSChannelDataStruct.h"
40 #include "AliHLTPHOSChannelDataHeaderStruct.h"
41 #include "AliHLTPHOSDigitDataStruct.h"
42 #include "AliHLTPHOSSharedMemoryInterfacev2.h" // added by PTH
46 ClassImp(AliHLTPHOSDigitMaker);
48 using namespace PhosHLTConst;
50 AliHLTPHOSDigitMaker::AliHLTPHOSDigitMaker() :
61 // See header file for documentation
63 fShmPtr = new AliHLTPHOSSharedMemoryInterfacev2();
65 for(int x = 0; x < NXCOLUMNSMOD; x++)
67 for(int z = 0; z < NZROWSMOD; z++)
69 fHighGainFactors[x][z] = 0.005;
70 fLowGainFactors[x][z] = 0.08;
71 fBadChannelMask[x][z][HIGHGAIN] = 1;
72 fBadChannelMask[x][z][LOWGAIN] = 1;
75 fMapperPtr = new AliHLTPHOSMapper();
77 fDigitPtrArray = new AliHLTPHOSDigitDataStruct*[NZROWSRCU*NXCOLUMNSMOD];
80 AliHLTPHOSDigitMaker::~AliHLTPHOSDigitMaker()
82 //See header file for documentation
86 AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
88 //See header file for documentation
90 fAvailableSize = availableSize;
92 UInt_t totSize = sizeof(AliHLTPHOSDigitDataStruct);
104 AliHLTPHOSChannelDataStruct* currentchannel = 0;
105 AliHLTPHOSChannelDataStruct* currentchannelLG = 0;
106 AliHLTPHOSChannelDataStruct* tmpchannel = 0;
108 fShmPtr->SetMemory(channelDataHeader);
109 currentchannel = fShmPtr->NextChannel();
111 while(currentchannel != 0)
113 if(availableSize < totSize) return -1;
115 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord1);
117 if(fOrdered) // High gain comes before low gain
119 tmpchannel = currentchannel;
121 if(coord1[2] == HIGHGAIN) // We got a completely new crystal
123 if(currentchannel->fEnergy < MAXBINVALUE) // Make sure we don't have signal overflow
125 //AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
126 if(!AddDigit(currentchannel, coord1, locCoord)) return -1;
128 totSize += sizeof(AliHLTPHOSDigitDataStruct);
130 currentchannel = fShmPtr->NextChannel(); // Get the next channel
132 if(currentchannel != 0) // There was a next channel!
134 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
135 if(coord1[0] == coord2[0] && coord1[1] == coord2[1]) // Did we get the low gain channel for this crystal?
137 currentchannel = fShmPtr->NextChannel(); // In that case, jump to next channel
142 else // Ooops, overflow, we try the next channel...
144 currentchannel = fShmPtr->NextChannel();
145 if(currentchannel != 0) // There was a next channel
147 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
148 if(coord2[0] == coord1[0] && coord2[1] == coord1[1]) // It is a low gain channel with the same coordinates, we may use it
150 // AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
151 if(!AddDigit(currentchannel, coord2, locCoord)) return -1;
153 totSize += sizeof(AliHLTPHOSDigitDataStruct);
154 currentchannel = fShmPtr->NextChannel();
157 else // No low gain channel with information about the overflow channel so we just use the overflowed one...
159 //AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
160 if(!AddDigit(tmpchannel, coord1, locCoord)) return -1;
162 totSize += sizeof(AliHLTPHOSDigitDataStruct);
163 // no need to get the next channel here, we already did...
169 else // Well, there seem to be missing a high gain channel for this crystal, let's use the low gain one
171 //AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
172 if(!AddDigit(tmpchannel, coord1, locCoord)) return -1;
174 totSize += sizeof(AliHLTPHOSDigitDataStruct);
175 currentchannel = fShmPtr->NextChannel();
179 else //Reversed ordered (low gain before high gain)
181 if(coord1[2] == LOWGAIN) // We got a new channel!
183 currentchannelLG = currentchannel; // Ok, let's back up the low gain channel and look for the fancy high gain one
184 currentchannel = fShmPtr->NextChannel();
186 if(currentchannel != 0) //There was another channel in the event
188 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
190 if(coord1[0] == coord2[0] && coord1[1] == coord2[1]) // Aha! Found the high gain channel
192 if(currentchannel->fEnergy < MAXBINVALUE) // To overflow or not to overflow?
194 // AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
195 if(!AddDigit(currentchannel, coord2, locCoord)) return -1;
197 totSize += sizeof(AliHLTPHOSDigitDataStruct);
198 currentchannel = fShmPtr->NextChannel();
200 else // Oh well, better use the low gain channel then
202 // AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
203 if(!AddDigit(currentchannelLG, coord1, locCoord)) return -1;
205 totSize += sizeof(AliHLTPHOSDigitDataStruct);
206 currentchannel = fShmPtr->NextChannel();
209 else // No available high gain channel for this crystal, adding the low gain one
211 // AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
212 if(!AddDigit(currentchannelLG, coord1, locCoord)) return -1;
214 totSize += sizeof(AliHLTPHOSDigitDataStruct);
217 else //Fine, no more channels, better add this one...
219 //AliHLTPHOSMapper::GetLocalCoord(currentchannelLG->fChannelID, locCoord);
220 if(!AddDigit(currentchannelLG, coord1, locCoord)) return -1;
222 totSize += sizeof(AliHLTPHOSDigitDataStruct);
225 else // Cool, no annoying low gain channel for this channel
227 //AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
228 if(!AddDigit(currentchannel, coord1, locCoord)) return -1;
230 currentchannel = fShmPtr->NextChannel();
234 if(fDigitCount > 1) SortDigits();
239 AliHLTPHOSDigitMaker::SetGlobalHighGainFactor(Float_t factor)
241 //See header file for documentation
242 for(int x = 0; x < NXCOLUMNSMOD; x++)
244 for(int z = 0; z < NZROWSMOD; z++)
246 fHighGainFactors[x][z] = factor;
252 AliHLTPHOSDigitMaker::SetGlobalLowGainFactor(Float_t factor)
254 //See header file for documentation
255 for(int x = 0; x < NXCOLUMNSMOD; x++)
257 for(int z = 0; z < NZROWSMOD; z++)
259 fLowGainFactors[x][z] = factor;
265 AliHLTPHOSDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
267 // See header file for documentation
268 for(int x = 0; x < NXCOLUMNSMOD; x++)
270 for(int z = 0; z < NZROWSMOD; z++)
272 if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
274 fBadChannelMask[x][z][HIGHGAIN] = 1;
278 fBadChannelMask[x][z][HIGHGAIN] = 0;
280 if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
282 fBadChannelMask[x][z][LOWGAIN] = 0;
286 fBadChannelMask[x][z][LOWGAIN] = 0;
293 AliHLTPHOSDigitMaker::SortDigits()
296 // See header file for documentation
298 // Int_t (*funcPtr)(const void*, const void*) = &AliHLTPHOSDigitMaker::CompareDigits;
299 // HLTError("fDigitPtrArray[0]: %lu, fDigitHeaderPtr: %lu, sizeof(AliHLTPHOSDigitHeaderStruct): %d", fDigitPtrArray[0], fDigitHeaderPtr, sizeof(AliHLTPHOSDigitHeaderStruct));
300 // HLTError("First digit offset: %d, first digit ptr: %ld, sizeof(AliHLTPHOSDigitDataStruct) = %d", fDigitHeaderPtr->fFirstDigitOffset, fDigitPtrArray[0], sizeof(AliHLTPHOSDigitDataStruct));
301 qsort(fDigitPtrArray, fDigitCount, sizeof(AliHLTPHOSDigitDataStruct*), CompareDigits);
303 // HLTError("fDigitPtrArray[0]: %lu, fDigitHeaderPtr: %lu, sizeof(AliHLTPHOSDigitHeaderStruct): %d", fDigitPtrArray[0], fDigitHeaderPtr, sizeof(AliHLTPHOSDigitHeaderStruct));
304 // fDigitHeaderPtr->fFirstDigitOffset = reinterpret_cast<Long_t>(fDigitPtrArray[0]) - reinterpret_cast<Long_t>(fDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct);
305 fDigitHeaderPtr->fFirstDigitOffset = reinterpret_cast<Long_t>(fDigitPtrArray[0]) - reinterpret_cast<Long_t>(fDigitHeaderPtr);
306 // HLTError("First digit offset: %d, first digit ptr: %ld, sizeof(AliHLTPHOSDigitDataStruct) = %d", fDigitHeaderPtr->fFirstDigitOffset, fDigitPtrArray[0], sizeof(AliHLTPHOSDigitDataStruct));
307 for(Int_t i = 0; i < fDigitCount-1; i++)
309 fDigitPtrArray[i]->fMemOffsetNext = reinterpret_cast<Long_t>(fDigitPtrArray[i+1]) - reinterpret_cast<Long_t>(fDigitPtrArray[i]);
310 // HLTError("Adding digit with energy: %f, ID: %d, offset: %d and pointer %lu", fDigitPtrArray[i]->fEnergy, fDigitPtrArray[i]->fID, fDigitPtrArray[i]->fMemOffsetNext, fDigitPtrArray[i]);
312 // fDigitHeaderPtr->fLastDigitOffset = reinterpret_cast<Long_t>(fDigitPtrArray[fDigitCount-1]) - (reinterpret_cast<Long_t>(fDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct));
313 fDigitHeaderPtr->fLastDigitOffset = reinterpret_cast<Long_t>(fDigitPtrArray[fDigitCount-1]) - reinterpret_cast<Long_t>(fDigitHeaderPtr);
314 // HLTError("Last digit offset: %d, last digit ptr: %ld", fDigitHeaderPtr->fLastDigitOffset, fDigitPtrArray[fDigitCount-1]);
315 fDigitPtrArray[fDigitCount-1]->fMemOffsetNext = 0;
316 // HLTError("Number of digits: %d", fDigitCount);
317 fDigitHeaderPtr->fNDigits = fDigitCount;
322 AliHLTPHOSDigitMaker::CompareDigits(const void *dig0, const void *dig1)
324 // See header file for documentation
325 return (*((AliHLTPHOSDigitDataStruct**)(dig0)))->fID - (*((AliHLTPHOSDigitDataStruct**)(dig1)))->fID;