1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Objects of this class contain basis for reference calibrations
26 #include "AliEMCALCalibReference.h"
30 ClassImp(AliEMCALCalibReference)
32 //____________________________________________________________________________
33 AliEMCALCalibReference::AliEMCALCalibReference(const int nSM) :
37 //Default constructor.
38 for (int i=0; i<fNSuperModule; i++) {
39 fSuperModuleData.Add(new AliEMCALSuperModuleCalibReference(i));
41 fSuperModuleData.Compress(); // compress the TObjArray
44 //____________________________________________________________________________
45 void AliEMCALCalibReference::ReadTextCalibReferenceInfo(Int_t nSM, const TString &txtFileName,
48 //Read data from txt file. ; coordinates given on SuperModule basis
50 std::ifstream inputFile(txtFileName.Data());
52 printf("AliEMCALCalibReference::ReadCalibReferenceInfo - Cannot open the APD info file %s\n", txtFileName.Data());
58 Int_t iSM = 0; // SuperModule index
63 // list of values to be read
64 // first: overall values for the whole SuperModule
66 // second: additional info for LED Reference and SM temperature
71 Float_t TemperatureRMS;
72 // third: info for each tower
74 Float_t LEDAmp; // low gain eq. amplitude
78 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
80 for (Int_t i = 0; i < fNSuperModule; i++) {
81 AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[i];
83 printf("AliEMCALCalibReference::ReadCalibReferenceInfo - Error while reading input file; likely EOF..");
87 t->SetSuperModuleNum(iSM);
89 // first: overall values for the whole SuperModule
90 inputFile >> ReferenceTime;
91 t->SetReferenceTime(ReferenceTime);
93 // second: additional info for LED Reference and SM temperature
94 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
95 inputFile >> id >> LEDRefHighLow >> LEDRefAmp >> LEDRefAmpRMS;
96 t->SetLEDRefHighLow(id, LEDRefHighLow);
97 t->SetLEDRefAmp(id, LEDRefAmp);
98 t->SetLEDRefAmpRMS(id, LEDRefAmpRMS);
100 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
101 inputFile >> id >> Temperature >> TemperatureRMS;
102 t->SetTemperature(id, Temperature);
103 t->SetTemperatureRMS(id, TemperatureRMS);
106 // third: info for each tower
107 for (Int_t j=0; j<nAPDPerSM; j++) {
108 inputFile >> iCol >> iRow
109 >> HighLow >> LEDAmp >> LEDAmpRMS;
111 // assume that this info is already swapped and done for this basis?
113 // C side, oriented differently than A side: swap is requested
114 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
115 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
118 AliEMCALCalibReferenceVal * v = t->GetAPDVal(iCol, iRow);
120 v->SetHighLow(HighLow);
121 v->SetLEDAmp(LEDAmp);
122 v->SetLEDAmpRMS(LEDAmpRMS);
132 //____________________________________________________________________________
133 void AliEMCALCalibReference::WriteTextCalibReferenceInfo(const TString &txtFileName,
136 // write data to txt file. ; coordinates given on SuperModule basis
138 std::ofstream outputFile(txtFileName.Data());
140 printf("AliEMCALCalibReference::WriteCalibReferenceInfo - Cannot open the APD output file %s\n", txtFileName.Data());
147 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
149 for (Int_t i = 0; i < fNSuperModule; i++) {
150 AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[i];
152 // first: overall values for the whole SuperModule
153 outputFile << t->GetSuperModuleNum() << endl;
154 outputFile << t->GetReferenceTime() << endl;
156 // second: additional info for LED Reference and SM temperature
157 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
158 outputFile << j << " " << t->GetLEDRefHighLow(j)
159 << " " << t->GetLEDRefAmp(j) << " " << t->GetLEDRefAmpRMS(j)
162 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
163 outputFile << j << " " << t->GetTemperature(j) << " " << t->GetTemperatureRMS(j) << endl;
166 // third: info for each tower
167 for (Int_t j=0; j<nAPDPerSM; j++) {
168 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
169 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
171 AliEMCALCalibReferenceVal * v = t->GetAPDVal(iCol, iRow);
174 // C side, oriented differently than A side: swap is requested
175 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
176 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
179 outputFile << iCol << " " << iRow
180 << " " << v->GetHighLow()
181 << " " << v->GetLEDAmp()
182 << " " << v->GetLEDAmpRMS() << endl;
192 //____________________________________________________________________________
193 void AliEMCALCalibReference::ReadRootCalibReferenceInfo(const TString &rootFileName,
196 //Read data from root file. ; coordinates given on SuperModule basis
197 TFile inputFile(rootFileName, "read");
199 TTree *tree = (TTree*) inputFile.Get("tree");
201 ReadTreeCalibReferenceInfo(tree, swapSides);
208 //____________________________________________________________________________
209 void AliEMCALCalibReference::ReadTreeCalibReferenceInfo(TTree *tree,
212 // how many SuperModule's worth of info do we have?
213 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
214 fNSuperModule = tree->GetEntries();
216 Int_t iSM = 0; // SuperModule index
217 // list of values to be read
218 // first: overall values for the whole SuperModule
219 Int_t ReferenceTime= {0};
220 // second: additional info for LED Reference and SM temperature
221 Float_t LEDRefAmp[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
222 Float_t LEDRefAmpRMS[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
223 Int_t LEDRefHighLow[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
224 Float_t Temperature[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
225 Float_t TemperatureRMS[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
226 // third: info for each tower
227 Int_t HighLow[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
228 Float_t LEDAmp[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
229 Float_t LEDAmpRMS[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
232 // just to make the initializations of the arrays are done correctly, let's use memset
233 memset(LEDRefAmp, 0, sizeof(LEDRefAmp));
234 memset(LEDRefAmpRMS, 0, sizeof(LEDRefAmpRMS));
235 memset(LEDRefHighLow, 0, sizeof(LEDRefHighLow));
236 memset(Temperature, 0, sizeof(Temperature));
237 memset(TemperatureRMS, 0, sizeof(TemperatureRMS));
238 memset(HighLow, 0, sizeof(HighLow));
239 memset(LEDAmp, 0, sizeof(LEDAmp));
240 memset(LEDAmpRMS, 0, sizeof(LEDAmpRMS));
242 // declare the branches
243 tree->SetBranchAddress("iSM", &iSM);
244 tree->SetBranchAddress("ReferenceTime", &ReferenceTime);
246 tree->SetBranchAddress("LEDRefAmp", LEDRefAmp);
247 tree->SetBranchAddress("LEDRefAmpRMS", LEDRefAmpRMS);
248 tree->SetBranchAddress("LEDRefHighLow", LEDRefHighLow);
249 tree->SetBranchAddress("Temperature", Temperature);
250 tree->SetBranchAddress("TemperatureRMS", TemperatureRMS);
252 tree->SetBranchAddress("HighLow", HighLow);
253 tree->SetBranchAddress("LEDAmp", LEDAmp);
254 tree->SetBranchAddress("LEDAmpRMS", LEDAmpRMS);
256 // indices for looping over the towers
260 for (int ient=0; ient<tree->GetEntries(); ient++) {
261 tree->GetEntry(ient);
263 // assume the index SuperModules come in order: i=iSM
264 AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[iSM];
266 t->SetSuperModuleNum(iSM);
267 // first, overall values
268 t->SetReferenceTime(ReferenceTime);
270 // second: additional info for LED references and SM temperatures
271 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
272 t->SetLEDRefAmp(j, LEDRefAmp[j]);
273 t->SetLEDRefAmpRMS(j, LEDRefAmpRMS[j]);
274 t->SetLEDRefHighLow(j, LEDRefHighLow[j]);
276 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
277 t->SetTemperature(j, Temperature[j]);
278 t->SetTemperatureRMS(j, TemperatureRMS[j]);
281 // third: info for each tower
282 for (Int_t j=0; j<nAPDPerSM; j++) {
283 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
284 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
286 // help variables: possibly modified or swapped indices
289 // assume that this info is already swapped and done for this basis?
291 // C side, oriented differently than A side: swap is requested
292 iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
293 iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
296 AliEMCALCalibReferenceVal * v = t->GetAPDVal(iColMod, iRowMod);
298 v->SetHighLow(HighLow[iCol][iRow]);
299 v->SetLEDAmp(LEDAmp[iCol][iRow]);
300 v->SetLEDAmpRMS(LEDAmpRMS[iCol][iRow]);
303 } // loop over entries
308 //____________________________________________________________________________
309 void AliEMCALCalibReference::WriteRootCalibReferenceInfo(const TString &rootFileName,
312 // write data to root file. ; coordinates given on SuperModule basis
313 TFile destFile(rootFileName, "recreate");
314 if (destFile.IsZombie()) {
319 TTree *tree = new TTree("tree","");
321 // variables for filling the TTree
322 Int_t iSM = 0; // SuperModule index
323 // list of values to be written
324 // first: overall values for the whole SuperModule
325 Int_t ReferenceTime = 0;
326 // second: additional info for LED Reference and SM temperature
327 Float_t LEDRefAmp[AliEMCALGeoParams::fgkEMCALLEDRefs] = {0};
328 Float_t LEDRefAmpRMS[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
329 Int_t LEDRefHighLow[AliEMCALGeoParams::fgkEMCALLEDRefs]= {0};
330 Float_t Temperature[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
331 Float_t TemperatureRMS[AliEMCALGeoParams::fgkEMCALTempSensors]= {0};
332 // third: info for each tower
333 Int_t HighLow[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
334 Float_t LEDAmp[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
335 Float_t LEDAmpRMS[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
338 // just to make the initializations of the arrays are done correctly, let's use memset
339 memset(LEDRefAmp, 0, sizeof(LEDRefAmp));
340 memset(LEDRefAmpRMS, 0, sizeof(LEDRefAmpRMS));
341 memset(LEDRefHighLow, 0, sizeof(LEDRefHighLow));
342 memset(Temperature, 0, sizeof(Temperature));
343 memset(TemperatureRMS, 0, sizeof(TemperatureRMS));
344 memset(HighLow, 0, sizeof(HighLow));
345 memset(LEDAmp, 0, sizeof(LEDAmp));
346 memset(LEDAmpRMS, 0, sizeof(LEDAmpRMS));
348 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
349 // for looping over towers
353 // declare the branches
355 tree->Branch("iSM", &iSM, "iSM/I");
356 tree->Branch("ReferenceTime", &ReferenceTime, "ReferenceTime/I");
358 tree->Branch( "LEDRefAmp", &LEDRefAmp, Form("LEDRefAmp[%d]/F", AliEMCALGeoParams::fgkEMCALLEDRefs) );
359 tree->Branch( "LEDRefAmpRMS", &LEDRefAmpRMS, Form("LEDRefAmpRMS[%d]/F", AliEMCALGeoParams::fgkEMCALLEDRefs) );
360 tree->Branch( "LEDRefHighLow", &LEDRefHighLow, Form("LEDRefHighLow[%d]/I", AliEMCALGeoParams::fgkEMCALLEDRefs) );
361 tree->Branch( "Temperature", &Temperature, Form("Temperature[%d]/F", AliEMCALGeoParams::fgkEMCALTempSensors) );
362 tree->Branch( "TemperatureRMS", &TemperatureRMS, Form("TemperatureRMS[%d]/F", AliEMCALGeoParams::fgkEMCALTempSensors) );
363 // third: info for each tower; see if a 2D array works OK or if we'll have to use 1D arrays instead
364 tree->Branch( "HighLow", &HighLow, Form("HighLow[%d][%d]/I", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
365 tree->Branch( "LEDAmp", &LEDAmp, Form("LEDAmp[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
366 tree->Branch( "LEDAmpRMS", &LEDAmpRMS, Form("LEDAmpRMS[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
368 for (iSM = 0; iSM < fNSuperModule; iSM++) {
369 AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[iSM];
371 iSM = t->GetSuperModuleNum();
372 // first, overall values
373 ReferenceTime = t->GetReferenceTime();
375 // second: additional info for LED references and SM temperatures
376 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
377 LEDRefAmp[j] = t->GetLEDRefAmp(j);
378 LEDRefAmpRMS[j] = t->GetLEDRefAmpRMS(j);
379 LEDRefHighLow[j] = t->GetLEDRefHighLow(j);
381 for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
382 Temperature[j] = t->GetTemperature(j);
383 TemperatureRMS[j] = t->GetTemperatureRMS(j);
386 // third: info for each tower
387 for (Int_t j=0; j<nAPDPerSM; j++) {
388 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
389 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
391 // help variables: possibly modified or swapped indices
394 // assume that this info is already swapped and done for this basis?
396 // C side, oriented differently than A side: swap is requested
397 iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
398 iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
401 AliEMCALCalibReferenceVal * v = t->GetAPDVal(iCol, iRow);
403 HighLow[iColMod][iRowMod] = v->GetHighLow();
404 LEDAmp[iColMod][iRowMod] = v->GetLEDAmp();
405 LEDAmpRMS[iColMod][iRowMod] = v->GetLEDAmpRMS();
417 //____________________________________________________________________________
418 AliEMCALCalibReference::~AliEMCALCalibReference()
420 fSuperModuleData.Delete();
423 //____________________________________________________________________________
424 AliEMCALSuperModuleCalibReference * AliEMCALCalibReference::GetSuperModuleCalibReferenceNum(Int_t supModIndex)const
426 for (int i=0; i<fNSuperModule; i++) {
427 AliEMCALSuperModuleCalibReference * t = (AliEMCALSuperModuleCalibReference*) fSuperModuleData[i];
428 if (t->GetSuperModuleNum() == supModIndex) {
433 // if we arrived here, then nothing was found.. just return a NULL pointer