]>
Commit | Line | Data |
---|---|---|
a8827307 | 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 | ||
16 | /* $Id: $ */ | |
17 | ||
18 | // Objects of this class read txt file with APD number data | |
19 | // | |
20 | ||
21 | #include <fstream> | |
22 | #include <TString.h> | |
23 | ||
24 | #include "AliEMCALMapAPD.h" | |
25 | ||
26 | const int kFirstAPD = 10213; // dummy number, only used for testing | |
27 | ||
28 | ClassImp(AliEMCALMapAPD) | |
29 | ||
30 | //____________________________________________________________________________ | |
31 | AliEMCALMapAPD::AliEMCALMapAPD() : | |
32 | fNSuperModule(0), | |
33 | fSuperModuleData(0) | |
34 | { | |
35 | //Default constructor. | |
36 | } | |
37 | ||
38 | //____________________________________________________________________________ | |
39 | void AliEMCALMapAPD::ReadMapAPDInfoStripBasis(Int_t nSM, const TString &txtFileName) | |
40 | { | |
41 | //Read data from txt file; coordinates given on StripModule basis | |
42 | ||
43 | std::ifstream inputFile(txtFileName.Data()); | |
44 | if (!inputFile) { | |
45 | printf("AliEMCALMapAPD::ReadMapAPDInfoStripBasis - Cannot open the APD info file %s\n",txtFileName.Data()); | |
46 | return; | |
47 | } | |
48 | ||
49 | fNSuperModule = nSM; | |
50 | if (fSuperModuleData) delete [] fSuperModuleData; | |
51 | fSuperModuleData = new AliEMCALSuperModuleMapAPD[fNSuperModule]; | |
52 | ||
53 | Int_t iSM = 0; // SuperModule index | |
54 | Int_t iAPD = 0; | |
55 | // info in map is based on Strip Info | |
56 | Int_t iStrip = 0; | |
57 | Int_t iStripCol = 0; | |
58 | Int_t iStripRow = 0; | |
59 | ||
60 | // we'll convert this into SuperModule Info | |
61 | Int_t iCol = 0; | |
62 | Int_t iRow = 0; | |
63 | ||
64 | Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows; | |
65 | ||
66 | for (Int_t i = 0; i < fNSuperModule; i++) { | |
67 | AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i]; | |
68 | if (!inputFile) { | |
cdb5074a | 69 | printf("AliEMCALMapAPD::ReadMapAPDInfoStripBasis - Error while reading input file; likely EOF..\n"); |
a8827307 | 70 | return; |
71 | } | |
72 | inputFile >> iSM; | |
73 | t.fSuperModuleNum = iSM; | |
74 | ||
75 | for (Int_t j=0; j<nAPDPerSM; j++) { | |
76 | inputFile >> iStrip >> iStripCol >> iStripRow >> iAPD; | |
77 | // iStrip is a number in the range 0..23 (number of StripModules per SuperModule) | |
78 | // iStripCol is a number in the range 0..1 (number of tower columns per StripModule) | |
79 | // iStripRow is a number in the range 0..23 (number of tower rows per StripModule) | |
80 | iCol = iStrip*2 + iStripCol; | |
81 | iRow = iStripRow; | |
82 | ||
83 | if (iSM%2 == 1) { // C side, oriented differently than A side: swap.. | |
84 | iCol = fgkEmCalCols-1 - iCol; | |
85 | iRow = fgkEmCalRows-1 - iRow; | |
86 | } | |
87 | ||
88 | t.fAPDNum[iCol][iRow] = iAPD; | |
89 | } | |
90 | ||
91 | } // i, SuperModule | |
92 | ||
93 | inputFile.close(); | |
94 | ||
95 | return; | |
96 | } | |
97 | ||
98 | ||
99 | //____________________________________________________________________________ | |
100 | void AliEMCALMapAPD::ReadMapAPDInfoSingleStripBasis(Int_t iSM, Int_t iStrip, const TString &txtFileName) | |
101 | // iSM is the SuperModule number | |
102 | // iStrip is a number in the range 0..23 (number of StripModules per SuperModule) | |
103 | { | |
104 | //Read data from txt file; coordinates given on StripModule basis | |
105 | ||
106 | std::ifstream inputFile(txtFileName.Data()); | |
107 | if (!inputFile) { | |
108 | printf("AliEMCALMapAPD::ReadMapAPDInfoSingleStripBasis - Cannot open the APD info file %s\n",txtFileName.Data()); | |
109 | return; | |
110 | } | |
111 | ||
112 | // see if there is an existing SuperModule with the right index | |
113 | Int_t foundSM = -1; | |
114 | for (Int_t i = 0; i < fNSuperModule; i++) { | |
115 | AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i]; | |
116 | if (t.fSuperModuleNum == iSM) foundSM = i; | |
117 | } | |
118 | ||
119 | if (foundSM == -1) { | |
120 | printf("AliEMCALMapAPD::ReadMapAPDInfoSingleStripBasis - no SuperModule %d found!\n", iSM); | |
121 | return; | |
122 | } | |
123 | ||
124 | AliEMCALSuperModuleMapAPD &t = fSuperModuleData[foundSM]; | |
125 | ||
126 | Int_t iAPD = 0; | |
127 | // info in map is based on Strip Info | |
128 | Int_t iStripCol = 0; | |
129 | Int_t iStripRow = 0; | |
130 | ||
131 | // we'll convert this into SuperModule Info | |
132 | Int_t iCol = 0; | |
133 | Int_t iRow = 0; | |
134 | ||
135 | Int_t nAPDPerStrip = 2 * fgkEmCalRows; // 2 columns in a strip | |
136 | ||
137 | for (Int_t j=0; j<nAPDPerStrip; j++) { | |
138 | if (!inputFile) { | |
cdb5074a | 139 | printf("AliEMCALMapAPD::ReadMapAPDInfoSingleStripBasis - Error while reading input file; likely EOF..\n"); |
a8827307 | 140 | return; |
141 | } | |
142 | inputFile >> iStripCol >> iStripRow >> iAPD; | |
143 | // iStripCol is a number in the range 0..1 (number of tower columns per StripModule) | |
144 | // iStripRow is a number in the range 0..23 (number of tower rows per StripModule) | |
145 | iCol = iStrip*2 + iStripCol; | |
146 | iRow = iStripRow; | |
147 | ||
148 | /* | |
149 | // For the SuperModule calibration we will typically use SuperModule 0 | |
150 | // for all - so don't worry about any swaps for now.. | |
151 | // I.e. we'll work in a local column and row coord. system, not necessarily ALICE | |
152 | // May revisit later.. | |
153 | if (iSM%2 == 1) { // C side, oriented differently than A side: swap.. | |
154 | iCol = fgkEmCalCols-1 - iCol; | |
155 | iRow = fgkEmCalRows-1 - iRow; | |
156 | } | |
157 | */ | |
158 | ||
159 | t.fAPDNum[iCol][iRow] = iAPD; | |
160 | } | |
161 | ||
162 | inputFile.close(); | |
163 | ||
164 | return; | |
165 | } | |
166 | ||
167 | ||
168 | //____________________________________________________________________________ | |
169 | void AliEMCALMapAPD::ReadMapAPDInfo(Int_t nSM, const TString &txtFileName) | |
170 | { | |
171 | //Read data from txt file. ; coordinates given on SuperModule basis | |
172 | ||
173 | std::ifstream inputFile(txtFileName.Data()); | |
174 | if (!inputFile) { | |
175 | printf("AliEMCALMapAPD::ReadMapAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data()); | |
176 | return; | |
177 | } | |
178 | ||
179 | fNSuperModule = nSM; | |
180 | if (fSuperModuleData) delete [] fSuperModuleData; | |
181 | fSuperModuleData = new AliEMCALSuperModuleMapAPD[fNSuperModule]; | |
182 | ||
183 | Int_t iSM = 0; // SuperModule index | |
184 | Int_t iAPD = 0; | |
185 | Int_t iCol = 0; | |
186 | Int_t iRow = 0; | |
187 | ||
188 | Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows; | |
189 | ||
190 | for (Int_t i = 0; i < fNSuperModule; i++) { | |
191 | AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i]; | |
192 | if (!inputFile) { | |
cdb5074a | 193 | printf("AliEMCALMapAPD::ReadMapAPDInfo - Error while reading input file; likely EOF.."); |
a8827307 | 194 | return; |
195 | } | |
196 | inputFile >> iSM; | |
197 | t.fSuperModuleNum = iSM; | |
198 | ||
199 | for (Int_t j=0; j<nAPDPerSM; j++) { | |
200 | inputFile >> iCol >> iRow >> iAPD; | |
201 | ||
202 | // assume that this info is already swapped and done for this basis? | |
203 | /* | |
204 | if (iSM%2 == 1) { // C side, oriented differently than A side: swap.. | |
205 | iCol = fgkEmCalCols-1 - iCol; | |
206 | iRow = fgkEmCalRows-1 - iRow; | |
207 | } | |
208 | */ | |
209 | ||
210 | t.fAPDNum[iCol][iRow] = iAPD; | |
211 | } | |
212 | ||
213 | } // i, SuperModule | |
214 | ||
215 | inputFile.close(); | |
216 | ||
217 | return; | |
218 | } | |
219 | ||
220 | //____________________________________________________________________________ | |
221 | void AliEMCALMapAPD::WriteMapAPDInfo(const TString &txtFileName) | |
222 | { | |
223 | // write data to txt file. ; coordinates given on SuperModule basis | |
224 | ||
225 | std::ofstream outputFile(txtFileName.Data()); | |
226 | if (!outputFile) { | |
227 | printf("AliEMCALMapAPD::WriteMapAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data()); | |
228 | return; | |
229 | } | |
230 | ||
231 | Int_t iCol = 0; | |
232 | Int_t iRow = 0; | |
233 | ||
234 | Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows; | |
235 | ||
236 | for (Int_t i = 0; i < fNSuperModule; i++) { | |
237 | AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i]; | |
238 | outputFile << t.fSuperModuleNum << endl; | |
239 | ||
240 | for (Int_t j=0; j<nAPDPerSM; j++) { | |
241 | iCol = j / fgkEmCalRows; | |
242 | iRow = j % fgkEmCalRows; | |
243 | outputFile << iCol << " " << iRow << " " | |
244 | << t.fAPDNum[iCol][iRow] << endl; | |
245 | } | |
246 | ||
247 | } // i, SuperModule | |
248 | ||
249 | outputFile.close(); | |
250 | ||
251 | return; | |
252 | } | |
253 | ||
254 | //____________________________________________________________________________ | |
255 | AliEMCALMapAPD::~AliEMCALMapAPD() | |
256 | { | |
257 | delete [] fSuperModuleData; | |
258 | } | |
259 | ||
260 | //____________________________________________________________________________ | |
261 | AliEMCALMapAPD::AliEMCALSuperModuleMapAPD AliEMCALMapAPD::GetSuperModuleMapAPDId(Int_t supModIndex)const | |
262 | { | |
263 | AliEMCALSuperModuleMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. | |
264 | if (!fSuperModuleData) | |
265 | return t; | |
266 | ||
267 | return fSuperModuleData[supModIndex]; | |
268 | } | |
269 | ||
270 | //____________________________________________________________________________ | |
271 | AliEMCALMapAPD::AliEMCALSuperModuleMapAPD AliEMCALMapAPD::GetSuperModuleMapAPDNum(Int_t supModIndex)const | |
272 | { | |
273 | AliEMCALSuperModuleMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. | |
274 | if (!fSuperModuleData) | |
275 | return t; | |
276 | ||
277 | for (int i=0; i<fNSuperModule; i++) { | |
278 | if (fSuperModuleData[i].fSuperModuleNum == supModIndex) { | |
279 | return fSuperModuleData[i]; | |
280 | } | |
281 | } | |
282 | ||
283 | return t; | |
284 | } | |
285 | ||
286 | //____________________________________________________________________________ | |
287 | void AliEMCALMapAPD::GenerateDummyAPDInfo(Int_t nSM, Int_t * iSM) | |
288 | { | |
289 | // just a temporary method to create some info to exercise I/O | |
290 | ||
291 | fNSuperModule = nSM; | |
292 | if (fSuperModuleData) delete [] fSuperModuleData; | |
293 | fSuperModuleData = new AliEMCALSuperModuleMapAPD[fNSuperModule]; | |
294 | ||
295 | Int_t iAPD = 0; | |
296 | Int_t iCol = 0; | |
297 | Int_t iRow = 0; | |
298 | ||
299 | Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows; | |
300 | ||
301 | for (Int_t i = 0; i < fNSuperModule; i++) { | |
302 | AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i]; | |
303 | t.fSuperModuleNum = iSM[i]; // set SuperModules in Order | |
304 | ||
305 | for (Int_t j=0; j<nAPDPerSM; j++) { | |
306 | ||
307 | iCol = j / fgkEmCalRows; | |
308 | iRow = j % fgkEmCalRows; | |
309 | iAPD = j + kFirstAPD + i*nAPDPerSM; // just a dummy number; assuming all APDs are assigned in order from Catania.. | |
310 | ||
311 | t.fAPDNum[iCol][iRow] = iAPD; | |
312 | } | |
313 | ||
314 | } // i, SuperModule | |
315 | ||
316 | return; | |
317 | } | |
318 | ||
c093846b | 319 | //____________________________________________________________________________ |
320 | int AliEMCALMapAPD::CheckForDuplicates() | |
321 | { | |
322 | // keep it simple: have one big array with place | |
323 | // for all APDs from Catania (10000-19999 max) Houston (20000-29999 max) | |
324 | // - and see how many times each APD occurs | |
325 | ||
326 | const int kMaxAPDNum = 30000; | |
327 | int counter[kMaxAPDNum] = {0}; | |
328 | for (int k=0; k<kMaxAPDNum; k++) { | |
329 | counter[k] = 0; | |
330 | } | |
331 | ||
332 | Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows; | |
333 | ||
334 | // go through all APDs | |
335 | int iCol, iRow; | |
336 | for (Int_t i = 0; i < fNSuperModule; i++) { | |
337 | AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i]; | |
338 | ||
339 | for (Int_t j=0; j<nAPDPerSM; j++) { | |
340 | iCol = j / fgkEmCalRows; | |
341 | iRow = j % fgkEmCalRows; | |
342 | counter[t.fAPDNum[iCol][iRow]]++; | |
343 | } | |
344 | } // i, SuperModule | |
345 | ||
346 | int nProblems = 0; | |
347 | for (int k=0; k<kMaxAPDNum; k++) { | |
348 | if (counter[k] > 1) { | |
349 | printf("AliEMCALMapAPD::CheckForDuplicates - APD %d occurs more than once!\n",k); | |
350 | nProblems++; | |
351 | } | |
352 | } | |
353 | ||
354 | return nProblems; | |
355 | } |