<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  EMCAL tender, apply corrections to EMCAl clusters                        //
//  and do track matching.                                                   //
//  Author: <NAME> (Utrecht University)                                // 
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include <TROOT.h>
#include <TFile.h>
#include <TTree.h>
#include <TInterpreter.h>
#include <TObjArray.h>
#include <TClonesArray.h>
#include <TGeoGlobalMagField.h>
#include <AliLog.h>
#include <AliESDEvent.h>
#include <AliAnalysisManager.h>
#include <AliTender.h>
#include "AliOADBContainer.h"
#include "AliCDBManager.h"
#include "AliCDBStorage.h"
#include "AliCDBEntry.h"
#include "AliMagF.h"
#include "AliESDCaloCluster.h"
#include "AliEMCALTenderSupply.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALRecoUtils.h"
#include "AliEMCALClusterizer.h"
#include "AliEMCALRecParam.h"
#include "AliEMCALRecPoint.h"
#include "AliEMCALAfterBurnerUF.h"
#include "AliEMCALClusterizerNxN.h"
#include "AliEMCALClusterizerv1.h"
#include "AliEMCALClusterizerv2.h"
#include "AliEMCALDigit.h"
#include "AliEMCALRecParam.h"

ClassImp(AliEMCALTenderSupply)

AliEMCALTenderSupply::AliEMCALTenderSupply() :
AliTenderSupply()
,fEMCALGeo(0x0)
,fEMCALGeoName("EMCAL_COMPLETEV1")
,fEMCALRecoUtils(0)
,fConfigName("")
,fDebugLevel(0)
,fNonLinearFunc(-1) 
,fNonLinearThreshold(-1)
,fReCalibCluster(kFALSE)
,fUpdateCell(kFALSE)  
,fCalibrateEnergy(kFALSE)
,fCalibrateTime(kFALSE)
,fDoNonLinearity(kFALSE)
,fBadCellRemove(kFALSE)
,fRejectExoticCells(kFALSE)
,fRejectExoticClusters(kFALSE)
,fClusterBadChannelCheck(kFALSE)
,fRecalClusPos(kFALSE)
,fFiducial(kFALSE) 
,fNCellsFromEMCALBorder(-1)
,fRecalDistToBadChannels(kFALSE)
,fRecalShowerShape(kFALSE)
,fInputTree(0)
,fInputFile(0)
,fFilepass(0) 
,fMass(-1)
,fStep(-1)
,fCutEtaPhiSum(kTRUE)
,fCutEtaPhiSeparate(kFALSE)
,fRcut(-1)
,fEtacut(-1)
,fPhicut(-1)
,fBasePath("")
,fReClusterize(kFALSE)
,fClusterizer(0)
,fGeomMatrixSet(kFALSE)
,fLoadGeomMatrices(kFALSE)
,fRecParam(0x0)
,fDoTrackMatch(kFALSE)
,fDoUpdateOnly(kFALSE)
,fUnfolder(0)
,fDigitsArr(0)
,fClusterArr(0)
,fMisalignSurvey(kdefault)  
,fExoticCellFraction(-1)
,fExoticCellDiffTime(-1)
,fExoticCellMinAmplitude(-1)
{
  // Default constructor.
  for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
}

//_____________________________________________________
AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
AliTenderSupply(name,tender)
,fEMCALGeo(0x0)
,fEMCALGeoName("EMCAL_COMPLETEV1")
,fEMCALRecoUtils(0)
,fConfigName("")
,fDebugLevel(0)
,fNonLinearFunc(-1) 
,fNonLinearThreshold(-1)        
,fReCalibCluster(kFALSE)  
,fUpdateCell(kFALSE)  
,fCalibrateEnergy(kFALSE)
,fCalibrateTime(kFALSE)
,fDoNonLinearity(kFALSE)
,fBadCellRemove(kFALSE)
,fRejectExoticCells(kFALSE)
,fRejectExoticClusters(kFALSE)
,fClusterBadChannelCheck(kFALSE)
,fRecalClusPos(kFALSE)
,fFiducial(kFALSE) 
,fNCellsFromEMCALBorder(-1)  
,fRecalDistToBadChannels(kFALSE)  
,fRecalShowerShape(kFALSE)
,fInputTree(0)  
,fInputFile(0)
,fFilepass(0) 
,fMass(-1)
,fStep(-1)
,fCutEtaPhiSum(kTRUE)
,fCutEtaPhiSeparate(kFALSE)
,fRcut(-1)  
,fEtacut(-1)  
,fPhicut(-1)  
,fBasePath("")
,fReClusterize(kFALSE)
,fClusterizer(0)
,fGeomMatrixSet(kFALSE)
,fLoadGeomMatrices(kFALSE)
,fRecParam(0x0)
,fDoTrackMatch(kFALSE)
,fDoUpdateOnly(kFALSE)
,fUnfolder(0)
,fDigitsArr(0)
,fClusterArr(0)
,fMisalignSurvey(kdefault)  
,fExoticCellFraction(-1)
,fExoticCellDiffTime(-1)
,fExoticCellMinAmplitude(-1)
{
  // Named constructor
  
  for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
  fEMCALRecoUtils  = new AliEMCALRecoUtils;
  fDigitsArr       = new TClonesArray("AliEMCALDigit",1000);
}

//_____________________________________________________
AliEMCALTenderSupply::~AliEMCALTenderSupply()
{
  //Destructor
  
  delete fEMCALRecoUtils;
  delete fRecParam;
  delete fUnfolder;
  if (!fClusterizer) {
    fDigitsArr->Clear("C");
    delete fDigitsArr; 
  } else {
    delete fClusterizer;
    fDigitsArr = 0;
  }
}

//_____________________________________________________
void AliEMCALTenderSupply::Init()
{
  // Initialise EMCAL tender.

  if (fDebugLevel>0) 
    AliInfo("Init EMCAL Tender supply"); 
  
  if (fConfigName.Length()>0 && gROOT->LoadMacro(fConfigName) >=0) {
    AliDebug(1, Form("Loading settings from macro %s", fConfigName.Data()));
    AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
    fDebugLevel             = tender->fDebugLevel;
    fEMCALGeoName           = tender->fEMCALGeoName; 
    fEMCALRecoUtils         = tender->fEMCALRecoUtils; 
    fConfigName             = tender->fConfigName;
    fNonLinearFunc          = tender->fNonLinearFunc;
    fNonLinearThreshold     = tender->fNonLinearThreshold;
    fReCalibCluster         = tender->fReCalibCluster;
    fUpdateCell             = tender->fUpdateCell;
    fRecalClusPos           = tender->fRecalClusPos;
    fCalibrateEnergy        = tender->fCalibrateEnergy;
    fCalibrateTime          = tender->fCalibrateTime;
    fFiducial               = tender->fFiducial;
    fNCellsFromEMCALBorder  = tender->fNCellsFromEMCALBorder;
    fRecalDistToBadChannels = tender->fRecalDistToBadChannels;    
    fRecalShowerShape       = tender->fRecalShowerShape;
    fClusterBadChannelCheck = tender->fClusterBadChannelCheck;
    fBadCellRemove          = tender->fBadCellRemove;
    fRejectExoticCells      = tender->fRejectExoticCells;
    fRejectExoticClusters   = tender->fRejectExoticClusters;
    fMass                   = tender->fMass;
    fStep                   = tender->fStep;
    fCutEtaPhiSum           = tender->fCutEtaPhiSum;
    fCutEtaPhiSeparate      = tender->fCutEtaPhiSeparate;
    fRcut                   = tender->fRcut;
    fEtacut                 = tender->fEtacut;
    fPhicut                 = tender->fPhicut;
    fReClusterize           = tender->fReClusterize;
    fLoadGeomMatrices       = tender->fLoadGeomMatrices;
    fRecParam               = tender->fRecParam;
    fDoNonLinearity         = tender->fDoNonLinearity;
    fDoTrackMatch           = tender->fDoTrackMatch;
    fDoUpdateOnly           = tender->fDoUpdateOnly;
    fMisalignSurvey         = tender->fMisalignSurvey;
    fExoticCellFraction     = tender->fExoticCellFraction;
    fExoticCellDiffTime     = tender->fExoticCellDiffTime;
    fExoticCellMinAmplitude = tender->fExoticCellMinAmplitude;

    for(Int_t i = 0; i < 10; i++) 
      fEMCALMatrix[i] = tender->fEMCALMatrix[i] ;
  }

  // Init geometry  
  fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
  
  // Initialising non-linearity parameters
  if( fNonLinearThreshold != -1 )
    fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
  if( fNonLinearFunc != -1 )
    fEMCALRecoUtils->SetNonLinearityFunction(fNonLinearFunc);

  // missalignment function
  fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);

  // fiducial cut
  // do not do the eta0 fiducial cut
  if( fNCellsFromEMCALBorder != -1 )
    fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
  fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
    
  // exotic cell rejection
  if( fExoticCellFraction != -1 )
    fEMCALRecoUtils->SetExoticCellFractionCut( fExoticCellFraction );
  if( fExoticCellDiffTime != -1 )
    fEMCALRecoUtils->SetExoticCellDiffTimeCut( fExoticCellDiffTime );
  if( fExoticCellMinAmplitude != -1 )
    fEMCALRecoUtils->SetExoticCellMinAmplitudeCut( fExoticCellMinAmplitude );

  // Setting track matching parameters ... mass, step size and residual cut
  if( fMass != -1 )
    fEMCALRecoUtils->SetMass(fMass);
  if( fStep != -1 )
    fEMCALRecoUtils->SetStep(fStep);
  
  // spatial cut based on separate eta/phi or common processing
  if(fCutEtaPhiSum){ 
    fEMCALRecoUtils->SwitchOnCutEtaPhiSum(); 
    if( fRcut != -1 )
      fEMCALRecoUtils->SetCutR(fRcut);
  } else if (fCutEtaPhiSeparate) {
    fEMCALRecoUtils->SwitchOnCutEtaPhiSeparate();
    if( fEtacut != -1 )
      fEMCALRecoUtils->SetCutEta(fEtacut);
    if( fPhicut != -1 )
      fEMCALRecoUtils->SetCutPhi(fPhicut);
  }
}

//_____________________________________________________
void AliEMCALTenderSupply::ProcessEvent()
{
  // Event loop.
  
  AliESDEvent *event = fTender->GetEvent();
  if (!event) {
    AliError("ESD event ptr = 0, returning");
    return;
  }
  
  // Initialising parameters once per run number
  if (fTender->RunChanged()){ 

    // initiate default reco params if not supplied by user
    if (!fRecParam)
      InitRecParam();

    // get pass
    GetPass();

    // define what recalib parameters are needed for various switches
    // this is based on implementation in AliEMCALRecoUtils
    Bool_t needBadChannels = fBadCellRemove   | fClusterBadChannelCheck | fRecalDistToBadChannels | fReClusterize;
    Bool_t needRecalib     = fCalibrateEnergy | fReClusterize;
    Bool_t needTimecalib   = fCalibrateTime   | fReClusterize;
    Bool_t needMisalign    = fRecalClusPos    | fReClusterize;
    Bool_t needClusterizer = fReClusterize;

    // Init bad channels
    if( needBadChannels )
    {
      Int_t fInitBC = InitBadChannels();
      if (fInitBC==0)
      {
        AliError("InitBadChannels returned false, returning");
        return;
      }
      if (fInitBC==1)
      {
        AliInfo("InitBadChannels OK");
      }
      if (fInitBC>1)
      {
        AliInfo(Form("No external hot channel set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
      }
    }

    // init recalibration factors
    if( needRecalib ) 
    { 
      Int_t fInitRecalib = InitRecalib();
      if (fInitRecalib==0)
      {
        AliError("InitRecalib returned false, returning");
        return;
      }
      if (fInitRecalib==1)
      {
        AliInfo("InitRecalib OK");
      }
      if (fInitRecalib>1)
      {
        AliInfo(Form("No recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
        fReCalibCluster = kFALSE;
      }
    }
    
    // init time calibration
    if( needTimecalib )
    {
      Int_t initTC = InitTimeCalibration();
      if ( !initTC ) 
      {
        AliError("InitTimeCalibration returned false, returning");
        return;
      }
      if (initTC==1)
      {
        AliInfo("InitTimeCalib OK");
      }
      if( initTC > 1 )
      {
        AliInfo(Form("No external time calibration set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
      }
    }

    // init misalignment matrix
    if( needMisalign ) 
    { 
      if (!InitMisalignMatrix()) {
        
        AliError("InitMisalignmentMatrix returned false, returning");
        return;
      }
      else
        AliInfo("InitMisalignMatrix OK");
    }
    
    // init clusterizer
    if( needClusterizer ) 
    {
      if (!InitClusterization()) 
      {
        AliError("InitClusterization returned false, returning");
        return;
      }
      else
        AliInfo("InitClusterization OK");
    }
    
    if(fDebugLevel>1) 
      fEMCALRecoUtils->Print("");
  }
  
  // disable implied switches -------------------------------------------------
  // AliEMCALRecoUtils or clusterizer functions alredy include some
  // recalibration so based on those implied callibration te switches
  // here are disabled to avoid duplication
    
  // clusterizer does cluster energy recalibration, position recomputation
  // and shower shape
  if( fReClusterize )
  {
    fReCalibCluster   = kFALSE;
    fRecalClusPos     = kFALSE;
    fRecalShowerShape = kFALSE;
  }
  
  // CONFIGURE THE RECO UTILS -------------------------------------------------
  // configure the reco utils
  // this option does energy recalibration<commit_msg>correct to make work with plugin plus other  - Jiri<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  EMCAL tender, apply corrections to EMCAL clusters                        //
//  and do track matching.                                                   //
//  Author: <NAME> (Utrecht University)                                // 
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include <TROOT.h>
#include <TFile.h>
#include <TTree.h>
#include <TInterpreter.h>
#include <TObjArray.h>
#include <TClonesArray.h>
#include <TGeoGlobalMagField.h>
#include <AliLog.h>
#include <AliESDEvent.h>
#include <AliAnalysisManager.h>
#include <AliTender.h>
#include "AliOADBContainer.h"
#include "AliCDBManager.h"
#include "AliCDBStorage.h"
#include "AliCDBEntry.h"
#include "AliMagF.h"
#include "AliESDCaloCluster.h"
#include "AliEMCALTenderSupply.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALRecoUtils.h"
#include "AliEMCALClusterizer.h"
#include "AliEMCALRecParam.h"
#include "AliEMCALRecPoint.h"
#include "AliEMCALAfterBurnerUF.h"
#include "AliEMCALClusterizerNxN.h"
#include "AliEMCALClusterizerv1.h"
#include "AliEMCALClusterizerv2.h"
#include "AliEMCALDigit.h"
#include "AliEMCALRecParam.h"

ClassImp(AliEMCALTenderSupply)

AliEMCALTenderSupply::AliEMCALTenderSupply() :
AliTenderSupply()
,fEMCALGeo(0x0)
,fEMCALGeoName("EMCAL_COMPLETEV1")
,fEMCALRecoUtils(0)
,fConfigName("")
,fDebugLevel(0)
,fNonLinearFunc(-1) 
,fNonLinearThreshold(-1)
,fReCalibCluster(kFALSE)
,fUpdateCell(kFALSE)  
,fCalibrateEnergy(kFALSE)
,fCalibrateTime(kFALSE)
,fDoNonLinearity(kFALSE)
,fBadCellRemove(kFALSE)
,fRejectExoticCells(kFALSE)
,fRejectExoticClusters(kFALSE)
,fClusterBadChannelCheck(kFALSE)
,fRecalClusPos(kFALSE)
,fFiducial(kFALSE) 
,fNCellsFromEMCALBorder(-1)
,fRecalDistToBadChannels(kFALSE)
,fRecalShowerShape(kFALSE)
,fInputTree(0)
,fInputFile(0)
,fFilepass(0) 
,fMass(-1)
,fStep(-1)
,fCutEtaPhiSum(kTRUE)
,fCutEtaPhiSeparate(kFALSE)
,fRcut(-1)
,fEtacut(-1)
,fPhicut(-1)
,fBasePath("")
,fReClusterize(kFALSE)
,fClusterizer(0)
,fGeomMatrixSet(kFALSE)
,fLoadGeomMatrices(kFALSE)
,fRecParam(0x0)
,fDoTrackMatch(kFALSE)
,fDoUpdateOnly(kFALSE)
,fUnfolder(0)
,fDigitsArr(0)
,fClusterArr(0)
,fMisalignSurvey(kdefault)  
,fExoticCellFraction(-1)
,fExoticCellDiffTime(-1)
,fExoticCellMinAmplitude(-1)
{
  // Default constructor.
  for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
  fEMCALRecoUtils  = new AliEMCALRecoUtils;
}

//_____________________________________________________
AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
AliTenderSupply(name,tender)
,fEMCALGeo(0x0)
,fEMCALGeoName("EMCAL_COMPLETEV1")
,fEMCALRecoUtils(0)
,fConfigName("")
,fDebugLevel(0)
,fNonLinearFunc(-1) 
,fNonLinearThreshold(-1)        
,fReCalibCluster(kFALSE)  
,fUpdateCell(kFALSE)  
,fCalibrateEnergy(kFALSE)
,fCalibrateTime(kFALSE)
,fDoNonLinearity(kFALSE)
,fBadCellRemove(kFALSE)
,fRejectExoticCells(kFALSE)
,fRejectExoticClusters(kFALSE)
,fClusterBadChannelCheck(kFALSE)
,fRecalClusPos(kFALSE)
,fFiducial(kFALSE) 
,fNCellsFromEMCALBorder(-1)  
,fRecalDistToBadChannels(kFALSE)  
,fRecalShowerShape(kFALSE)
,fInputTree(0)  
,fInputFile(0)
,fFilepass(0) 
,fMass(-1)
,fStep(-1)
,fCutEtaPhiSum(kTRUE)
,fCutEtaPhiSeparate(kFALSE)
,fRcut(-1)  
,fEtacut(-1)  
,fPhicut(-1)  
,fBasePath("")
,fReClusterize(kFALSE)
,fClusterizer(0)
,fGeomMatrixSet(kFALSE)
,fLoadGeomMatrices(kFALSE)
,fRecParam(0x0)
,fDoTrackMatch(kFALSE)
,fDoUpdateOnly(kFALSE)
,fUnfolder(0)
,fDigitsArr(0)
,fClusterArr(0)
,fMisalignSurvey(kdefault)  
,fExoticCellFraction(-1)
,fExoticCellDiffTime(-1)
,fExoticCellMinAmplitude(-1)
{
  // Named constructor
  
  for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
  fEMCALRecoUtils  = new AliEMCALRecoUtils;
}

//_____________________________________________________
AliEMCALTenderSupply::~AliEMCALTenderSupply()
{
  //Destructor
  
  delete fEMCALRecoUtils;
  delete fRecParam;
  delete fUnfolder;
  if (!fClusterizer) {
    fDigitsArr->Clear("C");
    delete fDigitsArr; 
  } else {
    delete fClusterizer;
    fDigitsArr = 0;
  }
}

//_____________________________________________________
void AliEMCALTenderSupply::Init()
{
  // Initialise EMCAL tender.

  if (fDebugLevel>0) 
    AliWarning("Init EMCAL Tender supply"); 
  
  if (fConfigName.Length()>0 && gROOT->LoadMacro(fConfigName) >=0) {
    AliDebug(1, Form("Loading settings from macro %s", fConfigName.Data()));
    AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
    fDebugLevel             = tender->fDebugLevel;
    fEMCALGeoName           = tender->fEMCALGeoName; 
    fEMCALRecoUtils         = tender->fEMCALRecoUtils; 
    fConfigName             = tender->fConfigName;
    fNonLinearFunc          = tender->fNonLinearFunc;
    fNonLinearThreshold     = tender->fNonLinearThreshold;
    fReCalibCluster         = tender->fReCalibCluster;
    fUpdateCell             = tender->fUpdateCell;
    fRecalClusPos           = tender->fRecalClusPos;
    fCalibrateEnergy        = tender->fCalibrateEnergy;
    fCalibrateTime          = tender->fCalibrateTime;
    fFiducial               = tender->fFiducial;
    fNCellsFromEMCALBorder  = tender->fNCellsFromEMCALBorder;
    fRecalDistToBadChannels = tender->fRecalDistToBadChannels;    
    fRecalShowerShape       = tender->fRecalShowerShape;
    fClusterBadChannelCheck = tender->fClusterBadChannelCheck;
    fBadCellRemove          = tender->fBadCellRemove;
    fRejectExoticCells      = tender->fRejectExoticCells;
    fRejectExoticClusters   = tender->fRejectExoticClusters;
    fMass                   = tender->fMass;
    fStep                   = tender->fStep;
    fCutEtaPhiSum           = tender->fCutEtaPhiSum;
    fCutEtaPhiSeparate      = tender->fCutEtaPhiSeparate;
    fRcut                   = tender->fRcut;
    fEtacut                 = tender->fEtacut;
    fPhicut                 = tender->fPhicut;
    fReClusterize           = tender->fReClusterize;
    fLoadGeomMatrices       = tender->fLoadGeomMatrices;
    fRecParam               = tender->fRecParam;
    fDoNonLinearity         = tender->fDoNonLinearity;
    fDoTrackMatch           = tender->fDoTrackMatch;
    fDoUpdateOnly           = tender->fDoUpdateOnly;
    fMisalignSurvey         = tender->fMisalignSurvey;
    fExoticCellFraction     = tender->fExoticCellFraction;
    fExoticCellDiffTime     = tender->fExoticCellDiffTime;
    fExoticCellMinAmplitude = tender->fExoticCellMinAmplitude;

    for(Int_t i = 0; i < 10; i++) 
      fEMCALMatrix[i] = tender->fEMCALMatrix[i] ;
  }
  
  if (fDebugLevel>0){
    AliInfo( "Emcal Tender settings: ======================================" ); 
    AliInfo( "------------ Switches --------------------------" ); 
    AliInfo( Form( "BadCellRemove : %d", fBadCellRemove )); 
    AliInfo( Form( "ExoticCellRemove : %d", fRejectExoticCells )); 
    AliInfo( Form( "CalibrateEnergy : %d", fCalibrateEnergy )); 
    AliInfo( Form( "CalibrateTime : %d", fCalibrateTime )); 
    AliInfo( Form( "UpdateCell : %d", fUpdateCell )); 
    AliInfo( Form( "DoUpdateOnly : %d", fDoUpdateOnly )); 
    AliInfo( Form( "Reclustering : %d", fReClusterize )); 
    AliInfo( Form( "ClusterBadChannelCheck : %d", fClusterBadChannelCheck )); 
    AliInfo( Form( "ClusterExoticChannelCheck : %d", fRejectExoticClusters )); 
    AliInfo( Form( "CellFiducialRegion : %d", fFiducial )); 
    AliInfo( Form( "ReCalibrateCluster : %d", fReCalibCluster )); 
    AliInfo( Form( "RecalculateClusPos : %d", fRecalClusPos )); 
    AliInfo( Form( "RecalShowerShape : %d", fRecalShowerShape )); 
    AliInfo( Form( "NonLinearityCorrection : %d", fDoNonLinearity )); 
    AliInfo( Form( "RecalDistBadChannel : %d", fRecalDistToBadChannels )); 
    AliInfo( Form( "TrackMatch : %d", fDoTrackMatch )); 
    AliInfo( "------------ Variables -------------------------" ); 
    AliInfo( Form( "DebugLevel : %d", fDebugLevel )); 
    AliInfo( Form( "BasePath : %s", fBasePath.Data() )); 
    AliInfo( Form( "ConfigFileName : %s", fConfigName.Data() )); 
    AliInfo( Form( "EMCALGeometryName : %s", fEMCALGeoName.Data() )); 
    AliInfo( Form( "NonLinearityFunction : %d", fNonLinearFunc )); 
    AliInfo( Form( "NonLinearityThreshold : %d", fNonLinearThreshold )); 
    AliInfo( Form( "MisalignmentMatrixSurvey : %d", fMisalignSurvey )); 
    AliInfo( Form( "NumberOfCellsFromEMCALBorder : %d", fNCellsFromEMCALBorder )); 
    AliInfo( Form( "RCut : %f", fRcut )); 
    AliInfo( Form( "Mass : %f", fMass )); 
    AliInfo( Form( "Step : %f", fStep )); 
    AliInfo( Form( "EtaCut : %f", fEtacut )); 
    AliInfo( Form( "PhiCut : %f", fPhicut )); 
    AliInfo( Form( "ExoticCellFraction : %f", fExoticCellFraction )); 
    AliInfo( Form( "ExoticCellDiffTime : %f", fExoticCellDiffTime )); 
    AliInfo( Form( "ExoticCellMinAmplitude : %f", fExoticCellMinAmplitude )); 
    AliInfo( "=============================================================" ); 
  }

  // Init geometry  
  fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;

  // digits array
  fDigitsArr       = new TClonesArray("AliEMCALDigit",1000);

  // Initialising non-linearity parameters
  if( fNonLinearThreshold != -1 )
    fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
  if( fNonLinearFunc != -1 )
    fEMCALRecoUtils->SetNonLinearityFunction(fNonLinearFunc);

  // missalignment function
  fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);

  // fiducial cut
  // do not do the eta0 fiducial cut
  if( fNCellsFromEMCALBorder != -1 )
    fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
  fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
    
  // exotic cell rejection
  if( fExoticCellFraction != -1 )
    fEMCALRecoUtils->SetExoticCellFractionCut( fExoticCellFraction );
  if( fExoticCellDiffTime != -1 )
    fEMCALRecoUtils->SetExoticCellDiffTimeCut( fExoticCellDiffTime );
  if( fExoticCellMinAmplitude != -1 )
    fEMCALRecoUtils->SetExoticCellMinAmplitudeCut( fExoticCellMinAmplitude );

  // Setting track matching parameters ... mass, step size and residual cut
  if( fMass != -1 )
    fEMCALRecoUtils->SetMass(fMass);
  if( fStep != -1 )
    fEMCALRecoUtils->SetStep(fStep);
  
  // spatial cut based on separate eta/phi or common processing
  if(fCutEtaPhiSum){ 
    fEMCALRecoUtils->SwitchOnCutEtaPhiSum(); 
    if( fRcut != -1 )
      fEMCALRecoUtils->SetCutR(fRcut);
  } else if (fCutEtaPhiSeparate) {
    fEMCALRecoUtils->SwitchOnCutEtaPhiSeparate();
    if( fEtacut != -1 )
      fEMCALRecoUtils->SetCutEta(fEtacut);
    if( fPhicut != -1 )
      fEMCALRecoUtils->SetCutPhi(fPhicut);
  }
}

//_____________________________________________________
void AliEMCALTenderSupply::ProcessEvent()
{
  // Event loop.
  
  AliESDEvent *event = fTender->GetEvent();
  if (!event) {
    AliError("ESD event ptr = 0, returning");
    return;
  }
  
  // Initialising parameters once per run number
  if (fTender->RunChanged()){ 

    // initiate default reco params if not supplied by user
    if (!fRecParam)
      InitRecParam();

    // get pass
    GetPass();

    // define what recalib parameters are needed for various switches
    // this is based on implementation in AliEMCALRecoUtils
    Bool_t needBadChannels = fBadCellRemove   | fClusterBadChannelCheck | fRecalDistToBadChannels | fReClusterize;
    Bool_t needRecalib     = fCalibrateEnergy | fReClusterize;
    Bool_t needTimecalib   = fCalibrateTime   | fReClusterize;
    Bool_t needMisalign    = fRecalClusPos    | fReClusterize;
    Bool_t needClusterizer = fReClusterize;

    // Init bad channels
    if( needBadChannels )
    {
      Int_t fInitBC = InitBadChannels();
      if (fInitBC==0)
      {
        AliError("InitBadChannels returned false, returning");
        return;
      }
      if (fInitBC==1)
      {
        AliWarning("InitBadChannels OK");
      }
      if (fInitBC>1)
      {
        AliWarning(Form("No external hot channel set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
      }
    }

    // init recalibration factors
    if( needRecalib ) 
    { 
      Int_t fInitRecalib = InitRecalib();
      if (fInitRecalib==0)
      {
        AliError("InitRecalib returned false, returning");
        return;
      }
      if (fInitRecalib==1)
      {
        AliWarning("InitRecalib OK");
      }
      if (fInitRecalib>1)
      {
        AliWarning(Form("No recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
        fReCalibCluster = kFALSE;
      }
    }
    
    // init time calibration
    if( needTimecalib )
    {
      Int_t initTC = InitTimeCalibration();
      if ( !initTC ) 
      {
        AliError("InitTimeCalibration returned false, returning");
        return;
      }
      if (initTC==1)
      {
        AliWarning("InitTimeCalib OK");
      }
      if( initTC > 1 )
      {
        AliWarning(Form("No external time calibration set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
      }
    }

    // init misalignment matrix
    if( needMisalign ) 
    { 
      if (!InitMisalignMatrix()) {
        
        AliError("InitMisalignmentMatrix returned false, returning");
        return;
      }
      else
        AliWarning("InitMisalignMatrix OK");
    }
    
    // init clusterizer
    if( needClusterizer ) 
    {
      if (!InitClusterization()) 
      {
        AliError("InitClusterization returned false, returning");
        return;
      }
      else
        AliWarning("InitClusterization OK");
    }
    
    if(fDebugLevel>1) 
      fEMCALRecoUtils->Print("");
  }
  
  // disable implied switches -------------------------------------------------
  // AliEMCALRecoUtils or clusterizer functions alredy include some
  // recalibration so based on those implied callibration te switches
  // here are disabled to avoid duplication
    
  // clusterizer does cluster energy recalibration, position recomputation
  // and shower shape
  if( fReClusterize )
  {
    fReCalibCluster   = kFALSE;
    fRecalClusPos     = kFALSE;
    fRecalShowerShape = kFALSE;
  }
  
  // CONFIGURE THE RECO UTILS -------------------------------------------------
  // configure the reco utils
  // this option does energy recalibration
{'fraction_non_alphanumeric': 0.13998949027850763, 'fraction_numerical': 0.007251707829742512, 'mean_word_length': 2.901858939311099, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 164, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6432029', 'n_tokens_mistral': 9810, 'n_tokens_neox': 9342, 'n_words': 1713}