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