]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALCalibMapAPD.cxx
intermediate calibration class commit: struct changed to classes and added root i/o
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibMapAPD.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 calibration and map info
19//
20
21#include <fstream>
22#include <TString.h>
61917ab3 23#include <TFile.h>
24#include <TTree.h>
d81e6423 25
26#include "AliEMCALCalibMapAPD.h"
27
28using namespace std;
29
30ClassImp(AliEMCALCalibMapAPD)
31
32//____________________________________________________________________________
33AliEMCALCalibMapAPD::AliEMCALCalibMapAPD() :
34 fNSuperModule(0),
35 fSuperModuleData(0)
36{
37 //Default constructor.
38}
39
40//____________________________________________________________________________
61917ab3 41void AliEMCALCalibMapAPD::ReadTextCalibMapAPDInfo(Int_t nSM, const TString &txtFileName,
42 Bool_t swapSides)
d81e6423 43{
44 //Read data from txt file. ; coordinates given on SuperModule basis
45
46 std::ifstream inputFile(txtFileName.Data());
47 if (!inputFile) {
48 printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data());
49 return;
50 }
51
52 fNSuperModule = nSM;
53 if (fSuperModuleData) delete [] fSuperModuleData;
54 fSuperModuleData = new AliEMCALSuperModuleCalibMapAPD[fNSuperModule];
55
56 Int_t iSM = 0; // SuperModule index
57 Int_t iCol = 0;
58 Int_t iRow = 0;
59 // list of values to be read
60 Int_t iHW = 0;
61 Int_t APDNum = 0;
62 Float_t V30 = 0;
63 Float_t Par[3] = {0};
64 Float_t ParErr[3] = {0};
65 Int_t BreakDown = 0;
66 Float_t DarkCurrent = 0;
67 // end - all values
68
69 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
70
71 for (Int_t i = 0; i < fNSuperModule; i++) {
72 AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[i];
73 if (!inputFile) {
74 printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Error while reading input file; likely EOF..");
75 return;
76 }
77 inputFile >> iSM;
78 t.fSuperModuleNum = iSM;
79
80 for (Int_t j=0; j<nAPDPerSM; j++) {
81 inputFile >> iCol >> iRow >> iHW
82 >> APDNum >> V30
83 >> Par[0] >> Par[1] >> Par[2]
84 >> ParErr[0] >> ParErr[1] >> ParErr[2]
85 >> BreakDown >> DarkCurrent;
86
87 // assume that this info is already swapped and done for this basis?
88 if (swapSides) {
89 // C side, oriented differently than A side: swap is requested
90 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
91 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
92 }
93
94 AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
95
96 v.fHardWareId = iHW;
97 v.fAPDNum = APDNum;
98 v.fV30 = V30;
99 v.fPar[0] = Par[0];
100 v.fPar[1] = Par[1];
101 v.fPar[2] = Par[2];
102 v.fParErr[0] = ParErr[0];
103 v.fParErr[1] = ParErr[1];
104 v.fParErr[2] = ParErr[2];
105 v.fBreakDown = BreakDown;
106 v.fDarkCurrent = DarkCurrent;
107 }
108
109 } // i, SuperModule
110
111 inputFile.close();
112
113 return;
114}
115
116//____________________________________________________________________________
61917ab3 117void AliEMCALCalibMapAPD::WriteTextCalibMapAPDInfo(const TString &txtFileName,
118 Bool_t swapSides)
d81e6423 119{
120 // write data to txt file. ; coordinates given on SuperModule basis
121
122 std::ofstream outputFile(txtFileName.Data());
123 if (!outputFile) {
124 printf("AliEMCALCalibMapAPD::WriteCalibMapAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
125 return;
126 }
127
128 Int_t iCol = 0;
129 Int_t iRow = 0;
130
131 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
132
133 for (Int_t i = 0; i < fNSuperModule; i++) {
134 AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[i];
135 outputFile << t.fSuperModuleNum << endl;
136
137 for (Int_t j=0; j<nAPDPerSM; j++) {
138 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
139 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
140
141 AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
142
143 if (swapSides) {
144 // C side, oriented differently than A side: swap is requested
145 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
146 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
147 }
148
149 outputFile << iCol << " " << iRow << " " << v.fHardWareId
150 << " " << v.fAPDNum << " " << v.fV30
151 << " " << v.fPar[0] << " " << v.fPar[1] << " " << v.fPar[2]
152 << " " << v.fParErr[0] << " " << v.fParErr[1] << " " << v.fParErr[2]
153 << " " << v.fBreakDown << " " << v.fDarkCurrent << endl;
154 }
155
156 } // i, SuperModule
157
158 outputFile.close();
159
160 return;
161}
162
61917ab3 163//____________________________________________________________________________
164void AliEMCALCalibMapAPD::ReadRootCalibMapAPDInfo(const TString &rootFileName,
165 Bool_t swapSides)
166{
167 //Read data from root file. ; coordinates given on SuperModule basis
168 TFile inputFile(rootFileName, "read");
169
170 TTree *tree = (TTree*) inputFile.Get("tree");
171
172 ReadTreeCalibMapAPDInfo(tree, swapSides);
173
174 inputFile.Close();
175
176 return;
177}
178
179//____________________________________________________________________________
180void AliEMCALCalibMapAPD::ReadTreeCalibMapAPDInfo(TTree *tree,
181 Bool_t swapSides)
182{
183 // how many SuperModule's worth of entries / APDs do we have?
184 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
185 fNSuperModule = tree->GetEntries() / nAPDPerSM;
186
187 if (fSuperModuleData) delete [] fSuperModuleData;
188 fSuperModuleData = new AliEMCALSuperModuleCalibMapAPD[fNSuperModule];
189
190 Int_t iSM = 0; // SuperModule index
191 Int_t iCol = 0;
192 Int_t iRow = 0;
193 // list of values to be read
194 Int_t iHW = 0;
195 Int_t APDNum = 0;
196 Float_t V30 = 0;
197 Float_t Par[3] = {0};
198 Float_t ParErr[3] = {0};
199 Int_t BreakDown = 0;
200 Float_t DarkCurrent = 0;
201 // end - all values
202
203 // declare the branches
204 tree->SetBranchAddress("iSM", &iSM);
205 tree->SetBranchAddress("iCol", &iCol);
206 tree->SetBranchAddress("iRow", &iRow);
207 tree->SetBranchAddress("iHW", &iHW);
208 tree->SetBranchAddress("APDNum", &APDNum);
209 tree->SetBranchAddress("V30", &V30);
210 tree->SetBranchAddress("Par", Par);
211 tree->SetBranchAddress("ParErr", ParErr);
212 tree->SetBranchAddress("BreakDown", &BreakDown);
213 tree->SetBranchAddress("DarkCurrent", &DarkCurrent);
214
215 for (int ient=0; ient<tree->GetEntries(); ient++) {
216 tree->GetEntry(ient);
217
218 // assume the index SuperModules come in order: i=iSM
219 AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[iSM];
220 t.fSuperModuleNum = iSM;
221
222 // assume that this info is already swapped and done for this basis?
223 if (swapSides) {
224 // C side, oriented differently than A side: swap is requested
225 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
226 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
227 }
228
229 AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
230
231 v.fHardWareId = iHW;
232 v.fAPDNum = APDNum;
233 v.fV30 = V30;
234 v.fPar[0] = Par[0];
235 v.fPar[1] = Par[1];
236 v.fPar[2] = Par[2];
237 v.fParErr[0] = ParErr[0];
238 v.fParErr[1] = ParErr[1];
239 v.fParErr[2] = ParErr[2];
240 v.fBreakDown = BreakDown;
241 v.fDarkCurrent = DarkCurrent;
242
243 } //
244
245 return;
246}
247
248//____________________________________________________________________________
249void AliEMCALCalibMapAPD::WriteRootCalibMapAPDInfo(const TString &rootFileName,
250 Bool_t swapSides)
251{
252 // write data to root file. ; coordinates given on SuperModule basis
253 TFile destFile(rootFileName, "recreate");
254 if (destFile.IsZombie()) {
255 return;
256 }
257 destFile.cd();
258
259 TTree *tree = new TTree("tree","");
260
261 // variables for filling the TTree
262 Int_t iSM = 0; // SuperModule index
263 Int_t iHW = 0;
264 Int_t APDNum = 0;
265 Float_t V30 = 0;
266 Float_t Par[3] = {0};
267 Float_t ParErr[3] = {0};
268 Int_t BreakDown = 0;
269 Float_t DarkCurrent = 0;
270 //
271 Int_t iCol = 0;
272 Int_t iRow = 0;
273 // declare the branches
274 tree->Branch("iSM", &iSM, "iSM/I");
275 tree->Branch("iCol", &iCol, "iCol/I");
276 tree->Branch("iRow", &iRow, "iRow/I");
277 tree->Branch("iHW", &iHW, "iHW/I");
278 tree->Branch("APDNum", &APDNum, "APDNum/I");
279 tree->Branch("V30", &V30, "V30/F");
280 tree->Branch("Par", &Par, "Par[3]/F");
281 tree->Branch("ParErr", &ParErr, "ParErr[3]/F");
282 tree->Branch("BreakDown", &BreakDown, "BreakDown/I");
283 tree->Branch("DarkCurrent", &DarkCurrent, "DarkCurrent/F");
284
285 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
286
287 for (iSM = 0; iSM < fNSuperModule; iSM++) {
288 AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[iSM];
289
290 for (Int_t j=0; j<nAPDPerSM; j++) {
291 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
292 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
293
294 AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
295
296 if (swapSides) {
297 // C side, oriented differently than A side: swap is requested
298 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
299 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
300 }
301
302 iHW = v.fHardWareId;
303 APDNum = v.fAPDNum;
304 V30 = v.fV30;
305 for (int k=0; k<3; k++) {
306 Par[k] = v.fPar[k];
307 ParErr[k] = v.fParErr[k];
308 }
309 BreakDown = v.fBreakDown;
310 DarkCurrent = v.fDarkCurrent;
311
312 tree->Fill();
313 }
314
315 } // i, SuperModule
316
317 tree->Write();
318 destFile.Close();
319
320 return;
321}
322
d81e6423 323//____________________________________________________________________________
324AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD()
325{
326 delete [] fSuperModuleData;
327}
328
329//____________________________________________________________________________
61917ab3 330AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDId(Int_t supModIndex)const
d81e6423 331{
332 AliEMCALSuperModuleCalibMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
333 if (!fSuperModuleData)
334 return t;
335
336 return fSuperModuleData[supModIndex];
337}
338
339//____________________________________________________________________________
61917ab3 340AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const
d81e6423 341{
342 AliEMCALSuperModuleCalibMapAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
343 if (!fSuperModuleData)
344 return t;
345
346 for (int i=0; i<fNSuperModule; i++) {
347 if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
348 return fSuperModuleData[i];
349 }
350 }
351
352 return t;
353}
354