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 AliHLTCaloDigitMaker.cxx
19 * @author Oystein Djuvsland
21 * @brief Digit maker for CALO HLT
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
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"
41 #include "AliHLTCaloConstants.h"
42 #include "AliHLTLogging.h"
44 ClassImp(AliHLTCaloDigitMaker);
46 //using namespace CaloHLTConst;
48 AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :
49 AliHLTCaloConstantsHandler(det),
63 // See header file for documentation
65 fShmPtr = new AliHLTCaloSharedMemoryInterfacev2(det);
67 fHighGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
68 fLowGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
70 fBadChannelMask = new Bool_t**[fCaloConstants->GetNXCOLUMNSMOD()];
72 fChannelBook= new AliHLTCaloDigitDataStruct**[fCaloConstants->GetNXCOLUMNSMOD()];
74 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
76 fHighGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
77 fLowGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
79 fBadChannelMask[x] = new Bool_t*[fCaloConstants->GetNZROWSMOD()];
81 fChannelBook[x] = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNZROWSMOD()];
83 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
86 fHighGainFactors[x][z] = 0.0153;
87 fLowGainFactors[x][z] = 0.245;
89 fBadChannelMask[x][z] = new Bool_t[fCaloConstants->GetNGAINS()];
90 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;
91 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
93 fChannelBook[x][z] = 0;
99 AliHLTCaloDigitMaker::~AliHLTCaloDigitMaker()
101 //See header file for documentation
102 delete [] fHighGainFactors;
103 delete [] fLowGainFactors;
104 delete [] fBadChannelMask;
105 delete [] fChannelBook;
111 AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
113 //See header file for documentation
117 UInt_t totSize = sizeof(AliHLTCaloDigitDataStruct);
123 AliHLTCaloCoordinate coord;
126 AliHLTCaloChannelDataStruct* currentchannel = 0;
128 fShmPtr->SetMemory(channelDataHeader);
129 currentchannel = fShmPtr->NextChannel();
131 while(currentchannel != 0)
133 if(availableSize < totSize) return -1;
135 fMapperPtr->ChannelId2Coordinate(currentchannel->fChannelID, coord);
137 // fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
138 if(UseDigit(coord, currentchannel))
140 AddDigit(currentchannel, coord);
142 totSize += sizeof(AliHLTCaloDigitDataStruct);
144 currentchannel = fShmPtr->NextChannel(); // Get the next channel
146 // if(currentchannel)
148 // fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
149 // if(UseDigit(coord1, currentchannel))
151 // AddDigit(currentchannel, coord1, locCoord);
153 // totSize += sizeof(AliHLTCaloDigitDataStruct);
155 // currentchannel = fShmPtr->NextChannel(); // Get the next channel
164 AliHLTCaloDigitMaker::SetGlobalHighGainFactor(Float_t factor)
166 //See header file for documentation
167 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
169 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
171 fHighGainFactors[x][z] = factor;
178 AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)
180 //See header file for documentation
181 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
183 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
185 fLowGainFactors[x][z] = factor;
192 AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
194 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
196 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
198 if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
200 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = true;
204 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;
206 if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
208 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
212 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
219 AliHLTCaloDigitMaker::Reset()
222 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
224 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
226 fChannelBook[x][z] = 0;
233 void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, AliHLTCaloCoordinate &coord)
236 // Some book keeping of the pointers
237 AliHLTCaloDigitDataStruct *tmpDigit = fDigitStructPtr + 1;
239 // Check if we already have a digit in this position, and correct the book keeping correspondently
240 if(fChannelBook[coord.fX][coord.fZ])
242 tmpDigit = fDigitStructPtr;
243 fDigitStructPtr = fChannelBook[coord.fX][coord.fZ];
245 // printf("Going to overwrite digit: x = %d, z = %d, gain = %d, energy = %f\n", fDigitStructPtr->fX, fDigitStructPtr->fZ, fDigitStructPtr->fGain, fDigitStructPtr->fEnergy);
248 fChannelBook[coord.fX][coord.fZ] = fDigitStructPtr;
250 fDigitStructPtr->fX = coord.fX;
251 fDigitStructPtr->fZ = coord.fZ;
252 fDigitStructPtr->fGain = coord.fGain;
253 fDigitStructPtr->fOverflow = false;
254 fDigitStructPtr->fAssociatedCluster = -1;
256 fDigitStructPtr->fID = fDigitStructPtr->fZ * fCaloConstants->GetNXCOLUMNSMOD() + fDigitStructPtr->fX;
258 if(coord.fGain == fCaloConstants->GetHIGHGAIN() )
260 fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[coord.fX][coord.fZ];
261 fDigitStructPtr->fHgPresent = true;
262 if(channelData->fEnergy >= fMaxEnergy)
264 fDigitStructPtr->fOverflow = true;
267 HLTDebug("HG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f \n",
268 coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy);
272 fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[coord.fX][coord.fZ];
273 if(channelData->fEnergy >= fMaxEnergy)
275 fDigitStructPtr->fOverflow = true;
277 HLTDebug("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy);
279 fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO
280 fDigitStructPtr->fCrazyness = channelData->fCrazyness;
281 fDigitStructPtr->fModule = coord.fModuleId;
282 fDigitStructPtr = tmpDigit;
283 // fDigitStructPtr++;
287 bool AliHLTCaloDigitMaker::UseDigit(AliHLTCaloCoordinate &channelCoordinates, AliHLTCaloChannelDataStruct *channel)
290 if(fBadChannelMask[channelCoordinates.fX][channelCoordinates.fZ][0] == true) return false;
291 if(channel->fTime < fMinTime || channel->fTime > fMaxTime) return false;
293 AliHLTCaloDigitDataStruct *tmpDigit = fChannelBook[channelCoordinates.fX][channelCoordinates.fZ];
294 //printf("UseDigit: Got digit, x: %d, z: %d, gain: %d, amp: %f\n", channelCoordinates.fX, channelCoordinates.fZ, channelCoordinates.fGain, channel->fEnergy);
297 if(channelCoordinates.fGain == fCaloConstants->GetLOWGAIN())
299 //printf("UseDigit: Already have digit with, x: %d, z: %d, with high gain \n", channelCoordinates.fX, channelCoordinates.fZ);
300 if(tmpDigit->fOverflow)
302 // printf("But it was in overflow! Let's use this low gain!\n");
309 //printf("UseDigit: Already have digit with, x: %d, z: %d, with low gain: %d\n", channelCoordinates.fX, channelCoordinates.fZ);
310 if(channel->fEnergy > fMaxEnergy )
312 tmpDigit->fHgPresent = true;
321 void AliHLTCaloDigitMaker::SetBadChannel(Int_t x, Int_t z, Bool_t bad)
323 // See header file for class documentation
324 fBadChannelMask[x][z][0] = bad;
325 fBadChannelMask[x][z][1] = bad;
328 void AliHLTCaloDigitMaker::SetGain(Int_t x, Int_t z, Float_t ratio, Float_t gain)
330 // See header file for class documentation
331 HLTDebug("Applying gain: %f for channel x: %d, z: %d", gain, x, z);
332 fHighGainFactors[x][z] = gain;
333 fLowGainFactors[x][z] = gain * ratio;