Add calorimeter utility class for geometry access, cell indexing bad channels rejecti...
authorgconesab <gconesab@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 2 May 2010 14:38:14 +0000 (14:38 +0000)
committergconesab <gconesab@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 2 May 2010 14:38:14 +0000 (14:38 +0000)
16 files changed:
PWG4/PWG4PartCorrBaseLinkDef.h
PWG4/PartCorrBase/AliAnaPartCorrBaseClass.cxx
PWG4/PartCorrBase/AliAnaPartCorrBaseClass.h
PWG4/PartCorrBase/AliAnaPartCorrMaker.cxx
PWG4/PartCorrBase/AliAnaPartCorrMaker.h
PWG4/PartCorrBase/AliCaloTrackAODReader.cxx
PWG4/PartCorrBase/AliCaloTrackAODReader.h
PWG4/PartCorrBase/AliCaloTrackESDReader.cxx
PWG4/PartCorrBase/AliCaloTrackESDReader.h
PWG4/PartCorrBase/AliCaloTrackReader.cxx
PWG4/PartCorrBase/AliCaloTrackReader.h
PWG4/PartCorrBase/AliCalorimeterUtils.cxx [new file with mode: 0755]
PWG4/PartCorrBase/AliCalorimeterUtils.h [new file with mode: 0755]
PWG4/PartCorrDep/AliAnaCalorimeterQA.cxx
PWG4/PartCorrDep/AliAnaPi0.cxx
PWG4/libPWG4PartCorrBase.pkg

index 13fd84e..fc0ee62 100755 (executable)
@@ -17,5 +17,6 @@
 #pragma link C++ class AliCaloTrackESDReader+;
 #pragma link C++ class AliCaloTrackAODReader+;
 #pragma link C++ class AliCaloTrackMCReader+;
+#pragma link C++ class AliCalorimeterUtils+;
 
 #endif
index 52eda52..e4b6d83 100755 (executable)
@@ -27,6 +27,7 @@
 //---- AliRoot system ----
 #include "AliAnaPartCorrBaseClass.h"
 #include "AliCaloTrackReader.h"
+#include "AliCalorimeterUtils.h"
 #include "AliCaloPID.h"
 #include "AliFiducialCut.h"
 #include "AliIsolationCut.h"
@@ -50,6 +51,7 @@ ClassImp(AliAnaPartCorrBaseClass)
     fAODObjArrayName(""), fAddToHistogramsName(""),
     fAODCaloCells(0x0),//fAODCaloClusters(0x0),  
     fCaloPID(0x0), fFidCut(0x0), fIC(0x0),fMCUtils(0x0), fNMS(0x0),
+       fCaloUtils(0x0),
        //fAnaOutContainer(0x0),
     fHistoPtBins(0),   fHistoPtMax(0.),   fHistoPtMin(0.),
     fHistoPhiBins(0),  fHistoPhiMax(0.),  fHistoPhiMin(0.),
@@ -68,7 +70,7 @@ AliAnaPartCorrBaseClass::AliAnaPartCorrBaseClass(const AliAnaPartCorrBaseClass &
   TObject(), fDataMC(abc.fDataMC), fDebug(abc.fDebug),
   fCheckFidCut(abc.fCheckFidCut),  fCheckCaloPID(abc. fCheckCaloPID),
   fRecalculateCaloPID(abc.fRecalculateCaloPID),
-  fMinPt(abc.fMinPt), fMaxPt(abc.fMaxPt), fReader(abc.fReader),  
+  fMinPt(abc.fMinPt), fMaxPt(abc.fMaxPt), fReader(new AliCaloTrackReader(*abc.fReader)),  
   fInputAODBranch(new TClonesArray(*abc.fInputAODBranch)), fInputAODName(abc.fInputAODName),
   fOutputAODBranch(new TClonesArray(*abc.fOutputAODBranch)),fNewAOD(abc.fNewAOD), 
   fOutputAODName(abc.fOutputAODName), fOutputAODClassName(abc.fOutputAODClassName),
@@ -78,6 +80,7 @@ AliAnaPartCorrBaseClass::AliAnaPartCorrBaseClass(const AliAnaPartCorrBaseClass &
   fAODCaloCells(new AliAODCaloCells(*abc.fAODCaloCells)),
   fCaloPID(new AliCaloPID(*abc.fCaloPID)), fFidCut(new AliFiducialCut(*abc.fFidCut)), fIC(new AliIsolationCut(*abc.fIC)),
   fMCUtils(new AliMCAnalysisUtils(*abc.fMCUtils)), fNMS(new AliNeutralMesonSelection(*abc.fNMS)),
+  fCaloUtils(new AliCalorimeterUtils(*abc.fCaloUtils)),
   //fAnaOutContainer(abc.fAnaOutContainer),
   fHistoPtBins(abc.fHistoPtBins),     fHistoPtMax(abc.fHistoPtMax),     fHistoPtMin(abc.fHistoPtMin),
   fHistoPhiBins(abc.fHistoPhiBins),   fHistoPhiMax(abc.fHistoPhiMax),   fHistoPhiMin(abc.fHistoPhiMin),
@@ -103,19 +106,20 @@ AliAnaPartCorrBaseClass & AliAnaPartCorrBaseClass::operator = (const AliAnaPartC
   fCheckCaloPID       = abc.fCheckCaloPID ;
   fCheckFidCut        = abc.fCheckFidCut ; 
        
-  fReader             = abc.fReader ;
   //delete fAODCaloClusters; fAODCaloClusters   = new TClonesArray(*abc.fAODCaloClusters) ;
   delete fAODCaloCells ; fAODCaloCells      = new AliAODCaloCells(*abc.fAODCaloCells) ;
   
   fMinPt   = abc.fMinPt;
   fMaxPt   = abc.fMaxPt;
        
-  delete fCaloPID; fCaloPID = new AliCaloPID        (*abc.fCaloPID);
-  delete fFidCut;  fFidCut  = new AliFiducialCut    (*abc.fFidCut);
-  delete fMCUtils; fMCUtils = new AliMCAnalysisUtils(*abc.fMCUtils);
-  delete fIC;      fIC      = new AliIsolationCut   (*abc.fIC);
-  delete fNMS;     fNMS     = new AliNeutralMesonSelection(*abc.fNMS);
-       
+  delete fCaloPID;   fCaloPID   = new AliCaloPID        (*abc.fCaloPID);
+  delete fFidCut;    fFidCut    = new AliFiducialCut    (*abc.fFidCut);
+  delete fMCUtils;   fMCUtils   = new AliMCAnalysisUtils(*abc.fMCUtils);
+  delete fIC;        fIC        = new AliIsolationCut   (*abc.fIC);
+  delete fNMS;       fNMS       = new AliNeutralMesonSelection(*abc.fNMS);
+  delete fCaloUtils; fCaloUtils = new AliCalorimeterUtils(*abc.fCaloUtils);
+  delete fReader;    fReader    = new AliCaloTrackReader(*abc.fReader) ;
+
   //fAnaOutContainer     = abc.fAnaOutContainer;
        
   delete fInputAODBranch;  fInputAODBranch      = new TClonesArray(*abc.fInputAODBranch) ;
@@ -165,12 +169,13 @@ AliAnaPartCorrBaseClass::~AliAnaPartCorrBaseClass()
 //     delete fAnaOutContainer ;
 //  }
                
-  if(fReader)  delete fReader ;
-  if(fCaloPID) delete fCaloPID ;
-  if(fFidCut)  delete fFidCut ;
-  if(fIC)      delete fIC ;
-  if(fMCUtils) delete fMCUtils ;
-  if(fNMS)     delete fNMS ;
+  if(fReader)    delete fCaloUtils ;
+  if(fCaloUtils) delete fReader ;
+  if(fCaloPID)   delete fCaloPID ;
+  if(fFidCut)    delete fFidCut ;
+  if(fIC)        delete fIC ;
+  if(fMCUtils)   delete fMCUtils ;
+  if(fNMS)       delete fNMS ;
   
 }
 
@@ -476,12 +481,13 @@ void AliAnaPartCorrBaseClass::InitParameters()
   fMinPt = 0.1  ; //Min pt in particle analysis
   fMaxPt = 300. ; //Max pt in particle analysis
 
-  fReader  = new AliCaloTrackReader();
-  fCaloPID = new AliCaloPID();
-  fFidCut  = new AliFiducialCut();
-  fIC      = new AliIsolationCut();
-  fMCUtils = new AliMCAnalysisUtils(); 
-  fNMS     = new AliNeutralMesonSelection;
+  fReader    = new AliCaloTrackReader();
+  fCaloUtils = new AliCalorimeterUtils();
+  fCaloPID   = new AliCaloPID();
+  fFidCut    = new AliFiducialCut();
+  fIC        = new AliIsolationCut();
+  fMCUtils   = new AliMCAnalysisUtils();       
+  fNMS       = new AliNeutralMesonSelection;
   
   //fAnaOutContainer = new TList();
        
index 2a24c88..1cacaad 100755 (executable)
@@ -21,17 +21,18 @@ class AliESDCaloCluster;
 class AliAODCaloCluster;
 class AliAODCaloCells;
 #include "AliCaloTrackReader.h"   
-#include "AliCaloTrackESDReader.h" 
-#include "AliCaloTrackAODReader.h" 
 class AliCaloPID ;
 class AliFiducialCut ;
 class AliIsolationCut ;
 class AliMCAnalysisUtils ;
 class AliNeutralMesonSelection ;
+#include "AliCalorimeterUtils.h" ;
 class AliStack ; 
 class AliHeader ; 
 class AliGenEventHeader ; 
 #include "AliAODPWG4ParticleCorrelation.h"
+class AliEMCALGeoUtils;
+class AliPHOSGeoUtils;
 
 class AliAnaPartCorrBaseClass : public TObject {
        
@@ -73,15 +74,18 @@ public:
   virtual AliCaloTrackReader * GetReader() const {return fReader ; }
   virtual void SetReader(AliCaloTrackReader * const reader) { fReader = reader ; }
   
-  //Calorimeter indexes information
+  //Calorimeter helper class access methods
+  AliEMCALGeoUtils *  GetEMCALGeometry() const { return fCaloUtils->GetEMCALGeometry(); }
+  AliPHOSGeoUtils  *  GetPHOSGeometry()  const { return fCaloUtils->GetPHOSGeometry() ; }
+
   Int_t GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t &iRCU) const {
-         return fReader->GetModuleNumberCellIndexes(absId, calo, icol, irow,iRCU);}
+         return fCaloUtils->GetModuleNumberCellIndexes(absId, calo, icol, irow,iRCU);}
   Int_t GetModuleNumber(AliAODPWG4Particle * part) const {
-         return fReader->GetModuleNumber(part);}
+         return fCaloUtils->GetModuleNumber(part, fReader->GetInputEvent());}
   Int_t GetModuleNumber(AliESDCaloCluster * cluster) const {
-         return ((AliCaloTrackESDReader*)fReader)->GetModuleNumber(cluster);}
+         return fCaloUtils->GetModuleNumber(cluster);}
   Int_t GetModuleNumber(AliAODCaloCluster * cluster) const {
-         return ((AliCaloTrackAODReader*)fReader)->GetModuleNumber(cluster);}
+         return fCaloUtils->GetModuleNumber(cluster);}
        
   virtual void Terminate(TList * /*outputList*/) {;}
        
@@ -94,7 +98,9 @@ public:
   virtual Bool_t NewOutputAOD() const {return fNewAOD;}
   virtual TString GetOutputAODClassName() const {return fOutputAODClassName;}
   virtual void SetOutputAODClassName(TString name) {fOutputAODClassName = name; }
-  
+  virtual AliCalorimeterUtils * GetCaloUtils() const {return fCaloUtils ; }
+  void SetCaloUtils(AliCalorimeterUtils * caloutils) { fCaloUtils = caloutils ; }      
+       
   virtual TString GetAODObjArrayName() const {return fAODObjArrayName;}
   virtual void SetAODObjArrayName(TString name) {fAODObjArrayName = name; }
 
@@ -135,7 +141,7 @@ public:
   
   virtual AliNeutralMesonSelection * GetNeutralMesonSelection() const {return  fNMS ;}
   virtual void SetNeutralMesonSelection(AliNeutralMesonSelection * const nms) { fNMS = nms ;}
-  
+       
   virtual Bool_t     IsDataMC() const {return fDataMC ; }
   virtual void SwitchOnDataMC()    {fDataMC = kTRUE ; }
   virtual void SwitchOffDataMC()    {fDataMC = kFALSE ; }
@@ -156,7 +162,7 @@ public:
   virtual Float_t    GetMinPt()         const {return fMinPt ; }
   virtual void SetMaxPt(Float_t pt)              {fMaxPt = pt ; }
   virtual void SetMinPt(Float_t pt)              {fMinPt = pt ; }
-  void SetPtCutRange(Double_t ptmin, Double_t ptmax)
+  virtual void SetPtCutRange(Double_t ptmin, Double_t ptmax)
   {  fMaxPt=ptmax;   fMinPt=ptmin;}
   
   //Histogrammes setters and getters
@@ -167,9 +173,9 @@ public:
     fHistoPtMin = min ;
   }
   
-  Int_t   GetHistoPtBins()  const { return fHistoPtBins; }
-  Float_t GetHistoPtMin()   const { return fHistoPtMin ; }
-  Float_t GetHistoPtMax()   const { return fHistoPtMax ; }
+  virtual Int_t   GetHistoPtBins()  const { return fHistoPtBins; }
+  virtual Float_t GetHistoPtMin()   const { return fHistoPtMin ; }
+  virtual Float_t GetHistoPtMax()   const { return fHistoPtMax ; }
   
   //Azimuthal angle
   virtual void SetHistoPhiRangeAndNBins(Float_t min, Float_t max, Int_t n) {
@@ -178,9 +184,9 @@ public:
     fHistoPhiMin   = min ;
   }
   
-  Int_t   GetHistoPhiBins()  const { return fHistoPhiBins; }
-  Float_t GetHistoPhiMin()   const { return fHistoPhiMin ; }
-  Float_t GetHistoPhiMax()   const { return fHistoPhiMax ; }
+  virtual Int_t   GetHistoPhiBins()  const { return fHistoPhiBins; }
+  virtual Float_t GetHistoPhiMin()   const { return fHistoPhiMin ; }
+  virtual Float_t GetHistoPhiMax()   const { return fHistoPhiMax ; }
   
   //Pseudorapidity-rapidity
   virtual void SetHistoEtaRangeAndNBins(Float_t min, Float_t max, Int_t n) {
@@ -189,9 +195,9 @@ public:
     fHistoEtaMin  = min ;
   }
   
-  Int_t   GetHistoEtaBins()  const { return fHistoEtaBins; }
-  Float_t GetHistoEtaMin()   const { return fHistoEtaMin ; }
-  Float_t GetHistoEtaMax()   const { return fHistoEtaMax ; }
+  virtual Int_t   GetHistoEtaBins()  const { return fHistoEtaBins; }
+  virtual Float_t GetHistoEtaMin()   const { return fHistoEtaMin ; }
+  virtual Float_t GetHistoEtaMax()   const { return fHistoEtaMax ; }
   
   //Mass
   virtual void SetHistoMassRangeAndNBins(Float_t min, Float_t max, Int_t n) {
@@ -200,9 +206,9 @@ public:
        fHistoMassMin  = min ;
   }
        
-  Int_t   GetHistoMassBins()  const { return fHistoMassBins ; }
-  Float_t GetHistoMassMin()   const { return fHistoMassMin ; }
-  Float_t GetHistoMassMax()   const { return fHistoMassMax ; }
+  virtual Int_t   GetHistoMassBins()  const { return fHistoMassBins ; }
+  virtual Float_t GetHistoMassMin()   const { return fHistoMassMin ; }
+  virtual Float_t GetHistoMassMax()   const { return fHistoMassMax ; }
        
   //Asymetry
   virtual void SetHistoAsymmetryRangeAndNBins(Float_t min, Float_t max, Int_t n) {
@@ -211,9 +217,9 @@ public:
        fHistoAsymMin  = min ;
   }
        
-  Int_t   GetHistoAsymmetryBins()  const { return fHistoAsymBins ; }
-  Float_t GetHistoAsymmetryMin()   const { return fHistoAsymMin ; }
-  Float_t GetHistoAsymmetryMax()   const { return fHistoAsymMax ; }    
+  virtual Int_t   GetHistoAsymmetryBins()  const { return fHistoAsymBins ; }
+  virtual Float_t GetHistoAsymmetryMin()   const { return fHistoAsymMin ; }
+  virtual Float_t GetHistoAsymmetryMax()   const { return fHistoAsymMax ; }    
        
  private:    
   
@@ -245,7 +251,8 @@ public:
   AliIsolationCut          * fIC;      //! Isolation cut 
   AliMCAnalysisUtils       * fMCUtils; //! MonteCarlo Analysis utils 
   AliNeutralMesonSelection * fNMS;     //! Neutral Meson Selection
-  
+  AliCalorimeterUtils      * fCaloUtils ; //  Pointer to CalorimeterUtils
+
   //TList * fAnaOutContainer;  // Temporal histogram output container, contents to be added to the main container passed to the main analysis frame
 
   //Histograms binning and range    
@@ -265,7 +272,7 @@ public:
   Float_t fHistoAsymMax  ;  // Maximum value of asymmetry histogram range
   Float_t fHistoAsymMin  ;  // Minimum value of asymmetry histogram range
        
-  ClassDef(AliAnaPartCorrBaseClass,6)
+  ClassDef(AliAnaPartCorrBaseClass,7)
     } ;
 
 
index 30626dc..9f05750 100755 (executable)
@@ -46,7 +46,7 @@ AliAnaPartCorrMaker::AliAnaPartCorrMaker() :
 TObject(),
 fOutputContainer(new TList ), fAnalysisContainer(new TList ),
 fMakeHisto(0), fMakeAOD(0), fAnaDebug(0), 
-fReader(0x0), fAODBranchList(new TList ), 
+fReader(0x0), fCaloUtils(0x0), fAODBranchList(new TList ), 
 fhNEvents(0x0)
 {
   //Default Ctor
@@ -54,8 +54,10 @@ fhNEvents(0x0)
   
   //Initialize parameters, pointers and histograms
   if(!fReader)
-    fReader = new AliCaloTrackReader();
-  
+    fReader    = new AliCaloTrackReader();
+  if(!fCaloUtils)
+       fCaloUtils = new AliCalorimeterUtils();
+       
   InitParameters();
 }
 
@@ -64,7 +66,9 @@ AliAnaPartCorrMaker::AliAnaPartCorrMaker(const AliAnaPartCorrMaker & maker) :
 TObject(),
 fOutputContainer(new TList()), fAnalysisContainer(new TList()), 
 fMakeHisto(maker.fMakeHisto), fMakeAOD(maker.fMakeAOD), fAnaDebug(maker.fAnaDebug),
-fReader(new AliCaloTrackReader(*maker.fReader)), fAODBranchList(new TList()), 
+fReader(new AliCaloTrackReader(*maker.fReader)), 
+fCaloUtils(new AliCalorimeterUtils(*maker.fCaloUtils)),
+fAODBranchList(new TList()), 
 fhNEvents(maker.fhNEvents)
 {
   // cpy ctor
@@ -110,7 +114,9 @@ AliAnaPartCorrMaker::~AliAnaPartCorrMaker()
   
   if (fReader) delete fReader ;
   
-  
+  if (fCaloUtils) delete fCaloUtils ;
+
+       
   if(fAODBranchList){
 //             for(Int_t iaod = 0; iaod < fAODBranchList->GetEntries(); iaod++)
 //                     fAODBranchList->At(iaod)->Clear();
@@ -148,6 +154,10 @@ TList *AliAnaPartCorrMaker::GetOutputContainer()
     //abort();
   }
 
+  //Initialize the geometry pointers
+  //GetCaloUtils()->InitPHOSGeometry();
+  //GetCaloUtils()->InitEMCALGeometry();
+               
   char newname[128];
   for(Int_t iana = 0; iana <  fAnalysisContainer->GetEntries(); iana++){
     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ;
@@ -188,13 +198,21 @@ void AliAnaPartCorrMaker::Init()
     //abort();
   }
 
+  //Initialize the geometry pointers
+  GetCaloUtils()->InitPHOSGeometry();
+  GetCaloUtils()->InitEMCALGeometry();
+       
   //Initialize reader
   fReader->Init();
+  fReader->SetCaloUtils(fCaloUtils); // pass the calo utils pointer to the reader
        
+  //fCaloUtils->Init();
   for(Int_t iana = 0; iana <  fAnalysisContainer->GetEntries(); iana++){
     
     AliAnaPartCorrBaseClass * ana =  ((AliAnaPartCorrBaseClass *) fAnalysisContainer->At(iana)) ;
     ana->SetReader(fReader); //SetReader for each analysis
+       ana->SetCaloUtils(fCaloUtils); //Set CaloUtils for each analysis
+
     ana->Init();
     
   }//Loop on analysis defined
@@ -232,6 +250,8 @@ void AliAnaPartCorrMaker::Print(const Option_t * opt) const
   
          printf("Print analysis Reader settings :\n") ;
          fReader->Print("");
+         printf("Print analysis Calorimeter Utils settings :\n") ;
+         fCaloUtils->Print("");
   }
 } 
 
@@ -267,6 +287,8 @@ void AliAnaPartCorrMaker::ProcessEvent(const Int_t iEntry, const char * currentF
          return ;
   }
        
+  fCaloUtils->SetGeometryTransformationMatrices(fReader->GetInputEvent());     
+       
   //printf(">>>>>>>>>> BEFORE >>>>>>>>>>>\n");
   //gObjectTable->Print();
   //Loop on analysis algorithms
index 2525a8b..2a818db 100755 (executable)
@@ -22,6 +22,7 @@ class TH1I;
 
 // --- Analysis system ---
 class AliCaloTrackReader ;
+class AliCalorimeterUtils ;
 
 class AliAnaPartCorrMaker : public TObject {
 
@@ -60,8 +61,11 @@ class AliAnaPartCorrMaker : public TObject {
   }
   
   AliCaloTrackReader * GetReader() const {return fReader ; }
-  void SetReader(AliCaloTrackReader * const reader) { fReader = reader ; }
+  void SetReader(AliCaloTrackReader * reader) { fReader = reader ; }
        
+  AliCalorimeterUtils * GetCaloUtils() const {return fCaloUtils ; }
+  void SetCaloUtils(AliCalorimeterUtils * caloutils) { fCaloUtils = caloutils ; }
+       
   //Others
   void Init();
   void InitParameters();
@@ -80,7 +84,9 @@ class AliAnaPartCorrMaker : public TObject {
   Bool_t  fMakeAOD ; // If true makes analysis generating AODs
   Int_t   fAnaDebug; // Debugging info.
  
-  AliCaloTrackReader *  fReader ;   //  Pointer to reader 
+  AliCaloTrackReader  *  fReader ;     //  Pointer to reader 
+  AliCalorimeterUtils *  fCaloUtils ;  //  Pointer to CalorimeterUtils
+
   TList * fAODBranchList ;          //! List with AOD branches created and needed in analysis
 
   TH1I *fhNEvents;                  //! Number of events counter histogram
index 91f9630..4ada8ac 100755 (executable)
@@ -155,9 +155,10 @@ void AliCaloTrackAODReader::FillInputEMCAL() {
     if ( (clus = ((AliAODEvent*)fInputEvent)->GetCaloCluster(iclus)) ) {
       if (clus->IsEMCALCluster()){
                  
-       //Check if the cluster contains any bad channel
-       if(ClusterContainsBadChannel("EMCAL",clus->GetCellsAbsId(), clus->GetNCells())) continue;
-                 
+       //Check if the cluster contains any bad channel and if close to calorimeter borders
+       if(GetCaloUtils()->ClusterContainsBadChannel("EMCAL",clus->GetCellsAbsId(), clus->GetNCells())) continue;
+       if(!GetCaloUtils()->CheckCellFiducialRegion(clus,((AliAODEvent*)fInputEvent)->GetEMCALCells())) continue;
+
        TLorentzVector momentum ;
        clus->GetMomentum(momentum, v);      
        
@@ -227,9 +228,10 @@ void AliCaloTrackAODReader::FillInputPHOS() {
     if ( (clus = ((AliAODEvent*)fInputEvent)->GetCaloCluster(iclus)) ) {
       if (clus->IsPHOSCluster()){
                  
-       //Check if the cluster contains any bad channel
-       if(ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells())) continue;
-                 
+       //Check if the cluster contains any bad channel and if close to calorimeter borders
+       if( GetCaloUtils()->ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells())) continue;
+       if(!GetCaloUtils()->CheckCellFiducialRegion(clus, ((AliAODEvent*)fInputEvent)->GetPHOSCells())) continue;
+
        TLorentzVector momentum ;
        clus->GetMomentum(momentum, v);      
        
@@ -323,46 +325,6 @@ Double_t AliCaloTrackAODReader::GetBField() const {
 
 }
 
-//____________________________________________________________________________________________________________________________________________________
-Int_t AliCaloTrackAODReader::GetModuleNumber(AliAODCaloCluster * cluster) const
-{
-       //Get the EMCAL/PHOS module number that corresponds to this cluster
-       TLorentzVector lv;
-       Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
-       cluster->GetMomentum(lv,v);
-       Float_t phi = lv.Phi();
-       if(phi < 0) phi+=TMath::TwoPi();        
-       Int_t absId = -1;
-       if(cluster->IsEMCALCluster()){
-               GetEMCALGeometry()->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
-               if(GetDebug() > 2) 
-                       printf("AliCaloTrackAODReader::GetModuleNumber(ESD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
-                                  lv.Eta(), phi*TMath::RadToDeg(),absId, GetEMCALGeometry()->GetSuperModuleNumber(absId));
-               return GetEMCALGeometry()->GetSuperModuleNumber(absId) ;
-       }//EMCAL
-       else if(cluster->IsPHOSCluster()) {
-               Int_t    relId[4];
-               if ( cluster->GetNCells() > 0) {
-                       absId = cluster->GetCellAbsId(0);
-                       if(GetDebug() > 2) 
-                               printf("AliCaloTrackAODReader::GetModuleNumber(AOD) - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
-                                          lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
-               }
-               else return -1;
-               
-               if ( absId >= 0) {
-                       GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
-                       if(GetDebug() > 2) 
-                               printf("AliCaloTrackAODReader::GetModuleNumber(AOD) - PHOS: Module %d\n",relId[0]-1);
-                       return relId[0]-1;
-               }
-               else return -1;
-       }//PHOS
-       
-       return -1;
-}
-
-
 //____________________________________________________________________________
 void AliCaloTrackAODReader::SetInputOutputMCEvent(AliVEvent* input, AliAODEvent* aod, AliMCEvent* mc) {
   // Connect the data pointers
index 516a4f7..fb154a7 100755 (executable)
@@ -44,10 +44,7 @@ public:
   void SwitchOffWriteStdAOD() {fWriteOutputStdAOD = kFALSE;}
 
   TString GetFiredTriggerClasses() {return ((AliAODEvent*)GetInputEvent())->GetFiredTriggerClasses();}
-       
-  // Get calorimeter (Super)module number where this cluster falled
-  Int_t GetModuleNumber(AliAODCaloCluster * cluster) const ;
-       
+
   void Print(const Option_t * opt) const;
        
 private:
index ebf87d9..f1b73a6 100755 (executable)
@@ -201,9 +201,10 @@ void AliCaloTrackESDReader::FillInputEMCAL() {
     if ( (clus = ((AliESDEvent*)fInputEvent)->GetCaloCluster(iclus)) ) {
       if (clus->IsEMCAL()){
                  
-       //Check if the cluster contains any bad channel
-       if(ClusterContainsBadChannel("EMCAL",clus->GetCellsAbsId(), clus->GetNCells())) continue;
-                 
+       //Check if the cluster contains any bad channel and if close to calorimeter borders
+       if( GetCaloUtils()->ClusterContainsBadChannel("EMCAL",clus->GetCellsAbsId(), clus->GetNCells())) continue;
+       if(!GetCaloUtils()->CheckCellFiducialRegion(clus, ((AliESDEvent*)fInputEvent)->GetEMCALCells())) continue;
+
        TLorentzVector momentum ;
        clus->GetMomentum(momentum, v);      
        if(fDebug > 3 && momentum.E() > 0.1) printf("AliCaloTrackESDReader::FillInputEMCAL() - all clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
@@ -288,8 +289,9 @@ void AliCaloTrackESDReader::FillInputPHOS() {
     if ( (clus = ((AliESDEvent*)fInputEvent)->GetCaloCluster(iclus)) ) {
       if (clus->IsPHOS()){
                  
-       //Check if the cluster contains any bad channel
-       if(ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells())) continue;
+       //Check if the cluster contains any bad channel and if close to calorimeter borders
+       if( GetCaloUtils()->ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells())) continue;
+       if(!GetCaloUtils()->CheckCellFiducialRegion(clus, ((AliESDEvent*)fInputEvent)->GetPHOSCells())) continue;
 
        TLorentzVector momentum ;
        clus->GetMomentum(momentum, v);      
@@ -375,45 +377,6 @@ void AliCaloTrackESDReader::FillInputPHOSCells() {
   
 }
 
-//____________________________________________________________________________________________________________________________________________________
-Int_t AliCaloTrackESDReader::GetModuleNumber(AliESDCaloCluster * cluster) const
-{
-       //Get the EMCAL/PHOS module number that corresponds to this cluster
-       TLorentzVector lv;
-       Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
-       cluster->GetMomentum(lv,v);
-       Float_t phi = lv.Phi();
-       if(phi < 0) phi+=TMath::TwoPi();        
-       Int_t absId = -1;
-       if(cluster->IsEMCAL()){
-               GetEMCALGeometry()->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
-               if(GetDebug() > 2) 
-                       printf("AliCaloTrackESDReader::GetModuleNumber(ESD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
-                                  lv.Eta(), phi*TMath::RadToDeg(),absId, GetEMCALGeometry()->GetSuperModuleNumber(absId));
-               return GetEMCALGeometry()->GetSuperModuleNumber(absId) ;
-       }//EMCAL
-       else if(cluster->IsPHOS()){
-               Int_t    relId[4];
-               if ( cluster->GetNCells() > 0) {
-                       absId = cluster->GetCellAbsId(0);
-                       if(GetDebug() > 2) 
-                               printf("AliCaloTrackESDReader::GetModuleNumber(ESD) - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
-                                          lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
-               }
-               else return -1;
-               
-               if ( absId >= 0) {
-                       GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
-                       if(GetDebug() > 2) 
-                               printf("AliCaloESDTrackReader::GetModuleNumber(ESD) - PHOS: Module %d\n",relId[0]-1);
-                       return relId[0]-1;
-               }
-               else return -1;
-       }//PHOS
-       
-       return -1;
-}
-
 
 //____________________________________________________________________________
 void AliCaloTrackESDReader::GetVertex(Double_t  v[3]) const {
index bf6dd44..66cf3be 100755 (executable)
@@ -43,11 +43,8 @@ class AliCaloTrackESDReader : public AliCaloTrackReader {
        
   TString GetFiredTriggerClasses() {return ((AliESDEvent*)GetInputEvent())->GetFiredTriggerClasses();}
 
-  // Get calorimeter (Super)module number where this cluster falled
-  Int_t GetModuleNumber(AliESDCaloCluster * cluster) const;
-       
   ClassDef(AliCaloTrackESDReader,1)
-    } ;
+} ;
 
 
 #endif //ALICALOTRACKESDREADER_H
index 7a3f5d1..443333a 100755 (executable)
@@ -28,7 +28,6 @@
 
 // --- ROOT system ---
 #include "TFile.h"
-#include "TGeoManager.h"
 
 //---- ANALYSIS system ----
 #include "AliCaloTrackReader.h"
 #include "AliAODMCHeader.h"
 #include "AliGenPythiaEventHeader.h"
 #include "AliAODEvent.h"
-#include "AliESDEvent.h"
-#include "AliAODPWG4Particle.h"
-#include "AliAODCaloCluster.h"
-#include "AliESDCaloCluster.h"
 
 ClassImp(AliCaloTrackReader)
   
@@ -61,10 +56,7 @@ ClassImp(AliCaloTrackReader)
     fAODPHOSNormalInputEntries(0), fTrackStatus(0), 
     fReadStack(kFALSE), fReadAODMCParticles(kFALSE), 
     fCleanOutputStdAOD(kFALSE), fDeltaAODFileName("deltaAODPartCorr.root"),fFiredTriggerClassName(""),
-    fEMCALGeoName("EMCAL_COMPLETE"),fPHOSGeoName("PHOSgeo"), 
-    fEMCALGeo(0x0), fPHOSGeo(0x0), fEMCALGeoMatrixSet(kFALSE), fPHOSGeoMatrixSet(kFALSE), fAnaLED(kFALSE),
-    fRemoveBadChannels(kFALSE),fEMCALBadChannelMap(new TObjArray()),
-    fPHOSBadChannelMap(new TObjArray()), fTaskName("")
+    fAnaLED(kFALSE),fTaskName(""),fCaloUtils(0x0)
 {
   //Ctor
   
@@ -73,39 +65,35 @@ ClassImp(AliCaloTrackReader)
 }
 
 //____________________________________________________________________________
-AliCaloTrackReader::AliCaloTrackReader(const AliCaloTrackReader & g) :   
-  TObject(g), fEventNumber(g.fEventNumber), fCurrentFileName(g.fCurrentFileName), 
-  fDataType(g.fDataType), fDebug(g.fDebug),
-  fFiducialCut(g.fFiducialCut),
-  fComparePtHardAndJetPt(g.fComparePtHardAndJetPt),
-  fPtHardAndJetPtFactor(g.fPtHardAndJetPtFactor),
-  fCTSPtMin(g.fCTSPtMin), fEMCALPtMin(g.fEMCALPtMin),fPHOSPtMin(g.fPHOSPtMin), 
-  fAODCTS(new TObjArray(*g.fAODCTS)),  
-  fAODEMCAL(new TObjArray(*g.fAODEMCAL)),
-  fAODPHOS(new TObjArray(*g.fAODPHOS)),
-  fEMCALCells(new TNamed(*g.fEMCALCells)),
-  fPHOSCells(new TNamed(*g.fPHOSCells)),
-  fInputEvent(g.fInputEvent), fOutputEvent(g.fOutputEvent), fMC(g.fMC),
-  fFillCTS(g.fFillCTS),fFillEMCAL(g.fFillEMCAL),fFillPHOS(g.fFillPHOS),
-  fFillEMCALCells(g.fFillEMCALCells),fFillPHOSCells(g.fFillPHOSCells),
-  fSecondInputAODTree(g.fSecondInputAODTree), 
-  fSecondInputAODEvent(g.fSecondInputAODEvent),
-  fSecondInputFileName(g.fSecondInputFileName), 
-  fSecondInputFirstEvent(g.fSecondInputFirstEvent),
-  fAODCTSNormalInputEntries(g.fAODCTSNormalInputEntries), 
-  fAODEMCALNormalInputEntries(g.fAODEMCALNormalInputEntries), 
-  fAODPHOSNormalInputEntries(g.fAODPHOSNormalInputEntries),
-  fTrackStatus(g.fTrackStatus),
-  fReadStack(g.fReadStack), fReadAODMCParticles(g.fReadAODMCParticles),
-  fCleanOutputStdAOD(g.fCleanOutputStdAOD), fDeltaAODFileName(g.fDeltaAODFileName),
-  fFiredTriggerClassName(g.fFiredTriggerClassName),
-  fEMCALGeoName(g.fEMCALGeoName),           fPHOSGeoName(g.fPHOSGeoName),
-  fEMCALGeo(new AliEMCALGeoUtils(*g.fEMCALGeo)), fPHOSGeo(new AliPHOSGeoUtils(*g.fPHOSGeo)),
-  fEMCALGeoMatrixSet(g.fEMCALGeoMatrixSet), fPHOSGeoMatrixSet(g.fPHOSGeoMatrixSet),
-  fAnaLED(g.fAnaLED),  fRemoveBadChannels(g.fRemoveBadChannels),
-  fEMCALBadChannelMap(new TObjArray(*g.fEMCALBadChannelMap)),
-  fPHOSBadChannelMap(new TObjArray(*g.fPHOSBadChannelMap)),
-  fTaskName(g.fTaskName)
+AliCaloTrackReader::AliCaloTrackReader(const AliCaloTrackReader & reader) :   
+  TObject(reader), fEventNumber(reader.fEventNumber), fCurrentFileName(reader.fCurrentFileName), 
+  fDataType(reader.fDataType), fDebug(reader.fDebug),
+  fFiducialCut(reader.fFiducialCut),
+  fComparePtHardAndJetPt(reader.fComparePtHardAndJetPt),
+  fPtHardAndJetPtFactor(reader.fPtHardAndJetPtFactor),
+  fCTSPtMin(reader.fCTSPtMin), fEMCALPtMin(reader.fEMCALPtMin),fPHOSPtMin(reader.fPHOSPtMin), 
+  fAODCTS(new TObjArray(*reader.fAODCTS)),  
+  fAODEMCAL(new TObjArray(*reader.fAODEMCAL)),
+  fAODPHOS(new TObjArray(*reader.fAODPHOS)),
+  fEMCALCells(new TNamed(*reader.fEMCALCells)),
+  fPHOSCells(new TNamed(*reader.fPHOSCells)),
+  fInputEvent(reader.fInputEvent), fOutputEvent(reader.fOutputEvent), fMC(reader.fMC),
+  fFillCTS(reader.fFillCTS),fFillEMCAL(reader.fFillEMCAL),fFillPHOS(reader.fFillPHOS),
+  fFillEMCALCells(reader.fFillEMCALCells),fFillPHOSCells(reader.fFillPHOSCells),
+  fSecondInputAODTree(reader.fSecondInputAODTree), 
+  fSecondInputAODEvent(reader.fSecondInputAODEvent),
+  fSecondInputFileName(reader.fSecondInputFileName), 
+  fSecondInputFirstEvent(reader.fSecondInputFirstEvent),
+  fAODCTSNormalInputEntries(reader.fAODCTSNormalInputEntries), 
+  fAODEMCALNormalInputEntries(reader.fAODEMCALNormalInputEntries), 
+  fAODPHOSNormalInputEntries(reader.fAODPHOSNormalInputEntries),
+  fTrackStatus(reader.fTrackStatus),
+  fReadStack(reader.fReadStack), fReadAODMCParticles(reader.fReadAODMCParticles),
+  fCleanOutputStdAOD(reader.fCleanOutputStdAOD), fDeltaAODFileName(reader.fDeltaAODFileName),
+  fFiredTriggerClassName(reader.fFiredTriggerClassName),
+  fAnaLED(reader.fAnaLED), 
+  fTaskName(reader.fTaskName),
+  fCaloUtils(new AliCalorimeterUtils(*reader.fCaloUtils))
 {
   // cpy ctor  
 }
@@ -164,18 +152,6 @@ AliCaloTrackReader::AliCaloTrackReader(const AliCaloTrackReader & g) :
 //     
 //  fFiredTriggerClassName = source.fFiredTriggerClassName  ;
 //     
-//  fEMCALGeoName      = source.fEMCALGeoName ; 
-//  fPHOSGeoName       = source.fPHOSGeoName ; 
-//  fEMCALGeo          = new AliEMCALGeoUtils(*source.fEMCALGeo);  
-//  fPHOSGeo           = new AliPHOSGeoUtils(*source.fPHOSGeo);
-//  fEMCALGeoMatrixSet = source.fEMCALGeoMatrixSet; 
-//  fPHOSGeoMatrixSet  = source.fPHOSGeoMatrixSet;
-//  fAnaLED            = source.fAnaLED;
-//  fRemoveBadChannels = source.fRemoveBadChannels;
-//  fEMCALBadChannelMap= source.fEMCALBadChannelMap;
-//  fPHOSBadChannelMap = source.fPHOSBadChannelMap;
-//
-//     
 //  return *this;
 //  
 //}
@@ -221,61 +197,8 @@ AliCaloTrackReader::~AliCaloTrackReader() {
   }
        
   if(fSecondInputAODEvent) delete fSecondInputAODEvent ;
-
-  if(fPHOSGeo)  delete fPHOSGeo  ;
-  if(fEMCALGeo) delete fEMCALGeo ;
-       
-  if(fEMCALBadChannelMap) { 
-    fEMCALBadChannelMap->Clear();
-    delete  fEMCALBadChannelMap;
-  }
-  if(fPHOSBadChannelMap) { 
-    fPHOSBadChannelMap->Clear();
-    delete  fPHOSBadChannelMap;
-  }
-
-  //fEMCALBadChannelMap. Delete();
-  //fPHOSBadChannelMap. Delete();
-       
-}
-
-//_________________________________________________________________________________________________________
-Bool_t AliCaloTrackReader::ClusterContainsBadChannel(TString calorimeter,UShort_t* cellList, Int_t nCells){
-       // Check that in the cluster cells, there is no bad channel of those stored 
-       // in fEMCALBadChannelMap or fPHOSBadChannelMap
-       
-       if (!fRemoveBadChannels) return kFALSE;
        
-       if(calorimeter == "EMCAL" && !fEMCALBadChannelMap->GetEntries()) return kFALSE;
-       if(calorimeter == "PHOS"  && !fPHOSBadChannelMap ->GetEntries()) return kFALSE;
-
-       Int_t icol = -1;
-       Int_t irow = -1;
-       Int_t imod = -1;
-       for(Int_t iCell = 0; iCell<nCells; iCell++){
-       
-               //Get the column and row
-               if(calorimeter == "EMCAL"){
-                       Int_t iTower = -1, iIphi = -1, iIeta = -1; 
-                       fEMCALGeo->GetCellIndex(cellList[iCell],imod,iTower,iIphi,iIeta); 
-                       if(fEMCALBadChannelMap->GetEntries() <= imod) continue;
-                       fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);                     
-                       if(GetEMCALChannelStatus(imod, icol, irow))return kTRUE;
-               }
-               else if(calorimeter=="PHOS"){
-                       Int_t    relId[4];
-                       fPHOSGeo->AbsToRelNumbering(cellList[iCell],relId);
-                       irow = relId[2];
-                       icol = relId[3];
-                       imod = relId[0]-1;
-                       if(fPHOSBadChannelMap->GetEntries() <= imod)continue;
-                       if(GetPHOSChannelStatus(imod, icol, irow)) return kTRUE;
-               }
-               else return kFALSE;
-               
-       }// cell cluster loop
-
-       return kFALSE;
+  if (fCaloUtils) delete fCaloUtils ;
 
 }
 
@@ -380,102 +303,6 @@ AliAODMCHeader* AliCaloTrackReader::GetAODMCHeader(Int_t input) const {
        }
 }
 
-//____________________________________________________________________________________________________________________________________________________
-Int_t AliCaloTrackReader::GetModuleNumber(AliAODPWG4Particle * particle) const
-{
-       //Get the EMCAL/PHOS module number that corresponds to this particle
-       
-       Int_t absId = -1;
-       if(particle->GetDetector()=="EMCAL"){
-               fEMCALGeo->GetAbsCellIdFromEtaPhi(particle->Eta(),particle->Phi(), absId);
-               if(GetDebug() > 2) 
-                       printf("AliCaloTrackReader::GetModuleNumber() - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
-                                  particle->Eta(), particle->Phi()*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
-               return fEMCALGeo->GetSuperModuleNumber(absId) ;
-       }//EMCAL
-       else if(particle->GetDetector()=="PHOS"){
-               Int_t    relId[4];
-               if(!strcmp(fInputEvent->GetName(),"AliESDEvent"))   {
-                       AliESDCaloCluster *cluster = ((AliESDEvent*)fInputEvent)->GetCaloCluster(particle->GetCaloLabel(0));
-                       if ( cluster->GetNCells() > 0) {
-                               absId = cluster->GetCellAbsId(0);
-                               if(GetDebug() > 2) 
-                                       printf("AliCaloTrackReader::GetModuleNumber(ESD) - PHOS: cluster eta %f, phi %f, e %f, e cluster %f, absId %d\n",
-                                                  particle->Eta(), particle->Phi()*TMath::RadToDeg(), particle->E(), cluster->E(), absId);
-                       }
-                       else return -1;
-               }//ESDs
-               else{
-                       AliAODCaloCluster *cluster = ((AliAODEvent*)fInputEvent)->GetCaloCluster(particle->GetCaloLabel(0));
-                       if ( cluster->GetNCells() > 0) {
-                               absId = cluster->GetCellAbsId(0);
-                               if(GetDebug() > 2) 
-                                       printf("AliCaloTrackReader::GetModuleNumber(AOD) - PHOS: cluster eta %f, phi %f, e %f, e cluster %f, absId %d\n",
-                                                  particle->Eta(), particle->Phi()*TMath::RadToDeg(), particle->E(), cluster->E(), absId);
-                       }
-                       else return -1;
-               }//AODs
-               
-               if ( absId >= 0) {
-                       fPHOSGeo->AbsToRelNumbering(absId,relId);
-                       if(GetDebug() > 2) 
-                               printf("PHOS: Module %d\n",relId[0]-1);
-                       return relId[0]-1;
-               }
-               else return -1;
-       }//PHOS
-       
-       return -1;
-}
-
-
-//_____________________________________________________________________________________________________________
-Int_t AliCaloTrackReader::GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t & iRCU) const
-{
-       //Get the EMCAL/PHOS module, columns, row and RCU number that corresponds to this absId
-       Int_t imod = -1;
-       if ( absId >= 0) {
-               if(calo=="EMCAL"){
-                       Int_t iTower = -1, iIphi = -1, iIeta = -1; 
-                       fEMCALGeo->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
-                       fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
-                       
-                       //RCU0
-                       if (0<=irow&&irow<8) iRCU=0; // first cable row
-                       else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half; 
-                       //second cable row
-                       //RCU1
-                       else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half; 
-                       //second cable row
-                       else if(16<=irow&&irow<24) iRCU=1; // third cable row
-                       
-                       if (imod%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
-                       if (iRCU<0) {
-                               printf("AliCaloTrackReader::GetModuleNumberCellIndexes() - Wrong EMCAL RCU number = %d\n", iRCU);
-                               abort();
-                       }                       
-                       
-                       return imod ;
-               }//EMCAL
-               else{//PHOS
-                       Int_t    relId[4];
-                       fPHOSGeo->AbsToRelNumbering(absId,relId);
-                       irow = relId[2];
-                       icol = relId[3];
-                       imod = relId[0]-1;
-                       iRCU= (Int_t)(relId[2]-1)/16 ;
-                       //Int_t iBranch= (Int_t)(relid[3]-1)/28 ; //0 to 1
-                       if (iRCU >= 4) {
-                               printf("AliCaloTrackReader::GetModuleNumberCellIndexes() - Wrong PHOS RCU number = %d\n", iRCU);
-                               abort();
-                       }                       
-                       return imod;
-               }//PHOS 
-       }
-       
-       return -1;
-}
-
 //_______________________________________________________________
 void AliCaloTrackReader::Init()
 {
@@ -511,11 +338,8 @@ void AliCaloTrackReader::Init()
                }
                else printf("AliCaloTrackReader::Init() - Second input not added, reader is not AOD\n");
        }
-
-       //printf("TaskName in reader: %s\n",fTaskName.Data());
-       fEMCALBadChannelMap->SetName(Form("EMCALBadMap_%s",fTaskName.Data()));
-       fPHOSBadChannelMap->SetName(Form("PHOSBadMap_%s",fTaskName.Data()));
 }
+
 //_______________________________________________________________
 void AliCaloTrackReader::InitParameters()
 {
@@ -540,75 +364,8 @@ void AliCaloTrackReader::InitParameters()
   fCleanOutputStdAOD     = kFALSE; // Clean the standard clusters/tracks?
   fDeltaAODFileName      = "deltaAODPartCorr.root";
   fFiredTriggerClassName      = "";
-  fEMCALGeoName = "EMCAL_COMPLETE";
-  fPHOSGeoName  = "PHOSgeo";
-       
-  if(gGeoManager) {// geoManager was set
-       if(fDebug > 2)printf("AliCaloTrackReader::InitParameters() - Geometry manager available\n");
-       fEMCALGeoMatrixSet = kTRUE;      
-       fPHOSGeoMatrixSet  = kTRUE;      
-  }
-  else{
-       fEMCALGeoMatrixSet = kFALSE;
-       fPHOSGeoMatrixSet  = kFALSE;
-  }
-       
+               
   fAnaLED = kFALSE;
-       
-  fRemoveBadChannels = kFALSE;
-}
-
-//________________________________________________________________
-void AliCaloTrackReader::InitEMCALBadChannelStatusMap(){
-  //Init EMCAL bad channels map
-   if(fDebug > 0 )printf("AliCaloTrackReader::InitEMCALBadChannelStatusMap()\n");
-  //In order to avoid rewriting the same histograms
-  Bool_t oldStatus = TH1::AddDirectoryStatus();
-  TH1::AddDirectory(kFALSE);
-  
-  for (int i = 0; i < 12; i++) fEMCALBadChannelMap->Add(new TH2I(Form("EMCALBadChannelMap_SM%d_%s",i,fTaskName.Data()),Form("EMCALBadChannelMap_SM%d",i),  48, 0, 48, 24, 0, 24));
-  
-  fEMCALBadChannelMap->SetOwner(kTRUE);
-  fEMCALBadChannelMap->Compress();
-  
-  //In order to avoid rewriting the same histograms
-  TH1::AddDirectory(oldStatus);                
-}
-
-//________________________________________________________________
-void AliCaloTrackReader::InitPHOSBadChannelStatusMap(){
-  //Init PHOS bad channels map
-  if(fDebug > 0 )printf("AliCaloTrackReader::InitPHOSBadChannelStatusMap()\n");
-  //In order to avoid rewriting the same histograms
-  Bool_t oldStatus = TH1::AddDirectoryStatus();
-  TH1::AddDirectory(kFALSE);
-  for (int i = 0; i < 5; i++)fPHOSBadChannelMap->Add(new TH2I(Form("PHOSBadChannelMap_Mod%d_%s",i,fTaskName.Data()),Form("PHOSBadChannelMap_Mod%d",i), 56, 0, 56, 64, 0, 64));
-    
-  fPHOSBadChannelMap->SetOwner(kTRUE);
-  fPHOSBadChannelMap->Compress();
-  
-  //In order to avoid rewriting the same histograms
-  TH1::AddDirectory(oldStatus);                
-}
-
-//________________________________________________________________
-void AliCaloTrackReader::InitEMCALGeometry()
-{
-       //Initialize EMCAL geometry if it did not exist previously
-       if (!fEMCALGeo){
-               fEMCALGeo = new AliEMCALGeoUtils(fEMCALGeoName); 
-               if (!gGeoManager && fDebug > 0) printf("AliCaloTrackReader::InitEMCALGeometry() - Careful!, gGeoManager not loaded, load misalign matrices\n");
-       }
-}
-
-//________________________________________________________________
-void AliCaloTrackReader::InitPHOSGeometry()
-{
-       //Initialize PHOS geometry if it did not exist previously
-       if (!fPHOSGeo){
-               fPHOSGeo = new AliPHOSGeoUtils(fPHOSGeoName); 
-               if (!gGeoManager && fDebug > 0) printf("AliCaloTrackReader::InitPHOSGeometry() - Careful!, gGeoManager not loaded, load misalign matrices\n");
-       }       
 }
 
 //________________________________________________________________
@@ -642,7 +399,6 @@ void AliCaloTrackReader::Print(const Option_t * opt) const
   printf("Read Kine from, stack? %d, AOD ? %d \n", fReadStack, fReadAODMCParticles) ;
   printf("Clean std AOD       =     %d\n", fCleanOutputStdAOD) ;
   printf("Delta AOD File Name =     %s\n", fDeltaAODFileName.Data()) ;
-  printf("Remove Clusters with bad channels? %d\n",fRemoveBadChannels);
   printf("    \n") ;
 } 
 
@@ -717,45 +473,7 @@ Bool_t AliCaloTrackReader::FillInputEvent(const Int_t iEntry, const char * curre
     }
     
   }
-       
-  //Get the EMCAL transformation geometry matrices from ESD 
-  if (!gGeoManager && fEMCALGeo) {//&& !fEMCALGeoMatrixSet) {
-    if(fDebug > 1) 
-      printf(" AliCaloTrackReader::FillInputEvent() - Load EMCAL misalignment matrices. \n");
-    if(!strcmp(fInputEvent->GetName(),"AliESDEvent"))  {
-      for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){ 
-       if(((AliESDEvent*)fInputEvent)->GetEMCALMatrix(mod)) {
-         //printf("EMCAL: mod %d, matrix %p\n",mod, ((AliESDEvent*)fInputEvent)->GetEMCALMatrix(mod));
-         fEMCALGeo->SetMisalMatrix(((AliESDEvent*)fInputEvent)->GetEMCALMatrix(mod),mod) ;
-         fEMCALGeoMatrixSet = kTRUE;//At least one, so good
-       }
-      }// loop over super modules      
-    }//ESD as input
-    else {
-      if(fDebug > 1)
-       printf("AliCaloTrackReader::FillInputEvent() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
-         }//AOD as input
-  }//EMCAL geo && no geoManager
-  
-  //Get the PHOS transformation geometry matrices from ESD 
-  if (!gGeoManager && fPHOSGeo && !fPHOSGeoMatrixSet) {
-    if(fDebug > 1) 
-      printf(" AliCaloTrackReader::FillInputEvent() - Load PHOS misalignment matrices. \n");
-    if(!strcmp(fInputEvent->GetName(),"AliESDEvent"))  {
-      for(Int_t mod=0; mod < 5; mod++){ 
-       if(((AliESDEvent*)fInputEvent)->GetPHOSMatrix(mod)) {
-         //printf("PHOS: mod %d, matrix %p\n",mod, ((AliESDEvent*)fInputEvent)->GetPHOSMatrix(mod));
-         fPHOSGeo->SetMisalMatrix(((AliESDEvent*)fInputEvent)->GetPHOSMatrix(mod),mod) ;
-         fPHOSGeoMatrixSet  = kTRUE; //At least one so good
-       }
-      }// loop over modules    
-    }//ESD as input
-    else {
-      if(fDebug > 1) 
-       printf("AliCaloTrackReader::FillInputEvent() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
-    }//AOD as input
-  }//PHOS geo  and  geoManager was not set
-       
+               
   if(fFillCTS)   FillInputCTS();
   if(fFillEMCAL) FillInputEMCAL();
   if(fFillPHOS)  FillInputPHOS();
index a8d2019..ff39e2f 100755 (executable)
 // --- ROOT system ---
 #include "TObject.h" 
 class TObjArray ; 
-class TLorentzVector ;
 #include "TString.h"
-#include "TObjArray.h"
-class TArrayF;  
 class TTree ;
-#include "TH2I.h"
 
 //--- ANALYSIS system ---
 class AliStack ; 
@@ -33,9 +29,7 @@ class AliAODEvent;
 class AliMCEvent;
 class AliFiducialCut;
 class AliAODMCHeader;
-class AliAODPWG4Particle;
-#include "AliPHOSGeoUtils.h"
-#include "AliEMCALGeoUtils.h"
+#include "AliCalorimeterUtils.h"
 
 class AliCaloTrackReader : public TObject {
 
@@ -181,63 +175,16 @@ public:
   void SetFiredTriggerClassName(TString name ) {fFiredTriggerClassName = name ; }
   TString GetFiredTriggerClassName() const {return fFiredTriggerClassName ; }
   virtual TString GetFiredTriggerClasses() {return "";}
-       
-  //Calorimeters Geometry Methods
-  void SetEMCALGeometryName(TString name)   { fEMCALGeoName = name ; }
-  TString EMCALGeometryName() const { return fEMCALGeoName ; }
-  void InitEMCALGeometry() ; 
-  AliEMCALGeoUtils * GetEMCALGeometry() const {return fEMCALGeo;}
-  Bool_t IsEMCALGeoMatrixSet() {return fEMCALGeoMatrixSet; }
-
-  void SetPHOSGeometryName(TString name)   { fPHOSGeoName = name ; }
-  TString PHOSGeometryName() const { return fPHOSGeoName ; }
-  void InitPHOSGeometry() ; 
-  AliPHOSGeoUtils * GetPHOSGeometry() const {return fPHOSGeo;} 
-  Bool_t IsPHOSGeoMatrixSet()  {return fPHOSGeoMatrixSet ; }
 
   void AnalyzeOnlyLED()     {fAnaLED = kTRUE;}
   void AnalyzeOnlyPhysics() {fAnaLED = kFALSE;}
        
-  // Bad channels
-       
-  Bool_t IsBadChannelsRemovalSwitchedOn()  const { return fRemoveBadChannels ; }
-  void SwitchOnBadChannelsRemoval()    {fRemoveBadChannels = kTRUE ; }
-  void SwitchOffBadChannelsRemoval()   {fRemoveBadChannels = kFALSE ; }
-       
-  void InitEMCALBadChannelStatusMap() ;
-  void InitPHOSBadChannelStatusMap () ;
-
-  Int_t GetEMCALChannelStatus(Int_t iSM , Int_t iCol, Int_t iRow) const { 
-    if(fEMCALBadChannelMap->GetEntries()>0) return (Int_t) ((TH2I*)fEMCALBadChannelMap->At(iSM))->GetBinContent(iCol,iRow); 
-    else return -1;}
-
-  Int_t GetPHOSChannelStatus (Int_t imod, Int_t iCol, Int_t iRow) const { 
-    if(fPHOSBadChannelMap->GetEntries()>0)return (Int_t) ((TH2I*)fPHOSBadChannelMap->At(imod))->GetBinContent(iCol,iRow); 
-    else return -1;}
-  
-  void SetEMCALChannelStatus(Int_t iSM , Int_t iCol, Int_t iRow, Double_t c = 1) { 
-    if(!fEMCALBadChannelMap->GetEntries())InitEMCALBadChannelStatusMap() ;
-    ((TH2I*)fEMCALBadChannelMap->At(iSM))->SetBinContent(iCol,iRow,c);}
-  
-  void SetPHOSChannelStatus (Int_t imod, Int_t iCol, Int_t iRow, Double_t c = 1) {
-       if(!fPHOSBadChannelMap->GetEntries()) InitPHOSBadChannelStatusMap() ; 
-       ((TH2I*)fPHOSBadChannelMap->At(imod))->SetBinContent(iCol,iRow,c);}
-    
-  TH2I * GetEMCALChannelStatusMap(Int_t iSM) const {return (TH2I*)fEMCALBadChannelMap->At(iSM);}
-  TH2I * GetPHOSChannelStatusMap(Int_t imod) const {return (TH2I*)fPHOSBadChannelMap->At(imod);}
-
-  void SetEMCALChannelStatusMap(TObjArray *map) {fEMCALBadChannelMap = map;}
-  void SetPHOSChannelStatusMap (TObjArray *map) {fPHOSBadChannelMap  = map;}
-       
-  Bool_t ClusterContainsBadChannel(TString calorimeter,UShort_t* cellList, Int_t nCells);
-       
   TString  GetTaskName() const {return fTaskName;}
   void SetTaskName(TString name) {fTaskName = name;}
 
-  //Calorimeter indexes information
-  Int_t GetModuleNumber(AliAODPWG4Particle * particle) const;
-  Int_t GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t &iRCU) const ;
-       
+  AliCalorimeterUtils * GetCaloUtils() const {return fCaloUtils ; }
+  void SetCaloUtils(AliCalorimeterUtils * caloutils) { fCaloUtils = caloutils ; }
+
  protected:
   Int_t                   fEventNumber; // Event number
   TString          fCurrentFileName; // Current file name under analysis
@@ -285,19 +232,13 @@ public:
   TString        fDeltaAODFileName ;   // Delta AOD file name
   TString        fFiredTriggerClassName  ;  // Name of trigger event type used to do the analysis
 
-  TString        fEMCALGeoName;       // Name of geometry to use for EMCAL.
-  TString        fPHOSGeoName;        // Name of geometry to use for PHOS.     
-  AliEMCALGeoUtils * fEMCALGeo ;      //! EMCAL geometry pointer
-  AliPHOSGeoUtils  * fPHOSGeo  ;      //! PHOS  geometry pointer  
-  Bool_t         fEMCALGeoMatrixSet;  // Check if the transformation matrix is set for EMCAL
-  Bool_t         fPHOSGeoMatrixSet ;  // Check if the transformation matrix is set for PHOS
   Bool_t         fAnaLED;             // Analyze LED data only.
-  Bool_t         fRemoveBadChannels;  // Check the channel status provided and remove clusters with bad channels
-  TObjArray     *fEMCALBadChannelMap; //! Array of histograms with map of bad channels, EMCAL
-  TObjArray     *fPHOSBadChannelMap;  //! Array of histograms with map of bad channels, PHOS
-  TString fTaskName;           // Name of task that executes the analysis
 
-  ClassDef(AliCaloTrackReader,13)
+  TString fTaskName;           // Name of task that executes the analysis
+       
+  AliCalorimeterUtils *  fCaloUtils ;  //  Pointer to CalorimeterUtils
+       
+  ClassDef(AliCaloTrackReader,14)
 } ;
 
 
diff --git a/PWG4/PartCorrBase/AliCalorimeterUtils.cxx b/PWG4/PartCorrBase/AliCalorimeterUtils.cxx
new file mode 100755 (executable)
index 0000000..e345a67
--- /dev/null
@@ -0,0 +1,623 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+/* $Id:  $ */
+
+//_________________________________________________________________________
+// Class utility for Calorimeter specific selection methods                ///
+//
+//
+//
+//-- Author: Gustavo Conesa (LPSC-Grenoble) 
+//////////////////////////////////////////////////////////////////////////////
+
+
+// --- ROOT system ---
+#include "TGeoManager.h"
+
+//---- ANALYSIS system ----
+#include "AliCalorimeterUtils.h"
+#include "AliAODEvent.h"
+#include "AliESDEvent.h"
+#include "AliAODPWG4Particle.h"
+#include "AliAODCaloCluster.h"
+#include "AliESDCaloCluster.h"
+#include "AliAODCaloCells.h"
+#include "AliESDCaloCells.h"
+
+
+ClassImp(AliCalorimeterUtils)
+  
+  
+//____________________________________________________________________________
+  AliCalorimeterUtils::AliCalorimeterUtils() : 
+    TObject(), fDebug(0), 
+    fEMCALGeoName("EMCAL_COMPLETE"),fPHOSGeoName("PHOSgeo"), 
+    fEMCALGeo(0x0), fPHOSGeo(0x0), 
+    fEMCALGeoMatrixSet(kFALSE), fPHOSGeoMatrixSet(kFALSE), 
+    fRemoveBadChannels(kFALSE),
+    fEMCALBadChannelMap(new TObjArray()),fPHOSBadChannelMap(new TObjArray()), 
+    fNCellsFromEMCALBorder(0), fNCellsFromPHOSBorder(0), 
+    fNoEMCALBorderAtEta0(kFALSE)
+{
+  //Ctor
+  
+  //Initialize parameters
+  InitParameters();
+}
+
+//____________________________________________________________________________
+AliCalorimeterUtils::AliCalorimeterUtils(const AliCalorimeterUtils & calo) :   
+  TObject(calo), fDebug(calo.fDebug),
+  fEMCALGeoName(calo.fEMCALGeoName), fPHOSGeoName(calo.fPHOSGeoName),
+  fEMCALGeo(new AliEMCALGeoUtils(*calo.fEMCALGeo)), 
+  fPHOSGeo(new AliPHOSGeoUtils(*calo.fPHOSGeo)),
+  fEMCALGeoMatrixSet(calo.fEMCALGeoMatrixSet), 
+  fPHOSGeoMatrixSet(calo.fPHOSGeoMatrixSet),
+  fRemoveBadChannels(calo.fRemoveBadChannels),
+  fEMCALBadChannelMap(new TObjArray(*calo.fEMCALBadChannelMap)),
+  fPHOSBadChannelMap(new TObjArray(*calo.fPHOSBadChannelMap)),
+  fNCellsFromEMCALBorder(calo.fNCellsFromEMCALBorder),
+  fNCellsFromPHOSBorder(calo.fNCellsFromPHOSBorder), 
+  fNoEMCALBorderAtEta0(calo.fNoEMCALBorderAtEta0)
+{
+  // cpy ctor  
+}
+
+
+//_________________________________
+AliCalorimeterUtils::~AliCalorimeterUtils() {
+  //Dtor
+  
+  if(fPHOSGeo)  delete fPHOSGeo  ;
+  if(fEMCALGeo) delete fEMCALGeo ;
+       
+  if(fEMCALBadChannelMap) { 
+    fEMCALBadChannelMap->Clear();
+    delete  fEMCALBadChannelMap;
+  }
+  if(fPHOSBadChannelMap) { 
+    fPHOSBadChannelMap->Clear();
+    delete  fPHOSBadChannelMap;
+  }
+       
+}
+
+//_______________________________________________________________
+Bool_t AliCalorimeterUtils::CheckCellFiducialRegion(AliAODCaloCluster* cluster, AliAODCaloCells* cells) const {
+       // Given the list of AbsId of the cluster, get the maximum cell and 
+       // check if there are fNCellsFromBorder from the calorimeter border
+       
+       //If the distance to the border is 0 or negative just exit accept all clusters
+       if(cells->GetType()==AliAODCaloCells::kEMCAL && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
+       if(cells->GetType()==AliAODCaloCells::kPHOS  && fNCellsFromPHOSBorder  <= 0 ) return kTRUE;
+
+       //Find cells with maximum amplitude
+       Int_t absIdMax  = -1;
+       Float_t ampMax  = -1;
+       for(Int_t i = 0; i < cluster->GetNCells() ; i++){
+               Int_t absId = cluster->GetCellAbsId(i) ;
+               Float_t amp     = cells->GetCellAmplitude(absId);
+               if(amp > ampMax){
+                       ampMax   = amp;
+                       absIdMax = absId;
+               }
+       }
+       
+       if(fDebug > 1)
+               printf("AliCalorimeterUtils::CheckCellFiducialRegion(AOD) - Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f\n", 
+                  absIdMax, ampMax, cluster->E());
+       
+       if(absIdMax==-1) return kFALSE;
+       
+       //Check if the cell is close to the borders:
+       Bool_t okrow = kFALSE;
+       Bool_t okcol = kFALSE;
+
+       if(cells->GetType()==AliAODCaloCells::kEMCAL){
+       
+               Int_t iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1, iSM = -1; 
+               fEMCALGeo->GetCellIndex(absIdMax,iSM,iTower,iIphi,iIeta); 
+               fEMCALGeo->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);
+               
+               //Check rows/phi
+               if(iSM < 10){
+                       if(iphi >= fNCellsFromEMCALBorder && iphi < 24-fNCellsFromEMCALBorder) okrow =kTRUE; 
+           }
+               else{
+                       if(iphi >= fNCellsFromEMCALBorder && iphi < 12-fNCellsFromEMCALBorder) okrow =kTRUE; 
+               }
+               
+               //Check collumns/eta
+               if(!fNoEMCALBorderAtEta0){
+                       if(ieta  > fNCellsFromEMCALBorder && ieta < 48-fNCellsFromEMCALBorder) okcol =kTRUE; 
+               }
+               else{
+                       if(iSM%2==0){
+                               if(ieta >= fNCellsFromEMCALBorder)     okcol = kTRUE;   
+                       }
+                       else {
+                               if(ieta <  48-fNCellsFromEMCALBorder)  okcol = kTRUE;   
+                       }
+               }//eta 0 not checked
+               if(fDebug > 1)
+               {
+                       printf("AliCalorimeterUtils::CheckCellFiducialRegion(AOD) - EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d ?",
+                                  fNCellsFromEMCALBorder, ieta, iphi, iSM);
+                       if (okcol && okrow ) printf(" YES \n");
+                       else  printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
+               }
+       }//EMCAL
+       else if(cells->GetType()==AliAODCaloCells::kPHOS){
+               Int_t relId[4];
+               Int_t irow = -1, icol = -1;
+               fPHOSGeo->AbsToRelNumbering(absIdMax,relId);
+               irow = relId[2];
+               icol = relId[3];
+               //imod = relId[0]-1;
+               if(irow >= fNCellsFromPHOSBorder && irow < 64-fNCellsFromPHOSBorder) okrow =kTRUE; 
+               if(icol >= fNCellsFromPHOSBorder && icol < 56-fNCellsFromPHOSBorder) okcol =kTRUE; 
+               if(fDebug > 1)
+               {
+                       printf("AliCalorimeterUtils::CheckCellFiducialRegion(AOD) - PHOS Cluster in %d cells fiducial volume: icol %d, irow %d, Module %d?",
+                                  fNCellsFromPHOSBorder, icol, irow, relId[0]-1);
+                       if (okcol && okrow ) printf(" YES \n");
+                       else  printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
+               }
+       }//PHOS
+       
+       if (okcol && okrow) return kTRUE; 
+       else                return kFALSE;
+       
+}      
+
+//_______________________________________________________________
+Bool_t AliCalorimeterUtils::CheckCellFiducialRegion(AliESDCaloCluster* cluster, AliESDCaloCells* cells) const {
+       // Given the list of AbsId of the cluster, get the maximum cell and 
+       // check if there are fNCellsFromBorder from the calorimeter border
+       
+       //If the distance to the border is 0 or negative just exit accept all clusters
+       if(cells->GetType()==AliESDCaloCells::kEMCALCell && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
+       if(cells->GetType()==AliESDCaloCells::kPHOSCell  && fNCellsFromPHOSBorder  <= 0 ) return kTRUE;
+       
+       //Find cell with maximum amplitude
+       Int_t absIdMax  = -1;
+       Float_t ampMax  = -1;
+       for(Int_t i = 0; i < cluster->GetNCells() ; i++){
+               Int_t absId = cluster->GetCellAbsId(i) ;
+               Float_t amp     = cells->GetCellAmplitude(absId);
+               if(amp > ampMax){
+                       ampMax   = amp;
+                       absIdMax = absId;
+               }
+       }
+       
+       if(fDebug > 1)
+               printf("AliCalorimeterUtils::CheckCellFiducialRegion(ESD) - Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f\n", 
+                                                absIdMax, ampMax, cluster->E());
+       if(absIdMax==-1) return kFALSE;
+       
+       //Check if the cell is close to the borders:
+       Bool_t okrow = kFALSE;
+       Bool_t okcol = kFALSE;
+       
+       if(cells->GetType()==AliESDCaloCells::kEMCALCell){
+               
+               Int_t iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1, iSM = -1; 
+               fEMCALGeo->GetCellIndex(absIdMax,iSM,iTower,iIphi,iIeta); 
+               fEMCALGeo->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);
+               
+               //Check rows/phi
+               if(iSM < 10){
+                       if(iphi >= fNCellsFromEMCALBorder && iphi < 24-fNCellsFromEMCALBorder) okrow =kTRUE; 
+           }
+               else{
+                       if(iphi >= fNCellsFromEMCALBorder && iphi < 12-fNCellsFromEMCALBorder) okrow =kTRUE; 
+               }
+               
+               //Check collumns/eta
+               if(!fNoEMCALBorderAtEta0){
+                       if(ieta  > fNCellsFromEMCALBorder && ieta < 48-fNCellsFromEMCALBorder) okcol =kTRUE; 
+               }
+               else{
+                       if(iSM%2==0){
+                               if(ieta >= fNCellsFromEMCALBorder)     okcol = kTRUE;   
+                       }
+                       else {
+                               if(ieta <  48-fNCellsFromEMCALBorder)  okcol = kTRUE;   
+                       }
+               }//eta 0 not checked
+               if(fDebug > 1)
+               {
+                       printf("AliCalorimeterUtils::CheckCellFiducialRegion(ESD) - EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d ?",
+                                  fNCellsFromEMCALBorder, ieta, iphi, iSM);
+                       if (okcol && okrow ) printf(" YES \n");
+                       else  printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
+               }
+       }//EMCAL
+       else if(cells->GetType()==AliESDCaloCells::kPHOSCell){
+               Int_t relId[4];
+               Int_t irow = -1, icol = -1;
+               fPHOSGeo->AbsToRelNumbering(absIdMax,relId);
+               irow = relId[2];
+               icol = relId[3];
+               //imod = relId[0]-1;
+               if(irow >= fNCellsFromPHOSBorder && irow < 64-fNCellsFromPHOSBorder) okrow =kTRUE; 
+               if(icol >= fNCellsFromPHOSBorder && icol < 56-fNCellsFromPHOSBorder) okcol =kTRUE; 
+               if(fDebug > 1)
+               {
+                       printf("AliCalorimeterUtils::CheckCellFiducialRegion(ESD) - PHOS Cluster in %d cells fiducial volume: icol %d, irow %d, Module %d ?",
+                                  fNCellsFromPHOSBorder, icol, irow,relId[0]-1);
+                       if (okcol && okrow ) printf(" YES \n");
+                       else  printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
+               }
+       }//PHOS
+       
+       if (okcol && okrow) return kTRUE; 
+       else                return kFALSE;
+       
+}      
+
+
+//_________________________________________________________________________________________________________
+Bool_t AliCalorimeterUtils::ClusterContainsBadChannel(TString calorimeter,UShort_t* cellList, Int_t nCells){
+       // Check that in the cluster cells, there is no bad channel of those stored 
+       // in fEMCALBadChannelMap or fPHOSBadChannelMap
+       
+       if (!fRemoveBadChannels) return kFALSE;
+       
+       if(calorimeter == "EMCAL" && !fEMCALBadChannelMap->GetEntries()) return kFALSE;
+       if(calorimeter == "PHOS"  && !fPHOSBadChannelMap ->GetEntries()) return kFALSE;
+
+       Int_t icol = -1;
+       Int_t irow = -1;
+       Int_t imod = -1;
+       for(Int_t iCell = 0; iCell<nCells; iCell++){
+       
+               //Get the column and row
+               if(calorimeter == "EMCAL"){
+                       Int_t iTower = -1, iIphi = -1, iIeta = -1; 
+                       fEMCALGeo->GetCellIndex(cellList[iCell],imod,iTower,iIphi,iIeta); 
+                       if(fEMCALBadChannelMap->GetEntries() <= imod) continue;
+                       fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);                     
+                       if(GetEMCALChannelStatus(imod, icol, irow))return kTRUE;
+               }
+               else if(calorimeter=="PHOS"){
+                       Int_t    relId[4];
+                       fPHOSGeo->AbsToRelNumbering(cellList[iCell],relId);
+                       irow = relId[2];
+                       icol = relId[3];
+                       imod = relId[0]-1;
+                       if(fPHOSBadChannelMap->GetEntries() <= imod)continue;
+                       if(GetPHOSChannelStatus(imod, icol, irow)) return kTRUE;
+               }
+               else return kFALSE;
+               
+       }// cell cluster loop
+
+       return kFALSE;
+
+}
+
+//____________________________________________________________________________________________________________________________________________________
+Int_t AliCalorimeterUtils::GetModuleNumber(AliAODPWG4Particle * particle, AliVEvent * inputEvent) const
+{
+       //Get the EMCAL/PHOS module number that corresponds to this particle
+       
+       Int_t absId = -1;
+       if(particle->GetDetector()=="EMCAL"){
+               fEMCALGeo->GetAbsCellIdFromEtaPhi(particle->Eta(),particle->Phi(), absId);
+               if(fDebug > 2) 
+                 printf("AliCalorimeterUtils::GetModuleNumber(PWG4AOD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
+                        particle->Eta(), particle->Phi()*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
+               return fEMCALGeo->GetSuperModuleNumber(absId) ;
+       }//EMCAL
+       else if(particle->GetDetector()=="PHOS"){
+               if(!strcmp(inputEvent->GetName(),"AliESDEvent"))   {
+                       AliESDCaloCluster *cluster = ((AliESDEvent*)inputEvent)->GetCaloCluster(particle->GetCaloLabel(0));
+                       return GetModuleNumber(cluster);
+               }//ESDs
+               else{
+                       AliAODCaloCluster *cluster = ((AliAODEvent*)inputEvent)->GetCaloCluster(particle->GetCaloLabel(0));
+                       return GetModuleNumber(cluster);
+               }//AODs
+       }//PHOS
+       
+       return -1;
+}
+
+//____________________________________________________________________________________________________________________________________________________
+Int_t AliCalorimeterUtils::GetModuleNumber(AliAODCaloCluster * cluster) const
+{
+       //Get the EMCAL/PHOS module number that corresponds to this cluster, input are AODs
+       TLorentzVector lv;
+       Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
+       cluster->GetMomentum(lv,v);
+       Float_t phi = lv.Phi();
+       if(phi < 0) phi+=TMath::TwoPi();        
+       Int_t absId = -1;
+       if(cluster->IsEMCALCluster()){
+               fEMCALGeo->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
+               if(fDebug > 2) 
+                 printf("AliCalorimeterUtils::GetModuleNumber(ESD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
+                        lv.Eta(), phi*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
+               return fEMCALGeo->GetSuperModuleNumber(absId) ;
+       }//EMCAL
+       else if(cluster->IsPHOSCluster()) {
+               Int_t    relId[4];
+               if ( cluster->GetNCells() > 0) {
+                       absId = cluster->GetCellAbsId(0);
+                       if(fDebug > 2) 
+                               printf("AliCalorimeterUtils::GetModuleNumber(AOD) - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
+                                          lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
+               }
+               else return -1;
+               
+               if ( absId >= 0) {
+                       fPHOSGeo->AbsToRelNumbering(absId,relId);
+                       if(fDebug > 2) 
+                         printf("AliCalorimeterUtils::GetModuleNumber(AOD) - PHOS: Module %d\n",relId[0]-1);
+                       return relId[0]-1;
+               }
+               else return -1;
+       }//PHOS
+       
+       return -1;
+}
+
+//____________________________________________________________________________________________________________________________________________________
+Int_t AliCalorimeterUtils::GetModuleNumber(AliESDCaloCluster * cluster) const
+{
+       //Get the EMCAL/PHOS module number that corresponds to this cluster, input are ESDs
+       TLorentzVector lv;
+       Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
+       cluster->GetMomentum(lv,v);
+       Float_t phi = lv.Phi();
+       if(phi < 0) phi+=TMath::TwoPi();        
+       Int_t absId = -1;
+       if(cluster->IsEMCAL()){
+               fEMCALGeo->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
+               if(fDebug > 2) 
+                 printf("AliCalorimeterUtils::GetModuleNumber(ESD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
+                        lv.Eta(), phi*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
+               return fEMCALGeo->GetSuperModuleNumber(absId) ;
+       }//EMCAL
+       else if(cluster->IsPHOS()){
+               Int_t    relId[4];
+               if ( cluster->GetNCells() > 0) {
+                       absId = cluster->GetCellAbsId(0);
+                       if(fDebug > 2) 
+                         printf("AliCalorimeterUtils::GetModuleNumber(ESD) - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
+                                lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
+               }
+               else return -1;
+               
+               if ( absId >= 0) {
+                       fPHOSGeo->AbsToRelNumbering(absId,relId);
+                       if(fDebug > 2) 
+                         printf("AliCalorimeterUtils::GetModuleNumber(ESD) - PHOS: Module %d\n",relId[0]-1);
+                       return relId[0]-1;
+               }
+               else return -1;
+       }//PHOS
+       
+       return -1;
+}
+
+
+//_____________________________________________________________________________________________________________
+Int_t AliCalorimeterUtils::GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t & iRCU) const
+{
+       //Get the EMCAL/PHOS module, columns, row and RCU number that corresponds to this absId
+       Int_t imod = -1;
+       if ( absId >= 0) {
+               if(calo=="EMCAL"){
+                       Int_t iTower = -1, iIphi = -1, iIeta = -1; 
+                       fEMCALGeo->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
+                       fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
+                       
+                       //RCU0
+                       if (0<=irow&&irow<8) iRCU=0; // first cable row
+                       else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half; 
+                       //second cable row
+                       //RCU1
+                       else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half; 
+                       //second cable row
+                       else if(16<=irow&&irow<24) iRCU=1; // third cable row
+                       
+                       if (imod%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
+                       if (iRCU<0) {
+                               printf("AliCalorimeterUtils::GetModuleNumberCellIndexes() - Wrong EMCAL RCU number = %d\n", iRCU);
+                               abort();
+                       }                       
+                       
+                       return imod ;
+               }//EMCAL
+               else{//PHOS
+                       Int_t    relId[4];
+                       fPHOSGeo->AbsToRelNumbering(absId,relId);
+                       irow = relId[2];
+                       icol = relId[3];
+                       imod = relId[0]-1;
+                       iRCU= (Int_t)(relId[2]-1)/16 ;
+                       //Int_t iBranch= (Int_t)(relid[3]-1)/28 ; //0 to 1
+                       if (iRCU >= 4) {
+                               printf("AliCalorimeterUtils::GetModuleNumberCellIndexes() - Wrong PHOS RCU number = %d\n", iRCU);
+                               abort();
+                       }                       
+                       return imod;
+               }//PHOS 
+       }
+       
+       return -1;
+}
+
+//_______________________________________________________________
+//void AliCalorimeterUtils::Init()
+//{
+//     //Init reader. Method to be called in AliAnaPartCorrMaker
+//     
+//     fEMCALBadChannelMap->SetName(Form("EMCALBadMap_%s",fTaskName.Data()));
+//     fPHOSBadChannelMap->SetName(Form("PHOSBadMap_%s",fTaskName.Data()));
+//}
+
+//_______________________________________________________________
+void AliCalorimeterUtils::InitParameters()
+{
+  //Initialize the parameters of the analysis.
+  fEMCALGeoName = "EMCAL_COMPLETE";
+  fPHOSGeoName  = "PHOSgeo";
+       
+  if(gGeoManager) {// geoManager was set
+       if(fDebug > 2)printf("AliCalorimeterUtils::InitParameters() - Geometry manager available\n");
+       fEMCALGeoMatrixSet = kTRUE;      
+       fPHOSGeoMatrixSet  = kTRUE;      
+  }
+  else{
+       fEMCALGeoMatrixSet = kFALSE;
+       fPHOSGeoMatrixSet  = kFALSE;
+  }
+               
+  fRemoveBadChannels   = kFALSE;
+       
+  fNCellsFromEMCALBorder   = 0;
+  fNCellsFromPHOSBorder    = 0;
+  fNoEMCALBorderAtEta0     = kFALSE;
+}
+
+//________________________________________________________________
+void AliCalorimeterUtils::InitEMCALBadChannelStatusMap(){
+  //Init EMCAL bad channels map
+   if(fDebug > 0 )printf("AliCalorimeterUtils::InitEMCALBadChannelStatusMap()\n");
+  //In order to avoid rewriting the same histograms
+  Bool_t oldStatus = TH1::AddDirectoryStatus();
+  TH1::AddDirectory(kFALSE);
+  
+  //for (int i = 0; i < 12; i++) fEMCALBadChannelMap->Add(new TH2I(Form("EMCALBadChannelMap_SM%d_%s",i,fTaskName.Data()),Form("EMCALBadChannelMap_SM%d",i),  48, 0, 48, 24, 0, 24));
+  for (int i = 0; i < 12; i++) fEMCALBadChannelMap->Add(new TH2I(Form("EMCALBadChannelMap_SM%d",i),Form("EMCALBadChannelMap_SM%d",i),  48, 0, 48, 24, 0, 24));
+
+  fEMCALBadChannelMap->SetOwner(kTRUE);
+  fEMCALBadChannelMap->Compress();
+  
+  //In order to avoid rewriting the same histograms
+  TH1::AddDirectory(oldStatus);                
+}
+
+//________________________________________________________________
+void AliCalorimeterUtils::InitPHOSBadChannelStatusMap(){
+  //Init PHOS bad channels map
+  if(fDebug > 0 )printf("AliCalorimeterUtils::InitPHOSBadChannelStatusMap()\n");
+  //In order to avoid rewriting the same histograms
+  Bool_t oldStatus = TH1::AddDirectoryStatus();
+  TH1::AddDirectory(kFALSE);
+  //for (int i = 0; i < 5; i++)fPHOSBadChannelMap->Add(new TH2I(Form("PHOSBadChannelMap_Mod%d_%s",i,fTaskName.Data()),Form("PHOSBadChannelMap_Mod%d",i), 56, 0, 56, 64, 0, 64));
+  for (int i = 0; i < 5; i++)fPHOSBadChannelMap->Add(new TH2I(Form("PHOSBadChannelMap_Mod%d",i),Form("PHOSBadChannelMap_Mod%d",i), 56, 0, 56, 64, 0, 64));
+
+  fPHOSBadChannelMap->SetOwner(kTRUE);
+  fPHOSBadChannelMap->Compress();
+  
+  //In order to avoid rewriting the same histograms
+  TH1::AddDirectory(oldStatus);                
+}
+
+//________________________________________________________________
+void AliCalorimeterUtils::InitEMCALGeometry()
+{
+       //Initialize EMCAL geometry if it did not exist previously
+       if (!fEMCALGeo){
+               fEMCALGeo = new AliEMCALGeoUtils(fEMCALGeoName);
+               if(fDebug > 0){
+                       printf("AliCalorimeterUtils::InitEMCALGeometry()");
+                       if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
+                       printf("\n");
+               }
+       }
+}
+
+//________________________________________________________________
+void AliCalorimeterUtils::InitPHOSGeometry()
+{
+       //Initialize PHOS geometry if it did not exist previously
+       if (!fPHOSGeo){
+               fPHOSGeo = new AliPHOSGeoUtils(fPHOSGeoName); 
+               if(fDebug > 0){
+                       printf("AliCalorimeterUtils::InitPHOSGeometry()");
+                       if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
+                       printf("\n");
+               }       
+       }       
+}
+
+//________________________________________________________________
+void AliCalorimeterUtils::Print(const Option_t * opt) const
+{
+
+  //Print some relevant parameters set for the analysis
+  if(! opt)
+    return;
+
+  printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
+  printf("Remove Clusters with bad channels? %d\n",fRemoveBadChannels);
+  printf("Remove Clusters with max cell at less than %d cells from EMCAL border and %d cells from PHOS border\n",
+        fNCellsFromEMCALBorder, fNCellsFromPHOSBorder);
+  if(fNoEMCALBorderAtEta0) printf("Do not remove EMCAL clusters at Eta = 0\n");
+
+  printf("    \n") ;
+} 
+
+//________________________________________________________________
+void AliCalorimeterUtils::SetGeometryTransformationMatrices(AliVEvent* inputEvent) 
+{
+  //Set the calorimeters transformation matrices
+       
+  //Get the EMCAL transformation geometry matrices from ESD 
+  if (!gGeoManager && fEMCALGeo) {//&& !fEMCALGeoMatrixSet) { FIXME
+         if(fDebug > 1) 
+                 printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load EMCAL misalignment matrices. \n");
+         if(!strcmp(inputEvent->GetName(),"AliESDEvent"))  {
+                       for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){ 
+                               if(((AliESDEvent*)inputEvent)->GetEMCALMatrix(mod)) {
+                                       //printf("EMCAL: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetEMCALMatrix(mod));
+                                       fEMCALGeo->SetMisalMatrix(((AliESDEvent*)inputEvent)->GetEMCALMatrix(mod),mod) ;
+                                       fEMCALGeoMatrixSet = kTRUE;//At least one, so good
+                               }
+                       }// loop over super modules     
+               }//ESD as input
+               else {
+                       if(fDebug > 1)
+                               printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
+                               }//AOD as input
+  }//EMCAL geo && no geoManager
+       
+       //Get the PHOS transformation geometry matrices from ESD 
+       if (!gGeoManager && fPHOSGeo && !fPHOSGeoMatrixSet) {
+               if(fDebug > 1) 
+                       printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load PHOS misalignment matrices. \n");
+                       if(!strcmp(inputEvent->GetName(),"AliESDEvent"))  {
+                               for(Int_t mod=0; mod < 5; mod++){ 
+                                       if(((AliESDEvent*)inputEvent)->GetPHOSMatrix(mod)) {
+                                               //printf("PHOS: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetPHOSMatrix(mod));
+                                               fPHOSGeo->SetMisalMatrix(((AliESDEvent*)inputEvent)->GetPHOSMatrix(mod),mod) ;
+                                               fPHOSGeoMatrixSet  = kTRUE; //At least one so good
+                                       }
+                               }// loop over modules   
+                       }//ESD as input
+                       else {
+                               if(fDebug > 1) 
+                                       printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
+                                       }//AOD as input
+       }//PHOS geo     and  geoManager was not set
+
+}
+
diff --git a/PWG4/PartCorrBase/AliCalorimeterUtils.h b/PWG4/PartCorrBase/AliCalorimeterUtils.h
new file mode 100755 (executable)
index 0000000..8f57336
--- /dev/null
@@ -0,0 +1,142 @@
+#ifndef ALICALORIMETERUTILS_H
+#define ALICALORIMETERUTILS_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+/* $Id:  $ */
+
+//_________________________________________________________________________
+// Class utility for Calorimeter specific selection methods                ///
+//
+//
+//
+//-- Author: Gustavo Conesa (LPSC-Grenoble) 
+//////////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+#include "TObject.h" 
+#include "TString.h"
+#include "TObjArray.h"
+class TArrayF;  
+#include "TH2I.h"
+
+//--- ANALYSIS system ---
+class AliVEvent;
+class AliAODPWG4Particle;
+class AliAODCaloCluster;
+class AliAODCaloCells;
+class AliESDCaloCluster;
+class AliESDCaloCells;
+#include "AliPHOSGeoUtils.h"
+#include "AliEMCALGeoUtils.h"
+
+class AliCalorimeterUtils : public TObject {
+
+public: 
+  
+  AliCalorimeterUtils() ; // ctor
+  AliCalorimeterUtils(const AliCalorimeterUtils & g) ; // cpy ctor
+  virtual ~AliCalorimeterUtils() ;//virtual dtor
+
+private:
+  AliCalorimeterUtils & operator = (const AliCalorimeterUtils & g) ;//cpy assignment
+
+public:
+  
+  virtual void InitParameters();
+  virtual void Print(const Option_t * opt) const;
+
+  virtual Int_t GetDebug()         const { return fDebug ; }
+  virtual void  SetDebug(Int_t d)        { fDebug = d ; }
+       
+  //virtual void Init();
+       
+  //Calorimeters Geometry Methods
+  AliEMCALGeoUtils * GetEMCALGeometry() const { return fEMCALGeo;}
+  TString  EMCALGeometryName()          const { return fEMCALGeoName ; }  
+  void  SetEMCALGeometryName(TString name)    { fEMCALGeoName = name ; }
+  void InitEMCALGeometry() ; 
+  Bool_t IsEMCALGeoMatrixSet()          const { return fEMCALGeoMatrixSet; }
+       
+  AliPHOSGeoUtils * GetPHOSGeometry() const { return fPHOSGeo;}        
+  TString  PHOSGeometryName()         const { return fPHOSGeoName ; }  
+  void  SetPHOSGeometryName(TString name)   { fPHOSGeoName = name ; }
+  void InitPHOSGeometry() ; 
+  Bool_t IsPHOSGeoMatrixSet()         const {return fPHOSGeoMatrixSet ; }
+
+  void SetGeometryTransformationMatrices(AliVEvent* inputEvent) ;
+       
+  // Bad channels
+  Bool_t IsBadChannelsRemovalSwitchedOn()  const { return fRemoveBadChannels ; }
+  void SwitchOnBadChannelsRemoval()    {fRemoveBadChannels = kTRUE ; }
+  void SwitchOffBadChannelsRemoval()   {fRemoveBadChannels = kFALSE ; }
+       
+  void InitEMCALBadChannelStatusMap() ;
+  void InitPHOSBadChannelStatusMap () ;
+
+  Int_t GetEMCALChannelStatus(Int_t iSM , Int_t iCol, Int_t iRow) const { 
+    if(fEMCALBadChannelMap->GetEntries()>0) return (Int_t) ((TH2I*)fEMCALBadChannelMap->At(iSM))->GetBinContent(iCol,iRow); 
+    else return -1;}
+
+  Int_t GetPHOSChannelStatus (Int_t imod, Int_t iCol, Int_t iRow) const { 
+    if(fPHOSBadChannelMap->GetEntries()>0)return (Int_t) ((TH2I*)fPHOSBadChannelMap->At(imod))->GetBinContent(iCol,iRow); 
+    else return -1;}
+  
+  void SetEMCALChannelStatus(Int_t iSM , Int_t iCol, Int_t iRow, Double_t c = 1) { 
+    if(!fEMCALBadChannelMap->GetEntries())InitEMCALBadChannelStatusMap() ;
+    ((TH2I*)fEMCALBadChannelMap->At(iSM))->SetBinContent(iCol,iRow,c);}
+  
+  void SetPHOSChannelStatus (Int_t imod, Int_t iCol, Int_t iRow, Double_t c = 1) {
+       if(!fPHOSBadChannelMap->GetEntries()) InitPHOSBadChannelStatusMap() ; 
+       ((TH2I*)fPHOSBadChannelMap->At(imod))->SetBinContent(iCol,iRow,c);}
+    
+  TH2I * GetEMCALChannelStatusMap(Int_t iSM) const {return (TH2I*)fEMCALBadChannelMap->At(iSM);}
+  TH2I * GetPHOSChannelStatusMap(Int_t imod) const {return (TH2I*)fPHOSBadChannelMap->At(imod);}
+
+  void SetEMCALChannelStatusMap(TObjArray *map) {fEMCALBadChannelMap = map;}
+  void SetPHOSChannelStatusMap (TObjArray *map) {fPHOSBadChannelMap  = map;}
+       
+  Bool_t ClusterContainsBadChannel(TString calorimeter,UShort_t* cellList, Int_t nCells);
+       
+  //Calorimeter indexes information
+  Int_t GetModuleNumber(AliAODPWG4Particle * particle, AliVEvent* inputEvent) const;
+  Int_t GetModuleNumber(AliAODCaloCluster * cluster) const;
+  Int_t GetModuleNumber(AliESDCaloCluster * cluster) const;
+
+  Int_t GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t &iRCU) const ;
+       
+  //Modules fiducial region
+  Bool_t CheckCellFiducialRegion(AliAODCaloCluster* cluster, AliAODCaloCells* cells) const ;
+  Bool_t CheckCellFiducialRegion(AliESDCaloCluster* cluster, AliESDCaloCells* cells) const ;
+       
+  void   SetNumberOfCellsFromEMCALBorder(Int_t n) {fNCellsFromEMCALBorder = n; }
+  Int_t  GetNumberOfCellsFromEMCALBorder() const  {return fNCellsFromEMCALBorder; }
+  void   SetNumberOfCellsFromPHOSBorder(Int_t n)  {fNCellsFromPHOSBorder = n; }
+  Int_t  GetNumberOfCellsFromPHOSBorder() const   {return fNCellsFromPHOSBorder; }
+       
+  void   SwitchOnNoFiducialBorderInEMCALEta0()  {fNoEMCALBorderAtEta0 = kTRUE; }
+  void   SwitchOffNoFiducialBorderInEMCALEta0() {fNoEMCALBorderAtEta0 = kFALSE; }
+
+ private:
+
+  Int_t              fDebug;              //  Debugging level
+  TString            fEMCALGeoName;       //  Name of geometry to use for EMCAL.
+  TString            fPHOSGeoName;        //  Name of geometry to use for PHOS.        
+  AliEMCALGeoUtils * fEMCALGeo ;          //! EMCAL geometry pointer
+  AliPHOSGeoUtils  * fPHOSGeo  ;          //! PHOS  geometry pointer  
+  Bool_t             fEMCALGeoMatrixSet;  //  Check if the transformation matrix is set for EMCAL
+  Bool_t             fPHOSGeoMatrixSet ;  //  Check if the transformation matrix is set for PHOS
+  Bool_t             fRemoveBadChannels;  //  Check the channel status provided and remove clusters with bad channels
+  TObjArray        * fEMCALBadChannelMap; //! Array of histograms with map of bad channels, EMCAL
+  TObjArray        * fPHOSBadChannelMap;  //! Array of histograms with map of bad channels, PHOS
+  Int_t              fNCellsFromEMCALBorder; // Number of cells from EMCAL border the cell with maximum amplitude has to be.
+  Int_t              fNCellsFromPHOSBorder;  // Number of cells from PHOS  border the cell with maximum amplitude has to be.
+  Bool_t             fNoEMCALBorderAtEta0;//  Do fidutial cut in EMCAL region eta = 0?
+
+  ClassDef(AliCalorimeterUtils,1)
+} ;
+
+
+#endif //ALICALORIMETERUTILS_H
+
+
+
index 556c8c3..866de1e 100755 (executable)
@@ -215,20 +215,7 @@ TList *  AliAnaCalorimeterQA::GetCreateOutputObjects()
 {  
        // Create histograms to be saved in output file and 
        // store them in outputContainer
-    
-       //If Geometry library loaded, do geometry selection during analysis.
-       if(fCalorimeter=="PHOS"){
-               if(!GetReader()->GetPHOSGeometry()) printf("AliAnaCalorimeterQA::GetCreateOutputObjects() - Initialize PHOS geometry!\n");
-               GetReader()->InitPHOSGeometry();
-               
-       }
-       else
-       if(fCalorimeter=="EMCAL"){
-               if(!GetReader()->GetEMCALGeometry()) printf("AliAnaCalorimeterQA::GetCreateOutputObjects() - Initialize EMCAL geometry!\n");
-               GetReader()->InitEMCALGeometry();
-       }
-       
-       
+       
        TList * outputContainer = new TList() ; 
        outputContainer->SetName("QAHistos") ; 
        
@@ -1402,10 +1389,14 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                
                if(GetReader()->GetDataType()==AliCaloTrackReader::kESD){
                        AliESDCaloCluster* clus =  (AliESDCaloCluster*) (caloClusters->At(iclus));
+                       AliESDCaloCells * cell = 0x0; 
+                       if(fCalorimeter == "PHOS") cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
+                       else                               cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
                        
-                       //Check if the cluster contains any bad channel
-                       if(GetReader()->ClusterContainsBadChannel(fCalorimeter,clus->GetCellsAbsId(), clus->GetNCells())) continue;     
-                       
+                       //Check if the cluster contains any bad channel or it is close to the calorimeter borders
+                       if( GetCaloUtils()->ClusterContainsBadChannel(fCalorimeter,clus->GetCellsAbsId(), clus->GetNCells())) continue; 
+                       if(!GetCaloUtils()->CheckCellFiducialRegion(clus, cell)) continue;
+
                        //Get cluster kinematics
                        clus->GetPosition(pos);
                        clus->GetMomentum(mom,v);
@@ -1445,10 +1436,6 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                        //Cells in cluster
                        //======================
 
-                       
-                       AliESDCaloCells * cell = 0x0; 
-                       if(fCalorimeter == "PHOS") cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
-                       else                       cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
                        //Get list of contributors
                        UShort_t * indexList = clus->GetCellsAbsId() ;
                        // check time of cells respect to max energy cell
@@ -1464,10 +1451,10 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                          absId  = indexList[ipos]; 
                          
                          //Get position of cell compare to cluster
-                         if(fCalorimeter=="EMCAL" && GetReader()->IsEMCALGeoMatrixSet()){
+                         if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
                            
                            Double_t cellpos[] = {0, 0, 0};
-                           GetReader()->GetEMCALGeometry()->GetGlobal(absId, cellpos);
+                           GetEMCALGeometry()->GetGlobal(absId, cellpos);
                            
                            fhDeltaCellClusterXNCells->Fill(pos[0]-cellpos[0],nCaloCellsPerCluster) ; 
                            fhDeltaCellClusterYNCells->Fill(pos[1]-cellpos[1],nCaloCellsPerCluster) ; 
@@ -1483,10 +1470,10 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                            fhDeltaCellClusterRE     ->Fill(r-rcell, mom.E())  ; 
                        
 //                                     Float_t celleta = 0, cellphi = 0;
-//                                     GetReader()->GetEMCALGeometry()->EtaPhiFromIndex(absId, celleta, cellphi); 
+//                                     GetEMCALGeometry()->EtaPhiFromIndex(absId, celleta, cellphi); 
 //                                     Int_t imod = -1, iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1;
-//                                     GetReader()->GetEMCALGeometry()->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
-//                                     GetReader()->GetEMCALGeometry()->GetCellPhiEtaIndexInSModule(imod,iTower,
+//                                     GetEMCALGeometry()->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
+//                                     GetEMCALGeometry()->GetCellPhiEtaIndexInSModule(imod,iTower,
 //                                                                                                                                                              iIphi, iIeta,iphi,ieta);
 //                                     printf("AbsId %d, SM %d, Index eta %d, phi %d\n", absId, imod, ieta, iphi);
 //                                     printf("Cluster E %f, eta %f, phi %f; Cell: Amp %f, eta %f, phi%f\n", mom.E(),mom.Eta(), mom.Phi()*TMath::RadToDeg(), cell->GetCellAmplitude(absId),celleta, cellphi*TMath::RadToDeg());
@@ -1497,15 +1484,15 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
 //                                     
 
                          }//EMCAL and its matrices are available
-                         else if(fCalorimeter=="PHOS" && GetReader()->IsPHOSGeoMatrixSet()){
+                         else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
                            TVector3 xyz;
                            Int_t relId[4], module;
                            Float_t xCell, zCell;
                            
-                           GetReader()->GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
+                           GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
                            module = relId[0];
-                           GetReader()->GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
-                           GetReader()->GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
+                           GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
+                           GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
                            
                            fhDeltaCellClusterXNCells->Fill(pos[0]-xyz.X(),nCaloCellsPerCluster) ; 
                            fhDeltaCellClusterYNCells->Fill(pos[1]-xyz.Y(),nCaloCellsPerCluster) ; 
@@ -1551,10 +1538,14 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                }//ESDs
                else{
                        AliAODCaloCluster* clus =  (AliAODCaloCluster*) (caloClusters->At(iclus));
+                       AliAODCaloCells * cell = 0x0; 
+                       if(fCalorimeter == "PHOS") cell =  ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
+                       else                                       cell =  ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
                        
-                       //Check if the cluster contains any bad channel
-                       if(GetReader()->ClusterContainsBadChannel(fCalorimeter,clus->GetCellsAbsId(), clus->GetNCells())) continue;
-                       
+                       //Check if the cluster contains any bad channel or it is close to calorimeter borders
+                       if( GetCaloUtils()->ClusterContainsBadChannel(fCalorimeter,clus->GetCellsAbsId(), clus->GetNCells())) continue;
+                       if(!GetCaloUtils()->CheckCellFiducialRegion(clus, cell)) continue;
+
                        //Get cluster kinematics
                        clus->GetPosition(pos);
                        clus->GetMomentum(mom,v);
@@ -1586,11 +1577,7 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                        //======================
                        //Cells in cluster
                        //======================
-                       
-                       AliAODCaloCells * cell = 0x0; 
-                       if(fCalorimeter == "PHOS") cell =  ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
-                       else                                       cell =  ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
-                       
+                                               
                        //Get list of contributors
                        UShort_t * indexList = clus->GetCellsAbsId() ;
                        Int_t absId   = -1 ;
@@ -1601,10 +1588,10 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                                absId  = indexList[ipos]; 
                                
                                //Get position of cell compare to cluster
-                               if(fCalorimeter=="EMCAL" && GetReader()->IsEMCALGeoMatrixSet()){
+                               if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
                                        
                                        Double_t cellpos[] = {0, 0, 0};
-                                       GetReader()->GetEMCALGeometry()->GetGlobal(absId, cellpos);
+                                       GetEMCALGeometry()->GetGlobal(absId, cellpos);
                                        
                                        fhDeltaCellClusterXNCells->Fill(pos[0]-cellpos[0],nCaloCellsPerCluster) ; 
                                        fhDeltaCellClusterYNCells->Fill(pos[1]-cellpos[1],nCaloCellsPerCluster) ; 
@@ -1625,15 +1612,15 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
 //                                             printf("r cluster %f, r cell %f, cluster-cell %f\n",r,      rcell,     r-rcell);                                        
                                        
                                }// EMCAL and its matrices are available
-                               else if(fCalorimeter=="PHOS" && GetReader()->IsPHOSGeoMatrixSet()){
+                               else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
                                  TVector3 xyz;
                                  Int_t relId[4], module;
                                  Float_t xCell, zCell;
                                  
-                                 GetReader()->GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
+                                 GetPHOSGeometry()->AbsToRelNumbering(absId,relId);
                                  module = relId[0];
-                                 GetReader()->GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
-                                 GetReader()->GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
+                                 GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
+                                 GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
                                  
                                  fhDeltaCellClusterXNCells->Fill(pos[0]-xyz.X(),nCaloCellsPerCluster) ; 
                                  fhDeltaCellClusterYNCells->Fill(pos[1]-xyz.Y(),nCaloCellsPerCluster) ; 
@@ -1680,8 +1667,13 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                        for(Int_t jclus = iclus + 1 ; jclus < nCaloClusters ; jclus++) {
                                if(GetReader()->GetDataType()==AliCaloTrackReader::kESD){
                                        AliESDCaloCluster* clus2 =  (AliESDCaloCluster*) (caloClusters->At(jclus));
-                                       //Check if the cluster contains any bad channel
-                                       if(GetReader()->ClusterContainsBadChannel(fCalorimeter,clus2->GetCellsAbsId(), clus2->GetNCells())) continue;   
+                                       AliESDCaloCells  * cell2 = 0x0; 
+                                       if(fCalorimeter == "PHOS") cell2 =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
+                                       else                               cell2 =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
+                                       //Check if the cluster contains any bad channel or it is close to calorimeter borders
+                                       if( GetCaloUtils()->ClusterContainsBadChannel(fCalorimeter,clus2->GetCellsAbsId(), clus2->GetNCells())) continue;
+                                       if(!GetCaloUtils()->CheckCellFiducialRegion(clus2, cell2)) continue;
+
                                        //Get cluster kinematics
                                        clus2->GetMomentum(mom2,v);
                                        //Check only certain regions
@@ -1696,8 +1688,13 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                                }
                                else if(GetReader()->GetDataType()==AliCaloTrackReader::kAOD){
                                        AliAODCaloCluster* clus2 =  (AliAODCaloCluster*) (caloClusters->At(jclus));
-                                       //Check if the cluster contains any bad channel
-                                       if(GetReader()->ClusterContainsBadChannel(fCalorimeter,clus2->GetCellsAbsId(), clus2->GetNCells())) continue;   
+                                       AliAODCaloCells  * cell2 = 0x0; 
+                                       if(fCalorimeter == "PHOS") cell2 =  ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
+                                       else                               cell2 =  ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
+                                       //Check if the cluster contains any bad channel or it is close to calorimeter borders 
+                                       if( GetCaloUtils()->ClusterContainsBadChannel(fCalorimeter,clus2->GetCellsAbsId(), clus2->GetNCells())) continue;
+                                       if(!GetCaloUtils()->CheckCellFiducialRegion(clus2, cell2)) continue;
+
                                        //Get cluster kinematics
                                        clus2->GetMomentum(mom2,v);
                                        //Check only certain regions
@@ -1760,7 +1757,7 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                AliESDCaloCells * cell = 0x0; 
                Int_t ncells = 0;
                if(fCalorimeter == "PHOS") cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
-               else                       cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
+               else                           cell =  ((AliESDEvent*)GetReader()->GetInputEvent())->GetEMCALCells();
                
                if(!cell) {
                        printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - STOP: No %s ESD CELLS available for analysis\n",fCalorimeter.Data());
@@ -1779,12 +1776,12 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                        
                        if(nModule < fNModules) {       
                                //Check if the cell is a bad channel
-                               if(GetReader()->IsBadChannelsRemovalSwitchedOn()){
+                               if(GetCaloUtils()->IsBadChannelsRemovalSwitchedOn()){
                                        if(fCalorimeter=="EMCAL"){
-                                               if(GetReader()->GetEMCALChannelStatus(nModule,icol,irow)) continue;
+                                               if(GetCaloUtils()->GetEMCALChannelStatus(nModule,icol,irow)) continue;
                                        }
                                        else {
-                                               if(GetReader()->GetPHOSChannelStatus(nModule,icol,irow)) continue;
+                                               if(GetCaloUtils()->GetPHOSChannelStatus(nModule,icol,irow)) continue;
                                        }
                                }
                                amp     = cell->GetAmplitude(iCell);
@@ -1853,14 +1850,14 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                        }//nmodules
                        
                        //Get Eta-Phi position of Cell
-                       if(fCalorimeter=="EMCAL" && GetReader()->IsEMCALGeoMatrixSet()){
+                       if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
                          Float_t celleta = 0.;
                          Float_t cellphi = 0.;
-                         GetReader()->GetEMCALGeometry()->EtaPhiFromIndex(id, celleta, cellphi); 
+                         GetEMCALGeometry()->EtaPhiFromIndex(id, celleta, cellphi); 
                          fhEtaPhiAmp->Fill(celleta,cellphi,amp);
                          
                          Double_t cellpos[] = {0, 0, 0};
-                         GetReader()->GetEMCALGeometry()->GetGlobal(id, cellpos);
+                         GetEMCALGeometry()->GetGlobal(id, cellpos);
                          fhXCellE->Fill(cellpos[0],amp)  ; 
                          fhYCellE->Fill(cellpos[1],amp)  ; 
                          fhZCellE->Fill(cellpos[2],amp)  ;
@@ -1869,15 +1866,15 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                          
                          fhXYZCell->Fill(cellpos[0],cellpos[1],cellpos[2])  ;
                        }//EMCAL Cells
-                       else if(fCalorimeter=="PHOS" && GetReader()->IsPHOSGeoMatrixSet()){
+                       else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
                          TVector3 xyz;
                          Int_t relId[4], module;
                          Float_t xCell, zCell;
                          
-                         GetReader()->GetPHOSGeometry()->AbsToRelNumbering(id,relId);
+                         GetPHOSGeometry()->AbsToRelNumbering(id,relId);
                          module = relId[0];
-                         GetReader()->GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
-                         GetReader()->GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
+                         GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
+                         GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
                          Float_t rcell = TMath::Sqrt(xyz.X()*xyz.X()+xyz.Y()*xyz.Y());
                          fhXCellE ->Fill(xyz.X(),amp)  ; 
                          fhYCellE ->Fill(xyz.Y(),amp)  ; 
@@ -1893,7 +1890,7 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                Int_t ncells = 0;
                
                if(fCalorimeter == "PHOS") cell = ((AliAODEvent*)GetReader()->GetInputEvent())->GetPHOSCells();
-               else                       cell = ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALCells();        
+               else                           cell = ((AliAODEvent*)GetReader()->GetInputEvent())->GetEMCALCells();    
                
                if(!cell) {
                        printf("AliAnaCalorimeterQA::MakeAnalysisFillHistograms() - STOP: No %s AOD CELLS available for analysis\n",fCalorimeter.Data());
@@ -1914,12 +1911,12 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                        
                        if(nModule < fNModules) {       
                                //Check if the cell is a bad channel
-                               if(GetReader()->IsBadChannelsRemovalSwitchedOn()){
+                               if(GetCaloUtils()->IsBadChannelsRemovalSwitchedOn()){
                                        if(fCalorimeter=="EMCAL"){
-                                               if(GetReader()->GetEMCALChannelStatus(nModule,icol,irow)) continue;
+                                               if(GetCaloUtils()->GetEMCALChannelStatus(nModule,icol,irow)) continue;
                                        }
                                        else{
-                                               if(GetReader()->GetPHOSChannelStatus(nModule,icol,irow)) continue;
+                                               if(GetCaloUtils()->GetPHOSChannelStatus(nModule,icol,irow)) continue;
                                        }       
                                }
                                amp     = cell->GetAmplitude(iCell);
@@ -1942,14 +1939,14 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                        }//nmodules
                        
                        //Get Eta-Phi position of Cell
-                       if(fCalorimeter=="EMCAL" && GetReader()->IsEMCALGeoMatrixSet()){
+                       if(fCalorimeter=="EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
                          Float_t celleta = 0.;
                          Float_t cellphi = 0.;
-                         GetReader()->GetEMCALGeometry()->EtaPhiFromIndex(id, celleta, cellphi); 
+                         GetEMCALGeometry()->EtaPhiFromIndex(id, celleta, cellphi); 
                          fhEtaPhiAmp->Fill(celleta,cellphi,amp);
                          
                          Double_t cellpos[] = {0, 0, 0};
-                         GetReader()->GetEMCALGeometry()->GetGlobal(id, cellpos);
+                         GetEMCALGeometry()->GetGlobal(id, cellpos);
                          fhXCellE->Fill(cellpos[0],amp)  ; 
                          fhYCellE->Fill(cellpos[1],amp)  ; 
                          fhZCellE->Fill(cellpos[2],amp)  ;
@@ -1958,15 +1955,15 @@ void  AliAnaCalorimeterQA::MakeAnalysisFillHistograms()
                          
                          fhXYZCell->Fill(cellpos[0],cellpos[1],cellpos[2])  ;
                        }//EMCAL Cells
-                       else if(fCalorimeter=="PHOS" && GetReader()->IsPHOSGeoMatrixSet()){
+                       else if(fCalorimeter=="PHOS" && GetCaloUtils()->IsPHOSGeoMatrixSet()){
                          TVector3 xyz;
                          Int_t relId[4], module;
                          Float_t xCell, zCell;
                          
-                         GetReader()->GetPHOSGeometry()->AbsToRelNumbering(id,relId);
+                         GetPHOSGeometry()->AbsToRelNumbering(id,relId);
                          module = relId[0];
-                         GetReader()->GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
-                         GetReader()->GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
+                         GetPHOSGeometry()->RelPosInModule(relId,xCell,zCell);
+                         GetPHOSGeometry()->Local2Global(module,xCell,zCell,xyz);
                          Float_t rcell = TMath::Sqrt(xyz.X()*xyz.X()+xyz.Y()*xyz.Y());
                          fhXCellE ->Fill(xyz.X(),amp)  ; 
                          fhYCellE ->Fill(xyz.Y(),amp)  ; 
index 51e0107..0733038 100755 (executable)
@@ -171,19 +171,7 @@ TList * AliAnaPi0::GetCreateOutputObjects()
       }
     }
   }
-  
-  //If Geometry library loaded, do geometry selection during analysis.
-  if(fCalorimeter=="PHOS"){
-    if(!GetReader()->GetPHOSGeometry()) printf("AliAnaPi0::GetCreateOutputObjects() - Initialize PHOS geometry!\n");
-    GetReader()->InitPHOSGeometry();
-    
-  }
-  else 
-       if(fCalorimeter=="EMCAL"){
-               if(!GetReader()->GetEMCALGeometry()) printf("AliAnaPi0::GetCreateOutputObjects() - Initialize EMCAL geometry!\n");
-               GetReader()->InitEMCALGeometry();
-  }
-       
+       
   TList * outputContainer = new TList() ; 
   outputContainer->SetName(GetName()); 
        
@@ -570,10 +558,10 @@ void AliAnaPi0::MakeAnalysisFillHistograms()
              
              Bool_t inacceptance = kFALSE;
              if(fCalorimeter == "PHOS"){
-               if(GetReader()->GetPHOSGeometry() && GetReader()->IsPHOSGeoMatrixSet()){
+               if(GetPHOSGeometry() && GetCaloUtils()->IsPHOSGeoMatrixSet()){
                  Int_t mod ;
                  Double_t x,z ;
-                 if(GetReader()->GetPHOSGeometry()->ImpactOnEmc(phot1,mod,z,x) && GetReader()->GetPHOSGeometry()->ImpactOnEmc(phot2,mod,z,x)) 
+                 if(GetPHOSGeometry()->ImpactOnEmc(phot1,mod,z,x) && GetPHOSGeometry()->ImpactOnEmc(phot2,mod,z,x)) 
                    inacceptance = kTRUE;
                  if(GetDebug() > 2) printf("In %s Real acceptance? %d\n",fCalorimeter.Data(),inacceptance);
                }
@@ -585,9 +573,9 @@ void AliAnaPi0::MakeAnalysisFillHistograms()
                }
                
              }    
-             else if(fCalorimeter == "EMCAL" && GetReader()->IsEMCALGeoMatrixSet()){
-               if(GetReader()->GetEMCALGeometry()){
-                 if(GetReader()->GetEMCALGeometry()->Impact(phot1) && GetReader()->GetEMCALGeometry()->Impact(phot2)) 
+             else if(fCalorimeter == "EMCAL" && GetCaloUtils()->IsEMCALGeoMatrixSet()){
+               if(GetEMCALGeometry()){
+                 if(GetEMCALGeometry()->Impact(phot1) && GetEMCALGeometry()->Impact(phot2)) 
                    inacceptance = kTRUE;
                  if(GetDebug() > 2) printf("In %s Real acceptance? %d\n",fCalorimeter.Data(),inacceptance);
                }
index 5d44128..ed66fb7 100755 (executable)
@@ -5,7 +5,7 @@ SRCS = PartCorrBase/AliNeutralMesonSelection.cxx PartCorrBase/AliFiducialCut.cxx
        PartCorrBase/AliAnaScale.cxx PartCorrBase/AliAnaPartCorrMaker.cxx \
        PartCorrBase/AliAnaPartCorrBaseClass.cxx PartCorrBase/AliAnalysisTaskParticleCorrelation.cxx \
        PartCorrBase/AliCaloTrackReader.cxx PartCorrBase/AliCaloTrackESDReader.cxx \
-       PartCorrBase/AliCaloTrackAODReader.cxx PartCorrBase/AliCaloTrackMCReader.cxx 
+       PartCorrBase/AliCaloTrackAODReader.cxx PartCorrBase/AliCaloTrackMCReader.cxx PartCorrBase/AliCalorimeterUtils.cxx
       
 
 HDRS:= $(SRCS:.cxx=.h)