]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/EMCAL/AliAnalysisTaskEmcal.cxx
make ptmin setteable
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliAnalysisTaskEmcal.cxx
CommitLineData
cdd4e0e2 1// $Id$
2da09763 2//
3// Emcal base analysis task.
4//
9239b066 5// Author: S.Aiola, M. Verweij
2da09763 6
7#include "AliAnalysisTaskEmcal.h"
8
2da09763 9#include <TClonesArray.h>
10#include <TList.h>
09ca054b 11#include <TObject.h>
159802e2 12#include <TH1F.h>
ed0243d8 13#include <TProfile.h>
14#include <TSystem.h>
15#include <TFile.h>
16#include <TChain.h>
17#include <TKey.h>
2da09763 18
d29ed625 19#include "AliAODEvent.h"
2da09763 20#include "AliAnalysisManager.h"
21#include "AliCentrality.h"
09ca054b 22#include "AliEMCALGeometry.h"
23#include "AliESDEvent.h"
09ca054b 24#include "AliEmcalParticle.h"
d29ed625 25#include "AliEventplane.h"
26#include "AliInputEventHandler.h"
2da09763 27#include "AliLog.h"
09ca054b 28#include "AliMCParticle.h"
29#include "AliVCluster.h"
30#include "AliVEventHandler.h"
31#include "AliVParticle.h"
00c77045 32#include "AliVCaloTrigger.h"
ed0243d8 33#include "AliGenPythiaEventHeader.h"
34#include "AliAODMCHeader.h"
35#include "AliMCEvent.h"
9239b066 36#include "AliAnalysisUtils.h"
37a63fdf 37#include "AliEmcalTriggerPatchInfo.h"
9239b066 38
39#include "AliParticleContainer.h"
40#include "AliClusterContainer.h"
2da09763 41
42ClassImp(AliAnalysisTaskEmcal)
43
44//________________________________________________________________________
45AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
46 AliAnalysisTaskSE("AliAnalysisTaskEmcal"),
159802e2 47 fForceBeamType(kNA),
48 fGeneralHistograms(kFALSE),
2da09763 49 fInitialized(kFALSE),
50 fCreateHisto(kTRUE),
f660c2d6 51 fCaloCellsName(),
00c77045 52 fCaloTriggersName(),
37a63fdf 53 fCaloTriggerPatchInfoName(),
2ac8ca4f 54 fMinCent(-999),
55 fMaxCent(-999),
56 fMinVz(-999),
57 fMaxVz(-999),
9239b066 58 fTrackPtCut(0),
59 fMinNTrack(0),
60 fUseAliAnaUtils(kFALSE),
61 fAliAnalysisUtils(0x0),
2ac8ca4f 62 fOffTrigger(AliVEvent::kAny),
b4339010 63 fTrigClass(),
8e49a788 64 fTriggerTypeSel(kND),
2da09763 65 fNbins(500),
66 fMinBinPt(0),
67 fMaxBinPt(250),
6c41fc8c 68 fMinPtTrackInEmcal(0),
6f6dc2ba 69 fEventPlaneVsEmcal(-1),
254370e1 70 fMinEventPlane(-1e6),
71 fMaxEventPlane(1e6),
a52de945 72 fCentEst("V0M"),
8c0d179d 73 fIsEmbedded(kFALSE),
ed0243d8 74 fIsPythia(kFALSE),
75 fSelectPtHardBin(-999),
76 fMinMCLabel(0),
77 fMCLabelShift(0),
2130abba 78 fNcentBins(4),
78a69392 79 fNeedEmcalGeom(kTRUE),
159802e2 80 fGeom(0),
2da09763 81 fTracks(0),
82 fCaloClusters(0),
f660c2d6 83 fCaloCells(0),
00c77045 84 fCaloTriggers(0),
37a63fdf 85 fTriggerPatchInfo(0),
2da09763 86 fCent(0),
87 fCentBin(-1),
3c124212 88 fEPV0(-1.0),
89 fEPV0A(-1.0),
90 fEPV0C(-1.0),
b4339010 91 fNVertCont(0),
1f6fff78 92 fBeamType(kNA),
ed0243d8 93 fPythiaHeader(0),
94 fPtHard(0),
95 fPtHardBin(0),
96 fNTrials(0),
8c34a1cc 97 fXsection(0),
9239b066 98 fParticleCollArray(),
99 fClusterCollArray(),
37a63fdf 100 fMainTriggerPatch(0x0),
8e49a788 101 fTriggerType(kND),
a4e91fed 102 fOutput(0),
ed0243d8 103 fHistTrialsAfterSel(0),
104 fHistEventsAfterSel(0),
6da81bde 105 fHistXsectionAfterSel(0),
ed0243d8 106 fHistTrials(0),
ed0243d8 107 fHistEvents(0),
6da81bde 108 fHistXsection(0),
ed0243d8 109 fHistPtHard(0),
a4e91fed 110 fHistCentrality(0),
6f6dc2ba 111 fHistZVertex(0),
8e49a788 112 fHistEventPlane(0),
113 fHistEventRejection(0)
2da09763 114{
115 // Default constructor.
116
117 fVertex[0] = 0;
118 fVertex[1] = 0;
119 fVertex[2] = 0;
9239b066 120
121 fParticleCollArray.SetOwner(kTRUE);
122 fClusterCollArray.SetOwner(kTRUE);
2da09763 123}
124
125//________________________________________________________________________
126AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
127 AliAnalysisTaskSE(name),
159802e2 128 fForceBeamType(kNA),
129 fGeneralHistograms(kFALSE),
2da09763 130 fInitialized(kFALSE),
131 fCreateHisto(histo),
f660c2d6 132 fCaloCellsName(),
00c77045 133 fCaloTriggersName(),
37a63fdf 134 fCaloTriggerPatchInfoName(),
2ac8ca4f 135 fMinCent(-999),
136 fMaxCent(-999),
137 fMinVz(-999),
138 fMaxVz(-999),
9239b066 139 fTrackPtCut(0),
140 fMinNTrack(0),
141 fUseAliAnaUtils(kFALSE),
142 fAliAnalysisUtils(0x0),
2ac8ca4f 143 fOffTrigger(AliVEvent::kAny),
b4339010 144 fTrigClass(),
8e49a788 145 fTriggerTypeSel(kND),
2da09763 146 fNbins(500),
147 fMinBinPt(0),
148 fMaxBinPt(250),
6c41fc8c 149 fMinPtTrackInEmcal(0),
6f6dc2ba 150 fEventPlaneVsEmcal(-1),
254370e1 151 fMinEventPlane(-1e6),
152 fMaxEventPlane(1e6),
a52de945 153 fCentEst("V0M"),
8c0d179d 154 fIsEmbedded(kFALSE),
ed0243d8 155 fIsPythia(kFALSE),
156 fSelectPtHardBin(-999),
157 fMinMCLabel(0),
158 fMCLabelShift(0),
2130abba 159 fNcentBins(4),
78a69392 160 fNeedEmcalGeom(kTRUE),
159802e2 161 fGeom(0),
2da09763 162 fTracks(0),
163 fCaloClusters(0),
f660c2d6 164 fCaloCells(0),
00c77045 165 fCaloTriggers(0),
37a63fdf 166 fTriggerPatchInfo(0),
2da09763 167 fCent(0),
168 fCentBin(-1),
3c124212 169 fEPV0(-1.0),
170 fEPV0A(-1.0),
171 fEPV0C(-1.0),
b4339010 172 fNVertCont(0),
1f6fff78 173 fBeamType(kNA),
ed0243d8 174 fPythiaHeader(0),
175 fPtHard(0),
176 fPtHardBin(0),
177 fNTrials(0),
8c34a1cc 178 fXsection(0),
9239b066 179 fParticleCollArray(),
180 fClusterCollArray(),
37a63fdf 181 fMainTriggerPatch(0x0),
8e49a788 182 fTriggerType(kND),
a4e91fed 183 fOutput(0),
ed0243d8 184 fHistTrialsAfterSel(0),
185 fHistEventsAfterSel(0),
6da81bde 186 fHistXsectionAfterSel(0),
ed0243d8 187 fHistTrials(0),
ed0243d8 188 fHistEvents(0),
6da81bde 189 fHistXsection(0),
ed0243d8 190 fHistPtHard(0),
a4e91fed 191 fHistCentrality(0),
6f6dc2ba 192 fHistZVertex(0),
8e49a788 193 fHistEventPlane(0),
194 fHistEventRejection(0)
2da09763 195{
196 // Standard constructor.
197
198 fVertex[0] = 0;
199 fVertex[1] = 0;
200 fVertex[2] = 0;
201
9239b066 202 fParticleCollArray.SetOwner(kTRUE);
203 fClusterCollArray.SetOwner(kTRUE);
204
2da09763 205 if (fCreateHisto) {
2da09763 206 DefineOutput(1, TList::Class());
207 }
208}
209
210//________________________________________________________________________
211AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
212{
213 // Destructor
214}
215
9239b066 216//________________________________________________________________________
217void AliAnalysisTaskEmcal::SetClusPtCut(Double_t cut, Int_t c)
218{
219 AliClusterContainer *cont = GetClusterContainer(c);
220 if (cont) cont->SetClusPtCut(cut);
221 else AliError(Form("%s in SetClusPtCut(...): container %d not found",GetName(),c));
222}
223
224//________________________________________________________________________
225void AliAnalysisTaskEmcal::SetClusTimeCut(Double_t min, Double_t max, Int_t c)
226{
227 AliClusterContainer *cont = GetClusterContainer(c);
228 if (cont) cont->SetClusTimeCut(min,max);
229 else AliError(Form("%s in SetClusTimeCut(...): container %d not found",GetName(),c));
230}
231
232//________________________________________________________________________
233void AliAnalysisTaskEmcal::SetTrackPtCut(Double_t cut, Int_t c)
234{
235 AliParticleContainer *cont = GetParticleContainer(c);
236 if (cont) cont->SetParticlePtCut(cut);
237 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
238
239 fTrackPtCut = cut;
240}
241
242//________________________________________________________________________
243void AliAnalysisTaskEmcal::SetTrackEtaLimits(Double_t min, Double_t max, Int_t c)
244{
245 AliParticleContainer *cont = GetParticleContainer(c);
246 if (cont) cont->SetParticleEtaLimits(min,max);
247 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
248}
249
250//________________________________________________________________________
251void AliAnalysisTaskEmcal::SetTrackPhiLimits(Double_t min, Double_t max, Int_t c)
252{
253 AliParticleContainer *cont = GetParticleContainer(c);
254 if (cont) cont->SetParticlePhiLimits(min,max);
255 else AliError(Form("%s in SetTrackPhiLimits(...): container %d not found",GetName(),c));
256}
257
159802e2 258//________________________________________________________________________
259void AliAnalysisTaskEmcal::UserCreateOutputObjects()
260{
261 // Create user output.
262 if (!fCreateHisto)
263 return;
264
265 OpenFile(1);
266 fOutput = new TList();
267 fOutput->SetOwner();
268
2130abba 269 if (fForceBeamType == kpp)
270 fNcentBins = 1;
271
159802e2 272 if (!fGeneralHistograms)
273 return;
274
ed0243d8 275 if (fIsPythia) {
276 fHistTrialsAfterSel = new TH1F("fHistTrialsAfterSel", "fHistTrialsAfterSel", 11, 0, 11);
277 fHistTrialsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
278 fHistTrialsAfterSel->GetYaxis()->SetTitle("trials");
279 fOutput->Add(fHistTrialsAfterSel);
280
281 fHistEventsAfterSel = new TH1F("fHistEventsAfterSel", "fHistEventsAfterSel", 11, 0, 11);
282 fHistEventsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
283 fHistEventsAfterSel->GetYaxis()->SetTitle("total events");
284 fOutput->Add(fHistEventsAfterSel);
6da81bde 285
286 fHistXsectionAfterSel = new TProfile("fHistXsectionAfterSel", "fHistXsectionAfterSel", 11, 0, 11);
287 fHistXsectionAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
288 fHistXsectionAfterSel->GetYaxis()->SetTitle("xsection");
289 fOutput->Add(fHistXsectionAfterSel);
ed0243d8 290
291 fHistTrials = new TH1F("fHistTrials", "fHistTrials", 11, 0, 11);
292 fHistTrials->GetXaxis()->SetTitle("p_{T} hard bin");
293 fHistTrials->GetYaxis()->SetTitle("trials");
294 fOutput->Add(fHistTrials);
295
ed0243d8 296 fHistEvents = new TH1F("fHistEvents", "fHistEvents", 11, 0, 11);
297 fHistEvents->GetXaxis()->SetTitle("p_{T} hard bin");
298 fHistEvents->GetYaxis()->SetTitle("total events");
299 fOutput->Add(fHistEvents);
300
6da81bde 301 fHistXsection = new TProfile("fHistXsection", "fHistXsection", 11, 0, 11);
302 fHistXsection->GetXaxis()->SetTitle("p_{T} hard bin");
303 fHistXsection->GetYaxis()->SetTitle("xsection");
304 fOutput->Add(fHistXsection);
305
ed0243d8 306 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
307 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
308
309 for (Int_t i = 1; i < 12; i++) {
310 fHistTrialsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
311 fHistEventsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
312
313 fHistTrials->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
314 fHistXsection->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
315 fHistEvents->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
316 }
317
318 fHistPtHard = new TH1F("fHistPtHard", "fHistPtHard", fNbins*2, fMinBinPt, fMaxBinPt*4);
319 fHistPtHard->GetXaxis()->SetTitle("p_{T,hard} (GeV/c)");
320 fHistPtHard->GetYaxis()->SetTitle("counts");
321 fOutput->Add(fHistPtHard);
322 }
323
159802e2 324 fHistCentrality = new TH1F("fHistCentrality","Event centrality distribution", 200, 0, 100);
325 fHistCentrality->GetXaxis()->SetTitle("Centrality (%)");
326 fHistCentrality->GetYaxis()->SetTitle("counts");
327 fOutput->Add(fHistCentrality);
328
329 fHistZVertex = new TH1F("fHistZVertex","Z vertex position", 60, -30, 30);
330 fHistZVertex->GetXaxis()->SetTitle("z");
331 fHistZVertex->GetYaxis()->SetTitle("counts");
332 fOutput->Add(fHistZVertex);
333
6f6dc2ba 334 fHistEventPlane = new TH1F("fHistEventPlane","Event plane", 120, -TMath::Pi(), TMath::Pi());
335 fHistEventPlane->GetXaxis()->SetTitle("event plane");
336 fHistEventPlane->GetYaxis()->SetTitle("counts");
337 fOutput->Add(fHistEventPlane);
338
8e49a788 339 fHistEventRejection = new TH1I("fHistEventRejection","Reasons to reject event",20,0,20);
340 fHistEventRejection->Fill("PhysSel",0);
341 fHistEventRejection->Fill("trigger",0);
342 fHistEventRejection->Fill("trigTypeSel",0);
343 fHistEventRejection->Fill("Cent",0);
344 fHistEventRejection->Fill("vertex contr.",0);
345 fHistEventRejection->Fill("Vz",0);
346 fHistEventRejection->Fill("trackInEmcal",0);
347 fHistEventRejection->Fill("minNTrack",0);
348 fHistEventRejection->Fill("VtxSel2013pA",0);
349 fHistEventRejection->Fill("PileUp",0);
350 fHistEventRejection->Fill("EvtPlane",0);
351 fHistEventRejection->Fill("SelPtHardBin",0);
352 fHistEventRejection->GetYaxis()->SetTitle("counts");
353 fOutput->Add(fHistEventRejection);
354
159802e2 355 PostData(1, fOutput);
356}
357
358//________________________________________________________________________
359Bool_t AliAnalysisTaskEmcal::FillGeneralHistograms()
360{
ed0243d8 361 if (fIsPythia) {
6da81bde 362 fHistEventsAfterSel->Fill(fPtHardBin, 1);
363 fHistTrialsAfterSel->Fill(fPtHardBin, fNTrials);
364 fHistXsectionAfterSel->Fill(fPtHardBin, fXsection);
ed0243d8 365 fHistPtHard->Fill(fPtHard);
366 }
367
159802e2 368 fHistCentrality->Fill(fCent);
369 fHistZVertex->Fill(fVertex[2]);
6f6dc2ba 370 fHistEventPlane->Fill(fEPV0);
159802e2 371
372 return kTRUE;
373}
374
2da09763 375//________________________________________________________________________
629c7ac0 376void AliAnalysisTaskEmcal::UserExec(Option_t *)
377{
378 // Main loop, called for each event.
379
6c3aa659 380 fMainTriggerPatch = NULL;
381
e44e8726 382 if (!fInitialized)
b3376347 383 ExecOnce();
629c7ac0 384
e44e8726 385 if (!fInitialized)
386 return;
387
629c7ac0 388 if (!RetrieveEventObjects())
389 return;
390
2ac8ca4f 391 if (!IsEventSelected())
392 return;
393
159802e2 394 if (fGeneralHistograms && fCreateHisto) {
395 if (!FillGeneralHistograms())
396 return;
397 }
398
629c7ac0 399 if (!Run())
400 return;
401
159802e2 402 if (fCreateHisto) {
403 if (!FillHistograms())
404 return;
405 }
629c7ac0 406
2ac8ca4f 407 if (fCreateHisto && fOutput) {
629c7ac0 408 // information for this iteration of the UserExec in the container
409 PostData(1, fOutput);
410 }
411}
412
413//________________________________________________________________________
a56383df 414Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Int_t c) const
2da09763 415{
629c7ac0 416 // Return true if cluster is accepted.
417
418 if (!clus)
419 return kFALSE;
420
9239b066 421 AliClusterContainer *cont = GetClusterContainer(c);
157b926a 422 if (!cont) {
9239b066 423 AliError(Form("%s:Container %d not found",GetName(),c));
424 return 0;
507f74bc 425 }
629c7ac0 426
9239b066 427 return cont->AcceptCluster(clus);
629c7ac0 428}
429
430//________________________________________________________________________
9239b066 431Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVParticle *track, Int_t c) const
629c7ac0 432{
159802e2 433 // Return true if track is accepted.
629c7ac0 434
159802e2 435 if (!track)
629c7ac0 436 return kFALSE;
437
9239b066 438 AliParticleContainer *cont = GetParticleContainer(c);
157b926a 439 if (!cont) {
9239b066 440 AliError(Form("%s:Container %d not found",GetName(),c));
441 return 0;
159802e2 442 }
443
9239b066 444 return cont->AcceptParticle(track);
2da09763 445}
446
ed0243d8 447//________________________________________________________________________
448Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &fXsec, Float_t &fTrials, Int_t &pthard)
449{
450 //
451 // Get the cross section and the trails either from pyxsec.root or from pysec_hists.root
452 // Get the pt hard bin from the file path
453 // This is to called in Notify and should provide the path to the AOD/ESD file
454 // (Partially copied from AliAnalysisHelperJetTasks)
455
456 TString file(currFile);
457 fXsec = 0;
458 fTrials = 1;
459
157b926a 460 if (file.Contains(".zip#")) {
ed0243d8 461 Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
462 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
463 Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
464 file.Replace(pos+1,pos2-pos1,"");
dbd1583b 465 } else {
ed0243d8 466 // not an archive take the basename....
467 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
468 }
9239b066 469 AliDebug(1,Form("File name: %s",file.Data()));
ed0243d8 470
471 // Get the pt hard bin
472 TString strPthard(file);
473
474 strPthard.Remove(strPthard.Last('/'));
475 strPthard.Remove(strPthard.Last('/'));
476 if (strPthard.Contains("AOD")) strPthard.Remove(strPthard.Last('/'));
477 strPthard.Remove(0,strPthard.Last('/')+1);
478 if (strPthard.IsDec())
479 pthard = strPthard.Atoi();
480 else
481 AliWarning(Form("Could not extract file number from path %s", strPthard.Data()));
482
9239b066 483 // problem that we cannot really test the existance of a file in a archive so we have to live with open error message from root
484 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root"));
485
157b926a 486 if (!fxsec) {
ed0243d8 487 // next trial fetch the histgram file
488 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
157b926a 489 if (!fxsec) {
ed0243d8 490 // not a severe condition but inciate that we have no information
491 return kFALSE;
dbd1583b 492 } else {
ed0243d8 493 // find the tlist we want to be independtent of the name so use the Tkey
494 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
157b926a 495 if (!key) {
ed0243d8 496 fxsec->Close();
497 return kFALSE;
498 }
499 TList *list = dynamic_cast<TList*>(key->ReadObj());
157b926a 500 if (!list) {
ed0243d8 501 fxsec->Close();
502 return kFALSE;
503 }
504 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
505 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
506 fxsec->Close();
507 }
dbd1583b 508 } else { // no tree pyxsec.root
ed0243d8 509 TTree *xtree = (TTree*)fxsec->Get("Xsection");
157b926a 510 if (!xtree) {
ed0243d8 511 fxsec->Close();
512 return kFALSE;
513 }
514 UInt_t ntrials = 0;
515 Double_t xsection = 0;
516 xtree->SetBranchAddress("xsection",&xsection);
517 xtree->SetBranchAddress("ntrials",&ntrials);
518 xtree->GetEntry(0);
519 fTrials = ntrials;
520 fXsec = xsection;
521 fxsec->Close();
522 }
523 return kTRUE;
524}
525
526//________________________________________________________________________
527Bool_t AliAnalysisTaskEmcal::UserNotify()
528{
b8aeed95 529 // Called when file changes.
530
ed0243d8 531 if (!fIsPythia || !fGeneralHistograms || !fCreateHisto)
532 return kTRUE;
533
534 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
535 if (!tree) {
536 AliError(Form("%s - UserNotify: No current tree!",GetName()));
537 return kFALSE;
538 }
539
6da81bde 540 Float_t xsection = 0;
541 Float_t trials = 0;
542 Int_t pthardbin = 0;
ed0243d8 543
544 TFile *curfile = tree->GetCurrentFile();
545 if (!curfile) {
546 AliError(Form("%s - UserNotify: No current file!",GetName()));
547 return kFALSE;
548 }
549
550 TChain *chain = dynamic_cast<TChain*>(tree);
6da81bde 551 if (chain) tree = chain->GetTree();
ed0243d8 552
553 Int_t nevents = tree->GetEntriesFast();
554
6da81bde 555 PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthardbin);
ed0243d8 556
413c4f06 557 // TODO: Workaround
6da81bde 558 if ((pthardbin < 0) || (pthardbin > 10)) pthardbin = 0;
559
560 fHistTrials->Fill(pthardbin, trials);
561 fHistXsection->Fill(pthardbin, xsection);
562 fHistEvents->Fill(pthardbin, nevents);
ed0243d8 563
564 return kTRUE;
565}
566
629c7ac0 567//________________________________________________________________________
b3376347 568void AliAnalysisTaskEmcal::ExecOnce()
8a28ded1 569{
570 // Init the analysis.
2ac8ca4f 571
b3376347 572 if (!InputEvent()) {
573 AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
574 return;
575 }
576
78a69392 577 if (fNeedEmcalGeom) {
578 fGeom = AliEMCALGeometry::GetInstance();
579 if (!fGeom) {
580 AliError(Form("%s: Can not create geometry", GetName()));
581 return;
582 }
bb98e333 583 }
159802e2 584
78a69392 585
6f6dc2ba 586 if (fEventPlaneVsEmcal >= 0) {
78a69392 587 if (fGeom) {
588 Double_t ep = (fGeom->GetArm1PhiMax() + fGeom->GetArm1PhiMin()) / 2 * TMath::DegToRad() + fEventPlaneVsEmcal - TMath::Pi();
589 fMinEventPlane = ep - TMath::Pi() / 4;
590 fMaxEventPlane = ep + TMath::Pi() / 4;
591 }
592 else {
593 AliWarning("Could not set event plane limits because EMCal geometry was not loaded!");
594 }
6f6dc2ba 595 }
596
9239b066 597 //Load all requested track branches - each container knows name already
157b926a 598 for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
9239b066 599 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
600 cont->SetArray(InputEvent());
601 }
602
603 if (fParticleCollArray.GetEntriesFast()>0) {
604 fTracks = GetParticleArray(0);
157b926a 605 if (!fTracks) {
9239b066 606 AliError(Form("%s: Could not retrieve first track branch!", GetName()));
b3376347 607 return;
b3376347 608 }
609 }
610
9239b066 611 //Load all requested cluster branches - each container knows name already
157b926a 612 for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
9239b066 613 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
614 cont->SetArray(InputEvent());
615 }
616
157b926a 617 if (fClusterCollArray.GetEntriesFast()>0) {
9239b066 618 fCaloClusters = GetClusterArray(0);
157b926a 619 if (!fCaloClusters) {
9239b066 620 AliError(Form("%s: Could not retrieve first cluster branch!", GetName()));
b3376347 621 return;
b3376347 622 }
623 }
159802e2 624
f660c2d6 625 if (!fCaloCellsName.IsNull() && !fCaloCells) {
626 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
627 if (!fCaloCells) {
507f74bc 628 AliError(Form("%s: Could not retrieve cells %s!", GetName(), fCaloCellsName.Data()));
f660c2d6 629 return;
630 }
631 }
632
00c77045 633 if (!fCaloTriggersName.IsNull() && !fCaloTriggers) {
634 fCaloTriggers = dynamic_cast<AliVCaloTrigger*>(InputEvent()->FindListObject(fCaloTriggersName));
635 if (!fCaloTriggers) {
636 AliError(Form("%s: Could not retrieve calo triggers %s!", GetName(), fCaloTriggersName.Data()));
637 return;
638 }
639 }
640
37a63fdf 641 if (!fCaloTriggerPatchInfoName.IsNull() && !fTriggerPatchInfo) {
37a63fdf 642 fTriggerPatchInfo = GetArrayFromEvent(fCaloTriggerPatchInfoName.Data(),"AliEmcalTriggerPatchInfo");
8e49a788 643 if (!fTriggerPatchInfo) {
644 AliError(Form("%s: Could not retrieve calo trigger patch info %s!", GetName(), fCaloTriggerPatchInfoName.Data()));
645 return;
646 }
37a63fdf 647
648 }
649
159802e2 650 fInitialized = kTRUE;
8a28ded1 651}
652
2ac8ca4f 653//_____________________________________________________
654AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
655{
656 // Get beam type : pp-AA-pA
657 // ESDs have it directly, AODs get it from hardcoded run number ranges
658
159802e2 659 if (fForceBeamType != kNA)
660 return fForceBeamType;
661
2ac8ca4f 662 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
663 if (esd) {
664 const AliESDRun *run = esd->GetESDRun();
665 TString beamType = run->GetBeamType();
666 if (beamType == "p-p")
667 return kpp;
668 else if (beamType == "A-A")
669 return kAA;
670 else if (beamType == "p-A")
671 return kpA;
672 else
673 return kNA;
674 } else {
675 Int_t runNumber = InputEvent()->GetRunNumber();
676 if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
dbd1583b 677 (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
2ac8ca4f 678 return kAA;
dbd1583b 679 } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
680 (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
493d6e49 681 return kpA;
2ac8ca4f 682 } else {
683 return kpp;
684 }
685 }
686}
687
8e49a788 688//_____________________________________________________
689AliAnalysisTaskEmcal::TriggerType AliAnalysisTaskEmcal::GetTriggerType()
690{
691 // Get trigger type: kND, kJ1, kJ2
692
157b926a 693 if (!fTriggerPatchInfo)
8e49a788 694 return kND;
695
696 //number of patches in event
697 Int_t nPatch = fTriggerPatchInfo->GetEntries();
698
699 //loop over patches to define trigger type of event
700 Int_t nJ1 = 0;
701 Int_t nJ2 = 0;
702 AliEmcalTriggerPatchInfo *patch;
157b926a 703 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
8e49a788 704 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
157b926a 705 if (patch->IsJetHigh()) nJ1++;
706 if (patch->IsJetLow()) nJ2++;
8e49a788 707 }
708
157b926a 709 if (nJ1>0)
8e49a788 710 return kJ1;
157b926a 711 else if (nJ2>0)
8e49a788 712 return kJ2;
713 else
714 return kND;
8e49a788 715}
716
2ac8ca4f 717//________________________________________________________________________
d29ed625 718Bool_t AliAnalysisTaskEmcal::IsEventSelected()
2ac8ca4f 719{
720 // Check if event is selected
721
722 if (fOffTrigger != AliVEvent::kAny) {
d29ed625 723 UInt_t res = 0;
724 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
725 if (eev) {
726 res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
727 } else {
728 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
729 if (aev) {
730 res = aev->GetHeader()->GetOfflineTrigger();
731 }
732 }
8e49a788 733 if ((res & fOffTrigger) == 0) {
254370e1 734 if (fGeneralHistograms)
735 fHistEventRejection->Fill("PhysSel",1);
b4339010 736 return kFALSE;
8e49a788 737 }
b4339010 738 }
739
740 if (!fTrigClass.IsNull()) {
741 TString fired;
742 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
743 if (eev) {
744 fired = eev->GetFiredTriggerClasses();
745 } else {
746 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
747 if (aev) {
748 fired = aev->GetFiredTriggerClasses();
749 }
750 }
8e49a788 751 if (!fired.Contains("-B-")) {
254370e1 752 if (fGeneralHistograms)
753 fHistEventRejection->Fill("trigger",1);
b4339010 754 return kFALSE;
8e49a788 755 }
b4339010 756 TObjArray *arr = fTrigClass.Tokenize("|");
8e49a788 757 if (!arr) {
254370e1 758 if (fGeneralHistograms)
759 fHistEventRejection->Fill("trigger",1);
b4339010 760 return kFALSE;
8e49a788 761 }
b4339010 762 Bool_t match = 0;
763 for (Int_t i=0;i<arr->GetEntriesFast();++i) {
764 TObject *obj = arr->At(i);
765 if (!obj)
766 continue;
767 if (fired.Contains(obj->GetName())) {
768 match = 1;
769 break;
770 }
771 }
772 delete arr;
8e49a788 773 if (!match) {
254370e1 774 if (fGeneralHistograms)
775 fHistEventRejection->Fill("trigger",1);
2ac8ca4f 776 return kFALSE;
8e49a788 777 }
2ac8ca4f 778 }
779
8e49a788 780 if (fTriggerTypeSel != kND) {
157b926a 781 if (fTriggerType != fTriggerTypeSel) {
254370e1 782 if (fGeneralHistograms)
783 fHistEventRejection->Fill("trigTypeSel",1);
2ac8ca4f 784 return kFALSE;
8e49a788 785 }
786 }
8e49a788 787
788 if ((fMinCent != -999) && (fMaxCent != -999)) {
789 if (fCent<fMinCent || fCent>fMaxCent) {
254370e1 790 if (fGeneralHistograms)
791 fHistEventRejection->Fill("Cent",1);
2ac8ca4f 792 return kFALSE;
8e49a788 793 }
2ac8ca4f 794 }
795
6cc60022 796 if (fUseAliAnaUtils) {
797 if (!fAliAnalysisUtils)
798 fAliAnalysisUtils = new AliAnalysisUtils();
799 fAliAnalysisUtils->SetMinVtxContr(2);
9b299cdd 800 fAliAnalysisUtils->SetMaxVtxZ(999);
6cc60022 801 if(fMinVz<-10.) fMinVz = -10.;
802 if(fMinVz>10.) fMaxVz = 10.;
803
804 if (!fAliAnalysisUtils->IsVertexSelected2013pA(InputEvent())) {
805 if (fGeneralHistograms)
806 fHistEventRejection->Fill("VtxSel2013pA",1);
807 return kFALSE;
808 }
809
810 if (fAliAnalysisUtils->IsPileUpEvent(InputEvent())) {
811 fHistEventRejection->Fill("PileUp",1);
812 return kFALSE;
813 }
814 }
815
2ac8ca4f 816 if ((fMinVz != -999) && (fMaxVz != -999)) {
8e49a788 817 if (fNVertCont == 0 ) {
254370e1 818 if (fGeneralHistograms)
819 fHistEventRejection->Fill("vertex contr.",1);
b4339010 820 return kFALSE;
8e49a788 821 }
2ac8ca4f 822 Double_t vz = fVertex[2];
8e49a788 823 if (vz<fMinVz || vz>fMaxVz) {
254370e1 824 if (fGeneralHistograms)
8e49a788 825 fHistEventRejection->Fill("Vz",1);
254370e1 826 return kFALSE;
827 }
2ac8ca4f 828 }
829
8e49a788 830 if (fMinPtTrackInEmcal > 0 && fGeom) {
6c41fc8c 831 Bool_t trackInEmcalOk = kFALSE;
9239b066 832 Int_t ntracks = GetNParticles(0);
6c41fc8c 833 for (Int_t i = 0; i < ntracks; i++) {
9239b066 834 AliVParticle *track = GetAcceptParticleFromArray(i,0);
157b926a 835 if (!track)
6c41fc8c 836 continue;
9239b066 837
838 Double_t phiMin = fGeom->GetArm1PhiMin() * TMath::DegToRad();
839 Double_t phiMax = fGeom->GetArm1PhiMax() * TMath::DegToRad();
840 Int_t runNumber = InputEvent()->GetRunNumber();
157b926a 841 if (runNumber>=177295 && runNumber<=197470) { //small SM masked in 2012 and 2013
9239b066 842 phiMin = 1.4;
843 phiMax = TMath::Pi();
844 }
845
846 if (track->Eta() < fGeom->GetArm1EtaMin() || track->Eta() > fGeom->GetArm1EtaMax() || track->Phi() < phiMin || track->Phi() > phiMax)
6c41fc8c 847 continue;
848 if (track->Pt() > fMinPtTrackInEmcal) {
849 trackInEmcalOk = kTRUE;
850 break;
851 }
852 }
8e49a788 853 if (!trackInEmcalOk) {
254370e1 854 if (fGeneralHistograms)
855 fHistEventRejection->Fill("trackInEmcal",1);
6c41fc8c 856 return kFALSE;
8e49a788 857 }
6c41fc8c 858 }
859
8e49a788 860 if (fMinNTrack > 0) {
9239b066 861 Int_t nTracksAcc = 0;
862 Int_t ntracks = GetNParticles(0);
863 for (Int_t i = 0; i < ntracks; i++) {
864 AliVParticle *track = GetAcceptParticleFromArray(i,0);
157b926a 865 if (!track)
9239b066 866 continue;
867 if (track->Pt() > fTrackPtCut) {
868 nTracksAcc++;
157b926a 869 if (nTracksAcc>=fMinNTrack)
9239b066 870 break;
871 }
872 }
8e49a788 873 if (nTracksAcc<fMinNTrack) {
254370e1 874 if (fGeneralHistograms)
875 fHistEventRejection->Fill("minNTrack",1);
9239b066 876 return kFALSE;
8e49a788 877 }
9239b066 878 }
879
6f6dc2ba 880 if (!(fEPV0 > fMinEventPlane && fEPV0 <= fMaxEventPlane) &&
881 !(fEPV0 + TMath::Pi() > fMinEventPlane && fEPV0 + TMath::Pi() <= fMaxEventPlane) &&
882 !(fEPV0 - TMath::Pi() > fMinEventPlane && fEPV0 - TMath::Pi() <= fMaxEventPlane))
8e49a788 883 {
254370e1 884 if (fGeneralHistograms)
885 fHistEventRejection->Fill("EvtPlane",1);
8e49a788 886 return kFALSE;
887 }
6f6dc2ba 888
8e49a788 889 if (fSelectPtHardBin != -999 && fSelectPtHardBin != fPtHardBin) {
254370e1 890 if (fGeneralHistograms)
891 fHistEventRejection->Fill("SelPtHardBin",1);
8e49a788 892 return kFALSE;
893 }
6f6dc2ba 894
2ac8ca4f 895 return kTRUE;
896}
897
c596bd28 898//________________________________________________________________________
899TClonesArray *AliAnalysisTaskEmcal::GetArrayFromEvent(const char *name, const char *clname)
900{
901 // Get array from event.
902
903 TClonesArray *arr = 0;
904 TString sname(name);
905 if (!sname.IsNull()) {
906 arr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(sname));
907 if (!arr) {
908 AliWarning(Form("%s: Could not retrieve array with name %s!", GetName(), name));
909 return 0;
910 }
af0280a9 911 } else {
912 return 0;
c596bd28 913 }
af0280a9 914
c596bd28 915 if (!clname)
916 return arr;
917
918 TString objname(arr->GetClass()->GetName());
919 TClass cls(objname);
920 if (!cls.InheritsFrom(clname)) {
921 AliWarning(Form("%s: Objects of type %s in %s are not inherited from %s!",
922 GetName(), cls.GetName(), name, clname));
923 return 0;
924 }
925 return arr;
926}
927
2da09763 928//________________________________________________________________________
929Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
930{
931 // Retrieve objects from event.
932
2da09763 933 fVertex[0] = 0;
934 fVertex[1] = 0;
935 fVertex[2] = 0;
b4339010 936 fNVertCont = 0;
937
938 const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
939 if (vert) {
940 vert->GetXYZ(fVertex);
941 fNVertCont = vert->GetNContributors();
942 }
2da09763 943
1f6fff78 944 fBeamType = GetBeamType();
945
a52de945 946 if (fBeamType == kAA || fBeamType == kpA ) {
2da09763 947 AliCentrality *aliCent = InputEvent()->GetCentrality();
948 if (aliCent) {
9239b066 949 fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
157b926a 950 if (fNcentBins==4) {
e304c410 951 if (fCent >= 0 && fCent < 10) fCentBin = 0;
952 else if (fCent >= 10 && fCent < 30) fCentBin = 1;
953 else if (fCent >= 30 && fCent < 50) fCentBin = 2;
954 else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
955 else {
956 AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
53e07ba4 957 fCentBin = fNcentBins-1;
e304c410 958 }
dbd1583b 959 } else {
e304c410 960 Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1781a0e2 961 if(centWidth>0.)
962 fCentBin = TMath::FloorNint(fCent/centWidth);
963 else
964 fCentBin = 0;
157b926a 965 if (fCentBin>=fNcentBins) {
53e07ba4 966 AliWarning(Form("%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),fCent,fCentBin));
967 fCentBin = fNcentBins-1;
968 }
2da09763 969 }
901cc837 970 } else {
971 AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
2da09763 972 fCentBin = 3;
973 }
3c124212 974 AliEventplane *aliEP = InputEvent()->GetEventplane();
975 if (aliEP) {
976 fEPV0 = aliEP->GetEventplane("V0" ,InputEvent());
977 fEPV0A = aliEP->GetEventplane("V0A",InputEvent());
978 fEPV0C = aliEP->GetEventplane("V0C",InputEvent());
979 } else {
980 AliWarning(Form("%s: Could not retrieve event plane information!", GetName()));
981 }
901cc837 982 } else {
2da09763 983 fCent = 99;
984 fCentBin = 0;
985 }
986
ed0243d8 987 if (fIsPythia) {
988
989 if (MCEvent()) {
990 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent()->GenEventHeader());
991 if (!fPythiaHeader) {
992 // Check if AOD
993 AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
994
995 if (aodMCH) {
157b926a 996 for (UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
ed0243d8 997 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
998 if (fPythiaHeader) break;
999 }
1000 }
1001 }
1002 }
1003
1004 if (fPythiaHeader) {
1005 fPtHard = fPythiaHeader->GetPtHard();
6a322f03 1006
ed0243d8 1007 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
1008 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
1009 for (fPtHardBin = 0; fPtHardBin < 11; fPtHardBin++) {
1010 if (fPtHard >= ptHardLo[fPtHardBin] && fPtHard < ptHardHi[fPtHardBin])
1011 break;
1012 }
6da81bde 1013
1014 fXsection = fPythiaHeader->GetXsection();
ed0243d8 1015 fNTrials = fPythiaHeader->Trials();
1016 }
1017 }
1018
8e49a788 1019 fTriggerType = GetTriggerType();
1020
2da09763 1021 return kTRUE;
1022}
9239b066 1023
1024//________________________________________________________________________
b8aeed95 1025AliParticleContainer* AliAnalysisTaskEmcal::AddParticleContainer(const char *n)
1026{
9239b066 1027 // Add particle container
1028 // will be called in AddTask macro
1029
1030 TString tmp = TString(n);
157b926a 1031 if (tmp.IsNull()) return 0;
9239b066 1032
1033 AliParticleContainer *cont = 0x0;
1034 cont = new AliParticleContainer();
1035 cont->SetArrayName(n);
1036 TString contName = cont->GetArrayName();
1037
1038 fParticleCollArray.Add(cont);
1039
1040 return cont;
1041}
1042
1043//________________________________________________________________________
b8aeed95 1044AliClusterContainer* AliAnalysisTaskEmcal::AddClusterContainer(const char *n)
1045{
9239b066 1046 // Add cluster container
1047 // will be called in AddTask macro
1048
1049 TString tmp = TString(n);
157b926a 1050 if (tmp.IsNull()) return 0;
9239b066 1051
1052 AliClusterContainer *cont = 0x0;
1053 cont = new AliClusterContainer();
1054 cont->SetArrayName(n);
1055
1056 fClusterCollArray.Add(cont);
1057
1058 return cont;
1059}
1060
1061//________________________________________________________________________
b8aeed95 1062AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(Int_t i) const
1063{
9239b066 1064 // Get i^th particle container
1065
157b926a 1066 if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
9239b066 1067 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1068 return cont;
1069}
1070
1071//________________________________________________________________________
b8aeed95 1072AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(Int_t i) const
1073{
9239b066 1074 // Get i^th cluster container
1075
157b926a 1076 if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
9239b066 1077 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1078 return cont;
1079}
1080
1081//________________________________________________________________________
b8aeed95 1082AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(const char *name) const
1083{
9239b066 1084 // Get particle container with name
1085
1086 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1087 return cont;
1088}
1089
1090//________________________________________________________________________
b8aeed95 1091AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(const char *name) const
1092{
9239b066 1093 // Get cluster container with name
1094
1095 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1096 return cont;
1097}
1098
1099//________________________________________________________________________
b8aeed95 1100TClonesArray* AliAnalysisTaskEmcal::GetParticleArray(Int_t i) const
1101{
9239b066 1102 // Get i^th TClonesArray with AliVParticle
1103
1104 AliParticleContainer *cont = GetParticleContainer(i);
157b926a 1105 if (!cont) {
9239b066 1106 AliError(Form("%s: Particle container %d not found",GetName(),i));
1107 return 0;
1108 }
1109 TString contName = cont->GetArrayName();
1110 return cont->GetArray();
1111}
1112
1113//________________________________________________________________________
b8aeed95 1114TClonesArray* AliAnalysisTaskEmcal::GetClusterArray(Int_t i) const
1115{
9239b066 1116 // Get i^th TClonesArray with AliVCluster
1117
1118 AliClusterContainer *cont = GetClusterContainer(i);
157b926a 1119 if (!cont) {
9239b066 1120 AliError(Form("%s:Cluster container %d not found",GetName(),i));
1121 return 0;
1122 }
1123 return cont->GetArray();
1124}
1125
1126//________________________________________________________________________
b8aeed95 1127AliVParticle* AliAnalysisTaskEmcal::GetAcceptParticleFromArray(Int_t p, Int_t c) const
1128{
9239b066 1129 // Get particle p if accepted from container c
1130 // If particle not accepted return 0
1131
1132 AliParticleContainer *cont = GetParticleContainer(c);
157b926a 1133 if (!cont) {
9239b066 1134 AliError(Form("%s: Particle container %d not found",GetName(),c));
1135 return 0;
1136 }
1137 AliVParticle *vp = cont->GetAcceptParticle(p);
1138
1139 return vp;
1140}
1141
1142//________________________________________________________________________
b8aeed95 1143AliVCluster* AliAnalysisTaskEmcal::GetAcceptClusterFromArray(Int_t cl, Int_t c) const
1144{
9239b066 1145 // Get particle p if accepted from container c
1146 // If particle not accepted return 0
1147
1148 AliClusterContainer *cont = GetClusterContainer(c);
157b926a 1149 if (!cont) {
9239b066 1150 AliError(Form("%s: Cluster container %d not found",GetName(),c));
1151 return 0;
1152 }
1153 AliVCluster *vc = cont->GetAcceptCluster(cl);
1154
1155 return vc;
1156}
1157
1158//________________________________________________________________________
b8aeed95 1159Int_t AliAnalysisTaskEmcal::GetNParticles(Int_t i) const
1160{
9239b066 1161 // Get number of entries in particle array i
1162
1163 AliParticleContainer *cont = GetParticleContainer(i);
157b926a 1164 if (!cont) {
9239b066 1165 AliError(Form("%s: Particle container %d not found",GetName(),i));
1166 return 0;
1167 }
1168 return cont->GetNEntries();
1169}
1170
1171//________________________________________________________________________
b8aeed95 1172Int_t AliAnalysisTaskEmcal::GetNClusters(Int_t i) const
1173{
9239b066 1174 // Get number of entries in cluster array i
1175
1176 AliClusterContainer *cont = GetClusterContainer(i);
157b926a 1177 if (!cont) {
9239b066 1178 AliError(Form("%s: Cluster container %d not found",GetName(),i));
1179 return 0;
1180 }
1181 return cont->GetNEntries();
1182}
1183
37a63fdf 1184//________________________________________________________________________
b8aeed95 1185AliEmcalTriggerPatchInfo* AliAnalysisTaskEmcal::GetMainTriggerPatch()
1186{
37a63fdf 1187 //get main trigger match; if not known yet, look for it and cache
1188
157b926a 1189 if (fMainTriggerPatch)
37a63fdf 1190 return fMainTriggerPatch;
1191
157b926a 1192 if (!fTriggerPatchInfo) {
37a63fdf 1193 AliError(Form("%s: fTriggerPatchInfo not available",GetName()));
1194 return 0;
1195 }
1196
1197 //number of patches in event
1198 Int_t nPatch = fTriggerPatchInfo->GetEntries();
1199
1200 //extract main trigger patch
1201 AliEmcalTriggerPatchInfo *patch;
157b926a 1202 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
37a63fdf 1203
1204 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
157b926a 1205 if (patch->IsMainTrigger()) {
37a63fdf 1206 fMainTriggerPatch = patch;
1207 break;
1208 }
1209 }
1210
1211 return fMainTriggerPatch;
37a63fdf 1212}
b8aeed95 1213
1214//________________________________________________________________________
1215void AliAnalysisTaskEmcal::AddObjectToEvent(TObject *obj)
1216{
1217 // Add object to event
1218
1219 if (!(InputEvent()->FindListObject(obj->GetName()))) {
1220 InputEvent()->AddObject(obj);
1221 } else {
1222 AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), obj->GetName()));
1223 }
1224}
9dc6ae4b 1225
1226//________________________________________________________________________
1227void AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max, Double_t* array) const
1228{
1229 Double_t binWidth = (max-min)/n;
1230 array[0] = min;
1231 for (Int_t i = 1; i <= n; i++) {
1232 array[i] = array[i-1]+binWidth;
1233 }
1234}
1235
1236//________________________________________________________________________
1237Double_t* AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max) const
1238{
1239 Double_t *array = new Double_t[n+1];
1240
1241 GenerateFixedBinArray(n, min, max, array);
1242
1243 return array;
1244}