updates to AliEmcalJet, AliEmcalJetTask and AliFJWrapper to include subtraction of...
[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        kSig1 = 1<<2,
24        kSig2 = 1<<3,
25        kBckgrd1 = 1<<4,
26        kBckgrd2 = 1<<5,
27        kBckgrd3 = 1<<6
28        //.....
29     }; 
30  
31   AliEmcalJet();
32   AliEmcalJet(Double_t px, Double_t py, Double_t pz);
33   AliEmcalJet(Double_t pt, Double_t eta, Double_t phi, Double_t m);
34   AliEmcalJet(const AliEmcalJet &jet); 
35   AliEmcalJet& operator=(const AliEmcalJet &jet);
36
37   Double_t          Px()                         const { return fPt*TMath::Cos(fPhi);  }
38   Double_t          Py()                         const { return fPt*TMath::Sin(fPhi);  }
39   Double_t          Pz()                         const { return fPt*TMath::SinH(fEta); }
40   Double_t          Pt()                         const { return fPt;                   }
41   Double_t          P()                          const { return fPt*TMath::CosH(fEta); }
42   Bool_t            PxPyPz(Double_t p[3])        const { p[0]=Px();p[1]=Py();p[2]=Pz(); return 1;         }
43   Double_t          Xv()                         const { return 0.;      }
44   Double_t          Yv()                         const { return 0.;      }
45   Double_t          Zv()                         const { return 0.;      }
46   Bool_t            XvYvZv(Double_t x[3])        const { x[0]=0;x[1]=0;x[2]=0; return 1;                  }
47   Double_t          OneOverPt()                  const { return 1./fPt;  }
48   Double_t          Phi()                        const { return fPhi;    }
49   Double_t          Theta()                      const { return 2*TMath::ATan(TMath::Exp(-fEta));         }
50   Double_t          E()                          const { Double_t p=P(); return TMath::Sqrt(M()*M()+p*p); }
51   Double_t          M()                          const { return fM; }
52   Double_t          Eta()                        const { return fEta;    }
53   Double_t          Y()                          const { return 0.5*TMath::Log((E()+Pz())/(E()-Pz()));    }
54   Short_t           Charge()                     const { return 0;       }
55   Int_t             GetLabel()                   const { return fLabel;  }
56   Int_t             PdgCode()                    const { return 0;       }
57   const Double_t   *PID()                        const { return 0;       }
58   void              GetMom(TLorentzVector &vec)  const;
59   void              Print(Option_t* option = "") const;
60
61   Double_t          Area()                       const { return fArea;                     }
62   Double_t          AreaPt()                     const { return fArea;                     }
63   Double_t          AreaEta()                    const { return fAreaEta;                  }
64   Double_t          AreaPhi()                    const { return fAreaPhi;                  }
65   Double_t          AreaEmc()                    const { return fAreaEmc;                  }
66   Bool_t            AxisInEmcal()                const { return fAxisInEmcal;              }
67   Int_t             Compare(const TObject* obj)  const;
68   Short_t           ClusterAt(Int_t idx)         const { return fClusterIDs.At(idx);       }
69   AliVCluster      *ClusterAt(Int_t idx, TClonesArray *ca)  const { if (!ca) return 0; return dynamic_cast<AliVCluster*>(ca->At(ClusterAt(idx))); }
70   AliVCluster      *GetLeadingCluster(TClonesArray *clusters) const;
71   UShort_t          GetNumberOfClusters()        const { return fClusterIDs.GetSize();     }
72   UShort_t          GetNumberOfTracks()          const { return fTrackIDs.GetSize();       }
73   UShort_t          GetNumberOfConstituents()    const { return GetNumberOfClusters()+GetNumberOfTracks();       }
74   Double_t          FracEmcalArea()              const { return fAreaEmc/fArea;            }
75   Bool_t            IsInsideEmcal()              const { return (fAreaEmc/fArea>0.999);    }
76   Bool_t            IsInEmcal()                  const { return (fAreaEmc>0);              }
77   Bool_t            IsMC()                       const { return (Bool_t)(MCPt() > 0);      }
78   Bool_t            IsSortable()                 const { return kTRUE;                     }
79   Double_t          MaxNeutralPt()               const { return fMaxNPt;                   }
80   Double_t          MaxChargedPt()               const { return fMaxCPt;                   }
81   Double_t          NEF()                        const { return fNEF;                      }
82   UShort_t          Nn()                         const { return fNn;                       }
83   UShort_t          Nch()                        const { return fNch;                      }
84   UShort_t          N()                          const { return Nch()+Nn();                }
85   Int_t             NEmc()                       const { return fNEmc;                     }
86   Double_t          MCPt()                       const { return fMCPt;                     }
87   Double_t          MaxClusterPt()               const { return MaxNeutralPt();            }
88   Double_t          MaxTrackPt()                 const { return MaxChargedPt();            }
89   Double_t          MaxPartPt()                  const { return fMaxCPt < fMaxNPt ? fMaxNPt : fMaxCPt;     }
90   Double_t          PtEmc()                      const { return fPtEmc;                    }
91   Double_t          PtSub()                      const { return fPtSub;                    }
92   Double_t          PtSub(Double_t rho)          const { return fPt - fArea*rho;           }
93   Double_t          PtSubVect(Double_t rho)      const;
94   Short_t           TrackAt(Int_t idx)           const { return fTrackIDs.At(idx);         }
95   AliVParticle     *TrackAt(Int_t idx, TClonesArray *ta)  const { if (!ta) return 0; return dynamic_cast<AliVParticle*>(ta->At(TrackAt(idx))); } 
96   AliVParticle     *GetLeadingTrack(TClonesArray *tracks) const;
97   Int_t             GetFlavour()                 const { return fFlavourTagging;           } 
98   
99   void              AddClusterAt(Int_t clus, Int_t idx){ fClusterIDs.AddAt(clus, idx);     }
100   void              AddFlavourTag(Int_t tag)           { fFlavourTagging |= tag; }
101   void              AddTrackAt(Int_t track, Int_t idx) { fTrackIDs.AddAt(track, idx);      }
102   void              Clear(Option_t */*option*/="")     { fClusterIDs.Set(0); fTrackIDs.Set(0); fClosestJets[0] = 0; fClosestJets[1] = 0; 
103                                                          fClosestJetsDist[0] = 0; fClosestJetsDist[1] = 0; fMatched = 0; fPtSub = 0; }
104   Double_t          DeltaR(const AliVParticle* part) const;
105
106   void              SetLabel(Int_t l)                  { fLabel = l;                       }
107   void              SetArea(Double_t a)                { fArea    = a;                     }
108   void              SetAreaEta(Double_t a)             { fAreaEta = a;                     }
109   void              SetAreaPhi(Double_t a)             { fAreaPhi = a;                     }
110   void              SetAreaEmc(Double_t a)             { fAreaEmc = a;                     }
111   void              SetAxisInEmcal(Bool_t b)           { fAxisInEmcal = b;                 }
112   void              SetFlavour(Int_t flavour)          { fFlavourTagging = flavour;        }
113   void              SetMaxNeutralPt(Double32_t t)      { fMaxNPt  = t;                     }
114   void              SetMaxChargedPt(Double32_t t)      { fMaxCPt  = t;                     }
115   void              SetNEF(Double_t nef)               { fNEF     = nef;                   }
116   void              SetNumberOfClusters(Int_t n)       { fClusterIDs.Set(n);               }
117   void              SetNumberOfTracks(Int_t n)         { fTrackIDs.Set(n);                 }
118   void              SetNumberOfCharged(Int_t n)        { fNch = n;                         }
119   void              SetNumberOfNeutrals(Int_t n)       { fNn = n;                          }
120   void              SetMCPt(Double_t p)                { fMCPt = p;                        }
121   void              SortConstituents();
122   std::vector<int>  SortConstituentsPt(TClonesArray *tracks) const;
123   void              SetNEmc(Int_t n)                   { fNEmc           = n;              }
124   void              SetPtEmc(Double_t pt)              { fPtEmc          = pt;             }
125   void              SetPtSub(Double_t ps)              { fPtSub          = ps;             } 
126   void              SetPtSubVect(Double_t ps)          { fPtVectSub      = ps;             }
127   Bool_t            TestFlavourTag(Int_t tag)          { return (Bool_t)((tag & fFlavourTagging) !=0); }
128
129   // Trigger
130   Bool_t            IsTriggerJet(UInt_t trigger=AliVEvent::kEMCEJE) const   { return (Bool_t)((fTriggers & trigger) != 0); }
131   void              SetTrigger(UInt_t trigger)                              { fTriggers  = trigger;                        }
132   void              AddTrigger(UInt_t trigger)                              { fTriggers |= trigger;                        }
133
134   // Matching
135   void              SetClosestJet(AliEmcalJet *j, Double_t d)       { fClosestJets[0] = j; fClosestJetsDist[0] = d    ; }
136   void              SetSecondClosestJet(AliEmcalJet *j, Double_t d) { fClosestJets[1] = j; fClosestJetsDist[1] = d    ; }
137   void              SetMatchedToClosest(UShort_t m)                 { fMatched        = 0; fMatchingType       = m    ; }
138   void              SetMatchedToSecondClosest(UShort_t m)           { fMatched        = 1; fMatchingType       = m    ; }
139   void              ResetMatching();
140   AliEmcalJet*      ClosestJet()                              const { return fClosestJets[0]                          ; }
141   Double_t          ClosestJetDistance()                      const { return fClosestJetsDist[0]                      ; }
142   AliEmcalJet*      SecondClosestJet()                        const { return fClosestJets[1]                          ; }
143   Double_t          SecondClosestJetDistance()                const { return fClosestJetsDist[1]                      ; }
144   AliEmcalJet*      MatchedJet()                              const { return fMatched < 2 ? fClosestJets[fMatched] : 0; }
145   UShort_t          GetMatchingType()                         const { return fMatchingType                            ; }
146
147   void              SetTaggedJet(AliEmcalJet *j)                    { fTaggedJet = j                                  ; }
148   void              SetTagStatus(Int_t i)                           { fTagStatus = i                                  ; }
149   AliEmcalJet*      GetTaggedJet()                            const { return fTaggedJet                               ; }
150   Int_t             GetTagStatus()                            const { return fTagStatus                               ; }
151
152   //jet shape derivatives
153   void              SetFirstDerivative(Double_t d)                  { fJetShapeMassFirstDer = d                       ; }
154   void              SetSecondDerivative(Double_t d)                 { fJetShapeMassSecondDer = d                      ; }
155   void              SetFirstOrderSubtracted(Double_t d)             { fJetShapeMassFirstSub = d                       ; }
156   void              SetSecondOrderSubtracted(Double_t d)            { fJetShapeMassSecondSub = d                      ; }
157   Double_t          GetFirstDerivative()                      const { return fJetShapeMassFirstDer                    ; }
158   Double_t          GetSecondDerivative()                     const { return fJetShapeMassSecondDer                   ; }
159   Double_t          GetFirstOrderSubtracted()                 const { return fJetShapeMassFirstSub                    ; }
160   Double_t          GetSecondOrderSubtracted()                const { return fJetShapeMassSecondSub                   ; }
161   
162   TArrayF GetGRNumerator()                                       const { return fGRNumerator                             ; }
163   TArrayF GetGRDenominator()                                     const { return fGRDenominator                           ; }
164   TArrayF GetGRNumeratorSub()                                    const { return fGRNumeratorSub                          ; }
165   TArrayF GetGRDenominatorSub()                                  const { return fGRDenominatorSub                        ; }
166   void              AddGRNumAt(Float_t num, Int_t idx)                 { fGRNumerator.AddAt(num, idx);                     }
167   void              AddGRDenAt(Float_t den, Int_t idx)                 { fGRDenominator.AddAt(den, idx);                   }
168   void              SetGRNumSize(UInt_t s) {fGRNumerator.Set(s); }
169   void              SetGRDenSize(UInt_t s) {fGRDenominator.Set(s); }
170
171   void              AddGRNumSubAt(Float_t num, Int_t idx)                 { fGRNumeratorSub.AddAt(num, idx);                     }
172   void              AddGRDenSubAt(Float_t den, Int_t idx)                 { fGRDenominatorSub.AddAt(den, idx);                   }
173   void              SetGRNumSubSize(UInt_t s) {fGRNumeratorSub.Set(s); }
174   void              SetGRDenSubSize(UInt_t s) {fGRDenominatorSub.Set(s); }
175   void              PrintGR();
176
177  protected:
178   Double32_t        fPt;                  //[0,0,12]   pt 
179   Double32_t        fEta;                 //[-1,1,12]  eta
180   Double32_t        fPhi;                 //[0,6.3,12] phi
181   Double32_t        fM;                   //[0,0,8]    mass
182   Double32_t        fNEF;                 //[0,1,8]    neutral energy fraction
183   Double32_t        fArea;                //[0,0,12]   area
184   Double32_t        fAreaEta;             //[0,0,12]   area eta
185   Double32_t        fAreaPhi;             //[0,0,12]   area phi
186   Double32_t        fAreaEmc;             //[0,0,12]   area on EMCAL surface (determined from ghosts)
187   Bool_t            fAxisInEmcal;         //           =true if jet axis inside EMCAL acceptance
188   Int_t             fFlavourTagging;      // tag jet with a falvour, bit 0 = no tag; bit 1= Dstar; bit 2 = D0
189   Double32_t        fMaxCPt;              //[0,0,12]   pt of maximum charged constituent
190   Double32_t        fMaxNPt;              //[0,0,12]   pt of maximum neutral constituent
191   Double32_t        fMCPt;                //           pt from MC particles contributing to the jet
192   Int_t             fNn;                  //           number of neutral constituents
193   Int_t             fNch;                 //           number of charged constituents
194   Double32_t        fPtEmc;               //[0,0,12]   pt in EMCAL acceptance
195   Int_t             fNEmc;                //           number of constituents in EMCAL acceptance
196   TArrayI           fClusterIDs;          //           array containing ids of cluster constituents  
197   TArrayI           fTrackIDs;            //           array containing ids of track constituents   
198   AliEmcalJet      *fClosestJets[2];      //!          if this is MC it contains the two closest detector level jets in order of distance and viceversa
199   Double32_t        fClosestJetsDist[2];  //!          distance to closest jets (see above)
200   UShort_t          fMatched;             //!          0,1 if it is matched with one of the closest jets; 2 if it is not matched
201   UShort_t          fMatchingType;        //!          matching type
202   AliEmcalJet      *fTaggedJet;           //!          jet tagged to this jet
203   Int_t             fTagStatus;           //!          status of tagging -1: NA 0: not tagged 1: tagged
204   Double_t          fPtSub;               //!          background subtracted pt (not stored set from outside) 
205   Double_t          fPtVectSub;           //!          background vector subtracted pt (not stored set from outside) 
206   UInt_t            fTriggers;            //!          triggers that the jet might have fired (AliVEvent::EOfflineTriggerTypes)
207   Double_t          fJetShapeMassFirstDer;  //!        result from shape derivatives for jet mass: 1st derivative
208   Double_t          fJetShapeMassSecondDer; //!        result from shape derivatives for jet mass: 2nd derivative
209   Double_t          fJetShapeMassFirstSub;  //!        result from shape derivatives for jet mass: 1st order subtracted
210   Double_t          fJetShapeMassSecondSub; //!        result from shape derivatives for jet mass: 2nd order subtracted
211   Int_t             fLabel;               //           label to inclusive jet for constituent subtracted jet    
212
213   TArrayF           fGRNumerator;         //!           array with angular structure function numerator
214   TArrayF           fGRDenominator;       //!           array with angular structure function denominator
215   TArrayF           fGRNumeratorSub;      //!           array with angular structure function numerator
216   TArrayF           fGRDenominatorSub;    //!           array with angular structure function denominator
217
218   private:
219     struct sort_descend
220         { // sort in decreasing order
221           // first value of the pair is Pt and the second is entry index
222         bool operator () (const std::pair<Double_t, Int_t>& p1, const std::pair<Double_t, Int_t>& p2)  { return p1.first > p2.first ; }
223         };
224
225   ClassDef(AliEmcalJet,15) // Emcal jet class in cylindrical coordinates
226 };
227 #endif