]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALCalibMapAPD.cxx
script that allows to 1) merge the QA data available in AliEn and belonging to a...
[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
24 #include "AliEMCALCalibMapAPD.h"
25
26 using namespace std;
27
28 ClassImp(AliEMCALCalibMapAPD)
29
30 //____________________________________________________________________________
31 AliEMCALCalibMapAPD::AliEMCALCalibMapAPD() : 
32   fNSuperModule(0),
33   fSuperModuleData(0)
34 {
35   //Default constructor.
36 }
37
38 //____________________________________________________________________________
39 void AliEMCALCalibMapAPD::ReadCalibMapAPDInfo(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("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - 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 AliEMCALSuperModuleCalibMapAPD[fNSuperModule];
53
54   Int_t iSM = 0; // SuperModule index
55   Int_t iCol = 0;
56   Int_t iRow = 0;
57   // list of values to be read
58   Int_t iHW = 0;
59   Int_t APDNum = 0;
60   Float_t V30 = 0;     
61   Float_t Par[3] = {0};   
62   Float_t ParErr[3] = {0}; 
63   Int_t BreakDown = 0;
64   Float_t DarkCurrent = 0; 
65   // end - all values
66
67   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
68
69   for (Int_t i = 0; i < fNSuperModule; i++) {
70     AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[i];
71     if (!inputFile) {
72       printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Error while reading input file; likely EOF..");
73       return;
74     }
75     inputFile >> iSM;
76     t.fSuperModuleNum = iSM;
77
78     for (Int_t j=0; j<nAPDPerSM; j++) {
79       inputFile >> iCol >> iRow >> iHW 
80                 >> APDNum >> V30 
81                 >> Par[0] >> Par[1] >> Par[2]
82                 >> ParErr[0] >> ParErr[1] >> ParErr[2]
83                 >> BreakDown >> DarkCurrent;
84
85       // assume that this info is already swapped and done for this basis?
86       if (swapSides) {
87         // C side, oriented differently than A side: swap is requested
88         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
89         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
90       }
91
92       AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
93
94       v.fHardWareId = iHW;
95       v.fAPDNum = APDNum;
96       v.fV30 = V30;
97       v.fPar[0] = Par[0];
98       v.fPar[1] = Par[1];
99       v.fPar[2] = Par[2];
100       v.fParErr[0] = ParErr[0];
101       v.fParErr[1] = ParErr[1];
102       v.fParErr[2] = ParErr[2];
103       v.fBreakDown = BreakDown;
104       v.fDarkCurrent = DarkCurrent;
105     }
106
107   } // i, SuperModule
108
109   inputFile.close();
110
111   return;
112 }
113
114 //____________________________________________________________________________
115 void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName,
116                                        Bool_t swapSides)
117 {
118   // write data to txt file. ; coordinates given on SuperModule basis
119
120   std::ofstream outputFile(txtFileName.Data());
121   if (!outputFile) {
122     printf("AliEMCALCalibMapAPD::WriteCalibMapAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
123     return;
124   }
125
126   Int_t iCol = 0;
127   Int_t iRow = 0;
128
129   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
130
131   for (Int_t i = 0; i < fNSuperModule; i++) {
132     AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[i];
133     outputFile << t.fSuperModuleNum << endl;
134
135     for (Int_t j=0; j<nAPDPerSM; j++) {
136       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
137       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
138
139       AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
140
141       if (swapSides) {
142         // C side, oriented differently than A side: swap is requested
143         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
144         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
145       }
146
147       outputFile << iCol << " " << iRow << " " << v.fHardWareId 
148                  << " " << v.fAPDNum << " " << v.fV30 
149                  << " " << v.fPar[0] << " " << v.fPar[1] << " " << v.fPar[2]
150                  << " " << v.fParErr[0] << " " << v.fParErr[1] << " " << v.fParErr[2]
151                  << " " << v.fBreakDown << " " << v.fDarkCurrent << endl;
152     }
153
154   } // i, SuperModule
155
156   outputFile.close();
157
158   return;
159 }
160
161 //____________________________________________________________________________
162 AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD()
163 {
164   delete [] fSuperModuleData;
165 }
166
167 //____________________________________________________________________________
168 AliEMCALCalibMapAPD::AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDId(Int_t supModIndex)const
169 {
170   AliEMCALSuperModuleCalibMapAPD t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
171   if (!fSuperModuleData)
172     return t;
173
174   return fSuperModuleData[supModIndex];
175 }
176
177 //____________________________________________________________________________
178 AliEMCALCalibMapAPD::AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const
179 {
180   AliEMCALSuperModuleCalibMapAPD t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
181   if (!fSuperModuleData)
182     return t;
183
184   for (int i=0; i<fNSuperModule; i++) {
185     if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
186       return fSuperModuleData[i];
187     }
188   }
189
190   return t;
191 }
192