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 info on APD calibration and map info
19 : //
20 :
21 : #include <fstream>
22 : #include <TString.h>
23 : #include <TFile.h>
24 : #include <TTree.h>
25 :
26 : #include "AliEMCALCalibMapAPD.h"
27 :
28 : using namespace std;
29 :
30 42 : ClassImp(AliEMCALCalibMapAPD)
31 :
32 : //____________________________________________________________________________
33 0 : AliEMCALCalibMapAPD::AliEMCALCalibMapAPD(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 AliEMCALSuperModuleCalibMapAPD(i));
40 : }
41 0 : fSuperModuleData.Compress(); // compress the TObjArray
42 0 : fSuperModuleData.SetOwner(kTRUE);
43 0 : }
44 :
45 : //____________________________________________________________________________
46 : void AliEMCALCalibMapAPD::ReadTextCalibMapAPDInfo(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("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - 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 : // list of values to be read
63 0 : Int_t iHW = 0;
64 0 : Int_t iAPDNum = 0;
65 0 : Float_t v30 = 0;
66 0 : Float_t par[3] = {0};
67 0 : Float_t parErr[3] = {0};
68 0 : Int_t iBreakDown = 0;
69 0 : Float_t darkCurrent = 0;
70 : // end - all values
71 :
72 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
73 :
74 0 : for (Int_t i = 0; i < fNSuperModule; i++) {
75 0 : AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
76 0 : if (!inputFile) {
77 0 : printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Error while reading input file; likely EOF..\n");
78 0 : return;
79 : }
80 0 : inputFile >> iSM;
81 0 : t->SetSuperModuleNum(iSM);
82 :
83 0 : for (Int_t j=0; j<nAPDPerSM; j++) {
84 0 : inputFile >> iCol >> iRow >> iHW
85 0 : >> iAPDNum >> v30
86 0 : >> par[0] >> par[1] >> par[2]
87 0 : >> parErr[0] >> parErr[1] >> parErr[2]
88 0 : >> iBreakDown >> darkCurrent;
89 :
90 : // check that input values are not out bounds
91 0 : if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) ||
92 0 : iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) ) {
93 0 : printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Error while reading input file; j %d iCol %d iRow %d\n", j, iCol, iRow);
94 0 : return;
95 : }
96 :
97 : // assume that this info is already swapped and done for this basis?
98 0 : if (swapSides) {
99 : // C side, oriented differently than A side: swap is requested
100 0 : iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
101 0 : iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
102 0 : }
103 :
104 0 : AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
105 :
106 0 : v->SetHardWareId(iHW);
107 0 : v->SetAPDNum(iAPDNum);
108 0 : v->SetV30(v30);
109 0 : v->SetPar(0, par[0]);
110 0 : v->SetPar(1, par[1]);
111 0 : v->SetPar(2, par[2]);
112 0 : v->SetParErr(0, parErr[0]);
113 0 : v->SetParErr(1, parErr[1]);
114 0 : v->SetParErr(2, parErr[2]);
115 0 : v->SetBreakDown(iBreakDown);
116 0 : v->SetDarkCurrent(darkCurrent);
117 : }
118 :
119 0 : } // i, SuperModule
120 :
121 0 : inputFile.close();
122 :
123 0 : return;
124 0 : }
125 :
126 : //____________________________________________________________________________
127 : void AliEMCALCalibMapAPD::WriteTextCalibMapAPDInfo(const TString &txtFileName,
128 : Bool_t swapSides)
129 : {
130 : // write data to txt file. ; coordinates given on SuperModule basis
131 :
132 0 : std::ofstream outputFile(txtFileName.Data());
133 0 : if (!outputFile) {
134 0 : printf("AliEMCALCalibMapAPD::WriteCalibMapAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
135 0 : return;
136 : }
137 :
138 : Int_t iCol = 0;
139 : Int_t iRow = 0;
140 :
141 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
142 :
143 0 : for (Int_t i = 0; i < fNSuperModule; i++) {
144 0 : AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
145 0 : outputFile << t->GetSuperModuleNum() << endl;
146 :
147 0 : for (Int_t j=0; j<nAPDPerSM; j++) {
148 0 : iCol = j / AliEMCALGeoParams::fgkEMCALRows;
149 0 : iRow = j % AliEMCALGeoParams::fgkEMCALRows;
150 :
151 0 : AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
152 :
153 0 : if (swapSides) {
154 : // C side, oriented differently than A side: swap is requested
155 0 : iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
156 0 : iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
157 0 : }
158 :
159 0 : outputFile << iCol << " " << iRow << " " << v->GetHardWareId()
160 0 : << " " << v->GetAPDNum() << " " << v->GetV30()
161 0 : << " " << v->GetPar(0) << " " << v->GetPar(1) << " " << v->GetPar(2)
162 0 : << " " << v->GetParErr(0) << " " << v->GetParErr(1) << " " << v->GetParErr(2)
163 0 : << " " << v->GetBreakDown() << " " << v->GetDarkCurrent() << endl;
164 : }
165 :
166 : } // i, SuperModule
167 :
168 0 : outputFile.close();
169 :
170 : return;
171 0 : }
172 :
173 : //____________________________________________________________________________
174 : void AliEMCALCalibMapAPD::ReadRootCalibMapAPDInfo(const TString &rootFileName,
175 : Bool_t swapSides)
176 : {
177 : //Read data from root file. ; coordinates given on SuperModule basis
178 0 : TFile inputFile(rootFileName, "read");
179 :
180 0 : TTree *tree = (TTree*) inputFile.Get("tree");
181 :
182 0 : ReadTreeCalibMapAPDInfo(tree, swapSides);
183 :
184 0 : inputFile.Close();
185 :
186 : return;
187 0 : }
188 :
189 : //____________________________________________________________________________
190 : void AliEMCALCalibMapAPD::ReadTreeCalibMapAPDInfo(TTree *tree,
191 : Bool_t swapSides)
192 : {
193 : // how many SuperModule's worth of entries / APDs do we have?
194 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
195 0 : fNSuperModule = tree->GetEntries() / nAPDPerSM;
196 :
197 0 : Int_t iSM = 0; // SuperModule index
198 0 : Int_t iCol = 0;
199 0 : Int_t iRow = 0;
200 : // list of values to be read
201 0 : Int_t iHW = 0;
202 0 : Int_t iAPDNum = 0;
203 0 : Float_t v30 = 0;
204 0 : Float_t par[3] = {0};
205 0 : Float_t parErr[3] = {0};
206 0 : Int_t iBreakDown = 0;
207 0 : Float_t darkCurrent = 0;
208 : // end - all values
209 :
210 : // declare the branches
211 0 : tree->SetBranchAddress("iSM", &iSM);
212 0 : tree->SetBranchAddress("iCol", &iCol);
213 0 : tree->SetBranchAddress("iRow", &iRow);
214 0 : tree->SetBranchAddress("iHW", &iHW);
215 0 : tree->SetBranchAddress("APDNum", &iAPDNum);
216 0 : tree->SetBranchAddress("V30", &v30);
217 0 : tree->SetBranchAddress("Par", par);
218 0 : tree->SetBranchAddress("ParErr", parErr);
219 0 : tree->SetBranchAddress("BreakDown", &iBreakDown);
220 0 : tree->SetBranchAddress("DarkCurrent", &darkCurrent);
221 :
222 0 : for (int ient=0; ient<tree->GetEntries(); ient++) {
223 0 : tree->GetEntry(ient);
224 :
225 : // assume the index SuperModules come in order: i=iSM
226 0 : AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[iSM];
227 0 : t->SetSuperModuleNum(iSM);
228 :
229 : // assume that this info is already swapped and done for this basis?
230 0 : if (swapSides) {
231 : // C side, oriented differently than A side: swap is requested
232 0 : iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
233 0 : iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
234 0 : }
235 :
236 0 : AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
237 :
238 0 : v->SetHardWareId(iHW);
239 0 : v->SetAPDNum(iAPDNum);
240 0 : v->SetV30(v30);
241 0 : v->SetPar(0, par[0]);
242 0 : v->SetPar(1, par[1]);
243 0 : v->SetPar(2, par[2]);
244 0 : v->SetParErr(0, parErr[0]);
245 0 : v->SetParErr(1, parErr[1]);
246 0 : v->SetParErr(2, parErr[2]);
247 0 : v->SetBreakDown(iBreakDown);
248 0 : v->SetDarkCurrent(darkCurrent);
249 : } //
250 :
251 : return;
252 0 : }
253 :
254 : //____________________________________________________________________________
255 : void AliEMCALCalibMapAPD::WriteRootCalibMapAPDInfo(const TString &rootFileName,
256 : Bool_t swapSides)
257 : {
258 : // write data to root file. ; coordinates given on SuperModule basis
259 0 : TFile destFile(rootFileName, "recreate");
260 0 : if (destFile.IsZombie()) {
261 0 : return;
262 : }
263 0 : destFile.cd();
264 :
265 0 : TTree *tree = new TTree("tree","");
266 :
267 : // variables for filling the TTree
268 0 : Int_t iSM = 0; // SuperModule index
269 0 : Int_t iHW = 0;
270 0 : Int_t iAPDNum = 0;
271 0 : Float_t v30 = 0;
272 0 : Float_t par[3] = {0};
273 0 : Float_t parErr[3] = {0};
274 0 : Int_t iBreakDown = 0;
275 0 : Float_t darkCurrent = 0;
276 : //
277 0 : Int_t iCol = 0;
278 0 : Int_t iRow = 0;
279 : // declare the branches
280 0 : tree->Branch("iSM", &iSM, "iSM/I");
281 0 : tree->Branch("iCol", &iCol, "iCol/I");
282 0 : tree->Branch("iRow", &iRow, "iRow/I");
283 0 : tree->Branch("iHW", &iHW, "iHW/I");
284 0 : tree->Branch("APDNum", &iAPDNum, "APDNum/I");
285 0 : tree->Branch("V30", &v30, "V30/F");
286 0 : tree->Branch("Par", &par, "Par[3]/F");
287 0 : tree->Branch("ParErr", &parErr, "ParErr[3]/F");
288 0 : tree->Branch("BreakDown", &iBreakDown, "BreakDown/I");
289 0 : tree->Branch("DarkCurrent", &darkCurrent, "DarkCurrent/F");
290 :
291 : Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
292 :
293 0 : for (iSM = 0; iSM < fNSuperModule; iSM++) {
294 0 : AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD *) fSuperModuleData[iSM];
295 :
296 0 : for (Int_t j=0; j<nAPDPerSM; j++) {
297 0 : iCol = j / AliEMCALGeoParams::fgkEMCALRows;
298 0 : iRow = j % AliEMCALGeoParams::fgkEMCALRows;
299 :
300 0 : AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
301 :
302 0 : if (swapSides) {
303 : // C side, oriented differently than A side: swap is requested
304 0 : iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
305 0 : iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
306 0 : }
307 :
308 0 : iHW = v->GetHardWareId();
309 0 : iAPDNum = v->GetAPDNum();
310 0 : v30 = v->GetV30();
311 0 : for (int k=0; k<3; k++) {
312 0 : par[k] = v->GetPar(k);
313 0 : parErr[k] = v->GetParErr(k);
314 : }
315 0 : iBreakDown = v->GetBreakDown();
316 0 : darkCurrent = v->GetDarkCurrent();
317 :
318 0 : tree->Fill();
319 : }
320 :
321 : } // i, SuperModule
322 :
323 0 : tree->Write();
324 0 : destFile.Close();
325 :
326 : return;
327 0 : }
328 :
329 : //____________________________________________________________________________
330 : AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD()
331 0 : {
332 0 : fSuperModuleData.Delete();
333 0 : }
334 :
335 : //____________________________________________________________________________
336 : AliEMCALSuperModuleCalibMapAPD * AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const
337 : { // getter via index
338 0 : for (int i=0; i<fNSuperModule; i++) {
339 0 : AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
340 0 : if (t->GetSuperModuleNum() == supModIndex) {
341 0 : return t;
342 : }
343 0 : }
344 :
345 : // if we arrived here, then nothing was found.. just return a NULL pointer
346 0 : return NULL;
347 0 : }
348 :
|