3 /**************************************************************************
\r
4 * This file is property of and copyright by the ALICE HLT Project *
\r
5 * All rights reserved. *
\r
7 * Primary Authors: Oystein Djuvsland *
\r
9 * Permission to use, copy, modify and distribute this software and its *
\r
10 * documentation strictly for non-commercial purposes is hereby granted *
\r
11 * without fee, provided that the above copyright notice appears in all *
\r
12 * copies and that both the copyright notice and this permission notice *
\r
13 * appear in the supporting documentation. The authors make no claims *
\r
14 * about the suitability of this software for any purpose. It is *
\r
15 * provided "as is" without express or implied warranty. *
\r
16 **************************************************************************/
\r
18 * @file AliHLTCaloDigitMaker.cxx
\r
19 * @author Oystein Djuvsland
\r
21 * @brief Digit maker for CALO HLT
\r
25 // see header file for class documentation
\r
27 // refer to README to build package
\r
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
\r
31 #include "AliHLTCaloDigitMaker.h"
\r
32 #include "AliHLTCaloConstantsHandler.h"
\r
33 #include "AliHLTCaloMapper.h"
\r
34 #include "AliHLTCaloChannelDataStruct.h"
\r
35 #include "AliHLTCaloChannelDataHeaderStruct.h"
\r
36 #include "AliHLTCaloDigitDataStruct.h"
\r
37 #include "AliHLTCaloCoordinate.h"
\r
38 #include "AliHLTCaloSharedMemoryInterfacev2.h" // added by PTH
\r
39 //#include "AliPHOSEMCAGeometry.h"
\r
41 #include "AliHLTCaloConstants.h"
\r
42 #include "AliHLTLogging.h"
\r
44 ClassImp(AliHLTCaloDigitMaker);
\r
46 //using namespace CaloHLTConst;
\r
48 AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :
\r
49 AliHLTCaloConstantsHandler(det),
\r
55 fHighGainFactors(0),
\r
63 // See header file for documentation
\r
65 fShmPtr = new AliHLTCaloSharedMemoryInterfacev2(det);
\r
67 fHighGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
\r
68 fLowGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
\r
70 fBadChannelMask = new Bool_t**[fCaloConstants->GetNXCOLUMNSMOD()];
\r
72 fChannelBook= new AliHLTCaloDigitDataStruct**[fCaloConstants->GetNXCOLUMNSMOD()];
\r
74 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
76 fHighGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
\r
77 fLowGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
\r
79 fBadChannelMask[x] = new Bool_t*[fCaloConstants->GetNZROWSMOD()];
\r
81 fChannelBook[x] = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNZROWSMOD()];
\r
83 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
86 fHighGainFactors[x][z] = 0.0153;
\r
87 fLowGainFactors[x][z] = 0.245;
\r
89 fBadChannelMask[x][z] = new Bool_t[fCaloConstants->GetNGAINS()];
\r
90 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;
\r
91 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
\r
93 fChannelBook[x][z] = 0;
\r
99 AliHLTCaloDigitMaker::~AliHLTCaloDigitMaker()
\r
101 //See header file for documentation
\r
102 delete [] fHighGainFactors;
\r
103 delete [] fLowGainFactors;
\r
104 delete [] fBadChannelMask;
\r
105 delete [] fChannelBook;
\r
111 AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
\r
113 //See header file for documentation
\r
117 UInt_t totSize = sizeof(AliHLTCaloDigitDataStruct);
\r
119 // Int_t xMod = -1;
\r
120 // Int_t zMod = -1;
\r
123 AliHLTCaloCoordinate coord;
\r
126 AliHLTCaloChannelDataStruct* currentchannel = 0;
\r
128 fShmPtr->SetMemory(channelDataHeader);
\r
129 currentchannel = fShmPtr->NextChannel();
\r
131 while(currentchannel != 0)
\r
133 if(availableSize < totSize) return -1;
\r
135 fMapperPtr->ChannelId2Coordinate(currentchannel->fChannelID, coord);
\r
137 // fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
\r
138 if(UseDigit(coord, currentchannel))
\r
140 AddDigit(currentchannel, coord);
\r
142 totSize += sizeof(AliHLTCaloDigitDataStruct);
\r
144 currentchannel = fShmPtr->NextChannel(); // Get the next channel
\r
146 // if(currentchannel)
\r
148 // fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
\r
149 // if(UseDigit(coord1, currentchannel))
\r
151 // AddDigit(currentchannel, coord1, locCoord);
\r
153 // totSize += sizeof(AliHLTCaloDigitDataStruct);
\r
155 // currentchannel = fShmPtr->NextChannel(); // Get the next channel
\r
159 // fDigitCount += j;
\r
160 return fDigitCount;
\r
164 AliHLTCaloDigitMaker::SetGlobalHighGainFactor(Float_t factor)
\r
166 //See header file for documentation
\r
167 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
169 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
171 fHighGainFactors[x][z] = factor;
\r
178 AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)
\r
180 //See header file for documentation
\r
181 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
183 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
185 fLowGainFactors[x][z] = factor;
\r
192 AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
\r
194 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
196 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
198 if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
\r
200 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = true;
\r
204 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;
\r
206 if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
\r
208 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
\r
212 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
\r
219 AliHLTCaloDigitMaker::Reset()
\r
222 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
224 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
226 fChannelBook[x][z] = 0;
\r
233 void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, AliHLTCaloCoordinate &coord)
\r
236 // Some book keeping of the pointers
\r
237 AliHLTCaloDigitDataStruct *tmpDigit = fDigitStructPtr + 1;
\r
239 // Check if we already have a digit in this position, and correct the book keeping correspondently
\r
240 if(fChannelBook[coord.fX][coord.fZ])
\r
242 tmpDigit = fDigitStructPtr;
\r
243 fDigitStructPtr = fChannelBook[coord.fX][coord.fZ];
\r
245 // printf("Going to overwrite digit: x = %d, z = %d, gain = %d, energy = %f\n", fDigitStructPtr->fX, fDigitStructPtr->fZ, fDigitStructPtr->fGain, fDigitStructPtr->fEnergy);
\r
248 fChannelBook[coord.fX][coord.fZ] = fDigitStructPtr;
\r
250 fDigitStructPtr->fX = coord.fX;
\r
251 fDigitStructPtr->fZ = coord.fZ;
\r
252 fDigitStructPtr->fGain = coord.fGain;
\r
253 fDigitStructPtr->fOverflow = false;
\r
254 fDigitStructPtr->fAssociatedCluster = -1;
\r
256 fDigitStructPtr->fID = fDigitStructPtr->fZ * fCaloConstants->GetNXCOLUMNSMOD() + fDigitStructPtr->fX;
\r
258 if(coord.fGain == fCaloConstants->GetHIGHGAIN() )
\r
260 fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[coord.fX][coord.fZ];
\r
261 fDigitStructPtr->fHgPresent = true;
\r
262 if(channelData->fEnergy >= fMaxEnergy)
\r
264 fDigitStructPtr->fOverflow = true;
\r
267 HLTDebug("HG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f \n",
\r
268 coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy);
\r
272 fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[coord.fX][coord.fZ];
\r
273 if(channelData->fEnergy >= fMaxEnergy)
\r
275 fDigitStructPtr->fOverflow = true;
\r
277 HLTDebug("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy);
\r
279 fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO
\r
280 fDigitStructPtr->fCrazyness = channelData->fCrazyness;
\r
281 fDigitStructPtr->fModule = coord.fModuleId;
\r
282 fDigitStructPtr = tmpDigit;
\r
283 // fDigitStructPtr++;
\r
287 bool AliHLTCaloDigitMaker::UseDigit(AliHLTCaloCoordinate &channelCoordinates, AliHLTCaloChannelDataStruct *channel)
\r
290 if(fBadChannelMask[channelCoordinates.fX][channelCoordinates.fZ][0] == true) return false;
\r
291 if(channel->fTime < fMinTime || channel->fTime > fMaxTime) return false;
\r
293 AliHLTCaloDigitDataStruct *tmpDigit = fChannelBook[channelCoordinates.fX][channelCoordinates.fZ];
\r
294 //printf("UseDigit: Got digit, x: %d, z: %d, gain: %d, amp: %f\n", channelCoordinates.fX, channelCoordinates.fZ, channelCoordinates.fGain, channel->fEnergy);
\r
297 if(channelCoordinates.fGain == fCaloConstants->GetLOWGAIN())
\r
299 //printf("UseDigit: Already have digit with, x: %d, z: %d, with high gain \n", channelCoordinates.fX, channelCoordinates.fZ);
\r
300 if(tmpDigit->fOverflow)
\r
302 // printf("But it was in overflow! Let's use this low gain!\n");
\r
309 //printf("UseDigit: Already have digit with, x: %d, z: %d, with low gain: %d\n", channelCoordinates.fX, channelCoordinates.fZ);
\r
310 if(channel->fEnergy > fMaxEnergy )
\r
312 tmpDigit->fHgPresent = true;
\r
321 void AliHLTCaloDigitMaker::SetBadChannel(Int_t x, Int_t z, Bool_t bad)
\r
323 // See header file for class documentation
\r
324 fBadChannelMask[x][z][0] = bad;
\r
325 fBadChannelMask[x][z][1] = bad;
\r
328 void AliHLTCaloDigitMaker::SetGain(Int_t x, Int_t z, Float_t ratio, Float_t gain)
\r
330 // See header file for class documentation
\r
331 HLTDebug("Applying gain: %f for channel x: %d, z: %d", gain, x, z);
\r
332 fHighGainFactors[x][z] = gain;
\r
333 fLowGainFactors[x][z] = gain * ratio;
\r