]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskEmcalHJetMass.cxx
bd5dfd70ac312784d44f86e43040bcdaee2b1961
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskEmcalHJetMass.cxx
1 //
2 // Jet mass analysis task for jets recoiling from high pT hadron
3 //
4 // Author: M.Verweij
5
6 #include <TClonesArray.h>
7 #include <TH1F.h>
8 #include <TH2F.h>
9 #include <TH3F.h>
10 #include <THnSparse.h>
11 #include <TList.h>
12 #include <TLorentzVector.h>
13 #include <TProfile.h>
14 #include <TChain.h>
15 #include <TSystem.h>
16 #include <TFile.h>
17 #include <TKey.h>
18 #include <TArrayI.h>
19 #include <TArrayF.h>
20 #include <TRandom3.h>
21
22 #include "AliVCluster.h"
23 #include "AliVTrack.h"
24 #include "AliEmcalJet.h"
25 #include "AliRhoParameter.h"
26 #include "AliLog.h"
27 #include "AliEmcalParticle.h"
28 #include "AliAnalysisManager.h"
29 #include "AliJetContainer.h"
30 #include "AliParticleContainer.h"
31
32 #include "AliAODEvent.h"
33
34 #include "AliAnalysisTaskEmcalHJetMass.h"
35
36 ClassImp(EmcalHJetMassAnalysis::AliAnalysisTaskEmcalHJetMass)
37
38 namespace EmcalHJetMassAnalysis {
39
40   //________________________________________________________________________
41   AliAnalysisTaskEmcalHJetMass::AliAnalysisTaskEmcalHJetMass() : 
42     AliAnalysisTaskEmcalJet("AliAnalysisTaskEmcalHJetMass", kTRUE),
43     fContainerBase(0),
44     fContainerUnsub(1),
45     fMinFractionShared(0),
46     fUseUnsubJet(0),
47     fJetMassType(kRaw),
48     fDPhiHJetMax(0.6),
49     fTriggerTrackType(kInclusive),
50     fPtTTMin(0),
51     fPtTTMax(0),
52     fRandom(0),
53     fEmbConstSel(0),
54     fh1PtHadron(0),
55     fh3PtHPtJDPhi(0),
56     fh3PtJet1VsMassVsHPtAllSel(0),
57     fh3PtJet1VsMassVsHPtAllSelMatch(0),
58     fh3PtJet1VsMassVsHPtTagged(0),
59     fh3PtJet1VsMassVsHPtTaggedMatch(0),
60     fh3PtJet1VsRatVsHPtAllSel(0),
61     fh3PtJet1VsRatVsHPtAllSelMatch(0),
62     fh3PtJet1VsRatVsHPtTagged(0),
63     fh3PtJet1VsRatVsHPtTaggedMatch(0)
64   {
65     // Default constructor.
66
67     fh1PtHadron                       = new TH1F*[fNcentBins];
68     fh3PtHPtJDPhi                     = new TH3F*[fNcentBins];
69     fh3PtJet1VsMassVsHPtAllSel        = new TH3F*[fNcentBins];
70     fh3PtJet1VsMassVsHPtAllSelMatch   = new TH3F*[fNcentBins];
71     fh3PtJet1VsMassVsHPtTagged        = new TH3F*[fNcentBins];
72     fh3PtJet1VsMassVsHPtTaggedMatch   = new TH3F*[fNcentBins];
73     fh3PtJet1VsRatVsHPtAllSel         = new TH3F*[fNcentBins];
74     fh3PtJet1VsRatVsHPtAllSelMatch    = new TH3F*[fNcentBins];
75     fh3PtJet1VsRatVsHPtTagged         = new TH3F*[fNcentBins];
76     fh3PtJet1VsRatVsHPtTaggedMatch    = new TH3F*[fNcentBins];
77
78     for (Int_t i = 0; i < fNcentBins; i++) {
79       fh1PtHadron[i]                       = 0;
80       fh3PtHPtJDPhi[i]                     = 0;
81       fh3PtJet1VsMassVsHPtAllSel[i]        = 0;
82       fh3PtJet1VsMassVsHPtAllSelMatch[i]   = 0;
83       fh3PtJet1VsMassVsHPtTagged[i]        = 0;
84       fh3PtJet1VsMassVsHPtTaggedMatch[i]   = 0;
85       fh3PtJet1VsRatVsHPtAllSel[i]         = 0;
86       fh3PtJet1VsRatVsHPtAllSelMatch[i]    = 0;
87       fh3PtJet1VsRatVsHPtTagged[i]         = 0;
88       fh3PtJet1VsRatVsHPtTaggedMatch[i]    = 0;
89     }
90
91     fPtTTMin = new TArrayF();
92     fPtTTMax = new TArrayF();
93
94     SetMakeGeneralHistograms(kTRUE);
95   }
96
97   //________________________________________________________________________
98   AliAnalysisTaskEmcalHJetMass::AliAnalysisTaskEmcalHJetMass(const char *name) : 
99     AliAnalysisTaskEmcalJet(name, kTRUE),  
100     fContainerBase(0),
101     fContainerUnsub(1),
102     fMinFractionShared(0),
103     fUseUnsubJet(0),
104     fJetMassType(kRaw),
105     fDPhiHJetMax(0.6),
106     fTriggerTrackType(kInclusive),
107     fPtTTMin(0),
108     fPtTTMax(0),
109     fRandom(0),
110     fEmbConstSel(0),
111     fh1PtHadron(0),
112     fh3PtHPtJDPhi(0),
113     fh3PtJet1VsMassVsHPtAllSel(0),
114     fh3PtJet1VsMassVsHPtAllSelMatch(0),
115     fh3PtJet1VsMassVsHPtTagged(0),
116     fh3PtJet1VsMassVsHPtTaggedMatch(0),
117     fh3PtJet1VsRatVsHPtAllSel(0),
118     fh3PtJet1VsRatVsHPtAllSelMatch(0),
119     fh3PtJet1VsRatVsHPtTagged(0),
120     fh3PtJet1VsRatVsHPtTaggedMatch(0)
121   {
122     // Standard constructor.
123
124     fh1PtHadron                       = new TH1F*[fNcentBins];
125     fh3PtHPtJDPhi                     = new TH3F*[fNcentBins];
126     fh3PtJet1VsMassVsHPtAllSel        = new TH3F*[fNcentBins];
127     fh3PtJet1VsMassVsHPtAllSelMatch   = new TH3F*[fNcentBins];
128     fh3PtJet1VsMassVsHPtTagged        = new TH3F*[fNcentBins];
129     fh3PtJet1VsMassVsHPtTaggedMatch   = new TH3F*[fNcentBins];
130     fh3PtJet1VsRatVsHPtAllSel         = new TH3F*[fNcentBins];
131     fh3PtJet1VsRatVsHPtAllSelMatch    = new TH3F*[fNcentBins];
132     fh3PtJet1VsRatVsHPtTagged         = new TH3F*[fNcentBins];
133     fh3PtJet1VsRatVsHPtTaggedMatch    = new TH3F*[fNcentBins];
134  
135     for (Int_t i = 0; i < fNcentBins; i++) {
136       fh1PtHadron[i]                       = 0;
137       fh3PtHPtJDPhi[i]                     = 0;
138       fh3PtJet1VsMassVsHPtAllSel[i]        = 0;
139       fh3PtJet1VsMassVsHPtAllSelMatch[i]   = 0;
140       fh3PtJet1VsMassVsHPtTagged[i]        = 0;
141       fh3PtJet1VsMassVsHPtTaggedMatch[i]   = 0;
142       fh3PtJet1VsRatVsHPtAllSel[i]         = 0;
143       fh3PtJet1VsRatVsHPtAllSelMatch[i]    = 0;
144       fh3PtJet1VsRatVsHPtTagged[i]         = 0;
145       fh3PtJet1VsRatVsHPtTaggedMatch[i]    = 0;
146     }
147
148     fPtTTMin = new TArrayF();
149     fPtTTMax = new TArrayF();
150
151     SetMakeGeneralHistograms(kTRUE);
152   }
153
154   //________________________________________________________________________
155   AliAnalysisTaskEmcalHJetMass::~AliAnalysisTaskEmcalHJetMass()
156   {
157     // Destructor.
158
159     if(fRandom)      delete fRandom;
160     if(fPtTTMin)     delete fPtTTMin;
161     if(fPtTTMax)     delete fPtTTMax;
162   }
163
164   //________________________________________________________________________
165   void AliAnalysisTaskEmcalHJetMass::UserCreateOutputObjects()
166   {
167     // Create user output.
168
169     AliAnalysisTaskEmcalJet::UserCreateOutputObjects();
170
171     Bool_t oldStatus = TH1::AddDirectoryStatus();
172     TH1::AddDirectory(kFALSE);
173
174     const Int_t nBinsPt  = 200;
175     const Double_t minPt = -50.;
176     const Double_t maxPt = 150.;
177
178     const Int_t nBinsM  = 100;
179     const Double_t minM = -20.;
180     const Double_t maxM = 80.;
181
182     const Int_t nBinsR  = 100;
183     const Double_t minR = -0.2;
184     const Double_t maxR = 0.8;
185
186     const Int_t nBinsPtH  = 100;
187     const Double_t minPtH = 0.;
188     const Double_t maxPtH = 100.;
189
190     const Int_t nBinsPhi  = 18*4;
191     const Double_t minPhi = -0.5*TMath::Pi();
192     const Double_t maxPhi = 1.5*TMath::Pi();
193
194     TString histName = "";
195     TString histTitle = "";
196     for (Int_t i = 0; i < fNcentBins; i++) {
197       histName = TString::Format("fh1PtHadron_%d",i);
198       histTitle = TString::Format("%s;#it{p}_{T,h}",histName.Data());
199       fh1PtHadron[i] = new TH1F(histName.Data(),histTitle.Data(),200.,0.,200.);
200       fOutput->Add(fh1PtHadron[i]);
201
202       histName = TString::Format("fh3PtHPtJDPhi_%d",i);
203       histTitle = TString::Format("%s;#it{p}_{T,h};#it{p}_{T,jet};#Delta#varphi_{h,jet}",histName.Data());
204       fh3PtHPtJDPhi[i] = new TH3F(histName.Data(),histTitle.Data(),nBinsPtH,minPtH,maxPtH,nBinsPt,minPt,maxPt,nBinsPhi,minPhi,maxPhi);
205       fOutput->Add(fh3PtHPtJDPhi[i]);
206
207       histName = TString::Format("fh3PtJet1VsMassVsHPtAllSel_%d",i);
208       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1};#it{p}_{T,h}",histName.Data());
209       fh3PtJet1VsMassVsHPtAllSel[i] = new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsM,minM,maxM,nBinsPtH,minPtH,maxPtH);
210       fOutput->Add(fh3PtJet1VsMassVsHPtAllSel[i]);
211
212       histName = TString::Format("fh3PtJet1VsMassVsHPtAllSelMatch_%d",i);
213       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1};#it{p}_{T,h}",histName.Data());
214       fh3PtJet1VsMassVsHPtAllSelMatch[i] = new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsM,minM,maxM,nBinsPtH,minPtH,maxPtH);
215       fOutput->Add(fh3PtJet1VsMassVsHPtAllSelMatch[i]);
216
217       histName = TString::Format("fh3PtJet1VsMassVsHPtTagged_%d",i);
218       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1};#it{p}_{T,h}",histName.Data());
219       fh3PtJet1VsMassVsHPtTagged[i] =  new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsM,minM,maxM,nBinsPtH,minPtH,maxPtH);
220       fOutput->Add(fh3PtJet1VsMassVsHPtTagged[i]);
221
222       histName = TString::Format("fh3PtJet1VsMassVsHPtTaggedMatch_%d",i);
223       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1};#it{p}_{T,h}",histName.Data());
224       fh3PtJet1VsMassVsHPtTaggedMatch[i] =  new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsM,minM,maxM,nBinsPtH,minPtH,maxPtH);
225       fOutput->Add(fh3PtJet1VsMassVsHPtTaggedMatch[i]);
226
227       //
228       histName = TString::Format("fh3PtJet1VsRatVsHPtAllSel_%d",i);
229       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1}/#it{p}_{T,jet1};#it{p}_{T,h}",histName.Data());
230       fh3PtJet1VsRatVsHPtAllSel[i] = new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsR,minR,maxR,nBinsPtH,minPtH,maxPtH);
231       fOutput->Add(fh3PtJet1VsRatVsHPtAllSel[i]);
232
233       histName = TString::Format("fh3PtJet1VsRatVsHPtAllSelMatch_%d",i);
234       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1}/#it{p}_{T,jet1};#it{p}_{T,h}",histName.Data());
235       fh3PtJet1VsRatVsHPtAllSelMatch[i] = new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsR,minR,maxR,nBinsPtH,minPtH,maxPtH);
236       fOutput->Add(fh3PtJet1VsRatVsHPtAllSelMatch[i]);
237
238       histName = TString::Format("fh3PtJet1VsRatVsHPtTagged_%d",i);
239       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1}/#it{p}_{T,jet1};#it{p}_{T,h}",histName.Data());
240       fh3PtJet1VsRatVsHPtTagged[i] =  new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsR,minR,maxR,nBinsPtH,minPtH,maxPtH);
241       fOutput->Add(fh3PtJet1VsRatVsHPtTagged[i]);
242
243       histName = TString::Format("fh3PtJet1VsRatVsHPtTaggedMatch_%d",i);
244       histTitle = TString::Format("%s;#it{p}_{T,jet1};#it{M}_{jet1}/#it{p}_{T,jet1};#it{p}_{T,h}",histName.Data());
245       fh3PtJet1VsRatVsHPtTaggedMatch[i] =  new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsR,minR,maxR,nBinsPtH,minPtH,maxPtH);
246       fOutput->Add(fh3PtJet1VsRatVsHPtTaggedMatch[i]);
247     }
248
249     TH1::AddDirectory(oldStatus);
250
251     fRandom = new TRandom3(0);
252
253     PostData(1, fOutput); // Post data for ALL output slots > 0 here.
254   }
255
256   //________________________________________________________________________
257   Bool_t AliAnalysisTaskEmcalHJetMass::Run()
258   {
259     // Run analysis code here, if needed. It will be executed before FillHistograms().
260
261     AliParticleContainer *pCont = GetParticleContainer(0);
262     AliJetContainer      *jCont = GetJetContainer(fContainerBase);
263     if(!pCont || !jCont) return kFALSE;
264
265     AliVParticle *vp = NULL;
266
267     if(fTriggerTrackType==kInclusive) {
268       pCont->ResetCurrentID();
269       while((vp = pCont->GetNextAcceptParticle())) {
270         fh1PtHadron[fCentBin]->Fill(vp->Pt()); //all hadrons
271         AliEmcalJet* jet = NULL;
272         if(jCont) {
273           jCont->ResetCurrentID();
274           while((jet = jCont->GetNextAcceptJet())) {
275             Double_t dphi = GetDeltaPhi(vp,jet)-TMath::Pi();
276             fh3PtHPtJDPhi[fCentBin]->Fill(vp->Pt(),jet->Pt() - GetRhoVal(fContainerBase)*jet->Area(),dphi);
277             if(dphi>fDPhiHJetMax) continue;
278             FillHJetHistograms(vp,jet);
279           }
280         }
281       }
282     }
283     else if(fTriggerTrackType==kSingleInclusive) {
284      for(Int_t it = 0; it<fPtTTMin->GetSize(); it++) {
285        vp = GetSingleInclusiveTT(pCont,fPtTTMin->At(it),fPtTTMax->At(it));
286        if(!vp) continue;
287        fh1PtHadron[fCentBin]->Fill(vp->Pt()); //all trigger tracks
288        AliEmcalJet* jet = NULL;
289        jCont->ResetCurrentID();
290        while((jet = jCont->GetNextAcceptJet())) {
291          Double_t dphi = GetDeltaPhi(vp,jet)-TMath::Pi();
292          fh3PtHPtJDPhi[fCentBin]->Fill(vp->Pt(),jet->Pt() - GetRhoVal(fContainerBase)*jet->Area(),dphi);
293          if(dphi>fDPhiHJetMax) continue;
294          FillHJetHistograms(vp,jet);
295        }
296      }//trigger track types
297     }
298     return kTRUE;
299   }
300
301   //________________________________________________________________________
302   AliVParticle* AliAnalysisTaskEmcalHJetMass::GetSingleInclusiveTT(AliParticleContainer *pCont, Double_t ptmin, Double_t ptmax) const {
303     AliVParticle *vp;
304     TArrayI arr; arr.Set(pCont->GetNParticles());
305     arr.Reset();
306     Int_t counter = -1;
307     pCont->ResetCurrentID();
308     while((vp = pCont->GetNextAcceptParticle())) {
309       if(vp->Pt()>=ptmin && vp->Pt()<ptmax ) {
310         counter++;
311         arr.SetAt(pCont->GetCurrentID(),counter);
312       }
313     }
314     if(counter<0) return NULL;
315     //select trigger track randomly
316     fRandom->SetSeed(arr.At(0)); //random selection reproducible
317     Double_t rnd = fRandom->Uniform() * counter;
318     Int_t trigID = arr.At(TMath::FloorNint(rnd));
319     vp = pCont->GetParticle(trigID);
320     return vp;
321   }
322
323   //________________________________________________________________________
324   Bool_t AliAnalysisTaskEmcalHJetMass::FillHJetHistograms(const AliVParticle *vp, const AliEmcalJet *jet)
325   {
326     // Fill hadron-jet histograms.
327     Double_t pt = vp->Pt();
328     Double_t ptJet = jet->Pt() - GetRhoVal(fContainerBase)*jet->Area();
329     Double_t mJet = GetJetMass(jet);
330     Double_t rat = -1.;
331     if(ptJet<0. || ptJet>0.) rat = mJet/ptJet;
332
333     fh3PtJet1VsMassVsHPtAllSel[fCentBin]->Fill(ptJet,mJet,pt);
334     fh3PtJet1VsRatVsHPtAllSel[fCentBin]->Fill(ptJet,rat,pt);
335
336     Double_t fraction = -1.;
337     if(fUseUnsubJet) {
338       AliEmcalJet *jetUS = NULL;
339       AliJetContainer *jetContUS = GetJetContainer(fContainerUnsub);
340       Int_t ifound = 0;
341       Int_t ilab = -1;
342       for(Int_t i = 0; i<jetContUS->GetNJets(); i++) {
343         jetUS = jetContUS->GetJet(i);
344         if(jetUS->GetLabel()==jet->GetLabel()) {
345           ifound++;
346           if(ifound==1) ilab = i;
347         }
348       }
349       if(ifound>1) AliDebug(2,Form("Found %d partners",ifound));
350       if(ifound==0) jetUS = 0x0;
351       else          jetUS = jetContUS->GetJet(ilab);
352       fraction = jetContUS->GetFractionSharedPt(jetUS);
353     } else {
354       AliJetContainer *jetCont = GetJetContainer(fContainerBase);
355       fraction = jetCont->GetFractionSharedPt(jet);
356     }
357   
358     if(fMinFractionShared>0. && fraction>fMinFractionShared) {
359       if(vp->TestBits(fEmbConstSel) != (Int_t)fEmbConstSel) 
360         AliDebug(11,Form("Skipping track with pT=%f because it does not match the bit mask (%d, %d)", vp->Pt(), fEmbConstSel, vp->TestBits(fEmbConstSel)));
361       else {
362         fh3PtJet1VsMassVsHPtAllSelMatch[fCentBin]->Fill(ptJet,mJet,pt);
363         fh3PtJet1VsRatVsHPtAllSelMatch[fCentBin]->Fill(ptJet,rat,pt);
364       }
365     }
366
367     if(jet->GetTagStatus()<1 || !jet->GetTaggedJet())
368       return kFALSE;
369
370     fh3PtJet1VsMassVsHPtTagged[fCentBin]->Fill(ptJet,mJet,pt);
371     fh3PtJet1VsRatVsHPtTagged[fCentBin]->Fill(ptJet,rat,pt);
372
373     if(fMinFractionShared>0. && fraction>fMinFractionShared) {
374       if(vp->TestBits(fEmbConstSel) != (Int_t)fEmbConstSel) 
375         AliDebug(11,Form("Skipping track with pT=%f because it does not match the bit mask (%d, %d)", vp->Pt(), fEmbConstSel, vp->TestBits(fEmbConstSel)));
376       else {
377         fh3PtJet1VsMassVsHPtTaggedMatch[fCentBin]->Fill(ptJet,mJet,pt);
378         fh3PtJet1VsRatVsHPtTaggedMatch[fCentBin]->Fill(ptJet,rat,pt);
379       }
380     }
381     return kTRUE;
382   }
383
384   //________________________________________________________________________
385   Double_t AliAnalysisTaskEmcalHJetMass::GetJetMass(const AliEmcalJet *jet) const {
386     //calc subtracted jet mass
387     if(fJetMassType==kRaw)
388       return jet->M();
389     else if(fJetMassType==kDeriv)
390       return jet->GetSecondOrderSubtracted();
391   
392     return 0;
393   }
394
395   //________________________________________________________________________
396   Double_t AliAnalysisTaskEmcalHJetMass::GetDeltaPhi(const AliVParticle *vp, const AliEmcalJet* jet) const {
397     // Calculate azimuthal angle between particle and jet. range:[-0.5\pi,1.5\pi]
398     return GetDeltaPhi(vp->Phi(),jet->Phi());
399   }
400
401   //________________________________________________________________________
402   Double_t AliAnalysisTaskEmcalHJetMass::GetDeltaPhi(Double_t phi1, Double_t phi2) const {
403     // Calculate azimuthal angle between phi1 and phi2. range:[-0.5\pi,1.5\pi]
404     Double_t dPhi = phi1-phi2;
405     if(dPhi <-0.5*TMath::Pi())  dPhi += TMath::TwoPi();
406     if(dPhi > 1.5*TMath::Pi())  dPhi -= TMath::TwoPi();
407     return dPhi;
408   }
409
410
411   //________________________________________________________________________
412   Bool_t AliAnalysisTaskEmcalHJetMass::RetrieveEventObjects() {
413     //
414     // retrieve event objects
415     //
416     if (!AliAnalysisTaskEmcalJet::RetrieveEventObjects())
417       return kFALSE;
418
419     return kTRUE;
420   }
421
422   //________________________________________________________________________
423   void AliAnalysisTaskEmcalHJetMass::AddTriggerTrackPtCuts(Float_t min, Float_t max) {
424     if(!fPtTTMin) fPtTTMin = new TArrayF();
425     if(!fPtTTMax) fPtTTMax = new TArrayF();
426     Int_t newSize = fPtTTMin->GetSize()+1;
427     fPtTTMin->Set(newSize);
428     fPtTTMax->Set(newSize);
429     fPtTTMin->AddAt(min,newSize-1);
430     fPtTTMax->AddAt(max,newSize-1);
431   }
432
433   //_______________________________________________________________________
434   void AliAnalysisTaskEmcalHJetMass::Terminate(Option_t *) 
435   {
436     // Called once at the end of the analysis.
437   }
438 }
439