1 // some global var/constants
2 const Int_t kNSM = 4; // for first LHC run
4 AliCaloAltroMapping *fMapping[4]; // 1 for each side (A/C) and each RCU (0/1), i.e. 2*2 total
5 const Int_t kNBranch = 2;
6 const Int_t kNFEC = 10; // 0..9, when including LED Ref
7 const Int_t kNChip = 5; // really 0,2..4, i.e. skip #1
8 const Int_t kNChan = 16;
9 Float_t fMeanPed[kNSM][kNRCU][kNBranch][kNFEC][kNChip][kNChan];
10 Float_t fRmsPed[kNSM][kNRCU][kNBranch][kNFEC][kNChip][kNChan];
12 const int kNStrips = 24; // per SM
13 Int_t fHWAddrLEDRef[kNStrips][2]; // [2] is for Low/High gain
15 const Bool_t kDebug = kFALSE;
16 const Float_t kBadRMS = 20;
19 void GetPedVal(const Int_t iSM, const Int_t igain, const TProfile2D *h2);
20 void GetPedValLEDRef(const Int_t iSM, const Int_t igain, const TProfile *h);
23 Int_t GetHWAddress(Int_t iside, Int_t icol, Int_t irow, Int_t igain);
24 Int_t GetHWAddressLEDRef(Int_t istrip, Int_t igain);
25 void DecodeHWAddress(Int_t hwAddr, Int_t & branch, Int_t & FEC, Int_t & chip, Int_t & chan);
27 void CreateMappingLEDRef();
31 //GeneratePedestalScript(const char * filename = "alien/Run113790_113790_v1_s0.root") // 1st set
32 GeneratePedestalScript(const char * filename = "Run117756_117756_v1_s0.root") // 2nd set
34 // get the DA info/object
35 TFile *file = TFile::Open(filename);
36 //TMP AliCaloCalibPedestal *emcCalibPedestal = AliCDBEntry->GetObject();
41 // Get mapping file info, and clear arrays
44 CreateMappingLEDRef();
46 // Store the pedestal info
47 for (Int_t iSM=0; iSM<kNSM; iSM++) {
48 GetPedVal( iSM, 0, emcCalibPedestal->GetPedProfileLowGain(iSM) );
49 GetPedVal( iSM, 1, emcCalibPedestal->GetPedProfileHighGain(iSM) );
50 GetPedValLEDRef( iSM, 0, emcCalibPedestal->GetPedLEDRefProfileLowGain(iSM) );
51 GetPedValLEDRef( iSM, 1, emcCalibPedestal->GetPedLEDRefProfileHighGain(iSM) );
54 // Generate the needed scripts
60 GetPedVal(const Int_t iSM, const Int_t igain, const TProfile2D *h2)
62 Int_t isect = iSM / 2; //
63 Int_t iside = iSM % 2; // A or C side
64 Int_t nCols = h2->GetNbinsX();
65 Int_t nRows = h2->GetNbinsY();
67 printf("GetPedVal: iSM %d isect %d iside %d igain %d nRows %d nCols %d\n",
68 iSM, isect, iside, igain, nRows, nCols);
81 for (icol=0; icol<nCols; icol++) {
82 for (irow=0; irow<nRows; irow++) {
84 hwAddress = GetHWAddress(iside, icol, irow, igain, iRCU);
85 DecodeHWAddress(hwAddress, branch, FEC, chip, chan);
86 bin = h2->FindBin(icol, irow);
89 fMeanPed[iSM][iRCU][branch][FEC][chip][chan] = h2->GetBinContent(bin);
90 fRmsPed[iSM][iRCU][branch][FEC][chip][chan] = h2->GetBinError(bin);
92 // report bad RMS channels:
93 if (h2->GetBinError(bin) > kBadRMS) {
94 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",
95 iSM, icol, irow, igain, iRCU, branch, FEC, chip, chan,
96 h2->GetBinContent(bin), h2->GetBinError(bin));
106 GetPedValLEDRef(const Int_t iSM, const Int_t igain, const TProfile *h)
108 Int_t isect = iSM / 2; //
109 Int_t iside = iSM % 2; // A or C side
110 Int_t nStrips = h->GetNbinsX();
113 printf("GetPedValLEDRef: iSM %d isect %d iside %d igain %d nStrips %d\n",
114 iSM, isect, iside, igain, nStrips);
117 Int_t iRCU = 0; // always true for LED Ref FEE
127 for (int istrip=0; istrip<nStrips; istrip++) {
129 hwAddress = GetHWAddressLEDRef(istrip, igain);
130 DecodeHWAddress(hwAddress, branch, FEC, chip, chan);
131 bin = h->FindBin(istrip);
134 fMeanPed[iSM][iRCU][branch][FEC][chip][chan] = h->GetBinContent(bin);
135 fRmsPed[iSM][iRCU][branch][FEC][chip][chan] = h->GetBinError(bin);
144 const char * sideStr[] = {"A","C"};
145 const char * branchStr[] = {"A","B"};
147 int RCUWrite = 0x200000;
150 char scriptLine[200];
160 for (iSM=0; iSM<kNSM; iSM++) {
163 for (iRCU=0; iRCU<kNRCU; iRCU++) {
164 sprintf(filename, "setSM%1s%dRCU%d.scr",
165 sideStr[iside], isect, iRCU);
166 ofstream fout(filename);
167 int nscriptLines = 0;
169 for (ibranch=0; ibranch<kNBranch; ibranch++) {
171 if (ibranch==0 && iRCU==0) { // extra LED Ref FEE in this location
175 for (iFEC=firstFEC; iFEC<kNFEC; iFEC++) { // FEC 1..9 (or 0..9)
176 for (ichip=0; ichip<kNChip; ichip++) { // ALTRO 0,2,3,4
178 for (ichan=0; ichan<kNChan; ichan++) {
180 if (iFEC!=0 || (ichan<8 || ichan>11)) {
182 Ped = TMath::Nint(fMeanPed[iSM][iRCU][ibranch][iFEC][ichip][ichan]);
183 // raise Ped value to max for channels with exceptionally large RMS
184 if (fRmsPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] > kBadRMS) {
185 printf(" bad pedestal RMS: iSM %d iRCU %d ibranch %d iFEC %d ichip %d ichan %d - raising from %d to 0x3ff\n",
186 iSM, iRCU, ibranch, iFEC, ichip, ichan, Ped);
190 int writeAddr = (ibranch << 16) | (iFEC << 12) | (ichip << 9) |
191 (ichan << 5) | VFPED | RCUWrite;
192 sprintf(scriptLine, "w 0x%04x 0x%06x # Branch %s, Card %d, Altro %d, Chan %d",
193 nscriptLines, writeAddr, branchStr[ibranch],
195 fout << scriptLine << endl;
198 int writeVal = (Ped | RCUWrite);
199 sprintf(scriptLine, "w 0x%04x 0x%06x # Pedestal 0x%x = %d",
200 nscriptLines, writeVal, Ped, Ped);
201 fout << scriptLine << endl;
210 // ending, with execute and update step..
211 sprintf(scriptLine, "w 0x%04x 0x380000 # End of the sequence",
213 fout << scriptLine << endl;
216 sprintf(scriptLine, "w 0x%04x 0x3F0000 # End of the instruction memory",
218 fout << scriptLine << endl;
221 fout << "wait 100 us" << endl;
222 fout << "w 0x5304 0x0 \# execute and update registers" << endl;
233 for (Int_t iSM=0; iSM<kNSM; iSM++) {
234 for (Int_t iRCU=0; iRCU<kNRCU; iRCU++) {
235 for (Int_t ibranch=0; ibranch<kNBranch; ibranch++) {
236 for (Int_t iFEC=0; iFEC<kNFEC; iFEC++) {
237 for (Int_t ichip=0; ichip<kNChip; ichip++) {
238 for (Int_t ichan=0; ichan<kNChan; ichan++) {
239 fMeanPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] = 0;
240 fRmsPed[iSM][iRCU][ibranch][iFEC][ichip][ichan] = 0;
248 for (int istrip=0; istrip<kNStrips; istrip++) {
249 fHWAddrLEDRef[istrip][0] = 0;
250 fHWAddrLEDRef[istrip][1] = 0;
257 DecodeHWAddress(Int_t hwAddr, Int_t & branch, Int_t & FEC, Int_t & chip, Int_t & chan)
260 chip = (hwAddr >> 4) & 0x7;
261 FEC = (hwAddr >> 7) & 0xf;
262 branch = (hwAddr >> 11) & 0x1;
267 GetHWAddress(Int_t iside, Int_t icol, Int_t irow, Int_t igain, Int_t & iRCU)
272 if (0<=irow&&irow<8) iRCU=0; // first cable row
273 else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half;
276 else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half;
278 else if(16<=irow&&irow<24) iRCU=1; // third cable row
280 // swap for odd=C side, to allow us to cable both sides the same
281 Int_t iRCUSide = iRCU;
284 iRCUSide = iRCU + 2; // to make it map file index
286 Int_t hwAddress = fMapping[iRCUSide]->GetHWAddress(irow, icol, igain);
292 GetHWAddressLEDRef(Int_t istrip, Int_t igain)
294 Int_t iRCU = 0; // for both sides; LED ref info is the same for both sides
295 Int_t caloflag = 3; // AliCaloRawStreamV3::kLEDMonData;
297 Int_t hwAddress = fHWAddrLEDRef[istrip][igain];
305 TString sides[]={"A","C"};
306 // Read mapping files from $ALICE_ROOT/CALO/mapping/*.data
307 TString path = gSystem->Getenv("ALICE_ROOT");
308 path += "/EMCAL/mapping/RCU";
310 for(Int_t j = 0; j < 2; j++){ // sides
311 for(Int_t i = 0; i < 2; i++) { // RCU
316 if (kDebug) { printf("Mapping file: %s\n",path2.Data()); }
317 fMapping[j*2 + i] = new AliCaloAltroMapping(path2.Data());
324 CreateMappingLEDRef()
326 Int_t iRCU = 0; // for both sides; LED ref info is the same for both sides
327 Int_t caloflag = 3; // AliCaloRawStreamV3::kLEDMonData;
329 Int_t maxAddr = 1 << 7; // LED Ref FEE is in FEC pos 0, i.e. addr space 0..127
331 int nLEDRefFEEChan = 0;
337 for (int hwaddr = 0; hwaddr<maxAddr; hwaddr++) {
339 DecodeHWAddress(hwaddr, branch, FEC, chip, chan);
340 if ( (chip!=1 && chip<kNChip) && // ALTROs 0,2,3,4
341 (chan<8 || chan>11) ) { // actual installed LED Ref FEE channels
343 int istrip = fMapping[iRCU]->GetPad(hwaddr);
344 int igain = fMapping[iRCU]->GetPadRow(hwaddr);
345 int iflag = fMapping[iRCU]->GetSector(hwaddr);
346 if (iflag == caloflag) {
347 fHWAddrLEDRef[istrip][igain] = hwaddr;
353 if (kDebug) { cout << " nLEDRefFEEChan " << nLEDRefFEEChan << endl; }