AliRoot Core  3dc7879 (3dc7879)
GeneratePedestalScript.C
Go to the documentation of this file.
1 
11 // some global var/constants
12 const Int_t kNSM = 4; // for first LHC run
13 const Int_t kNRCU = 2;
14 AliCaloAltroMapping *fMapping[4]; // 1 for each side (A/C) and each RCU (0/1), i.e. 2*2 total
15 const Int_t kNBranch = 2;
16 const Int_t kNFEC = 10; // 0..9, when including LED Ref
17 const Int_t kNChip = 5; // really 0,2..4, i.e. skip #1
18 const Int_t kNChan = 16;
21 //
22 const int kNStrips = 24; // per SM
23 Int_t fHWAddrLEDRef[kNStrips][2]; // [2] is for Low/High gain
24 
25 const Bool_t kDebug = kFALSE;
26 const Float_t kBadRMS = 20;
27 
28 // help methods
29 void GetPedVal(const Int_t iSM, const Int_t igain, const TProfile2D *h2);
30 void GetPedValLEDRef(const Int_t iSM, const Int_t igain, const TProfile *h);
31 void PrintScript();
32 void Clear();
33 Int_t GetHWAddress(Int_t iside, Int_t icol, Int_t irow, Int_t igain);
34 Int_t GetHWAddressLEDRef(Int_t istrip, Int_t igain);
35 void DecodeHWAddress(Int_t hwAddr, Int_t & branch, Int_t & FEC, Int_t & chip, Int_t & chan);
36 void GetMapping();
37 void CreateMappingLEDRef();
38 
41 void
42 //GeneratePedestalScript(const char * filename = "alien/Run113790_113790_v1_s0.root") // 1st set
43 GeneratePedestalScript(const char * filename = "Run117756_117756_v1_s0.root") // 2nd set
44 {
45  // get the DA info/object
46  TFile *file = TFile::Open(filename);
47  //TMP AliCaloCalibPedestal *emcCalibPedestal = AliCDBEntry->GetObject();
48 
49  if (kDebug)
50  file->ls();
51 
52  // Get mapping file info, and clear arrays
53  Clear();
54  GetMapping();
56 
57  // Store the pedestal info
58  for (Int_t iSM=0; iSM<kNSM; iSM++)
59  {
60  GetPedVal ( iSM, 0, emcCalibPedestal->GetPedProfileLowGain(iSM) );
61  GetPedVal ( iSM, 1, emcCalibPedestal->GetPedProfileHighGain(iSM) );
62  GetPedValLEDRef( iSM, 0, emcCalibPedestal->GetPedLEDRefProfileLowGain(iSM) );
63  GetPedValLEDRef( iSM, 1, emcCalibPedestal->GetPedLEDRefProfileHighGain(iSM) );
64  }
65 
66  // Generate the needed scripts
67  PrintScript();
68 }
69 
72 void
73 GetPedVal(const Int_t iSM, const Int_t igain, const TProfile2D *h2)
74 {
75  Int_t isect = iSM / 2; //
76  Int_t iside = iSM % 2; // A or C side
77  Int_t nCols = h2->GetNbinsX();
78  Int_t nRows = h2->GetNbinsY();
79  if (kDebug)
80  {
81  printf("GetPedVal: iSM %d isect %d iside %d igain %d nRows %d nCols %d\n",
82  iSM, isect, iside, igain, nRows, nCols);
83  }
84 
85  Int_t hwAddress = 0;
86  Int_t iRCU = 0;
87  Int_t branch = 0;
88  Int_t FEC = 0;
89  Int_t chip = 0;
90  Int_t chan = 0;
91 
92  Int_t icol = 0;
93  Int_t irow = 0;
94  Int_t bin = 0;
95 
96  for (icol=0; icol<nCols; icol++)
97  {
98  for (irow=0; irow<nRows; irow++)
99  {
100 
101  hwAddress = GetHWAddress(iside, icol, irow, igain, iRCU);
102  DecodeHWAddress(hwAddress, branch, FEC, chip, chan);
103  bin = h2->FindBin(icol, irow);
104 
105  // store the values
106  fMeanPed[iSM][iRCU][branch][FEC][chip][chan] = h2->GetBinContent(bin);
107  fRmsPed[iSM][iRCU][branch][FEC][chip][chan] = h2->GetBinError(bin);
108 
109  // report bad RMS channels:
110  if (h2->GetBinError(bin) > kBadRMS)
111  {
112  printf(" bad pedestal RMS: iSM %d icol %d irow %d igain %d iRCU %d branch %d FEC %d chip %d chan %d - mean %4.1f rms %4.1f\n",
113  iSM, icol, irow, igain, iRCU, branch, FEC, chip, chan,
114  h2->GetBinContent(bin), h2->GetBinError(bin));
115  }
116  }
117  }
118 
119  return;
120 }
121 
124 void
125 GetPedValLEDRef(const Int_t iSM, const Int_t igain, const TProfile *h)
126 {
127  Int_t isect = iSM / 2; //
128  Int_t iside = iSM % 2; // A or C side
129  Int_t nStrips = h->GetNbinsX();
130 
131  if (kDebug)
132  {
133  printf("GetPedValLEDRef: iSM %d isect %d iside %d igain %d nStrips %d\n",
134  iSM, isect, iside, igain, nStrips);
135  }
136 
137  Int_t hwAddress = 0;
138  Int_t iRCU = 0; // always true for LED Ref FEE
139  Int_t branch = 0;
140  Int_t FEC = 0;
141  Int_t chip = 0;
142  Int_t chan = 0;
143 
144  Int_t icol = 0;
145  Int_t irow = 0;
146  Int_t bin = 0;
147 
148  for (int istrip=0; istrip<nStrips; istrip++)
149  {
150  hwAddress = GetHWAddressLEDRef(istrip, igain);
151  DecodeHWAddress(hwAddress, branch, FEC, chip, chan);
152  bin = h->FindBin(istrip);
153 
154  // store the values
155  fMeanPed[iSM][iRCU][branch][FEC][chip][chan] = h->GetBinContent(bin);
156  fRmsPed[iSM][iRCU][branch][FEC][chip][chan] = h->GetBinError(bin);
157  }
158 
159  return;
160 }
161 
164 void
166 {
167  const char * sideStr[] = {"A","C"};
168  const char * branchStr[] = {"A","B"};
169  int VFPED = 0x06;
170  int RCUWrite = 0x200000;
171 
172  char filename[100];
173  char scriptLine[200];
174 
175  Int_t iSM = 0;
176  Int_t iRCU = 0;
177  Int_t ibranch = 0;
178  Int_t iFEC = 0;
179  Int_t ichip = 0;
180  Int_t ichan = 0;
181  Int_t Ped = 0;
182 
183  for (iSM=0; iSM<kNSM; iSM++)
184  {
185  int iside = iSM % 2;
186  int isect = iSM / 2;
187  for (iRCU=0; iRCU<kNRCU; iRCU++)
188  {
189  sprintf(filename, "setSM%1s%dRCU%d.scr",
190  sideStr[iside], isect, iRCU);
191  ofstream fout(filename);
192  int nscriptLines = 0;
193 
194  for (ibranch=0; ibranch<kNBranch; ibranch++)
195  {
196  int firstFEC = 1;
197 
198  if (ibranch==0 && iRCU==0)
199  { // extra LED Ref FEE in this location
200  firstFEC = 0;
201  }
202 
203  for (iFEC=firstFEC; iFEC<kNFEC; iFEC++)
204  { // FEC 1..9 (or 0..9)
205  for (ichip=0; ichip<kNChip; ichip++)
206  { // ALTRO 0,2,3,4
207  if (ichip!=1) {
208  for (ichan=0; ichan<kNChan; ichan++)
209  {
210 
211  if (iFEC!=0 || (ichan<8 || ichan>11))
212  {
213 
214  Ped = TMath::Nint(fMeanPed[iSM][iRCU][ibranch][iFEC][ichip][ichan]);
215  // raise Ped value to max for channels with exceptionally large RMS
216  if (fRmsPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] > kBadRMS) {
217  printf(" bad pedestal RMS: iSM %d iRCU %d ibranch %d iFEC %d ichip %d ichan %d - raising from %d to 0x3ff\n",
218  iSM, iRCU, ibranch, iFEC, ichip, ichan, Ped);
219  Ped = 0x3ff;
220  }
221 
222  //
223  int writeAddr = (ibranch << 16) | (iFEC << 12) | (ichip << 9) |
224  (ichan << 5) | VFPED | RCUWrite;
225  sprintf(scriptLine, "w 0x%04x 0x%06x # Branch %s, Card %d, Altro %d, Chan %d",
226  nscriptLines, writeAddr, branchStr[ibranch],
227  iFEC, ichip, ichan);
228  fout << scriptLine << endl;
229  nscriptLines++;
230 
231  int writeVal = (Ped | RCUWrite);
232  sprintf(scriptLine, "w 0x%04x 0x%06x # Pedestal 0x%x = %d",
233  nscriptLines, writeVal, Ped, Ped);
234  fout << scriptLine << endl;
235  nscriptLines++;
236 
237  }
238  }
239  }
240  }
241  }
242  }
243  // ending, with execute and update step..
244  sprintf(scriptLine, "w 0x%04x 0x380000 # End of the sequence",
245  nscriptLines);
246  fout << scriptLine << endl;
247  nscriptLines++;
248 
249  sprintf(scriptLine, "w 0x%04x 0x3F0000 # End of the instruction memory",
250  nscriptLines);
251  fout << scriptLine << endl;
252  nscriptLines++;
253 
254  fout << "wait 100 us" << endl;
255  fout << "w 0x5304 0x0 \# execute and update registers" << endl;
256  fout.close();
257  } // iRCU
258  }// iSM
259 
260  return;
261 }
262 
265 void
267 {
268  for (Int_t iSM=0; iSM<kNSM; iSM++)
269  {
270  for (Int_t iRCU=0; iRCU<kNRCU; iRCU++)
271  {
272  for (Int_t ibranch=0; ibranch<kNBranch; ibranch++)
273  {
274  for (Int_t iFEC=0; iFEC<kNFEC; iFEC++)
275  {
276  for (Int_t ichip=0; ichip<kNChip; ichip++)
277  {
278  for (Int_t ichan=0; ichan<kNChan; ichan++)
279  {
280  fMeanPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] = 0;
281  fRmsPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] = 0;
282  }
283  }
284  }
285  }
286  }
287  }
288 
289  for (int istrip=0; istrip<kNStrips; istrip++)
290  {
291  fHWAddrLEDRef[istrip][0] = 0;
292  fHWAddrLEDRef[istrip][1] = 0;
293  }
294 
295  return;
296 }
297 
300 void
301 DecodeHWAddress(Int_t hwAddr, Int_t & branch, Int_t & FEC, Int_t & chip, Int_t & chan)
302 {
303  chan = hwAddr & 0xf;
304  chip = (hwAddr >> 4) & 0x7;
305  FEC = (hwAddr >> 7) & 0xf;
306  branch = (hwAddr >> 11) & 0x1;
307  return;
308 }
309 
312 Int_t
313 GetHWAddress(Int_t iside, Int_t icol, Int_t irow, Int_t igain, Int_t & iRCU)
314 {
315  iRCU = -111;
316 
317  //RCU0
318  if (0<=irow&&irow<8) iRCU=0; // first cable row
319  else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half;
320  //second cable row
321  //RCU1
322  else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half;
323  //second cable row
324  else if(16<=irow&&irow<24) iRCU=1; // third cable row
325 
326  // swap for odd=C side, to allow us to cable both sides the same
327  Int_t iRCUSide = iRCU;
328  if (iside == 1)
329  {
330  iRCU = 1 - iRCU;
331  iRCUSide = iRCU + 2; // to make it map file index
332  }
333 
334  Int_t hwAddress = fMapping[iRCUSide]->GetHWAddress(irow, icol, igain);
335 
336  return hwAddress;
337 }
338 
341 Int_t
342 GetHWAddressLEDRef(Int_t istrip, Int_t igain)
343 {
344  Int_t iRCU = 0; // for both sides; LED ref info is the same for both sides
345  Int_t caloflag = 3; // AliCaloRawStreamV3::kLEDMonData;
346 
347  Int_t hwAddress = fHWAddrLEDRef[istrip][igain];
348 
349  return hwAddress;
350 }
351 
354 void
356 {
357  TString sides[]={"A","C"};
358  // Read mapping files from $ALICE_ROOT/CALO/mapping/*.data
359  TString path = gSystem->Getenv("ALICE_ROOT");
360  path += "/EMCAL/mapping/RCU";
361 
362  TString path2;
363  for(Int_t j = 0; j < 2; j++)
364  { // sides
365  for(Int_t i = 0; i < 2; i++)
366  { // RCU
367  path2 = path;
368  path2 += i;
369  path2 += sides[j];
370  path2 += ".data";
371  if (kDebug) { printf("Mapping file: %s\n",path2.Data());
372  }
373 
374  fMapping[j*2 + i] = new AliCaloAltroMapping(path2.Data());
375  }
376  }
377  return;
378 }
379 
382 void
384 {
385  Int_t iRCU = 0; // for both sides; LED ref info is the same for both sides
386  Int_t caloflag = 3; // AliCaloRawStreamV3::kLEDMonData;
387 
388  Int_t maxAddr = 1 << 7; // LED Ref FEE is in FEC pos 0, i.e. addr space 0..127
389 
390  int nLEDRefFEEChan = 0;
391 
392  Int_t branch = 0;
393  Int_t FEC = 0;
394  Int_t chip = 0;
395  Int_t chan = 0;
396  for (int hwaddr = 0; hwaddr<maxAddr; hwaddr++)
397  {
398  DecodeHWAddress(hwaddr, branch, FEC, chip, chan);
399  if ( (chip!=1 && chip<kNChip) && // ALTROs 0,2,3,4
400  (chan<8 || chan>11) )
401  { // actual installed LED Ref FEE channels
402 
403  int istrip = fMapping[iRCU]->GetPad(hwaddr);
404  int igain = fMapping[iRCU]->GetPadRow(hwaddr);
405  int iflag = fMapping[iRCU]->GetSector(hwaddr);
406 
407  if (iflag == caloflag)
408  {
409  fHWAddrLEDRef[istrip][igain] = hwaddr;
410  nLEDRefFEEChan++;
411  }
412  }
413  }
414 
415  if (kDebug) { cout << " nLEDRefFEEChan " << nLEDRefFEEChan << endl; }
416 }
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
TFile * Open(const char *filename, Long64_t &nevents)
const Int_t kNBranch
const int kNStrips
Float_t fRmsPed[kNSM][kNRCU][kNBranch][kNFEC][kNChip][kNChan]
const Float_t kBadRMS
const char * path
Float_t fMeanPed[kNSM][kNRCU][kNBranch][kNFEC][kNChip][kNChan]
void PrintScript()
Add comment.
void GetMapping()
Add comment.
const Int_t kNChan
Int_t fHWAddrLEDRef[kNStrips][2]
const Int_t kNSM
const Int_t kNChip
void Clear()
Add comment.
TFile * fout
Definition: PlotSys.C:39
Int_t GetHWAddress(Int_t iside, Int_t icol, Int_t irow, Int_t igain)
void DecodeHWAddress(Int_t hwAddr, Int_t &branch, Int_t &FEC, Int_t &chip, Int_t &chan)
Add comment.
AliCaloAltroMapping * fMapping[4]
const Int_t kNRCU
void GetPedValLEDRef(const Int_t iSM, const Int_t igain, const TProfile *h)
Add comment.
void CreateMappingLEDRef()
Add comment.
const Int_t kNFEC
void GetPedVal(const Int_t iSM, const Int_t igain, const TProfile2D *h2)
Add comment.
void GeneratePedestalScript(const char *filename="Run117756_117756_v1_s0.root")
Main method.
Int_t GetHWAddressLEDRef(Int_t istrip, Int_t igain)
Add comment.
const Bool_t kDebug