]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSDigitMaker.cxx
7abb28b93ee4bd44656b78a46b5cfead84268b73
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDigitMaker.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   AliHLTPHOSDigitMaker.cxx
19  * @author Oystein Djuvsland
20  * @date 
21  * @brief  Digit maker for PHOS HLT  
22  */
23   
24
25     
26
27 // see header file for class documentation
28 // or
29 // refer to README to build package
30 // or
31 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
32
33 #include "AliHLTPHOSDigitMaker.h"
34 #include "AliHLTLogging.h"
35
36 #include "AliHLTPHOSConstants.h"
37 #include "AliHLTPHOSMapper.h"
38
39 #include "AliHLTPHOSChannelDataStruct.h"
40 #include "AliHLTPHOSChannelDataHeaderStruct.h"
41 #include "AliHLTPHOSDigitDataStruct.h"
42 #include "AliHLTPHOSSharedMemoryInterfacev2.h" // added by PTH
43 #include "AliPHOSEMCAGeometry.h"
44 #include "TH2F.h"
45
46
47 ClassImp(AliHLTPHOSDigitMaker);
48
49 using namespace PhosHLTConst;
50
51 AliHLTPHOSDigitMaker::AliHLTPHOSDigitMaker() :
52   AliHLTLogging(),
53   fShmPtr(0),
54   fDigitStructPtr(0),
55   fDigitCount(0),
56   fOrdered(true),
57   fMapperPtr(0)
58 {
59   // See header file for documentation
60
61   fShmPtr = new AliHLTPHOSSharedMemoryInterfacev2();
62
63   for(int x = 0; x < NXCOLUMNSMOD; x++)
64     {
65       for(int z = 0; z < NZROWSMOD; z++)
66         {
67           fHighGainFactors[x][z] = 0.005;
68           fLowGainFactors[x][z] = 0.08;
69           fBadChannelMask[x][z][HIGHGAIN] = 1;
70           fBadChannelMask[x][z][LOWGAIN] = 1; 
71         }
72     }     
73   fMapperPtr = new AliHLTPHOSMapper();
74 }
75    
76 AliHLTPHOSDigitMaker::~AliHLTPHOSDigitMaker() 
77 {
78   //See header file for documentation
79 }
80
81 Int_t
82 AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
83 {
84   //See header file for documentation
85   
86   Int_t j = 0;
87   UInt_t totSize = sizeof(AliHLTPHOSDigitDataStruct);
88   
89 //   Int_t xMod = -1;
90 //   Int_t zMod = -1;
91   
92   UShort_t coord1[4];
93   UShort_t coord2[4];
94   Float_t locCoord[3];
95   
96   
97   AliHLTPHOSChannelDataStruct* currentchannel = 0;
98   AliHLTPHOSChannelDataStruct* currentchannelLG = 0;  
99   AliHLTPHOSChannelDataStruct* tmpchannel = 0;
100
101   fShmPtr->SetMemory(channelDataHeader);
102   currentchannel = fShmPtr->NextChannel();
103   
104   while(currentchannel != 0)
105     {
106       if(availableSize < totSize) return -1;
107
108       AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord1);
109       
110       if(fOrdered) // High gain comes before low gain
111         {
112           tmpchannel = currentchannel;
113           
114           if(coord1[2] == HIGHGAIN) // We got a completely new crystal
115             {
116               if(currentchannel->fEnergy < MAXBINVALUE) // Make sure we don't have signal overflow
117                 {
118                   AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
119                   AddDigit(currentchannel, coord1, locCoord);
120                   j++;        
121                   totSize += sizeof(AliHLTPHOSDigitDataStruct);
122
123                   currentchannel = fShmPtr->NextChannel(); // Get the next channel
124
125                   if(currentchannel != 0) // There was a next channel!
126                     {
127                       AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
128                       if(coord1[0] == coord2[0] && coord1[1] == coord2[1]) // Did we get the low gain channel for this crystal?
129                         {
130                           currentchannel = fShmPtr->NextChannel(); // In that case, jump to next channel
131                         }
132                     }
133                 }
134
135               else // Ooops, overflow, we try the next channel... 
136                 {
137                   currentchannel = fShmPtr->NextChannel();
138                   if(currentchannel != 0) // There was a next channel
139                     {
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
142                         {
143                           AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
144                           AddDigit(currentchannel, coord2, locCoord);
145                           j++;
146                           totSize += sizeof(AliHLTPHOSDigitDataStruct);
147                           currentchannel = fShmPtr->NextChannel();                    
148                         }
149                       
150                       else // No low gain channel with information about the overflow channel so we just use the overflowed one...
151                         {
152                           AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
153                           AddDigit(tmpchannel, coord1, locCoord);
154                           j++;        
155                           totSize += sizeof(AliHLTPHOSDigitDataStruct);
156                           // no need to get the next channel here, we already did...
157                         }
158                       
159                     }
160                 }
161             }
162           else // Well, there seem to be missing a high gain channel for this crystal, let's use the low gain one
163             {    
164               AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);  
165               AddDigit(tmpchannel, coord1, locCoord);
166               j++;            
167               totSize += sizeof(AliHLTPHOSDigitDataStruct);
168               currentchannel = fShmPtr->NextChannel(); 
169             }
170
171         }
172       else  //Reversed ordered (low gain before high gain)
173         {
174           if(coord1[2] == LOWGAIN) // We got a new channel!
175             {
176               currentchannelLG = currentchannel; // Ok, let's back up the low gain channel and look for the fancy high gain one
177               currentchannel = fShmPtr->NextChannel();
178
179               if(currentchannel != 0) //There was another channel in the event
180                 {
181                   AliHLTPHOSMapper::GetChannelCoord(currentchannel->fChannelID, coord2);
182                   
183                   if(coord1[0] == coord2[0] && coord1[1] == coord2[1]) // Aha! Found the high gain channel
184                     {
185                       if(currentchannel->fEnergy < MAXBINVALUE)  // To overflow or not to overflow?
186                         {
187                           AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
188                           AddDigit(currentchannel, coord2, locCoord);
189                           j++;
190                           totSize += sizeof(AliHLTPHOSDigitDataStruct);
191                           currentchannel = fShmPtr->NextChannel();
192                         }
193                       else // Oh well, better use the low gain channel then
194                         {
195                           AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
196                           AddDigit(currentchannelLG, coord1, locCoord);
197                           j++;
198                           totSize += sizeof(AliHLTPHOSDigitDataStruct);
199                           currentchannel = fShmPtr->NextChannel();
200                         }
201                     }
202                   else // No available high gain channel for this crystal, adding the low gain one
203                     {
204                       AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
205                       AddDigit(currentchannelLG, coord1, locCoord);
206                       j++;
207                       totSize += sizeof(AliHLTPHOSDigitDataStruct);
208                     }
209                 }
210               else //Fine, no more channels, better add this one...
211                 {
212                   AliHLTPHOSMapper::GetLocalCoord(currentchannelLG->fChannelID, locCoord);
213                   AddDigit(currentchannelLG, coord1, locCoord);
214                   j++;
215                   totSize += sizeof(AliHLTPHOSDigitDataStruct);
216                 }
217             } 
218           else // Cool, no annoying low gain channel for this channel
219             {
220               AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
221               AddDigit(currentchannel, coord1, locCoord);
222               j++;
223               currentchannel = fShmPtr->NextChannel();
224             }
225         }
226     }
227
228   fDigitCount += j;
229   return fDigitCount; 
230 }
231
232 void 
233 AliHLTPHOSDigitMaker::SetGlobalHighGainFactor(Float_t factor)
234 {
235   //See header file for documentation
236   for(int x = 0; x < NXCOLUMNSMOD; x++)
237     {
238       for(int z = 0; z < NZROWSMOD; z++)
239         {
240           fHighGainFactors[x][z] = factor;
241         }
242     }
243 }
244
245 void
246 AliHLTPHOSDigitMaker::SetGlobalLowGainFactor(Float_t factor)
247 {
248   //See header file for documentation
249   for(int x = 0; x < NXCOLUMNSMOD; x++)
250     {
251       for(int z = 0; z < NZROWSMOD; z++)
252         {
253           fLowGainFactors[x][z] = factor;
254         }
255     }
256 }
257
258 void
259 AliHLTPHOSDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
260 {
261  for(int x = 0; x < NXCOLUMNSMOD; x++)
262     {
263       for(int z = 0; z < NZROWSMOD; z++)
264         {
265           if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)
266             {
267               fBadChannelMask[x][z][HIGHGAIN] = 1;
268             }
269           else
270             {
271               fBadChannelMask[x][z][HIGHGAIN] = 0;
272             }
273           if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)
274             {
275               fBadChannelMask[x][z][LOWGAIN] = 0;
276             }
277           else
278             {
279               fBadChannelMask[x][z][LOWGAIN] = 0;
280             }
281         }
282     }
283 }
284