moving jetfinder code to subdirectory
authorjklay <jklay@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 28 Feb 2006 21:56:34 +0000 (21:56 +0000)
committerjklay <jklay@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 28 Feb 2006 21:56:34 +0000 (21:56 +0000)
47 files changed:
EMCAL/jetfinder/AliEMCALFast.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALFast.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALFastRecParticle.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALFastRecParticle.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALGeneratorFactory.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALGeneratorFactory.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALHadronCorrection.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALHadronCorrection.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALHadronCorrectionv0.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALHadronCorrectionv0.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALHadronCorrectionv1.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALHadronCorrectionv1.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJet.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJet.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinder.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinder.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderAlgo.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderAlgo.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderAlgoOmni.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderAlgoOmni.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderAlgoUA1Unit.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderAlgoUA1Unit.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderInput.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderInput.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderInputPrep.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderInputPrep.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderInputSimPrep.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderInputSimPrep.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderOutput.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderOutput.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderPlots.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderPlots.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetFinderTypes.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetMicroDst.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALJetMicroDst.h [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALParton.cxx [new file with mode: 0644]
EMCAL/jetfinder/AliEMCALParton.h [new file with mode: 0644]
EMCAL/jetfinder/AnaJets.C [new file with mode: 0644]
EMCAL/jetfinder/Ecommon.h [new file with mode: 0644]
EMCAL/jetfinder/anaDst.C [new file with mode: 0644]
EMCAL/jetfinder/anaDst.h [new file with mode: 0644]
EMCAL/jetfinder/jetDst.C [new file with mode: 0644]
EMCAL/jetfinder/jetDst.h [new file with mode: 0644]
EMCAL/jetfinder/jet_finder_ua1.F [new file with mode: 0644]
EMCAL/jetfinder/sgpdge.F [new file with mode: 0644]
EMCAL/jetfinder/testJetFinder.C [new file with mode: 0644]
EMCAL/jetfinder/testJetFinderBg.C [new file with mode: 0644]

diff --git a/EMCAL/jetfinder/AliEMCALFast.cxx b/EMCAL/jetfinder/AliEMCALFast.cxx
new file mode 100644 (file)
index 0000000..2255ac8
--- /dev/null
@@ -0,0 +1,113 @@
+/**************************************************************************
+ * 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$ */
+//____________________________________________________________________________
+//*-- 
+//*-- Author: Andreas Morsch (CERN)
+//*--
+//*--
+////////////////////////////////////////////////////////////////////////////
+
+#include "TMath.h"
+#include <TRandom.h>
+
+#include "AliEMCALFast.h"
+
+
+ClassImp(AliEMCALFast)
+
+//____________________________________________________________________________
+
+
+Float_t AliEMCALFast::SmearMomentum(Int_t ind, Float_t p)
+{
+//
+//  The relative momentum error, i.e. 
+//  (delta p)/p = sqrt (a**2 + (b*p)**2) * 10**-2,
+//  where typically a = 0.75 and b = 0.16 - 0.24 depending on multiplicity
+//  (the lower value is for dn/d(eta) about 2000, and the higher one for 8000)
+//
+//  If we include information from TRD b will be by a factor 2/3 smaller.
+//
+//  ind = 1: high multiplicity
+//  ind = 2: low  multiplicity
+//  ind = 3: high multiplicity + TRD
+//  ind = 4: low  multiplicity + TRD
+
+    Float_t pSmeared;
+    Float_t a = 0.75;
+    Float_t b = 0.24;
+
+    if (ind == 1) b = 0.24;
+    if (ind == 2) b = 0.16;
+    if (ind == 3) b = 0.16;    
+    if (ind == 4) b = 0.11;    
+    
+    Float_t sigma = p*TMath::Sqrt(a*a+b*b*p*p)*0.01;
+    pSmeared = p + gRandom->Gaus(0., sigma);
+    return pSmeared;
+}
+
+
+Float_t AliEMCALFast::Efficiency(Int_t ind, Float_t p)
+{
+// Tracking efficiency:
+// above pt 0.5 GeV practically constant, between 90 and 95 % (again,
+// depending on multplicity)
+// below 0.5 GeV goes down to about 70% at 0.2 GeV.
+// On top of that there is 90% geometrical acceptance for tracking due
+// to TPC (dead zones between readout chambers).  
+// Tracking 
+//      
+    Float_t eff = 0.9;
+    if (ind == 2) eff  = 0.95;
+    if (p < 0.5) eff -= (0.5-p)*0.2/0.3;
+// Geometry
+    eff *= 0.9;
+// Acceptance    
+    return eff;
+}
+
+Bool_t AliEMCALFast::EmcalAcceptance(Float_t eta, Float_t phi)
+{
+// 27-oct-05 -> should be change
+// EMCAL eta-phi acceptance
+    Bool_t acc = kFALSE;
+    if (TMath::Abs(eta) < 0.7 &&
+       phi > 60.*TMath::Pi()/180. &&
+       phi < TMath::Pi())
+       acc = kTRUE;
+    return acc;
+}
+
+
+Bool_t AliEMCALFast::RandomReject(Float_t eff)
+{
+//
+// Random rejection 
+    Bool_t rej = kFALSE;
+    Float_t ran = gRandom->Rndm();
+    if (ran > eff) rej = kTRUE;
+    return rej;
+}
+
+
+
+
+
+
+
diff --git a/EMCAL/jetfinder/AliEMCALFast.h b/EMCAL/jetfinder/AliEMCALFast.h
new file mode 100644 (file)
index 0000000..3ec0bd6
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef ALIEMCALFAST_H
+#define ALIEMCALFAST_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+#include <TObject.h>
+//*-- Author: Andreas Morsch (CERN)
+
+class AliEMCALFast : public TObject {
+ public:
+    virtual ~AliEMCALFast(){;}
+    static Float_t SmearMomentum  (Int_t ind,   Float_t p);
+    static Float_t Efficiency     (Int_t ind,   Float_t p);
+    static Bool_t  EmcalAcceptance(Float_t eta, Float_t phi);
+    static Bool_t  RandomReject   (Float_t eff);    
+ protected:
+  ClassDef(AliEMCALFast,1) // Jet for EMCAL
+};
+      
+
+#endif // ALIEMCALJet_H
diff --git a/EMCAL/jetfinder/AliEMCALFastRecParticle.cxx b/EMCAL/jetfinder/AliEMCALFastRecParticle.cxx
new file mode 100644 (file)
index 0000000..f340990
--- /dev/null
@@ -0,0 +1,512 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+//  A  Particle modified by EMCAL response and produced by AliEMCALvFast
+//*--
+//  To become a general class of AliRoot ?    
+//*--               
+//*-- Author: Yves Schutz (SUBATECH)
+//*--
+/////////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+#include "AliEMCALFastRecParticle.h"
+#include "TPad.h"
+#include "TPaveText.h"
+
+ClassImp(AliEMCALFastRecParticle) 
+
+//____________________________________________________________________________
+AliEMCALFastRecParticle::AliEMCALFastRecParticle() : TParticle()
+{
+  // ctor
+  fType = 0 ; 
+}
+
+//____________________________________________________________________________
+AliEMCALFastRecParticle::AliEMCALFastRecParticle(const AliEMCALFastRecParticle & rp)
+  : TParticle(rp)
+{
+  // copy ctor
+
+  fType        = rp.fType ;
+  fPdgCode     = rp.fPdgCode;
+  fStatusCode  = rp.fStatusCode;
+  fMother[0]   = rp.fMother[0];
+  fMother[1]   = rp.fMother[1];
+  fDaughter[0] = rp.fDaughter[0];
+  fDaughter[1] = rp.fDaughter[1];
+  fWeight      = rp.fWeight;
+  fCalcMass    = rp.fCalcMass;
+  fPx          = rp.fPx;
+  fPy          = rp.fPy;
+  fPz          = rp.fPz;
+  fE           = rp.fE;
+  fVx          = rp.fVx;
+  fVy          = rp.fVy;
+  fVz          = rp.fVz;
+  fVt          = rp.fVt;
+  fPolarTheta  = rp.fPolarTheta;
+  fPolarPhi    = rp.fPolarPhi;
+  fParticlePDG = rp.fParticlePDG; 
+}
+
+//____________________________________________________________________________
+ AliEMCALFastRecParticle::AliEMCALFastRecParticle(const TParticle & pp)
+{
+  // ctor from a TParticle (crummy?!)
+  TParticle & pnoconst = (TParticle &)(pp) ;
+  AliEMCALFastRecParticle & p = (AliEMCALFastRecParticle &)(pnoconst) ;
+  fType        = 0  ;
+  fPdgCode     = p.fPdgCode;
+  fStatusCode  = p.fStatusCode;
+  fMother[0]   = p.fMother[0];
+  fMother[1]   = p.fMother[1];
+  fDaughter[0] = p.fDaughter[0];
+  fDaughter[1] = p.fDaughter[1];
+  fWeight      = p.fWeight;
+  fCalcMass    = p.fCalcMass;
+  fPx          = p.fPx;
+  fPy          = p.fPy;
+  fPz          = p.fPz;
+  fE           = p.fE;
+  fVx          = p.fVx;
+  fVy          = p.fVy;
+  fVz          = p.fVz;
+  fVt          = p.fVt;
+  fPolarTheta  = p.fPolarTheta;
+  fPolarPhi    = p.fPolarPhi;
+  fParticlePDG = p.fParticlePDG; 
+
+}
+
+//____________________________________________________________________________
+Int_t AliEMCALFastRecParticle::DistancetoPrimitive(Int_t px, Int_t py)
+{
+  //  Compute distance from point px,py to a AliEMCALFastRecParticle considered as a Tmarker
+  //  Compute the closest distance of approach from point px,py to this marker.
+  //  The distance is computed in pixels units.
+
+  Double_t kRADDEG = 180. / TMath::Pi() ; 
+  Coord_t x = Phi() * kRADDEG     ;
+  Coord_t y = Theta() * kRADDEG     ;
+  const Int_t kMaxDiff = 10;
+  Int_t pxm  = gPad->XtoAbsPixel(x);
+  Int_t pym  = gPad->YtoAbsPixel(y);
+  Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
+  
+  if (dist > kMaxDiff) return 9999;
+  return dist;
+}
+
+//___________________________________________________________________________
+ void AliEMCALFastRecParticle::Draw(Option_t *option)
+ {
+   // Draw this AliEMCALFastRecParticle with its current attributes
+    
+   AppendPad(option);
+ }
+
+//______________________________________________________________________________
+void AliEMCALFastRecParticle::ExecuteEvent(Int_t event, Int_t /*px*/, Int_t /*py*/)
+{
+  //  Execute action corresponding to one event
+  //  This member function is called when a AliEMCALFastRecParticle is clicked with the locator
+  
+  if (!gPad->IsEditable()) 
+    return ;
+  
+  static TPaveText * clustertext = 0 ; 
+  
+  switch (event) {
+    
+  case kButton1Down: {
+    Double_t kRADDEG = 180. / TMath::Pi() ; 
+    Coord_t x = Phi() * kRADDEG     ;
+    Coord_t y = Theta() * kRADDEG     ;
+    clustertext = new TPaveText(x-1, y+1, x+5, y+3, "") ;
+    Text_t  line1[40] ;
+    Text_t  line2[40] ;
+    sprintf( line1, "PID: %s ", (const char*)Name() ) ;
+    sprintf( line2, "ENERGY: %f ", Energy() ) ;
+    clustertext ->AddText(line1) ;
+    clustertext ->AddText(line2) ;
+    clustertext ->Draw("");   
+    gPad->Update() ; 
+    break ;
+  }
+  
+  case kButton1Up: {
+    delete clustertext ; 
+    clustertext = 0 ; 
+    gPad->Update() ; 
+    break ;
+  }
+  }
+  
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsPhoton(TString purity) const
+{
+  //FIXME : just a blind copy from PHOS
+  // Rec.Particle is a photon if it has a photon-like shape, fast and neutral
+  // photon-like shape is defined with a purity "low", "medium" or "high"
+
+  purity.ToLower();
+  Bool_t photonLike = kFALSE;
+  if      (purity == "low"   ) photonLike = TestPIDBit(6);
+  else if (purity == "medium") photonLike = TestPIDBit(7);
+  else if (purity == "high"  ) photonLike = TestPIDBit(8);
+  if (photonLike                                   && //  photon by PCA
+      (TestPIDBit(5)||TestPIDBit(4)||TestPIDBit(3))&& //  fast by TOF
+      (TestPIDBit(2)||TestPIDBit(1)||TestPIDBit(0))&& //  neutral by CPV
+      !TestPIDBit(14))                              //  no charged track
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsPi0(TString purity) const
+{
+  //FIXME : just a blind copy from PHOS
+  // Rec.Particle is a pi0 if it has a pi0-like shape, fast and neutral
+  // pi0-like shape is defined with a purity "low", "medium" or "high"
+
+  purity.ToLower();
+  Bool_t pi0Like = kFALSE;
+  if      (purity == "low"   ) pi0Like = TestPIDBit(9);
+  else if (purity == "medium") pi0Like = TestPIDBit(10);
+  else if (purity == "high"  ) pi0Like = TestPIDBit(11);
+  else Error("IsPi0","Wrong purity type: %s",purity.Data());
+  if (pi0Like                                      && //  pi0 by PCA
+      (TestPIDBit(5)||TestPIDBit(4)||TestPIDBit(3))&& //  fast by TOF
+      (TestPIDBit(2)||TestPIDBit(1)||TestPIDBit(0))&& //  neutral by CPV
+      !TestPIDBit(14))                              //  no charged track
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsElectron(TString purity) const
+{
+  //FIXME : just a blind copy from PHOS
+  // Rec.Particle is an electron if it has a photon-like shape, fast and charged
+  // photon-like shape is defined with a purity "low", "medium" or "high"
+
+  purity.ToLower();
+  Bool_t photonLike = kFALSE;
+  if      (purity == "low"   ) photonLike = TestPIDBit(6);
+  else if (purity == "medium") photonLike = TestPIDBit(7);
+  else if (purity == "high"  ) photonLike = TestPIDBit(8);
+  else Error("IsElectron","Wrong purity type: %s",purity.Data());
+  
+  if (photonLike                                   && //  photon by PCA
+      (TestPIDBit(5)|| TestPIDBit(4)|| TestPIDBit(3))&& //  fast by TOF
+      (!TestPIDBit(2)||!TestPIDBit(1)||!TestPIDBit(0))&& //  charged by CPV
+      TestPIDBit(14))                                  //  no charged track
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsEleCon(TString purity) const
+{
+  //FIXME : just a blind copy from PHOS
+  // Rec.Particle is an electron if it has a photon-like shape, fast and charged
+  // photon-like shape is defined with a purity "low", "medium" or "high"
+
+  purity.ToLower();
+  Bool_t photonLike = kFALSE;
+  if      (purity == "low"   ) photonLike = TestPIDBit(6);
+  else if (purity == "medium") photonLike = TestPIDBit(7);
+  else if (purity == "high"  ) photonLike = TestPIDBit(8);
+  else Error("IsElectron","Wrong purity type: %s",purity.Data());
+  
+  if (photonLike                                   && //  photon by PCA
+      (TestPIDBit(5)|| TestPIDBit(4)|| TestPIDBit(3))&& //  fast by TOF
+      (!TestPIDBit(2)||!TestPIDBit(1)||!TestPIDBit(0))&& //  charged by CPV
+      !TestPIDBit(14))                                  //  no charged track
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsHardPhoton() const
+{
+  //FIXME : just a blind copy from PHOS
+  // Rec.Particle is a hard photon (E > 30 GeV) if its second moment M2x
+  // corresponds to photons
+  if (TestPIDBit(12) && !TestPIDBit(14))
+    return kTRUE;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsHardPi0() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is a hard pi0 (E > 30 GeV) if its second moment M2x
+  // corresponds to pi0
+  if (TestPIDBit(13)&& !TestPIDBit(14))
+    return kTRUE;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsHadron() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is an hadron if it does not look like
+  // a low-purity photon nor low-purity pi0
+
+  if ( !TestPIDBit(6) && !TestPIDBit(9) )             // not photon nor pi0
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsChargedHadron() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is a charged hadron if it does not look like
+  // a low-purity photon nor low-purity pi0 and is low-purity charged
+
+  if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
+       !TestPIDBit(2))                                // charged by CPV
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsNeutralHadron() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is a neutral hadron if it does not look like
+  // a low-purity photon nor low-purity pi0 and is high-purity neutral
+
+  if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
+        TestPIDBit(2))                                // neutral by CPV
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsFastChargedHadron() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is a fast charged hadron if it does not look like
+  // a low-purity photon nor low-purity pi0, is low-purity charged
+  // and is high-purity fast
+
+  if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
+       !TestPIDBit(2) &&                              // charged by CPV
+        TestPIDBit(5))                                // fast by TOF
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsSlowChargedHadron() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is a slow neutral hadron if it does not look like
+  // a low-purity photon nor low-purity pi0, is high-purity neutral
+  // and is not high-purity fast
+
+  if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
+       !TestPIDBit(2) &&                              // charged by CPV
+       !TestPIDBit(5))                                // slow by TOF
+    return kTRUE ;
+  else
+    return kFALSE;
+
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsFastNeutralHadron() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is a fast neutral hadron if it does not look like
+  // a low-purity photon nor low-purity pi0, is high-purity neutral
+  // and is high-purity fast
+
+  if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
+        TestPIDBit(2) &&                              // neutral by CPV
+        TestPIDBit(5))                                // fast by TOF
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+//____________________________________________________________________________
+Bool_t AliEMCALFastRecParticle::IsSlowNeutralHadron() const
+{
+  //FIXME : just a blind copy from EMCAL
+  // Rec.Particle is a slow neutral hadron if it does not look like
+  // a low-purity photon nor low-purity pi0, is high-purity neutral
+  // and is not high-purity fast
+
+  if ( !TestPIDBit(6) && !TestPIDBit(9) &&            // not photon nor pi0
+        TestPIDBit(2) &&                              // neutral by CPV
+       !TestPIDBit(5))                                // slow by TOF
+    return kTRUE ;
+  else
+    return kFALSE;
+}
+
+
+//____________________________________________________________________________
+TString AliEMCALFastRecParticle::Name()const
+{
+   // Returns the name of the particle type (only valid if PIDv1 is employed)
+
+  TString  name ; 
+
+  name = "Undefined particle" ;
+  
+  if      (IsPhoton("low"))
+    name = "Photon low purity, ";
+  else if (IsPhoton("medium"))
+    name = "Photon medium purity, ";
+  else if (IsPhoton("high"))
+    name = "Photon high purity, ";
+
+  if      (IsPi0("low"))
+    name += "Pi0 low purity, ";
+  else if (IsPi0("medium"))
+    name += "Pi0 medium purity, ";
+  else if (IsPi0("high"))
+    name += "Pi0 high purity, ";
+
+  if      (IsElectron("low"))
+    name += "Electron low purity, ";
+  else if (IsElectron("medium"))
+    name += "Electron medium purity, ";
+  else if (IsElectron("high"))
+    name += "Electron high purity, ";
+
+  if     (IsHadron()) {
+    name = "hadron";
+    if      (IsChargedHadron()) {
+      name.Prepend("charged, ");
+      if      (IsFastChargedHadron())
+       name.Prepend("fast, ");
+      else if (IsSlowChargedHadron())
+       name.Prepend("slow, ");
+    }
+    else if (IsNeutralHadron()) {
+      name.Prepend("neutral, ");
+      if      (IsFastNeutralHadron())
+       name.Prepend("fast, ");
+      else if (IsSlowNeutralHadron())
+       name.Prepend("slow, ");
+    }
+  }
+
+  return name ; 
+}
+
+//______________________________________________________________________________
+void AliEMCALFastRecParticle::SetType(Int_t type) { 
+  // sets the particle type 
+  // bit-mask of the particle type means the following:
+  // bits 0,1,2   - neutral particle with low, medium and high purity
+  // bits 3.4,5   - fast particle with low, medium and high purity
+  // bits 6.7,8   - photon shower with low, medium and high purity
+  // bits 9,10,11 - hard-pi0 shower with low, medium and high purity
+
+  fType = type ; 
+  
+  if((type == 127) || (fType == 511) || (fType == 255) ||(fType == 383)||(fType == 447)){
+    fPdgCode = 22 ; 
+    return ;
+  }
+  
+  if ((fType == 63)|| ((fType < 8)&&(fType > 0)) ){
+    fPdgCode = 2112 ; 
+    return ;
+  }
+  if ( ((fType == 504) || (fType == 505) ||(fType == 248)||(fType == 249)||(fType == 120)||(fType == 121)) ){
+    fPdgCode = 11 ; 
+    return ;
+  }
+  if ((fType == 448) || (fType == 449) ||(fType == 192)||(fType == 193)||(fType == 64)||(fType == 64)){
+    fPdgCode = 13 ; 
+    return ;
+  }
+  if((fType == 56)||(fType == 57)){
+    fPdgCode = 211 ; 
+    return ;
+  }
+  if (fType == 0){
+    fPdgCode = 2212 ; 
+    return ;
+  }
+
+}          
+
+//______________________________________________________________________________
+void AliEMCALFastRecParticle::Paint(Option_t *)
+{
+  // Paint this ALiRecParticle in theta,phi coordinate as a TMarker  with its current attributes
+
+  Double_t kRADDEG = 180. / TMath::Pi() ; 
+  Coord_t x = Phi() * kRADDEG     ;
+  Coord_t y = Theta() * kRADDEG     ;
+  Color_t markercolor = 1 ;
+  Size_t  markersize  = 1. ;
+  Style_t markerstyle = 5 ;
+  
+  if (!gPad->IsBatch()) {
+    gVirtualX->SetMarkerColor(markercolor) ;
+    gVirtualX->SetMarkerSize (markersize)  ;
+    gVirtualX->SetMarkerStyle(markerstyle) ;
+  }
+  gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
+  gPad->PaintPolyMarker(1,&x,&y,"") ;
+}
+
+//____________________________________________________________________________
+void AliEMCALFastRecParticle::Print(Option_t * /*opt*/)const
+{
+  // Print the type, energy and momentum of the reconstructed particle
+  
+  printf("Print Summary:") ; 
+  printf("AliEMCALFastRecParticle > type is  %s\n", Name().Data()) ; 
+  printf("                      Energy = %f\n", fE) ; 
+  printf("                         Px     = %f\n", fPx) ; 
+  printf("                         Py     = %f\n", fPy) ;
+  printf("                         Pz     = %f\n", fPz) ; 
+}
diff --git a/EMCAL/jetfinder/AliEMCALFastRecParticle.h b/EMCAL/jetfinder/AliEMCALFastRecParticle.h
new file mode 100644 (file)
index 0000000..7faa0dd
--- /dev/null
@@ -0,0 +1,102 @@
+#ifndef ALIEMCALFASTRECPARTICLE_H
+#define ALIEMCALFASTRECPARTICLE_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  A  Particle modified by EMCAL response and produced by AliEMCALvFast
+//  To become a general class of AliRoot ?    
+//               
+//*-- Author: Yves Schutz (SUBATECH)
+
+// --- ROOT system ---
+
+class TClonesArray;
+#include "TParticle.h"
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+class AliEMCALFastRecParticle : public TParticle {
+  
+ public:
+  
+  AliEMCALFastRecParticle() ;
+  
+  AliEMCALFastRecParticle(const AliEMCALFastRecParticle & rp) ;  // ctor
+  AliEMCALFastRecParticle(const TParticle & p) ;  // ctor
+  virtual ~AliEMCALFastRecParticle(){
+    // dtor
+  }
+  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py) ; 
+  virtual void Draw(Option_t *option) ;  
+  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py) ;
+  Int_t GetIndexInList() const { 
+    // returns the index of this in the list
+    return fIndexInList ; 
+  } 
+  virtual Int_t GetNPrimaries() const {return 0 ;}
+  virtual const TParticle * GetPrimary(Int_t /*index=0*/) const  {return 0 ;} 
+  Int_t GetType() const { 
+    // returns the type of the particle
+    return fType ; 
+  } 
+  void SetPIDBit(UInt_t fSet) {
+    // Set PID bit number fSet
+    fType |= (1<<fSet) ; 
+  } 
+  
+  Bool_t TestPIDBit(UInt_t fTest) const {
+    // Check PID bit number fTest
+    if (fType & (1<<fTest) ) return  kTRUE ;   
+    else return kFALSE ;
+  }
+  
+  Bool_t IsPhoton           (TString purity = "low") const;
+  Bool_t IsPi0              (TString purity = "low") const;
+  Bool_t IsElectron         (TString purity = "low") const;
+  Bool_t IsHardPhoton       () const;
+  Bool_t IsHardPi0          () const;
+  Bool_t IsHadron           () const;
+  Bool_t IsChargedHadron    () const;
+  Bool_t IsNeutralHadron    () const;
+  Bool_t IsFastChargedHadron() const;
+  Bool_t IsSlowChargedHadron() const;
+  Bool_t IsFastNeutralHadron() const;
+  Bool_t IsSlowNeutralHadron() const;
+  Bool_t IsEleCon(TString purity = "low") const;  
+
+  TString Name() const ; 
+  virtual void Paint(Option_t * option="");
+  virtual void Print(Option_t * option = "") const ; 
+  
+  void SetType(Int_t type) ;
+  
+  void SetIndexInList(Int_t val) { 
+    // sets the value of the index in the list 
+    fIndexInList = val ; 
+  }
+  //This has to disappear
+  enum EParticleType { kUNDEFINED=-1, 
+                      kNEUTRALEMFAST, kNEUTRALHAFAST,  kNEUTRALEMSLOW, kNEUTRALHASLOW, 
+                      kCHARGEDEMFAST, kCHARGEDHAFAST,  kCHARGEDEMSLOW, kCHARGEDHASLOW } ; 
+  
+  
+  typedef TClonesArray  FastRecParticlesList ; 
+  
+ protected:
+
+  Int_t fIndexInList ; // the index of this RecParticle in the list stored in TreeR (to be set by analysis)
+  Int_t fType ;        // particle type obtained by "virtual" reconstruction
+ private:
+
+
+  ClassDef(AliEMCALFastRecParticle,2)  // Reconstructed Particle produced by the fast simulation 
+
+};
+
+#endif // AliEMCALFASTRECPARTICLE_H
diff --git a/EMCAL/jetfinder/AliEMCALGeneratorFactory.cxx b/EMCAL/jetfinder/AliEMCALGeneratorFactory.cxx
new file mode 100644 (file)
index 0000000..7880f91
--- /dev/null
@@ -0,0 +1,672 @@
+/**************************************************************************
+ * Copyright(c) 1998-2002, 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.                  *
+ **************************************************************************/
+
+/*
+$Log$
+Revision 1.1  2005/08/01 16:11:18  pavlinov
+"Version
+
+*/
+#include "assert.h"
+#include "TString.h"
+#include "AliEMCALGeneratorFactory.h"
+#include "AliGenerator.h"
+#include "AliGenFixed.h"
+#include "AliGenBox.h"
+#include "AliGenHIJINGpara.h"
+#include "AliGenHIJINGparaBa.h"
+#include "AliGenHijing.h"
+#include "AliGenCocktail.h"
+#include "AliGenPythia.h"
+
+//*-- Authors: Aleksei Pavlinov (WSU)
+//*   Initial variant is in Config.C for EMCAL production.
+ClassImp(AliEMCALGeneratorFactory)
+
+AliEMCALGeneratorFactory::AliEMCALGeneratorFactory(PprRunFact_t run, PprRadFact_t rad) 
+{
+    fGenerator = fBgGenerator = fSignalGenerator = 0;
+    fRunType   = run;
+    fRadiation = rad;
+    fMomentum  = 0;
+
+    Int_t isw = 3;
+    if (rad == kNoGluonRadiation) isw = 0;    
+    Float_t thmin=0, thmax=0;
+
+    AliGenFixed *genGG=0;
+    AliGenBox   *genB=0;
+    AliGenHIJINGparaBa *genHijParaB=0, *bg=0;
+    AliGenHIJINGpara   *genHijPara=0;
+    AliGenHijing       *genHij=0;
+    AliGenCocktail     *genCoct=0;
+    AliGenPythia       *genPy=0, *jets=0;
+    //    AliPythia          *aliPy = 0;
+
+    fComment = new TString;
+
+    switch (run) {
+    case kGammaGun:
+        genGG = new AliGenFixed(1);
+       genGG->SetMomentum(100.);
+       genGG->SetPhi(240.);
+       genGG->SetTheta(91.);
+       genGG->SetPart(kGamma);
+       fGenerator = (AliGenerator*)genGG;
+     break;
+
+    case kGammaBox:
+       genB = new AliGenBox(100);
+       genB->SetMomentumRange(100., 100.1);
+       genB->SetPhiRange(0,360);
+       genB->SetThetaRange(45., 135.);
+       genB->SetPart(kGamma);
+        fGenerator = (AliGenerator*)genB;
+       break;
+       
+    case kTest50:
+       genHijParaB = new AliGenHIJINGparaBa(50);
+       genHijParaB->SetMomentumRange(0, 999999.);
+       genHijParaB->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta(8);   // theta min. <---> eta max
+       thmax = EtaToTheta(-8);  // theta max. <---> eta min 
+       genHijParaB->SetThetaRange(thmin,thmax);
+        fGenerator = (AliGenerator*)genHijParaB;
+       break;
+
+    case kParam_8000:
+       //coment= fComment.Append(":HIJINGparam N=8000");
+       genHijPara = new AliGenHIJINGpara(86030);
+       genHijPara->SetMomentumRange(0, 999999.);
+       genHijPara->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta(8);   // theta min. <---> eta max
+       thmax = EtaToTheta(-8);  // theta max. <---> eta min 
+       genHijPara->SetThetaRange(thmin,thmax);
+        fGenerator = (AliGenerator*)genHijPara;
+       break;
+    case kParam_4000:
+       genHijPara = new AliGenHIJINGpara(43015);
+       genHijPara->SetMomentumRange(0, 999999.);
+       genHijPara->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta(8);   // theta min. <---> eta max
+       thmax = EtaToTheta(-8);  // theta max. <---> eta min 
+       genHijPara->SetThetaRange(thmin,thmax);
+        fGenerator = (AliGenerator*)genHijPara;
+       break;
+    case kParam_2000:
+        (*fComment) = "HIJINGparam N=2000";
+       genHijPara = new AliGenHIJINGpara(21507);
+       genHijPara->SetMomentumRange(0, 999999.);
+       genHijPara->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta(8);   // theta min. <---> eta max
+       thmax = EtaToTheta(-8);  // theta max. <---> eta min 
+       genHijPara->SetThetaRange(thmin,thmax);
+        fGenerator = (AliGenerator*)genHijPara;
+       break;
+
+    case kParam_8000_Ecal:
+       genHijParaB = new AliGenHIJINGparaBa(82534);
+       genHijParaB->SetMomentumRange(0, 999999.);
+       genHijParaB->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta( 5);   // theta min. <---> eta max
+       thmax = EtaToTheta(-5);  // theta max. <---> eta min 
+       genHijParaB->SetThetaRange(thmin,thmax);
+        fGenerator = (AliGenerator*)genHijParaB;
+       break;
+
+    case kParam_4000_Ecal:
+       genHijParaB = new AliGenHIJINGparaBa(82534/2);
+       genHijParaB->SetMomentumRange(0, 999999.);
+       genHijParaB->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta( 5);   // theta min. <---> eta max
+       thmax = EtaToTheta(-5);  // theta max. <---> eta min 
+       genHijParaB->SetThetaRange(thmin,thmax);
+        fGenerator = (AliGenerator*)genHijParaB;
+       break;
+//
+//  Hijing Central
+//
+    case kHijing_cent1:
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+        fGenerator = (AliGenerator*)genHij;
+       break;
+    case kHijing_cent2:
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 2.);
+        fGenerator = (AliGenerator*)genHij;
+       break;
+//
+// Hijing Peripheral 
+//
+    case kHijing_per1:
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(5., 8.6);
+        fGenerator = (AliGenerator*)genHij;
+       break;
+    case kHijing_per2:
+       //coment= comment.Append("HIJING per2");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(8.6, 11.2);
+        fGenerator = (AliGenerator*)genHij;
+       break;
+    case kHijing_per3:
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(11.2, 13.2);
+        fGenerator = (AliGenerator*)genHij;
+       break;
+    case kHijing_per4:
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(13.2, 15.);
+        fGenerator = (AliGenerator*)genHij;
+       break;
+    case kHijing_per5:
+       //coment= comment.Append("HIJING per5");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(15., 100.);
+        fGenerator = (AliGenerator*)genHij;
+       break;
+//
+//  Jet-Jet
+//
+    case kHijing_jj25:
+       //coment= comment.Append("HIJING Jet 25 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(1);
+       genHij->SetPtJet(25.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_jj50:
+       //coment= comment.Append("HIJING Jet 50 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(1);
+       genHij->SetPtJet(50.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_jj75:
+       //coment= comment.Append("HIJING Jet 75 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(1);
+       genHij->SetPtJet(75.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_jj100:
+       //coment= comment.Append("HIJING Jet 100 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(1);
+       genHij->SetPtJet(100.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_jj125:
+       //coment= comment.Append("HIJING Jet 125 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(1);
+       genHij->SetPtJet(125.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+//
+// Gamma-Jet
+//
+    case kHijing_gj25:
+       //coment= comment.Append("HIJING Gamma 25 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(2);
+       genHij->SetPtJet(25.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_gj50:
+       //coment= comment.Append("HIJING Gamma 50 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(2);
+       genHij->SetPtJet(50.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_gj75:
+       //coment= comment.Append("HIJING Gamma 75 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(2);
+       genHij->SetPtJet(75.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_gj100:
+       //coment= comment.Append("HIJING Gamma 100 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(2);
+       genHij->SetPtJet(100.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+
+    case kHijing_gj125:
+       //coment= comment.Append("HIJING Gamma 125 GeV");
+       genHij = HijingStandard();
+// impact parameter range
+       genHij->SetImpactParameterRange(0., 5.);
+       // trigger
+       genHij->SetTrigger(2);
+       genHij->SetPtJet(125.);
+       genHij->SetSimpleJets(1);
+       genHij->SetRadiation(isw);
+       genHij->SetJetEtaRange(-0.3,0.3);
+       genHij->SetJetPhiRange(15.,105.);   
+        fGenerator = (AliGenerator*)genHij;
+       break;
+    case kJetPlusBg:
+       genCoct = new AliGenCocktail();
+       genCoct->SetMomentumRange(0, 999999.);
+       genCoct->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta( 5.);   // theta min. <---> eta max
+       thmax = EtaToTheta(-5.);  // theta max. <---> eta min 
+       genCoct->SetThetaRange(thmin,thmax);
+
+//
+//      Underlying Event
+//
+//     AliGenHIJINGparaBa *bg = new AliGenHIJINGparaBa(82534);
+       bg = new AliGenHIJINGparaBa(10);
+        fBgGenerator = (AliGenerator*)bg;
+//
+//      Jets from Pythia
+//
+       jets = new AliGenPythia(-1);
+        fSignalGenerator = (AliGenerator*)jets; 
+//   Centre of mass energy 
+       jets->SetEnergyCMS(5500.);
+//   Process type
+       jets->SetProcess(kPyJets);
+//   final state kinematic cuts
+       jets->SetJetEtaRange(-0.3, 0.3);
+       jets->SetJetPhiRange(15., 105.);
+//   Structure function
+       jets->SetStrucFunc(kGRVLO98);
+//   
+//   Pt transfer of the hard scattering
+       jets->SetPtHard(100.,100.1);
+//   Decay type (semielectronic, semimuonic, nodecay)
+       jets->SetForceDecay(kAll);
+//
+//      Add all to cockail ...    
+//
+       genCoct->AddGenerator(jets,"Jets",1);
+       genCoct->AddGenerator(bg,"Underlying Event", 1);
+        fGenerator = (AliGenerator*)genCoct;
+
+     break;    
+    case kGammaPlusBg:
+       genCoct = new AliGenCocktail();
+       genCoct->SetMomentumRange(0, 999999.);
+       genCoct->SetPhiRange(-180., 180.);
+       // Set pseudorapidity range from -8 to 8.
+       thmin = EtaToTheta( 5.);   // theta min. <---> eta max
+       thmax = EtaToTheta(-5.);  // theta max. <---> eta min 
+       genCoct->SetThetaRange(thmin,thmax);
+//
+//      Underlying Event
+//
+       bg = new AliGenHIJINGparaBa(82534);
+        fBgGenerator = (AliGenerator*)bg;
+//
+//      Jets from Pythia
+//
+       jets = new AliGenPythia(-1);
+        fSignalGenerator = (AliGenerator*)jets; 
+//   Centre of mass energy 
+       jets->SetEnergyCMS(5500.);
+//   Process type
+       jets->SetProcess(kPyDirectGamma);
+//   final state kinematic cuts
+       jets->SetJetEtaRange(-0.3, 0.3);
+       jets->SetJetPhiRange(15., 105.);
+       jets->SetGammaEtaRange(-0.12, 0.12);
+       jets->SetGammaPhiRange(220., 320.);
+//   Structure function
+       jets->SetStrucFunc(kGRVLO98);
+//   
+//   Pt transfer of the hard scattering
+       jets->SetPtHard(100.,100.1);
+//   Decay type (semielectronic, semimuonic, nodecay)
+       jets->SetForceDecay(kAll);
+//
+//      Add all to cockail ...    
+//
+       genCoct->AddGenerator(jets,"Jets",1);
+       genCoct->AddGenerator(bg,"Underlying Event", 1);
+        fGenerator = (AliGenerator*)genCoct;
+
+       break;
+    case kJets_50:
+//  50 GeV Jets
+        genPy = PythiaJets(50.);
+        fGenerator = (AliGenerator*)genPy;
+        break; 
+    case kJets_75:
+//  75 GeV Jets
+        genPy = PythiaJets(75.);
+        fGenerator = (AliGenerator*)genPy;
+        break; 
+    case kJets_100:
+//  100 GeV Jets  
+       genPy = PythiaJets(100.);
+        fGenerator = (AliGenerator*)genPy;
+       break; 
+    case kJets_200:
+//  200 GeV Jets
+        genPy = PythiaJets(200.);
+        fGenerator = (AliGenerator*)genPy;
+        break;
+
+    case kJets_100RadOn:
+//  100 GeV Jets with radiation on - 22-mar-2002 
+//  See AliPythia.cxx for default
+       genPy = PythiaJets(100.);
+       //        genPy->SetKeyPartonJets(1);   // for jet partons
+       //        genPy->DefineParametersForPartonsJets(); 
+
+        fGenerator = (AliGenerator*)genPy;
+       break; 
+
+    case kGammaJets_50:
+//  50 GeV Jets + Gamma
+        genPy = PythiaJets(-1);
+        genPy->SetEnergyCMS(5500.);
+        genPy->SetProcess(kPyDirectGamma);
+        genPy->SetJetEtaRange(-0.3,+0.3);
+        genPy->SetJetPhiRange(15.,105.);
+        genPy->SetGammaEtaRange(-0.12, 0.12);
+        genPy->SetGammaPhiRange(220., 320.);
+        genPy->SetStrucFunc(kGRVLO98);
+        genPy->SetPtHard(50.,50.001);
+        genPy->SetForceDecay(kAll);
+        fGenerator = (AliGenerator*)genPy;
+        break;
+    case kGammaJets_75:
+//  75 GeV Jets + Gamma 
+        genPy = PythiaJets(-1);
+        genPy->SetEnergyCMS(5500.);
+        genPy->SetProcess(kPyDirectGamma);
+        genPy->SetJetEtaRange(-0.3,+0.3);
+        genPy->SetJetPhiRange(15.,105.);
+        genPy->SetGammaEtaRange(-0.12, 0.12);
+        genPy->SetGammaPhiRange(220., 320.);
+        genPy->SetStrucFunc(kGRVLO98);
+        genPy->SetPtHard(75.,75.001);
+        genPy->SetForceDecay(kAll);
+        fGenerator = (AliGenerator*)genPy;
+        break; 
+    case kGammaJets_100:
+// 100 GeV Jets + Gamma
+        genPy = PythiaJets(-1);
+        genPy->SetEnergyCMS(5500.);
+        genPy->SetProcess(kPyDirectGamma);
+        genPy->SetJetEtaRange(-0.3,+0.3);
+        genPy->SetJetPhiRange(15.,105.);
+        genPy->SetGammaEtaRange(-0.12, 0.12);
+        genPy->SetGammaPhiRange(220., 320.);
+        genPy->SetStrucFunc(kGRVLO98);
+        genPy->SetPtHard(100.,100.001);
+        genPy->SetForceDecay(kAll);
+        fGenerator = (AliGenerator*)genPy;
+        break; 
+    case kGammaJets_200:
+//  200 GeV Jets + Gamma
+        genPy = PythiaJets(-1);
+        genPy->SetEnergyCMS(5500.);
+        genPy->SetProcess(kPyDirectGamma);
+        genPy->SetJetEtaRange(-0.3,+0.3);
+        genPy->SetJetPhiRange(15.,105.);
+        genPy->SetGammaEtaRange(-0.12, 0.12);
+        genPy->SetGammaPhiRange(220., 320.);
+        genPy->SetStrucFunc(kGRVLO98);
+        genPy->SetPtHard(200.,200.001);
+        genPy->SetForceDecay(kAll);
+        fGenerator = (AliGenPythia*)genPy;
+        break; 
+    case kGammaJets_250:
+//  250 GeV Jets + Gamma
+        genPy = PythiaJets(-1);
+        genPy->SetEnergyCMS(5500.);
+        genPy->SetProcess(kPyDirectGamma);
+        genPy->SetJetEtaRange(-0.3,+0.3);
+        genPy->SetJetPhiRange(15.,105.);
+        genPy->SetGammaEtaRange(-0.12, 0.12);
+        genPy->SetGammaPhiRange(220., 320.);
+        genPy->SetStrucFunc(kGRVLO98);
+        genPy->SetPtHard(250.,250.001);
+        genPy->SetForceDecay(kAll);
+        fGenerator = (AliGenerator*)genPy;
+        break; 
+    case kGammaJets_300:
+//  300 GeV Jets + Gamma
+        genPy = PythiaJets(-1);
+        genPy->SetEnergyCMS(5500.);
+        genPy->SetProcess(kPyDirectGamma);
+        genPy->SetJetEtaRange(-0.3,+0.3);
+        genPy->SetJetPhiRange(15.,105.);
+        genPy->SetGammaEtaRange(-0.12, 0.12);
+        genPy->SetGammaPhiRange(220., 320.);
+        genPy->SetStrucFunc(kGRVLO98);
+        genPy->SetPtHard(300.,300.001);
+        genPy->SetForceDecay(kAll);
+        fGenerator = (AliGenerator*)genPy;
+        break;
+    default:
+        printf("<I> wrong parameter for generator run %i rad %i\n", run, rad);
+        assert(0);
+    }
+    if(fGenerator) fGenerator->SetPtRange(0.,1.e10); // discard the limit on pT
+
+}
+
+AliEMCALGeneratorFactory::AliEMCALGeneratorFactory(PprRunFact_t run, Float_t p) 
+{
+    fGenerator = fBgGenerator = fSignalGenerator = 0;
+    fRunType   = run;
+    fMomentum  = p;
+
+    AliGenBox   *genB=0;
+
+    switch (run) {
+    case kGammaBoxOne:
+        genB = OneParticleWithFixedEnergy(kGamma, p);  
+    break;
+    case kPi0BoxOne:
+        genB = OneParticleWithFixedEnergy(kPi0, p);  
+    break;
+    default:
+        printf("<I> wrong parameter for generator run %i \n",run);
+        assert(0);
+    }
+    if(genB) fGenerator = (AliGenerator*)genB;
+    //    if(fGenerator) fGenerator->SetPtRange(0.,1.e10); // discard the limit on pT - 23-aug-04
+}
+
+AliGenHijing* AliEMCALGeneratorFactory::HijingStandard()
+{
+    AliGenHijing *gener = new AliGenHijing(-1);
+// centre of mass energy 
+    gener->SetEnergyCMS(5500.);
+// reference frame
+    gener->SetReferenceFrame("CMS");
+// projectile
+    gener->SetProjectile("A", 208, 82);
+    gener->SetTarget    ("A", 208, 82);
+// tell hijing to keep the full parent child chain
+    gener->KeepFullEvent();
+// enable jet quenching
+    gener->SetJetQuenching(1);
+// enable shadowing
+    gener->SetShadowing(1);
+// neutral pion and heavy particle decays switched off
+    gener->SetDecaysOff(1);
+// Don't track spectators
+    gener->SetSpectators(0);
+// kinematic selection
+    gener->SetSelectAll(0);
+    return gener;
+}
+
+AliGenPythia* AliEMCALGeneratorFactory::PythiaJets(Float_t energy)
+{
+    AliGenPythia *gener = new AliGenPythia(-1);
+//   Centre of mass energy 
+    gener->SetEnergyCMS(5500.);
+//   Process type
+    gener->SetProcess(kPyJets);
+//   final state kinematic cuts
+    gener->SetJetEtaRange(-0.3, 0.3);
+    gener->SetJetPhiRange(15., 105.);
+//   Structure function
+    gener->SetStrucFunc(kGRVLO98);
+//   
+//   Pt transfer of the hard scattering
+    gener->SetPtHard(energy, energy+0.1);
+//   Decay type (semielectronic, semimuonic, nodecay)
+    gener->SetForceDecay(kAll);
+//
+    return gener;
+}
+
+
+AliGenPythia* AliEMCALGeneratorFactory::PythiaGamma(Float_t energy)
+{
+    AliGenPythia *gener = new AliGenPythia(-1);
+//   Centre of mass energy 
+    gener->SetEnergyCMS(5500.);
+//   Process type
+    gener->SetProcess(kPyDirectGamma);
+//   final state kinematic cuts
+    gener->SetJetEtaRange(-0.3, 0.3);
+    gener->SetJetPhiRange(15., 105.);
+    gener->SetGammaEtaRange(-0.12, 0.12);
+    gener->SetGammaPhiRange(220., 320.);
+//   Structure function
+    gener->SetStrucFunc(kGRVLO98);
+//   
+//   Pt transfer of the hard scattering
+    gener->SetPtHard(energy, energy+0.1);
+//   Decay type (semielectronic, semimuonic, nodecay)
+    gener->SetForceDecay(kAll);
+//
+    return gener;
+}
+
+//
+// Staff of Aleksei Pavlinov.
+//
+AliGenBox* AliEMCALGeneratorFactory::OneParticleWithFixedEnergy(Int_t type, Float_t p)
+{// one particle in EMCAL acceptance
+   Float_t thmin  = EtaToTheta(0.7), thmax  = EtaToTheta(-0.7); 
+   Float_t phimin=0, phimax=120;
+   Float_t pmin=p, pmax=p+0.01;
+
+   AliGenBox *gen = new AliGenBox(1);
+   gen->SetPart(type);
+   gen->SetNumberParticles(1); 
+   gen->SetThetaRange(thmin, thmax);
+   gen->SetPhiRange(phimin, phimax);
+   gen->SetMomentumRange(pmin, pmax);
+
+   printf("<I> AliEMCALGeneratorFactory::OneParticleWithFixedEnergy \n");
+   printf("       type of particle -> %i \n", type);
+   printf("    %6.4f <    eta   < %6.4f\n", thmin,  thmax);
+   printf("    %6.4f <    phi   < %6.4f\n", phimin, phimax);
+   printf("    %7.2f < Momentum < %7.2f\n", pmin, pmax);
+   printf("     TestBit(kPtRange) %i | TestBit(kMomentumRange) %i\n", 
+   gen->TestBit(BIT(17)), gen->TestBit(BIT(19)));
+   return gen;
+}
diff --git a/EMCAL/jetfinder/AliEMCALGeneratorFactory.h b/EMCAL/jetfinder/AliEMCALGeneratorFactory.h
new file mode 100644 (file)
index 0000000..252882d
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef ALIEMCALGENERATORFACTORY_H
+#define ALIEMCALGENERATORFACTORY_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Class for generator factory which used in production for EMCAL.
+//  Based on Config.C file 
+//*-- Author: Aleksei Pavlinov (WSU)
+#include <TObject.h>
+#include <TMath.h>
+#include "AliPDG.h"
+// 23-aug-04 for kGamma and kPi0
+#include <TPDGCode.h>
+
+class AliGenerator;
+class AliGenHijing;
+class AliGenPythia;
+class AliGenBox;
+class TString;
+
+enum PprRunFact_t 
+{
+    kTest50,
+    kParam_8000,   kParam_4000,  kParam_2000, 
+    kHijing_cent1, kHijing_cent2, 
+    kHijing_per1,  kHijing_per2, kHijing_per3, kHijing_per4,  kHijing_per5,
+    kHijing_jj25,  kHijing_jj50, kHijing_jj75, kHijing_jj100, kHijing_jj125, 
+    kHijing_gj25,  kHijing_gj50, kHijing_gj75, kHijing_gj100, kHijing_gj125, 
+    kJetPlusBg,    kGammaPlusBg, 
+    kParam_8000_Ecal, kParam_4000_Ecal, 
+    kJets_50,       kJets_75,      kJets_100,      kJets_200,
+    kJets_100RadOn, 
+    kGammaJets_50,  kGammaJets_75, kGammaJets_100, kGammaJets_200,
+    kGammaJets_250, kGammaJets_300,
+    kGammaGun, kGammaBox,
+    kGammaBoxOne, kPi0BoxOne 
+};
+
+enum PprRadFact_t
+{ // Concern only HIJING 
+    kGluonRadiation, kNoGluonRadiation
+};
+
+class AliEMCALGeneratorFactory : public TObject{
+
+ public:
+  explicit AliEMCALGeneratorFactory
+  (PprRunFact_t run=kJets_50, PprRadFact_t rad = kGluonRadiation);
+  explicit AliEMCALGeneratorFactory(PprRunFact_t run, Float_t p);
+  AliGenHijing* HijingStandard();
+  AliGenPythia* PythiaJets(Float_t energy);
+  AliGenPythia* PythiaGamma(Float_t energy);
+  AliGenBox*    OneParticleWithFixedEnergy(Int_t type=kGamma, Float_t p=1.0);
+
+  AliGenerator* GetGenerator() {return fGenerator;}
+  AliGenerator* GetBgGenerator() {return fBgGenerator;}
+  AliGenerator* GetSignalGenerator() {return fSignalGenerator;}
+  PprRunFact_t  GetRunType()   {return fRunType;}
+  PprRadFact_t  GetRadiation() {return fRadiation;}
+  TString*      GetComment() {return fComment;}
+  static Float_t EtaToTheta(Float_t arg) {return (180./TMath::Pi())*2.*atan(exp(-arg));}
+
+protected:
+  AliGenerator* fGenerator;        //! 
+  AliGenerator* fBgGenerator;      //! 
+  AliGenerator* fSignalGenerator;  //! 
+  PprRunFact_t  fRunType;
+  PprRadFact_t  fRadiation;
+  Float_t       fMomentum;
+  TString      *fComment;          //!
+
+  ClassDef(AliEMCALGeneratorFactory,1) // Generator Factory for EMCAL production
+
+};
+#endif // ALIEMCALGENERATORFACTORY_H
diff --git a/EMCAL/jetfinder/AliEMCALHadronCorrection.cxx b/EMCAL/jetfinder/AliEMCALHadronCorrection.cxx
new file mode 100644 (file)
index 0000000..5a429ee
--- /dev/null
@@ -0,0 +1,30 @@
+/**************************************************************************
+ * Copyright(c) 1998-2002, 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$ */
+//--
+//--
+//--  Hadron correction base class
+//--
+//--
+//--
+
+
+#include "AliEMCALHadronCorrection.h"
+
+ClassImp(AliEMCALHadronCorrection)
+
+AliEMCALHadronCorrection::AliEMCALHadronCorrection(const char *name,const char *title) 
+:TNamed(name,title) { }
diff --git a/EMCAL/jetfinder/AliEMCALHadronCorrection.h b/EMCAL/jetfinder/AliEMCALHadronCorrection.h
new file mode 100644 (file)
index 0000000..c8f5808
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef ALIEMCALHADRONCORRECTION_H
+#define ALIEMCALHADRONCORRECTION_H
+/* Copyright(c) 1998-2002, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//                  
+//*-- Author: Aleksei Pavlinov (WSU)
+// This pure abstract class which defines only interface
+// 
+#include "TNamed.h"
+
+class AliEMCALHadronCorrection : public TNamed {
+
+  public:
+  AliEMCALHadronCorrection(const char *name="name", const char *title="title");
+  virtual ~AliEMCALHadronCorrection() {} 
+
+  // Add for particle
+  virtual Double_t GetEnergy(Double_t pmom, Double_t eta, Int_t gid)=0; 
+
+  ClassDef(AliEMCALHadronCorrection,1) // Hadron correction for EMC (abstract class)
+};
+
+#endif // ALIEMCALHADRONCORRECTION_H
diff --git a/EMCAL/jetfinder/AliEMCALHadronCorrectionv0.cxx b/EMCAL/jetfinder/AliEMCALHadronCorrectionv0.cxx
new file mode 100644 (file)
index 0000000..39cfbd2
--- /dev/null
@@ -0,0 +1,78 @@
+/**************************************************************************
+ * Copyright(c) 1998-2002, 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 "AliEMCALHadronCorrectionv0.h"
+
+const Int_t maxVariant = 8;  // size eta grid
+const Int_t nVec = 10;       // size momentum grid
+const Int_t nPol = 4;        // number coefficients of polinom
+static Double_t etaGrid[maxVariant]={ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.67};
+static Double_t pGrid[nVec]={ 0.2, 0.5, 1.0, 2.0, 3.0, 5.0,10.0,15.0,25.0,40.0};
+// c[][] - first index for eta, second for momentum 
+static Double_t c[maxVariant][nPol] ={
+    {1.305705e-01, 3.725653e-01, -1.219962e-02, 1.806235e-04},
+    {1.296153e-01, 3.827408e-01, -1.238640e-02, 1.822804e-04},
+    {1.337690e-01, 3.797454e-01, -1.245227e-02, 1.848243e-04},
+    {1.395796e-01, 3.623994e-01, -9.196803e-03, 1.243278e-04},
+    {1.457184e-01, 3.753655e-01, -1.035324e-02, 1.473447e-04},
+    {1.329164e-01, 4.219044e-01, -1.310515e-02, 1.948883e-04},
+    {8.136581e-02, 4.646087e-01, -1.531917e-02, 2.274749e-04},
+    {1.119836e-01, 4.262497e-01, -1.160125e-02, 1.628738e-04} };
+
+ClassImp(AliEMCALHadronCorrectionv0)
+
+AliEMCALHadronCorrectionv0* AliEMCALHadronCorrectionv0::fHadrCorr = 0;
+
+AliEMCALHadronCorrectionv0::AliEMCALHadronCorrectionv0(const char *name,const char *title) 
+                           :AliEMCALHadronCorrection(name, title)
+{
+  fHadrCorr = this;
+}
+
+AliEMCALHadronCorrectionv0*
+AliEMCALHadronCorrectionv0::Instance()
+{
+  fHadrCorr = new AliEMCALHadronCorrectionv0();
+  return fHadrCorr;
+}
+
+Double_t 
+AliEMCALHadronCorrectionv0::GetEnergy(Double_t pmom, Double_t eta, Int_t /*gid*/)
+{
+  Int_t iEta=0; // index 
+  Double_t etaw = TMath::Abs(eta);
+  if(etaw > etaGrid[maxVariant-1]) etaw = etaGrid[maxVariant-1];
+  for(Int_t i=0; i<maxVariant; i++) if(eta>=etaGrid[i]) {iEta = i; break;}
+
+  Double_t e[2], y, pw = pmom;
+  if(pmom > pGrid[nVec-1]) pw = pGrid[nVec-1];
+  for(Int_t i=0; i<2; i++){ // e for two eta value
+    e[i] = c[iEta][0];
+    y = 1.;
+    for(Int_t j=1; j<nPol; j++){
+      y *= pw;
+      e[i] += c[iEta][j]*y;
+    }
+    if(i==0) iEta ++;
+  }
+
+  Double_t deta = etaGrid[iEta] - etaGrid[iEta-1];
+  Double_t a = (e[1] - e[0])/deta; // slope 
+  Double_t energy = e[0] + a*(eta-etaGrid[iEta-1]);
+  return energy;
+}
diff --git a/EMCAL/jetfinder/AliEMCALHadronCorrectionv0.h b/EMCAL/jetfinder/AliEMCALHadronCorrectionv0.h
new file mode 100644 (file)
index 0000000..2e0ff27
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef ALIEMCALHADRONCORRECTIONV0_H
+#define ALIEMCALHADRONCORRECTIONV0_H
+/* Copyright(c) 1998-2002, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//                  
+//*-- Author: Aleksei Pavlinov (WSU)
+#include "AliEMCALHadronCorrection.h"
+
+class AliEMCALHadronCorrectionv0: public AliEMCALHadronCorrection {
+
+  private:
+  static AliEMCALHadronCorrectionv0* fHadrCorr;
+
+  protected:
+  AliEMCALHadronCorrectionv0(const char *name="HadronCorrectionv0", const char *title="title");
+
+  public:
+  static  AliEMCALHadronCorrectionv0* Instance();
+  virtual Double_t GetEnergy(Double_t pmom, Double_t eta, Int_t gid); 
+  Double_t GetEnergy(Double_t pmom, Double_t eta) 
+  {return GetEnergy(pmom,eta,7);}
+
+  virtual ~AliEMCALHadronCorrectionv0() {}
+
+  ClassDef(AliEMCALHadronCorrectionv0,1) // Hadron correction for EMC (version for MDC)
+};
+
+#endif // ALIEMCALHADRONCORRECTIONV0_H
diff --git a/EMCAL/jetfinder/AliEMCALHadronCorrectionv1.cxx b/EMCAL/jetfinder/AliEMCALHadronCorrectionv1.cxx
new file mode 100644 (file)
index 0000000..26b763e
--- /dev/null
@@ -0,0 +1,122 @@
+/**************************************************************************
+ * Copyright(c) 1998-2002, 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.                  *
+ **************************************************************************/
+
+
+// Author : Mark Horner (LBL/UCT)
+
+#include "AliEMCALHadronCorrectionv1.h"
+#include "AliEMCALGeometry.h"
+#include "Riostream.h"
+#include "TMath.h"
+
+ClassImp(AliEMCALHadronCorrectionv1)
+
+Double_t AliEMCALHadronCorrectionv1::fgParLookup[HCPARAMETERS][HCPARAMETERSETS] = 
+{  
+    {-2.82271e-4 , -2.39954e-4},   
+    {2.50796e-2  , 2.07172e-2},   
+    {1.02861e-3  , 1.48576e-3},   
+    {2.11539e-2  , -1.38473-2},   
+    {2.27003e-2  , 2.78252e-2},   
+    {1.65078e-6  , 1.51821e-6}
+};
+
+AliEMCALHadronCorrectionv1* AliEMCALHadronCorrectionv1::fgHadrCorr = 0;
+
+void AliEMCALHadronCorrectionv1::SetGeometry(AliEMCALGeometry *geometry)
+{
+  // Initialise EMCAL geometry
+    if (!geometry)
+    {
+       SetParameters();
+       fSamplingFraction = geometry->GetSampling();
+       cout<<"Setting the sampling fraction to :"<<fSamplingFraction<<endl; 
+    }else
+    {
+        SetParameters(geometry->GetName());
+       fSamplingFraction = geometry->GetSampling();
+       cout<<"Setting the sampling fraction to :"<<fSamplingFraction<<endl; 
+    }
+    return;    
+}      
+       
+void AliEMCALHadronCorrectionv1::SetGeometry(TString name,Double_t fs)
+{
+  // Initialise EMCAL geometry
+  cout << "Setting sampling fraction to "<<fSamplingFraction<<endl;    
+   fSamplingFraction = fs;     
+  if ( name == ""              ||
+       name == "EMCAL_5655_21" ||
+       name == "EMCALArch1a"   ||
+       name == "EMCALArch1aN"  ||
+       name == "G56_2_55_19"   ||
+       name == "G56_2_55_19_104_14" )
+  { // set parameters to this hadron correction
+     cout<<"HC parameters!"<<endl;
+     for (Int_t i=0;i<6;i++)
+     {
+          fPar[i] = fgParLookup[i][0];  
+          cout <<fPar[i]<<endl;
+     }
+  }else if( name == "EMCAL_6564_21" ||  
+           name == "G65_2_64_19" )
+  {      
+      cout<<"HC parameters!"<<endl;
+     for (Int_t i=0;i<6;i++)
+     {
+          fPar[i] = fgParLookup[i][1];  
+          cout <<fPar[i]<<endl;
+     }
+  }else
+  {
+    printf("Geometry not defined in hadron correction\n"); 
+  }      
+       
+}      
+
+       
+AliEMCALHadronCorrectionv1::AliEMCALHadronCorrectionv1(const char *name,const char *title) 
+                           :AliEMCALHadronCorrection(name, title)
+{
+  fgHadrCorr = this;
+}
+
+/*
+AliEMCALHadronCorrectionv1::AliEMCALHadronCorrectionv1(const char *name,const char *title,AliEMCALGeometry *geometry)
+{
+
+  fHadrCorr = this;
+  SetGeometry(geometry);  
+       
+}      
+*/
+
+AliEMCALHadronCorrectionv1*
+AliEMCALHadronCorrectionv1::Instance()
+{
+  // return pointer to global instance. Instantiate if needed
+  if (! fgHadrCorr) new AliEMCALHadronCorrectionv1();
+  return fgHadrCorr;
+}
+
+Double_t 
+AliEMCALHadronCorrectionv1::GetEnergy(Double_t pmom, Double_t eta, Int_t /*gid*/)
+{
+  // Return parametrised energy response
+  Double_t etai = TMath::Abs(eta); 
+  Double_t value =  fPar[5]*pmom*pmom*pmom+ fPar[0]*pmom*pmom+fPar[1]*pmom +fPar[2]*pmom*etai +fPar[3]*etai + fPar[4];
+  return fSamplingFraction*value;
+   
+}
diff --git a/EMCAL/jetfinder/AliEMCALHadronCorrectionv1.h b/EMCAL/jetfinder/AliEMCALHadronCorrectionv1.h
new file mode 100644 (file)
index 0000000..7b059ab
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef ALIEMCALHADRONCORRECTIONV1_H
+#define ALIEMCALHADRONCORRECTIONV1_H
+/* Copyright(c) 1998-2002, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+//                  
+//*-- Author: Mark Horner (LBL/UCT)
+//
+#include "AliEMCALHadronCorrection.h"
+
+
+#define HCPARAMETERS    6
+#define HCPARAMETERSETS 2
+
+class AliEMCALGeometry;
+
+class AliEMCALHadronCorrectionv1: public AliEMCALHadronCorrection {
+ public:
+    static  AliEMCALHadronCorrectionv1* Instance();
+    virtual Double_t GetEnergy(Double_t pmom, Double_t eta, Int_t gid); 
+    Double_t GetEnergy(Double_t pmom, Double_t eta) 
+       {return GetEnergy(pmom,eta,7);}
+    
+    void SetGeometry(TString name, Double_t fs = 1.); 
+    virtual ~AliEMCALHadronCorrectionv1() {}
+ protected:
+    AliEMCALHadronCorrectionv1(const char *name="HadronCorrectionv1", const char *title="Hadron Correction");
+    
+//    AliEMCALHadronCorrectionv1(const char *name="HadronCorrectionv1", const char *title="Hadron Correction",AliEMCALGeometry *geometry = NULL);
+    void SetGeometry(AliEMCALGeometry *geometry);
+    
+ private:
+    void SetParameters(TString name = "") {Warning("SetParameter","Dummy method with argument %s",name.Data());}
+    
+    static AliEMCALHadronCorrectionv1* fgHadrCorr;  // Pointer to global instance (singleton)
+    static Double_t fgParLookup[HCPARAMETERS][HCPARAMETERSETS]; // Global array with parameters for hadronic response
+    Double_t fPar[6];
+    Float_t  fSamplingFraction;  // Sampling fraction
+    
+    
+    ClassDef(AliEMCALHadronCorrectionv1,2) // Hadron correction for EMC (version for MDC)
+};
+
+#endif // ALIEMCALHADRONCORRECTIONV1_H
diff --git a/EMCAL/jetfinder/AliEMCALJet.cxx b/EMCAL/jetfinder/AliEMCALJet.cxx
new file mode 100644 (file)
index 0000000..dedf693
--- /dev/null
@@ -0,0 +1,80 @@
+/**************************************************************************
+ * 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$ */
+
+//*-- Author: Andreas Morsch (CERN)
+
+#include "AliEMCALJet.h"
+#include "Ecommon.h"
+
+ClassImp(AliEMCALJet)
+
+//____________________________________________________________________________
+AliEMCALJet::AliEMCALJet()
+{
+// Default constructor
+}
+
+AliEMCALJet::AliEMCALJet(Float_t energy, Float_t phi, Float_t eta)
+{
+// Constructor
+    fEnergy = energy;
+    fPhi    = phi;
+    fEta    = eta;
+}
+
+//____________________________________________________________________________
+AliEMCALJet::~AliEMCALJet()
+{
+// Destructor
+}
+
+
+void AliEMCALJet::SetTrackList(Int_t n, Float_t* pt, Float_t* eta, Float_t* phi, Int_t* pdg)
+{
+//
+// 
+    fNt = n;
+    for (Int_t i = 0; i < n; i++) {
+       fPtT [i]  = pt [i];
+       fEtaT[i]  = eta[i];
+       fPhiT[i]  = phi[i];
+       fPdgT[i]  = pdg[i];
+    }
+}
+
+
+
+Int_t AliEMCALJet::TrackList(Float_t* pt, Float_t* eta, Float_t* phi, Int_t* pdg) const
+{
+//
+// 
+    for (Int_t i = 0; i < fNt; i++) {
+       pt [i] = fPtT [i];
+       eta[i] = fEtaT[i];
+       phi[i] = fPhiT[i];
+       pdg[i] = fPdgT[i];
+    }
+    return fNt;
+}
+
+
+
+
+
+
+
diff --git a/EMCAL/jetfinder/AliEMCALJet.h b/EMCAL/jetfinder/AliEMCALJet.h
new file mode 100644 (file)
index 0000000..d43cef6
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef ALIEMCALJET_H
+#define ALIEMCALJET_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+#include <TObject.h>
+//*-- Author: Andreas Morsch (CERN)
+
+
+class AliEMCALJet : public TObject {
+ public:
+  AliEMCALJet();
+  AliEMCALJet(Float_t energy, Float_t phi, Float_t eta); 
+  virtual ~AliEMCALJet();
+  void SetEnergy(Float_t val) {fEnergy = val;}
+  void SetEMCALEnergy(Float_t val) {fEMCALEnergy = val;}
+  void SetEMCALEnergyBGSub(Float_t val){fEMCALEnergyBGSub = val;}
+  void SetTrackEnergy(Float_t val) {fTrackEnergy = val;}
+  void SetTrackEnergyPtCut(Float_t val){fTrackEnergyPtCut = val;}
+  void SetHCEnergy(Float_t val) {fHCEnergy = val;}
+  void SetPhi(Float_t val)    {fPhi    = val;}  
+  void SetEta(Float_t val)    {fEta    = val;}    
+  void SetIsWeightedEnergy(Bool_t flag)    {fIsWeightedEnergy    = flag;}    
+  void SetTrackList(Int_t val, Float_t* pt, Float_t* eta, Float_t* phi, Int_t* pdg);
+  Float_t Energy() const  {return fEnergy;}
+  Float_t EMCALEnergy() const  {return fEMCALEnergy;}
+  Float_t EMCALEnergyBGSub()  const {return fEMCALEnergyBGSub;}
+  Float_t TrackEnergy() const  {return fTrackEnergy;}
+  Float_t TrackEnergyPtCut() const  {return fTrackEnergyPtCut;}
+  Float_t HCEnergy() const  {return fHCEnergy;}
+  Float_t Phi() const     {return fPhi;}
+  Float_t Eta()  const    {return fEta;}
+  Int_t   TrackList(Float_t* pt, Float_t* eta, Float_t* phi, Int_t* pdg)const;
+  Int_t   NTracks() const {return fNt;} 
+  
+protected:
+  Float_t  fEnergy;      // Jet Energy
+  Float_t  fEMCALEnergy; // EMCAL component of Energy inside Jet cone before BG subtraction
+  Float_t  fEMCALEnergyBGSub; // EMCAL component of Energy inside Jet cone after BG subtraction
+  Float_t  fTrackEnergy; // Charge tracks component of Energy inside Jet cone with no pT cut
+  Float_t  fTrackEnergyPtCut; // Charge tracks component of Energy inside Jet cone after pT cut
+  Float_t  fHCEnergy;    // HC  component of Energy inside Jet cone
+  Bool_t   fIsWeightedEnergy; // Store flag regarding energy calculation
+  Float_t  fEta;      // Jet Eta
+  Float_t  fPhi;      // Jet Phi
+  Int_t    fNt;       // Number of associated tracks
+  Float_t  fPtT [1000]; // Track pt 
+  Float_t  fEtaT[1000]; // Track eta
+  Float_t  fPhiT[1000]; // Track phi
+  Int_t    fPdgT[1000]; // Track pdg code
+  ClassDef(AliEMCALJet,8) // Jet for EMCAL
+
+} ;
+
+#endif // ALIEMCALJet_H
diff --git a/EMCAL/jetfinder/AliEMCALJetFinder.cxx b/EMCAL/jetfinder/AliEMCALJetFinder.cxx
new file mode 100644 (file)
index 0000000..0ea8700
--- /dev/null
@@ -0,0 +1,1975 @@
+/**************************************************************************
+ * 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$ */
+
+//*-- Authors: Andreas Morsch   (CERN)
+//*            J.L. Klay        (LBL)
+//*            Aleksei Pavlinov (WSU) 
+//--
+//--
+//
+
+#include <stdio.h>
+// From root ...
+#include <TArrayF.h>
+#include <TAxis.h>
+#include <TBranchElement.h>
+#include <TCanvas.h>
+#include <TClonesArray.h>
+#include <TFile.h>
+#include <TH1.h>
+#include <TH2.h>
+#include <TList.h>
+#include <TPDGCode.h>
+#include <TPad.h>
+#include <TParticle.h>
+#include <TParticlePDG.h>
+#include <TPaveText.h>
+#include <TPythia6Calls.h>
+#include <TROOT.h>
+#include <TStyle.h>
+#include <TTree.h>
+#include <TBrowser.h>
+
+// From AliRoot ...
+#include "AliEMCALJetFinder.h"
+#include "AliHeader.h"
+#include "AliMagF.h"
+#include "AliMagFCM.h"
+#include "AliRun.h"
+#include "AliGenerator.h"
+#include "AliRunLoader.h"
+#include "AliEMCAL.h"
+#include "AliEMCALLoader.h"
+#include "AliEMCALDigit.h"
+#include "AliEMCALDigitizer.h"
+#include "AliEMCALFast.h"
+#include "AliEMCALGeometry.h"
+#include "AliEMCALHadronCorrection.h"
+#include "AliEMCALHit.h"
+#include "AliEMCALJetMicroDst.h"
+
+// Interface to FORTRAN
+#include "Ecommon.h"
+#include "AliMC.h"
+
+
+ClassImp(AliEMCALJetFinder)
+
+//____________________________________________________________________________
+AliEMCALJetFinder::AliEMCALJetFinder()
+{
+// Default constructor
+    fJets             = 0;
+    fNjets            = 0;
+    fLego             = 0;
+    fLegoB            = 0;
+
+    fTrackList        = 0;
+    fPtT              = 0;
+    fEtaT             = 0;
+    fPhiT             = 0;
+    fPdgT             = 0;
+    
+    fTrackListB       = 0;
+    fPtB              = 0;
+    fEtaB             = 0;
+    fPhiB             = 0;
+    fPdgB             = 0;
+
+    fHCorrection      = 0;
+    fHadronCorrector  = 0;
+
+    fWrite            = 0;
+    fOutFileName      = 0;
+    fOutFile          = 0;
+    fInFile           = 0;
+    fEvent            = 0;
+
+    fRandomBg         = 0;
+    
+    SetParametersForBgSubtraction();
+}
+
+AliEMCALJetFinder::AliEMCALJetFinder(const char* name, const char *title)
+    : TTask(name, title)
+{
+// Constructor 
+// Title is used in method GetFileNameForParameters();
+//
+    fJets  = new TClonesArray("AliEMCALJet",10000);
+    fNjets = 0;
+    for (Int_t i = 0; i < 30000; i++)
+    {
+       fEtCell[i]  = 0.;
+       fEtaCell[i] = 0.;
+        fPhiCell[i] = 0.;
+    }
+    fLego       = 0;
+    fLegoB      = 0;
+
+    fTrackList  = 0;
+    fPtT        = 0;
+    fEtaT       = 0;
+    fPhiT       = 0;
+    fPdgT       = 0;
+
+    fTrackListB       = 0;
+    fPtB        = 0;
+    fEtaB       = 0;
+    fPhiB       = 0;
+    fPdgB       = 0;
+
+    fHCorrection      = 0;
+    fHadronCorrector  = 0;
+    fBackground       = 0;
+    fWrite            = 0;
+    fOutFileName      = 0;
+    fOutFile          = 0;
+    fInFile           = 0;
+    fEvent            = 0;
+//
+    SetPtCut();
+    SetMomentumSmearing();
+    SetEfficiencySim();
+    SetDebug();
+    SetHadronCorrection();
+    SetIncludeK0andN();
+
+    fRandomBg         = 0;
+    SetParametersForBgSubtraction();
+}
+
+void AliEMCALJetFinder::SetParametersForBgSubtraction
+(Int_t mode, Float_t minMove, Float_t maxMove, Float_t precBg)
+{
+// see file /home/pavlinov/cosmic/pythia/jetFinderParamData.inc
+// at WSU Linux cluster - 11-feb-2002
+// These parameters must be tuned more carefull !!!
+  SetMode(mode);
+  SetMinMove(minMove);
+  SetMaxMove(maxMove);
+  SetPrecBg(precBg);
+}
+
+//____________________________________________________________________________
+AliEMCALJetFinder::~AliEMCALJetFinder()
+{
+// Destructor
+//
+    if (fJets){
+       fJets->Delete();
+       delete fJets;
+    }
+    delete fLego;            
+    delete fLegoB;
+    delete fhLegoTracks;  
+    delete fhLegoEMCAL;   
+    delete fhLegoHadrCorr;
+    delete fhEff;         
+    delete fhCellEt;      
+    delete fhCellEMCALEt; 
+    delete fhTrackPt;     
+    delete fhTrackPtBcut; 
+    delete fhChPartMultInTpc;
+
+    delete[] fTrackList;
+    delete[] fPtT;      
+    delete[] fEtaT;     
+    delete[] fPhiT;     
+    delete[] fPdgT;     
+    delete[] fTrackListB;
+    delete[] fPtB;       
+    delete[] fEtaB;      
+    delete[] fPhiB;      
+    delete[] fPdgB;      
+}
+
+#ifndef WIN32
+# define jet_finder_ua1 jet_finder_ua1_
+# define hf1 hf1_
+# define type_of_call
+
+#else
+# define jet_finder_ua1 JET_FINDER_UA1
+# define hf1 HF1
+# define type_of_call _stdcall
+#endif
+
+extern "C" void type_of_call 
+jet_finder_ua1(Int_t& ncell, Int_t& ncell_tot,
+              Float_t  etc[30000],  Float_t etac[30000],
+              Float_t  phic[30000], 
+              Float_t& min_move, Float_t& max_move, Int_t& mode, 
+              Float_t& prec_bg,  Int_t& ierror);
+
+extern "C" void type_of_call hf1(Int_t& id, Float_t& x, Float_t& wgt);
+
+
+void AliEMCALJetFinder::Init()
+{
+//
+// Geometry and I/O initialization
+//
+//
+//
+//  Get geometry parameters from EMCAL
+//
+//
+//  Geometry 
+  //AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
+  AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
+
+//    SetSamplingFraction(geom->GetSampling());
+
+    fNbinEta = geom->GetNZ();
+    fNbinPhi = geom->GetNPhi();
+    fPhiMin  = geom->GetArm1PhiMin()*TMath::Pi()/180.;
+    fPhiMax  = geom->GetArm1PhiMax()*TMath::Pi()/180.;
+    fEtaMin  = geom->GetArm1EtaMin();
+    fEtaMax  = geom->GetArm1EtaMax();
+    fDphi    = (fPhiMax-fPhiMin)/fNbinPhi;
+    fDeta    = (fEtaMax-fEtaMin)/fNbinEta;
+    fNtot    = fNbinPhi*fNbinEta;
+    fWeightingMethod = kFALSE;
+
+//
+    SetCellSize(fDeta, fDphi);
+//
+//  I/O
+    if (fOutFileName) fOutFile = new TFile(fOutFileName, "recreate");
+//
+//
+}
+
+void AliEMCALJetFinder::Find(Int_t ncell, Int_t ncelltot, Float_t etc[30000], 
+                            Float_t etac[30000], Float_t phic[30000],
+                            Float_t minmove, Float_t maxmove, Int_t mode, 
+                            Float_t precbg,  Int_t   ierror)
+{
+// Wrapper for fortran coded jet finder
+// Full argument list
+    jet_finder_ua1(ncell, ncelltot, etc, etac, phic, 
+                  minmove, maxmove, mode, precbg, ierror);
+    // Write result to output
+    if(fWrite) WriteJets();
+    fEvent++;
+}
+
+void AliEMCALJetFinder::Find()
+{
+// Wrapper for fortran coded jet finder using member data for 
+// argument list
+
+    Float_t minmove = fMinMove;
+    Float_t maxmove = fMaxMove;
+    Int_t   mode     = fMode;
+    Float_t precbg  = fPrecBg;
+    Int_t   ierror;
+    ResetJets(); // 4-feb-2002 by PAI
+
+    jet_finder_ua1(fNcell, fNtot, fEtCell, fEtaCell, fPhiCell, 
+                  minmove, maxmove, mode, precbg, ierror);
+    fError = ierror;
+    // Write result to output
+    Int_t njet = Njets();
+    
+    for (Int_t nj=0; nj<njet; nj++)
+    {
+       if (fWeightingMethod)
+       {
+          fJetT[nj] = new AliEMCALJet(WeightedJetEnergy( JetEtaW(nj),JetPhiW(nj) ),
+                                      JetPhiW(nj),
+                                      JetEtaW(nj));
+
+       }else{
+               
+       fJetT[nj] = new AliEMCALJet(JetEnergy(nj),
+                                   JetPhiW(nj),
+                                   JetEtaW(nj));
+       }
+        fJetT[nj]->SetIsWeightedEnergy(fWeightingMethod); 
+        fJetT[nj]->SetEMCALEnergy( EMCALConeEnergy(JetEtaW(nj),JetPhiW(nj)) ); 
+        fJetT[nj]->SetTrackEnergy(TrackConeEnergy( JetEtaW(nj),JetPhiW(nj)  )); 
+       
+    }
+
+    FindTracksInJetCone();
+    if(fWrite) WriteJets();
+    fEvent++;
+}
+
+
+Float_t AliEMCALJetFinder::EMCALConeEnergy(Float_t eta, Float_t phi)
+{
+// Calculate the energy in the cone    
+Float_t newenergy = 0.0;
+Float_t bineta,binphi;
+TAxis *x = fhLegoEMCAL->GetXaxis();
+TAxis *y = fhLegoEMCAL->GetYaxis();
+for (Int_t i = 0 ; i < fNbinEta  ; i++) // x coord
+       {
+   for (Int_t j = 0 ; j < fNbinPhi  ; j++)  // y coord
+      {
+         bineta = x->GetBinCenter(i);
+         binphi = y->GetBinCenter(j);
+       if ( (bineta-eta)*(bineta-eta) + (binphi-phi)*(binphi-phi) < fConeRadius*fConeRadius)
+      {
+           newenergy += fhLegoEMCAL->GetBinContent(i,j);
+      }
+    }
+}
+return newenergy;
+}      
+
+Float_t AliEMCALJetFinder::TrackConeEnergy(Float_t eta, Float_t phi)
+{
+// Calculate the track energy in the cone      
+Float_t newenergy = 0.0;
+Float_t bineta,binphi;
+TAxis *x = fhLegoTracks->GetXaxis();
+TAxis *y = fhLegoTracks->GetYaxis();
+for (Int_t i = 0 ; i < fNbinEta  ; i++) // x coord
+   {
+   for (Int_t j = 0 ; j < fNbinPhi  ; j++)  // y coord
+   {
+    bineta = x->GetBinCenter(i);
+    binphi = y->GetBinCenter(j);
+    if ( (bineta-eta)*(bineta-eta) + (binphi-phi)*(binphi-phi) < fConeRadius*fConeRadius)
+      {
+          newenergy += fhLegoTracks->GetBinContent(i,j);
+       }
+    }
+}
+return newenergy;
+}
+
+
+Float_t AliEMCALJetFinder::WeightedJetEnergy(Float_t eta, Float_t phi)
+{
+// Calculate the weighted jet energy
+        
+Float_t newenergy = 0.0;
+Float_t bineta,binphi;
+TAxis *x = fhLegoEMCAL->GetXaxis();
+TAxis *y = fhLegoEMCAL->GetYaxis();
+
+
+for (Int_t i = 0 ; i < fNbinEta  ; i++) // x coord
+{
+   for (Int_t j = 0 ; j < fNbinPhi  ; j++)  // y coord
+   {
+      bineta = x->GetBinCenter(i);
+      binphi = y->GetBinCenter(j);
+      if ( (bineta-eta)*(bineta-eta) + (binphi-phi)*(binphi-phi) < fConeRadius*fConeRadius)
+      {
+          newenergy += (fEMCALWeight)* fhLegoEMCAL->GetBinContent(i,j) + (fTrackWeight)* fhLegoTracks->GetBinContent(i,j);
+      }
+    }
+}
+
+return newenergy;
+
+}
+
+       
+Int_t AliEMCALJetFinder::Njets() const
+{
+// Get number of reconstructed jets
+    return EMCALJETS.njet;
+}
+
+Float_t AliEMCALJetFinder::JetEnergy(Int_t i) const
+{
+// Get reconstructed jet energy
+    return EMCALJETS.etj[i];
+}
+
+Float_t AliEMCALJetFinder::JetPhiL(Int_t i) const
+{
+// Get reconstructed jet phi from leading particle
+    return EMCALJETS.phij[0][i];
+}
+
+Float_t AliEMCALJetFinder::JetPhiW(Int_t i) const
+{
+// Get reconstructed jet phi from weighting
+    return EMCALJETS.phij[1][i];
+}
+
+Float_t  AliEMCALJetFinder::JetEtaL(Int_t i) const
+{
+// Get reconstructed jet eta from leading particles
+    return EMCALJETS.etaj[0][i];
+}
+
+
+Float_t  AliEMCALJetFinder::JetEtaW(Int_t i)  const
+{
+// Get reconstructed jet eta from weighting
+    return EMCALJETS.etaj[1][i];
+}
+
+void AliEMCALJetFinder::SetCellSize(Float_t eta, Float_t phi)
+{
+// Set grid cell size
+    EMCALCELLGEO.etaCellSize = eta;
+    EMCALCELLGEO.phiCellSize = phi;    
+}
+
+void AliEMCALJetFinder::SetConeRadius(Float_t par)
+{
+// Set jet cone radius
+    EMCALJETPARAM.coneRad = par;
+    fConeRadius = par;
+}
+
+void AliEMCALJetFinder::SetEtSeed(Float_t par)
+{
+// Set et cut for seeds
+    EMCALJETPARAM.etSeed = par;
+    fEtSeed = par;
+}
+
+void AliEMCALJetFinder::SetMinJetEt(Float_t par)
+{
+// Set minimum jet et
+    EMCALJETPARAM.ejMin = par;
+    fMinJetEt = par;
+}
+
+void AliEMCALJetFinder::SetMinCellEt(Float_t par)
+{
+// Set et cut per cell
+    EMCALJETPARAM.etMin = par;
+    fMinCellEt = par;
+}
+
+void AliEMCALJetFinder::SetPtCut(Float_t par)
+{
+// Set pT cut on charged tracks
+    fPtCut = par;
+}
+
+
+void AliEMCALJetFinder::Test()
+{
+//
+// Test the finder call
+//
+    const Int_t knmax = 30000;
+    Int_t ncell      = 10;
+    Int_t ncelltot  = 100;
+
+    Float_t etc[knmax];
+    Float_t etac[knmax];
+    Float_t phic[knmax];
+    Float_t minmove = 0;
+    Float_t maxmove = 0;
+    Int_t   mode = 0;
+    Float_t precbg = 0;
+    Int_t   ierror = 0;
+
+    
+    Find(ncell, ncelltot, etc, etac, phic, 
+        minmove, maxmove, mode, precbg, ierror);
+
+}
+
+//
+//  I/O
+//     
+
+void AliEMCALJetFinder::AddJet(const AliEMCALJet& jet)
+{
+    //
+    // Add a jet 
+    //
+    TClonesArray &lrawcl = *fJets;
+    new(lrawcl[fNjets++]) AliEMCALJet(jet);
+}
+
+void AliEMCALJetFinder::ResetJets()
+{
+    //
+    // Reset Jet List 
+    //
+    fJets->Clear();
+    fNjets = 0;
+}
+
+void AliEMCALJetFinder::WriteJets()
+{
+//
+// Add all jets to the list
+//
+    const Int_t kBufferSize = 4000;
+    const char* file = 0;
+
+    Int_t njet = Njets();
+
+    for (Int_t nj = 0; nj < njet; nj++)
+    {
+       AddJet(*fJetT[nj]);
+       delete fJetT[nj];
+    }
+
+// I/O
+    AliRunLoader *rl = AliRunLoader::GetRunLoader();
+    AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
+
+    if (!fOutFileName) {
+//
+// output written to input file
+//
+      AliEMCAL* pEMCAL = (AliEMCAL* )gAlice->GetModule("EMCAL");
+      TTree* pK = rl->TreeK();
+      file = (pK->GetCurrentFile())->GetName();
+      TBranch * jetBranch ;  
+       if (fDebug > 1)
+           printf("Make Branch - TreeR address %p %p\n",(void*)gAlice->TreeR(), (void*)pEMCAL);
+       //if (fJets && gAlice->TreeR()) {
+       if (fJets && emcalLoader->TreeR()) {
+         // pEMCAL->MakeBranchInTree(gAlice->TreeR(), 
+          jetBranch = emcalLoader->TreeR()->Branch("EMCALJets", &fJets, kBufferSize, 0) ; 
+         //pEMCAL->MakeBranchInTree(gime->TreeR(), 
+         //                         "EMCALJets", 
+         //                         &fJets, 
+         //                         kBufferSize, 
+         //                         file);
+         
+         //Int_t nev = gAlice->GetHeader()->GetEvent();
+         //gAlice->TreeR()->Fill();
+         jetBranch->Fill();
+         //char hname[30];
+         //sprintf(hname,"TreeR%d", nev);
+         //gAlice->TreeR()->Write(hname);
+         //gAlice->TreeR()->Reset();
+         //gime->WriteRecPoints("OVERWRITE");
+         emcalLoader->WriteRecPoints("OVERWRITE");
+       }
+    } else {
+//
+// Output written to user specified output file
+//
+      //TTree* pK = gAlice->TreeK();
+      TTree* pK = rl->TreeK();
+      fInFile  = pK->GetCurrentFile();
+
+      fOutFile->cd();
+      char hname[30];
+      sprintf(hname,"TreeR%d", fEvent);
+      TTree* treeJ = new TTree(hname, "EMCALJets");
+      treeJ->Branch("EMCALJets", &fJets, kBufferSize);
+      treeJ->Fill();
+      treeJ->Write(hname);
+      fInFile->cd();
+    }
+    ResetJets();        
+}
+
+void AliEMCALJetFinder::BookLego()
+{
+//
+//  Book histo for discretization
+//
+
+//
+//  Don't add histos to the current directory
+    if(fDebug) printf("\n AliEMCALJetFinder::BookLego() \n");
+    //    TH2::AddDirectory(0); // hists wil be put to the list from gROOT
+    //    TH1::AddDirectory(0);
+    gROOT->cd();
+//    
+//  Signal map
+    fLego = new TH2F("legoH","eta-phi",
+                          fNbinEta, fEtaMin, fEtaMax, 
+                          fNbinPhi, fPhiMin, fPhiMax);
+//
+//  Background map
+    fLegoB = new TH2F("legoB","eta-phi for BG event",
+                          fNbinEta, fEtaMin, fEtaMax, 
+                          fNbinPhi, fPhiMin, fPhiMax);
+
+//  Tracks map
+    fhLegoTracks = new TH2F("hLegoTracks","eta-phi for Tracks",
+    fNbinEta, fEtaMin, fEtaMax, fNbinPhi, fPhiMin, fPhiMax);
+//  EMCAL map
+    fhLegoEMCAL = new TH2F("hLegoEMCAL","eta-phi for EMCAL",
+    fNbinEta, fEtaMin, fEtaMax, fNbinPhi, fPhiMin, fPhiMax);
+//  Hadron correction map
+    fhLegoHadrCorr = new TH2F("hLegoHadrCorr","eta-phi for Hadron. Correction",
+    fNbinEta, fEtaMin, fEtaMax, fNbinPhi, fPhiMin, fPhiMax);
+//  Hists. for tuning jet finder 
+    fhEff = new TH2F("hEff","#epsilon vs momentum ", 100,0.,20., 50,0.5,1.);
+
+    TArrayF eTmp(1101);
+    eTmp[0] = 0.0;
+    for(Int_t i=1; i<=1000; i++)      eTmp[i] = 0.1*i; // step 100 mev
+    for(Int_t i=1001; i<=1100; i++)   eTmp[i] = eTmp[1000] + 1.0*(i-1000); // step 1GeV
+
+    fhCellEt  = new TH1F("hCellEt","Cell E_{T} from fLego", 
+    eTmp.GetSize()-1, eTmp.GetArray()); 
+    fhCellEMCALEt  = new TH1F("hCellEMCALEt","Cell E_{T} for EMCAL itself", 
+    eTmp.GetSize()-1, eTmp.GetArray()); 
+    fhTrackPt = new TH1F("hTrackPt","Ch.particles P_{T} ",
+    eTmp.GetSize()-1, eTmp.GetArray()); 
+    fhTrackPtBcut = new TH1F("hTrackPtBcut","Ch.particles P_{T} + magnetic field cut",
+    eTmp.GetSize()-1, eTmp.GetArray()); 
+
+    fhChPartMultInTpc = new TH1F("hChPartMultInTpc",
+    "Charge partilcle multiplicity in |%eta|<0.9", 2000, 0, 20000);
+
+    fhSinTheta = new TH1F("fhSinTheta","sin(theta)", fNbinEta, fEtaMin, fEtaMax);
+    TAxis *xax = fhSinTheta->GetXaxis();
+    for(Int_t i=1; i<=fNbinEta; i++) {
+      Double_t eta = xax->GetBinCenter(i);
+      fhSinTheta->Fill(eta, 1./TMath::CosH(eta)); // cosh(eta) = 1./sin(theta)
+    }
+    
+    //! first canvas for drawing
+    fHistsList=AliEMCALJetMicroDst::MoveHistsToList("Hists from AliEMCALJetFinder", kFALSE);
+}
+
+void AliEMCALJetFinder::DumpLego()
+{
+//
+// Dump lego histo into array
+//
+    fNcell = 0;
+    TAxis* xaxis = fLego->GetXaxis();
+    TAxis* yaxis = fLego->GetYaxis();
+    //    fhCellEt->Clear();
+    Float_t e, eH;
+    for (Int_t i = 1; i <= fNbinEta; i++) {
+       for (Int_t j = 1; j <= fNbinPhi; j++) {
+           
+           e = fLego->GetBinContent(i,j);
+           if (fRandomBg) {
+               if (gRandom->Rndm() < 0.5) {
+                   Float_t ebg = 0.28 * TMath::Abs(gRandom->Gaus(0.,1.));
+                   e += ebg;
+               }
+           }
+           if (e > 0.0) e -= fMinCellEt;
+           if (e < 0.0) e = 0.;
+           Float_t eta  = xaxis->GetBinCenter(i);
+           Float_t phi  = yaxis->GetBinCenter(j);          
+           fEtCell[fNcell]  = e;
+           fEtaCell[fNcell] = eta;
+           fPhiCell[fNcell] = phi;
+           fNcell++;
+           fhCellEt->Fill(e);
+            if(fhLegoEMCAL) {
+              eH = fhLegoEMCAL->GetBinContent(i,j);
+              if(eH > 0.0) fhCellEMCALEt->Fill(eH);
+            }
+       } // phi
+    } // eta
+//  today
+//    fNcell--;
+}
+
+void AliEMCALJetFinder::ResetMap()
+{
+//
+// Reset eta-phi array
+
+    for (Int_t i=0; i<30000; i++)
+    {
+       fEtCell[i]  = 0.;
+       fEtaCell[i] = 0.;
+       fPhiCell[i] = 0.;
+    }
+}
+
+
+void AliEMCALJetFinder::FillFromTracks(Int_t flag, Int_t ich)
+{
+// Which generator
+//
+    const char* name = gAlice->Generator()->GetName();
+    enum {kPythia, kHijing, kHijingPara};
+    Int_t genType = 0;
+    
+    if (!strcmp(name, "Hijing")){
+       genType = kHijing;
+    } else if (!strcmp(name, "Pythia")) {
+       genType = kPythia;
+    } else if (!strcmp(name, "HIJINGpara") ||!strcmp(name, "HIGINGpara")) {
+       genType = kHijingPara;
+    }
+    if (fDebug>=2) 
+       printf("Fill tracks generated by %s %d\n", name, genType);
+        
+           
+//
+// Fill Cells with track information
+//
+    if (fDebug >= 2)
+    printf("\n AliEMCALJetFinder::FillFromTracks(%i,%i) ",flag,ich);
+    fNChTpc = 0;
+
+    ResetMap();
+    
+    if (!fLego) BookLego();
+// Reset
+    if (flag == 0) fLego->Reset();
+//
+// Access particle information    
+    Int_t npart = (gAlice->GetHeader())->GetNprimary();
+    Int_t ntr   = (gAlice->GetHeader())->GetNtrack();
+    printf(" : #primary particles %i # tracks %i : (before) Sum.Et %f\n", 
+    npart, ntr, fLego->Integral());
+// Create track list
+//
+// 0: not selected
+// 1: selected for jet finding
+// 2: inside jet
+// ....
+    if (fTrackList) delete[] fTrackList;
+    if (fPtT)       delete[] fPtT;
+    if (fEtaT)      delete[] fEtaT;
+    if (fPhiT)      delete[] fPhiT;
+    if (fPdgT)      delete[] fPdgT;
+    
+    fTrackList = new Int_t  [npart];
+    fPtT       = new Float_t[npart];
+    fEtaT      = new Float_t[npart];
+    fPhiT      = new Float_t[npart];
+    fPdgT      = new Int_t[npart];
+
+    fNt   = npart;
+    fNtS  = 0;
+    Float_t chTmp=0.0; // charge of current particle 
+    //    Int_t idGeant;
+
+    // this is for Pythia ??
+    for (Int_t part = 0; part < npart; part++) {
+       TParticle *mPart = gAlice->GetMCApp()->Particle(part);
+       Int_t mpart   = mPart->GetPdgCode();
+       Int_t child1  = mPart->GetFirstDaughter();
+       Float_t pT    = mPart->Pt();
+       Float_t p     = mPart->P();
+       Float_t phi   = mPart->Phi();
+       Float_t eta   = -100.;
+       if(pT > 0.001) eta   = mPart->Eta();
+       Float_t theta = mPart->Theta(); 
+        if  (fDebug>=2 && mPart->GetStatusCode()==1) { 
+          printf("ind %7i part %7i -> child1 %5i child2 %5i Status %5i\n", 
+           part, mpart, child1, mPart->GetLastDaughter(), mPart->GetStatusCode());
+        }
+       
+       if (fDebug >= 2 && genType == kPythia) {
+           if (part == 6 || part == 7)
+           {
+               printf("\n Simulated Jet (pt, eta, phi): %d %f %f %f\n", 
+                      part-5, pT, eta, phi);
+           }
+       }
+       
+       fTrackList[part] = 0; 
+       fPtT[part]       = pT; // must be change after correction for resolution !!!
+       fEtaT[part]      = eta;
+       fPhiT[part]      = phi;
+       fPdgT[part]      = mpart;
+       
+//     final state particles only
+
+       if (genType == kPythia) {
+           if (mPart->GetStatusCode() != 1) continue;
+       } else if (genType == kHijing) {
+           if (child1 >= 0 && child1 < npart) continue;
+       }
+       
+       
+       TParticlePDG* pdgP = 0;
+// charged or neutral 
+       pdgP  = mPart->GetPDG();
+        chTmp = pdgP->Charge() / 3.; // 13-feb-2001!!  
+
+       if (ich == 0) {
+           if (chTmp == 0) {
+               if (!fK0N) { 
+                   continue;
+               } else {
+                   if (mpart != kNeutron    &&
+                       mpart != kNeutronBar &&
+                       mpart != kK0Long) continue;
+               }
+           }
+       } else if (ich == 2) {
+         if (mpart == kNeutron    ||
+             mpart == kNeutronBar ||
+             mpart == kK0Long) continue;
+       }
+
+       if (TMath::Abs(eta)<=0.9) fNChTpc++;
+// final state only
+       if (child1 >= 0 && child1 < npart) continue;
+// acceptance cut
+       if (eta > fEtaMax || eta < fEtaMin)    continue;
+       if (phi > fPhiMax || phi < fPhiMin )   continue;
+//
+       if (fDebug >= 3) 
+       printf("\n=>nsel:%5d mpart %5d child1 %5d eta %6.2f phi %6.2f pT %6.2f ch %3.0f ",
+       part, mpart, child1, eta, phi, pT, chTmp);
+//
+//
+// Momentum smearing goes here ...
+//
+        fhTrackPt->Fill(pT);
+        Float_t pw;
+       if (fSmear && TMath::Abs(chTmp)) {
+           pw = AliEMCALFast::SmearMomentum(1,p);
+           // p changed - take into account when calculate pT,
+           // pz and so on ..  ?
+            pT = (pw/p) * pT;
+            if(fDebug >= 4) printf("\n Smearing : p %8.4f change to %8.4f ", p, pw);
+            p  = pw;
+       }
+//
+// Tracking Efficiency and TPC acceptance goes here ...
+       Float_t eff;
+       if (fEffic && TMath::Abs(chTmp)) {
+           eff = 0.9; //  AliEMCALFast::Efficiency(2,p);
+            if(fhEff) fhEff->Fill(p, eff);
+           if (AliEMCALFast::RandomReject(eff)) {
+               if(fDebug >= 5) printf(" reject due to unefficiency ");
+               continue;
+            }
+       }
+//
+// Correction of Hadronic Energy goes here ...
+//
+//
+// phi propagation for hadronic correction
+
+       Bool_t curls = kFALSE; // hit two the EMCAL (no curl)
+       Float_t phiHC=0.0, dpH=0.0, dphi=0.0, eTdpH=0;
+        if(TMath::Abs(chTmp)) {
+           // hadr. correction only for charge particle 
+           dphi  = PropagatePhi(pT, chTmp, curls);
+           phiHC = phi + dphi;
+           if (fDebug >= 6) {
+               printf("\n Delta phi %f pT %f ", dphi, pT);
+               if (curls) printf("\n !! Track is curling");
+           }
+           if(!curls) fhTrackPtBcut->Fill(pT);
+           
+           if (fHCorrection && !curls) {
+               if (!fHadronCorrector)
+                   Fatal("AliEMCALJetFinder",
+                         "Hadronic energy correction required but not defined !");
+               
+               dpH    = fHadronCorrector->GetEnergy(p, eta, 7);
+               eTdpH  = dpH*TMath::Sin(theta);
+               
+               if (fDebug >= 7) printf(" phi %f phiHC %f eTcorr %f\n", 
+                                       phi, phiHC, -eTdpH); // correction is negative
+               Int_t xbin,ybin;
+               xbin = fLego->GetXaxis()->FindBin(eta);
+               ybin = fLego->GetYaxis()->FindBin(phiHC);
+               cout <<"Hadron Correction affected bin - contents before correction : "<<fLego->GetBinContent(xbin,ybin)<<endl;
+               fLego->Fill(eta, phi, -fSamplingF*eTdpH );
+               cout <<"Hadron Correction affected bin - contents after  correction : "<<fLego->GetBinContent(xbin,ybin)<<endl;
+               fhLegoHadrCorr->Fill(eta, phi, fSamplingF*eTdpH);
+           }
+        }
+//
+//  More to do ? Just think about it !
+//
+       if (phi > fPhiMax || phi < fPhiMin )   continue;
+
+        if(TMath::Abs(chTmp) ) { // charge particle
+           if (pT > fPtCut && !curls) {
+               if (fDebug >= 8) printf("Charge :  fLego->Fill(%5.2f, %5.2f, %6.2f, %d)\n",
+                                       eta , phi, pT, fNtS); 
+               fLego->Fill(eta, phi, pT);
+               fhLegoTracks->Fill(eta, phi, pT); // 20-feb for checking
+               fTrackList[part] = 1;
+               fNtS++;
+           }
+       } else if(ich > 0 || fK0N) {
+           // case of n, nbar and K0L
+           if (fDebug >= 9) printf("Neutral :  fLego->Fill(%5.2f, %5.2f, %6.2f, %d)\n",
+                                   eta , phi, pT, fNtS); 
+            fLego->Fill(eta, phi, pT);
+           fTrackList[part] = 1;
+           fNtS++;
+        }
+    } // primary loop    
+    Float_t etsum = 0.;
+    for(Int_t i=0; i<fLego->GetSize(); i++) {
+       Float_t etc =  (*fLego)[i];
+       if (etc > fMinCellEt) etsum += etc;
+    }
+    
+    printf("FillFromTracks: Sum above threshold %f -> %f (%f)\n", fMinCellEt, etsum, fLego->Integral());
+    printf("                Track selected(fNtS) %i \n", fNtS);
+
+    DumpLego();
+}
+
+void AliEMCALJetFinder::FillFromHits(Int_t flag)
+{
+//
+// Fill Cells with hit information
+//
+//
+    if (fDebug >= 2)
+    printf("\n AliEMCALJetFinder::FillFromHits(%i)\n",flag);
+
+    ResetMap();
+    
+    if (!fLego) BookLego();
+//  Reset eta-phi maps if needed
+    if (flag == 0) { // default behavior
+      fLego->Reset();
+      fhLegoTracks->Reset();
+      fhLegoEMCAL->Reset();
+      fhLegoHadrCorr->Reset();
+    }
+//  Initialize from background event if available
+//
+// Access hit information    
+    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
+    AliLoader *emcalLoader = AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL");
+    TTree *treeH = emcalLoader->TreeH();
+    Int_t ntracks = (Int_t) treeH->GetEntries();
+//
+//   Loop over tracks
+//
+    Int_t nbytes = 0;
+    //    Double_t etH = 0.0;
+
+    for (Int_t track=0; track<ntracks;track++) {
+       gAlice->ResetHits();
+       nbytes += treeH->GetEvent(track);
+//
+//  Loop over hits
+//
+       for(AliEMCALHit* mHit=(AliEMCALHit*) pEMCAL->FirstHit(-1); 
+           mHit;
+           mHit=(AliEMCALHit*) pEMCAL->NextHit()) 
+       {
+           Float_t x      =    mHit->X();         // x-pos of hit
+           Float_t y      =    mHit->Y();         // y-pos
+           Float_t z      =    mHit->Z();         // z-pos
+           Float_t eloss  =    mHit->GetEnergy(); // deposited energy
+
+           Float_t r      =    TMath::Sqrt(x*x+y*y);
+           Float_t theta  =    TMath::ATan2(r,z);
+           Float_t eta    =   -TMath::Log(TMath::Tan(theta/2.));
+           Float_t phi    =    TMath::ATan2(y,x);
+
+           if (fDebug >= 21) printf("\n Hit %f %f %f %f %f %f %f %f", x, y, z, eloss, r, eta, phi, fSamplingF);
+           
+           //            etH = fSamplingF*eloss*TMath::Sin(theta);
+           fLego->Fill(eta, phi, eloss);
+       } // Hit Loop
+    } // Track Loop
+
+    // Transition from deposit energy to eT (eT = de*SF*sin(theta))
+    Double_t etsum = 0;    
+    for(Int_t i=1; i<=fLego->GetNbinsX(); i++){   // eta
+       Double_t sinTheta = fhSinTheta->GetBinContent(i), eT=0;
+       for(Int_t j=1; j<=fLego->GetNbinsY(); j++){ // phi
+         eT = fLego->GetBinContent(i,j)*fSamplingF*sinTheta;
+         fLego->SetBinContent(i,j,eT);
+    // copy content of fLego to fhLegoEMCAL (fLego and fhLegoEMCAL are identical)    
+          fhLegoEMCAL->SetBinContent(i,j,eT);
+         if (eT > fMinCellEt) etsum += eT;
+       }
+    }
+
+    //    for(Int_t i=0; i<fLego->GetSize(); i++) {
+    // (*fhLegoEMCAL)[i] = (*fLego)[i];
+    // Float_t etc =  (*fLego)[i];
+    // if (etc > fMinCellEt) etsum += etc;
+    //    }
+    
+    printf("FillFromHits: Sum above threshold %f -> %f \n ", fMinCellEt, etsum);
+    //    DumpLego(); ??
+}
+
+void AliEMCALJetFinder::FillFromDigits(Int_t flag)
+{
+//
+// Fill Cells with digit information
+//
+//
+    ResetMap();
+    
+    if (!fLego) BookLego();
+    if (flag == 0) fLego->Reset();
+    Int_t nbytes=0;
+    
+
+//
+//  Connect digits    
+//
+    TClonesArray* digs      = new TClonesArray("AliEMCALDigit", 10000);
+    TTree *treeD = gAlice->TreeD();
+    TBranchElement* branchDg = (TBranchElement*)
+       treeD->GetBranch("EMCAL");
+
+    if (!branchDg) Fatal("AliEMCALJetFinder", 
+                        "Reading digits requested but no digits in file !");
+    
+    branchDg->SetAddress(&digs);
+    Int_t nent = (Int_t) branchDg->GetEntries();
+//
+//  Connect digitizer
+//
+    AliEMCALDigitizer* digr = new AliEMCALDigitizer();
+    TBranchElement* branchDr = (TBranchElement*) 
+       treeD->GetBranch("AliEMCALDigitizer");
+    branchDr->SetAddress(&digr);
+//
+//
+    nbytes += branchDg->GetEntry(0);
+    nbytes += branchDr->GetEntry(0);
+//
+//  Get digitizer parameters
+    Float_t ecADCped  = digr->GetECApedestal();
+    Float_t ecADCcha  = digr->GetECAchannel();
+
+    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
+    AliEMCALGeometry* geom = 
+       AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
+    
+    if (fDebug) {
+       Int_t   ndig = digs->GetEntries();
+               Info("FillFromDigits","Number of Digits: %d %d\n Parameters: EC: %f %f\n Geometry: %d %d", 
+            ndig, nent, ecADCped, ecADCcha, geom->GetNEta(), geom->GetNPhi());
+    }
+    
+//
+//  Loop over digits
+    AliEMCALDigit* sdg;
+    TIter next(digs);
+    while ((sdg = (AliEMCALDigit*)(next())))
+    {
+       Double_t pedestal = 0.;
+       Double_t channel  = 0.;
+       if (geom->IsInECA(sdg->GetId()))  {
+         pedestal = ecADCped;
+         channel  = ecADCcha; 
+               }
+       else 
+         Fatal("FillFromDigits", "unexpected digit is number!") ; 
+       
+       Float_t eta = sdg->GetEta();
+       Float_t phi = sdg->GetPhi() * TMath::Pi()/180.;
+       Float_t amp = (Float_t) (channel*(sdg->GetAmp())-pedestal);
+       
+       if (fDebug > 1) 
+         Info("FillFromDigits", "Digit: eta %8.3f phi %8.3f amp %8.3f %8d",
+                          eta, phi, amp, sdg->GetAmp());
+       
+       fLego->Fill(eta, phi, fSamplingF*amp);
+    } // digit loop
+// 
+//  Dump lego hist
+    DumpLego();
+}
+
+
+void AliEMCALJetFinder::FillFromHitFlaggedTracks(Int_t flag)
+{
+//
+// Fill Cells with hit information
+//
+//
+    ResetMap();
+    
+    if (!fLego) BookLego();
+// Reset
+    if (flag == 0) fLego->Reset();
+
+// Flag charged tracks passing through TPC which 
+// are associated to EMCAL Hits
+    BuildTrackFlagTable();
+
+//
+// Access particle information    
+    TTree *treeK = gAlice->TreeK();
+    Int_t ntracks = (Int_t) treeK->GetEntries();
+
+    if (fPtT)       delete[] fPtT;   
+    if (fEtaT)      delete[] fEtaT;    
+    if (fPhiT)      delete[] fPhiT;   
+    if (fPdgT)      delete[] fPdgT;   
+   
+    fPtT       = new Float_t[ntracks];
+    fEtaT      = new Float_t[ntracks];
+    fPhiT      = new Float_t[ntracks];
+    fPdgT      = new Int_t[ntracks];
+
+    fNt   = ntracks;
+    fNtS  = 0;
+    
+    for (Int_t track = 0; track < ntracks; track++) {
+         TParticle *mPart = gAlice->GetMCApp()->Particle(track);
+         Float_t pT    = mPart->Pt();
+         Float_t phi   = mPart->Phi();
+         Float_t eta   = mPart->Eta();
+
+       if(fTrackList[track]) {
+         fPtT[track]       = pT;
+         fEtaT[track]      = eta;
+         fPhiT[track]      = phi;
+         fPdgT[track]      = mPart->GetPdgCode();
+         
+         if (track < 2) continue;      //Colliding particles?
+         if (pT == 0 || pT < fPtCut) continue;
+         fNtS++;
+         fLego->Fill(eta, phi, pT);
+       }
+      } // track loop
+    DumpLego();
+}
+
+void AliEMCALJetFinder::FillFromParticles()
+{
+// 26-feb-2002 PAI - for checking all chain
+// Work on particles level; accept all particle (not neutrino )
+    
+    Double_t pX=0, pY=0, pZ=0, energy=0; // checking conservation law 
+    fNChTpc = 0;
+
+    ResetMap();
+    if (!fLego) BookLego();
+    fLego->Reset();
+//
+// Access particles information    
+    Int_t npart = (gAlice->GetHeader())->GetNprimary();
+    if (fDebug >= 2 || npart<=0) {
+       printf(" AliEMCALJetFinder::FillFromParticles : npart %i\n", npart);
+       if(npart<=0) return;
+    }
+    fNt   = npart;
+    fNtS  = 0;
+    RearrangeParticlesMemory(npart);
+//  Go through the particles
+    Int_t mpart, child1, child2, geantPdg;
+    Float_t pT, phi, eta, e=0, px=0, py=0, pz=0;
+    TParticle *mPart=0;
+    for (Int_t part = 0; part < npart; part++) {
+
+       fTrackList[part] = 0;
+
+       mPart   = gAlice->GetMCApp()->Particle(part);
+       mpart   = mPart->GetPdgCode();
+       child1  = mPart->GetFirstDaughter();
+       child2  = mPart->GetLastDaughter();
+       pT      = mPart->Pt();
+       phi     = mPart->Phi();
+       eta     = mPart->Eta();
+
+        px      = mPart->Px();
+        py      = mPart->Py();
+        pz      = mPart->Pz();
+        e       = mPart->Energy();
+
+// see pyedit in Pythia's text
+        geantPdg = mpart;
+       if (IsThisPartonsOrDiQuark(mpart)) continue;
+        printf("%5i: %5i(%2i) px %5.1f py %5.1f pz %6.1f e %6.1f childs %5i,%5i \n", 
+        part, mpart, geantPdg, px, py, pz, e, child1, child2);
+       
+//  exclude partons (21 - gluon, 92 - string) 
+       
+
+// exclude neutrinous also ??
+       if (fDebug >= 11 && pT>0.01) 
+       printf("\n part:%5d mpart %5d eta %9.2f phi %9.2f pT %9.2f ",
+       part, mpart, eta, phi, pT);
+
+       fPtT[part]       = pT;
+       fEtaT[part]      = eta;
+       fPhiT[part]      = phi;
+       fPdgT[part]      = mpart;
+       fNtS++;
+       
+// final state only
+       if (child1 >= 0 && child1 < npart) continue;
+
+       //        printf("%4i -> %5i(%3i) px %6.1f py %6.1f pz %7.1f e %8.2f child1 %5i %s\n", 
+       //        part, mpart, geantPdg, px, py, pz, e, child1, name.Data());
+        pX += px; 
+        pY += py; 
+        pZ += pz;
+        energy  += e; 
+
+        
+       if (TMath::Abs(eta) <= 0.9) fNChTpc++;
+// acceptance cut
+       if (eta > fEtaMax || eta < fEtaMin)    continue;
+       if (phi > fPhiMax || phi < fPhiMin )   continue;
+//
+        if(fK0N==0 ) { // exclude neutral hadrons
+          if (mpart == kNeutron || mpart == kNeutronBar || mpart == kK0Long) continue; 
+        }
+       fTrackList[part] = 1;
+        fLego->Fill(eta, phi, pT);
+
+    } // primary loop
+    printf("\n                PX %8.2f  PY %8.2f  PZ %8.2f  E %8.2f \n", 
+    pX, pY, pZ, energy);
+    DumpLego();
+    if(fhChPartMultInTpc) fhChPartMultInTpc->Fill(fNChTpc);
+}
+
+void AliEMCALJetFinder::FillFromPartons()
+{
+// function under construction - 13-feb-2002 PAI
+    
+    if (fDebug >= 2)
+    printf("\n AliEMCALJetFinder::FillFromPartons()\n");
+    // 
+
+    ResetMap();
+    if (!fLego) BookLego();
+    fLego->Reset();
+//
+// Access particle information    
+    Int_t npart = (gAlice->GetHeader())->GetNprimary();
+    if (fDebug >= 2 || npart<=0)
+    printf("\n AliEMCALJetFinder::FillFromPartons : npart %i\n", npart);
+    fNt   = 0; // for FindTracksInJetCone
+    fNtS  = 0;
+//  Go through the partons
+    Int_t statusCode=0;
+    for (Int_t part = 8; part < npart; part++) {
+       TParticle *mPart = gAlice->GetMCApp()->Particle(part);
+       Int_t mpart   = mPart->GetPdgCode();
+       //      Int_t child1  = MPart->GetFirstDaughter();
+       Float_t pT    = mPart->Pt();
+       //      Float_t p     = MPart->P();
+       Float_t phi   = mPart->Phi();
+       Float_t eta   = mPart->Eta();
+       //      Float_t theta = MPart->Theta();
+        statusCode    = mPart->GetStatusCode();
+       
+// accept partons (21 - gluon, 92 - string) 
+       if (!(TMath::Abs(mpart) <= 6 || mpart == 21 ||mpart == 92)) continue;
+       if (fDebug > 1 && pT>0.01) 
+       printf("\n part:%5d mpart %5d status  %5d eta %8.2f phi %8.2f pT %8.2f ",
+       part, mpart, statusCode, eta, phi, pT);
+       //      if (fDebug >= 3) MPart->Print(); 
+// accept partons before fragmentation - p.57 in Pythia manual
+//        if(statusCode != 1) continue;
+// acceptance cut
+       if (eta > fEtaMax || eta < fEtaMin)    continue;
+       if (phi > fPhiMax || phi < fPhiMin )   continue;
+// final state only
+//     if (child1 >= 0 && child1 < npart) continue;
+//
+//
+        fLego->Fill(eta, phi, pT);
+
+    } // primary loop
+    DumpLego();
+}
+
+void AliEMCALJetFinder::BuildTrackFlagTable() {
+
+// Method to generate a lookup table for TreeK particles
+// which are linked to hits in the EMCAL
+//
+// --Author: J.L. Klay
+//
+// Access hit information    
+    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
+    
+    TTree *treeK = gAlice->TreeK();            // Get the number of entries in the kine tree
+    Int_t nKTrks = (Int_t) treeK->GetEntries();        // (Number of particles created somewhere)
+    
+    if(fTrackList) delete[] fTrackList;                //Make sure we get rid of the old one
+    fTrackList = new Int_t[nKTrks];            //before generating a new one
+    
+    for (Int_t i = 0; i < nKTrks; i++) {       //Initialize members to 0
+       fTrackList[i] = 0;
+    }
+
+    AliLoader *emcalLoader = AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL");
+    //AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
+    // TTree *treeH = gAlice->TreeH();
+    TTree *treeH = emcalLoader->TreeH();
+   Int_t ntracks = (Int_t) treeH->GetEntries();
+//
+//   Loop over tracks
+//
+    Int_t nbytes = 0;
+    
+    for (Int_t track=0; track<ntracks;track++) {
+       gAlice->ResetHits();
+       nbytes += treeH->GetEvent(track);
+        if (pEMCAL)  {
+           
+//
+//  Loop over hits
+//
+           for(AliEMCALHit* mHit=(AliEMCALHit*) pEMCAL->FirstHit(-1); 
+               mHit;
+               mHit=(AliEMCALHit*) pEMCAL->NextHit()) 
+           {
+               Int_t   iTrk   =    mHit->Track();       // track number
+               Int_t   idprim =    mHit->GetPrimary();  // primary particle
+               
+               //Determine the origin point of this particle - it made a hit in the EMCAL
+               TParticle         *trkPart = gAlice->GetMCApp()->Particle(iTrk);
+               TParticlePDG  *trkPdg  = trkPart->GetPDG();
+               Int_t      trkCode = trkPart->GetPdgCode();
+               Double_t           trkChg;
+               if (trkCode < 10000) {          //Big Ions cause problems for 
+                   trkChg  = trkPdg->Charge(); //this function.  Since they aren't
+               } else {                                //likely to make it very far, set
+                   trkChg  = 0.0;                      //their charge to 0 for the Flag test
+               }
+               Float_t            vxTrk   = trkPart->Vx();
+               Float_t            vyTrk   = trkPart->Vy();
+               Float_t            vrTrk   = TMath::Sqrt(vxTrk*vxTrk+vyTrk*vyTrk); 
+               fTrackList[iTrk] = SetTrackFlag(vrTrk,trkCode,trkChg);
+               
+               //Loop through the ancestry of the EMCAL entrance particles
+               Int_t ancestor = trkPart->GetFirstMother();  //Get track's Mother
+               while (ancestor != -1) {
+                   TParticle     *ancPart = gAlice->GetMCApp()->Particle(ancestor);  //get particle info on ancestor
+                   TParticlePDG  *ancPdg  = ancPart->GetPDG();
+                   Int_t             ancCode = ancPart->GetPdgCode();
+                   Double_t       ancChg;
+                   if (ancCode < 10000) {
+                       ancChg  = ancPdg->Charge();
+                   } else {
+                       ancChg  = 0.0;
+                   }
+                   Float_t           vxAnc   = ancPart->Vx();
+                   Float_t           vyAnc   = ancPart->Vy();
+                   Float_t           vrAnc   = TMath::Sqrt(vxAnc*vxAnc+vyAnc*vyAnc);
+                   fTrackList[ancestor] = SetTrackFlag(vrAnc,ancCode,ancChg);
+                   ancestor = ancPart->GetFirstMother();           //Get the next ancestor
+               }
+               
+               //Determine the origin point of the primary particle associated with the hit
+               TParticle     *primPart = gAlice->GetMCApp()->Particle(idprim);
+               TParticlePDG  *primPdg  = primPart->GetPDG();
+               Int_t      primCode = primPart->GetPdgCode();
+               Double_t           primChg;
+               if (primCode < 10000) {
+                   primChg  = primPdg->Charge();
+               } else {
+                   primChg  = 0.0;
+               }
+               Float_t    vxPrim = primPart->Vx();
+               Float_t    vyPrim = primPart->Vy();
+               Float_t    vrPrim = TMath::Sqrt(vxPrim*vxPrim+vyPrim*vyPrim);
+               fTrackList[idprim] = SetTrackFlag(vrPrim,primCode,primChg);
+           } // Hit Loop
+       } //if (pEMCAL)
+    } // Track Loop
+}
+
+Int_t AliEMCALJetFinder
+::SetTrackFlag(Float_t radius, Int_t code, Double_t charge) {
+// Set the flag for the track
+    Int_t flag    = 0; 
+    Int_t parton  = 0; 
+    Int_t neutral = 0;
+    
+    if (charge == 0) neutral = 1;
+    
+    if (TMath::Abs(code) <= 6   ||     
+       code == 21              ||   
+       code == 92) parton = 1;
+    
+    //It's not a parton, it's charged and it went through the TPC
+    if (!parton && !neutral && radius <= 84.0) flag = 1;
+    
+    return flag;
+}
+
+
+
+void AliEMCALJetFinder::SaveBackgroundEvent(const char *name)
+{
+// Saves the eta-phi lego and the tracklist and name of file with BG events
+//
+    if (fLegoB) {
+       fLegoB->Reset();
+       (*fLegoB) = (*fLegoB) + (*fLego); 
+       //       if(fDebug) 
+       printf("\n AliEMCALJetFinder::SaveBackgroundEvent() (fLegoB) %f = %f(fLego) \n", 
+       fLegoB->Integral(), fLego->Integral()); 
+    }
+    
+    if (fPtB)        delete[] fPtB;   
+    if (fEtaB)       delete[] fEtaB;    
+    if (fPhiB)       delete[] fPhiB;   
+    if (fPdgB)       delete[] fPdgB;   
+    if (fTrackListB) delete[] fTrackListB;   
+   
+    fPtB          = new Float_t[fNtS];
+    fEtaB         = new Float_t[fNtS];
+    fPhiB         = new Float_t[fNtS];
+    fPdgB         = new Int_t  [fNtS];
+    fTrackListB   = new Int_t  [fNtS];
+    
+    fNtB = 0;
+    
+    for (Int_t i = 0; i < fNt; i++) {
+       if (!fTrackList[i]) continue;
+       fPtB [fNtB]       = fPtT [i];
+       fEtaB[fNtB]       = fEtaT[i];
+       fPhiB[fNtB]       = fPhiT[i];
+       fPdgB[fNtB]       = fPdgT[i];
+       fTrackListB[fNtB] = 1;
+       fNtB++;
+    }
+    fBackground = 1;
+    printf(" fNtB %i => fNtS %i #particles %i \n", fNtB, fNtS, fNt);
+
+    if(strlen(name) == 0) {
+       TSeqCollection *li = gROOT->GetListOfFiles();
+       TString nf;
+       for(Int_t i=0; i<li->GetSize(); i++) {
+          nf = ((TFile*)li->At(i))->GetName();
+          if(nf.Contains("backgorund")) break;
+       }
+       fBGFileName = nf;
+    } else {
+       fBGFileName = name;
+    }
+    printf("BG file name is \n %s\n", fBGFileName.Data());
+}
+
+void AliEMCALJetFinder::InitFromBackground()
+{
+//
+//    
+    if (fDebug) printf("\n AliEMCALJetFinder::InitFromBackground() ");
+    
+    if (fLego) {
+       fLego->Reset(); 
+       (*fLego) = (*fLego) + (*fLegoB);
+       if(fDebug) 
+           printf("\n AliEMCALJetFinder::InitBackgroundEvent() (fLego) %f = %f(fLegoB) \n", 
+                  fLego->Integral(), fLegoB->Integral()); 
+    } else {
+       printf(" => fLego undefined \n");
+    }
+}
+
+    
+void AliEMCALJetFinder::FindTracksInJetCone()
+{
+//
+//  Build list of tracks inside jet cone
+//
+//  Loop over jets
+    Int_t njet = Njets();
+    for (Int_t nj = 0; nj < njet; nj++)
+    {
+       Float_t etaj = JetEtaW(nj);
+       Float_t phij = JetPhiW(nj);     
+       Int_t   nT   = 0;           // number of associated tracks
+       
+// Loop over particles in current event 
+       for (Int_t part = 0; part < fNt; part++) {
+           if (!fTrackList[part]) continue;
+           Float_t phi      = fPhiT[part];
+           Float_t eta      = fEtaT[part];
+           Float_t dr       = TMath::Sqrt((etaj-eta)*(etaj-eta) +
+                                          (phij-phi)*(phij-phi));
+           if (dr < fConeRadius) {
+               fTrackList[part] = nj+2;
+               nT++;
+           } // < ConeRadius ?
+       } // particle loop
+       
+// Same for background event if available
+       Int_t nTB = 0;
+       if (fBackground) {
+           for (Int_t part = 0; part < fNtB; part++) {
+               Float_t phi      = fPhiB[part];
+               Float_t eta      = fEtaB[part];
+               Float_t dr       = TMath::Sqrt((etaj-eta)*(etaj-eta) +
+                                              (phij-phi)*(phij-phi));
+               fTrackListB[part] = 1;
+
+               if (dr < fConeRadius) {
+                   fTrackListB[part] = nj+2;
+                   nTB++;
+               } // < ConeRadius ?
+           } // particle loop
+       } // Background available ?
+       
+       Int_t nT0 = nT + nTB;
+       printf("Total number of tracks %d\n", nT0);
+       
+       if (nT0 > 1000) nT0 = 1000;
+       
+       Float_t* ptT  = new Float_t[nT0];
+       Float_t* etaT = new Float_t[nT0];
+       Float_t* phiT = new Float_t[nT0];
+       Int_t*   pdgT = new Int_t[nT0];
+
+       Int_t iT = 0;
+       Int_t j;
+       
+       for (Int_t part = 0; part < fNt; part++) {
+           if (fTrackList[part] == nj+2) {
+               Int_t index = 0;
+               for (j=iT-1; j>=0; j--) {
+                   if (fPtT[part] > ptT[j]) {
+                       index = j+1;
+                       break;
+                   }
+               }
+               for (j=iT-1; j>=index; j--) {
+                   ptT [j+1]  = ptT [j];
+                   etaT[j+1]  = etaT[j];
+                   phiT[j+1]  = phiT[j];
+                   pdgT[j+1]  = pdgT[j];
+               }
+               ptT [index] = fPtT [part];
+               etaT[index] = fEtaT[part];
+               phiT[index] = fPhiT[part];
+               pdgT[index] = fPdgT[part];
+               iT++;
+           } // particle associated
+           if (iT > nT0) break;
+       } // particle loop
+       
+       if (fBackground) {
+           for (Int_t part = 0; part < fNtB; part++) {
+               if (fTrackListB[part] == nj+2) {
+                   Int_t index = 0;
+                   for (j=iT-1; j>=0; j--) {
+                       if (fPtB[part] > ptT[j]) {
+                           index = j+1;
+
+                           break;
+                       }
+                   }
+                   for (j=iT-1; j>=index; j--) {
+                       ptT [j+1]  = ptT [j];
+                       etaT[j+1]  = etaT[j];
+                       phiT[j+1]  = phiT[j];
+                       pdgT[j+1]  = pdgT[j];
+                   }
+                   ptT [index] = fPtB [part];
+                   etaT[index] = fEtaB[part];
+                   phiT[index] = fPhiB[part];
+                   pdgT[index] = fPdgB[part];
+                   iT++;
+               } // particle associated
+               if (iT > nT0) break;
+           } // particle loop
+       } // Background available ?
+
+       fJetT[nj]->SetTrackList(nT0, ptT, etaT, phiT, pdgT);
+       delete[] ptT;
+       delete[] etaT;
+       delete[] phiT;
+       delete[] pdgT;
+       
+    } // jet loop loop
+}
+
+Float_t AliEMCALJetFinder::PropagatePhi(Float_t pt, Float_t charge, Bool_t& curls)
+{
+// Propagates phi angle to EMCAL radius
+//
+  static Float_t b = 0.0, rEMCAL = -1.0;
+// Get field in kGS
+  b = gAlice->Field()->SolenoidField();
+// Get EMCAL radius in cm 
+  rEMCAL = AliEMCALGeometry::GetInstance()->GetIPDistance();
+  Float_t dPhi = 0.;
+//
+//
+// bending radies
+// pt [Gev]
+// B  [kG]
+//
+    Float_t rB = 3335.6 * pt / b;  // [cm]  (case of |charge|=1)
+//
+// check if particle is curling below EMCAL
+    if (2.*rB < rEMCAL) {
+       curls = kTRUE;
+       return dPhi;
+    }
+//
+// if not calculate delta phi
+    Float_t phi = TMath::ACos(1.-rEMCAL*rEMCAL/(2.*rB*rB));
+    dPhi = TMath::ATan2(1.-TMath::Cos(phi), TMath::Sin(phi));
+    dPhi = -TMath::Sign(dPhi, charge);
+//    
+    return dPhi;
+}
+
+void hf1(Int_t& , Float_t& , Float_t& )
+{
+// dummy for hbook calls
+    ;
+}
+
+void AliEMCALJetFinder::DrawLego(const char *opt) 
+{
+// Draw lego
+       if(fLego) fLego->Draw(opt);
+}
+
+void  AliEMCALJetFinder::DrawLegoBackground(const char *opt) 
+{
+// Draw background lego
+       if(fLegoB) fLegoB->Draw(opt);
+}
+
+void AliEMCALJetFinder::DrawLegoEMCAL(const char *opt) 
+{
+// Draw EMCAL Lego
+       if(fhLegoEMCAL) fhLegoEMCAL->Draw(opt);
+}
+
+void AliEMCALJetFinder::DrawHistsForTuning(Int_t mode)
+{ 
+// Draw all hists      
+  static TPaveText *varLabel=0;
+  if(!fC1) {
+    fC1 = new TCanvas("C1","Hists. for tunning", 0,25,600,800);
+  }
+  fC1->Clear();
+  fC1->Divide(2,2);
+  fC1->cd(1);
+  gPad->SetLogy(1);
+  fhCellEt->Draw();
+
+  fC1->cd(2);
+  gPad->SetLogy(1);
+  fhCellEMCALEt->Draw();
+
+  fC1->cd(3);
+  gPad->SetLogy(1);
+  fhTrackPt->Draw();
+  fhTrackPtBcut->SetLineColor(2);
+  fhTrackPtBcut->Draw("same");
+  fC1->cd(4);
+  if(!varLabel) {
+    PrintParameters(1);
+    varLabel = new TPaveText(0.05,0.5,0.95,0.95,"NDC");
+    varLabel->SetTextAlign(12);
+    varLabel->SetFillColor(19); // see TAttFill
+    TString tmp(GetTitle());
+    varLabel->ReadFile(GetFileNameForParameters());
+  }
+  varLabel->Draw();
+  fC1->Update();
+  if(mode) { // for saving picture to the file
+    TString stmp(GetFileNameForParameters());
+    stmp.ReplaceAll("_Par.txt",".ps");
+    fC1->Print(stmp.Data());
+  }
+}
+
+void AliEMCALJetFinder::PrintParameters(Int_t mode)
+{
+// Print all parameters out    
+       
+  FILE *file=0;
+  if(mode==0) file = stdout; // output to terminal
+  else {
+    file = fopen(GetFileNameForParameters(),"w");
+    if(file==0) file = stdout; 
+  }
+  fprintf(file,"====   Filling lego   ==== \n");
+  fprintf(file,"Sampling fraction %6.3f  ", fSamplingF);
+  fprintf(file,"Smearing          %6i  ", fSmear);
+  fprintf(file,"Efficiency        %6i\n", fEffic);
+  fprintf(file,"Hadr.Correct.     %6i  ", fHCorrection);
+  fprintf(file,"P_{T} Cut of ch.par. %6.2f\n", fPtCut);
+  fprintf(file,"====  Jet finding     ==== \n");
+  fprintf(file,"Cone radius       %6.2f  ", fConeRadius);
+  fprintf(file,"Seed E_{T}           %6.1f\n", fEtSeed);
+  fprintf(file,"Min E_{T} of cell    %6.1f  ", fMinCellEt);
+  fprintf(file,"Min E_{T} of jet     %6.1f\n", fMinJetEt);
+  if(fMode) {
+    fprintf(file,"====  Bg subtraction     ==== \n");
+    fprintf(file,"BG subtraction  %6i  ", fMode);
+    fprintf(file,"Min cone move   %6.2f\n", fMinMove);
+    fprintf(file,"Max cone move   %6.2f  ", fMaxMove);
+    fprintf(file,"%% change for BG %6.4f\n", fPrecBg);
+  } else
+  fprintf(file,"==== No Bg subtraction     ==== \n");
+  // 
+  printf("BG file name is %s \n", fBGFileName.Data());
+  if(file != stdout) fclose(file); 
+}
+
+void AliEMCALJetFinder::DrawLegos()
+{ 
+// Draw all legos      
+  if(!fC1) {
+    fC1 = new TCanvas("C1","Hists. for tunning", 0,25,600,800);
+  }
+  fC1->Clear();
+  fC1->Divide(2,2);
+  gStyle->SetOptStat(111111);
+
+  Int_t nent1, nent2, nent3, nent4;
+  Double_t int1, int2, int3, int4;
+  nent1 = (Int_t)fLego->GetEntries();
+  int1  = fLego->Integral();
+  fC1->cd(1);
+  if(int1) fLego->Draw("lego");
+
+  nent2 = (Int_t)fhLegoTracks->GetEntries();
+  int2  = fhLegoTracks->Integral();
+  fC1->cd(2);
+  if(int2) fhLegoTracks->Draw("lego");
+
+  nent3 = (Int_t)fhLegoEMCAL->GetEntries();
+  int3  = fhLegoEMCAL->Integral();
+  fC1->cd(3);
+  if(int3) fhLegoEMCAL->Draw("lego");
+
+  nent4 = (Int_t)fhLegoHadrCorr->GetEntries();
+  int4  = fhLegoHadrCorr->Integral();
+  fC1->cd(4);
+  if(int4) fhLegoHadrCorr->Draw("lego");
+
+  // just for checking 
+  printf(" Integrals \n");
+  printf("lego   %10.3f \ntrack  %10.3f \nhits   %10.3f \nHCorr   %10.3f\n--      %10.3f(must be 0)\n", 
+  int1, int2, int3, int4, int1 - (int2 + int3 - int4));
+}
+
+const Char_t* AliEMCALJetFinder::GetFileNameForParameters(const char* dir)
+{
+// Get paramters from a file   
+  static TString tmp;
+  if(strlen(dir)) tmp = dir;
+  tmp += GetTitle();
+  tmp += "_Par.txt";
+  return tmp.Data();
+}
+
+void AliEMCALJetFinder::RearrangeParticlesMemory(Int_t npart)
+{ 
+       // See FillFromTracks() - npart must be positive
+    if (fTrackList) delete[] fTrackList;
+    if (fPtT)       delete[] fPtT;
+    if (fEtaT)      delete[] fEtaT;
+    if (fPhiT)      delete[] fPhiT;
+    if (fPdgT)      delete[] fPdgT;
+    
+    if(npart>0) { 
+       fTrackList = new Int_t  [npart];
+       fPtT       = new Float_t[npart];
+       fEtaT      = new Float_t[npart];
+       fPhiT      = new Float_t[npart];
+       fPdgT      = new Int_t[npart];
+    } else {
+       printf("AliEMCALJetFinder::RearrangeParticlesMemory : npart = %d\n", npart);
+    }
+}
+
+Bool_t AliEMCALJetFinder::IsThisPartonsOrDiQuark(Int_t pdg)
+{
+// Return quark info   
+  Int_t absPdg = TMath::Abs(pdg);
+  if(absPdg<=6) return kTRUE; // quarks
+  if(pdg == 21) return kTRUE; // gluon 
+  if(pdg == 92) return kTRUE; // string 
+
+  // see p.51 of Pythia Manual
+  // Not include diquarks with c and b quark - 4-mar-2002
+  //                 ud_0,sd_0,su_0; dd_1,ud_1,uu_1;  sd_1,su_1,ss_1
+  static Int_t diquark[9]={2101,3101,3201, 1103,2103,2203,  3103,3203,3303};
+  for(Int_t i=0; i<9; i++) if(absPdg == diquark[i])  return kTRUE; // diquarks
+
+  return kFALSE;
+}
+
+void AliEMCALJetFinder::FindChargedJet()
+{
+//
+// Find jet from charged particle information only
+//
+    
+//
+//  Look for seeds
+//
+    Int_t njets = 0;
+    Int_t part  = 0;
+    Int_t nseed = 0;
+  
+//
+//
+    ResetJets();
+    
+//  
+    for (part = 0; part < fNt; part++) {
+       if (!fTrackList[part]) continue;
+       if (fPtT[part] > fEtSeed) nseed++;
+    }
+    printf("\nThere are %d seeds (%d)\n", nseed, fNtS);
+    Int_t* iSeeds = new Int_t[nseed];
+    nseed = 0;
+    
+    for (part = 0; part < fNt; part++) {
+       if (!fTrackList[part]) continue;
+       if (fPtT[part] > fEtSeed) iSeeds[nseed++] =  part;
+    }
+
+//
+// Loop over seeds
+//
+    Int_t seed = 0;
+    Float_t pt;
+    
+    while(1){
+//
+// Find seed with highest pt
+// 
+       Float_t ptmax = -1.;
+       Int_t   index = -1;
+       Int_t   jndex = -1;
+       for (seed = 0; seed < nseed; seed++) {
+           if ((pt = fPtT[iSeeds[seed]]) > ptmax && iSeeds[seed] != -1) {
+               ptmax = pt;
+               index = seed;
+           } // ptmax ?
+       } // seeds 
+       if (ptmax < 0.) break;
+       jndex = iSeeds[index];
+//
+// Remove from the list   
+       iSeeds[index] = -1;
+       printf("\n Next Seed %d %f", jndex, ptmax);
+//
+// Find tracks in cone around seed
+//
+       Float_t phiSeed = fPhiT[jndex];
+       Float_t etaSeed = fEtaT[jndex];
+       Float_t eT = 0.;
+       Float_t pxJ = 0.;
+       Float_t pyJ = 0.;
+       Float_t pzJ = 0.;
+       
+       for (part = 0; part < fNt; part++) {
+           if (!fTrackList[part]) continue;
+           Float_t deta = fEtaT[part] - etaSeed;
+           Float_t dphi = fPhiT[part] - phiSeed;
+           Float_t dR   = TMath::Sqrt(deta * deta + dphi * dphi);
+           if (dR < fConeRadius) {
+               eT += fPtT[part];
+               Float_t theta = 2. * TMath::ATan(TMath::Exp(-fEtaT[part]));
+               Float_t px = fPtT[part] * TMath::Cos(fPhiT[part]);
+               Float_t py = fPtT[part] * TMath::Sin(fPhiT[part]);
+               Float_t pz = fPtT[part] / TMath::Tan(theta);
+               pxJ += px;
+               pyJ += py;
+               pzJ += pz;
+               //
+               // if seed, remove it
+               //
+               for (seed = 0; seed < nseed; seed++) {
+                   if (part == iSeeds[seed]) iSeeds[seed] = -1;
+               } // seed ?
+           } // < cone radius
+       } // particle loop
+
+//
+//      Estimate of jet direction
+       Float_t phiJ   = TMath::ATan2(pyJ, pxJ);
+       Float_t thetaJ = TMath::ATan2(TMath::Sqrt(pxJ * pxJ + pyJ * pyJ), pzJ);
+       Float_t etaJ   = TMath::Log(TMath::Tan(thetaJ / 2.));
+//     Float_t ptJ    = TMath::Sqrt(pxJ * pxJ + pyJ * pyJ);
+       
+//
+//      Sum up all energy
+//
+       Int_t iPhi0 = Int_t((phiJ - fPhiMin) / fDphi);
+       Int_t iEta0 = Int_t((etaJ - fEtaMin) / fDeta);
+       Int_t dIphi = Int_t(fConeRadius / fDphi);
+       Int_t dIeta = Int_t(fConeRadius / fDeta);
+       Int_t iPhi, iEta;
+       Float_t sumE = 0;
+       for (iPhi = iPhi0 -dIphi; iPhi < iPhi0 + dIphi; iPhi++) {
+           for (iEta = iEta0 - dIeta; iEta < iEta0 + dIeta; iEta++) {
+               if (iPhi < 0 || iEta < 0) continue;
+               Float_t dPhi = fPhiMin + iPhi * fDphi;
+               Float_t dEta = fEtaMin + iEta * fDeta;
+               if (TMath::Sqrt(dPhi * dPhi + dEta * dEta) < fConeRadius) continue;
+               sumE += fLego->GetBinContent(iEta, iPhi);
+           } // eta
+       } // phi
+//
+//
+//
+       fJetT[njets++] = new AliEMCALJet(sumE, phiJ, etaJ);
+       FindTracksInJetCone();
+       printf("\n Jet Energy %f %f %f %f %d\n", eT, sumE, fPtT[6], fPtT[7], njets);
+       printf("\n Jet Phi %f %f %f \n", phiJ, fPhiT[6], fPhiT[7]);
+       printf("\n Jet Eta %f %f %f \n", etaJ, fEtaT[6], fEtaT[7]);
+    } // while(1)
+    EMCALJETS.njet = njets;
+    if (fWrite) WriteJets();
+    fEvent++;
+}
+// 16-jan-2003 - just for convenience
+void AliEMCALJetFinder::Browse(TBrowser* b)
+{
+// Add to browser      
+   if(fHistsList)  b->Add((TObject*)fHistsList);
+}
+
+Bool_t AliEMCALJetFinder::IsFolder() const
+{
+// Return folder status        
+  if(fHistsList) return kTRUE;
+  else           return kFALSE;
+}
+
+const Char_t* AliEMCALJetFinder::GetNameOfVariant()
+{
+       // generate the literal string with info about jet finder
+  Char_t name[200];
+  sprintf(name, "jF_R%3.2fMinCell%4.1fPtCut%4.1fEtSeed%4.1fMinEt%4.1fBGSubtr%iSF%4.1f",
+         fConeRadius,fMinCellEt,fPtCut,fEtSeed,fMinJetEt, fMode, fSamplingF);
+  TString nt(name);
+  nt.ReplaceAll(" ","");
+  if(fBGFileName.Length()) {
+     Int_t i1 = fBGFileName.Index("kBackground");
+     Int_t i2 = fBGFileName.Index("/0000") - 1;
+     if(i1>=0 && i2>=0) {
+        TString bg(fBGFileName(i1,i2-i1+1));
+        nt += bg;
+     }
+  }
+  printf("<I> Name of variant %s \n", nt.Data());
+  return nt.Data();
+}
diff --git a/EMCAL/jetfinder/AliEMCALJetFinder.h b/EMCAL/jetfinder/AliEMCALJetFinder.h
new file mode 100644 (file)
index 0000000..890d2d7
--- /dev/null
@@ -0,0 +1,217 @@
+#ifndef ALIEMCALJETFINDER_H
+#define ALIEMCALJETFINDER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+//*-- Author:
+//*-- Andreas Morsch (CERN)
+
+#include <TTask.h>
+#include "AliEMCALJet.h"
+#include <TString.h>
+
+class TClonesArray;
+class TH2F;
+class TH1F;
+class TCanvas;
+class TList;
+class AliEMCALHadronCorrection;
+
+class AliEMCALJetFinder : public TTask {
+  friend class AliEMCALJetMicroDst; //PH Temporary solution
+ public:
+    AliEMCALJetFinder();
+    AliEMCALJetFinder(const char* name, const char *title);
+    virtual ~AliEMCALJetFinder();
+    virtual void  Init();
+    virtual void  Find(Int_t ncell, Int_t ncelltot, Float_t etc[30000], 
+                     Float_t etac[30000], Float_t phic[30000],
+                     Float_t minmove, Float_t maxmove, Int_t mode,
+                     Float_t precbg, Int_t ierror);
+    virtual void  Find();
+    virtual void  FindChargedJet();
+    virtual void  FindTracksInJetCone();
+    virtual void  Test();
+    virtual void  BuildTrackFlagTable();
+    virtual Int_t SetTrackFlag(Float_t radius, Int_t pdgCode, Double_t charge);
+    // Geometry
+    virtual void SetCellSize(Float_t eta, Float_t phi);
+    // Parameters
+    virtual void SetDebug(Int_t flag = 0) {fDebug = flag;}
+    virtual void SetConeRadius(Float_t par);
+    virtual void SetEtSeed(Float_t par);
+    virtual void SetMinJetEt(Float_t par);
+    virtual void SetMinCellEt(Float_t par);
+    virtual void SetPtCut(Float_t par = 1.);
+    virtual void SetMomentumSmearing(Bool_t flag = kFALSE) {fSmear = flag;}
+    virtual void SetEfficiencySim(Bool_t flag = kFALSE)    {fEffic = flag;}
+    virtual void SetSamplingFraction(Float_t par) {fSamplingF = par;}
+    virtual void SetEnergyWeightingFlag(Bool_t flag) {fWeightingMethod = flag;}
+    virtual void SetEMCALWeight(Float_t par) {fEMCALWeight = par;}
+    virtual void SetTrackWeight(Float_t par) {fTrackWeight = par;}
+    virtual void SetIncludeK0andN(Bool_t flag = kFALSE) {fK0N = flag;}
+    // Correction of hadronic energy
+    virtual void SetHadronCorrector(AliEMCALHadronCorrection* corr)
+       {fHadronCorrector = corr;}
+    virtual void SetHadronCorrection(Int_t flag = 1) {fHCorrection = flag;}
+    // PAI
+    void SetWriteKey(Bool_t flag = kFALSE) {fWrite = flag;}
+    void SetMode(Int_t mode = 0) {fMode = mode;}
+    void SetMinMove(Float_t minMove = 0.05) {fMinMove = minMove;}
+    void SetMaxMove(Float_t maxMove = 0.15) {fMaxMove = maxMove;}
+    void SetPrecBg (Float_t precBg = 0.035) {fPrecBg = precBg;}
+    void SetParametersForBgSubtraction
+    (Int_t mode=0, Float_t minMove=0.05, Float_t maxMove=0.15, Float_t precBg=0.035);
+    //    virtual void Print(Option_t* option="") const;    // *MENU*
+    void  SetRandomBg(Bool_t flag) {fRandomBg = flag;}
+    Bool_t GetWriteKey() const {return fWrite;}
+  //AliEMCALJet* GetJetT() {return fJetT[0];}
+    AliEMCALJet* GetJetT(Int_t n = 0) {return fJetT[n];}
+    virtual void DrawHistsForTuning(Int_t mode=0);           // *MENU*
+    virtual void PrintParameters(Int_t mode=0);              // *MENU*
+    virtual const Char_t* GetFileNameForParameters(const char* dir="RES/");
+
+    // Access to Results
+    virtual Int_t Njets() const;
+    virtual Float_t JetEnergy (Int_t count) const;
+    virtual Float_t JetPhiL  (Int_t count) const;
+    virtual Float_t JetPhiW  (Int_t count) const ;
+    virtual Float_t JetEtaL (Int_t count) const ;  
+    virtual Float_t JetEtaW (Int_t count) const;
+    TH2F*   GetLego() const {return fLego;}
+    TH2F*   GetLegoB() const {return fLegoB;}
+    TH2F*   GetLegoEMCAL() const {return fhLegoEMCAL;}
+    TH2F*   GetLegoTracks() const {return fhLegoTracks;}
+    TH2F*   GethEff() const {return fhEff;}
+    TH1F*   GetCellEt() const {return fhCellEt;}
+    TH1F*   GetCellEMCALEt() const {return fhCellEMCALEt;}
+    TH1F*   GetTrackPt() const {return fhTrackPt;}
+    TH1F*   GetTrackPtBcut() const {return fhTrackPtBcut;}
+    TList*  GetHistsList() const {return fHistsList;}
+    Int_t   GetNChTpc() const {return fNChTpc;}
+    Bool_t  GetEnergyWeightingFlag() const {return fWeightingMethod ;}
+    Float_t GetEMCALWeight() const {return fEMCALWeight;}
+    Float_t GetTrackWeight() const {return fTrackWeight;}
+    void    DrawLego(const char *opt="lego");         // *MENU*
+    void    DrawLegoEMCAL(const char *opt="lego");    // *MENU*
+    void    DrawLegos();                          // *MENU*
+    void    DrawLegoBackground(const char *opt="lego"); // *MENU*
+    Bool_t  IsThisPartonsOrDiQuark(Int_t pdg);
+    // I/O
+    virtual void SetOutputFileName(const char* name) {fOutFileName = name;}
+    virtual void FillFromHits(Int_t flag = 0);
+    virtual void FillFromHitFlaggedTracks(Int_t flag = 0);
+    virtual void FillFromDigits(Int_t flag = 0);
+    virtual void FillFromTracks(Int_t flag = 0, Int_t ich = 0);
+    virtual void FillFromParticles();
+    virtual void FillFromPartons();
+
+    virtual void SaveBackgroundEvent(const char *name="");
+    virtual void InitFromBackground();
+    virtual void AddJet(const AliEMCALJet& jet);
+    virtual void WriteJets();
+    virtual void ResetJets();
+    virtual TClonesArray* Jets() const {return fJets;}
+    const char* GetNameOfVariant();
+
+    virtual Bool_t  IsFolder() const;
+    virtual void Browse(TBrowser* b);
+
+
+
+    
+ protected:
+    TString fBGFileName;                               // file name for background
+    Float_t                       fEMCALWeight;        // EMCal energy weighting
+    Float_t                       fTrackWeight;        // Track energy weighting
+    Bool_t                         fRandomBg;        //  Flag for Random Background 
+    Bool_t                         fWrite;           // Key for writing
+    Bool_t                         fWeightingMethod; // Key for writing
+    TClonesArray*                  fJets;            //! List of Jets
+    TH2F*                          fLego;            //! Lego Histo
+    TH2F*                          fLegoB;           //! Lego Histo Backg
+    TH2F*                          fhLegoTracks;     //! Lego for Tracks
+    TH2F*                          fhLegoEMCAL;      //! Lego for EMCAL itself
+    TH2F*                          fhLegoHadrCorr;   //! Lego for hadron correction
+    TH2F*                          fhEff;            //! Hist. for controling eff.
+    TH1F*                          fhCellEt;         //! Et distr. for cells from fLego
+    TH1F*                          fhCellEMCALEt;    //! Et distr. for cells from fLegoEMCAL
+    TH1F*                          fhTrackPt;        //! Pt distr. for charge particles
+    TH1F*                          fhTrackPtBcut;    //! Pt distr. for charge particles + cut due to magnetic field
+    TH1F*                          fhChPartMultInTpc;//! Ch. part. multiplicity in TPC acceptance
+    TH1F*                          fhSinTheta;       //! sin(theta)
+    TCanvas*                       fC1;              //! first canvas for drawing
+    TList*                         fHistsList;       //! List of hists - 4-mar-2002
+    AliEMCALJet*                   fJetT[10];        //! Jet temporary storage
+    AliEMCALHadronCorrection*      fHadronCorrector; //! Pointer to hadronic correction
+    Int_t                          fHCorrection;     //  Hadron correction flag
+    Int_t                          fDebug;           //! Debug flag
+    Int_t                          fBackground;      //! Background flag
+    Float_t                        fConeRadius;      //  Cone radius
+    Float_t                        fPtCut;           //  Pt cut on charged tracks
+    Float_t                        fEtSeed;          //  Min. Et for seed
+    Float_t                        fMinJetEt;        //  Min Et of jet
+    Float_t                        fMinCellEt;       //  Min Et in one cell
+    Float_t                        fSamplingF;       //  Sampling Fraction
+    Bool_t                         fSmear;           //  Flag for momentum smearing
+    Bool_t                         fEffic;           //  Flag for efficiency simulation
+    Bool_t                         fK0N;             //  Flag for efficiency simulation
+    Int_t                          fNjets;           //! Number of Jetsp
+    Float_t                        fDeta;            //! eta cell size 
+    Float_t                        fDphi;            //! phi cell size
+    Int_t                          fNcell;           //! number of cells
+    Int_t                          fNtot;            //! total number of cells
+    Int_t                          fNbinEta;         //! number of cells in eta
+    Int_t                          fNbinPhi;         //! number of cells in phi
+    Float_t                        fEtaMin;          //! minimum eta  
+    Float_t                        fEtaMax;          //! maximum eta
+    Float_t                        fPhiMin;          //! minimun phi
+    Float_t                        fPhiMax;          //! maximum phi
+    Float_t                        fEtCell[30000];   //! Cell Energy
+    Float_t                        fEtaCell[30000];  //! Cell eta
+    Float_t                        fPhiCell[30000];  //! Cell phi
+    Int_t                          fNt;              //! number of tracks
+    Int_t                          fNChTpc;          //! number of ch.part in TPC
+
+    Int_t                          fNtS;             //! number of tracks selected
+    Int_t*                         fTrackList;       //! List of selected tracks
+    Float_t*                       fPtT;             //! Pt   of tracks 
+    Float_t*                       fEtaT;            //! Eta  of tracks
+    Float_t*                       fPhiT;            //! Phi  of tracks
+    Int_t*                         fPdgT;            //! PDG code of tracks
+    Int_t                          fNtB;             //! number of tracks in Bg
+    Int_t*                         fTrackListB;      //! List of selected tracks in Bg
+    Float_t*                       fPtB;             //! Pt   of tracks in Bg
+    Float_t*                       fEtaB;            //! Eta  of tracks in Bg
+    Float_t*                       fPhiB;            //! Phi  of tracks in Bg
+    Int_t*                         fPdgB;            //! PDG  of tracks in Bg
+
+    // parameter for jet_finder_ua1
+    Int_t                          fMode;            // key for BG subtraction
+    Float_t                        fMinMove;         // min cone move 
+    Float_t                        fMaxMove;         // max cone move
+    Float_t                        fPrecBg;          // max value of change for BG (in %)
+    Int_t                          fError;           // error variables 
+
+    const char*                    fOutFileName;     //! Output file name
+    TFile*                         fOutFile;         //! Output file
+    TFile*                         fInFile;          //! Output file
+    Int_t                          fEvent;           //! Processed event
+ private:
+    virtual void BookLego();
+    Float_t WeightedJetEnergy(Float_t eta, Float_t phi);
+    Float_t EMCALConeEnergy(Float_t eta, Float_t phi);
+    Float_t TrackConeEnergy(Float_t eta, Float_t phi);
+    virtual void DumpLego();
+    virtual void ResetMap();
+    virtual void RearrangeParticlesMemory(Int_t npart);
+ public:
+    virtual Float_t PropagatePhi(Float_t pt, Float_t charge, Bool_t& curls);
+
+    ClassDef(AliEMCALJetFinder,5)                    // JetFinder for EMCAL
+}
+;
+#endif // ALIEMCALJetFinder_H
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderAlgo.cxx b/EMCAL/jetfinder/AliEMCALJetFinderAlgo.cxx
new file mode 100644 (file)
index 0000000..c176af9
--- /dev/null
@@ -0,0 +1,100 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+//  Base Class for JetFinder Algorithms     
+// --                  
+//*-- Author: Mark Horner (LBL/UCT)
+// --
+
+
+
+#include "AliEMCALJetFinderAlgo.h"
+#include "AliRun.h"
+#include "AliEMCALGeometry.h"
+#include "AliMagF.h"
+ClassImp(AliEMCALJetFinderAlgo)
+
+AliEMCALJetFinderAlgo::AliEMCALJetFinderAlgo()
+{
+   fDebug =0;
+   fOutputPointer=0;
+   fInputPointer=0;
+   fOutputAllocated=kFALSE;
+}
+
+AliEMCALJetFinderAlgo::~AliEMCALJetFinderAlgo()
+{
+  if (fOutputAllocated)
+    delete fOutputPointer;
+}
+
+void AliEMCALJetFinderAlgo::SetOutput(AliEMCALJetFinderOutput* output) {
+  if (fOutputAllocated)
+    delete fOutputPointer;
+  fOutputPointer=output;
+  fOutputAllocated=kFALSE;
+}
+
+void AliEMCALJetFinderAlgo::InitInput(AliEMCALJetFinderInput* input)
+{
+// Take input data     
+if (fDebug>1) Info("InitInput","Beginning InitInput");         
+       fInputPointer = input;
+       if (fOutputPointer==0) {
+         
+         if (fDebug>1) Info("InitInput","Allocating output object");           
+         fOutputPointer=new AliEMCALJetFinderOutput();
+         fOutputAllocated=kTRUE;
+       }
+       fOutputPointer->Reset(kResetAll);       
+       // automatically copy parton and particle info to output object
+        
+       for (Int_t counter = 0 ; counter < fInputPointer->GetNPartons();counter++)
+       {
+               fOutputPointer->AddParton(fInputPointer->GetParton(counter));
+       }
+       for (Int_t counter = 0 ; counter < fInputPointer->GetNParticles();counter++)
+       {
+               fOutputPointer->AddParticle(fInputPointer->GetParticle(counter));
+       }
+}
+
+Float_t AliEMCALJetFinderAlgo::PropagatePhi(Float_t pt, Float_t charge, Bool_t& curls)
+{
+       // Propagates phi angle to EMCAL radius
+       // //
+ Float_t b = 0.0, rEMCAL = -1.0;
+ if(rEMCAL<0) 
+ {     
+        b =  gAlice->Field()->SolenoidField();
+        rEMCAL = AliEMCALGeometry::GetInstance()->GetIPDistance();
+ }
+ Float_t dPhi = 0.;
+ Float_t rB = 3335.6 * pt / b;  // [cm]  (case of |charge|=1)
+ if (2.*rB < rEMCAL) 
+ {
+        curls = kTRUE;
+        return dPhi;
+ }
+ Float_t phi = TMath::ACos(1.-rEMCAL*rEMCAL/(2.*rB*rB));
+ dPhi = TMath::ATan2(1.-TMath::Cos(phi), TMath::Sin(phi));
+ dPhi = -TMath::Sign(dPhi, charge);
+ return dPhi;
+}
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderAlgo.h b/EMCAL/jetfinder/AliEMCALJetFinderAlgo.h
new file mode 100644 (file)
index 0000000..aef0918
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef ALIEMCALJETFINDERALGO_H
+#define ALIEMCALJETFINDERALGO_H
+
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Base Class for JetFinder Algorithms     
+//                  
+//*-- Author: Mark Horner (LBL/UCT)
+
+
+#include "TTask.h"
+#include "AliEMCALJetFinderInput.h"
+#include "AliEMCALJetFinderOutput.h"
+
+
+class AliEMCALJetFinderAlgo : public TTask
+{
+public:
+  AliEMCALJetFinderAlgo();
+  virtual ~AliEMCALJetFinderAlgo();
+  virtual void FindJets() = 0 ;
+  void InitInput(AliEMCALJetFinderInput* input);
+  void SetDebug(Int_t debug = 0){fDebug = debug; if (fOutputPointer) fOutputPointer->SetDebug(debug);}
+  AliEMCALJetFinderOutput* GetOutput() { return fOutputPointer;}
+  void SetOutput(AliEMCALJetFinderOutput *output);
+  Float_t PropagatePhi(Float_t pt, Float_t charge, Bool_t& curls);     
+  Bool_t GetPythiaComparison(){return fPythiaComparison;}
+  void SetPythiaComparison(Bool_t value){fPythiaComparison=value;}
+protected:
+   
+  AliEMCALJetFinderInput*        fInputPointer;  // pointer to the input object 
+  AliEMCALJetFinderOutput*       fOutputPointer;  // output object for results
+  Bool_t                         fOutputAllocated; // flags if ouputobject is woned by JetFinderAlgo
+  Int_t                                 fDebug;         // debug level
+  Bool_t                        fPythiaComparison; // for pyclus comparison
+
+  ClassDef(AliEMCALJetFinderAlgo,4)
+
+};
+#endif
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderAlgoOmni.cxx b/EMCAL/jetfinder/AliEMCALJetFinderAlgoOmni.cxx
new file mode 100644 (file)
index 0000000..990e058
--- /dev/null
@@ -0,0 +1,901 @@
+
+//THIS Also includes summing ALL cells in the jetcone towards the jet energy NOT just those above threshold!!!!!
+
+
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+/*
+$Log$
+Revision 1.16  2006/02/15 15:11:05  pavlinov
+update of Jenn and Marco
+
+Revision 1.15  2004/11/22 19:52:05  mhorner
+Make sure pi0 get through
+
+Revision 1.14  2004/04/02 17:11:33  mhorner
+Marco's bug - fixes implemented
+
+Revision 1.13  2004/03/26 01:00:38  mhorner
+Implementing Marco's optimisations
+
+Revision 1.12  2004/03/15 19:59:37  mhorner
+Pyhtia comparison extended
+
+Revision 1.11  2004/03/09 17:06:38  mhorner
+Made more robust
+
+Revision 1.10  2004/03/06 01:56:09  mhorner
+Pythai comp code
+
+Revision 1.9  2004/02/23 20:37:32  mhorner
+changed geometry call
+
+Revision 1.8  2004/01/29 23:28:44  mhorner
+Jet Finder - hard coded geom parameters removed
+
+Revision 1.7  2004/01/21 22:27:47  mhorner
+Cleaning up coding conventions
+
+Revision 1.6  2003/10/28 13:54:30  schutz
+Compilation warnings fixed
+
+Revision 1.5  2003/09/23 13:31:41  mhorner
+Changed coordinate system
+
+Revision 1.4  2003/09/19 13:16:20  mhorner
+Added additional jet energy info
+
+
+Revision 1.3  2003/09/04 12:49:56  mhorner
+Changed hadron correction and added saving EMCAL and track contributions
+
+*/
+
+
+//*--Author: Sarah Blyth (LBL)
+//*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
+
+#include "TTask.h"
+#include "TMath.h"
+#include "TParticle.h"
+#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliEMCALJetFinderInput.h"
+#include "AliEMCALJetFinderOutput.h"
+#include "AliEMCALJetFinderAlgo.h"
+#include "AliEMCALJetFinderAlgoOmni.h"
+#include "AliEMCALJetFinderAlgoUA1Unit.h"
+#include "AliEMCALGeometry.h"
+#include "AliEMCALLoader.h"
+#include "AliEMCAL.h"
+#include "AliEMCALDigit.h"
+#include "AliEMCALJet.h"
+
+
+ClassImp(AliEMCALJetFinderAlgoOmni)
+
+  AliEMCALJetFinderAlgoOmni::AliEMCALJetFinderAlgoOmni()
+{
+  //Default constructor
+if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Default Constructor");
+  AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
+  fNumIter           = 0;
+  fNumUnits          = geom->GetNTowers();     //Number of towers in EMCAL
+  fESeed             = 5.0;       //Default value
+  fConeRad           = 0.3;       //Default value
+  fJetEMin           = 10.0;      //Default value
+  fEtMin             = 0.0;      //Default value
+  fMinMove           = 0.05;      //From original UA1 JetFinder
+  fMaxMove           = 0.15;      //From original UA1 JetFinder
+  fBGMaxMove         = 0.035;     //From original UA1 JetFinder
+  fPtCut             = 0;         
+  fHadCorr           = 0;       
+  fEBGTotal          = 1.0;       //Set to 1 so that no div by zero in first FindJets() loop
+  fEBGTotalOld       = 0.0;
+  fEBGAve            = 0.0;
+  fEnergy            = 0.0;
+  fJetEta            = 0.0;
+  fJetPhi            = 0.0;
+  fEtaInit           = 0.0;
+  fPhiInit           = 0.0;
+  fEtaB              = 0.0;
+  fPhiB              = 0.0;
+  fJetESum           = 0.0;
+  fJetEtaSum         = 0.0;
+  fJetPhiSum         = 0.0;
+  fDEta              = 0.0;
+  fDPhi              = 0.0;
+  fDistP             = 0.0;
+  fDistI             = 0.0;
+  fTempE             = 0.0;
+  fRad               = 2.0;      //Set to 2 to start 
+  fNumInCone         = 0;
+  fNumJets           = 0;
+  fArrayInitialised  = 0;        //Set to FALSE to start
+  fBGType            = kRatio;   //Set Ratio method as default BG subtraction method 
+  fBGPar             = -1.0;      //Set to 1 to start
+}
+
+ AliEMCALJetFinderAlgoOmni::~AliEMCALJetFinderAlgoOmni()
+   {
+     //Destructor
+     if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Destructor");
+     delete[] fUnit;
+     delete[] fUnitNoCuts;
+   }
+
+ void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
+                               (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin, 
+                               Float_t minMove, Float_t maxMove, Float_t bgMaxMove)
+   {
+     //Sets parameters for the JetFinding algorithm
+     if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
+
+     SetNumUnits(numUnits);
+     SetJetESeed(eSeed);
+     SetConeRad(coneRad);
+     SetJetEMin(jetEMin);
+     SetEtMin(etMin);
+     SetMinMove(minMove);
+     SetMaxMove(maxMove);
+     SetBGMaxMove(bgMaxMove);
+   }
+
+ void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
+                               (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin)
+   {
+     //Sets fewer parameters for the JetFinding algorithm
+     if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
+
+     SetNumUnits(numUnits);
+     SetJetESeed(eSeed);
+     SetConeRad(coneRad);
+     SetJetEMin(jetEMin);
+     SetEtMin(etMin);
+     SetMinMove(fMinMove);
+     SetMaxMove(fMaxMove);
+     SetBGMaxMove(fBGMaxMove);
+   }
+
+ void AliEMCALJetFinderAlgoOmni::InitUnitArray()
+   {
+     //Initialises unit arrays
+     if(fArrayInitialised) delete [] fUnit;
+     if(fArrayInitialised) delete [] fUnitNoCuts;
+     fUnit = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
+     fUnitNoCuts = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
+     fArrayInitialised = 1;
+   }
+
+ void AliEMCALJetFinderAlgoOmni::FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag)
+   {
+          // Fill the unit array 
+     if (fDebug>1) Info("FillUnitArray","Beginning FillUnitArray");
+         //    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
+         //   if (pEMCAL){ 
+         //         AliEMCALGeometry* geom =  AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
+         //     }else
+         //    {
+
+     AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
+     if (geom == 0)
+      geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
+
+        //    }
+         
+     AliEMCALJetFinderAlgoUA1FillUnitFlagType_t option = flag;
+     Int_t         numTracks, numDigits;
+    
+     //Loops over all elements in the AliEMCALJetFinderAlgoUA1Unit array and 
+     //fills the objects with relevant values from the Data Input object
+     if (fDebug>10) Info("FillUnitArray","Filling array with Unit objects");
+     if (fDebug>15) Info("FillUnitArray","NTracks %i NDigits %i",fInputPointer->GetNTracks(),fInputPointer->GetNDigits());
+        numTracks = fInputPointer->GetNTracks();
+        numDigits = fInputPointer->GetNDigits();
+        TParticle         *myPart;
+        AliEMCALDigit     *myDigit;
+     if (!fPythiaComparison)
+     {
+        //Fill units with Track info if appropriate
+        if(option==kFillTracksOnly || option ==kFillAll) 
+          {          
+           for(Int_t j=0; j<numTracks; j++)
+           {
+            myPart = fInputPointer->GetTrack(j);
+            Float_t eta = myPart->Eta();
+            Float_t  phi = myPart->Phi();
+            Int_t towerID = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
+            Float_t  pT = myPart->Pt();
+            Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy(); 
+            Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy();
+
+            
+            //OLD WAY:   //Do Hadron Correction
+              if(fHadCorr != 0)
+              {
+                Double_t   fullP = myPart->P();
+                Double_t   hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
+                unitEnergy -= hCEnergy*TMath::Sin(myPart->Theta());
+                unitEnergyNoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
+                fUnit[towerID-1].SetUnitEnergy(unitEnergy);
+                fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
+              } //end Hadron Correction loop 
+             
+    
+            /*
+             //Do Hadron Correction with propagate phi for the track
+             if(fHadCorr != 0)
+               {
+                 Bool_t curl = 1;
+                 Float_t deltaPhi;
+                 TParticlePDG *pdg = myPart->GetPDG();
+                 if(pdg->Charge() < 0)
+                   {
+                     deltaPhi = PropagatePhi(myPart->Pt(), -1.0, curl);
+                   }
+                 else{
+                   deltaPhi = PropagatePhi(myPart->Pt(), 1.0, curl);
+                 }
+                 phi += deltaPhi;
+                 //Get new tower id for cell that track would curve into
+                  Int_t towerID2;
+                  if(phi>(TMath::Pi()/180.0)*geom->GetArm1PhiMax() || phi<(TMath::Pi()/180.0)*geom->GetArm1PhiMin())
+                    {
+                      towerID2 = -1;
+                    }
+                  else{
+                      towerID2 = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
+                    }
+                  
+                 if(towerID2 != -1)
+                   {
+                     //Find unit energy of new tower
+                     Float_t unitEnergy2 = fUnit[towerID2-1].GetUnitEnergy();
+                     Float_t unitEnergy2NoCuts = fUnitNoCuts[towerID2-1].GetUnitEnergy();
+                     Double_t   fullP = myPart->P();
+                     Double_t   hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
+                     unitEnergy2 -= hCEnergy*TMath::Sin(myPart->Theta());
+                     unitEnergy2NoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
+                     fUnit[towerID2-1].SetUnitEnergy(unitEnergy2);
+                     fUnitNoCuts[towerID2-1].SetUnitEnergy(unitEnergy2NoCuts);
+                   }//end if for towerID2
+               }//end Hadron Correction loop
+            */
+
+             fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts + pT);
+            //Do Pt cut on tracks
+            if(fPtCut != 0 && pT < fPtCut) continue;
+
+            fUnit[towerID-1].SetUnitEnergy(unitEnergy+pT);
+
+             }//end tracks loop
+          }//end Tracks condition
+
+
+        //Fill units with Digit info if appropriate
+        if(option ==kFillDigitsOnly || option ==kFillAll)
+          {
+            for(Int_t k=0; k<numDigits; k++)
+           {
+            myDigit = fInputPointer->GetDigit(k);
+             if (fDebug>10) Info("FillUnitArray","getting digits %i %i numdigits",k,numDigits );
+            Int_t towerID = myDigit->GetId();
+            Int_t amplitude = myDigit->GetAmp();     //Gets the integer valued amplitude of the digit
+            Float_t amp = (Float_t)amplitude;        //Need to typecast to Float_t before doing real energy conversion
+            Float_t digitEnergy = amp/10000000.0;    //Factor of 10 million needed to convert!
+            Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy() + digitEnergy;
+            Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy() + digitEnergy;
+            fUnit[towerID-1].SetUnitEnergy(unitEnergy);
+            fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
+           }//end digits loop
+          }//end digits condition
+
+        //Set all unit flags, Eta, Phi
+        for(Int_t i=0; i<fNumUnits; i++)
+          {
+             if (fDebug>10) Info("FillUnitArray","Setting all units outside jets");
+            //Set all units to be outside a jet initially
+            fUnit[i].SetUnitFlag(kOutJet);           
+            fUnit[i].SetUnitID(i+1);
+            Float_t eta;
+            Float_t phi;
+            geom->EtaPhiFromIndex(fUnit[i].GetUnitID(), eta, phi);
+            fUnit[i].SetUnitEta(eta);
+            fUnit[i].SetUnitPhi(phi*TMath::Pi()/180.0);
+            //Set all units to be outside a jet initially
+            fUnitNoCuts[i].SetUnitFlag(kOutJet);          
+            fUnitNoCuts[i].SetUnitID(i+1);
+            eta = 0.0;
+            phi = 0.0;
+            geom->EtaPhiFromIndex(fUnitNoCuts[i].GetUnitID(), eta, phi);
+            fUnitNoCuts[i].SetUnitEta(eta);
+            fUnitNoCuts[i].SetUnitPhi(phi*TMath::Pi()/180.0);
+            //      if(i>13000) cout<<"!!!!!!!!!!!!!!!!!For unit0, eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" and ID="<<fUnit[i].GetUnitID()<<endl;
+            //  if(fUnit[i].GetUnitEnergy()>0) cout<<"Unit ID "<<fUnit[i].GetUnitID() <<"with eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" has energy="<<fUnit[i].GetUnitEnergy()<<endl;
+          }//end loop over all units in array (same as all towers in EMCAL)
+
+     }
+     if (fPythiaComparison)
+     {
+            for(Int_t j=0; j<numTracks; j++)                            
+            {
+                    myPart = fInputPointer->GetTrack(j);
+                    fUnit[j].SetUnitID(j);
+                    fUnit[j].SetUnitFlag(kOutJet);
+                    fUnit[j].SetUnitEta(myPart->Eta());
+                    fUnit[j].SetUnitPhi(myPart->Phi());
+                    if (myPart->Energy()*TMath::Sin(myPart->Theta()) > fPtCut || myPart->GetPDG()->Charge() == 0.0  )
+                    {
+                            fUnit[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
+                    }else
+                    {
+                            fUnit[j].SetUnitEnergy(0.00);
+                    }
+                    fUnitNoCuts[j].SetUnitID(j);
+                    fUnitNoCuts[j].SetUnitFlag(kOutJet);
+                    fUnitNoCuts[j].SetUnitEta(myPart->Eta());
+                    fUnitNoCuts[j].SetUnitPhi(myPart->Phi());
+                    fUnitNoCuts[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
+            }
+            for(Int_t k=numTracks; k < fNumUnits; k++)
+            {
+                    fUnit[k].SetUnitID(k);
+                    fUnit[k].SetUnitFlag(kBelowMinEt);
+                    fUnit[k].SetUnitEta(0.0);
+                    fUnit[k].SetUnitPhi(0.0);
+                    fUnit[k].SetUnitEnergy(0.0);                    
+                    fUnitNoCuts[k].SetUnitID(k);
+                    fUnitNoCuts[k].SetUnitFlag(kBelowMinEt);
+                    fUnitNoCuts[k].SetUnitEta(0.0);
+                    fUnitNoCuts[k].SetUnitPhi(0.0);
+                    fUnitNoCuts[k].SetUnitEnergy(0.0);                   
+            }
+     }
+
+
+
+   }
+
+
+ void AliEMCALJetFinderAlgoOmni::Sort(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t length)
+ {
+   //Calls the recursive quicksort method to sort unit objects in decending order of Energy
+   if (fDebug>1) Info("Sort","Sorting Unit objects");
+   QS(unit, 0, length-1);
+ }
+  
+
+ void AliEMCALJetFinderAlgoOmni::QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right)
+ {
+  //Sorts the AliEMCALJetFinderAlgoUA1Unit objects in decending order of Energy
+   if (fDebug>111) Info("QS","QuickSorting Unit objects");   
+
+   Int_t    i;
+   Int_t    j;
+   AliEMCALJetFinderAlgoUA1Unit  unitFirst;
+   AliEMCALJetFinderAlgoUA1Unit  unitSecond;
+
+   i = left;
+   j = right;
+   unitFirst = unit[(left+right)/2];
+
+ do
+  {
+    while( (unit[i].GetUnitEnergy() > unitFirst.GetUnitEnergy()) && (i < right)) i++;
+    while( (unitFirst.GetUnitEnergy() > unit[j].GetUnitEnergy()) && (j > left)) j--;
+
+    if(i <= j)
+      {
+       unitSecond = unit[i];
+       unit[i] = unit[j];
+       unit[j] = unitSecond;
+       i++;
+       j--;
+      }//end if
+  }while(i <= j);
+
+ if(left < j) QS(unit, left, j);
+ if(i < right) QS(unit, i, right);
+ }
+
+
+ void AliEMCALJetFinderAlgoOmni::FindBG()
+ {
+   if(fBGType == kRatio) RatioBG();
+   else if(fBGType == kCone) ConeBG();
+   else if(fBGType == kConstant) ConstantBG();
+ }
+
+ void AliEMCALJetFinderAlgoOmni::RatioBG()
+   {
+     //Finds the background energy for the iteration
+     //using the Ratio method
+     if (fDebug>1) Info("FindBG","Finding Average Background"); 
+     //Store BGEperCell from previous iteration!
+     fEBGTotalOld = fEBGTotal;
+     fEBGTotal          = 0.0;
+     Int_t numCone      = 0;
+
+     //If user has not set fBGPar, set it to the default
+     //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
+     if(fBGPar == -1) fBGPar = 0.4685;
+
+     //Loop over all unit objects in the Unit array and link to same
+     //unit ID in NoCuts Unit array
+     for(Int_t i=0; i<fNumUnits; i++)
+       {
+        if(fUnit[i].GetUnitFlag() != kInJet)
+          {
+            Int_t id = fUnit[i].GetUnitID();
+            fEBGTotal += fUnitNoCuts[id-1].GetUnitEnergy();  
+          }
+        else numCone++;
+       }//end for
+
+     fEBGTotal *= fBGPar;
+     fEBGAve = fEBGTotal / (fNumUnits - numCone);
+     if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve); 
+
+     for(Int_t count=0; count<fNumUnits;count++)
+       {
+        fUnit[count].SetUnitFlag(kOutJet);
+       }//end for
+   }
+
+ void AliEMCALJetFinderAlgoOmni::ConeBG()
+   {
+     //Finds the background energy for the iteration
+     //using all energy not contained inside a jet
+     if (fDebug>1) Info("FindBG","Finding Average Background"); 
+     //Store old value of BGEperCell!
+     fEBGTotalOld = fEBGTotal;
+     fEBGTotal          = 0.0;
+     Int_t numCone      = 0;
+
+     //Loop over all unit objects in the array and sum the energy of those not in a jet
+     for(Int_t i=0; i<fNumUnits; i++)
+       {
+        if(fUnit[i].GetUnitFlag() != kInJet)
+          fEBGTotal += fUnit[i].GetUnitEnergy();
+        else numCone++;
+       }//end for
+
+     fEBGAve = fEBGTotal / (fNumUnits - numCone);
+     if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);      
+
+     for(Int_t count=0; count<fNumUnits;count++)
+       {
+        fUnit[count].SetUnitFlag(kOutJet);
+       }//end for
+   }
+
+ void AliEMCALJetFinderAlgoOmni::ConstantBG()
+   {     
+     //Finds the background energy for the iteration
+     //using all energy not contained inside a jet
+     if (fDebug>1) Info("FindBG","Finding Average Background"); 
+
+     //If user has not set fBGPar, set it to the default
+     //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
+     if(fBGPar == -1) fBGPar = 0.03378;
+
+     fEBGAve = fBGPar;
+     if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);      
+
+     fEBGTotal          = 0.0;
+     Int_t numCone      = 0;
+     for(Int_t count=0; count<fNumUnits;count++)
+       {
+        if(fUnit[count].GetUnitFlag() == kInJet)
+          {
+            numCone++;
+          }
+        fUnit[count].SetUnitFlag(kOutJet);
+       }//end for
+     fEBGTotal = fEBGAve * (fNumUnits-numCone);
+     fEBGTotalOld = fEBGTotal;
+   }
+
+ void AliEMCALJetFinderAlgoOmni::FindJetEtaPhi(Int_t counter)
+   {
+     //Finds the eta and phi of the jet axis
+     if (fDebug>10) Info("FindJetEtaPhi","Finding Jet Eta and Phi");
+
+     fDEta = fUnit[counter].GetUnitEta() - fEtaInit;
+     fDPhi = fUnit[counter].GetUnitPhi() - fPhiInit;
+
+     fEnergy = fUnit[counter].GetUnitEnergy() - fEBGAve;
+     fJetEtaSum += fEnergy * fDEta;
+     fJetPhiSum += fEnergy * fDPhi;
+     fJetESum += fEnergy;
+     if (fJetESum >1.0e-7)
+     {
+            fJetEta = fEtaInit + (fJetEtaSum / fJetESum);
+            fJetPhi = fPhiInit + (fJetPhiSum / fJetESum);
+     }
+   }
+
+
+ void AliEMCALJetFinderAlgoOmni::FindJetEnergy()
+   {
+     //Finds the energy of the jet after the final axis has been found
+     if (fDebug>1) Info("FindJetEnergy","Finding Jet Energy");
+
+     for(Int_t i=0; i<fNumUnits; i++)
+       {
+        //Loop over all unit objects in the array and find if within cone radius
+        Float_t dEta = fUnit[i].GetUnitEta() - fJetEta;
+        Float_t dPhi = fUnit[i].GetUnitPhi() - fJetPhi;
+        Float_t rad;
+        if ((dEta*dEta) + (dPhi*dPhi)>1.e-7)
+        {
+                rad = TMath::Sqrt( (dEta*dEta) + (dPhi*dPhi) );
+        }else
+        {
+                rad=0.0;
+        }
+
+        if(fUnit[i].GetUnitFlag()==kOutJet && rad<= fConeRad)
+          {
+            fUnit[i].SetUnitFlag(kInCurrentJet);
+            Float_t energy = fUnit[i].GetUnitEnergy() - fEBGAve;
+            fJetESum += energy;                             
+            fJetEtaSum += energy * dEta;
+            fJetPhiSum += energy * dPhi;
+            fNumInCone++;                     //Increment the number of cells in the jet cone
+          }//end if
+       }//end for
+   }
+
+
+ void AliEMCALJetFinderAlgoOmni::StoreJetInfo()
+   {
+     //Stores the resulting jet information in appropriate storage structure (TO BE DECIDED!!!!)
+     if (fDebug>1) Info("StoreJetInfo","Storing Jet Information");
+     AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
+     if (geom == 0)
+       geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
+     //Store:
+     //fJetESum is the final jet energy (background has been subtracted)
+     //fJetEta is the final jet Eta
+     //fJetPhi is the final jet Phi
+     //fNumInCone is the final number of cells included in the jet cone
+     //fEtaInit is the eta of the initiator cell
+     //fPhiInit is the phi of the initiator cell
+
+     AliEMCALJet jet(fJetESum,fJetPhi,fJetEta);
+
+      cout<<"For iteration "<<fNumIter <<" and Jet number " <<fNumJets <<endl;
+      cout<<"The jet energy is: " <<fJetESum <<endl;
+      cout<<"The jet eta is ---->" <<fJetEta <<endl;
+      cout<<"The jet phi is ---->" <<fJetPhi <<endl;
+
+     Int_t             numberTracks = fInputPointer->GetNTracks();
+     Int_t            numberDigits = fInputPointer->GetNDigits();
+     AliEMCALDigit     *myD;
+     TParticle         *myP;
+     Int_t             numTracksInCone = 0;
+     Float_t           trackEnergy = 0.0;
+     Float_t           trackEnergyPtCut =0.0; 
+     Float_t           emcalEnergy = 0.0;
+     Float_t           emcalEnergyBGSub = 0.0;
+
+     for(Int_t counter=0; counter<numberTracks; counter++)
+       {
+       myP = fInputPointer->GetTrack(counter);
+       Float_t eta = myP->Eta();
+       Float_t phi = myP->Phi(); 
+       Float_t deta = fJetEta-eta;
+       Float_t dphi = fJetPhi -phi;
+       Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
+       if(rad<=fConeRad) numTracksInCone++;
+       }//end for
+
+     Float_t    *pTArray = new Float_t[numTracksInCone];
+     Float_t    *etaArray = new Float_t[numTracksInCone];
+     Float_t    *phiArray = new Float_t[numTracksInCone];
+     Int_t      *pdgArray = new Int_t[numTracksInCone];
+     Int_t             index = 0;
+
+     for(Int_t counter2=0; counter2<numberTracks; counter2++)
+       {
+        myP = fInputPointer->GetTrack(counter2);
+        Float_t eta = myP->Eta();
+         Float_t phi = myP->Phi(); 
+        Float_t deta = fJetEta-eta;
+        Float_t dphi = fJetPhi -phi;
+        Float_t rad ;
+        if ((deta*deta) + (dphi*dphi)>1.e-7)
+        {
+                rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
+        }else
+        {
+                rad=0.0;
+        }
+
+        if(rad<=fConeRad)
+          {
+            pTArray[index] = myP->Pt();
+            //Calculate track contribution within jetcone
+            trackEnergy += myP->Pt();
+            if(myP->Pt() >= fPtCut) trackEnergyPtCut += myP->Pt();
+            etaArray[index] = eta;
+            phiArray[index] = phi;
+            pdgArray[index] = myP->GetPdgCode();
+            index++;
+            if(fHadCorr != 0)
+            {
+                    Double_t   fullP = myP->P();
+                    Double_t   hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
+                    emcalEnergy -= hCEnergy*TMath::Sin(myP->Theta());
+                    emcalEnergyBGSub -= hCEnergy*TMath::Sin(myP->Theta());
+            } //end Hadron Correction loop 
+                          
+          }//end if
+       }//end for
+
+     //Loop over digits to find EMCal contribution within jetcone
+     for(Int_t counter3=0; counter3<numberDigits; counter3++)
+       {
+        myD = fInputPointer->GetDigit(counter3);
+        //GET DIGIT ETA, PHI so that can check if inside R!
+        Float_t eta = 0.0;
+        Float_t phi = 0.0;
+        Int_t iID = myD->GetId();
+        geom->EtaPhiFromIndex(iID, eta, phi);
+        Float_t deta = fJetEta-eta;
+        Float_t dphi = fJetPhi -(TMath::Pi()/180.0)*phi;
+        //Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
+        Float_t rad ;
+        if ((deta*deta) + (dphi*dphi)>1.e-7)
+        {
+                rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
+        }else
+        {
+                rad=0.0;
+        }
+
+        if(rad<=fConeRad)
+          {
+        Int_t amplitude = myD->GetAmp();     //Gets the integer valued amplitude of the digit
+        Float_t amp = (Float_t)amplitude;        //Need to typecast to Float_t before doing real energy conversion
+        Float_t digitEnergy = amp/10000000.0;    //Factor of 10 million needed to convert!
+        emcalEnergy += digitEnergy;
+        emcalEnergyBGSub += (digitEnergy - fEBGAve);
+          }//end if
+       }//end count3 for
+
+     //Save in JET object
+     jet.SetTrackList(numTracksInCone,pTArray, etaArray, phiArray, pdgArray);
+     jet.SetEMCALEnergy(emcalEnergy);
+     jet.SetEMCALEnergyBGSub(emcalEnergyBGSub);
+     jet.SetTrackEnergy(trackEnergy);
+     jet.SetTrackEnergyPtCut(trackEnergyPtCut);
+     fOutputPointer->AddJet(&jet);
+     delete[] pTArray;
+     delete[] etaArray;
+     delete[] phiArray;
+     delete[] pdgArray;
+   }
+
+
+ void AliEMCALJetFinderAlgoOmni::FindJets()
+   {
+     //Runs the complete UA1 JetFinding algorithm to find jets!
+     if (fDebug>1) Info("FindJets","Starting Jet Finding!!!");
+
+     //If the array of JetFinderUnit objects has not been initialised then initialise with default settings
+     if(!fArrayInitialised) 
+      {
+       InitUnitArray();
+       FillUnitArray(kFillAll);
+      }//end if
+     if (fDebug>1) Info("FindJets","Unit array filled");
+
+     //Step 1. Sort the array in descending order of Energy
+     Sort(fUnit,fNumUnits);
+
+     //Step 2. Set the number of iterations and Number of jets found to zero to start
+     fNumIter = 0;
+     fNumJets = 0;
+
+     //Step 3. Begin the iteration loop to find jets
+     //Need to iterate the algorithm while number of iterations<2 OR number of iterations<10 AND 
+     //the value of the average background has changed more than specified amount
+     //Min iterations = 2, Max iterations = 10
+     //while(fNumIter<2 || (fNumIter <10 && ( (fEBGTotal-fEBGTotalOld)/fEBGTotal) > fBGMaxMove) )
+
+     while(fNumIter<2 || (fNumIter <10 && ( fEBGTotal-fEBGTotalOld) > fEBGTotal*fBGMaxMove) )
+       {
+        if (fDebug>1) Info("FindJets","Starting BIG iteration ---> %i",fNumIter);
+
+         //Step 4. Find the value of the average background energy
+        FindBG();
+        fOutputPointer->Reset(kResetJets); //Reset output object to store info for new iteration
+        fNumJets=0;
+
+        //Loop over the array of unit objects and flag those with energy below MinCellEt
+         Int_t numbelow = 0;
+        for(Int_t j=0; j<fNumUnits; j++)
+          {
+            if( (fUnit[j].GetUnitEnergy()-fEBGAve) < fEtMin)
+               {       
+                 //          fUnit[j].SetUnitFlag(kBelowMinEt);    TAKING OUT kBelow flag
+                  numbelow++;
+                }//end if
+          }//end for
+        //cout<<"THERE WERE "<<numbelow<<" units with E <EtMin!!!!!!!!!!!!!!!"<<endl;
+
+        //Do quick check if there are no jets upfront
+        // if(fUnit[0].GetUnitFlag() == kBelowMinEt)
+        if( (fUnit[0].GetUnitEnergy()-fEBGAve) < fEtMin)
+          {
+            cout <<"There are no jets for this event!" <<endl;
+           break;
+          }//end if
+
+         //Step 5. Begin with the first jet candidate cell (JET SEED LOOP)
+         if (fDebug>5) Info("FindJets","Beginning JET SEED LOOP");
+        for(Int_t count=0; count<fNumUnits; count++)
+          {
+
+//CHECK CONDITION HERE _ NOT SURE IF SHOULD MAYBE BE: GetUnitEnergy()-fEBGAve >fESeed?????????????????????????????
+            if(fUnit[count].GetUnitEnergy()>=fESeed && fUnit[count].GetUnitFlag()==kOutJet)
+              {
+                fEnergy = fUnit[count].GetUnitEnergy() - fEBGAve;
+                fJetEta = fUnit[count].GetUnitEta();
+                fJetPhi = fUnit[count].GetUnitPhi();
+                Int_t seedID = fUnit[count].GetUnitID();
+                 if (fDebug>5) Info("FindJets","Inside first candidate jet seed loop for time : %i", count);
+                 if (fDebug>5) Info("FindJets","Found candidate energy %f ",fEnergy);
+                 if (fDebug>5) Info("FindJets","Found candidate eta %f ", fJetEta);
+                 if (fDebug>5) Info("FindJets","Found candidate phi %f ", fJetPhi);
+                if (fDebug>5) Info("FindJets","Found candidate ID %i", seedID);
+
+                fEtaInit = fJetEta;
+                fPhiInit = fJetPhi;
+                fEtaB = fJetEta;
+                fPhiB = fJetPhi;
+                Int_t testflag = 1;
+                do
+                  {
+                fJetESum = 0.0;
+                fJetEtaSum = 0.0;
+                fJetPhiSum = 0.0;
+       
+         //Step 6. Find Jet Eta and Phi
+                //Loop over all units in the array to find the ones in the jet cone and determine contrib to Jet eta, phi
+                    for(Int_t count1=0; count1<fNumUnits; count1++)               
+                      {
+                        if(fUnit[count1].GetUnitID() == seedID && testflag)
+                        {
+                                testflag=0;
+                                continue;   //skip unit if the jetseed to avoid doublecounting
+                        }
+                        if(fUnit[count1].GetUnitFlag() == kOutJet)
+                          {
+                            fDEta = fUnit[count1].GetUnitEta() - fJetEta;
+                            fDPhi = fUnit[count1].GetUnitPhi() - fJetPhi;
+                            if ( (fDEta*fDEta) + (fDPhi*fDPhi) >1.e-7)
+                            {
+                                    fRad = TMath::Sqrt( (fDEta*fDEta) + (fDPhi*fDPhi) );
+                            }else
+                            {
+                                    fRad=0.000;
+                            }
+                            if(fRad <= fConeRad)
+                              {
+                                FindJetEtaPhi(count1); 
+                              }//end if
+                          }//end if
+                      }//end for (Jet Eta, Phi LOOP)
+                            
+                     //Find the distance cone centre moved from previous cone centre
+                     if (fDebug>10) Info("FindJets","Checking if cone move small enough");
+                     if (((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB))  >1.e-7)
+                     {
+                             fDistP = TMath::Sqrt( ((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) );
+                     }else
+                     {
+                             fDistP = 0.00;
+                     }
+                     //     if(fDistP <= fMinMove) break;
+                            
+
+                     //Find the distance cone centre is from initiator cell
+                     if (fDebug>10) Info("FindJets","Checking if cone move too large");
+                     if ( ((fJetEtaSum)*(fJetEtaSum))+((fJetPhiSum)*(fJetPhiSum)) >1.e-7)
+                     {
+                             fDistI = TMath::Sqrt( ((fJetEtaSum/fJetESum)*(fJetEtaSum/fJetESum)) + ((fJetPhiSum/fJetESum)*
+                                                                                                   (fJetPhiSum/fJetESum)));
+                     }else
+                     {
+                             fDistI = 0.00;
+                     }
+
+                     if(fDistP>fMinMove && fDistI<fMaxMove)
+                       {
+                         fEtaB = fJetEta;
+                         fPhiB = fJetPhi;
+                       }//end if
+                
+                  }while(fDistP>fMinMove && fDistI<fMaxMove);
+                         
+                fJetEta = fEtaB;
+                fJetPhi = fPhiB;
+
+
+       //Step 7. Find the Jet Energy
+                 if (fDebug>1) Info("FindJets","Looking for Jet energy");
+                fJetESum = 0.0;
+                fJetEtaSum = 0.0;
+                fJetPhiSum = 0.0;
+                fNumInCone = 0;
+                FindJetEnergy();
+
+                //cout<<"Number of cells in jet cone is: "<<fNumInCone<<endl;
+
+       //Step 8. Check if the jet is a valid jet
+                //Check if cluster energy is above Min allowed to be a jet
+//DID NOT DO THE COSH COMPARISON HERE -> NEED TO CHECK WHICH COMPARISON IS BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                 if (fDebug>5) Info("FindJets","Checking cluster is valid jet");
+                if(fJetESum < fJetEMin)
+                  {
+                    for(Int_t count2=0; count2<fNumUnits; count2++)
+                      {
+                        if(fUnit[count2].GetUnitFlag()==kInCurrentJet || fUnit[count2].GetUnitFlag()==kOutJet)
+                          fUnit[count2].SetUnitFlag(kOutJet);
+                      }//end for
+                   if (fDebug>10) Info("FindJets","NOT a valid jet cell");
+                 }else
+                   {
+                    for(Int_t count2=0; count2<fNumUnits; count2++)
+                      {
+                        if(fUnit[count2].GetUnitFlag()==kInCurrentJet)
+                          {
+                            //      cout<<"Setting unit #"<<count2 <<" to be officially in a jet!"<<endl;
+                           fUnit[count2].SetUnitFlag(kInJet);
+                          }
+                      }//end for                       
+
+ //NEED TO CHECK FINAL WEIRD ITERATION OF ETA AND PHI CHANGES!!!!!!!!!
+                    //  fJetPhi += fJetPhiSum/fJetESum;        //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                    //  fJetEta += fJetEtaSum/fJetESum;        //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+                    fNumJets++;              //Incrementing number of jets found
+                    StoreJetInfo();          //Storing jet info
+
+                }//end if (check cluster above Min Jet Energy)
+              }//end if (Jet Seed condition)
+          }//end (JET SEED LOOP)
+
+if (fDebug>5) Info("FindJets","End of BIG iteration number %i",fNumIter);
+// this->Dump();
+        fNumIter++;
+       }//end 10 iteration WHILE LOOP
+ }
+
+
+
+
+
+
+
+
+
+
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderAlgoOmni.h b/EMCAL/jetfinder/AliEMCALJetFinderAlgoOmni.h
new file mode 100644 (file)
index 0000000..41ceaee
--- /dev/null
@@ -0,0 +1,112 @@
+
+#ifndef ALIEMCALJETFINDERALGOOMNI_H
+#define ALIEMCALJETFINDERALGOOMNI_H
+
+//THIS IS SARAH'S REVISED UA1 CODE WITH CHANGES FOR ETA/PHI ITERATION INCLUDED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//THIS Also includes summing ALL cells in the jetcone towards the jet energy NOT just those above threshold!!!!!
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  *  * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//*--Author: Sarah Blyth (LBL)
+//*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
+
+
+#include "TTask.h"
+#include "AliEMCALJetFinderInput.h"
+#include "AliEMCALJetFinderOutput.h"
+#include "AliEMCALJetFinderAlgo.h"
+#include "AliEMCALJetFinderAlgoUA1Unit.h"
+#include "AliEMCALJet.h"
+#include "AliEMCALHadronCorrectionv1.h"
+
+
+class AliEMCALJetFinderAlgoOmni : public AliEMCALJetFinderAlgo
+{
+
+public:
+  AliEMCALJetFinderAlgoOmni();
+  ~AliEMCALJetFinderAlgoOmni();
+  void InitUnitArray();                      
+  void SetNumUnits(Int_t numUnits)           {fNumUnits = numUnits;}
+  Int_t GetNumUnits() const                  {return fNumUnits;}
+  void SetJetESeed(Float_t eSeed)            {fESeed = eSeed;}
+  Float_t GetJetESeed() const                {return fESeed;}
+  void SetConeRad(Float_t coneRad)           {fConeRad = coneRad;}
+  Float_t GetConeRad() const                 {return fConeRad;}
+  void SetJetEMin(Float_t jetEMin)           {fJetEMin = jetEMin;}
+  Float_t GetJetEMin() const                 {return fJetEMin;}
+  void SetEtMin(Float_t etMin)               {fEtMin = etMin;}
+  Float_t GetEtMin() const                   {return fEtMin;}
+  void SetMinMove(Float_t minMove)           {fMinMove = minMove;}
+  void SetMaxMove(Float_t maxMove)           {fMaxMove = maxMove;}
+  void SetBGMaxMove(Float_t bgMaxMove)       {fBGMaxMove = bgMaxMove;}
+  void SetPtCut(Float_t ptCut)               {fPtCut = ptCut;}
+  Float_t GetPtCut() const                   {return fPtCut;}
+  void SetHadronCorrection(AliEMCALHadronCorrectionv1 *hadCorr) {fHadCorr = hadCorr;}
+  AliEMCALHadronCorrectionv1* GetHadronCorrection() const {return fHadCorr;}
+  void SetJetFindingParameters(Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin, 
+                               Float_t minMove, Float_t maxMove, Float_t bgMaxMove); 
+  void SetJetFindingParameters(Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin);
+  void FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag);
+  void SetBGCalcType(AliEMCALJetFinderAlgoBGCalcType_t flag2, Float_t bgPar = -1) {fBGType = flag2; fBGPar = bgPar;}
+  void Sort(AliEMCALJetFinderAlgoUA1Unit* unit,Int_t integer);
+  void FindBG();
+  void RatioBG();
+  void ConeBG();
+  void ConstantBG();
+  void FindJetEtaPhi(Int_t counter);
+  void FindJetEnergy();
+  void StoreJetInfo();
+  void FindJets();
+  void QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right);
+  AliEMCALJetFinderAlgoUA1Unit* GetUnitArrayPointer() const {return fUnit;}
+  AliEMCALJetFinderAlgoUA1Unit* GetUnitArrayPointerNoCuts() const {return fUnitNoCuts;}
+
+protected:
+  AliEMCALJetFinderAlgoUA1Unit   *fUnit; //Array of JetFinder Unit objects (treated as the cells)
+  AliEMCALJetFinderAlgoUA1Unit   *fUnitNoCuts; //Second array of JetFinder Unit objects ('raw data')
+  AliEMCALHadronCorrectionv1 *fHadCorr; //Pointer to Hadron Correction Object
+  AliEMCALJetFinderAlgoBGCalcType_t fBGType; //Method of background calculation to be used 
+  Int_t             fNumIter;          //Number of iterations for entire algorithm
+  Int_t             fNumUnits;         //Number of units in the unit object array (same as num towers in EMCAL)
+  Float_t           fESeed;            //Minimum energy a cell must have to be considered a jet seed
+  Float_t           fConeRad;          //Size of cone radius 
+  Float_t           fJetEMin;          //Minimum energy a cluster must have to be considered a jet
+  Float_t           fEtMin;            //Minimum cell Et cut
+  Float_t           fMinMove;          //Minimum move of jet centre from its previous position
+  Float_t           fMaxMove;          //Maximum move allowed of jet centre from its initiator cell position
+  Float_t           fBGMaxMove;        //Maximum allowed change in background energy between iterations 
+  Float_t           fPtCut;            //Pt cut for tracks to minimise background contribution
+  Float_t           fBGPar;            //Parameter to be used for method of background calculation  
+
+  Float_t           fEBGTotal;         //Total background energy
+  Float_t           fEBGTotalOld;      //Old total background energy
+  Float_t           fEBGAve;           //Average background energy
+  Float_t           fEnergy;           //Energy 
+  Float_t           fJetEta;           //Jet eta value
+  Float_t           fJetPhi;           //Jet phi value
+  Float_t           fEtaInit;          //Jet initiate cell eta
+  Float_t           fPhiInit;          //Jet initiate cell phi
+  Float_t           fEtaB;             //Value of jet eta Before
+  Float_t           fPhiB;             //Value of jet phi Before
+  Float_t           fJetESum;          //Sum of weighted jet energy
+  Float_t           fJetEtaSum;        //Sum of weighted jet eta
+  Float_t           fJetPhiSum;        //Sum of weighted jet phi
+  Float_t           fDEta;             //Offset of unit from jet eta value
+  Float_t           fDPhi;             //Offset of unit from jet phi value
+  Float_t           fDistP;            //Distance of new jet axis position from Previous position
+  Float_t           fDistI;            //Distance of new jet axis position from Initiator cell position
+  Float_t           fTempE;            //Temp E for comparing with JetEMin
+  Float_t           fRad;              //Distance of cell from jet cone centre
+  Int_t             fNumInCone;        //Number of units in the jet cone
+  Int_t             fNumJets;          //Number of jets in an event
+  Bool_t            fArrayInitialised; //To check that array of units is initialised
+
+  ClassDef(AliEMCALJetFinderAlgoOmni,3)
+
+};
+#endif
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderAlgoUA1Unit.cxx b/EMCAL/jetfinder/AliEMCALJetFinderAlgoUA1Unit.cxx
new file mode 100644 (file)
index 0000000..2e398be
--- /dev/null
@@ -0,0 +1,71 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+//  Unit used by UA1 algorithm
+// --
+//*-- Author: Sarah Blyth (LBL/UCT)
+// --
+
+
+#include "AliEMCALJetFinderAlgoUA1Unit.h"
+
+
+ClassImp(AliEMCALJetFinderAlgoUA1Unit)
+
+AliEMCALJetFinderAlgoUA1Unit::AliEMCALJetFinderAlgoUA1Unit()
+{
+       // Default constructor
+      fUnitEnergy         = 0.0;
+      fUnitEta            = 0.0;
+      fUnitPhi            = 0.0;
+      fUnitID             = 0;
+      fUnitFlag           = kOutJet;
+    }  
+
+AliEMCALJetFinderAlgoUA1Unit::~AliEMCALJetFinderAlgoUA1Unit()
+{
+
+}
+       
+Bool_t AliEMCALJetFinderAlgoUA1Unit::operator>(AliEMCALJetFinderAlgoUA1Unit unit) const
+{
+       // Greater than operator used by sort
+  if( fUnitEnergy > unit.GetUnitEnergy())
+    return kTRUE;
+  else 
+    return kFALSE;
+}
+
+Bool_t AliEMCALJetFinderAlgoUA1Unit::operator<( AliEMCALJetFinderAlgoUA1Unit unit) const
+{
+       // Less than operator used by sort
+  if( fUnitEnergy < unit.GetUnitEnergy())
+     return kTRUE;
+  else
+     return kFALSE;
+}
+
+Bool_t AliEMCALJetFinderAlgoUA1Unit::operator==( AliEMCALJetFinderAlgoUA1Unit unit) const
+    {
+           // equality operator used by sort
+      if( fUnitEnergy == unit.GetUnitEnergy())
+        return kTRUE;
+      else
+        return kFALSE;
+    }
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderAlgoUA1Unit.h b/EMCAL/jetfinder/AliEMCALJetFinderAlgoUA1Unit.h
new file mode 100644 (file)
index 0000000..80c09d1
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef ALIEMCALJETFINDERALGOUA1UNIT_H
+#define ALIEMCALJETFINDERALGOUA1UNIT_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  *  * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Unit used by UA1 algorithm
+//
+//*-- Author: Sarah Blyth (LBL/UCT)
+
+
+#include <TObject.h>
+#include "AliEMCALJetFinderTypes.h"
+
+class AliEMCALJetFinderAlgoUA1Unit : public TObject
+{
+ public:
+  AliEMCALJetFinderAlgoUA1Unit();
+  ~AliEMCALJetFinderAlgoUA1Unit();
+  void SetUnitEnergy(Float_t energy)  {fUnitEnergy = energy;}
+  Float_t GetUnitEnergy() const            { return fUnitEnergy;}
+  void SetUnitEta(Float_t eta)        {fUnitEta = eta;} 
+  Float_t GetUnitEta() const               {return fUnitEta;}
+  void SetUnitPhi(Float_t phi)        {fUnitPhi = phi;}
+  Float_t GetUnitPhi() const                {return fUnitPhi;}         
+  void SetUnitID(Int_t id)            {fUnitID = id;}
+  Int_t GetUnitID() const                   {return fUnitID;}
+  
+  void SetUnitFlag(AliEMCALJetFinderAlgoUA1UnitFlagType_t flag)   
+  {
+         fUnitFlag = flag;
+  }
+  
+  AliEMCALJetFinderAlgoUA1UnitFlagType_t GetUnitFlag() const     
+  {
+         return fUnitFlag;
+  }
+  
+  Bool_t operator>  ( AliEMCALJetFinderAlgoUA1Unit unit1) const;
+  Bool_t operator<  ( AliEMCALJetFinderAlgoUA1Unit unit1) const;
+  Bool_t operator== ( AliEMCALJetFinderAlgoUA1Unit unit1) const;
+
+ protected:
+  Float_t         fUnitEnergy;        // Energy of the unit 
+  Float_t         fUnitEta;           // Eta of the unit
+  Float_t         fUnitPhi;           // Phi of the unit
+  Int_t           fUnitID;            // ID of the unit
+  AliEMCALJetFinderAlgoUA1UnitFlagType_t      fUnitFlag; //Flag of the unit
+
+  ClassDef(AliEMCALJetFinderAlgoUA1Unit,3)
+};
+
+#endif
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderInput.cxx b/EMCAL/jetfinder/AliEMCALJetFinderInput.cxx
new file mode 100644 (file)
index 0000000..11e5af8
--- /dev/null
@@ -0,0 +1,305 @@
+/**************************************************************************
+ * 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$ */
+
+
+//________________________________________________________________________
+// Initial JetFinder input object
+// --
+//*-- Author: Mark Horner (LBL/UCT)
+// --
+// --
+// --
+
+
+
+#include "AliEMCALJetFinderInput.h"
+#include "AliEMCALDigit.h"
+#include "AliEMCALGeometry.h"
+#include "AliEMCALParton.h"
+class TClonesArray;
+
+
+ClassImp(AliEMCALJetFinderInput)
+
+AliEMCALJetFinderInput::AliEMCALJetFinderInput(): 
+fDigitsArray(0),
+fTracksArray(0),
+fPartonsArray(0),
+fParticlesArray(0)
+{
+// Default constructor
+// Defines all TClonesArrays  
+// Creates full array of Digits - all other arrays will have objects created as necessary 
+
+  //if (fDebug>0) Info("AliEMCALJetFinderInput","Beginning Constructor");      
+  fDebug=0;
+  fInitialised = kFALSE;
+  fNDigits = 19152;     // This is the number of digits
+  fNMaxDigits = fNDigits;
+  fNMaxTracks = 3000;
+  fNMaxParticles = 2000;
+  fNMaxPartons = 4;
+  fNTracks        = 0;
+  fNPartons       = 0;
+  fNParticles     = 0;
+
+}
+
+void AliEMCALJetFinderInput::InitArrays()
+{
+if (fDebug>0) Info("AliEMCALJetFinderInput","Beginning InitArrays");
+fNDigits = 19152;     // This is the number of digits
+fNMaxDigits = fNDigits;
+fNMaxTracks = 3000;
+fNMaxParticles = 2000;
+fNMaxPartons = 4;
+
+fDigitsArray  = new TClonesArray ("AliEMCALDigit",fNDigits);     // This is the digits array for the EMCAL
+fTracksArray  = new TClonesArray("TParticle",fNMaxTracks);
+fPartonsArray = new TClonesArray("AliEMCALParton",fNMaxPartons);
+fParticlesArray       = new TClonesArray ("TParticle",fNMaxParticles);
+
+for (Int_t i = 0; i < 19152; i++)
+{
+       AliEMCALDigit tempdigit(0,0,i+1,0,1.0,-1);
+       tempdigit.SetAmp(0);
+//      AliEMCALDigit(0,0,i+1,0,1.0,-1)
+       new((*fDigitsArray)[i]) AliEMCALDigit(tempdigit);       // Default digit amplitude is zero
+}
+fNTracks       = 0;
+fNPartons      = 0;
+fNParticles    = 0;
+fInitialised = kTRUE;
+}
+
+
+AliEMCALJetFinderInput::~AliEMCALJetFinderInput()
+{
+// Destructor -
+
+if (fDebug>0) Info("~AliEMCALJetFinderInput","Beginning Destructor");  
+if (fInitialised)
+ {
+       fDigitsArray->Delete();
+       fTracksArray->Delete();
+       fPartonsArray->Delete();
+       fParticlesArray->Delete();
+       delete fDigitsArray;
+       delete fTracksArray;
+       delete fPartonsArray;
+       delete fParticlesArray;
+}
+               
+}
+
+void AliEMCALJetFinderInput::Reset(AliEMCALJetFinderResetType_t resettype)
+{
+// Clears the contents of all the arrays and returns to the state we were in 
+// after the constructor
+if (fDebug>1) Info("Reset","Beginning Reset"); 
+  
+  if (!fInitialised) InitArrays();     
+
+  if (         resettype == kResetData   ||    
+       resettype == kResetDigits ||
+       resettype == kResetAll   ){
+               if (fInitialised)
+               {       
+                       fDigitsArray->Delete();                 
+                       fTracksArray->Delete();
+                       fPartonsArray->Delete();
+                       fParticlesArray->Delete();
+               }
+               for (Int_t i = 0; i < 19152; i++)
+               {
+                       AliEMCALDigit tempdigit(0,0,i+1,0,1.0,-1);
+                       tempdigit.SetAmp(0);
+                       new((*fDigitsArray)[i]) AliEMCALDigit(tempdigit);       // Default digit amplitude is zero
+               }
+  }
+  if (  resettype == kResetData   ||    
+        resettype == kResetTracks ||
+        resettype == kResetAll   ){
+         fNTracks = 0;
+  }
+ if (  resettype == kResetData    ||
+       resettype == kResetPartons ||
+       resettype == kResetAll   ){
+        fNPartons=0;
+ }
+ if (  resettype == kResetData      ||
+       resettype == kResetParticles ||
+       resettype == kResetAll   ){
+        fNParticles = 0;
+ }
+
+}
+void AliEMCALJetFinderInput::AddEnergyToDigit(Int_t digitID,Int_t denergy)
+{
+// Adds energy to the digit specified - Note these are tower IDs and
+// so start at 1!
+               
+if (fDebug>15) Info("AddEnergyToDigit","Beginning AddEnergyToDigit");
+ if (!fInitialised) InitArrays();      
+
+ Int_t amp = 0;
+ AliEMCALDigit *mydigit = (AliEMCALDigit*)(*fDigitsArray)[digitID];
+ amp = mydigit->GetAmp();
+ mydigit->SetAmp(amp+denergy);
+}      
+
+void AliEMCALJetFinderInput::AddTrack(TParticle track)
+{
+// Adds a TParticle to the track array
+               
+if (fDebug>5) Info("AddTrack","Beginning AddTrack");
+       if (!fInitialised) InitArrays();        
+       if (fNTracks < fNMaxTracks){  
+               new((*fTracksArray)[fNTracks]) TParticle(track);
+               fNTracks++;
+               if (fDebug>5) Info("AddTracks","Added Tracks %i",fNTracks);     
+       }else
+       {
+               Error("AddTracks","Cannot AddTrack - maximum exceeded");
+       }
+
+}
+
+void AliEMCALJetFinderInput::AddTrack(TMCParticle *track)
+{
+// Adds a TParticle to the particle array
+       
+if (fDebug>5) Info("AddTrack","Beginning AddTrack");   
+
+ if (!fInitialised) InitArrays();      
+ if (fNTracks < fNMaxTracks){  
+   new((*fTracksArray)[fNTracks]) 
+     TParticle(track->GetKF(), track->GetKS(), track->GetParent(), 0,
+              track->GetFirstChild(), track->GetLastChild(),
+              track->GetPx(), track->GetPy(), track->GetPz(), 
+              track->GetEnergy(), 
+              track->GetVx(), track->GetVy(), track->GetVz(), 
+              track->GetTime());
+   fNTracks++;
+   if (fDebug>5) Info("AddTrack","Added Track %i",fNTracks);   
+ } else {
+   Error("AddTrack","Cannot AddTrack - maximum exceeded");
+ }     
+}
+
+
+void AliEMCALJetFinderInput::AddParton(AliEMCALParton *parton)
+{
+// Adds an AliEMCALParton to the parton array 
+       
+if (fDebug>5) Info("AddParton","Beginning AddParton");
+
+       if (!fInitialised) InitArrays();        
+       if (fNPartons < fNMaxPartons){  
+               new((*fPartonsArray)[fNPartons]) AliEMCALParton(*parton);
+               fNPartons++;
+               if (fDebug>5) Info("AddParton","Added Parton %i",fNPartons);    
+       }else
+       {
+               Error("AddParton","Cannot AddParton - maximum exceeded");
+       }
+}
+
+void AliEMCALJetFinderInput::AddParticle(TParticle *particle)
+{
+// Adds a TParticle to the particle array
+       
+if (fDebug>5) Info("AddParticle","Beginning AddParticle");     
+
+       if (!fInitialised) InitArrays();        
+       if (fNParticles < fNMaxParticles){  
+               new((*fParticlesArray)[fNParticles]) TParticle(*particle);
+               fNParticles++;
+               if (fDebug>5) Info("AddParticle","Added Particle %i",fNParticles);      
+       }else
+       {
+               Error("AddParticle","Cannot AddParticle - maximum exceeded");
+       }
+
+}
+
+void AliEMCALJetFinderInput::AddParticle(TMCParticle *particle)
+{
+// Adds a TParticle to the particle array
+       
+if (fDebug>5) Info("AddParticle","Beginning AddParticle");     
+
+ if (!fInitialised) InitArrays();      
+ if (fNParticles < fNMaxParticles){  
+   new((*fParticlesArray)[fNParticles]) 
+     TParticle(particle->GetKF(), particle->GetKS(), particle->GetParent(), 0,
+              particle->GetFirstChild(), particle->GetLastChild(),
+              particle->GetPx(), particle->GetPy(), particle->GetPz(), 
+              particle->GetEnergy(), 
+              particle->GetVx(), particle->GetVy(), particle->GetVz(), 
+              particle->GetTime());
+   fNParticles++;
+   if (fDebug>5) Info("AddParticle","Added Particle %i",fNParticles);  
+ } else {
+   Error("AddParticle","Cannot AddParticle - maximum exceeded");
+ }     
+}
+
+
+AliEMCALDigit* AliEMCALJetFinderInput::GetDigit(Int_t digitID)
+{
+// Returns a pointer to an AliEMCALDigit with the given ID
+       
+if (fDebug>15) Info("GetDigit","Beginning GetDigit");
+
+    if (digitID >= fNDigits) return 0;
+    return (AliEMCALDigit*)((*fDigitsArray)[digitID]);
+}
+
+TParticle* AliEMCALJetFinderInput::GetTrack(Int_t trackID)
+{
+// Returns a pointer to a TParticle specified by the ID
+       
+if (fDebug>15) Info("GetTrack","Beginning GetTrack with trackID %i",trackID);
+
+    if (trackID >= fNTracks) return 0;
+    return (TParticle*)((*fTracksArray)[trackID]);
+}
+
+AliEMCALParton* AliEMCALJetFinderInput::GetParton(Int_t partonID)
+{
+// Returns a pointer to an AliEMCALParton  specified by the ID
+       
+if (fDebug>15) Info("GetParton","Beginning GetParton");
+
+    if (partonID >= fNPartons) return 0;
+    return (AliEMCALParton*)((*fPartonsArray)[partonID]);
+}
+
+TParticle* AliEMCALJetFinderInput::GetParticle(Int_t particleID)
+{
+// Returns a pointer to a TParticle specified by the ID
+       
+if (fDebug>15) Info("GetParticle","Beginning GetParticle");
+
+    if (particleID >= fNParticles) return 0;
+    return (TParticle*)((*fParticlesArray)[particleID]);
+}
+
+
+       
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderInput.h b/EMCAL/jetfinder/AliEMCALJetFinderInput.h
new file mode 100644 (file)
index 0000000..8c917b8
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef ALIEMCALJETFINDERINPUT_H
+#define ALIEMCALJETFINDERINPUT_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  *  * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Initial input object for jetfinder
+//
+//*-- Author: Mark Horner (LBL/UCT)
+//
+//
+
+
+#include "TObject.h"
+#include "TParticle.h"
+#include "TMCParticle6.h"
+#include "TClonesArray.h"
+#include "AliEMCALParton.h"
+#include "AliEMCALDigit.h"
+#include "AliEMCALJetFinderTypes.h"
+
+class AliEMCALJetFinderInput : public TObject
+{
+       public:
+               AliEMCALJetFinderInput();
+               ~AliEMCALJetFinderInput();
+               void Reset(AliEMCALJetFinderResetType_t resettype);
+               void SetDebug(Int_t debug=0){fDebug = debug;}
+               void AddEnergyToDigit(Int_t digitID,Int_t denergy); 
+               void AddTrack(TParticle track);
+               void AddTrack(TMCParticle *track);
+               void AddParton(AliEMCALParton *parton);
+               void AddParticle(TParticle *particle);
+               void AddParticle(TMCParticle *particle);
+               AliEMCALDigit* GetDigit(Int_t digitID);
+               Int_t GetNDigits() const {return fNDigits;}
+               TParticle* GetTrack(Int_t trackID);
+               Int_t GetNTracks() const {return fNTracks;}
+               AliEMCALParton* GetParton(Int_t partonID);
+               Int_t GetNPartons() const {return fNPartons;}
+               TParticle* GetParticle(Int_t particleID);
+               Int_t GetNParticles() const {return fNParticles;}
+
+       private:
+               void InitArrays();
+               TClonesArray*   fDigitsArray;   //-> This is the digits array for the EMCAL
+               Int_t           fNDigits;       // This is the number of digits
+               Int_t           fNMaxDigits;    // This is the max number of digits
+               TClonesArray*   fTracksArray;   //-> This is the track array 
+               Int_t           fNTracks;       // This stores the number of tracks     
+               Int_t           fNMaxTracks;    // This stores the maximum number of tracks
+               TClonesArray*   fPartonsArray;  //->  This is the partons array
+               Int_t           fNPartons;      // This stores the number of partons
+               Int_t           fNMaxPartons;   // This stores the maximum number of partons
+               TClonesArray*   fParticlesArray;//-> This stores the particles  
+               Int_t           fNParticles;    // This stores the number of particles
+               Int_t           fNMaxParticles; // This stroes the maximum number of particles
+               Int_t           fDebug;         // This is the debug value 
+               Bool_t          fInitialised;   // Stores whether or not the arrays have been initialised 
+               
+       ClassDef(AliEMCALJetFinderInput,5)
+};
+#endif
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderInputPrep.cxx b/EMCAL/jetfinder/AliEMCALJetFinderInputPrep.cxx
new file mode 100644 (file)
index 0000000..752b8e9
--- /dev/null
@@ -0,0 +1,93 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+//  Base Class for JetFinder Input Preparation
+// --
+//*-- Author: Mark Horner (LBL/UCT)
+// --
+
+
+
+#include <stdio.h>
+#include <TClonesArray.h>
+#include <TParticle.h>
+#include <TTree.h>
+#include "Riostream.h"
+//.....................
+#include "AliEMCALJet.h"
+#include "AliEMCALParton.h"
+#include "AliEMCALJetFinderInputPrep.h"
+#include "AliEMCALJetFinderInput.h"
+
+ClassImp(AliEMCALJetFinderInputPrep)
+
+//________________________________________________________________________
+AliEMCALJetFinderInputPrep::AliEMCALJetFinderInputPrep()
+{
+       // Default constructor
+if (fDebug > 0) Info("AliEMCALJetFinderInputPrep","Beginning Constructor");    
+  fDebug = 0;
+  fPythiaComparison = 0; // This requires lots of checks 
+  fInputObject.SetDebug(0);
+}
+AliEMCALJetFinderInputPrep::~AliEMCALJetFinderInputPrep()
+{
+
+}
+
+Int_t AliEMCALJetFinderInputPrep::FillFromFile(TString * /*filename*/,
+                                              AliEMCALJetFinderFileType_t /*fileType*/,
+                                              Int_t /*EventNumber*/)
+{
+  return 0;
+}
+void AliEMCALJetFinderInputPrep::Reset(AliEMCALJetFinderResetType_t resettype)
+{ 
+       //  Reset data
+if (fDebug > 1) Info("Reset","Beginning Reset");
+       
+       switch (resettype){
+               case kResetData:
+                       fInputObject.Reset(resettype);
+                       break;
+               case kResetTracks:
+                       fInputObject.Reset(kResetTracks);
+                       break;
+               case kResetDigits:
+                       fInputObject.Reset(kResetDigits);
+                       break;
+               case kResetParameters:
+                       break;
+               case kResetAll:
+                       fInputObject.Reset(kResetAll);
+                       break;
+               case kResetPartons:
+                 Warning("FillFromFile", "kResetPartons not implemented") ; 
+                 break;
+              case kResetParticles:
+                Warning("FillFromFile", "kResetParticles not implemented") ; 
+                break;
+              case kResetJets:
+                Warning("FillFromFile", "kResetJets not implemented") ; 
+                break;
+       }// end switch
+
+}
+
+
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderInputPrep.h b/EMCAL/jetfinder/AliEMCALJetFinderInputPrep.h
new file mode 100644 (file)
index 0000000..40d44c2
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef ALIEMCALJETFINDERINPUTPREP_H
+#define ALIEMCALJETFINDERINPUTPREP_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  *  * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Base class for jetfinder input preparation 
+//
+//*-- Author: Mark Horner (LBL/UCT)
+//
+
+
+
+#include "TTask.h"
+#include "AliEMCALJetFinderInput.h"
+#include "AliEMCALJetFinderTypes.h"
+
+class AliEMCALJetFinderInputPrep : public TTask
+{
+               
+       public:
+       AliEMCALJetFinderInputPrep();
+       ~AliEMCALJetFinderInputPrep();
+       void Reset(AliEMCALJetFinderResetType_t resettype);
+       void SetDebug(Int_t debug = 0){fDebug = debug; fInputObject.SetDebug(debug-2); }
+       Int_t FillFromFile(TString *filename, AliEMCALJetFinderFileType_t filetype, Int_t EventNumber);
+       AliEMCALJetFinderInput* GetJetFinderInput()  {return &fInputObject;}
+       void SetPythiaComparison(Bool_t value) {fPythiaComparison = value;}
+       Bool_t GetPythiaComparison() {return fPythiaComparison;}
+       protected:
+       Int_t           fDebug; // The debug flag to be used for messages
+       AliEMCALJetFinderInput  fInputObject;   // The JetFinder input object to be filled
+       Bool_t          fPythiaComparison;      // Special flag for pyclus comparison
+       private:
+
+       ClassDef(AliEMCALJetFinderInputPrep,3)
+       
+};
+#endif
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderInputSimPrep.cxx b/EMCAL/jetfinder/AliEMCALJetFinderInputSimPrep.cxx
new file mode 100644 (file)
index 0000000..df12d77
--- /dev/null
@@ -0,0 +1,688 @@
+/**************************************************************************
+ * 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 JetFinder Input preparation from simulated data 
+//
+//*-- Author: Mark Horner (LBL/UCT)
+//
+
+
+
+#include "AliEMCALJetFinderInputSimPrep.h"
+
+#include <TParticle.h>
+#include <TParticlePDG.h>
+#include <TPDGCode.h>
+#include <TFile.h>
+#include <TTree.h>
+#include <TObjectTable.h>
+#include <TMath.h>
+
+
+#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliStack.h"
+#include "AliMagF.h"
+#include "AliEMCALFast.h"
+#include "AliEMCAL.h"
+#include "AliEMCALHit.h"
+#include "AliEMCALGeometry.h"
+#include "AliEMCALLoader.h"
+#include "AliGenEventHeader.h"
+#include "AliGenPythiaEventHeader.h"
+#include "AliGenerator.h"
+#include "AliHeader.h"
+#include "AliMC.h"
+
+
+
+ClassImp(AliEMCALJetFinderInputSimPrep)
+       
+AliEMCALJetFinderInputSimPrep::AliEMCALJetFinderInputSimPrep()
+{
+       // Default constructor
+if (fDebug > 0) Info("AliEMCALJetFinderInputSimPrep","Beginning Constructor"); 
+  
+  fDebug = 0;
+  fSmearType = kSmearEffic;
+  fEMCALType = kHits;
+  fTrackType = kCharged;
+  fEfficiency = 0.90;
+  
+}
+AliEMCALJetFinderInputSimPrep::~AliEMCALJetFinderInputSimPrep()
+{
+if (fDebug > 0) Info("~AliEMCALJetFinderInputSimPrep","Beginning Destructor"); 
+       
+}
+
+void AliEMCALJetFinderInputSimPrep::Reset(AliEMCALJetFinderResetType_t resettype)
+{
+       // Method to reset data
+  if (fDebug > 1) Info("Reset","Beginning Reset");
+       switch (resettype){
+
+       case kResetData:
+               fInputObject.Reset(resettype);
+               break;
+       case kResetTracks:
+               fInputObject.Reset(resettype);
+               break;
+       case kResetDigits:
+               fInputObject.Reset(resettype);
+               break;
+       case kResetParameters:
+               fSmearType = kSmearEffic;
+               fEMCALType = kHits;
+               fTrackType = kCharged;
+               break;
+       case kResetAll:
+               fSmearType = kSmearEffic;
+               fEMCALType = kHits;
+               fTrackType = kCharged;
+               fInputObject.Reset(resettype);
+               break;
+       case kResetPartons:
+         Warning("FillFromFile", "kResetPartons not implemented") ; 
+         break;
+       case kResetParticles:
+         Warning("FillFromFile", "kResetParticles not implemented") ; 
+         break;
+       case kResetJets:
+         Warning("FillFromFile", "kResetJets not implemented") ; 
+         break;
+       }// end switch
+
+}
+
+Int_t AliEMCALJetFinderInputSimPrep::FillFromFile(TString *filename, AliEMCALJetFinderFileType_t filetype,Int_t EventNumber,TString data)
+{
+  if (fDebug > 1) Info("FillFromFile","Beginning FillFromFile");
+  fFileType = filetype;        
+  AliRunLoader *rl=AliRunLoader::Open(filename->Data());
+  if (fDebug > 1) Info("FillFromFile","Opened file %s",filename->Data());
+   if (data.Contains("S"))
+   {
+          rl->LoadKinematics();
+          rl->LoadSDigits();
+          rl->GetEvent(EventNumber);
+   }else
+   {
+          rl->LoadKinematics();
+          rl->LoadHits();
+          rl->GetEvent(EventNumber);
+   }
+   if (fDebug > 1) Info("FillFromFile","Got event %i with option \"XH\"",EventNumber);
+
+   if (        fEMCALType == kHits ||
+       fEMCALType == kTimeCut )  
+   {
+          if (data.Contains("S"))
+          {
+                  FillSDigits();
+          }else
+          {
+                   FillHits();
+          }
+   }
+   if ( fTrackType != kNoTracks  )  FillTracks();      
+   if ( fFileType  != kData){
+          FillPartons();
+   }
+   return 0;   
+}
+
+void AliEMCALJetFinderInputSimPrep::FillHits()         
+{
+       // Fill from the hits to input object from simulation
+if (fDebug > 1) Info("FillHits","Beginning FillHits");
+       
+// Access hit information
+//  AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
+//  Info("AliEMCALJetFinderInputSimPrep","Title of the geometry is %s",pEMCAL->GetTitle());
+    AliEMCALGeometry* geom =  AliEMCALGeometry::GetInstance();
+    AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
+
+    //    TTree *treeH = AliEMCALGetter::Instance()->TreeH();
+//    Int_t ntracks = (Int_t) treeH->GetEntries();
+//
+//   Loop over tracks
+//
+    Double_t etH = 0.0;
+
+/*    for (Int_t track=0; track<ntracks;track++) {
+        gAlice->ResetHits();
+        nbytes += treeH->GetEvent(track);*/
+//
+//  Loop over hits
+//
+        for(Int_t i =0; i < emcalLoader->Hits()->GetEntries() ;i++)
+        {
+           const AliEMCALHit *mHit = emcalLoader->Hit(i);      
+           if (fEMCALType == kTimeCut && 
+                   (mHit->GetTime()>fTimeCut) ) continue;
+            Float_t x      =    mHit->X();         // x-pos of hit
+            Float_t y      =    mHit->Y();         // y-pos
+            Float_t z      =    mHit->Z();         // z-pos
+            Float_t eloss  =    mHit->GetEnergy(); // deposited energy
+
+            Float_t r      =    TMath::Sqrt(x*x+y*y);
+            Float_t theta  =    TMath::ATan2(r,z);
+            Float_t eta    =   -TMath::Log(TMath::Tan(theta/2.));
+            Float_t phi    =    TMath::ATan2(y,x);
+            etH = eloss*TMath::Sin(theta);
+           if (fDebug > 10) Info("FillHits","Values of hit energy %i",Int_t(1e7*etH));
+           if (geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi) == -1) 
+           {
+                   if (fDebug >5)  
+                   {
+                           Error("FillHits","Hit not inside EMCAL!");
+                           mHit->Dump();
+                   }
+                   continue;
+           }
+            fInputObject.AddEnergyToDigit(geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi)-1,Int_t(1e7*etH));
+        } // Hit Loop
+//    } // Track Loop
+
+
+}
+void AliEMCALJetFinderInputSimPrep::FillTracks()       
+{
+       // Fill from particles simulating a TPC to input object from simulation
+    if (fDebug > 1) Info("FillTracks","Beginning FillTracks");
+       
+    AliRunLoader *rl = AliRunLoader::GetRunLoader();
+    TParticlePDG* pdgP = 0;
+    TParticle *mPart;
+    Int_t npart = rl->Stack()->GetNprimary();
+    if (fDebug > 1) Info("FillTracks","Header says there are %i primaries",npart);
+    Float_t bfield,rEMCAL;              
+    
+    if (fDebug > 1) Info("FillTracks","Defining the geometry");
+    
+    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
+    AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
+    if (geom == 0 && pEMCAL) 
+      geom = AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
+    if (geom == 0) 
+      geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","");//","SHISH_77_TRD1_2X2_FINAL_110DEG");
+    fEtaMax = geom->GetArm1EtaMax();
+    fEtaMin = geom->GetArm1EtaMin();
+    fPhiMax = TMath::Pi()/180.0*geom->GetArm1PhiMax();
+    fPhiMin = TMath::Pi()/180.0*geom->GetArm1PhiMin();
+
+    if (fDebug > 1) Info("FillTracks","Starting particle loop");
+           
+    if (fDebug > 1) Info("FillTracks","Particle loop of %i",npart);
+    for (Int_t part = 0; part < npart; part++) {
+       mPart = rl->Stack()->Particle(part);
+       pdgP = mPart->GetPDG();
+
+       if (fDebug > 5) Info("FillTracks","Checking if track is a primary");
+       
+       if (fFileType == kPythia) {
+           if (mPart->GetStatusCode() != 1) continue;
+       } else if (fFileType == kHijing) {
+           if (mPart->GetFirstDaughter() >= 0 && mPart->GetFirstDaughter() < npart) continue;
+       }
+       
+       if (fDebug > 15) Info("FillTracks","Checking if track (eta - %f, phi - %f) is in acceptance",mPart->Eta(),mPart->Phi());
+       if (fDebug > 10) Info("FillTracks","Checking if EMCAL acceptance  ( %f < eta < %f, %f < phi < %f) is in acceptance",fEtaMin,fEtaMax,fPhiMin,fPhiMax);
+
+       if ((!fPythiaComparison)&&(mPart->Eta() > fEtaMax || mPart->Eta() < fEtaMin))   continue;
+       if ((!fPythiaComparison)&&(mPart->Phi() > fPhiMax || mPart->Phi() < fPhiMin))   continue;
+       
+/*
+       {kProton, kProtonBar, kElectron, kPositron,
+         kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
+         kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
+         kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
+         kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
+         0,kNuMu,kNuMuBar
+*/
+
+       if (fDebug > 15) Info("FillTracks","Checking if track is rejected");
+
+       if ((fSmearType == kEfficiency  ||
+             fSmearType == kSmearEffic)        && 
+            pdgP->Charge()!=0) {
+           if (AliEMCALFast::RandomReject(fEfficiency)) {
+               continue;
+            }
+       }
+
+       if (gAlice && gAlice->Field()) 
+         bfield = gAlice->Field()->SolenoidField();
+       else
+         bfield = 0.4;
+       rEMCAL = AliEMCALGeometry::GetInstance()->GetIPDistance();
+       Float_t rB = 3335.6 * mPart->Pt() / bfield;  // [cm]  (case of |charge|=1)
+       if (2.*rB < rEMCAL) continue;  // track curls away
+       
+       //if (part%10) gObjectTable->Print();
+        switch(fTrackType)
+        {
+
+          case kAllP:  // All Stable particles to be included
+               if (fDebug > 5) Info("FillTracks","Storing track");
+               if (fSmearType == kSmear ||
+                   fSmearType == kSmearEffic ){
+                       Smear(mPart);/*
+                       TParticle *tmp = Smear(MPart);
+                       fInputObject.AddTrack(Smear(MPart));
+                       delete tmp;*/
+               }else{
+                       fInputObject.AddTrack(*mPart);
+               }
+          break;
+          case kEM:   // All Electromagnetic particles
+               if (mPart->GetPdgCode() == kElectron  ||
+                    mPart->GetPdgCode() == kMuonPlus  || 
+                    mPart->GetPdgCode() == kMuonMinus ||
+                   mPart->GetPdgCode() == kPositron ){
+                     if (fDebug > 5) Info("FillTracks","Storing electron or positron");
+                     if (fSmearType == kSmear ||
+                           fSmearType == kSmearEffic ){
+                             Smear(mPart);/*
+                             TParticle *tmp = Smear(MPart); 
+                             fInputObject.AddTrack(tmp);
+                             delete tmp;*/
+                     }else{
+                         fInputObject.AddTrack(*mPart);
+                     }
+               }
+               if ( mPart->GetPdgCode() == kGamma ){ 
+                       fInputObject.AddTrack(*mPart);
+                       if (fDebug > 5) Info("FillTracks","Storing gamma");
+               }
+                       
+          break;
+           case kCharged: // All Particles with non-zero charge
+               if (pdgP->Charge() != 0) {
+                       if (fDebug > 5) Info("FillTracks","Storing charged track");
+                       if (fSmearType == kSmear ||
+                           fSmearType == kSmearEffic ){
+                               Smear(mPart);/*
+                               TParticle *tmp = Smear(MPart);
+                               fInputObject.AddTrack(tmp);
+                               delete tmp;*/
+                       }else{
+                        fInputObject.AddTrack(*mPart);
+                       }
+               }
+          break;
+          case kNeutral: // All particles with no charge
+               if (pdgP->Charge() == 0){ 
+                       fInputObject.AddTrack(*mPart);
+                       if (fDebug > 5) Info("FillTracks","Storing neutral");
+               }
+          break;
+          case kHadron: //All hadrons
+               if (mPart->GetPdgCode() != kElectron  &&
+                    mPart->GetPdgCode() != kPositron  &&
+                    mPart->GetPdgCode() != kMuonPlus  &&
+                    mPart->GetPdgCode() != kMuonMinus &&
+                    mPart->GetPdgCode() != kGamma ) 
+               {
+                       if (fDebug > 5) Info("FillTracks","Storing hadron");
+                       if (pdgP->Charge() == 0){
+                           fInputObject.AddTrack(*mPart);
+                       }else{
+                               if (fSmearType == kSmear ||
+                                   fSmearType == kSmearEffic ){
+                                       Smear(mPart);/*
+                                       TParticle *tmp = Smear(MPart);  
+                                       fInputObject.AddTrack(tmp);
+                                       delete tmp;*/
+                               }else{
+                                   fInputObject.AddTrack(*mPart);
+                               }
+                       }
+               }
+          break;
+          case kChargedHadron:  // only charged hadrons
+               if (mPart->GetPdgCode() != kElectron  &&
+                    mPart->GetPdgCode() != kPositron  &&
+                    mPart->GetPdgCode() != kGamma     &&
+                    mPart->GetPdgCode() != kMuonPlus  &&
+                    mPart->GetPdgCode() != kMuonMinus &&
+                   pdgP->Charge()      != 0       ){
+                       if (fDebug > 5) Info("FillTracks","Storing charged hadron");
+                       if (fSmearType == kSmear ||
+                           fSmearType == kSmearEffic ){
+                               Smear(mPart);/*
+                               TParticle *tmp = Smear(MPart);
+                               fInputObject.AddTrack(tmp);
+                               delete tmp;*/
+                       }else{
+                              fInputObject.AddTrack(*mPart);
+                       }
+               }
+          break;
+          case kNoTracks:
+          break;
+          case kEMChargedPi0:
+               if (pdgP->Charge() != 0 || mPart->GetPdgCode() == kPi0  ||
+                       mPart->GetPdgCode() == kGamma     )
+               {
+                       if (fDebug > 5) Info("FillTracks","Storing charged track");
+                       if (fSmearType == kSmear ||
+                           fSmearType == kSmearEffic ){
+                               Smear(mPart);/*
+                               TParticle *tmp = Smear(MPart);
+                               fInputObject.AddTrack(tmp);
+                               delete tmp;*/
+                       }else{
+                        fInputObject.AddTrack(*mPart);
+                       }
+               }
+          break;
+          case kNoNeutronNeutrinoKlong:
+               if ( mPart->GetPdgCode() != kNeutron    &&
+                    mPart->GetPdgCode() != kNeutronBar &&
+                    mPart->GetPdgCode() != kK0Long     &&
+                    mPart->GetPdgCode() != kNuE        &&
+                     mPart->GetPdgCode() != kNuEBar     &&
+                     mPart->GetPdgCode() != kNuMu       &&
+                     mPart->GetPdgCode() != kNuMuBar    &&
+                     mPart->GetPdgCode() != kNuTau      &&
+                     mPart->GetPdgCode() != kNuTauBar   )
+               {
+                       if (fDebug > 5) Info("FillTracks","Storing charged track");
+                       if (fSmearType == kSmear ||
+                                       fSmearType == kSmearEffic ){
+                               Smear(mPart);/*
+                                               TParticle *tmp = Smear(MPart);
+                                               fInputObject.AddTrack(tmp);
+                                               delete tmp;*/
+                       }else{
+                               fInputObject.AddTrack(*mPart);
+                       }
+               }
+          break;
+          default:
+          break;
+          //      delete mPart;
+        }      //end of switch
+//     Info("FillTracks","After Particle Storage");
+       //if (part%10) gObjectTable->Print();
+
+   }   //end of particle loop
+   //gObjectTable->Print();    
+}
+
+void AliEMCALJetFinderInputSimPrep::FillPartons()      
+{
+       // Fill partons to
+       // input object from simulation
+if (fDebug > 1) Info("FillPartons","Beginning FillPartons");
+
+  AliRunLoader *rl = AliRunLoader::GetRunLoader();
+  AliGenEventHeader* evHeader = rl->GetHeader()->GenEventHeader();
+  Float_t triggerJetValues[4];
+  AliEMCALParton tempParton;
+  
+  if (fFileType == kPythia)
+  {
+       Int_t ntriggerjets = ((AliGenPythiaEventHeader*)evHeader)->NTriggerJets();
+       if (fDebug > 1) Info("FillPartons","Number of trigger jets --> %i",ntriggerjets);
+               for (Int_t jetcounter = 0 ; jetcounter < ntriggerjets; jetcounter++){
+       ((AliGenPythiaEventHeader*)evHeader)->TriggerJet(jetcounter,triggerJetValues);
+               TLorentzVector tempLParton;
+               tempLParton.SetPxPyPzE(triggerJetValues[0],triggerJetValues[1],triggerJetValues[2],triggerJetValues[3]);
+       tempParton.SetEnergy(tempLParton.Energy());
+       tempParton.SetEta(tempLParton.Eta());
+       tempParton.SetPhi(tempLParton.Phi());
+       FillPartonTracks(&tempParton);
+       fInputObject.AddParton(&tempParton);
+       }
+         
+  }
+}
+
+void AliEMCALJetFinderInputSimPrep::FillParticles()            
+{
+       // Fill particles to input object from simulation
+if (fDebug > 1) Info("FillParticles","Beginning FillParticles");
+
+    Int_t npart = (gAlice->GetHeader())->GetNprimary();
+    TParticlePDG* pdgP = 0;
+    for (Int_t part = 0; part < npart; part++) {
+       TParticle *mPart = gAlice->GetMCApp()->Particle(part);
+       pdgP = mPart->GetPDG();
+       
+       if (fDebug > 10) Info("FillParticles","Checking if particle is a primary");
+       
+       if (fFileType == kPythia) {
+           if (mPart->GetStatusCode() != 1) continue;
+       } else if (fFileType == kHijing) {
+           if (mPart->GetFirstDaughter() >= 0 && mPart->GetFirstDaughter() < npart) continue;
+       }
+
+       if (fDebug > 10) Info("FillParticles","Checking if particle is in acceptance");
+       
+       if ((!fPythiaComparison)&&(mPart->Eta() > fEtaMax || mPart->Eta() < fEtaMin))   continue;
+       if ((!fPythiaComparison)&&(mPart->Phi() > fPhiMax || mPart->Phi() < fPhiMin))   continue;
+       
+
+/*
+       {kProton, kProtonBar, kElectron, kPositron,
+         kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
+         kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
+         kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
+         kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
+         0,kNuMu,kNuMuBar
+*/
+        switch(fTrackType)
+        {
+
+          case kAllP:  // All Stable particles to be included
+               if (fDebug > 5) Info("FillParticles","Storing particle");
+               fInputObject.AddParticle(mPart);
+          break;
+          case kEM:   // All Electromagnetic particles
+               if (mPart->GetPdgCode() == kElectron ||
+                   mPart->GetPdgCode() == kPositron ||
+                   mPart->GetPdgCode() == kGamma){
+                       if (fDebug > 5) Info("FillParticles","Storing electromagnetic particle");
+                       fInputObject.AddParticle(mPart);
+               }
+          break;
+           case kCharged: // All Particles with non-zero charge
+               if (pdgP->Charge() != 0) {
+                       if (fDebug > 5) Info("FillParticles","Storing charged particle");
+                       fInputObject.AddParticle(mPart);
+               }
+          break;
+          case kNeutral: // All particles with no charge
+               if (pdgP->Charge() == 0){
+                       if (fDebug > 5) Info("FillParticles","Storing neutral particle");
+                       fInputObject.AddParticle(mPart);
+               }
+          break;
+          case kHadron: //All hadrons
+               if (mPart->GetPdgCode() != kElectron &&
+                    mPart->GetPdgCode() != kPositron &&
+                    mPart->GetPdgCode() != kGamma ) 
+               {
+
+               if (fDebug > 5) Info("FillParticles","Storing hadron");
+                   fInputObject.AddParticle(mPart);
+               }
+          break;
+          case kChargedHadron:  // only charged hadrons
+               if (mPart->GetPdgCode() != kElectron &&
+                    mPart->GetPdgCode() != kPositron &&
+                    mPart->GetPdgCode() != kGamma    &&
+                   pdgP->Charge()      != 0       ){
+               if (fDebug > 5) Info("FillParticles","Storing charged hadron");
+                      fInputObject.AddParticle(mPart);
+               }
+          break;
+          case kNoTracks:
+          break;
+          case kEMChargedPi0:
+               if (pdgP->Charge() != 0 || mPart->GetPdgCode() == kPi0  ||
+                       mPart->GetPdgCode() == kGamma     )
+               {
+                       if (fDebug > 5) Info("FillTracks","Storing kEMChargedPi0 track");
+                       if (fSmearType == kSmear ||
+                           fSmearType == kSmearEffic ){
+                               Smear(mPart);/*
+                               TParticle *tmp = Smear(MPart);
+                               fInputObject.AddTrack(tmp);
+                               delete tmp;*/
+                       }else{
+                        fInputObject.AddTrack(*mPart);
+                       }
+               }
+          break;
+          case kNoNeutronNeutrinoKlong:
+               if ( mPart->GetPdgCode() != kNeutron    &&
+                    mPart->GetPdgCode() != kNeutronBar &&
+                    mPart->GetPdgCode() != kK0Long     &&
+                    mPart->GetPdgCode() != kNuE        &&
+                     mPart->GetPdgCode() != kNuEBar     &&
+                     mPart->GetPdgCode() != kNuMu       &&
+                     mPart->GetPdgCode() != kNuMuBar    &&
+                     mPart->GetPdgCode() != kNuTau      &&
+                     mPart->GetPdgCode() != kNuTauBar   )
+               {
+                       if (fDebug > 5) Info("FillTracks","Storing kNoNeutronNeutrinoKlong track");
+                       if (fSmearType == kSmear ||
+                                       fSmearType == kSmearEffic ){
+                               Smear(mPart);/*
+                                               TParticle *tmp = Smear(MPart);
+                                               fInputObject.AddTrack(tmp);
+                                               delete tmp;*/
+                       }else{
+                               fInputObject.AddTrack(*mPart);
+                       }
+               }
+          break;
+          default:
+          break;
+        }      //end of switch
+    }// end of loop over particles
+
+}
+void AliEMCALJetFinderInputSimPrep::FillDigits()  
+{
+       // Fill digits to input object
+
+}
+void AliEMCALJetFinderInputSimPrep::FillSDigits()  
+{
+Info("FillSDigits","Beginning FillSDigits");
+       AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
+        
+       // Fill digits to input object
+       for (Int_t towerid=0; towerid < emcalLoader->SDigits()->GetEntries(); towerid++)
+       {
+               fInputObject.AddEnergyToDigit(emcalLoader->SDigit(towerid)->GetId(), emcalLoader->SDigit(towerid)->GetAmp());
+       }
+
+}
+
+void AliEMCALJetFinderInputSimPrep::Smear(TParticle *particle)
+{
+       // Smear particle momentum
+if (fDebug > 5) Info("Smear","Beginning Smear");
+
+       Float_t tmp = AliEMCALFast::SmearMomentum(1,particle->P());
+       Float_t tmpt = (tmp/particle->P()) * particle->Pt();
+       if (fDebug > 10) Info("Smear","Smearing changed P from %f to %f",particle->Pt(),tmpt);
+       TLorentzVector tmpvector;
+       tmpvector.SetPtEtaPhiM(tmpt,particle->Eta(), particle->Phi(), particle->GetMass());
+// create a new particle with smearing momentum - and no daughter or parent information and the same
+// vertex      
+
+       TParticle tmparticle(particle->GetPdgCode(), 1, 0, 0,0,0, 
+                       tmpvector.Px()  , tmpvector.Py(), tmpvector.Pz(), tmpvector.Energy(), 
+                       particle->Vx(), particle->Vy(), particle->Vz(), particle->T());
+       fInputObject.AddTrack(tmparticle);      
+       return;
+}
+
+void AliEMCALJetFinderInputSimPrep::FillPartonTracks(AliEMCALParton *parton)
+{
+       // Populate parton tracks for input distributions
+  if (fDebug>1) Info("FillPartonTracks","Beginning FillPartonTracks");
+  AliRunLoader *rl = AliRunLoader::GetRunLoader();
+       
+       Int_t npart = rl->Stack()->GetNprimary();
+       Int_t ntracks =0;
+       TParticlePDG *getpdg;
+       TParticle *tempPart;
+       for (Int_t part = 0; part < npart; part++)
+       {
+               tempPart = rl->Stack()->Particle(part);
+               if (tempPart->GetStatusCode() != 1) continue;
+               if ((!fPythiaComparison)&&(tempPart->Eta() > fEtaMax || tempPart->Eta() < fEtaMin || 
+                   tempPart->Phi() > fPhiMax || tempPart->Phi() < fPhiMin) ){
+                       if (fDebug>10) Info("FillPartonTracks","Excluding particle not pointing at the EMCAL");    
+                       continue;
+               }
+               getpdg = tempPart->GetPDG();
+               if (getpdg->Charge() == 0.0  ) { 
+                       if (fDebug>10) Info("FillPartonTracks","Excluding a neutral particle");
+                       continue;
+               }
+               if ( (parton->Eta() - tempPart->Eta())*(parton->Eta() - tempPart->Eta()) +
+               (parton->Phi() - tempPart->Phi())*(parton->Phi() - tempPart->Phi()) < 1.0 ) ntracks++;
+       }
+       Float_t *energy = new Float_t[ntracks];
+       Float_t *eta    = new Float_t[ntracks];
+       Float_t *phi    = new Float_t[ntracks];
+       Int_t   *pdg    = new Int_t[ntracks];
+       ntracks=0;
+       for (Int_t part = 0; part < npart; part++)
+       {
+               tempPart = rl->Stack()->Particle(part);
+               if (tempPart->GetStatusCode() != 1) continue;
+               if ((!fPythiaComparison)&&(tempPart->Eta() > fEtaMax || tempPart->Eta() < fEtaMin ||
+                   tempPart->Phi() > fPhiMax || tempPart->Phi() < fPhiMin) ){ 
+                       if (fDebug>10) Info("FillPartonTracks","Excluding particle not pointing at the EMCAL");       
+                       continue;
+               }
+               if (tempPart->GetStatusCode() != 1) continue;
+               getpdg = tempPart->GetPDG();
+               if (getpdg->Charge() == 0.0  ) {
+                       if (fDebug>10) Info("FillPartonTracks","Excluding a neutral particle");
+                       continue;
+               }
+               if (   (parton->Eta() - tempPart->Eta())*(parton->Eta() - tempPart->Eta()) +
+               (parton->Phi() - tempPart->Phi())*(parton->Phi() - tempPart->Phi()) < 1.0 )
+               {
+                       energy[ntracks] = tempPart->Pt();
+                       eta[ntracks] = tempPart->Eta();
+                       phi[ntracks] = tempPart->Phi();
+                       pdg[ntracks] = tempPart->GetPdgCode();
+                       ntracks++;
+               }
+       }
+       parton->SetTrackList(ntracks,energy,eta,phi,pdg);
+       delete[] energy;
+       delete[] eta;
+       delete[] phi;
+       delete[] pdg;
+}
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderInputSimPrep.h b/EMCAL/jetfinder/AliEMCALJetFinderInputSimPrep.h
new file mode 100644 (file)
index 0000000..28509d4
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef ALIEMCALJETFINDERINPUTSIMPREP_H
+#define ALIEMCALJETFINDERINPUTSIMPREP_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  *  * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Class for JetFinder Input preparation from simulated data 
+//*-- Author: Mark Horner (LBL/UCT)
+//
+//
+
+
+#include "AliEMCALJetFinderInput.h"
+#include "AliEMCALJetFinderInputPrep.h"
+#include "TTask.h"
+#include "AliEMCALJetFinderTypes.h"
+
+class AliEMCALJetFinderInputSimPrep : public AliEMCALJetFinderInputPrep
+{
+       public:
+       AliEMCALJetFinderInputSimPrep();
+       ~AliEMCALJetFinderInputSimPrep();
+       void Reset(AliEMCALJetFinderResetType_t resettype);
+        void SetEMCALType(AliEMCALJetFinderEMCALType_t emcaltype )  {fEMCALType = emcaltype;}
+       //void SetDebug(Int_t debug = 0)  {fDebug = debug;}
+        void SetSmearingType(AliEMCALJetFinderSmearingType_t smeartype ) {fSmearType = smeartype;}
+       void SetTrackType(AliEMCALJetFinderTrackType_t tracktype){fTrackType = tracktype;}  
+       void SetEfficiency(Float_t efficiency)  {fEfficiency = efficiency;}
+       void SetTimeCut(Float_t timecut)  {fTimeCut = timecut; fEMCALType = kTimeCut;}
+       Int_t FillFromFile(TString *filename, AliEMCALJetFinderFileType_t filetype,Int_t EventNumber,TString data="XH");
+       AliEMCALJetFinderInput* GetJetFinderInput(){return &fInputObject;}
+       private:
+       void FillHits();                // Fill from the hits to input object from simulation
+       void FillSDigits();             // Fill from the hits to input object from simulation
+       void FillTracks();              // Fill from particles simulating a TPC to input object from simulation
+       void Smear(TParticle *particle);
+       Bool_t Efficiency();
+       void FillPartons();             // Fill partons to input object from simulation
+       void FillPartonTracks(AliEMCALParton *parton);  // Fill partons to input object from simulation
+       void FillParticles();           // Fill particles to input object from simulation
+       void FillDigits();              // Fill digits to input object  
+
+        AliEMCALJetFinderEMCALType_t   fEMCALType;     // The EMCAL type set by the user       
+        AliEMCALJetFinderSmearingType_t fSmearType;    // The efficiency and smearing for TPC  
+        AliEMCALJetFinderTrackType_t   fTrackType;     // The Track type set by the user       
+       AliEMCALJetFinderFileType_t     fFileType;      //! The type of file being processed
+       Float_t                         fEfficiency;    // The TPC efficiency
+       Float_t                         fTimeCut;       // User specified time cut
+       Float_t                         fEtaMax;        // User specified time cut
+       Float_t                         fEtaMin;        // User specified time cut
+       Float_t                         fPhiMax;        // User specified time cut
+       Float_t                         fPhiMin;        // User specified time cut
+       
+       ClassDef(AliEMCALJetFinderInputSimPrep,1)
+       
+};
+#endif
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderOutput.cxx b/EMCAL/jetfinder/AliEMCALJetFinderOutput.cxx
new file mode 100644 (file)
index 0000000..4b213c3
--- /dev/null
@@ -0,0 +1,196 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+//  Output object for jetfinder
+// --
+//*-- Author:  Renan Cabrera (LBL)
+//             Mark Horner (LBL/UCT)
+// --
+
+
+#include <stdio.h>
+#include <TParticle.h>
+#include <TTree.h>
+
+//.....................
+#include "AliEMCALJet.h"
+#include "AliEMCALParton.h"
+#include "AliEMCALJetFinderOutput.h"
+#include "AliEMCALJetFinderInput.h"
+
+ClassImp(AliEMCALJetFinderOutput)
+
+//________________________________________________________________________
+AliEMCALJetFinderOutput::AliEMCALJetFinderOutput(){ 
+       // Default constructor
+       
+       fNMaxJets=10;
+       fNMaxParticles=2000;
+       fNMaxPartons=4;
+       fInitialised=kFALSE;
+       fDebug=0;
+       fNPartons=0;
+       fNJets=0;    
+       fNParticles=0;
+
+       fJetsArray=0;
+       fParticlesArray=0;
+       fPartonsArray=0;
+
+if (fDebug>0) Info("AliEMCALJetFinderOutput","Beginning Constructor");
+
+} //________________________________________________________________________
+void AliEMCALJetFinderOutput::InitArrays()
+{
+       // Initialise arrays - legacy from TClones days
+if (fDebug>1) Info("AliEMCALJetFinderOutput","Beginning InitArrays");
+ fParticlesArray=new TClonesArray("TParticle",fNMaxParticles);
+ fPartonsArray=new TClonesArray("AliEMCALParton",fNMaxPartons);
+ fJetsArray=new TClonesArray("AliEMCALJet",fNMaxJets);
+ //fJetsArray->BypassStreamer(kFALSE);
+ fInitialised=1;
+}
+
+//_______________________________________________________________________
+AliEMCALJetFinderOutput::~AliEMCALJetFinderOutput()
+{
+       // Default destrucotr
+if (fDebug>0) Info("~AliEMCALJetFinderOutput","Beginning Destructor");
+ delete fParticlesArray;
+ delete fPartonsArray;
+ delete fJetsArray;
+}
+
+//_______________________________________________________________________
+void AliEMCALJetFinderOutput::Reset(AliEMCALJetFinderResetType_t resettype)
+{
+// Reset stored data
+       
+if (fDebug>1) Info("Reset","Beginning Reset");
+if (!fInitialised) InitArrays();
+ if (  resettype == kResetAll ||
+       resettype == kResetJets||
+       resettype == kResetData ){
+        fNJets = 0;
+        if (fJetsArray)
+          fJetsArray->Clear();
+ }
+ if (   resettype == kResetAll ||
+        resettype == kResetPartons||              
+        resettype == kResetData ){
+        fNPartons = 0;
+        if (fPartonsArray)
+          fPartonsArray->Clear();
+ }
+ if (   resettype == kResetAll ||    
+        resettype == kResetParticles||              
+        resettype == kResetData ){
+        fNParticles = 0;
+        if (fParticlesArray)
+          fParticlesArray->Clear();
+ }
+}
+//________________________________________________________________________
+void AliEMCALJetFinderOutput::AddJet(AliEMCALJet* jet)
+{
+// Add a jet to the array
+       
+if (fDebug>1) Info("AddJet","Beginning AddJet");
+if (!fInitialised) InitArrays();
+
+
+       if (fNJets < fNMaxJets){
+               new(fJetsArray->AddrAt(fNJets))   AliEMCALJet( *jet );
+               fNJets++;
+       }else
+       {
+               Error("AddJet","Cannot AddJet - maximum exceeded");
+                }
+   
+}
+
+
+//_______________________________________________________________________
+void AliEMCALJetFinderOutput::AddParton(AliEMCALParton* parton)
+{
+//Add a parton to the array
+       
+if (fDebug>1) Info("AddParton","Beginning AddParton");
+if (!fInitialised) InitArrays();
+
+       if (fNPartons < fNMaxPartons){
+               new(fPartonsArray->AddrAt(fNPartons))  AliEMCALParton( *parton );
+               fNPartons++;
+       }else
+       {
+                Error("AddParton","Cannot AddParton - maximum exceeded");
+       }
+}
+
+//_______________________________________________________________________
+void AliEMCALJetFinderOutput::AddParticle(TParticle* particle)
+{
+//Add a particle tot he array
+       
+if (fDebug>1) Info("AddParticle","Beginning AddParticle");
+if (!fInitialised) InitArrays();
+
+       if (fNParticles < fNMaxParticles){
+               new(fParticlesArray->AddrAt(fNParticles))  TParticle( *particle );
+               fNParticles++;
+       }else
+       {
+               Error("AddParticle","Cannot AddParticle - maximum exceeded");
+                }
+}
+
+//______________________________________________________________________
+AliEMCALJet* AliEMCALJetFinderOutput::GetJet(Int_t jetID)
+{
+       // return a jet
+if (fDebug>1) Info("GetJet","Beginning GetJet");
+       
+  if (jetID >= fNJets) return 0;
+  return (AliEMCALJet*)fJetsArray->At(jetID);
+  
+}
+
+//______________________________________________________________________
+AliEMCALParton* AliEMCALJetFinderOutput::GetParton(Int_t partonID)
+{
+       //return a parton
+if (fDebug>1) Info("GetParton","Beginning GetParton");
+
+  if (partonID >= fNPartons) return 0;
+  return (AliEMCALParton*) fPartonsArray->At(partonID);
+}
+
+//______________________________________________________________________
+TParticle* AliEMCALJetFinderOutput::GetParticle(Int_t particleID)
+{
+//return a particle
+       
+if (fDebug>1) Info("GetParticle","Beginning GetParticle");
+
+  if (particleID >= fNParticles) return 0;
+  return (TParticle*) fParticlesArray->At(particleID);
+
+}
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderOutput.h b/EMCAL/jetfinder/AliEMCALJetFinderOutput.h
new file mode 100644 (file)
index 0000000..1342348
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef ALIEMCALJETFINDEROUTPUT_H
+#define ALIEMCALJETFINDEROUTPUT_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  *  * See cxx source for full Copyright notice     */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Output object for jetfinder
+//
+//*-- Author:  Renan Cabrera (LBL)
+//             Mark Horner (LBL/UCT)
+//
+
+class TClonesArray;
+#include "TObject.h"
+#include "TParticle.h"
+#include "AliEMCALParton.h"
+#include "AliEMCALJet.h"
+#include "AliEMCALJetFinderTypes.h"
+
+class AliEMCALJetFinderOutput : public TObject
+{
+               
+       public:
+               AliEMCALJetFinderOutput();
+               ~AliEMCALJetFinderOutput();
+               void Reset(AliEMCALJetFinderResetType_t resettype);
+               void AddJet(AliEMCALJet *jet); 
+               void AddParton(AliEMCALParton *parton);
+               void AddParticle(TParticle *particle);
+               void SetDebug(Int_t debug){fDebug = debug;}
+               AliEMCALJet* GetJet(Int_t jetID);
+               Int_t GetNJets() const {return fNJets;}
+               TClonesArray *GetJets() {return fJetsArray; }
+               AliEMCALParton* GetParton(Int_t partonID);
+               Int_t GetNPartons() const {return fNPartons;}
+               TParticle* GetParticle(Int_t particleID);
+               TClonesArray *GetParticles() {return fParticlesArray; }
+               Int_t GetNParticles() const {return fNParticles;}
+
+       ClassDef(AliEMCALJetFinderOutput,5)
+       private:
+               void InitArrays();
+               TClonesArray    *fJetsArray;            // Array of jet objects
+               TClonesArray    *fPartonsArray;         // Array of parton objects
+               Int_t           fNPartons;              // Number of Partons actually stored
+               Int_t           fNJets;                 // Number of jets actually stored
+               TClonesArray    *fParticlesArray;       // Array of particles
+               Int_t           fNParticles;            // Number of particles actually stored
+                Int_t           fNMaxJets;             // Maximum number of jets 
+                Int_t           fNMaxParticles;        // Maximum number of primary particles
+                Int_t           fNMaxPartons;          // Maximum number of primary particles
+                Int_t           fDebug;                        // Debug level
+               Bool_t          fInitialised;           // stores whether or not the arrays have been initialised
+               
+};
+#endif
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderPlots.cxx b/EMCAL/jetfinder/AliEMCALJetFinderPlots.cxx
new file mode 100644 (file)
index 0000000..d57d7b4
--- /dev/null
@@ -0,0 +1,684 @@
+/**************************************************************************
+ * 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 Filling JetFinder Plots
+// --
+//*-- Author: Mark Horner (LBL/UCT)
+// --
+// --
+
+
+#include "TMath.h"
+#include "AliEMCALJetFinderPlots.h"
+
+ClassImp(AliEMCALJetFinderPlots)
+       
+AliEMCALJetFinderPlots::AliEMCALJetFinderPlots()
+{
+       // Constructor to initialise variables
+  fInitialised = kFALSE;
+  fNominalEnergy = 0.0;
+  fConeRadius = 0.3;
+  fDebug = 0;
+  fOutput=0;
+    fhFragmFcn=0;// = new TH1F("hFragmFcn","Fragmentation Function",100,0,1);
+    fhPartonFragmFcn=0;// = new TH1F("hPartonFragmFcn","Fragmentation Function",100,0,1);
+   fhPartonJT=0;// = new TH1F("hPartonJT","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+    fhPartonPL=0;// = new TH1F("hPartonPL","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+    fhJetJT=0;// = new TH1F("hJetJT","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+    fhJetPL=0;// = new TH1F("hJetPL","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+    fhJetEt=0;// = new TH1F("hJetEt","E_{T}^{reco}",250,0.,250.);
+    fhJetEta=0;// = new       TH1F("hJetEta","#eta_{jet}^{reco}",180,-0.9,0.9);
+    fhJetPhi=0;// = new       TH1F("hJetPhi","#phi_{jet}^{reco}",62,0.,3.1);
+    fhPartonEta=0;// = new    TH1F("hPartonEta","#eta_{Parton}",180,-0.9,0.9);
+    fhPartonPhi=0;// = new    TH1F("hPartonPhi","#phi_{Parton}",62,0.,3.1);
+    fhEtaDiff=0;// = new      TH1F("hEtaDiff","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+    fhPhiDiff=0;//  = new TH1F("hPhiDiff","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+    fhNJets=0;// = new        TH1F("hNJets","N Reconstructed jets",11,-0.5,10.5);
+  fhEtaPhiSpread=0;        
+
+fhFragmFcn2=0; // ("hFragmFcn2","Fragmentation Function",100,0,1);
+fhPartonFragmFcn2=0;// ("hFragmFcn2","Parton Fragmentation Function",100,0,1);
+fhPartonJT2=0; // ("hPartonJT2","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+fhPartonPL2=0; // ("hPartonPL2","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+fhJetJT2=0;    // ("hJetJT2","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+fhJetPL2=0;    // ("hJetPL2","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+fhJetEt2=0;    // ("hJetEt2","E_{T}^{reco}",250,0.,250.);
+fhJetEta2=0;   // ("hJetEta2","#eta_{jet}^{reco}",180,-0.9,0.9);
+fhJetPhi2=0;   // ("hJetPhi2","#phi_{jet}^{reco}",62,0.,3.1);
+fhPartonEta2=0;        // ("hPartonEta2","#eta_{Parton}",180,-0.9,0.9);
+fhPartonPhi2=0;        // ("hPartonPhi2","#phi_{Parton}",62,0.,3.1);
+fhEtaDiff2=0;  // ("hEtaDiff2","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+fhPhiDiff2=0;  // ("hPhiDiff2","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+fhEtaPhiSpread2=0;     // ("hEtaPhiSpread2","#eta - #phi Distribution 
+                                               //of Reconstructed Jets",192,-0.7,0.7,288,pi/3,pi);
+fhNJets2=0;    // ("hNJets2","N Reconstructed jets",11,-0.5,10.5);
+fhJetEtSecond2=0; //("hJetEtSecond2","E_{T}^{reco}",250,0.,250.); 
+fhJetEtRatio2=0;  //("hJetEtRatio2","Ratio of Second Highest to Highest",100,0,1);
+fhEtaPhiDist2=0;  //("hEtaPhiDist2","Angular Distance Between First and Second",100,0,3);
+fhInputOutput=0;
+//     TH2F                            *fhInputOutput;  //("hJetEtRatio2","Ratio of Second Highest to Highest",100,0,1);
+     
+fhRecoBinPt=0;        // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+fhRecoBinPtNoBg=0;            // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+fhRecoBinPartonPt=0;    // ("fhRecoBinPartonPt","Input Pt Distribution",100,0,1);
+fhRecoBinJetEt=0;       // ("fhRecoJetEt","E_{T}^{reco}",250,0.,250.);
+fhRecoBinInputJetEt=0;  // ("fhRecoInputJetEt","E_{T}^{reco}",250,0.,250.);
+fhJetPT =0;// new TH1F("hJetPT","P_{T} Distribution",200,0,200);
+fhPartonPT =0;// new TH1F("hPartonPT","Parton P_{T} Distribution",200,0,1);
+fhJetPT2 =0;// new TH1F("hJetPT","P_{T} Distribution",200,0,200);
+fhPartonPT2 =0;// new TH1F("hPartonPT","Parton P_{T} Distribution",200,0,1);
+fhRecoBinFragmFcn =0;//new TH1F("fhRecoBinFragmFcn","Reconstructed Frag. Fcn",100,0,1);
+fhRecoBinFragmFcnNoBg =0;//new TH1F("fhRecoBinFragmFcn","Reconstructed Frag. Fcn",100,0,1);
+fhRecoBinPartonFragmFcn =0;// new TH1F("fhRecoBinPartonFragmFcn","Input Bin Fragm Fcn Distribution",100,0,1);
+fhJetInvE=0;// = new TH1F("fhJetInvE","#frac{1}{E_{R}}",100,0,1);
+fhJetInvE2=0;// = new TH1F("fhJetInvE","#frac{1}{E_{R}}",100,0,1);
+fScaleFactor = 1.0/0.6731;
+fhBackHisto=0;
+
+}
+
+void AliEMCALJetFinderPlots::InitPlots()
+{
+//========================= CASE 1 =======================================     
+    fhFragmFcn = new TH1F("hFragmFcn","Fragmentation Function",200,0,2);
+    fhFragmFcn->Sumw2();
+    fhJetPT = new TH1F("hJetPT","P_{T} Distribution",200,0,200);
+    fhJetPT->Sumw2();
+    fhPartonPT = new TH1F("hPartonPT","Parton P_{T} Distribution",200,0,200);
+    fhPartonPT->Sumw2();
+    fhPartonFragmFcn = new TH1F("hPartonFragmFcn","Parton Fragmentation Function",200,0,2);
+    fhPartonFragmFcn->Sumw2();
+    fhPartonJT = new TH1F("hPartonJT","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+    fhPartonJT->Sumw2();
+    fhPartonPL = new TH1F("hPartonPL","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+    fhPartonPL->Sumw2();
+    fhJetJT = new TH1F("hJetJT","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+    fhJetJT->Sumw2();
+    fhJetPL = new TH1F("hJetPL","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+    fhJetPL->Sumw2();
+    fhJetEt = new TH1F("hJetEt","E_{T}^{reco}",250,0.,250.);
+    fhJetEt->Sumw2();
+    fhJetEtDiff = new TH1F("hJetEtDiff","E_{T}^{reco}-E_{T}^{Parton}",250,-124.,125.);
+    fhJetEtDiff->Sumw2();
+    fhJetEta = new     TH1F("hJetEta","#eta_{jet}^{reco}",180,-0.9,0.9);
+    fhJetEta->Sumw2();
+    fhJetPhi = new     TH1F("hJetPhi","#phi_{jet}^{reco}",62,0.,3.1);
+    fhJetPhi->Sumw2();
+    fhPartonEta = new  TH1F("hPartonEta","#eta_{Parton}",180,-0.9,0.9);
+    fhPartonEta->Sumw2();
+    fhPartonPhi = new  TH1F("hPartonPhi","#phi_{Parton}",62,0.,3.1);
+    fhPartonPhi->Sumw2();
+    fhEtaDiff = new    TH1F("hEtaDiff","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+    fhEtaDiff->Sumw2();
+    fhPhiDiff  = new TH1F("hPhiDiff","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+    fhPhiDiff->Sumw2();
+    fhNJets = new      TH1F("hNJets","N Reconstructed jets",11,-0.5,10.5);
+    fhNJets->Sumw2();
+    fhEtaPhiSpread = new TH2F("hEtaPhiSpread","#eta - #phi Distribution of Reconstructed Jets",100,-0.5,0.5,100,-0.5,0.5);
+    fhEtaPhiSpread->Sumw2();    
+  fhNJets->SetXTitle("N_{jets}^{reco}/event");
+  fhNJets->SetYTitle("N_{events}");
+
+  //Jet properties
+  fhJetEt->SetFillColor(16);
+  fhJetEt->SetXTitle("E_{T}^{reco}");
+  
+  fhJetEta->SetFillColor(16);
+  fhJetEta->SetXTitle("#eta_{jet}^{reco}");
+  
+  fhJetPhi->SetFillColor(16);
+  fhJetPhi->SetXTitle("#phi_{jet}^{reco}");
+  
+  fhPartonEta->SetFillColor(16);
+  fhPartonEta->SetXTitle("#eta_{parton}");
+  
+  fhPartonPhi->SetFillColor(16);
+  fhPartonPhi->SetXTitle("#phi_{parton}");
+
+  fhPartonPL->SetXTitle("p (GeV/c)");
+  fhPartonJT->SetXTitle("p (GeV/c)");
+
+  fhPartonFragmFcn->SetXTitle("Z = p_{T}^{Chg}/E_{T}^{parton}");
+
+  //Jet component properties
+
+  fhJetPL->SetXTitle("p (GeV/c)");
+  fhJetJT->SetXTitle("p (GeV/c)");
+  fhFragmFcn->SetXTitle("Z = p_{T}^{Chg}/E_{T}^{reco}");
+  fhPartonFragmFcn->SetXTitle("Z = p_{T}^{Chg}/E_{T}^{reco}");
+
+  fhEtaDiff->SetXTitle("#eta_{jet}^{reco}-#eta_{jet}^{input}");
+  fhPhiDiff->SetXTitle("#phi_{jet}^{reco}-#phi_{jet}^{input}");
+  fhEtaPhiSpread->SetXTitle("#eta");
+  fhEtaPhiSpread->SetYTitle("#phi");
+
+//======================= CASE 2 ======================================
+  
+
+fhFragmFcn2            = new TH1F("hFragmFcn2","Fragmentation Function",200,0,2);
+fhFragmFcn2->Sumw2();
+    fhJetPT2 = new TH1F("hJetPT2","P_{T} Distribution",200,0,200);
+    fhJetPT2->Sumw2();
+    fhPartonPT2 = new TH1F("hPartonPT2","Parton P_{T} Distribution",200,0,1);
+    fhPartonPT2->Sumw2();
+fhPartonFragmFcn2      = new TH1F("hPartonFragmFcn2","Parton Fragmentation Function",200,0,2);
+fhPartonFragmFcn2->Sumw2();
+fhPartonJT2            = new TH1F("hPartonJT2","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+fhPartonJT2->Sumw2();
+fhPartonPL2            = new TH1F("hPartonPL2","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+fhPartonPL2->Sumw2();
+fhJetJT2                       = new TH1F("hJetJT2","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+fhJetJT2->Sumw2();
+fhJetPL2                       = new TH1F("hJetPL2","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+fhJetPL2->Sumw2();
+fhJetEt2                       = new TH1F("hJetEt2","E_{T}^{reco}",250,0.,250.);
+fhJetEt2->Sumw2();
+    fhJetEtDiff2 = new TH1F("hJetEtDiff2","E_{T}^{reco}-E_{T}^{Parton}",250,-124.,125.);
+    fhJetEtDiff2->Sumw2();
+fhJetEta2              = new TH1F("hJetEta2","#eta_{jet}^{reco}",180,-0.9,0.9);
+fhJetEta2->Sumw2();
+fhJetPhi2              = new TH1F("hJetPhi2","#phi_{jet}^{reco}",62,0.,3.1);
+fhJetPhi2->Sumw2();
+fhPartonEta2           = new TH1F("hPartonEta2","#eta_{Parton}",180,-0.9,0.9);
+fhPartonEta2->Sumw2();
+fhPartonPhi2           = new TH1F("hPartonPhi2","#phi_{Parton}",62,0.,3.1);
+fhPartonPhi2->Sumw2();
+fhEtaDiff2             = new TH1F("hEtaDiff2","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+fhEtaDiff2->Sumw2();
+fhPhiDiff2             = new TH1F("hPhiDiff2","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+fhPhiDiff2->Sumw2();
+fhEtaPhiSpread2 = new TH2F("hEtaPhiSpread2","#eta - #phi Distribution of Reconstructed Jets",100,-0.5,0.5,100,-0.5,0.5);
+fhEtaPhiSpread2->Sumw2();
+fhNJets2                       = new TH1F("hNJets2","N Reconstructed jets",11,-0.5,10.5);
+fhNJets2->Sumw2();
+fhJetEtSecond2         = new TH1F("hJetEtSecond2","E_{T}^{reco}",250,0.,250.); 
+fhJetEtSecond2->Sumw2();
+fhJetEtRatio2          = new TH1F("hJetEtRatio2","Ratio of Second Highest to Highest",100,0,1);
+fhJetEtRatio2->Sumw2();
+fhEtaPhiDist2          = new TH1F("hEtaPhiDist2","Angular Distance Between First and Second",100,0,3);
+fhEtaPhiDist2->Sumw2();
+
+fhInputOutput= new TH2F("hInputOutput","Input and Reconstruction Correlations;Input;Output",200,0,200,200,0,200);  //("hJetEtRatio2","Ratio of Second Highest to Highest",100,0,1);
+
+//============================== Reconstruction Bin Comparison  ============================================
+
+fhRecoBinPt =new TH1F("fhRecoBinPt","Reconstructed Pt Distribution",200,0,200);
+fhRecoBinPt->Sumw2();
+fhRecoBinPtNoBg =new TH1F("fhRecoBinPtNoBg","Reconstructed Pt Distribution Background Subtracted",200,0,200);
+fhRecoBinPtNoBg->Sumw2();
+fhRecoBinPartonPt = new TH1F("fhRecoBinPartonPt","Input Pt Distribution",200,0,200);
+fhRecoBinPartonPt->Sumw2();
+fhRecoBinFragmFcn =new TH1F("fhRecoBinFragmFcn","Reconstructed Frag. Fcn",200,0,2);
+fhRecoBinFragmFcn->Sumw2();
+fhRecoBinFragmFcnNoBg =new TH1F("fhRecoBinFragmFcnNoBg","Reconstructed Frag. Fcn With Background Removed",200,0,2);
+fhRecoBinFragmFcnNoBg->Sumw2();
+fhRecoBinPartonFragmFcn = new TH1F("fhRecoBinPartonFragmFcn","Input Bin Fragm Fcn Distribution",200,0,2);
+fhRecoBinPartonFragmFcn->Sumw2();
+fhRecoBinJetEt = new TH1F("fhRecoJetEt","E_{T}^{reco}",250,0.,250.);
+fhRecoBinJetEt->Sumw2();
+fhRecoBinInputJetEt = new TH1F("fhRecoInputJetEt","E_{T}^{reco}",250,0.,250.);
+fhRecoBinInputJetEt->Sumw2();
+        
+
+fhJetInvE = new TH1F("fhJetInvE","#frac{1}{E_{R}}",100,0,1);
+fhJetInvE->Sumw2();
+fhJetInvE2 = new TH1F("fhJetInvE2","#frac{1}{E_{R}}",100,0,1);
+fhJetInvE2->Sumw2();
+               
+
+
+  fInitialised = kTRUE;        
+  
+}
+
+AliEMCALJetFinderPlots::~AliEMCALJetFinderPlots()
+{
+       // To ensure that all requested memory is returned
+delete    fhFragmFcn;// = new TH1F("hFragmFcn","Fragmentation Function",100,0,1);
+delete    fhPartonFragmFcn;// = new TH1F("hFragmFcn","Fragmentation Function",100,0,1);
+delete   fhPartonJT;// = new TH1F("hPartonJT","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+delete    fhPartonPL;// = new TH1F("hPartonPL","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+delete    fhJetJT;// = new TH1F("hJetJT","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+delete    fhJetPL;// = new TH1F("hJetPL","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+delete    fhJetEt;// = new TH1F("hJetEt","E_{T}^{reco}",250,0.,250.);
+delete fhJetEtDiff;    // ("hJetEt2","E_{T}^{reco}",250,0.,250.);
+delete    fhJetEta;// = new       TH1F("hJetEta","#eta_{jet}^{reco}",180,-0.9,0.9);
+delete    fhJetPhi;// = new       TH1F("hJetPhi","#phi_{jet}^{reco}",62,0.,3.1);
+delete    fhPartonEta;// = new    TH1F("hPartonEta","#eta_{Parton}",180,-0.9,0.9);
+delete    fhPartonPhi;// = new    TH1F("hPartonPhi","#phi_{Parton}",62,0.,3.1);
+delete    fhEtaDiff;// = new      TH1F("hEtaDiff","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+delete    fhPhiDiff;//  = new TH1F("hPhiDiff","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+delete    fhNJets;// = new        TH1F("hNJets","N Reconstructed jets",11,-0.5,10.5);
+delete           fhEtaPhiSpread;           
+
+       delete                          fhFragmFcn2;    // ("hFragmFcn2","Fragmentation Function",100,0,1);
+       delete                          fhPartonFragmFcn2;// ("hFragmFcn2","Parton Fragmentation Function",100,0,1);
+       delete                          fhPartonJT2;    // ("hPartonJT2","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+       delete                          fhPartonPL2;    // ("hPartonPL2","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+       delete                          fhJetJT2;       // ("hJetJT2","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+       delete                          fhJetPL2;       // ("hJetPL2","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+       delete                          fhJetEt2;       // ("hJetEt2","E_{T}^{reco}",250,0.,250.);
+       delete                          fhJetEtDiff2;   // ("hJetEt2","E_{T}^{reco}",250,0.,250.);
+       delete                          fhJetEta2;      // ("hJetEta2","#eta_{jet}^{reco}",180,-0.9,0.9);
+       delete                          fhJetPhi2;      // ("hJetPhi2","#phi_{jet}^{reco}",62,0.,3.1);
+       delete                          fhPartonEta2;   // ("hPartonEta2","#eta_{Parton}",180,-0.9,0.9);
+       delete                          fhPartonPhi2;   // ("hPartonPhi2","#phi_{Parton}",62,0.,3.1);
+       delete                          fhEtaDiff2;     // ("hEtaDiff2","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+       delete                          fhPhiDiff2;     // ("hPhiDiff2","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+       delete                          fhEtaPhiSpread2;        // ("hEtaPhiSpread2","#eta - #phi Distribution 
+                                                       //of Reconstructed Jets",192,-0.7,0.7,288,pi/3,pi);
+       delete                          fhNJets2;       // ("hNJets2","N Reconstructed jets",11,-0.5,10.5);
+       delete                          fhJetEtSecond2; //("hJetEtSecond2","E_{T}^{reco}",250,0.,250.); 
+       delete                          fhJetEtRatio2;  //("hJetEtRatio2","Ratio of Second Highest to Highest",100,0,1);
+       delete                          fhEtaPhiDist2;  //("hEtaPhiDist2","Angular Distance Between First and Second",100,0,3);
+
+       delete fhRecoBinPt;          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+       delete fhRecoBinPtNoBg;          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+       delete fhRecoBinPartonPt;    // ("fhRecoBinPartonPt","Input Pt Distribution",100,0,1);
+       delete fhRecoBinJetEt;       // ("fhRecoJetEt","E_{T}^{reco}",250,0.,250.);
+       delete fhRecoBinInputJetEt;  // ("fhRecoInputJetEt","E_{T}^{reco}",250,0.,250.);
+                                       
+       delete fhJetPT ;// new TH1F("hJetPT","P_{T} Distribution",200,0,200);
+       delete fhPartonPT ;// new TH1F("hPartonPT","Parton P_{T} Distribution",200,0,1);
+       delete fhJetPT2 ;// new TH1F("hJetPT","P_{T} Distribution",200,0,200);
+       delete fhPartonPT2 ;// new TH1F("hPartonPT","Parton P_{T} Distribution",200,0,1);
+       delete fhRecoBinFragmFcn;//new TH1F("fhRecoBinFragmFcn","Reconstructed Frag. Fcn",100,0,1);
+       delete fhRecoBinFragmFcnNoBg;//new TH1F("fhRecoBinFragmFcn","Reconstructed Frag. Fcn",100,0,1);
+       delete fhRecoBinPartonFragmFcn;// new TH1F("fhRecoBinPartonFragmFcn","Input Bin Fragm Fcn Distribution",100,0,1);
+    delete fhJetInvE;// = new TH1F("fhJetInvE","#frac{1}{E_{R}}",100,0,1);
+    delete fhJetInvE2;// = new TH1F("fhJetInvE","#frac{1}{E_{R}}",100,0,1);
+
+}      
+
+void AliEMCALJetFinderPlots::FillFromOutput(AliEMCALJetFinderOutput* output, Float_t weight)
+{
+       // Fill histograms from an output object
+if (!fInitialised) InitPlots();        
+  fOutput = output;
+  if (!fOutput) return;
+// Make some temporary histograms to make sure we subtract 
+  // background properly
+/*
+tempFragmFcnNoBg =new TH1F("tempFragmFcnNoBg","Reconstructed Frag. Fcn With Background Removed",200,0,2);
+tempPtNoBg =new TH1F("tempPtNoBg","Reconstructed Frag. Fcn With Background Removed",200,0,200);
+tempFragmFcnNoBg->Fill(count/(jethighest->Energy()*fScaleFactor),-fhBackHisto->GetBinContent(count));
+tempPtNoBg->AddBinContent(count,-fhBackHisto->GetBinContent(count));
+*/
+  
+  fhNJets->Fill(fOutput->GetNJets());
+  Bool_t doesJetMeetBinCriteria = 0;
+  AliEMCALJet* jethighest=0; 
+  AliEMCALJet* jetsecond=0; 
+  //  Find Highest and Second Highest Jet 
+  // (NB!!!!!!!)  Pointing into the EMCAL!!!!!!
+  
+// =========================== All cases ===================================
+
+       // I will make a little array of jet indices for which jets are in 
+       // the EMCAL then my counter can loop from 0 below - but it will 
+       // be the index of the array of applicable jets
+    
+  Int_t appjet[4];
+  Int_t numappjet=0;
+  
+  for (Int_t appc=0;appc<fOutput->GetNJets();appc++)
+  { // Check all jets for applicability
+         Float_t eta = fOutput->GetJet(appc)->Eta();
+         Float_t phi = fOutput->GetJet(appc)->Phi();
+         if (eta > -0.7 && eta < 0.7 && phi > 1./3.*TMath::Pi() && phi < TMath::Pi())
+         { // Then jet is applicable
+                 appjet[numappjet]=appc;                               
+                 numappjet++;
+         }
+  }
+       
+  
+Float_t et=0;
+if (numappjet >=1)
+{
+       Float_t theta = 2.0*atan(exp(-fOutput->GetParton(0)->Eta()));
+       et    = fOutput->GetParton(0)->Energy() * TMath::Sin(theta);
+       if (fOutput->GetNJets()>1)
+       {
+               for (Int_t counter = 0; counter<numappjet;counter++)  
+               {         
+                       if (counter==0)
+                       {                 
+                               jethighest = fOutput->GetJet(appjet[0]);
+                               jetsecond  = fOutput->GetJet(appjet[1]);
+                       }
+                       if (counter>0)
+                       {
+                               Float_t energyhighest = jethighest->Energy();
+                               Float_t energysecond = jetsecond->Energy();
+                               
+                               if ((fOutput->GetJet(appjet[counter]))->Energy()>energyhighest) 
+                               {
+                                       jetsecond=jethighest;
+                                       jethighest=fOutput->GetJet(appjet[counter]);
+                               }else if ((fOutput->GetJet(appjet[counter]))->Energy()>energysecond) 
+                               {
+                                       jetsecond=fOutput->GetJet(appjet[counter]);
+                               }
+             
+                       }
+               }
+       }else
+       {
+               Float_t eta = fOutput->GetJet(0)->Eta();
+               Float_t phi = fOutput->GetJet(0)->Phi();
+               if (eta > -0.7 && eta < 0.7 && phi > 1./3.*TMath::Pi() && phi < TMath::Pi())
+               { // Then jet is applicable
+                       jethighest=fOutput->GetJet(0);
+                       jetsecond=0;
+               }else
+               {
+                       Error("FillFromOutput","There is only one jet and it isn't in the area of applicability");
+               }
+                                               
+       }
+       if ( 95.0 < jethighest->Energy()*fScaleFactor && jethighest->Energy()*fScaleFactor < 105.0  )
+       {
+               doesJetMeetBinCriteria = 1;
+               fhRecoBinJetEt->Fill(jethighest->Energy()*fScaleFactor,weight);
+               fhRecoBinInputJetEt->Fill(et,weight);
+       }
+       fhInputOutput->Fill(et,jethighest->Energy());
+               
+}
+
+if (numappjet > 1)
+{      
+//========================= CASE 2 =========================== 
+  Int_t nPartons = fOutput->GetNPartons();
+  fhNJets2->Fill(fOutput->GetNJets());
+  AliEMCALParton* parton;
+
+  // End finding highest and second highest and continue
+  fhJetEt2->Fill(jethighest->Energy()*fScaleFactor,weight);
+  fhJetEtDiff2->Fill(jethighest->Energy()*fScaleFactor-et,weight);
+  fhJetInvE2->Fill(1.0/(jethighest->Energy()*fScaleFactor),weight);
+  fhJetEta2->Fill(jethighest->Eta(),weight  );
+  fhJetPhi2->Fill(jethighest->Phi(),weight );
+  if (nPartons ==0) return;
+  parton = fOutput->GetParton(0);
+  
+  fhPartonEta2->Fill( parton->Eta(),weight );
+  fhPartonPhi2->Fill( parton->Phi(),weight );
+
+  //hJetEtDiff->Fill( jet->Energy() - parton->Energy() );
+  fhEtaDiff2->Fill( jethighest->Eta() - parton->Eta(),weight );
+  fhPhiDiff2->Fill( jethighest->Phi() - parton->Phi(),weight );
+  fhEtaPhiSpread2->Fill(jethighest->Eta()-parton->Eta(),jethighest->Phi() - parton->Phi());
+  fhJetEtSecond2->Fill(jetsecond->Energy()*fScaleFactor,weight); 
+  fhJetEtRatio2->Fill(jetsecond->Energy()/jethighest->Energy(),weight); 
+  fhEtaPhiDist2->Fill( TMath::Sqrt((jethighest->Eta() - jetsecond->Eta())*(jethighest->Eta() - jetsecond->Eta())
+                     + (jethighest->Phi() - jetsecond->Phi())*(jethighest->Phi() - jetsecond->Phi())     ),weight);  
+  /* 
+  Float_t *pt,*phi,*eta;
+  Int_t *pdg;
+  pt  = new Float_t[parton->GetNTracks()];
+  eta = new Float_t[parton->GetNTracks()];
+  phi = new Float_t[parton->GetNTracks()];
+  pdg = new Int_t[parton->GetNTracks()];*/
+
+
+
+ Float_t pt[2000];
+ Float_t eta[2000];
+ Float_t phi[2000];
+ Int_t pdg[2000];
+  
+  parton->GetTrackList(pt,eta,phi,pdg);
+  for(Int_t iT=0; iT< parton->GetNTracks() ; iT++ ) 
+  {
+      if ( (eta[iT]-parton->Eta())*(eta[iT]-parton->Eta())+
+           (phi[iT]-parton->Phi())*(phi[iT]-parton->Phi()) >fConeRadius * fConeRadius ) continue; 
+      Double_t tt = 2.0*atan(exp(-eta[iT])); // These names are short to make the equation manageable
+      Double_t rt = 2.0*atan(exp(-parton->Eta()));
+      Double_t ctt = cos(tt);
+      Double_t crt = cos(rt);
+      Double_t stt = sin(tt);
+      Double_t srt = sin(rt);
+      Double_t ctp = cos(phi[iT]);
+      Double_t crp = cos(parton->Phi());
+      Double_t stp = sin(phi[iT]);
+      Double_t srp = sin(parton->Phi());
+      //Double_t alpha = acos(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);
+         Double_t alpha;   
+         if (TMath::Abs(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt) > 0.9990)
+         {
+                 alpha = 0.0;
+         }else
+         {
+                 alpha = TMath::ACos(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);   
+         }
+      Double_t correctp = pt[iT]/stt;  
+      fhPartonPL2->Fill( correctp*cos(alpha),weight);
+      if ( (parton->Eta()-eta[iT])*(parton->Eta()-eta[iT]) +  
+      (parton->Phi()-phi[iT])*(parton->Phi()-phi[iT]) < 0.2*0.2 ) 
+             fhPartonJT2->Fill( correctp*sin(alpha),weight);
+      fhPartonPT2->Fill(correctp*sin(tt),weight);
+      if (fNominalEnergy == 0.0) {
+             fhPartonFragmFcn2->Fill(  correctp*sin(tt)/parton->Energy(),weight  );
+      }else 
+      {
+              fhPartonFragmFcn2->Fill(correctp*sin(tt)/fNominalEnergy,weight);
+      }          
+      if (doesJetMeetBinCriteria)
+      {
+             fhRecoBinPartonPt->Fill(correctp*sin(tt),weight);          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+      }
+  }// loop over tracks
+
+/*
+  pt  = new Float_t[jet->NTracks()];
+  eta = new Float_t[jet->NTracks()];
+  phi = new Float_t[jet->NTracks()];
+  pdg = new Int_t[jet->NTracks()];*/
+  jethighest->TrackList(pt,eta,phi,pdg);
+  for(Int_t iT=0; iT< jethighest->NTracks() ; iT++ )
+  {
+         Double_t tt = 2.0*atan(exp(-eta[iT])); // These names are short to make the equation manageable
+         Double_t rt = 2.0*atan(exp(-jethighest->Eta()));
+         Double_t ctt = cos(tt);                   
+         Double_t crt = cos(rt);                         
+         Double_t stt = sin(tt);                               
+         Double_t srt = sin(rt);
+         Double_t ctp = cos(phi[iT]);
+         Double_t crp = cos(jethighest->Phi());
+         Double_t stp = sin(phi[iT]);
+         Double_t srp = sin(jethighest->Phi());
+        // Double_t alpha = acos(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);   
+         Double_t alpha;   
+         if (TMath::Abs(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt) > 0.9990)
+         {
+                 alpha = 0.0;
+         }else
+         {
+                 alpha = TMath::ACos(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);   
+         }
+         Double_t correctp = pt[iT]/stt;
+         fhJetPL2->Fill( correctp*cos(alpha),weight);      
+         if ( (jethighest->Eta()-eta[iT])*(jethighest->Eta()-eta[iT]) +  
+                         (jethighest->Phi()-phi[iT])*(jethighest->Phi()-phi[iT]) < 0.2*0.2 )   
+                 fhJetJT2->Fill( correctp*sin(alpha),weight);
+         fhJetPT2->Fill(correctp*sin(tt),weight);
+         if (fNominalEnergy==0.0){
+                 fhFragmFcn2->Fill(  correctp*sin(tt)/(jethighest->Energy()*fScaleFactor),weight  );
+         } else
+         {
+                  fhFragmFcn2->Fill(  correctp*sin(tt)/fNominalEnergy,weight );
+         }
+         if (doesJetMeetBinCriteria)
+         {
+                 fhRecoBinPt->Fill(correctp*sin(tt),weight);          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+                 fhRecoBinPtNoBg->Fill(correctp*sin(tt),weight);          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+                 fhRecoBinFragmFcn->Fill(  correctp*sin(tt)/(jethighest->Energy()*fScaleFactor),weight  ); // This is the jet fragmentation function
+                 fhRecoBinFragmFcnNoBg->Fill(  correctp*sin(tt)/(jethighest->Energy()*fScaleFactor),weight  ); // This is the jet fragmentation function
+         }
+  }// loop over tracks
+  }
+
+  if (numappjet == 1)
+  {
+
+//========================= CASE 1 =========================== 
+  Int_t nPartons = fOutput->GetNPartons();
+  if (fOutput->GetNJets()!=1) return;
+  AliEMCALParton* parton;
+  AliEMCALJet* jet; 
+  jet = jethighest;//fOutput->GetJet(0);
+  fhJetEt->Fill(jet->Energy()*fScaleFactor,weight);
+  fhJetEtDiff->Fill(jethighest->Energy()*fScaleFactor-et,weight);
+  fhJetInvE->Fill(1.0/(jethighest->Energy()*fScaleFactor),weight);
+  fhJetEta->Fill(jet->Eta(),weight  );
+  fhJetPhi->Fill(jet->Phi(),weight );
+  if (nPartons ==0) return;
+  parton = fOutput->GetParton(0);
+  
+  fhPartonEta->Fill( parton->Eta(),weight );
+  fhPartonPhi->Fill( parton->Phi(),weight );
+
+  //hJetEtDiff->Fill( jet->Energy() - parton->Energy() );
+  fhEtaDiff->Fill( jet->Eta() - parton->Eta(),weight );
+  fhPhiDiff->Fill( jet->Phi() - parton->Phi(),weight );
+  fhEtaPhiSpread->Fill(jet->Eta()-parton->Eta(),jet->Phi() - parton->Phi());
+ /* 
+  Float_t *pt,*phi,*eta;
+  Int_t *pdg;
+  pt  = new Float_t[parton->GetNTracks()];
+  eta = new Float_t[parton->GetNTracks()];
+  phi = new Float_t[parton->GetNTracks()];
+  pdg = new Int_t[parton->GetNTracks()];*/
+
+
+
+ Float_t pt[2000];
+ Float_t eta[2000];
+ Float_t phi[2000];
+ Int_t pdg[2000];
+  
+  parton->GetTrackList(pt,eta,phi,pdg);
+  for(Int_t iT=0; iT< parton->GetNTracks() ; iT++ ) 
+  {
+      if ( (eta[iT]-parton->Eta())*(eta[iT]-parton->Eta())+
+           (phi[iT]-parton->Phi())*(phi[iT]-parton->Phi()) >fConeRadius * fConeRadius ) continue; 
+      Double_t tt = 2.0*atan(exp(-eta[iT])); // These names are short to make the equation manageable
+      Double_t rt = 2.0*atan(exp(-parton->Eta()));
+      Double_t ctt = cos(tt);
+      Double_t crt = cos(rt);
+      Double_t stt = sin(tt);
+      Double_t srt = sin(rt);
+      Double_t ctp = cos(phi[iT]);
+      Double_t crp = cos(parton->Phi());
+      Double_t stp = sin(phi[iT]);
+      Double_t srp = sin(parton->Phi());
+     // Double_t alpha = acos(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);
+         Double_t alpha;   
+         if (TMath::Abs(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt) > 0.9990)
+         {
+                 alpha = 0.0;
+         }else
+         {
+                 alpha = TMath::ACos(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);           }
+      Double_t correctp = pt[iT]/stt;  
+      fhPartonPL->Fill( correctp*cos(alpha),weight);
+      if ( (parton->Eta()-eta[iT])*(parton->Eta()-eta[iT]) +  
+      (parton->Phi()-phi[iT])*(parton->Phi()-phi[iT]) < 0.2*0.2 ) 
+             fhPartonJT->Fill( correctp*sin(alpha),weight);
+      if (fNominalEnergy == 0.0) {
+             fhPartonFragmFcn->Fill(  correctp*sin(tt)/parton->Energy(),weight  );
+         fhPartonPT->Fill(correctp*sin(tt),weight);
+      }else 
+      {
+              fhPartonFragmFcn->Fill(correctp*sin(tt)/fNominalEnergy,weight);
+      }
+      if (doesJetMeetBinCriteria)
+      {
+             fhRecoBinPartonPt->Fill(correctp*sin(tt),weight);          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+      }
+  }// loop over tracks
+
+/*
+  pt  = new Float_t[jet->NTracks()];
+  eta = new Float_t[jet->NTracks()];
+  phi = new Float_t[jet->NTracks()];
+  pdg = new Int_t[jet->NTracks()];*/
+  jet->TrackList(pt,eta,phi,pdg);
+  for(Int_t iT=0; iT< jet->NTracks() ; iT++ )
+  {
+         Double_t tt = 2.0*atan(exp(-eta[iT])); // These names are short to make the equation manageable
+         Double_t rt = 2.0*atan(exp(-jet->Eta()));
+         Double_t ctt = cos(tt);                   
+         Double_t crt = cos(rt);                         
+         Double_t stt = sin(tt);                               
+         Double_t srt = sin(rt);
+         Double_t ctp = cos(phi[iT]);
+         Double_t crp = cos(jet->Phi());
+         Double_t stp = sin(phi[iT]);
+         Double_t srp = sin(jet->Phi());
+         //Info("plots","acos(%1.16f)\nstt=%f\npt=%f",crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt,stt,pt[iT]);
+         //Info("plots","diff to 1 %f",1.0-crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);
+         Double_t alpha;   
+         if (TMath::Abs(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt) > 0.9990)
+         {
+                 alpha = 0.0;
+         }else
+         {
+                 alpha = TMath::ACos(crp*ctp*srt*stt+srp*stp*srt*stt+crt*ctt);   
+         }
+         Double_t correctp = pt[iT]/stt;
+         fhJetPL->Fill( correctp*cos(alpha),weight);      
+         if ( (jet->Eta()-eta[iT])*(jet->Eta()-eta[iT]) +  
+              (jet->Phi()-phi[iT])*(jet->Phi()-phi[iT]) < 0.2*0.2 )   
+                 fhJetJT->Fill( correctp*sin(alpha),weight);
+         fhJetPT->Fill(correctp*sin(tt),weight);
+         if (fNominalEnergy==0.0){
+                 fhFragmFcn->Fill(  correctp*sin(tt)/(jet->Energy()*fScaleFactor),weight  ); // This is the jet fragmentation function
+         } else
+         {
+                  fhFragmFcn->Fill(  correctp*sin(tt)/fNominalEnergy,weight );
+         }
+         if (doesJetMeetBinCriteria)
+         {
+                 fhRecoBinPt->Fill(correctp*sin(tt),weight);          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+                 fhRecoBinPtNoBg->Fill(correctp*sin(tt),weight);          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+                 fhRecoBinFragmFcn->Fill(  correctp*sin(tt)/(jet->Energy()*fScaleFactor),weight  ); // This is the jet fragmentation function
+                 fhRecoBinFragmFcnNoBg->Fill(  correctp*sin(tt)/(jet->Energy()*fScaleFactor),weight  ); // This is the jet fragmentation function
+         }
+  }// loop over tracks
+  }
+
+if (numappjet>=1 && fhBackHisto != 0 && doesJetMeetBinCriteria)
+  {
+    for (Int_t count=1;count<=100;count++)
+    {
+       fhRecoBinFragmFcnNoBg->Fill( ((Float_t)count)/(jethighest->Energy()*fScaleFactor),-fhBackHisto->GetBinContent(count)*weight);
+       fhRecoBinPtNoBg->AddBinContent(count,-fhBackHisto->GetBinContent(count)*weight);
+    } 
+  }
+
+
+}
+
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderPlots.h b/EMCAL/jetfinder/AliEMCALJetFinderPlots.h
new file mode 100644 (file)
index 0000000..717f4e6
--- /dev/null
@@ -0,0 +1,180 @@
+#ifndef ALIEMCALJETFINDERPLOTS_H
+#define ALIEMCALJETFINDERPLOTS_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *  *  * See cxx source for full Copyright notice     */
+
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Class for Filling jetfinder plots
+//
+//*-- Author: Mark Horner (LBL/UCT)
+//
+//
+
+
+
+#include "TObject.h"
+#include "TH1F.h"
+#include "TH2F.h"
+
+#include "AliEMCALJetFinderOutput.h"
+
+class AliEMCALJetFinderPlots : public TObject
+{
+       public: 
+       AliEMCALJetFinderPlots();
+       ~AliEMCALJetFinderPlots();
+       void SetConeRadius(Float_t coneradius){fConeRadius = coneradius;}
+       void SetNominalEnergy(Float_t energy){fNominalEnergy = energy;}
+       void SetDebug(Int_t debug){fDebug = debug;}
+       void SetBackHisto(TH1F* histo){fhBackHisto=histo;}
+       void FillFromOutput(AliEMCALJetFinderOutput* output,Float_t weight=1.0);
+       //========================== CASE 1 ========================
+       // Only consider events with only 1 jet
+       TH1F* GetFragmFcn(){return fhFragmFcn;} 
+       TH1F* GetPartonFragmFcn(){return fhPartonFragmFcn;}     
+       TH1F* GetPT(){return fhJetPT;}  
+       TH1F* GetPartonPT(){return fhPartonPT;} 
+       TH1F* GetJetJT(){return fhJetJT;}       
+       TH1F* GetPartonJT(){return fhPartonJT;} 
+       TH1F* GetJetPL(){return fhJetPL;}
+       TH1F* GetPartonPL(){return fhPartonPL;}
+       TH1F* GetJetEt(){return fhJetEt;}
+       TH1F* GetJetEtDiff(){return fhJetEtDiff;}
+       TH1F* GetJetEta(){return fhJetEta;}
+       TH1F* GetPartonEta(){return fhPartonEta;}
+       TH1F* GetPartonPhi(){return fhPartonPhi;}
+       TH1F* GetJetPhi(){return fhJetPhi;}
+       TH1F* GetEtaDiff(){return fhEtaDiff;}
+       TH1F* GetPhiDiff(){return fhPhiDiff;}
+       TH2F* GetEtaPhiSpread(){return fhEtaPhiSpread;}
+       TH1F* GetNJets(){return fhNJets;}
+
+       //========================== CASE 2 ========================
+       // Only consider events with at least 2 jets
+       TH1F* GetFragmFcn2(){return fhFragmFcn2;}       
+       TH1F* GetPartonFragmFcn2(){return fhPartonFragmFcn2;}   
+       TH1F* GetPT2(){return fhJetPT2;}        
+       TH1F* GetPartonPT2(){return fhPartonPT2;}       
+       TH1F* GetJetJT2(){return fhJetJT2;}     
+       TH1F* GetPartonJT2(){return fhPartonJT2;}       
+       TH1F* GetJetPL2(){return fhJetPL2;}
+       TH1F* GetPartonPL2(){return fhPartonPL2;}
+       TH1F* GetJetEt2(){return fhJetEt2;}
+       TH1F* GetJetEtDiff2(){return fhJetEtDiff2;}
+       TH1F* GetJetEta2(){return fhJetEta2;}
+       TH1F* GetPartonEta2(){return fhPartonEta2;}
+       TH1F* GetPartonPhi2(){return fhPartonPhi2;}
+       TH1F* GetJetPhi2(){return fhJetPhi2;}
+       TH1F* GetEtaDiff2(){return fhEtaDiff2;}
+       TH1F* GetPhiDiff2(){return fhPhiDiff2;}
+       TH2F* GetEtaPhiSpread2(){return fhEtaPhiSpread2;}
+       TH1F* GetNJets2(){return fhNJets2;}
+       TH1F* GetJetEtSecond2(){return fhJetEtSecond2;}
+       TH1F* GetJetEtRatio2(){return fhJetEtRatio2;}
+       TH1F* GetEtaPhiDist2(){return fhEtaPhiDist2;}
+
+       
+        TH1F* GetJetPt(){return        fhJetPT ;}
+        TH1F* GetPartonPt(){return fhPartonPT ;}
+        TH1F* GetJetPt2(){return       fhJetPT2;}
+        TH1F* GetPartonPt2(){return fhPartonPT2;}
+        TH1F* GetRecoBinFragmFcn() {return fhRecoBinFragmFcn;}
+        TH1F* GetRecoBinFragmFcnNoBg() {return fhRecoBinFragmFcnNoBg;}
+        TH1F* GetRecoBinPartonFragmFcn() {return       fhRecoBinPartonFragmFcn;}
+
+       //============================== ALL CASES ============================================
+       
+       TH2F* GetInputOutput(){return fhInputOutput;}
+       
+       //============================== Reconstruction Bin Comparison  ============================================
+       
+       TH1F* GetRecoBinPt(){return fhRecoBinPt;}                  // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+       TH1F* GetRecoBinPtNoBg(){return fhRecoBinPtNoBg;}                  // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+       TH1F* GetRecoBinPartonPt(){return fhRecoBinPartonPt;}      // ("fhRecoBinPartonPt","Input Pt Distribution",100,0,1);
+       TH1F* GetRecoBinJetEt(){return fhRecoBinJetEt;}            // ("fhRecoJetEt","E_{T}^{reco}",250,0.,250.);
+       TH1F* GetRecoBinInputJetEt(){return fhRecoBinInputJetEt;}  // ("fhRecoInputJetEt","E_{T}^{reco}",250,0.,250.);
+
+       private:
+       void InitPlots();
+       Int_t                           fDebug;         // Debug value
+       Float_t                         fConeRadius;    // Cone radius to be used in filling
+       Float_t                         fNominalEnergy; // Force a nominal energy - specifically for 80+20 jets
+       AliEMCALJetFinderOutput*        fOutput;        // Output object to be analysed
+       //===================== CASE 1 ===========================================
+       TH1F                            *fhFragmFcn;    // ("hFragmFcn","Fragmentation Function",100,0,1);
+       TH1F                            *fhPartonFragmFcn;// ("hFragmFcn","Parton Fragmentation Function",100,0,1);
+       TH1F                            *fhPartonJT;    // ("hPartonJT","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+       TH1F                            *fhPartonPL;    // ("hPartonPL","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+       TH1F                            *fhJetJT;       // ("hJetJT","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+       TH1F                            *fhJetPL;       // ("hJetPL","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+       TH1F                            *fhJetEt;       // ("hJetEt","E_{T}^{reco}",250,0.,250.);
+       TH1F                            *fhJetEtDiff;   // ("hJetEt","E_{T}^{reco}",250,0.,250.);
+       TH1F                            *fhJetEta;      // ("hJetEta","#eta_{jet}^{reco}",180,-0.9,0.9);
+       TH1F                            *fhJetPhi;      // ("hJetPhi","#phi_{jet}^{reco}",62,0.,3.1);
+       TH1F                            *fhPartonEta;   // ("hPartonEta","#eta_{Parton}",180,-0.9,0.9);
+       TH1F                            *fhPartonPhi;   // ("hPartonPhi","#phi_{Parton}",62,0.,3.1);
+       TH1F                            *fhEtaDiff;     // ("hEtaDiff","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+       TH1F                            *fhPhiDiff;     // ("hPhiDiff","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+       TH2F                            *fhEtaPhiSpread;        // ("hEtaPhiSpread","#eta - #phi Distribution 
+                                                       //of Reconstructed Jets",192,-0.7,0.7,288,pi/3,pi);
+       TH1F                            *fhNJets;       // ("hNJets","N Reconstructed jets",11,-0.5,10.5);
+  
+       //============================== CASE 2 ============================================
+
+       TH1F                            *fhFragmFcn2;   // ("hFragmFcn2","Fragmentation Function",100,0,1);
+       TH1F                            *fhPartonFragmFcn2;// ("hFragmFcn2","Parton Fragmentation Function",100,0,1);
+       TH1F                            *fhPartonJT2;   // ("hPartonJT2","Track Momentum Perpendicular to Parton Axis",100,0.,10.);
+       TH1F                            *fhPartonPL2;   // ("hPartonPL2","Track Momentum Parallel to Parton Axis ",100,0.,100.);
+       TH1F                            *fhJetJT2;      // ("hJetJT2","Track Momentum Perpendicular to Jet Axis",100,0.,10.);
+       TH1F                            *fhJetPL2;      // ("hJetPL2","Track Momentum Parallel to Jet Axis ",100,0.,100.);
+       TH1F                            *fhJetEt2;      // ("hJetEt2","E_{T}^{reco}",250,0.,250.);
+       TH1F                            *fhJetEtDiff2;  // ("hJetEt","E_{T}^{reco}",250,0.,250.);
+       TH1F                            *fhJetEta2;     // ("hJetEta2","#eta_{jet}^{reco}",180,-0.9,0.9);
+       TH1F                            *fhJetPhi2;     // ("hJetPhi2","#phi_{jet}^{reco}",62,0.,3.1);
+       TH1F                            *fhPartonEta2;  // ("hPartonEta2","#eta_{Parton}",180,-0.9,0.9);
+       TH1F                            *fhPartonPhi2;  // ("hPartonPhi2","#phi_{Parton}",62,0.,3.1);
+       TH1F                            *fhEtaDiff2;    // ("hEtaDiff2","#eta_{jet}^{reco}-#eta_{jet}^{input}",100,-0.5,0.5);
+       TH1F                            *fhPhiDiff2;    // ("hPhiDiff2","#phi_{jet}^{reco}-#phi_{jet}^{input}",100,-0.5,0.5);
+       TH2F                            *fhEtaPhiSpread2;       // ("hEtaPhiSpread2","#eta - #phi Distribution 
+                                                       //of Reconstructed Jets",192,-0.7,0.7,288,pi/3,pi);
+       TH1F                            *fhNJets2;      // ("hNJets2","N Reconstructed jets",11,-0.5,10.5);
+       TH1F                            *fhJetEtSecond2; //("hJetEtSecond2","E_{T}^{reco}",250,0.,250.); 
+       TH1F                            *fhJetEtRatio2;  //("hJetEtRatio2","Ratio of Second Highest to Highest",100,0,1);
+       TH1F                            *fhEtaPhiDist2;  //("hEtaPhiDist2","Angular Distance Between First and Second",100,0,3);
+
+       //============================== ALL CASES ============================================
+
+       TH2F                            *fhInputOutput;  //("hJetEtRatio2","Ratio of Second Highest to Highest",100,0,1);
+
+       //============================== Reconstruction Bin Comparison  ============================================
+       
+       TH1F                            *fhRecoBinPt;          // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+       TH1F                            *fhRecoBinPtNoBg;              // ("fhRecoBinPt","Reconstructed Pt Distribution",100,0,1);
+       TH1F                            *fhRecoBinPartonPt;    // ("fhRecoBinPartonPt","Input Pt Distribution",100,0,1);
+       TH1F                            *fhRecoBinJetEt;       // ("fhRecoJetEt","E_{T}^{reco}",250,0.,250.);
+       TH1F                            *fhRecoBinInputJetEt;  // ("fhRecoInputJetEt","E_{T}^{reco}",250,0.,250.);
+    TH1F*                              fhJetPT ;// new TH1F("hJetPT","P_{T} Distribution",200,0,200);
+    TH1F*                              fhPartonPT ;// new TH1F("hPartonPT","Parton P_{T} Distribution",200,0,1);
+    TH1F*                              fhJetPT2 ;// new TH1F("hJetPT","P_{T} Distribution",200,0,200);
+    TH1F*                              fhPartonPT2 ;// new TH1F("hPartonPT","Parton P_{T} Distribution",200,0,1);
+    TH1F*                              fhRecoBinFragmFcn;//new TH1F("fhRecoBinFragmFcn","Reconstructed Frag. Fcn",100,0,1);
+    TH1F*                              fhRecoBinFragmFcnNoBg;//new TH1F("fhRecoBinFragmFcn","Reconstructed Frag. Fcn",100,0,1);
+    TH1F*                              fhRecoBinPartonFragmFcn;// new TH1F("fhRecoBinPartonFragmFcn","Input Bin Fragm Fcn Distribution",100,0,1);
+        
+       TH1F*                           fhJetInvE;// new TH1F("fhJetInvE","#frac{1}{E_{R}}",100,0,1);
+       TH1F*                           fhJetInvE2;// new TH1F("fhJetInvE2","#frac{1}{E_{R}}",100,0,1);
+       TH1F*                           fhBackHisto;
+       Float_t                         fScaleFactor; //Scaling to get back to correct energy
+       Bool_t                          fInitialised; // have histograms been initialised
+               
+       
+       ClassDef(AliEMCALJetFinderPlots,6)
+       
+};
+#endif
+
diff --git a/EMCAL/jetfinder/AliEMCALJetFinderTypes.h b/EMCAL/jetfinder/AliEMCALJetFinderTypes.h
new file mode 100644 (file)
index 0000000..9e2781c
--- /dev/null
@@ -0,0 +1,74 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+//  Enumerated types for use in JetFinder classes
+//
+//*-- Author: Mark Horner (LBL/UCT)
+//
+
+#ifndef ALIEMCALJETFINDERALGOBGCALCTYPE_T
+#define ALIEMCALJETFINDERALGOBGCALCTYPE_T
+
+        typedef enum { kRatio, kCone, kConstant  
+       } AliEMCALJetFinderAlgoBGCalcType_t;
+#endif
+
+#ifndef ALIEMCALJETFINDERRESETTYPE_T
+#define ALIEMCALJETFINDERRESETTYPE_T
+
+        typedef enum {  kResetData, kResetTracks, kResetDigits, kResetParameters,
+                        kResetAll, kResetPartons, kResetParticles, kResetJets
+        } AliEMCALJetFinderResetType_t;
+#endif
+
+#ifndef  ALIEMCALJETFINDERTRACKTYPE_T
+#define  ALIEMCALJETFINDERTRACKTYPE_T
+       typedef enum {  kAllP, kEM, kCharged, kNeutral, kHadron, kChargedHadron, kNoTracks, kEMChargedPi0, kNoNeutronNeutrinoKlong
+       } AliEMCALJetFinderTrackType_t;
+#endif
+
+#ifndef  ALIEMCALJETFINDERSMEARINGTYPE_T
+#define  ALIEMCALJETFINDERSMEARINGTYPE_T
+       typedef enum {  kSmear, kEfficiency , kSmearEffic, kPerfectTracks
+       } AliEMCALJetFinderSmearingType_t;
+#endif
+       
+#ifndef  ALIEMCALJETFINDEREMCALTYPE_T
+#define  ALIEMCALJETFINDEREMCALTYPE_T
+       typedef enum {  kHits, kTimeCut,kNoHits 
+       } AliEMCALJetFinderEMCALType_t;
+#endif
+
+#ifndef  ALIEMCALJETFINDERFILETYPE_T
+#define  ALIEMCALJETFINDERFILETYPE_T
+       typedef enum {  kHijing,kPythia,kData
+       } AliEMCALJetFinderFileType_t;
+#endif
+
+#ifndef  ALIEMCALJETFINDERUA1UNITFLAGTYPE_T
+#define  ALIEMCALJETFINDERUA1UNITFLAGTYPE_T
+       typedef enum {  kInCurrentJet, kInJet, kOutJet, kBelowMinEt
+       } AliEMCALJetFinderAlgoUA1UnitFlagType_t;
+#endif
+
+#ifndef  ALIEMCALJETFINDERUA1FILLUNITFLAGTYPE_T
+#define  ALIEMCALJETFINDERUA1FILLUNITFLAGTYPE_T
+       typedef enum {  kFillTracksOnly, kFillDigitsOnly, kFillAll
+       } AliEMCALJetFinderAlgoUA1FillUnitFlagType_t;
+#endif
diff --git a/EMCAL/jetfinder/AliEMCALJetMicroDst.cxx b/EMCAL/jetfinder/AliEMCALJetMicroDst.cxx
new file mode 100644 (file)
index 0000000..79fb831
--- /dev/null
@@ -0,0 +1,824 @@
+/**************************************************************************
+ * Copyright(c) 1998-2002, 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$ */
+
+//*-- Authors: Aleksei Pavlinov (WSU) 
+
+//*
+
+#include <TBrowser.h>
+#include <TFile.h>
+#include <TH1F.h>
+#include <TH2.h>
+#include <TParticle.h>
+#include <TROOT.h>
+#include <TString.h>
+#include <TVector3.h>
+
+#include "AliEMCALJetFinder.h"
+#include "AliEMCALJetMicroDst.h"
+#include "AliGenEventHeader.h"
+#include "AliGenHijingEventHeader.h"
+#include "AliHeader.h"
+#include "AliMC.h"
+#include "AliRun.h"
+
+ClassImp(AliEMCALJetMicroDst)
+
+TString gAliNameTree("jetMDST"); // 7-feb-2002
+
+//TH1F*  fhPtPart, *fhNJet, *fhPtJet;
+//TH2F*  fhEtaPhiPart, *fhEtaPhiJet;
+//TH1F*  fhNcell, *fhCellId, *fhCellEt, *fhSumEt;
+//TH1F*  fhNgrid, *fhGridId, *fhGridEt, *fhSumEtGrForJF;
+
+extern "C" void sgpdge_(Int_t &i, Int_t &pdggea);
+
+AliEMCALJetMicroDst::AliEMCALJetMicroDst(const char *name, const char *tit) : TNamed(name,tit)
+{
+       //constructor
+  fFile  = 0;
+  fTree  = 0;
+  fDebug = 0;
+    
+//  Don't add histos to the current directory
+//  TH1::AddDirectory(0);
+  gROOT->cd();
+  fhPtPart     = new TH1F("fhPtPart","P_{T} for partons", 300, 0., 300.);
+  // 16-jan-2002 - new limit fo phi 
+  fhEtaPhiPart = new TH2F("fhEtaPhiPart","#eta #phi distr.for partons after HSc", 
+                      28, -0.7, 0.7, 21, 0.0, (2.0/3.0)*TMath::Pi());
+
+  fhNJet  = new TH1F("fhNJet","number of jets", 11, -0.5, 10.5);
+  fhPtJet = new TH1F("fhPtJet","P_{T} for jets", 500, 0., 500.);
+  fhEtaPhiJet = new TH2F("fhEtaPhiJet","#eta #phi distr.for jets (W)", 
+                      28, -0.7, 0.7, 21, 0.0, (2.0/3.0)*TMath::Pi());
+
+  fhNcell  = new TH1F("fhNcell","#cell with de>0.0 for EMCAL", 1400, 0.0, 14000.);
+  fhCellId = new TH1F("fhCellId","cell ID with de>0.0 for EMCAL", 1400, 0.0, 14000.);
+  fhCellEt = new TH1F("fhCellEt","cell Et for EMCAL", 1000, 0.0, 10.);
+  fhSumEt  = new TH1F("fhSumEt","sum Et for EMCAL", 1000, 0.0, 1000.);
+
+  fhNgrid  = new TH1F("fhNgrid","#cell with de>0.0 in EMCAL grid for JF", 1400, 0.0, 14000.);
+  fhGridId = new TH1F("fhGridId","cell ID with de>0.0 in EMCAL grid for JF", 1400, 0.0, 14000.);
+  fhGridEt = new TH1F("fhGridEt","cell Et in EMCAL grid for JF", 1000, 0.0, 10.);
+  fhSumEtGrForJF  = new TH1F("fhSumEtGrForJF","sum Et in EMCAL grid for JF", 1000, 0.0, 1000.);
+
+  fListHist = MoveHistsToList("Hist For AliEMCALJetMicroDst", kFALSE); 
+}
+
+AliEMCALJetMicroDst::~AliEMCALJetMicroDst()
+{
+       //destructor
+  if(fFile) fFile->Close();
+}  
+
+Bool_t AliEMCALJetMicroDst::Create(TFile *file)
+{
+  // Creates the DST file
+  if(!file) {
+    Error("Create", "define TFile for output\n");
+    return kFALSE;
+  }
+  fFile     = file;
+  fFileName = fFile->GetName();
+  fFile->cd();
+  fTree = new TTree(gAliNameTree.Data(),"Temporary micro DST for jets analysis");
+  // for jet calibration - 4-mar-2003
+  fTree->Branch("fdecone", &fdecone, "fdecone/F");
+  fTree->Branch("fptcone", &fptcone, "fptcone/F");
+  // partons 
+  fTree->Branch("fnpart", &fnpart, "fnpart/I");
+  fTree->Branch("fxpt",  fxpt,  "fxpt[fnpart]/F");
+  fTree->Branch("fxeta", fxeta, "fxeta[fnpart]/F");
+  fTree->Branch("fxphi", fxphi, "fxphi[fnpart]/F");
+  // jets 
+  fTree->Branch("fnjet", &fnjet, "fnjet/I");
+  fTree->Branch("fjet",  fjet,  "fjet[fnjet]/F");
+  fTree->Branch("fjetaw", fjetaw, "fjetaw[fnjet]/F");
+  fTree->Branch("fjphiw", fjphiw, "fjphiw[fnjet]/F");
+  fTree->Branch("fjetal", fjetal, "fjetal[fnjet]/F");
+  fTree->Branch("fjphil", fjphil, "fjphil[fnjet]/F");
+
+  // Et in EMCAL itself 
+  fTree->Branch("fncell", &fncell, "fncell/I");
+  fTree->Branch("fidcell", fidcell, "fidcell[fncell]/I");
+  fTree->Branch("fetcell", fetcell, "fetcell[fncell]/F");
+
+  // Et in EMCAL grid for JF 
+  fTree->Branch("fngrid", &fngrid,  "fngrid/I");
+  fTree->Branch("fidgrid", fidgrid, "fidgrid[fngrid]/I");
+  fTree->Branch("fetgrid", fetgrid, "fetgrid[fngrid]/F");
+
+  // charge particle which hit to EMCAL
+  fTree->Branch("fnchp", &fnchp, "fnchp/I");
+  fTree->Branch("fpid", fpid, "fpid[fnchp]/I");
+  fTree->Branch("fppt", fppt, "fppt[fnchp]/F");
+  fTree->Branch("fpeta", fpeta, "fpeta[fnchp]/F");
+  fTree->Branch("fpphi", fpphi, "fpphi[fnchp]/F");
+
+  return kTRUE;
+}
+
+Bool_t AliEMCALJetMicroDst::Create(const char *fname)
+{
+       // Create member
+  TFile *file = new TFile(fname, "RECREATE");
+  if(file) {
+    //    fNameFile = fname;
+    return Create(file);
+  } else   return kFALSE;
+}
+
+Bool_t AliEMCALJetMicroDst::Open(const char *fname)
+{
+       //Open member
+  if(fFile && fFile->IsOpen()) fFile->Close();
+  if(strlen(fname)) fName = fname;
+  TFile *file = new TFile(fName.Data(), "READ");
+  if(file) {
+    Bool_t ini =  Initialize(file);
+    Info("Open", "open file %s : initialize TTree %i",fName.Data(), Int_t(ini)); 
+    return ini;
+  } else {
+    Error("Open", "can not open file %s",fName.Data()); 
+    return kFALSE;
+  }
+}
+
+const Char_t* AliEMCALJetMicroDst::DefineName(Int_t mode)
+{
+       //DefineName member
+  static TString dir, name;
+  //  dir = "jetDST/"; // 24-jan-2003
+  dir = "/auto/alice/pavlinov/jet/microDST/"; // 24-jan-2003
+  switch (mode) {
+  case 1: // for characteristic of BG
+    name = dir + "mDst1_1.root"; // Bg 2000 - first version 
+    SetTitle("Bg2000");
+    break;
+  case 2: // for characteristic of BG
+    name = dir + "mDst2_1.root"; // Bg 4000 - first version 
+    SetTitle("Bg4000");
+    break;
+  case 3: // for characteristic of BG
+    name = dir + "mDst3_1.root"; // Bg 8000 - first version 
+    SetTitle("Bg8000");
+    break;
+  case 4: // Central Hijing - 18-mar-2003
+    name  = dir  + "march/";
+    name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0HijingCentral.root";
+    SetTitle("HijingCentral");
+    break;
+  case 5: // Para Hijing (Dn/Dy=8000) - 21-mar-2003
+    name  = dir  + "march/";
+    name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0ParaHijing8000.root";
+    SetTitle("HIJINGparaDnDy8000");
+    break;
+  case 6: // Para Hijing (Dn/Dy=4000) - 21-mar-2003
+    name  = dir  + "march/";
+    name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0ParaHijing4000.root";
+    SetTitle("HIJINGparaDnDy4000");
+    break;
+  case 7: // Para Hijing (Dn/Dy=2000) - 21-mar-2003
+    name  = dir  + "march/";
+    name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0ParaHijing2000.root";
+    SetTitle("HIJINGparaDnDy2000");
+    break;
+  case 11: // pure PYTHIA with default value of parameters
+    name = dir + "jF_R0.50MinCell0.0PtCut0.0EtSeed8.0MinEt40.0BGSubtr0SF11.6.root";
+    break;
+  case 12: // 0 + background 
+    name = dir + "jF_R0.50MinCell0.0PtCut0.0EtSeed8.0MinEt40.0BGSubtr0SF11.6kBackground2000.root";
+    break;
+    // calibration case 
+  case 101:
+    name  = dir  + "march/";
+    name += "Pythia100_1.root";
+    SetTitle("Pythia100_1");
+    break;
+  case 102: // 2-apr-2003
+    name  = dir  + "march/";
+    name += "Pythia50_1.root";
+    SetTitle("Pythia50_1");
+    //    name = "microDst3th.root"; // 101 + (smearing and eff) - 14-mar-2003
+    break;
+  case 103:// 4-apr-2003
+    name  = dir  + "march/";
+    name += "Pythia200_1.root";
+    SetTitle("Pythia200_1");
+    //    name = "microDst4th.root"; // 102 + MinCell= 1.0
+    break;
+  default:
+    Fatal("DefineName", "NO  D E F A U L T : mode %i\n", mode);
+  }
+  Info("DefineName", "mode %5i file : %s : Title %s\n", mode, name.Data(), GetTitle());
+  return name.Data();
+}
+
+Bool_t AliEMCALJetMicroDst::Initialize(TFile *file)
+{
+       // Initialize method
+  if(file) fFile = file; 
+  fFile->cd();
+  fTree = (TTree*)fFile->Get(gAliNameTree.Data());
+  if(!fTree) return kFALSE;
+  // for jet calibration - 4-mar-2003
+  fTree->SetBranchAddress("fdecone",&fdecone);
+  fTree->SetBranchAddress("fptcone",&fptcone);
+  // partons
+  fTree->SetBranchAddress("fnpart",&fnpart);
+  fTree->SetBranchAddress("fxpt",   fxpt);
+  fTree->SetBranchAddress("fxeta",  fxeta);
+  fTree->SetBranchAddress("fxphi",  fxphi);
+  // jets 
+  fTree->SetBranchAddress("fnjet", &fnjet);
+  fTree->SetBranchAddress("fjet",   fjet);
+  fTree->SetBranchAddress("fjetaw", fjetaw);
+  fTree->SetBranchAddress("fjphiw", fjphiw);
+  fTree->SetBranchAddress("fjetal", fjetal);
+  fTree->SetBranchAddress("fjphil", fjphil);
+  // eT in EMCAL
+  fTree->SetBranchAddress("fncell", &fncell);
+  fTree->SetBranchAddress("fidcell", fidcell);
+  fTree->SetBranchAddress("fetcell", fetcell);
+  // eT in EMCAL grid for JF
+  fTree->SetBranchAddress("fngrid", &fngrid);
+  fTree->SetBranchAddress("fidgrid", fidgrid);
+  fTree->SetBranchAddress("fetgrid", fetgrid);
+  // 28-jan-2003
+  fTree->SetBranchAddress("fnchp", &fnchp);
+  fTree->SetBranchAddress("fpid", fpid);
+  fTree->SetBranchAddress("fppt", fppt);
+  fTree->SetBranchAddress("fpeta", fpeta);
+  fTree->SetBranchAddress("fpphi", fpphi);
+
+  return kTRUE;
+}
+
+void AliEMCALJetMicroDst::Print(Option_t* option) const
+{
+       // 
+  if(option);
+  if(fFile) {
+    fFile->Print();
+    if(fTree) fTree->Print();
+    else Info("Print", "TRee is zero\n");
+  } else {
+     Info("Print", "File with TRee is closed \n Name of file %s(from fFileName", fFileName.Data());
+  }
+
+  Info("Print", "******* Current(last) event *****");
+  printf("#partons %2i \n", fnpart);
+  for(Int_t i=0; i<fnpart; i++){
+    printf("     %1i Pt %7.1f eta  %7.4f phi  %7.4f \n",
+    i, fxpt[i],fxeta[i],fxphi[i]);  
+  }
+  printf("#jets    %2i \n", fnjet);
+  for(Int_t i=0; i<fnjet; i++){
+    printf("     %1i Et %7.1f etaw %7.4f phiw %7.4f \n",
+    i,fjet[i],fjetaw[i],fjphiw[i]);  
+  }
+  printf(" Title %s \n", GetTitle());
+}
+
+void AliEMCALJetMicroDst::Fill(AliRun *run, AliEMCALJetFinder* jetFinder, Int_t modeFilling)
+{
+  //  modeFilling >=1 - fill info for EMCAL grid
+  if(!run) run = gAlice;
+  AliGenEventHeader* evHeader = run->GetHeader()->GenEventHeader();
+  TString tmp(evHeader->ClassName());
+  if(tmp.Contains("Hijing")) {
+     AliGenHijingEventHeader *hijEvHeader = (AliGenHijingEventHeader*)evHeader;
+     FillPartons(hijEvHeader);
+  } else if(tmp.Contains("Pythia")) {
+     FillPartons();     
+  } else {
+    Error("Fill", "Wrong type of generator -> %s \n Info about partons will be absent",tmp.Data()); 
+  }
+
+  FillJets(jetFinder);
+
+  if(modeFilling >= 1) {
+     FillEtForEMCAL(jetFinder);
+     FillEtForGrid(jetFinder);
+     FillChargeParticles(jetFinder);
+  } else {
+     fncell = 0; // 27-jan-2003
+     fngrid = 0; // 27-jan-2003
+     fnchp  = 0;
+     // negative - no signal 
+     fdecone = -1.;
+     fptcone = -1.;
+  }
+
+  FillJetsControl();  //24-jan-2003
+
+  fTree->Fill();
+}
+
+void AliEMCALJetMicroDst::FillPartons(AliGenHijingEventHeader *header)
+{
+  //Make partons arrays
+  TLorentzVector parton[4];
+  header->GetJets(parton[0], parton[1], parton[2], parton[3]);
+
+  fnpart = 4; // 
+  for(Int_t i=0; i<4; i++){
+     fxpt[i]  = parton[i].Pt();
+     fxeta[i] = parton[i].Eta();
+     fxphi[i] = parton[i].Phi();
+  }
+}
+
+void AliEMCALJetMicroDst::FillPartons()
+{
+  // for case of Pythia -> get info from full event record
+
+  fnpart = 2;
+  TParticle *mPart;
+  Int_t ind;
+  for(Int_t i=6; i<8; i++){
+     mPart = gAlice->GetMCApp()->Particle(i);
+     ind   = i-6;
+     fxpt[ind]  = mPart->Pt();
+     fxeta[ind] = mPart->Eta();
+     fxphi[ind] = mPart->Phi();
+  }
+}
+
+void AliEMCALJetMicroDst::FillJets(AliEMCALJetFinder* jetFinder)
+{
+  // Fill Jets
+  fnjet = 0;
+  if(fDebug>1) Info("FillJets", "Debug"); 
+  if(!jetFinder) {
+    if(fDebug>1) Info("FillJets", "jetFinder is zero"); 
+    return;
+  }
+  fnjet = jetFinder->Njets();
+  if(fnjet>10) {
+    if(fDebug>1) Warning("FillJets", "wrong value of jetFinder->Njets() %i ", fnjet); 
+    fnjet = 10;
+  }
+  //  fhNJet->Fill(njet);
+  if(fDebug>1) Info("FillJets", "njet %i", fnjet); 
+  if(fnjet){
+    for(Int_t i=0; i<fnjet; i++){
+      fjet[i]   = jetFinder->JetEnergy(i);
+      fjetaw[i] = jetFinder->JetEtaW(i);
+      fjphiw[i] = jetFinder->JetPhiW(i);
+      fjetal[i] = jetFinder->JetEtaL(i);
+      fjphil[i] = jetFinder->JetPhiL(i);
+    }
+  }
+}
+
+void AliEMCALJetMicroDst::FillEtForEMCAL(AliEMCALJetFinder* jetFinder)
+{
+  // Fill Et for EMCAL
+   fncell = 0;
+   TH2F *hid = jetFinder->GetLegoEMCAL();
+   if(!hid) return;
+
+   Double_t de = 0.;
+   Int_t neta = hid->GetNbinsX(), nphi = hid->GetNbinsY();
+   for(Int_t ieta=1; ieta<=neta; ieta++) {
+      for(Int_t iphi=1; iphi<=nphi; iphi++) {
+        de = hid->GetBinContent(ieta,iphi);
+         if(de > 0.0) {
+          fetcell[fncell] = Float_t(de);
+           fidcell[fncell] = nphi*(ieta-1) + iphi;
+          fncell++;
+           if(fncell >= 13824) break; 
+          // Info("FillEtForEMCAL", " ncell %i6 id %i6 de %f \n", ncell, idcell[ncell], etcell[ncell]); 
+         }
+      }
+   }
+   if(fnjet == 1) {
+     // jet energy calculate around LP direction !!! - 10-mar-2003 
+      fdecone = jetFinder->EMCALConeEnergy(fjetal[0],fjphil[0]); 
+      fptcone = jetFinder->TrackConeEnergy(fjetal[0],fjphil[0]); // get from lego plot fo ch.part
+      Info("FillEtForEMCAL", " njet %i Emcal in cone %f pt ch.part in cone %f\n", fnjet, fdecone, fptcone); 
+      Info("FillEtForEMCAL", " jet - decone - ptcone : %9.2f\n", fjet[0]-fdecone-fptcone);
+   } else {
+      fdecone = -1.;
+      fptcone = -1.;
+   }
+
+   Info("FillEtForEMCAL", "neta %3i nphi %3i # array size %i Sum.Et %f\n", 
+   neta,nphi, fncell, hid->Integral());
+}
+
+void AliEMCALJetMicroDst::FillEtForGrid(AliEMCALJetFinder* jetFinder)
+{
+  // Fill ET for Grid
+   TH2F *hid = jetFinder->GetLego();
+   if(!hid) return;
+
+   FillArrays(hid, fngrid, fidgrid, fetgrid);
+}
+
+void AliEMCALJetMicroDst::FillArrays(TH2* hid, Int_t &n, Int_t *id, Float_t *et)
+{
+  // Fill arays
+   n = 0;
+   Double_t de = 0.;
+   Int_t neta = hid->GetNbinsX(), nphi = hid->GetNbinsY();
+   for(Int_t ieta=1; ieta<=neta; ieta++) {
+      for(Int_t iphi=1; iphi<=nphi; iphi++) {
+        de = hid->GetBinContent(ieta,iphi);
+         if(de > 0.0) {
+          et[n] = Float_t(de);
+           id[n] = nphi*(ieta-1) + iphi;
+          n++;
+           if(n >= 13824) break; 
+         }
+      }
+   }
+   Info("FillArrays", "neta %3i nphi %3i # array size %i Sum.Et %f\n", 
+   neta, nphi, n, hid->Integral());
+}
+
+void AliEMCALJetMicroDst::FillChargeParticles(AliEMCALJetFinder* jetFinder)
+{
+  // 28-jan-2003 for fullness ; 18-mar - sometimes 
+  fnchp = 0;
+  Int_t gid=0;
+  for(Int_t i=0; i<jetFinder->fNt; i++) {
+    //     fPdgT[i];
+     if(jetFinder->fTrackList[i] >= 1) {
+        sgpdge_(jetFinder->fPdgT[i], gid);
+        fpid[fnchp]  = gid; 
+        fppt[fnchp]  = jetFinder->fPtT[i];
+        fpeta[fnchp] = jetFinder->fEtaT[i];
+        fpphi[fnchp] = jetFinder->fPhiT[i];
+        fnchp++;
+     }
+  }
+  Info("FillChargedParticles", "fNtS %i : nchp %i -> %i\n", jetFinder->fNtS, fnchp, jetFinder->fNtS - fnchp);
+}
+
+void AliEMCALJetMicroDst::FillJetsControl()
+{  
+  // see FillJets(AliEMCALJetFinder* jetFinder) and FillPartons
+  fhNJet->Fill(fnjet);
+  for(Int_t i=0; i<fnjet; i++){
+     fhPtJet->Fill(fjet[i]);
+     fhEtaPhiJet->Fill(fjetaw[i],fjphiw[i]); 
+  }
+
+  for(Int_t i=0; i < fnpart; i++){
+     fhEtaPhiPart->Fill(fxeta[i], fxphi[i]);
+     fhPtPart->Fill(fxpt[i]);
+  }
+
+  Double_t sum = 0.0;
+  fhNcell->Fill(fncell);
+  for(Int_t i=0; i < fncell; i++){
+    fhCellId->Fill(fidcell[i]);
+    fhCellEt->Fill(fetcell[i]);
+    sum += Double_t(fetcell[i]);
+  }
+  fhSumEt->Fill(sum);
+
+  sum = 0.0;
+  fhNgrid->Fill(fngrid);
+  for(Int_t i=0; i < fngrid; i++){
+    fhGridId->Fill(fidgrid[i]);
+    fhGridEt->Fill(fetgrid[i]);
+    sum += Double_t(fetgrid[i]);
+  }
+  fhSumEtGrForJF->Fill(sum);
+}