adding JETAN and FASTJETAN development libs for new i/o of tracks/particles for the...
authorkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 24 Jan 2012 20:06:42 +0000 (20:06 +0000)
committerkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 24 Jan 2012 20:06:42 +0000 (20:06 +0000)
76 files changed:
JETAN/CMakeLists.txt [new file with mode: 0644]
JETAN/CMakelibFASTJETANdev.pkg [new file with mode: 0644]
JETAN/CMakelibJETANdev.pkg [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskDiJets.cxx [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskDiJets.h [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskFastEmbedding.cxx [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskFastEmbedding.h [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetBackgroundSubtract.cxx [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetBackgroundSubtract.h [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetCluster.cxx [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetCluster.h [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetsFinder.cxx [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetsFinder.h [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetsReader.cxx [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskJetsReader.h [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskKMeans.cxx [new file with mode: 0644]
JETAN/DEV/AliAnalysisTaskKMeans.h [new file with mode: 0644]
JETAN/DEV/AliCdfJetFinder.cxx [new file with mode: 0644]
JETAN/DEV/AliCdfJetFinder.h [new file with mode: 0644]
JETAN/DEV/AliCdfJetHeader.cxx [new file with mode: 0644]
JETAN/DEV/AliCdfJetHeader.h [new file with mode: 0644]
JETAN/DEV/AliDAJetFinder.cxx [new file with mode: 0644]
JETAN/DEV/AliDAJetFinder.h [new file with mode: 0644]
JETAN/DEV/AliDAJetHeader.cxx [new file with mode: 0644]
JETAN/DEV/AliDAJetHeader.h [new file with mode: 0644]
JETAN/DEV/AliEventShape.cxx [new file with mode: 0644]
JETAN/DEV/AliEventShape.h [new file with mode: 0644]
JETAN/DEV/AliFastJetBkg.cxx [new file with mode: 0644]
JETAN/DEV/AliFastJetBkg.h [new file with mode: 0644]
JETAN/DEV/AliFastJetFinder.cxx [new file with mode: 0644]
JETAN/DEV/AliFastJetFinder.h [new file with mode: 0644]
JETAN/DEV/AliFastJetHeaderV1.cxx [new file with mode: 0644]
JETAN/DEV/AliFastJetHeaderV1.h [new file with mode: 0644]
JETAN/DEV/AliFastJetInput.cxx [new file with mode: 0644]
JETAN/DEV/AliFastJetInput.h [new file with mode: 0644]
JETAN/DEV/AliJetBkg.cxx [new file with mode: 0644]
JETAN/DEV/AliJetBkg.h [new file with mode: 0644]
JETAN/DEV/AliJetCalTrk.cxx [new file with mode: 0644]
JETAN/DEV/AliJetCalTrk.h [new file with mode: 0644]
JETAN/DEV/AliJetFillCalTrkEvent.cxx [new file with mode: 0644]
JETAN/DEV/AliJetFillCalTrkEvent.h [new file with mode: 0644]
JETAN/DEV/AliJetFillCalTrkTrack.cxx [new file with mode: 0644]
JETAN/DEV/AliJetFillCalTrkTrack.h [new file with mode: 0644]
JETAN/DEV/AliJetFillCalTrkTrackMC.cxx [new file with mode: 0644]
JETAN/DEV/AliJetFillCalTrkTrackMC.h [new file with mode: 0644]
JETAN/DEV/AliJetFinder.cxx [new file with mode: 0644]
JETAN/DEV/AliJetFinder.h [new file with mode: 0644]
JETAN/DEV/AliJetHeader.cxx [new file with mode: 0644]
JETAN/DEV/AliJetHeader.h [new file with mode: 0644]
JETAN/DEV/AliJetHistos.cxx [new file with mode: 0644]
JETAN/DEV/AliJetHistos.h [new file with mode: 0644]
JETAN/DEV/AliJetKineReaderHeader.cxx [new file with mode: 0644]
JETAN/DEV/AliJetKineReaderHeader.h [new file with mode: 0644]
JETAN/DEV/AliJetReader.cxx [new file with mode: 0644]
JETAN/DEV/AliJetReader.h [new file with mode: 0644]
JETAN/DEV/AliJetReaderHeader.cxx [new file with mode: 0644]
JETAN/DEV/AliJetReaderHeader.h [new file with mode: 0644]
JETAN/DEV/AliKMeansClustering.cxx [new file with mode: 0644]
JETAN/DEV/AliKMeansClustering.h [new file with mode: 0644]
JETAN/DEV/AliSISConeJetFinder.cxx [new file with mode: 0644]
JETAN/DEV/AliSISConeJetFinder.h [new file with mode: 0644]
JETAN/DEV/AliSISConeJetHeader.cxx [new file with mode: 0644]
JETAN/DEV/AliSISConeJetHeader.h [new file with mode: 0644]
JETAN/DEV/AliUA1JetFinder.cxx [new file with mode: 0644]
JETAN/DEV/AliUA1JetFinder.h [new file with mode: 0644]
JETAN/DEV/AliUA1JetHeaderV1.cxx [new file with mode: 0644]
JETAN/DEV/AliUA1JetHeaderV1.h [new file with mode: 0644]
JETAN/FASTJETANdevLinkDef.h [new file with mode: 0644]
JETAN/JETANdevLinkDef.h [new file with mode: 0644]
JETAN/Makefile
JETAN/PROOF-INF.FASTJETANdev/BUILD.sh [new file with mode: 0644]
JETAN/PROOF-INF.FASTJETANdev/SETUP.C [new file with mode: 0644]
JETAN/PROOF-INF.JETANdev/BUILD.sh [new file with mode: 0644]
JETAN/PROOF-INF.JETANdev/SETUP.C [new file with mode: 0644]
PWG4/Makefile
PWG4/macros/AnalysisTrainPWG4Jets.C

diff --git a/JETAN/CMakeLists.txt b/JETAN/CMakeLists.txt
new file mode 100644 (file)
index 0000000..90347d6
--- /dev/null
@@ -0,0 +1,10 @@
+# AliRoot Build System CMakeLists for JETAN
+#
+# Author: Johny Jose m(johny.jose@cern.ch)
+#         Port of previous Makefile build to cmake
+
+cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
+
+file(GLOB PACKAGES CMake*.pkg)
+
+ALICE_BuildModule()
diff --git a/JETAN/CMakelibFASTJETANdev.pkg b/JETAN/CMakelibFASTJETANdev.pkg
new file mode 100644 (file)
index 0000000..4a099b4
--- /dev/null
@@ -0,0 +1,42 @@
+#--------------------------------------------------------------------------------#
+# Package File for JETAN                                                         #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#--------------------------------------------------------------------------------#
+
+set ( SRCS DEV/AliFastJetFinder.cxx DEV/AliFastJetHeaderV1.cxx DEV/AliFastJetInput.cxx DEV/AliFastJetBkg.cxx DEV/AliSISConeJetFinder.cxx DEV/AliSISConeJetHeader.cxx DEV/AliAnalysisTaskJetCluster.cxx DEV/AliAnalysisTaskJetBackgroundSubtract.cxx)
+
+set(FASTJET_ROOT $ENV{FASTJET_ROOT})
+
+if(FASTJET_ROOT)
+  set ( EDEFINE -isystem${FASTJET_ROOT}/include )
+else()
+  set ( EDEFINE -isystem${ALICE_ROOT}/JETAN/fastjet)
+endif(FASTJET_ROOT)
+
+string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
+
+set ( DHDR  FASTJETANdevLinkDef.h)
+
+set ( EINCLUDE JETAN/DEV JETAN/fastjet ANALYSIS STEER/AOD STEER/STEERBase )
diff --git a/JETAN/CMakelibJETANdev.pkg b/JETAN/CMakelibJETANdev.pkg
new file mode 100644 (file)
index 0000000..96d5644
--- /dev/null
@@ -0,0 +1,49 @@
+#--------------------------------------------------------------------------------#
+# Package File for JETAN                                                         #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#--------------------------------------------------------------------------------#
+
+set ( SRCS DEV/AliJetHeader.cxx DEV/AliJetFinder.cxx  DEV/AliJetReaderHeader.cxx DEV/AliJetReader.cxx DEV/AliUA1JetHeaderV1.cxx DEV/AliUA1JetFinder.cxx DEV/AliCdfJetFinder.cxx  DEV/AliCdfJetHeader.cxx DEV/AliAnalysisTaskJetsReader.cxx  DEV/AliAnalysisTaskJetsFinder.cxx DEV/AliDAJetFinder.cxx DEV/AliDAJetHeader.cxx DEV/AliJetKineReaderHeader.cxx DEV/AliJetHistos.cxx DEV/AliAnalysisTaskDiJets.cxx DEV/AliEventShape.cxx DEV/AliKMeansClustering.cxx DEV/AliAnalysisTaskKMeans.cxx DEV/AliAnalysisTaskFastEmbedding.cxx DEV/AliJetBkg.cxx DEV/AliJetCalTrk.cxx DEV/AliJetFillCalTrkTrack.cxx DEV/AliJetFillCalTrkTrackMC.cxx DEV/AliJetFillCalTrkEvent.cxx )
+
+string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
+
+set ( DHDR  JETANdevLinkDef.h)
+
+set(FASTJET_ROOT $ENV{FASTJET_ROOT})
+
+if(FASTJET_ROOT)
+  set ( EDEFINE -isystem${FASTJET_ROOT}/include)
+else()
+  set ( EDEFINE -isystem${ALICE_ROOT}/JETAN/fastjet)
+endif(FASTJET_ROOT)
+
+set ( EINCLUDE  ANALYSIS  OADB)
+
+if( ALICE_TARGET STREQUAL "win32gcc")
+       
+                       set ( PACKSOFLAGS  ${SOFLAGS} -L${ALICE_ROOT}/lib/tgt_${ALICE_TARGET} -lSTEERBase -lESD -lAOD -lANALYSIS -lANALYSISalice -L${ROOTLIBDIR} -lEG -lGeom)
+
+endif( ALICE_TARGET STREQUAL "win32gcc")
+
diff --git a/JETAN/DEV/AliAnalysisTaskDiJets.cxx b/JETAN/DEV/AliAnalysisTaskDiJets.cxx
new file mode 100644 (file)
index 0000000..f1df281
--- /dev/null
@@ -0,0 +1,218 @@
+/**************************************************************************
+ * 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$ */
+/*
+ Analysis Task 
+ for Dijet Analysis
+ based on AOD
+*/
+
+#include "AliAnalysisTaskDiJets.h"
+#include "AliAODEvent.h"
+#include "AliAODJet.h"
+#include "AliAODDiJet.h"
+#include <TClonesArray.h>
+#include <TLorentzVector.h>
+#include <TStyle.h>
+
+
+ClassImp(AliAnalysisTaskDiJets)
+
+////////////////////////////////////////////////////////////////////////
+
+AliAnalysisTaskDiJets::AliAnalysisTaskDiJets():
+    AliAnalysisTaskSE(),
+    fDiJets(0),
+    fDiJetsIn(0),
+    fUseAODInput(kFALSE),
+    fFillAOD(kFALSE),
+    fJetBranch("jets"),
+    fAOD(0),
+    fHistList(0),
+    fH1DeltaPt(0),
+    fH1DeltaPhi(0),
+    fH1PhiImbal(0),
+    fH1Asym(0),
+    fH2Pt2vsPt1(0),
+    fH2DifvsSum(0)
+{
+  // Default constructor
+}
+
+//----------------------------------------------------------------------
+AliAnalysisTaskDiJets::AliAnalysisTaskDiJets(const char* name):
+    AliAnalysisTaskSE(name),
+    fDiJets(0),
+    fDiJetsIn(0),
+    fUseAODInput(kFALSE),
+    fFillAOD(kFALSE),
+    fJetBranch("jets"),
+    fAOD(0),
+    fHistList(0),
+    fH1DeltaPt(0),
+    fH1DeltaPhi(0),
+    fH1PhiImbal(0),
+    fH1Asym(0),
+    fH2Pt2vsPt1(0),
+    fH2DifvsSum(0)
+{
+  // Default constructor
+    DefineOutput(1, TList::Class());  
+}
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskDiJets::UserCreateOutputObjects()
+{
+// Create the output container
+//
+    if (fDebug) printf("AnalysisTaskDiJets::CreateOutPutData() \n");
+    fDiJets = new TClonesArray("AliAODDiJet", 0);
+    if (fFillAOD){
+      fDiJets->SetName(Form("dijets_%s",fJetBranch.Data()));
+      AddAODBranch("TClonesArray", &fDiJets);
+       }
+
+    if (!fHistList) fHistList = new TList();
+    fHistList->SetOwner();
+    Float_t pi=TMath::Pi();
+    gStyle->SetPalette(1);
+
+    fH1DeltaPt  = new TH1F("DeltaPt","Difference between the jets' Pt;#Deltap_{T} (GeV/c);Entries",150,0.,150.);
+    fH1DeltaPt->SetMarkerSize(0.6);
+    fH1DeltaPt->SetMarkerColor(4);
+    fH1DeltaPt->SetMarkerStyle(21);
+    fH1DeltaPt->SetOption("E");
+
+    fH1DeltaPhi = new TH1F("DeltaPhi","Difference in the azimuthal angle;#Delta#phi;Entries",100,0.,pi);
+    fH1DeltaPhi->SetMarkerSize(0.6);
+    fH1DeltaPhi->SetMarkerColor(4);
+    fH1DeltaPhi->SetMarkerStyle(21);
+    fH1DeltaPhi->SetOption("E");
+
+    fH1PhiImbal = new TH1F("PhiImb","Phi imbalance;#phi;Entries",100,-pi,pi);
+    fH1PhiImbal->SetMarkerSize(0.6);
+    fH1PhiImbal->SetMarkerColor(4);
+    fH1PhiImbal->SetMarkerStyle(21);
+    fH1PhiImbal->SetOption("E");
+
+    fH1Asym     = new TH1F("Asym","Pt asymmetry;#Deltap_{T}/(p_{T,1}+p_{T,2});Entries",50,0.,1.);
+    fH1Asym->SetMarkerSize(0.6);
+    fH1Asym->SetMarkerColor(4);
+    fH1Asym->SetMarkerStyle(21);
+    fH1Asym->SetOption("E");
+
+    fH2Pt2vsPt1 = new TH2F("Pt2vsPt1","Pt2 versus Pt1;p_{T,1} (GeV/c);p_{T,2} (GeV/c)",250,0.,250.,250,0.,250.);
+    fH2Pt2vsPt1->SetOption("cont0");
+
+    fH2DifvsSum = new TH2F("DifvsSum","Pt difference vs Pt sum;p_{T,1}+p_{T,2} (GeV/c);#Deltap_{T} (GeV/c)",400,0.,400.,150,0.,150.);
+    fH2DifvsSum->SetOption("cont0");
+
+    fHistList->Add(fH1DeltaPt);
+    fHistList->Add(fH1DeltaPhi);
+    fHistList->Add(fH1PhiImbal);
+    fHistList->Add(fH1Asym);
+    fHistList->Add(fH2Pt2vsPt1);
+    fHistList->Add(fH2DifvsSum);
+}
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskDiJets::Init()
+{
+    // Initialization
+    if (fDebug) printf("AnalysisTaskDiJets::Init() \n");
+}
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskDiJets::UserExec(Option_t */*option*/)
+{
+// Execute analysis for current event
+//
+    if (fDiJets) fDiJets->Delete();
+
+    if(fUseAODInput){
+      fAOD = dynamic_cast<AliAODEvent*> (InputEvent());
+      if(!fAOD){
+        // We do not have an input AOD, look in the output
+        if (fDebug) printf("%s:%d No AOD event in the input\n",(char*)__FILE__,__LINE__);
+        return;
+      }
+    } else {
+      fAOD = AODEvent();
+      if(!fAOD){
+        if (fDebug) printf("%s:%d AODEvent not found in the Output",(char*)__FILE__,__LINE__);
+        return;
+      }
+    }
+
+    TClonesArray* jets = (TClonesArray*) fAOD->FindListObject(fJetBranch.Data());
+    // N.B. if we take the aod from the output this is always
+    // empty and since it is the same as fDiJets 
+    fDiJetsIn = (TClonesArray*) (fAOD->GetList()->FindObject("dijets"));
+
+    if (fDiJetsIn) {
+      if (fDebug) printf("Found %d dijets in old list \n", fDiJetsIn->GetEntries());
+      AliAODJet* jj1, *jj2;
+      AliAODDiJet* testJ;
+
+      if (fDiJetsIn->GetEntries() > 0) {
+        testJ = (AliAODDiJet*) (fDiJetsIn->At(0));
+        jj1 = testJ->Jet(0);
+        jj1->Print("");
+        jj2 = testJ->Jet(1);
+        jj2->Print("");
+      }
+    }
+
+    Int_t nj = jets->GetEntriesFast();
+    if (fDebug) printf("There are %5d jets in the event \n", nj);
+
+    if (nj < 2){
+      PostData(1, fHistList);
+      return;
+    }
+    AliAODJet* jet1 = (AliAODJet*) (jets->At(0));
+    TLorentzVector v1 = *(jet1->MomentumVector());
+    AliAODJet* jet2 = (AliAODJet*) (jets->At(1));
+    TLorentzVector v2 = *(jet2->MomentumVector());
+    TLorentzVector v = v1 + v2;
+    if (fDiJets) {
+       Int_t ndi = fDiJets->GetEntriesFast();
+       TClonesArray &lref = *fDiJets;
+       new(lref[ndi]) AliAODDiJet(v);
+       AliAODDiJet* dijet = (AliAODDiJet*) (fDiJets->At(ndi));
+       dijet->SetJetRefs(jet1, jet2);
+       fH1DeltaPhi->Fill(dijet->DeltaPhi());
+       fH1PhiImbal->Fill(dijet->PhiImbalance());
+
+    }
+    
+    fH1DeltaPt->Fill(jet1->Pt()-jet2->Pt());
+    fH1Asym->Fill((jet1->Pt()-jet2->Pt())/(jet1->Pt()+jet2->Pt()));
+    fH2Pt2vsPt1->Fill(jet1->Pt(),jet2->Pt());
+    fH2DifvsSum->Fill(jet1->Pt()+jet2->Pt(),jet1->Pt()-jet2->Pt());
+
+    PostData(1, fHistList);
+    return;
+}
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskDiJets::Terminate(Option_t */*option*/)
+{
+// Terminate analysis
+//
+    if (fDebug) printf("AnalysisDiJets: Terminate() \n");
+}
+
diff --git a/JETAN/DEV/AliAnalysisTaskDiJets.h b/JETAN/DEV/AliAnalysisTaskDiJets.h
new file mode 100644 (file)
index 0000000..70e52d4
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef ALIANALYSISTASKDIJETS_H
+#define ALIANALYSISTASKDIJETS_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#include "AliAnalysisTaskSE.h"
+#include <TList.h>
+#include <TH1F.h>
+#include <TH2F.h>
+
+class AliAnalysisTaskDiJets : public AliAnalysisTaskSE
+{
+ public:
+    AliAnalysisTaskDiJets();
+    AliAnalysisTaskDiJets(const char* name);
+    virtual ~AliAnalysisTaskDiJets() {;}
+
+    // Implementation of interface methods
+    virtual void UserCreateOutputObjects();
+    virtual void Init();
+    virtual void LocalInit() {Init();}
+    virtual void UserExec(Option_t *option);
+    virtual void Terminate(Option_t *option);
+
+    void SetAODInput(Bool_t b)   {fUseAODInput = b;}
+    void SetFillAOD(Bool_t fill) { fFillAOD=fill; }
+    void SetJetBranch(const Char_t *br){ fJetBranch=br; }
+
+ private:
+  AliAnalysisTaskDiJets(const AliAnalysisTaskDiJets &det);
+  AliAnalysisTaskDiJets &operator=(const AliAnalysisTaskDiJets &det);
+
+ private:
+  TClonesArray* fDiJets;    // Array of dijets
+  TClonesArray* fDiJetsIn;  // Array of dijets
+
+  Bool_t        fUseAODInput; // read jets from input AOD
+  Bool_t        fFillAOD;   // option to fill AOD branch
+  TString       fJetBranch; // jet branch to read
+
+  AliAODEvent  *fAOD;       // AOD event
+  TList        *fHistList;  // Output list
+
+  TH1F         *fH1DeltaPt;  // Pt difference
+  TH1F         *fH1DeltaPhi; // delta phi plot in (0,pi)
+  TH1F         *fH1PhiImbal; // phi imbalance (-pi,pi)
+  TH1F         *fH1Asym;     // asymmetry of the dijet
+  TH2F         *fH2Pt2vsPt1; // scatter plot with the two jets' Pt
+  TH2F         *fH2DifvsSum; // Pt difference vs Pt sum
+
+  ClassDef(AliAnalysisTaskDiJets, 2) // Analysis task for standard dijet analysis
+};
+
+#endif
diff --git a/JETAN/DEV/AliAnalysisTaskFastEmbedding.cxx b/JETAN/DEV/AliAnalysisTaskFastEmbedding.cxx
new file mode 100644 (file)
index 0000000..c092b06
--- /dev/null
@@ -0,0 +1,1196 @@
+/*************************************************************************
+ *                                                                       *
+ * Task for fast embedding                                               *
+ * read extra input from AOD                                             *
+ *                                                                       *
+ *************************************************************************/
+
+
+/**************************************************************************
+ * 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: */
+
+#include <TFile.h>
+#include <TTree.h>
+#include <TChain.h>
+#include <TClonesArray.h>
+#include <TDirectory.h>
+#include <TSystem.h>
+#include <TRef.h>
+#include <TRandom3.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TProfile.h>
+#include <TKey.h>
+
+
+#include "AliAnalysisTaskFastEmbedding.h"
+#include "AliAnalysisManager.h"
+#include "AliESDEvent.h"
+#include "AliESDtrack.h"
+#include "AliAODEvent.h"
+#include "AliAODTrack.h"
+#include "AliAODJet.h"
+#include "AliAODMCParticle.h"
+#include "AliAODMCHeader.h"
+#include "AliInputEventHandler.h"
+
+#include "AliLog.h"
+
+ClassImp(AliAnalysisTaskFastEmbedding)
+
+//__________________________________________________________________________
+AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding()
+: AliAnalysisTaskSE()
+,fESD(0)
+,fAODout(0)
+,fAODevent(0)
+,fAODtree(0)
+,fAODfile(0)
+,mcHeader(0)
+,rndm(0)
+,fInputEntries(0)
+,fAODPathArray(0)
+,fAODEntriesArray(0)
+,fAODPath("AliAOD.root")
+,fAODEntries(-1)
+,fAODEntriesSum(0)
+,fAODEntriesMax(0)
+,fOfflineTrgMask(AliVEvent::kAny)
+,fMinContribVtx(1)
+,fVtxZMin(-8.)
+,fVtxZMax(8.)
+,fEvtClassMin(0)
+,fEvtClassMax(4)
+,fCentMin(0.)
+,fCentMax(100.)
+,fNInputTracksMin(0)
+,fNInputTracksMax(-1)
+,fTrackBranch("aodExtraTracks")
+,fMCparticlesBranch("aodExtraMCparticles")
+,fJetBranch("")
+,fFileId(-1)
+,fAODEntry(0)
+,fCountEvents(-1)
+,fEmbedMode(0)
+,fEvtSelecMode(0)
+,fEvtSelMinJetPt(-1)
+,fEvtSelMaxJetPt(-1)
+,fEvtSelMinJetEta(-999.)
+,fEvtSelMaxJetEta( 999.)
+,fEvtSelMinJetPhi(0.)
+,fEvtSelMaxJetPhi(TMath::Pi()*2.)
+,fToyMinNbOfTracks(1)
+,fToyMaxNbOfTracks(1)
+,fToyMinTrackPt(50.)
+,fToyMaxTrackPt(50.)
+,fToyDistributionTrackPt(0.)
+,fToyMinTrackEta(-.5)
+,fToyMaxTrackEta(.5)
+,fToyMinTrackPhi(0.)
+,fToyMaxTrackPhi(2*TMath::Pi())
+,fToyFilterMap(0)
+,fTrackFilterMap(0)
+,fNPtHard(10)
+,fPtHard(0)
+,fPtHardBin(-1)
+,fAODJets(0x0)
+,fNevents(0)
+,fXsection(0)
+,fAvgTrials(0)
+,fHistList(0)
+,fHistEvtSelection(0)
+,fh1Xsec(0)
+,fh1Trials(0)
+,fh1TrialsEvtSel(0)
+,fh2PtHard(0)
+,fh2PtHardEvtSel(0)
+,fh2PtHardTrials(0)
+,fh1TrackPt(0)
+,fh2TrackEtaPhi(0)
+,fh1TrackN(0)
+,fh1JetPt(0)
+,fh2JetEtaPhi(0)
+,fh1JetN(0)
+,fh1MCTrackPt(0)
+,fh2MCTrackEtaPhi(0)
+,fh1MCTrackN(0)
+,fh1AODfile(0)
+,fh2AODevent(0)
+{
+   // default constructor
+
+}
+
+
+//__________________________________________________________________________
+AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding(const char *name)
+: AliAnalysisTaskSE(name)
+,fESD(0)
+,fAODout(0)
+,fAODevent(0)
+,fAODtree(0)
+,fAODfile(0)
+,mcHeader(0)
+,rndm(0)
+,fInputEntries(0)
+,fAODPathArray(0)
+,fAODEntriesArray(0)
+,fAODPath("AliAOD.root")
+,fAODEntries(-1)
+,fAODEntriesSum(0)
+,fAODEntriesMax(0)
+,fOfflineTrgMask(AliVEvent::kAny)
+,fMinContribVtx(1)
+,fVtxZMin(-8.)
+,fVtxZMax(8.)
+,fEvtClassMin(0)
+,fEvtClassMax(4)
+,fCentMin(0.)
+,fCentMax(100.)
+,fNInputTracksMin(0)
+,fNInputTracksMax(-1)
+,fTrackBranch("aodExtraTracks")
+,fMCparticlesBranch("aodExtraMCparticles")
+,fJetBranch("")
+,fFileId(-1)
+,fAODEntry(0)
+,fCountEvents(-1)
+,fEmbedMode(0)
+,fEvtSelecMode(0)
+,fEvtSelMinJetPt(-1)
+,fEvtSelMaxJetPt(-1)
+,fEvtSelMinJetEta(-999.)
+,fEvtSelMaxJetEta( 999.)
+,fEvtSelMinJetPhi(0.)
+,fEvtSelMaxJetPhi(TMath::Pi()*2.)
+,fToyMinNbOfTracks(1)
+,fToyMaxNbOfTracks(1)
+,fToyMinTrackPt(50.)
+,fToyMaxTrackPt(50.)
+,fToyDistributionTrackPt(0.)
+,fToyMinTrackEta(-.5)
+,fToyMaxTrackEta(.5)
+,fToyMinTrackPhi(0.)
+,fToyMaxTrackPhi(2*TMath::Pi())
+,fToyFilterMap(0)
+,fTrackFilterMap(0)
+,fNPtHard(10)
+,fPtHard(0)
+,fPtHardBin(-1)
+,fAODJets(0x0)
+,fNevents(0)
+,fXsection(0)
+,fAvgTrials(0)
+,fHistList(0)
+,fHistEvtSelection(0)
+,fh1Xsec(0)
+,fh1Trials(0)
+,fh1TrialsEvtSel(0)
+,fh2PtHard(0)
+,fh2PtHardEvtSel(0)
+,fh2PtHardTrials(0)
+,fh1TrackPt(0)
+,fh2TrackEtaPhi(0)
+,fh1TrackN(0)
+,fh1JetPt(0)
+,fh2JetEtaPhi(0)
+,fh1JetN(0)
+,fh1MCTrackPt(0)
+,fh2MCTrackEtaPhi(0)
+,fh1MCTrackN(0)
+,fh1AODfile(0)
+,fh2AODevent(0)
+{
+   // constructor
+   DefineOutput(1, TList::Class());
+}
+
+
+//__________________________________________________________________________
+AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding(const AliAnalysisTaskFastEmbedding &copy)
+: AliAnalysisTaskSE()
+,fESD(copy.fESD)
+,fAODout(copy.fAODout)
+,fAODevent(copy.fAODevent)
+,fAODtree(copy.fAODtree)
+,fAODfile(copy.fAODfile)
+,mcHeader(copy.mcHeader)
+,rndm(copy.rndm)
+,fInputEntries(copy.fInputEntries)
+,fAODPathArray(copy.fAODPathArray)
+,fAODEntriesArray(copy.fAODEntriesArray)
+,fAODPath(copy.fAODPath)
+,fAODEntries(copy.fAODEntries)
+,fAODEntriesSum(copy.fAODEntriesSum)
+,fAODEntriesMax(copy.fAODEntriesMax)
+,fOfflineTrgMask(copy.fOfflineTrgMask)
+,fMinContribVtx(copy.fMinContribVtx)
+,fVtxZMin(copy.fVtxZMin)
+,fVtxZMax(copy.fVtxZMax)
+,fEvtClassMin(copy.fEvtClassMin)
+,fEvtClassMax(copy.fEvtClassMax)
+,fCentMin(copy.fCentMin)
+,fCentMax(copy.fCentMax)
+,fNInputTracksMin(copy.fNInputTracksMin)
+,fNInputTracksMax(copy.fNInputTracksMax)
+,fTrackBranch(copy.fTrackBranch)
+,fMCparticlesBranch(copy.fMCparticlesBranch)
+,fJetBranch(copy.fJetBranch)
+,fFileId(copy.fFileId)
+,fAODEntry(copy.fAODEntry)
+,fCountEvents(copy.fCountEvents)
+,fEmbedMode(copy.fEmbedMode)
+,fEvtSelecMode(copy.fEvtSelecMode)
+,fEvtSelMinJetPt(copy.fEvtSelMinJetPt)
+,fEvtSelMaxJetPt(copy.fEvtSelMaxJetPt)
+,fEvtSelMinJetEta(copy.fEvtSelMinJetEta)
+,fEvtSelMaxJetEta(copy.fEvtSelMaxJetEta)
+,fEvtSelMinJetPhi(copy.fEvtSelMinJetPhi)
+,fEvtSelMaxJetPhi(copy.fEvtSelMaxJetPhi)
+,fToyMinNbOfTracks(copy.fToyMinNbOfTracks)
+,fToyMaxNbOfTracks(copy.fToyMaxNbOfTracks)
+,fToyMinTrackPt(copy.fToyMinTrackPt)
+,fToyMaxTrackPt(copy.fToyMaxTrackPt)
+,fToyDistributionTrackPt(copy.fToyDistributionTrackPt)
+,fToyMinTrackEta(copy.fToyMinTrackEta)
+,fToyMaxTrackEta(copy.fToyMaxTrackEta)
+,fToyMinTrackPhi(copy.fToyMinTrackPhi)
+,fToyMaxTrackPhi(copy.fToyMaxTrackPhi)
+,fToyFilterMap(copy.fToyFilterMap)
+,fTrackFilterMap(copy.fTrackFilterMap)
+,fNPtHard(copy.fNPtHard)
+,fPtHard(copy.fPtHard)
+,fPtHardBin(copy.fPtHardBin)
+,fAODJets(copy.fAODJets)
+,fNevents(copy.fNevents)
+,fXsection(copy.fXsection)
+,fAvgTrials(copy.fAvgTrials)
+,fHistList(copy.fHistList)
+,fHistEvtSelection(copy.fHistEvtSelection)
+,fh1Xsec(copy.fh1Xsec)
+,fh1Trials(copy.fh1Trials)
+,fh1TrialsEvtSel(copy.fh1TrialsEvtSel)
+,fh2PtHard(copy.fh2PtHard)
+,fh2PtHardEvtSel(copy.fh2PtHardEvtSel)
+,fh2PtHardTrials(copy.fh2PtHardTrials)
+,fh1TrackPt(copy.fh1TrackPt)
+,fh2TrackEtaPhi(copy.fh2TrackEtaPhi)
+,fh1TrackN(copy.fh1TrackN)
+,fh1JetPt(copy.fh1JetPt)
+,fh2JetEtaPhi(copy.fh2JetEtaPhi)
+,fh1JetN(copy.fh1JetN)
+,fh1MCTrackPt(copy.fh1MCTrackPt)
+,fh2MCTrackEtaPhi(copy.fh2MCTrackEtaPhi)
+,fh1MCTrackN(copy.fh1MCTrackN)
+,fh1AODfile(copy.fh1AODfile)
+,fh2AODevent(copy.fh2AODevent)
+{
+   // copy constructor
+}
+
+
+//__________________________________________________________________________
+AliAnalysisTaskFastEmbedding& AliAnalysisTaskFastEmbedding::operator=(const AliAnalysisTaskFastEmbedding& o)
+{
+   // assignment
+
+   if(this!=&o){
+      AliAnalysisTaskSE::operator=(o);
+      fESD               = o.fESD;
+      fAODout            = o.fAODout;
+      fAODevent          = o.fAODevent;
+      fAODtree           = o.fAODtree;
+      fAODfile           = o.fAODfile;
+      mcHeader           = o.mcHeader;
+      rndm               = o.rndm;
+      fInputEntries      = o.fInputEntries;
+      fAODPathArray      = o.fAODPathArray;
+      fAODEntriesArray   = o.fAODEntriesArray;
+      fAODPath           = o.fAODPath;
+      fAODEntries        = o.fAODEntries;
+      fAODEntriesSum     = o.fAODEntriesSum;
+      fAODEntriesMax     = o.fAODEntriesMax;
+      fOfflineTrgMask    = o.fOfflineTrgMask;
+      fMinContribVtx     = o.fMinContribVtx;
+      fVtxZMin           = o.fVtxZMin;
+      fVtxZMax           = o.fVtxZMax;
+      fEvtClassMin       = o.fEvtClassMin;
+      fEvtClassMax       = o.fEvtClassMax;
+      fCentMin           = o.fCentMin;
+      fCentMax           = o.fCentMax;
+      fNInputTracksMin   = o.fNInputTracksMin;
+      fNInputTracksMax   = o.fNInputTracksMax;
+      fTrackBranch       = o.fTrackBranch;
+      fMCparticlesBranch = o.fMCparticlesBranch;
+      fJetBranch         = o.fJetBranch;
+      fFileId            = o.fFileId;
+      fAODEntry          = o.fAODEntry;
+      fCountEvents       = o.fCountEvents;
+      fEmbedMode         = o.fEmbedMode;
+      fEvtSelecMode      = o.fEvtSelecMode;
+      fEvtSelMinJetPt    = o.fEvtSelMinJetPt;
+      fEvtSelMaxJetPt    = o.fEvtSelMaxJetPt;
+      fEvtSelMinJetEta   = o.fEvtSelMinJetEta;
+      fEvtSelMaxJetEta   = o.fEvtSelMaxJetEta;
+      fEvtSelMinJetPhi   = o.fEvtSelMinJetPhi;
+      fEvtSelMaxJetPhi   = o.fEvtSelMaxJetPhi;
+      fToyMinNbOfTracks  = o.fToyMinNbOfTracks;
+      fToyMaxNbOfTracks  = o.fToyMaxNbOfTracks;
+      fToyMinTrackPt     = o.fToyMinTrackPt;
+      fToyMaxTrackPt     = o.fToyMaxTrackPt;
+      fToyDistributionTrackPt = o.fToyDistributionTrackPt;
+      fToyMinTrackEta    = o.fToyMinTrackEta;
+      fToyMaxTrackEta    = o.fToyMaxTrackEta;
+      fToyMinTrackPhi    = o.fToyMinTrackPhi;
+      fToyMaxTrackPhi    = o.fToyMaxTrackPhi;
+      fToyFilterMap      = o.fToyFilterMap;
+      fTrackFilterMap    = o.fTrackFilterMap;
+      fNPtHard           = o.fNPtHard;
+      fPtHard            = o.fPtHard;
+      fPtHardBin         = o.fPtHardBin;
+      fAODJets           = o.fAODJets;
+      fNevents           = o.fNevents;
+      fXsection          = o.fXsection;
+      fAvgTrials         = o.fAvgTrials;
+      fHistList          = o.fHistList;
+      fHistEvtSelection  = o.fHistEvtSelection;
+      fh1Xsec            = o.fh1Xsec;
+      fh1Trials          = o.fh1Trials;
+      fh1TrialsEvtSel    = o.fh1TrialsEvtSel;
+      fh2PtHard          = o.fh2PtHard;
+      fh2PtHardEvtSel    = o.fh2PtHardEvtSel;
+      fh2PtHardTrials    = o.fh2PtHardTrials;
+      fh1TrackPt         = o.fh1TrackPt;
+      fh2TrackEtaPhi     = o.fh2TrackEtaPhi;
+      fh1TrackN          = o.fh1TrackN;
+      fh1JetPt           = o.fh1JetPt;
+      fh2JetEtaPhi       = o.fh2JetEtaPhi;
+      fh1JetN            = o.fh1JetN;
+      fh1MCTrackPt       = o.fh1MCTrackPt;
+      fh2MCTrackEtaPhi   = o.fh2MCTrackEtaPhi;
+      fh1MCTrackN        = o.fh1MCTrackN;
+      fh1AODfile         = o.fh1AODfile;
+      fh2AODevent        = o.fh2AODevent;
+   }
+
+   return *this;
+}
+
+
+//__________________________________________________________________________
+AliAnalysisTaskFastEmbedding::~AliAnalysisTaskFastEmbedding()
+{
+   // destructor
+   delete rndm;
+}
+
+
+//__________________________________________________________________________
+void AliAnalysisTaskFastEmbedding::UserCreateOutputObjects()
+{
+   // create output objects
+   if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::UserCreateOutputObjects()");
+   AliLog::SetClassDebugLevel("AliAnalysisTaskFastEmbedding", AliLog::kInfo);
+
+   OpenFile(1);
+   if(!fHistList) fHistList = new TList();
+   fHistList->SetOwner(kTRUE);
+   
+
+   // set seed
+   rndm = new TRandom3();
+   Int_t id = GetJobID();
+   if(id>-1) rndm->SetSeed(id);
+   else      rndm->SetSeed();   // a TTUID is generated and used for seed
+   AliInfo(Form("TRandom3 seed: %d", rndm->GetSeed()));
+
+
+
+   // embed mode with AOD
+   if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks || fEmbedMode==kAODJet4Mom){
+
+      // open input AOD
+      fFileId = OpenAODfile();
+      fNevents = 0; // force to open another aod in UserExec()
+      if(fFileId<0){
+         AliError("");
+         PostData(1, fHistList);
+         return;
+      }
+   } //end: embed mode with AOD
+
+
+   // connect output aod
+   // create a new branch for extra tracks
+   fAODout = AODEvent();
+   if(!fAODout){
+      AliError("Output AOD not found.");
+      PostData(1, fHistList);
+      return;
+   }
+   if(!fAODout->FindListObject(fTrackBranch.Data()) && strlen(fTrackBranch.Data())){
+      AliInfo(Form("Add AOD branch %s", fTrackBranch.Data()));
+      TClonesArray *tracks = new TClonesArray("AliAODTrack",0);
+      tracks->SetName(fTrackBranch.Data());
+      AddAODBranch("TClonesArray", &tracks);
+   }
+   // create new branch for extra mcparticle if available as input
+   if(fAODevent && fAODevent->FindListObject("mcparticles") && strlen(fMCparticlesBranch.Data())){
+      AliInfo(Form("Add AOD branch %s", fMCparticlesBranch.Data()));
+      TClonesArray *mcparticles = new TClonesArray("AliAODMCParticle",0);
+      mcparticles->SetName(fMCparticlesBranch.Data());
+      AddAODBranch("TClonesArray", &mcparticles);
+   }
+
+
+
+   //qa histograms
+   Bool_t oldStatus = TH1::AddDirectoryStatus();
+   TH1::AddDirectory(kFALSE);
+   
+   fHistEvtSelection = new TH1I("fHistEvtSelection", "event selection", 6, -0.5, 5.5);
+   fHistEvtSelection->GetXaxis()->SetBinLabel(1,"ACCEPTED");
+   fHistEvtSelection->GetXaxis()->SetBinLabel(2,"events IN");
+   fHistEvtSelection->GetXaxis()->SetBinLabel(3,"event selection (rejected)");
+   fHistEvtSelection->GetXaxis()->SetBinLabel(4,"vertex cut (rejected)");
+   fHistEvtSelection->GetXaxis()->SetBinLabel(5,"centrality (rejected)");
+   fHistEvtSelection->GetXaxis()->SetBinLabel(6,"multiplicity (rejected)");
+   
+   fh1Xsec         = new TProfile("fh1Xsec","xsec from pyxsec.root;p_{T,hard} bin;<#sigma>",fNPtHard+1,-1.5,fNPtHard-0.5);
+   fh1Trials       = new TH1F("fh1Trials","trials (simulation) from pyxsec.root;p_{T,hard} bin;#sum{ntrials}",fNPtHard+1,-1.5,fNPtHard-0.5);
+   fh1TrialsEvtSel = new TH1F("fh1TrialsEvtSel","trials (event selection) from pyxsec.root;p_{T,hard} bin;#sum{ntrials}",fNPtHard+1,-1.5,fNPtHard-0.5);
+   fh2PtHard       = new TH2F("fh2PtHard","PYTHIA Pt hard;p_{T,hard} bin;p_{T,hard}",fNPtHard+1,-1.5,fNPtHard-0.5,350,-.5,349.5);
+   fh2PtHardEvtSel = new TH2F("fh2PtHardEvtSel","PYTHIA Pt hard (event selection);p_{T,hard} bin;p_{T,hard}",fNPtHard+1,-1.5,fNPtHard-0.5,350,-.5,349.5);
+   fh2PtHardTrials = new TH2F("fh2PtHardTrials","PYTHIA Pt hard weight with trials;p_{T,hard} bin;#sum{p_{T,hard}}",fNPtHard+1,-1.5,fNPtHard-0.5,350,-.5,349.5);
+   
+   fHistList->Add(fHistEvtSelection);
+   fHistList->Add(fh1Xsec);
+   fHistList->Add(fh1Trials);
+   fHistList->Add(fh1TrialsEvtSel);
+   fHistList->Add(fh2PtHard);
+   fHistList->Add(fh2PtHardEvtSel);
+   fHistList->Add(fh2PtHardTrials);
+
+   fh1TrackPt      =  new TH1F("fh1TrackPt","pT of extra tracks;p_{T};entries", 250, 0., 250.);
+   fh2TrackEtaPhi  =  new TH2F("fh2TrackEtaPhi","eta-phi distribution of extra tracks;#eta;#phi", 20, -1., 1., 60, 0., 2*TMath::Pi());
+   fh1TrackN       =  new TH1F("fh1TrackN", "nb. of extra tracks per event;nb. of tracks;entries",300, 0., 300.);
+
+   fHistList->Add(fh1TrackPt);
+   fHistList->Add(fh2TrackEtaPhi);
+   fHistList->Add(fh1TrackN);
+   
+   if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks || fEmbedMode==kAODJet4Mom){
+      
+      fh1JetPt        =  new TH1F("fh1JetPt", "pT of extra jets;p_{T};entries", 120, 0., 120.);
+      fh2JetEtaPhi    =  new TH2F("fh2JetEtaPhi", "eta-phi distribution of extra jets;#eta;#phi", 20, -1., 1., 60, 0., 2*TMath::Pi());
+      fh1JetN         =  new TH1F("fh1JetN", "nb. of extra jets per event;nb. of jets;entries",20,0.,20.);
+      
+      fHistList->Add(fh1JetPt);
+      fHistList->Add(fh2JetEtaPhi);
+      fHistList->Add(fh1JetN);
+   }
+
+
+   if(fAODevent && fAODevent->FindListObject("mcparticles") && strlen(fMCparticlesBranch.Data())){ 
+
+      fh1MCTrackPt      =  new TH1F("fh1MCTrackPt","pT of MC extra tracks;p_{T};entries", 250, 0., 250.);
+      fh2MCTrackEtaPhi  =  new TH2F("fh2MCTrackEtaPhi","eta-phi distribution of MC extra tracks;#eta;#phi", 20, -1., 1., 60, 0., 2*TMath::Pi());
+      fh1MCTrackN       =  new TH1F("fh1MCTrackN", "nb. of MC extra tracks per event;nb. of tracks;entries",300, 0., 300.);
+      
+      fHistList->Add(fh1MCTrackPt);
+      fHistList->Add(fh2MCTrackEtaPhi);
+      fHistList->Add(fh1MCTrackN);
+      
+   }
+   
+   fh1AODfile = new TH1I("fh1AODfile", "overview of opened AOD files from the array", 2300, -0.5, 2299.5);
+   fh2AODevent = new TH2I("fh1AODevent","selected events;file;event", 2500,-.5,2499.5,5000,-.5,4999.5);
+   fHistList->Add(fh1AODfile);
+   fHistList->Add(fh2AODevent);
+
+   // =========== Switch on Sumw2 for all histos ===========
+   for (Int_t i=0; i<fHistList->GetEntries(); ++i) {
+      TH1 *h1 = dynamic_cast<TH1*>(fHistList->At(i));
+      if (h1){
+         h1->Sumw2();
+         continue;
+      }
+   }
+
+   TH1::AddDirectory(oldStatus);
+
+   PostData(1, fHistList);
+}
+
+
+//__________________________________________________________________________
+void AliAnalysisTaskFastEmbedding::Init()
+{
+   // Initialization
+   if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::Init()");
+
+}
+
+//__________________________________________________________________________
+Bool_t AliAnalysisTaskFastEmbedding::UserNotify()
+{
+
+   if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::UserNotify()");
+
+   // get total nb of events in tree (of this subjob)
+   AliInputEventHandler* inputHandler = (AliInputEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
+   fInputEntries = inputHandler->GetTree()->GetEntriesFast();
+   AliInfo(Form("Total nb. of events: %d", fInputEntries));
+
+   return kTRUE;
+
+}
+
+
+//__________________________________________________________________________
+void AliAnalysisTaskFastEmbedding::UserExec(Option_t *)
+{
+   if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::UserExec()");
+
+   if(!fAODout){
+      AliError("Need output AOD, but is not connected."); 
+      PostData(1, fHistList);
+      return;
+   }
+
+   fESD=dynamic_cast<AliESDEvent*>(InputEvent());
+   if (!fESD) {
+      AliError("ESD not available");
+      PostData(1, fHistList);
+      return;
+   }
+
+   // -- event selection --
+   fHistEvtSelection->Fill(1); // number of events before event selection
+
+   // physics selection
+   AliInputEventHandler* inputHandler = (AliInputEventHandler*)
+   ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
+   if(!(inputHandler->IsEventSelected() & fOfflineTrgMask)){
+      if(fDebug) Printf(" Trigger Selection: event REJECTED ... ");
+      fHistEvtSelection->Fill(2);
+      PostData(1, fHistList);
+      return;
+   } 
+
+   // vertex selection
+   AliAODVertex* primVtx = fAODout->GetPrimaryVertex();
+   Int_t nTracksPrim = primVtx->GetNContributors();
+   if ((nTracksPrim < fMinContribVtx) ||
+         (primVtx->GetZ() < fVtxZMin) ||
+         (primVtx->GetZ() > fVtxZMax) ){
+      if(fDebug) Printf("%s:%d primary vertex z = %f: event REJECTED...",(char*)__FILE__,__LINE__,primVtx->GetZ());
+      fHistEvtSelection->Fill(3);
+      PostData(1, fHistList);
+      return;
+   }
+
+   /** takes wrong value, since jet service tasks runs later
+   // event class selection (from jet helper task)
+   Int_t eventClass = AliAnalysisHelperJetTasks::EventClass();
+   if(fDebug) Printf("Event class %d", eventClass);
+   if (eventClass < fEvtClassMin || eventClass > fEvtClassMax){
+   fHistEvtSelection->Fill(4);
+   PostData(1, fHistList);
+   return;
+   }*/
+
+   // centrality selection
+   AliCentrality *cent = 0x0;
+   Float_t centValue = 0.; 
+   if(fESD) cent = fESD->GetCentrality();
+   if(cent) centValue = cent->GetCentralityPercentile("V0M");
+   if(fDebug) printf("centrality: %f\n", centValue);
+   if (centValue < fCentMin || centValue > fCentMax){
+      fHistEvtSelection->Fill(4);
+      PostData(1, fHistList);
+      return;
+   }
+
+
+   /*  ** not implemented **
+   // multiplicity due to input tracks
+   Int_t nInputTracks = GetNInputTracks();
+
+   if (nInputTracks < fNInputTracksMin || (fNInputTracksMax > -1 && nInputTracks > fNInputTracksMax)){
+   fHistEvtSelection->Fill(5);
+   PostData(1, fHistList);
+   return;
+   }
+   */
+
+   fHistEvtSelection->Fill(0); // accepted events  
+   // -- end event selection --
+
+   // connect aod out
+   TClonesArray *tracks = (TClonesArray*)(fAODout->FindListObject(fTrackBranch.Data()));
+   if(!tracks){
+      AliError("Extra track branch not found in output.");
+      PostData(1, fHistList);
+      return;
+   }
+   tracks->Delete();
+   Int_t nAODtracks=0;
+
+   TRef dummy;
+
+   // === embed mode with AOD ===
+   if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks || fEmbedMode==kAODJet4Mom){
+      if(!fAODevent){
+         AliError("Need input AOD, but is not connected."); 
+         PostData(1, fHistList);
+         return;
+      }
+
+
+
+      Bool_t useEntry = kFALSE;
+      while(!useEntry){  // protection need, if no event fulfills requierment
+
+         fAODEntry++; // go to next event 
+         fCountEvents++;
+         if(fAODEntry>=fNevents) fAODEntry=0; 
+
+         // open new aod file
+         if(fCountEvents>=fNevents){ 
+            if(!fAODPathArray){
+               AliDebug(AliLog::kDebug, "No list of AODs, keep current AOD.");
+            } 
+            else {
+               AliDebug(AliLog::kDebug, "Select new AOD file ...");
+
+               fFileId = OpenAODfile();
+               if(fFileId<0) {
+                  PostData(1, fHistList);
+                  return;
+               }
+               fh1AODfile->Fill(fFileId);
+               if(fAODEntries!=fNevents){
+                  AliError("File with list of AODs and file with nb. of entries inconsistent");
+                  PostData(1, fHistList);
+                  return;
+               }
+            }
+         }
+
+
+
+         // get next event
+         fAODtree->GetEvent(fAODEntry);
+
+         // get pt hard
+         if(mcHeader){
+            fPtHard = mcHeader->GetPtHard();
+            GetPtHard(kTRUE,fPtHard); // make value available for other tasks (e.g. jet response task)
+            AliDebug(AliLog::kDebug,Form("pt hard %.2f", fPtHard));
+         }
+         else{
+            AliDebug(AliLog::kDebug,"No mcHeader");
+         }
+         fPtHardBin = GetPtHardBin(fPtHard);
+
+         //Printf("pt hard (bin) %.2f (%d), xSection %.2e, trials %.2f",fPtHard, fPtHardBin, fXsection, fAvgTrials); 
+
+         // fill event variables for each event
+         fh1Xsec->Fill(fPtHardBin,fXsection);
+         fh2PtHard->Fill(fPtHardBin,fPtHard);
+
+         fh1Trials->Fill(fPtHardBin, fAvgTrials);
+         fh1TrialsEvtSel->Fill(fPtHardBin);
+         fh2PtHardTrials->Fill(fPtHardBin,fPtHard,fAvgTrials);
+
+         // jet pt selection
+         if(fEvtSelecMode==kEventsJetPt){
+            Int_t nJets = fAODJets->GetEntries();
+            //Printf("nb. jets: %d",nJets);
+            for(Int_t ij=0; ij<nJets; ++ij){
+               AliAODJet *jet = dynamic_cast<AliAODJet*>(fAODJets->At(ij));
+               if(!jet) continue;
+
+               if(   (fEvtSelMinJetPt==-1. || jet->Pt()>=fEvtSelMinJetPt)
+                     && (fEvtSelMaxJetPt==-1. || jet->Pt()<=fEvtSelMaxJetPt)
+                     && (jet->Eta()>=fEvtSelMinJetEta && jet->Eta()<=fEvtSelMaxJetEta)
+                     && (jet->Phi()>=fEvtSelMinJetPhi && jet->Phi()<=fEvtSelMaxJetPhi)){
+                  useEntry = kTRUE;
+                  break;
+               } 
+            }
+         }
+
+         // no selection
+         if(fEvtSelecMode==kEventsAll){
+            useEntry = kTRUE;
+         }
+
+      }
+      AliDebug(AliLog::kDebug,Form("Use entry %d from extra AOD.", fAODEntry));
+
+      fh2PtHardEvtSel->Fill(fPtHardBin,fPtHard);
+      fh2AODevent->Fill(fFileId,fAODEntry);
+
+      TClonesArray *mcpartIN  = (TClonesArray*)(fAODevent->FindListObject("mcparticles"));
+      TClonesArray *mcpartOUT = 0x0;
+      if(mcpartIN){
+         mcpartOUT = (TClonesArray*)(fAODout->FindListObject(fMCparticlesBranch.Data()));
+         if(!mcpartOUT){
+            AliError("Extra MC particles branch not found in output.");
+            PostData(1, fHistList);
+            return;
+         }
+         mcpartOUT->Delete();
+      } else {
+         AliInfo("No extra MC particles found.");
+      }
+
+
+      if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks){ // take all tracks or jet tracks
+         // loop over input tracks
+         // add to output aod
+         Int_t nTracks = 0;
+         Int_t nJets = fAODJets->GetEntries();
+         Int_t nSelectedJets = 0;
+         AliAODJet *leadJet = 0x0; // used for jet tracks only
+
+         if(fEmbedMode==kAODFull){
+            nTracks = fAODevent->GetNumberOfTracks();
+
+            for(Int_t ij=0; ij<nJets; ++ij){
+               AliAODJet *jet = dynamic_cast<AliAODJet*>(fAODJets->At(ij));
+               if(!jet) continue;
+               if(   (fEvtSelMinJetPt==-1. || jet->Pt()>=fEvtSelMinJetPt)
+                     && (fEvtSelMaxJetPt==-1. || jet->Pt()<=fEvtSelMaxJetPt)
+                     && (jet->Eta()>=fEvtSelMinJetEta && jet->Eta()<=fEvtSelMaxJetEta)
+                     && (jet->Phi()>=fEvtSelMinJetPhi && jet->Eta()<=fEvtSelMaxJetPhi)){
+
+                  fh1JetPt->Fill(jet->Pt());
+                  fh2JetEtaPhi->Fill(jet->Eta(), jet->Phi());
+                  nSelectedJets++;
+
+               }
+            }                             
+            fh1JetN->Fill(nSelectedJets);
+         }
+
+         if(fEmbedMode==kAODJetTracks){
+            // look for leading jet within selection
+            // get reference tracks for this jet
+            Float_t leadJetPt = 0.;
+            for(Int_t ij=0; ij<nJets; ++ij){
+               AliAODJet *jet = dynamic_cast<AliAODJet*>(fAODJets->At(ij));
+               if(!jet) continue;
+               if(   (fEvtSelMinJetPt==-1. || jet->Pt()>=fEvtSelMinJetPt)
+                     && (fEvtSelMaxJetPt==-1. || jet->Pt()<=fEvtSelMaxJetPt)
+                     && (jet->Eta()>=fEvtSelMinJetEta && jet->Eta()<=fEvtSelMaxJetEta)
+                     && (jet->Phi()>=fEvtSelMinJetPhi && jet->Eta()<=fEvtSelMaxJetPhi)){
+                  if(jet->Pt()>leadJetPt){
+                     leadJetPt = jet->Pt();
+                     leadJet = jet;
+                  } 
+               }
+            }
+            if(leadJet){
+               nTracks = leadJet->GetRefTracks()->GetEntriesFast();
+               fh1JetPt->Fill(leadJet->Pt());
+               fh2JetEtaPhi->Fill(leadJet->Eta(), leadJet->Pt());
+               fh1JetN->Fill(1);                                  
+            }
+         }
+
+         fh1TrackN->Fill((Float_t)nTracks);
+
+         for(Int_t it=0; it<nTracks; ++it){
+            AliAODTrack *tmpTr = 0x0;
+            if(fEmbedMode==kAODFull)      tmpTr = fAODevent->GetTrack(it);
+            if(fEmbedMode==kAODJetTracks) tmpTr = dynamic_cast<AliAODTrack*>(leadJet->GetRefTracks()->At(it));
+            if(!tmpTr) continue;
+
+            tmpTr->SetStatus(AliESDtrack::kEmbedded);
+
+            new ((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr); 
+            dummy = (*tracks)[nAODtracks-1];
+
+            if(fTrackFilterMap<=0 || tmpTr->TestFilterBit(fTrackFilterMap)){
+               fh1TrackPt->Fill(tmpTr->Pt());
+               fh2TrackEtaPhi->Fill(tmpTr->Eta(), tmpTr->Phi());
+            }
+         }
+
+         if(mcpartIN){
+            Int_t nMCpart = mcpartIN->GetEntriesFast();
+
+            Int_t nPhysicalPrimary=0;
+            Int_t nAODmcpart=0;
+            for(Int_t ip=0; ip<nMCpart; ++ip){
+               AliAODMCParticle *tmpPart = (AliAODMCParticle*) mcpartIN->At(ip);
+
+               if(fEmbedMode==kAODJetTracks){
+                  // jet track? else continue
+                  // not implemented yet
+                  continue;
+               } 
+
+               new((*mcpartOUT)[nAODmcpart++]) AliAODMCParticle(*tmpPart);
+               dummy = (*mcpartOUT)[nAODmcpart-1];
+
+               if(tmpPart->IsPhysicalPrimary() && tmpPart->Charge()!=0. && tmpPart->Charge()!=-99. ){
+                  fh1MCTrackPt->Fill(tmpPart->Pt());
+                  fh2MCTrackEtaPhi->Fill(tmpPart->Eta(), tmpPart->Phi());
+                  nPhysicalPrimary++;
+               }
+            }
+            fh1MCTrackN->Fill((Float_t)nPhysicalPrimary);
+
+         }
+      } // end: embed all tracks or jet tracks
+
+
+      if(fEmbedMode==kAODJet4Mom){
+
+         // loop over jets
+         Int_t nJets = fAODJets->GetEntries();
+         fh1TrackN->Fill((Float_t)nJets);
+         for(Int_t ij=0; ij<nJets; ++ij){
+            AliAODJet *jet = dynamic_cast<AliAODJet*>(fAODJets->At(ij));
+            if(!jet) continue;
+            AliAODTrack *tmpTr = (AliAODTrack*)jet;
+            tmpTr->SetFlags(AliESDtrack::kEmbedded);
+
+            new ((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr);
+            dummy = (*tracks)[nAODtracks-1]; 
+
+            fh1TrackPt->Fill(tmpTr->Pt());
+            fh2TrackEtaPhi->Fill(tmpTr->Eta(), tmpTr->Phi());
+         }
+
+      } // end: embed jets as 4-momenta
+
+
+   } //end: embed mode with AOD
+
+
+   // === embed mode with toy ===
+   if(fEmbedMode==kToyTracks){
+      Int_t nT = (Int_t)(rndm->Uniform(fToyMinNbOfTracks, fToyMaxNbOfTracks)+0.5);
+
+      fh1TrackN->Fill((Float_t)nT);
+
+      for(Int_t i=0; i<nT; ++i){
+
+         Double_t pt = -1.;
+         if(fToyMinTrackPt!=fToyMaxTrackPt){
+            if(fToyDistributionTrackPt==0){
+               pt = rndm->Uniform(fToyMinTrackPt, fToyMaxTrackPt);
+            } else {
+               while(pt<fToyMinTrackPt||pt>fToyMaxTrackPt){
+                  pt = rndm->Exp(fToyDistributionTrackPt);   // no power law yet!!
+                  pt += fToyMinTrackPt;
+               }
+            }
+         } else {
+            pt = fToyMinTrackPt;
+         }
+         Double_t eta = rndm->Uniform(fToyMinTrackEta,fToyMaxTrackEta);
+         Double_t phi = rndm->Uniform(fToyMinTrackPhi,fToyMaxTrackPhi);
+         phi = TVector2::Phi_0_2pi(phi);
+
+         if(fDebug) Printf("Add track #%d: pt %.2f, eta %.2f, phi %.2f", i, pt, eta, phi);
+
+         Double_t theta = 2*TMath::ATan(1/TMath::Exp(eta));
+         Float_t mom[3];
+         mom[0] = pt;
+         mom[1] = phi;
+         mom[2] = theta;
+
+         Float_t xyz[3];
+         xyz[0] = -999.;
+         xyz[1] = -999.;
+         xyz[2] = -999.;
+
+         AliAODTrack *tmpTr = new AliAODTrack( -999,   // id
+         -999,   // label
+         mom,    // momentum[3]
+         kFALSE, // cartesian
+         xyz,    // position
+         kFALSE, // DCA
+         NULL,   // covMatrix,
+         -99,    // charge
+         0,      // itsClusMap
+         NULL,   // pid 
+         NULL,   // prodVertex
+         kFALSE, // used for vertex fit
+         kFALSE, // used for prim vtx fit
+         AliAODTrack::kUndef, // type
+         fToyFilterMap,  // select info
+         -999.    // chi2 per NDF
+         );
+         tmpTr->SetFlags(AliESDtrack::kEmbedded);
+
+         new((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr);
+         dummy = (*tracks)[nAODtracks-1];
+
+         fh1TrackPt->Fill(pt);
+         fh2TrackEtaPhi->Fill(eta,phi);
+
+         delete tmpTr;
+      }
+   } //end: embed mode with toy
+
+
+   PostData(1, fHistList);
+}
+
+
+//__________________________________________________________________________
+void AliAnalysisTaskFastEmbedding::Terminate(Option_t *)
+{
+   if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::Terminate()");
+
+   if(fAODfile && fAODfile->IsOpen())
+   fAODfile->Close();  
+
+}
+
+//__________________________________________________________________________
+Int_t AliAnalysisTaskFastEmbedding::GetJobID()
+{
+   Int_t id=-1;
+
+   const char* env = gSystem->Getenv("ALIEN_PROC_ID"); // GRID
+   //if(!env || !strlen(env)) env = gSystem->Getenv("LSB_JOBINDEX"); // GSI
+
+   if(env && strlen(env)){
+      id= atoi(env);
+      AliInfo(Form("Job index %d", id));
+   }
+   else{
+      AliInfo("Job index not found. Okay if running locally.");
+   }
+
+   return id;
+}
+
+//__________________________________________________________________________
+
+Int_t AliAnalysisTaskFastEmbedding::SelectAODfile(){
+
+   Int_t nFiles = fAODPathArray->GetEntries();
+
+   // choose randomly file and event
+   Int_t n = -1;
+   Float_t tmpProp = -1.;
+   Int_t pendingEvents = fInputEntries-Entry();
+   //Printf("input entries %d, entry %d, pending events %d", fInputEntries, (Int_t)Entry(), pendingEvents);
+   while(rndm->Rndm()>tmpProp){
+      n = rndm->Integer(nFiles);
+      fAODEntries = fAODEntriesArray->At(n);
+      Int_t tmpEntries = fAODEntries<pendingEvents ? pendingEvents : fAODEntries;
+      tmpProp = fAODEntriesMax ? (Float_t)tmpEntries/fAODEntriesMax : 1.;
+   }
+   fAODEntry = (Int_t)(rndm->Uniform(fAODEntries));
+
+   AliInfo(Form("Select AOD file %d", n));
+   TObjString *objStr = (TObjString*) fAODPathArray->At(n);
+   if(!objStr){
+      AliError("Could not get path of aod file.");
+      return -1;
+   }
+   fAODPath = objStr->GetString();
+
+   return n;
+}
+
+//__________________________________________________________________________
+
+Int_t AliAnalysisTaskFastEmbedding::OpenAODfile(Int_t trial){
+
+   if(fAODPathArray) fFileId = SelectAODfile();
+   if(fFileId<0) return -1;
+
+   TDirectory *owd = gDirectory;
+   if (fAODfile) fAODfile->Close();
+   fAODfile = TFile::Open(fAODPath.Data(),"TIMEOUT=180");
+   owd->cd();
+   if(!fAODfile){
+
+      fFileId = -1;
+      if(fAODPathArray){
+         if(trial<=3){ 
+            AliError(Form("Could not open AOD file %s (trial %d), try again ...", fAODPath.Data(), trial));
+            fFileId = OpenAODfile(trial+1);
+         } else {
+            AliError(Form("Could not open AOD file %s, give up ...",fAODPath.Data()));
+            return -1;
+         }
+      } else {
+         AliError(Form("Could not open AOD file %s.", fAODPath.Data()));
+      }
+
+      return fFileId;
+   }
+
+   fAODtree = (TTree*)fAODfile->Get("aodTree");
+
+   if(!fAODtree){
+      AliError("AOD tree not found.");
+      return -1;
+   }
+
+   /*
+      fAODtree->SetBranchStatus("*",0);
+      fAODtree->SetBranchStatus("header",1);
+      fAODtree->SetBranchStatus("tracks*",1);
+      fAODtree->SetBranchStatus("jets*",1);
+      fAODtree->SetBranchStatus("clusters*",1);
+      fAODtree->SetBranchStatus("mcparticles*",1);
+      fAODtree->SetBranchStatus("mcHeader*",1);
+   */
+
+   delete fAODevent;
+   fAODevent = new AliAODEvent();
+   fAODevent->ReadFromTree(fAODtree);
+
+
+   // fetch header, jets, etc. from new file
+   fNevents = fAODtree->GetEntries();
+   mcHeader = (AliAODMCHeader*)fAODevent->FindListObject(AliAODMCHeader::StdBranchName());
+
+   if(fJetBranch.Length()) fAODJets = dynamic_cast<TClonesArray*>(fAODevent->FindListObject(fJetBranch.Data()));
+   else                    fAODJets = fAODevent->GetJets();
+   if(!fAODJets){
+      AliError("Could not find jets in AOD. Check jet branch when indicated.");
+      return -1;
+   }
+
+   TFile *curfile = fAODtree->GetCurrentFile();
+   if (!curfile) {
+      AliError("No current file.");
+      return -1;
+   }
+
+   Float_t trials = 1.;
+   Float_t xsec = 0.;
+   PythiaInfoFromFile(curfile->GetName(),xsec,trials);
+   fXsection = xsec;
+
+   // construct a poor man average trials 
+   Float_t nEntries = (Float_t)fAODtree->GetTree()->GetEntries();
+   if(trials>=nEntries && nEntries>0.)fAvgTrials = trials/nEntries;
+
+   if(fFileId>=0){
+      AliInfo(Form("Read successfully AOD event from file %d",fFileId));
+   }
+
+   fCountEvents=0; // new file, reset counter
+
+   return fFileId;  // file position in AOD path array, if array available
+}
+
+
+//____________________________________________________________________________
+Float_t AliAnalysisTaskFastEmbedding::GetPtHard(Bool_t bSet, Float_t newValue){
+
+   static Float_t ptHard = -1.;
+   if(bSet) ptHard = newValue;
+
+   return ptHard;
+}
+
+//____________________________________________________________________________
+Int_t AliAnalysisTaskFastEmbedding::GetPtHardBin(Double_t ptHard){
+
+   const Int_t nBins = 10;
+   Double_t binLimits[nBins] = { 5., 11., 21., 36., 57., 84., 117., 156., 200., 249. }; // lower limits
+
+   Int_t bin = -1;
+   while(bin<nBins-1 && binLimits[bin+1]<ptHard){
+      bin++;
+   }
+
+   return bin;
+}
+
+//____________________________________________________________________________
+Bool_t AliAnalysisTaskFastEmbedding::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
+   //
+   // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
+   // This should provide the path to the AOD/ESD file
+   // (taken from PWG4/JetTasks/AliAnalysisHelperJetTasks) 
+
+   TString file(currFile);  
+   fXsec = 0;
+   fTrials = 1;
+
+   if(file.Contains("root_archive.zip#")){
+      Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
+      Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
+      file.Replace(pos+1,20,"");
+   }
+   else {
+      // not an archive take the basename....
+      file.ReplaceAll(gSystem->BaseName(file.Data()),"");
+   }
+
+   TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); // problem that we cannot really test the existance of a file in a archive so we have to lvie with open error message from root
+   if(!fxsec){
+      // next trial fetch the histgram file
+      fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
+      if(!fxsec){
+         // not a severe condition but inciate that we have no information
+         AliDebug(AliLog::kDebug,Form("Neither pyxsec.root nor pyxsec_hists.root found in %s",file.Data()));
+         return kFALSE;
+      }
+      else{
+         // find the tlist we want to be independtent of the name so use the Tkey
+         TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0); 
+         if(!key){
+            fxsec->Close();
+            return kFALSE;
+         }
+         TList *list = dynamic_cast<TList*>(key->ReadObj());
+         if(!list){
+            fxsec->Close();
+            return kFALSE;
+         }
+         fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
+         fTrials  = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
+         fxsec->Close();
+      }
+   } // no tree pyxsec.root
+   else {
+      TTree *xtree = (TTree*)fxsec->Get("Xsection");
+      if(!xtree){
+         fxsec->Close();
+         return kFALSE;
+      }
+      UInt_t   ntrials  = 0;
+      Double_t  xsection  = 0;
+      xtree->SetBranchAddress("xsection",&xsection);
+      xtree->SetBranchAddress("ntrials",&ntrials);
+      xtree->GetEntry(0);
+      fTrials = ntrials;
+      fXsec = xsection;
+      fxsec->Close();
+   }
+   return kTRUE;
+}
+
+
diff --git a/JETAN/DEV/AliAnalysisTaskFastEmbedding.h b/JETAN/DEV/AliAnalysisTaskFastEmbedding.h
new file mode 100644 (file)
index 0000000..d17a43c
--- /dev/null
@@ -0,0 +1,197 @@
+#ifndef ALIANALYSISTASKFASTEMBEDDING_H
+#define ALIANALYSISTASKFASTEMBEDDING_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#include "AliAnalysisTaskSE.h"
+
+class AliESDEvent;
+class AliAODEvent;
+class TTree;
+class TFile;
+class TChain;
+class TObjArray;
+class TObjString;
+class TRandom3;
+class TH1F;
+class TH2F;
+class TProfile;
+class AliAODMCHeader;
+
+class AliAnalysisTaskFastEmbedding : public AliAnalysisTaskSE {
+
+public:
+   
+   AliAnalysisTaskFastEmbedding();
+   AliAnalysisTaskFastEmbedding(const char *name);
+   AliAnalysisTaskFastEmbedding(const AliAnalysisTaskFastEmbedding &copy);
+   AliAnalysisTaskFastEmbedding& operator=(const AliAnalysisTaskFastEmbedding &o);
+   virtual ~AliAnalysisTaskFastEmbedding();
+
+   virtual void UserCreateOutputObjects();
+   virtual void LocalInit() { Init(); }
+   virtual void Init();
+   virtual Bool_t UserNotify();
+   virtual void UserExec(Option_t*);
+   virtual void Terminate(Option_t */*option*/);
+
+   void SetAODPath(TString path) {fAODPath = path;}
+   void SetArrayOfAODPaths(TObjArray* arr) {fAODPathArray = arr;}
+   void SetArrayOfAODEntries(TArrayI* arr) {fAODEntriesArray = arr;}
+   void SetAODEntriesSum(Int_t i){ fAODEntriesSum = i;}
+   void SetAODEntriesMax(Int_t i){ fAODEntriesMax = i;}
+   
+   virtual void     SetOfflineTrgMask(AliVEvent::EOfflineTriggerTypes mask) { fOfflineTrgMask = mask; }
+   virtual void     SetMinContribVtx(Int_t n) { fMinContribVtx = n; }
+   virtual void     SetVtxZMin(Float_t z) { fVtxZMin = z; }
+   virtual void     SetVtxZMax(Float_t z) { fVtxZMax = z; }
+   virtual void     SetEvtClassMin(Int_t evtClass) { fEvtClassMin = evtClass; }
+   virtual void     SetEvtClassMax(Int_t evtClass) { fEvtClassMax = evtClass; }
+   virtual void     SetCentMin(Float_t cent) { fCentMin = cent; }
+   virtual void     SetCentMax(Float_t cent) { fCentMax = cent; }
+   virtual void     SetNInputTracksMin(Int_t nTr) { fNInputTracksMin = nTr; }
+   virtual void     SetNInputTracksMax(Int_t nTr) { fNInputTracksMax = nTr; }
+   
+   void SetTrackBranch(TString name) {fTrackBranch = name;}
+   void SetMCparticlesBranch(TString name) {fMCparticlesBranch = name;}
+   void SetJetBranch(TString name) {fJetBranch = name;}
+
+   void SetEmbedMode(Int_t m) {fEmbedMode = m;}
+   Int_t GetEmbedMode() {return fEmbedMode;} 
+   void SetEvtSelecMode(Int_t s) {fEvtSelecMode = s;}
+   Int_t GetEvtSelecMode() {return fEvtSelecMode;}
+
+   void SetEvtSelJetPtRange(Float_t minPt, Float_t maxPt) {fEvtSelMinJetPt = minPt; fEvtSelMaxJetPt = maxPt;}
+   void SetEvtSelJetEtaRange(Float_t minEta, Float_t maxEta) {fEvtSelMinJetEta = minEta; fEvtSelMaxJetEta = maxEta;}
+   void SetEvtSelJetPhiRange(Float_t minPhi, Float_t maxPhi) {fEvtSelMinJetPhi = minPhi; fEvtSelMaxJetPhi = maxPhi;}
+   
+   void SetToyNumberOfTrackRange(Int_t minN = 1, Int_t maxN = 1){ fToyMinNbOfTracks = minN, fToyMaxNbOfTracks = maxN; }
+   void SetToyTrackRanges(Double_t minPt = 50., Double_t maxPt = 50., Double_t ptDistr=0,
+   Double_t minEta = -.5, Double_t maxEta = .5,
+   Double_t minPhi = 0., Double_t maxPhi = 2*TMath::Pi())
+   {
+      fToyMinTrackPt = minPt; fToyMaxTrackPt = maxPt; fToyDistributionTrackPt = ptDistr;
+      fToyMinTrackEta = minEta; fToyMaxTrackEta = maxEta;
+      fToyMinTrackPhi = minPhi; fToyMaxTrackPhi = maxPhi;}
+   void SetToyFilterMap(UInt_t f) {fToyFilterMap = f;}
+   void SetTrackFilterMap(UInt_t f) {fTrackFilterMap = f;}
+
+   static Float_t GetPtHard(Bool_t bSet=kFALSE, Float_t newValue = 0.);
+   
+   virtual Int_t      GetPtHardBin(Double_t ptHard);
+   virtual Bool_t     PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials);
+
+   // embedding modes
+   enum {kAODFull=0, kAODJetTracks, kAODJet4Mom, kToyTracks};
+   // event selection from AOD
+   enum {kEventsAll=0, kEventsJetPt};
+
+
+private:
+
+   AliESDEvent    *fESD;        //! ESD object
+   AliAODEvent    *fAODout;     //! AOD out
+   AliAODEvent    *fAODevent;   //! AOD in
+   TTree          *fAODtree;    //! AODin tree
+   TFile          *fAODfile;    //! AODin file
+   AliAODMCHeader *mcHeader;    //! mc header
+   TRandom3       *rndm;        //! random nummer generator
+   Int_t          fInputEntries; // total nb. of events (for this subjob)
+
+   TObjArray *fAODPathArray;    // array of paths of AOD in file
+   TArrayI   *fAODEntriesArray; // array of entries of AODs 
+   TString    fAODPath;         // path of AOD in file
+   Int_t      fAODEntries;      // entries of AOD
+   Int_t      fAODEntriesSum;   // sum of all entries of AODs
+   Int_t      fAODEntriesMax;   // maximum entries of AODs
+
+   AliVEvent::EOfflineTriggerTypes fOfflineTrgMask; // mask of offline triggers to accept
+   Int_t   fMinContribVtx; // minimum number of track contributors for primary vertex
+   Float_t fVtxZMin;         // lower bound on vertex z
+   Float_t fVtxZMax;         // upper bound on vertex z
+   Int_t   fEvtClassMin;       // lower bound on event class
+   Int_t   fEvtClassMax;       // upper bound on event class
+   Float_t fCentMin;         // lower bound on centrality
+   Float_t fCentMax;         // upper bound on centrality
+   Int_t   fNInputTracksMin;  // lower bound of nb. of input tracks
+   Int_t   fNInputTracksMax;  // upper bound of nb. of input tracks
+   
+   TString fTrackBranch;       // name of branch for extra tracks in AOD out
+   TString fMCparticlesBranch; // name of branch for extra mcparticles in AOD out
+   TString fJetBranch;         // name of branch for extra jets AOD in
+
+   Int_t fFileId;   // nb. of file from the list
+   Int_t fAODEntry; // entry of extra AOD
+   Int_t fCountEvents; // count processed events in this file
+
+   Int_t fEmbedMode;
+   Int_t fEvtSelecMode;
+
+   // event selection from AOD
+   Float_t fEvtSelMinJetPt;       // minimum pt of the leading jet
+   Float_t fEvtSelMaxJetPt;       // maximum pt of the leading jet
+   Float_t fEvtSelMinJetEta;      // minimum eta of the leading jet
+   Float_t fEvtSelMaxJetEta;      // maximum eta of the leading jet
+   Float_t fEvtSelMinJetPhi;      // minimum phi of the leading jet
+   Float_t fEvtSelMaxJetPhi;      // maximum phi of the leading jet
+   
+   
+   // settings for toy "track generation"
+   Int_t    fToyMinNbOfTracks;             // minimum nb. of tracks per event
+   Int_t    fToyMaxNbOfTracks;             // maximum nb. of tracks per event
+   Float_t  fToyMinTrackPt;                // minimum track pT
+   Float_t  fToyMaxTrackPt;                // maximum track pT
+   Float_t  fToyDistributionTrackPt;       // distribution of track pt
+   Float_t  fToyMinTrackEta;               // minimum eta of tracks
+   Float_t  fToyMaxTrackEta;               // maximum eta of tracks
+   Float_t  fToyMinTrackPhi;               // minimum phi of tracks
+   Float_t  fToyMaxTrackPhi;               // maximum phi of tracks
+   UInt_t   fToyFilterMap;                 // filter map of tracks
+   UInt_t   fTrackFilterMap;               // filter map of tracks for QA plots
+   
+   Int_t         fNPtHard;      // nb. of pT hard bins
+   Double_t      fPtHard;       // pT hard
+   Int_t         fPtHardBin;    // pT hard bin
+   TClonesArray* fAODJets;      //! array of jets from aod
+   Int_t         fNevents;      // number of events in aod
+   Float_t       fXsection;     // average xsection of the event
+   Float_t       fAvgTrials;    // average number of trials per event
+
+
+   // histos
+   TList *fHistList;          //  list of histograms
+   TH1I  *fHistEvtSelection;  //! stastic of event selection
+   TProfile *fh1Xsec;         //! cross-section
+   TH1F  *fh1Trials;          //! nb. of trials (simulation)
+   TH1F  *fh1TrialsEvtSel;    //! nb. of trials (event selection, e.g. jet pT)
+   TH2F  *fh2PtHard;          //! pT hard bin
+   TH2F  *fh2PtHardEvtSel;    //! pT hard bin (event selection)
+   TH2F  *fh2PtHardTrials;     //! pT hard bin, weighted by nb. of trials
+   
+   // qa histos
+   TH1F  *fh1TrackPt;         //! track pt
+   TH2F  *fh2TrackEtaPhi;     //! track eta-phi
+   TH1F  *fh1TrackN;          //! nb. of tracks
+   TH1F  *fh1JetPt;           //! jet pt
+   TH2F  *fh2JetEtaPhi;       //! jet eta-phi
+   TH1F  *fh1JetN;            //! nb. of jets
+   TH1F  *fh1MCTrackPt;       //! MC track pt
+   TH2F  *fh2MCTrackEtaPhi;   //! MC track eta-phi
+   TH1F  *fh1MCTrackN;        //! nb. of MC tracks
+   TH1I  *fh1AODfile;         //! used AOD files from AODPathArray
+   TH2I  *fh2AODevent;        //! selected events in AODs
+   
+
+   Int_t GetJobID();    // get job id (sub-job id on the GRID)
+   Int_t SelectAODfile();
+   Int_t OpenAODfile(Int_t trial = 0);
+
+
+   ClassDef(AliAnalysisTaskFastEmbedding, 5);
+};
+
+#endif
+
diff --git a/JETAN/DEV/AliAnalysisTaskJetBackgroundSubtract.cxx b/JETAN/DEV/AliAnalysisTaskJetBackgroundSubtract.cxx
new file mode 100644 (file)
index 0000000..baf57fd
--- /dev/null
@@ -0,0 +1,727 @@
+// **************************************
+// Task used for the correction of determiantion of reconstructed jet spectra
+// Compares input (gen) and output (rec) jets   
+// *******************************************
+
+
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+#include <TROOT.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <THnSparse.h>
+#include <TSystem.h>
+#include <TInterpreter.h>
+#include <TList.h>
+#include <TLorentzVector.h>
+#include <TRefArray.h>
+#include  "TDatabasePDG.h"
+
+#include "AliAnalysisTaskJetBackgroundSubtract.h"
+#include "AliAnalysisManager.h"
+#include "AliAODHandler.h"
+#include "AliAODTrack.h"
+#include "AliAODJet.h"
+#include "AliAODEvent.h"
+#include "AliInputEventHandler.h"
+#include "AliAODJetEventBackground.h"
+
+
+ClassImp(AliAnalysisTaskJetBackgroundSubtract)
+
+AliAnalysisTaskJetBackgroundSubtract::~AliAnalysisTaskJetBackgroundSubtract(){
+  delete fJBArray;
+  delete fOutJetArrayList;
+  delete fInJetArrayList;
+}
+
+AliAnalysisTaskJetBackgroundSubtract::AliAnalysisTaskJetBackgroundSubtract(): 
+  AliAnalysisTaskSE(),
+  fAODOut(0x0),
+  fAODIn(0x0),  
+  fAODExtension(0x0),
+  fJBArray(new TObjArray()),
+  fBackgroundBranch(""),
+  fNonStdFile(""),
+  fReplaceString1("B0"),
+  fReplaceString2("B%d"),
+  fSubtraction(k4Area),
+  fKeepJets(kFALSE),
+  fInJetArrayList(0x0),
+  fOutJetArrayList(0x0),
+  fh2CentvsRho(0x0),
+  fh2CentvsSigma(0x0),
+  fh2MultvsRho(0x0),
+  fh2MultvsSigma(0x0),
+  fh2ShiftEta(0x0),
+  fh2ShiftPhi(0x0),
+  fh2ShiftEtaLeading(0x0),
+  fh2ShiftPhiLeading(0x0),
+  fHistList(0x0)  
+{
+
+}
+
+AliAnalysisTaskJetBackgroundSubtract::AliAnalysisTaskJetBackgroundSubtract(const char* name):
+
+  AliAnalysisTaskSE(name),
+  fAODOut(0x0),
+  fAODIn(0x0),  
+  fAODExtension(0x0),
+  fJBArray(new TObjArray()),
+  fBackgroundBranch(""),
+  fNonStdFile(""),
+  fReplaceString1("B0"),
+  fReplaceString2("B%d"),
+  fSubtraction(k4Area),
+  fKeepJets(kFALSE),
+  fInJetArrayList(0x0),
+  fOutJetArrayList(0x0),
+  fh2CentvsRho(0x0),
+  fh2CentvsSigma(0x0),
+  fh2MultvsRho(0x0),
+  fh2MultvsSigma(0x0),
+  fh2ShiftEta(0x0),
+  fh2ShiftPhi(0x0),
+  fh2ShiftEtaLeading(0x0),
+  fh2ShiftPhiLeading(0x0),
+  fHistList(0x0)  
+{
+ DefineOutput(1, TList::Class());  
+}
+
+
+
+Bool_t AliAnalysisTaskJetBackgroundSubtract::Notify()
+{
+  //
+  fAODIn = dynamic_cast<AliAODEvent*>(InputEvent());
+
+  ResetOutJets();
+
+  // Now we also have the Input Event Available! Fillvthe pointers in the list
+
+  fInJetArrayList->Clear();
+  fOutJetArrayList->Clear();
+
+  for(int iJB = 0;iJB<fJBArray->GetEntries();iJB++){
+    TObjString *ostr = (TObjString*)fJBArray->At(iJB);
+  
+    TClonesArray* jarray = 0;      
+    if(!jarray&&fAODOut){
+      jarray = (TClonesArray*)(fAODOut->FindListObject(ostr->GetString().Data()));
+    }
+    if(!jarray&&fAODExtension){
+      jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(ostr->GetString().Data()));
+    }
+    if(!jarray&&fAODIn){
+      jarray = (TClonesArray*)(fAODIn->FindListObject(ostr->GetString().Data()));
+    }
+
+    if(!jarray){
+      if(fDebug){
+       Printf("%s:%d Input jet branch %s not found",(char*)__FILE__,__LINE__,ostr->GetString().Data());
+      }
+      continue;
+    }
+    
+    TString newName(ostr->GetString().Data());
+    newName.ReplaceAll(fReplaceString1.Data(),Form(fReplaceString2.Data(),fSubtraction));
+    TClonesArray* jarrayOut = 0;      
+    if(newName.CompareTo(ostr->GetString())==0){
+      Printf("%s:%d Input and output branch would have the same name, skipping %s ",(char*)__FILE__,__LINE__,ostr->GetString().Data());
+      continue;
+    }
+
+    if(!jarrayOut&&fAODOut){
+      jarrayOut = (TClonesArray*)(fAODOut->FindListObject(newName.Data()));
+    }
+    if(!jarrayOut&&fAODExtension){
+      jarrayOut = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(newName.Data()));
+    }
+
+    if(!jarrayOut){
+      if(fDebug){
+       Printf("%s:%d Output jet branch %s not found",(char*)__FILE__,__LINE__,newName.Data());
+       PrintAODContents();
+      }
+      continue;
+    }
+    if(jarrayOut&&jarray){
+      fOutJetArrayList->Add(jarrayOut);
+      fInJetArrayList->Add(jarray);
+    }
+  }
+  return kTRUE;
+}
+
+void AliAnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects()
+{
+
+  //
+  // Create the output container
+  //
+  // Connect the AOD
+
+  if (fDebug > 1) printf("AnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects() \n");
+
+
+
+  if(fNonStdFile.Length()!=0){
+    
+    // case that we have an AOD extension we need to fetch the jets from the extended output
+    // we identifay the extension aod event by looking for the branchname
+    AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
+
+    fAODExtension = (aodH?aodH->GetExtension(fNonStdFile.Data()):0);
+    
+    if(!fAODExtension){
+      if(fDebug>1)Printf("AODExtension found for %s",fNonStdFile.Data());
+    }
+  }
+  fAODOut = AODEvent();
+
+  // usually we do not have the input already here
+
+  if(!fInJetArrayList)fInJetArrayList =new TList();
+  if(!fOutJetArrayList)fOutJetArrayList =new TList();
+
+  for(int iJB = 0;iJB<fJBArray->GetEntries();iJB++){
+    TObjString *ostr = (TObjString*)fJBArray->At(iJB);
+    TString newName(ostr->GetString().Data());
+    if(!newName.Contains(fReplaceString1.Data())){
+      Printf("%s:%d cannot replace string %s in %s",(char*)__FILE__,__LINE__,fReplaceString1.Data(),
+            newName.Data());
+      continue;
+    }
+
+
+    // add a new branch to the output for the background subtracted jets take the names from
+    // the input jets and replace the background flag names
+    TClonesArray *tca = new TClonesArray("AliAODJet", 0);
+    newName.ReplaceAll(fReplaceString1.Data(),Form(fReplaceString2.Data(),fSubtraction));
+    if(newName.CompareTo(ostr->GetString())==0){
+      Printf("%s:%d Input and output branch would have the same name, skipping: %s ",(char*)__FILE__,__LINE__,ostr->GetString().Data());
+      continue;
+    }
+
+    if(fDebug){
+      Printf("%s:%d created branch \n %s from \n %s",(char*)__FILE__,__LINE__,newName.Data(),
+            ostr->GetString().Data());
+    }
+    tca->SetName(newName.Data());
+    AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
+  }
+  
+
+  if(!fHistList)fHistList = new TList();
+  fHistList->SetOwner();
+  PostData(1, fHistList); // post data in any case once
+
+  // 
+  
+  // delta pT vs. area vs. cent vs. mult
+  const Int_t nSparseBinsDelta = 4;
+  const Int_t nBinsDelta[nSparseBinsDelta] =   {   241,  10,  10,  25}; 
+  const Double_t xminDelta[nSparseBinsDelta] = {-120.5,   0,   0,   0};
+  const Double_t xmaxDelta[nSparseBinsDelta] = { 120.5, 1.0, 100,5000};
+  for(int iJB = 0;iJB<fJBArray->GetEntries();iJB++){
+    TObjString *ostr = (TObjString*)fJBArray->At(iJB);
+    TString oldName(ostr->GetString().Data()); 
+    TString newName(ostr->GetString().Data()); 
+    if(!newName.Contains(fReplaceString1.Data())){
+      Printf("%s:%d cannot replace string %s in %s",(char*)__FILE__,__LINE__,fReplaceString1.Data(),
+            newName.Data());
+      continue;
+    }
+    newName.ReplaceAll(fReplaceString1.Data(),Form(fReplaceString2.Data(),fSubtraction));
+    
+    TH2F *hTmp = new TH2F(Form("h2PtInPtOut_%d",iJB),Form(";%s p_{T}; %s p_{T}",oldName.Data(),newName.Data()),200,0,200.,400,-200.,200.);
+    fHistList->Add(hTmp);
+    THnSparseF *hFTmp = new THnSparseF(Form("hnDPtAreaCentMult_%d",iJB),Form("%s delta;#delta p_{T};Area;cent;mult",newName.Data()),nSparseBinsDelta,nBinsDelta,xminDelta,xmaxDelta);
+    fHistList->Add(hFTmp);
+  }
+
+  Bool_t oldStatus = TH1::AddDirectoryStatus();
+  TH1::AddDirectory(kFALSE);
+
+  //
+  //  Histogram booking, add som control histograms here
+  //    
+
+    fh2CentvsRho = new TH2F("fh2CentvsRho","centrality vs background density", 100,0.,100.,600,0.,300.);
+    fh2CentvsSigma = new TH2F("fh2CentvsSigma","centrality vs backgroun sigma",100,0.,100.,500,0.,50.);
+    fHistList->Add(fh2CentvsRho);
+    fHistList->Add(fh2CentvsSigma);
+
+    fh2MultvsRho = new TH2F("fh2MultvsRho","mult vs background density", 100,0.,5000.,600,0.,300.);
+    fh2MultvsSigma = new TH2F("fh2MultvsSigma","mult vs background sigma",100,0.,5000.,500,0.,50.);
+    fHistList->Add(fh2MultvsRho);
+    fHistList->Add(fh2MultvsSigma);
+
+   if(fSubtraction==k4Area){
+    fh2ShiftEta = new TH2F("fh2ShiftEta","extended correction Eta",100,-0.9,0.9,100,-0.9,0.9);
+    fh2ShiftPhi = new TH2F("fh2ShiftPhi","extended correction Phi",100,0.,6.5,100,0.,6.5);
+    fh2ShiftEtaLeading = new TH2F("fh2ShiftEtaLeading","extended correction Eta",100,-0.9,0.9,100,-0.9,0.9);
+    fh2ShiftPhiLeading = new TH2F("fh2ShiftPhiLeading","extended correction Phi",100,0.,6.5,100,0.,6.5);
+     fHistList->Add(fh2ShiftEta);
+     fHistList->Add(fh2ShiftPhi);
+     fHistList->Add(fh2ShiftEtaLeading);
+     fHistList->Add(fh2ShiftPhiLeading);
+   }
+    
+  // =========== Switch on Sumw2 for all histos ===========
+  for (Int_t i=0; i<fHistList->GetEntries(); ++i) {
+    TH1 *h1 = dynamic_cast<TH1*>(fHistList->At(i));
+    if (h1){
+      h1->Sumw2();
+      continue;
+    }
+    THnSparse *hn = dynamic_cast<THnSparse*>(fHistList->At(i));
+    if(hn)hn->Sumw2();
+  }
+  TH1::AddDirectory(oldStatus);
+
+  if(fBackgroundBranch.Length()==0)
+    AliError(Form("%s:%d No BackgroundBranch defined",(char*)__FILE__,__LINE__));
+  if(fJBArray->GetEntries()==0)
+    AliError(Form("%s:%d No Jet Branches defined defined",(char*)__FILE__,__LINE__));
+}
+
+void AliAnalysisTaskJetBackgroundSubtract::Init()
+{
+  //
+  // Initialization
+  //
+  if (fDebug > 1) printf("AnalysisTaskJetBackgroundSubtract::Init() \n");
+}
+
+void AliAnalysisTaskJetBackgroundSubtract::UserExec(Option_t */*option*/)
+{
+
+  if (fDebug > 1) printf("AnalysisTaskJetBackgroundSubtract::UserExec() \n");
+  ResetOutJets();
+  if(fBackgroundBranch.Length()==0||fJBArray->GetEntries()==0){
+    if(fDebug)Printf("%s:%d No background subtraction done",(char*)__FILE__,__LINE__);
+    PostData(1,fHistList);
+  }
+  if(fJBArray->GetEntries()!=fInJetArrayList->GetEntries()){
+    if(fDebug)Printf("%s:%d different Array  sizes %d %d %d",(char*)__FILE__,__LINE__,fJBArray->GetEntries(),fInJetArrayList->GetEntries(),fOutJetArrayList->GetEntries());
+    PostData(1,fHistList);
+  }
+
+
+
+  AliAODJetEventBackground*  evBkg = 0;
+  TClonesArray*              bkgClusters = 0;
+  TClonesArray*              bkgClustersRC = 0;
+  TString bkgClusterName(fBackgroundBranch.Data());
+  bkgClusterName.ReplaceAll(Form("%s_",AliAODJetEventBackground::StdBranchName()),"");
+  TString bkgClusterRCName(Form("%s%s",bkgClusterName.Data(),"RandomCone")); 
+
+  if(!evBkg&&!bkgClusters&&!bkgClustersRC&&fAODOut){
+    evBkg = (AliAODJetEventBackground*)(fAODOut->FindListObject(fBackgroundBranch.Data()));
+    bkgClusters = (TClonesArray*)(fAODOut->FindListObject(bkgClusterName.Data()));
+    bkgClustersRC = (TClonesArray*)(fAODOut->FindListObject(bkgClusterRCName.Data()));
+
+    if(fDebug&&bkgClusters)Printf("%s:%d Background cluster branch %s found",(char*)__FILE__,__LINE__,bkgClusterName.Data());
+    if(fDebug&&bkgClustersRC)Printf("%s:%d Background cluster RC branch %s found",(char*)__FILE__,__LINE__,bkgClusterRCName.Data());
+    if(fDebug&&evBkg)Printf("%s:%d Backgroundbranch %s found",(char*)__FILE__,__LINE__,fBackgroundBranch.Data());
+  }
+  if(!evBkg&&!bkgClusters&&!bkgClustersRC&&fAODExtension){
+    evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(fBackgroundBranch.Data()));
+    bkgClusters = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(bkgClusterName.Data()));
+    bkgClustersRC = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(bkgClusterRCName.Data()));
+    if(fDebug&&bkgClusters)Printf("%s:%d Background cluster branch %s found",(char*)__FILE__,__LINE__,bkgClusterName.Data());
+    if(fDebug&&bkgClustersRC)Printf("%s:%d Background cluster RC branch %s found",(char*)__FILE__,__LINE__,bkgClusterRCName.Data());
+
+    if(fDebug&&evBkg)Printf("%s:%d Backgroundbranch %s found",(char*)__FILE__,__LINE__,fBackgroundBranch.Data());
+  }
+
+  if(!evBkg&&!bkgClusters&&!bkgClustersRC&&fAODIn){
+    evBkg = (AliAODJetEventBackground*)(fAODIn->FindListObject(fBackgroundBranch.Data()));
+    bkgClusters = (TClonesArray*)(fAODIn->FindListObject(bkgClusterName.Data()));
+    bkgClustersRC = (TClonesArray*)(fAODIn->FindListObject(bkgClusterRCName.Data()));
+
+    if(fDebug&&bkgClusters)Printf("%s:%d Background cluster branch %s found",(char*)__FILE__,__LINE__,bkgClusterName.Data());
+    if(fDebug&&bkgClustersRC)Printf("%s:%d Background cluster RC branch %s found",(char*)__FILE__,__LINE__,bkgClusterRCName.Data());
+    if(fDebug&&evBkg)Printf("%s:%d Backgroundbranch %s found",(char*)__FILE__,__LINE__,fBackgroundBranch.Data());
+  }
+
+  if(!evBkg&&(fSubtraction==kArea||fSubtraction==kRhoRecalc||fSubtraction==k4Area)){
+    if(fDebug){
+      Printf("%s:%d Backgroundbranch %s not found",(char*)__FILE__,__LINE__,fBackgroundBranch.Data());
+      PrintAODContents();
+    }
+    PostData(1,fHistList);
+    return;
+  }
+
+  if(!bkgClusters&&(fSubtraction==kRhoRecalc)){
+    if(fDebug){
+      Printf("%s:%d Background cluster branch %s not found",(char*)__FILE__,__LINE__,bkgClusterName.Data());
+      PrintAODContents();
+    }
+    PostData(1,fHistList);
+    return;
+  }
+
+  if(!bkgClustersRC&&(fSubtraction==kRhoRC)){
+    if(fDebug){
+      Printf("%s:%d Background cluster RC branch %s not found",(char*)__FILE__,__LINE__,bkgClusterRCName.Data());
+      PrintAODContents();
+    }
+    PostData(1,fHistList);
+    return;
+  }
+  // LOOP over all jet branches and subtract the background
+
+   Float_t rho = 0;
+   Float_t sigma=0.;
+   Double_t meanarea = 0;
+   TLorentzVector backgroundv;
+   Float_t cent=0.;
+   
+   if(fAODOut)cent = fAODOut->GetHeader()->GetCentrality();
+   if(fAODIn) cent = fAODIn->GetHeader()->GetCentrality();
+
+   if(evBkg)sigma=evBkg->GetSigma(1); 
+
+   if(fSubtraction==kArea) rho = evBkg->GetBackground(1);
+   if(fSubtraction==k4Area){
+     rho = evBkg->GetBackground(0);
+     sigma=evBkg->GetSigma(0);
+   }
+
+   if(fSubtraction==kRhoRecalc){
+     meanarea=evBkg->GetMeanarea(1);
+     rho =RecalcRho(bkgClusters,meanarea);
+   }
+   if(fSubtraction==kRhoRC) rho=RhoRC(bkgClustersRC);
+
+   Float_t mult = 0;
+   for(int iJB = 0;iJB<fInJetArrayList->GetEntries();iJB++){
+    TClonesArray* jarray = (TClonesArray*)fInJetArrayList->At(iJB);
+    if(jarray){
+      TString tmp(jarray->GetName());
+      if(tmp.Contains("cluster")){
+       mult = MultFromJetRefs(jarray);
+       if(mult>0)break;
+      }
+    }
+   }
+
+   fh2CentvsRho->Fill(cent,rho);
+   fh2CentvsSigma->Fill(cent,sigma);
+
+   fh2MultvsRho->Fill(mult,rho);
+   fh2MultvsSigma->Fill(mult,sigma);
+   
+   for(int iJB = 0;iJB<fInJetArrayList->GetEntries();iJB++){
+    TClonesArray* jarray = (TClonesArray*)fInJetArrayList->At(iJB);
+    TClonesArray* jarrayOut = (TClonesArray*)fOutJetArrayList->At(iJB);
+    
+    if(!jarray||!jarrayOut){
+      Printf("%s:%d Array not found %d: %p %p",(char*)__FILE__,__LINE__,iJB,jarray,jarrayOut);
+      continue;
+    }
+    TH2F* h2PtInOut = (TH2F*)fHistList->FindObject(Form("h2PtInPtOut_%d",iJB));
+    THnSparseF* hnDPtAreaCentMult = (THnSparseF*)fHistList->FindObject(Form("hnDPtAreaCentMult_%d",iJB));
+    // loop over all jets
+    Int_t nOut = 0;
+      
+    Double_t deltaPt[4];
+    deltaPt[2] = cent;
+    deltaPt[3] = mult;
+
+    for(int i = 0;i < jarray->GetEntriesFast();i++){
+      AliAODJet *jet = (AliAODJet*)jarray->At(i);
+      AliAODJet tmpNewJet(*jet);
+      Bool_t bAdd = false;
+      Float_t ptSub = 0;
+
+
+      if(fSubtraction==kArea){ 
+       Double_t background = rho * jet->EffectiveAreaCharged();
+       ptSub = jet->Pt() - background; 
+       if(fDebug>2){
+         Printf("%s:%d Jet %d %3.3f %3.3f",(char*)__FILE__,__LINE__,i,jet->Pt(),ptSub);
+       }
+       if(ptSub<=0){
+         // optionally rescale it and keep??
+         if(fKeepJets){
+            bAdd = RescaleJetMomentum(&tmpNewJet,0.1);
+         }
+         else{
+           bAdd = false;
+         }
+       }
+       else{
+         bAdd = RescaleJetMomentum(&tmpNewJet,ptSub);
+       }
+       // add background estimates to the new jet object
+       // allows to recover old p_T and rho...
+       tmpNewJet.SetBgEnergy(background,0);
+       tmpNewJet.SetPtSubtracted(ptSub,0);
+      }// kAREA
+      else if(fSubtraction==kRhoRecalc){
+       Double_t background = rho * jet->EffectiveAreaCharged();
+       ptSub = jet->Pt() - background; 
+        if(fDebug>2){
+         Printf("%s:%d Jet %d %3.3f %3.3f %3.3f %3.3f",(char*)__FILE__,__LINE__,i,jet->Pt(),ptSub,background,rho);}
+       if(ptSub<=0){
+         // optionally rescale it and keep
+         if(fKeepJets){
+            bAdd = RescaleJetMomentum(&tmpNewJet,0.1);
+         }
+         else{
+           bAdd = false;
+         }
+       }
+       else{
+         bAdd = RescaleJetMomentum(&tmpNewJet,ptSub);
+       }
+       // add background estimates to the new jet object
+       // allows to recover old p_T and rho...
+       tmpNewJet.SetBgEnergy(background,0);
+       tmpNewJet.SetPtSubtracted(ptSub,0);
+      }//kRhoRecalc
+       else if(fSubtraction==kRhoRC){
+       Double_t background = rho * jet->EffectiveAreaCharged();
+       ptSub = jet->Pt() - background; 
+       if(fDebug>2){   Printf("%s:%d Jet %d %3.3f %3.3f %3.3f %3.3f",(char*)__FILE__,__LINE__,i,jet->Pt(),ptSub,background,rho);}
+       if(ptSub<=0){
+         if(fKeepJets){
+            bAdd = RescaleJetMomentum(&tmpNewJet,0.1);
+         }
+         else{
+           bAdd = false;
+         }
+       }
+       else{
+         bAdd = RescaleJetMomentum(&tmpNewJet,ptSub);
+       }
+       // add background estimates to the new jet object
+       // allows to recover old p_T and rho...
+       tmpNewJet.SetBgEnergy(background,0);
+       tmpNewJet.SetPtSubtracted(ptSub,0);
+       }//kRhoRC
+
+       else if(fSubtraction==k4Area&&jet->VectorAreaCharged()){
+        backgroundv.SetPxPyPzE(rho*(jet->VectorAreaCharged())->Px(),rho*(jet->VectorAreaCharged())->Py(),rho*(jet->VectorAreaCharged())->Pz(),rho*(jet->VectorAreaCharged())->E());
+        ptSub = jet->Pt()-backgroundv.Pt();
+        if((backgroundv.E()>=jet->E())||(backgroundv.Pt()>=jet->Pt())){
+          if(fKeepJets){
+            bAdd =  RescaleJetMomentum(&tmpNewJet,0.1);
+          }
+          else{
+            bAdd = false;
+          }
+        }
+        else{
+          bAdd = RescaleJet4vector(&tmpNewJet,backgroundv);
+        }
+        // add background estimates to the new jet object
+        // allows to recover old p_T and rho...
+        tmpNewJet.SetBgEnergy(backgroundv.Pt(),0);
+        tmpNewJet.SetPtSubtracted(ptSub,0);
+        
+       }//kArea4vector  
+
+      if(bAdd){
+        AliAODJet *newJet = new ((*jarrayOut)[nOut++]) AliAODJet(tmpNewJet);
+       // what about track references, clear for now...
+       if(fSubtraction==k4Area){
+         fh2ShiftEta->Fill(jet->Eta(),newJet->Eta());
+         fh2ShiftPhi->Fill(jet->Phi(),newJet->Phi());
+         if(i==0){fh2ShiftEtaLeading->Fill(jet->Eta(),newJet->Eta());
+          fh2ShiftPhiLeading->Fill(jet->Phi(),newJet->Phi());}}
+
+       // set the references 
+       newJet->GetRefTracks()->Clear();
+       TRefArray *refs = jet->GetRefTracks();
+       for(Int_t ir=0;ir<refs->GetEntriesFast();ir++){
+         AliVParticle *vp = dynamic_cast<AliVParticle*>(refs->At(ir));
+         if(vp)newJet->AddTrack(vp);
+       }
+      }
+      if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
+      if(hnDPtAreaCentMult){
+       deltaPt[0] = ptSub;
+       deltaPt[1] = jet->EffectiveAreaCharged();
+       hnDPtAreaCentMult->Fill(deltaPt);
+      }
+    }
+    if(jarrayOut)jarrayOut->Sort();
+   }
+   
+   PostData(1, fHistList);
+}
+
+void AliAnalysisTaskJetBackgroundSubtract::Terminate(Option_t */*option*/)
+{
+  // Terminate analysis
+  //
+  if (fDebug > 1) printf("AnalysisJetBackgroundSubtract: Terminate() \n");
+}
+
+Bool_t AliAnalysisTaskJetBackgroundSubtract::RescaleJetMomentum(AliAODJet *jet,Float_t pT){
+  // keep the direction and the jet mass
+  if(pT<=0)return kFALSE;
+  Double_t pTold = jet->Pt();
+  Double_t scale  = pT/pTold;
+  Double_t mass  = jet->M();
+  Double_t pNew = jet->P() * scale;
+  jet->SetPxPyPzE(scale*jet->Px(),scale*jet->Py(),scale*jet->Pz(),TMath::Sqrt(mass*mass+pNew*pNew));
+
+
+  return kTRUE;
+}
+
+Bool_t AliAnalysisTaskJetBackgroundSubtract::RescaleJet4vector(AliAODJet *jet,TLorentzVector backgroundv){
+  
+  if(backgroundv.Pt()<0.) return kFALSE;
+  jet->SetPxPyPzE(jet->Px()-backgroundv.Px(),jet->Py()-backgroundv.Py(),jet->Pz()-backgroundv.Pz(),jet->E()-backgroundv.E());
+ return kTRUE;
+}
+
+
+
+
+
+
+
+
+Double_t AliAnalysisTaskJetBackgroundSubtract::RecalcRho(TClonesArray* bkgClusters,Double_t meanarea){
+  
+  Double_t ptarea=0.;
+  Int_t count=0;
+  Double_t rho=0.; 
+  const Double_t Rlimit2=0.8*0.8;  //2*jet radius.
+  TClonesArray* jarray=0;
+  
+  for(int iJB = 0;iJB<fInJetArrayList->GetEntries();iJB++){
+    TObjString *ostr = (TObjString*)fInJetArrayList->At(iJB);
+    TString jetref=ostr->GetString().Data();
+    if(jetref.Contains("ANTIKT04")){ 
+      jarray = (TClonesArray*)fInJetArrayList->At(iJB);
+    }
+  }
+  if(!jarray)return rho;
+  if(jarray->GetEntries()>=2){ 
+    AliAODJet *first = (AliAODJet*)(jarray->At(0)); 
+    AliAODJet *second= (AliAODJet*)(jarray->At(1)); 
+    for(Int_t k=0;k<bkgClusters->GetEntriesFast();k++){
+      AliAODJet *clus = (AliAODJet*)(bkgClusters->At(k));
+      if(TMath::Abs(clus->Eta())>0.5) continue;
+      if((clus->EffectiveAreaCharged())<0.1*meanarea) continue; 
+      Double_t distance1=(first->Eta()-clus->Eta())*(first->Eta()-clus->Eta())+
+       (first->Phi()-clus->Phi())*(first->Phi()-clus->Phi());
+      Double_t distance2= (second->Eta()-clus->Eta())*(second->Eta()-clus->Eta())+
+       (second->Phi()-clus->Phi())*(second->Phi()-clus->Phi());
+      if((distance1<Rlimit2)||(distance2<Rlimit2)) continue;    
+      ptarea=ptarea+clus->Pt()/clus->EffectiveAreaCharged(); 
+      count=count+1;}
+    if(count!=0) rho=ptarea/count; 
+  }        
+  return rho;
+}
+
+   Double_t AliAnalysisTaskJetBackgroundSubtract::RhoRC(TClonesArray* bkgClustersRC){
+  
+       Double_t ptarea=0.;
+       Int_t count=0;
+       Double_t rho=0.; 
+       const Double_t Rlimit2=0.8*0.8;  //2*jet radius.
+       TClonesArray* jarray=0;
+        for(int iJB = 0;iJB<fInJetArrayList->GetEntries();iJB++){
+         TObjString *ostr = (TObjString*)fInJetArrayList->At(iJB);
+         TString jetref=ostr->GetString().Data();
+         if(jetref.Contains("ANTIKT04")){ 
+           jarray = (TClonesArray*)fInJetArrayList->At(iJB);
+         }
+       }
+       if(!jarray)return rho;
+
+         if(jarray->GetEntries()>=2){ 
+          AliAODJet *first = (AliAODJet*)(jarray->At(0)); 
+          AliAODJet *second=(AliAODJet*)(jarray->At(1)); 
+         for(Int_t k=0;k<bkgClustersRC->GetEntriesFast();k++){
+          AliAODJet *clus = (AliAODJet*)(bkgClustersRC->At(k));
+          if(TMath::Abs(clus->Eta())>0.5) continue;
+          Double_t distance1=(first->Eta()-clus->Eta())*(first->Eta()-clus->Eta())+
+            (first->Phi()-clus->Phi())*(first->Phi()-clus->Phi());
+          Double_t distance2= (second->Eta()-clus->Eta())*(second->Eta()-clus->Eta())+
+            (second->Phi()-clus->Phi())*(second->Phi()-clus->Phi());
+          if((distance1<Rlimit2)||(distance2<Rlimit2)) continue;    
+          ptarea=ptarea+clus->Pt()/clus->EffectiveAreaCharged(); 
+          count=count+1;}
+         if(count!=0) rho=ptarea/count;  }
+         return rho;
+}
+
+
+
+
+
+
+
+
+
+void AliAnalysisTaskJetBackgroundSubtract::ResetOutJets(){
+  if(!fOutJetArrayList)return;
+  for(int iJB = 0;iJB<fOutJetArrayList->GetEntries();iJB++){
+    TClonesArray* jarray = (TClonesArray*)fOutJetArrayList->At(iJB);
+    if(jarray)jarray->Delete();
+  }
+}
+
+
+void AliAnalysisTaskJetBackgroundSubtract::PrintAODContents(){
+  if(fAODIn){
+    Printf("%s:%d >>>>>> Input",(char*)__FILE__,__LINE__);
+    fAODIn->Print();
+  }
+  if(fAODExtension){
+    Printf("%s:%d >>>>>> Extenstion",(char*)__FILE__,__LINE__);
+    fAODExtension->GetAOD()->Print();
+  }
+  if(fAODOut){
+    Printf("%s:%d >>>>>> Output",(char*)__FILE__,__LINE__);
+    fAODOut->Print();
+  }
+}
+
+Int_t AliAnalysisTaskJetBackgroundSubtract::MultFromJetRefs(TClonesArray* jets){
+  if(!jets)return 0;
+
+  Int_t refMult = 0;
+  for(int ij = 0;ij < jets->GetEntries();++ij){
+    AliAODJet* jet = (AliAODJet*)jets->At(ij);
+    if(!jet)continue;
+    TRefArray *refs = jet->GetRefTracks();
+    if(!refs)continue;
+    refMult += refs->GetEntries();
+  }
+  return refMult;
+
+}
diff --git a/JETAN/DEV/AliAnalysisTaskJetBackgroundSubtract.h b/JETAN/DEV/AliAnalysisTaskJetBackgroundSubtract.h
new file mode 100644 (file)
index 0000000..9f0e0a1
--- /dev/null
@@ -0,0 +1,106 @@
+#ifndef ALIANALYSISTASKJETBACKGROUNDSUBTRACT_H
+#define ALIANALYSISTASKJETBACKGROUNDSUBTRACT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// **************************************
+// task used for background subtration of all jets found with clustering algos
+// *******************************************
+
+#include  "AliAnalysisTaskSE.h"
+#include  "TObjString.h"
+#include  "TString.h"
+#include  "TObjArray.h"
+
+
+////////////////
+class AliJetHeader;
+class AliESDEvent;
+class AliAODEvent;
+class AliAODExtension;
+class AliAODJet;
+class AliAODJetEventBackground;
+class AliJetFinder;
+class TList;
+class TChain;
+class TH2F;
+class TH1F;
+class TH3F;
+class TProfile;
+class TRandom3;
+class TRefArray;
+
+
+class AliAnalysisTaskJetBackgroundSubtract : public AliAnalysisTaskSE
+{
+ public:
+    AliAnalysisTaskJetBackgroundSubtract();
+    AliAnalysisTaskJetBackgroundSubtract(const char* name);
+    virtual ~AliAnalysisTaskJetBackgroundSubtract();
+    // Implementation of interface methods
+    virtual void UserCreateOutputObjects();
+    virtual void Init();
+    virtual void LocalInit() { Init(); }
+    virtual void UserExec(Option_t *option);
+    virtual void Terminate(Option_t *option);
+    virtual Bool_t Notify();
+
+    // Task specific methods...
+    virtual void   AddJetBranch(const char* c){fJBArray->Add(new TObjString(c));}
+    virtual void   SetSubtractionMethod(Int_t i){fSubtraction = i;}
+    virtual Int_t  GetSubtractionMethod(){return fSubtraction;}
+    virtual void   SetKeepJets(Bool_t b = kTRUE){fKeepJets = b;}
+    virtual void   SetBackgroundBranch(char* c){fBackgroundBranch = c;}  
+    virtual void   SetNonStdOutputFile(char* c){fNonStdFile = c;}  
+    virtual void   SetToReplace(char* c){fReplaceString1 = c;}  
+    const char*    GetToReplace(){return fReplaceString1.Data();}  
+    virtual void   SetReplacementMask(char* c){fReplaceString2 = c;}  
+    const char*    GetReplacementMask(){return fReplaceString2.Data();}  
+   
+    enum {kNoSubtract = 0,kArea,k4Area,kRhoRecalc,kRhoRC};
+ private:
+
+    
+
+    AliAnalysisTaskJetBackgroundSubtract(const AliAnalysisTaskJetBackgroundSubtract&);
+    AliAnalysisTaskJetBackgroundSubtract& operator=(const AliAnalysisTaskJetBackgroundSubtract&);
+    Bool_t RescaleJetMomentum(AliAODJet *jet,Float_t pT);
+    Bool_t RescaleJet4vector(AliAODJet *jet,TLorentzVector backgroundv);
+    Int_t  MultFromJetRefs(TClonesArray* jets);
+    Double_t RecalcRho(TClonesArray* fbkgclusters,Double_t meanarea);
+    Double_t RhoRC(TClonesArray* fbkgclustersRC);
+    void ResetOutJets();
+    void PrintAODContents();
+
+    AliAODEvent     *fAODOut;                // ! where we take the jets from and they are modified
+    AliAODEvent     *fAODIn;                 // ! where we may take the background from, only in case we do not find it in the output
+    AliAODExtension *fAODExtension;          // ! where we take the jets from can be input or output AOD
+    TObjArray       *fJBArray;               // Array that stores the name of all jet branches to be subtracted   
+    TString         fBackgroundBranch;       // name of the branch used for background subtraction
+    //
+    TString         fNonStdFile;        // The optional name of the output file the non-std brnach is written to
+    TString         fReplaceString1;     // To construct the new output name  
+    TString         fReplaceString2;     // To construct the new output name   
+    Int_t           fSubtraction;       // Parameter for subtraction mode 
+    Bool_t          fKeepJets;          // keeps the jets with negative p_t rescaled to 0.1 GeV
+    TList *fInJetArrayList; //! transient list to make ease the handling of input jets
+    TList *fOutJetArrayList; //! transient list to make ease the reset of output jets
+
+    TH2F*         fh2CentvsRho;   //! centrality vs background density  
+    TH2F*         fh2CentvsSigma;   //! centrality vs background sigma  
+    TH2F*         fh2MultvsRho;   //! centrality vs background density  
+    TH2F*         fh2MultvsSigma;   //! centrality vs background sigma  
+    TH2F*         fh2ShiftEta;   //! extended correction Eta
+    TH2F*         fh2ShiftPhi;   //! extended correction Phi
+    TH2F*         fh2ShiftEtaLeading;   //! extended correction Eta leading jet
+    TH2F*         fh2ShiftPhiLeading;   //! extended correction Phi leading jet
+
+    TList *fHistList; //! the histograms output list
+   
+    ClassDef(AliAnalysisTaskJetBackgroundSubtract, 6) 
+};
+#endif
diff --git a/JETAN/DEV/AliAnalysisTaskJetCluster.cxx b/JETAN/DEV/AliAnalysisTaskJetCluster.cxx
new file mode 100644 (file)
index 0000000..1b27611
--- /dev/null
@@ -0,0 +1,1490 @@
+// **************************************
+// Task used for the correction of determiantion of reconstructed jet spectra
+// Compares input (gen) and output (rec) jets   
+// *******************************************
+
+
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+#include <TROOT.h>
+#include <TRandom3.h>
+#include <TSystem.h>
+#include <TInterpreter.h>
+#include <TChain.h>
+#include <TRefArray.h>
+#include <TFile.h>
+#include <TKey.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TH3F.h>
+#include <TProfile.h>
+#include <TList.h>
+#include <TLorentzVector.h>
+#include <TClonesArray.h>
+#include  "TDatabasePDG.h"
+
+#include "AliAnalysisTaskJetCluster.h"
+#include "AliAnalysisManager.h"
+#include "AliJetFinder.h"
+#include "AliJetHeader.h"
+#include "AliJetReader.h"
+#include "AliESDEvent.h"
+#include "AliAODEvent.h"
+#include "AliAODHandler.h"
+#include "AliAODExtension.h"
+#include "AliAODTrack.h"
+#include "AliAODJet.h"
+#include "AliAODMCParticle.h"
+#include "AliMCEventHandler.h"
+#include "AliMCEvent.h"
+#include "AliStack.h"
+#include "AliGenPythiaEventHeader.h"
+#include "AliJetKineReaderHeader.h"
+#include "AliGenCocktailEventHeader.h"
+#include "AliInputEventHandler.h"
+#include "AliAODJetEventBackground.h"
+
+#include "fastjet/PseudoJet.hh"
+#include "fastjet/ClusterSequenceArea.hh"
+#include "fastjet/AreaDefinition.hh"
+#include "fastjet/JetDefinition.hh"
+// get info on how fastjet was configured
+#include "fastjet/config.h"
+
+
+ClassImp(AliAnalysisTaskJetCluster)
+
+AliAnalysisTaskJetCluster::~AliAnalysisTaskJetCluster(){
+  delete fRef;
+  delete fRandom;
+
+  if(fTCAJetsOut)fTCAJetsOut->Delete();
+  delete fTCAJetsOut;
+  if(fTCAJetsOutRan)fTCAJetsOutRan->Delete();
+  delete fTCAJetsOutRan;
+  if(fTCARandomConesOut)fTCARandomConesOut->Delete();
+  delete fTCARandomConesOut;
+  if(fTCARandomConesOutRan)fTCARandomConesOutRan->Delete();
+  delete fTCARandomConesOutRan;
+  if(fAODJetBackgroundOut)fAODJetBackgroundOut->Reset();
+  delete fAODJetBackgroundOut;
+}
+
+AliAnalysisTaskJetCluster::AliAnalysisTaskJetCluster(): 
+  AliAnalysisTaskSE(),
+  fAOD(0x0),
+  fAODExtension(0x0),
+  fRef(new TRefArray),
+  fUseAODTrackInput(kFALSE),
+  fUseAODMCInput(kFALSE),
+  fUseBackgroundCalc(kFALSE),
+  fEventSelection(kFALSE),     
+  fFilterMask(0),
+  fFilterType(0),
+  fJetTypes(kJet),
+  fTrackTypeRec(kTrackUndef),
+  fTrackTypeGen(kTrackUndef),  
+  fNSkipLeadingRan(0),
+  fNSkipLeadingCone(0),
+  fNRandomCones(0),
+  fAvgTrials(1),
+  fExternalWeight(1),
+  fTrackEtaWindow(0.9),    
+  fRecEtaWindow(0.5),
+  fTrackPtCut(0.),                                                     
+  fJetOutputMinPt(0.150),
+  fMaxTrackPtInJet(100.),
+  fJetTriggerPtCut(0),
+  fVtxZCut(8),
+  fVtxR2Cut(1),
+  fCentCutUp(0),
+  fCentCutLo(0),
+  fNonStdBranch(""),
+  fBackgroundBranch(""),
+  fNonStdFile(""),
+  fRparam(1.0), 
+  fAlgorithm(fastjet::kt_algorithm),
+  fStrategy(fastjet::Best),
+  fRecombScheme(fastjet::BIpt_scheme),
+  fAreaType(fastjet::active_area), 
+  fGhostArea(0.01),
+  fActiveAreaRepeats(1),
+  fGhostEtamax(1.5),
+  fTCAJetsOut(0x0),
+  fTCAJetsOutRan(0x0),
+  fTCARandomConesOut(0x0),
+  fTCARandomConesOutRan(0x0),
+  fAODJetBackgroundOut(0x0),
+  fRandom(0),
+  fh1Xsec(0x0),
+  fh1Trials(0x0),
+  fh1PtHard(0x0),
+  fh1PtHardNoW(0x0),  
+  fh1PtHardTrials(0x0),
+  fh1NJetsRec(0x0),
+  fh1NConstRec(0x0),
+  fh1NConstLeadingRec(0x0),
+  fh1PtJetsRecIn(0x0),
+  fh1PtJetsLeadingRecIn(0x0),
+  fh1PtJetConstRec(0x0),
+  fh1PtJetConstLeadingRec(0x0),
+  fh1PtTracksRecIn(0x0),
+  fh1PtTracksLeadingRecIn(0x0),
+  fh1NJetsRecRan(0x0),
+  fh1NConstRecRan(0x0),
+  fh1PtJetsLeadingRecInRan(0x0),
+  fh1NConstLeadingRecRan(0x0),
+  fh1PtJetsRecInRan(0x0),
+  fh1PtTracksGenIn(0x0),
+  fh1Nch(0x0),
+  fh1CentralityPhySel(0x0), 
+  fh1Centrality(0x0), 
+  fh1CentralitySelect(0x0),
+  fh1ZPhySel(0x0), 
+  fh1Z(0x0), 
+  fh1ZSelect(0x0),
+  fh2NRecJetsPt(0x0),
+  fh2NRecTracksPt(0x0),
+  fh2NConstPt(0x0),
+  fh2NConstLeadingPt(0x0),
+  fh2JetPhiEta(0x0),
+  fh2LeadingJetPhiEta(0x0),
+  fh2JetEtaPt(0x0),
+  fh2LeadingJetEtaPt(0x0),
+  fh2TrackEtaPt(0x0),
+  fh2LeadingTrackEtaPt(0x0),
+  fh2JetsLeadingPhiEta(0x0),
+  fh2JetsLeadingPhiPt(0x0),
+  fh2TracksLeadingPhiEta(0x0),
+  fh2TracksLeadingPhiPt(0x0),
+  fh2TracksLeadingJetPhiPt(0x0),
+  fh2JetsLeadingPhiPtW(0x0),
+  fh2TracksLeadingPhiPtW(0x0),
+  fh2TracksLeadingJetPhiPtW(0x0),
+  fh2NRecJetsPtRan(0x0),
+  fh2NConstPtRan(0x0),
+  fh2NConstLeadingPtRan(0x0),
+  fh2PtNch(0x0),
+  fh2PtNchRan(0x0),
+  fh2PtNchN(0x0),
+  fh2PtNchNRan(0x0),
+  fh2TracksLeadingJetPhiPtRan(0x0),
+  fh2TracksLeadingJetPhiPtWRan(0x0),
+  fHistList(0x0)  
+{
+  for(int i = 0;i<3;i++){
+    fh1BiARandomCones[i] = 0;
+    fh1BiARandomConesRan[i] = 0;
+  }
+  for(int i = 0;i<kMaxCent;i++){
+    fh2JetsLeadingPhiPtC[i] = 0;     
+    fh2JetsLeadingPhiPtWC[i] = 0;      //! jet correlation with leading jet
+    fh2TracksLeadingJetPhiPtC[i] = 0;
+    fh2TracksLeadingJetPhiPtWC[i] = 0;
+  }
+}
+
+AliAnalysisTaskJetCluster::AliAnalysisTaskJetCluster(const char* name):
+  AliAnalysisTaskSE(name),
+  fAOD(0x0),
+  fAODExtension(0x0),
+  fRef(new TRefArray),
+  fUseAODTrackInput(kFALSE),
+  fUseAODMCInput(kFALSE),
+  fUseBackgroundCalc(kFALSE),
+  fEventSelection(kFALSE),                                                     
+  fFilterMask(0),
+  fFilterType(0),
+  fJetTypes(kJet),
+  fTrackTypeRec(kTrackUndef),
+  fTrackTypeGen(kTrackUndef),
+  fNSkipLeadingRan(0),
+  fNSkipLeadingCone(0),
+  fNRandomCones(0),
+  fAvgTrials(1),
+  fExternalWeight(1),    
+  fTrackEtaWindow(0.9),    
+  fRecEtaWindow(0.5),
+  fTrackPtCut(0.),                                                     
+  fJetOutputMinPt(0.150),
+  fMaxTrackPtInJet(100.),
+  fJetTriggerPtCut(0),
+  fVtxZCut(8),
+  fVtxR2Cut(1),
+  fCentCutUp(0),
+  fCentCutLo(0),
+  fNonStdBranch(""),
+  fBackgroundBranch(""),
+  fNonStdFile(""),
+  fRparam(1.0), 
+  fAlgorithm(fastjet::kt_algorithm),
+  fStrategy(fastjet::Best),
+  fRecombScheme(fastjet::BIpt_scheme),
+  fAreaType(fastjet::active_area), 
+  fGhostArea(0.01),
+  fActiveAreaRepeats(1),
+  fGhostEtamax(1.5),
+  fTCAJetsOut(0x0),
+  fTCAJetsOutRan(0x0),
+  fTCARandomConesOut(0x0),
+  fTCARandomConesOutRan(0x0),
+  fAODJetBackgroundOut(0x0),
+  fRandom(0),
+  fh1Xsec(0x0),
+  fh1Trials(0x0),
+  fh1PtHard(0x0),
+  fh1PtHardNoW(0x0),  
+  fh1PtHardTrials(0x0),
+  fh1NJetsRec(0x0),
+  fh1NConstRec(0x0),
+  fh1NConstLeadingRec(0x0),
+  fh1PtJetsRecIn(0x0),
+  fh1PtJetsLeadingRecIn(0x0),
+  fh1PtJetConstRec(0x0),
+  fh1PtJetConstLeadingRec(0x0),
+  fh1PtTracksRecIn(0x0),
+  fh1PtTracksLeadingRecIn(0x0),
+  fh1NJetsRecRan(0x0),
+  fh1NConstRecRan(0x0),
+  fh1PtJetsLeadingRecInRan(0x0),
+  fh1NConstLeadingRecRan(0x0),
+  fh1PtJetsRecInRan(0x0),
+  fh1PtTracksGenIn(0x0),
+  fh1Nch(0x0),
+  fh1CentralityPhySel(0x0), 
+  fh1Centrality(0x0), 
+  fh1CentralitySelect(0x0),
+  fh1ZPhySel(0x0), 
+  fh1Z(0x0), 
+  fh1ZSelect(0x0),
+  fh2NRecJetsPt(0x0),
+  fh2NRecTracksPt(0x0),
+  fh2NConstPt(0x0),
+  fh2NConstLeadingPt(0x0),
+  fh2JetPhiEta(0x0),
+  fh2LeadingJetPhiEta(0x0),
+  fh2JetEtaPt(0x0),
+  fh2LeadingJetEtaPt(0x0),
+  fh2TrackEtaPt(0x0),
+  fh2LeadingTrackEtaPt(0x0),
+  fh2JetsLeadingPhiEta(0x0),
+  fh2JetsLeadingPhiPt(0x0),
+  fh2TracksLeadingPhiEta(0x0),
+  fh2TracksLeadingPhiPt(0x0),
+  fh2TracksLeadingJetPhiPt(0x0),
+  fh2JetsLeadingPhiPtW(0x0),
+  fh2TracksLeadingPhiPtW(0x0),
+  fh2TracksLeadingJetPhiPtW(0x0),
+  fh2NRecJetsPtRan(0x0),
+  fh2NConstPtRan(0x0),
+  fh2NConstLeadingPtRan(0x0),
+  fh2PtNch(0x0),
+  fh2PtNchRan(0x0),
+  fh2PtNchN(0x0),
+  fh2PtNchNRan(0x0),
+  fh2TracksLeadingJetPhiPtRan(0x0),
+  fh2TracksLeadingJetPhiPtWRan(0x0),
+  fHistList(0x0)
+{
+  for(int i = 0;i<3;i++){
+    fh1BiARandomCones[i] = 0;
+    fh1BiARandomConesRan[i] = 0;
+  }
+  for(int i = 0;i<kMaxCent;i++){
+    fh2JetsLeadingPhiPtC[i] = 0;     
+    fh2JetsLeadingPhiPtWC[i] = 0;      //! jet correlation with leading jet
+    fh2TracksLeadingJetPhiPtC[i] = 0;
+    fh2TracksLeadingJetPhiPtWC[i] = 0;
+  }
+ DefineOutput(1, TList::Class());  
+}
+
+
+
+Bool_t AliAnalysisTaskJetCluster::Notify()
+{
+  //
+  // Implemented Notify() to read the cross sections
+  // and number of trials from pyxsec.root
+  // 
+  return kTRUE;
+}
+
+void AliAnalysisTaskJetCluster::UserCreateOutputObjects()
+{
+
+  //
+  // Create the output container
+  //
+
+  fRandom = new TRandom3(0);
+
+
+  // Connect the AOD
+
+
+  if (fDebug > 1) printf("AnalysisTaskJetCluster::UserCreateOutputObjects() \n");
+
+  
+
+  if(fNonStdBranch.Length()!=0)
+    {
+      // only create the output branch if we have a name
+      // Create a new branch for jets...
+      //  -> cleared in the UserExec....
+      // here we can also have the case that the brnaches are written to a separate file
+      
+      if(fJetTypes&kJet){
+       fTCAJetsOut = new TClonesArray("AliAODJet", 0);
+       fTCAJetsOut->SetName(fNonStdBranch.Data());
+       AddAODBranch("TClonesArray",&fTCAJetsOut,fNonStdFile.Data());
+      }
+   
+      if(fJetTypes&kJetRan){
+       fTCAJetsOutRan = new TClonesArray("AliAODJet", 0);
+       fTCAJetsOutRan->SetName(Form("%s_%s",fNonStdBranch.Data(),"random"));
+       AddAODBranch("TClonesArray",&fTCAJetsOutRan,fNonStdFile.Data());
+      }
+
+      if(fUseBackgroundCalc){
+       if(!AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
+         fAODJetBackgroundOut = new AliAODJetEventBackground();
+         fAODJetBackgroundOut->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
+         AddAODBranch("AliAODJetEventBackground",&fAODJetBackgroundOut,fNonStdFile.Data());  
+       }
+      }
+      // create the branch for the random cones with the same R 
+      TString cName = Form("%sRandomConeSkip%02d",fNonStdBranch.Data(),fNSkipLeadingCone);
+  
+      if(fNRandomCones>0){
+       if(fJetTypes&kRC){
+         if(!AODEvent()->FindListObject(cName.Data())){
+           fTCARandomConesOut = new TClonesArray("AliAODJet", 0);
+           fTCARandomConesOut->SetName(cName.Data());
+           AddAODBranch("TClonesArray",&fTCARandomConesOut,fNonStdFile.Data());
+         }
+       }
+       // create the branch with the random for the random cones on the random event
+       if(fJetTypes&kRCRan){
+         cName = Form("%sRandomCone_random",fNonStdBranch.Data());
+         if(!AODEvent()->FindListObject(cName.Data())){
+           fTCARandomConesOutRan = new TClonesArray("AliAODJet", 0);
+           fTCARandomConesOutRan->SetName(cName.Data());
+           AddAODBranch("TClonesArray",&fTCARandomConesOutRan,fNonStdFile.Data());
+         }
+       }
+      }
+    
+      if(fNonStdFile.Length()!=0){
+       // 
+       // case that we have an AOD extension we need to fetch the jets from the extended output
+       // we identify the extension aod event by looking for the branchname
+       AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
+       // case that we have an AOD extension we need can fetch the background maybe from the extended output                                                                  
+       fAODExtension = (aodH?aodH->GetExtension(fNonStdFile.Data()):0);
+      }
+    }
+
+
+  if(!fHistList)fHistList = new TList();
+  fHistList->SetOwner();
+  PostData(1, fHistList); // post data in any case once
+
+  Bool_t oldStatus = TH1::AddDirectoryStatus();
+  TH1::AddDirectory(kFALSE);
+
+  //
+  //  Histogram
+    
+  const Int_t nBinPt = 100;
+  Double_t binLimitsPt[nBinPt+1];
+  for(Int_t iPt = 0;iPt <= nBinPt;iPt++){
+    if(iPt == 0){
+      binLimitsPt[iPt] = 0.0;
+    }
+    else {// 1.0
+      binLimitsPt[iPt] =  binLimitsPt[iPt-1] + 2.0;
+    }
+  }
+  
+  const Int_t nBinPhi = 90;
+  Double_t binLimitsPhi[nBinPhi+1];
+  for(Int_t iPhi = 0;iPhi<=nBinPhi;iPhi++){
+    if(iPhi==0){
+      binLimitsPhi[iPhi] = -1.*TMath::Pi();
+    }
+    else{
+      binLimitsPhi[iPhi] = binLimitsPhi[iPhi-1] + 1/(Float_t)nBinPhi * TMath::Pi()*2;
+    }
+  }
+
+
+
+  const Int_t nBinEta = 40;
+  Double_t binLimitsEta[nBinEta+1];
+  for(Int_t iEta = 0;iEta<=nBinEta;iEta++){
+    if(iEta==0){
+      binLimitsEta[iEta] = -2.0;
+    }
+    else{
+      binLimitsEta[iEta] = binLimitsEta[iEta-1] + 0.1;
+    }
+  }
+
+  const int nChMax = 5000;
+
+  fh1Xsec = new TProfile("fh1Xsec","xsec from pyxsec.root",1,0,1);
+  fh1Xsec->GetXaxis()->SetBinLabel(1,"<#sigma>");
+
+  fh1Trials = new TH1F("fh1Trials","trials root file",1,0,1);
+  fh1Trials->GetXaxis()->SetBinLabel(1,"#sum{ntrials}");
+
+
+  fh1NJetsRec = new TH1F("fh1NJetsRec","N reconstructed jets",120,-0.5,119.5);
+  fh1NJetsRecRan = new TH1F("fh1NJetsRecRan","N reconstructed jets",120,-0.5,119.5);
+
+  fh1NConstRec = new TH1F("fh1NConstRec","# jet constituents",120,-0.5,119.5);
+  fh1NConstRecRan = new TH1F("fh1NConstRecRan","# jet constituents",120,-0.5,119.5);
+  fh1NConstLeadingRec = new TH1F("fh1NConstLeadingRec","jet constituents",120,-0.5,119.5);
+  fh1NConstLeadingRecRan = new TH1F("fh1NConstLeadingRecRan","jet constituents",120,-0.5,119.5);
+
+
+  fh1PtHard = new TH1F("fh1PtHard","PYTHIA Pt hard;p_{T,hard}",nBinPt,binLimitsPt);
+  fh1PtHardNoW = new TH1F("fh1PtHardNoW","PYTHIA Pt hard no weight;p_{T,hard}",nBinPt,binLimitsPt);
+  fh1PtHardTrials = new TH1F("fh1PtHardTrials","PYTHIA Pt hard weight with trials;p_{T,hard}",nBinPt,binLimitsPt);
+
+  fh1PtJetsRecIn  = new TH1F("fh1PtJetsRecIn","Rec jets P_T;p_{T} (GeV/c)",nBinPt,binLimitsPt);
+  fh1PtJetsRecInRan  = new TH1F("fh1PtJetsRecInRan","Rec jets P_T;p_{T} (GeV/c)",nBinPt,binLimitsPt);
+  fh1PtJetsLeadingRecIn = new TH1F("fh1PtJetsLeadingRecIn","Rec jets P_T;p_{T} (GeV/c)",nBinPt,binLimitsPt);
+  fh1PtJetsLeadingRecInRan = new TH1F("fh1PtJetsLeadingRecInRan","Rec jets P_T;p_{T} (GeV/c)",nBinPt,binLimitsPt);
+  fh1PtJetConstRec = new TH1F("fh1PtJetsConstRec","Rec jets constituents P_T;p_{T} (GeV/c)",nBinPt,binLimitsPt);
+  fh1PtJetConstLeadingRec = new TH1F("fh1PtJetsConstLeadingRec","Rec jets constituents P_T;p_{T} (GeV/c)",nBinPt,binLimitsPt);
+  fh1PtTracksRecIn  = new TH1F("fh1PtTracksRecIn",Form("Rec tracks P_T #eta < %1.2f;p_{T} (GeV/c)",fTrackEtaWindow),nBinPt,binLimitsPt);
+  fh1PtTracksLeadingRecIn  = new TH1F("fh1PtTracksLeadingRecIn",Form("Rec tracks P_T #eta < %1.2f ;p_{T} (GeV/c)",fTrackEtaWindow),nBinPt,binLimitsPt);
+  fh1PtTracksGenIn  = new TH1F("fh1PtTracksGenIn",Form("gen tracks P_T #eta < %1.2f ;p_{T} (GeV/c)",fTrackEtaWindow),nBinPt,binLimitsPt);
+  fh1Nch = new TH1F("fh1Nch","charged multiplicity; N_{ch}",nChMax,-0.5,nChMax-0.5);
+
+  fh1Centrality = new TH1F("fh1Centrality",";cent (%)",111,-0.5,110.5);
+  fh1CentralitySelect = new TH1F("fh1CentralitySelect",";cent (%)",111,-0.5,110.5);
+  fh1CentralityPhySel = new TH1F("fh1CentralityPhySel",";cent (%)",111,-0.5,110.5);
+
+  fh1Z = new TH1F("fh1Z",";zvtx",100,-25,25);
+  fh1ZSelect = new TH1F("fh1ZSelect",";zvtx",100,-25,25);
+  fh1ZPhySel = new TH1F("fh1ZPhySel",";zvtx",100,-25,25);
+
+  fh2NRecJetsPt = new TH2F("fh2NRecJetsPt","Number of jets above threshhold;p_{T,cut} (GeV/c);N_{jets}",nBinPt,binLimitsPt,50,-0.5,49.5);
+  fh2NRecJetsPtRan = new TH2F("fh2NRecJetsPtRan","Number of jets above threshhold;p_{T,cut} (GeV/c);N_{jets}",nBinPt,binLimitsPt,50,-0.5,49.5);
+  fh2NRecTracksPt = new TH2F("fh2NRecTracksPt","Number of tracks above threshhold;p_{T,cut} (GeV/c);N_{tracks}",nBinPt,binLimitsPt,50,-0.5,49.5);
+  // 
+
+
+  fh2NConstPt = new TH2F("fh2NConstPt","Number of constituents ;p_{T} (GeV/c);N",nBinPt,binLimitsPt,50,-0.5,49.5);
+  fh2NConstLeadingPt = new TH2F("fh2NConstLeadingPt","Number of constituents ;p_{T} (GeV/c);N",nBinPt,binLimitsPt,50,-0.5,49.5);
+  fh2NConstPtRan = new TH2F("fh2NConstPtRan","Number of constituents ;p_{T} (GeV/c);N",nBinPt,binLimitsPt,50,-0.5,49.5);
+  fh2NConstLeadingPtRan = new TH2F("fh2NConstLeadingPtRan","Number of constituents ;p_{T} (GeV/c);N",nBinPt,binLimitsPt,50,-0.5,49.5);
+
+  fh2PtNch = new TH2F("fh2PtNch","p_T of cluster vs. multiplicity; N_{ch};p_{T} (GeV/c);",nChMax,-0.5,nChMax-0.5,nBinPt,binLimitsPt);
+  fh2PtNchRan = new TH2F("fh2PtNchRan","p_T of cluster vs. multiplicity ran; N_{ch};p_{T} (GeV/c);",nChMax,-0.5,nChMax-0.5,nBinPt,binLimitsPt);
+  fh2PtNchN = new TH2F("fh2PtNchN","p_T of cluster vs. multiplicity N weighted; N_{ch};p_{T} (GeV/c);",nChMax,-0.5,nChMax-0.5,nBinPt,binLimitsPt);
+  fh2PtNchNRan = new TH2F("fh2PtNchNRan","p_T of cluster vs. multiplicity N weighted ran; N_{ch};p_{T} (GeV/c);",nChMax,-0.5,nChMax-0.5,nBinPt,binLimitsPt);
+
+
+
+  fh2JetPhiEta  = new TH2F("fh2JetPhiEta","eta vs phi all jets;#phi;#eta",
+                          nBinPhi,0.,2.*TMath::Pi(),nBinEta,binLimitsEta);
+  fh2LeadingJetPhiEta  = new TH2F("fh2LeadingJetPhiEta","eta vs phi leading jets;#phi;#eta",
+                                 nBinPhi,0.,2.*TMath::Pi(),nBinEta,binLimitsEta);
+
+  fh2JetEtaPt  = new TH2F("fh2JetEtaPt","pt vs eta all jets;#eta;p_{T}",
+                         nBinEta,binLimitsEta,nBinPt,binLimitsPt);
+  fh2LeadingJetEtaPt  = new TH2F("fh2LeadingJetEtaPt","pT vs eta leading jets;#eta;p_{T}",
+                                nBinEta,binLimitsEta,nBinPt,binLimitsPt);
+
+  fh2TrackEtaPt  = new TH2F("fh2TrackEtaPt","pt vs eta all jets;#eta;p_{T}",
+                         nBinEta,binLimitsEta,nBinPt,binLimitsPt);
+  fh2LeadingTrackEtaPt  = new TH2F("fh2LeadingTrackEtaPt","pT vs eta leading jets;#eta;p_{T}",
+                                nBinEta,binLimitsEta,nBinPt,binLimitsPt);
+
+
+
+  fh2JetsLeadingPhiEta = new TH2F("fh2JetsLeadingPhiEta","delta eta vs delta phi to leading jet;#Delta#phi;#Delta#eta",
+                               nBinPhi,binLimitsPhi,nBinEta,binLimitsEta);
+  fh2JetsLeadingPhiPt = new TH2F("fh2JetsLeadingPhiPt","leading p_T vs delta phi to leading jet;#Delta#phi;p_{T} (GeV/c)",
+                               nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+  fh2TracksLeadingPhiEta = new TH2F("fh2TracksLeadingPhiEta","delta eta vs delta phi to leading track;#Delta#phi;#Delta#eta",
+                                   nBinPhi,binLimitsPhi,nBinEta,binLimitsEta);
+  fh2TracksLeadingPhiPt = new TH2F("fh2TracksLeadingPhiPt","leading p_T vs delta phi to leading jet;#Delta#phi;p_{T} (GeV/c)",
+                                nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+  fh2TracksLeadingJetPhiPt = new TH2F("fh2TracksLeadingJetPhiPt","leading p_T vs delta phi to leading jet;#Delta#phi;p_{T} (GeV/c)",
+                                nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+  fh2TracksLeadingJetPhiPtRan = new TH2F("fh2TracksLeadingJetPhiPtRan","leading p_T vs delta phi to leading jet;#Delta#phi;p_{T} (GeV/c)",
+                                nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+
+  fh2JetsLeadingPhiPtW      = new TH2F("fh2JetsLeadingPhiPtW","leading p_T vs delta phi p_T weigted to leading jet;#Delta#phi;p_{T} (GeV/c)",
+                               nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+  fh2TracksLeadingPhiPtW    = new TH2F("fh2TracksLeadingPhiPtW","leading p_T vs delta phi to leading jet (p_T weighted);#Delta#phi;p_{T} (GeV/c)",
+                                   nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+
+  fh2TracksLeadingJetPhiPtW = new TH2F("fh2TracksLeadingJetPhiPtW","leading p_T vs delta phi to leading jet;#Delta#phi;p_{T} (GeV/c)",
+                                      nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+  fh2TracksLeadingJetPhiPtWRan = new TH2F("fh2TracksLeadingJetPhiPtWRan","leading p_T vs delta phi to leading jet;#Delta#phi;p_{T} (GeV/c)",
+                                      nBinPhi,binLimitsPhi,nBinPt,binLimitsPt);
+
+
+  if(fNRandomCones>0&&fUseBackgroundCalc){
+    for(int i = 0;i<3;i++){
+      fh1BiARandomCones[i] = new TH1F(Form("fh1BiARandomCones%d",i),";B_{i}^{A} (GeV/c)",200,-100,100);
+      fh1BiARandomConesRan[i] =  new TH1F(Form("fh1BiARandomConesRan%d",i),";B_{i}^{A} (GeV/c)",200,-100,100);
+    }
+  }
+
+  for(int i = 0;i < kMaxCent;i++){
+    fh2JetsLeadingPhiPtC[i] = (TH2F*)fh2JetsLeadingPhiPt->Clone(Form("%s_C%02d",fh2JetsLeadingPhiPt->GetName(),i+1));
+    fh2JetsLeadingPhiPtWC[i]= (TH2F*)fh2JetsLeadingPhiPtW->Clone(Form("%s_C%02d",fh2JetsLeadingPhiPtW->GetName(),i+1));
+    fh2TracksLeadingJetPhiPtC[i] = (TH2F*)fh2TracksLeadingJetPhiPt->Clone(Form("%s_C%02d",fh2TracksLeadingJetPhiPt->GetName(),i+1));
+    fh2TracksLeadingJetPhiPtWC[i] = (TH2F*)fh2TracksLeadingJetPhiPtW->Clone(Form("%s_C%02d",fh2TracksLeadingJetPhiPtW->GetName(),i+1));
+  }
+
+  const Int_t saveLevel = 3; // large save level more histos
+  if(saveLevel>0){
+    fHistList->Add(fh1Xsec);
+    fHistList->Add(fh1Trials);
+
+    fHistList->Add(fh1NJetsRec);
+    fHistList->Add(fh1NConstRec);
+    fHistList->Add(fh1NConstLeadingRec);
+    fHistList->Add(fh1PtJetsRecIn);
+    fHistList->Add(fh1PtJetsLeadingRecIn);
+    fHistList->Add(fh1PtTracksRecIn);
+    fHistList->Add(fh1PtTracksLeadingRecIn);
+    fHistList->Add(fh1PtJetConstRec);
+    fHistList->Add(fh1PtJetConstLeadingRec);
+    fHistList->Add(fh1NJetsRecRan);
+    fHistList->Add(fh1NConstRecRan);
+    fHistList->Add(fh1PtJetsLeadingRecInRan);
+    fHistList->Add(fh1NConstLeadingRecRan);
+    fHistList->Add(fh1PtJetsRecInRan);
+    fHistList->Add(fh1Nch);
+    fHistList->Add(fh1Centrality);
+    fHistList->Add(fh1CentralitySelect);
+    fHistList->Add(fh1CentralityPhySel);
+    fHistList->Add(fh1Z);
+    fHistList->Add(fh1ZSelect);
+    fHistList->Add(fh1ZPhySel);
+    if(fNRandomCones>0&&fUseBackgroundCalc){
+      for(int i = 0;i<3;i++){
+       fHistList->Add(fh1BiARandomCones[i]);
+       fHistList->Add(fh1BiARandomConesRan[i]);
+      }
+    }
+  for(int i = 0;i < kMaxCent;i++){
+    fHistList->Add(fh2JetsLeadingPhiPtC[i]);
+    fHistList->Add(fh2JetsLeadingPhiPtWC[i]);
+    fHistList->Add(fh2TracksLeadingJetPhiPtC[i]);
+    fHistList->Add(fh2TracksLeadingJetPhiPtWC[i]);
+  }
+
+    fHistList->Add(fh2NRecJetsPt);
+    fHistList->Add(fh2NRecTracksPt);
+    fHistList->Add(fh2NConstPt);
+    fHistList->Add(fh2NConstLeadingPt);
+    fHistList->Add(fh2PtNch);
+    fHistList->Add(fh2PtNchRan);
+    fHistList->Add(fh2PtNchN);
+    fHistList->Add(fh2PtNchNRan);
+    fHistList->Add(fh2JetPhiEta);
+    fHistList->Add(fh2LeadingJetPhiEta);
+    fHistList->Add(fh2JetEtaPt);
+    fHistList->Add(fh2LeadingJetEtaPt);
+    fHistList->Add(fh2TrackEtaPt);
+    fHistList->Add(fh2LeadingTrackEtaPt);
+    fHistList->Add(fh2JetsLeadingPhiEta );
+    fHistList->Add(fh2JetsLeadingPhiPt);
+    fHistList->Add(fh2TracksLeadingPhiEta);
+    fHistList->Add(fh2TracksLeadingPhiPt);
+    fHistList->Add(fh2TracksLeadingJetPhiPt);
+    fHistList->Add(fh2JetsLeadingPhiPtW);
+    fHistList->Add(fh2TracksLeadingPhiPtW);
+    fHistList->Add(fh2TracksLeadingJetPhiPtW);
+    fHistList->Add(fh2NRecJetsPtRan);
+    fHistList->Add(fh2NConstPtRan);
+    fHistList->Add(fh2NConstLeadingPtRan);
+    fHistList->Add(fh2TracksLeadingJetPhiPtRan);
+    fHistList->Add(fh2TracksLeadingJetPhiPtWRan);
+  }
+
+  // =========== Switch on Sumw2 for all histos ===========
+  for (Int_t i=0; i<fHistList->GetEntries(); ++i) {
+    TH1 *h1 = dynamic_cast<TH1*>(fHistList->At(i));
+    if (h1){
+      h1->Sumw2();
+      continue;
+    }
+    THnSparse *hn = dynamic_cast<THnSparse*>(fHistList->At(i));
+    if(hn)hn->Sumw2();
+  }
+  TH1::AddDirectory(oldStatus);
+}
+
+void AliAnalysisTaskJetCluster::Init()
+{
+  //
+  // Initialization
+  //
+
+  if (fDebug > 1) printf("AnalysisTaskJetCluster::Init() \n");
+
+}
+
+void AliAnalysisTaskJetCluster::UserExec(Option_t */*option*/)
+{
+
+  // handle and reset the output jet branch 
+
+  if(fTCAJetsOut)fTCAJetsOut->Delete();
+  if(fTCAJetsOutRan)fTCAJetsOutRan->Delete();
+  if(fTCARandomConesOut)fTCARandomConesOut->Delete();
+  if(fTCARandomConesOutRan)fTCARandomConesOutRan->Delete();
+  if(fAODJetBackgroundOut)fAODJetBackgroundOut->Reset();
+
+  AliAODJetEventBackground* externalBackground = 0;
+  if(!externalBackground&&fBackgroundBranch.Length()){
+    externalBackground =  (AliAODJetEventBackground*)(AODEvent()->FindListObject(fBackgroundBranch.Data()));
+    if((!externalBackground)&&fAODExtension)externalBackground = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(fBackgroundBranch.Data()));
+    if(!externalBackground)Printf("%s:%d Background branch not found %s",(char*)__FILE__,__LINE__,fBackgroundBranch.Data());;
+  }
+  //
+  // Execute analysis for current event
+  //
+  AliESDEvent *fESD = 0;
+  if(fUseAODTrackInput){    
+    fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
+    if(!fAOD){
+      Printf("%s:%d AODEvent not found in Input Manager %d",(char*)__FILE__,__LINE__,fUseAODTrackInput);
+      return;
+    }
+    // fethc the header
+  }
+  else{
+    //  assume that the AOD is in the general output...
+    fAOD  = AODEvent();
+    if(!fAOD){
+      Printf("%s:%d AODEvent not found in the Output",(char*)__FILE__,__LINE__);
+      return;
+    }
+    if(fDebug>0){
+      fESD = dynamic_cast<AliESDEvent*> (InputEvent());
+    }
+  }
+  
+  Bool_t selectEvent =  false;
+  Bool_t physicsSelection = true;// handled by the framework(fInputHandler->IsEventSelected()&AliVEvent::kMB)==AliVEvent::kMB;
+
+  Float_t cent = 0;
+  Float_t zVtx  = 0;
+  Int_t cenClass = -1;
+  if(fAOD){
+    const AliAODVertex *vtxAOD = fAOD->GetPrimaryVertex();
+    TString vtxTitle(vtxAOD->GetTitle());
+    zVtx = vtxAOD->GetZ();
+
+    cent = fAOD->GetHeader()->GetCentrality();
+    if(cent<10)cenClass = 0;
+    else if(cent<30)cenClass = 1;
+    else if(cent<50)cenClass = 2;
+    else if(cent<80)cenClass = 3;
+    if(physicsSelection){
+      fh1CentralityPhySel->Fill(cent);
+      fh1ZPhySel->Fill(zVtx);
+    }
+
+    if(fEventSelection){
+      if(vtxAOD->GetNContributors()>2&&!vtxTitle.Contains("TPCVertex")){
+       Float_t yvtx = vtxAOD->GetY();
+       Float_t xvtx = vtxAOD->GetX();
+       Float_t r2   = yvtx*yvtx+xvtx*xvtx;  
+       if(TMath::Abs(zVtx)<fVtxZCut&&r2<fVtxR2Cut){ // apply vertex cut later on
+         if(physicsSelection){
+           selectEvent = true;
+         }
+       }
+      }
+      if(fCentCutUp>0){
+       if(cent<fCentCutLo||cent>fCentCutUp){
+         selectEvent = false;
+       }
+      }
+    }else{
+      selectEvent = true;
+    }
+  }
+  
+
+  if(!selectEvent){
+    PostData(1, fHistList);
+    return;
+  }
+  fh1Centrality->Fill(cent);  
+  fh1Z->Fill(zVtx);
+  fh1Trials->Fill("#sum{ntrials}",1);
+  
+
+  if (fDebug > 10)Printf("%s:%d",(char*)__FILE__,__LINE__);
+
+  // ==== General variables needed
+
+
+
+  // we simply fetch the tracks/mc particles as a list of AliVParticles
+
+  TList recParticles;
+  TList genParticles;
+
+  Int_t nT = GetListOfTracks(&recParticles,fTrackTypeRec);
+  Float_t nCh = recParticles.GetEntries(); 
+  fh1Nch->Fill(nCh);
+  if(fDebug>2)Printf("%s:%d Selected Rec tracks: %d %d",(char*)__FILE__,__LINE__,nT,recParticles.GetEntries());
+  nT = GetListOfTracks(&genParticles,fTrackTypeGen);
+  if(fDebug>2)Printf("%s:%d Selected Gen tracks: %d %d",(char*)__FILE__,__LINE__,nT,genParticles.GetEntries());
+
+  // find the jets....
+
+  vector<fastjet::PseudoJet> inputParticlesRec;
+  vector<fastjet::PseudoJet> inputParticlesRecRan;
+  
+  // Generate the random cones
+  
+  AliAODJet vTmpRan(1,0,0,1);
+  for(int i = 0; i < recParticles.GetEntries(); i++){
+    AliVParticle *vp = (AliVParticle*)recParticles.At(i);
+    // Carefull energy is not well determined in real data, should not matter for p_T scheme?
+    // we take total momentum here
+    fastjet::PseudoJet jInp(vp->Px(),vp->Py(),vp->Pz(),vp->P());
+    jInp.set_user_index(i);
+    inputParticlesRec.push_back(jInp);
+
+    // the randomized input changes eta and phi, but keeps the p_T
+    if(i>=fNSkipLeadingRan){// eventually skip the leading particles
+      Double_t pT = vp->Pt();
+      Double_t eta = 2.*fTrackEtaWindow * fRandom->Rndm() - fTrackEtaWindow;
+      Double_t phi = 2.* TMath::Pi() * fRandom->Rndm();
+      
+      Double_t theta = 2.*TMath::ATan(TMath::Exp(-eta));  
+      Double_t pZ = pT/TMath::Tan(theta);
+
+      Double_t pX = pT * TMath::Cos(phi);
+      Double_t pY = pT * TMath::Sin(phi);
+      Double_t p  = TMath::Sqrt(pT*pT+pZ*pZ); 
+      fastjet::PseudoJet jInpRan(pX,pY,pZ,p);
+
+      jInpRan.set_user_index(i);
+      inputParticlesRecRan.push_back(jInpRan);
+      vTmpRan.SetPxPyPzE(pX,pY,pZ,p);
+    }
+
+    // fill the tref array, only needed when we write out jets
+    if(fTCAJetsOut){
+      if(i == 0){
+       fRef->Delete(); // make sure to delete before placement new...
+       new(fRef) TRefArray(TProcessID::GetProcessWithUID(vp));
+      }
+      fRef->Add(vp);
+    }
+  }// recparticles
+
+  if(inputParticlesRec.size()==0){
+    if(fDebug)Printf("%s:%d No input particles found, skipping event",(char*)__FILE__,__LINE__);
+    PostData(1, fHistList);
+    return;
+  }
+  
+  // run fast jet
+  // employ setters for these...
+
+  // now create the object that holds info about ghosts                        
+  /*
+  if(!fUseBackgroundCalc&& fNonStdBranch.Length()==0){
+    // reduce CPU time...
+    fGhostArea = 0.5; 
+    fActiveAreaRepeats = 0; 
+  }
+  */
+
+  fastjet::GhostedAreaSpec ghostSpec(fGhostEtamax, fActiveAreaRepeats, fGhostArea);
+  fastjet::AreaType areaType =   fastjet::active_area;
+  fastjet::AreaDefinition areaDef = fastjet::AreaDefinition(areaType,ghostSpec);
+  fastjet::JetDefinition jetDef(fAlgorithm, fRparam, fRecombScheme, fStrategy);
+  fastjet::ClusterSequenceArea clustSeq(inputParticlesRec, jetDef,areaDef);
+  
+  //range where to compute background
+  Double_t phiMin = 0, phiMax = 0, rapMin = 0, rapMax = 0;
+  phiMin = 0;
+  phiMax = 2*TMath::Pi();
+  rapMax = fGhostEtamax - fRparam;
+  rapMin = - fGhostEtamax + fRparam;
+  fastjet::RangeDefinition range(rapMin,rapMax, phiMin, phiMax);
+
+  const vector <fastjet::PseudoJet> &inclusiveJets = clustSeq.inclusive_jets();
+  const vector <fastjet::PseudoJet> &sortedJets = sorted_by_pt(inclusiveJets);
+
+  fh1NJetsRec->Fill(sortedJets.size());
+
+ // loop over all jets an fill information, first on is the leading jet
+
+  Int_t nRecOver = inclusiveJets.size();
+  Int_t nRec     = inclusiveJets.size();
+  if(inclusiveJets.size()>0){
+    AliAODJet leadingJet (sortedJets[0].px(), sortedJets[0].py(), sortedJets[0].pz(), sortedJets[0].E());
+    Double_t area = clustSeq.area(sortedJets[0]);
+    leadingJet.SetEffArea(area,0);
+    Float_t pt = leadingJet.Pt();
+    Int_t nAodOutJets = 0;
+    Int_t nAodOutTracks = 0;
+    AliAODJet *aodOutJet = 0;
+
+    Int_t iCount = 0;
+    for(int i = 1;i <= fh2NRecJetsPt->GetNbinsX();i++){
+      Float_t ptCut = fh2NRecJetsPt->GetXaxis()->GetBinCenter(i);
+      while(pt<ptCut&&iCount<nRec){
+       nRecOver--;
+       iCount++;
+       if(iCount<nRec){
+         pt = sortedJets[iCount].perp();
+       }
+      }
+      if(nRecOver<=0)break;
+      fh2NRecJetsPt->Fill(ptCut,nRecOver);
+    }
+    Float_t phi = leadingJet.Phi();
+    if(phi<0)phi+=TMath::Pi()*2.;    
+    Float_t eta = leadingJet.Eta();
+    Float_t pTback = 0;
+    if(externalBackground){
+      // carefull has to be filled in a task before
+      // todo, ReArrange to the botom
+      pTback = externalBackground->GetBackground(1)*leadingJet.EffectiveAreaCharged();
+    }
+    pt = leadingJet.Pt() - pTback;
+    // correlation of leading jet with tracks
+    TIterator *recIter = recParticles.MakeIterator();
+    recIter->Reset();
+    AliVParticle *tmpRecTrack = 0;
+    while((tmpRecTrack = (AliVParticle*)(recIter->Next()))){
+      Float_t tmpPt = tmpRecTrack->Pt();
+      // correlation
+      Float_t tmpPhi =  tmpRecTrack->Phi();     
+      if(tmpPhi<0)tmpPhi+=TMath::Pi()*2.;    
+      Float_t dPhi = phi - tmpPhi;
+      if(dPhi>TMath::Pi())dPhi = dPhi - 2.*TMath::Pi();
+      if(dPhi<(-1.*TMath::Pi()))dPhi = dPhi + 2.*TMath::Pi();      
+      fh2TracksLeadingJetPhiPt->Fill(dPhi,pt);
+      fh2TracksLeadingJetPhiPtW->Fill(dPhi,pt,tmpPt);
+      if(cenClass>=0){
+       fh2TracksLeadingJetPhiPtC[cenClass]->Fill(dPhi,pt);
+       fh2TracksLeadingJetPhiPtWC[cenClass]->Fill(dPhi,pt,tmpPt);
+      }
+
+    }  
+    
+   
+    TLorentzVector vecareab;
+    for(int j = 0; j < nRec;j++){
+      AliAODJet tmpRec (sortedJets[j].px(), sortedJets[j].py(), sortedJets[j].pz(), sortedJets[j].E());
+      aodOutJet = 0;
+      nAodOutTracks = 0;
+      Float_t tmpPt = tmpRec.Pt();  
+      
+      if(tmpPt>fJetOutputMinPt&&fTCAJetsOut){// cut on the non-background subtracted...
+       aodOutJet =  new ((*fTCAJetsOut)[nAodOutJets++]) AliAODJet(tmpRec);
+       aodOutJet->GetRefTracks()->Clear();
+       Double_t area1 = clustSeq.area(sortedJets[j]);
+       aodOutJet->SetEffArea(area1,0);
+        fastjet::PseudoJet vecarea=clustSeq.area_4vector(sortedJets[j]);  
+        vecareab.SetPxPyPzE(vecarea.px(),vecarea.py(),vecarea.pz(),vecarea.e());     
+       aodOutJet->SetVectorAreaCharged(&vecareab);
+      }
+
+
+      Float_t tmpPtBack = 0;
+      if(externalBackground){
+       // carefull has to be filled in a task before
+       // todo, ReArrange to the botom
+       tmpPtBack = externalBackground->GetBackground(2)*tmpRec.EffectiveAreaCharged();
+      }
+      tmpPt = tmpPt - tmpPtBack;
+      if(tmpPt<0)tmpPt = 0; // avoid negative weights...
+      
+      fh1PtJetsRecIn->Fill(tmpPt);
+      // Fill Spectra with constituentsemacs
+      const vector<fastjet::PseudoJet> &constituents = clustSeq.constituents(sortedJets[j]);
+
+      fh1NConstRec->Fill(constituents.size());
+      fh2PtNch->Fill(nCh,tmpPt);
+      fh2PtNchN->Fill(nCh,tmpPt,constituents.size());
+      fh2NConstPt->Fill(tmpPt,constituents.size());
+      // loop over constiutents and fill spectrum
+   
+      for(unsigned int ic = 0; ic < constituents.size();ic++){
+       AliVParticle *part = (AliVParticle*)recParticles.At(constituents[ic].user_index());
+       fh1PtJetConstRec->Fill(part->Pt());
+       if(aodOutJet){
+         aodOutJet->AddTrack(fRef->At(constituents[ic].user_index()));
+         if(part->Pt()>fMaxTrackPtInJet)aodOutJet->SetTrigger(AliAODJet::kHighTrackPtTriggered);
+       }
+       if(j==0)fh1PtJetConstLeadingRec->Fill(part->Pt());
+      }
+      
+     // correlation
+     Float_t tmpPhi =  tmpRec.Phi();
+     Float_t tmpEta =  tmpRec.Eta();
+     if(tmpPhi<0)tmpPhi+=TMath::Pi()*2.;        
+     if(j==0){
+       fh1PtJetsLeadingRecIn->Fill(tmpPt);
+       fh2LeadingJetPhiEta->Fill(tmpPhi,tmpEta);
+       fh2LeadingJetEtaPt->Fill(tmpEta,tmpPt);
+       fh1NConstLeadingRec->Fill(constituents.size());
+       fh2NConstLeadingPt->Fill(tmpPt,constituents.size());
+       continue;
+     }
+     fh2JetPhiEta->Fill(tmpRec.Phi(),tmpEta);
+     fh2JetEtaPt->Fill(tmpEta,tmpPt);
+     Float_t dPhi = phi - tmpPhi;
+     if(dPhi>TMath::Pi())dPhi = dPhi - 2.*TMath::Pi();
+     if(dPhi<(-1.*TMath::Pi()))dPhi = dPhi + 2.*TMath::Pi();      
+     Float_t dEta = eta - tmpRec.Eta();
+     fh2JetsLeadingPhiEta->Fill(dPhi,dEta);
+     fh2JetsLeadingPhiPt->Fill(dPhi,pt);
+     if(cenClass>=0){
+       fh2JetsLeadingPhiPtC[cenClass]->Fill(dPhi,pt);
+       fh2JetsLeadingPhiPtWC[cenClass]->Fill(dPhi,pt,tmpPt);
+     }
+     fh2JetsLeadingPhiPtW->Fill(dPhi,pt,tmpPt);
+    }// loop over reconstructed jets
+   delete recIter;
+
+
+
+   // Add the random cones...
+   if(fNRandomCones>0&&fTCARandomConesOut){       
+     // create a random jet within the acceptance
+     Double_t etaMax = fTrackEtaWindow - fRparam;
+     Int_t nCone = 0;
+     Int_t nConeRan = 0;
+     Double_t pTC = 1; // small number
+     for(int ir = 0;ir < fNRandomCones;ir++){
+       Double_t etaC = etaMax*2.*(fRandom->Rndm()-0.5); // +- etamax
+       Double_t phiC = fRandom->Rndm()*2.*TMath::Pi(); // 0 - 2pi
+       // massless jet
+       Double_t thetaC = 2.*TMath::ATan(TMath::Exp(-etaC));  
+       Double_t pZC = pTC/TMath::Tan(thetaC);
+       Double_t pXC = pTC * TMath::Cos(phiC);
+       Double_t pYC = pTC * TMath::Sin(phiC);
+       Double_t pC  = TMath::Sqrt(pTC*pTC+pZC*pZC); 
+       AliAODJet tmpRecC (pXC,pYC,pZC, pC); 
+       bool skip = false;
+       for(int jj = 0; jj < TMath::Min(nRec,fNSkipLeadingCone);jj++){// test for overlap with leading jets
+        AliAODJet jet (sortedJets[jj].px(), sortedJets[jj].py(), sortedJets[jj].pz(), sortedJets[jj].E());
+        if(jet.DeltaR(& tmpRecC)<2.*fRparam+0.2){
+          skip = true;
+          break;
+        }
+       }
+       // test for overlap with previous cones to avoid double counting
+       for(int iic = 0;iic<ir;iic++){
+        AliAODJet *iicone = (AliAODJet*)fTCARandomConesOut->At(iic);
+        if(iicone){
+          if(iicone->DeltaR(&tmpRecC)<2.*fRparam){
+            skip = true;
+            break;
+          }
+        }
+       }
+       if(skip)continue;
+       tmpRecC.SetBgEnergy(0,0); // this is use as temporary storage of the summed p_T below
+       if(fTCARandomConesOut)new ((*fTCARandomConesOut)[nCone++]) AliAODJet(tmpRecC);
+       if(fTCARandomConesOutRan)new ((*fTCARandomConesOutRan)[nConeRan++]) AliAODJet(tmpRecC);
+     }// loop over random cones creation
+
+  
+     // loop over the reconstructed particles and add up the pT in the random cones
+     // maybe better to loop over randomized particles not in the real jets...
+     // but this by definition brings dow average energy in the whole  event
+     AliAODJet vTmpRanR(1,0,0,1);
+     for(int i = 0; i < recParticles.GetEntries(); i++){
+       AliVParticle *vp = (AliVParticle*)recParticles.At(i);
+       if(fTCARandomConesOut){
+        for(int ir = 0;ir < fNRandomCones;ir++){
+          AliAODJet *jC = (AliAODJet*)fTCARandomConesOut->At(ir);  
+          if(jC&&jC->DeltaR(vp)<fRparam){
+            if(vp->Pt()>fMaxTrackPtInJet)jC->SetTrigger(AliAODJet::kHighTrackPtTriggered);
+            jC->SetBgEnergy(jC->ChargedBgEnergy()+vp->Pt(),0);
+          }
+        }  
+       }// add up energy in cone
+      
+       // the randomized input changes eta and phi, but keeps the p_T
+       if(i>=fNSkipLeadingRan){// eventually skip the leading particles
+        Double_t pTR = vp->Pt();
+        Double_t etaR = 2.*fTrackEtaWindow* fRandom->Rndm() - fTrackEtaWindow;
+        Double_t phiR = 2.* TMath::Pi() * fRandom->Rndm();
+        
+        Double_t thetaR = 2.*TMath::ATan(TMath::Exp(-etaR));  
+        Double_t pZR = pTR/TMath::Tan(thetaR);
+        
+        Double_t pXR = pTR * TMath::Cos(phiR);
+        Double_t pYR = pTR * TMath::Sin(phiR);
+        Double_t pR  = TMath::Sqrt(pTR*pTR+pZR*pZR); 
+        vTmpRanR.SetPxPyPzE(pXR,pYR,pZR,pR);
+        if(fTCARandomConesOutRan){
+          for(int ir = 0;ir < fTCARandomConesOutRan->GetEntriesFast();ir++){
+            AliAODJet *jC = (AliAODJet*)fTCARandomConesOutRan->At(ir);  
+            if(jC&&jC->DeltaR(&vTmpRanR)<fRparam){
+              if(vTmpRanR.Pt()>fMaxTrackPtInJet)jC->SetTrigger(AliAODJet::kHighTrackPtTriggered);
+              jC->SetBgEnergy(jC->ChargedBgEnergy()+vTmpRanR.Pt(),0);
+            }
+          }  
+        }
+       }
+     }// loop over recparticles
+    
+     Float_t jetArea = fRparam*fRparam*TMath::Pi();
+     if(fTCARandomConesOut){
+       for(int ir = 0;ir < fTCARandomConesOut->GetEntriesFast();ir++){
+        // rescale the momntum vectors for the random cones
+        
+        AliAODJet *rC = (AliAODJet*)fTCARandomConesOut->At(ir);
+        if(rC){
+          Double_t etaC = rC->Eta();
+          Double_t phiC = rC->Phi();
+          // massless jet, unit vector
+          pTC = rC->ChargedBgEnergy();
+          if(pTC<=0)pTC = 0.001; // for almost empty events
+          Double_t thetaC = 2.*TMath::ATan(TMath::Exp(-etaC));  
+          Double_t pZC = pTC/TMath::Tan(thetaC);
+          Double_t pXC = pTC * TMath::Cos(phiC);
+          Double_t pYC = pTC * TMath::Sin(phiC);
+          Double_t pC  = TMath::Sqrt(pTC*pTC+pZC*pZC); 
+          rC->SetPxPyPzE(pXC,pYC,pZC, pC); 
+          rC->SetBgEnergy(0,0);
+          rC->SetEffArea(jetArea,0);
+        }
+       }
+     }
+     if(fTCARandomConesOutRan){
+       for(int ir = 0;ir < fTCARandomConesOutRan->GetEntriesFast();ir++){
+        AliAODJet* rC = (AliAODJet*)fTCARandomConesOutRan->At(ir);
+        // same wit random
+        if(rC){
+          Double_t etaC = rC->Eta();
+          Double_t phiC = rC->Phi();
+          // massless jet, unit vector
+          pTC = rC->ChargedBgEnergy();
+          if(pTC<=0)pTC = 0.001;// for almost empty events
+          Double_t thetaC = 2.*TMath::ATan(TMath::Exp(-etaC));  
+          Double_t pZC = pTC/TMath::Tan(thetaC);
+          Double_t pXC = pTC * TMath::Cos(phiC);
+          Double_t pYC = pTC * TMath::Sin(phiC);
+          Double_t pC  = TMath::Sqrt(pTC*pTC+pZC*pZC); 
+          rC->SetPxPyPzE(pXC,pYC,pZC, pC); 
+          rC->SetBgEnergy(0,0);
+          rC->SetEffArea(jetArea,0);
+        }
+       }
+     }
+   }// if(fNRandomCones
+  
+   //background estimates:all bckg jets(0) & wo the 2 hardest(1)
+
+
+
+
+   if(fAODJetBackgroundOut){
+     vector<fastjet::PseudoJet> jets2=sortedJets;
+     if(jets2.size()>2) jets2.erase(jets2.begin(),jets2.begin()+2); 
+     Double_t bkg1=0;
+     Double_t sigma1=0.;
+     Double_t meanarea1=0.;
+     Double_t bkg2=0;
+     Double_t sigma2=0.;
+     Double_t meanarea2=0.;
+
+     clustSeq.get_median_rho_and_sigma(jets2, range, true, bkg1, sigma1, meanarea1, true);
+     fAODJetBackgroundOut->SetBackground(0,bkg1,sigma1,meanarea1);
+
+     //     fh1BiARandomCones[0]->Fill(omCone-(bkg1*areaRandomCone));    
+     //  fh1BiARandomConesRan[0]->Fill(ptRandomConeRan-(bkg1*areaRandomCone));    
+     
+     clustSeq.get_median_rho_and_sigma(jets2, range, false, bkg2, sigma2, meanarea2, true);
+     fAODJetBackgroundOut->SetBackground(1,bkg2,sigma2,meanarea2);
+     //  fh1BiARandomCones[1]->Fill(ptRandomCone-(bkg2*areaRandomCone));    
+     //   fh1BiARandomConesRan[1]->Fill(ptRandomConeRan-(bkg2*areaRandomCone));    
+
+   }
+  }
+   
+
+  
+  
+  // fill track information
+  Int_t nTrackOver = recParticles.GetSize();
+  // do the same for tracks and jets
+
+  if(nTrackOver>0){
+   TIterator *recIter = recParticles.MakeIterator();
+   AliVParticle *tmpRec = (AliVParticle*)(recIter->Next());  
+   Float_t pt = tmpRec->Pt();
+
+   //    Printf("Leading track p_t %3.3E",pt);
+   for(int i = 1;i <= fh2NRecTracksPt->GetNbinsX();i++){
+     Float_t ptCut = fh2NRecTracksPt->GetXaxis()->GetBinCenter(i);
+     while(pt<ptCut&&tmpRec){
+       nTrackOver--;
+       tmpRec = (AliVParticle*)(recIter->Next()); 
+       if(tmpRec){
+        pt = tmpRec->Pt();
+       }
+     }
+     if(nTrackOver<=0)break;
+     fh2NRecTracksPt->Fill(ptCut,nTrackOver);
+   }
+   
+   recIter->Reset();
+   AliVParticle *leading = (AliVParticle*)recParticles.At(0);
+   Float_t phi = leading->Phi();
+   if(phi<0)phi+=TMath::Pi()*2.;    
+   Float_t eta = leading->Eta();
+   pt  = leading->Pt();
+   while((tmpRec = (AliVParticle*)(recIter->Next()))){
+     Float_t tmpPt = tmpRec->Pt();
+     Float_t tmpEta = tmpRec->Eta();
+     fh1PtTracksRecIn->Fill(tmpPt);
+     fh2TrackEtaPt->Fill(tmpEta,tmpPt);
+     if(tmpRec==leading){
+       fh1PtTracksLeadingRecIn->Fill(tmpPt);
+       fh2LeadingTrackEtaPt->Fill(tmpEta,tmpPt);
+       continue;
+     }
+      // correlation
+     Float_t tmpPhi =  tmpRec->Phi();
+     
+     if(tmpPhi<0)tmpPhi+=TMath::Pi()*2.;    
+     Float_t dPhi = phi - tmpPhi;
+     if(dPhi>TMath::Pi())dPhi = dPhi - 2.*TMath::Pi();
+     if(dPhi<(-1.*TMath::Pi()))dPhi = dPhi + 2.*TMath::Pi();      
+     Float_t dEta = eta - tmpRec->Eta();
+     fh2TracksLeadingPhiEta->Fill(dPhi,dEta);
+     fh2TracksLeadingPhiPt->Fill(dPhi,pt);
+     fh2TracksLeadingPhiPtW->Fill(dPhi,pt,tmpPt);
+   }  
+   delete recIter;
+ }
+
+ // find the random jets
+
+ fastjet::ClusterSequenceArea clustSeqRan(inputParticlesRecRan, jetDef, areaDef);
+  
+ // fill the jet information from random track
+ const vector <fastjet::PseudoJet> &inclusiveJetsRan = clustSeqRan.inclusive_jets();
+ const vector <fastjet::PseudoJet> &sortedJetsRan    = sorted_by_pt(inclusiveJetsRan);
+
+  fh1NJetsRecRan->Fill(sortedJetsRan.size());
+
+ // loop over all jets an fill information, first on is the leading jet
+
+ Int_t nRecOverRan = inclusiveJetsRan.size();
+ Int_t nRecRan     = inclusiveJetsRan.size();
+
+ if(inclusiveJetsRan.size()>0){
+   AliAODJet leadingJet (sortedJetsRan[0].px(), sortedJetsRan[0].py(), sortedJetsRan[0].pz(), sortedJetsRan[0].E());
+   Float_t pt = leadingJet.Pt();
+   
+   Int_t iCount = 0;
+   TLorentzVector vecarearanb;
+
+   for(int i = 1;i <= fh2NRecJetsPtRan->GetNbinsX();i++){
+     Float_t ptCut = fh2NRecJetsPtRan->GetXaxis()->GetBinCenter(i);
+      while(pt<ptCut&&iCount<nRecRan){
+       nRecOverRan--;
+       iCount++;
+       if(iCount<nRecRan){
+         pt = sortedJetsRan[iCount].perp();
+       }
+      }
+      if(nRecOverRan<=0)break;
+      fh2NRecJetsPtRan->Fill(ptCut,nRecOverRan);
+    }
+    Float_t phi = leadingJet.Phi();
+    if(phi<0)phi+=TMath::Pi()*2.;    
+    pt = leadingJet.Pt();
+
+    // correlation of leading jet with random tracks
+
+    for(unsigned int ip = 0; ip < inputParticlesRecRan.size();ip++)
+      { 
+       Float_t tmpPt = inputParticlesRecRan[ip].perp();
+       // correlation
+       Float_t tmpPhi =  inputParticlesRecRan[ip].phi();
+       if(tmpPhi<0)tmpPhi+=TMath::Pi()*2.;    
+       Float_t dPhi = phi - tmpPhi;
+       if(dPhi>TMath::Pi())dPhi = dPhi - 2.*TMath::Pi();
+       if(dPhi<(-1.*TMath::Pi()))dPhi = dPhi + 2.*TMath::Pi();      
+       fh2TracksLeadingJetPhiPtRan->Fill(dPhi,pt);
+       fh2TracksLeadingJetPhiPtWRan->Fill(dPhi,pt,tmpPt);
+      }  
+
+    Int_t nAodOutJetsRan = 0;
+     AliAODJet *aodOutJetRan = 0;
+    for(int j = 0; j < nRecRan;j++){
+      AliAODJet tmpRec (sortedJetsRan[j].px(), sortedJetsRan[j].py(), sortedJetsRan[j].pz(), sortedJetsRan[j].E());
+      Float_t tmpPt = tmpRec.Pt();
+      fh1PtJetsRecInRan->Fill(tmpPt);
+      // Fill Spectra with constituents
+      const vector<fastjet::PseudoJet> &constituents = clustSeqRan.constituents(sortedJetsRan[j]);
+      fh1NConstRecRan->Fill(constituents.size());
+      fh2NConstPtRan->Fill(tmpPt,constituents.size());
+      fh2PtNchRan->Fill(nCh,tmpPt);
+      fh2PtNchNRan->Fill(nCh,tmpPt,constituents.size());
+
+
+     if(tmpPt>fJetOutputMinPt&&fTCAJetsOutRan){
+       aodOutJetRan =  new ((*fTCAJetsOutRan)[nAodOutJetsRan++]) AliAODJet(tmpRec);
+       Double_t arearan=clustSeqRan.area(sortedJetsRan[j]);
+       aodOutJetRan->GetRefTracks()->Clear();
+       aodOutJetRan->SetEffArea(arearan,0);
+       fastjet::PseudoJet vecarearan=clustSeqRan.area_4vector(sortedJetsRan[j]);  
+       vecarearanb.SetPxPyPzE(vecarearan.px(),vecarearan.py(),vecarearan.pz(),vecarearan.e());
+       aodOutJetRan->SetVectorAreaCharged(&vecarearanb);
+
+     }
+
+      // correlation
+      Float_t tmpPhi =  tmpRec.Phi();
+      if(tmpPhi<0)tmpPhi+=TMath::Pi()*2.;    
+
+      if(j==0){
+       fh1PtJetsLeadingRecInRan->Fill(tmpPt);
+       fh1NConstLeadingRecRan->Fill(constituents.size());
+       fh2NConstLeadingPtRan->Fill(tmpPt,constituents.size());
+       continue;
+      }
+    }  
+
+     
+    if(fAODJetBackgroundOut){
+     Double_t bkg3=0.;
+     Double_t sigma3=0.;
+     Double_t meanarea3=0.;
+     clustSeqRan.get_median_rho_and_sigma(sortedJetsRan ,range, false, bkg3, sigma3, meanarea3, true);
+     fAODJetBackgroundOut->SetBackground(2,bkg3,sigma3,meanarea3);
+     //     float areaRandomCone = rRandomCone2 *TMath::Pi();         
+     /*
+     fh1BiARandomCones[2]->Fill(ptRandomCone-(bkg3*areaRandomCone));    
+     fh1BiARandomConesRan[2]->Fill(ptRandomConeRan-(bkg3*areaRandomCone));    
+     */
+    }
+
+
+
+ }
+
+
+ // do the event selection if activated
+ if(fJetTriggerPtCut>0){
+   bool select = false;
+   Float_t minPt = fJetTriggerPtCut;
+   /*
+   // hard coded for now ...
+   // 54.50 44.5 29.5 18.5 for anti-kt rejection 1E-3
+   if(cent<10)minPt = 50;
+   else if(cent<30)minPt = 42;
+   else if(cent<50)minPt = 28;
+   else if(cent<80)minPt = 18;
+   */
+   float rho = 0;
+   if(externalBackground)rho = externalBackground->GetBackground(2);
+   if(fTCAJetsOut){
+     for(int i = 0;i < fTCAJetsOut->GetEntriesFast();i++){
+       AliAODJet *jet = (AliAODJet*)fTCAJetsOut->At(i);
+       Float_t ptSub = jet->Pt() - rho *jet->EffectiveAreaCharged();
+       if(ptSub>=minPt){
+        select = true;
+        break;
+       }
+     }
+   }   
+   if(select){
+     static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
+     fh1CentralitySelect->Fill(cent);
+     fh1ZSelect->Fill(zVtx);
+     aodH->SetFillAOD(kTRUE);
+   }
+ }
+ if (fDebug > 2){
+   if(fTCAJetsOut)Printf("%s:%d Rec Jets %d",(char*)__FILE__,__LINE__,fTCAJetsOut->GetEntriesFast());
+   if(fTCAJetsOutRan)Printf("%s:%d Rec Jets Ran %d",(char*)__FILE__,__LINE__,fTCAJetsOutRan->GetEntriesFast());
+   if(fTCARandomConesOut)Printf("%s:%d RC %d",(char*)__FILE__,__LINE__,fTCARandomConesOut->GetEntriesFast());
+   if(fTCARandomConesOutRan)Printf("%s:%d RC Ran %d",(char*)__FILE__,__LINE__,fTCARandomConesOutRan->GetEntriesFast());
+ }
+ PostData(1, fHistList);
+}
+
+void AliAnalysisTaskJetCluster::Terminate(Option_t */*option*/)
+{
+// Terminate analysis
+//
+    if (fDebug > 1) printf("AnalysisJetCluster: Terminate() \n");
+}
+
+
+Int_t  AliAnalysisTaskJetCluster::GetListOfTracks(TList *list,Int_t type){
+
+  if(fDebug>2)Printf("%s:%d Selecting tracks with %d",(char*)__FILE__,__LINE__,type);
+
+  Int_t iCount = 0;
+  if(type==kTrackAOD || type==kTrackAODextra || type==kTrackAODextraonly){
+    if(type!=kTrackAODextraonly) {
+      AliAODEvent *aod = 0;
+      if(fUseAODTrackInput)aod = dynamic_cast<AliAODEvent*>(InputEvent());
+      else aod = AODEvent();
+      if(!aod){
+       if(fDebug>2)Printf("%s:%d No AOD",(char*)__FILE__,__LINE__);
+       return iCount;
+      }
+      for(int it = 0;it < aod->GetNumberOfTracks();++it){
+       AliAODTrack *tr = aod->GetTrack(it);
+       Bool_t bGood = false;
+       if(fFilterType == 0)bGood = true;
+       else if(fFilterType == 1)bGood = tr->IsHybridTPCConstrainedGlobal();
+       else if(fFilterType == 2)bGood = tr->IsHybridGlobalConstrainedGlobal();
+       if((fFilterMask>0)&&((!tr->TestFilterBit(fFilterMask)||(!bGood)))){
+         if(fDebug>10)Printf("%s:%d Not matching filter %d/%d %d/%d",(char*)__FILE__,__LINE__,it,aod->GetNumberOfTracks(),fFilterMask,tr->GetFilterMap());     
+         continue;
+       }
+       if(TMath::Abs(tr->Eta())>fTrackEtaWindow){
+         if(fDebug>10)Printf("%s:%d Not matching eta %d/%d",(char*)__FILE__,__LINE__,it,aod->GetNumberOfTracks());     
+         continue;
+       }
+       if(tr->Pt()<fTrackPtCut){
+         if(fDebug>10)Printf("%s:%d Not matching pt %d/%d",(char*)__FILE__,__LINE__,it,aod->GetNumberOfTracks());      
+         continue;
+       }
+       if(fDebug>10)Printf("%s:%d MATCHED %d/%d",(char*)__FILE__,__LINE__,it,aod->GetNumberOfTracks());        
+       list->Add(tr);
+       iCount++;
+      }
+    }
+    if(type==kTrackAODextra || type==kTrackAODextraonly) {
+      AliAODEvent *aod = 0;
+      if(fUseAODTrackInput)aod = dynamic_cast<AliAODEvent*>(InputEvent());
+      else aod = AODEvent();
+      
+      if(!aod){
+       return iCount;
+      }
+      TClonesArray *aodExtraTracks = dynamic_cast<TClonesArray*>(aod->FindListObject("aodExtraTracks"));
+      if(!aodExtraTracks)return iCount;
+      for(int it =0; it<aodExtraTracks->GetEntries(); it++) {
+       AliVParticle *track = dynamic_cast<AliVParticle*> ((*aodExtraTracks)[it]);
+       if (!track) continue;
+
+       AliAODTrack *trackAOD = dynamic_cast<AliAODTrack*> (track);
+       if(!trackAOD)continue;
+       Bool_t bGood = false;
+       if(fFilterType == 0)bGood = true;
+       else if(fFilterType == 1)bGood = trackAOD->IsHybridTPCConstrainedGlobal();
+       else if(fFilterType == 2)bGood = trackAOD->IsHybridGlobalConstrainedGlobal();
+       if((fFilterMask>0)&&((!trackAOD->TestFilterBit(fFilterMask)||(!bGood))))continue;
+        if(TMath::Abs(trackAOD->Eta())>fTrackEtaWindow) continue;
+       if(trackAOD->Pt()<fTrackPtCut) continue;
+       list->Add(trackAOD);
+       iCount++;
+      }
+    }
+  }
+  else if (type ==  kTrackKineAll||type == kTrackKineCharged){
+    AliMCEvent* mcEvent = MCEvent();
+    if(!mcEvent)return iCount;
+    // we want to have alivpartilces so use get track
+    for(int it = 0;it < mcEvent->GetNumberOfTracks();++it){
+      if(!mcEvent->IsPhysicalPrimary(it))continue;
+      AliMCParticle* part = (AliMCParticle*)mcEvent->GetTrack(it);
+      if(type == kTrackKineAll){
+       if(part->Pt()<fTrackPtCut)continue;
+       list->Add(part);
+       iCount++;
+      }
+      else if(type == kTrackKineCharged){
+       if(part->Particle()->GetPDG()->Charge()==0)continue;
+       if(part->Pt()<fTrackPtCut)continue;
+       list->Add(part);
+       iCount++;
+      }
+    }
+  }
+  else if (type == kTrackAODMCCharged || type == kTrackAODMCAll || type == kTrackAODMCChargedAcceptance) {
+    AliAODEvent *aod = 0;
+    if(fUseAODMCInput)aod = dynamic_cast<AliAODEvent*>(InputEvent());
+    else aod = AODEvent();
+    if(!aod)return iCount;
+    TClonesArray *tca = dynamic_cast<TClonesArray*>(aod->FindListObject(AliAODMCParticle::StdBranchName()));
+    if(!tca)return iCount;
+    for(int it = 0;it < tca->GetEntriesFast();++it){
+      AliAODMCParticle *part = (AliAODMCParticle*)(tca->At(it));
+      if(!part->IsPhysicalPrimary())continue;
+      if(type == kTrackAODMCAll){
+       if(part->Pt()<fTrackPtCut)continue;
+       list->Add(part);
+       iCount++;
+      }
+      else if (type == kTrackAODMCCharged || type == kTrackAODMCChargedAcceptance ){
+       if(part->Charge()==0)continue;
+       if(part->Pt()<fTrackPtCut)continue;
+       if(kTrackAODMCCharged){
+         list->Add(part);
+       }
+       else {
+         if(TMath::Abs(part->Eta())>fTrackEtaWindow)continue;
+         list->Add(part);
+       }
+       iCount++;
+      }
+    }
+  }// AODMCparticle
+  list->Sort();
+  return iCount;
+}
+
+/*
+Int_t AliAnalysisTaskJetCluster::AddParticlesFastJet(TList &particles,vector<fastjet::PseudoJet> &inputParticles){
+  for(int i = 0; i < particles.GetEntries(); i++){
+    AliVParticle *vp = (AliVParticle*)particles.At(i);
+    // Carefull energy is not well determined in real data, should not matter for p_T scheme?
+    fastjet::PseudoJet jInp(vp->Px(),vp->Py(),vp->Pz(),vp->E());
+    jInp.set_user_index(i);
+    inputParticles.push_back(jInp);
+  }
+
+  return 0;
+
+}
+*/
diff --git a/JETAN/DEV/AliAnalysisTaskJetCluster.h b/JETAN/DEV/AliAnalysisTaskJetCluster.h
new file mode 100644 (file)
index 0000000..93d7b27
--- /dev/null
@@ -0,0 +1,252 @@
+#ifndef ALIANALYSISTASKJETCLUSTER_H
+#define ALIANALYSISTASKJETCLUSTER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// **************************************
+// task used for comparing different jets D parmaters from fastjet 
+// *******************************************
+
+#include  "AliAnalysisTaskSE.h"
+#include  "THnSparse.h" // cannot forward declare ThnSparseF
+#include "fastjet/ClusterSequenceArea.hh"
+#include "fastjet/AreaDefinition.hh"
+#include "fastjet/JetDefinition.hh"
+#include "fastjet/PseudoJet.hh"
+
+////////////////
+class AliJetHeader;
+class AliESDEvent;
+class AliAODEvent;
+class AliAODExtension;
+class AliAODJet;
+class AliGenPythiaEventHeader;
+class AliCFManager;
+class AliAODJetEventBackground;
+class AliJetFinder;
+class TList;
+class TChain;
+class TH2F;
+class TH1F;
+class TH3F;
+class TProfile;
+class TRandom3;
+class TRefArray;
+class TClonesArray;
+
+class AliAnalysisTaskJetCluster : public AliAnalysisTaskSE
+{
+ public:
+    AliAnalysisTaskJetCluster();
+    AliAnalysisTaskJetCluster(const char* name);
+    virtual ~AliAnalysisTaskJetCluster();
+    // Implementation of interface methods
+    virtual void UserCreateOutputObjects();
+    virtual void Init();
+    virtual void LocalInit() { Init(); }
+    virtual void UserExec(Option_t *option);
+    virtual void Terminate(Option_t *option);
+    virtual Bool_t Notify();
+
+    
+
+    virtual void SetAODTrackInput(Bool_t b){fUseAODTrackInput = b;}
+    virtual void SetAODMCInput(Bool_t b){fUseAODMCInput = b;}
+    virtual void SetEventSelection(Bool_t b){fEventSelection = b;}
+    virtual void SetRecEtaWindow(Float_t f){fRecEtaWindow = f;}
+    virtual void SetTrackEtaWindow(Float_t f){fTrackEtaWindow = f;}
+    virtual void SetTrackTypeGen(Int_t i){fTrackTypeGen = i;}
+    virtual void SetTrackTypeRec(Int_t i){fTrackTypeRec = i;}
+    virtual void SetTrackPtCut(Float_t x){fTrackPtCut = x;}
+    virtual void SetCentralityCut(Float_t xLo,Float_t xUp){fCentCutLo = xLo; fCentCutUp = xUp;}
+    virtual void SetFilterMask(UInt_t i,Int_t iType = 0){fFilterMask = i;
+      fFilterType = iType;}
+    virtual void SetJetTypes(UInt_t i){fJetTypes = i;}
+    virtual void SetJetTriggerPtCut(Float_t x){fJetTriggerPtCut = x;}    
+    virtual void SetVtxCuts(Float_t z,Float_t r = 1){fVtxZCut = z; fVtxR2Cut = r *r;}    
+    virtual void SetBackgroundBranch(const char* c){fBackgroundBranch = c;}
+    virtual const char* GetBackgroundBranch(){return fBackgroundBranch.Data();}    
+    virtual void SetNSkipLeadingRan(Int_t x){fNSkipLeadingRan = x;}
+    virtual void SetNSkipLeadingCone(Int_t x){fNSkipLeadingCone = x;}
+    virtual void SetNRandomCones(Int_t x){fNRandomCones = x;}
+
+    virtual void SetJetOutputBranch(const char *c){fNonStdBranch = c;}
+    virtual const char* GetJetOutputBranch(){return fNonStdBranch.Data();}
+    virtual void SetJetOutputFile(const char *c){fNonStdFile = c;}
+    virtual const char* GetJetOutputFile(){return fNonStdFile.Data();}
+    virtual void SetMaxTrackPtInJet(Float_t x){fMaxTrackPtInJet = x;}
+    virtual void SetJetOutputMinPt(Float_t x){fJetOutputMinPt = x;}
+    virtual void SetBackgroundCalc(Bool_t b){fUseBackgroundCalc = b;} 
+
+
+
+    // for Fast Jet
+    fastjet::JetAlgorithm        GetAlgorithm()         const {return fAlgorithm;}
+    fastjet::Strategy            GetStrategy()          const {return fStrategy;}
+    fastjet::RecombinationScheme GetRecombScheme()      const {return fRecombScheme;}
+    fastjet::AreaType            GetAreaType()          const {return fAreaType;}
+    // Setters
+    void SetRparam(Double_t f)                           {fRparam = f;}
+    void SetAlgorithm(fastjet::JetAlgorithm f)           {fAlgorithm = f;}
+    void SetStrategy(fastjet::Strategy f)                {fStrategy = f;}
+    void SetRecombScheme(fastjet::RecombinationScheme f) {fRecombScheme = f;}
+    void SetAreaType(fastjet::AreaType f)                {fAreaType = f;}
+    void SetGhostArea(Double_t f) {fGhostArea = f;}
+    void SetActiveAreaRepeats(Int_t f) {fActiveAreaRepeats = f;}
+    void SetGhostEtamax(Double_t f) {fGhostEtamax = f;}
+
+
+
+    // Helper
+    //
+
+    // we have different cases
+    // AOD reading -> MC from AOD
+    // ESD reading -> MC from Kinematics
+    // this has to match with our selection of input events
+    enum {kTrackUndef = 0, kTrackAOD, kTrackKineAll,kTrackKineCharged, kTrackAODMCAll, kTrackAODMCCharged, kTrackAODMCChargedAcceptance, kTrackAODextra, kTrackAODextraonly};
+    enum {kMaxJets = 4};
+    enum {kMaxCorrelation =  3};
+    enum {kMaxRadius =       5};
+    enum {kMaxCent =         4};
+    enum {kJet = 1<<0,
+         kJetRan = 1<<1,         
+         kRC = 1<<2,
+         kRCRan = 1<<3
+    };
+    
+
+ private:
+
+    AliAnalysisTaskJetCluster(const AliAnalysisTaskJetCluster&);
+    AliAnalysisTaskJetCluster& operator=(const AliAnalysisTaskJetCluster&);
+
+    Int_t GetListOfTracks(TList *list,Int_t type);
+
+    AliAODEvent     *fAOD;                // ! where we take the jets from can be input or output AOD
+    AliAODExtension *fAODExtension;       // ! AOD extension in case we write a non-sdt branch to a separate file and the aod is standard
+    TRefArray       *fRef;               // ! trefarray for track references within the jet
+    Bool_t        fUseAODTrackInput;      // take track from input AOD not from ouptu AOD
+    Bool_t        fUseAODMCInput;         // take MC from input AOD not from ouptu AOD
+    Bool_t        fUseBackgroundCalc;     // switches on background calculations
+    Bool_t        fEventSelection;        // use the event selection of this task, otherwise analyse all
+    UInt_t        fFilterMask;            // filter bit for slecected tracks
+    UInt_t        fFilterType;            // filter type 0 = all, 1 = ITSTPC, 2 = TPC
+    UInt_t        fJetTypes;              // 1<<0 regular jets, 1<<1 << randomized event 1<<2 random cones 1<<3 random cones randomiuzed evetn
+    Int_t         fTrackTypeRec;          // type of tracks used for FF 
+    Int_t         fTrackTypeGen;          // type of tracks used for FF 
+    Int_t         fNSkipLeadingRan;       // number of leading tracks to be skipped in the randomized event
+    Int_t         fNSkipLeadingCone;      // number of leading jets to be for the random cones
+    Int_t         fNRandomCones;          // number of generated random cones
+    Float_t       fAvgTrials;             // Average nimber of trials
+    Float_t       fExternalWeight;        // external weight
+    Float_t       fTrackEtaWindow;        // eta window used for corraltion plots between rec and gen 
+    Float_t       fRecEtaWindow;          // eta window used for corraltion plots between rec and gen 
+    Float_t       fTrackPtCut;            // minimum track pt to be accepted
+    Float_t       fJetOutputMinPt;        // minimum p_t for jets to be written out
+    Float_t       fMaxTrackPtInJet;       // maximum track pt within a jet for flagging...
+    Float_t       fJetTriggerPtCut;       // minimum jwt pT for AOD to be written
+    Float_t       fVtxZCut;               // zvtx cut
+    Float_t       fVtxR2Cut;              // R vtx cut (squared) 
+    Float_t       fCentCutUp;             // upper limit on centrality
+    Float_t       fCentCutLo;             // lower limit on centrality
+    // output configurartion
+    TString       fNonStdBranch;      // the name of the non-std branch name, if empty no branch is filled
+    TString       fBackgroundBranch;  // name of the branch used for background subtraction
+    TString       fNonStdFile;        // The optional name of the output file the non-std brnach is written to
+    
+
+    // Fast jet
+    Double_t fRparam;
+    fastjet::JetAlgorithm fAlgorithm; //fastjet::kt_algorithm
+    fastjet::Strategy fStrategy;  //= fastjet::Best;
+    fastjet::RecombinationScheme fRecombScheme; // = fastjet::BIpt_scheme;
+    fastjet::AreaType fAreaType; 
+    Double_t fGhostArea;
+    Int_t fActiveAreaRepeats;
+    Double_t fGhostEtamax;
+
+    TClonesArray  *fTCAJetsOut; //! TCA of output jets
+    TClonesArray  *fTCAJetsOutRan; //! TCA of output jets in randomized event
+    TClonesArray  *fTCARandomConesOut; //! TCA of output jets in randomized event
+    TClonesArray  *fTCARandomConesOutRan; //! TCA of output jets in randomized event
+    AliAODJetEventBackground *fAODJetBackgroundOut; //! jet background to be written out
+
+    TRandom3*     fRandom;   //! random number generator
+    TProfile*     fh1Xsec;   //! pythia cross section and trials
+    TH1F*         fh1Trials; //! trials are added
+    TH1F*         fh1PtHard;  //! Pt har of the event...       
+    TH1F*         fh1PtHardNoW;  //! Pt har of the event without weigt       
+    TH1F*         fh1PtHardTrials;  //! Number of trials 
+
+    TH1F*         fh1NJetsRec; //! number of reconstructed jets
+    TH1F*         fh1NConstRec;//! number of constiutens in leading jet
+    TH1F*         fh1NConstLeadingRec;//! number of constiutens in leading jet
+    TH1F*         fh1PtJetsRecIn;  //! Jet pt for all jets
+    TH1F*         fh1PtJetsLeadingRecIn;  //! Jet pt for all jets
+    TH1F*         fh1PtJetConstRec;//! pt of constituents
+    TH1F*         fh1PtJetConstLeadingRec;// pt of constituents
+    TH1F*         fh1PtTracksRecIn;  //! track pt for all tracks
+    TH1F*         fh1PtTracksLeadingRecIn;  //! track pt for all tracks
+
+    // Randomized track histos
+    TH1F*         fh1NJetsRecRan; //! number of reconstructed jets from randomized
+    TH1F*         fh1NConstRecRan;//! number of constiutens in leading jet
+    TH1F*         fh1PtJetsLeadingRecInRan;  //! Jet pt for all jets
+    TH1F*         fh1NConstLeadingRecRan;//! number of constiutens in leading jet
+    TH1F*         fh1PtJetsRecInRan;  //! Jet pt for all jets
+
+    TH1F*         fh1PtTracksGenIn;  //! track pt for all tracks
+    TH1F*         fh1Nch;            //! charged particle mult
+    TH1F*         fh1BiARandomCones[3]; //! Residual distribtion from reandom cones on real event
+    TH1F*         fh1BiARandomConesRan[3]; //! Residual distribtion from reandom cones on random event
+    TH1F*         fh1CentralityPhySel;          // ! centrality of anaylsed events 
+    TH1F*         fh1Centrality;                // ! centrality of anaylsed events 
+    TH1F*         fh1CentralitySelect;          // ! centrality of selected events 
+    TH1F*         fh1ZPhySel;          // ! centrality of anaylsed events 
+    TH1F*         fh1Z;                // ! centrality of anaylsed events 
+    TH1F*         fh1ZSelect;          // ! centrality of selected events 
+
+
+    TH2F*         fh2NRecJetsPt;            //! Number of found jets above threshold
+    TH2F*         fh2NRecTracksPt;          //! Number of found tracks above threshold
+    TH2F*         fh2NConstPt;           //! number of constituents vs. pt
+    TH2F*         fh2NConstLeadingPt;           //! number of constituents vs. pt
+    TH2F*         fh2JetPhiEta;             //! jet phi eta
+    TH2F*         fh2LeadingJetPhiEta;      //! leading jet phi eta
+    TH2F*         fh2JetEtaPt;              //! leading jet eta
+    TH2F*         fh2LeadingJetEtaPt;              //! leading jet eta
+    TH2F*         fh2TrackEtaPt;              //! track eta
+    TH2F*         fh2LeadingTrackEtaPt;       //! leading track eta
+    TH2F*         fh2JetsLeadingPhiEta;     //! jet phi eta
+    TH2F*         fh2JetsLeadingPhiPt;      //! jet correlation with leading jet
+    TH2F*         fh2TracksLeadingPhiEta;   //! track correlation with leading track
+    TH2F*         fh2TracksLeadingPhiPt;    //! track correlation with leading track
+    TH2F*         fh2TracksLeadingJetPhiPt; //! track correlation with leading Jet
+    TH2F*         fh2JetsLeadingPhiPtW;      //! jet correlation with leading jet
+    TH2F*         fh2TracksLeadingPhiPtW;   //! track correlation with leading track
+    TH2F*         fh2TracksLeadingJetPhiPtW; //! track correlation with leading Jet
+    TH2F*         fh2NRecJetsPtRan;            //! Number of found jets above threshold
+    TH2F*         fh2NConstPtRan;           //! number of constituents vs. pt
+    TH2F*         fh2NConstLeadingPtRan;           //! number of constituents vs. pt
+    TH2F*         fh2PtNch;               //! p_T of cluster vs. multiplicity,
+    TH2F*         fh2PtNchRan;            //! p_T of cluster vs. multiplicity,random
+    TH2F*         fh2PtNchN;               //! p_T of cluster vs. multiplicity, weigthed with constituents
+    TH2F*         fh2PtNchNRan;            //! p_T of cluster vs. multiplicity, weigthed with constituents random
+    TH2F*         fh2TracksLeadingJetPhiPtRan; //! track correlation with leading Jet
+    TH2F*         fh2TracksLeadingJetPhiPtWRan; //! track correlation with leading Jet
+
+
+    TH2F*         fh2JetsLeadingPhiPtC[kMaxCent]; //! jet correlation with leading jet    
+    TH2F*         fh2JetsLeadingPhiPtWC[kMaxCent];      //! jet correlation with leading jet
+    TH2F*         fh2TracksLeadingJetPhiPtC[kMaxCent]; //! track correlation with leading Jet
+    TH2F*         fh2TracksLeadingJetPhiPtWC[kMaxCent]; //! track correlation with leading Jet
+
+    TList *fHistList; //!leading tracks to be skipped in the randomized event Output list
+   
+
+    ClassDef(AliAnalysisTaskJetCluster, 20) 
+};
+#endif
diff --git a/JETAN/DEV/AliAnalysisTaskJetsFinder.cxx b/JETAN/DEV/AliAnalysisTaskJetsFinder.cxx
new file mode 100644 (file)
index 0000000..a15cd71
--- /dev/null
@@ -0,0 +1,308 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+//----------------------------------------------------------------
+// Analysis task for interfacing the jet finders with the analysis framework
+//
+// Author: magali.estienne@subatech.in2p3.fr
+//        alexandre.shabetai@cern.ch
+//          
+//----------------------------------------------------------------
+
+#include <Riostream.h> 
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TInterpreter.h>
+#include <TFile.h>
+#include <TList.h>
+#include <TH1.h>
+
+#include "AliAnalysisTaskJetsFinder.h"
+#include "AliAnalysisManager.h"
+#include "AliJetFinder.h"
+#include "AliJetHeader.h"
+#include "AliJetHistos.h"
+#include "AliAODEvent.h"
+#include "AliAODJetEventBackground.h"
+#include "AliAODHandler.h"
+#include "AliAODExtension.h"
+
+ClassImp(AliAnalysisTaskJetsFinder)
+
+////////////////////////////////////////////////////////////////////////
+
+AliAnalysisTaskJetsFinder::AliAnalysisTaskJetsFinder():
+  AliAnalysisTaskSE(),
+  fConfigFile("ConfigJetAnalysis.C"),
+  fNonStdBranch(""), 
+  fNonStdFile(""),
+  fJetFinder(0x0),
+  fHistos(0x0),
+  fAODExtension(0x0),
+  fListOfHistos(0x0),
+  fTreeI(0x0),
+  fEvent(0x0),
+  fUseAODBackground(kFALSE),
+  fFilterPt(0.)
+{
+  // Default constructor
+}
+
+//----------------------------------------------------------------
+AliAnalysisTaskJetsFinder::AliAnalysisTaskJetsFinder(const char* name):
+  AliAnalysisTaskSE(name),
+  fConfigFile("ConfigJetAnalysis.C"),
+  fNonStdBranch(""),
+  fNonStdFile(""),
+  fJetFinder(0x0),
+  fHistos(0x0),
+  fAODExtension(0x0),
+  fListOfHistos(0x0),
+  fTreeI(0x0),
+  fEvent(0x0),
+  fUseAODBackground(kFALSE),
+  fFilterPt(0.)
+{
+  // Constructor 2
+  DefineInput(1, TTree::Class());
+  DefineOutput(1, TList::Class());
+
+}
+
+//----------------------------------------------------------------
+AliAnalysisTaskJetsFinder::~AliAnalysisTaskJetsFinder()
+{
+  // destructor
+  if (fHistos && ! AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fHistos;
+  if (fListOfHistos &&  ! AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fListOfHistos;
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsFinder::ConnectInputData(Option_t *)
+{
+  // Get the exchanged tree and event
+  AliAnalysisTaskSE::ConnectInputData();
+
+  fTreeI = (TTree*)GetInputData(1);
+
+  char **address =(char **)GetBranchAddress(1,"AliJetCalTrkEvent");
+  if (address) {
+    fEvent = (AliJetCalTrkEvent*) (*address);
+  }
+  else { printf("AliJetCalTrkEvent address not found, pleae check containers"); }
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsFinder::UserCreateOutputObjects()
+{
+  // Create the output container containt
+  //
+  if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
+
+  AliJetHeader *fH = fJetFinder->GetJetHeader();
+
+  if(fNonStdBranch.Length()==0)
+    {
+      // Connect default AOD to jet finder
+      // create a new branch for the background
+
+      if(fUseAODBackground){
+        if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
+         AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
+         evBkg->SetName(AliAODJetEventBackground::StdBranchName());
+         AddAODBranch("AliAODJetEventBackground",&evBkg);
+        }
+      }
+      fJetFinder->ConnectAOD(AODEvent());
+    }
+  else
+    {
+      // Create a new branch for jets...
+      // how is this reset? -> cleared in the UserExec....
+      // Can this be handled by the framework?
+      // here we can also have the case that the brnaches are written to a separate file
+
+      TClonesArray *tca = new TClonesArray("AliAODJet", 0);
+      tca->SetName(fNonStdBranch.Data());
+      AddAODBranch("TClonesArray",&tca,fNonStdFile.Data());
+      if(fUseAODBackground){
+        if(!AODEvent() || !AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
+         AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
+         evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
+         AddAODBranch("AliAODJetEventBackground",&evBkg,fNonStdFile.Data());
+        }
+      }
+      if(fNonStdFile.Length()!=0){
+       // 
+       // case that we have an AOD extension we need to fetch the jets from the extended output
+       // we identifay the extension aod event by looking for the branchname
+       AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
+        fAODExtension = 0;
+        if(aodH){
+         TObjArray* extArray = aodH->GetExtensions();
+         if (extArray) {
+           TIter next(extArray);
+           while ((fAODExtension=(AliAODExtension*)next())){
+             TObject *obj = fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data());
+             if(fDebug>10){
+               Printf("%s:%d Dumping..",(char*)__FILE__,__LINE__);
+               fAODExtension->GetAOD()->Dump();
+             }
+             if(obj){
+               if(fDebug>1)Printf("AODExtension found for %s",fNonStdBranch.Data());
+               break;
+             }
+             fAODExtension = 0;
+           }
+         }
+        }
+       if(fAODExtension)fJetFinder->ConnectAODNonStd(fAODExtension->GetAOD(), fNonStdBranch.Data()); 
+      }
+      else{
+        if (fDebug > 1) printf("Connecting Non Std Branch AOD %p %s \n",AODEvent(),fNonStdBranch.Data());
+       fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data()); 
+      }
+    }
+
+  // do not add the histograms in the directory
+  // all handled by the list
+  Bool_t oldStatus = TH1::AddDirectoryStatus();
+  TH1::AddDirectory(kFALSE);
+
+  // Histograms
+  fListOfHistos = new TList();
+  fListOfHistos->SetOwner();
+  fHistos       = new AliJetHistos();
+  fHistos->CreateHistos();
+  fHistos->AddHistosToList(fListOfHistos);
+  // CDF case
+  if(fJetFinder->InheritsFrom("AliCdfJetFinder")) fJetFinder->CreateOutputObjects(fListOfHistos);
+
+  // Add the JetFinderInformation to the Outputlist
+  
+  // Compose a characteristic output name
+  // with the name of the output branch
+  if(fH) {
+    if(fNonStdBranch.Length()==0) {
+      fH->SetName("AliJetHeader_jets");
+    }
+    else {
+      fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
+    }
+  }
+
+  TH1::AddDirectory(oldStatus);
+  
+  if(!fAODExtension)OutputTree()->GetUserInfo()->Add(fH);
+  else fAODExtension->GetTree()->GetUserInfo()->Add(fH);
+
+  // post
+  PostData(1, fListOfHistos);
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsFinder::Init()
+{
+  // Initialization
+  if (fDebug > 1) printf("AnalysisTaskJetsFinder::Init() \n");
+
+  // Call configuration file
+  if (fConfigFile.Length()) {
+    gROOT->LoadMacro(fConfigFile);
+    fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
+  }
+
+  // Initialise Jet Analysis
+  fJetFinder->Init();
+
+}
+
+
+//----------------------------------------------------------------
+Bool_t AliAnalysisTaskJetsFinder::Notify()
+{
+  if (fDebug > 1) printf("AnalysisTaskJetsFinder::Notify() \n");
+  return kTRUE;
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsFinder::UserExec(Option_t */*option*/)
+{
+
+  // Execute analysis for current event
+
+  if (fDebug > 1) printf("AnalysisTaskJetsFinder::UserExec() \n");
+
+  TClonesArray* jarray = 0;
+  AliAODJetEventBackground* evBkg = 0;
+
+  // only need this once
+  static AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
+
+  if(fNonStdBranch.Length()==0) {
+    jarray = AODEvent()->GetJets();
+    if(fUseAODBackground){
+      evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
+      evBkg->Reset();
+    }
+  }
+  else {
+    if(AODEvent())jarray = (TClonesArray*)(AODEvent()->FindListObject(fNonStdBranch.Data()));
+    if(!jarray)jarray = (TClonesArray*)(fAODExtension->GetAOD()->FindListObject(fNonStdBranch.Data()));
+    if(jarray)jarray->Delete();    // this is our responsibility, clear before filling again
+    if(fUseAODBackground){
+      if(AODEvent())evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
+      if(!evBkg)  evBkg = (AliAODJetEventBackground*)(fAODExtension->GetAOD()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
+      if(evBkg)evBkg->Reset();
+    }
+  }
+
+  fTreeI->GetEntry(0);
+
+  fJetFinder->SetCalTrkEvent(*fEvent);
+
+  fJetFinder->ProcessEvent(); 
+
+  // Fill control histos
+  if(jarray)fHistos->FillHistos(jarray);
+
+  // Store the jet branch in the AOD
+  if(jarray&&aodH&&fFilterPt>0){
+    if(jarray->GetEntries()>0){
+      AliAODJet *jet = (AliAODJet*)jarray->At(0);
+      if(jet->Pt()>fFilterPt){
+        aodH->SetFillAOD(kTRUE);
+      }
+    }
+  }
+
+  // Post the data
+  PostData(1, fListOfHistos);
+  return;
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsFinder::Terminate(Option_t */*option*/)
+{
+  // Terminate analysis
+  if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
+
+}
+
diff --git a/JETAN/DEV/AliAnalysisTaskJetsFinder.h b/JETAN/DEV/AliAnalysisTaskJetsFinder.h
new file mode 100644 (file)
index 0000000..6d0540e
--- /dev/null
@@ -0,0 +1,67 @@
+#ifndef ALIANALYSISTASKJETSFINDER_H
+#define ALIANALYSISTASKJETSFINDER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+//----------------------------------------------------------------
+// Analysis task for interfacing the jet finders with the analysis framework
+//
+// Author: magali.estienne@subatech.in2p3.fr 
+//        alexandre.shabetai@cern.ch
+//----------------------------------------------------------------
+#include "AliAnalysisTaskSE.h"
+#include "AliJetCalTrk.h"
+
+class AliJetFinder;
+class AliJetHistos;
+class AliAODExtension;
+class TTree;
+class TString;
+
+class AliAnalysisTaskJetsFinder : public AliAnalysisTaskSE
+{
+ public:
+  AliAnalysisTaskJetsFinder();
+  AliAnalysisTaskJetsFinder(const char* name);
+  virtual             ~AliAnalysisTaskJetsFinder();
+  // Implementation of interface methods
+  virtual void        UserCreateOutputObjects();
+  virtual void        Init();
+  virtual Bool_t      Notify();
+  virtual void        LocalInit() {Init();}
+  virtual void        ConnectInputData(Option_t *);
+  virtual void        UserExec(Option_t *option);
+  virtual void        SetConfigFile(const char *c) {fConfigFile = c;}
+  virtual void        SetJetFinder(AliJetFinder *finder) {fJetFinder = finder;}
+  virtual void        SetNonStdBranch(const char *c){fNonStdBranch = c;}
+  virtual const char* GetNonStdBranch(){return fNonStdBranch.Data();}
+  virtual void        SetNonStdOutputFile(const char *c){fNonStdFile = c;}
+  virtual void        SetBookAODBackground(Bool_t b){fUseAODBackground = b;}
+  virtual void        Terminate(Option_t *option);
+  virtual void        SetFilterPt(Float_t f){fFilterPt = f;}
+    
+  AliJetFinder*       GetJetFinder() {return fJetFinder;}
+
+ private:
+  AliAnalysisTaskJetsFinder(const AliAnalysisTaskJetsFinder &det);
+  AliAnalysisTaskJetsFinder &operator=(const AliAnalysisTaskJetsFinder &det);
+    
+  TString             fConfigFile;        //  The name of the ConfigFile
+  TString             fNonStdBranch;      //  The name of the non-std branch name
+  TString             fNonStdFile;        //  The optional name of the output file the non-std brnach is written to
+  AliJetFinder*       fJetFinder;         //  Pointer to the jet finder 
+  AliJetHistos*       fHistos;            //! Histogram manager class
+  AliAODExtension*    fAODExtension;      //  AOD extension in case we write a non-sdt brnach to a separate file and the aod is standard
+  TList*              fListOfHistos;      //! Output list of histograms
+  TTree*              fTreeI;             //! Input Tree 
+  AliJetCalTrkEvent*  fEvent;             //! Pointer to jet input objects
+  Bool_t              fUseAODBackground;  //  Decide wether we book the backround branch or not
+  Float_t             fFilterPt;          //  Use this as a switch for writing the AOD, minium p_T of leading jet
+
+  ClassDef(AliAnalysisTaskJetsFinder, 1)  // Jet Finder Analysis task
+
+};
+#endif
diff --git a/JETAN/DEV/AliAnalysisTaskJetsReader.cxx b/JETAN/DEV/AliAnalysisTaskJetsReader.cxx
new file mode 100644 (file)
index 0000000..139256b
--- /dev/null
@@ -0,0 +1,151 @@
+/**************************************************************************
+ * 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$ */
+
+//----------------------------------------------------------------
+// Analysis task for interfacing the jet reader with the analysis framework
+//
+// Author: magali.estienne@subatech.in2p3.fr 
+//         alexandre.shabetai@cern.ch
+//----------------------------------------------------------------
+
+#include <Riostream.h> 
+#include <TROOT.h>
+#include <TInterpreter.h>
+#include <TTree.h>
+
+#include "AliAnalysisTaskJetsReader.h"
+#include "AliAnalysisManager.h"
+#include "AliJetReader.h"
+#include "AliAODEvent.h"
+#include "AliMCEvent.h"
+#include "AliJetCalTrk.h"
+
+ClassImp(AliAnalysisTaskJetsReader)
+
+////////////////////////////////////////////////////////////////////////
+
+AliAnalysisTaskJetsReader::AliAnalysisTaskJetsReader():
+  AliAnalysisTaskSE(),
+  fConfigFile("ConfigJetReaderAnalysis.C"),
+  fJetReader(0x0),
+  fReadAODFromOutput(0),
+  fReaderEvent(0x0),
+  fExchangeTree(0x0)
+{
+  // Default constructor
+}
+
+//----------------------------------------------------------------
+AliAnalysisTaskJetsReader::AliAnalysisTaskJetsReader(const char* name):
+  AliAnalysisTaskSE(name),
+  fConfigFile("ConfigJetReaderAnalysis.C"),
+  fJetReader(0x0),
+  fReadAODFromOutput(0),
+  fReaderEvent(0x0),
+  fExchangeTree(0x0)
+{
+  // Default constructor
+  DefineOutput(1, TTree::Class());
+
+}
+
+//----------------------------------------------------------------
+AliAnalysisTaskJetsReader::~AliAnalysisTaskJetsReader()
+{
+  // Destructor
+
+  if (fExchangeTree)
+   delete fExchangeTree;
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsReader::UserCreateOutputObjects()
+{
+  // Create the TTree to be exchanged between the reader and finder
+  //
+   
+  if (fDebug > 1) printf("AnalysisTaskJetsReader::CreateOutPutData() \n");
+
+  fExchangeTree = new TTree("jets_ExchangeContainer","ExchangeTree");
+
+  fJetReader->InitTasks();
+
+  fReaderEvent = fJetReader->GetCalTrkEvent();
+
+  fExchangeTree->Branch("AliJetCalTrkEvent", &fReaderEvent);
+
+  PostData(1, fExchangeTree);
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsReader::Init()
+{
+  // Initialization
+  if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
+  // Call configuration file
+  if (fConfigFile.Length()) {
+    gROOT->LoadMacro(fConfigFile);
+    fJetReader = (AliJetReader*) gInterpreter->ProcessLine("ConfigJetReaderAnalysis()");
+  }
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsReader::UserExec(Option_t */*option*/)
+{
+
+  // Execute analysis for current event
+  //
+
+  // Clear current CalTrkEvent 
+  fReaderEvent->Clear();
+
+  fExchangeTree->Reset();
+
+  // Give InputEvent to the reader
+  if (dynamic_cast<AliAODEvent*>(InputEvent()) !=  0 && !fReadAODFromOutput) {
+    // AOD is input event..........................................V                                       
+    fJetReader->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
+  } else {
+    // AOD is read from output ....................................V     
+    fJetReader->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
+  }
+
+  // Process current event
+  fJetReader->ProcessEvent();
+
+  // Fill object to be exchanged between reader and finder tasks
+  fExchangeTree->Fill();
+
+  // Post the data
+  PostData(1, fExchangeTree);
+
+  return;
+
+}
+
+//----------------------------------------------------------------
+void AliAnalysisTaskJetsReader::Terminate(Option_t */*option*/)
+{
+  // Terminate analysis
+  if (fDebug > 1) printf("AnalysisJets: Terminate() \n");
+
+}
+
diff --git a/JETAN/DEV/AliAnalysisTaskJetsReader.h b/JETAN/DEV/AliAnalysisTaskJetsReader.h
new file mode 100644 (file)
index 0000000..2295b0f
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef ALIANALYSISTASKJETSREADER_H
+#define ALIANALYSISTASKJETSREADER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+//----------------------------------------------------------------
+// Analysis task for interfacing the jet reader with the analysis framework
+//
+// Authors: magali.estienne@subatech.in2p3.fr 
+//         alexandre.shabetai@cern.ch
+//----------------------------------------------------------------
+#include "AliAnalysisTaskSE.h"
+
+class AliJetReader;
+class TTree;
+class TString;
+class AliJetCalTrkEvent;
+
+class AliAnalysisTaskJetsReader : public AliAnalysisTaskSE
+{
+ public:
+  AliAnalysisTaskJetsReader();
+  AliAnalysisTaskJetsReader(const char* name);
+  virtual               ~AliAnalysisTaskJetsReader();
+  // Implementation of interface methods
+  virtual void          UserCreateOutputObjects();
+  virtual void          Init();
+  virtual void          LocalInit() {Init();}
+  virtual void          UserExec(Option_t *option);
+  virtual void          SetConfigFile(const char *c) {fConfigFile = c;}
+  virtual void          SetJetReader(AliJetReader *reader) {fJetReader = reader;}
+  virtual void          Terminate(Option_t *option);
+  virtual void          ReadAODFromOutput() {fReadAODFromOutput = kTRUE;}
+  virtual AliJetReader* GetJetReader() {return fJetReader;}
+    
+ private:
+  AliAnalysisTaskJetsReader(const AliAnalysisTaskJetsReader& rd);
+  AliAnalysisTaskJetsReader& operator = (const AliAnalysisTaskJetsReader& rd);
+  TString               fConfigFile;        //  The name of the ConfigFile
+  AliJetReader*         fJetReader;         //  Pointer to the jet finder
+  Bool_t                fReadAODFromOutput; //  Force reading of the AOD from the output 
+  AliJetCalTrkEvent*    fReaderEvent;       //! Pointer to AliJetCalTrkEvent
+  TTree*               fExchangeTree;      //! Tree of AliJetCalTrkEvent
+  ClassDef(AliAnalysisTaskJetsReader, 1)    // Jet reader Analysis task
+
+};
+#endif
diff --git a/JETAN/DEV/AliAnalysisTaskKMeans.cxx b/JETAN/DEV/AliAnalysisTaskKMeans.cxx
new file mode 100644 (file)
index 0000000..c47df6f
--- /dev/null
@@ -0,0 +1,559 @@
+/**************************************************************************
+ * Copyright(c) 1998-2007, 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$ */
+//---------------------------------------------------------------------------------------
+//     Analysis Task that uses the Soft K-Means Algorithm to find clusters in
+//     the eta-phi space of Minimum Bias. No pt information is used for the clustering.
+//     
+//
+//     Author: Andreas Morsch (CERN)
+//     andreas.morsch@cern.ch
+//---------------------------------------------------------------------------------------
+
+
+
+#include "TChain.h"
+#include "TFile.h"
+#include "TTree.h"
+#include "TH1F.h"
+#include "TH2F.h"
+#include "TProfile.h"
+
+#include "TList.h"
+#include "TParticle.h"
+#include "TParticlePDG.h"
+#include "TProfile.h"
+#include "TMath.h"
+#include "TRandom.h"
+#include "TObjArray.h"
+
+#include "AliAnalysisTask.h"
+#include "AliAnalysisManager.h"
+
+#include "AliVEvent.h"
+#include "AliESDEvent.h"
+#include "AliExternalTrackParam.h"
+#include "AliStack.h"
+#include "AliESDVertex.h"
+#include "AliESDInputHandler.h"
+#include "AliESDtrackCuts.h"
+#include "AliMultiplicity.h"
+
+#include "AliMCParticle.h"
+#include "AliMCEvent.h"
+#include "AliAnalysisTaskKMeans.h"
+#include "AliTrackReference.h"
+#include "AliStack.h"
+#include "AliHeader.h"
+#include "AliKMeansClustering.h"
+
+
+
+ClassImp(AliAnalysisTaskKMeans)
+
+AliAnalysisTaskKMeans::AliAnalysisTaskKMeans() 
+    : AliAnalysisTaskSE()
+    ,fK(0)
+    ,fNMin(0)
+    ,fHists(0)
+    ,fH1CEta(0)
+    ,fH1CPhi(0)
+    ,fH1CEtaR(0)
+    ,fH2N1N2(0)
+    ,fH1Pt(0)
+    ,fH1PtC(0)
+    ,fH1PtC1(0)
+    ,fH1PtC2(0)
+    ,fH1PtAS(0)
+    ,fH1PtR(0)
+    ,fH1SPt(0)
+    ,fH1SPtC(0)
+    ,fH1DPhi(0)
+    ,fH1DR(0)
+    ,fH1DRR(0)
+    ,fH2DPhiEta(0)
+    ,fH2DPhiEtaR(0)
+    ,fH2DPhiEtaL(0)
+    ,fH2DPhiEtaLR(0)
+    ,fH2DPhiEtaC(0)
+    ,fH2DPhiEtaCR(0)
+    ,fH1Resp(0)
+    ,fH1RespR(0)
+    ,fH2Sigma(0)
+    ,fH2SigmaR(0)
+    ,fHDensity(0)
+    ,fHCSize(0)
+    ,fHNCluster(0)
+    ,fHPtDensity(0)
+    ,fHDPhi(0)
+    ,fH2EtaPhi(0)
+    ,fH2REtaPhi(0)
+    ,fCuts(0)
+
+{
+  //
+
+  // Constructor
+  //
+    for (Int_t i=0; i< 10; i++) {
+       fA[i] = 0;
+       fB[i] = 0;
+    }
+}
+
+//________________________________________________________________________
+AliAnalysisTaskKMeans::AliAnalysisTaskKMeans(const char *name) 
+    : AliAnalysisTaskSE(name) 
+      ,fK(0)
+      ,fNMin(0)
+      ,fHists(0)
+      ,fH1CEta(0)
+      ,fH1CPhi(0)
+      ,fH1CEtaR(0)
+      ,fH2N1N2(0)
+      ,fH1Pt(0)
+      ,fH1PtC(0)
+      ,fH1PtC1(0)
+      ,fH1PtC2(0)
+      ,fH1PtAS(0)
+      ,fH1PtR(0)
+      ,fH1SPt(0)
+      ,fH1SPtC(0)
+      ,fH1DPhi(0)
+      ,fH1DR(0)
+      ,fH1DRR(0)
+      ,fH2DPhiEta(0)
+      ,fH2DPhiEtaR(0)
+      ,fH2DPhiEtaL(0)
+      ,fH2DPhiEtaLR(0)
+      ,fH2DPhiEtaC(0)
+      ,fH2DPhiEtaCR(0)
+      ,fH1Resp(0)
+      ,fH1RespR(0)
+      ,fH2Sigma(0)
+      ,fH2SigmaR(0)
+      ,fHDensity(0)
+      ,fHCSize(0)
+      ,fHNCluster(0)
+      ,fHPtDensity(0)
+      ,fHDPhi(0)
+      ,fH2EtaPhi(0)
+      ,fH2REtaPhi(0)
+      ,fCuts(0)
+
+{
+  //
+  // Constructor
+  //
+    for (Int_t i=0; i< 10; i++) {
+       fA[i] = 0;
+       fB[i] = 0;
+    }
+  DefineOutput(1,  TList::Class());
+}
+
+AliAnalysisTaskKMeans::AliAnalysisTaskKMeans(const AliAnalysisTaskKMeans &res)
+: AliAnalysisTaskSE(res) 
+      ,fK(0)
+      ,fNMin(0)
+      ,fHists(0)
+      ,fH1CEta(0)
+      ,fH1CPhi(0)
+      ,fH1CEtaR(0)
+      ,fH2N1N2(0)
+      ,fH1Pt(0)
+      ,fH1PtC(0)
+      ,fH1PtC1(0)
+      ,fH1PtC2(0)
+      ,fH1PtAS(0)
+      ,fH1PtR(0)
+      ,fH1SPt(0)
+      ,fH1SPtC(0)
+      ,fH1DPhi(0)
+      ,fH1DR(0)
+      ,fH1DRR(0)
+      ,fH2DPhiEta(0)
+      ,fH2DPhiEtaR(0)
+      ,fH2DPhiEtaL(0)
+      ,fH2DPhiEtaLR(0)
+      ,fH2DPhiEtaC(0)
+      ,fH2DPhiEtaCR(0)
+      ,fH1Resp(0)
+      ,fH1RespR(0)
+      ,fH2Sigma(0)
+      ,fH2SigmaR(0)
+      ,fHDensity(0)
+      ,fHCSize(0)  
+      ,fHNCluster(0)
+      ,fHPtDensity(0)
+      ,fHDPhi(0)
+      ,fH2EtaPhi(0)
+      ,fH2REtaPhi(0)
+      ,fCuts(0)
+{
+    // Dummy copy constructor
+    for (Int_t i=0; i< 10; i++) {
+       fA[i] = 0;
+       fB[i] = 0;
+    }
+}
+
+AliAnalysisTaskKMeans& AliAnalysisTaskKMeans::operator=(const AliAnalysisTaskKMeans& /*trclass*/)
+{
+    // Dummy assignment operator
+    return *this;
+}
+
+
+
+//________________________________________________________________________
+void AliAnalysisTaskKMeans::UserCreateOutputObjects()
+{
+  // Create histograms
+  // Called once
+    fHists   = new TList();
+    fH1CEta  = new TH1F("fH1CEta",   "eta distribution of clusters",        90, -1.5, 1.5);
+    fH1CEtaR = new TH1F("fH1CEtaR",  "eta distribution of clusters",        90, -1.5, 1.5);
+    fH1CPhi  = new TH1F("fH1CPhi",   "phi distribution of clusters",       157,  0.0, 2. * TMath::Pi());
+    fH2N1N2  = new TH2F("fH2N1N2",   "multiplicity distribution",          50, 0., 50., 50, 0., 50.);
+    
+    fH1Pt    = new TH1F("fH1Pt",     "pt distribution",50, 0., 10.);
+    fH1PtC   = new TH1F("fH1PtC",    "pt distribution",50, 0., 10.);
+    fH1PtC1  = new TH1F("fH1PtC1",   "pt distribution",50, 0., 10.);
+    fH1PtC2  = new TH1F("fH1PtC2",   "pt distribution",50, 0., 10.);
+    fH1PtAS  = new TH1F("fH1PtAS",   "pt distribution",50, 0., 10.);
+    fH1PtR   = new TH1F("fH1PtR",    "pt distribution",50, 0., 10.);
+
+    fH1SPt    = new TH1F("fH1SPt",     "sum pt distribution",50, 0., 10.);
+    fH1SPtC   = new TH1F("fH1SPtC",    "sum pt distribution",50, 0., 10.);
+
+    fH1DR         = new TH1F("fH1DR",     "dR distribution", 50, 0., 5.);
+    fH1DPhi       = new TH1F("fH1DPhi",   "dPhi distribution", 31, 0., TMath::Pi());
+    fH2DPhiEta    = new TH2F("fH2DPhiEta","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
+    fH2DPhiEtaR   = new TH2F("fH2DPhiEtaR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
+    fH2DPhiEtaL   = new TH2F("fH2DPhiEtaL","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
+    fH2DPhiEtaLR  = new TH2F("fH2DPhiEtaLR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
+    fH2DPhiEtaC   = new TH2F("fH2DPhiEtaC","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
+    fH2DPhiEtaCR  = new TH2F("fH2DPhiEtaCR","eta phi distribution", 31, 0., TMath::Pi(), 20, 0., 2.);
+    fH1DRR        = new TH1F("fH1DRR",    "dR distribution", 50, 0., 5.);
+    fH1Resp       = new TH1F("fH1Resp",   "Responsibility", 50, 0., 1.);
+    fH1RespR      = new TH1F("fH1RespR",  "Responsibility", 50, 0., 1.);
+    fH2Sigma      = new TH2F("fH2Sigma",  "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
+    fH2SigmaR     = new TH2F("fH2SigmaR", "Sigma", 31, 0., TMath::Pi(), 20, 0., 2.);
+
+
+    fHDensity    = new TH1F("fHDensity",    "density distribution", 100, 0., 20.);
+    fHCSize      = new TH1F("fHCSize",      "cluster size", 20, -0.5, 19.5);
+
+    fHNCluster   = new TH1F("fHNCluster",   "Number of clusters", 11, -0.5, 10.5);
+    fHPtDensity  = new TH2F("fHPtDensity", "Pt vs density", 100, 0., 20., 50, 0., 10.);
+    fHDPhi       = new TH1F("fHDPhi",   "phi correlation", 100, 0., 0.5);
+    fH2EtaPhi    = new TH2F("fH2EtaPhi", "Eta Phi", 200, -1., 1., 628, 0., 2. * TMath::Pi());  
+    fHists->SetOwner();
+
+    fHists->Add(fH1CEta);
+    fHists->Add(fH1CEtaR);
+    fHists->Add(fH1CPhi);
+    fHists->Add(fH2N1N2);
+    fHists->Add(fH1Pt);
+    fHists->Add(fH1PtR);
+    fHists->Add(fH1PtC);
+    fHists->Add(fH1PtC1);
+    fHists->Add(fH1PtC2);
+    fHists->Add(fH1PtAS);
+    fHists->Add(fH1DR);
+    fHists->Add(fH1SPtC);
+    fHists->Add(fH1SPt);
+    fHists->Add(fH1DPhi);
+    fHists->Add(fH2DPhiEta);
+    fHists->Add(fH2DPhiEtaR);
+    fHists->Add(fH2DPhiEtaL);
+    fHists->Add(fH2DPhiEtaLR);
+    fHists->Add(fH2DPhiEtaC);
+    fHists->Add(fH2DPhiEtaCR);
+    fHists->Add(fH1DRR);
+    fHists->Add(fH1RespR);
+    fHists->Add(fH1Resp);    
+    fHists->Add(fH2Sigma);    
+    fHists->Add(fH2SigmaR);
+    fHists->Add(fHCSize);    
+    fHists->Add(fHDensity);
+    fHists->Add(fHNCluster);
+    fHists->Add(fHPtDensity);
+    fHists->Add(fHDPhi);
+    fHists->Add(fH2EtaPhi);
+    //
+    for (Int_t i = 0; i < 10; i++) {
+      fA[i] = new AliKMeansResult(i+1);
+      fB[i] = new AliKMeansResult(i+1);
+    }
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskKMeans::UserExec(Option_t *) 
+{
+  // Main loop
+  // Called for each event
+    Double_t   phi [500] = {0};
+    Double_t   phiR[500] = {0};
+    Double_t    eta[500] = {0};
+    Double_t   etaR[500] = {0};
+    Double_t    pt [500] = {0};
+
+  if (!fInputEvent) {
+    Printf("ERROR: fESD not available");
+    return;
+  }
+  
+
+  Int_t ic = 0;
+  
+  //
+  // Fill eta-phi positions
+  //
+
+  Double_t ptmax = 0.;
+  Int_t    icmax = -1;
+  
+  for (Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++) {
+      AliVParticle* track = fInputEvent->GetTrack(iTracks);
+      if ((fCuts->AcceptTrack((AliESDtrack*)track))) 
+      {
+       const AliExternalTrackParam * tpcT = ((AliESDtrack*) track)->GetTPCInnerParam();
+       if (!tpcT) continue;
+       if (TMath::Abs(tpcT->Eta()) > 0.9) continue;
+
+         phi [ic] = tpcT->Phi();
+         eta [ic] = tpcT->Eta();
+         pt  [ic] = tpcT->Pt();
+
+         if (fH2REtaPhi) {
+           fH2REtaPhi->GetRandom2(etaR[ic], phiR[ic]);
+         } else {
+           phiR[ic] = 2. * TMath::Pi() * gRandom->Rndm();
+           etaR[ic] = 1.8 * gRandom->Rndm() - 0.9;
+         }
+         
+
+         if (pt[ic] > ptmax) {
+             ptmax = pt[ic];
+             icmax = ic;
+         }
+
+         fH2EtaPhi->Fill(eta[ic], phi[ic]);
+         ic++;
+      }
+  } //track loop 
+
+  for (Int_t i = 0; i < ic; i++) {
+    for (Int_t j = i+1; j < ic; j++) {
+      Double_t dphi = TMath::Abs(phi[i] - phi[j]);
+      fHDPhi->Fill(dphi);
+    }
+  }
+
+  //
+  // Cluster
+  if (ic < fNMin) {
+      PostData(1, fHists);
+      return;
+  }
+
+  //
+  Double_t rk0[10];
+  AliKMeansResult* res = 0;
+  AliKMeansResult best(10);
+  Float_t   rmaxG = -1.;
+
+  for (Int_t k = 0; k < 20; k++) {
+    Float_t   rmax   = -1.;
+    Int_t     imax   = 0;
+    for (Int_t i = 0; i < fK; i++) {
+      res = fA[i];
+      AliKMeansClustering::SoftKMeans2(i+1, ic, phi, eta, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
+      res->Sort(ic, phi, eta);
+      Int_t j = (res->GetInd())[0];
+      rk0[i]  = (res->GetTarget())[j];
+      if (rk0[i] > rmax)  {
+       rmax = rk0[i];
+       imax = i;
+      }
+    }
+    if (rmax > rmaxG) {
+      rmaxG = rmax;
+      best.CopyResults(fA[imax]);
+    }
+  }
+  Double_t* mPhi     = best.GetMx();
+  Double_t* mEta     = best.GetMy();
+  Double_t* sigma2   = best.GetSigma2();
+  Int_t     nk       = best.GetK();
+  Int_t     im       = (best.GetInd())[0];
+  Double_t  etaC     = mEta[im];
+
+  fHDensity->Fill(rmaxG / TMath::Pi());
+  fHCSize->Fill(2.28 * rmaxG * sigma2[im]);
+  fHNCluster->Fill(Float_t(nk));
+
+  Double_t dphic, detac;
+
+  if (rmaxG > 0. && TMath::Abs(etaC) < 0.4) {
+    // Analysis
+    //
+    // Cluster Multiplicity
+    Int_t mult[2] = {0, 0};
+    //
+    if (nk > 1) {
+      dphic = DeltaPhi(mPhi[0], mPhi[1]);
+      detac = TMath::Abs(mEta[0] - mEta[1]);
+      fH2DPhiEtaC->Fill(dphic, detac);  
+    }
+    //
+    // Random cluster position
+    Int_t ir = Int_t(Float_t(ic) * gRandom->Rndm());
+
+    Double_t crPhi = phi[ir];
+    Double_t crEta = eta[ir];
+    //
+    Double_t sumPt  = 0;
+    Double_t sumPtC = 0;
+
+    for (Int_t i = 0; i < 1; i++) {
+      fH1CEta->Fill(mEta[im]);
+      fH1CPhi->Fill(mPhi[im]);      
+      for (Int_t j = 0; j < ic; j++) {
+       Double_t r    = DeltaR(mPhi[im], mEta[im], phi[j], eta[j]);
+       Double_t dphi = DeltaPhi(mPhi[im], phi[j]);
+       Double_t deta = mEta[im] - eta[j];
+       Double_t rr   = DeltaR(crPhi, crEta, phi[j], eta[j]);
+
+       fH1DR->Fill(r);
+       fH1DPhi->Fill(dphi);
+       fH2DPhiEta->Fill(dphi, TMath::Abs(deta));
+       if (j == icmax) fH2DPhiEtaL->Fill(dphi, TMath::Abs(deta));
+       
+       if (r < 0.2) {
+         fH1PtC2->Fill(pt[j]);
+       }
+       if (r < 0.3) {
+         fH1PtC1->Fill(pt[j]);
+         fHPtDensity->Fill(rmaxG/TMath::Pi(), pt[j]);
+       }
+       if (rr < 0.3) {
+           fH1PtR->Fill(pt[j]);
+       }
+
+       if (r < 0.4)  {
+         sumPtC += pt[j];
+         mult[i]++;
+         fH1PtC->Fill(pt[j]);
+       } 
+       if (r > 0.7 && dphi < (TMath::Pi() - 0.3)) {
+         fH1Pt->Fill(pt[j]);
+       }
+       
+       if (r > 0.7 && r < 1.) {
+         sumPt += pt[j];
+       }
+       
+       if (dphi > (TMath::Pi() - 0.3)) {
+         fH1PtAS->Fill(pt[j], 1.);
+       }
+      }
+    }
+
+    fH2N1N2->Fill(Float_t(mult[0]), Float_t(mult[1]));
+    fH1SPt ->Fill(sumPt);
+    fH1SPtC->Fill(sumPtC);
+  }
+    //
+    // Randomized phi
+    //
+  rmaxG = -1.;
+  for (Int_t k = 0; k < 20; k++) {
+    Float_t rmax   = -1.;
+    Int_t   imax   =  0;
+    for (Int_t i = 0; i < fK; i++) {
+      res = fB[i];
+      AliKMeansClustering::SoftKMeans2(i+1, ic, phiR, etaR, res->GetMx(),res->GetMy(), res->GetSigma2(), res->GetRk());
+      res->Sort(ic, phiR, etaR);
+      Int_t j = (res->GetInd())[0];
+      rk0[i]  = (res->GetTarget())[j];
+      if (rk0[i] > rmax) {
+       rmax = rk0[i];
+       imax = i;
+      }
+    }
+    if (rmax > rmaxG) {
+      rmaxG = rmax;
+      best.CopyResults(fB[imax]);
+    }    
+  }
+  
+    mPhi    = best.GetMx();
+    mEta    = best.GetMy();
+    nk      = best.GetK();
+    im      = (best.GetInd())[0];
+    etaC    = mEta[im];    
+
+    //
+    // Cluster Multiplicity
+    if (rmaxG > 0. && TMath::Abs(etaC) < 0.4) {
+      for (Int_t i = 0; i < 1; i++) {
+       im = (best.GetInd())[i];
+       fH1CEtaR->Fill(mEta[im]);
+      }
+      
+      for (Int_t i = 0; i < 1; i++) {
+       im = (best.GetInd())[i];
+       for (Int_t j = 0; j < ic; j++) {
+         Double_t dphi = DeltaPhi(mPhi[im], phiR[j]);
+         Double_t deta = mEta[im] - etaR[j];
+         Double_t r = DeltaR(mPhi[im], mEta[im], phiR[j], etaR[j]);
+         fH1DRR->Fill(r);
+         fH2DPhiEtaR->Fill(dphi, TMath::Abs(deta));
+         if (j == icmax) fH2DPhiEtaLR->Fill(dphi, TMath::Abs(deta));
+       }
+      }
+      if (nk > 1) {
+       dphic = DeltaPhi(mPhi[0], mPhi[1]);
+       detac = TMath::Abs(mEta[0] - mEta[1]);
+       fH2DPhiEtaCR->Fill(dphic, detac);  
+      }
+    }
+    PostData(1, fHists);
+}      
+
+Double_t AliAnalysisTaskKMeans::DeltaPhi(Double_t phi1, Double_t phi2)
+{
+    Double_t dphi = TMath::Abs(phi1 - phi2);
+    if (dphi > TMath::Pi()) dphi = 2. * TMath::Pi() - dphi;
+    return dphi;
+}
+
+Double_t AliAnalysisTaskKMeans::DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2)
+{
+    Double_t dphi = DeltaPhi(phi1, phi2);
+    Double_t deta = eta1 - eta2;
+    return (TMath::Sqrt(dphi * dphi + deta * deta));
+    
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskKMeans::Terminate(Option_t *) 
+{
+}  
+
diff --git a/JETAN/DEV/AliAnalysisTaskKMeans.h b/JETAN/DEV/AliAnalysisTaskKMeans.h
new file mode 100644 (file)
index 0000000..58116b3
--- /dev/null
@@ -0,0 +1,87 @@
+#ifndef ALIANALYSISTASKKMEANS_H
+#define ALIANALYSISTASKKMEANS_H
+ /* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//-------------------------------------------------------------------------
+//     Analysis Task that uses the Soft K-Means Algorithm to find clusters in
+//     the eta-phi space of Minimum Bias. No pt information is used for the clustering.
+//     
+//
+//     Author: Andreas Morsch (CERN)
+//     andreas.morsch@cern.ch
+//-------------------------------------------------------------------------
+
+class TH1F;
+class TH2F;
+class TList;
+class TProfile;
+class AliESDEvent;
+class AliESDtrack;
+class AliESDtrackCuts;
+class AliKMeansResult;
+
+#include "AliAnalysisTaskSE.h"
+
+class AliAnalysisTaskKMeans : public AliAnalysisTaskSE {
+ public:
+  AliAnalysisTaskKMeans();
+  AliAnalysisTaskKMeans(const char *name);
+  AliAnalysisTaskKMeans(const AliAnalysisTaskKMeans &res);
+  AliAnalysisTaskKMeans& operator=(const AliAnalysisTaskKMeans& trclass);
+  virtual ~AliAnalysisTaskKMeans() {}
+  virtual void     UserCreateOutputObjects();
+  virtual void     UserExec(Option_t *option);
+  virtual void     Terminate(Option_t *);
+  virtual void     SetCuts(AliESDtrackCuts* cuts) {fCuts = cuts;}
+  virtual Double_t DeltaPhi(Double_t phi1, Double_t phi2);
+  virtual Double_t DeltaR(Double_t phi1, Double_t eta1, Double_t phi2, Double_t eta2);
+  virtual void     SetK(Int_t k) {fK = k;} 
+  virtual void     SetMinimumMultiplicity(Int_t k) {fNMin = k;} 
+  virtual void     SetEtaPhi(TH2F* h2) {fH2REtaPhi = h2;}
+ private:
+  // Others
+  Int_t            fK;             // K                        
+  Int_t            fNMin;          // Minimum multipicity                         
+  TList*           fHists;         //! Histograms
+  TH1F*            fH1CEta;        //! Eta distribution of clusters
+  TH1F*            fH1CPhi;        //! Phi distribution of clusters  
+  TH1F*            fH1CEtaR;       //! Eta distribution of clusters for rndm evnt
+  TH2F*            fH2N1N2;        //! Cluster sizes 
+  TH1F*            fH1Pt;          //! pt outside clusters
+  TH1F*            fH1PtC;         //! pt outside clusters
+  TH1F*            fH1PtC1;        //! pt dr > 0.4
+  TH1F*            fH1PtC2;        //! pt dr > 0.2 
+  TH1F*            fH1PtAS;        //! away-side peak 
+  TH1F*            fH1PtR;         //! away-side peak 
+  TH1F*            fH1SPt;         //! sum pt
+  TH1F*            fH1SPtC;        //! sum pt
+  TH1F*            fH1DPhi;        //! Dphi wr to cluster
+  TH1F*            fH1DR;          //! DR   wr to cluster
+  TH1F*            fH1DRR;         //! DR   wr to cluster from rndm events   
+  TH2F*            fH2DPhiEta;     //! eta-phi wr to cluster
+  TH2F*            fH2DPhiEtaR;    //! eta-phi wr to cluster for rndm events 
+  TH2F*            fH2DPhiEtaL;    //! eta-phi of leading particle
+  TH2F*            fH2DPhiEtaLR;   //! eta-phi of leading particle
+  TH2F*            fH2DPhiEtaC;    //! eta-phi of Clusters
+  TH2F*            fH2DPhiEtaCR;   //! eta-phi of Clusters
+  TH1F*            fH1Resp;        //! responsibility
+  TH1F*            fH1RespR;       //! responsibility
+  TH2F*            fH2Sigma;       //! sigma
+  TH2F*            fH2SigmaR;      //! sigma random
+  TH1F*            fHDensity;      //! Particle density
+  TH1F*            fHCSize;        //! Cluster Size
+  TH1F*            fHNCluster;     //! Number of clusters
+  TH2F*            fHPtDensity;    //! Pt vs density
+  TH1F*            fHDPhi;         //! Phi Correlation 
+  TH2F*            fH2EtaPhi;      //! eta phi 
+  TH2F*            fH2REtaPhi;     //  eta phi 
+  AliKMeansResult* fA[10];         //! Array of results
+  AliKMeansResult* fB[10];         //! Array of results
+  AliESDtrackCuts* fCuts;          // List of cuts
+  ClassDef(AliAnalysisTaskKMeans, 1); // A k-means clustering analysis
+};
+
+#endif
diff --git a/JETAN/DEV/AliCdfJetFinder.cxx b/JETAN/DEV/AliCdfJetFinder.cxx
new file mode 100644 (file)
index 0000000..a22e6d2
--- /dev/null
@@ -0,0 +1,903 @@
+/**************************************************************************
+ * 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 usec, 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$ */
+
+//---------------------------------------------------------------------
+// Jet Finder based on CDF algortihm
+// Charged jet evolution and the underlying event in proton-antiproton collisions at 1.8 TeV
+// Physical Review D, vol. 65, Issue 9, id. 092002
+// http://www.phys.ufl.edu/~rfield/cdf/chgjet/chgjet_intro.html
+// Authors : Adrian.Sevcenco@cern.ch (adriansev@spacescience.ro )
+//           Daniel.Felea@cern.ch    (dfelea@spacescience.ro)
+//           Ciprian.Mihai.Mitu@cern.ch  (mcm@spacescience.ro)
+//           magali.estienne@subatech.in2p3.fr &
+//           alexandre.shabetai@cern.ch (Modification of the input object (reader/finder splitting))
+// ** 2011
+// Modified accordingly to reader/finder splitting and new handling of neutral information
+//---------------------------------------------------------------------
+
+#include <Riostream.h>
+#include <TMath.h>
+#include <TBits.h>
+#include <TFile.h>
+#include <TH1F.h>
+#include <TProfile.h>
+#include <TVector2.h>
+
+#include "AliAODJet.h"
+#include "AliJetFinder.h"
+#include "AliJetCalTrk.h"
+#include "AliCdfJetFinder.h"
+#include "AliCdfJetHeader.h"
+
+ClassImp(AliCdfJetFinder)
+
+//______________________________________________________________________________
+AliCdfJetFinder::AliCdfJetFinder():
+  AliJetFinder(),
+  fHistos(0),
+  fAODwrite(0),
+  fAODtracksWrite(0),
+  fAnalyseJets(0),
+  fNJets(0),
+  fNPart(0),
+  fNInC(0),
+  fNInN(0),
+  fRadius(0.7),
+  fMinJetParticles(1),
+  fJetPtCut(0.),
+  fVectParticle(NULL),
+  fVectJet(NULL),
+  fPtArray(NULL),
+  fIdxArray(NULL)
+{  
+  // Default constructor
+}
+
+//______________________________________________________________________________
+AliCdfJetFinder::~AliCdfJetFinder()
+{
+  // destructor
+  Clean();
+
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::CreateOutputObjects(TList * const histos)
+{
+  // Create the list of histograms. Only the list is owned.
+  fHistos = histos;
+
+  //  gStyle->SetOptStat(11111111);
+
+  TH1F *h1 = new TH1F ("histo1", "Pt distribution of jets", 200, 0,200);  // 1GeV/bin
+  h1->SetStats(kTRUE);
+  h1->GetXaxis()->SetTitle("P_{T} of jets");
+  h1->GetYaxis()->SetTitle("Number of jets");
+  h1->GetXaxis()->SetTitleColor(1);
+  h1->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h1);
+
+  TH1F *h2 = new TH1F ("histo2", "Eta distribution of jets", 240, -1.2,1.2); // 1 unit of rapidity / 100 bin
+  h2->SetStats(kTRUE);
+  h2->GetXaxis()->SetTitle("Eta of jets");
+  h2->GetYaxis()->SetTitle("Number of jets");
+  h2->GetXaxis()->SetTitleColor(1);
+  h2->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h2);
+
+  TH1F *h3 = new TH1F ("histo3", "Phi distribution of jets", 400, -4,4);
+  h3->SetStats(kTRUE);
+  h3->GetXaxis()->SetTitle("Phi of jets");
+  h3->GetYaxis()->SetTitle("Number of jets");
+  h3->GetXaxis()->SetTitleColor(1);
+  h3->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h3);
+
+  TH1F *h4 = new TH1F ("histo4", "Multiplicity of jets", 40, 0,40);  // 1 unit of multiplicity /bin
+  h4->SetStats(kTRUE);
+  h4->GetXaxis()->SetTitle("Particles in jets");
+  h4->GetYaxis()->SetTitle("Number of jets");
+  h4->GetXaxis()->SetTitleColor(1);
+  h4->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h4);
+
+  TH1F *h5 = new TH1F ("histo5", "Distribution of jets in events", 100, 0,100);
+  h5->SetStats(kTRUE);
+  h5->GetXaxis()->SetTitle("Number of jets");
+  h5->GetYaxis()->SetTitle("Number of events");
+  h5->GetXaxis()->SetTitleColor(1);
+  h5->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h5);
+
+  TH1F *h6 = new TH1F ("histo6", "Jet1 Charged Multiplicity Distribution", 30, 0,30);
+  h6->SetStats(kTRUE);
+  h6->GetXaxis()->SetTitle("N_{chg}");
+  h6->GetYaxis()->SetTitle("Number of jets");
+  h6->GetXaxis()->SetTitleColor(1);
+  h6->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h6);
+
+  TProfile * h7 = new TProfile ("histo7","N_{chg}(jet1) vs P_{T}(charged jet1)", 200, 0. ,200. , 0.,200. ) ;
+  h7->SetStats(kTRUE);
+  h7->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h7->GetYaxis()->SetTitle("<N_{chg}(jet1)> in 1 GeV/c bin");
+  h7->GetXaxis()->SetTitleColor(1);
+  h7->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h7);
+
+  TH1F *h8 = new TH1F ("histo8", "Charge momentum distribution for leading jet", 120, 0 , 1.2);
+  h8->SetStats(kTRUE);
+  h8->GetXaxis()->SetTitle("Jets");
+  h8->GetYaxis()->SetTitle("Particle distribution");
+  h8->GetXaxis()->SetTitleColor(1);
+  h8->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h8);
+
+  TProfile *h9 = new TProfile ("histo9", "N_{chg} vs the Azimuthal Angle from Charged Jet1", 50 , 0. , 180. , 0 , 20 );
+  h9->SetStats(kTRUE);
+  h9->GetXaxis()->SetTitle("#Delta#phi (degrees)");
+  h9->GetYaxis()->SetTitle("<N_{chg}> in 3.6 degree bin");
+  h9->GetXaxis()->SetTitleColor(1);
+  h9->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h9);
+
+  TProfile *h10 = new TProfile ("histo10", "P_{T} sum vs the Azimuthal Angle from Charged Jet1", 50 , 0. , 180. , 0 , 100 );
+  h10->SetStats(kTRUE);
+  h10->GetXaxis()->SetTitle("#Delta#phi (degrees)");
+  h10->GetYaxis()->SetTitle("<P_{T} sum> in 3.6 degree bin");
+  h10->GetXaxis()->SetTitleColor(1);
+  h10->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h10);
+
+  TH1F *h11 = new TH1F ("histo11", " \"Transverse\" Pt Distribution ", 70, 0 , 14);
+  h11->SetStats(kTRUE);
+  h11->GetXaxis()->SetTitle("P_{T} (GeV/c)");
+  h11->GetYaxis()->SetTitle("dN_{chg}/dP_{T} (1/GeV/c)");
+  h11->GetXaxis()->SetTitleColor(1);
+  h11->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h11);
+
+  TH1F *h20 = new TH1F ("histo20", "Distribution of R in leading jet", 400, 0.,4.);
+  h20->SetStats(kTRUE);
+  h20->GetXaxis()->SetTitle("R [formula]");
+  h20->GetYaxis()->SetTitle("dN/dR");
+  h20->GetXaxis()->SetTitleColor(1);
+  h20->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h20);
+
+  TProfile * h21 = new TProfile ("histo21","N_{chg}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0., 50. , 0., 30. ) ;
+  h21->SetStats(kTRUE);
+  h21->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h21->GetYaxis()->SetTitle("<N_{chg}(in the event - including jet1)> in 1 GeV/c bin");
+  h21->GetXaxis()->SetTitleColor(1);
+  h21->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h21);
+
+  TProfile * h22 = new TProfile ("histo22","PT_{sum}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0. , 50. , 0., 50. ) ;
+  h22->SetStats(kTRUE);
+  h22->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h22->GetYaxis()->SetTitle("<PT_{sum}(in the event - including jet1)> in 1 GeV/c bin");
+  h22->GetXaxis()->SetTitleColor(1);
+  h22->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h22);
+
+  TProfile * h21Toward = new TProfile ("histo21_toward","N_{chg}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0., 50. , 0., 12. ) ;
+  h21Toward->SetStats(kTRUE);
+  h21Toward->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h21Toward->GetYaxis()->SetTitle("<N_{chg}(in the event - including jet1)> in 1 GeV/c bin");
+  h21Toward->GetXaxis()->SetTitleColor(1);
+  h21Toward->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h21Toward);
+
+  TProfile * h21Transverse = new TProfile ("histo21_transverse","N_{chg}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0., 50. , 0., 12. ) ;
+  h21Transverse->SetStats(kTRUE);
+  h21Transverse->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h21Transverse->GetYaxis()->SetTitle("<N_{chg}(in the event - including jet1)> in 1 GeV/c bin");
+  h21Transverse->GetXaxis()->SetTitleColor(1);
+  h21Transverse->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h21Transverse);
+
+  TProfile * h21Away = new TProfile ("histo21_away","N_{chg}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0., 50. , 0., 12. ) ;
+  h21Away->SetStats(kTRUE);
+  h21Away->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h21Away->GetYaxis()->SetTitle("<N_{chg}(in the event - including jet1)> in 1 GeV/c bin");
+  h21Away->GetXaxis()->SetTitleColor(1);
+  h21Away->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h21Away);
+
+  TProfile * h22Toward = new TProfile ("histo22_toward","PT_{sum}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0. , 50. , 0., 50. ) ;
+  h22Toward->SetStats(kTRUE);
+  h22Toward->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h22Toward->GetYaxis()->SetTitle("<PT_{sum}(in the event - including jet1)> in 1 GeV/c bin");
+  h22Toward->GetXaxis()->SetTitleColor(1);
+  h22Toward->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h22Toward);
+
+  TProfile * h22Transverse = new TProfile ("histo22_transverse","PT_{sum}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0. , 50. , 0., 50. ) ;
+  h22Transverse->SetStats(kTRUE);
+  h22Transverse->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h22Transverse->GetYaxis()->SetTitle("<PT_{sum}(in the event - including jet1)> in 1 GeV/c bin");
+  h22Transverse->GetXaxis()->SetTitleColor(1);
+  h22Transverse->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h22Transverse);
+
+  TProfile * h22Away = new TProfile ("histo22_away","PT_{sum}(in the event - including jet1) vs P_{T}(charged jet1)", 200, 0. , 50. , 0., 50. ) ;
+  h22Away->SetStats(kTRUE);
+  h22Away->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h22Away->GetYaxis()->SetTitle("<PT_{sum}(in the event - including jet1)> in 1 GeV/c bin");
+  h22Away->GetXaxis()->SetTitleColor(1);
+  h22Away->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h22Away);
+
+  TH1F *h23Toward = new TH1F ("histo23_toward","'Toward' Pt Distribution of charged particles", 200, 0., 14.);
+  h23Toward->SetStats(kTRUE);
+  h23Toward->GetXaxis()->SetTitle("P_{T} (charged) (GeV/c)");
+  h23Toward->GetYaxis()->SetTitle("dN_{chg}/dP_{T} (1/GeV/c)");
+  h23Toward->GetXaxis()->SetTitleColor(1);
+  h23Toward->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h23Toward);
+
+  TH1F *h23Transverse = new TH1F ("histo23_transverse","'Transverse' Pt Distribution of charged particles", 200, 0., 14.);
+  h23Transverse->SetStats(kTRUE);
+  h23Transverse->GetXaxis()->SetTitle("P_{T} (charged) (GeV/c)");
+  h23Transverse->GetYaxis()->SetTitle("dN_{chg}/dP_{T} (1/GeV/c)");
+  h23Transverse->GetXaxis()->SetTitleColor(1);
+  h23Transverse->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h23Transverse);
+
+  TH1F *h23Away = new TH1F ("histo23_away","'Away' Pt Distribution of charged particles", 200, 0., 14.);
+  h23Away->SetStats(kTRUE);
+  h23Away->GetXaxis()->SetTitle("P_{T} (charged) (GeV/c)");
+  h23Away->GetYaxis()->SetTitle("dN_{chg}/dP_{T} (1/GeV/c)");
+  h23Away->GetXaxis()->SetTitleColor(1);
+  h23Away->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h23Away);
+
+  TProfile * h24 = new TProfile ("histo24","Jet1 Size vs P_{T}(charged jet1)", 200, 0., 50. , 0., 0.5) ;
+  h24->SetStats(kTRUE);
+  h24->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h24->GetYaxis()->SetTitle("<R(chgjet1)> in 1 GeV/c bin");
+  h24->GetXaxis()->SetTitleColor(1);
+  h24->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h24);
+
+  TProfile * h25 = new TProfile ("histo25","Jet1 Size vs P_{T}(charged jet1)", 200, 0., 50. , 0., 0.5) ;
+  h25->SetStats(kTRUE);
+  h25->GetXaxis()->SetTitle("P_{T} (charged jet1) (GeV/c)");
+  h25->GetYaxis()->SetTitle("<R(chgjet1)> in 1 GeV/c bin");
+  h25->GetXaxis()->SetTitleColor(1);
+  h25->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h25);
+
+  TProfile *h26 = new TProfile ("histo26", "N_{chg} vs the Distance R from Charged Jet1", 30, 0., 0.6, 0., 0.8);
+  h26->SetStats(kTRUE);
+  h26->GetXaxis()->SetTitle("Distance R");
+  h26->GetYaxis()->SetTitle("<N_{chg}> in 0.02 bin");
+  h26->GetXaxis()->SetTitleColor(1);
+  h26->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h26);
+
+  TProfile *h27 = new TProfile ("histo27", "N_{chg} vs the Distance R from Charged Jet1", 30, 0., 0.6, 0., 0.8);
+  h27->SetStats(kTRUE);
+  h27->GetXaxis()->SetTitle("Distance R");
+  h27->GetYaxis()->SetTitle("<N_{chg}> in 0.02 bin");
+  h27->GetXaxis()->SetTitleColor(1);
+  h27->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h27);
+
+  TProfile *h28 = new TProfile ("histo28", "PT_{sum} vs the Distance R from Charged Jet1", 30, 0., 0.6, 0.01, 10.);
+  h28->SetStats(kTRUE);
+  h28->GetXaxis()->SetTitle("Distance R");
+  h28->GetYaxis()->SetTitle("<PT_{sum} (GeV/c)> in 0.02 bin");
+  h28->GetXaxis()->SetTitleColor(1);
+  h28->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h28);
+
+  TProfile *h29 = new TProfile ("histo29", "PT_{sum} vs the Distance R from Charged Jet1", 30, 0., 0.6, 0.01, 10.);
+  h29->SetStats(kTRUE);
+  h29->GetXaxis()->SetTitle("Distance R");
+  h29->GetYaxis()->SetTitle("<PT_{sum} (GeV/c)> in 0.02 bin");
+  h29->GetXaxis()->SetTitleColor(1);
+  h29->SetMarkerStyle(kFullCircle);
+  fHistos->Add(h29);
+
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::FindJets()
+{
+  // Jet Algorithm:
+  //  * Order all charged particles according to their PT.
+  //  * Start with the highest PT particle and include in the "jet" all particles within the "radius" R = 0.7
+  //     (considering each particle in the order of decreasing PT and recalculating the centroid of the jet after
+  //     each new particle is added to the jet).
+  //  * Go to the next highest PT particle (not already included in a jet) and include in the "jet" all particles
+  //     (not already included in a jet) within the radius R =0.7.
+  //  * Continue until all particles are in a "jet".
+  if (fDebug) { printf("AliCDJetfinder::FindJets() %d \n", __LINE__ ); }
+  AliCdfJetHeader *header = (AliCdfJetHeader*)fHeader;
+
+  if (header)
+    {
+      fDebug            = header->GetDebug();
+      fAODwrite         = header->IsAODwrite() ;       // write jets to AOD
+      fAODtracksWrite   = header->IsAODtracksWrite() ; // write jet tracks to AOD
+      fRadius           = header->GetRadius();      // get Radius from jet finder header
+      fMinJetParticles  = header->GetMinPartJet (); // get minimum multiplicity of an jet
+      fJetPtCut         = header->GetJetPtCut ();   // get minimum of jet pt
+      fAnalyseJets      = header->GetAnalyseJets(); // get analyse jet
+    }
+  else
+    { cout << "Header not found" << endl; return; }
+
+  InitData();
+
+  if (!fNPart) { 
+    if (fDebug) {
+      cout << "entries = 0 ; Event empty !!!" << endl ;
+    }
+    // no need to call clean, InitData does not 
+    // create pointers if npart == 0
+    return; 
+  } // if event empty then exit
+
+  FindCones();
+  ComputeConesWeight();
+  if (fAODwrite) { 
+    if(fDebug)cout << "Writing AOD" << endl ; 
+    WriteJets();
+  }
+  if (fAnalyseJets) AnalizeJets();
+  Clean();
+
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::InitData()
+{
+  // initialisation of variables and data members
+
+  if( fHeader->GetDebug() && fCalTrkEvent->GetNCalTrkTracks()  == 0) { cout << "No charged tracks found" << endl; }
+
+  fNPart = fCalTrkEvent->GetNCalTrkTracks() ;
+
+  if ( fCalTrkEvent->GetNCalTrkTracks() ) { return; } // if event empty then exit
+
+  fVectParticle = new varContainer* [fNPart]; // container for Particles
+
+  fPtArray  = new Double_t [fCalTrkEvent->GetNCalTrkTracks()] ; 
+  fIdxArray = new Int_t    [fCalTrkEvent->GetNCalTrkTracks()] ; // index array of sorted pts
+
+  // initialisation of momentum and index arrays
+  for (  Int_t i = 0 ; i <fCalTrkEvent->GetNCalTrkTracks() ; i++ )
+    {// SORTING STEP :: fPtArray with data from CalTrkTracks
+
+      // INITIALISATION of local arrays for temporary storage
+      varContainer *aParticle = new varContainer;
+      aParticle->pt   = fCalTrkEvent->GetCalTrkTrack(i)->GetPt();
+      aParticle->eta  = fCalTrkEvent->GetCalTrkTrack(i)->GetEta();
+      aParticle->phi  = TVector2::Phi_mpi_pi ( fCalTrkEvent->GetCalTrkTrack(i)->GetPhi() ); // normalize to -pi,pi
+      aParticle->njet = -999;
+
+      fVectParticle[i] = aParticle;  // vector of Particles
+
+      // initializing arrays
+      fIdxArray [i] = -999 ;
+      fPtArray [i] = aParticle->pt ;
+    }
+
+  TMath::Sort ( fNPart, fPtArray, fIdxArray ) ; // get a sorted array of indexes
+
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::FindCones()
+{
+  // parsing of particles in event and estlabish jets (label them with jet index)
+
+  Double_t  ptSeed = 0. , etaSeed = 0. , phiSeed = 0. ; // leading particle params
+  Double_t pttmp = 0. , etatmp = 0. , phitmp = 0. ; // temporary variables to be used in various calculations
+  Double_t deta = 0. , dphi = 0. , dcomputed = 0. ;
+  Bool_t injet = 0 ;
+
+  fNJets = -1 ; // n jets in this event
+  Int_t idxPtSort = -1 ;  // index of array of sorted pt indexes
+
+  if (fDebug) { cout << "\n\n\n\n\n\n------------------\nBegin Event Analysis\n------------------\n\n" << endl ;}
+
+  if(fDebug)cout << "fNPart = " << fNPart << endl;
+
+  TBits lkupTable ( fNPart ) ;  // bit container ; 1-to-1 corespondence with fIdxArray
+
+  while ( lkupTable.CountBits() != (UInt_t)fNPart )
+    { // loop over particles in event until all flags are set
+      UInt_t firstnonflagged = lkupTable.FirstNullBit() ; // set the index to the first NON flagged bit ; less conditions
+
+      if(fDebug)cout << "\n\nfirst_non_flagged : " << firstnonflagged << endl;
+
+      ++fNJets; // incrementing the jet counter
+      if (fDebug) { printf("JET %d \n", fNJets); }
+
+      ptSeed = 0. ; etaSeed = 0. ; phiSeed = 0. ;  // reseting leading particle params
+
+      for (  UInt_t ipart = firstnonflagged ; ipart < (UInt_t)fNPart ; ipart++ )
+       {// iteration over particles in event
+         // the loop is done over sorted array of pt
+         idxPtSort = fIdxArray[ipart] ;  // index of particle ! fIdxArray is an index list pt sorted
+
+         if ( lkupTable.TestBitNumber(ipart) ) { continue; } // if 4vector is already flagged skip it
+
+         //init computed and used vars
+         pttmp = 0. ; etatmp = 0. ; phitmp = 0. ;
+         deta = 0. ; dphi = 0. ; dcomputed = 0. ; injet = 0 ;
+
+         //taking info from fVectParticle ;
+         pttmp = fVectParticle[idxPtSort]->pt ;
+         etatmp = fVectParticle[idxPtSort]->eta ;
+         phitmp = fVectParticle[idxPtSort]->phi ;
+
+         if ( ipart == firstnonflagged )
+           {// this is first particle in event; leading particle
+             // begin the search around this particle in a fRadius
+
+             // CENTRE OF THE JET
+             ptSeed = pttmp ; etaSeed = etatmp ; phiSeed = phitmp ; // seeding the jet with first particle idxPtSort
+
+             lkupTable.SetBitNumber ( ipart ) ; // flag the index of particle in lkup_table
+             fVectParticle[idxPtSort]->njet = fNJets ; // associate particle with current jet number
+
+             if (fDebug) { printf("\nLeading particle :: particle index = %d ;  at sorted index %d ; in jet %d \n", idxPtSort, ipart, fNJets); }
+             if (fDebug) { printf("pt= %g ; eta= %g ; phi = %g \n", pttmp, etatmp, phitmp) ; }
+             if (fDebug) { lkupTable.Print() ;}
+
+             continue ; // skip to next particle
+           }
+
+         // condition to be in jet
+         deta = etatmp - etaSeed ;
+         dphi = TVector2::Phi_mpi_pi (phitmp - phiSeed) ; // computing dphi and normalizing to (0,2pi) interval in one step
+
+         dcomputed = TMath::Hypot(deta, dphi) ; // Distance(fRadius) to (eta,phi) seed
+
+         injet = ( ( fRadius - dcomputed ) >= 0.000000001 ) ? 1 : 0 ; // if r_computed is within jet_r in_jet == 1 else 0
+
+         if ( injet )
+           { // calculus of jet variables
+             lkupTable.SetBitNumber ( ipart ) ;  // flag the index of particle in lkup_table
+             fVectParticle[idxPtSort]->njet = fNJets ; // setting in particle list the associated jet
+
+             if (fDebug) { printf("\njet particle :: particle index = %d ; at sorted index %d ; in jet %d ; found at radius %g ;  \n", idxPtSort, ipart, fNJets, dcomputed); }
+             if (fDebug) { printf("pt= %g ; eta= %g ; phi = %g \n", pttmp, etatmp, phitmp) ; }
+             if (fDebug) { lkupTable.Print() ;}
+
+             continue ; // skip to next particle
+           }
+
+       }
+      // end of iteration over event; one jet definition of content ; jet parameters to be computed later
+    }
+
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::ComputeConesWeight()
+{
+  // computing of jets Pt, Eta and Phi (centre of weight in (eta,phi) plane)
+  // rescan the vector of particles by identify them by asociate jet number for computing of weight centre
+
+  // JET CONTAINER
+  fVectJet      = new varContainer* [fNJets]; // container for Jets
+
+  Double_t ptJet, ptJet2 , etaJet , phiJet ; Int_t npartJet ;
+  Double_t pttmp = 0. , etatmp = 0. , phitmp = 0. ; // temporary variables to be used in various calculations
+  Int_t idxPtSort = -999 ;  // index of array of sorted pt indexes
+
+  for(  Int_t jet = 0 ; jet < fNJets ; jet++ )
+    {
+      if (fDebug) { printf("\n\n--- Computing weight of Jet %d \n", jet ); }
+      npartJet = 0 ; ptJet = 0. ; etaJet = 0. ; phiJet = 0. ; // reset variables for a new computation
+
+      for (  Int_t ipart = 0 ; ipart < fNPart ; ipart++ )
+       {// iteration over particles in event
+         // the loop is done over sorted array of pt
+         idxPtSort = fIdxArray[ipart] ;  // index of particle ! fIdxArray is an index list pt sorted
+
+         if ( fVectParticle[idxPtSort]->njet == jet )
+           {
+             ++npartJet; // incrementing the counter of jet particles
+
+             //taking info from fVectParticle ;
+             pttmp = fVectParticle[idxPtSort]->pt ;
+             etatmp = fVectParticle[idxPtSort]->eta ;
+             phitmp = TVector2::Phi_mpi_pi (fVectParticle[idxPtSort]->phi) ;
+
+             //      jet_new_angular_coordinate = jet_old_angular_coordinate * jet_old_pt / jet_new_pt +
+             //                                    part[i]_angular_coordinate * part[i]_pt/jet_new_pt
+
+             ptJet2 = ptJet + pttmp ;
+
+             etaJet = etaJet * ptJet / ptJet2 +  etatmp * pttmp / ptJet2 ;
+             phiJet = phiJet * ptJet / ptJet2 +  phitmp * pttmp / ptJet2 ;
+
+             ptJet = ptJet2 ;
+
+           }
+         // add a particle and recalculation of centroid
+       }
+      // end of 1 jet computation
+
+      varContainer *aJet = new varContainer;  // Jet container
+      aJet->pt = ptJet; aJet->eta = etaJet; aJet->phi = phiJet; aJet->njet = npartJet; // setting jet vars in container
+      fVectJet[jet] = aJet;   // store the number of the jet(fNJets) and increment afterwards
+
+      if (fDebug) { printf ("=== current jet %d : npartjet= %d ; pt_jet= %g ; eta_jet = %g ; phi_jet = %g \n\n\n",
+                           jet,     npartJet,      ptJet,      etaJet,       phiJet ) ; }
+
+    }
+  //end loop over jets
+
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::WriteJets()  
+{ 
+  // Writing AOD jets and AOD tracks
+
+  for(  Int_t jetnr = 0 ; jetnr < fNJets ; jetnr++ )
+    {
+      Double_t pt = 0., eta = 0., phi = 0., // jet variables
+       px = 0., py = 0., pz = 0., en = 0.; // convert to 4-vector
+      pt  = fVectJet[ jetnr ]->pt   ; // pt  of jet
+      eta = fVectJet[ jetnr ]->eta  ; // eta of jet
+      phi = fVectJet[ jetnr ]->phi  ; // phi of jet
+
+      px = pt * TMath::Cos ( phi ) ;
+      py = pt * TMath::Sin ( phi ) ;
+      pz = pt / TMath::Tan ( 2.0 * TMath::ATan ( TMath::Exp ( -eta ) ) ) ;
+      en = TMath::Sqrt ( px * px + py * py + pz * pz );
+
+      AliAODJet jet (px, py, pz, en);
+
+
+      if (fDebug) jet.Print("");
+
+      if (fAODtracksWrite)
+       {
+         for (  Int_t jetTrack = 0; jetTrack < fCalTrkEvent->GetNCalTrkTracks(); jetTrack++ )
+           {
+             // The first if condition below has to be checked
+             if ( fVectParticle[jetTrack]->njet == jetnr ) { jet.AddTrack(fCalTrkEvent->GetCalTrkTrack(jetTrack)->GetTrackObject()) ; }
+           }
+       }
+      // tracks REFs written in AOD
+      AddJet(jet);
+
+    }
+  //jets vector parsed and written to AOD
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::AnalizeJets()
+{
+  // analyzing of jets and filling of histograms
+
+  const Double_t kPI = TMath::Pi();
+    
+  //persistent pointer to histo20
+  TH1F *hR = (TH1F*)fHistos->FindObject("histo20");
+
+  Int_t   *jetsptidx = 0;     // sorted array of jets pt
+  Double_t    *jetspt = 0;     // array of jets pts
+  Int_t leadingjetindex = -1 ;   // index of leading jet from fVectJet
+  Int_t partleadjet = 0 ; // number of particles in leading jet
+  Double_t   ptleadjet = 0. ; // pt  of leading jet
+  Double_t  etaleadjet = 0. ; // eta of leading jet
+  Double_t  phileadjet = 0. ; // phi of leading jet
+
+  jetsptidx = new Int_t    [fNJets] ;
+  jetspt    = new Double_t [fNJets] ;
+
+  //________________________________________________________________________________________
+  //  Jet sorting and finding the leading jet that coresponds to cuts in pt and multiplicity
+  //________________________________________________________________________________________
+
+  // filing the idx_ptjets array
+  if (fDebug) printf("List of unsorted jets:\n");
+  for(  Int_t i = 0 ; i < fNJets ; i++ )
+    {
+      jetsptidx [i] = 0 ;
+      jetspt    [i] = fVectJet[i]->pt ;
+      if (fDebug) { cout << "   jet found: " << i << " npartjet=" << fVectJet[i]->njet << " ; jets_pt = " << jetspt[i] << endl; }
+    }
+
+  TMath::Sort ( fNJets, jetspt , jetsptidx ) ; // sorting pt of jets
+
+  // selection of leading jet
+  // looping over jets searching for __first__ one that coresponds to cuts
+  for(  Int_t i = 0 ; i < fNJets ; i++ )
+    {
+      if ( ( fVectJet[ jetsptidx[i] ]->njet >= fMinJetParticles ) && ( fVectJet[ jetsptidx[i] ]->pt >= fJetPtCut ) )
+       {
+         leadingjetindex = jetsptidx[i] ;
+         partleadjet = fVectJet[ leadingjetindex ]->njet ; // number of particles in leading jet
+         ptleadjet = fVectJet[ leadingjetindex ]->pt   ; // pt  of leading jet
+         etaleadjet = fVectJet[ leadingjetindex ]->eta  ; // eta of leading jet
+         phileadjet = fVectJet[ leadingjetindex ]->phi  ; // phi of leading jet
+
+         if (fDebug)
+           { printf("Leading jet %d : npart= %d ; pt= %g ; eta = %g ; phi = %g \n", leadingjetindex, partleadjet, ptleadjet, etaleadjet, phileadjet ); }
+
+         break ;
+       }
+    }
+  // end of selection of leading jet
+
+
+
+  //////////////////////////////////////////////////
+  ////  Computing of values used in histograms
+  //////////////////////////////////////////////////
+
+  //___________________________________________________________________________
+  // pt_sum of all particles in event
+  //___________________________________________________________________________
+  if (fDebug) cout << "Computing sum of pt in event" << endl ;
+  Double_t ptsumevent = 0.;
+  for (  Int_t i = 0 ; i< fNPart ; i++ ) { ptsumevent += fVectParticle[i]->pt ; }
+  if (fDebug) printf ("Sum of all Pt in event : pt_sum_event = %g", ptsumevent) ;
+
+  //___________________________________________________________________________
+  // Filling an array with indexes of leading jet particles
+  //___________________________________________________________________________
+  Int_t * idxpartLJ = new Int_t [partleadjet] ;
+  Int_t counterpartleadjet = 0;
+
+  if (fDebug) cout << "Filling an array with indexes of leading jet particles" << endl;
+
+  for( Int_t i = 0 ; i < fNPart ; i++ )
+    {
+      if ( fVectParticle[i]->njet == leadingjetindex )
+       {  idxpartLJ[counterpartleadjet++] = i ; }
+    }
+
+  if ( (counterpartleadjet-1) > partleadjet ) { cout << " Counter_part_lead_jet > part_leadjet !!!!" << endl;}
+
+
+  //___________________________________________________________________________
+  // Calculus of part distribution in leading jet
+  //___________________________________________________________________________
+  Double_t z = 0. ;
+  Double_t *zpartljet = new Double_t [ partleadjet ] ; // array of z of particles in leading jet
+
+  if (fDebug) cout << "Entering loop of calculus of part distribution in leading jet" << endl ;
+
+  for( Int_t j = 0 ; j < partleadjet ; j++ )
+    {
+      Double_t zj = fVectParticle[idxpartLJ[j]]->pt ;
+      z =  zj / ptleadjet ;
+      zpartljet [j] = z ;
+      if (fDebug) cout << "idx_leadjet_part[j] = " << idxpartLJ[j]
+                      << " p of particle = " << zj
+                      << " pt lead jet = " << ptleadjet
+                      << " Z = " << z << endl;
+    }
+
+
+  //___________________________________________________________________________
+  // array of delta phi's between phi of particles and leading jet phi
+  //___________________________________________________________________________
+  if (fDebug) cout << "array of delta phi's between phi of particles and leading jet phi" << endl;
+  Double_t dphipartLJ = 0. ;
+  Double_t *dphipartljet = new Double_t [fNPart];
+  for(  Int_t part = 0 ; part < fNPart ; part++ )
+    {
+      dphipartLJ = fVectParticle[part]->phi - phileadjet ;
+      dphipartLJ = TVector2::Phi_mpi_pi (dphipartLJ) ; // restrict the delta phi to (-pi,pi) interval
+      dphipartljet [part] = dphipartLJ ;
+      if (fDebug) printf("part= %d ; dphi_partLJ = %g  \n", part, dphipartLJ );
+    }
+
+
+  //______________________________________________________________________________
+  //  Pt distribution for all particles
+  //______________________________________________________________________________
+  TH1F * hpt = (TH1F*)fHistos->FindObject("histo11");
+  if ( hpt ) { for (  Int_t i = 0 ; i < fNPart ; i++ ) { hpt->Fill( fVectParticle[i]->pt ); } }
+
+  //___________________________________________________________________________
+  // Recomputing of radius of particles in leading jet
+  //___________________________________________________________________________
+  if (fDebug) { printf("   Searching particles with jet index %d\n", leadingjetindex); }
+
+  Double_t ddeta = 0. , ddphi = 0. , rpart = 0. ;
+
+  for( Int_t j = 0 ; j < partleadjet ; j++ )
+    {
+      ddeta = etaleadjet - fVectParticle[idxpartLJ[j]]->eta;
+
+      Double_t phitmp = fVectParticle[idxpartLJ[j]]->phi ;
+
+      ddphi = TVector2::Phi_mpi_pi ( phileadjet - phitmp ) ; // restrict the delta phi to (-pi,pi) interval
+
+      rpart = TMath::Hypot (ddeta, ddphi) ;
+
+      if (fDebug) printf ("Particle %d with Re-Computed radius = %f ", idxpartLJ[j], rpart) ;
+      if ( (rpart - fRadius) >= 0.00000001 )
+       { if (fDebug) printf ("    bigger than selected radius of %f\n", fRadius ); }
+      else
+       { if (fDebug) printf ("\n") ; }
+
+      if (hR) hR->Fill(rpart);
+
+    }
+
+
+
+  //_______________________________________________________________________
+  // Computing of radius that contain 80% of Leading Jet ( PT and multiplicity )
+  //_______________________________________________________________________
+  Double_t corepartleadjet = 0.8 * partleadjet ;
+  Double_t coreptleadjet = 0.8 * ptleadjet ;
+  Int_t countercorepart = 0 ;
+  Double_t countercorept = 0. ;
+  Int_t sortedindex = -1 ;
+
+  TProfile * hprof24 = (TProfile*)fHistos->FindObject("histo24");
+  TProfile * hprof25 = (TProfile*)fHistos->FindObject("histo25");
+  TProfile * hprof26 = (TProfile*)fHistos->FindObject("histo26");
+  TProfile * hprof27 = (TProfile*)fHistos->FindObject("histo27");
+  TProfile * hprof28 = (TProfile*)fHistos->FindObject("histo28");
+  TProfile * hprof29 = (TProfile*)fHistos->FindObject("histo29");
+
+
+  if ((hprof24) && (hprof25) && (hprof26) && (hprof27) && (hprof28) && (hprof29) )
+    {
+      for(  Int_t part = 0 ; part < fNPart ; part++ )
+       {
+         Double_t pttmp = 0. ; Double_t etatmp = 0. ; Double_t phitmp = 0. ; // temporary variables
+         Double_t dpart = 0. ;
+         sortedindex = fIdxArray[part] ;
+
+         if ( fVectParticle [ sortedindex ]->njet == leadingjetindex )
+           {
+             pttmp = fVectParticle[sortedindex]->pt ;
+             etatmp = fVectParticle[sortedindex]->eta ;
+             phitmp = fVectParticle[sortedindex]->phi ;
+
+             ++countercorepart ;
+             countercorept += pttmp ;
+
+             dpart = TMath::Hypot ( etaleadjet - etatmp, TVector2::Phi_mpi_pi (phileadjet - phitmp) ) ;
+
+             if ( countercorepart <=  corepartleadjet ) { hprof24->Fill(ptleadjet, dpart); }
+             if ( countercorept <= coreptleadjet ) { hprof25->Fill(ptleadjet, dpart); }
+
+             if (ptleadjet >  5.) { hprof26->Fill(dpart, countercorepart); hprof28->Fill(dpart, countercorept); }
+             if (ptleadjet > 30.) { hprof27->Fill(dpart, countercorepart); hprof29->Fill(dpart, countercorept); }
+
+           }
+       }
+    }
+
+  TH1F *hjetpt = (TH1F*)fHistos->FindObject("histo1");
+  TH1F *hjeteta = (TH1F*)fHistos->FindObject("histo2");
+  TH1F *hjetphi = (TH1F*)fHistos->FindObject("histo3");
+  TH1F *hjetnjet = (TH1F*)fHistos->FindObject("histo4");
+
+  for(  Int_t jet = 0 ; jet < fNJets ; jet++ )
+    {
+      if (hjetpt)   hjetpt   ->Fill ( fVectJet[jet]->pt   ) ;
+      if (hjeteta)  hjeteta  ->Fill ( fVectJet[jet]->eta  ) ;
+      if (hjetphi)  hjetphi  ->Fill ( fVectJet[jet]->phi  ) ;
+      if (hjetnjet) hjetnjet ->Fill ( fVectJet[jet]->njet ) ;
+    }
+
+  TH1F *hjets = (TH1F*)fHistos->FindObject("histo5");
+  if (hjets) hjets->Fill(fNJets);
+
+  TH1F *hleadpart = (TH1F*)fHistos->FindObject("histo6");
+  if (hleadpart) hleadpart->Fill(partleadjet);
+
+  TProfile * hprof = (TProfile*)fHistos->FindObject("histo7");
+  if (hprof) hprof->Fill(ptleadjet,partleadjet);
+
+  TH1F *hMD = (TH1F*)fHistos->FindObject("histo8");
+  for(  Int_t k = 0  ; k < partleadjet ; k++)
+    { hMD->Fill( zpartljet[k] ); }
+
+  TProfile * hphi = (TProfile*)fHistos->FindObject("histo9");
+  for(  Int_t k = 0  ; k < partleadjet ; k++)
+    { hphi->Fill( TMath::RadToDeg() * dphipartljet [k] , fNPart ) ; }
+
+  TProfile * htpd = (TProfile*)fHistos->FindObject("histo10");
+  for(  Int_t k = 0  ; k < fNPart ; k++)
+    { htpd->Fill( TMath::RadToDeg() * dphipartljet [k] , ptsumevent ) ; }
+
+
+  TProfile * hprof1 = (TProfile*)fHistos->FindObject("histo21");
+  if (hprof1) hprof1->Fill(ptleadjet, fNPart);
+
+  TProfile * hprof2 = (TProfile*)fHistos->FindObject("histo22");
+  if (hprof2) hprof2->Fill(ptleadjet, ptsumevent);
+
+  TProfile * hprof1toward = (TProfile*)fHistos->FindObject("histo21_toward");
+  TProfile * hprof1transverse = (TProfile*)fHistos->FindObject("histo21_transverse");
+  TProfile * hprof1away = (TProfile*)fHistos->FindObject("histo21_away");
+  TProfile * hprof2toward = (TProfile*)fHistos->FindObject("histo22_toward");
+  TProfile * hprof2transverse = (TProfile*)fHistos->FindObject("histo22_transverse");
+  TProfile * hprof2away = (TProfile*)fHistos->FindObject("histo22_away");
+  TH1F * hpttoward = (TH1F*)fHistos->FindObject("histo23_toward");
+  TH1F * hpttransverse = (TH1F*)fHistos->FindObject("histo23_transverse");
+  TH1F * hptaway = (TH1F*)fHistos->FindObject("histo23_away");
+
+  if ( (hprof1toward) && (hprof1transverse) && (hprof1away) && (hprof2toward) && (hprof2transverse) && (hprof2away) )
+    {
+      for( Int_t part = 0  ; part < fNPart ; part++)
+       {
+         Double_t ptpart = fVectParticle[part]->pt ; // pt of particle
+         if ( ( dphipartljet[part] >=0.) && ( dphipartljet[part] < kPI/3. ) )
+           {
+             hprof1toward->Fill( ptleadjet, fNPart );
+             hprof2toward->Fill( ptleadjet, ptsumevent);
+             hpttoward->Fill( ptpart );
+           }
+         else
+           if ( ( dphipartljet[part] >= (kPI/3.)) && ( dphipartljet[part] < (2.*kPI/3.)) )
+             {
+               hprof1transverse->Fill( ptleadjet, fNPart );
+               hprof2transverse->Fill( ptleadjet, ptsumevent);
+               hpttransverse->Fill( ptpart );
+             }
+           else
+             if ( ( dphipartljet[part] >= ( 2.*kPI/3.)) && ( dphipartljet[part] < kPI ) )
+               {
+                 hprof1away->Fill( ptleadjet, fNPart );
+                 hprof2away->Fill( ptleadjet, ptsumevent);
+                 hptaway->Fill( ptpart );
+               }
+       }
+    }
+
+}
+
+//______________________________________________________________________________
+void AliCdfJetFinder::Clean()
+{
+  // CLEANING SECTION
+  for (  Int_t i = 0 ; i < fNPart ; i++ ){
+    delete fVectParticle[i];
+    fVectParticle[i] = 0;
+  }
+  delete [] fVectParticle;fVectParticle = 0;
+
+  for (  Int_t i = 0 ; i < fNJets ; i++ ){
+    delete fVectJet[i];
+    fVectJet[i] = 0;
+  } 
+  delete [] fVectJet;fVectJet = 0;
+
+  delete [] fPtArray;fPtArray = 0;
+  delete [] fIdxArray;fIdxArray = 0;
+
+  Reset();
+
+}
+
diff --git a/JETAN/DEV/AliCdfJetFinder.h b/JETAN/DEV/AliCdfJetFinder.h
new file mode 100644 (file)
index 0000000..8407aad
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef ALICDFJETFINDER_H
+#define ALICDFJETFINDER_H
+
+/*
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved.
+ * See cxx source for full Copyright notice
+ *
+*/
+
+/* $Id$ */
+
+//  Definition of constants, structures and functions for jet finder
+
+#include "AliJetFinder.h"
+
+using namespace std ;
+
+
+// structure of jet and particles container
+struct varContainer
+{
+  Double_t pt;   // pt of particle/jet
+  Double_t eta;  // eta of particle/jet
+  Double_t phi;  // phi of particle/jet
+  Int_t    njet; // njet is multiplicity of jet or if particles are stored , njet is index number of jet 
+};
+
+class AliCdfJetHeader;
+
+class AliCdfJetFinder : public AliJetFinder
+{
+ public:
+  AliCdfJetFinder();
+  virtual        ~AliCdfJetFinder();
+
+  void           CreateOutputObjects(TList * const histos);
+  void           FindJets();
+  void           InitData();
+  void           FindCones();
+  void           ComputeConesWeight();
+  void           WriteJets() ;
+  void           AnalizeJets();
+  void           Clean();
+    
+ protected:
+  AliCdfJetFinder ( const AliCdfJetFinder& jf );
+  AliCdfJetFinder& operator = ( const AliCdfJetFinder& jf );
+
+  TList*         fHistos;          //  List of histograms
+
+  Bool_t         fAODwrite ;       //  write jets to AOD
+  Bool_t         fAODtracksWrite;  //  write jet tracks to AOD
+  Bool_t         fAnalyseJets;     //  analyse jets
+       
+  Int_t          fNJets;           //! counter of number of jets
+  Int_t          fNPart;           //! number of particles in event
+  Int_t          fNInC;            //! number of charged particles in event
+  Int_t          fNInN;            //! number of neutral cells in event
+
+  Double_t       fRadius;          // radius of jet 
+
+  Int_t          fMinJetParticles; //  leading jet must contain AT LEAST fMinJetParticles
+  Double_t       fJetPtCut;        //  leading jet must have AT LEAST fJetPtCut
+
+  varContainer** fVectParticle;    //! container for Particles
+  varContainer** fVectJet;         //! container for Jets
+
+  Double_t*      fPtArray;         //! momentum array
+  Int_t*         fIdxArray;        //! index array of sorted pts
+
+  ClassDef(AliCdfJetFinder,3)      //  CDF jet finder
+
+};
+#endif
+
diff --git a/JETAN/DEV/AliCdfJetHeader.cxx b/JETAN/DEV/AliCdfJetHeader.cxx
new file mode 100644 (file)
index 0000000..0f0cb32
--- /dev/null
@@ -0,0 +1,48 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+//---------------------------------------------------------------------
+// Jet Finder based on CDF algortihm
+// Charged jet evolution and the underlying event in proton-antiproton collisions at 1.8 TeV
+// Physical Review D, vol. 65, Issue 9, id. 092002
+// http://www.phys.ufl.edu/~rfield/cdf/chgjet/chgjet_intro.html
+// Authors : Adrian.Sevcenco@cern.ch (adriansev@spacescience.ro )
+//           Daniel.Felea@cern.ch    (dfelea@spacescience.ro)
+//           Ciprian.Mihai.Mitu@cern.ch  (mcm@spacescience.ro)
+//---------------------------------------------------------------------
+
+
+/*
+  Changelog
+
+
+
+*/
+
+#include "AliCdfJetHeader.h"
+
+ClassImp ( AliCdfJetHeader )
+
+////////////////////////////////////////////////////////////////////////
+
+AliCdfJetHeader::AliCdfJetHeader():
+  fMinPartJet(1),
+  fJetPtCut(0.),
+  fAODwrite(kFALSE),
+  fAODtracksWrite(kFALSE),
+  fkAnalyseJets(kFALSE)
+{
+  // Constructor
+}
diff --git a/JETAN/DEV/AliCdfJetHeader.h b/JETAN/DEV/AliCdfJetHeader.h
new file mode 100644 (file)
index 0000000..4356fe8
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef ALICDFJETHEADER_H
+#define ALICDFJETHEADER_H
+
+/*
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved.
+ * See cxx source for full Copyright notice
+ *
+*/
+
+// settings for jet finder process
+
+#include "AliJetHeader.h"
+
+class AliCdfJetHeader : public AliJetHeader
+{
+ public:
+  AliCdfJetHeader();
+  virtual ~AliCdfJetHeader() { }
+
+  // Getters
+  Double_t GetJetPtCut() const      { return fJetPtCut; }
+  Int_t    GetMinPartJet() const    { return fMinPartJet; }
+  Bool_t   GetAnalyseJets() const   { return fkAnalyseJets; }
+
+  // Setters
+  void     SetJetPtCut(Double_t jetptcut)          { fJetPtCut = jetptcut; }
+  void     SetAODwrite(Bool_t aodwrite)            { fAODwrite = aodwrite; }
+  void     SetAODtracksWrite(Bool_t aodtrackswrite){ fAODtracksWrite = aodtrackswrite; }
+  void     SetMinPartJet(Int_t npart)              { fMinPartJet = npart; }
+  void     SetAnalyseJets(Bool_t flag = kTRUE)     { fkAnalyseJets = flag; }
+
+  Bool_t   IsAODwrite() const       { return fAODwrite; }
+  Bool_t   IsAODtracksWrite() const { return fAODtracksWrite; }
+
+ protected:
+  // Parameters of algorithm
+  Int_t    fMinPartJet;           // minimum number of particles in jet
+  Double_t fJetPtCut;             // pt cut of jets
+
+  Bool_t   fAODwrite;             // flag for writing to AOD
+  Bool_t   fAODtracksWrite;       // flag for writing tracks to AOD
+
+  Bool_t   fkAnalyseJets;         // analyse jets 
+
+  ClassDef ( AliCdfJetHeader, 2 ) // CDF jet header class
+
+};
+
+#endif
diff --git a/JETAN/DEV/AliDAJetFinder.cxx b/JETAN/DEV/AliDAJetFinder.cxx
new file mode 100644 (file)
index 0000000..3bd12ee
--- /dev/null
@@ -0,0 +1,546 @@
+
+//  **************************************************************************
+//  * 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$ */
+
+//-----------------------------------------------------------------------------------
+// Jet finder based on Deterministic Annealing
+// For further informations about the DA working features see:
+// Phys.Lett. B601 (2004) 56-63 (http://arxiv.org/abs/hep-ph/0407214)
+// Author: Davide Perrino (davide.perrino@ba.infn.it, davide.perrino@cern.ch)
+//         alexandre.shabetai@cern.ch (Modification of the input object (reader/finder splitting)) 
+// ** 2011
+// Modified accordingly to reader/finder splitting and new handling of neutral information   
+//-----------------------------------------------------------------------------------
+
+#include <TMath.h>
+#include <TRandom2.h>
+
+#include "AliAODJet.h"
+#include "AliDAJetHeader.h"
+#include "AliDAJetFinder.h"
+
+ClassImp(AliDAJetFinder)
+
+///////////////////////////////////////////////////////////////////////
+
+AliDAJetFinder::AliDAJetFinder():
+  AliJetFinder(),
+  fAlpha(1.01),
+  fDelta(1e-8),
+  fAvDist(1e-6),
+  fEps(1e-4),
+  fEpsMax(1e-2),
+  fNloopMax(100),
+  fBeta(0.1),
+  fNclustMax(0),
+  fNin(0),
+  fNeff(0)
+{
+  // Constructor
+}
+
+//-----------------------------------------------------------------------------------
+AliDAJetFinder::~AliDAJetFinder()
+{
+  // Destructor
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::FindJets()  
+{
+  // Find the jets in current event
+  //
+  Float_t betaStop=100.;
+  fDebug = fHeader->GetDebug();
+
+  Double_t dEtSum=0;
+  Double_t *xData[2];
+  TVectorD *vPx = new TVectorD();
+  TVectorD *vPy = new TVectorD();
+  TMatrixD *mPyx= new TMatrixD();
+  TMatrixD *mY  = new TMatrixD();
+  InitDetAnn(dEtSum,xData,vPx,vPy,mPyx,mY);
+  if (fNin < fNclustMax){
+    delete [] xData[0], delete [] xData[1];
+    delete vPx;
+    delete vPy;
+    delete mPyx;
+    delete mY;
+    return;
+  }
+  Int_t nc=1, nk;
+  DoubleClusters(nc,nk,vPy,mY);
+  do{                                  //loop over beta
+    fBeta*=fAlpha;
+    Annealing(nk,xData,vPx,vPy,mPyx,mY);
+    NumCl(nc,nk,vPy,mPyx,mY);
+  }while((fBeta<betaStop || nc<4) && nc<fNclustMax);
+
+  Int_t *xx=new Int_t[fNeff];
+  for (Int_t i = 0; i < fNeff; i++) xx[i] = 0;
+
+  EndDetAnn(nk,xData,xx,dEtSum,vPx,vPy,mPyx,mY);
+  StoreJets(nk,xData,xx,mY);
+  delete [] xx;
+
+  delete [] xData[0], delete [] xData[1];
+  delete mPyx;
+  delete mY;
+  delete vPx;
+  delete vPy;
+
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::InitDetAnn(Double_t &dEtSum,Double_t **xData,TVectorD *vPx,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
+{
+  //Initialise the variables used by the algorithm
+  fBeta=0.1;
+  fNclustMax = ((AliDAJetHeader*)fHeader)->GetFixedCl() ?
+    ((AliDAJetHeader*)fHeader)->GetNclustMax() :
+    TMath::Max((Int_t)TMath::Sqrt(fNin),5);
+  Float_t etaEff = ((AliDAJetHeader*)fHeader)->GetEtaEff();
+
+  fNin=0;
+  for (Int_t iTr=0; iTr<GetCalTrkEvent()->GetNCalTrkTracks(); iTr++) if (GetCalTrkEvent()->GetCalTrkTrack(iTr)->GetCutFlag()==1) fNin++;
+
+  fNeff = ((AliDAJetHeader*)fHeader)->GetNeff();
+  fNeff = TMath::Max(fNeff,fNin);
+  Double_t *xEta = new Double_t[fNeff];
+  Double_t *xPhi = new Double_t[fNeff];
+  xData[0]=xEta; xData[1]=xPhi;
+  vPx->ResizeTo(fNeff);
+  Int_t iIn=0;
+
+  for (Int_t iTr=0; iTr<GetCalTrkEvent()->GetNCalTrkTracks(); iTr++){
+    AliJetCalTrkTrack* ctT = GetCalTrkEvent()->GetCalTrkTrack(iTr);
+    if (ctT->GetCutFlag()==0) continue;
+    xEta[iIn] = ctT->GetEta();
+    xPhi[iIn] = ctT->GetPhi()<0 ? ctT->GetPhi() + 2*TMath::Pi() : ctT->GetPhi();
+    (*vPx)(iIn)=ctT->GetPt();
+    dEtSum+=(*vPx)(iIn);
+    iIn++;
+  }
+
+  TRandom2 r;
+  r.SetSeed(0);
+  for (iIn=fNin; iIn<fNeff; iIn++){
+    xEta[iIn]=r.Uniform(-1*etaEff,etaEff);
+    xPhi[iIn]=r.Uniform(0.,2*TMath::Pi());
+    (*vPx)(iIn)=r.Uniform(0.01,0.02);
+    dEtSum+=(*vPx)(iIn);
+  }
+  for (iIn=0; iIn<fNeff; iIn++) (*vPx)(iIn)=(*vPx)(iIn)/dEtSum;
+
+  Int_t njdim=2*fNclustMax+1;
+  mPyx->ResizeTo(fNeff,njdim);
+  mY->ResizeTo(4,njdim);
+  vPy->ResizeTo(njdim);
+  mY->Zero();mPyx->Zero();vPy->Zero();
+  (*vPy)(0)=1;
+  TMatrixDColumn(*mPyx,0)=1;
+  Double_t ypos=0,xpos=0;
+  for (iIn=0; iIn<fNeff; iIn++){
+    (*mY)(0,0)+=(*vPx)(iIn)*xEta[iIn];
+    ypos+=(*vPx)(iIn)*TMath::Sin(xPhi[iIn]);
+    xpos+=(*vPx)(iIn)*TMath::Cos(xPhi[iIn]);
+  }
+  (*mY)(1,0)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*TMath::Pi();
+
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::DoubleClusters(Int_t nc,Int_t &nk, TVectorD *vPy, TMatrixD *mY) const
+{
+  // Return double clusters
+  for(Int_t iClust=0; iClust<nc; iClust++){
+    (*vPy)(iClust)=(*vPy)(iClust)/2;
+    (*vPy)(nc+iClust)=(*vPy)(iClust);
+    for(Int_t iComp=0; iComp<3; iComp++) (*mY)(iComp,nc+iClust)=(*mY)(iComp,iClust);
+  }
+  nk=2*nc;
+
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::Annealing(Int_t nk,Double_t **xData,  const TVectorD *vPx,  TVectorD *vPy,  TMatrixD *mPyx,  TMatrixD *mY)
+{
+  // Main part of the algorithm
+  const Double_t pi=TMath::Pi();
+  TVectorD *py = new TVectorD(nk);
+  TVectorD *p  = new TVectorD(nk);
+  TMatrixD *y  = new TMatrixD(4,nk);
+  TMatrixD *y1 = new TMatrixD(4,nk);
+  TMatrixD *ry = new TMatrixD(2,nk);
+  Double_t *xEta = xData[0];
+  Double_t *xPhi = xData[1];
+  Double_t Dist(TVectorD,TVectorD);
+
+  Double_t df[2]={((AliDAJetHeader*)fHeader)->GetFiducialEtaMax(),pi};
+  TVectorD vPart(2);
+  Double_t *m = new Double_t[nk];
+  Double_t chi,chi1;
+  do{
+    Int_t nloop=0;
+    for (Int_t iClust=0; iClust<nk; iClust++){
+      for (Int_t i=0; i<3; i++)(*y1)(i,iClust)=(*mY)(i,iClust);
+      (*py)(iClust)=(*vPy)(iClust);
+    }
+    //perturbation of codevectors
+    Double_t seed=1000000*gRandom->Rndm(24);
+    ry->Randomize(-0.5,0.5,seed);
+    for (Int_t i=0; i<2; i++){
+      for (Int_t iClust=0; iClust<nk/2; iClust++)
+       (*y1)(i,iClust)+=((*ry)(i,iClust)+TMath::Sign(0.5,(*ry)(i,iClust)))*fDelta*df[i];
+      for (Int_t iClust=nk/2; iClust<nk; iClust++)
+       (*y1)(i,iClust)-=((*ry)(i,iClust-nk/2)+TMath::Sign(0.5,(*ry)(i,iClust-nk/2)))*fDelta*df[i];
+    }
+    do{
+      //recalculate conditional probabilities
+      nloop++;
+      for (Int_t iIn=0; iIn<fNeff; iIn++){
+       vPart(0)=xEta[iIn]; vPart(1)=xPhi[iIn];
+       for(Int_t iClust=0; iClust<nk; iClust++){
+         (*mPyx)(iIn,iClust)=-log((*py)(iClust))+fBeta*Dist(vPart,TMatrixDColumn(*y1,iClust));
+         m[iClust]=(*mPyx)(iIn,iClust);
+       }
+       Double_t pyxNorm=0;
+       Double_t minPyx=TMath::MinElement(nk,m);
+       for (Int_t iClust=0; iClust<nk; iClust++){
+         (*mPyx)(iIn,iClust)-=minPyx;
+         (*mPyx)(iIn,iClust)=exp(-(*mPyx)(iIn,iClust));
+         pyxNorm+=(*mPyx)(iIn,iClust);
+       }
+       for (Int_t iClust=0; iClust<nk; iClust++) (*mPyx)(iIn,iClust)/=pyxNorm;
+      }
+      p->Zero();
+      y->Zero();
+      //recalculate codevectors
+      for (Int_t iClust=0; iClust<nk; iClust++){
+       Double_t xpos=0,ypos=0,pxy;
+       for (Int_t iIn=0; iIn<fNeff; iIn++) (*p)(iClust)+=(*vPx)(iIn)*(*mPyx)(iIn,iClust);
+       for (Int_t iIn=0; iIn<fNeff; iIn++){
+         pxy=(*vPx)(iIn)*(*mPyx)(iIn,iClust)/(*p)(iClust);
+         ypos+=pxy*TMath::Sin(xPhi[iIn]);
+         xpos+=pxy*TMath::Cos(xPhi[iIn]);
+         (*y)(0,iClust)+=pxy*xEta[iIn];
+       }
+       (*y)(1,iClust)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*pi;
+      }
+      //verify codevectors' stability
+      chi=0;
+      for (Int_t iClust=0; iClust<nk; iClust++){
+       chi1=TMath::CosH((*y1)(0,iClust)-(*y)(0,iClust))-TMath::Cos((*y1)(1,iClust)-(*y)(1,iClust));
+       chi1/=(2*TMath::CosH((*y1)(0,iClust))*TMath::CosH((*y)(0,iClust)));
+       chi1*=chi1;
+       if (chi1>chi) chi=chi1;
+      }
+      chi=TMath::Sqrt(chi);
+      for (Int_t iClust=0; iClust<nk; iClust++){
+       for (Int_t i=0; i<2; i++) (*y1)(i,iClust)=(*y)(i,iClust);
+       (*py)(iClust)=(*p)(iClust);
+      }
+      if (nloop>fNloopMax){
+       if (chi<fEpsMax || nloop>500) break;
+      }
+    }while (chi>fEps);
+  }while (chi>fEpsMax);
+  for (Int_t iClust=0; iClust<nk; iClust++){                           //set codevectors and probability equal to those calculated
+    for (Int_t i=0; i<2; i++) (*mY)(i,iClust)=(*y)(i,iClust);
+    (*vPy)(iClust)=(*p)(iClust);
+  }
+  delete py;
+  delete p;
+  delete y;
+  delete y1;
+  delete ry;
+  delete [] m;
+
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::NumCl(Int_t &nc,Int_t &nk,TVectorD *vPy, TMatrixD *mPyx,TMatrixD *mY)
+{
+  // Number of clusters
+  static Bool_t growcl=true;
+       
+  if (nk==2) growcl=true;
+  if (growcl){
+    //verify if two codevectors are equal within fAvDist
+    Int_t *nSame = new Int_t[nk];
+    Int_t **iSame = new Int_t*[nk];
+    Int_t **cont = new Int_t*[nk];
+    for (Int_t iClust=0; iClust<nk; iClust++) {
+      cont[iClust] =new Int_t[nk];
+      iSame[iClust]=new Int_t[nk];         
+    }
+
+    for (Int_t iClust=0; iClust<nk; iClust++){
+      iSame[iClust][iClust]=1;
+      for (Int_t iClust1=iClust+1; iClust1<nk; iClust1++){
+       Double_t eta  = (*mY)(0,iClust) ; Double_t phi  = (*mY)(1,iClust);
+       Double_t eta1 = (*mY)(0,iClust1); Double_t phi1 = (*mY)(1,iClust1);
+       Double_t distCl=(TMath::CosH(eta-eta1)-TMath::Cos(phi-phi1))/(2*TMath::CosH(eta)*TMath::CosH(eta1));
+       if (distCl < fAvDist) iSame[iClust][iClust1]=iSame[iClust1][iClust]=1;
+       else iSame[iClust][iClust1]=iSame[iClust1][iClust]=0;
+      }
+    }
+    ReduceClusters(iSame,nk,nc,cont,nSame);
+    if (nc >= fNclustMax) growcl=false;
+    //recalculate the nc distinct codevectors
+    TMatrixD *pyx = new TMatrixD(fNeff,2*nc);
+    TVectorD *py = new TVectorD(nk);
+    TMatrixD *y1  = new TMatrixD(3,nk);
+    for (Int_t iClust=0; iClust<nc; iClust++){
+      for(Int_t j=0; j<nSame[iClust]; j++){
+       Int_t iClust1 = cont[iClust][j];
+       for (Int_t iIn=0; iIn<fNeff; iIn++) (*pyx)(iIn,iClust)+=(*mPyx)(iIn,iClust1);
+       (*py)(iClust)+=(*vPy)(iClust1);
+       for (Int_t i=0; i<2; i++) (*y1)(i,iClust)+=(*mY)(i,iClust1);
+      }
+      for (Int_t i=0; i<2; i++) (*y1)(i,iClust)/=nSame[iClust];
+    }
+    for (Int_t iClust=0; iClust<nk; iClust++) delete [] cont[iClust], delete [] iSame[iClust];
+    delete [] iSame;
+    delete [] cont;
+    delete [] nSame;
+    if (nc > nk/2){
+      for (Int_t iClust=0; iClust<nc; iClust++){
+       for (Int_t iIn=0; iIn<fNeff; iIn++) (*mPyx)(iIn,iClust)=(*pyx)(iIn,iClust);
+       for (Int_t iComp=0; iComp<2; iComp++) (*mY)(iComp,iClust)=(*y1)(iComp,iClust);
+       (*vPy)(iClust)=(*py)(iClust);
+      }
+      nk=nc;
+      if (growcl) DoubleClusters(nc,nk,vPy,mY);
+    }
+    delete pyx;
+    delete py;
+    delete y1;
+  }
+
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::ReduceClusters(Int_t **iSame,Int_t nc,Int_t &ncout,Int_t **cont,Int_t *nSameOut) const
+{
+  // Reduction step
+  Int_t *nSame = new Int_t[nc];
+  Int_t *iperm = new Int_t[nc];
+  Int_t *go = new Int_t[nc];
+  for (Int_t iCl=0; iCl<nc; iCl++){
+    nSame[iCl]=0;
+    for (Int_t jCl=0; jCl<nc; jCl++) nSame[iCl]+=iSame[iCl][jCl], cont[iCl][jCl]=0;
+    iperm[iCl]=iCl;
+    go[iCl]=1;
+  }
+  TMath::Sort(nc,nSame,iperm,true);
+  Int_t l=0;
+  for (Int_t iCl=0; iCl<nc; iCl++){
+    Int_t k=iperm[iCl];
+    if (go[k] == 1){
+      Int_t m=0;
+      for (Int_t jCl=0; jCl<nc; jCl++){
+       if (iSame[k][jCl] == 1){
+         cont[l][m]=jCl;
+         go[jCl]=0;
+         m++;
+       }
+      }
+      nSameOut[l]=m;
+      l++;
+    }
+  }
+  ncout=l;
+  delete [] nSame;
+  delete [] iperm;
+  delete [] go;
+
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::EndDetAnn(Int_t &nk,Double_t **xData,Int_t *xx,Double_t etx,const TVectorD *vPx,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
+{
+  //now assign each particle to only one cluster
+  Double_t *clusters=new Double_t[nk];
+  for (Int_t iIn=0; iIn<fNeff; iIn++){
+    for (Int_t iClust=0; iClust<nk; iClust++) clusters[iClust]=(*mPyx)(iIn,iClust);
+    xx[iIn]=TMath::LocMax(nk,clusters);
+  }
+  delete [] clusters;
+       
+  //recalculate codevectors, having all p(y|x)=0 or 1
+  Double_t *xEta = xData[0];
+  Double_t *xPhi = xData[1];
+  mY->Zero();
+  mPyx->Zero();
+  vPy->Zero();
+  for (Int_t iIn=0; iIn<fNin; iIn++){
+    Int_t iClust=xx[iIn];
+    (*mPyx)(iIn,iClust)=1;
+    (*vPy)(iClust)+=(*vPx)(iIn);
+    (*mY)(0,iClust)+=(*vPx)(iIn)*xEta[iIn];
+    (*mY)(3,iClust)+=(*vPx)(iIn)*etx;
+  }
+  Int_t k=0;
+  for (Int_t iClust=0; iClust<nk; iClust++){
+    if ((*vPy)(iClust)>0){
+      Double_t xpos=0,ypos=0,pxy;
+      for (Int_t iIn=0; iIn<fNin; iIn++){
+       pxy=(*vPx)(iIn)*(*mPyx)(iIn,iClust)/(*vPy)(iClust);
+       ypos+=pxy*TMath::Sin(xPhi[iIn]);
+       xpos+=pxy*TMath::Cos(xPhi[iIn]);
+       if (xx[iIn]==iClust) xx[iIn]=k;
+      }
+      (*mY)(0,k)=(*mY)(0,iClust)/(*vPy)(iClust);
+      (*mY)(1,k)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*TMath::Pi();
+      (*mY)(3,k)=(*mY)(3,iClust);
+      k++;
+    }
+  }
+  nk=k;
+
+}
+
+//-----------------------------------------------------------------------------------
+void AliDAJetFinder::StoreJets(Int_t nk, Double_t **xData, const Int_t *xx, const TMatrixD *mY)
+{
+  //evaluate significant clusters properties
+  const Double_t pi=TMath::Pi();
+  Float_t dFidEtaMax = ((AliDAJetHeader*)fHeader)->GetFiducialEtaMax();
+  Float_t dFidEtaMin = ((AliDAJetHeader*)fHeader)->GetFiducialEtaMin();
+  Float_t dFiducialEta= dFidEtaMax - dFidEtaMin;
+  Double_t *xEta = xData[0];
+  Double_t *xPhi = xData[1];
+  Int_t nEff = 0;
+  for (Int_t i=0; i<fNeff; i++) if (xEta[i]<dFidEtaMax && xEta[i]>dFidEtaMin) nEff++;
+  Double_t dMeanDist=0.;
+  if (nEff > 0)
+    dMeanDist=TMath::Sqrt(2*dFiducialEta*pi/nEff);
+  Bool_t   *isJet = new Bool_t[nk];
+  Double_t *etNoBg= new Double_t[nk];
+  Double_t *dDeltaEta=new Double_t[nk];
+  Double_t *dDeltaPhi=new Double_t[nk];
+  Double_t *surf  = new Double_t[nk];
+  Double_t *etDens= new Double_t[nk];
+  for (Int_t iClust=0; iClust<nk; iClust++){
+    isJet[iClust]=false;
+    Double_t dEtaMin=10.,dEtaMax=-10.,dPhiMin=10.,dPhiMax=0.;
+    for (Int_t iIn=0; iIn<fNeff; iIn++){
+      if (xx[iIn]!=iClust || xEta[iIn]>dFidEtaMax || xEta[iIn]<dFidEtaMin) continue;
+      if (xEta[iIn] < dEtaMin) dEtaMin=xEta[iIn];
+      if (xEta[iIn] > dEtaMax) dEtaMax=xEta[iIn];
+      Double_t dPhi=xPhi[iIn]-(*mY)(1,iClust);
+      if      (dPhi > pi     ) dPhi-=2*pi;
+      else if (dPhi < (-1)*pi) dPhi+=2*pi;
+      if      (dPhi < dPhiMin) dPhiMin=dPhi;
+      else if (dPhi > dPhiMax) dPhiMax=dPhi;
+    }
+    dDeltaEta[iClust]=dEtaMax-dEtaMin+dMeanDist;
+    dDeltaPhi[iClust]=dPhiMax-dPhiMin+dMeanDist;
+    surf[iClust]=0.25*pi*dDeltaEta[iClust]*dDeltaPhi[iClust];
+    etDens[iClust]=(*mY)(3,iClust)/surf[iClust];
+  }
+
+  if (((AliDAJetHeader*)fHeader)->GetSelJets()){
+    for (Int_t iClust=0; iClust<nk; iClust++){
+      if (!isJet[iClust] && (*mY)(0,iClust)<dFidEtaMax && (*mY)(0,iClust)>dFidEtaMin){
+       Double_t etDensMed=0.;
+       Double_t etDensSqr=0.;
+       Int_t norm=0;
+       for (Int_t iClust1=0; iClust1<nk; iClust1++){
+         if(iClust1!=iClust && (*mY)(0,iClust)<dFidEtaMax && (*mY)(0,iClust)>dFidEtaMin){
+           etDensMed+=etDens[iClust1];
+           etDensSqr+=TMath::Power(etDens[iClust1],2);
+           norm++;
+         }
+       }
+       etDensMed/=TMath::Max(norm,1);
+       etDensSqr/=TMath::Max(norm,1);
+       Double_t deltaEtDens=TMath::Sqrt(etDensSqr-TMath::Power(etDensMed,2));
+       if ((*mY)(3,iClust) > (etDensMed+deltaEtDens)*surf[iClust]) isJet[iClust]=kTRUE;
+       etNoBg[iClust]=(*mY)(3,iClust)-etDensMed*surf[iClust];
+      }
+    }
+    for (Int_t iClust=0; iClust<nk; iClust++){
+      if (isJet[iClust]){
+       Double_t etDensMed=0;
+       Double_t extSurf=2*dFiducialEta*pi;
+       for (Int_t iClust1=0; iClust1<nk; iClust1++){
+         if (!isJet[iClust1]) etDensMed+=(*mY)(3,iClust1);
+         else extSurf-=surf[iClust1];
+       }
+       etDensMed/=extSurf;
+       etNoBg[iClust]=(*mY)(3,iClust)-etDensMed*surf[iClust];
+       if (etNoBg[iClust]<((AliDAJetHeader*)fHeader)->GetEtMin()){
+         isJet[iClust]=kFALSE;
+         iClust=-1;
+       }
+      }
+    }
+  } else {
+    for (Int_t iClust=0; iClust<nk; iClust++){
+      isJet[iClust]=true;
+      etNoBg[iClust]=(*mY)(3,iClust);
+    }
+  }
+  delete [] etDens;
+  delete [] surf;
+       
+  //now add selected jets to the list
+  Int_t *iSort = new Int_t[nk];
+  TMath::Sort(nk,etNoBg,iSort,true);
+  Int_t iCl = 0;
+
+  for (Int_t iClust=0; iClust<nk; iClust++){ //clusters loop
+    iCl=iSort[iClust];
+    if (isJet[iCl]){ //choose cluster
+      Float_t px,py,pz,en;
+      px = (*mY)(3,iCl)*TMath::Cos((*mY)(1,iCl));
+      py = (*mY)(3,iCl)*TMath::Sin((*mY)(1,iCl));
+      pz = (*mY)(3,iCl)/TMath::Tan(2.0 * TMath::ATan(TMath::Exp(-(*mY)(0,iCl))));
+      en = TMath::Sqrt(px * px + py * py + pz * pz);
+      AliAODJet jet(px, py, pz, en);
+      Int_t iIn=0;
+      Int_t nTr = GetCalTrkEvent()->GetNCalTrkTracks();
+      for (Int_t iTr=0; iTr<nTr; iTr++){
+       AliJetCalTrkTrack* ctT = GetCalTrkEvent()->GetCalTrkTrack(iTr);
+       if (ctT->GetCutFlag()==0) continue;
+       if (xx[iIn]==iCl) jet.AddTrack(ctT->GetTrackObject());
+       iIn++;
+      }
+      AddJet(jet);
+      if (fDebug > 0) printf("jet %d, Eta: %f, Phi: %f, Et: %f\n",iCl,jet.Eta(),jet.Phi(),jet.Pt());
+    }
+  }
+  delete [] dDeltaEta; delete [] dDeltaPhi;
+  delete [] etNoBg;
+  delete [] isJet;
+  delete [] iSort;
+
+}
+
+//-----------------------------------------------------------------------------------
+Double_t Dist(TVectorD x,TVectorD y)
+{
+  // Squared distance
+  const Double_t pi=TMath::Pi();
+  Double_t dphi=TMath::Abs(x(1)-y(1));
+  if (dphi > pi) dphi=2*pi-dphi;
+  Double_t dist=pow(x(0)-y(0),2)+pow(dphi,2);
+  return dist;
+
+}
diff --git a/JETAN/DEV/AliDAJetFinder.h b/JETAN/DEV/AliDAJetFinder.h
new file mode 100644 (file)
index 0000000..b484e6b
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef ALIDAJETFINDER_H
+#define ALIDAJETFINDER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//---------------------------------------------------------------------
+//Jet finder based on Deterministic Annealing
+//Author: Davide Perrino (davide.perrino@ba.infn.it)
+//        magali.estienne@subatech.in2p3.fr &
+//        alexandre.shabetai@cern.ch (Modification of the input object (reader/finder splitting))
+// ** 2011
+// Modified accordingly to reader/finder splitting and new handling of neutral information
+//---------------------------------------------------------------------
+
+#include "AliJetFinder.h"
+
+#include <TMatrixD.h>
+#include <TVectorD.h>
+
+class AliDAJetFinder : public AliJetFinder
+{
+ public:
+  AliDAJetFinder();
+  virtual  ~AliDAJetFinder();
+
+  void     FindJets      ();
+
+ protected:
+  Double_t fAlpha;          // beta increment
+  Double_t fDelta;          // perturbation proportional to Delta
+  Double_t fAvDist;         // minimum distance to distinguish two clusters
+  Double_t fEps;            // convergence criterium below max number of loops
+  Double_t fEpsMax;         // convergence criterium above max number of loops
+  Int_t    fNloopMax;       // maximum number of loops at a fixed beta
+  Double_t fBeta;           // increasing multiplier of entropy
+  Int_t    fNclustMax;      // maximum number of clusters to find
+  Int_t    fNin;            // number of input data
+  Int_t    fNeff;           // total input data, including fakes
+
+ private:
+  void     InitDetAnn    (Double_t &dEtSum, Double_t **xData, TVectorD *px, TVectorD *py, TMatrixD *pyx, TMatrixD *y);
+  void     Annealing     (Int_t nk, Double_t **xData, const TVectorD *vPx, TVectorD *vPy, TMatrixD *mPyx, TMatrixD *mY);
+  void     NumCl         (Int_t &nc, Int_t &nk, TVectorD *vPy, TMatrixD *mPyx, TMatrixD *mY);
+  void     ReduceClusters(Int_t **iSame, Int_t nc, Int_t &ncout, Int_t **cont, Int_t *nSameOut) const;
+  void     DoubleClusters(Int_t nc, Int_t &nk, TVectorD *vPy, TMatrixD *mY) const;
+  void     EndDetAnn     (Int_t &nk, Double_t **xData, Int_t *xx, Double_t etx, const TVectorD *px, TVectorD *py, TMatrixD *pyx, TMatrixD *y);
+  void     StoreJets     (Int_t nk, Double_t **xData, const Int_t *xx, const TMatrixD *mY);
+
+  ClassDef(AliDAJetFinder,4) // DA Jet finder
+
+};
+
+#endif
diff --git a/JETAN/DEV/AliDAJetHeader.cxx b/JETAN/DEV/AliDAJetHeader.cxx
new file mode 100644 (file)
index 0000000..bde89af
--- /dev/null
@@ -0,0 +1,56 @@
+//  **************************************************************************
+//  * 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.                  *
+//  **************************************************************************
+
+//----------------------------------------------------------------------------
+// Deterministic Annealing Jet header class
+// Stores parameters of DA jet algorithm
+// Author: Davide Perrino (davide.perrino@ba.infn.it, davide.perrino@cern.ch)
+// 2011:
+// Adding FiducialEta/PhiMin/Max setters/getters and variables to accommodate with reader/finder splitting 
+//----------------------------------------------------------------------------
+
+#include "AliDAJetHeader.h"
+
+ClassImp(AliDAJetHeader)
+
+///////////////////////////////////////////////////////////////////////
+
+AliDAJetHeader::AliDAJetHeader():
+  AliJetHeader("AliDAJetHeader"),
+  fSelectJets(kTRUE),
+  fNclustMax(10),
+  fFixedCl(kFALSE),
+  fEtMin(10.),
+  fNeff(0),
+  fEtaEff(0.9),
+  fFidEtaMin(-0.9),
+  fFidEtaMax(0.9),
+  fFidPhiMin(0.),
+  fFidPhiMax(2*TMath::Pi())
+{
+  // Constructor
+}
+
+//---------------------------------------------------------------------
+void AliDAJetHeader::SetRadius(Float_t radius)
+{
+  // The radius requested is used to estimate the number of clusters
+  // to be found, in order to obtain jets with the expected area.
+  // It must not be intended as a sharp limit on the cluster radius
+    
+  Int_t nclust = (Int_t) (4.*fEtaEff/(radius*radius)) + 1;
+  SetNclust(nclust);
+
+}
diff --git a/JETAN/DEV/AliDAJetHeader.h b/JETAN/DEV/AliDAJetHeader.h
new file mode 100644 (file)
index 0000000..c8cfca0
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef ALIDAJETHEADER_H
+#define ALIDAJETHEADER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+//---------------------------------------------------------------------
+// Jet header class for Deterministic Annealing
+// Stores the parameters of the DA jet algorithm
+// Author: Davide Perrino (davide.perrino@ba.infn.it)
+// 2011:
+// Adding FiducialEta/PhiMin/Max setters/getters and variables to accommodate with reader/finder splitting
+//---------------------------------------------------------------------
+
+#include "AliJetHeader.h"
+
+class AliDAJetHeader : public AliJetHeader
+{
+ public:
+  AliDAJetHeader();
+  virtual ~AliDAJetHeader() {}
+
+  void    SelectJets        (Bool_t seljets) { fSelectJets=seljets; }
+  void    SetRadius        (Float_t radius);
+  void    SetNclust        (Int_t ncl     ) { fNclustMax=ncl ; fFixedCl=kTRUE; }
+  void    SetEtMin         (Float_t etmin ) { fEtMin =etmin; }
+  void    SetNeff          (Int_t n       ) { fNeff = n; }
+  void    SetEtaEff        (Float_t eta   ) { fEtaEff = eta; }
+  void    SetFiducialEtaMin (Float_t etamin) { fFidEtaMin = etamin; }
+  void    SetFiducialEtaMax (Float_t etamax) { fFidEtaMax = etamax; }
+  void    SetFiducialPhiMin (Float_t phimin) { fFidPhiMin = phimin; }
+  void    SetFiducialPhiMax (Float_t phimax) { fFidPhiMax = phimax; }
+
+  Bool_t  GetSelJets() const                 { return fSelectJets; }
+  Float_t GetRadius() const                  { return fRadius; }
+  Int_t   GetNclustMax() const               { return fNclustMax; }
+  Bool_t  GetFixedCl() const                 { return fFixedCl; }
+  Float_t GetEtMin() const                   { return fEtMin; }
+  Int_t   GetNeff() const                    { return fNeff; }
+  Float_t GetEtaEff() const                  { return fEtaEff; }
+  Float_t GetFiducialEtaMin() const          { return fFidEtaMin; }
+  Float_t GetFiducialEtaMax() const          { return fFidEtaMax; }
+  Float_t GetFiducialPhiMin() const          { return fFidPhiMin; }
+  Float_t GetFiducialPhiMax() const          { return fFidPhiMax; }
+
+ protected:
+  Bool_t  fSelectJets;      // select jets among clusters
+  Int_t          fNclustMax;        // number of clusters when to stop annealing
+  Bool_t  fFixedCl;         // use a fixed fNclustMax
+  Float_t fEtMin;           // minimum energy for found jets
+  Int_t          fNeff;             // number of total input data, including fakes
+  Float_t fEtaEff;          // eta range in which fake tracks are generated
+  Float_t fFidEtaMin;        // fiducial eta min for particles
+  Float_t fFidEtaMax;        // fiducial eta max for particles
+  Float_t fFidPhiMin;        // fiducial phi min for paticles
+  Float_t fFidPhiMax;        // fiducial phi max for paticles
+
+  ClassDef(AliDAJetHeader,4) // DA jet header class
+
+};
+
+#endif
diff --git a/JETAN/DEV/AliEventShape.cxx b/JETAN/DEV/AliEventShape.cxx
new file mode 100644 (file)
index 0000000..e34640d
--- /dev/null
@@ -0,0 +1,311 @@
+/**************************************************************************
+ * 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$ */
+//---------------------------------------------------------------------
+// Event shape utility class
+// Circularity, Thrust, ... 
+// Authors: Antonio Ortiz Velasquez <Antonio.Ortiz.Velasquez@cern.ch>
+//          
+//---------------------------------------------------------------------
+
+
+#include "AliEventShape.h"
+
+#include "AliStack.h"
+#include "AliLog.h"
+#include "AliMCEventHandler.h"
+#include "AliMCEvent.h"
+
+#include <TMatrixDSym.h>
+#include <TVectorD.h>
+#include <TMatrixDSymEigen.h>
+#include <TParticle.h>
+#include <TParticlePDG.h>
+
+
+
+
+//____________________________________________________________________
+ClassImp(AliEventShape)
+
+//___________________________________________________________________
+TArrayD * AliEventShape::GetThrustParamMC(AliMCEvent* mcEvent, Int_t  nstudymin, Double_t ptcutoff, Double_t etacutoff, Bool_t chom)
+{
+  /*
+    This function returns an array of values of thrust. To get these values you have to do:
+    TArrayD* eventshapes = 0;
+    eventshapes = AliShapeEvent::GetThrustParamMC(mcEvent, 3, 1, 1, kFALSE);
+    Double_t thrust=eventshapes->GetAt(0);
+    Double_t thrustmin=eventshapes->GetAt(1);
+    Double_t recoil=eventshapes->GetAt(2);  
+    The calculus uses  primary  particles. The input parameters:
+    1. nstudymin, is the minumum number of particles which you want that participate in the calculus.(default:nstudymin =3)
+    2. ptcutoff, is the cut in pt applied to participants to calculate the variables.(default: ptcutoff=1)
+    3. etacutoff, is the cut in acceptance applied to participants to calculate the variables.(default: etacutoff=1)
+    4. if chom=kTRUE, then the calculus includes neutral particles (rejecting photons and neutrinos).
+       if chom=kFALSE, then the calculus includes only charged particles (rejecting photons and neutrinos).
+       Returned values: thrust->0: 2-jet event, thrust->0.5: isotropic event
+       Recoil is a term which is sensitive to radiation outside from acceptance, 1>=recoil>=0,
+       thrustmin, is a measure of the radiation which is perpendicular to the plane formed by beam axis and thrust axis, 2/TMath::Pi()>thrustmin>0. In the limit of 2 back-to-back jets thrusmin->0, while in the case of a uniformly distributed event thrustmin->2/TMath::Pi();
+  */
+  
+  AliStack* stack = 0;
+
+  stack = mcEvent->Stack();
+  Double_t * ptT = 0;
+  Double_t * pxT = 0;
+  Double_t * pyT = 0;
+  Double_t ptsuma = 0;
+  Double_t pxsuma = 0;
+  Double_t pysuma = 0;
+
+  TArrayD* evsh = new TArrayD(3);  
+  Int_t nPrim  = stack->GetNprimary();
+  Int_t  nmctracks = 0;  
+  for (Int_t iMCTracks = 0; iMCTracks < nPrim; iMCTracks++) {    
+      TParticle* trackmc = stack->Particle(iMCTracks);
+      if (!trackmc) continue;
+      Double_t etamc =trackmc ->Eta();
+      Double_t ptmc=trackmc->Pt();
+      Int_t pdgCode = TMath::Abs(trackmc->GetPdgCode());
+      if (TMath::Abs(etamc) > etacutoff) continue; //only particles in |eta|<=etacutoff
+      if(ptmc < ptcutoff) continue;  // PT cut
+      Bool_t isprimary = stack->IsPhysicalPrimary(iMCTracks);    // Check if particle is charged, and primary
+      if(isprimary == 0) continue;  // only primary particles
+      TParticlePDG* pdgPart =trackmc ->GetPDG();
+      if(chom == 1){//include neutral particles
+         // skip photons and neutrinos
+         if (pdgCode == 22 || pdgCode == 12 || pdgCode == 14 || pdgCode == 16) continue;
+         nmctracks++;  
+      }
+      else{ //only charged particles
+         if (pdgPart->Charge() == 0)continue;
+         nmctracks++;     
+      }
+  }
+  // Minimum number of particles used in the analysis
+  if(nmctracks < nstudymin){
+      evsh->AddAt(-2,0);
+      evsh->AddAt(-2,1);
+      evsh->AddAt(-2,2);
+      return evsh;
+  }
+  
+  Int_t j=0;
+  pxT = new Double_t[nmctracks];
+  pyT = new Double_t[nmctracks];
+  ptT = new Double_t[nmctracks];
+  for (Int_t i = 0; i < nmctracks; i++)
+    {
+      pxT[i] = 0;
+      pyT[i] = 0;
+      ptT[i] = 0;
+    }
+  for (Int_t iMCTracks = 0; iMCTracks < nPrim; ++iMCTracks) {    
+      TParticle* trackmc = stack->Particle(iMCTracks);
+      if (!trackmc) continue;
+      Double_t etamc = trackmc ->Eta();
+      Double_t pxmc  = trackmc->Px();
+      Double_t pymc  = trackmc->Py();
+      Double_t ptmc  = trackmc->Pt();
+      Int_t pdgCode  = TMath::Abs(trackmc->GetPdgCode());
+      if (TMath::Abs(etamc) > etacutoff) continue;
+      if(ptmc < ptcutoff) continue;
+      Bool_t isprimary = stack->IsPhysicalPrimary(iMCTracks); 
+      if(isprimary==0) continue;
+      TParticlePDG* pdgPart =trackmc ->GetPDG();
+
+      if(chom==1){
+         if (pdgCode == 22 || pdgCode == 12 || pdgCode == 14 || pdgCode == 16)continue;
+      } else {
+         if (pdgPart->Charge() == 0) continue;
+      }
+      
+      ptT[j] = ptmc;
+      pxT[j] = pxmc;
+      pyT[j] = pymc;
+      ptsuma += ptmc;
+      pxsuma+=pxmc;
+      pysuma+=pymc;
+      j++;    
+  }
+
+  Double_t numerador = 0;
+  Double_t numerador2 = 0;
+  Double_t phimax = -1;  
+  Double_t pFull = -1;
+  Double_t pMax = 0;
+  Double_t phi = 0;
+  Double_t thrust = 80;
+  Double_t thrustminor = 80;
+  Double_t nx = 0;
+  Double_t ny = 0;
+  Double_t phiparam = 0;
+  //Getting thrust
+  for(Int_t i = 0; i < 360; ++i){
+      numerador = 0;
+      phiparam  = 0;
+      nx = 0;
+      ny = 0;
+      phiparam=((TMath::Pi()) * i) / 180; // parametrization of the angle
+      nx = TMath::Cos(phiparam);            // x component of an unitary vector n
+      ny = TMath::Sin(phiparam);            // y component of an unitary vector n
+      for(Int_t i1 = 0; i1 < nmctracks; ++i1){
+         numerador += TMath::Abs(nx * pxT[i1] + ny * pyT[i1]);//product between momentum proyection in XY plane and the unitari vector.
+      }
+      pFull=numerador / ptsuma;
+      if(pFull > pMax)//maximization of pFull
+      {
+         pMax = pFull;
+         phi = phiparam;
+      }
+  }
+
+  phimax=(phi * 180) / TMath::Pi();//angular parameter of the unitary vector which maximiza thrust
+  //if n vector and beam axis form a plane, then we can calculate a second unitary vector perpendicular to that plane
+  Double_t nx1 = TMath::Cos(phi);
+  Double_t ny1 = TMath::Sin(phi);
+  for(Int_t i2 =0; i2 < nmctracks; ++i2){
+      numerador2 += TMath::Abs(pxT[i2] * ny1 - nx1 * pyT[i2]);//cross product: P_{i} X n, P_{i}=(px_{i},py_{i})
+  }
+  thrust = 1 - pMax;//this is the value of thrust
+  thrustminor = numerador2 / ptsuma;//this is the value of thrust minor
+  Double_t recoil = TMath::Abs(TMath::Sqrt(pxsuma * pxsuma + pysuma * pysuma)) / (ptsuma);//factor sentsitive to radiation outside from acceptance 
+
+  evsh->AddAt(thrust, 0);
+  evsh->AddAt(thrustminor, 1);
+  evsh->AddAt(recoil, 2);
+
+
+  delete [] ptT;
+  delete [] pxT;
+  delete [] pyT;
+
+  return evsh;  
+}
+
+
+Double_t AliEventShape::GetCircularityMC(AliMCEvent* mcEvent, Int_t  nstudymin, Double_t ptcutoff, Double_t etacutoff, Bool_t chom)
+{
+  /*
+    This function returns the circularity value of the event 
+
+    The calculus uses  primary  particles. The input parameters:
+    1. nstudymin, is the minumum number of particles which you want that participate in the calculus.(default:nstudymin =3)
+    2. ptcutoff, is the cut in pt applied to participants to calculate the variables.(default: ptcutoff=1)
+    3. etacutoff, is the cut in acceptance applied to participants to calculate the variables.(default: etacutoff=1)
+    4. if chom=kTRUE, then the calculus includes neutral particles (rejecting photons and neutrinos).
+       if chom=kFALSE, then the calculus includes only charged particles (rejecting photons and neutrinos).
+       1>=circularity>=0
+  */
+
+
+  AliStack* stack = 0;
+
+  stack = mcEvent->Stack();
+
+  TMatrixDSym s(2);
+
+  Double_t s00 =  0;
+  Double_t s01 =  0;
+  Double_t s10 =  0;
+  Double_t s11 =  0;
+  Double_t ptot = 0;
+  Double_t circularity = -2;
+  Int_t  nmctracks = 0;  
+  Int_t nPrim  = stack->GetNprimary();
+
+  for (Int_t iMCTracks = 0; iMCTracks < nPrim; ++iMCTracks) {
+    TParticle* trackmc = stack->Particle(iMCTracks);
+    if (!trackmc) continue;
+    Double_t etamc = trackmc ->Eta();
+    Double_t ptmc  = trackmc->Pt();
+    Double_t pxmc  = trackmc->Px();
+    Double_t pymc  = trackmc->Py();
+    Int_t pdgCode = TMath::Abs(trackmc->GetPdgCode());
+    if (TMath::Abs(etamc) > etacutoff) continue;
+    if (ptmc < ptcutoff) continue;
+    Bool_t isprimary = stack->IsPhysicalPrimary(iMCTracks);
+    if (isprimary == 0) continue;
+    TParticlePDG* pdgPart = trackmc ->GetPDG();
+    if(chom == kTRUE){
+      // skip photons and neutrinos
+      if (pdgCode == 22 || pdgCode == 12 || pdgCode == 14 || pdgCode == 16) continue; 
+    }
+    else{
+      if (pdgPart->Charge() == 0)continue;
+    }
+
+    ptot = ptot + (ptmc * ptmc);
+    s00 = s00 + (pxmc * pxmc);
+    s01 = s01 + (pxmc * pymc);
+    s10 = s10 + (pymc * pxmc);
+    s11 = s11 + (pymc * pymc); 
+    nmctracks++;
+  } //track loop 
+
+
+  if (nmctracks < nstudymin) {
+      Printf("Too few particles, stopping");
+      return -2;
+  }
+
+
+  
+  if(ptot != 0){
+    s(0,0) = s00 / ptot;
+    s(0,1) = s01 / ptot;
+    s(1,0) = s10 / ptot;
+    s(1,1) = s11 / ptot;
+    const TMatrixDSymEigen eigen(s);
+    const TVectorD eigenVal=eigen.GetEigenValues();
+    circularity = 2 * (1 - eigenVal(0));
+  }
+  return circularity;
+}
+  
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JETAN/DEV/AliEventShape.h b/JETAN/DEV/AliEventShape.h
new file mode 100644 (file)
index 0000000..b5acaa5
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef ALIEVENTSHAPE_H
+#define ALIEVENTSHAPE_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+//---------------------------------------------------------------------
+// Event shape utility class
+// Circularity, Thrust, ... 
+// Authors: Antonio Ortiz Velasquez <Antonio.Ortiz.Velasquez@cern.ch>
+//          
+//---------------------------------------------------------------------
+
+#include <TObject.h>
+
+
+class AliMCEvent;
+class TParticle;
+class TArrayD;
+
+class AliEventShape : public TObject
+{
+  public:
+    static TArrayD * GetThrustParamMC(AliMCEvent* mcEvent, Int_t  NSTUDYMIN=3, Double_t ptcutoff=1, Double_t etacutoff=1, Bool_t chom=kFALSE);
+    static Double_t GetCircularityMC(AliMCEvent* mcEvent, Int_t  NSTUDYMIN=3, Double_t ptcutoff=1, Double_t etacutoff=1, Bool_t chom=kFALSE);
+  private:
+    AliEventShape(const AliEventShape&);
+    AliEventShape& operator=(const AliEventShape&);
+    ClassDef(AliEventShape, 0)
+};
+
+#endif
+
diff --git a/JETAN/DEV/AliFastJetBkg.cxx b/JETAN/DEV/AliFastJetBkg.cxx
new file mode 100644 (file)
index 0000000..1fd7845
--- /dev/null
@@ -0,0 +1,553 @@
+/**************************************************************************
+ * 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 to calculate the background per unit area
+// manages the search for jets
+// Authors: Elena Bruna elena.bruna@yale.edu
+//          Sevil Salur ssalur@lbl.gov
+//
+// 2011 :
+// renamed from AliJetBkg to AliFastJetBkg as this class uses only FASTJET based algos.
+//---------------------------------------------------------------------
+
+#include <Riostream.h> 
+#include <TClonesArray.h>
+#include <TF1.h>
+#include <TString.h>
+
+#include "AliJetHeader.h"
+#include "AliFastJetHeaderV1.h"
+#include "AliAODJet.h"
+#include "AliFastJetInput.h"
+#include "AliFastJetBkg.h"
+
+#include "fastjet/PseudoJet.hh"
+#include "fastjet/ClusterSequenceArea.hh"
+#include "fastjet/AreaDefinition.hh"
+#include "fastjet/JetDefinition.hh"
+
+#include<vector> 
+
+using namespace std;
+
+ClassImp(AliFastJetBkg)
+
+////////////////////////////////////////////////////////////////////////
+
+AliFastJetBkg::AliFastJetBkg():
+  TObject(),
+  fHeader(0),
+  fInputFJ(0)
+{
+  // Default constructor
+}
+
+//______________________________________________________________________
+AliFastJetBkg::AliFastJetBkg(const AliFastJetBkg& input):
+  TObject(input),
+  fHeader(input.fHeader),
+  fInputFJ(input.fInputFJ)
+{
+  // copy constructor
+}
+
+//______________________________________________________________________
+AliFastJetBkg& AliFastJetBkg::operator=(const AliFastJetBkg& source)
+{
+  // Assignment operator. 
+  if(this!=&source){ 
+   TObject::operator=(source);
+   fHeader = source.fHeader;
+   fInputFJ = source.fInputFJ;
+  }
+  
+  return *this;
+
+}
+
+//___________________________________________________________________
+void AliFastJetBkg::BkgFastJetb(Double_t& rho,Double_t& sigma, 
+                               Double_t& meanarea)
+{
+  // Bkg estimation
+   
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader; 
+  Bool_t debug  = header->GetDebug();     // debug option 
+  if(debug>0) cout<<"===============  AliFastJetBkg::BkgFastJetb()  =========== "<<endl;
+  vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
+  
+  double rParamBkg = header->GetRparamBkg(); //Radius for background calculation
+
+  Double_t medianb,sigmab,meanareab;
+  CalcRhob(medianb,sigmab,meanareab,inputParticles,rParamBkg,"All");
+  rho=medianb;
+  sigma=sigmab;
+  meanarea=meanareab;
+}
+
+//_________________________________________________________________
+void AliFastJetBkg::BkgFastJetWoHardest(Double_t& rho,Double_t& sigma, 
+                                       Double_t& meanarea)
+{
+
+  // Bkg estimation without hardest jet
+
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader; 
+  Bool_t debug  = header->GetDebug();     // debug option 
+  if(debug) cout<<"===============  AliFastJetBkg::BkgWoHardest()  =========== "<<endl;
+  vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
+  
+  double rParamBkg = header->GetRparamBkg(); //Radius for background calculation  
+  Double_t medianb,sigmab,meanareab;
+  CalcRhoWoHardest(medianb,sigmab,meanareab,inputParticles,rParamBkg,"All");
+  rho=medianb;
+  sigma=sigmab;
+  meanarea=meanareab;
+
+}
+
+//____________________________________________________________________
+void AliFastJetBkg::CalcRhob(Double_t& median,Double_t& 
+                            sigma,Double_t& 
+                            meanarea,vector<fastjet::PseudoJet> inputParticles,Double_t 
+                            rParamBkg,TString method)
+{
+  // calculate rho using the fastjet method
+
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Bool_t debug  = header->GetDebug();     // debug option
+
+  fastjet::Strategy strategy = header->GetStrategy();
+  fastjet::RecombinationScheme recombScheme = header->GetRecombScheme();
+  fastjet::JetAlgorithm algorithm = header->GetBGAlgorithm();
+  fastjet::JetDefinition jetDef(algorithm, rParamBkg, recombScheme, strategy);
+
+  // create an object that specifies how we to define the area
+  fastjet::AreaDefinition areaDef;
+  double ghostEtamax = header->GetGhostEtaMax(); 
+  double ghostArea   = header->GetGhostArea(); 
+  int    activeAreaRepeats = header->GetActiveAreaRepeats(); 
+
+  // now create the object that holds info about ghosts
+
+  fastjet::GhostedAreaSpec ghost_spec(ghostEtamax, activeAreaRepeats, ghostArea);
+  // and from that get an area definition
+  fastjet::AreaType areaType = header->GetAreaType();
+  areaDef = fastjet::AreaDefinition(areaType,ghost_spec);
+  
+  //fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef);
+  fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef,areaDef);
+  TString comment = "Running FastJet algorithm for BKG calculation with the following setup. ";
+  comment+= "Jet definition: ";
+  comment+= TString(jetDef.description());
+  // comment+= ". Area definition: ";
+  // comment+= TString(areaDef.description());
+  comment+= ". Strategy adopted by FastJet: ";
+  comment+= TString(clust_seq.strategy_string());
+  comment+= Form("Method: %s",method.Data());
+  header->SetComment(comment);
+  if(debug>0){
+    cout << "--------------------------------------------------------" << endl;
+    cout << comment << endl;
+    cout << "--------------------------------------------------------" << endl;
+  }
+
+  vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(0.);
+  vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets); 
+
+  double phiMin = 0, phiMax = 0, rapMin = 0, rapMax = 0;
+
+  phiMin = 0;
+  phiMax = 2*TMath::Pi();
+  rapMax = ghostEtamax - rParamBkg;
+  rapMin = - ghostEtamax + rParamBkg;
+
+  fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
+
+  double medianb, sigmab, meanareab;
+  clust_seq.get_median_rho_and_sigma(inclusiveJets, range, false, medianb, sigmab, meanareab, false);
+  median=medianb;
+  sigma=sigmab;
+  meanarea=meanareab; 
+}
+
+//____________________________________________________________________
+void AliFastJetBkg::CalcRhoWoHardest(Double_t& median,Double_t& 
+                                    sigma,Double_t& meanarea,vector<fastjet::PseudoJet> inputParticles,Double_t 
+                                    rParamBkg,TString method)
+{
+  // calculate rho (without the hardest jet) using the fastjet method
+
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Bool_t debug  = header->GetDebug();     // debug option
+
+  fastjet::Strategy strategy = header->GetStrategy();
+  fastjet::RecombinationScheme recombScheme = header->GetRecombScheme();
+  fastjet::JetAlgorithm algorithm = header->GetBGAlgorithm();
+  fastjet::JetDefinition jetDef(algorithm, rParamBkg, recombScheme, strategy);
+
+  // create an object that specifies how we to define the area
+  fastjet::AreaDefinition areaDef;
+  double ghostEtamax = header->GetGhostEtaMax(); 
+  double ghostArea   = header->GetGhostArea(); 
+  int    activeAreaRepeats = header->GetActiveAreaRepeats(); 
+
+  // now create the object that holds info about ghosts
+
+  fastjet::GhostedAreaSpec ghost_spec(ghostEtamax, activeAreaRepeats, ghostArea);
+  // and from that get an area definition
+  fastjet::AreaType areaType = header->GetAreaType();
+  areaDef = fastjet::AreaDefinition(areaType,ghost_spec);
+  //fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef);
+  fastjet::ClusterSequenceArea clust_seq(inputParticles,jetDef,areaDef);
+  TString comment = "Running FastJet algorithm for BKG calculation with the following setup. ";
+  comment+= "Jet definition: ";
+  comment+= TString(jetDef.description());
+  // comment+= ". Area definition: ";
+  // comment+= TString(areaDef.description());
+  comment+= ". Strategy adopted by FastJet: ";
+  comment+= TString(clust_seq.strategy_string());
+  comment+= Form("Method: %s",method.Data());
+  header->SetComment(comment);
+if(debug>0){
+    cout << "--------------------------------------------------------" << endl;
+    cout << comment << endl;
+    cout << "--------------------------------------------------------" << endl;
+  }
+
+  vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(0.);
+  vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets); 
+  vector<fastjet::PseudoJet> jets2=sorted_by_pt(inclusiveJets);
+  if(jets2.size()>=2) jets2.erase(jets2.begin(),jets2.begin()+1);
+    
+  double phiMin = 0, phiMax = 0, rapMin = 0, rapMax = 0;
+
+  phiMin = 0;
+  phiMax = 2*TMath::Pi();
+  rapMax = ghostEtamax - rParamBkg;
+  rapMin = - ghostEtamax + rParamBkg;
+
+  fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
+
+  double medianb, sigmab, meanareab;
+  clust_seq.get_median_rho_and_sigma(jets2, range, false, medianb, sigmab, 
+                                    meanareab, false);
+  median=medianb;
+  sigma=sigmab;
+  meanarea=meanareab; 
+
+}
+
+//___________________________________________________________________
+Float_t AliFastJetBkg::BkgFastJet()
+{
+  // Return background  
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Bool_t debug  = header->GetDebug();     // debug option
+
+  if(debug>0) cout<<"===============  AliFastJetBkg::BkgFastJet()  =========== "<<endl;
+  vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
+  
+  if(debug>0) cout<<"printing inputParticles for BKG "<<inputParticles.size()<<endl;
+  
+  double rParamBkg = header->GetRparamBkg(); //Radius for background calculation
+  Double_t rho=CalcRho(inputParticles,rParamBkg,"All");
+  if(debug) cout<<"-------- rho (from all part)="<<rho<<endl; 
+  return rho;
+}
+
+//___________________________________________________________________
+Float_t AliFastJetBkg::BkgChargedFastJet()
+{
+  // Background for charged jets
+  
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Bool_t debug  = header->GetDebug();     // debug option
+
+  if(debug>0) cout<<"===============  AliFastJetBkg::BkgChargedFastJet()  =========== "<<endl;
+
+  vector<fastjet::PseudoJet> inputParticlesCharged=fInputFJ->GetInputParticlesCh();
+  
+  if(debug>0) cout<<"printing CHARGED inputParticles for BKG "<<inputParticlesCharged.size()<<endl;
+
+  double rParam = header->GetRparam();
+
+  Double_t rho=CalcRho(inputParticlesCharged,rParam,"Charg");
+
+  if(debug>0) cout<<"-------- rho (from CHARGED part)="<<rho<<endl; 
+  return rho;
+
+}
+
+//___________________________________________________________________
+Float_t AliFastJetBkg::BkgStat()
+{
+  // background subtraction using statistical method
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Bool_t debug  = header->GetDebug();     // debug option
+
+  if(debug>0) cout<<"==============AliFastJetBkg::BkgStat()============="<<endl;
+  //TO BE IMPLEMENTED 
+  Int_t nTracks= 0;
+  TF1 fun("fun",BkgFunction,0,800,1);
+  Double_t enTot=fun.Eval(nTracks);
+  Double_t accEMCal=2*0.7*110./180*TMath::Pi();//2.68 area of EMCal
+  return enTot/accEMCal;
+
+}
+
+//___________________________________________________________________
+Float_t AliFastJetBkg::BkgFastJetCone(TClonesArray* fAODJets)
+{
+  // Cone background subtraction method applied on the fastjet: REmove the particles of the
+  // two largest jets with the given R from the estimation of new rho. 
+
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Bool_t debug  = header->GetDebug();     // debug option
+
+  if(debug>0) cout<<"==============AliFastJetBkg::SubtractFastJetBackgCone()============="<<endl;
+
+  Float_t rc= header->GetRparam();
+
+  //Hard wired Calorimeter area (get it later from the AliJetReaderHeader.h)
+  Double_t accEMCal=2*0.7*110./180*TMath::Pi();//2.68 area of EMCal
+
+  Int_t nJ=fAODJets->GetEntries(); //this must be the # of jets... 
+  if(debug>0) cout<<"nJets:  "<<nJ<<endl;
+  
+  // Information extracted from fInputParticle
+  // load input vectors and calculate total energy in array
+  Float_t pt,eta,phi;
+  Float_t jeteta = 0,jetphi = 0,jeteta1 = 0, jetphi1 = 0;
+  Float_t rhoback=0.0;
+
+  Float_t ptallback=0.0; //particles without the jet
+  Float_t restarea=accEMCal; //initial area set 
+  Bool_t acc=0;
+  Bool_t acc1=0;
+  Float_t rCone=0.4;
+  
+  if(nJ==1) { 
+    AliAODJet *jettmp = (AliAODJet*)(fAODJets->At(0));
+    jeteta=jettmp->Eta();
+    jetphi=jettmp->Phi();
+    acc=EmcalAcceptance(jeteta,jetphi,rCone);
+    if(acc==1)restarea= accEMCal-TMath::Pi()*rc*rc;
+    if(debug) cout<<" acc  "<<acc<<endl;
+  }
+  
+  if(nJ>=2) { 
+    AliAODJet *jettmp = (AliAODJet*)(fAODJets->At(0));
+    AliAODJet *jettmp1 = (AliAODJet*)(fAODJets->At(1));
+    jeteta=jettmp->Eta();
+    jetphi=jettmp->Phi();
+    jeteta1=jettmp1->Eta();
+    jetphi1=jettmp1->Phi(); 
+    acc=EmcalAcceptance(jeteta,jetphi,rCone);
+    acc1=EmcalAcceptance(jeteta1,jetphi1,rCone);
+    if(acc1==1 && acc==1)restarea= accEMCal-2*TMath::Pi()*rc*rc;
+    if(acc1==1 && acc==0)restarea= accEMCal-TMath::Pi()*rc*rc;
+    if(acc1==0 && acc==1)restarea= accEMCal-TMath::Pi()*rc*rc;
+
+    if(debug) cout<<" acc1="<<acc<<"  acc2="<<acc1<<"  restarea="<<restarea<<endl;
+
+  }
+  
+  // cout<<" nIn = "<<nIn<<endl;
+  Float_t sumpt=0;
+  vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
+  for(UInt_t i=0; i<inputParticles.size(); i++)
+    { // Loop over input list of particles
+      pt    = inputParticles[i].perp();
+      eta   = inputParticles[i].eta();
+      phi   = inputParticles[i].phi();
+
+      // To be updated
+      //cout<<"test emcal acceptance for particles "<<EmcalAcceptance(eta,phi,0.)<<endl;
+       
+      Float_t deta=0.0, dphi=0.0, dr=100.0;
+      Float_t deta1=0.0, dphi1=0.0, dr1=100.0;
+
+      //cout<<i<<"  pt="<<pt<<"  eta="<<eta<<"  phi="<<phi<<endl;
+      if(phi>1.396 && phi<3.316 && eta>-0.7 && eta<0.7){
+       sumpt+=pt;
+       //if(i<30)cout<<i<<" pt = "<<pt<<endl;
+
+       if(nJ==1 && acc==1) { 
+         deta = eta - jeteta;
+         dphi = phi - jetphi;
+         if (dphi < -TMath::Pi()) dphi= -dphi - 2.0 * TMath::Pi();
+         if (dphi > TMath::Pi()) dphi = 2.0 * TMath::Pi() - dphi;
+         dr = TMath::Sqrt(deta * deta + dphi * dphi);
+         if(dr<=rc)sumpt-=pt;
+       }
+       
+       if(nJ>=2) { 
+         if(acc==1){
+           deta = eta - jeteta;
+           dphi = phi - jetphi;
+           if (dphi < -TMath::Pi()) dphi= -dphi - 2.0 * TMath::Pi();
+           if (dphi > TMath::Pi()) dphi = 2.0 * TMath::Pi() - dphi;
+           dr = TMath::Sqrt(deta * deta + dphi * dphi);
+           if(dr<=rc)sumpt-=pt;
+         }
+         if(acc1==1){
+           deta1 = eta - jeteta1;
+           dphi1 = phi - jetphi1;
+           if (dphi1 < -TMath::Pi()) dphi1= -dphi1 - 2.0 * TMath::Pi();
+           if (dphi1 > TMath::Pi()) dphi1 = 2.0 * TMath::Pi() - dphi1;
+           dr1 = TMath::Sqrt(deta1 * deta1 + dphi1 * dphi1);
+           if(dr1<=rc)sumpt-=pt;
+         }
+       }
+
+       if(dr >= rc && dr1 >=rc) { 
+         // particles outside both cones
+         if(debug>1) cout<<" out of the cone  "<<dr<<"    "<<deta<<"  deltaeta  "<<dphi<<"  dphi "<<i<<"  particle  "<<endl;
+         if(debug>1) cout<<" out of the cone  "<<dr1<<"    "<<deta1<<"  deltaeta1  "<<dphi1<<"  dphi1 "<<i<<"  particle  "<<endl;
+         ptallback+=pt;
+       }
+      }
+    } // End loop on input list of particles 
+  
+  if(debug>0) cout<<"total area left "<<restarea<<endl;
+  if(debug>0) cout<<"sumpt="<<sumpt<<endl;
+  // if(acc==1 || acc1==1) rhoback= ptallback/restarea;
+  // else rhoback=ptallback;
+
+  rhoback= ptallback/restarea;
+  if(debug)cout<<"rhoback    "<<rhoback<<"     "<<nJ<<"   "<<endl;
+
+  return rhoback;
+   
+}
+
+//___________________________________________________________________
+Double_t AliFastJetBkg::CalcRho(vector<fastjet::PseudoJet> inputParticles,Double_t rParamBkg,TString method)
+{
+  // calculate rho using the fastjet method
+
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Bool_t debug  = header->GetDebug();     // debug option
+
+  fastjet::Strategy strategy = header->GetStrategy();
+  fastjet::RecombinationScheme recombScheme = header->GetRecombScheme();
+  fastjet::JetAlgorithm algorithm = header->GetBGAlgorithm();
+  fastjet::JetDefinition jetDef(algorithm, rParamBkg, recombScheme, strategy);
+
+  // create an object that specifies how we to define the area
+  fastjet::AreaDefinition areaDef;
+  double ghostEtamax       = header->GetGhostEtaMax(); 
+  double ghostArea         = header->GetGhostArea(); 
+  int    activeAreaRepeats = header->GetActiveAreaRepeats(); 
+  
+  // now create the object that holds info about ghosts
+
+  if (method.Contains("Charg"))ghostEtamax=0.9;
+
+  fastjet::GhostedAreaSpec ghost_spec(ghostEtamax, activeAreaRepeats, ghostArea);
+  // and from that get an area definition
+  fastjet::AreaType areaType = header->GetAreaType();
+  areaDef = fastjet::AreaDefinition(areaType,ghost_spec);
+  if(debug>0) cout<<"rParamBkg="<<rParamBkg<<"  ghostEtamax="<<ghostEtamax<<"  ghostArea="<<ghostArea<<" areadef="<<TString(areaDef.description())<< endl;
+  //fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef);
+  fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef,areaDef);
+  TString comment = "Running FastJet algorithm for BKG calculation with the following setup. ";
+  comment+= "Jet definition: ";
+  comment+= TString(jetDef.description());
+  // comment+= ". Area definition: ";
+  // comment+= TString(areaDef.description());
+  comment+= ". Strategy adopted by FastJet: ";
+  comment+= TString(clust_seq.strategy_string());
+  header->SetComment(comment);
+  if(debug>0){
+    cout << "--------------------------------------------------------" << endl;
+    cout << comment << endl;
+    cout << "--------------------------------------------------------" << endl;
+  }
+
+  double ptmin = header->GetPtMin(); 
+  vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
+  vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets); 
+
+  if (debug>0) {
+    cout<<"# of BKG jets = "<<jets.size()<<endl;
+    for (size_t j = 0; j < jets.size(); j++) { // loop for jets   
+      printf("BKG Jet found %5d %9.5f %8.5f %10.3f %4.4f \n",(Int_t)j,jets[j].rap(),jets[j].phi(),jets[j].perp(),clust_seq.area(jets[j]));
+    }
+  }
+  
+  double phiMin = 0, phiMax = 0, rapMin = 0, rapMax = 0;
+
+  if (method.Contains("All")){
+    phiMin = 80.*TMath::Pi()/180+rParamBkg;
+    phiMax = 190.*TMath::Pi()/180-rParamBkg;
+  }
+  if (method.Contains("Charg")){
+    phiMin = 0;
+    phiMax = 2*TMath::Pi();
+  }
+  rapMax = ghostEtamax - rParamBkg;
+  rapMin = - ghostEtamax + rParamBkg;
+
+  fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
+
+  Double_t rho=clust_seq.median_pt_per_unit_area(range);
+  // double median, sigma, meanArea;
+  // clust_seq.get_median_rho_and_sigma(inclusiveJets, range, false, median, sigma, meanArea, true);
+  // fastjet::ActiveAreaSpec area_spec(ghostEtamax,activeAreaRepeats,ghostArea);
+
+  // fastjet::ClusterSequenceActiveArea clust_seq_bkg(inputParticles, jetDef,area_spec);
+
+  if(debug>0) cout<<"bkg in R="<<rParamBkg<<"  : "<<rho<<" range: Rap="<<rapMin<<","<<rapMax<<" --  phi="<<phiMin<<","<<phiMax<<endl;
+
+  return rho;
+
+}
+
+//___________________________________________________________________
+Double_t  AliFastJetBkg::BkgFunction(Double_t */*x*/,Double_t */*par*/)
+{
+  // to be implemented--- (pT + Energy in EMCal Acceptance vs Multiplicity)
+  return 1;
+
+}
+
+//___________________________________________________________________
+Bool_t AliFastJetBkg::EmcalAcceptance(const Float_t eta, const Float_t phi, const Float_t radius) const
+{
+  // Apply emcal acceptance cuts
+  // To be updated
+
+  Float_t meanPhi=190./180.*TMath::Pi()-110./180.*TMath::Pi()/2;
+  Float_t deltaphi=110./180.*TMath::Pi();
+  Float_t phicut=deltaphi/2.-radius;
+  Float_t etacut=0.7-radius;
+  //cout<<"  eta    "<<eta<<"  phi    "<<phi<<endl;
+  //cout<<etacut<<"    "<<phicut<<"    "<<meanPhi<<"    "<<endl;
+  if(TMath::Abs(eta)<etacut && TMath::Abs(phi-meanPhi)<phicut) return 1;
+  else return 0; 
+
+}
diff --git a/JETAN/DEV/AliFastJetBkg.h b/JETAN/DEV/AliFastJetBkg.h
new file mode 100644 (file)
index 0000000..d7bbe71
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef ALIFASTJETBKG_H
+#define ALIFASTJETBKG_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//---------------------------------------------------------------------
+// Class to calculate the background per unit area
+// manages the search for jets 
+// Authors: Elena Bruna elena.bruna@yale.edu
+//          Sevil Salur ssalur@lbl.gov
+//  
+// 2011 :
+// renamed from AliJetBkg to AliFastJetBkg as this class uses only FASTJET based algos        
+//---------------------------------------------------------------------
+
+class TString;
+class AliFastJetInput;
+
+class AliFastJetBkg : public TObject
+{
+ public:
+  AliFastJetBkg();
+  AliFastJetBkg(const AliFastJetBkg &input);
+  AliFastJetBkg& operator=(const AliFastJetBkg& source);
+  virtual          ~AliFastJetBkg() {;}
+  void             SetHeader(AliJetHeader *header)  {fHeader=header;}
+  void             SetFastJetInput(AliFastJetInput *fjinput)  {fInputFJ=fjinput;}
+  void             BkgFastJetb(Double_t& x,Double_t& y, Double_t& z);
+  void             BkgFastJetWoHardest(Double_t& x,Double_t& y, Double_t& z);
+  Float_t          BkgFastJet();
+  Float_t          BkgChargedFastJet();
+  Float_t          BkgStat();
+  Float_t          BkgFastJetCone(TClonesArray* fAODJets);
+
+  Bool_t           EmcalAcceptance(const Float_t eta, const Float_t phi, const Float_t radius) const;
+  static Double_t  BkgFunction(Double_t *x,Double_t *par);
+    
+ private:
+  Double_t         CalcRho(vector<fastjet::PseudoJet> input_particles,Double_t RparamBkg,TString method);
+  void             CalcRhob(Double_t& median, Double_t& sigma, Double_t& meanarea,
+                           vector<fastjet::PseudoJet> input_particles,Double_t RparamBkg,TString method);
+  void             CalcRhoWoHardest(Double_t& median, Double_t& sigma, Double_t& meanarea,
+                                   vector<fastjet::PseudoJet> input_particles,Double_t RparamBkg,TString method);
+
+  AliJetHeader*    fHeader;  //! header
+  AliFastJetInput* fInputFJ; //! input particles
+
+  ClassDef(AliFastJetBkg, 2)   //  Fastjet backgroud analysis
+};
+#endif
diff --git a/JETAN/DEV/AliFastJetFinder.cxx b/JETAN/DEV/AliFastJetFinder.cxx
new file mode 100644 (file)
index 0000000..ddce477
--- /dev/null
@@ -0,0 +1,369 @@
+/**************************************************************************
+ * 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$ */
+
+//---------------------------------------------------------------------
+// FastJet v2.3.4 finder algorithm interface
+// Last modification: Neutral cell energy included in the jet reconstruction
+//
+// Authors: Rafael.Diaz.Valdes@cern.ch
+//          Magali.estienne@subatech.in2p3.fr (neutral part + bg subtraction option)
+//
+// ** 2011 magali.estienne@subatech.in2p3.fr &  alexandre.shabetai@cern.ch
+// new implementation of background subtraction
+// allowing to subtract bkg using a different algo than the one used for signal jets
+//---------------------------------------------------------------------
+
+#include <Riostream.h>
+
+#include "AliFastJetFinder.h"
+#include "AliFastJetHeaderV1.h"
+#include "AliFastJetInput.h"
+#include "AliFastJetBkg.h"
+#include "AliAODJetEventBackground.h"
+#include "AliAODJet.h"
+
+#include "fastjet/PseudoJet.hh"
+#include "fastjet/ClusterSequenceArea.hh"
+#include "fastjet/AreaDefinition.hh"
+#include "fastjet/JetDefinition.hh"
+
+#include<vector> 
+
+using namespace std;
+
+ClassImp(AliFastJetFinder)
+
+////////////////////////////////////////////////////////////////////////
+
+AliFastJetFinder::AliFastJetFinder():
+  AliJetFinder(),
+  fInputFJ(new AliFastJetInput()),
+  fJetBkg(new  AliFastJetBkg())
+{
+  // Constructor
+}
+
+//____________________________________________________________________________
+AliFastJetFinder::~AliFastJetFinder()
+{
+  // destructor
+  delete  fInputFJ;
+  delete  fJetBkg;
+
+}
+
+//______________________________________________________________________________
+void AliFastJetFinder::FindJets()
+{
+  // runs a FASTJET based algo
+
+  //pick up fastjet header
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Int_t  debug  = header->GetDebug();     // debug option
+  Bool_t bgMode = header->GetBGMode();    // choose to subtract BG or not
+  if(debug>0) cout<<"----------in AliFastJetFinder::FindJets() ------------------"<<endl;
+
+  // RUN ALGORITHM  
+  // read input particles -----------------------------
+
+  vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
+  if(inputParticles.size()==0){
+    if(debug>0) Printf("%s:%d No input particles found, skipping event",(char*)__FILE__,__LINE__);
+    return;
+  }
+
+  // create an object that represents your choice of jet algorithm, and 
+  // the associated parameters
+  double rParam = header->GetRparam();
+  double rBkgParam = header->GetRparamBkg();
+  fastjet::Strategy strategy = header->GetStrategy();
+  fastjet::RecombinationScheme recombScheme = header->GetRecombScheme();
+  fastjet::JetAlgorithm algorithm = header->GetAlgorithm(); 
+  fastjet::JetDefinition jetDef(algorithm, rParam, recombScheme, strategy);
+
+  // create an object that specifies how we to define the area
+  fastjet::AreaDefinition areaDef;
+  double ghostEtamax       = header->GetGhostEtaMax(); 
+  double ghostArea         = header->GetGhostArea(); 
+  int    activeAreaRepeats = header->GetActiveAreaRepeats(); 
+  
+  // now create the object that holds info about ghosts
+  fastjet::GhostedAreaSpec ghostSpec(ghostEtamax, activeAreaRepeats, ghostArea);
+  // and from that get an area definition
+  fastjet::AreaType areaType = header->GetAreaType();
+  areaDef = fastjet::AreaDefinition(areaType,ghostSpec);
+  
+  //***************************** JETS FINDING
+  // run the jet clustering with the above jet definition
+  fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
+
+  vector<fastjet::PseudoJet> jets;
+
+  if(bgMode) // Do BG subtraction directly with the same algorithm (cambridge or kt) for jet signal and background
+    {
+      //***************************** JETS FINDING FOR RHO ESTIMATION
+      // run the jet clustering with the above jet definition
+      fastjet::JetAlgorithm algorithmBkg = header->GetBGAlgorithm();
+      fastjet::JetDefinition jetDefBkg(algorithmBkg, rBkgParam, recombScheme, strategy);
+      fastjet::ClusterSequenceArea clust_seq_bkg(inputParticles, jetDefBkg, areaDef);
+
+      // save a comment in the header
+      TString comment = "Running FastJet algorithm with the following setup. ";
+      comment+= "Jet definition: ";
+      comment+= TString(jetDef.description());
+      comment+= "Jet bckg definition: ";
+      comment+= TString(jetDefBkg.description());
+      comment+= ". Area definition: ";
+      comment+= TString(areaDef.description());
+      comment+= ". Strategy adopted by FastJet: ";
+      comment+= TString(clust_seq.strategy_string());
+      header->SetComment(comment);
+      if(debug>0){
+       cout << "--------------------------------------------------------" << endl;
+       cout << comment << endl;
+       cout << "--------------------------------------------------------" << endl;
+      }
+      
+      // extract the inclusive jets sorted by pt
+      double ptmin = header->GetPtMin(); 
+      vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets();
+      
+      //subtract background // ===========================================
+      // set the rapididty , phi range within which to study the background 
+      double rapMax = header->GetRapMax(); 
+      double rapMin = header->GetRapMin();
+      double phiMax = header->GetPhiMax();
+      double phiMin = header->GetPhiMin();
+      fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
+     
+      // Extract rho and sigma
+      Double_t rho = 0.;
+      Double_t sigma = 0.;
+      Double_t meanarea = 0.;
+      Bool_t kUse4VectorArea = header->Use4VectorArea();
+      vector<fastjet::PseudoJet> bkgJets = clust_seq_bkg.inclusive_jets();
+      clust_seq_bkg.get_median_rho_and_sigma(bkgJets,range, kUse4VectorArea, rho, sigma, meanarea, false);
+
+      // subtract background and extract jets bkg subtracted
+      vector<fastjet::PseudoJet> subJets = clust_seq.subtracted_jets(rho,ptmin);
+      
+      // sort jets into increasing pt
+      jets = sorted_by_pt(subJets);  
+
+    }
+
+  else { // No BG subtraction!!!!!!!! Default header is bgmode=0.
+    
+    // save a comment in the header
+    TString comment = "Running FastJet algorithm with the following setup. ";
+    comment+= "Jet definition: ";
+    comment+= TString(jetDef.description());
+    comment+= ". Strategy adopted by FastJet: ";
+    comment+= TString(clust_seq.strategy_string());
+    header->SetComment(comment);
+    if(debug>0){
+      cout << "--------------------------------------------------------" << endl;
+      cout << comment << endl;
+      cout << "--------------------------------------------------------" << endl;
+    }
+  
+    // extract the inclusive jets with pt > ptmin, sorted by pt
+    double ptmin = header->GetPtMin(); 
+    vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
+    
+    jets = sorted_by_pt(inclusiveJets); 
+  
+  }
+   
+  for (size_t j = 0; j < jets.size(); j++) { // loop for jets     
+
+    double area      = clust_seq.area(jets[j]);
+    double areaError = clust_seq.area_error(jets[j]);
+
+    if(debug>0) printf("Jet found %5d %9.5f %8.5f %10.3f \n",(Int_t)j,jets[j].rap(),jets[j].phi(),jets[j].perp());
+
+    vector<fastjet::PseudoJet> constituents = clust_seq.constituents(jets[j]);
+    int nCon= constituents.size();
+    TArrayI ind(nCon);
+      
+    if ((jets[j].eta() > (header->GetJetEtaMax())) ||
+       (jets[j].eta() < (header->GetJetEtaMin())) ||
+       (jets[j].phi() > (header->GetJetPhiMax())) ||
+       (jets[j].phi() < (header->GetJetPhiMin())) ||
+       (jets[j].perp() < header->GetPtMin())) continue; // acceptance eta range and etmin
+
+    // go to write AOD  info
+    AliAODJet aodjet (jets[j].px(), jets[j].py(), jets[j].pz(), jets[j].E());
+    aodjet.SetEffArea(area,areaError);
+    //cout << "Printing jet " << endl;
+    if(debug>0) aodjet.Print("");
+      
+    for (int i=0; i < nCon; i++)
+      {
+       fastjet::PseudoJet mPart=constituents[i];
+       ind[i]=mPart.user_index();
+
+       // Jet constituents (charged tracks) added to the AliAODJet
+       AliJetCalTrkEvent* calEvt  = GetCalTrkEvent();
+       for(Int_t itrack=0; itrack<calEvt->GetNCalTrkTracks(); itrack++)
+         {
+           if(itrack==ind[i])
+             {
+               TObject *track = calEvt->GetCalTrkTrack(itrack)->GetTrackObject();
+               aodjet.AddTrack(track);
+             }
+         }
+      } // End loop on Constituents
+
+    AddJet(aodjet);
+           
+  } // end loop for jets
+
+}
+
+//____________________________________________________________________________
+void AliFastJetFinder::RunTest(const char* datafile)
+{
+  // This simple test run the kt algorithm for an ascii file testdata.dat
+
+  // read input particles -----------------------------
+  vector<fastjet::PseudoJet> inputParticles;
+  Float_t px,py,pz,en;
+  ifstream in;
+  Int_t nlines = 0;
+  // we assume a file basic.dat in the current directory
+  // this file has 3 columns of float data
+  in.open(datafile);
+  while (1) {
+    in >> px >> py >> pz >> en;
+    if (!in.good()) break;
+    //printf("px=%8f, py=%8f, pz=%8fn",px,py,pz);
+    nlines++;
+    inputParticles.push_back(fastjet::PseudoJet(px,py,pz,en)); 
+  }
+  //printf(" found %d pointsn",nlines);
+  in.close();
+  //////////////////////////////////////////////////
+  // create an object that represents your choice of jet algorithm, and 
+  // the associated parameters
+  double rParam = 1.0;
+  fastjet::Strategy strategy = fastjet::Best;
+  fastjet::RecombinationScheme recombScheme = fastjet::BIpt_scheme;
+  fastjet::JetDefinition jetDef(fastjet::kt_algorithm, rParam, recombScheme, strategy);
+  
+  // create an object that specifies how we to define the area
+  fastjet::AreaDefinition areaDef;
+  double ghostEtamax = 7.0;
+  double ghostArea    = 0.05;
+  int    activeAreaRepeats = 1;
+  
+  // now create the object that holds info about ghosts
+  fastjet::GhostedAreaSpec ghostSpec(ghostEtamax, activeAreaRepeats, ghostArea);
+  // and from that get an area definition
+  areaDef = fastjet::AreaDefinition(fastjet::active_area,ghostSpec);
+
+  // run the jet clustering with the above jet definition
+  fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
+  
+  // tell the user what was done
+  cout << "--------------------------------------------------------" << endl;
+  cout << "Jet definition was: " << jetDef.description() << endl;
+  cout << "Area definition was: " << areaDef.description() << endl;
+  cout << "Strategy adopted by FastJet was "<< clust_seq.strategy_string()<<endl<<endl;
+  cout << "--------------------------------------------------------" << endl;
+  
+  // extract the inclusive jets with pt > 5 GeV, sorted by pt
+  double ptmin = 5.0;
+  vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
+  
+  cout << "Number of unclustered particles: " << clust_seq.unclustered_particles().size() << endl;
+  //subtract background // ===========================================
+  // set the rapididty range within which to study the background 
+  double rapMax = ghostEtamax - rParam;
+  fastjet::RangeDefinition range(rapMax);
+  // subtract background
+  vector<fastjet::PseudoJet> subJets =  clust_seq.subtracted_jets(range,ptmin);  
+  
+  // print them out //================================================
+  cout << "Printing inclusive jets  after background subtraction \n";
+  cout << "------------------------------------------------------\n";
+  // sort jets into increasing pt
+  vector<fastjet::PseudoJet> jets = sorted_by_pt(subJets);  
+
+  printf(" ijet   rap      phi        Pt         area  +-   err\n");
+  for (size_t j = 0; j < jets.size(); j++) {
+    double area      = clust_seq.area(jets[j]);
+    double areaError = clust_seq.area_error(jets[j]);
+    printf("%5d %9.5f %8.5f %10.3f %8.3f +- %6.3f\n",(Int_t)j,jets[j].rap(),
+          jets[j].phi(),jets[j].perp(), area, areaError);
+  }
+  cout << endl;
+  // ================================================================
+
+}
+
+//____________________________________________________________________________
+void AliFastJetFinder::WriteJHeaderToFile() const
+{
+  // Write Jet Header to file
+  fHeader->Write();
+
+}
+
+//____________________________________________________________________________
+Bool_t AliFastJetFinder::ProcessEvent()
+{
+  // Process one event
+  // Charged only or charged+neutral jets
+
+  fInputFJ->SetHeader(fHeader);
+  fInputFJ->SetCalTrkEvent(GetCalTrkEvent());
+  fInputFJ->FillInput();
+  
+  // Find Jets
+  FindJets(); 
+
+  // Background
+  if(fAODEvBkg){
+    AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+
+    fJetBkg->SetHeader(fHeader);
+    fJetBkg->SetFastJetInput(fInputFJ);
+    
+     Int_t count = 0;  
+     if(header->GetBkgFastJetb()){
+        Double_t sigma1 = 0 , meanarea1= 0, bkg1 = 0;
+        fJetBkg->BkgFastJetb(bkg1,sigma1,meanarea1);
+        fAODEvBkg->SetBackground(count,bkg1,sigma1,meanarea1);
+        count++;
+     }
+
+     if(header->GetBkgFastJetWoHardest()){
+        Double_t sigma2 = 0 , meanarea2 = 0, bkg2 = 0;
+        fJetBkg->BkgFastJetWoHardest(bkg2,sigma2,meanarea2);
+        fAODEvBkg->SetBackground(count,bkg2,sigma2,meanarea2);
+        count++;
+     }
+
+  }  
+
+  Reset();  
+  return kTRUE;
+
+}
diff --git a/JETAN/DEV/AliFastJetFinder.h b/JETAN/DEV/AliFastJetFinder.h
new file mode 100644 (file)
index 0000000..df594d3
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef ALIFASTJETFINDER_H
+#define ALIFASTJETFINDER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//---------------------------------------------------------------------
+// FastJet v2.3.4 finder algorithm interface
+//
+// Author: Rafael.Diaz.Valdes@cern.ch
+//
+// ** 2011 magali.estienne@subatech.in2p3.fr &  alexandre.shabetai@cern.ch
+// new implementation of background subtraction
+// allowing to subtract bkg using a different algo than the one used for signal jets  
+//---------------------------------------------------------------------
+
+// FastJet classes 
+#include "fastjet/PseudoJet.hh"
+#include "fastjet/ClusterSequenceArea.hh"
+#include "fastjet/AreaDefinition.hh"
+#include "fastjet/JetDefinition.hh"
+
+#include "AliJetFinder.h"
+
+class AliFastJetInput;
+class AliFastJetBkg;
+
+using namespace std;
+
+class AliFastJetFinder : public AliJetFinder
+{
+ public:
+
+  AliFastJetFinder();
+  ~AliFastJetFinder();
+
+  virtual void      FindJets(); 
+  void              RunTest(const char* datafile); // a simple test
+  virtual void      WriteJHeaderToFile() const;
+  virtual Bool_t    ProcessEvent();
+      
+  protected:
+  AliFastJetFinder(const AliFastJetFinder& rfj);
+  AliFastJetFinder& operator = (const AliFastJetFinder& rsfj);
+  AliFastJetInput*  fInputFJ;  //! input particles array
+  AliFastJetBkg*    fJetBkg;   //! pointer to bkg class
+
+  ClassDef(AliFastJetFinder,3) //  Fastjet analysis class
+
+};
+
+#endif
diff --git a/JETAN/DEV/AliFastJetHeaderV1.cxx b/JETAN/DEV/AliFastJetHeaderV1.cxx
new file mode 100644 (file)
index 0000000..698a02c
--- /dev/null
@@ -0,0 +1,89 @@
+/**************************************************************************
+ * 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$ */
+
+//---------------------------------------------------------------------
+// FastJet v2.3.4 finder algorithm interface
+// Finder Header Class 
+// Author: Rafael.Diaz.Valdes@cern.ch
+//---------------------------------------------------------------------
+
+#include <Riostream.h>
+#include <TMath.h>
+
+#include "fastjet/AreaDefinition.hh"
+#include "fastjet/JetDefinition.hh"
+
+#include "AliFastJetHeaderV1.h"
+
+ClassImp(AliFastJetHeaderV1)
+
+////////////////////////////////////////////////////////////////////////
+
+AliFastJetHeaderV1::AliFastJetHeaderV1():
+  AliJetHeader("AliFastJetHeaderV1"),
+  fRparam(0.4),
+  fRparamBkg(0.4),  
+  fAlgorithm(fastjet::kt_algorithm),
+  fBGAlgorithm(fastjet::kt_algorithm),
+  fStrategy(fastjet::Best),
+  fRecombScheme(fastjet::BIpt_scheme),
+  fGhostEtaMax(2.0),
+  fGhostArea(0.01),
+  fActiveAreaRepeats(1),
+  fAreaType(fastjet::active_area), 
+  fPtMin(5.0),
+  fMinCellEt(0.),
+  fRapMax(0.),
+  fRapMin(0.),
+  fPhiMax(TMath::TwoPi()),
+  fPhiMin(0),
+  fUse4VectorArea(kFALSE),
+  fkBkgFastJetb(kFALSE),
+  fktBkgFastJetWoHardest(kFALSE)
+{
+  // Default constructor
+  Double_t rapmax = fGhostEtaMax - fRparam;
+  Double_t rapmin = -fGhostEtaMax + fRparam;
+  SetRapRange(rapmin, rapmax);
+  
+}
+
+//____________________________________________________________________________
+void AliFastJetHeaderV1::PrintParameters() const
+{
+  // prints out parameters of jet algorithm
+
+  cout << "FastJet algorithm  parameters:"           << endl;
+  cout << "-- Jet Definition --- "                   << endl;
+  cout << "R "                                       << fRparam << endl;
+  cout << "Jet Algorithm "                           << fAlgorithm << endl; 
+  cout << "Bkg Jet Algorithm "                       << fBGAlgorithm << endl;
+  cout << "Strategy "                                << fStrategy << endl;  
+  cout << "Recombination Scheme "                    << fRecombScheme << endl; 
+  cout << "-- Ghosted Area Spec parameters --- "     << endl;
+  cout << "Ghost Eta Max "                           << fGhostEtaMax << endl;
+  cout << "Ghost Area "                              << fGhostArea << endl;
+  cout << "Active Area Repeats "                     << fActiveAreaRepeats << endl;
+  cout << "-- Area Definition parameters --- "       << endl;
+  cout << "Area Type "                               << fAreaType << endl; 
+  cout << "-- Cluster Sequence Area parameters --- " << endl;
+  cout << "pt min "                                  << fPtMin << endl; 
+  cout << "-- Range Definition parameters --- "      << endl;
+  cout << " bkg rapidity range from  "               << fRapMin << " to " << fRapMax << endl;
+  cout << " bkg phi range from "                     << fPhiMin << " to " << fPhiMax << endl;
+
+}
diff --git a/JETAN/DEV/AliFastJetHeaderV1.h b/JETAN/DEV/AliFastJetHeaderV1.h
new file mode 100644 (file)
index 0000000..d1c01b8
--- /dev/null
@@ -0,0 +1,102 @@
+#ifndef ALIFASTJETHEADERV1_H
+#define ALIFASTJETHEADERV1_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+//---------------------------------------------------------------------
+// FastJet v2.3.4 finder algorithm interface
+// Finder Header Class 
+// Author: Rafael.Diaz.Valdes@cern.ch
+//---------------------------------------------------------------------
+#include "fastjet/AreaDefinition.hh"
+#include "fastjet/JetDefinition.hh"
+
+#include "AliJetHeader.h"
+
+class AliFastJetHeaderV1 : public AliJetHeader
+{
+ public:
+  AliFastJetHeaderV1();
+  virtual ~AliFastJetHeaderV1() { }
+
+  // Getters
+  Double_t                     GetRparam()              const                  {return fRparam;}
+  fastjet::JetAlgorithm        GetAlgorithm()           const                  {return fAlgorithm;}
+  fastjet::JetAlgorithm        GetBGAlgorithm()         const                  {return fBGAlgorithm;}
+  fastjet::Strategy            GetStrategy()            const                  {return fStrategy;}
+  fastjet::RecombinationScheme GetRecombScheme()        const                  {return fRecombScheme;}
+  Double_t                     GetGhostEtaMax()         const                  {return fGhostEtaMax;}
+  Double_t                     GetGhostArea()           const                  {return fGhostArea;}
+  Int_t                        GetActiveAreaRepeats()   const                  {return fActiveAreaRepeats;}
+  fastjet::AreaType            GetAreaType()            const                  {return fAreaType;}
+  Double_t                     GetPtMin()               const                  {return fPtMin;}
+  Double_t                     GetRapMax()              const                  {return fRapMax;}
+  Double_t                     GetRapMin()              const                  {return fRapMin;}
+  Double_t                     GetPhiMax()              const                  {return fPhiMax;}
+  Double_t                     GetPhiMin()              const                  {return fPhiMin;}
+  Bool_t                       GetBGMode()              const                  {return fBGMode;}
+  Double_t                     GetRparamBkg()           const                  {return fRparamBkg;}
+  Bool_t                       Use4VectorArea()         const                  {return fUse4VectorArea;}
+  Bool_t                       GetBkgFastJetb()         const                  {return fkBkgFastJetb;}   
+  Bool_t                       GetBkgFastJetWoHardest() const                  {return fktBkgFastJetWoHardest;}
+  // Setters
+  void                         SetRparam(Double_t f)                           {fRparam = f;}
+  void                         SetAlgorithm(fastjet::JetAlgorithm f)           {fAlgorithm = f;}
+  void                         SetBGAlgorithm(fastjet::JetAlgorithm f)         {fBGAlgorithm = f;}
+  void                         SetStrategy(fastjet::Strategy f)                {fStrategy = f;}
+  void                         SetRecombScheme(fastjet::RecombinationScheme f) {fRecombScheme = f;}
+  void                         SetGhostEtaMax(Double_t f)                      {fGhostEtaMax = f;}
+  void                         SetGhostArea(Double_t f)                        {fGhostArea = f;}
+  void                         SetActiveAreaRepeats(Int_t f)                   {fActiveAreaRepeats =f;}
+  void                         SetAreaType(fastjet::AreaType f)                {fAreaType = f;}
+  void                         SetRapRange(Double_t fmin, Double_t fmax)       {fRapMin = fmin; fRapMax = fmax;}
+  void                         SetPhiRange(Double_t fmin, Double_t fmax)       {fPhiMin = fmin; fPhiMax = fmax;}
+  void                         SetPtMin(Double_t ptmin)                        {fPtMin = ptmin;}
+  void                         SetBGMode(Bool_t bgmode)                        {fBGMode = bgmode;}
+  void                         SetUse4VectorArea()                             {fUse4VectorArea = kTRUE;}
+  void                         SetComment(TString com)                         {fComment=com;}
+  void                         SetComment(const char* com)                     {AliJetHeader::SetComment(com);}
+  void                         SetRparamBkg(Double_t f)                        {fRparamBkg = f;}
+  void                         SetBkgFastJetb(Bool_t f = 1)                    {fkBkgFastJetb = f;}     
+  void                         SetBkgFastJetWoHardest(Bool_t f = 1)            {fktBkgFastJetWoHardest = f;}
+  // others
+  void                         PrintParameters() const;
+
+ protected:
+  //fastjet::JetDefinition parameters
+  Double_t                     fRparam;                // R param
+  Double_t                     fRparamBkg;             // R param for bkg calculation
+  fastjet::JetAlgorithm        fAlgorithm;             // fastjet::kt_algorithm
+  fastjet::JetAlgorithm        fBGAlgorithm;           // fastjet::kt_algorithm
+  fastjet::Strategy            fStrategy;              // fastjet::Best;
+  fastjet::RecombinationScheme fRecombScheme;          // fastjet::BIpt_scheme;
+  
+  //fastjet::GhostedAreaSpec parameters
+  Double_t                     fGhostEtaMax;           // Max eta for ghosts
+  Double_t                     fGhostArea;             // Ghost area 
+  Int_t                        fActiveAreaRepeats;     // Active are repetitions
+  
+  //fastjet::AreaDefinition parameters
+  fastjet::AreaType            fAreaType;              // area types
+  
+  //fastjet::ClusterSequenceArea options parameters
+  Double_t                     fPtMin;                 // jets with pt > ptmin
+  Float_t                      fMinCellEt;             // Min Et in one cell
+
+  //fastjet::RangeDefinition parameters 
+  Double_t                     fRapMax, fRapMin;       // rapidity range of background sub 
+  Double_t                     fPhiMax, fPhiMin;       // phi range of background sub
+  Bool_t                       fUse4VectorArea;        // Toggle use of 4-vector area
+  
+  //background methods flags
+  Bool_t                       fkBkgFastJetb;          // Toggle background estimation using AliFastJetBkg::BkgFastJetb()
+  Bool_t                       fktBkgFastJetWoHardest; // Toggle background estimation using AliFastJetBkg::BkgFastJetWoHardest()  
+  ClassDef(AliFastJetHeaderV1,4)                       // Fastjet header class
+};
+#endif
diff --git a/JETAN/DEV/AliFastJetInput.cxx b/JETAN/DEV/AliFastJetInput.cxx
new file mode 100644 (file)
index 0000000..89ae79c
--- /dev/null
@@ -0,0 +1,132 @@
+/**************************************************************************
+ * 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 for input particles
+// manages the search for jets
+// Authors: Elena Bruna elena.bruna@yale.edu
+//
+// ** 2011 magali.estienne@subatech.in2p3.fr &  alexandre.shabetai@cern.ch
+// Modified accordingly to reader/finder splitting and new handling of neutral information
+//---------------------------------------------------------------------
+
+#include <Riostream.h> 
+
+#include "AliJetHeader.h"
+#include "AliFastJetHeaderV1.h"
+#include "AliFastJetInput.h"
+#include "AliJetCalTrk.h"
+
+#include "fastjet/PseudoJet.hh"
+
+#include<vector> 
+
+using namespace std;
+
+ClassImp(AliFastJetInput)
+
+////////////////////////////////////////////////////////////////////////
+
+AliFastJetInput::AliFastJetInput():
+  fHeader(0x0),
+  fCalTrkEvent(0x0),
+  fInputParticles(0),
+  fInputParticlesCh(0)
+{
+  // Default constructor
+}
+
+//______________________________________________________________________
+AliFastJetInput::AliFastJetInput(const AliFastJetInput &input):
+  TObject(input),
+  fHeader(input.fHeader),
+  fCalTrkEvent(input.fCalTrkEvent),
+  fInputParticles(input.fInputParticles),
+  fInputParticlesCh(input.fInputParticlesCh)
+{
+  // copy constructor
+}
+
+//______________________________________________________________________
+AliFastJetInput& AliFastJetInput::operator=(const AliFastJetInput& source)
+{
+  // Assignment operator. 
+  if(this!=&source){
+   TObject::operator=(source);
+   fHeader = source.fHeader;
+   fCalTrkEvent = source.fCalTrkEvent;
+   fInputParticles = source.fInputParticles;
+   fInputParticlesCh = source.fInputParticlesCh;
+  }
+
+  return *this;
+
+}
+
+//___________________________________________________________
+void AliFastJetInput::FillInput()
+{
+  // fills input particles for FASTJET based analysis
+  
+  AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
+  Int_t debug  = header->GetDebug();     // debug option
+
+  if(debug>0) cout<<"-------- AliFastJetInput::FillInput()  ----------------"<<endl;
+
+  fInputParticles.clear();
+  fInputParticlesCh.clear();
+
+  // RUN ALGORITHM  
+  // read input particles -----------------------------
+  vector<fastjet::PseudoJet> inputParticles;
+
+  if(fCalTrkEvent == 0) { cout << "Could not get the CalTrk Event" << endl; return; }
+  Int_t nIn =  fCalTrkEvent->GetNCalTrkTracks() ;
+  if(nIn == 0) { if (debug>0) cout << "entries = 0 ; Event empty !!!" << endl ; return; }
+
+  // Information extracted from fCalTrkEvent
+  // load input vectors and calculate total energy in array
+  Float_t px = -999., py = -999., pz = -999., en = -999.; 
+  // Fill charged tracks
+  for(Int_t i = 0; i < fCalTrkEvent->GetNCalTrkTracks(); i++)
+    { // loop for all input particles
+      if (fCalTrkEvent->GetCalTrkTrack(i)->GetCutFlag() != 1) continue;
+      px =  fCalTrkEvent->GetCalTrkTrack(i)->GetPx();
+      py =  fCalTrkEvent->GetCalTrkTrack(i)->GetPy();
+      pz =  fCalTrkEvent->GetCalTrkTrack(i)->GetPz();
+      en =  fCalTrkEvent->GetCalTrkTrack(i)->GetP();
+
+      fastjet::PseudoJet inputPart(px,py,pz,en);  // create PseudoJet object
+      inputPart.set_user_index(i);      //label the particle into Fastjet algortihm
+      fInputParticles.push_back(inputPart);       // back of the inputParticles vector
+      // only for charged particles (TPC+ITS)
+      fastjet::PseudoJet inputPartCh(px,py,pz,en); // create PseudoJet object
+      inputPartCh.set_user_index(i);               //label the particle into Fastjet algortihm
+      fInputParticlesCh.push_back(inputPartCh);    // back of the inputParticles vector
+    } // End loop on CalTrk
+
+}
+
+//_____________________________________________________________________
+Double_t AliFastJetInput::Thermalspectrum(const Double_t *x, const Double_t *par)
+{
+  // compute an exponential function
+  return x[0]*TMath::Exp(-x[0]/par[0]);
+
+}
diff --git a/JETAN/DEV/AliFastJetInput.h b/JETAN/DEV/AliFastJetInput.h
new file mode 100644 (file)
index 0000000..9e6425e
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef ALIFASTJETINPUT_H
+#define ALIFASTJETINPUT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//---------------------------------------------------------------------
+// Class for input particles
+// manages the search for jets 
+// Authors: Elena Bruna elena.bruna@yale.edu
+//
+// ** 2011 magali.estienne@subatech.in2p3.fr &  alexandre.shabetai@cern.ch             
+// Modified accordingly to reader/finder splitting and new handling of neutral information
+//---------------------------------------------------------------------
+
+#include <TObject.h>
+
+// FastJet classes 
+#include "fastjet/PseudoJet.hh"
+
+#include <vector> 
+
+class AliJetCalTrkEvent;
+class AliJetHeader;
+
+class AliFastJetInput : public TObject
+{
+ public:
+  AliFastJetInput();
+  AliFastJetInput(const AliFastJetInput &input);
+  AliFastJetInput& operator=(const AliFastJetInput& source);
+  virtual                    ~AliFastJetInput() {;}
+  void                       SetHeader(AliJetHeader *header)            {fHeader=header;}
+  void                       SetCalTrkEvent(AliJetCalTrkEvent *caltrk)  {fCalTrkEvent=caltrk;}
+  void                       FillInput();
+  vector<fastjet::PseudoJet> GetInputParticles()   const                {return fInputParticles;}
+  vector<fastjet::PseudoJet> GetInputParticlesCh() const                {return fInputParticlesCh;}
+  static Double_t            Thermalspectrum(const Double_t *x, const Double_t *par);
+
+ private:
+  AliJetHeader *fHeader;                        //! header 
+  AliJetCalTrkEvent *fCalTrkEvent;              //! caltrkevent
+   
+  vector<fastjet::PseudoJet> fInputParticles;   //! input particles for FastJet
+  vector<fastjet::PseudoJet> fInputParticlesCh; //! input charged particles for FastJet
+
+  ClassDef(AliFastJetInput, 2)                  //  fills input particles for FASTJET based analysis
+    
+};
+#endif
diff --git a/JETAN/DEV/AliJetBkg.cxx b/JETAN/DEV/AliJetBkg.cxx
new file mode 100644 (file)
index 0000000..9409d4a
--- /dev/null
@@ -0,0 +1,564 @@
+/**************************************************************************
+ * 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$ */
+
+//--------------------------------------------------
+// Method implementation for background studies and background subtraction with UA1 algorithms
+//
+// Author: magali.estienne@subatech.in2p3.fr
+//-------------------------------------------------
+
+#include <Riostream.h> 
+#include <TList.h>
+#include <TClonesArray.h>
+#include <TH1F.h>
+#include <TH2F.h>
+
+#include "AliAODJetEventBackground.h"