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