]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALCalibAbs.cxx
first version of new classes for time-dependent corrections; not yet used in Preproce...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibAbs.cxx
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>
23
24 #include "AliEMCALCalibAbs.h"
25
26 using namespace std;
27
28 ClassImp(AliEMCALCalibAbs)
29
30 //____________________________________________________________________________
31 AliEMCALCalibAbs::AliEMCALCalibAbs() : 
32   fNSuperModule(0),
33   fSuperModuleData(0)
34 {
35   //Default constructor.
36 }
37
38 //____________________________________________________________________________
39 void AliEMCALCalibAbs::ReadCalibAbsInfo(Int_t nSM, const TString &txtFileName,
40                                       Bool_t swapSides)
41 {
42   //Read data from txt file. ; coordinates given on SuperModule basis
43
44   std::ifstream inputFile(txtFileName.Data());
45   if (!inputFile) {
46     printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Cannot open the APD info file %s\n", txtFileName.Data());
47     return;
48   }
49
50   fNSuperModule = nSM;
51   if (fSuperModuleData) delete [] fSuperModuleData;
52   fSuperModuleData = new AliEMCALSuperModuleCalibAbs[fNSuperModule];
53
54   Int_t iSM = 0; // SuperModule index
55   Int_t iCol = 0;
56   Int_t iRow = 0;
57   Int_t id = 0;
58
59   // list of values to be read
60   // first: overall values for the whole SuperModule
61   Int_t CalibMethod; 
62   Int_t CalibPass; 
63   Int_t CalibTime; 
64   Float_t AbsoluteGain; 
65   // second: additional info for LED Reference and SM temperature
66   Float_t LEDRefAmp;
67   Float_t LEDRefAmpRMS;
68   Float_t LEDRefHighLowRatio;
69   Int_t LEDRefHighLow;
70   Float_t Temperature;
71   Float_t TemperatureRMS;
72   // third: info for each tower
73   Float_t RelativeGain; // (ADC>GeV relative gain/conversion), value around 1
74   Float_t HighLowRatio; // value around 16 or so
75   Int_t HighLow; // 
76   Float_t LEDAmp; // low gain eq. amplitude
77   Float_t LEDAmpRMS; //
78   // end - all values
79
80   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
81
82   for (Int_t i = 0; i < fNSuperModule; i++) {
83     AliEMCALSuperModuleCalibAbs &t = fSuperModuleData[i];
84     if (!inputFile) {
85       printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; likely EOF..");
86       return;
87     }
88     inputFile >> iSM;
89     t.fSuperModuleNum = iSM;
90
91     // first: overall values for the whole SuperModule
92     inputFile >> CalibMethod >> CalibPass >> CalibTime >> AbsoluteGain;
93     t.fCalibMethod = CalibMethod;
94     t.fCalibPass = CalibPass;
95     t.fCalibTime = CalibTime;
96     t.fAbsoluteGain = AbsoluteGain;
97
98     // second: additional info for LED Reference and SM temperature
99     for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
100       inputFile >> id >> LEDRefAmp >> LEDRefAmpRMS >> LEDRefHighLowRatio >> LEDRefHighLow;
101       t.fLEDRefAmp[id] = LEDRefAmp;
102       t.fLEDRefAmpRMS[id] = LEDRefAmpRMS;
103       t.fLEDRefHighLowRatio[id] = LEDRefHighLowRatio;
104       t.fLEDRefHighLow[id] = LEDRefHighLow;
105     }
106     for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
107       inputFile >> id >> Temperature >> TemperatureRMS;
108       t.fTemperature[id] = Temperature;
109       t.fTemperatureRMS[id] = TemperatureRMS;
110     }
111
112     // third: info for each tower
113     for (Int_t j=0; j<nAPDPerSM; j++) {
114       inputFile >> iCol >> iRow 
115                 >> RelativeGain >> HighLowRatio >> HighLow >> LEDAmp >> LEDAmpRMS;
116
117       // assume that this info is already swapped and done for this basis?
118       if (swapSides) {
119         // C side, oriented differently than A side: swap is requested
120         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
121         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
122       }
123
124       AliEMCALCalibAbsVal &v = t.fAPDVal[iCol][iRow];
125
126       v.fRelativeGain = RelativeGain;
127       v.fHighLowRatio = HighLowRatio;
128       v.fHighLow = HighLow;
129       v.fLEDAmp = LEDAmp;
130       v.fLEDAmpRMS = LEDAmpRMS;
131     }
132
133   } // i, SuperModule
134
135   inputFile.close();
136
137   return;
138 }
139
140 //____________________________________________________________________________
141 void AliEMCALCalibAbs::WriteCalibAbsInfo(const TString &txtFileName,
142                                        Bool_t swapSides)
143 {
144   // write data to txt file. ; coordinates given on SuperModule basis
145
146   std::ofstream outputFile(txtFileName.Data());
147   if (!outputFile) {
148     printf("AliEMCALCalibAbs::WriteCalibAbsInfo - Cannot open the APD output file %s\n", txtFileName.Data());
149     return;
150   }
151
152   Int_t iCol = 0;
153   Int_t iRow = 0;
154
155   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
156
157   for (Int_t i = 0; i < fNSuperModule; i++) {
158     AliEMCALSuperModuleCalibAbs &t = fSuperModuleData[i];
159     // first: overall values for the whole SuperModule
160     outputFile << t.fSuperModuleNum << endl;
161     outputFile << t.fCalibMethod << " " 
162                << t.fCalibPass << " " 
163                << t.fCalibTime << " " 
164                << t.fAbsoluteGain << endl;
165
166     // second: additional info for LED Reference and SM temperature
167     for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
168       outputFile << j << " " << t.fLEDRefAmp[j] << " " << t.fLEDRefAmpRMS[j] 
169                  << " " << t.fLEDRefHighLowRatio[j] << " " << t.fLEDRefHighLow[j] 
170                  << endl;
171     }
172     for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
173       outputFile << j << " " << t.fTemperature[j] << " " << t.fTemperatureRMS[j] << endl;
174     }
175
176     for (Int_t j=0; j<nAPDPerSM; j++) {
177       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
178       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
179
180       AliEMCALCalibAbsVal &v = t.fAPDVal[iCol][iRow];
181
182       if (swapSides) {
183         // C side, oriented differently than A side: swap is requested
184         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
185         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
186       }
187
188       outputFile << iCol << " " << iRow 
189                  << " " << v.fRelativeGain
190                  << " " << v.fHighLowRatio 
191                  << " " << v.fHighLow 
192                  << " " << v.fLEDAmp 
193                  << " " << v.fLEDAmpRMS << endl;
194     }
195
196   } // i, SuperModule
197
198   outputFile.close();
199
200   return;
201 }
202
203 //____________________________________________________________________________
204 AliEMCALCalibAbs::~AliEMCALCalibAbs()
205 {
206   delete [] fSuperModuleData;
207 }
208
209 //____________________________________________________________________________
210 AliEMCALCalibAbs::AliEMCALSuperModuleCalibAbs AliEMCALCalibAbs::GetSuperModuleCalibAbsId(Int_t supModIndex)const
211 {
212   AliEMCALSuperModuleCalibAbs t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
213   if (!fSuperModuleData)
214     return t;
215
216   return fSuperModuleData[supModIndex];
217 }
218
219 //____________________________________________________________________________
220 AliEMCALCalibAbs::AliEMCALSuperModuleCalibAbs AliEMCALCalibAbs::GetSuperModuleCalibAbsNum(Int_t supModIndex)const
221 {
222   AliEMCALSuperModuleCalibAbs t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
223   if (!fSuperModuleData)
224     return t;
225
226   for (int i=0; i<fNSuperModule; i++) {
227     if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
228       return fSuperModuleData[i];
229     }
230   }
231
232   return t;
233 }
234