+//_________________________________________________
+void AliAnalysisTaskEMCALClusterize::InitGeometry()
+{
+ // Set the geometry matrix, for the first event, skip the rest
+ // Also set once the run dependent calibrations
+
+ if(!fGeomMatrixSet){
+ if(fLoadGeomMatrices){
+ for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
+ if(fGeomMatrix[mod]){
+ if(DebugLevel() > 1)
+ fGeomMatrix[mod]->Print();
+ fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
+ }
+ fGeomMatrixSet=kTRUE;
+ }//SM loop
+ }//Load matrices
+ else if(!gGeoManager){
+ printf("AliAnalysisTaksEMCALClusterize::InitGeometry() - Get geo matrices from data");
+ //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
+ if(!strcmp(fEvent->GetName(),"AliAODEvent")) {
+ if(DebugLevel() > 1)
+ Warning("UserExec","Use ideal geometry, values geometry matrix not kept in AODs.");
+ }//AOD
+ else {
+ if(DebugLevel() > 1)
+ printf("AliAnalysisTaksEMCALClusterize::InitGeometry() - AliAnalysisTaskEMCALClusterize Load Misaligned matrices.");
+ AliESDEvent* esd = dynamic_cast<AliESDEvent*>(fEvent) ;
+ if(!esd) {
+ Error("InitGeometry"," - This event does not contain ESDs?");
+ AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);
+ return;
+ }
+ for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
+ if(DebugLevel() > 1)
+ esd->GetEMCALMatrix(mod)->Print();
+ if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
+ }
+ fGeomMatrixSet=kTRUE;
+ }//ESD
+ }//Load matrices from Data
+
+ //Recover time dependent corrections, put then in recalibration histograms. Do it once
+ fRecoUtils->SetRunDependentCorrections(InputEvent()->GetRunNumber());
+
+ }//first event
+
+}
+
+//___________________________________________________________________
+Bool_t AliAnalysisTaskEMCALClusterize::IsExoticCell(const Int_t absID,
+ const Float_t ecell,
+ const Float_t tcell,
+ AliVCaloCells* cells)
+{
+ //Look to cell neighbourhood and reject if it seems exotic
+
+ if(!fRemoveExoticCells) return kFALSE;
+
+ if(ecell < fExoticCellMinAmplitude) return kFALSE;
+
+ Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
+ fGeom->GetCellIndex(absID,imod,iTower,iIphi,iIeta);
+ fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
+
+ //Get close cells index, energy and time, not in corners
+ Int_t absID1 = fGeom-> GetAbsCellIdFromCellIndexes(imod, iphi+1, ieta);
+ Int_t absID2 = fGeom-> GetAbsCellIdFromCellIndexes(imod, iphi-1, ieta);
+ Int_t absID3 = fGeom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1);
+ Int_t absID4 = fGeom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1);
+
+ Float_t ecell1 = 0, ecell2 = 0, ecell3 = 0, ecell4 = 0;
+ Double_t tcell1 = 0, tcell2 = 0, tcell3 = 0, tcell4 = 0;
+ Bool_t accept1 = 0, accept2 = 0, accept3 = 0, accept4 = 0;
+
+ accept1 = AcceptCalibrateCell(absID1,ecell1,tcell1,cells);
+ accept2 = AcceptCalibrateCell(absID2,ecell2,tcell2,cells);
+ accept3 = AcceptCalibrateCell(absID3,ecell3,tcell3,cells);
+ accept4 = AcceptCalibrateCell(absID4,ecell4,tcell4,cells);
+
+ if(DebugLevel() > 2 ){
+ printf("AliAnalysisTaksEMCALClusterize::IsExoticCell() - Cell absID %d \n",absID);
+ printf("\t accept1 %d, accept2 %d, accept3 %d, accept4 %d\n",
+ accept1,accept2,accept3,accept4);
+ printf("\t id %d: id1 %d, id2 %d, id3 %d, id4 %d\n",
+ absID,absID1,absID2,absID3,absID4);
+ printf("\t e %f: e1 %f, e2 %f, e3 %f, e4 %f\n",
+ ecell,ecell1,ecell2,ecell3,ecell4);
+ printf("\t t %f: t1 %f, t2 %f, t3 %f, t4 %f;\n dt1 %f, dt2 %f, dt3 %f, dt4 %f\n",
+ tcell*1.e9,tcell1*1.e9,tcell2*1.e9,tcell3*1.e9,tcell4*1.e9,
+ TMath::Abs(tcell-tcell1)*1.e9, TMath::Abs(tcell-tcell2)*1.e9, TMath::Abs(tcell-tcell3)*1.e9, TMath::Abs(tcell-tcell4)*1.e9);
+ }
+
+ if(TMath::Abs(tcell-tcell1)*1.e9 > fExoticCellDiffTime) ecell1 = 0 ;
+ if(TMath::Abs(tcell-tcell2)*1.e9 > fExoticCellDiffTime) ecell2 = 0 ;
+ if(TMath::Abs(tcell-tcell3)*1.e9 > fExoticCellDiffTime) ecell3 = 0 ;
+ if(TMath::Abs(tcell-tcell4)*1.e9 > fExoticCellDiffTime) ecell4 = 0 ;
+
+
+ Float_t eCross = ecell1+ecell2+ecell3+ecell4;
+ if(DebugLevel() > 2 ){
+ printf("\t eCell %f, eCross %f, 1-eCross/eCell %f\n",ecell,eCross,1-eCross/ecell);
+ }
+
+ if(1-eCross/ecell > fExoticCellFraction) {
+ //cells->SetCell(icell,absID,0,1e6);
+ if(DebugLevel() > 2 ) printf("AliAnalysisTaskEMCALClusterize::IsExoticCell() - EXOTIC CELL REMOVED id %d, eCell %f, eCross %f, 1-eCross/eCell %f\n",absID,ecell,eCross,1-eCross/ecell);
+ return kTRUE;
+ }
+
+ return kFALSE;
+
+}
+
+//____________________________________________________
+Bool_t AliAnalysisTaskEMCALClusterize::IsExoticEvent()
+{
+
+ // Check if event is exotic, get an exotic cell and compare with triggered patch
+ // If there is a match remove event ... to be completed, filled with something provisional
+
+ if(!fRemoveExoticEvents) return kFALSE;
+
+ // Loop on cells
+ AliVCaloCells * cells = fEvent->GetEMCALCells();
+ Float_t totCellE = 0;
+ for(Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++){
+
+ Float_t ecell = 0 ;
+ Double_t tcell = 0 ;
+
+ Int_t absID = cells->GetCellNumber(icell);
+ Bool_t accept = AcceptCalibrateCell(absID,ecell,tcell,cells);
+ if(accept && !IsExoticCell(absID, ecell,tcell,cells)) totCellE += ecell;
+ }
+
+ // TString triggerclasses = "";
+ // if(esdevent) triggerclasses = esdevent ->GetFiredTriggerClasses();
+ // else triggerclasses = ((AliAODEvent*)event)->GetFiredTriggerClasses();
+ // //
+ // printf("AliAnalysisTaskEMCALClusterize - reject event %d with cluster - reject event with ncells in SM3 %d and SM4 %d\n",(Int_t)Entry(),ncellsSM3, ncellsSM4);
+ // AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);
+ // return;
+ //
+
+ //printf("TotE cell %f\n",totCellE);
+ if(totCellE < 1) return kTRUE;
+
+ return kFALSE;
+
+}
+
+//_________________________________________________
+Bool_t AliAnalysisTaskEMCALClusterize::IsLEDEvent()
+{
+ //Check if event is LED
+
+ if(!fRemoveLEDEvents) return kFALSE;
+
+ // Count number of cells with energy larger than 0.1 in SM3, cut on this number
+ Int_t ncellsSM3 = 0;
+ Int_t ncellsSM4 = 0;
+ AliVCaloCells * cells = fEvent->GetEMCALCells();
+ for(Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++){
+ if(cells->GetAmplitude(icell) > 0.1 && cells->GetCellNumber(icell)/(24*48)==3) ncellsSM3++;
+ if(cells->GetAmplitude(icell) > 0.1 && cells->GetCellNumber(icell)/(24*48)==4) ncellsSM4++;
+ }
+
+ TString triggerclasses = "";
+
+ AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(fEvent);
+ if(esdevent) triggerclasses = esdevent ->GetFiredTriggerClasses();
+ else triggerclasses = ((AliAODEvent*)fEvent)->GetFiredTriggerClasses();
+
+ Int_t ncellcut = 21;
+ if(triggerclasses.Contains("EMC")) ncellcut = 35;
+
+ if( ncellsSM3 >= ncellcut || ncellsSM4 >= 100 ){
+ printf("AliAnalysisTaksEMCALClusterize::IsLEDEvent() - reject event %d with ncells in SM3 %d and SM4 %d\n",(Int_t)Entry(),ncellsSM3, ncellsSM4);
+ AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);
+ return kTRUE;
+ }
+
+ return kFALSE;
+
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskEMCALClusterize::RecPoints2Clusters(TClonesArray *digitsArr,
+ TObjArray *recPoints,
+ TObjArray *clusArray)