+//____________________________________________________________________________
+void AliEMCALQADataMakerRec::SetFittingAlgorithm(Int_t fitAlgo)
+{
+ //Set fitting algorithm and initialize it if this same algorithm was not set before.
+ //printf("**** Set Algorithm , number %d ****\n",fitAlgo);
+
+
+ fRawAnalyzer = AliCaloRawAnalyzerFactory::CreateAnalyzer(fitAlgo);
+ fFittingAlgorithm = fitAlgo;
+
+ /*
+ if(fitAlgo == fFittingAlgorithm && fRawAnalyzer) {
+ //Do nothing, this same algorithm already set before.
+ //printf("**** Algorithm already set before, number %d, %s ****\n",fitAlgo, fRawAnalyzer->GetName());
+ return;
+ }
+ //Initialize the requested algorithm
+ if(fitAlgo != fFittingAlgorithm || !fRawAnalyzer) {
+ //printf("**** Init Algorithm , number %d ****\n",fitAlgo);
+
+ fFittingAlgorithm = fitAlgo;
+ if (fRawAnalyzer) delete fRawAnalyzer; // delete prev. analyzer if existed.
+
+ if (fitAlgo == kFastFit) {
+ fRawAnalyzer = new AliCaloRawAnalyzerFastFit();
+ }
+ else if (fitAlgo == kNeuralNet) {
+ fRawAnalyzer = new AliCaloRawAnalyzerNN();
+ }
+ else if (fitAlgo == kLMS) {
+ fRawAnalyzer = new AliCaloRawAnalyzerLMS();
+ }
+ else if (fitAlgo == kPeakFinder) {
+ fRawAnalyzer = new AliCaloRawAnalyzerPeakFinder();
+ }
+ else if (fitAlgo == kCrude) {
+ fRawAnalyzer = new AliCaloRawAnalyzerCrude();
+ }
+ else {
+ AliWarning("EMCAL QA invalid fit algorithm choice") ;
+ }
+
+ }
+ return;
+ */
+}
+
+//_____________________________________________________________________________________
+void AliEMCALQADataMakerRec::ConvertProfile2H(TProfile * p, TH2 * histo)
+{
+ // reset histogram
+ histo->Reset("ICE") ;
+ histo->ResetStats();
+
+ Int_t nbinsProf = p->GetNbinsX();
+
+ // loop through the TProfile p and fill the TH2F histo
+ Int_t row = 0;
+ Int_t col = 0;
+ Double_t binContent = 0;
+ Int_t towerNum = 0; // global tower Id
+ // i = 0; // tower Id within SuperModule
+ Int_t iSM = 0; // SuperModule index
+ Int_t iSMSide = 0; // 0=A, 1=C side
+ Int_t iSMSector = 0; // 2 SM's per sector
+
+ // indices for 2D plots
+ Int_t col2d = 0;
+ Int_t row2d = 0;
+
+ for (Int_t ibin = 1; ibin <= nbinsProf; ibin++) {
+ towerNum = (Int_t) p->GetBinCenter(ibin);
+ binContent = p->GetBinContent(ibin);
+
+ // figure out what the tower indices are: col, row within a SuperModule
+ iSM = towerNum/(AliEMCALGeoParams::fgkEMCALRows * AliEMCALGeoParams::fgkEMCALCols);
+ col = (towerNum/AliEMCALGeoParams::fgkEMCALRows) % (AliEMCALGeoParams::fgkEMCALCols);
+ row = towerNum % (AliEMCALGeoParams::fgkEMCALRows);
+
+ //DecodeTowerNum(towerNum, &SM, &col, &row);
+ // then we calculate what the global 2D coord are, based on which SM
+ // we are in
+ iSMSector = iSM / 2;
+ iSMSide = iSM % 2;
+
+ if (iSMSide == 1) { // C side, shown to the right
+ col2d = col + AliEMCALGeoParams::fgkEMCALCols;
+ }
+ else { // A side, shown to the left
+ col2d = col;
+ }
+
+ row2d = row + iSMSector * AliEMCALGeoParams::fgkEMCALRows;
+
+ histo->SetBinContent(col2d+1, row2d+1, binContent);
+ }
+}
+//____________________________________________________________________________
+void AliEMCALQADataMakerRec::GetTruChannelPosition( Int_t &globRow, Int_t &globColumn, Int_t module, Int_t ddl, Int_t branch, Int_t column ) const
+{ // from local to global indices
+ Int_t mrow;
+ Int_t mcol;
+ Int_t trow;
+ Int_t tcol;
+ Int_t drow;
+ Int_t rcu;
+ // RCU 0 or 1
+ rcu = ddl % 2;
+
+ // 12 rows of 2x2s in a module (3 TRUs by 4 rows)
+ mrow = (module/2) * 12;
+ // 24 columns per module, odd module numbers increased by 24
+ mcol = (module%2) * 24;
+
+ // position within TRU coordinates
+ tcol = column / 4;
+ trow = column % 4;
+
+ //.combine
+ if( module%2 == 0 ){ // A side
+ // mirror rows
+ trow = 3 - trow;
+
+ // TRU in module row addition
+ drow = (rcu*branch+rcu) * 4;
+
+ }
+ else{ // C side
+ // mirror columns
+ tcol = 23 - tcol;
+
+ // TRU in module row addition
+ drow = (2 - (rcu*branch+rcu)) * 4;
+ }
+
+ // output global row/collumn position (0,0 = SMA0, phi = 0, |eta| = max)
+ globRow = mrow + drow + trow;
+ globColumn = mcol + tcol;
+ return;
+
+}
+//____________________________________________________________________________
+void AliEMCALQADataMakerRec::MakeRawsSTU(AliRawReader* rawReader)
+{ // STU specifics
+ AliEMCALTriggerSTURawStream* inSTU = new AliEMCALTriggerSTURawStream(rawReader);
+
+ rawReader->Reset();
+ rawReader->Select("EMCAL", 44);
+
+ //L1 segmentation
+ Int_t sizeL1gsubr = 1;
+ Int_t sizeL1gpatch = 2;
+ Int_t sizeL1jsubr = 4;
+
+ Int_t iEMCALtrig[AliEMCALGeoParams::fgkEMCALSTUCols][AliEMCALGeoParams::fgkEMCALSTURows];
+ memset(iEMCALtrig, 0, sizeof(int) * AliEMCALGeoParams::fgkEMCALSTUCols * AliEMCALGeoParams::fgkEMCALSTURows);
+
+ if (inSTU->ReadPayLoad())
+ {
+ //Fw version (use in case of change in L1 jet
+ Int_t fw = inSTU->GetFwVersion();
+ Int_t sizeL1jpatch = 2+(fw >> 16);
+
+ //To check link
+ Int_t mask = inSTU->GetFrameReceived() ^ inSTU->GetRegionEnable();
+
+ for (int i = 0; i < 32; i++)
+ {
+ if (!((mask >> i) & 0x1)) FillRawsData(kSTUTRU, i);
+ }
+
+ //V0 signal in STU
+ Int_t iV0Sig = inSTU->GetV0A()+inSTU->GetV0C();
+
+ //FastOR amplitude receive from TRU
+ for (Int_t i = 0; i < 32; i++)
+ {
+ UInt_t adc[96];
+ for (Int_t j = 0; j < 96; j++) adc[j] = 0;
+
+ inSTU->GetADC(i, adc);
+
+ Int_t iTRU = fGeom->GetTRUIndexFromSTUIndex(i);
+
+ for (Int_t j = 0; j < 96; j++)
+ {
+ Int_t idx;
+ fGeom->GetAbsFastORIndexFromTRU(iTRU, j, idx);
+
+ Int_t px, py;
+ fGeom->GetPositionInEMCALFromAbsFastORIndex(idx, px, py);
+
+ iEMCALtrig[px][py] = adc[j];
+ }
+ }
+
+ //L1 Gamma patches
+ Int_t iTRUSTU, x, y;
+ for (Int_t i = 0; i < inSTU->GetNL1GammaPatch(0); i++)
+ {
+ if (inSTU->GetL1GammaPatch(i, 0, iTRUSTU, x, y)) // col (0..23), row (0..3)
+ {
+ Int_t iTRU;
+ iTRU = fGeom->GetTRUIndexFromSTUIndex(iTRUSTU);
+
+ Int_t etaG = 23-x, phiG = y + 4 * int(iTRU/2); //position in EMCal
+ if (iTRU%2) etaG += 24; //C-side
+
+ etaG = etaG - sizeL1gsubr * sizeL1gpatch + 1;
+
+ //Position of patch L1G (bottom-left FastOR of the patch)
+ FillRawsData(kGL1, etaG, phiG);
+
+ //loop to sum amplitude of FOR in the gamma patch
+ Int_t iL1GPatchAmp = 0;
+ for (Int_t L1Gx = 0; L1Gx < sizeL1gpatch; L1Gx ++)
+ {
+ for (Int_t L1Gy = 0; L1Gy < sizeL1gpatch; L1Gy ++)
+ {
+ if (etaG+L1Gx < 48 && phiG+L1Gy < 64) iL1GPatchAmp += iEMCALtrig[etaG+L1Gx][phiG+L1Gy];
+ //cout << iEMCALtrig[etaG+L1Gx][phiG+L1Gy] << endl;
+ }
+ }
+
+ //if (iL1GPatchAmp > 500) cout << "L1G amp =" << iL1GPatchAmp << endl;
+ FillRawsData(kGL1V0, iV0Sig, iL1GPatchAmp);
+
+ }
+ }
+
+ //L1 Jet patches
+ for (Int_t i = 0; i < inSTU->GetNL1JetPatch(0); i++)
+ {
+ if (inSTU->GetL1JetPatch(i, 0, x, y)) // col (0,15), row (0,11)
+ {
+
+ Int_t etaJ = sizeL1jsubr * (11-y-sizeL1jpatch + 1);
+ Int_t phiJ = sizeL1jsubr * (15-x-sizeL1jpatch + 1);
+
+ //position of patch L1J (FOR bottom-left)
+ FillRawsData(kJL1, etaJ, phiJ);
+
+ //loop the sum aplitude of FOR in the jet patch
+ Int_t iL1JPatchAmp = 0;
+ for (Int_t L1Jx = 0; L1Jx < sizeL1jpatch*4; L1Jx ++)
+ {
+ for (Int_t L1Jy = 0; L1Jy < sizeL1jpatch*4; L1Jy ++)
+ {
+ if (etaJ+L1Jx < 48 && phiJ+L1Jy < 64) iL1JPatchAmp += iEMCALtrig[etaJ+L1Jx][phiJ+L1Jy];
+ }
+ }
+
+ //cout << "L1J amp =" << iL1JPatchAmp << endl;
+ FillRawsData(kJL1V0, iV0Sig, iL1JPatchAmp);
+ }
+ }
+ }
+
+ //Fill FOR amplitude histo
+ for (Int_t i = 0; i < 48; i++)
+ {
+ for (Int_t j = 0; j < 60; j++)
+ {
+ if (iEMCALtrig[i][j] != 0) FillRawsData(kAmpL1, i, j, iEMCALtrig[i][j]);
+ }
+ }
+
+ delete inSTU;
+ return;
+}
+
+