]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloDigitMaker.cxx
cleaning up HLT defines
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloDigitMaker.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * All rights reserved.                                                   *
6  *                                                                        *
7  * Primary Authors: Oystein Djuvsland                                     *
8  *                                                                        *
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  **************************************************************************/
17  /** 
18  * @file   AliHLTCaloDigitMaker.cxx
19  * @author Oystein Djuvsland
20  * @date 
21  * @brief  Digit maker for CALO HLT  
22  */
23       
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
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"
40 #include "TH2F.h"
41 #include "AliHLTCaloConstants.h"
42 #include "AliHLTLogging.h"
43
44 ClassImp(AliHLTCaloDigitMaker);
45
46 //using namespace CaloHLTConst;
47
48 AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :
49   AliHLTCaloConstantsHandler(det),
50   AliHLTLogging(),
51   fShmPtr(0),
52   fDigitStructPtr(0),
53   fDigitCount(0),
54   fMapperPtr(0),
55   fHighGainFactors(0),
56   fLowGainFactors(0),
57   fBadChannelMask(0),
58   fChannelBook(0),
59   fMaxEnergy(900),
60   fMinTime(0.0),
61   fMaxTime(1008.0)
62 {
63   // See header file for documentation
64
65   fShmPtr = new AliHLTCaloSharedMemoryInterfacev2(det);
66
67   fHighGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
68   fLowGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];
69   
70   fBadChannelMask = new Bool_t**[fCaloConstants->GetNXCOLUMNSMOD()];
71   
72   fChannelBook= new AliHLTCaloDigitDataStruct**[fCaloConstants->GetNXCOLUMNSMOD()];
73   
74   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
75     {
76       fHighGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
77       fLowGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];
78
79       fBadChannelMask[x] = new Bool_t*[fCaloConstants->GetNZROWSMOD()];
80
81       fChannelBook[x] = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNZROWSMOD()];
82
83       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
84         {
85
86           fHighGainFactors[x][z] = 0.0153;
87           fLowGainFactors[x][z] = 0.245;
88          
89           fBadChannelMask[x][z] = new Bool_t[fCaloConstants->GetNGAINS()];
90           fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;
91           fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false; 
92           
93           fChannelBook[x][z] = 0;
94           
95         }
96     }     
97 }
98
99 AliHLTCaloDigitMaker::~AliHLTCaloDigitMaker() 
100 {
101   //See header file for documentation
102   delete [] fHighGainFactors;
103   delete [] fLowGainFactors;
104   delete [] fBadChannelMask;  
105   delete [] fChannelBook;
106   delete fShmPtr;
107
108 }
109
110 Int_t
111 AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
112 {
113   //See header file for documentation
114   
115   Reset();
116
117   UInt_t totSize = sizeof(AliHLTCaloDigitDataStruct);
118   
119 //   Int_t xMod = -1;
120 //   Int_t zMod = -1;
121   
122
123   AliHLTCaloCoordinate coord;
124   
125   
126   AliHLTCaloChannelDataStruct* currentchannel = 0;
127   
128   fShmPtr->SetMemory(channelDataHeader);
129   currentchannel = fShmPtr->NextChannel();
130
131   while(currentchannel != 0)
132     {
133       if(availableSize < totSize) return -1;
134
135       fMapperPtr->ChannelId2Coordinate(currentchannel->fChannelID, coord);
136       
137       //      fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
138       if(UseDigit(coord, currentchannel))
139       {
140         AddDigit(currentchannel, coord);
141         //      j++;          
142         totSize += sizeof(AliHLTCaloDigitDataStruct);
143       }
144       currentchannel = fShmPtr->NextChannel(); // Get the next channel
145     }
146 //       if(currentchannel)
147 //      {
148 //        fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);
149 //        if(UseDigit(coord1, currentchannel))
150 //          {
151 //            AddDigit(currentchannel, coord1, locCoord);
152 //            j++;            
153 //            totSize += sizeof(AliHLTCaloDigitDataStruct);
154 //          }
155 //        currentchannel = fShmPtr->NextChannel(); // Get the next channel
156 //      }
157 //     }
158    
159 //   fDigitCount += j;
160    return fDigitCount; 
161 }
162
163 void 
164 AliHLTCaloDigitMaker::SetGlobalHighGainFactor(Float_t factor)
165 {
166   //See header file for documentation
167   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
168     {
169       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
170         {
171           fHighGainFactors[x][z] = factor;
172         }
173     }
174 }
175
176
177 void
178 AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)
179 {
180   //See header file for documentation
181   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
182     {
183       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
184         {
185           fLowGainFactors[x][z] = factor;
186         }
187     }
188 }
189
190
191 void
192 AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
193 {
194  for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
195     {
196       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
197         {
198           if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
199             {
200               fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = true;
201             }
202           else
203             {
204               fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;
205             }
206           if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
207             {
208               fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
209             }
210           else
211             {
212               fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;
213             }
214         }
215     }
216 }
217
218 void
219 AliHLTCaloDigitMaker::Reset()
220 {
221   fDigitCount = 0;
222   for(int x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
223     {
224       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
225         {
226           fChannelBook[x][z] = 0;
227         }
228     }     
229
230 }
231
232
233 void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, AliHLTCaloCoordinate &coord)
234 {
235
236   // Some book keeping of the pointers
237   AliHLTCaloDigitDataStruct *tmpDigit = fDigitStructPtr + 1;
238
239   // Check if we already have a digit in this position, and correct the book keeping correspondently
240   if(fChannelBook[coord.fX][coord.fZ]) 
241     {
242       tmpDigit = fDigitStructPtr;
243       fDigitStructPtr = fChannelBook[coord.fX][coord.fZ];
244       fDigitCount--;
245       //      printf("Going to overwrite digit: x = %d, z = %d, gain = %d, energy = %f\n", fDigitStructPtr->fX, fDigitStructPtr->fZ, fDigitStructPtr->fGain, fDigitStructPtr->fEnergy);
246     }
247   
248   fChannelBook[coord.fX][coord.fZ] = fDigitStructPtr;
249  
250   fDigitStructPtr->fX = coord.fX;
251   fDigitStructPtr->fZ = coord.fZ;
252   fDigitStructPtr->fGain = coord.fGain;
253   fDigitStructPtr->fOverflow = false;
254   fDigitStructPtr->fAssociatedCluster = -1;
255   
256   fDigitStructPtr->fID = fDigitStructPtr->fZ * fCaloConstants->GetNXCOLUMNSMOD() + fDigitStructPtr->fX;
257   
258   if(coord.fGain == fCaloConstants->GetHIGHGAIN() )
259     {
260       fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[coord.fX][coord.fZ];
261       fDigitStructPtr->fHgPresent = true;
262       if(channelData->fEnergy >= fMaxEnergy)
263         {
264           fDigitStructPtr->fOverflow = true;
265         }
266       
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);
269     }
270   else
271     {
272       fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[coord.fX][coord.fZ];
273       if(channelData->fEnergy >= fMaxEnergy)
274         {
275           fDigitStructPtr->fOverflow = true;
276         }
277       HLTDebug("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy); 
278     }
279   fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO
280   fDigitStructPtr->fCrazyness = channelData->fCrazyness;
281   fDigitStructPtr->fModule = coord.fModuleId;
282   fDigitStructPtr = tmpDigit;
283   //  fDigitStructPtr++;
284   fDigitCount++;
285 }
286
287 bool AliHLTCaloDigitMaker::UseDigit(AliHLTCaloCoordinate &channelCoordinates, AliHLTCaloChannelDataStruct *channel) 
288 {
289    
290    if(fBadChannelMask[channelCoordinates.fX][channelCoordinates.fZ][0] == true) return false;
291    if(channel->fTime < fMinTime || channel->fTime > fMaxTime) return false;
292    
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);
295   if(tmpDigit)
296     {
297       if(channelCoordinates.fGain == fCaloConstants->GetLOWGAIN())
298         {
299                   //printf("UseDigit: Already have digit with, x: %d, z: %d, with high gain \n", channelCoordinates.fX, channelCoordinates.fZ);
300           if(tmpDigit->fOverflow)
301             {
302                      // printf("But it was in overflow! Let's use this low gain!\n");
303               return true;
304             }
305           return false;
306         }
307       else
308         {
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 )
311             {
312               tmpDigit->fHgPresent = true;
313               return false;
314             }
315           return true;
316         }
317     }
318   return true;
319 }
320
321 void AliHLTCaloDigitMaker::SetBadChannel(Int_t x, Int_t z, Bool_t bad)
322 {
323    // See header file for class documentation
324    fBadChannelMask[x][z][0] = bad;
325    fBadChannelMask[x][z][1] = bad;
326 }
327
328 void AliHLTCaloDigitMaker::SetGain(Int_t x, Int_t z, Float_t ratio, Float_t gain)
329 {
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;
334    
335 }