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 "AliHLTPHOSConstants.h"
37 #include "AliHLTPHOSMapper.h"
39 #include "AliHLTPHOSChannelDataStruct.h"
40 #include "AliHLTPHOSChannelDataHeaderStruct.h"
41 #include "AliHLTPHOSDigitDataStruct.h"
42 #include "AliHLTPHOSSharedMemoryInterfacev2.h" // added by PTH
43 #include "AliPHOSEMCAGeometry.h"
47 ClassImp(AliHLTPHOSDigitMaker);
49 using namespace PhosHLTConst;
51 AliHLTPHOSDigitMaker::AliHLTPHOSDigitMaker() :
59 // See header file for documentation
61 fShmPtr = new AliHLTPHOSSharedMemoryInterfacev2();
63 for(int x = 0; x < NXCOLUMNSMOD; x++)
65 for(int z = 0; z < NZROWSMOD; z++)
67 fHighGainFactors[x][z] = 0.005;
68 fLowGainFactors[x][z] = 0.08;
69 fBadChannelMask[x][z][HIGHGAIN] = 1;
70 fBadChannelMask[x][z][LOWGAIN] = 1;
73 fMapperPtr = new AliHLTPHOSMapper();
76 AliHLTPHOSDigitMaker::~AliHLTPHOSDigitMaker()
78 //See header file for documentation
82 AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
84 //See header file for documentation
87 UInt_t totSize = sizeof(AliHLTPHOSDigitDataStruct);
97 AliHLTPHOSChannelDataStruct* currentchannel = 0;
98 AliHLTPHOSChannelDataStruct* currentchannelLG = 0;
99 AliHLTPHOSChannelDataStruct* tmpchannel = 0;
101 fShmPtr->SetMemory(channelDataHeader);
102 currentchannel = fShmPtr->NextChannel();
104 while(currentchannel != 0)
106 if(availableSize < totSize) return -1;
108 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord1);
110 if(fOrdered) // High gain comes before low gain
112 tmpchannel = currentchannel;
114 if(coord1[2] == HIGHGAIN) // We got a completely new crystal
116 if(currentchannel->fEnergy < MAXBINVALUE) // Make sure we don't have signal overflow
118 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
119 AddDigit(currentchannel, coord1, locCoord);
121 totSize += sizeof(AliHLTPHOSDigitDataStruct);
123 currentchannel = fShmPtr->NextChannel(); // Get the next channel
125 if(currentchannel != 0) // There was a next channel!
127 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
128 if(coord1[0] == coord2[0] && coord1[1] == coord2[1]) // Did we get the low gain channel for this crystal?
130 currentchannel = fShmPtr->NextChannel(); // In that case, jump to next channel
135 else // Ooops, overflow, we try the next channel...
137 currentchannel = fShmPtr->NextChannel();
138 if(currentchannel != 0) // There was a next channel
140 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
141 if(coord2[0] == coord1[0] && coord2[1] == coord1[1]) // It is a low gain channel with the same coordinates, we may use it
143 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
144 AddDigit(currentchannel, coord2, locCoord);
146 totSize += sizeof(AliHLTPHOSDigitDataStruct);
147 currentchannel = fShmPtr->NextChannel();
150 else // No low gain channel with information about the overflow channel so we just use the overflowed one...
152 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
153 AddDigit(tmpchannel, coord1, locCoord);
155 totSize += sizeof(AliHLTPHOSDigitDataStruct);
156 // no need to get the next channel here, we already did...
162 else // Well, there seem to be missing a high gain channel for this crystal, let's use the low gain one
164 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
165 AddDigit(tmpchannel, coord1, locCoord);
167 totSize += sizeof(AliHLTPHOSDigitDataStruct);
168 currentchannel = fShmPtr->NextChannel();
172 else //Reversed ordered (low gain before high gain)
174 if(coord1[2] == LOWGAIN) // We got a new channel!
176 currentchannelLG = currentchannel; // Ok, let's back up the low gain channel and look for the fancy high gain one
177 currentchannel = fShmPtr->NextChannel();
179 if(currentchannel != 0) //There was another channel in the event
181 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
183 if(coord1[0] == coord2[0] && coord1[1] == coord2[1]) // Aha! Found the high gain channel
185 if(currentchannel->fEnergy < MAXBINVALUE) // To overflow or not to overflow?
187 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
188 AddDigit(currentchannel, coord2, locCoord);
190 totSize += sizeof(AliHLTPHOSDigitDataStruct);
191 currentchannel = fShmPtr->NextChannel();
193 else // Oh well, better use the low gain channel then
195 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
196 AddDigit(currentchannelLG, coord1, locCoord);
198 totSize += sizeof(AliHLTPHOSDigitDataStruct);
199 currentchannel = fShmPtr->NextChannel();
202 else // No available high gain channel for this crystal, adding the low gain one
204 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
205 AddDigit(currentchannelLG, coord1, locCoord);
207 totSize += sizeof(AliHLTPHOSDigitDataStruct);
210 else //Fine, no more channels, better add this one...
212 AliHLTPHOSMapper::GetLocalCoord(currentchannelLG->fChannelID, locCoord);
213 AddDigit(currentchannelLG, coord1, locCoord);
215 totSize += sizeof(AliHLTPHOSDigitDataStruct);
218 else // Cool, no annoying low gain channel for this channel
220 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
221 AddDigit(currentchannel, coord1, locCoord);
223 currentchannel = fShmPtr->NextChannel();
233 AliHLTPHOSDigitMaker::SetGlobalHighGainFactor(Float_t factor)
235 //See header file for documentation
236 for(int x = 0; x < NXCOLUMNSMOD; x++)
238 for(int z = 0; z < NZROWSMOD; z++)
240 fHighGainFactors[x][z] = factor;
246 AliHLTPHOSDigitMaker::SetGlobalLowGainFactor(Float_t factor)
248 //See header file for documentation
249 for(int x = 0; x < NXCOLUMNSMOD; x++)
251 for(int z = 0; z < NZROWSMOD; z++)
253 fLowGainFactors[x][z] = factor;
259 AliHLTPHOSDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
261 for(int x = 0; x < NXCOLUMNSMOD; x++)
263 for(int z = 0; z < NZROWSMOD; z++)
265 if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
267 fBadChannelMask[x][z][HIGHGAIN] = 1;
271 fBadChannelMask[x][z][HIGHGAIN] = 0;
273 if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
275 fBadChannelMask[x][z][LOWGAIN] = 0;
279 fBadChannelMask[x][z][LOWGAIN] = 0;