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