]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliCaloAltroMapping.cxx
Adding the correction for wrongly simulated pid TOF signal
[u/mrichter/AliRoot.git] / RAW / AliCaloAltroMapping.cxx
CommitLineData
d84933b0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15/* $Id$ */
16
17// This class handles the mapping of the Altro channels in the PHOS/EMCAL
18// The mapping is read from an external mapping files
19// Author: C.Cheshkov
20
21/// Exported from PHOS to be used also by EMCAL
22/// November 2006 Gustavo Conesa Balbastre
23
24#include "AliCaloAltroMapping.h"
25#include "AliLog.h"
26#include <Riostream.h>
27//#include <stdlib.h>
28
29
30ClassImp(AliCaloAltroMapping)
31
44174d11 32//_____________________________________________________________________________
33AliCaloAltroMapping::AliCaloAltroMapping():
34 AliAltroMapping(),
35 fMinRow(0),
36 fMaxRow(0),
37 fMinCol(0),
38 fMaxCol(0),
44174d11 39 fInvMappingLow(NULL),
40 fInvMappingHigh(NULL)
41{
42 // Default constructor
43}
44
d84933b0 45//_____________________________________________________________________________
46AliCaloAltroMapping::AliCaloAltroMapping(const char *mappingFile):
47 AliAltroMapping(mappingFile),
48 fMinRow(0),
49 fMaxRow(0),
50 fMinCol(0),
51 fMaxCol(0),
d84933b0 52 fInvMappingLow(NULL),
53 fInvMappingHigh(NULL)
54{
55 // Constructor
56 ReadMapping();
57 CloseMappingFile();
58}
59
60//_____________________________________________________________________________
61AliCaloAltroMapping::~AliCaloAltroMapping()
62{
63 // destructor
573322da 64 // Deletes the arrays which have been
65 // allocated during the reading of the
66 // mapping file
67 if (fInvMappingLow) delete [] fInvMappingLow;
68
69 if (fInvMappingHigh) delete [] fInvMappingHigh;
d84933b0 70}
71
d84933b0 72//_____________________________________________________________________________
73Bool_t AliCaloAltroMapping::ReadMapping()
74{
75 // Initalizes the ALTRO mapping from a file
76 // Look at the Calo module for the format of
77 // the mapping file
78 if (!fIn) {
79 AliFatal("Mapping file has not been opened !");
80 return kFALSE;
81 }
82
83 fMinRow = 0x7fffffff;
84 fMaxRow = 0;
85 fMinCol = 0x7fffffff;
86 fMaxCol = 0;
44174d11 87 fMappingSize = 3*(fMaxHWAddress+1);
88 fMapping = new Short_t[fMappingSize];
d84933b0 89 for (Int_t i = 0; i <= fMaxHWAddress; i++) {
44174d11 90 fMapping[3*i] = fMapping[3*i+1] = fMapping[3*i+2] = -1;
d84933b0 91 }
92
93 for(Int_t i = 0; i < fNumberOfChannels ; i++) { // 1792 = 2*896 channels connected to each RCU
94 Int_t hwAddress;
95 if (!(*fIn >> hwAddress)) {
96 AliFatal("Syntax of the mapping file is wrong !");
97 return kFALSE;
98 }
99 if (hwAddress > fMaxHWAddress) {
100 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
101 return kFALSE;
102 }
c64b0521 103 Int_t row,col,caloFlag;
104 if (!(*fIn >> row >> col >> caloFlag)) {
d84933b0 105 AliFatal("Syntax of the mapping file is wrong !");
106 return kFALSE;
107 }
108
c64b0521 109 if (caloFlag < 0 || caloFlag > 3) {
110 AliFatal(Form("Wrong CaloFlag value found (%d)! Should be 0 ,1, 2 or 3 !",caloFlag));
d84933b0 111 return kFALSE;
112 }
113
44174d11 114 fMapping[3*hwAddress] = row;
115 fMapping[3*hwAddress+1] = col;
c64b0521 116 fMapping[3*hwAddress+2] = caloFlag;
d84933b0 117
118 if (row > fMaxRow) fMaxRow = row;
119 if (row < fMinRow) fMinRow = row;
120 if (col > fMaxCol) fMaxCol = col;
121 if (col < fMinCol) fMinCol = col;
122
123 }
124
573322da 125 return kTRUE;
126}
127
128//_____________________________________________________________________________
129Bool_t AliCaloAltroMapping::CreateInvMapping()
130{
131 // Create the inverse mapping
132 // needed for the simulation of
133 // raw data
134 if (fInvMappingLow) return kTRUE;
135
136 if (!fMapping) {
137 AliWarning("Mapping array was not initalized correctly ! Impossible to create the inverse mapping !");
138 return kFALSE;
139 }
140
44174d11 141 Int_t nRows = fMaxRow - fMinRow + 1;
142 Int_t nCols = fMaxCol - fMinCol + 1;
573322da 143 Int_t invMappingSize = nRows*nCols;
44174d11 144
573322da 145 fInvMappingLow = new Short_t[invMappingSize];
146 fInvMappingHigh = new Short_t[invMappingSize];
44174d11 147 for (Int_t i = 0; i < nRows; i++) {
148 for (Int_t j = 0; j < nCols; j++) {
149 fInvMappingLow[nCols*i+j] = -1;
150 fInvMappingHigh[nCols*i+j] = -1;
d84933b0 151 }
152 }
d84933b0 153 for(Int_t i = 0; i <= fMaxHWAddress; i++) {
44174d11 154 Int_t row = fMapping[3*i];
155 Int_t col = fMapping[3*i+1];
c64b0521 156 Int_t caloFlag = fMapping[3*i+2];
d84933b0 157 if(row != -1 && col != -1) {
c64b0521 158 if (caloFlag == 0)
44174d11 159 fInvMappingLow[nCols*(row-fMinRow)+(col-fMinCol)] = i;
c64b0521 160 if (caloFlag == 1)
44174d11 161 fInvMappingHigh[nCols*(row-fMinRow)+(col-fMinCol)] = i;
d84933b0 162 }
163 }
164
165 return kTRUE;
166}
167
168//_____________________________________________________________________________
c64b0521 169Int_t AliCaloAltroMapping::GetHWAddress(Int_t row, Int_t col, Int_t caloFlag)
d84933b0 170{
171 // Get the content of the mapping array
172 // return -1 in case there is no hardware
c64b0521 173 // adress defined for these row-column-caloFlag
d84933b0 174 if (!fInvMappingLow || !fInvMappingHigh) {
573322da 175 if (!CreateInvMapping()) return -1;
d84933b0 176 }
177 if (row < fMinRow || row > fMaxRow) {
178 AliWarning(Form("Index of row (%d) outside the range (%d -> %d) !",row,fMinRow,fMaxRow));
179 return -1;
180 }
181 if (col < fMinCol || col > fMaxCol) {
6c12d59f 182 AliWarning(Form("Index of column (%d) outside the range (%d -> %d) !",col,fMinCol,fMaxCol));
d84933b0 183 return -1;
184 }
c64b0521 185 if (caloFlag < 0 || caloFlag > 3) {
186 AliWarning(Form("Invalid caloFlag (%d)! Should be 0, 1, 2 or 3 !",caloFlag));
d84933b0 187 return -1;
188 }
189 Int_t hwAddress = -1;
c64b0521 190 if (caloFlag == 0)
44174d11 191 hwAddress = fInvMappingLow[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
c64b0521 192 if (caloFlag == 1)
44174d11 193 hwAddress = fInvMappingHigh[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
d84933b0 194
195 if (hwAddress == -1)
c64b0521 196 AliWarning(Form("Hardware (ALTRO) adress is not defined for these row (%d), column (%d) and caloFlag (%d) !",row,col,caloFlag));
d84933b0 197
198 return hwAddress;
199}
200
201//_____________________________________________________________________________
202Int_t AliCaloAltroMapping::GetPadRow(Int_t hwAddress) const
203{
204 // Return the row index
205 // Note the difference w.r.t to the base class notation
206 if (!fMapping) {
207 AliWarning("Mapping array was not initalized correctly !");
208 return -1;
209 }
210 if (hwAddress > fMaxHWAddress) {
211 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
212 return -1;
213 }
44174d11 214 Int_t row = fMapping[3*hwAddress];
d84933b0 215 if (row == -1)
216 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
217
218 return row;
219}
220
221//_____________________________________________________________________________
222Int_t AliCaloAltroMapping::GetPad(Int_t hwAddress) const
223{
224 // Return the column index
225 // Note the difference w.r.t to the base class notation
226 if (!fMapping) {
227 AliWarning("Mapping array was not initalized correctly !");
228 return -1;
229 }
230 if (hwAddress > fMaxHWAddress) {
231 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
232 return -1;
233 }
44174d11 234 Int_t col = fMapping[3*hwAddress+1];
d84933b0 235 if (col == -1)
236 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
237
238 return col;
239}
240
241//_____________________________________________________________________________
242Int_t AliCaloAltroMapping::GetSector(Int_t hwAddress) const
243{
c64b0521 244 // Return the caloFlag factor (0/1)
d84933b0 245 // Note the difference w.r.t to the base class notation
246 if (!fMapping) {
247 AliWarning("Mapping array was not initalized correctly !");
248 return -1;
249 }
250 if (hwAddress > fMaxHWAddress) {
251 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
252 return -1;
253 }
c64b0521 254 Int_t caloFlag = fMapping[3*hwAddress+2];
255 if (caloFlag == -1)
d84933b0 256 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
257
c64b0521 258 return caloFlag;
d84933b0 259}