3 // Emcal base analysis task.
5 // Author: S.Aiola, M. Verweij
7 #include "AliAnalysisTaskEmcal.h"
9 #include <TClonesArray.h>
19 #include "AliAODEvent.h"
20 #include "AliAnalysisManager.h"
21 #include "AliCentrality.h"
22 #include "AliEMCALGeometry.h"
23 #include "AliESDEvent.h"
24 #include "AliEmcalParticle.h"
25 #include "AliEventplane.h"
26 #include "AliInputEventHandler.h"
28 #include "AliMCParticle.h"
29 #include "AliVCluster.h"
30 #include "AliVEventHandler.h"
31 #include "AliVParticle.h"
32 #include "AliVCaloTrigger.h"
33 #include "AliGenPythiaEventHeader.h"
34 #include "AliAODMCHeader.h"
35 #include "AliMCEvent.h"
36 #include "AliAnalysisUtils.h"
37 #include "AliEmcalTriggerPatchInfo.h"
39 #include "AliParticleContainer.h"
40 #include "AliClusterContainer.h"
42 ClassImp(AliAnalysisTaskEmcal)
44 //________________________________________________________________________
45 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
46 AliAnalysisTaskSE("AliAnalysisTaskEmcal"),
48 fGeneralHistograms(kFALSE),
53 fCaloTriggerPatchInfoName(),
60 fUseAliAnaUtils(kFALSE),
61 fAliAnalysisUtils(0x0),
62 fOffTrigger(AliVEvent::kAny),
68 fMinPtTrackInEmcal(0),
69 fEventPlaneVsEmcal(-1),
75 fSelectPtHardBin(-999),
79 fNeedEmcalGeom(kTRUE),
101 fMainTriggerPatch(0x0),
104 fHistTrialsAfterSel(0),
105 fHistEventsAfterSel(0),
106 fHistXsectionAfterSel(0),
114 fHistEventRejection(0)
116 // Default constructor.
122 fParticleCollArray.SetOwner(kTRUE);
123 fClusterCollArray.SetOwner(kTRUE);
126 //________________________________________________________________________
127 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
128 AliAnalysisTaskSE(name),
130 fGeneralHistograms(kFALSE),
131 fInitialized(kFALSE),
135 fCaloTriggerPatchInfoName(),
142 fUseAliAnaUtils(kFALSE),
143 fAliAnalysisUtils(0x0),
144 fOffTrigger(AliVEvent::kAny),
146 fTriggerTypeSel(kND),
150 fMinPtTrackInEmcal(0),
151 fEventPlaneVsEmcal(-1),
152 fMinEventPlane(-1e6),
157 fSelectPtHardBin(-999),
161 fNeedEmcalGeom(kTRUE),
168 fTriggerPatchInfo(0),
181 fParticleCollArray(),
183 fMainTriggerPatch(0x0),
186 fHistTrialsAfterSel(0),
187 fHistEventsAfterSel(0),
188 fHistXsectionAfterSel(0),
196 fHistEventRejection(0)
198 // Standard constructor.
204 fParticleCollArray.SetOwner(kTRUE);
205 fClusterCollArray.SetOwner(kTRUE);
208 DefineOutput(1, TList::Class());
212 //________________________________________________________________________
213 AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
218 //________________________________________________________________________
219 void AliAnalysisTaskEmcal::SetClusPtCut(Double_t cut, Int_t c)
221 AliClusterContainer *cont = GetClusterContainer(c);
222 if (cont) cont->SetClusPtCut(cut);
223 else AliError(Form("%s in SetClusPtCut(...): container %d not found",GetName(),c));
226 //________________________________________________________________________
227 void AliAnalysisTaskEmcal::SetClusTimeCut(Double_t min, Double_t max, Int_t c)
229 AliClusterContainer *cont = GetClusterContainer(c);
230 if (cont) cont->SetClusTimeCut(min,max);
231 else AliError(Form("%s in SetClusTimeCut(...): container %d not found",GetName(),c));
234 //________________________________________________________________________
235 void AliAnalysisTaskEmcal::SetTrackPtCut(Double_t cut, Int_t c)
237 AliParticleContainer *cont = GetParticleContainer(c);
238 if (cont) cont->SetParticlePtCut(cut);
239 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
244 //________________________________________________________________________
245 void AliAnalysisTaskEmcal::SetTrackEtaLimits(Double_t min, Double_t max, Int_t c)
247 AliParticleContainer *cont = GetParticleContainer(c);
248 if (cont) cont->SetParticleEtaLimits(min,max);
249 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
252 //________________________________________________________________________
253 void AliAnalysisTaskEmcal::SetTrackPhiLimits(Double_t min, Double_t max, Int_t c)
255 AliParticleContainer *cont = GetParticleContainer(c);
256 if (cont) cont->SetParticlePhiLimits(min,max);
257 else AliError(Form("%s in SetTrackPhiLimits(...): container %d not found",GetName(),c));
260 //________________________________________________________________________
261 void AliAnalysisTaskEmcal::UserCreateOutputObjects()
263 // Create user output.
265 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
267 AliVEventHandler *evhand = mgr->GetInputEventHandler();
269 if (evhand->InheritsFrom("AliESDInputHandler")) {
277 AliError("Event handler not found!");
281 AliError("Analysis manager not found!");
288 fOutput = new TList();
291 if (fForceBeamType == kpp)
294 if (!fGeneralHistograms)
298 fHistTrialsAfterSel = new TH1F("fHistTrialsAfterSel", "fHistTrialsAfterSel", 11, 0, 11);
299 fHistTrialsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
300 fHistTrialsAfterSel->GetYaxis()->SetTitle("trials");
301 fOutput->Add(fHistTrialsAfterSel);
303 fHistEventsAfterSel = new TH1F("fHistEventsAfterSel", "fHistEventsAfterSel", 11, 0, 11);
304 fHistEventsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
305 fHistEventsAfterSel->GetYaxis()->SetTitle("total events");
306 fOutput->Add(fHistEventsAfterSel);
308 fHistXsectionAfterSel = new TProfile("fHistXsectionAfterSel", "fHistXsectionAfterSel", 11, 0, 11);
309 fHistXsectionAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
310 fHistXsectionAfterSel->GetYaxis()->SetTitle("xsection");
311 fOutput->Add(fHistXsectionAfterSel);
313 fHistTrials = new TH1F("fHistTrials", "fHistTrials", 11, 0, 11);
314 fHistTrials->GetXaxis()->SetTitle("p_{T} hard bin");
315 fHistTrials->GetYaxis()->SetTitle("trials");
316 fOutput->Add(fHistTrials);
318 fHistEvents = new TH1F("fHistEvents", "fHistEvents", 11, 0, 11);
319 fHistEvents->GetXaxis()->SetTitle("p_{T} hard bin");
320 fHistEvents->GetYaxis()->SetTitle("total events");
321 fOutput->Add(fHistEvents);
323 fHistXsection = new TProfile("fHistXsection", "fHistXsection", 11, 0, 11);
324 fHistXsection->GetXaxis()->SetTitle("p_{T} hard bin");
325 fHistXsection->GetYaxis()->SetTitle("xsection");
326 fOutput->Add(fHistXsection);
328 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
329 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
331 for (Int_t i = 1; i < 12; i++) {
332 fHistTrialsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
333 fHistEventsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
335 fHistTrials->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
336 fHistXsection->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
337 fHistEvents->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
340 fHistPtHard = new TH1F("fHistPtHard", "fHistPtHard", fNbins*2, fMinBinPt, fMaxBinPt*4);
341 fHistPtHard->GetXaxis()->SetTitle("p_{T,hard} (GeV/c)");
342 fHistPtHard->GetYaxis()->SetTitle("counts");
343 fOutput->Add(fHistPtHard);
346 fHistCentrality = new TH1F("fHistCentrality","Event centrality distribution", 200, 0, 100);
347 fHistCentrality->GetXaxis()->SetTitle("Centrality (%)");
348 fHistCentrality->GetYaxis()->SetTitle("counts");
349 fOutput->Add(fHistCentrality);
351 fHistZVertex = new TH1F("fHistZVertex","Z vertex position", 60, -30, 30);
352 fHistZVertex->GetXaxis()->SetTitle("z");
353 fHistZVertex->GetYaxis()->SetTitle("counts");
354 fOutput->Add(fHistZVertex);
356 fHistEventPlane = new TH1F("fHistEventPlane","Event plane", 120, -TMath::Pi(), TMath::Pi());
357 fHistEventPlane->GetXaxis()->SetTitle("event plane");
358 fHistEventPlane->GetYaxis()->SetTitle("counts");
359 fOutput->Add(fHistEventPlane);
361 fHistEventRejection = new TH1I("fHistEventRejection","Reasons to reject event",20,0,20);
362 fHistEventRejection->Fill("PhysSel",0);
363 fHistEventRejection->Fill("trigger",0);
364 fHistEventRejection->Fill("trigTypeSel",0);
365 fHistEventRejection->Fill("Cent",0);
366 fHistEventRejection->Fill("vertex contr.",0);
367 fHistEventRejection->Fill("Vz",0);
368 fHistEventRejection->Fill("trackInEmcal",0);
369 fHistEventRejection->Fill("minNTrack",0);
370 fHistEventRejection->Fill("VtxSel2013pA",0);
371 fHistEventRejection->Fill("PileUp",0);
372 fHistEventRejection->Fill("EvtPlane",0);
373 fHistEventRejection->Fill("SelPtHardBin",0);
374 fHistEventRejection->GetYaxis()->SetTitle("counts");
375 fOutput->Add(fHistEventRejection);
377 PostData(1, fOutput);
380 //________________________________________________________________________
381 Bool_t AliAnalysisTaskEmcal::FillGeneralHistograms()
384 fHistEventsAfterSel->Fill(fPtHardBin, 1);
385 fHistTrialsAfterSel->Fill(fPtHardBin, fNTrials);
386 fHistXsectionAfterSel->Fill(fPtHardBin, fXsection);
387 fHistPtHard->Fill(fPtHard);
390 fHistCentrality->Fill(fCent);
391 fHistZVertex->Fill(fVertex[2]);
392 fHistEventPlane->Fill(fEPV0);
397 //________________________________________________________________________
398 void AliAnalysisTaskEmcal::UserExec(Option_t *)
400 // Main loop, called for each event.
402 fMainTriggerPatch = NULL;
410 if (!RetrieveEventObjects())
413 if (!IsEventSelected())
416 if (fGeneralHistograms && fCreateHisto) {
417 if (!FillGeneralHistograms())
425 if (!FillHistograms())
429 if (fCreateHisto && fOutput) {
430 // information for this iteration of the UserExec in the container
431 PostData(1, fOutput);
435 //________________________________________________________________________
436 Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Int_t c) const
438 // Return true if cluster is accepted.
443 AliClusterContainer *cont = GetClusterContainer(c);
445 AliError(Form("%s:Container %d not found",GetName(),c));
449 return cont->AcceptCluster(clus);
452 //________________________________________________________________________
453 Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVParticle *track, Int_t c) const
455 // Return true if track is accepted.
460 AliParticleContainer *cont = GetParticleContainer(c);
462 AliError(Form("%s:Container %d not found",GetName(),c));
466 return cont->AcceptParticle(track);
469 //________________________________________________________________________
470 Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &fXsec, Float_t &fTrials, Int_t &pthard)
473 // Get the cross section and the trails either from pyxsec.root or from pysec_hists.root
474 // Get the pt hard bin from the file path
475 // This is to called in Notify and should provide the path to the AOD/ESD file
476 // (Partially copied from AliAnalysisHelperJetTasks)
478 TString file(currFile);
482 if (file.Contains(".zip#")) {
483 Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
484 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
485 Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
486 file.Replace(pos+1,pos2-pos1,"");
488 // not an archive take the basename....
489 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
491 AliDebug(1,Form("File name: %s",file.Data()));
493 // Get the pt hard bin
494 TString strPthard(file);
496 strPthard.Remove(strPthard.Last('/'));
497 strPthard.Remove(strPthard.Last('/'));
498 if (strPthard.Contains("AOD")) strPthard.Remove(strPthard.Last('/'));
499 strPthard.Remove(0,strPthard.Last('/')+1);
500 if (strPthard.IsDec())
501 pthard = strPthard.Atoi();
503 AliWarning(Form("Could not extract file number from path %s", strPthard.Data()));
505 // 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
506 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root"));
509 // next trial fetch the histgram file
510 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
512 // not a severe condition but inciate that we have no information
515 // find the tlist we want to be independtent of the name so use the Tkey
516 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
521 TList *list = dynamic_cast<TList*>(key->ReadObj());
526 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
527 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
530 } else { // no tree pyxsec.root
531 TTree *xtree = (TTree*)fxsec->Get("Xsection");
537 Double_t xsection = 0;
538 xtree->SetBranchAddress("xsection",&xsection);
539 xtree->SetBranchAddress("ntrials",&ntrials);
548 //________________________________________________________________________
549 Bool_t AliAnalysisTaskEmcal::UserNotify()
551 // Called when file changes.
553 if (!fIsPythia || !fGeneralHistograms || !fCreateHisto)
556 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
558 AliError(Form("%s - UserNotify: No current tree!",GetName()));
562 Float_t xsection = 0;
566 TFile *curfile = tree->GetCurrentFile();
568 AliError(Form("%s - UserNotify: No current file!",GetName()));
572 TChain *chain = dynamic_cast<TChain*>(tree);
573 if (chain) tree = chain->GetTree();
575 Int_t nevents = tree->GetEntriesFast();
577 PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthardbin);
580 if ((pthardbin < 0) || (pthardbin > 10)) pthardbin = 0;
582 fHistTrials->Fill(pthardbin, trials);
583 fHistXsection->Fill(pthardbin, xsection);
584 fHistEvents->Fill(pthardbin, nevents);
589 //________________________________________________________________________
590 void AliAnalysisTaskEmcal::ExecOnce()
592 // Init the analysis.
595 AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
599 if (fNeedEmcalGeom) {
600 fGeom = AliEMCALGeometry::GetInstance();
602 AliError(Form("%s: Can not create geometry", GetName()));
608 if (fEventPlaneVsEmcal >= 0) {
610 Double_t ep = (fGeom->GetArm1PhiMax() + fGeom->GetArm1PhiMin()) / 2 * TMath::DegToRad() + fEventPlaneVsEmcal - TMath::Pi();
611 fMinEventPlane = ep - TMath::Pi() / 4;
612 fMaxEventPlane = ep + TMath::Pi() / 4;
615 AliWarning("Could not set event plane limits because EMCal geometry was not loaded!");
619 //Load all requested track branches - each container knows name already
620 for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
621 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
622 cont->SetArray(InputEvent());
625 if (fParticleCollArray.GetEntriesFast()>0) {
626 fTracks = GetParticleArray(0);
628 AliError(Form("%s: Could not retrieve first track branch!", GetName()));
633 //Load all requested cluster branches - each container knows name already
634 for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
635 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
636 cont->SetArray(InputEvent());
639 if (fClusterCollArray.GetEntriesFast()>0) {
640 fCaloClusters = GetClusterArray(0);
641 if (!fCaloClusters) {
642 AliError(Form("%s: Could not retrieve first cluster branch!", GetName()));
647 if (!fCaloCellsName.IsNull() && !fCaloCells) {
648 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
650 AliError(Form("%s: Could not retrieve cells %s!", GetName(), fCaloCellsName.Data()));
655 if (!fCaloTriggersName.IsNull() && !fCaloTriggers) {
656 fCaloTriggers = dynamic_cast<AliVCaloTrigger*>(InputEvent()->FindListObject(fCaloTriggersName));
657 if (!fCaloTriggers) {
658 AliError(Form("%s: Could not retrieve calo triggers %s!", GetName(), fCaloTriggersName.Data()));
663 if (!fCaloTriggerPatchInfoName.IsNull() && !fTriggerPatchInfo) {
664 fTriggerPatchInfo = GetArrayFromEvent(fCaloTriggerPatchInfoName.Data(),"AliEmcalTriggerPatchInfo");
665 if (!fTriggerPatchInfo) {
666 AliError(Form("%s: Could not retrieve calo trigger patch info %s!", GetName(), fCaloTriggerPatchInfoName.Data()));
672 fInitialized = kTRUE;
675 //_____________________________________________________
676 AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
678 // Get beam type : pp-AA-pA
679 // ESDs have it directly, AODs get it from hardcoded run number ranges
681 if (fForceBeamType != kNA)
682 return fForceBeamType;
684 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
686 const AliESDRun *run = esd->GetESDRun();
687 TString beamType = run->GetBeamType();
688 if (beamType == "p-p")
690 else if (beamType == "A-A")
692 else if (beamType == "p-A")
697 Int_t runNumber = InputEvent()->GetRunNumber();
698 if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
699 (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
701 } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
702 (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
710 //_____________________________________________________
711 AliAnalysisTaskEmcal::TriggerType AliAnalysisTaskEmcal::GetTriggerType()
713 // Get trigger type: kND, kJ1, kJ2
715 if (!fTriggerPatchInfo)
718 //number of patches in event
719 Int_t nPatch = fTriggerPatchInfo->GetEntries();
721 //loop over patches to define trigger type of event
724 AliEmcalTriggerPatchInfo *patch;
725 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
726 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
727 if (patch->IsJetHigh()) nJ1++;
728 if (patch->IsJetLow()) nJ2++;
739 //________________________________________________________________________
740 Bool_t AliAnalysisTaskEmcal::IsEventSelected()
742 // Check if event is selected
744 if (fOffTrigger != AliVEvent::kAny) {
746 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
748 res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
750 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
752 res = aev->GetHeader()->GetOfflineTrigger();
755 if ((res & fOffTrigger) == 0) {
756 if (fGeneralHistograms)
757 fHistEventRejection->Fill("PhysSel",1);
762 if (!fTrigClass.IsNull()) {
764 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
766 fired = eev->GetFiredTriggerClasses();
768 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
770 fired = aev->GetFiredTriggerClasses();
773 if (!fired.Contains("-B-")) {
774 if (fGeneralHistograms)
775 fHistEventRejection->Fill("trigger",1);
778 TObjArray *arr = fTrigClass.Tokenize("|");
780 if (fGeneralHistograms)
781 fHistEventRejection->Fill("trigger",1);
785 for (Int_t i=0;i<arr->GetEntriesFast();++i) {
786 TObject *obj = arr->At(i);
789 if (fired.Contains(obj->GetName())) {
796 if (fGeneralHistograms)
797 fHistEventRejection->Fill("trigger",1);
802 if (fTriggerTypeSel != kND) {
803 if (fTriggerType != fTriggerTypeSel) {
804 if (fGeneralHistograms)
805 fHistEventRejection->Fill("trigTypeSel",1);
810 if ((fMinCent != -999) && (fMaxCent != -999)) {
811 if (fCent<fMinCent || fCent>fMaxCent) {
812 if (fGeneralHistograms)
813 fHistEventRejection->Fill("Cent",1);
818 if (fUseAliAnaUtils) {
819 if (!fAliAnalysisUtils)
820 fAliAnalysisUtils = new AliAnalysisUtils();
821 fAliAnalysisUtils->SetMinVtxContr(2);
822 fAliAnalysisUtils->SetMaxVtxZ(999);
823 if(fMinVz<-10.) fMinVz = -10.;
824 if(fMinVz>10.) fMaxVz = 10.;
826 if (!fAliAnalysisUtils->IsVertexSelected2013pA(InputEvent())) {
827 if (fGeneralHistograms)
828 fHistEventRejection->Fill("VtxSel2013pA",1);
832 if (fAliAnalysisUtils->IsPileUpEvent(InputEvent())) {
833 fHistEventRejection->Fill("PileUp",1);
838 if ((fMinVz != -999) && (fMaxVz != -999)) {
839 if (fNVertCont == 0 ) {
840 if (fGeneralHistograms)
841 fHistEventRejection->Fill("vertex contr.",1);
844 Double_t vz = fVertex[2];
845 if (vz<fMinVz || vz>fMaxVz) {
846 if (fGeneralHistograms)
847 fHistEventRejection->Fill("Vz",1);
852 if (fMinPtTrackInEmcal > 0 && fGeom) {
853 Bool_t trackInEmcalOk = kFALSE;
854 Int_t ntracks = GetNParticles(0);
855 for (Int_t i = 0; i < ntracks; i++) {
856 AliVParticle *track = GetAcceptParticleFromArray(i,0);
860 Double_t phiMin = fGeom->GetArm1PhiMin() * TMath::DegToRad();
861 Double_t phiMax = fGeom->GetArm1PhiMax() * TMath::DegToRad();
862 Int_t runNumber = InputEvent()->GetRunNumber();
863 if (runNumber>=177295 && runNumber<=197470) { //small SM masked in 2012 and 2013
865 phiMax = TMath::Pi();
868 if (track->Eta() < fGeom->GetArm1EtaMin() || track->Eta() > fGeom->GetArm1EtaMax() || track->Phi() < phiMin || track->Phi() > phiMax)
870 if (track->Pt() > fMinPtTrackInEmcal) {
871 trackInEmcalOk = kTRUE;
875 if (!trackInEmcalOk) {
876 if (fGeneralHistograms)
877 fHistEventRejection->Fill("trackInEmcal",1);
882 if (fMinNTrack > 0) {
883 Int_t nTracksAcc = 0;
884 Int_t ntracks = GetNParticles(0);
885 for (Int_t i = 0; i < ntracks; i++) {
886 AliVParticle *track = GetAcceptParticleFromArray(i,0);
889 if (track->Pt() > fTrackPtCut) {
891 if (nTracksAcc>=fMinNTrack)
895 if (nTracksAcc<fMinNTrack) {
896 if (fGeneralHistograms)
897 fHistEventRejection->Fill("minNTrack",1);
902 if (!(fEPV0 > fMinEventPlane && fEPV0 <= fMaxEventPlane) &&
903 !(fEPV0 + TMath::Pi() > fMinEventPlane && fEPV0 + TMath::Pi() <= fMaxEventPlane) &&
904 !(fEPV0 - TMath::Pi() > fMinEventPlane && fEPV0 - TMath::Pi() <= fMaxEventPlane))
906 if (fGeneralHistograms)
907 fHistEventRejection->Fill("EvtPlane",1);
911 if (fSelectPtHardBin != -999 && fSelectPtHardBin != fPtHardBin) {
912 if (fGeneralHistograms)
913 fHistEventRejection->Fill("SelPtHardBin",1);
920 //________________________________________________________________________
921 TClonesArray *AliAnalysisTaskEmcal::GetArrayFromEvent(const char *name, const char *clname)
923 // Get array from event.
925 TClonesArray *arr = 0;
927 if (!sname.IsNull()) {
928 arr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(sname));
930 AliWarning(Form("%s: Could not retrieve array with name %s!", GetName(), name));
940 TString objname(arr->GetClass()->GetName());
942 if (!cls.InheritsFrom(clname)) {
943 AliWarning(Form("%s: Objects of type %s in %s are not inherited from %s!",
944 GetName(), cls.GetName(), name, clname));
950 //________________________________________________________________________
951 Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
953 // Retrieve objects from event.
960 const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
962 vert->GetXYZ(fVertex);
963 fNVertCont = vert->GetNContributors();
966 fBeamType = GetBeamType();
968 if (fBeamType == kAA || fBeamType == kpA ) {
969 AliCentrality *aliCent = InputEvent()->GetCentrality();
971 fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
973 if (fCent >= 0 && fCent < 10) fCentBin = 0;
974 else if (fCent >= 10 && fCent < 30) fCentBin = 1;
975 else if (fCent >= 30 && fCent < 50) fCentBin = 2;
976 else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
978 AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
979 fCentBin = fNcentBins-1;
982 Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
984 fCentBin = TMath::FloorNint(fCent/centWidth);
987 if (fCentBin>=fNcentBins) {
988 AliWarning(Form("%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),fCent,fCentBin));
989 fCentBin = fNcentBins-1;
993 AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
996 AliEventplane *aliEP = InputEvent()->GetEventplane();
998 fEPV0 = aliEP->GetEventplane("V0" ,InputEvent());
999 fEPV0A = aliEP->GetEventplane("V0A",InputEvent());
1000 fEPV0C = aliEP->GetEventplane("V0C",InputEvent());
1002 AliWarning(Form("%s: Could not retrieve event plane information!", GetName()));
1012 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent()->GenEventHeader());
1013 if (!fPythiaHeader) {
1015 AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
1018 for (UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
1019 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
1020 if (fPythiaHeader) break;
1026 if (fPythiaHeader) {
1027 fPtHard = fPythiaHeader->GetPtHard();
1029 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
1030 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
1031 for (fPtHardBin = 0; fPtHardBin < 11; fPtHardBin++) {
1032 if (fPtHard >= ptHardLo[fPtHardBin] && fPtHard < ptHardHi[fPtHardBin])
1036 fXsection = fPythiaHeader->GetXsection();
1037 fNTrials = fPythiaHeader->Trials();
1041 fTriggerType = GetTriggerType();
1046 //________________________________________________________________________
1047 AliParticleContainer* AliAnalysisTaskEmcal::AddParticleContainer(const char *n)
1049 // Add particle container
1050 // will be called in AddTask macro
1052 TString tmp = TString(n);
1053 if (tmp.IsNull()) return 0;
1055 AliParticleContainer *cont = 0x0;
1056 cont = new AliParticleContainer();
1057 cont->SetArrayName(n);
1058 TString contName = cont->GetArrayName();
1060 fParticleCollArray.Add(cont);
1065 //________________________________________________________________________
1066 AliClusterContainer* AliAnalysisTaskEmcal::AddClusterContainer(const char *n)
1068 // Add cluster container
1069 // will be called in AddTask macro
1071 TString tmp = TString(n);
1072 if (tmp.IsNull()) return 0;
1074 AliClusterContainer *cont = 0x0;
1075 cont = new AliClusterContainer();
1076 cont->SetArrayName(n);
1078 fClusterCollArray.Add(cont);
1083 //________________________________________________________________________
1084 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(Int_t i) const
1086 // Get i^th particle container
1088 if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1089 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1093 //________________________________________________________________________
1094 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(Int_t i) const
1096 // Get i^th cluster container
1098 if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1099 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1103 //________________________________________________________________________
1104 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(const char *name) const
1106 // Get particle container with name
1108 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1112 //________________________________________________________________________
1113 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(const char *name) const
1115 // Get cluster container with name
1117 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1121 //________________________________________________________________________
1122 TClonesArray* AliAnalysisTaskEmcal::GetParticleArray(Int_t i) const
1124 // Get i^th TClonesArray with AliVParticle
1126 AliParticleContainer *cont = GetParticleContainer(i);
1128 AliError(Form("%s: Particle container %d not found",GetName(),i));
1131 TString contName = cont->GetArrayName();
1132 return cont->GetArray();
1135 //________________________________________________________________________
1136 TClonesArray* AliAnalysisTaskEmcal::GetClusterArray(Int_t i) const
1138 // Get i^th TClonesArray with AliVCluster
1140 AliClusterContainer *cont = GetClusterContainer(i);
1142 AliError(Form("%s:Cluster container %d not found",GetName(),i));
1145 return cont->GetArray();
1148 //________________________________________________________________________
1149 AliVParticle* AliAnalysisTaskEmcal::GetAcceptParticleFromArray(Int_t p, Int_t c) const
1151 // Get particle p if accepted from container c
1152 // If particle not accepted return 0
1154 AliParticleContainer *cont = GetParticleContainer(c);
1156 AliError(Form("%s: Particle container %d not found",GetName(),c));
1159 AliVParticle *vp = cont->GetAcceptParticle(p);
1164 //________________________________________________________________________
1165 AliVCluster* AliAnalysisTaskEmcal::GetAcceptClusterFromArray(Int_t cl, Int_t c) const
1167 // Get particle p if accepted from container c
1168 // If particle not accepted return 0
1170 AliClusterContainer *cont = GetClusterContainer(c);
1172 AliError(Form("%s: Cluster container %d not found",GetName(),c));
1175 AliVCluster *vc = cont->GetAcceptCluster(cl);
1180 //________________________________________________________________________
1181 Int_t AliAnalysisTaskEmcal::GetNParticles(Int_t i) const
1183 // Get number of entries in particle array i
1185 AliParticleContainer *cont = GetParticleContainer(i);
1187 AliError(Form("%s: Particle container %d not found",GetName(),i));
1190 return cont->GetNEntries();
1193 //________________________________________________________________________
1194 Int_t AliAnalysisTaskEmcal::GetNClusters(Int_t i) const
1196 // Get number of entries in cluster array i
1198 AliClusterContainer *cont = GetClusterContainer(i);
1200 AliError(Form("%s: Cluster container %d not found",GetName(),i));
1203 return cont->GetNEntries();
1206 //________________________________________________________________________
1207 AliEmcalTriggerPatchInfo* AliAnalysisTaskEmcal::GetMainTriggerPatch()
1209 //get main trigger match; if not known yet, look for it and cache
1211 if (fMainTriggerPatch)
1212 return fMainTriggerPatch;
1214 if (!fTriggerPatchInfo) {
1215 AliError(Form("%s: fTriggerPatchInfo not available",GetName()));
1219 //number of patches in event
1220 Int_t nPatch = fTriggerPatchInfo->GetEntries();
1222 //extract main trigger patch
1223 AliEmcalTriggerPatchInfo *patch;
1224 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
1226 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
1227 if (patch->IsMainTrigger()) {
1228 fMainTriggerPatch = patch;
1233 return fMainTriggerPatch;
1236 //________________________________________________________________________
1237 void AliAnalysisTaskEmcal::AddObjectToEvent(TObject *obj)
1239 // Add object to event
1241 if (!(InputEvent()->FindListObject(obj->GetName()))) {
1242 InputEvent()->AddObject(obj);
1244 AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), obj->GetName()));
1248 //________________________________________________________________________
1249 void AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max, Double_t* array) const
1251 Double_t binWidth = (max-min)/n;
1253 for (Int_t i = 1; i <= n; i++) {
1254 array[i] = array[i-1]+binWidth;
1258 //________________________________________________________________________
1259 Double_t* AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max) const
1261 Double_t *array = new Double_t[n+1];
1263 GenerateFixedBinArray(n, min, max, array);