+ TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",100);
+ Int_t bufsize = 32000;
+ digitsTree->Branch("EMCAL", &digitsArr, bufsize);
+
+ //must be done here because, in constructor, option is not yet known
+ fgRawUtils->SetOption(GetOption());
+
+ fgRawUtils->SetRawFormatHighLowGainFactor(fgkRecParam->GetHighLowGainFactor());
+ fgRawUtils->SetRawFormatOrder(fgkRecParam->GetOrderParameter());
+ fgRawUtils->SetRawFormatTau(fgkRecParam->GetTau());
+ fgRawUtils->SetNoiseThreshold(fgkRecParam->GetNoiseThreshold());
+ fgRawUtils->SetNPedSamples(fgkRecParam->GetNPedSamples());
+
+ fgRawUtils->Raw2Digits(rawReader,digitsArr);
+
+ digitsTree->Fill();
+ digitsArr->Delete();
+ delete digitsArr;
+
+}
+
+
+//____________________________________________________________________________
+void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
+ AliESDEvent* esd) const
+{
+ // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
+ // and V0
+ // Works on the current event
+ // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
+ //return;
+ const double timeScale = 1.e+11; // transition constant from sec to 0.01 ns
+
+ //######################################################
+ //#########Calculate trigger and set trigger info###########
+ //######################################################
+
+ AliEMCALTrigger tr;
+ // tr.SetPatchSize(1); // create 4x4 patches
+ tr.SetSimulation(kFALSE); // Reconstruction mode
+ tr.SetDigitsList(fgDigitsArr);
+ // Get VZERO total multiplicity for jet trigger simulation
+ // The simulation of jey trigger will be incorrect if no VZERO data
+ // at ESD
+ AliESDVZERO* vZero = esd->GetVZEROData();
+ if(vZero) {
+ tr.SetVZER0Multiplicity(vZero->GetMTotV0A() + vZero->GetMTotV0C());
+ }
+ //
+ tr.Trigger();
+
+ Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
+ Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
+ Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
+ Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
+
+ Int_t iSM2x2 = tr.Get2x2SuperModule();
+ Int_t iSMnxn = tr.GetnxnSuperModule();
+ Int_t iModulePhi2x2 = tr.Get2x2ModulePhi();
+ Int_t iModulePhinxn = tr.GetnxnModulePhi();
+ Int_t iModuleEta2x2 = tr.Get2x2ModuleEta();
+ Int_t iModuleEtanxn = tr.GetnxnModuleEta();
+
+ AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iModulePhi2x2, iModuleEta2x2));
+ AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iModulePhinxn, iModuleEtanxn));
+
+ TVector3 pos2x2(-1,-1,-1);
+ TVector3 posnxn(-1,-1,-1);
+
+ Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iModulePhi2x2, iModuleEta2x2) ; // should be changed to Module
+ Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iModulePhinxn, iModuleEtanxn) ;
+ fGeom->GetGlobal(iAbsId2x2, pos2x2);
+ fGeom->GetGlobal(iAbsIdnxn, posnxn);
+ //printf(" iAbsId2x2 %i iAbsIdnxn %i \n", iAbsId2x2, iAbsIdnxn);
+
+ TArrayF triggerPosition(6);
+ triggerPosition[0] = pos2x2(0) ;
+ triggerPosition[1] = pos2x2(1) ;
+ triggerPosition[2] = pos2x2(2) ;
+ triggerPosition[3] = posnxn(0) ;
+ triggerPosition[4] = posnxn(1) ;
+ triggerPosition[5] = posnxn(2) ;
+ //printf(" triggerPosition ");
+ //for(int i=0; i<6; i++) printf(" %i %f : ", i, triggerPosition[i]);
+
+ TArrayF triggerAmplitudes(4);
+ triggerAmplitudes[0] = maxAmp2x2 ;
+ triggerAmplitudes[1] = ampOutOfPatch2x2 ;
+ triggerAmplitudes[2] = maxAmpnxn ;
+ triggerAmplitudes[3] = ampOutOfPatchnxn ;
+ //printf("\n triggerAmplitudes ");
+ //for(int i=0; i<4; i++) printf(" %i %f : ", i, triggerAmplitudes[i]);
+ //printf("\n");
+ tr.Print("");
+
+ esd->AddEMCALTriggerPosition(triggerPosition);
+ esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
+ // Fill trigger hists
+ AliEMCALHistoUtilities::FillTriggersListOfHists(fList,&triggerPosition,&triggerAmplitudes);
+
+ //########################################
+ //##############Fill CaloCells###############
+ //########################################
+
+ TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
+ TBranch *branchdig = digitsTree->GetBranch("EMCAL");
+ if (!branchdig) {
+ AliError("can't get the branch with the PHOS digits !");
+ return;
+ }
+ branchdig->SetAddress(&digits);
+ digitsTree->GetEvent(0);
+ Int_t nDigits = digits->GetEntries(), idignew = 0 ;
+ AliDebug(1,Form("%d digits",nDigits));
+
+ AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
+ emcCells.CreateContainer(nDigits);
+ emcCells.SetType(AliESDCaloCells::kEMCALCell);
+ for (Int_t idig = 0 ; idig < nDigits ; idig++) {
+ const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
+ if(dig->GetAmp() > 0 ){
+ emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());
+ idignew++;
+ }
+ }
+ emcCells.SetNumberOfCells(idignew);
+ emcCells.Sort();
+
+ //------------------------------------------------------------
+ //-----------------CLUSTERS-----------------------------
+ //------------------------------------------------------------
+ TObjArray *clusters = new TObjArray(100);
+ TBranch *branch = clustersTree->GetBranch("EMCALECARP");
+ branch->SetAddress(&clusters);
+ clustersTree->GetEvent(0);
+
+ Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
+ AliDebug(1,Form("%d clusters",nClusters));