]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALCalibAbs.cxx
Reordering cuts to go faster
[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 #include <TFile.h>
24 #include <TTree.h>
25
26 #include "AliEMCALCalibAbs.h"
27
28 using namespace std;
29
30 ClassImp(AliEMCALCalibAbs)
31
32 //____________________________________________________________________________
33 AliEMCALCalibAbs::AliEMCALCalibAbs(const int nSM) : 
34   fNSuperModule(nSM),
35   fSuperModuleData()
36 {
37   //Default constructor.
38   for (int i=0; i<fNSuperModule; i++) {
39     fSuperModuleData.Add(new AliEMCALSuperModuleCalibAbs(i));
40   }
41   fSuperModuleData.Compress(); // compress the TObjArray
42   fSuperModuleData.SetOwner(kTRUE); 
43 }
44
45 //____________________________________________________________________________
46 void AliEMCALCalibAbs::ReadTextCalibAbsInfo(Int_t nSM, const TString &txtFileName,
47                                             Bool_t swapSides)
48 {
49   //Read data from txt file. ; coordinates given on SuperModule basis
50
51   std::ifstream inputFile(txtFileName.Data());
52   if (!inputFile) {
53     printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Cannot open the APD info file %s\n", txtFileName.Data());
54     return;
55   }
56
57   fNSuperModule = nSM;
58
59   Int_t iSM = 0; // SuperModule index
60   Int_t iCol = 0;
61   Int_t iRow = 0;
62
63   // list of values to be read
64   // first: overall values for the whole SuperModule
65   Int_t iCalibMethod = 0; 
66   Int_t iCalibPass = 0; 
67   Float_t absoluteCalib = 0; 
68   // third: info for each tower
69   Float_t relativeCalib = 0; // (ADC>GeV relative gain/conversion), value around 1
70   // end - all values
71
72   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
73
74   for (Int_t i = 0; i < fNSuperModule; i++) {
75     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
76     if (!inputFile) {
77       printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; likely EOF..\n");
78       return;
79     }
80     inputFile >> iSM;
81     t->SetSuperModuleNum(iSM);
82
83     // first: overall values for the whole SuperModule
84     inputFile >> iCalibMethod >> iCalibPass >> absoluteCalib;
85     t->SetCalibMethod(iCalibMethod);
86     t->SetCalibPass(iCalibPass);
87     t->SetAbsoluteCalib(absoluteCalib);
88
89     // third: info for each tower
90     for (Int_t j=0; j<nAPDPerSM; j++) {
91       inputFile >> iCol >> iRow >> relativeCalib;
92
93       // check that input values are not out bounds
94       if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) ||
95           iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) ) {
96         printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; j %d iCol %d iRow %d\n", j, iCol, iRow);
97       return;
98       }
99
100       // assume that this info is already swapped and done for this basis?
101       if (swapSides) {
102         // C side, oriented differently than A side: swap is requested
103         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
104         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
105       }
106
107       t->SetRelativeCalib(iCol, iRow, relativeCalib);
108     }
109
110   } // i, SuperModule
111
112   inputFile.close();
113
114   return;
115 }
116
117 //____________________________________________________________________________
118 void AliEMCALCalibAbs::WriteTextCalibAbsInfo(const TString &txtFileName,
119                                              Bool_t swapSides)
120 {
121   // write data to txt file. ; coordinates given on SuperModule basis
122
123   std::ofstream outputFile(txtFileName.Data());
124   if (!outputFile) {
125     printf("AliEMCALCalibAbs::WriteCalibAbsInfo - Cannot open the APD output file %s\n", txtFileName.Data());
126     return;
127   }
128
129   Int_t iCol = 0;
130   Int_t iRow = 0;
131
132   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
133   Float_t relativeCalib = 0;
134   for (Int_t i = 0; i < fNSuperModule; i++) {
135     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
136
137     // first: overall values for the whole SuperModule
138     outputFile << t->GetSuperModuleNum() << endl;
139     outputFile << t->GetCalibMethod() << " " 
140                << t->GetCalibPass() << " " 
141                << t->GetAbsoluteCalib() << endl;
142
143     // third: info for each tower
144     for (Int_t j=0; j<nAPDPerSM; j++) {
145       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
146       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
147
148       relativeCalib = t->GetRelativeCalib(iCol, iRow);
149
150       if (swapSides) {
151         // C side, oriented differently than A side: swap is requested
152         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
153         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
154       }
155
156       outputFile << iCol << " " << iRow 
157                  << " " << relativeCalib << endl;
158     }
159
160   } // i, SuperModule
161
162   outputFile.close();
163
164   return;
165 }
166
167 //____________________________________________________________________________
168 void AliEMCALCalibAbs::ReadRootCalibAbsInfo(const TString &rootFileName,
169                                             Bool_t swapSides)
170 {
171   //Read data from root file. ; coordinates given on SuperModule basis
172   TFile inputFile(rootFileName, "read");  
173
174   TTree *tree = (TTree*) inputFile.Get("tree");
175
176   ReadTreeCalibAbsInfo(tree, swapSides);
177
178   inputFile.Close();
179
180   return;
181 }
182
183 //____________________________________________________________________________
184 void AliEMCALCalibAbs::ReadTreeCalibAbsInfo(TTree *tree,
185                                             Bool_t swapSides)
186 {
187   // how many SuperModule's worth of info do we have?
188   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
189   fNSuperModule = tree->GetEntries();
190
191   Int_t iSM = 0; // SuperModule index
192   // list of values to be read
193   // first: overall values for the whole SuperModule
194   Int_t iCalibMethod = 0; 
195   Int_t iCalibPass = 0; 
196   Float_t absoluteCalib = 0; 
197   // third: info for each tower
198   Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows]; 
199   // end - all values
200
201   // just to make the initializations of the arrays are done correctly, let's use memset
202   memset(relativeCalib, 0, sizeof(relativeCalib)); 
203
204   // declare the branches
205   tree->SetBranchAddress("iSM", &iSM);
206   tree->SetBranchAddress("CalibMethod", &iCalibMethod);
207   tree->SetBranchAddress("CalibPass", &iCalibPass);
208   tree->SetBranchAddress("AbsoluteCalib", &absoluteCalib);
209   //
210   tree->SetBranchAddress("RelativeCalib", relativeCalib);
211
212   // indices for looping over the towers
213   Int_t iCol = 0;
214   Int_t iRow = 0;
215
216   for (int ient=0; ient<tree->GetEntries(); ient++) {
217     tree->GetEntry(ient);
218
219     // assume the index SuperModules come in order: i=iSM
220     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
221
222     t->SetSuperModuleNum(iSM);
223     // first, overall values
224     t->SetCalibMethod(iCalibMethod);
225     t->SetCalibPass(iCalibPass);
226     t->SetAbsoluteCalib(absoluteCalib);
227
228     // third: info for each tower
229     for (Int_t j=0; j<nAPDPerSM; j++) {
230       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
231       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
232
233       // help variables: possibly modified or swapped indices
234       int iColMod = iCol;
235       int iRowMod = iRow;
236       // assume that this info is already swapped and done for this basis?
237       if (swapSides) {
238         // C side, oriented differently than A side: swap is requested
239         iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
240         iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
241       }
242
243       t->SetRelativeCalib(iColMod, iRowMod, relativeCalib[iCol][iRow]);
244     }
245
246   } // loop over entries
247
248   return;
249 }
250
251 //____________________________________________________________________________
252 void AliEMCALCalibAbs::WriteRootCalibAbsInfo(const TString &rootFileName,
253                                              Bool_t swapSides)
254 {
255   // write data to root file. ; coordinates given on SuperModule basis
256   TFile destFile(rootFileName, "recreate");  
257   if (destFile.IsZombie()) {
258     return;
259   }  
260   destFile.cd();
261
262   TTree *tree = new TTree("tree","");
263
264   // variables for filling the TTree
265   Int_t iSM = 0; // SuperModule index
266   // list of values to be written
267   // first: overall values for the whole SuperModule
268   Int_t iCalibMethod = 0; 
269   Int_t iCalibPass = 0; 
270   Float_t absoluteCalib = 0; 
271   // third: info for each tower
272   Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows]; 
273   // end - all values
274
275   // just to make the initializations of the arrays are done correctly, let's use memset
276   memset(relativeCalib, 0, sizeof(relativeCalib)); 
277
278   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
279   // for looping over towers
280   Int_t iCol = 0;
281   Int_t iRow = 0;
282
283   // declare the branches
284   // first
285   tree->Branch("iSM", &iSM, "iSM/I");
286   tree->Branch("CalibMethod", &iCalibMethod, "CalibMethod/I");
287   tree->Branch("CalibPass", &iCalibPass, "CalibPass/I");
288   tree->Branch("AbsoluteCalib", &absoluteCalib, "AbsoluteCalib/F");
289   // third: info for each tower; see if a 2D array works OK or if we'll have to use 1D arrays instead 
290   tree->Branch( "RelativeCalib", &relativeCalib, Form("RelativeCalib[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
291
292   for (iSM = 0; iSM < fNSuperModule; iSM++) {
293     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
294
295     iSM = t->GetSuperModuleNum();
296     // first, overall values
297     iCalibMethod = t->GetCalibMethod();
298     iCalibPass = t->GetCalibPass();
299     absoluteCalib = t->GetAbsoluteCalib();
300
301     // third: info for each tower
302     for (Int_t j=0; j<nAPDPerSM; j++) {
303       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
304       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
305
306       // help variables: possibly modified or swapped indices
307       int iColMod = iCol;
308       int iRowMod = iRow;
309       // assume that this info is already swapped and done for this basis?
310       if (swapSides) {
311         // C side, oriented differently than A side: swap is requested
312         iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
313         iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
314       }
315
316       relativeCalib[iColMod][iRowMod] = t->GetRelativeCalib(iCol, iRow);
317     }
318
319     tree->Fill();
320   } // i, SuperModule
321
322   tree->Write();
323   destFile.Close();
324
325   return;
326 }
327
328 //____________________________________________________________________________
329 AliEMCALCalibAbs::~AliEMCALCalibAbs()
330 {
331   fSuperModuleData.Delete();
332 }
333
334 //____________________________________________________________________________
335 AliEMCALSuperModuleCalibAbs * AliEMCALCalibAbs::GetSuperModuleCalibAbsNum(Int_t supModIndex)const
336 {
337   for (int i=0; i<fNSuperModule; i++) {
338     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
339     if (t->GetSuperModuleNum() == supModIndex) {
340       return t;
341     }
342   }
343
344   // if we arrived here, then nothing was found.. just return a NULL pointer 
345   return NULL;
346 }
347