1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Objects of this class read txt file with APD number data
24 #include "AliEMCALMapAPD.h"
26 const int kFirstAPD = 10213; // dummy number, only used for testing
28 ClassImp(AliEMCALMapAPD)
30 //____________________________________________________________________________
31 AliEMCALMapAPD::AliEMCALMapAPD() :
35 //Default constructor.
38 //____________________________________________________________________________
39 void AliEMCALMapAPD::ReadMapAPDInfoStripBasis(Int_t nSM, const TString &txtFileName)
41 //Read data from txt file; coordinates given on StripModule basis
43 std::ifstream inputFile(txtFileName.Data());
45 printf("AliEMCALMapAPD::ReadMapAPDInfoStripBasis - Cannot open the APD info file %s\n",txtFileName.Data());
50 if (fSuperModuleData) delete [] fSuperModuleData;
51 fSuperModuleData = new AliEMCALSuperModuleMapAPD[fNSuperModule];
53 Int_t iSM = 0; // SuperModule index
55 // info in map is based on Strip Info
60 // we'll convert this into SuperModule Info
64 Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows;
66 for (Int_t i = 0; i < fNSuperModule; i++) {
67 AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i];
69 printf("AliEMCALMapAPD::ReadMapAPDInfoStripBasis - Error while reading input file; likely EOF..\n");
73 t.fSuperModuleNum = iSM;
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;
83 if (iSM%2 == 1) { // C side, oriented differently than A side: swap..
84 iCol = fgkEmCalCols-1 - iCol;
85 iRow = fgkEmCalRows-1 - iRow;
88 t.fAPDNum[iCol][iRow] = iAPD;
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)
104 //Read data from txt file; coordinates given on StripModule basis
106 std::ifstream inputFile(txtFileName.Data());
108 printf("AliEMCALMapAPD::ReadMapAPDInfoSingleStripBasis - Cannot open the APD info file %s\n",txtFileName.Data());
112 // see if there is an existing SuperModule with the right index
114 for (Int_t i = 0; i < fNSuperModule; i++) {
115 AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i];
116 if (t.fSuperModuleNum == iSM) foundSM = i;
120 printf("AliEMCALMapAPD::ReadMapAPDInfoSingleStripBasis - no SuperModule %d found!\n", iSM);
124 AliEMCALSuperModuleMapAPD &t = fSuperModuleData[foundSM];
127 // info in map is based on Strip Info
131 // we'll convert this into SuperModule Info
135 Int_t nAPDPerStrip = 2 * fgkEmCalRows; // 2 columns in a strip
137 for (Int_t j=0; j<nAPDPerStrip; j++) {
139 printf("AliEMCALMapAPD::ReadMapAPDInfoSingleStripBasis - Error while reading input file; likely EOF..\n");
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;
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;
159 t.fAPDNum[iCol][iRow] = iAPD;
168 //____________________________________________________________________________
169 void AliEMCALMapAPD::ReadMapAPDInfo(Int_t nSM, const TString &txtFileName)
171 //Read data from txt file. ; coordinates given on SuperModule basis
173 std::ifstream inputFile(txtFileName.Data());
175 printf("AliEMCALMapAPD::ReadMapAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data());
180 if (fSuperModuleData) delete [] fSuperModuleData;
181 fSuperModuleData = new AliEMCALSuperModuleMapAPD[fNSuperModule];
183 Int_t iSM = 0; // SuperModule index
188 Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows;
190 for (Int_t i = 0; i < fNSuperModule; i++) {
191 AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i];
193 printf("AliEMCALMapAPD::ReadMapAPDInfo - Error while reading input file; likely EOF..");
197 t.fSuperModuleNum = iSM;
199 for (Int_t j=0; j<nAPDPerSM; j++) {
200 inputFile >> iCol >> iRow >> iAPD;
202 // assume that this info is already swapped and done for this basis?
204 if (iSM%2 == 1) { // C side, oriented differently than A side: swap..
205 iCol = fgkEmCalCols-1 - iCol;
206 iRow = fgkEmCalRows-1 - iRow;
210 t.fAPDNum[iCol][iRow] = iAPD;
220 //____________________________________________________________________________
221 void AliEMCALMapAPD::WriteMapAPDInfo(const TString &txtFileName)
223 // write data to txt file. ; coordinates given on SuperModule basis
225 std::ofstream outputFile(txtFileName.Data());
227 printf("AliEMCALMapAPD::WriteMapAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
234 Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows;
236 for (Int_t i = 0; i < fNSuperModule; i++) {
237 AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i];
238 outputFile << t.fSuperModuleNum << endl;
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;
254 //____________________________________________________________________________
255 AliEMCALMapAPD::~AliEMCALMapAPD()
257 delete [] fSuperModuleData;
260 //____________________________________________________________________________
261 AliEMCALMapAPD::AliEMCALSuperModuleMapAPD AliEMCALMapAPD::GetSuperModuleMapAPDId(Int_t supModIndex)const
263 AliEMCALSuperModuleMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
264 if (!fSuperModuleData)
267 return fSuperModuleData[supModIndex];
270 //____________________________________________________________________________
271 AliEMCALMapAPD::AliEMCALSuperModuleMapAPD AliEMCALMapAPD::GetSuperModuleMapAPDNum(Int_t supModIndex)const
273 AliEMCALSuperModuleMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
274 if (!fSuperModuleData)
277 for (int i=0; i<fNSuperModule; i++) {
278 if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
279 return fSuperModuleData[i];
286 //____________________________________________________________________________
287 void AliEMCALMapAPD::GenerateDummyAPDInfo(Int_t nSM, Int_t * iSM)
289 // just a temporary method to create some info to exercise I/O
292 if (fSuperModuleData) delete [] fSuperModuleData;
293 fSuperModuleData = new AliEMCALSuperModuleMapAPD[fNSuperModule];
299 Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows;
301 for (Int_t i = 0; i < fNSuperModule; i++) {
302 AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i];
303 t.fSuperModuleNum = iSM[i]; // set SuperModules in Order
305 for (Int_t j=0; j<nAPDPerSM; j++) {
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..
311 t.fAPDNum[iCol][iRow] = iAPD;
319 //____________________________________________________________________________
320 int AliEMCALMapAPD::CheckForDuplicates()
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
326 const int kMaxAPDNum = 30000;
327 int counter[kMaxAPDNum] = {0};
328 for (int k=0; k<kMaxAPDNum; k++) {
332 Int_t nAPDPerSM = fgkEmCalCols * fgkEmCalRows;
334 // go through all APDs
336 for (Int_t i = 0; i < fNSuperModule; i++) {
337 AliEMCALSuperModuleMapAPD &t = fSuperModuleData[i];
339 for (Int_t j=0; j<nAPDPerSM; j++) {
340 iCol = j / fgkEmCalRows;
341 iRow = j % fgkEmCalRows;
342 counter[t.fAPDNum[iCol][iRow]]++;
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);