]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALCalibTimeDepCorrection.cxx
first version of new classes for time-dependent corrections; not yet used in Preproce...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibTimeDepCorrection.cxx
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 contain info on APD bias settings/voltages
19 //
20
21 #include <fstream>
22 #include <TString.h>
23 #include <TArrayF.h>
24
25 #include "AliEMCALCalibTimeDepCorrection.h"
26
27 using namespace std;
28
29 ClassImp(AliEMCALCalibTimeDepCorrection)
30
31 //____________________________________________________________________________
32 AliEMCALCalibTimeDepCorrection::AliEMCALCalibTimeDepCorrection() : 
33   fNSuperModule(0),
34   fSuperModuleData(0)
35 {
36   //Default constructor.
37 }
38
39 //____________________________________________________________________________
40 void AliEMCALCalibTimeDepCorrection::InitCorrection(Int_t nSM, Int_t nBins, Float_t val=1.0)
41 {
42   // This methods assumes that you are using SuperModules 0..nSM-1
43   fNSuperModule = nSM;
44   if (fSuperModuleData) delete [] fSuperModuleData;
45   fSuperModuleData = new AliEMCALSuperModuleCalibTimeDepCorrection[fNSuperModule];
46
47   Int_t iSM = 0; // SuperModule index
48   Int_t iCol = 0;
49   Int_t iRow = 0;
50   Int_t nCorr = nBins;
51   Float_t Correction = val;
52
53   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
54
55   for (Int_t i = 0; i < fNSuperModule; i++) {
56     AliEMCALSuperModuleCalibTimeDepCorrection &t = fSuperModuleData[i];
57     t.fSuperModuleNum = iSM; // assume SMs are coming in order
58
59     for (Int_t j=0; j<nAPDPerSM; j++) {
60
61       // set size of TArray
62       t.fCorrection[iCol][iRow].Set(nCorr);
63       for (Int_t k=0; k<nCorr; k++) {
64         // add to TArray
65         t.fCorrection[iCol][iRow].AddAt(Correction, k); // AddAt = SetAt..
66       }
67     }
68
69   } // i, SuperModule
70
71   return;
72 }
73
74 //____________________________________________________________________________
75 void AliEMCALCalibTimeDepCorrection::SetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin, Float_t val)
76 { // if you call for non-existing data, there may be a crash..
77   fSuperModuleData[supModIndex].fCorrection[iCol][iRow].AddAt(val, iBin); // AddAt = SetAt..
78  return; 
79 }
80
81 //____________________________________________________________________________
82 Float_t AliEMCALCalibTimeDepCorrection::GetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin)const
83 { // if you call for non-existing data, there may be a crash..
84   return fSuperModuleData[supModIndex].fCorrection[iCol][iRow].At(iBin);
85 }
86
87 //____________________________________________________________________________
88 void AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo(Int_t nSM, const TString &txtFileName,
89                                                                     Bool_t swapSides)
90 {
91   //Read data from txt file. ; coordinates given on SuperModule basis
92
93   std::ifstream inputFile(txtFileName.Data());
94   if (!inputFile) {
95     printf("AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo - Cannot open the APD info file %s\n", txtFileName.Data());
96     return;
97   }
98
99   fNSuperModule = nSM;
100   if (fSuperModuleData) delete [] fSuperModuleData;
101   fSuperModuleData = new AliEMCALSuperModuleCalibTimeDepCorrection[fNSuperModule];
102
103   Int_t iSM = 0; // SuperModule index
104   Int_t iCol = 0;
105   Int_t iRow = 0;
106   Int_t nCorr = 0;
107   Float_t Correction = 0;
108
109   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
110
111   for (Int_t i = 0; i < fNSuperModule; i++) {
112     AliEMCALSuperModuleCalibTimeDepCorrection &t = fSuperModuleData[i];
113     if (!inputFile) {
114       printf("AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo - Error while reading input file; likely EOF..");
115       return;
116     }
117     inputFile >> iSM;
118     t.fSuperModuleNum = iSM;
119
120     for (Int_t j=0; j<nAPDPerSM; j++) {
121       inputFile >> iCol >> iRow >> nCorr;
122
123       // assume that this info is already swapped and done for this basis?
124       if (swapSides) {
125         // C side, oriented differently than A side: swap is requested
126         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
127         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
128       }
129
130       // set size of TArray
131       t.fCorrection[iCol][iRow].Set(nCorr);
132       for (Int_t k=0; k<nCorr; k++) {
133         inputFile >> Correction;
134         // add to TArray
135         t.fCorrection[iCol][iRow].AddAt(Correction, k);
136       }
137     }
138
139   } // i, SuperModule
140
141   inputFile.close();
142
143   return;
144 }
145
146 //____________________________________________________________________________
147 void AliEMCALCalibTimeDepCorrection::WriteCalibTimeDepCorrectionInfo(const TString &txtFileName,
148                                                                      Bool_t swapSides)
149 {
150   // write data to txt file. ; coordinates given on SuperModule basis
151
152   std::ofstream outputFile(txtFileName.Data());
153   if (!outputFile) {
154     printf("AliEMCALCalibTimeDepCorrection::WriteCalibTimeDepCorrectionInfo - Cannot open the APD output file %s\n", txtFileName.Data());
155     return;
156   }
157
158   Int_t iCol = 0;
159   Int_t iRow = 0;
160   Int_t nCorr = 0;
161
162   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
163
164   for (Int_t i = 0; i < fNSuperModule; i++) {
165     AliEMCALSuperModuleCalibTimeDepCorrection &t = fSuperModuleData[i];
166     outputFile << t.fSuperModuleNum << endl;
167
168     for (Int_t j=0; j<nAPDPerSM; j++) {
169       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
170       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
171
172       nCorr = t.fCorrection[iCol][iRow].GetSize();
173
174       if (swapSides) {
175         // C side, oriented differently than A side: swap is requested
176         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
177         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
178       }
179
180       outputFile << iCol << " " << iRow << " " << nCorr << endl;
181       for (Int_t k=0; k<nCorr; k++) {
182         outputFile << t.fCorrection[iCol][iRow].At(k) << " ";
183       }
184       outputFile << endl;
185
186     }
187
188   } // i, SuperModule
189
190   outputFile.close();
191
192   return;
193 }
194
195 //____________________________________________________________________________
196 AliEMCALCalibTimeDepCorrection::~AliEMCALCalibTimeDepCorrection()
197 {
198   delete [] fSuperModuleData;
199 }
200
201 //____________________________________________________________________________
202 AliEMCALCalibTimeDepCorrection::AliEMCALSuperModuleCalibTimeDepCorrection AliEMCALCalibTimeDepCorrection::GetSuperModuleCalibTimeDepCorrectionId(Int_t supModIndex)const
203 {
204   AliEMCALSuperModuleCalibTimeDepCorrection t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
205   if (!fSuperModuleData)
206     return t;
207
208   return fSuperModuleData[supModIndex];
209 }
210
211 //____________________________________________________________________________
212 AliEMCALCalibTimeDepCorrection::AliEMCALSuperModuleCalibTimeDepCorrection AliEMCALCalibTimeDepCorrection::GetSuperModuleCalibTimeDepCorrectionNum(Int_t supModIndex)const
213 {
214   AliEMCALSuperModuleCalibTimeDepCorrection t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
215   if (!fSuperModuleData)
216     return t;
217
218   for (int i=0; i<fNSuperModule; i++) {
219     if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
220       return fSuperModuleData[i];
221     }
222   }
223
224   return t;
225 }
226