]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/macros/GeneratePedestalScript.C
move geometry initialization pointers from Init to CreateOutputObjects
[u/mrichter/AliRoot.git] / EMCAL / macros / GeneratePedestalScript.C
CommitLineData
29f94584 1// some global var/constants
2const Int_t kNSM = 4; // for first LHC run
3const Int_t kNRCU = 2;
4AliCaloAltroMapping *fMapping[4]; // 1 for each side (A/C) and each RCU (0/1), i.e. 2*2 total
5const Int_t kNBranch = 2;
6const Int_t kNFEC = 10; // 0..9, when including LED Ref
7const Int_t kNChip = 5; // really 0,2..4, i.e. skip #1
8const Int_t kNChan = 16;
9Float_t fMeanPed[kNSM][kNRCU][kNBranch][kNFEC][kNChip][kNChan];
10Float_t fRmsPed[kNSM][kNRCU][kNBranch][kNFEC][kNChip][kNChan];
11//
12const int kNStrips = 24; // per SM
13Int_t fHWAddrLEDRef[kNStrips][2]; // [2] is for Low/High gain
14
15// help methods
16void GetPedVal(const Int_t iSM, const Int_t igain, const TProfile2D *h2);
17void GetPedValLEDRef(const Int_t iSM, const Int_t igain, const TProfile *h);
18void PrintScript();
19void Clear();
20Int_t GetHWAddress(Int_t iside, Int_t icol, Int_t irow, Int_t igain);
21Int_t GetHWAddressLEDRef(Int_t istrip, Int_t igain);
22void DecodeHWAddress(Int_t hwAddr, Int_t & branch, Int_t & FEC, Int_t & chip, Int_t & chan);
23void GetMapping();
24void CreateMappingLEDRef();
25
26// main method
27void
28GeneratePedestalScript(const char * filename = "alien/Run113790_113790_v1_s0.root")
29{
30 // get the DA info/object
31 TFile *file = TFile::Open(filename);
32 AliCaloCalibPedestal *emcCalibPedestal = AliCDBEntry->GetObject();
33
34 // Get mapping file info, and clear arrays
35 Clear();
36 GetMapping();
37 CreateMappingLEDRef();
38
39 // Store the pedestal info
40 for (Int_t iSM=0; iSM<kNSM; iSM++) {
41 GetPedVal( iSM, 0, emcCalibPedestal->GetPedProfileLowGain(iSM) );
42 GetPedVal( iSM, 1, emcCalibPedestal->GetPedProfileHighGain(iSM) );
43 GetPedValLEDRef( iSM, 0, emcCalibPedestal->GetPedLEDRefProfileLowGain(iSM) );
44 GetPedValLEDRef( iSM, 1, emcCalibPedestal->GetPedLEDRefProfileHighGain(iSM) );
45 }
46
47 // Generate the needed scripts
48 PrintScript();
49
50}
51
52void
53GetPedVal(const Int_t iSM, const Int_t igain, const TProfile2D *h2)
54{
55 Int_t isect = iSM / 2; //
56 Int_t iside = iSM % 2; // A or C side
57 Int_t nCols = h2->GetNbinsX();
58 Int_t nRows = h2->GetNbinsY();
59 // debug print
60 printf("GetPedVal: iSM %d isect %d iside %d igain %d nRows %d nCols %d\n",
61 iSM, isect, iside, igain, nRows, nCols);
62
63 Int_t hwAddress = 0;
64 Int_t iRCU = 0;
65 Int_t branch = 0;
66 Int_t FEC = 0;
67 Int_t chip = 0;
68 Int_t chan = 0;
69
70 Int_t icol = 0;
71 Int_t irow = 0;
72 Int_t bin = 0;
73
74 for (icol=0; icol<nCols; icol++) {
75 for (irow=0; irow<nRows; irow++) {
76
77 hwAddress = GetHWAddress(iside, icol, irow, igain, iRCU);
78 DecodeHWAddress(hwAddress, branch, FEC, chip, chan);
79 bin = h2->FindBin(icol, irow);
80
81 // store the values
82 fMeanPed[iSM][iRCU][branch][FEC][chip][chan] = h2->GetBinContent(bin);
83 fRmsPed[iSM][iRCU][branch][FEC][chip][chan] = h2->GetBinError(bin);
84 }
85 }
86
87 return;
88}
89
90
91void
92GetPedValLEDRef(const Int_t iSM, const Int_t igain, const TProfile *h)
93{
94 Int_t isect = iSM / 2; //
95 Int_t iside = iSM % 2; // A or C side
96 Int_t nStrips = h->GetNbinsX();
97
98 // debug print
99 printf("GetPedValLEDRef: iSM %d isect %d iside %d igain %d nStrips %d\n",
100 iSM, isect, iside, igain, nStrips);
101
102 Int_t hwAddress = 0;
103 Int_t iRCU = 0; // always true for LED Ref FEE
104 Int_t branch = 0;
105 Int_t FEC = 0;
106 Int_t chip = 0;
107 Int_t chan = 0;
108
109 Int_t icol = 0;
110 Int_t irow = 0;
111 Int_t bin = 0;
112
113 for (int istrip=0; istrip<nStrips; istrip++) {
114
115 hwAddress = GetHWAddressLEDRef(istrip, igain);
116 DecodeHWAddress(hwAddress, branch, FEC, chip, chan);
117 bin = h->FindBin(istrip);
118
119 // store the values
120 fMeanPed[iSM][iRCU][branch][FEC][chip][chan] = h->GetBinContent(bin);
121 fRmsPed[iSM][iRCU][branch][FEC][chip][chan] = h->GetBinError(bin);
122 }
123
124 return;
125}
126
127void
128PrintScript()
129{
130 const char * sideStr[] = {"A","C"};
131 const char * branchStr[] = {"A","B"};
132 int VFPED = 0x06;
133 int RCUWrite = 0x200000;
134
135 char filename[100];
136 char scriptLine[200];
137
138 Int_t iSM = 0;
139 Int_t iRCU = 0;
140 Int_t ibranch = 0;
141 Int_t iFEC = 0;
142 Int_t ichip = 0;
143 Int_t ichan = 0;
144 Int_t Ped = 0;
145
146 for (iSM=0; iSM<kNSM; iSM++) {
147 int iside = iSM % 2;
148 int isect = iSM / 2;
149 for (iRCU=0; iRCU<kNRCU; iRCU++) {
150 sprintf(filename, "setSM%1s%dRCU%d.scr",
151 sideStr[iside], isect, iRCU);
152 ofstream fout(filename);
153 int nscriptLines = 0;
154
155 for (ibranch=0; ibranch<kNBranch; ibranch++) {
156 int firstFEC = 1;
157 if (ibranch==0 && iRCU==0) { // extra LED Ref FEE in this location
158 firstFEC = 0;
159 }
160
161 for (iFEC=firstFEC; iFEC<kNFEC; iFEC++) { // FEC 1..9 (or 0..9)
162 for (ichip=0; ichip<kNChip; ichip++) { // ALTRO 0,2,3,4
163 if (ichip!=1) {
164 for (ichan=0; ichan<kNChan; ichan++) {
165
166 if (iFEC!=0 || (ichan<8 || ichan>11)) {
167
168 Ped = TMath::Nint(fMeanPed[iSM][iRCU][ibranch][iFEC][ichip][ichan]);
169 //
170 int writeAddr = (ibranch << 16) | (iFEC << 12) | (ichip << 9) |
171 (ichan << 5) | VFPED | RCUWrite;
172 sprintf(scriptLine, "w 0x%04x 0x%06x # Branch %s, Card %d, Altro %d, Chan %d",
173 nscriptLines, writeAddr, branchStr[ibranch],
174 iFEC, ichip, ichan);
175 fout << scriptLine << endl;
176 nscriptLines++;
177
178 int writeVal = (Ped | RCUWrite);
179 sprintf(scriptLine, "w 0x%04x 0x%06x # Pedestal 0x%x = %d",
180 nscriptLines, writeVal, Ped, Ped);
181 fout << scriptLine << endl;
182 nscriptLines++;
183
184 }
185 }
186 }
187 }
188 }
189 }
190 // ending, with execute and update step..
191 sprintf(scriptLine, "w 0x%04x 0x380000 # End of the sequence",
192 nscriptLines);
193 fout << scriptLine << endl;
194 nscriptLines++;
195
196 sprintf(scriptLine, "w 0x%04x 0x3F0000 # End of the instruction memory",
197 nscriptLines);
198 fout << scriptLine << endl;
199 nscriptLines++;
200
201 fout << "wait 100 us" << endl;
202 fout << "w 0x5304 0x0 \# execute and update registers" << endl;
203 fout.close();
204 } // iRCU
205 }// iSM
206
207 return;
208}
209
210void
211Clear()
212{
213 for (Int_t iSM=0; iSM<kNSM; iSM++) {
214 for (Int_t iRCU=0; iRCU<kNRCU; iRCU++) {
215 for (Int_t ibranch=0; ibranch<kNBranch; ibranch++) {
216 for (Int_t iFEC=0; iFEC<kNFEC; iFEC++) {
217 for (Int_t ichip=0; ichip<kNChip; ichip++) {
218 for (Int_t ichan=0; ichan<kNChan; ichan++) {
219 fMeanPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] = 0;
220 fRmsPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] = 0;
221 }
222 }
223 }
224 }
225 }
226 }
227
228 for (int istrip=0; istrip<kNStrips; istrip++) {
229 fHWAddrLEDRef[istrip][0] = 0;
230 fHWAddrLEDRef[istrip][1] = 0;
231 }
232
233 return;
234}
235
236void
237DecodeHWAddress(Int_t hwAddr, Int_t & branch, Int_t & FEC, Int_t & chip, Int_t & chan)
238{
239 chan = hwAddr & 0xf;
240 chip = (hwAddr >> 4) & 0x7;
241 FEC = (hwAddr >> 7) & 0xf;
242 branch = (hwAddr >> 11) & 0x1;
243 return;
244}
245
246Int_t
247GetHWAddress(Int_t iside, Int_t icol, Int_t irow, Int_t igain, Int_t & iRCU)
248{
249 iRCU = -111;
250
251 //RCU0
252 if (0<=irow&&irow<8) iRCU=0; // first cable row
253 else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half;
254 //second cable row
255 //RCU1
256 else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half;
257 //second cable row
258 else if(16<=irow&&irow<24) iRCU=1; // third cable row
259
260 // swap for odd=C side, to allow us to cable both sides the same
261 Int_t iRCUSide = iRCU;
262 if (iside == 1) {
263 iRCU = 1 - iRCU;
264 iRCUSide = iRCU + 2; // to make it map file index
265 }
266 Int_t hwAddress = fMapping[iRCUSide]->GetHWAddress(irow, icol, igain);
267
268 return hwAddress;
269}
270
271Int_t
272GetHWAddressLEDRef(Int_t istrip, Int_t igain)
273{
274 Int_t iRCU = 0; // for both sides; LED ref info is the same for both sides
275 Int_t caloflag = 3; // AliCaloRawStreamV3::kLEDMonData;
276
277 Int_t hwAddress = fHWAddrLEDRef[istrip][igain];
278
279 return hwAddress;
280}
281
282void
283GetMapping()
284{
285 TString sides[]={"A","C"};
286 // Read mapping files from $ALICE_ROOT/CALO/mapping/*.data
287 TString path = gSystem->Getenv("ALICE_ROOT");
288 path += "/EMCAL/mapping/RCU";
289 TString path2;
290 for(Int_t j = 0; j < 2; j++){ // sides
291 for(Int_t i = 0; i < 2; i++) { // RCU
292 path2 = path;
293 path2 += i;
294 path2 += sides[j];
295 path2 += ".data";
296 printf("Mapping file: %s\n",path2.Data());
297 fMapping[j*2 + i] = new AliCaloAltroMapping(path2.Data());
298 }
299 }
300 return;
301}
302
303void
304CreateMappingLEDRef()
305{
306 Int_t iRCU = 0; // for both sides; LED ref info is the same for both sides
307 Int_t caloflag = 3; // AliCaloRawStreamV3::kLEDMonData;
308
309 Int_t maxAddr = 1 << 7; // LED Ref FEE is in FEC pos 0, i.e. addr space 0..127
310
311 int nLEDRefFEEChan = 0;
312
313 Int_t branch = 0;
314 Int_t FEC = 0;
315 Int_t chip = 0;
316 Int_t chan = 0;
317 for (int hwaddr = 0; hwaddr<maxAddr; hwaddr++) {
318
319 DecodeHWAddress(hwaddr, branch, FEC, chip, chan);
320 if ( (chip!=1 && chip<kNChip) && // ALTROs 0,2,3,4
321 (chan<8 || chan>11) ) { // actual installed LED Ref FEE channels
322
323 int istrip = fMapping[iRCU]->GetPad(hwaddr);
324 int igain = fMapping[iRCU]->GetPadRow(hwaddr);
325 int iflag = fMapping[iRCU]->GetSector(hwaddr);
326 if (iflag == caloflag) {
327 fHWAddrLEDRef[istrip][igain] = hwaddr;
328 nLEDRefFEEChan++;
329 }
330 }
331 }
332
333 cout << " nLEDRefFEEChan " << nLEDRefFEEChan << endl;
334}