18f8cf691c60f71d064e0259bf393bb2a8b9e136
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliEmcalJetTask.h
1 #ifndef ALIEMCALJETTASK_H
2 #define ALIEMCALJETTASK_H
3
4 class TClonesArray;
5 class AliVEvent;
6 class AliRhoParameter;
7
8 namespace fastjet {
9   class PseudoJet;
10 }
11
12 #include "AliLog.h"
13 #include "AliAnalysisTaskSE.h"
14 #include "AliFJWrapper.h"
15 #include "AliAODMCParticle.h"
16
17 class AliEmcalJetTask : public AliAnalysisTaskSE {
18  public:
19
20   enum JetType {
21     kNone=0,
22     kKT=1<<0,
23     kAKT=1<<1,
24     kFullJet=1<<2,
25     kChargedJet=1<<3,
26     kNeutralJet=1<<4,
27     kR020Jet=1<<5,
28     kR030Jet=1<<6,
29     kR040Jet=1<<7,
30     kRX1Jet=1<<8,  // user defined radii, use SetRadius(Double_t)
31     kRX2Jet=1<<9,
32     kRX3Jet=1<<10
33   };
34
35
36   AliEmcalJetTask();
37   AliEmcalJetTask(const char *name);
38   virtual ~AliEmcalJetTask();
39
40   void                   UserCreateOutputObjects();
41   void                   UserExec(Option_t *option);
42   void                   Terminate(Option_t *option);
43
44   Bool_t                 IsLocked()                       { if(fLocked) {AliFatal("Jet finder task is locked! Changing properties is not allowed."); return kTRUE;} else return kFALSE;};
45   void                   SetLocked()                      { fLocked = kTRUE;}
46   void                   SelectConstituents(UInt_t constSel, UInt_t MCconstSel)  { fConstSel = constSel; fMCConstSel = MCconstSel; };
47   void                   SetAlgo(Int_t a)                 { if(IsLocked()) return; if (a==0) fJetType |= kKT; else fJetType |= kAKT; }  // for backward compatibility only
48   void                   SetClusName(const char *n)       { if(IsLocked()) return; fCaloName      = n     ; }
49   void                   SetJetsName(const char *n)       { if(IsLocked()) return; fJetsName      = n     ; }
50   void                   SetJetsSubName(const char *n)    { fJetsSubName   = n     ; }
51   void                   SetJetType(UInt_t t)             { if(IsLocked()) return; fJetType       = t     ; }
52   void                   SetMarkConstituents(UInt_t m)    { if(IsLocked()) return; fMarkConst     = m     ; }
53   void                   SetMinJetArea(Double_t a)        { if(IsLocked()) return; fMinJetArea    = a     ; }
54   void                   SetMinJetClusPt(Double_t min)    { if(IsLocked()) return; fMinJetClusPt  = min   ; }
55   void                   SetMinJetPt(Double_t j)          { if(IsLocked()) return; fMinJetPt      = j     ; }
56   void                   SetMinJetTrackPt(Double_t min)   { if(IsLocked()) return; fMinJetTrackPt = min   ; }
57   void                   SetRadius(Double_t r)            { if(IsLocked()) return; fRadius        = r     ; if ((fJetType & (kRX1Jet|kRX2Jet|kRX3Jet)) == 0) AliWarning("Radius value will be ignored if jet type is not set to a user defined radius (kRX1Jet,kRX2Jet,kRX3Jet)."); }
58   void                   SetTrackEfficiency(Double_t t)   { if(IsLocked()) return; fTrackEfficiency = t   ; }
59   void                   SetTracksName(const char *n)     { if(IsLocked()) return; fTracksName    = n     ; }
60   void                   SetType(Int_t t)                 { if(IsLocked()) return; 
61                                                             if (t==0) fJetType |= kFullJet; 
62                                                             else if (t==1) fJetType |= kChargedJet; 
63                                                             else if (t==2) fJetType |= kNeutralJet; } // for backward compatibility only
64   void                   SetEtaRange(Double_t emi, Double_t ema) {if(IsLocked()) return; fEtaMin = emi; fEtaMax = ema; }
65   void                   SetPhiRange(Double_t pmi, Double_t pma) {if(IsLocked()) return; fPhiMin = pmi; fPhiMax = pma; }
66   void                   SetJetEtaRange(Double_t emi, Double_t ema) {if(IsLocked()) return; fJetEtaMin = emi; fJetEtaMax = ema; }
67   void                   SetJetPhiRange(Double_t pmi, Double_t pma) {if(IsLocked()) return; fJetPhiMin = pmi; fJetPhiMax = pma; }
68   void                   SetGhostArea(Double_t gharea)    { if(IsLocked()) return; fGhostArea      = gharea;  }
69   void                   SetMinMCLabel(Int_t s)           { if(IsLocked()) return; fMinMCLabel     = s     ;  }
70   void                   SetRecombScheme(Int_t scheme)    { if(IsLocked()) return; fRecombScheme   = scheme;  }
71   void                   SelectCollisionCandidates(UInt_t offlineTriggerMask = AliVEvent::kMB)
72   {
73     if(!fIsPSelSet)
74     {
75       fIsPSelSet = kTRUE;
76       fOfflineTriggerMask = offlineTriggerMask;
77     }
78     else
79     {
80       AliWarning("Manually setting the event selection for jet finders is not allowed! Using trigger=old_trigger | your_trigger");  
81       fOfflineTriggerMask = fOfflineTriggerMask | offlineTriggerMask;
82     }
83   }
84   void                   SetLegacyMode(Bool_t mode)           { if(IsLocked()) return; fLegacyMode = mode; }
85   void                   SetMCFlag(UInt_t m)                  { if(IsLocked()) return; fMCFlag     = m   ; }
86   void                   SelectHIJING(Bool_t s)               { if(IsLocked()) return; if (s) fGeneratorIndex = 0; else fGeneratorIndex = -1; }
87   void                   SetGeneratorIndex(Short_t i)         { if(IsLocked()) return; fGeneratorIndex = i; }
88   void                   SelectPhysicalPrimaries(Bool_t s)    { if(IsLocked()) return; 
89                                                                 if (s) fMCFlag |=  AliAODMCParticle::kPhysicalPrim ; 
90                                                                 else   fMCFlag &= ~AliAODMCParticle::kPhysicalPrim ; }
91
92   void                   SetCodeDebug(Bool_t val)         { fCodeDebug = val; }
93
94   void                   SetRhoName(const char *n)              { fRhoName      = n            ; }
95   void                   SetRhomName(const char *n)             { fRhomName     = n            ; }
96   void                   SetGenericSubtraction(Bool_t b)        { fDoGenericSubtraction     = b; }
97   void                   SetConstituentSubtraction(Bool_t b)    { fDoConstituentSubtraction = b; }
98   void                   SetUseExternalBkg(Bool_t b, Double_t rho, Double_t rhom) { fUseExternalBkg = b; fRho = rho; fRhom = rhom;}
99
100   UInt_t                 GetJetType()                     { return fJetType; }
101   Bool_t                 GetLegacyMode()                  { return fLegacyMode; }
102   TString                GetJetsSubName()                 { return fJetsSubName; }
103
104   const char*            GetJetsName()                    { return fJetsName.Data(); }
105   Double_t               GetRadius()                      { return fRadius; }
106   const char*            GetTracksName()                  { return fTracksName.Data(); }
107   const char*            GetClusName()                    { return fCaloName.Data(); }
108   const char*            GetRhoName()                     { return fRhoName.Data(); }
109   UInt_t                 GetMarkConstituents()            { return fMarkConst; }
110   Double_t               GetMinJetArea()                  { return fMinJetArea; }
111   Double_t               GetMinJetClusPt()                { return fMinJetClusPt; }
112   Double_t               GetMinJetPt()                    { return fMinJetPt; }
113   Double_t               GetMinJetTrackPt()               { return fMinJetTrackPt; }
114   Double_t               GetTrackEfficiency()             { return fTrackEfficiency; }
115   Double_t               GetGhostArea()                   { return fGhostArea; }
116   Int_t                  GetMinMCLabel()                  { return fMinMCLabel; }
117   Int_t                  GetRecombScheme()                { return fRecombScheme; }
118   Double_t               GetEtaMin()                      { return fEtaMin; }
119   Double_t               GetEtaMax()                      { return fEtaMax; }
120   Double_t               GetPhiMin()                      { return fPhiMin; }
121   Double_t               GetPhiMax()                      { return fPhiMax; }
122   Double_t               GetJetEtaMin()                   { return fJetEtaMin; }
123   Double_t               GetJetEtaMax()                   { return fJetEtaMax; }
124   Double_t               GetJetPhiMin()                   { return fJetPhiMin; }
125   Double_t               GetJetPhiMax()                   { return fJetPhiMax; }
126
127   AliVEvent*             GetEvent()                       { return fEvent;}
128   TClonesArray*          GetClusters()                    { return fClus;}
129   TClonesArray*          GetTracks()                      { return fTracks;}
130   TClonesArray*          GetJets()                        { return fJets;}
131
132  protected:
133   void                   FindJets();
134   Bool_t                 DoInit();
135   Bool_t                 GetSortedArray(Int_t indexes[], std::vector<fastjet::PseudoJet> array) const;
136
137   TString                fTracksName;             // name of track collection
138   TString                fCaloName;               // name of calo cluster collection
139   TString                fJetsName;               // name of jet collection
140   TString                fJetsSubName;            // name of subtracted jet collection
141   UInt_t                 fJetType;                // jet type (algorithm, radius, constituents)
142   UInt_t                 fConstSel;               // select constituents from a previous jet finding
143   UInt_t                 fMCConstSel;             // select MC constituents (label!=0) from a previous jet finding
144   UInt_t                 fMarkConst;              // constituents are marked (via TObject::SetBit) as belonging to the # leading jets
145   Double_t               fRadius;                 // jet radius
146   Double_t               fMinJetTrackPt;          // min jet track momentum   (applied before clustering)
147   Double_t               fMinJetClusPt;           // min jet cluster momentum (applied before clustering)
148   Double_t               fPhiMin;                 // minimum phi for constituents (applied before clustering)
149   Double_t               fPhiMax;                 // maximum phi for constituents (applied before clustering)
150   Double_t               fEtaMin;                 // minimum eta for constituents (applied before clustering)
151   Double_t               fEtaMax;                 // maximum eta for constituents (applied before clustering)
152   Double_t               fMinJetArea;             // min area to keep jet in output
153   Double_t               fMinJetPt;               // min jet pt to keep jet in output
154   Double_t               fJetPhiMin;              // minimum phi to keep jet in output
155   Double_t               fJetPhiMax;              // maximum phi to keep jet in output
156   Double_t               fJetEtaMin;              // minimum eta to keep jet in output
157   Double_t               fJetEtaMax;              // maximum eta to keep jet in output
158   Double_t               fGhostArea;              // ghost area
159   Int_t                  fMinMCLabel;             // minimum MC label value for the tracks/clusters being considered MC particles
160   Int_t                  fRecombScheme;           // recombination scheme used by fastjet
161   Double_t               fTrackEfficiency;        // artificial tracking inefficiency (0...1)
162   UInt_t                 fMCFlag;                 // select MC particles with flags
163   Short_t                fGeneratorIndex;         // select MC particles with generator index (default = -1 = switch off selection)
164   Bool_t                 fIsInit;                 //!=true if already initialized
165   Bool_t                 fLocked;                 // true if lock is set
166   Bool_t                 fIsPSelSet;              //!=true if physics selection was set
167   Bool_t                 fIsMcPart;               //!=true if MC particles are given as input
168   Bool_t                 fIsEmcPart;              //!=true if emcal particles are given as input (for clusters)
169   Bool_t                 fLegacyMode;             //! if true, enable FJ 2.x behavior
170   Bool_t                 fCodeDebug;              // use nontested code changes 
171
172   Bool_t                 fDoGenericSubtraction;   // calculate generic subtraction
173   Bool_t                 fDoConstituentSubtraction; // calculate constituent subtraction
174   Bool_t                 fUseExternalBkg;         // use external background for generic subtractor
175   TString                fRhoName;                // name of rho
176   TString                fRhomName;               // name of rhom
177   Double_t               fRho;                    // pT background density
178   Double_t               fRhom;                   // mT background density
179
180   TClonesArray          *fJets;                   //!jet collection
181   TClonesArray          *fJetsSub;                //!subtracted jet collection
182   AliVEvent             *fEvent;                  //!current event
183   TClonesArray          *fTracks;                 //!tracks collection
184   TClonesArray          *fClus;                   //!cluster collection
185   AliRhoParameter       *fRhoParam;               //!event rho
186   AliRhoParameter       *fRhomParam;              //!event rhom
187
188  private:
189   AliEmcalJetTask(const AliEmcalJetTask&);            // not implemented
190   AliEmcalJetTask &operator=(const AliEmcalJetTask&); // not implemented
191
192   ClassDef(AliEmcalJetTask, 14) // Jet producing task
193 };
194 #endif