bug-fix: rotation of sub-leading jet in di-jet
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskJetMatching.h
1 #ifndef AliAnalysisTaskJetMatching_H
2 #define AliAnalysisTaskJetMatching_H
3
4 #include <AliAnalysisTaskEmcalJet.h>
5 #include <AliEmcalJet.h>
6 #include <AliVTrack.h>
7 #include <TClonesArray.h>
8 #include <TMath.h>
9 #include <TRandom3.h>
10
11 class TF1;
12 class THF1;
13 class THF2;
14 class TProfile;
15 class AliRhoParameter;
16 class AliLocalRhoParameter;
17 class TClonesArray;
18
19 class AliAnalysisTaskJetMatching : public AliAnalysisTaskEmcalJet
20 {
21     public:
22         // enumerators
23         enum matchingSceme      {kGeoEtaPhi, kGeoR, kDiJet};
24         enum sourceBKG          {kNoSourceBKG, kSourceRho, kSourceLocalRho};
25         enum targetBKG          {kNoTargetBKG, kTargetRho, kTargetLocalRho};
26         // constructors, destructor
27                                 AliAnalysisTaskJetMatching();
28                                 AliAnalysisTaskJetMatching(const char *name);
29         virtual                 ~AliAnalysisTaskJetMatching();
30         // setting up the task and technical aspects
31         void                    ExecOnce();
32         virtual Bool_t          Notify();
33         virtual void            UserCreateOutputObjects();
34         TH1F*                   BookTH1F(const char* name, const char* x, Int_t bins, Double_t min, Double_t max, Bool_t append = kTRUE);
35         TH2F*                   BookTH2F(const char* name, const char* x, const char* y, Int_t binsx, Double_t minx, Double_t maxx, Int_t binsy, Double_t miny, Double_t maxy, Bool_t append = kTRUE);
36         virtual Bool_t          Run();
37         /* inline */    Double_t PhaseShift(Double_t x) const {  
38             while (x>=TMath::TwoPi())x-=TMath::TwoPi();
39             while (x<0.)x+=TMath::TwoPi();
40             return x; }
41         /* inline */    Double_t PhaseShift(Double_t x, Double_t n) const {
42             x = PhaseShift(x);
43             if(TMath::Nint(n)==2) while (x>TMath::Pi()) x-=TMath::Pi();
44             if(TMath::Nint(n)==3) {
45                 if(x>2.*TMath::TwoPi()/n) x = TMath::TwoPi() - x;
46                 if(x>TMath::TwoPi()/n) x = TMath::TwoPi()-(x+TMath::TwoPi()/n);
47             }
48             return x; }
49         /* inline */    Bool_t CompareTracks(AliVParticle* a, AliVParticle* b) const {
50             return (TMath::AreEqualAbs(a->Pt(), b->Pt(), 1e-2) && TMath::AreEqualAbs(a->Eta(), b->Eta(), 1e-2) && TMath::AreEqualAbs(a->Phi(), b->Phi(), 1e-2)) ? kTRUE : kFALSE; }
51         /* inline */    Double_t GetR(AliVParticle* a, AliVParticle* b) const {
52                if(!(a&&b)) return 999;
53                Double_t phiA(a->Phi()), phiB(b->Phi()), etaA(a->Eta()), etaB(b->Eta());
54                if(TMath::Abs(phiA-phiB) > TMath::Abs(phiA-phiB + TMath::TwoPi())) phiA+=TMath::TwoPi();
55                if(TMath::Abs(phiA-phiB) > TMath::Abs(phiA-phiB - TMath::TwoPi())) phiA-=TMath::TwoPi();
56                return TMath::Sqrt(TMath::Abs((etaA-etaB)*(etaA-etaB)+(phiA-phiB)*(phiA-phiB))); }
57
58         // setters - setup how to run
59         void                    SetDebugMode(Int_t d)                           {fDebug = d;}
60         void                    SetMatchingScheme(matchingSceme m)              {fMatchingScheme = m;}
61         void                    SetMatchConstituents(Bool_t m)                  {fMatchConstituents = m;}
62         void                    SetMinFracRecoveredConstituents(Float_t f)      {fMinFracRecoveredConstituents = f;}
63         void                    SetMinFracRecoveredConstituentPt(Float_t f)     {fMinFracRecoveredConstituentPt = f;}
64         void                    SetUseEmcalBaseJetCuts(Bool_t b)                {fUseEmcalBaseJetCuts = b;}
65         void                    SetGetBijection(Bool_t b)                       {fGetBijection = b;}
66         void                    SetSourceBKG(sourceBKG b)                       {fSourceBKG = b;}
67         void                    SetTargetBKG(targetBKG b)                       {fTargetBKG = b;}
68         void                    SetSourceJetsName(const char* n)                {fSourceJetsName = n;}
69         void                    SetTargetJetsName(const char* n)                {fTargetJetsName = n; }
70         void                    SetMatchedJetsName(const char* n)               {fMatchedJetsName = n;}
71         void                    SetSourceLocalRhoName(const char* n)            {fSourceRhoName = n;}
72         void                    SetTargetLocalRhoName(const char* n)            {fTargetRhoName = n;}
73         void                    SetSourceRadius(Float_t r)                      {fSourceRadius = r;}
74         void                    SetTargetRadius(Float_t r)                      {fTargetRadius = r;}
75         void                    SetMatchEta(Float_t f)                          {fMatchEta = f;}
76         void                    SetMatchPhi(Float_t f)                          {fMatchPhi = f;}
77         void                    SetMatchR(Float_t f)                            {fMatchR = f;}
78         void                    SetDoDetectorResponse(Bool_t d)                 {fDoDetectorResponse = d;}
79         // methods
80         void                    DoGeometricMatchingEtaPhi();
81         void                    DoGeometricMatchingR();
82         void                    DoDiJetMatching();
83         void                    DoConstituentMatching();
84         void                    GetBijection();
85         void                    PostMatchedJets();
86         // fill histogrmas
87         void                    FillAnalysisSummaryHistogram() const;
88         void                    FillMatchedJetHistograms();
89         // setters - analysis details
90         /* inline */    Bool_t PassesCuts(const AliVTrack* track) const {
91             return (!track || TMath::Abs(track->Eta()) > 0.9 || track->Phi() < 0 || track->Phi() > TMath::TwoPi()) ? kFALSE : kTRUE; }
92         /* inline */    Bool_t PassesCuts(AliEmcalJet* jet, Int_t c)  { if(!fUseEmcalBaseJetCuts) return (jet) ? kTRUE : kFALSE; 
93             else return AcceptJet(jet, c);}
94         /* inline */    void ClearMatchedJetsCache() {
95             for (Int_t i(0); i < fNoMatchedJets; i++) {
96                 fMatchedJetContainer[i][0] = 0x0; fMatchedJetContainer[i][1] = 0x0; }
97             fNoMatchedJets = 0;
98         }
99         AliEmcalJet*            GetLeadingJet(TClonesArray* source, Int_t &leadingJetIndex, Double_t etaMin = -.7, Double_t etaMax = .7);
100         AliEmcalJet*            GetSubLeadingJet(TClonesArray* source, Int_t leadingJetIndex, Int_t &subLeadingJetIndex, Double_t etaMin = -.7, Double_t etaMax = .7);
101         void                    PrintInfo() const;
102         virtual void            Terminate(Option_t* option);
103
104     private: 
105         Int_t                   fDebug;                 // debug level (0 none, 1 fcn calls, 2 verbose)
106         TClonesArray*           fSourceJets;            //! array with source jets
107         TString                 fSourceJetsName;        // name of array with source jets
108         TClonesArray*           fTargetJets;            //! array with target jets
109         TString                 fTargetJetsName;        // name of array with target jets
110         TClonesArray*           fMatchedJets;           //! final list of matched jets which is added to event
111         TString                 fMatchedJetsName;       // name of list of matched jets
112         AliLocalRhoParameter*   fSourceRho;             //! source rho
113         TString                 fSourceRhoName;         // source rho  name
114         AliLocalRhoParameter*   fTargetRho;             //! target rho
115         TString                 fTargetRhoName;         // target rho name
116         Bool_t                  fUseScaledRho;          // use scaled rho
117         Float_t                 fSourceRadius;          // source radius 
118         Float_t                 fTargetRadius;          // target radius
119         matchingSceme           fMatchingScheme;        // select your favorite matching algorithm
120         Bool_t                  fUseEmcalBaseJetCuts;   // use the emcal jet base class for jet cuts
121         sourceBKG               fSourceBKG;             // subtracted background of source jets
122         targetBKG               fTargetBKG;             // subtracted background of target jets
123         // transient object pointers
124         TList*                  fOutputList;            //! output list
125         TH1F*                   fHistUnsortedCorrelation;       //! dphi correlation of unsorted jets
126         TH1F*                   fHistMatchedCorrelation;        //! dphi correlation of matched jets
127         TH1F*                   fHistSourceJetPt;       //! pt of source jets
128         TH1F*                   fHistMatchedSourceJetPt;//! pt of matched source jets
129         TH1F*                   fHistTargetJetPt;       //! pt of target jets
130         TH1F*                   fHistMatchedJetPt;      //! pt of matched jets
131         TH2F*                   fHistSourceMatchedJetPt;//! pt or source vs matched jets
132         TH2F*                   fHistDetectorResponseProb;      //! det prob
133         TH1F*                   fHistNoConstSourceJet;  //! number of constituents of source jet
134         TH1F*                   fHistNoConstTargetJet;  //! number of constituents of target jet
135         TH1F*                   fHistNoConstMatchJet;   //! number of constituents of matched jets
136         TProfile*               fProfFracPtMatched;     //! sum pt fraction for matched tracks / jet
137         TProfile*               fProfFracPtJets;        //! sum pt fraction for matched jets
138         TProfile*               fProfFracNoMatched;     //! no of constituents fraction found / jet
139         TProfile*               fProfFracNoJets;        //! no of consstituents fraction jet / jet
140         TH2F*                   fHistDiJet;             //! matched dijet eta, phi
141         TH2F*                   fHistDiJetLeadingJet;   //! leading jet (for dijet) eta, phi
142         TH1F*                   fHistDiJetDPhi;         //! dijet dphi
143         TH1F*                   fHistAnalysisSummary;   //! flags
144         TProfile*               fProfQAMatched;         //! QA spreads of matched jets
145         TProfile*               fProfQA;                //! QA spreads of source and target jets
146         Int_t                   fNoMatchedJets;         //! number of matched jets
147         AliEmcalJet*            fMatchedJetContainer[200][2];   //! pointers to matched jets
148         // geometric matching parameters
149         Float_t                 fMatchEta;              // max eta distance between centers of matched jets
150         Float_t                 fMatchPhi;              // max phi distance between centers of matched jets
151         Float_t                 fMatchR;                // max distance between matched jets
152         Bool_t                  fDoDetectorResponse;    // get detector response matrix (not normalized)
153         Bool_t                  fMatchConstituents;     // match constituents
154         Float_t                 fMinFracRecoveredConstituents;  // minimium fraction of constituents that needs to be found
155         Float_t                 fMinFracRecoveredConstituentPt; // minimium fraction of constituent pt that needs to be recovered
156         Bool_t                  fGetBijection;          // get bijection of source and matched jets
157         // pythia ntrials xsec bookkeeping
158         TH1F*                   fh1Trials;              //! sum of trails (in Notify)
159         TH1F*                   fh1AvgTrials;           //! average sum of trials (in Run)
160         TProfile*               fh1Xsec;                //! pythia cross section and trials
161         Float_t                 fAvgTrials;             // average number of trails per event
162
163         AliAnalysisTaskJetMatching(const AliAnalysisTaskJetMatching&);                  // not implemented
164         AliAnalysisTaskJetMatching& operator=(const AliAnalysisTaskJetMatching&);       // not implemented
165
166         ClassDef(AliAnalysisTaskJetMatching, 6);
167 };
168
169 #endif