new file to test SDigits
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibAbs.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 basis for absolute calibrations
19//
20
21#include <fstream>
22#include <TString.h>
61917ab3 23#include <TFile.h>
24#include <TTree.h>
d81e6423 25
26#include "AliEMCALCalibAbs.h"
27
28using namespace std;
29
30ClassImp(AliEMCALCalibAbs)
31
32//____________________________________________________________________________
2f17a269 33AliEMCALCalibAbs::AliEMCALCalibAbs(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 AliEMCALSuperModuleCalibAbs(i));
40 }
41 fSuperModuleData.Compress(); // compress the TObjArray
61e4e2e3 42 fSuperModuleData.SetOwner(kTRUE);
d81e6423 43}
44
45//____________________________________________________________________________
61917ab3 46void AliEMCALCalibAbs::ReadTextCalibAbsInfo(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("AliEMCALCalibAbs::ReadCalibAbsInfo - 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;
d81e6423 62
63 // list of values to be read
64 // first: overall values for the whole SuperModule
18831b6c 65 Int_t iCalibMethod = 0;
66 Int_t iCalibPass = 0;
67 Float_t absoluteCalib = 0;
d81e6423 68 // third: info for each tower
18831b6c 69 Float_t relativeCalib = 0; // (ADC>GeV relative gain/conversion), value around 1
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 AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
d81e6423 76 if (!inputFile) {
b48d1356 77 printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; likely EOF..\n");
d81e6423 78 return;
79 }
80 inputFile >> iSM;
2f17a269 81 t->SetSuperModuleNum(iSM);
d81e6423 82
83 // first: overall values for the whole SuperModule
ab962f7b 84 inputFile >> iCalibMethod >> iCalibPass >> absoluteCalib;
85 t->SetCalibMethod(iCalibMethod);
86 t->SetCalibPass(iCalibPass);
87 t->SetAbsoluteCalib(absoluteCalib);
d81e6423 88
89 // third: info for each tower
90 for (Int_t j=0; j<nAPDPerSM; j++) {
b48d1356 91 inputFile >> iCol >> iRow >> relativeCalib;
92
93 // check that input values are not out bounds
94 if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) ||
95 iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) ) {
96 printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; j %d iCol %d iRow %d\n", j, iCol, iRow);
97 return;
98 }
d81e6423 99
100 // assume that this info is already swapped and done for this basis?
101 if (swapSides) {
102 // C side, oriented differently than A side: swap is requested
103 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
104 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
105 }
106
ab962f7b 107 t->SetRelativeCalib(iCol, iRow, relativeCalib);
d81e6423 108 }
109
110 } // i, SuperModule
111
112 inputFile.close();
113
114 return;
115}
116
117//____________________________________________________________________________
61917ab3 118void AliEMCALCalibAbs::WriteTextCalibAbsInfo(const TString &txtFileName,
119 Bool_t swapSides)
d81e6423 120{
121 // write data to txt file. ; coordinates given on SuperModule basis
122
123 std::ofstream outputFile(txtFileName.Data());
124 if (!outputFile) {
125 printf("AliEMCALCalibAbs::WriteCalibAbsInfo - Cannot open the APD output file %s\n", txtFileName.Data());
126 return;
127 }
128
129 Int_t iCol = 0;
130 Int_t iRow = 0;
131
132 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
ab962f7b 133 Float_t relativeCalib = 0;
d81e6423 134 for (Int_t i = 0; i < fNSuperModule; i++) {
2f17a269 135 AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
136
d81e6423 137 // first: overall values for the whole SuperModule
2f17a269 138 outputFile << t->GetSuperModuleNum() << endl;
139 outputFile << t->GetCalibMethod() << " "
140 << t->GetCalibPass() << " "
82d90a2f 141 << t->GetAbsoluteCalib() << endl;
d81e6423 142
61917ab3 143 // third: info for each tower
d81e6423 144 for (Int_t j=0; j<nAPDPerSM; j++) {
145 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
146 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
147
ab962f7b 148 relativeCalib = t->GetRelativeCalib(iCol, iRow);
d81e6423 149
150 if (swapSides) {
151 // C side, oriented differently than A side: swap is requested
152 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
153 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
154 }
155
156 outputFile << iCol << " " << iRow
ab962f7b 157 << " " << relativeCalib << endl;
d81e6423 158 }
159
160 } // i, SuperModule
161
162 outputFile.close();
163
164 return;
165}
166
167//____________________________________________________________________________
61917ab3 168void AliEMCALCalibAbs::ReadRootCalibAbsInfo(const TString &rootFileName,
169 Bool_t swapSides)
170{
171 //Read data from root file. ; coordinates given on SuperModule basis
172 TFile inputFile(rootFileName, "read");
173
174 TTree *tree = (TTree*) inputFile.Get("tree");
175
176 ReadTreeCalibAbsInfo(tree, swapSides);
177
178 inputFile.Close();
179
180 return;
181}
182
183//____________________________________________________________________________
184void AliEMCALCalibAbs::ReadTreeCalibAbsInfo(TTree *tree,
185 Bool_t swapSides)
186{
82d90a2f 187 // how many SuperModule's worth of info do we have?
61917ab3 188 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
82d90a2f 189 fNSuperModule = tree->GetEntries();
61917ab3 190
61917ab3 191 Int_t iSM = 0; // SuperModule index
192 // list of values to be read
193 // first: overall values for the whole SuperModule
18831b6c 194 Int_t iCalibMethod = 0;
ab962f7b 195 Int_t iCalibPass = 0;
196 Float_t absoluteCalib = 0;
61917ab3 197 // third: info for each tower
ab962f7b 198 Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
61917ab3 199 // end - all values
200
201 // just to make the initializations of the arrays are done correctly, let's use memset
ab962f7b 202 memset(relativeCalib, 0, sizeof(relativeCalib));
61917ab3 203
204 // declare the branches
205 tree->SetBranchAddress("iSM", &iSM);
ab962f7b 206 tree->SetBranchAddress("CalibMethod", &iCalibMethod);
207 tree->SetBranchAddress("CalibPass", &iCalibPass);
208 tree->SetBranchAddress("AbsoluteCalib", &absoluteCalib);
61917ab3 209 //
ab962f7b 210 tree->SetBranchAddress("RelativeCalib", relativeCalib);
61917ab3 211
212 // indices for looping over the towers
213 Int_t iCol = 0;
214 Int_t iRow = 0;
215
216 for (int ient=0; ient<tree->GetEntries(); ient++) {
217 tree->GetEntry(ient);
218
219 // assume the index SuperModules come in order: i=iSM
2f17a269 220 AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
221
222 t->SetSuperModuleNum(iSM);
61917ab3 223 // first, overall values
ab962f7b 224 t->SetCalibMethod(iCalibMethod);
225 t->SetCalibPass(iCalibPass);
226 t->SetAbsoluteCalib(absoluteCalib);
61917ab3 227
228 // third: info for each tower
229 for (Int_t j=0; j<nAPDPerSM; j++) {
230 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
231 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
232
233 // help variables: possibly modified or swapped indices
234 int iColMod = iCol;
235 int iRowMod = iRow;
236 // assume that this info is already swapped and done for this basis?
237 if (swapSides) {
238 // C side, oriented differently than A side: swap is requested
239 iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
240 iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
241 }
242
ab962f7b 243 t->SetRelativeCalib(iColMod, iRowMod, relativeCalib[iCol][iRow]);
61917ab3 244 }
245
246 } // loop over entries
247
248 return;
249}
250
251//____________________________________________________________________________
252void AliEMCALCalibAbs::WriteRootCalibAbsInfo(const TString &rootFileName,
253 Bool_t swapSides)
254{
255 // write data to root file. ; coordinates given on SuperModule basis
256 TFile destFile(rootFileName, "recreate");
257 if (destFile.IsZombie()) {
258 return;
259 }
260 destFile.cd();
261
262 TTree *tree = new TTree("tree","");
263
264 // variables for filling the TTree
265 Int_t iSM = 0; // SuperModule index
266 // list of values to be written
267 // first: overall values for the whole SuperModule
ab962f7b 268 Int_t iCalibMethod = 0;
269 Int_t iCalibPass = 0;
270 Float_t absoluteCalib = 0;
61917ab3 271 // third: info for each tower
ab962f7b 272 Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
61917ab3 273 // end - all values
274
275 // just to make the initializations of the arrays are done correctly, let's use memset
ab962f7b 276 memset(relativeCalib, 0, sizeof(relativeCalib));
61917ab3 277
278 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
279 // for looping over towers
280 Int_t iCol = 0;
281 Int_t iRow = 0;
282
283 // declare the branches
284 // first
285 tree->Branch("iSM", &iSM, "iSM/I");
ab962f7b 286 tree->Branch("CalibMethod", &iCalibMethod, "CalibMethod/I");
287 tree->Branch("CalibPass", &iCalibPass, "CalibPass/I");
288 tree->Branch("AbsoluteCalib", &absoluteCalib, "AbsoluteCalib/F");
61917ab3 289 // third: info for each tower; see if a 2D array works OK or if we'll have to use 1D arrays instead
ab962f7b 290 tree->Branch( "RelativeCalib", &relativeCalib, Form("RelativeCalib[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
61917ab3 291
292 for (iSM = 0; iSM < fNSuperModule; iSM++) {
2f17a269 293 AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
61917ab3 294
2f17a269 295 iSM = t->GetSuperModuleNum();
61917ab3 296 // first, overall values
ab962f7b 297 iCalibMethod = t->GetCalibMethod();
298 iCalibPass = t->GetCalibPass();
299 absoluteCalib = t->GetAbsoluteCalib();
61917ab3 300
301 // third: info for each tower
302 for (Int_t j=0; j<nAPDPerSM; j++) {
303 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
304 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
305
306 // help variables: possibly modified or swapped indices
307 int iColMod = iCol;
308 int iRowMod = iRow;
309 // assume that this info is already swapped and done for this basis?
310 if (swapSides) {
311 // C side, oriented differently than A side: swap is requested
312 iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
313 iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
314 }
315
ab962f7b 316 relativeCalib[iColMod][iRowMod] = t->GetRelativeCalib(iCol, iRow);
61917ab3 317 }
318
319 tree->Fill();
320 } // i, SuperModule
321
322 tree->Write();
323 destFile.Close();
324
325 return;
326}
327
328//____________________________________________________________________________
d81e6423 329AliEMCALCalibAbs::~AliEMCALCalibAbs()
330{
2f17a269 331 fSuperModuleData.Delete();
d81e6423 332}
333
334//____________________________________________________________________________
2f17a269 335AliEMCALSuperModuleCalibAbs * AliEMCALCalibAbs::GetSuperModuleCalibAbsNum(Int_t supModIndex)const
afae9650 336{ // getter via index
d81e6423 337 for (int i=0; i<fNSuperModule; i++) {
2f17a269 338 AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
339 if (t->GetSuperModuleNum() == supModIndex) {
340 return t;
d81e6423 341 }
342 }
343
2f17a269 344 // if we arrived here, then nothing was found.. just return a NULL pointer
345 return NULL;
d81e6423 346}
347