]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New helper functions: sort jet constituents by pt and delta R (from A. Sevcenco)
authorsaiola <salvatore.aiola@cern.ch>
Tue, 3 Jun 2014 20:53:15 +0000 (16:53 -0400)
committersaiola <salvatore.aiola@cern.ch>
Tue, 3 Jun 2014 20:54:39 +0000 (16:54 -0400)
PWGJE/EMCALJetTasks/AliEmcalJet.cxx
PWGJE/EMCALJetTasks/AliEmcalJet.h

index 8ae3f3ca0e961da819c773bbb98cbbb157840141..f99fa83c3e9e38d3b609efe08dd1c676bbca6b36 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 //
 // Emcal jet class.
 //
@@ -268,6 +267,50 @@ void AliEmcalJet::SortConstituents()
   std::sort(fTrackIDs.GetArray(), fTrackIDs.GetArray() + fTrackIDs.GetSize());
 }
 
+//__________________________________________________________________________________________________
+Double_t AliEmcalJet::DeltaR (const AliVParticle* part) const
+{ // Helper function to calculate the distance between two jets or a jet and a particle
+    Double_t dPhi = this->Phi() - part->Phi();
+    Double_t dEta = this->Eta() - part->Eta();
+    dPhi = TVector2::Phi_mpi_pi ( dPhi );
+
+    return TMath::Sqrt ( dPhi * dPhi + dEta * dEta );
+}
+
+
+//__________________________________________________________________________________________________
+std::vector<int> AliEmcalJet::SortConstituentsPt( TClonesArray *tracks ) const
+{   //___________________________________________
+    // Sorting by p_T (decreasing) jet constituents
+    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    typedef std::pair<Double_t, Int_t> ptidx_pair;
+
+    // Create vector for Pt sorting
+    std::vector<ptidx_pair> pair_list ;
+
+    for ( Int_t i_entry = 0; i_entry < GetNumberOfTracks(); i_entry++ )
+        {
+        AliVParticle *track = TrackAt(i_entry, tracks);
+        if (!track)
+            {
+            AliError(Form("Unable to find jet track %d in collection %s (pos in collection %d, max %d)", i_entry, tracks->GetName(), TrackAt(i_entry), tracks->GetEntriesFast()));
+            continue;
+            }
+
+        pair_list.push_back( std::make_pair ( track->Pt(), i_entry ) );
+        }
+
+    std::stable_sort( pair_list.begin() , pair_list.end() , sort_descend() );
+
+    // return an vector of indexes of constituents (sorted descending by pt)
+    std::vector <int> index_sorted_list;
+
+    for ( std::vector< std::pair<Double_t,Int_t> >::iterator it = pair_list.begin(); it != pair_list.end(); ++it)
+        { index_sorted_list.push_back( (*it).second ); } // populating the return object with indexes of sorted tracks
+
+    return index_sorted_list;
+}
+
 //__________________________________________________________________________________________________
 AliVParticle* AliEmcalJet::GetLeadingTrack(TClonesArray *tracks) const
 {
index 5b7e4f787c4ae303a07c1185e6b33df98f4ed4eb..2a9672c48be06d2b43b27c26b2c2804a9b42e1c2 100644 (file)
@@ -1,12 +1,14 @@
 #ifndef AliEmcalJet_H
 #define AliEmcalJet_H
 
-// $Id$
-
+#include <vector>
+#include <algorithm>
+#include <utility>
 #include <TArrayS.h>
 #include <TLorentzVector.h>
 #include <TMath.h>
 #include <TClonesArray.h>
+#include <TVector2.h>
 
 #include "AliVParticle.h"
 #include "AliVCluster.h"
@@ -94,6 +96,7 @@ class AliEmcalJet : public AliVParticle
   void              AddTrackAt(Int_t track, Int_t idx) { fTrackIDs.AddAt(track, idx);      }
   void              Clear(Option_t */*option*/="")     { fClusterIDs.Set(0); fTrackIDs.Set(0); fClosestJets[0] = 0; fClosestJets[1] = 0; 
                                                          fClosestJetsDist[0] = 0; fClosestJetsDist[1] = 0; fMatched = 0; fPtSub = 0; }
+  Double_t          DeltaR(const AliVParticle* part) const;
   void              SetArea(Double_t a)                { fArea    = a;                     }
   void              SetAreaEta(Double_t a)             { fAreaEta = a;                     }
   void              SetAreaPhi(Double_t a)             { fAreaPhi = a;                     }
@@ -109,6 +112,7 @@ class AliEmcalJet : public AliVParticle
   void              SetNumberOfNeutrals(Int_t n)       { fNn = n;                          }
   void              SetMCPt(Double_t p)                { fMCPt = p;                        }
   void              SortConstituents();
+  std::vector<int>  SortConstituentsPt(TClonesArray *tracks) const;
   void              SetNEmc(Int_t n)                   { fNEmc           = n;              }
   void              SetPtEmc(Double_t pt)              { fPtEmc          = pt;             }
   void              SetPtSub(Double_t ps)              { fPtSub          = ps;             } 
@@ -169,6 +173,13 @@ class AliEmcalJet : public AliVParticle
   Double_t          fPtVectSub;           //!          background vector subtracted pt (not stored set from outside) 
   UInt_t            fTriggers;            //!          triggers that the jet might have fired (AliVEvent::EOfflineTriggerTypes)
 
-  ClassDef(AliEmcalJet,12) // Emcal jet class in cylindrical coordinates
+  private:
+    struct sort_descend
+        { // sort in decreasing order
+          // first value of the pair is Pt and the second is entry index
+        bool operator () (const std::pair<Double_t, Int_t>& p1, const std::pair<Double_t, Int_t>& p2)  { return p1.first > p2.first ; }
+        };
+
+  ClassDef(AliEmcalJet,13) // Emcal jet class in cylindrical coordinates
 };
 #endif