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