+ // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
+ //return;
+
+ //########################################
+ // Trigger
+ //########################################
+
+ static int saveOnce = 0;
+
+ Int_t v0M[2] = {0, 0};
+
+ AliESDVZERO* esdV0 = esd->GetVZEROData();
+
+ if (esdV0)
+ {
+ v0M[0] = esdV0->GetTriggerChargeC();
+ v0M[1] = esdV0->GetTriggerChargeA();
+ }
+ else
+ {
+ AliWarning("No V0 ESD! Run trigger processor w/ null V0 charges");
+ }
+
+ if (fgTriggerDigits && fgTriggerDigits->GetEntriesFast()) fgTriggerDigits->Delete();
+
+ TBranch *branchtrg = digitsTree->GetBranch("EMTRG");
+
+ if (!branchtrg)
+ {
+ AliError("Can't get the branch with the EMCAL trigger digits!");
+ return;
+ }
+
+ branchtrg->SetAddress(&fgTriggerDigits);
+ branchtrg->GetEntry(0);
+
+ // Note: fgTriggerProcessor reset done at the end of this method
+ fgTriggerProcessor->Digits2Trigger(fgTriggerDigits, v0M, fTriggerData);
+
+ // Fill ESD
+ AliESDCaloTrigger* trgESD = esd->GetCaloTrigger("EMCAL");
+
+ if (trgESD)
+ {
+ trgESD->Allocate(fgTriggerDigits->GetEntriesFast());
+
+ for (Int_t i = 0; i < fgTriggerDigits->GetEntriesFast(); i++)
+ {
+ AliEMCALTriggerRawDigit* rdig = (AliEMCALTriggerRawDigit*)fgTriggerDigits->At(i);
+ if (AliDebugLevel() > 999) rdig->Print("");
+
+ Int_t px, py;
+ if (fGeom->GetPositionInEMCALFromAbsFastORIndex(rdig->GetId(), px, py))
+ {
+ Int_t a = -1, t = -1, times[10];
+
+ rdig->GetMaximum(a, t);
+ rdig->GetL0Times(times);
+
+ trgESD->Add(px, py, a, t, times, rdig->GetNL0Times(), rdig->GetL1TimeSum(), rdig->GetTriggerBits());
+ }
+ }
+
+ for (int i = 0; i < 2; i++) {
+ trgESD->SetL1Threshold(2 * i , fTriggerData->GetL1JetThreshold( i));
+ trgESD->SetL1Threshold(2 * i + 1, fTriggerData->GetL1GammaThreshold(i));
+ }
+
+ Int_t v0[2];
+ fTriggerData->GetL1V0(v0);
+
+ trgESD->SetL1V0(v0);
+ trgESD->SetL1FrameMask(fTriggerData->GetL1FrameMask());
+
+ if (!saveOnce && fTriggerData->GetL1DataDecoded())
+ {
+ int type[15] = {0};
+ fTriggerData->GetL1TriggerType(type);
+
+ esd->SetCaloTriggerType(type);
+
+ saveOnce = 1;
+ }
+ }
+
+ // Resetting
+ fTriggerData->Reset();
+
+ //########################################
+ //##############Fill CaloCells###############
+ //########################################
+
+ //Get input digits and put them in fgDigitsArr, clear the list before
+ ReadDigitsArrayFromTree(digitsTree);
+
+ Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
+ AliDebug(1,Form("%d digits",nDigits));
+
+ AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
+ emcCells.CreateContainer(nDigits);
+ emcCells.SetType(AliVCaloCells::kEMCALCell);
+
+ Float_t energy = 0;
+ Float_t time = 0;
+ for (Int_t idig = 0 ; idig < nDigits ; idig++)
+ {
+ const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
+ time = dig->GetTime(); // Time already calibrated in clusterizer
+ energy = dig->GetAmplitude(); // energy calibrated in clusterizer
+
+ if(energy > 0 )
+ {
+ fgClusterizer->Calibrate(energy,time,dig->GetId()); //Digits already calibrated in clusterizers
+
+ if(energy > 0) //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
+ {
+ // Only for MC
+ // Get the label of the primary particle that generated the cell
+ // Assign the particle that deposited more energy
+ Int_t nprimaries = dig->GetNprimary() ;
+ Int_t digLabel =-1 ;
+ Float_t edep =-1.;
+ if ( nprimaries > 0 )
+ {
+ Int_t jndex ;
+ for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
+
+ if(edep < dig->GetDEParent(jndex+1))
+ {
+ digLabel = dig->GetIparent (jndex+1);
+ edep = dig->GetDEParent(jndex+1);
+ }
+
+ } // all primaries in digit
+ } // select primary label
+
+ Bool_t highGain = kFALSE;
+ if( dig->GetType() == AliEMCALDigit::kHG ) highGain = kTRUE;
+
+ emcCells.SetCell(idignew,dig->GetId(),energy, time,digLabel,0.,highGain);
+ idignew++;
+ }
+ }
+ }
+
+ emcCells.SetNumberOfCells(idignew);
+ emcCells.Sort();
+
+ //------------------------------------------------------------
+ //-----------------CLUSTERS-----------------------------
+ //------------------------------------------------------------
+ clustersTree->SetBranchStatus("*",0); //disable all branches
+ clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
+ if(fgClustersArr) fgClustersArr->Clear();