]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliAnalysisTaskSAJF.cxx
consistent filename
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliAnalysisTaskSAJF.cxx
CommitLineData
00514d01 1// $Id$
91f4b7c5 2//
980821ba 3// Jet finder analysis task (S.Aiola).
91f4b7c5 4//
5//
25283b37 6
7#include <TChain.h>
8#include <TClonesArray.h>
9#include <TH1F.h>
10#include <TH2F.h>
11#include <TList.h>
12#include <TLorentzVector.h>
13#include <TParticle.h>
14
15#include "AliAnalysisManager.h"
16#include "AliCentrality.h"
f0a0fd33 17#include "AliVCluster.h"
25283b37 18#include "AliESDtrack.h"
19#include "AliEmcalJet.h"
25283b37 20#include "AliAODTrack.h"
25283b37 21#include "AliEmcalJet.h"
22#include "AliVEventHandler.h"
35789a2d 23#include "AliPicoTrack.h"
25283b37 24
00514d01 25#include "AliAnalysisTaskSAJF.h"
25283b37 26
00514d01 27ClassImp(AliAnalysisTaskSAJF)
25283b37 28
29//________________________________________________________________________
00514d01 30AliAnalysisTaskSAJF::AliAnalysisTaskSAJF() :
31 AliAnalysisTaskSE("AliAnalysisTaskSAJF"),
91f4b7c5 32 fAnaType(kEMCAL),
25283b37 33 fOutput(0),
34 fTracksName("Tracks"),
35 fCaloName("CaloClusters"),
36 fJetsName("Jets"),
e82e282c 37 fTrgClusName("ClustersL1GAMMAFEE"),
25283b37 38 fTracks(0),
39 fCaloClusters(0),
40 fJets(0),
e82e282c 41 fTrgClusters(0),
f0a0fd33 42 fCent(0),
43 fHistCentrality(0),
91f4b7c5 44 fHistJetPhiEta(0),
f0a0fd33 45 Ptbins(400),
25283b37 46 Ptlow(0),
f0a0fd33 47 Ptup(200),
48 Ebins(400),
25283b37 49 Elow(0),
f0a0fd33 50 Eup(200)
25283b37 51{
52 // Default constructor.
f0a0fd33 53
54 for (Int_t i = 0; i < 4; i++) {
55 fHistJetsE[i] = 0;
56 fHistJetsNE[i] = 0;
57 fHistJetsNEF[i] = 0;
58 fHistJetsZ[i] = 0;
59 fHistLeadingJetE[i] = 0;
60 fHistTracksPtLJ[i] = 0;
61 fHistClusELJ[i] = 0;
62 fHistTracksPtBkg[i] = 0;
63 fHistClusEBkg[i] = 0;
64 }
91f4b7c5 65
66 // Output slot #1 writes into a TH1 container
67 DefineOutput(1, TList::Class());
25283b37 68}
69
70//________________________________________________________________________
00514d01 71AliAnalysisTaskSAJF::AliAnalysisTaskSAJF(const char *name) :
72 AliAnalysisTaskSE(name),
91f4b7c5 73 fAnaType(kEMCAL),
25283b37 74 fOutput(0),
75 fTracksName("Tracks"),
76 fCaloName("CaloClusters"),
77 fJetsName("Jets"),
e82e282c 78 fTrgClusName("ClustersL1GAMMAFEE"),
25283b37 79 fTracks(0),
80 fCaloClusters(0),
81 fJets(0),
e82e282c 82 fTrgClusters(0),
f0a0fd33 83 fCent(0),
84 fHistCentrality(0),
91f4b7c5 85 fHistJetPhiEta(0),
f0a0fd33 86 Ptbins(400),
25283b37 87 Ptlow(0),
f0a0fd33 88 Ptup(200),
89 Ebins(400),
25283b37 90 Elow(0),
f0a0fd33 91 Eup(200)
25283b37 92{
93 // Standard constructor.
94
f0a0fd33 95 for (Int_t i = 0; i < 4; i++) {
96 fHistJetsE[i] = 0;
97 fHistJetsNE[i] = 0;
98 fHistJetsNEF[i] = 0;
99 fHistJetsZ[i] = 0;
100 fHistLeadingJetE[i] = 0;
101 fHistTracksPtLJ[i] = 0;
102 fHistClusELJ[i] = 0;
103 fHistTracksPtBkg[i] = 0;
104 fHistClusEBkg[i] = 0;
105 }
91f4b7c5 106
107 // Output slot #1 writes into a TH1 container
108 DefineOutput(1, TList::Class());
25283b37 109}
110
111//________________________________________________________________________
00514d01 112AliAnalysisTaskSAJF::~AliAnalysisTaskSAJF()
25283b37 113{
114 // Destructor
115}
116
117//________________________________________________________________________
00514d01 118void AliAnalysisTaskSAJF::UserCreateOutputObjects()
25283b37 119{
f0a0fd33 120 // Create histograms
25283b37 121
122 fOutput = new TList();
123 fOutput->SetOwner(); // IMPORTANT!
124
f0a0fd33 125 fHistCentrality = new TH1F("fHistCentrality","Event centrality distribution", Ebins, 0, 100);
126 fHistCentrality->GetXaxis()->SetTitle("Centrality (%)");
127 fHistCentrality->GetYaxis()->SetTitle("counts");
128 fOutput->Add(fHistCentrality);
25283b37 129
91f4b7c5 130 fHistJetPhiEta = new TH2F("fHistJetPhiEta","Phi-Eta distribution of jets", 20, -2, 2, 32, 0, 6.4);
131 fHistJetPhiEta->GetXaxis()->SetTitle("Eta");
132 fHistJetPhiEta->GetYaxis()->SetTitle("Phi");
133 fOutput->Add(fHistJetPhiEta);
134
f0a0fd33 135 TString histname;
136
137 for (Int_t i = 0; i < 4; i++) {
138 histname = "fHistJetsE_";
139 histname += i;
140 fHistJetsE[i] = new TH1F(histname.Data(), histname.Data(), Ebins, Elow, Eup);
141 fHistJetsE[i]->GetXaxis()->SetTitle("E [GeV]");
142 fHistJetsE[i]->GetYaxis()->SetTitle("counts");
143 fOutput->Add(fHistJetsE[i]);
25283b37 144
f0a0fd33 145 histname = "fHistJetsNE_";
146 histname += i;
147 fHistJetsNE[i] = new TH1F(histname.Data(), histname.Data(), Ebins, Elow, Eup);
148 fHistJetsNE[i]->GetXaxis()->SetTitle("E [GeV]");
149 fHistJetsNE[i]->GetYaxis()->SetTitle("counts");
150 fOutput->Add(fHistJetsNE[i]);
25283b37 151
f0a0fd33 152 histname = "fHistJetsNEF_";
153 histname += i;
154 fHistJetsNEF[i] = new TH1F(histname.Data(), histname.Data(), Ebins, 0, 1.2);
155 fHistJetsNEF[i]->GetXaxis()->SetTitle("NEF");
156 fHistJetsNEF[i]->GetYaxis()->SetTitle("counts");
157 fOutput->Add(fHistJetsNEF[i]);
158
159 histname = "fHistJetsZ_";
160 histname += i;
161 fHistJetsZ[i] = new TH1F(histname.Data(), histname.Data(), Ebins, 0, 1.2);
162 fHistJetsZ[i]->GetXaxis()->SetTitle("Z");
163 fHistJetsZ[i]->GetYaxis()->SetTitle("counts");
164 fOutput->Add(fHistJetsZ[i]);
165
166 histname = "fHistLeadingJetE_";
167 histname += i;
168 fHistLeadingJetE[i] = new TH1F(histname.Data(), histname.Data(), Ebins, Elow, Eup);
169 fHistLeadingJetE[i]->GetXaxis()->SetTitle("E [GeV]");
170 fHistLeadingJetE[i]->GetYaxis()->SetTitle("counts");
171 fOutput->Add(fHistLeadingJetE[i]);
25283b37 172
f0a0fd33 173 histname = "fHistTracksPtLJ_";
174 histname += i;
175 fHistTracksPtLJ[i] = new TH1F(histname.Data(), histname.Data(), Ptbins, Ptlow, Ptup);
176 fHistTracksPtLJ[i]->GetXaxis()->SetTitle("P_{T} [GeV/c]");
177 fHistTracksPtLJ[i]->GetYaxis()->SetTitle("counts");
178 fOutput->Add(fHistTracksPtLJ[i]);
179
180 histname = "fHistClusELJ_";
181 histname += i;
182 fHistClusELJ[i] = new TH1F(histname.Data(), histname.Data(), Ebins, Elow, Eup);
183 fHistClusELJ[i]->GetXaxis()->SetTitle("E [GeV]");
184 fHistClusELJ[i]->GetYaxis()->SetTitle("counts");
185 fOutput->Add(fHistClusELJ[i]);
186
187 histname = "fHistTracksPtBkg_";
188 histname += i;
189 fHistTracksPtBkg[i] = new TH1F(histname.Data(), histname.Data(), Ptbins, Ptlow, Ptup);
190 fHistTracksPtBkg[i]->GetXaxis()->SetTitle("P_{T} [GeV/c]");
191 fHistTracksPtBkg[i]->GetYaxis()->SetTitle("counts");
192 fOutput->Add(fHistTracksPtBkg[i]);
193
194 histname = "fHistClusEBkg_";
195 histname += i;
196 fHistClusEBkg[i] = new TH1F(histname.Data(), histname.Data(), Ebins, Elow, Eup);
197 fHistClusEBkg[i]->GetXaxis()->SetTitle("E [GeV]");
198 fHistClusEBkg[i]->GetYaxis()->SetTitle("counts");
199 fOutput->Add(fHistClusEBkg[i]);
e82e282c 200 }
201
25283b37 202 PostData(1, fOutput); // Post data for ALL output slots >0 here, to get at least an empty histogram
203}
204
00514d01 205void AliAnalysisTaskSAJF::RetrieveEventObjects()
25283b37 206{
207 fCaloClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
f0a0fd33 208 if (!fCaloClusters) {
209 AliWarning(Form("Could not retrieve clusters!"));
210 }
25283b37 211
f0a0fd33 212 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
25283b37 213 if (!fTracks) {
e82e282c 214 AliWarning(Form("Could not retrieve tracks!"));
25283b37 215 }
f0a0fd33 216
217 fJets = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fJetsName));
25283b37 218 if (!fJets) {
e82e282c 219 AliWarning(Form("Could not retrieve jets!"));
220 }
f0a0fd33 221
222 if (strcmp(fTrgClusName,"")) {
223 fTrgClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTrgClusName));
224 if (!fTrgClusters) {
225 AliWarning(Form("Could not retrieve trigger clusters!"));
226 }
25283b37 227 }
f0a0fd33 228
229 fCent = InputEvent()->GetCentrality();
25283b37 230}
231
00514d01 232AliVTrack* AliAnalysisTaskSAJF::GetTrack(const Int_t i) const
25283b37 233{
e82e282c 234 if (fTracks)
235 return dynamic_cast<AliVTrack*>(fTracks->At(i));
236 else
237 return 0;
25283b37 238}
239
00514d01 240Int_t AliAnalysisTaskSAJF::GetNumberOfTracks() const
25283b37 241{
e82e282c 242 if (fTracks)
243 return fTracks->GetEntriesFast();
244 else
245 return 0;
25283b37 246}
247
00514d01 248AliVCluster* AliAnalysisTaskSAJF::GetCaloCluster(const Int_t i) const
e82e282c 249{
250 if (fCaloClusters)
251 return dynamic_cast<AliVCluster*>(fCaloClusters->At(i));
252 else
253 return 0;
25283b37 254}
255
00514d01 256Int_t AliAnalysisTaskSAJF::GetNumberOfCaloClusters() const
e82e282c 257{
258 if (fCaloClusters)
259 return fCaloClusters->GetEntriesFast();
260 else
261 return 0;
25283b37 262}
263
00514d01 264AliEmcalJet* AliAnalysisTaskSAJF::GetJet(const Int_t i) const
25283b37 265{
e82e282c 266 if (fJets)
267 return dynamic_cast<AliEmcalJet*>(fJets->At(i));
268 else
269 return 0;
25283b37 270}
271
00514d01 272Int_t AliAnalysisTaskSAJF::GetNumberOfJets() const
25283b37 273{
e82e282c 274 if (fJets)
275 return fJets->GetEntriesFast();
276 else
277 return 0;
278}
279
00514d01 280AliVCluster* AliAnalysisTaskSAJF::GetTrgCluster(const Int_t i) const
e82e282c 281{
282 if (fTrgClusters)
283 return dynamic_cast<AliVCluster*>(fTrgClusters->At(i));
284 else
285 return 0;
286}
287
00514d01 288Int_t AliAnalysisTaskSAJF::GetNumberOfTrgClusters() const
e82e282c 289{
290 if (fTrgClusters)
291 return fTrgClusters->GetEntriesFast();
292 else
293 return 0;
25283b37 294}
295
00514d01 296void AliAnalysisTaskSAJF::FillHistograms()
25283b37 297{
91f4b7c5 298 Float_t cent = 100;
299
300 if (fCent)
301 cent = fCent->GetCentralityPercentile("V0M");
302 else
303 AliWarning("Centrality not available!");
25283b37 304
f0a0fd33 305 fHistCentrality->Fill(cent);
e82e282c 306
f0a0fd33 307 Int_t centbin=-1;
308 if(cent>=0 && cent<10) centbin=0;
309 else if(cent>=10 && cent<30) centbin=1;
310 else if(cent>=30 && cent<50) centbin=2;
311 else if(cent>=50 && cent<=100) centbin=3;
25283b37 312
313 // Jet loop
314 Int_t njets = GetNumberOfJets();
315 //cout << njets << " jets" << endl;
f0a0fd33 316 Float_t maxJetEnergy = 0;
317 Int_t maxJetIndex = -1;
25283b37 318 for (Int_t ij = 0; ij < njets; ij++) {
f0a0fd33 319
25283b37 320 AliEmcalJet* jet = GetJet(ij);
f0a0fd33 321
25283b37 322 if (!jet) {
323 printf("ERROR: Could not receive jet %d\n", ij);
324 continue;
325 }
326
f0a0fd33 327 if (jet->E() <= 0)
328 continue;
329
91f4b7c5 330 if (!AcceptJet(jet))
331 continue;
332
333 fHistJetPhiEta->Fill(jet->Eta(), jet->Phi());
334
f0a0fd33 335 fHistJetsE[centbin]->Fill(jet->E());
336 fHistJetsNEF[centbin]->Fill(jet->NEF());
337 fHistJetsNE[centbin]->Fill(jet->E() * jet->NEF());
338
339 //cout << "****** jet id = " << ij << " ******" << endl;
340
35789a2d 341 for (Int_t it = 0; it < jet->GetNumberOfTracks(); it++) {
342 Int_t trackid = jet->TrackAt(it);
343 AliVTrack *track = GetTrack(trackid);
f0a0fd33 344 //cout << "track id = " << trackid << endl;
35789a2d 345 if (track)
f0a0fd33 346 fHistJetsZ[centbin]->Fill(track->Pt() / jet->E());
35789a2d 347 }
348 for (Int_t ic = 0; ic < jet->GetNumberOfClusters(); ic++) {
349 Int_t clusterid = jet->ClusterAt(ic);
f0a0fd33 350 //cout << "cluster id = " << clusterid << endl;
35789a2d 351 AliVCluster *cluster = GetCaloCluster(clusterid);
352 if (cluster)
f0a0fd33 353 fHistJetsZ[centbin]->Fill(cluster->E() / jet->E());
354 }
355
356 if (maxJetEnergy < jet->E()) {
357 maxJetEnergy = jet->E();
358 maxJetIndex = ij;
35789a2d 359 }
25283b37 360 } //jet loop
e82e282c 361
f0a0fd33 362
363 if (!(maxJetEnergy > 0) || maxJetIndex < 0)
364 return;
365
366 fHistLeadingJetE[centbin]->Fill(maxJetEnergy);
367
368 AliEmcalJet* jet = GetJet(maxJetIndex);
369 if (!jet)
370 return;
371
372 jet->SortConstituents();
373
374 // Cluster loop
375 Int_t clusJetId = 0;
376 Int_t nclusters = GetNumberOfCaloClusters();
377 for (Int_t iClusters = 0; iClusters < nclusters; iClusters++) {
378 AliVCluster* cluster = GetCaloCluster(iClusters);
e82e282c 379 if (!cluster) {
380 printf("ERROR: Could not receive cluster %d\n", iClusters);
381 continue;
382 }
383
384 if (!(cluster->IsEMCAL())) continue;
f0a0fd33 385
386 if (jet->GetNumberOfClusters() > 0) {
387 if (jet->ClusterAt(clusJetId) < iClusters) {
388 if (clusJetId < jet->GetNumberOfClusters() - 1)
389 clusJetId++;
390 }
391
392 if (jet->ClusterAt(clusJetId) == iClusters) {
393 fHistClusELJ[centbin]->Fill(cluster->E());
394 }
395 else {
396 fHistClusEBkg[centbin]->Fill(cluster->E());
397 }
398 }
399 else {
400 fHistClusEBkg[centbin]->Fill(cluster->E());
401 }
e82e282c 402 } //cluster loop
e82e282c 403
f0a0fd33 404
405 // Track loop
406 Int_t trackJetId = 0;
407 Int_t ntracks = GetNumberOfTracks();
408 for(Int_t iTracks = 0; iTracks < ntracks; iTracks++) {
409 AliVTrack* track = GetTrack(iTracks);
410 if(!track) {
411 AliError(Form("ERROR: Could not retrieve track %d",iTracks));
412 continue;
25283b37 413 }
f0a0fd33 414
415 if (!AcceptTrack(track)) continue;
416
417 if (jet->GetNumberOfTracks() > 0) {
418 if (jet->TrackAt(trackJetId) < iTracks) {
419 if (trackJetId < jet->GetNumberOfTracks() - 1)
420 trackJetId++;
421 }
25283b37 422
f0a0fd33 423 if (jet->TrackAt(trackJetId) == iTracks) {
424 fHistTracksPtLJ[centbin]->Fill(track->Pt());
425 }
426 else {
427 fHistTracksPtBkg[centbin]->Fill(track->Pt());
428 }
429 }
430 else {
431 fHistTracksPtBkg[centbin]->Fill(track->Pt());
25283b37 432 }
433 }
f0a0fd33 434}
435
91f4b7c5 436//________________________________________________________________________
437Bool_t AliAnalysisTaskSAJF::AcceptJet(AliEmcalJet* jet)
438{
439 if (fAnaType == kFullAcceptance) {
440 return kTRUE;
441 }
442 else if (fAnaType == kEMCAL) {
443 return (Bool_t)(TMath::Abs(jet->Eta()) < 0.7 && jet->Phi() * TMath::RadToDeg() > 80 && jet->Phi() * TMath::RadToDeg() < 180);
444 }
445 else if (fAnaType == kEMCALFiducial) {
446 return (Bool_t)(TMath::Abs(jet->Eta()) < 0.7 && jet->Phi() * TMath::RadToDeg() > 80 && jet->Phi() * TMath::RadToDeg() < 180);
447 }
448 else {
449 AliWarning("Analysis type not recognized! Assuming kFullAcceptance...");
450 return kTRUE;
451 }
452}
f0a0fd33 453
454//________________________________________________________________________
00514d01 455Bool_t AliAnalysisTaskSAJF::AcceptTrack(AliVTrack* /*track*/)
f0a0fd33 456{
457 return kTRUE;
25283b37 458}
459
460//________________________________________________________________________
00514d01 461void AliAnalysisTaskSAJF::UserExec(Option_t *)
25283b37 462{
463 // Main loop, called for each event.
464 // Add jets to event if not yet there
465
466 RetrieveEventObjects();
467
468 FillHistograms();
469
470 // information for this iteration of the UserExec in the container
471 PostData(1, fOutput);
472}
473
474//________________________________________________________________________
00514d01 475void AliAnalysisTaskSAJF::Terminate(Option_t *)
25283b37 476{
477 // Called once at the end of the analysis.
478}