2 // Emcal base analysis task.
4 // Author: S.Aiola, M. Verweij
6 #include "AliAnalysisTaskEmcal.h"
8 #include <TClonesArray.h>
18 #include "AliAODEvent.h"
19 #include "AliAnalysisManager.h"
20 #include "AliCentrality.h"
21 #include "AliEMCALGeometry.h"
22 #include "AliESDEvent.h"
23 #include "AliEmcalParticle.h"
24 #include "AliEventplane.h"
25 #include "AliInputEventHandler.h"
27 #include "AliMCParticle.h"
28 #include "AliVCluster.h"
29 #include "AliVEventHandler.h"
30 #include "AliVParticle.h"
31 #include "AliVCaloTrigger.h"
32 #include "AliGenPythiaEventHeader.h"
33 #include "AliAODMCHeader.h"
34 #include "AliMCEvent.h"
35 #include "AliAnalysisUtils.h"
36 #include "AliEmcalTriggerPatchInfo.h"
38 #include "AliParticleContainer.h"
39 #include "AliClusterContainer.h"
41 ClassImp(AliAnalysisTaskEmcal)
43 //________________________________________________________________________
44 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
45 AliAnalysisTaskSE("AliAnalysisTaskEmcal"),
47 fGeneralHistograms(kFALSE),
52 fCaloTriggerPatchInfoName(),
59 fUseAliAnaUtils(kFALSE),
60 fRejectPileup(kFALSE),
61 fTklVsClusSPDCut(kFALSE),
62 fAliAnalysisUtils(0x0),
63 fOffTrigger(AliVEvent::kAny),
69 fMinPtTrackInEmcal(0),
70 fEventPlaneVsEmcal(-1),
76 fSelectPtHardBin(-999),
80 fNeedEmcalGeom(kTRUE),
100 fParticleCollArray(),
102 fMainTriggerPatch(0x0),
106 fHistTrialsAfterSel(0),
107 fHistEventsAfterSel(0),
108 fHistXsectionAfterSel(0),
116 fHistEventRejection(0)
118 // Default constructor.
124 fParticleCollArray.SetOwner(kTRUE);
125 fClusterCollArray.SetOwner(kTRUE);
128 //________________________________________________________________________
129 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
130 AliAnalysisTaskSE(name),
132 fGeneralHistograms(kFALSE),
133 fInitialized(kFALSE),
137 fCaloTriggerPatchInfoName(),
144 fUseAliAnaUtils(kFALSE),
145 fRejectPileup(kFALSE),
146 fTklVsClusSPDCut(kFALSE),
147 fAliAnalysisUtils(0x0),
148 fOffTrigger(AliVEvent::kAny),
150 fTriggerTypeSel(kND),
154 fMinPtTrackInEmcal(0),
155 fEventPlaneVsEmcal(-1),
156 fMinEventPlane(-1e6),
161 fSelectPtHardBin(-999),
165 fNeedEmcalGeom(kTRUE),
172 fTriggerPatchInfo(0),
185 fParticleCollArray(),
187 fMainTriggerPatch(0x0),
191 fHistTrialsAfterSel(0),
192 fHistEventsAfterSel(0),
193 fHistXsectionAfterSel(0),
201 fHistEventRejection(0)
203 // Standard constructor.
209 fParticleCollArray.SetOwner(kTRUE);
210 fClusterCollArray.SetOwner(kTRUE);
213 DefineOutput(1, TList::Class());
217 //________________________________________________________________________
218 AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
223 //________________________________________________________________________
224 void AliAnalysisTaskEmcal::SetClusPtCut(Double_t cut, Int_t c)
226 AliClusterContainer *cont = GetClusterContainer(c);
227 if (cont) cont->SetClusPtCut(cut);
228 else AliError(Form("%s in SetClusPtCut(...): container %d not found",GetName(),c));
231 //________________________________________________________________________
232 void AliAnalysisTaskEmcal::SetClusTimeCut(Double_t min, Double_t max, Int_t c)
234 AliClusterContainer *cont = GetClusterContainer(c);
235 if (cont) cont->SetClusTimeCut(min,max);
236 else AliError(Form("%s in SetClusTimeCut(...): container %d not found",GetName(),c));
239 //________________________________________________________________________
240 void AliAnalysisTaskEmcal::SetTrackPtCut(Double_t cut, Int_t c)
242 AliParticleContainer *cont = GetParticleContainer(c);
243 if (cont) cont->SetParticlePtCut(cut);
244 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
249 //________________________________________________________________________
250 void AliAnalysisTaskEmcal::SetTrackEtaLimits(Double_t min, Double_t max, Int_t c)
252 AliParticleContainer *cont = GetParticleContainer(c);
253 if (cont) cont->SetParticleEtaLimits(min,max);
254 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
257 //________________________________________________________________________
258 void AliAnalysisTaskEmcal::SetTrackPhiLimits(Double_t min, Double_t max, Int_t c)
260 AliParticleContainer *cont = GetParticleContainer(c);
261 if (cont) cont->SetParticlePhiLimits(min,max);
262 else AliError(Form("%s in SetTrackPhiLimits(...): container %d not found",GetName(),c));
265 //________________________________________________________________________
266 void AliAnalysisTaskEmcal::UserCreateOutputObjects()
268 // Create user output.
270 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
272 AliVEventHandler *evhand = mgr->GetInputEventHandler();
274 if (evhand->InheritsFrom("AliESDInputHandler")) {
282 AliError("Event handler not found!");
286 AliError("Analysis manager not found!");
293 fOutput = new TList();
296 if (fForceBeamType == kpp)
299 if (!fGeneralHistograms)
303 fHistTrialsAfterSel = new TH1F("fHistTrialsAfterSel", "fHistTrialsAfterSel", 11, 0, 11);
304 fHistTrialsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
305 fHistTrialsAfterSel->GetYaxis()->SetTitle("trials");
306 fOutput->Add(fHistTrialsAfterSel);
308 fHistEventsAfterSel = new TH1F("fHistEventsAfterSel", "fHistEventsAfterSel", 11, 0, 11);
309 fHistEventsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
310 fHistEventsAfterSel->GetYaxis()->SetTitle("total events");
311 fOutput->Add(fHistEventsAfterSel);
313 fHistXsectionAfterSel = new TProfile("fHistXsectionAfterSel", "fHistXsectionAfterSel", 11, 0, 11);
314 fHistXsectionAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
315 fHistXsectionAfterSel->GetYaxis()->SetTitle("xsection");
316 fOutput->Add(fHistXsectionAfterSel);
318 fHistTrials = new TH1F("fHistTrials", "fHistTrials", 11, 0, 11);
319 fHistTrials->GetXaxis()->SetTitle("p_{T} hard bin");
320 fHistTrials->GetYaxis()->SetTitle("trials");
321 fOutput->Add(fHistTrials);
323 fHistEvents = new TH1F("fHistEvents", "fHistEvents", 11, 0, 11);
324 fHistEvents->GetXaxis()->SetTitle("p_{T} hard bin");
325 fHistEvents->GetYaxis()->SetTitle("total events");
326 fOutput->Add(fHistEvents);
328 fHistXsection = new TProfile("fHistXsection", "fHistXsection", 11, 0, 11);
329 fHistXsection->GetXaxis()->SetTitle("p_{T} hard bin");
330 fHistXsection->GetYaxis()->SetTitle("xsection");
331 fOutput->Add(fHistXsection);
333 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
334 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
336 for (Int_t i = 1; i < 12; i++) {
337 fHistTrialsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
338 fHistEventsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
340 fHistTrials->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
341 fHistXsection->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
342 fHistEvents->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
345 fHistPtHard = new TH1F("fHistPtHard", "fHistPtHard", fNbins*2, fMinBinPt, fMaxBinPt*4);
346 fHistPtHard->GetXaxis()->SetTitle("p_{T,hard} (GeV/c)");
347 fHistPtHard->GetYaxis()->SetTitle("counts");
348 fOutput->Add(fHistPtHard);
351 fHistCentrality = new TH1F("fHistCentrality","Event centrality distribution", 200, 0, 100);
352 fHistCentrality->GetXaxis()->SetTitle("Centrality (%)");
353 fHistCentrality->GetYaxis()->SetTitle("counts");
354 fOutput->Add(fHistCentrality);
356 fHistZVertex = new TH1F("fHistZVertex","Z vertex position", 60, -30, 30);
357 fHistZVertex->GetXaxis()->SetTitle("z");
358 fHistZVertex->GetYaxis()->SetTitle("counts");
359 fOutput->Add(fHistZVertex);
361 fHistEventPlane = new TH1F("fHistEventPlane","Event plane", 120, -TMath::Pi(), TMath::Pi());
362 fHistEventPlane->GetXaxis()->SetTitle("event plane");
363 fHistEventPlane->GetYaxis()->SetTitle("counts");
364 fOutput->Add(fHistEventPlane);
366 fHistEventRejection = new TH1F("fHistEventRejection","Reasons to reject event",20,0,20);
367 fHistEventRejection->GetXaxis()->SetBinLabel(1,"PhysSel");
368 fHistEventRejection->GetXaxis()->SetBinLabel(2,"trigger");
369 fHistEventRejection->GetXaxis()->SetBinLabel(3,"trigTypeSel");
370 fHistEventRejection->GetXaxis()->SetBinLabel(4,"Cent");
371 fHistEventRejection->GetXaxis()->SetBinLabel(5,"vertex contr.");
372 fHistEventRejection->GetXaxis()->SetBinLabel(6,"Vz");
373 fHistEventRejection->GetXaxis()->SetBinLabel(7,"trackInEmcal");
374 fHistEventRejection->GetXaxis()->SetBinLabel(8,"minNTrack");
375 fHistEventRejection->GetXaxis()->SetBinLabel(9,"VtxSel2013pA");
376 fHistEventRejection->GetXaxis()->SetBinLabel(10,"PileUp");
377 fHistEventRejection->GetXaxis()->SetBinLabel(11,"EvtPlane");
378 fHistEventRejection->GetXaxis()->SetBinLabel(12,"SelPtHardBin");
379 fHistEventRejection->GetXaxis()->SetBinLabel(13,"Bkg evt");
380 fHistEventRejection->GetYaxis()->SetTitle("counts");
381 fOutput->Add(fHistEventRejection);
383 fHistEventCount = new TH1F("fHistEventCount","fHistEventCount",2,0,2);
384 fHistEventCount->GetXaxis()->SetBinLabel(1,"Accepted");
385 fHistEventCount->GetXaxis()->SetBinLabel(2,"Rejected");
386 fHistEventCount->GetYaxis()->SetTitle("counts");
387 fOutput->Add(fHistEventCount);
389 PostData(1, fOutput);
392 //________________________________________________________________________
393 Bool_t AliAnalysisTaskEmcal::FillGeneralHistograms()
396 fHistEventsAfterSel->Fill(fPtHardBin, 1);
397 fHistTrialsAfterSel->Fill(fPtHardBin, fNTrials);
398 fHistXsectionAfterSel->Fill(fPtHardBin, fXsection);
399 fHistPtHard->Fill(fPtHard);
402 fHistCentrality->Fill(fCent);
403 fHistZVertex->Fill(fVertex[2]);
404 fHistEventPlane->Fill(fEPV0);
409 //________________________________________________________________________
410 void AliAnalysisTaskEmcal::UserExec(Option_t *)
412 // Main loop, called for each event.
414 fMainTriggerPatch = NULL;
422 if (!RetrieveEventObjects())
425 if (IsEventSelected()) {
426 if (fGeneralHistograms) fHistEventCount->Fill("Accepted",1);
429 if (fGeneralHistograms) fHistEventCount->Fill("Rejected",1);
433 if (fGeneralHistograms && fCreateHisto) {
434 if (!FillGeneralHistograms())
442 if (!FillHistograms())
446 if (fCreateHisto && fOutput) {
447 // information for this iteration of the UserExec in the container
448 PostData(1, fOutput);
452 //________________________________________________________________________
453 Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Int_t c) const
455 // Return true if cluster is accepted.
460 AliClusterContainer *cont = GetClusterContainer(c);
462 AliError(Form("%s:Container %d not found",GetName(),c));
466 return cont->AcceptCluster(clus);
469 //________________________________________________________________________
470 Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVParticle *track, Int_t c) const
472 // Return true if track is accepted.
477 AliParticleContainer *cont = GetParticleContainer(c);
479 AliError(Form("%s:Container %d not found",GetName(),c));
483 return cont->AcceptParticle(track);
486 //________________________________________________________________________
487 Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &fXsec, Float_t &fTrials, Int_t &pthard)
490 // Get the cross section and the trails either from pyxsec.root or from pysec_hists.root
491 // Get the pt hard bin from the file path
492 // This is to called in Notify and should provide the path to the AOD/ESD file
493 // (Partially copied from AliAnalysisHelperJetTasks)
495 TString file(currFile);
499 if (file.Contains(".zip#")) {
500 Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
501 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
502 Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
503 file.Replace(pos+1,pos2-pos1,"");
505 // not an archive take the basename....
506 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
508 AliDebug(1,Form("File name: %s",file.Data()));
510 // Get the pt hard bin
511 TString strPthard(file);
513 strPthard.Remove(strPthard.Last('/'));
514 strPthard.Remove(strPthard.Last('/'));
515 if (strPthard.Contains("AOD")) strPthard.Remove(strPthard.Last('/'));
516 strPthard.Remove(0,strPthard.Last('/')+1);
517 if (strPthard.IsDec())
518 pthard = strPthard.Atoi();
520 AliWarning(Form("Could not extract file number from path %s", strPthard.Data()));
522 // 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
523 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root"));
526 // next trial fetch the histgram file
527 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
529 // not a severe condition but inciate that we have no information
532 // find the tlist we want to be independtent of the name so use the Tkey
533 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
538 TList *list = dynamic_cast<TList*>(key->ReadObj());
543 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
544 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
547 } else { // no tree pyxsec.root
548 TTree *xtree = (TTree*)fxsec->Get("Xsection");
554 Double_t xsection = 0;
555 xtree->SetBranchAddress("xsection",&xsection);
556 xtree->SetBranchAddress("ntrials",&ntrials);
565 //________________________________________________________________________
566 Bool_t AliAnalysisTaskEmcal::UserNotify()
568 // Called when file changes.
570 if (!fIsPythia || !fGeneralHistograms || !fCreateHisto)
573 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
575 AliError(Form("%s - UserNotify: No current tree!",GetName()));
579 Float_t xsection = 0;
583 TFile *curfile = tree->GetCurrentFile();
585 AliError(Form("%s - UserNotify: No current file!",GetName()));
589 TChain *chain = dynamic_cast<TChain*>(tree);
590 if (chain) tree = chain->GetTree();
592 Int_t nevents = tree->GetEntriesFast();
594 PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthardbin);
597 if ((pthardbin < 0) || (pthardbin > 10)) pthardbin = 0;
599 fHistTrials->Fill(pthardbin, trials);
600 fHistXsection->Fill(pthardbin, xsection);
601 fHistEvents->Fill(pthardbin, nevents);
606 //________________________________________________________________________
607 void AliAnalysisTaskEmcal::ExecOnce()
609 // Init the analysis.
612 AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
616 if (fNeedEmcalGeom) {
617 fGeom = AliEMCALGeometry::GetInstance();
619 AliError(Form("%s: Can not create geometry", GetName()));
625 if (fEventPlaneVsEmcal >= 0) {
627 Double_t ep = (fGeom->GetArm1PhiMax() + fGeom->GetArm1PhiMin()) / 2 * TMath::DegToRad() + fEventPlaneVsEmcal - TMath::Pi();
628 fMinEventPlane = ep - TMath::Pi() / 4;
629 fMaxEventPlane = ep + TMath::Pi() / 4;
632 AliWarning("Could not set event plane limits because EMCal geometry was not loaded!");
636 //Load all requested track branches - each container knows name already
637 for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
638 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
639 cont->SetArray(InputEvent());
642 if (fParticleCollArray.GetEntriesFast()>0) {
643 fTracks = GetParticleArray(0);
645 AliError(Form("%s: Could not retrieve first track branch!", GetName()));
650 //Load all requested cluster branches - each container knows name already
651 for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
652 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
653 cont->SetArray(InputEvent());
656 if (fClusterCollArray.GetEntriesFast()>0) {
657 fCaloClusters = GetClusterArray(0);
658 if (!fCaloClusters) {
659 AliError(Form("%s: Could not retrieve first cluster branch!", GetName()));
664 if (!fCaloCellsName.IsNull() && !fCaloCells) {
665 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
667 AliError(Form("%s: Could not retrieve cells %s!", GetName(), fCaloCellsName.Data()));
672 if (!fCaloTriggersName.IsNull() && !fCaloTriggers) {
673 fCaloTriggers = dynamic_cast<AliVCaloTrigger*>(InputEvent()->FindListObject(fCaloTriggersName));
674 if (!fCaloTriggers) {
675 AliError(Form("%s: Could not retrieve calo triggers %s!", GetName(), fCaloTriggersName.Data()));
680 if (!fCaloTriggerPatchInfoName.IsNull() && !fTriggerPatchInfo) {
681 fTriggerPatchInfo = GetArrayFromEvent(fCaloTriggerPatchInfoName.Data(),"AliEmcalTriggerPatchInfo");
682 if (!fTriggerPatchInfo) {
683 AliError(Form("%s: Could not retrieve calo trigger patch info %s!", GetName(), fCaloTriggerPatchInfoName.Data()));
689 fInitialized = kTRUE;
692 //_____________________________________________________
693 AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
695 // Get beam type : pp-AA-pA
696 // ESDs have it directly, AODs get it from hardcoded run number ranges
698 if (fForceBeamType != kNA)
699 return fForceBeamType;
701 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
703 const AliESDRun *run = esd->GetESDRun();
704 TString beamType = run->GetBeamType();
705 if (beamType == "p-p")
707 else if (beamType == "A-A")
709 else if (beamType == "p-A")
714 Int_t runNumber = InputEvent()->GetRunNumber();
715 if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
716 (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
718 } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
719 (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
727 //________________________________________________________________________
728 ULong_t AliAnalysisTaskEmcal::GetTriggerList()
730 if (!fTriggerPatchInfo)
733 //number of patches in event
734 Int_t nPatch = fTriggerPatchInfo->GetEntries();
736 //loop over patches to define trigger type of event
741 AliEmcalTriggerPatchInfo *patch;
742 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
743 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
744 if (patch->IsGammaHigh()) nG1++;
745 if (patch->IsGammaLow()) nG2++;
746 if (patch->IsJetHigh()) nJ1++;
747 if (patch->IsJetLow()) nJ2++;
750 AliDebug(2, "Patch summary: ");
751 AliDebug(2, Form("Number of patches: %d", nPatch));
752 AliDebug(2, Form("Jet: low[%d], high[%d]" ,nJ2, nJ1));
753 AliDebug(2, Form("Gamma: low[%d], high[%d]" ,nG2, nG1));
757 SETBIT(triggers, kG1);
759 SETBIT(triggers, kG2);
761 SETBIT(triggers, kJ1);
763 SETBIT(triggers, kJ2);
767 //________________________________________________________________________
768 Bool_t AliAnalysisTaskEmcal::HasTriggerType(TriggerType t)
770 // Check if event has a given trigger type
772 return fTriggers == 0;
774 return TESTBIT(fTriggers, int(t));
777 //________________________________________________________________________
778 Bool_t AliAnalysisTaskEmcal::IsEventSelected()
780 // Check if event is selected
782 if (fOffTrigger != AliVEvent::kAny) {
784 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
786 res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
788 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
790 res = ((AliVAODHeader*)aev->GetHeader())->GetOfflineTrigger();
793 if ((res & fOffTrigger) == 0) {
794 if (fGeneralHistograms) fHistEventRejection->Fill("PhysSel",1);
799 if (!fTrigClass.IsNull()) {
801 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
803 fired = eev->GetFiredTriggerClasses();
805 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
807 fired = aev->GetFiredTriggerClasses();
810 if (!fired.Contains("-B-")) {
811 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
814 TObjArray *arr = fTrigClass.Tokenize("|");
816 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
820 for (Int_t i=0;i<arr->GetEntriesFast();++i) {
821 TObject *obj = arr->At(i);
824 if (fired.Contains(obj->GetName())) {
831 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
836 if (fTriggerTypeSel != kND) {
837 if (!HasTriggerType(fTriggerTypeSel)) {
838 if (fGeneralHistograms) fHistEventRejection->Fill("trigTypeSel",1);
843 if ((fMinCent != -999) && (fMaxCent != -999)) {
844 if (fCent<fMinCent || fCent>fMaxCent) {
845 if (fGeneralHistograms) fHistEventRejection->Fill("Cent",1);
850 if (fUseAliAnaUtils) {
851 if (!fAliAnalysisUtils)
852 fAliAnalysisUtils = new AliAnalysisUtils();
853 fAliAnalysisUtils->SetMinVtxContr(2);
854 fAliAnalysisUtils->SetMaxVtxZ(999);
855 if(fMinVz<-10.) fMinVz = -10.;
856 if(fMinVz>10.) fMaxVz = 10.;
858 if (!fAliAnalysisUtils->IsVertexSelected2013pA(InputEvent())) {
859 if (fGeneralHistograms) fHistEventRejection->Fill("VtxSel2013pA",1);
863 if (fRejectPileup && fAliAnalysisUtils->IsPileUpEvent(InputEvent())) {
864 if (fGeneralHistograms) fHistEventRejection->Fill("PileUp",1);
868 if(fTklVsClusSPDCut && fAliAnalysisUtils->IsSPDClusterVsTrackletBG(InputEvent())) {
869 if (fGeneralHistograms) fHistEventRejection->Fill("Bkg evt",1);
874 if ((fMinVz != -999) && (fMaxVz != -999)) {
875 if (fNVertCont == 0 ) {
876 if (fGeneralHistograms) fHistEventRejection->Fill("vertex contr.",1);
879 Double_t vz = fVertex[2];
880 if (vz<fMinVz || vz>fMaxVz) {
881 if (fGeneralHistograms) fHistEventRejection->Fill("Vz",1);
886 if (fMinPtTrackInEmcal > 0 && fGeom) {
887 Bool_t trackInEmcalOk = kFALSE;
888 Int_t ntracks = GetNParticles(0);
889 for (Int_t i = 0; i < ntracks; i++) {
890 AliVParticle *track = GetAcceptParticleFromArray(i,0);
894 Double_t phiMin = fGeom->GetArm1PhiMin() * TMath::DegToRad();
895 Double_t phiMax = fGeom->GetArm1PhiMax() * TMath::DegToRad();
896 Int_t runNumber = InputEvent()->GetRunNumber();
897 if (runNumber>=177295 && runNumber<=197470) { //small SM masked in 2012 and 2013
899 phiMax = TMath::Pi();
902 if (track->Eta() < fGeom->GetArm1EtaMin() || track->Eta() > fGeom->GetArm1EtaMax() || track->Phi() < phiMin || track->Phi() > phiMax)
904 if (track->Pt() > fMinPtTrackInEmcal) {
905 trackInEmcalOk = kTRUE;
909 if (!trackInEmcalOk) {
910 if (fGeneralHistograms) fHistEventRejection->Fill("trackInEmcal",1);
915 if (fMinNTrack > 0) {
916 Int_t nTracksAcc = 0;
917 Int_t ntracks = GetNParticles(0);
918 for (Int_t i = 0; i < ntracks; i++) {
919 AliVParticle *track = GetAcceptParticleFromArray(i,0);
922 if (track->Pt() > fTrackPtCut) {
924 if (nTracksAcc>=fMinNTrack)
928 if (nTracksAcc<fMinNTrack) {
929 if (fGeneralHistograms) fHistEventRejection->Fill("minNTrack",1);
934 if (!(fEPV0 > fMinEventPlane && fEPV0 <= fMaxEventPlane) &&
935 !(fEPV0 + TMath::Pi() > fMinEventPlane && fEPV0 + TMath::Pi() <= fMaxEventPlane) &&
936 !(fEPV0 - TMath::Pi() > fMinEventPlane && fEPV0 - TMath::Pi() <= fMaxEventPlane))
938 if (fGeneralHistograms) fHistEventRejection->Fill("EvtPlane",1);
942 if (fSelectPtHardBin != -999 && fSelectPtHardBin != fPtHardBin) {
943 if (fGeneralHistograms) fHistEventRejection->Fill("SelPtHardBin",1);
950 //________________________________________________________________________
951 TClonesArray *AliAnalysisTaskEmcal::GetArrayFromEvent(const char *name, const char *clname)
953 // Get array from event.
955 TClonesArray *arr = 0;
957 if (!sname.IsNull()) {
958 arr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(sname));
960 AliWarning(Form("%s: Could not retrieve array with name %s!", GetName(), name));
970 TString objname(arr->GetClass()->GetName());
972 if (!cls.InheritsFrom(clname)) {
973 AliWarning(Form("%s: Objects of type %s in %s are not inherited from %s!",
974 GetName(), cls.GetName(), name, clname));
980 //________________________________________________________________________
981 Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
983 // Retrieve objects from event.
990 const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
992 vert->GetXYZ(fVertex);
993 fNVertCont = vert->GetNContributors();
996 fBeamType = GetBeamType();
998 if (fBeamType == kAA || fBeamType == kpA ) {
999 AliCentrality *aliCent = InputEvent()->GetCentrality();
1001 fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
1002 if (fNcentBins==4) {
1003 if (fCent >= 0 && fCent < 10) fCentBin = 0;
1004 else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1005 else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1006 else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
1008 AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
1009 fCentBin = fNcentBins-1;
1012 Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1014 fCentBin = TMath::FloorNint(fCent/centWidth);
1017 if (fCentBin>=fNcentBins) {
1018 AliWarning(Form("%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),fCent,fCentBin));
1019 fCentBin = fNcentBins-1;
1023 AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
1024 fCentBin = fNcentBins-1;
1026 AliEventplane *aliEP = InputEvent()->GetEventplane();
1028 fEPV0 = aliEP->GetEventplane("V0" ,InputEvent());
1029 fEPV0A = aliEP->GetEventplane("V0A",InputEvent());
1030 fEPV0C = aliEP->GetEventplane("V0C",InputEvent());
1032 AliWarning(Form("%s: Could not retrieve event plane information!", GetName()));
1042 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent()->GenEventHeader());
1043 if (!fPythiaHeader) {
1045 AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
1048 for (UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
1049 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
1050 if (fPythiaHeader) break;
1056 if (fPythiaHeader) {
1057 fPtHard = fPythiaHeader->GetPtHard();
1059 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
1060 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
1061 for (fPtHardBin = 0; fPtHardBin < 11; fPtHardBin++) {
1062 if (fPtHard >= ptHardLo[fPtHardBin] && fPtHard < ptHardHi[fPtHardBin])
1066 fXsection = fPythiaHeader->GetXsection();
1067 fNTrials = fPythiaHeader->Trials();
1071 fTriggers = GetTriggerList();
1076 //________________________________________________________________________
1077 AliParticleContainer* AliAnalysisTaskEmcal::AddParticleContainer(const char *n)
1079 // Add particle container
1080 // will be called in AddTask macro
1082 TString tmp = TString(n);
1083 if (tmp.IsNull()) return 0;
1085 AliParticleContainer *cont = 0x0;
1086 cont = new AliParticleContainer();
1087 cont->SetArrayName(n);
1088 TString contName = cont->GetArrayName();
1090 fParticleCollArray.Add(cont);
1095 //________________________________________________________________________
1096 AliClusterContainer* AliAnalysisTaskEmcal::AddClusterContainer(const char *n)
1098 // Add cluster container
1099 // will be called in AddTask macro
1101 TString tmp = TString(n);
1102 if (tmp.IsNull()) return 0;
1104 AliClusterContainer *cont = 0x0;
1105 cont = new AliClusterContainer();
1106 cont->SetArrayName(n);
1108 fClusterCollArray.Add(cont);
1113 //________________________________________________________________________
1114 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(Int_t i) const
1116 // Get i^th particle container
1118 if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1119 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1123 //________________________________________________________________________
1124 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(Int_t i) const
1126 // Get i^th cluster container
1128 if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1129 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1133 //________________________________________________________________________
1134 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(const char *name) const
1136 // Get particle container with name
1138 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1142 //________________________________________________________________________
1143 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(const char *name) const
1145 // Get cluster container with name
1147 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1151 //________________________________________________________________________
1152 TClonesArray* AliAnalysisTaskEmcal::GetParticleArray(Int_t i) const
1154 // Get i^th TClonesArray with AliVParticle
1156 AliParticleContainer *cont = GetParticleContainer(i);
1158 AliError(Form("%s: Particle container %d not found",GetName(),i));
1161 TString contName = cont->GetArrayName();
1162 return cont->GetArray();
1165 //________________________________________________________________________
1166 TClonesArray* AliAnalysisTaskEmcal::GetClusterArray(Int_t i) const
1168 // Get i^th TClonesArray with AliVCluster
1170 AliClusterContainer *cont = GetClusterContainer(i);
1172 AliError(Form("%s:Cluster container %d not found",GetName(),i));
1175 return cont->GetArray();
1178 //________________________________________________________________________
1179 AliVParticle* AliAnalysisTaskEmcal::GetAcceptParticleFromArray(Int_t p, Int_t c) const
1181 // Get particle p if accepted from container c
1182 // If particle not accepted return 0
1184 AliParticleContainer *cont = GetParticleContainer(c);
1186 AliError(Form("%s: Particle container %d not found",GetName(),c));
1189 AliVParticle *vp = cont->GetAcceptParticle(p);
1194 //________________________________________________________________________
1195 AliVCluster* AliAnalysisTaskEmcal::GetAcceptClusterFromArray(Int_t cl, Int_t c) const
1197 // Get particle p if accepted from container c
1198 // If particle not accepted return 0
1200 AliClusterContainer *cont = GetClusterContainer(c);
1202 AliError(Form("%s: Cluster container %d not found",GetName(),c));
1205 AliVCluster *vc = cont->GetAcceptCluster(cl);
1210 //________________________________________________________________________
1211 Int_t AliAnalysisTaskEmcal::GetNParticles(Int_t i) const
1213 // Get number of entries in particle array i
1215 AliParticleContainer *cont = GetParticleContainer(i);
1217 AliError(Form("%s: Particle container %d not found",GetName(),i));
1220 return cont->GetNEntries();
1223 //________________________________________________________________________
1224 Int_t AliAnalysisTaskEmcal::GetNClusters(Int_t i) const
1226 // Get number of entries in cluster array i
1228 AliClusterContainer *cont = GetClusterContainer(i);
1230 AliError(Form("%s: Cluster container %d not found",GetName(),i));
1233 return cont->GetNEntries();
1236 //________________________________________________________________________
1237 AliEmcalTriggerPatchInfo* AliAnalysisTaskEmcal::GetMainTriggerPatch()
1239 //get main trigger match; if not known yet, look for it and cache
1241 if (fMainTriggerPatch)
1242 return fMainTriggerPatch;
1244 if (!fTriggerPatchInfo) {
1245 AliError(Form("%s: fTriggerPatchInfo not available",GetName()));
1249 //number of patches in event
1250 Int_t nPatch = fTriggerPatchInfo->GetEntries();
1252 //extract main trigger patch
1253 AliEmcalTriggerPatchInfo *patch;
1254 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
1256 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
1257 if (patch->IsMainTrigger()) {
1258 fMainTriggerPatch = patch;
1263 return fMainTriggerPatch;
1266 //________________________________________________________________________
1267 void AliAnalysisTaskEmcal::AddObjectToEvent(TObject *obj)
1269 // Add object to event
1271 if (!(InputEvent()->FindListObject(obj->GetName()))) {
1272 InputEvent()->AddObject(obj);
1274 AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), obj->GetName()));
1278 //________________________________________________________________________
1279 void AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max, Double_t* array) const
1281 Double_t binWidth = (max-min)/n;
1283 for (Int_t i = 1; i <= n; i++) {
1284 array[i] = array[i-1]+binWidth;
1288 //________________________________________________________________________
1289 Double_t* AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max) const
1291 Double_t *array = new Double_t[n+1];
1293 GenerateFixedBinArray(n, min, max, array);
1298 //________________________________________________________________________
1299 void AliAnalysisTaskEmcal::SetRejectionReasonLabels(TAxis* axis)
1301 axis->SetBinLabel(1, "NullObject");
1302 axis->SetBinLabel(2, "Pt");
1303 axis->SetBinLabel(3, "Acceptance");
1304 axis->SetBinLabel(4, "BitMap");
1305 axis->SetBinLabel(5, "Bit4");
1306 axis->SetBinLabel(6, "Bit5");
1307 axis->SetBinLabel(7, "Bit6");
1308 axis->SetBinLabel(8, "Bit7");
1309 axis->SetBinLabel(9, "MCFlag");
1310 axis->SetBinLabel(10, "MCGenerator");
1311 axis->SetBinLabel(11, "ChargeCut");
1312 axis->SetBinLabel(12, "Bit11");
1313 axis->SetBinLabel(13, "Bit12");
1314 axis->SetBinLabel(14, "IsEMCal");
1315 axis->SetBinLabel(15, "Time");
1316 axis->SetBinLabel(16, "Energy");
1317 axis->SetBinLabel(17, "Bit16");
1318 axis->SetBinLabel(18, "Bit17");
1319 axis->SetBinLabel(19, "Area");
1320 axis->SetBinLabel(20, "AreaEmc");
1321 axis->SetBinLabel(21, "ZLeadingCh");
1322 axis->SetBinLabel(22, "ZLeadingEmc");
1323 axis->SetBinLabel(23, "NEF");
1324 axis->SetBinLabel(24, "MinLeadPt");
1325 axis->SetBinLabel(25, "MaxTrackPt");
1326 axis->SetBinLabel(26, "MaxClusterPt");
1327 axis->SetBinLabel(27, "Flavour");
1328 axis->SetBinLabel(28, "TagStatus");
1329 axis->SetBinLabel(29, "Bit28");
1330 axis->SetBinLabel(30, "Bit29");
1331 axis->SetBinLabel(31, "Bit30");
1332 axis->SetBinLabel(32, "Bit31");