Line data Source code
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 reference calibrations
19 : //
20 :
21 : #include <fstream>
22 : #include <TString.h>
23 : #include <TFile.h>
24 : #include <TTree.h>
25 :
26 : #include "AliEMCALCalibReference.h"
27 :
28 : using namespace std;
29 :
30 42 : ClassImp(AliEMCALCalibReference)
31 :
32 : //____________________________________________________________________________
33 0 : AliEMCALCalibReference::AliEMCALCalibReference(const int nSM) :
34 0 : fNSuperModule(nSM),
35 0 : fSuperModuleData()
36 0 : {
37 : //Default constructor.
38 0 : for (int i=0; i<fNSuperModule; i++) {
39 0 : fSuperModuleData.Add(new AliEMCALSuperModuleCalibReference(i));
40 : }
41 0 : fSuperModuleData.Compress(); // compress the TObjArray
42 0 : fSuperModuleData.SetOwner(kTRUE);
43 0 : }
44 :
45 : //____________________________________________________________________________
46 : void AliEMCALCalibReference::ReadTextCalibReferenceInfo(Int_t nSM, const TString &txtFileName,
47 : Bool_t swapSides)
48 : {
49 : //Read data from txt file. ; coordinates given on SuperModule basis
50 :
51 0 : std::ifstream inputFile(txtFileName.Data());
52 0 : if (!inputFile) {
53 0 : printf("AliEMCALCalibReference::ReadCalibReferenceInfo - Cannot open the APD info file %s\n", txtFileName.Data());
54 0 : return;
55 : }
56 :
57 0 : fNSuperModule = nSM;
58 :
59 0 : Int_t iSM = 0; // SuperModule index
60 0 : Int_t iCol = 0;
61 0 : Int_t iRow = 0;
62 0 : Int_t id = 0;
63 :
64 : // list of values to be read
65 : // first: overall values for the whole SuperModule
66 0 : Int_t iReferenceTime = 0;
67 : // second: additional info for LED Reference and SM temperature
68 0 : Float_t rLEDRefAmp = 0;
69 0 : Float_t rLEDRefAmpRMS = 0;
70 0 : Int_t iLEDRefHighLow = 0;
71 0 : Float_t temperature = 0;
72 0 : Float_t temperatureRMS = 0;
73 : // third: info for each tower
74 0 : Int_t iHighLow = 0; //
75 0 : Float_t rLEDAmp = 0; // low gain eq. amplitude
76 0 : Float_t rLEDAmpRMS = 0; //
77 : // end - all values
78 :
79 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
80 :
81 0 : for (Int_t i = 0; i < fNSuperModule; i++) {
82 0 : AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[i];
83 0 : if (!inputFile) {
84 0 : printf("AliEMCALCalibReference::ReadCalibReferenceInfo - Error while reading input file; likely EOF..\n");
85 0 : return;
86 : }
87 0 : inputFile >> iSM;
88 0 : t->SetSuperModuleNum(iSM);
89 :
90 : // first: overall values for the whole SuperModule
91 0 : inputFile >> iReferenceTime;
92 0 : t->SetReferenceTime(iReferenceTime);
93 :
94 : // second: additional info for LED Reference and SM temperature
95 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
96 0 : inputFile >> id >> iLEDRefHighLow >> rLEDRefAmp >> rLEDRefAmpRMS;
97 0 : if (id<0 || id>(AliEMCALGeoParams::fgkEMCALLEDRefs-1) ) {
98 0 : printf("AliEMCALCalibReference::ReadCalibReferenceInfo - Error while reading input file; LEDRef j %d id %d\n", j, id);
99 0 : return;
100 : }
101 0 : t->SetLEDRefHighLow(id, iLEDRefHighLow);
102 0 : t->SetLEDRefAmp(id, rLEDRefAmp);
103 0 : t->SetLEDRefAmpRMS(id, rLEDRefAmpRMS);
104 : }
105 :
106 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
107 0 : inputFile >> id >> temperature >> temperatureRMS;
108 0 : if (id<0 || id>(AliEMCALGeoParams::fgkEMCALTempSensors-1) ) {
109 0 : printf("AliEMCALCalibReference::ReadCalibReferenceInfo - Error while reading input file; TempSensor j %d id %d\n", j, id);
110 0 : return;
111 : }
112 0 : t->SetTemperature(id, temperature);
113 0 : t->SetTemperatureRMS(id, temperatureRMS);
114 : }
115 :
116 : // third: info for each tower
117 0 : for (Int_t j=0; j<nAPDPerSM; j++) {
118 0 : inputFile >> iCol >> iRow
119 0 : >> iHighLow >> rLEDAmp >> rLEDAmpRMS;
120 :
121 : // check that input values are not out bounds
122 0 : if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) ||
123 0 : iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) ) {
124 0 : printf("AliEMCALCalibReference::ReadCalibReferenceInfo - Error while reading input file; j %d iCol %d iRow %d\n", j, iCol, iRow);
125 0 : return;
126 : }
127 :
128 : // assume that this info is already swapped and done for this basis?
129 0 : if (swapSides) {
130 : // C side, oriented differently than A side: swap is requested
131 0 : iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
132 0 : iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
133 0 : }
134 :
135 0 : AliEMCALCalibReferenceVal * v = t->GetAPDVal(iCol, iRow);
136 :
137 0 : v->SetHighLow(iHighLow);
138 0 : v->SetLEDAmp(rLEDAmp);
139 0 : v->SetLEDAmpRMS(rLEDAmpRMS);
140 : }
141 :
142 0 : } // i, SuperModule
143 :
144 0 : inputFile.close();
145 :
146 0 : return;
147 0 : }
148 :
149 : //____________________________________________________________________________
150 : void AliEMCALCalibReference::WriteTextCalibReferenceInfo(const TString &txtFileName,
151 : Bool_t swapSides)
152 : {
153 : // write data to txt file. ; coordinates given on SuperModule basis
154 :
155 0 : std::ofstream outputFile(txtFileName.Data());
156 0 : if (!outputFile) {
157 0 : printf("AliEMCALCalibReference::WriteCalibReferenceInfo - Cannot open the APD output file %s\n", txtFileName.Data());
158 0 : return;
159 : }
160 :
161 : Int_t iCol = 0;
162 : Int_t iRow = 0;
163 :
164 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
165 :
166 0 : for (Int_t i = 0; i < fNSuperModule; i++) {
167 0 : AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[i];
168 :
169 : // first: overall values for the whole SuperModule
170 0 : outputFile << t->GetSuperModuleNum() << endl;
171 0 : outputFile << t->GetReferenceTime() << endl;
172 :
173 : // second: additional info for LED Reference and SM temperature
174 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
175 0 : outputFile << j << " " << t->GetLEDRefHighLow(j)
176 0 : << " " << t->GetLEDRefAmp(j) << " " << t->GetLEDRefAmpRMS(j)
177 0 : << endl;
178 : }
179 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
180 0 : outputFile << j << " " << t->GetTemperature(j) << " " << t->GetTemperatureRMS(j) << endl;
181 : }
182 :
183 : // third: info for each tower
184 0 : for (Int_t j=0; j<nAPDPerSM; j++) {
185 0 : iCol = j / AliEMCALGeoParams::fgkEMCALRows;
186 0 : iRow = j % AliEMCALGeoParams::fgkEMCALRows;
187 :
188 0 : AliEMCALCalibReferenceVal * v = t->GetAPDVal(iCol, iRow);
189 :
190 0 : if (swapSides) {
191 : // C side, oriented differently than A side: swap is requested
192 0 : iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
193 0 : iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
194 0 : }
195 :
196 0 : outputFile << iCol << " " << iRow
197 0 : << " " << v->GetHighLow()
198 0 : << " " << v->GetLEDAmp()
199 0 : << " " << v->GetLEDAmpRMS() << endl;
200 : }
201 :
202 : } // i, SuperModule
203 :
204 0 : outputFile.close();
205 :
206 : return;
207 0 : }
208 :
209 : //____________________________________________________________________________
210 : void AliEMCALCalibReference::ReadRootCalibReferenceInfo(const TString &rootFileName,
211 : Bool_t swapSides)
212 : {
213 : //Read data from root file. ; coordinates given on SuperModule basis
214 0 : TFile inputFile(rootFileName, "read");
215 :
216 0 : TTree *tree = (TTree*) inputFile.Get("tree");
217 :
218 0 : ReadTreeCalibReferenceInfo(tree, swapSides);
219 :
220 0 : inputFile.Close();
221 :
222 : return;
223 0 : }
224 :
225 : //____________________________________________________________________________
226 : void AliEMCALCalibReference::ReadTreeCalibReferenceInfo(TTree *tree,
227 : Bool_t swapSides)
228 : {
229 : // how many SuperModule's worth of info do we have?
230 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
231 0 : fNSuperModule = tree->GetEntries();
232 :
233 0 : Int_t iSM = 0; // SuperModule index
234 : // list of values to be read
235 : // first: overall values for the whole SuperModule
236 0 : Int_t iReferenceTime= 0;
237 : // second: additional info for LED Reference and SM temperature
238 0 : Float_t rLEDRefAmp[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
239 0 : Float_t rLEDRefAmpRMS[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
240 0 : Int_t iLEDRefHighLow[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
241 0 : Float_t temperature[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
242 0 : Float_t temperatureRMS[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
243 : // third: info for each tower
244 0 : Int_t iHighLow[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
245 0 : Float_t rLEDAmp[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
246 0 : Float_t rLEDAmpRMS[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
247 : // end - all values
248 :
249 : // just to make the initializations of the arrays are done correctly, let's use memset
250 0 : memset(rLEDRefAmp, 0, sizeof(rLEDRefAmp));
251 0 : memset(rLEDRefAmpRMS, 0, sizeof(rLEDRefAmpRMS));
252 0 : memset(iLEDRefHighLow, 0, sizeof(iLEDRefHighLow));
253 0 : memset(temperature, 0, sizeof(temperature));
254 0 : memset(temperatureRMS, 0, sizeof(temperatureRMS));
255 0 : memset(iHighLow, 0, sizeof(iHighLow));
256 0 : memset(rLEDAmp, 0, sizeof(rLEDAmp));
257 0 : memset(rLEDAmpRMS, 0, sizeof(rLEDAmpRMS));
258 :
259 : // declare the branches
260 0 : tree->SetBranchAddress("iSM", &iSM);
261 0 : tree->SetBranchAddress("ReferenceTime", &iReferenceTime);
262 : //
263 0 : tree->SetBranchAddress("LEDRefAmp", rLEDRefAmp);
264 0 : tree->SetBranchAddress("LEDRefAmpRMS", rLEDRefAmpRMS);
265 0 : tree->SetBranchAddress("LEDRefHighLow", iLEDRefHighLow);
266 0 : tree->SetBranchAddress("Temperature", temperature);
267 0 : tree->SetBranchAddress("TemperatureRMS", temperatureRMS);
268 : //
269 0 : tree->SetBranchAddress("HighLow", iHighLow);
270 0 : tree->SetBranchAddress("LEDAmp", rLEDAmp);
271 0 : tree->SetBranchAddress("LEDAmpRMS", rLEDAmpRMS);
272 :
273 : // indices for looping over the towers
274 : Int_t iCol = 0;
275 : Int_t iRow = 0;
276 :
277 0 : for (int ient=0; ient<tree->GetEntries(); ient++) {
278 0 : tree->GetEntry(ient);
279 :
280 : // assume the index SuperModules come in order: i=iSM
281 0 : AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[iSM];
282 :
283 0 : t->SetSuperModuleNum(iSM);
284 : // first, overall values
285 0 : t->SetReferenceTime(iReferenceTime);
286 :
287 : // second: additional info for LED references and SM temperatures
288 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
289 0 : t->SetLEDRefAmp(j, rLEDRefAmp[j]);
290 0 : t->SetLEDRefAmpRMS(j, rLEDRefAmpRMS[j]);
291 0 : t->SetLEDRefHighLow(j, iLEDRefHighLow[j]);
292 : }
293 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
294 0 : t->SetTemperature(j, temperature[j]);
295 0 : t->SetTemperatureRMS(j, temperatureRMS[j]);
296 : }
297 :
298 : // third: info for each tower
299 0 : for (Int_t j=0; j<nAPDPerSM; j++) {
300 0 : iCol = j / AliEMCALGeoParams::fgkEMCALRows;
301 0 : iRow = j % AliEMCALGeoParams::fgkEMCALRows;
302 :
303 : // help variables: possibly modified or swapped indices
304 : int iColMod = iCol;
305 : int iRowMod = iRow;
306 : // assume that this info is already swapped and done for this basis?
307 0 : if (swapSides) {
308 : // C side, oriented differently than A side: swap is requested
309 0 : iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
310 0 : iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
311 0 : }
312 :
313 0 : AliEMCALCalibReferenceVal * v = t->GetAPDVal(iColMod, iRowMod);
314 :
315 0 : v->SetHighLow(iHighLow[iCol][iRow]);
316 0 : v->SetLEDAmp(rLEDAmp[iCol][iRow]);
317 0 : v->SetLEDAmpRMS(rLEDAmpRMS[iCol][iRow]);
318 : }
319 :
320 : } // loop over entries
321 :
322 : return;
323 0 : }
324 :
325 : //____________________________________________________________________________
326 : void AliEMCALCalibReference::WriteRootCalibReferenceInfo(const TString &rootFileName,
327 : Bool_t swapSides)
328 : {
329 : // write data to root file. ; coordinates given on SuperModule basis
330 0 : TFile destFile(rootFileName, "recreate");
331 0 : if (destFile.IsZombie()) {
332 0 : return;
333 : }
334 0 : destFile.cd();
335 :
336 0 : TTree *tree = new TTree("tree","");
337 :
338 : // variables for filling the TTree
339 0 : Int_t iSM = 0; // SuperModule index
340 : // list of values to be written
341 : // first: overall values for the whole SuperModule
342 0 : Int_t iReferenceTime = 0;
343 : // second: additional info for LED Reference and SM temperature
344 0 : Float_t rLEDRefAmp[AliEMCALGeoParams::fgkEMCALLEDRefs] = {0};
345 0 : Float_t rLEDRefAmpRMS[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
346 0 : Int_t iLEDRefHighLow[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
347 0 : Float_t temperature[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
348 0 : Float_t temperatureRMS[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
349 : // third: info for each tower
350 0 : Int_t iHighLow[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
351 0 : Float_t rLEDAmp[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
352 0 : Float_t rLEDAmpRMS[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
353 : // end - all values
354 :
355 : // just to make the initializations of the arrays are done correctly, let's use memset
356 0 : memset(rLEDRefAmp, 0, sizeof(rLEDRefAmp));
357 0 : memset(rLEDRefAmpRMS, 0, sizeof(rLEDRefAmpRMS));
358 0 : memset(iLEDRefHighLow, 0, sizeof(iLEDRefHighLow));
359 0 : memset(temperature, 0, sizeof(temperature));
360 0 : memset(temperatureRMS, 0, sizeof(temperatureRMS));
361 0 : memset(iHighLow, 0, sizeof(iHighLow));
362 0 : memset(rLEDAmp, 0, sizeof(rLEDAmp));
363 0 : memset(rLEDAmpRMS, 0, sizeof(rLEDAmpRMS));
364 :
365 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
366 : // for looping over towers
367 : Int_t iCol = 0;
368 : Int_t iRow = 0;
369 :
370 : // declare the branches
371 : // first
372 0 : tree->Branch("iSM", &iSM, "iSM/I");
373 0 : tree->Branch("ReferenceTime", &iReferenceTime, "ReferenceTime/I");
374 : // second
375 0 : tree->Branch( "LEDRefAmp", &rLEDRefAmp, Form("LEDRefAmp[%d]/F", AliEMCALGeoParams::fgkEMCALLEDRefs) );
376 0 : tree->Branch( "LEDRefAmpRMS", &rLEDRefAmpRMS, Form("LEDRefAmpRMS[%d]/F", AliEMCALGeoParams::fgkEMCALLEDRefs) );
377 0 : tree->Branch( "LEDRefHighLow", &iLEDRefHighLow, Form("LEDRefHighLow[%d]/I", AliEMCALGeoParams::fgkEMCALLEDRefs) );
378 0 : tree->Branch( "Temperature", &temperature, Form("Temperature[%d]/F", AliEMCALGeoParams::fgkEMCALTempSensors) );
379 0 : tree->Branch( "TemperatureRMS", &temperatureRMS, Form("TemperatureRMS[%d]/F", AliEMCALGeoParams::fgkEMCALTempSensors) );
380 : // third: info for each tower; see if a 2D array works OK or if we'll have to use 1D arrays instead
381 0 : tree->Branch( "HighLow", &iHighLow, Form("HighLow[%d][%d]/I", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
382 0 : tree->Branch( "LEDAmp", &rLEDAmp, Form("LEDAmp[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
383 0 : tree->Branch( "LEDAmpRMS", &rLEDAmpRMS, Form("LEDAmpRMS[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
384 :
385 0 : for (iSM = 0; iSM < fNSuperModule; iSM++) {
386 0 : AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[iSM];
387 :
388 0 : iSM = t->GetSuperModuleNum();
389 : // first, overall values
390 0 : iReferenceTime = t->GetReferenceTime();
391 :
392 : // second: additional info for LED references and SM temperatures
393 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
394 0 : rLEDRefAmp[j] = t->GetLEDRefAmp(j);
395 0 : rLEDRefAmpRMS[j] = t->GetLEDRefAmpRMS(j);
396 0 : iLEDRefHighLow[j] = t->GetLEDRefHighLow(j);
397 : }
398 0 : for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
399 0 : temperature[j] = t->GetTemperature(j);
400 0 : temperatureRMS[j] = t->GetTemperatureRMS(j);
401 : }
402 :
403 : // third: info for each tower
404 0 : for (Int_t j=0; j<nAPDPerSM; j++) {
405 0 : iCol = j / AliEMCALGeoParams::fgkEMCALRows;
406 0 : iRow = j % AliEMCALGeoParams::fgkEMCALRows;
407 :
408 : // help variables: possibly modified or swapped indices
409 : int iColMod = iCol;
410 : int iRowMod = iRow;
411 : // assume that this info is already swapped and done for this basis?
412 0 : if (swapSides) {
413 : // C side, oriented differently than A side: swap is requested
414 0 : iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
415 0 : iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
416 0 : }
417 :
418 0 : AliEMCALCalibReferenceVal * v = t->GetAPDVal(iCol, iRow);
419 :
420 0 : iHighLow[iColMod][iRowMod] = v->GetHighLow();
421 0 : rLEDAmp[iColMod][iRowMod] = v->GetLEDAmp();
422 0 : rLEDAmpRMS[iColMod][iRowMod] = v->GetLEDAmpRMS();
423 : }
424 :
425 0 : tree->Fill();
426 : } // i, SuperModule
427 :
428 0 : tree->Write();
429 0 : destFile.Close();
430 :
431 : return;
432 0 : }
433 :
434 : //____________________________________________________________________________
435 : AliEMCALCalibReference::~AliEMCALCalibReference()
436 0 : {
437 0 : fSuperModuleData.Delete();
438 0 : }
439 :
440 : //____________________________________________________________________________
441 : AliEMCALSuperModuleCalibReference * AliEMCALCalibReference::GetSuperModuleCalibReferenceNum(Int_t supModIndex)const
442 : { // getter via index
443 0 : for (int i=0; i<fNSuperModule; i++) {
444 0 : AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[i];
445 0 : if (t->GetSuperModuleNum() == supModIndex) {
446 0 : return t;
447 : }
448 0 : }
449 :
450 : // if we arrived here, then nothing was found.. just return a NULL pointer
451 0 : return NULL;
452 0 : }
453 :
|