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"
35 #include "AliHLTPHOSConstants.h"
36 #include "AliHLTPHOSMapper.h"
38 #include "AliHLTPHOSChannelDataStruct.h"
39 #include "AliHLTPHOSChannelDataHeaderStruct.h"
40 #include "AliHLTPHOSDigitDataStruct.h"
41 #include "AliHLTPHOSSharedMemoryInterfacev2.h" // added by PTH
42 #include "AliPHOSEMCAGeometry.h"
45 ClassImp(AliHLTPHOSDigitMaker);
47 using namespace PhosHLTConst;
49 AliHLTPHOSDigitMaker::AliHLTPHOSDigitMaker() :
57 // See header file for documentation
59 fShmPtr = new AliHLTPHOSSharedMemoryInterfacev2();
61 for(int x = 0; x < NXCOLUMNSMOD; x++)
63 for(int z = 0; z < NZROWSMOD; z++)
65 fHighGainFactors[x][z] = 0.005;
66 fLowGainFactors[x][z] = 0.08;
67 fBadChannelMask[x][z][HIGHGAIN] = 1;
68 fBadChannelMask[x][z][LOWGAIN] = 1;
71 fMapperPtr = new AliHLTPHOSMapper();
74 AliHLTPHOSDigitMaker::~AliHLTPHOSDigitMaker()
76 //See header file for documentation
80 AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
82 //See header file for documentation
85 UInt_t totSize = sizeof(AliHLTPHOSDigitDataStruct);
95 AliHLTPHOSChannelDataStruct* currentchannel = 0;
96 AliHLTPHOSChannelDataStruct* currentchannelLG = 0;
97 AliHLTPHOSChannelDataStruct* tmpchannel = 0;
99 fShmPtr->SetMemory(channelDataHeader);
100 currentchannel = fShmPtr->NextChannel();
102 while(currentchannel != 0)
104 if(availableSize < totSize) return -1;
106 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord1);
108 if(fOrdered) // High gain comes before low gain
110 tmpchannel = currentchannel;
112 if(coord1[2] == HIGHGAIN) // We got a completely new crystal
115 if(currentchannel->fEnergy < MAXBINVALUE) // Make sure we don't have signal overflow
117 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
118 AddDigit(currentchannel, coord1, locCoord);
120 totSize += sizeof(AliHLTPHOSDigitDataStruct);
122 currentchannel = fShmPtr->NextChannel(); // Get the next channel
124 if(currentchannel != 0) // There was a next channel!
126 AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
127 if(coord1[0] == coord2[0] && coord1[1] == coord2[1]) // Did we get the low gain channel for this crystal?
129 currentchannel = fShmPtr->NextChannel(); // In that case, jump to next channel
134 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 // cout << "Reverse: Overflow!" << endl;
196 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
197 AddDigit(currentchannelLG, coord1, locCoord);
199 totSize += sizeof(AliHLTPHOSDigitDataStruct);
200 currentchannel = fShmPtr->NextChannel();
203 else // No available high gain channel for this crystal, adding the low gain one
205 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
206 AddDigit(currentchannelLG, coord1, locCoord);
208 totSize += sizeof(AliHLTPHOSDigitDataStruct);
211 else //Fine, no more channels, better add this one...
213 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
214 AddDigit(currentchannelLG, coord1, locCoord);
216 totSize += sizeof(AliHLTPHOSDigitDataStruct);
219 else // Cool, no annoying low gain channel for this channel
221 AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
222 AddDigit(currentchannel, coord1, locCoord);
224 currentchannel = fShmPtr->NextChannel();
234 AliHLTPHOSDigitMaker::SetGlobalHighGainFactor(Float_t factor)
236 //See header file for documentation
237 for(int x = 0; x < NXCOLUMNSMOD; x++)
239 for(int z = 0; z < NZROWSMOD; z++)
241 fHighGainFactors[x][z] = factor;
247 AliHLTPHOSDigitMaker::SetGlobalLowGainFactor(Float_t factor)
249 //See header file for documentation
250 for(int x = 0; x < NXCOLUMNSMOD; x++)
252 for(int z = 0; z < NZROWSMOD; z++)
254 fLowGainFactors[x][z] = factor;
260 AliHLTPHOSDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
262 for(int x = 0; x < NXCOLUMNSMOD; x++)
264 for(int z = 0; z < NZROWSMOD; z++)
266 if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
268 fBadChannelMask[x][z][HIGHGAIN] = 1;
272 fBadChannelMask[x][z][HIGHGAIN] = 0;
274 if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
276 fBadChannelMask[x][z][LOWGAIN] = 0;
280 fBadChannelMask[x][z][LOWGAIN] = 0;