2a9672c48be06d2b43b27c26b2c2804a9b42e1c2
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliEmcalJet.h
1 #ifndef AliEmcalJet_H
2 #define AliEmcalJet_H
3
4 #include <vector>
5 #include <algorithm>
6 #include <utility>
7 #include <TArrayS.h>
8 #include <TLorentzVector.h>
9 #include <TMath.h>
10 #include <TClonesArray.h>
11 #include <TVector2.h>
12
13 #include "AliVParticle.h"
14 #include "AliVCluster.h"
15 #include "AliVEvent.h"
16
17 class AliEmcalJet : public AliVParticle
18 {
19  public:
20      enum EFlavourTag{
21        kDStar = 1<<0,
22        kD0 = 1<<1
23        //.....
24     }; 
25  
26   AliEmcalJet();
27   AliEmcalJet(Double_t px, Double_t py, Double_t pz);
28   AliEmcalJet(Double_t pt, Double_t eta, Double_t phi, Double_t m);
29   AliEmcalJet(const AliEmcalJet &jet); 
30   AliEmcalJet& operator=(const AliEmcalJet &jet);
31
32   Double_t          Px()                         const { return fPt*TMath::Cos(fPhi);  }
33   Double_t          Py()                         const { return fPt*TMath::Sin(fPhi);  }
34   Double_t          Pz()                         const { return fPt*TMath::SinH(fEta); }
35   Double_t          Pt()                         const { return fPt;                   }
36   Double_t          P()                          const { return fPt*TMath::CosH(fEta); }
37   Bool_t            PxPyPz(Double_t p[3])        const { p[0]=Px();p[1]=Py();p[2]=Pz(); return 1;         }
38   Double_t          Xv()                         const { return 0.;      }
39   Double_t          Yv()                         const { return 0.;      }
40   Double_t          Zv()                         const { return 0.;      }
41   Bool_t            XvYvZv(Double_t x[3])        const { x[0]=0;x[1]=0;x[2]=0; return 1;                  }
42   Double_t          OneOverPt()                  const { return 1./fPt;  }
43   Double_t          Phi()                        const { return fPhi;    }
44   Double_t          Theta()                      const { return 2*TMath::ATan(TMath::Exp(-fEta));         }
45   Double_t          E()                          const { Double_t p=P(); return TMath::Sqrt(M()*M()+p*p); }
46   Double_t          M()                          const { return fM; }
47   Double_t          Eta()                        const { return fEta;    }
48   Double_t          Y()                          const { return 0.5*TMath::Log((E()+Pz())/(E()-Pz()));    }
49   Short_t           Charge()                     const { return 0;       }
50   Int_t             GetLabel()                   const { return -1;      }
51   Int_t             PdgCode()                    const { return 0;       }
52   const Double_t   *PID()                        const { return 0;       }
53   void              GetMom(TLorentzVector &vec)  const;
54   void              Print(Option_t* option = "") const;
55
56   Double_t          Area()                       const { return fArea;                     }
57   Double_t          AreaPt()                     const { return fArea;                     }
58   Double_t          AreaEta()                    const { return fAreaEta;                  }
59   Double_t          AreaPhi()                    const { return fAreaPhi;                  }
60   Double_t          AreaEmc()                    const { return fAreaEmc;                  }
61   Bool_t            AxisInEmcal()                const { return fAxisInEmcal;              }
62   Int_t             Compare(const TObject* obj)  const;
63   Short_t           ClusterAt(Int_t idx)         const { return fClusterIDs.At(idx);       }
64   AliVCluster      *ClusterAt(Int_t idx, TClonesArray *ca)  const { if (!ca) return 0; return dynamic_cast<AliVCluster*>(ca->At(ClusterAt(idx))); }
65   AliVCluster      *GetLeadingCluster(TClonesArray *clusters) const;
66   UShort_t          GetNumberOfClusters()        const { return fClusterIDs.GetSize();     }
67   UShort_t          GetNumberOfTracks()          const { return fTrackIDs.GetSize();       }
68   UShort_t          GetNumberOfConstituents()    const { return GetNumberOfClusters()+GetNumberOfTracks();       }
69   Double_t          FracEmcalArea()              const { return fAreaEmc/fArea;            }
70   Bool_t            IsInsideEmcal()              const { return (fAreaEmc/fArea>0.999);    }
71   Bool_t            IsInEmcal()                  const { return (fAreaEmc>0);              }
72   Bool_t            IsMC()                       const { return (Bool_t)(MCPt() > 0);      }
73   Bool_t            IsSortable()                 const { return kTRUE;                     }
74   Double_t          MaxNeutralPt()               const { return fMaxNPt;                   }
75   Double_t          MaxChargedPt()               const { return fMaxCPt;                   }
76   Double_t          NEF()                        const { return fNEF;                      }
77   UShort_t          Nn()                         const { return fNn;                       }
78   UShort_t          Nch()                        const { return fNch;                      }
79   UShort_t          N()                          const { return Nch()+Nn();                }
80   Int_t             NEmc()                       const { return fNEmc;                     }
81   Double_t          MCPt()                       const { return fMCPt;                     }
82   Double_t          MaxClusterPt()               const { return MaxNeutralPt();            }
83   Double_t          MaxTrackPt()                 const { return MaxChargedPt();            }
84   Double_t          MaxPartPt()                  const { return fMaxCPt < fMaxNPt ? fMaxNPt : fMaxCPt;     }
85   Double_t          PtEmc()                      const { return fPtEmc;                    }
86   Double_t          PtSub()                      const { return fPtSub;                    }
87   Double_t          PtSub(Double_t rho)          const { return fPt - fArea*rho;           }
88   Double_t          PtSubVect(Double_t rho)      const;
89   Short_t           TrackAt(Int_t idx)           const { return fTrackIDs.At(idx);         }
90   AliVParticle     *TrackAt(Int_t idx, TClonesArray *ta)  const { if (!ta) return 0; return dynamic_cast<AliVParticle*>(ta->At(TrackAt(idx))); } 
91   AliVParticle     *GetLeadingTrack(TClonesArray *tracks) const;
92   Int_t             GetFlavour()                 const { return fFlavourTagging;           } 
93   
94   void              AddClusterAt(Int_t clus, Int_t idx){ fClusterIDs.AddAt(clus, idx);     }
95   void              AddFlavourTag(Int_t tag)           { fFlavourTagging |= tag; }
96   void              AddTrackAt(Int_t track, Int_t idx) { fTrackIDs.AddAt(track, idx);      }
97   void              Clear(Option_t */*option*/="")     { fClusterIDs.Set(0); fTrackIDs.Set(0); fClosestJets[0] = 0; fClosestJets[1] = 0; 
98                                                          fClosestJetsDist[0] = 0; fClosestJetsDist[1] = 0; fMatched = 0; fPtSub = 0; }
99   Double_t          DeltaR(const AliVParticle* part) const;
100   void              SetArea(Double_t a)                { fArea    = a;                     }
101   void              SetAreaEta(Double_t a)             { fAreaEta = a;                     }
102   void              SetAreaPhi(Double_t a)             { fAreaPhi = a;                     }
103   void              SetAreaEmc(Double_t a)             { fAreaEmc = a;                     }
104   void              SetAxisInEmcal(Bool_t b)           { fAxisInEmcal = b;                 }
105   void              SetFlavour(Int_t flavour)          { fFlavourTagging = flavour;        }
106   void              SetMaxNeutralPt(Double32_t t)      { fMaxNPt  = t;                     }
107   void              SetMaxChargedPt(Double32_t t)      { fMaxCPt  = t;                     }
108   void              SetNEF(Double_t nef)               { fNEF     = nef;                   }
109   void              SetNumberOfClusters(Int_t n)       { fClusterIDs.Set(n);               }
110   void              SetNumberOfTracks(Int_t n)         { fTrackIDs.Set(n);                 }
111   void              SetNumberOfCharged(Int_t n)        { fNch = n;                         }
112   void              SetNumberOfNeutrals(Int_t n)       { fNn = n;                          }
113   void              SetMCPt(Double_t p)                { fMCPt = p;                        }
114   void              SortConstituents();
115   std::vector<int>  SortConstituentsPt(TClonesArray *tracks) const;
116   void              SetNEmc(Int_t n)                   { fNEmc           = n;              }
117   void              SetPtEmc(Double_t pt)              { fPtEmc          = pt;             }
118   void              SetPtSub(Double_t ps)              { fPtSub          = ps;             } 
119   void              SetPtSubVect(Double_t ps)          { fPtVectSub      = ps;             }
120   Bool_t            TestFlavourTag(Int_t tag)          { return (Bool_t)((tag & fFlavourTagging) !=0); }
121
122   // Trigger
123   Bool_t            IsTriggerJet(UInt_t trigger=AliVEvent::kEMCEJE) const   { return (Bool_t)((fTriggers & trigger) != 0); }
124   void              SetTrigger(UInt_t trigger)                              { fTriggers  = trigger;                        }
125   void              AddTrigger(UInt_t trigger)                              { fTriggers |= trigger;                        }
126
127   // Matching
128   void              SetClosestJet(AliEmcalJet *j, Double_t d)       { fClosestJets[0] = j; fClosestJetsDist[0] = d    ; }
129   void              SetSecondClosestJet(AliEmcalJet *j, Double_t d) { fClosestJets[1] = j; fClosestJetsDist[1] = d    ; }
130   void              SetMatchedToClosest(UShort_t m)                 { fMatched        = 0; fMatchingType       = m    ; }
131   void              SetMatchedToSecondClosest(UShort_t m)           { fMatched        = 1; fMatchingType       = m    ; }
132   void              ResetMatching();
133   AliEmcalJet*      ClosestJet()                              const { return fClosestJets[0]                          ; }
134   Double_t          ClosestJetDistance()                      const { return fClosestJetsDist[0]                      ; }
135   AliEmcalJet*      SecondClosestJet()                        const { return fClosestJets[1]                          ; }
136   Double_t          SecondClosestJetDistance()                const { return fClosestJetsDist[1]                      ; }
137   AliEmcalJet*      MatchedJet()                              const { return fMatched < 2 ? fClosestJets[fMatched] : 0; }
138   UShort_t          GetMatchingType()                         const { return fMatchingType                            ; }
139
140   void              SetTaggedJet(AliEmcalJet *j)                    { fTaggedJet = j                                  ; }
141   void              SetTagStatus(Int_t i)                           { fTagStatus = i                                  ; }
142   AliEmcalJet*      GetTaggedJet()                            const { return fTaggedJet                               ; }
143   Int_t             GetTagStatus()                            const { return fTagStatus                               ; }
144
145  protected:
146   Double32_t        fPt;                  //[0,0,12]   pt 
147   Double32_t        fEta;                 //[-1,1,12]  eta
148   Double32_t        fPhi;                 //[0,6.3,12] phi
149   Double32_t        fM;                   //[0,0,8]    mass
150   Double32_t        fNEF;                 //[0,1,8]    neutral energy fraction
151   Double32_t        fArea;                //[0,0,12]   area
152   Double32_t        fAreaEta;             //[0,0,12]   area eta
153   Double32_t        fAreaPhi;             //[0,0,12]   area phi
154   Double32_t        fAreaEmc;             //[0,0,12]   area on EMCAL surface (determined from ghosts)
155   Bool_t            fAxisInEmcal;         //           =true if jet axis inside EMCAL acceptance
156   Int_t             fFlavourTagging;      // tag jet with a falvour, bit 0 = no tag; bit 1= Dstar; bit 2 = D0
157   Double32_t        fMaxCPt;              //[0,0,12]   pt of maximum charged constituent
158   Double32_t        fMaxNPt;              //[0,0,12]   pt of maximum neutral constituent
159   Double32_t        fMCPt;                //           pt from MC particles contributing to the jet
160   Int_t             fNn;                  //           number of neutral constituents
161   Int_t             fNch;                 //           number of charged constituents
162   Double32_t        fPtEmc;               //[0,0,12]   pt in EMCAL acceptance
163   Int_t             fNEmc;                //           number of constituents in EMCAL acceptance
164   TArrayI           fClusterIDs;          //           array containing ids of cluster constituents  
165   TArrayI           fTrackIDs;            //           array containing ids of track constituents   
166   AliEmcalJet      *fClosestJets[2];      //!          if this is MC it contains the two closest detector level jets in order of distance and viceversa
167   Double32_t        fClosestJetsDist[2];  //!          distance to closest jets (see above)
168   UShort_t          fMatched;             //!          0,1 if it is matched with one of the closest jets; 2 if it is not matched
169   UShort_t          fMatchingType;        //!          matching type
170   AliEmcalJet      *fTaggedJet;           //!          jet tagged to this jet
171   Int_t             fTagStatus;           //!          status of tagging -1: NA 0: not tagged 1: tagged
172   Double_t          fPtSub;               //!          background subtracted pt (not stored set from outside) 
173   Double_t          fPtVectSub;           //!          background vector subtracted pt (not stored set from outside) 
174   UInt_t            fTriggers;            //!          triggers that the jet might have fired (AliVEvent::EOfflineTriggerTypes)
175
176   private:
177     struct sort_descend
178         { // sort in decreasing order
179           // first value of the pair is Pt and the second is entry index
180         bool operator () (const std::pair<Double_t, Int_t>& p1, const std::pair<Double_t, Int_t>& p2)  { return p1.first > p2.first ; }
181         };
182
183   ClassDef(AliEmcalJet,13) // Emcal jet class in cylindrical coordinates
184 };
185 #endif