]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - JETAN/AliUA1JetFinderV2.cxx
removed unnecessary constants
[u/mrichter/AliRoot.git] / JETAN / AliUA1JetFinderV2.cxx
index 47f9ce693f0810a6a46c6829f6e3509cd46d00da..0e73b96a28d330625d4f67f0980b5caa628cdd2b 100644 (file)
 // Author: magali.estienne@subatech.in2p3.fr
 //---------------------------------------------------------------------
 
-#include <Riostream.h>
-#include <vector>
-
-#include <TArrayF.h>
 #include <TClonesArray.h>
-#include <TFile.h>
 #include <TH1F.h>
 #include <TH2F.h>
 #include <TLorentzVector.h>
 #include <TMath.h>
 #include <TRefArray.h>
+#include "TFile.h"
 
 #include "AliUA1JetFinderV2.h"
 #include "AliUA1JetHeaderV1.h"
 #include "AliJetUnitArray.h"
 #include "AliJetReaderHeader.h"
 #include "AliJetReader.h"
-#include "AliJet.h"
-#include "AliAODJet.h"
+#include "AliJetHeader.h"
 
+class TArrayF;
+class TFile;
+class AliJetReader;
+class AliAODJet;
 
 ClassImp(AliUA1JetFinderV2)
 
@@ -51,7 +50,6 @@ ClassImp(AliUA1JetFinderV2)
 AliUA1JetFinderV2::AliUA1JetFinderV2() :
   AliJetFinder(),
   fLego(0),  
-  fDebug(0),
   fOpt(0)
 {
   //
@@ -88,6 +86,7 @@ void AliUA1JetFinderV2::FindJetsC()
   AliUA1JetHeaderV1* header  = (AliUA1JetHeaderV1*) fHeader;
   TClonesArray*      lvArray = fReader->GetMomentumArray();
   Int_t              nIn     = lvArray->GetEntries();
+  fDebug   = fHeader->GetDebug();
   
   if (nIn == 0) return;
   
@@ -95,10 +94,18 @@ void AliUA1JetFinderV2::FindJetsC()
   Float_t* ptT    = new Float_t[nIn];
   Float_t* etaT   = new Float_t[nIn];
   Float_t* phiT   = new Float_t[nIn];
-  Float_t* cFlagT = new Float_t[nIn]; // Temporarily added
-  Float_t* sFlagT = new Float_t[nIn]; // Temporarily added
+  Int_t*   cFlagT = new Int_t[nIn]; // Temporarily added
+  Int_t*   sFlagT = new Int_t[nIn]; // Temporarily added
   Int_t*   injet  = new Int_t[nIn];
-  
+
+  for (Int_t i = 0; i < nIn; i++) {
+    ptT[i]    = 0.;
+    etaT[i]   = 0.;
+    phiT[i]   = 0.;
+    cFlagT[i] = 0; 
+    sFlagT[i] = 0; 
+    injet[i]  = 0;
+  }
   //total energy in array
   Float_t  etbgTotal = 0.0;
   TH1F*    hPtTotal  = new TH1F("hPt","Pt distribution of all particles ",100,0.0,15.0);
@@ -109,8 +116,8 @@ void AliUA1JetFinderV2::FindJetsC()
     ptT[i]  = lv->Pt();
     etaT[i] = lv->Eta();
     phiT[i] = ((lv->Phi() < 0) ? (lv->Phi()) + 2 * TMath::Pi() : lv->Phi());
-    cFlagT[i] = fReader->GetCutFlag(i); // Temporarily added
-    sFlagT[i] = fReader->GetSignalFlag(i); // Temporarily added peut-etre a mettre apres cut en pt !!!
+    cFlagT[i] = fReader->GetCutFlag(i); 
+    sFlagT[i] = fReader->GetSignalFlag(i); 
     
     if (fReader->GetCutFlag(i) != 1) continue;
     fLego->Fill(etaT[i], phiT[i], ptT[i]);
@@ -118,7 +125,6 @@ void AliUA1JetFinderV2::FindJetsC()
     etbgTotal+= ptT[i];
   }
   
-  fJets->SetNinput(nIn);
   
   // calculate total energy and fluctuation in map
   Double_t meanpt   = hPtTotal->GetMean();
@@ -127,21 +133,21 @@ void AliUA1JetFinderV2::FindJetsC()
   Double_t dEtTotal = (TMath::Sqrt(npart))*TMath::Sqrt(meanpt * meanpt + ptRMS*ptRMS);
   
   // arrays to hold jets
-  Float_t* etaJet    = new Float_t[30];
-  Float_t* phiJet    = new Float_t[30];
-  Float_t* etJet     = new Float_t[30];
-  Float_t* etsigJet  = new Float_t[30]; //signal et in jet
-  Float_t* etallJet  = new Float_t[30];  // total et in jet (tmp variable)
-  Int_t*   ncellsJet = new Int_t[30];
-  Int_t*   multJet   = new Int_t[30];
+  Float_t etaJet[30];  // eta jet
+  Float_t phiJet[30];  // phi jet
+  Float_t etJet[30];  // et jet
+  Float_t etsigJet[30];  // signal et in jet
+  Float_t etallJet[30];  // total et in jet (tmp variable)
+  Int_t   ncellsJet[30];
+  Int_t   multJet[30];
   //--- Added for jet reordering at the end of the jet finding procedure
-  Float_t* etaJetOk    = new Float_t[30];
-  Float_t* phiJetOk    = new Float_t[30];
-  Float_t* etJetOk     = new Float_t[30];
-  Float_t* etsigJetOk  = new Float_t[30]; //signal et in jet
-  Float_t* etallJetOk  = new Float_t[30];  // total et in jet (tmp variable)
-  Int_t*   ncellsJetOk = new Int_t[30];
-  Int_t*   multJetOk   = new Int_t[30];
+  Float_t etaJetOk[30];
+  Float_t phiJetOk[30];
+  Float_t etJetOk[30];
+  Float_t etsigJetOk[30];  // signal et in jet
+  Float_t etallJetOk[30];  // total et in jet (tmp variable)
+  Int_t   ncellsJetOk[30];
+  Int_t   multJetOk[30];
   //--------------------------
   Int_t nJets; // to hold number of jets found by algorithm
   Int_t nj;    // number of jets accepted
@@ -181,7 +187,6 @@ void AliUA1JetFinderV2::FindJetsC()
     //subtract background
     Float_t etbgTotalN = 0.0; //new background
     if(header->GetBackgMode() == 1) // standard
-      //      SubtractBackgC(nIn,nj,etbgTotalN,ptT,etaT,phiT,cFlagT,sFlagT,etJet,etaJet,phiJet,etsigJet,multJet,injet);
       SubtractBackgC(nIn,nj,etbgTotalN,ptT,etaT,phiT,etJet,etaJet,phiJet,etsigJet,multJet,injet);
     if(header->GetBackgMode() == 2) //cone
       SubtractBackgCone(nIn,nj,etbgTotalN,ptT,etaT,phiT,cFlagT,sFlagT,etJet,etaJet,phiJet,etsigJet,multJet,injet);
@@ -190,7 +195,7 @@ void AliUA1JetFinderV2::FindJetsC()
     if(header->GetBackgMode() == 4) //statistic
       SubtractBackgStat(nIn,nj,etbgTotalN,ptT,etaT,phiT,cFlagT,sFlagT,etJet,etaJet,phiJet,etsigJet,multJet,injet);
     //calc precision
-    if(etbgTotalN != 0.0)
+    if(TMath::Abs(etbgTotalN) > 0.001)
       bgprec = (etbgTotal - etbgTotalN)/etbgTotalN;
     else
       bgprec = 0;
@@ -210,6 +215,7 @@ void AliUA1JetFinderV2::FindJetsC()
     phiJetOk[p]    = phiJet[idx[p]];
     etJetOk[p]     = etJet[idx[p]];
     etallJetOk[p]  = etJet[idx[p]];
+    etsigJetOk[p]  = etsigJet[idx[p]];
     ncellsJetOk[p] = ncellsJet[idx[p]];
     multJetOk[p]   = multJet[idx[p]];
   }
@@ -224,7 +230,6 @@ void AliUA1JetFinderV2::FindJetsC()
       py = etJetOk[kj] * TMath::Sin(phiJetOk[kj]);
       pz = etJetOk[kj] / TMath::Tan(2.0 * TMath::ATan(TMath::Exp(-etaJetOk[kj])));
       en = TMath::Sqrt(px * px + py * py + pz * pz);
-      fJets->AddJet(px, py, pz, en);
       
       AliAODJet jet(px, py, pz, en);
       jet.Print("");
@@ -261,14 +266,6 @@ void AliUA1JetFinderV2::FindJetsC()
       if(bflag == 0) injet[bj] = -1; // set as background particle
     }
 
-  fJets->SetNCells(ncells);
-  fJets->SetPtFromSignal(percentage);
-  fJets->SetMultiplicities(mult);
-  fJets->SetInJet(injet);
-  fJets->SetEtaIn(etaT);
-  fJets->SetPhiIn(phiT);
-  fJets->SetPtIn(ptT);
-  fJets->SetEtAvg(etbgTotal/(4*(header->GetLegoEtaMax())*TMath::Pi()));
  
   //delete
   delete[] ptT;
@@ -277,26 +274,13 @@ void AliUA1JetFinderV2::FindJetsC()
   delete[] cFlagT;
   delete[] sFlagT;
   delete[] injet;
-  delete[] hPtTotal;
-  delete[] etaJet;
-  delete[] phiJet;
-  delete[] etJet;
-  delete[] etsigJet;
-  delete[] etallJet;
-  delete[] ncellsJet;
-  delete[] multJet;
+  delete hPtTotal;
   delete[] idxjets;
+  delete[] idx;
+
   delete[] percentage;
   delete[] ncells;
   delete[] mult;
-  //--- Added for jet reordering
-  delete etaJetOk;
-  delete phiJetOk;
-  delete etJetOk;
-  delete etsigJetOk;
-  delete etallJetOk;
-  delete ncellsJetOk;
-  delete multJetOk;
   //--------------------------
 
 }
@@ -325,7 +309,7 @@ void AliUA1JetFinderV2::FindJets()
   Int_t              nCand    = fReader->GetNumCandidate();
   Int_t              nCandCut = fReader->GetNumCandidateCut();
   Int_t              nIn      = fUnit->GetEntries();
-  Float_t            fPtMin   = fReader->GetReaderHeader()->GetPtCut();
+  Float_t            ptMin   = fReader->GetReaderHeader()->GetPtCut();
 
   if (nIn == 0) return;
 
@@ -337,38 +321,62 @@ void AliUA1JetFinderV2::FindJets()
 
   // local arrays for input No Cuts
   // Both pt < ptMin and pt > ptMin
-  Float_t* ptT       = new Float_t[nCandidate];
-  Float_t* en2T      = new Float_t[nCandidate];
-  Float_t* pt2T      = new Float_t[nCandidate];
-  Int_t*   detT      = new Int_t[nCandidate]; 
-  Float_t* etaT      = new Float_t[nCandidate];
-  Float_t* phiT      = new Float_t[nCandidate];
-  Float_t* cFlagT    = new Float_t[nCandidate];
-  Float_t* cFlag2T   = new Float_t[nCandidate];
-  Float_t* sFlagT    = new Float_t[nCandidate];
-  Float_t* cClusterT = new Float_t[nCandidate];
-  Int_t*   vectT     = new Int_t[nCandidate];
-  Int_t    loop1     = 0;
-  Int_t*   injet     = new Int_t[nCandidate];
-  Int_t*   sflag     = new Int_t[nCandidate];
-  vector< vector<Float_t> > pxT;
-  vector< vector<Float_t> > pyT;
-  vector< vector<Float_t> > pzT;
+  Float_t*   ptT       = new Float_t[nCandidate];
+  Float_t*   en2T      = new Float_t[nCandidate];
+  Float_t*   pt2T      = new Float_t[nCandidate];
+  Int_t*     detT      = new Int_t[nCandidate]; 
+  Float_t*   etaT      = new Float_t[nCandidate];
+  Float_t*   phiT      = new Float_t[nCandidate];
+  Int_t*     cFlagT    = new Int_t[nCandidate];
+  Int_t*     cFlag2T   = new Int_t[nCandidate];
+  Int_t*     sFlagT    = new Int_t[nCandidate];
+  Float_t*   cClusterT = new Float_t[nCandidate];
+  Int_t*     vectT     = new Int_t[nCandidate];
+  Int_t      loop1     = 0;
+  Int_t*     injet     = new Int_t[nCandidate];
+  Int_t*     sflag     = new Int_t[nCandidate];
+  
+  for(Int_t i = 0; i < nCandidate; i++) {
+      ptT[i]       = 0;
+      en2T[i]      = 0;
+      pt2T[i]      = 0;
+      detT[i]      = 0;
+      etaT[i]      = 0;
+      phiT[i]      = 0;
+      cFlagT[i]    = 0;
+      cFlag2T[i]   = 0;
+      sFlagT[i]    = 0;
+      cClusterT[i] = 0;
+      vectT[i]     = 0;
+      injet[i]     = 0;
+      sflag[i]     = 0;
+}
+
+  TRefArray* trackRef  = new TRefArray();
 
   //total energy in array
-  Float_t  etbgTotal = 0.0;
-  TH1F* hPtTotal = new TH1F("hPt","Pt distribution of all particles ",100,0.0,15.0);
+  Float_t etbgTotal = 0.0;
+  TH1F*    hPtTotal  = new TH1F("hPt","Pt distribution of all particles ",100,0.0,15.0);
 
   // Input cell info
-  Float_t *etCell = new Float_t[nIn];   //! Cell Energy - Extracted from UnitArray
-  Float_t *etaCell = new Float_t[nIn];  //! Cell eta - Extracted from UnitArray
-  Float_t *phiCell = new Float_t[nIn];  //! Cell phi - Extracted from UnitArray
-  Int_t   *flagCell = new Int_t[nIn];   //! Cell phi - Extracted from UnitArray
-  Float_t *etCell2 = new Float_t[nIn];  //! Cell Energy - Extracted from UnitArray
-  Float_t *etaCell2 = new Float_t[nIn]; //! Cell eta - Extracted from UnitArray
-  Float_t *phiCell2 = new Float_t[nIn]; //! Cell phi - Extracted from UnitArray
+  Float_t *etCell    = new Float_t[nIn];   //! Cell Energy - Extracted from UnitArray
+  Float_t *etaCell   = new Float_t[nIn];  //! Cell eta - Extracted from UnitArray
+  Float_t *phiCell   = new Float_t[nIn];  //! Cell phi - Extracted from UnitArray
+  Int_t   *flagCell  = new Int_t[nIn];   //! Cell phi - Extracted from UnitArray
+  Float_t *etCell2   = new Float_t[nIn];  //! Cell Energy - Extracted from UnitArray
+  Float_t *etaCell2  = new Float_t[nIn]; //! Cell eta - Extracted from UnitArray
+  Float_t *phiCell2  = new Float_t[nIn]; //! Cell phi - Extracted from UnitArray
   Int_t   *flagCell2 = new Int_t[nIn];  //! Cell phi - Extracted from UnitArray
-
+  for(Int_t i = 0; i < nIn; i++) {
+    etCell[i]    = 0.;
+    etaCell[i]   = 0.;
+    phiCell[i]   = 0.;
+    flagCell[i]  = 0;
+    etCell2[i]   = 0.;
+    etaCell2[i]  = 0.;
+    phiCell2[i]  = 0.;
+    flagCell2[i] = 0;
+  }
   // Information extracted from fUnitArray
   // Load input vectors and calculate total energy in array
   for(Int_t i=0; i<nIn; i++) 
@@ -376,25 +384,13 @@ void AliUA1JetFinderV2::FindJets()
       // Recover particle information from UnitArray
       
       AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(i);
-      
+      TRefArray* ref = uArray->GetUnitTrackRef();
+      Int_t nRef = ref->GetEntries();
+
       if(uArray->GetUnitEnergy()>0.){
-       vector<Float_t> vtmpx; 
-       vector<Float_t> vtmpy; 
-       vector<Float_t> vtmpz; 
-       for(Int_t j=0; j<uArray->GetUnitVectorSize();j++)
-         {
-           Float_t x=0.;  Float_t y=0.;  Float_t z=0.;
-           uArray->GetUnitPxPyPz(j,x,y,z);
-           vtmpx.push_back(x);
-           vtmpy.push_back(y);
-           vtmpz.push_back(z);
-         }
-       pxT.push_back(vtmpx);
-       pyT.push_back(vtmpy);
-       pzT.push_back(vtmpz);
-       vtmpx.clear();
-       vtmpy.clear();
-       vtmpz.clear();
+
+       for(Int_t jpart=0; jpart<nRef;jpart++)
+         trackRef->Add((AliVTrack*)ref->At(jpart));
        ptT[loop1]   = uArray->GetUnitEnergy();
         detT[loop1]  = uArray->GetUnitDetectorFlag();
        etaT[loop1]  = uArray->GetUnitEta();
@@ -402,7 +398,7 @@ void AliUA1JetFinderV2::FindJets()
        cFlagT[loop1]= uArray->GetUnitCutFlag();   // pt cut tpc
        cFlag2T[loop1]= uArray->GetUnitCutFlag2(); // pt cut emcal
        sFlagT[loop1]= uArray->GetUnitSignalFlag();
-       vectT[loop1] = uArray->GetUnitVectorSize();
+       vectT[loop1] = nRef;
        if(cFlagT[loop1] == 1 || cFlag2T[loop1] == 1) {
          pt2T[loop1] = 0.;
          en2T[loop1] = 0.;
@@ -414,11 +410,13 @@ void AliUA1JetFinderV2::FindJets()
          }
          if(detT[loop1]==0){ // TPC+ITS
            Float_t pt = 0.;
-           for(Int_t j=0; j<vectT[loop1];j++){
+           for(Int_t j=0; j<nRef;j++){
              Float_t x=0.;  Float_t y=0.;  Float_t z=0.;
-             uArray->GetUnitPxPyPz(j,x,y,z);
+             x = ((AliVTrack*)ref->At(j))->Px();
+             y = ((AliVTrack*)ref->At(j))->Py();
+             z = ((AliVTrack*)ref->At(j))->Pz();
              pt = TMath::Sqrt(x*x+y*y);
-             if(pt>fPtMin) {
+             if(pt>ptMin) {
                pt2T[loop1] += pt;
                en2T[loop1] += pt;
                hPtTotal->Fill(pt);
@@ -430,11 +428,13 @@ void AliUA1JetFinderV2::FindJets()
            Float_t ptCTot = 0.;
            Float_t pt = 0.;
            Float_t enC = 0.;
-           for(Int_t j=0; j<vectT[loop1];j++) {
+           for(Int_t j=0; j<nRef;j++){
              Float_t x=0.;  Float_t y=0.;  Float_t z=0.;
-             uArray->GetUnitPxPyPz(j,x,y,z);
+             x = ((AliVTrack*)ref->At(j))->Px();
+             y = ((AliVTrack*)ref->At(j))->Py();
+             z = ((AliVTrack*)ref->At(j))->Pz();
              pt = TMath::Sqrt(x*x+y*y);
-             if(pt>fPtMin) {
+             if(pt>ptMin) {
                pt2T[loop1]+=pt;
                en2T[loop1]+=pt;
                hPtTotal->Fill(pt);
@@ -466,12 +466,14 @@ void AliUA1JetFinderV2::FindJets()
         }
         if(uArray->GetUnitDetectorFlag()==0){ // TPC case
           Float_t pt = 0.; Float_t et1 = 0.; Float_t et2 = 0.;
-          for(Int_t j=0; j<uArray->GetUnitVectorSize();j++)
+          for(Int_t j=0; j<nRef;j++)
             {
               Float_t x=0.;  Float_t y=0.;  Float_t z=0.;
-              uArray->GetUnitPxPyPz(j,x,y,z);
+             x = ((AliVTrack*)ref->At(j))->Px();
+             y = ((AliVTrack*)ref->At(j))->Py();
+             z = ((AliVTrack*)ref->At(j))->Pz();
               pt = TMath::Sqrt(x*x+y*y);
-              if(pt>fPtMin) {
+              if(pt>ptMin) {
                 et1 += pt;
                 et2 += pt;
               }
@@ -490,12 +492,14 @@ void AliUA1JetFinderV2::FindJets()
           Float_t ptCTot = 0.;
           Float_t pt = 0.; Float_t et1 = 0.; Float_t et2 = 0.;
           Float_t enC = 0.;
-          for(Int_t j=0; j<uArray->GetUnitVectorSize();j++)
+          for(Int_t j=0; j<nRef;j++)
             {
               Float_t x=0.;  Float_t y=0.;  Float_t z=0.;
-              uArray->GetUnitPxPyPz(j,x,y,z);
+             x = ((AliVTrack*)ref->At(j))->Px();
+             y = ((AliVTrack*)ref->At(j))->Py();
+             z = ((AliVTrack*)ref->At(j))->Pz();
               pt = TMath::Sqrt(x*x+y*y);
-              if(pt>fPtMin) {
+              if(pt>ptMin) {
                 et1 += pt;
                 et2 += pt;
               }
@@ -525,7 +529,6 @@ void AliUA1JetFinderV2::FindJets()
       }
     } // end loop on nCandidate
 
-  fJets->SetNinput(nCandidate);
 
   // calculate total energy and fluctuation in map
   Double_t meanpt = hPtTotal->GetMean();
@@ -534,21 +537,21 @@ void AliUA1JetFinderV2::FindJets()
   Double_t dEtTotal = (TMath::Sqrt(npart))*TMath::Sqrt(meanpt * meanpt + ptRMS*ptRMS);
 
   // arrays to hold jets
-  Float_t* etaJet    = new Float_t[30];
-  Float_t* phiJet    = new Float_t[30];
-  Float_t* etJet     = new Float_t[30];
-  Float_t* etsigJet  = new Float_t[30]; //signal et in jet
-  Float_t* etallJet  = new Float_t[30];  // total et in jet (tmp variable)
-  Int_t*   ncellsJet = new Int_t[30];
-  Int_t*   multJet   = new Int_t[30];
+  Float_t etaJet[30];
+  Float_t phiJet[30];
+  Float_t etJet[30];
+  Float_t etsigJet[30]; //signal et in jet
+  Float_t etallJet[30];  // total et in jet (tmp variable)
+  Int_t   ncellsJet[30];
+  Int_t   multJet[30];
   //--- Added by me for jet reordering at the end of the jet finding procedure
-  Float_t* etaJetOk    = new Float_t[30];
-  Float_t* phiJetOk    = new Float_t[30];
-  Float_t* etJetOk     = new Float_t[30];
-  Float_t* etsigJetOk  = new Float_t[30]; //signal et in jet
-  Float_t* etallJetOk  = new Float_t[30];  // total et in jet (tmp variable)
-  Int_t*   ncellsJetOk = new Int_t[30];
-  Int_t*   multJetOk   = new Int_t[30];
+  Float_t etaJetOk[30];
+  Float_t phiJetOk[30];
+  Float_t etJetOk[30];
+  Float_t etsigJetOk[30]; //signal et in jet
+  Float_t etallJetOk[30];  // total et in jet (tmp variable)
+  Int_t   ncellsJetOk[30];
+  Int_t   multJetOk[30];
   //--------------------------
   Int_t    nJets; // to hold number of jets found by algorithm
   Int_t    nj;    // number of jets accepted
@@ -625,10 +628,19 @@ void AliUA1JetFinderV2::FindJets()
       phiJetOk[p]    = phiJet[idx[p]];
       etJetOk[p]     = etJet[idx[p]];
       etallJetOk[p]  = etJet[idx[p]];
+      etsigJetOk[p]  = etsigJet[idx[p]];
       ncellsJetOk[p] = ncellsJet[idx[p]];
       multJetOk[p]   = multJet[idx[p]];
     }
 
+  TRefArray *refs = 0;
+  Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetAODReader");
+  if (fromAod) refs = fReader->GetReferences();
+  Int_t nTracks = 0;
+  if (fromAod) nTracks = ((TRefArray*)refs)->GetEntries();
+  Int_t* trackinjet     = new Int_t[nTracks];
+  for(Int_t it=0; it<nTracks; it++) trackinjet[it]=-1;
+
   for(Int_t kj=0; kj<nj; kj++)
     {
       if ((etaJetOk[kj] > (header->GetJetEtaMax())) ||
@@ -639,10 +651,31 @@ void AliUA1JetFinderV2::FindJets()
       py = etJetOk[kj] * TMath::Sin(phiJetOk[kj]);
       pz = etJetOk[kj] / TMath::Tan(2.0 * TMath::ATan(TMath::Exp(-etaJetOk[kj])));
       en = TMath::Sqrt(px * px + py * py + pz * pz);
-      fJets->AddJet(px, py, pz, en);
+
       AliAODJet jet(px, py, pz, en);
       jet.Print("");
       
+      if (fromAod){
+       for(Int_t jpart = 0; jpart < nTracks; jpart++) { // loop for all particles in array
+         Float_t deta = ((AliAODTrack*)refs->At(jpart))->Eta() - etaJetOk[kj];
+         Float_t dphi = ((AliAODTrack*)refs->At(jpart))->Phi() - phiJetOk[kj];
+         if (dphi < -TMath::Pi()) dphi= -dphi - 2.0 * TMath::Pi();
+         if (dphi > TMath::Pi()) dphi = 2.0 * TMath::Pi() - dphi;
+         
+         Float_t dr = TMath::Sqrt(deta * deta + dphi * dphi);
+         if(dr <= header->GetRadius() && fReader->GetCutFlag(jpart) == 1) {
+             // particles inside this cone
+             if(trackinjet[jpart]==-1) {
+                 trackinjet[jpart] = kj;
+             } else if(fDebug>10) {
+                 printf("The track already belongs to jet %d \n",trackinjet[jpart]);
+             }
+         }
+         if(trackinjet[jpart]==kj)
+             jet.AddTrack(refs->At(jpart));  // check if the particle belongs to the jet and add the ref
+       }
+      }
+
       AddJet(jet);
       
       idxjets[nselectj] = kj;
@@ -675,78 +708,57 @@ void AliUA1JetFinderV2::FindJets()
     if(bflag == 0) injet[bj] = -1; // set as background particle
   }
 
-  fJets->SetNCells(ncells);
-  fJets->SetPtFromSignal(percentage);
-  fJets->SetMultiplicities(mult);
-  fJets->SetInJet(injet);
-  fJets->SetEtaIn(etaT);
-  fJets->SetPhiIn(phiT);
-  fJets->SetPtIn(ptT);
-  fJets->SetVectorSizeIn(vectT);
-  fJets->SetVectorPxIn(pxT);
-  fJets->SetVectorPyIn(pyT);
-  fJets->SetVectorPzIn(pzT);
-  fJets->SetDetectorFlagIn(detT);
-  fJets->SetEtAvg(etbgTotal/(2*(header->GetLegoEtaMax())*(header->GetLegoPhiMax()-header->GetLegoPhiMin())));
 
   //delete
-  delete ptT;
-  delete en2T;
-  delete pt2T;
-  delete etaT;
-  delete phiT;
-  pxT.clear();
-  pyT.clear();
-  pzT.clear();
-  delete detT;
-  delete cFlagT;
-  delete cFlag2T;
-  delete sFlagT;
-  delete cClusterT;
-  delete vectT;
-  delete injet;
-  delete sflag;
+  delete [] ptT;
+  delete [] en2T;
+  delete [] pt2T;
+  delete [] etaT;
+  delete [] phiT;
+  delete [] detT;
+  delete [] cFlagT;
+  delete [] cFlag2T;
+  delete [] sFlagT;
+  delete [] cClusterT;
+  delete [] vectT;
+  delete [] injet;
+  delete [] sflag;
+  trackRef->Delete();
+  delete trackRef;
+
   delete hPtTotal;
-  delete etCell;
-  delete etaCell;
-  delete phiCell;
-  delete flagCell;
-  delete etCell2;
-  delete etaCell2;
-  delete phiCell2;
-  delete flagCell2;
-  delete etaJet;
-  delete phiJet;
-  delete etJet;
-  delete etsigJet;
-  delete etallJet;
-  delete ncellsJet;
-  delete multJet;
-  //--- Added for jet reordering
-  delete etaJetOk;
-  delete phiJetOk;
-  delete etJetOk;
-  delete etsigJetOk;
-  delete etallJetOk;
-  delete ncellsJetOk;
-  delete multJetOk;
+  delete [] etCell;
+  delete [] etaCell;
+  delete [] phiCell;
+  delete [] flagCell;
+  delete [] etCell2;
+  delete [] etaCell2;
+  delete [] phiCell2;
+  delete [] flagCell2;
   //--------------------------
-  delete idxjets;
-  delete percentage;
-  delete ncells;
-  delete mult;
+  delete [] idxjets;
+  delete [] idx;
+  delete [] trackinjet;
+
+  delete [] percentage;
+  delete [] ncells;
+  delete [] mult;
 
 }
 
 ////////////////////////////////////////////////////////////////////////
-void AliUA1JetFinderV2::RunAlgoritm(Int_t nIn, Float_t* etCell, Float_t* etaCell, Float_t* phiCell, 
-                                   Int_t* flagCell, Float_t* etCell2, Float_t* etaCell2, Float_t* phiCell2, 
-                                   Int_t* flagCell2, Float_t etbgTotal, Double_t dEtTotal, 
-                                   Int_t& nJets, Float_t* etJet,Float_t* etaJet, Float_t* phiJet,
-                                   Float_t* etallJet, Int_t* ncellsJet)
+void AliUA1JetFinderV2::RunAlgoritm(Int_t nIn, Float_t* etCell, Float_t* const etaCell, Float_t* phiCell, 
+                  Int_t* const flagCell, const Float_t* etCell2, const Float_t* etaCell2, const Float_t* phiCell2, 
+                  const Int_t* flagCell2, Float_t etbgTotal, Double_t dEtTotal, 
+                  Int_t& nJets, Float_t* const etJet, Float_t* const etaJet, Float_t* const phiJet,
+                  Float_t* const etallJet, Int_t* const ncellsJet)
 {
-  
-  Int_t nCell  = nIn; 
+  //
+  // Main method for jet finding
+  // UA1 base cone finder
+  //
+
+  Int_t nCell  = nIn;
 
   // Dump lego
   // Check enough space! *to be done*
@@ -765,10 +777,10 @@ void AliUA1JetFinderV2::RunAlgoritm(Int_t nIn, Float_t* etCell, Float_t* etaCell
   Float_t etseed  = header->GetEtSeed();
 
   // Tmp array of jets form algoritm
-  Float_t etaAlgoJet[30];
-  Float_t phiAlgoJet[30];
-  Float_t etAlgoJet[30];
-  Int_t   ncellsAlgoJet[30];
+  Float_t etaAlgoJet[30]    = {0.};
+  Float_t phiAlgoJet[30]    = {0.};
+  Float_t etAlgoJet[30]     = {0.};
+  Int_t   ncellsAlgoJet[30] = {0};
 
   // Run algorithm//
 
@@ -927,14 +939,14 @@ void AliUA1JetFinderV2::RunAlgoritm(Int_t nIn, Float_t* etCell, Float_t* etaCell
     }
 
   //delete
-  delete index;
+  delete[] index;
 
 }
 
 ////////////////////////////////////////////////////////////////////////
 void AliUA1JetFinderV2::RunAlgoritmC(Float_t etbgTotal, Double_t dEtTotal, Int_t& nJets,
-                                  Float_t* etJet,Float_t* etaJet, Float_t* phiJet,
-                                  Float_t* etallJet, Int_t* ncellsJet)
+                  Float_t* const etJet,Float_t* const etaJet, Float_t* const phiJet,
+                  Float_t* const etallJet, Int_t* const ncellsJet)
 {
   // Dump lego
   // Check enough space! *to be done*
@@ -971,10 +983,10 @@ void AliUA1JetFinderV2::RunAlgoritmC(Float_t etbgTotal, Double_t dEtTotal, Int_t
   Float_t etseed  = header->GetEtSeed();
 
   // Tmp array of jets form algoritm
-  Float_t etaAlgoJet[30];
-  Float_t phiAlgoJet[30];
-  Float_t etAlgoJet[30];
-  Int_t   ncellsAlgoJet[30];
+  Float_t etaAlgoJet[30]    = {0.};
+  Float_t phiAlgoJet[30]    = {0.};
+  Float_t etAlgoJet[30]     = {0.};
+  Int_t   ncellsAlgoJet[30] = {0};
 
   // Run algorithm//
 
@@ -1131,16 +1143,16 @@ void AliUA1JetFinderV2::RunAlgoritmC(Float_t etbgTotal, Double_t dEtTotal, Int_t
     }
   
   //delete
-  delete index;
-  delete idx;
+  delete [] index;
+  delete [] idx;
 
 }
 
 ////////////////////////////////////////////////////////////////////////
-void AliUA1JetFinderV2::SubtractBackg(Int_t& nIn, Int_t&nJ, Float_t&etbgTotalN, Float_t* ptT, 
-                                     Int_t*vectT, Float_t* etaT, Float_t* phiT, Float_t* cFlagT, Float_t* cFlag2T, 
-                                     Float_t* sFlagT, Float_t* etJet,Float_t* etaJet, Float_t* phiJet, 
-                                     Float_t* etsigJet, Int_t* multJet, Int_t* injet)
+void AliUA1JetFinderV2::SubtractBackg(const Int_t& nIn, const Int_t&nJ, Float_t& etbgTotalN, const Float_t* ptT, const Int_t* vectT, 
+                                     const Float_t* etaT, const Float_t* phiT, const Int_t* cFlagT, const Int_t* cFlag2T, 
+                                     const Int_t* sFlagT, Float_t* const etJet, const Float_t* etaJet, const Float_t* phiJet, 
+                                     Float_t* const etsigJet, Int_t* const multJet, Int_t* const injet)
 {
   //
   // Background subtraction using cone method but without correction in dE/deta distribution
@@ -1149,13 +1161,11 @@ void AliUA1JetFinderV2::SubtractBackg(Int_t& nIn, Int_t&nJ, Float_t&etbgTotalN,
   
   //calculate energy inside and outside cones
   AliUA1JetHeaderV1* header = (AliUA1JetHeaderV1*) fHeader;
-  Int_t              fOpt = fReader->GetReaderHeader()->GetDetector();
+  fOpt = fReader->GetReaderHeader()->GetDetector();
   Float_t rc= header->GetRadius();
-  Float_t etIn[30];
+  Float_t etIn[30] = {0.};
   Float_t etOut = 0;
-  
-  for(Int_t j=0;j<30;j++){etIn[j]=0.;}
-  
+    
   for(Int_t jpart = 0; jpart < nIn; jpart++){ // loop for all particles in array
 
     for(Int_t ijet=0; ijet<nJ; ijet++){
@@ -1342,17 +1352,17 @@ void AliUA1JetFinderV2::SubtractBackg(Int_t& nIn, Int_t&nJ, Float_t&etbgTotalN,
 }
 
 ////////////////////////////////////////////////////////////////////////
-void AliUA1JetFinderV2::SubtractBackgC(Int_t& nIn, Int_t&nJ, Float_t&etbgTotalN,
-                                      Float_t* ptT, Float_t* etaT, Float_t* phiT,
-                                      Float_t* etJet,Float_t* etaJet, Float_t* phiJet, Float_t* etsigJet,
-                                      Int_t* multJet, Int_t* injet)
+void AliUA1JetFinderV2::SubtractBackgC(const Int_t& nIn, const Int_t&nJ, Float_t&etbgTotalN,
+                      const Float_t* ptT, const Float_t* etaT, const Float_t* phiT,
+                      Float_t* const etJet, const Float_t* etaJet, const Float_t* phiJet,
+                      Float_t* const etsigJet,Int_t* const multJet, Int_t* const injet)
 {
   //background subtraction using cone method but without correction in dE/deta distribution
   
   //calculate energy inside and outside cones
   AliUA1JetHeaderV1* header = (AliUA1JetHeaderV1*) fHeader;
   Float_t rc= header->GetRadius();
-  Float_t etIn[30];
+  Float_t etIn[30] = {0.};
   Float_t etOut = 0;
   for(Int_t jpart = 0; jpart < nIn; jpart++){ // loop for all particles in array
     // if((fReader->GetCutFlag(jpart)) != 1) continue; // pt cut
@@ -1408,10 +1418,10 @@ void AliUA1JetFinderV2::SubtractBackgC(Int_t& nIn, Int_t&nJ, Float_t&etbgTotalN,
 
 
 ////////////////////////////////////////////////////////////////////////
-void AliUA1JetFinderV2::SubtractBackgStat(Int_t& nIn, Int_t&nJ,Float_t&etbgTotalN,
-                     Float_t* ptT, Float_t* etaT, Float_t* phiT, Float_t* cFlagT, Float_t* sFlagT,
-                      Float_t* etJet,Float_t* etaJet, Float_t* phiJet, Float_t* etsigJet,
-                      Int_t* multJet, Int_t* injet)
+void AliUA1JetFinderV2::SubtractBackgStat(const Int_t& nIn, const Int_t&nJ,Float_t&etbgTotalN,
+                                         const Float_t* ptT, const Float_t* etaT, const Float_t* phiT, const Int_t* cFlagT, 
+                                         const Int_t* sFlagT, Float_t* const etJet, const Float_t* etaJet, const Float_t* phiJet,
+                                         Float_t* const etsigJet, Int_t* const multJet, Int_t* const injet)
 {
 
   //background subtraction using statistical method
@@ -1420,7 +1430,7 @@ void AliUA1JetFinderV2::SubtractBackgStat(Int_t& nIn, Int_t&nJ,Float_t&etbgTotal
   
   //calculate energy inside
   Float_t rc= header->GetRadius();
-  Float_t etIn[30];
+  Float_t etIn[30] = {0.};
   
   for(Int_t jpart = 0; jpart < nIn; jpart++)
     { // loop for all particles in array
@@ -1473,10 +1483,10 @@ void AliUA1JetFinderV2::SubtractBackgStat(Int_t& nIn, Int_t&nJ,Float_t&etbgTotal
 }
 
 ////////////////////////////////////////////////////////////////////////
-void AliUA1JetFinderV2::SubtractBackgCone(Int_t& nIn, Int_t&nJ,Float_t& etbgTotalN, Float_t* ptT,
-                                         Float_t* etaT, Float_t* phiT, Float_t* cFlagT, Float_t* sFlagT,
-                                         Float_t* etJet,Float_t* etaJet, Float_t* phiJet, Float_t* etsigJet,
-                                         Int_t* multJet, Int_t* injet)
+void AliUA1JetFinderV2::SubtractBackgCone(const Int_t& nIn, const Int_t&nJ,Float_t& etbgTotalN,
+                      const Float_t* ptT, const Float_t* etaT, const Float_t* phiT, const Int_t* cFlagT, const Int_t* sFlagT,
+                      Float_t* const etJet, const Float_t* etaJet, const Float_t* phiJet,
+                      Float_t* const etsigJet, Int_t* const multJet, Int_t* const injet)
 {
   // Cone background subtraction method taking into acount dEt/deta distribution
   AliUA1JetHeaderV1* header = (AliUA1JetHeaderV1*) fHeader;
@@ -1491,7 +1501,7 @@ void AliUA1JetFinderV2::SubtractBackgCone(Int_t& nIn, Int_t&nJ,Float_t& etbgTota
   TH1F* hAreaJet[30];
   for(Int_t mjet=0; mjet<nJ; mjet++){
     char hEtname[256]; char hAreaname[256];
-    sprintf(hEtname, "hEtJet%d", mjet); sprintf(hAreaname, "hAreaJet%d", mjet);
+    snprintf(hEtname, 256, "hEtJet%d", mjet); snprintf(hAreaname, 256, "hAreaJet%d", mjet);
     hEtJet[mjet] = new TH1F(hEtname,"et dist in eta ",ndiv,etamin,etamax);
     hAreaJet[mjet] = new TH1F(hAreaname,"area dist in eta ",ndiv,etamin,etamax);
   }
@@ -1587,10 +1597,10 @@ void AliUA1JetFinderV2::SubtractBackgCone(Int_t& nIn, Int_t&nJ,Float_t& etbgTota
 }
 
 ////////////////////////////////////////////////////////////////////////
-void AliUA1JetFinderV2::SubtractBackgRatio(Int_t& nIn, Int_t&nJ,Float_t& etbgTotalN,
-                     Float_t* ptT, Float_t* etaT, Float_t* phiT, Float_t* cFlagT, Float_t* sFlagT,
-                     Float_t* etJet,Float_t* etaJet, Float_t* phiJet, Float_t* etsigJet,
-                     Int_t* multJet, Int_t* injet)
+void AliUA1JetFinderV2::SubtractBackgRatio(const Int_t& nIn, const Int_t&nJ,Float_t& etbgTotalN,
+                      const Float_t* ptT, const Float_t* etaT, const Float_t* phiT, const Int_t* cFlagT, const Int_t* sFlagT,
+                      Float_t* const etJet, const Float_t* etaJet, const Float_t* phiJet,
+                      Float_t* const etsigJet, Int_t* const multJet, Int_t* const injet)
 {
   // Ratio background subtraction method taking into acount dEt/deta distribution
   AliUA1JetHeaderV1* header = (AliUA1JetHeaderV1*) fHeader;
@@ -1608,7 +1618,7 @@ void AliUA1JetFinderV2::SubtractBackgRatio(Int_t& nIn, Int_t&nJ,Float_t& etbgTot
   TH1F* hAreaJet[30];
   for(Int_t mjet=0; mjet<nJ; mjet++){
     char hEtname[256]; char hAreaname[256];
-    sprintf(hEtname, "hEtJet%d", mjet); sprintf(hAreaname, "hAreaJet%d", mjet);
+    snprintf(hEtname, 256, "hEtJet%d", mjet); snprintf(hAreaname, 256, "hAreaJet%d", mjet);
     hEtJet[mjet] = new TH1F(hEtname,"et dist in eta ",ndiv,etamin,etamax);        // change range
     hAreaJet[mjet] = new TH1F(hAreaname,"area dist in eta ",ndiv,etamin,etamax);  // change range
   }
@@ -1705,12 +1715,11 @@ void AliUA1JetFinderV2::SubtractBackgRatio(Int_t& nIn, Int_t&nJ,Float_t& etbgTot
 void AliUA1JetFinderV2::Reset()
 {
   fLego->Reset();
-  fJets->ClearJets();
   AliJetFinder::Reset();
 }
 
 ////////////////////////////////////////////////////////////////////////
-void AliUA1JetFinderV2::WriteJHeaderToFile()
+void AliUA1JetFinderV2::WriteJHeaderToFile() const
 {
   AliUA1JetHeaderV1* header = (AliUA1JetHeaderV1*) fHeader;
   header->Write();
@@ -1728,7 +1737,7 @@ void AliUA1JetFinderV2::InitTask(TChain* tree)
                   header->GetLegoEtaMax(),  header->GetLegoNbinPhi(),
                   header->GetLegoPhiMin(),  header->GetLegoPhiMax());
   
-  fDebug = fReader->GetReaderHeader()->GetDebug();
+  fDebug = fHeader->GetDebug();
   fOpt = fReader->GetReaderHeader()->GetDetector();
   
   // Tasks initialization