+ // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
+ // and V0
+ // Works on the current event
+ // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
+ //return;
+
+ //######################################################
+ //#########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("");
+ //
+ // Trigger jet staff
+ //
+ if(tr.GetNJetThreshold()>0) {
+ // Jet phi/eta
+ Int_t n0 = triggerPosition.GetSize();
+ const TH2F *hpatch = tr.GetJetMatrixE();
+ triggerPosition.Set(n0 + 2);
+ for(Int_t i=0; i<2; i++) triggerPosition[n0+i] = hpatch->GetMean(i+1);
+ // Add jet ampitudes
+ n0 = triggerAmplitudes.GetSize();
+ triggerAmplitudes.Set(n0 + tr.GetNJetThreshold());
+ Double_t *ampJet = tr.GetL1JetThresholds();
+ for(Int_t i=0; i<tr.GetNJetThreshold(); i++){
+ triggerAmplitudes[n0 + i] = Float_t(ampJet[i]);
+ }
+ }
+ 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 EMCAL 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);
+ Float_t energy = 0;
+ for (Int_t idig = 0 ; idig < nDigits ; idig++) {
+ const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
+ if(dig->GetAmp() > 0 ){
+ energy = (static_cast<AliEMCALClusterizerv1*> (fgClusterizer))->Calibrate(dig->GetAmp(),dig->GetId());
+ emcCells.SetCell(idignew,dig->GetId(),energy, 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));
+ esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
+
+
+ //######################################################
+ //#######################TRACK MATCHING###############
+ //######################################################
+ //Fill list of integers, each one is index of track to which the cluster belongs.
+
+ // step 1 - initialize array of matched track indexes
+ Int_t *matchedTrack = new Int_t[nClusters];
+ for (Int_t iclus = 0; iclus < nClusters; iclus++)
+ matchedTrack[iclus] = -1; // neg. index --> no matched track
+
+ // step 2, change the flag for all matched clusters found in tracks
+ Int_t iemcalMatch = -1;
+ Int_t endtpc = esd->GetNumberOfTracks();
+ for (Int_t itrack = 0; itrack < endtpc; itrack++) {
+ AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
+ iemcalMatch = track->GetEMCALcluster();
+ if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
+ }
+
+ //########################################
+ //##############Fill CaloClusters#############
+ //########################################
+ esd->SetNumberOfEMCALClusters(nClusters);
+ for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
+ const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
+ //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
+ if (Debug()) clust->Print();
+ // Get information from EMCAL reconstruction points
+ Float_t xyz[3];
+ TVector3 gpos;
+ clust->GetGlobalPosition(gpos);
+ for (Int_t ixyz=0; ixyz<3; ixyz++)
+ xyz[ixyz] = gpos[ixyz];
+ Float_t elipAxis[2];
+ clust->GetElipsAxis(elipAxis);
+ //Create digits lists
+ Int_t cellMult = clust->GetMultiplicity();
+ //TArrayS digiList(digitMult);
+ Float_t *amplFloat = clust->GetEnergiesList();
+ Int_t *digitInts = clust->GetAbsId();
+ TArrayS absIdList(cellMult);
+ TArrayD fracList(cellMult);
+
+ Int_t newCellMult = 0;
+ for (Int_t iCell=0; iCell<cellMult; iCell++) {
+ if (amplFloat[iCell] > 0) {
+ absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
+ //Uncomment when unfolding is done
+ //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
+ //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
+ //else
+ fracList[newCellMult] = 0;
+ newCellMult++;
+ }
+ }
+
+ absIdList.Set(newCellMult);
+ fracList.Set(newCellMult);
+
+ if(newCellMult > 0) { // accept cluster if it has some digit
+ nClustersNew++;
+ //Primaries
+ Int_t parentMult = 0;
+ Int_t *parentList = clust->GetParents(parentMult);
+ // fills the ESDCaloCluster
+ AliESDCaloCluster * ec = new AliESDCaloCluster() ;
+ ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
+ ec->SetPosition(xyz);
+ ec->SetE(clust->GetEnergy());
+ ec->SetNCells(newCellMult);
+ //Change type of list from short to ushort
+ UShort_t *newAbsIdList = new UShort_t[newCellMult];
+ Double_t *newFracList = new Double_t[newCellMult];
+ for(Int_t i = 0; i < newCellMult ; i++) {
+ newAbsIdList[i]=absIdList[i];
+ newFracList[i]=fracList[i];
+ }
+ ec->SetCellsAbsId(newAbsIdList);
+ ec->SetCellsAmplitudeFraction(newFracList);
+ ec->SetClusterDisp(clust->GetDispersion());
+ ec->SetClusterChi2(-1); //not yet implemented
+ ec->SetM02(elipAxis[0]*elipAxis[0]) ;
+ ec->SetM20(elipAxis[1]*elipAxis[1]) ;
+ ec->SetTOF(clust->GetTime()) ; //time-of-fligh
+ ec->SetNExMax(clust->GetNExMax()); //number of local maxima
+ TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
+ arrayTrackMatched[0]= matchedTrack[iClust];
+ ec->AddTracksMatched(arrayTrackMatched);
+
+ TArrayI arrayParents(parentMult,parentList);
+ ec->AddLabels(arrayParents);
+
+ // add the cluster to the esd object
+ esd->AddCaloCluster(ec);
+ delete ec;
+ delete [] newAbsIdList ;
+ delete [] newFracList ;
+ }
+ } // cycle on clusters
+
+ delete [] matchedTrack;
+
+ esd->SetNumberOfEMCALClusters(nClustersNew);
+ //if(nClustersNew != nClusters)
+ //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
+
+ //Fill ESDCaloCluster with PID weights
+ AliEMCALPID *pid = new AliEMCALPID;
+ //pid->SetPrintInfo(kTRUE);
+ pid->SetReconstructor(kTRUE);
+ pid->RunPID(esd);
+ delete pid;