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 AliHLTCALOClusterizer.cxx
\r
19 * @author Oystein Djuvsland
\r
21 * @brief Digit maker for CALO HLT
\r
27 // see header file for class documentation
\r
29 // refer to README to build package
\r
31 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
\r
33 #include "AliHLTCaloDigitMaker.h"
\r
35 #include "AliHLTCaloConstants.h"
\r
36 #include "AliHLTCaloMapper.h"
\r
38 #include "AliHLTCaloChannelDataStruct.h"
\r
39 #include "AliHLTCaloChannelDataHeaderStruct.h"
\r
40 #include "AliHLTCaloDigitDataStruct.h"
\r
41 #include "AliHLTCaloSharedMemoryInterfacev2.h" // added by PTH
\r
42 //#include "AliPHOSEMCAGeometry.h"
\r
44 #include "AliHLTCaloConstantsHandler.h"
\r
45 #include "AliHLTCaloConstants.h"
\r
47 ClassImp(AliHLTCaloDigitMaker);
\r
49 //using namespace CaloHLTConst;
\r
51 AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :
\r
52 AliHLTCaloConstantsHandler(det),
\r
58 fHighGainFactors(0),
\r
65 //Must set this in the child instance
\r
67 // See header file for documentation
\r
69 fShmPtr = new AliHLTCaloSharedMemoryInterfacev2();
\r
71 fHighGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
\r
72 fLowGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
\r
74 fBadChannelMask = new Float_t**[fCaloConstants->GetNXCOLUMNSMOD()];
\r
76 fChannelBook= new AliHLTCaloDigitDataStruct**[fCaloConstants->GetNXCOLUMNSMOD()];
\r
78 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
80 fHighGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
\r
81 fLowGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
\r
83 fBadChannelMask[x] = new Float_t*[fCaloConstants->GetNZROWSMOD()];
\r
85 fChannelBook[x] = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNZROWSMOD()];
\r
87 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
90 fHighGainFactors[x][z] = 0.005;
\r
91 fLowGainFactors[x][z] = 0.08;
\r
93 fBadChannelMask[x][z] = new Float_t[fCaloConstants->GetNGAINS()];
\r
94 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 1;
\r
95 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 1;
\r
97 fChannelBook[x][z] = 0;
\r
102 //Must be set in child instance
\r
103 //fMapperPtr = new AliHLTCaloMapper(det);
\r
106 AliHLTCaloDigitMaker::~AliHLTCaloDigitMaker()
\r
108 //See header file for documentation
\r
112 AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
\r
114 //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
122 UShort_t coord1[4];
\r
123 UShort_t coord2[4];
\r
124 Float_t locCoord[3];
\r
127 AliHLTCaloChannelDataStruct* currentchannel = 0;
\r
128 AliHLTCaloChannelDataStruct* currentchannelLG = 0;
\r
129 AliHLTCaloChannelDataStruct* tmpchannel = 0;
\r
131 fShmPtr->SetMemory(channelDataHeader);
\r
132 currentchannel = fShmPtr->NextChannel();
\r
134 while(currentchannel != 0)
\r
136 if(availableSize < totSize) return -1;
\r
138 fMapperPtr->GetChannelCoord(currentchannel->fChannelID, coord1);
\r
140 tmpchannel = currentchannel;
\r
142 if(coord1[2] == fCaloConstants->GetHIGHGAIN()) // We got a completely new crystal
\r
144 fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
\r
145 if(UseDigit(coord1, currentchannel))
\r
147 AddDigit(currentchannel, coord1, locCoord);
\r
149 totSize += sizeof(AliHLTCaloDigitDataStruct);
\r
151 currentchannel = fShmPtr->NextChannel(); // Get the next channel
\r
153 else if(coord1[2] == fCaloConstants->GetLOWGAIN())
\r
155 fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
\r
156 if(UseDigit(coord1, currentchannel))
\r
158 AddDigit(currentchannel, coord1, locCoord);
\r
160 totSize += sizeof(AliHLTCaloDigitDataStruct);
\r
162 currentchannel = fShmPtr->NextChannel(); // Get the next channel
\r
167 return fDigitCount;
\r
171 AliHLTCaloDigitMaker::SetGlobalHighGainFactor(Float_t factor)
\r
173 //See header file for documentation
\r
174 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
176 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
178 fHighGainFactors[x][z] = factor;
\r
184 AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)
\r
186 //See header file for documentation
\r
187 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
189 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
191 fLowGainFactors[x][z] = factor;
\r
197 AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
\r
199 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
201 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
203 if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
\r
205 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 1;
\r
209 fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 0;
\r
211 if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
\r
213 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 0;
\r
217 fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 0;
\r
224 AliHLTCaloDigitMaker::Reset()
\r
227 for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
\r
229 for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
\r
231 fChannelBook[x][z] = 0;
\r
238 void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, UShort_t* channelCoordinates, Float_t* localCoordinates)
\r
241 fChannelBook[channelCoordinates[0]][channelCoordinates[0]] = fDigitStructPtr;
\r
243 fDigitStructPtr->fX = channelCoordinates[0];
\r
244 fDigitStructPtr->fZ = channelCoordinates[1];
\r
246 fDigitStructPtr->fLocX = localCoordinates[0];
\r
247 fDigitStructPtr->fLocZ = localCoordinates[1];
\r
249 if(channelCoordinates[2] == fCaloConstants->GetHIGHGAIN() )
\r
251 fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[channelCoordinates[0]][channelCoordinates[1]];
\r
252 if(channelData->fEnergy >= 1023)
\r
254 fDigitStructPtr->fOverflow = true;
\r
256 // printf("HG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f \n", channelCoordinates[0], channelCoordinates[1], channelData->fEnergy, fDigitStructPtr->fEnergy);
\r
260 fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[channelCoordinates[0]][channelCoordinates[1]];
\r
261 if(channelData->fEnergy >= 1023)
\r
263 fDigitStructPtr->fOverflow = true;
\r
265 // printf("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", channelCoordinates[0], channelCoordinates[1], channelData->fEnergy, fDigitStructPtr->fEnergy);
\r
267 fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO
\r
268 fDigitStructPtr->fCrazyness = channelData->fCrazyness;
\r
269 fDigitStructPtr->fModule = channelCoordinates[3];
\r
273 bool AliHLTCaloDigitMaker::UseDigit(UShort_t *channelCoordinates, AliHLTCaloChannelDataStruct *channel)
\r
275 AliHLTCaloDigitDataStruct *tmpDigit = fChannelBook[channelCoordinates[0]][channelCoordinates[1]];
\r
278 if(channelCoordinates[2] == fCaloConstants->GetLOWGAIN())
\r
280 if(tmpDigit->fOverflow)
\r
288 if(channel->fEnergy >= fCaloConstants->GetMAXBINVALUE() )
\r