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 fAliAnalysisUtils(0x0),
61 fOffTrigger(AliVEvent::kAny),
67 fMinPtTrackInEmcal(0),
68 fEventPlaneVsEmcal(-1),
74 fSelectPtHardBin(-999),
78 fNeedEmcalGeom(kTRUE),
100 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),
187 fHistTrialsAfterSel(0),
188 fHistEventsAfterSel(0),
189 fHistXsectionAfterSel(0),
197 fHistEventRejection(0)
199 // Standard constructor.
205 fParticleCollArray.SetOwner(kTRUE);
206 fClusterCollArray.SetOwner(kTRUE);
209 DefineOutput(1, TList::Class());
213 //________________________________________________________________________
214 AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
219 //________________________________________________________________________
220 void AliAnalysisTaskEmcal::SetClusPtCut(Double_t cut, Int_t c)
222 AliClusterContainer *cont = GetClusterContainer(c);
223 if (cont) cont->SetClusPtCut(cut);
224 else AliError(Form("%s in SetClusPtCut(...): container %d not found",GetName(),c));
227 //________________________________________________________________________
228 void AliAnalysisTaskEmcal::SetClusTimeCut(Double_t min, Double_t max, Int_t c)
230 AliClusterContainer *cont = GetClusterContainer(c);
231 if (cont) cont->SetClusTimeCut(min,max);
232 else AliError(Form("%s in SetClusTimeCut(...): container %d not found",GetName(),c));
235 //________________________________________________________________________
236 void AliAnalysisTaskEmcal::SetTrackPtCut(Double_t cut, Int_t c)
238 AliParticleContainer *cont = GetParticleContainer(c);
239 if (cont) cont->SetParticlePtCut(cut);
240 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
245 //________________________________________________________________________
246 void AliAnalysisTaskEmcal::SetTrackEtaLimits(Double_t min, Double_t max, Int_t c)
248 AliParticleContainer *cont = GetParticleContainer(c);
249 if (cont) cont->SetParticleEtaLimits(min,max);
250 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
253 //________________________________________________________________________
254 void AliAnalysisTaskEmcal::SetTrackPhiLimits(Double_t min, Double_t max, Int_t c)
256 AliParticleContainer *cont = GetParticleContainer(c);
257 if (cont) cont->SetParticlePhiLimits(min,max);
258 else AliError(Form("%s in SetTrackPhiLimits(...): container %d not found",GetName(),c));
261 //________________________________________________________________________
262 void AliAnalysisTaskEmcal::UserCreateOutputObjects()
264 // Create user output.
266 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
268 AliVEventHandler *evhand = mgr->GetInputEventHandler();
270 if (evhand->InheritsFrom("AliESDInputHandler")) {
278 AliError("Event handler not found!");
282 AliError("Analysis manager not found!");
289 fOutput = new TList();
292 if (fForceBeamType == kpp)
295 if (!fGeneralHistograms)
299 fHistTrialsAfterSel = new TH1F("fHistTrialsAfterSel", "fHistTrialsAfterSel", 11, 0, 11);
300 fHistTrialsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
301 fHistTrialsAfterSel->GetYaxis()->SetTitle("trials");
302 fOutput->Add(fHistTrialsAfterSel);
304 fHistEventsAfterSel = new TH1F("fHistEventsAfterSel", "fHistEventsAfterSel", 11, 0, 11);
305 fHistEventsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
306 fHistEventsAfterSel->GetYaxis()->SetTitle("total events");
307 fOutput->Add(fHistEventsAfterSel);
309 fHistXsectionAfterSel = new TProfile("fHistXsectionAfterSel", "fHistXsectionAfterSel", 11, 0, 11);
310 fHistXsectionAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
311 fHistXsectionAfterSel->GetYaxis()->SetTitle("xsection");
312 fOutput->Add(fHistXsectionAfterSel);
314 fHistTrials = new TH1F("fHistTrials", "fHistTrials", 11, 0, 11);
315 fHistTrials->GetXaxis()->SetTitle("p_{T} hard bin");
316 fHistTrials->GetYaxis()->SetTitle("trials");
317 fOutput->Add(fHistTrials);
319 fHistEvents = new TH1F("fHistEvents", "fHistEvents", 11, 0, 11);
320 fHistEvents->GetXaxis()->SetTitle("p_{T} hard bin");
321 fHistEvents->GetYaxis()->SetTitle("total events");
322 fOutput->Add(fHistEvents);
324 fHistXsection = new TProfile("fHistXsection", "fHistXsection", 11, 0, 11);
325 fHistXsection->GetXaxis()->SetTitle("p_{T} hard bin");
326 fHistXsection->GetYaxis()->SetTitle("xsection");
327 fOutput->Add(fHistXsection);
329 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
330 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
332 for (Int_t i = 1; i < 12; i++) {
333 fHistTrialsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
334 fHistEventsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
336 fHistTrials->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
337 fHistXsection->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
338 fHistEvents->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
341 fHistPtHard = new TH1F("fHistPtHard", "fHistPtHard", fNbins*2, fMinBinPt, fMaxBinPt*4);
342 fHistPtHard->GetXaxis()->SetTitle("p_{T,hard} (GeV/c)");
343 fHistPtHard->GetYaxis()->SetTitle("counts");
344 fOutput->Add(fHistPtHard);
347 fHistCentrality = new TH1F("fHistCentrality","Event centrality distribution", 200, 0, 100);
348 fHistCentrality->GetXaxis()->SetTitle("Centrality (%)");
349 fHistCentrality->GetYaxis()->SetTitle("counts");
350 fOutput->Add(fHistCentrality);
352 fHistZVertex = new TH1F("fHistZVertex","Z vertex position", 60, -30, 30);
353 fHistZVertex->GetXaxis()->SetTitle("z");
354 fHistZVertex->GetYaxis()->SetTitle("counts");
355 fOutput->Add(fHistZVertex);
357 fHistEventPlane = new TH1F("fHistEventPlane","Event plane", 120, -TMath::Pi(), TMath::Pi());
358 fHistEventPlane->GetXaxis()->SetTitle("event plane");
359 fHistEventPlane->GetYaxis()->SetTitle("counts");
360 fOutput->Add(fHistEventPlane);
362 fHistEventRejection = new TH1F("fHistEventRejection","Reasons to reject event",20,0,20);
363 fHistEventRejection->GetXaxis()->SetBinLabel(1,"PhysSel");
364 fHistEventRejection->GetXaxis()->SetBinLabel(2,"trigger");
365 fHistEventRejection->GetXaxis()->SetBinLabel(3,"trigTypeSel");
366 fHistEventRejection->GetXaxis()->SetBinLabel(4,"Cent");
367 fHistEventRejection->GetXaxis()->SetBinLabel(5,"vertex contr.");
368 fHistEventRejection->GetXaxis()->SetBinLabel(6,"Vz");
369 fHistEventRejection->GetXaxis()->SetBinLabel(7,"trackInEmcal");
370 fHistEventRejection->GetXaxis()->SetBinLabel(8,"minNTrack");
371 fHistEventRejection->GetXaxis()->SetBinLabel(9,"VtxSel2013pA");
372 fHistEventRejection->GetXaxis()->SetBinLabel(10,"PileUp");
373 fHistEventRejection->GetXaxis()->SetBinLabel(11,"EvtPlane");
374 fHistEventRejection->GetXaxis()->SetBinLabel(12,"SelPtHardBin");
375 fHistEventRejection->GetYaxis()->SetTitle("counts");
376 fOutput->Add(fHistEventRejection);
378 fHistEventCount = new TH1F("fHistEventCount","fHistEventCount",2,0,2);
379 fHistEventCount->GetXaxis()->SetBinLabel(1,"Accepted");
380 fHistEventCount->GetXaxis()->SetBinLabel(2,"Rejected");
381 fHistEventCount->GetYaxis()->SetTitle("counts");
382 fOutput->Add(fHistEventCount);
384 PostData(1, fOutput);
387 //________________________________________________________________________
388 Bool_t AliAnalysisTaskEmcal::FillGeneralHistograms()
391 fHistEventsAfterSel->Fill(fPtHardBin, 1);
392 fHistTrialsAfterSel->Fill(fPtHardBin, fNTrials);
393 fHistXsectionAfterSel->Fill(fPtHardBin, fXsection);
394 fHistPtHard->Fill(fPtHard);
397 fHistCentrality->Fill(fCent);
398 fHistZVertex->Fill(fVertex[2]);
399 fHistEventPlane->Fill(fEPV0);
404 //________________________________________________________________________
405 void AliAnalysisTaskEmcal::UserExec(Option_t *)
407 // Main loop, called for each event.
409 fMainTriggerPatch = NULL;
417 if (!RetrieveEventObjects())
420 if (IsEventSelected()) {
421 if (fGeneralHistograms) fHistEventCount->Fill("Accepted",1);
424 if (fGeneralHistograms) fHistEventCount->Fill("Rejected",1);
428 if (fGeneralHistograms && fCreateHisto) {
429 if (!FillGeneralHistograms())
437 if (!FillHistograms())
441 if (fCreateHisto && fOutput) {
442 // information for this iteration of the UserExec in the container
443 PostData(1, fOutput);
447 //________________________________________________________________________
448 Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Int_t c) const
450 // Return true if cluster is accepted.
455 AliClusterContainer *cont = GetClusterContainer(c);
457 AliError(Form("%s:Container %d not found",GetName(),c));
461 return cont->AcceptCluster(clus);
464 //________________________________________________________________________
465 Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVParticle *track, Int_t c) const
467 // Return true if track is accepted.
472 AliParticleContainer *cont = GetParticleContainer(c);
474 AliError(Form("%s:Container %d not found",GetName(),c));
478 return cont->AcceptParticle(track);
481 //________________________________________________________________________
482 Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &fXsec, Float_t &fTrials, Int_t &pthard)
485 // Get the cross section and the trails either from pyxsec.root or from pysec_hists.root
486 // Get the pt hard bin from the file path
487 // This is to called in Notify and should provide the path to the AOD/ESD file
488 // (Partially copied from AliAnalysisHelperJetTasks)
490 TString file(currFile);
494 if (file.Contains(".zip#")) {
495 Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
496 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
497 Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
498 file.Replace(pos+1,pos2-pos1,"");
500 // not an archive take the basename....
501 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
503 AliDebug(1,Form("File name: %s",file.Data()));
505 // Get the pt hard bin
506 TString strPthard(file);
508 strPthard.Remove(strPthard.Last('/'));
509 strPthard.Remove(strPthard.Last('/'));
510 if (strPthard.Contains("AOD")) strPthard.Remove(strPthard.Last('/'));
511 strPthard.Remove(0,strPthard.Last('/')+1);
512 if (strPthard.IsDec())
513 pthard = strPthard.Atoi();
515 AliWarning(Form("Could not extract file number from path %s", strPthard.Data()));
517 // 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
518 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root"));
521 // next trial fetch the histgram file
522 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
524 // not a severe condition but inciate that we have no information
527 // find the tlist we want to be independtent of the name so use the Tkey
528 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
533 TList *list = dynamic_cast<TList*>(key->ReadObj());
538 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
539 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
542 } else { // no tree pyxsec.root
543 TTree *xtree = (TTree*)fxsec->Get("Xsection");
549 Double_t xsection = 0;
550 xtree->SetBranchAddress("xsection",&xsection);
551 xtree->SetBranchAddress("ntrials",&ntrials);
560 //________________________________________________________________________
561 Bool_t AliAnalysisTaskEmcal::UserNotify()
563 // Called when file changes.
565 if (!fIsPythia || !fGeneralHistograms || !fCreateHisto)
568 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
570 AliError(Form("%s - UserNotify: No current tree!",GetName()));
574 Float_t xsection = 0;
578 TFile *curfile = tree->GetCurrentFile();
580 AliError(Form("%s - UserNotify: No current file!",GetName()));
584 TChain *chain = dynamic_cast<TChain*>(tree);
585 if (chain) tree = chain->GetTree();
587 Int_t nevents = tree->GetEntriesFast();
589 PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthardbin);
592 if ((pthardbin < 0) || (pthardbin > 10)) pthardbin = 0;
594 fHistTrials->Fill(pthardbin, trials);
595 fHistXsection->Fill(pthardbin, xsection);
596 fHistEvents->Fill(pthardbin, nevents);
601 //________________________________________________________________________
602 void AliAnalysisTaskEmcal::ExecOnce()
604 // Init the analysis.
607 AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
611 if (fNeedEmcalGeom) {
612 fGeom = AliEMCALGeometry::GetInstance();
614 AliError(Form("%s: Can not create geometry", GetName()));
620 if (fEventPlaneVsEmcal >= 0) {
622 Double_t ep = (fGeom->GetArm1PhiMax() + fGeom->GetArm1PhiMin()) / 2 * TMath::DegToRad() + fEventPlaneVsEmcal - TMath::Pi();
623 fMinEventPlane = ep - TMath::Pi() / 4;
624 fMaxEventPlane = ep + TMath::Pi() / 4;
627 AliWarning("Could not set event plane limits because EMCal geometry was not loaded!");
631 //Load all requested track branches - each container knows name already
632 for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
633 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
634 cont->SetArray(InputEvent());
637 if (fParticleCollArray.GetEntriesFast()>0) {
638 fTracks = GetParticleArray(0);
640 AliError(Form("%s: Could not retrieve first track branch!", GetName()));
645 //Load all requested cluster branches - each container knows name already
646 for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
647 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
648 cont->SetArray(InputEvent());
651 if (fClusterCollArray.GetEntriesFast()>0) {
652 fCaloClusters = GetClusterArray(0);
653 if (!fCaloClusters) {
654 AliError(Form("%s: Could not retrieve first cluster branch!", GetName()));
659 if (!fCaloCellsName.IsNull() && !fCaloCells) {
660 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
662 AliError(Form("%s: Could not retrieve cells %s!", GetName(), fCaloCellsName.Data()));
667 if (!fCaloTriggersName.IsNull() && !fCaloTriggers) {
668 fCaloTriggers = dynamic_cast<AliVCaloTrigger*>(InputEvent()->FindListObject(fCaloTriggersName));
669 if (!fCaloTriggers) {
670 AliError(Form("%s: Could not retrieve calo triggers %s!", GetName(), fCaloTriggersName.Data()));
675 if (!fCaloTriggerPatchInfoName.IsNull() && !fTriggerPatchInfo) {
676 fTriggerPatchInfo = GetArrayFromEvent(fCaloTriggerPatchInfoName.Data(),"AliEmcalTriggerPatchInfo");
677 if (!fTriggerPatchInfo) {
678 AliError(Form("%s: Could not retrieve calo trigger patch info %s!", GetName(), fCaloTriggerPatchInfoName.Data()));
684 fInitialized = kTRUE;
687 //_____________________________________________________
688 AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
690 // Get beam type : pp-AA-pA
691 // ESDs have it directly, AODs get it from hardcoded run number ranges
693 if (fForceBeamType != kNA)
694 return fForceBeamType;
696 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
698 const AliESDRun *run = esd->GetESDRun();
699 TString beamType = run->GetBeamType();
700 if (beamType == "p-p")
702 else if (beamType == "A-A")
704 else if (beamType == "p-A")
709 Int_t runNumber = InputEvent()->GetRunNumber();
710 if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
711 (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
713 } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
714 (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
722 //________________________________________________________________________
723 ULong_t AliAnalysisTaskEmcal::GetTriggerList()
725 if (!fTriggerPatchInfo)
728 //number of patches in event
729 Int_t nPatch = fTriggerPatchInfo->GetEntries();
731 //loop over patches to define trigger type of event
736 AliEmcalTriggerPatchInfo *patch;
737 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
738 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
739 if (patch->IsGammaHigh()) nG1++;
740 if (patch->IsGammaLow()) nG2++;
741 if (patch->IsJetHigh()) nJ1++;
742 if (patch->IsJetLow()) nJ2++;
745 AliDebug(2, "Patch summary: ");
746 AliDebug(2, Form("Number of patches: %d", nPatch));
747 AliDebug(2, Form("Jet: low[%d], high[%d]" ,nJ2, nJ1));
748 AliDebug(2, Form("Gamma: low[%d], high[%d]" ,nG2, nG1));
752 SETBIT(triggers, kG1);
754 SETBIT(triggers, kG2);
756 SETBIT(triggers, kJ1);
758 SETBIT(triggers, kJ2);
762 //________________________________________________________________________
763 Bool_t AliAnalysisTaskEmcal::HasTriggerType(TriggerType t)
765 // Check if event has a given trigger type
767 return fTriggers == 0;
769 return TESTBIT(fTriggers, int(t));
772 //________________________________________________________________________
773 Bool_t AliAnalysisTaskEmcal::IsEventSelected()
775 // Check if event is selected
777 if (fOffTrigger != AliVEvent::kAny) {
779 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
781 res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
783 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
785 res = aev->GetHeader()->GetOfflineTrigger();
788 if ((res & fOffTrigger) == 0) {
789 if (fGeneralHistograms) fHistEventRejection->Fill("PhysSel",1);
794 if (!fTrigClass.IsNull()) {
796 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
798 fired = eev->GetFiredTriggerClasses();
800 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
802 fired = aev->GetFiredTriggerClasses();
805 if (!fired.Contains("-B-")) {
806 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
809 TObjArray *arr = fTrigClass.Tokenize("|");
811 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
815 for (Int_t i=0;i<arr->GetEntriesFast();++i) {
816 TObject *obj = arr->At(i);
819 if (fired.Contains(obj->GetName())) {
826 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
831 if (fTriggerTypeSel != kND) {
832 if (!HasTriggerType(fTriggerTypeSel)) {
833 if (fGeneralHistograms) fHistEventRejection->Fill("trigTypeSel",1);
838 if ((fMinCent != -999) && (fMaxCent != -999)) {
839 if (fCent<fMinCent || fCent>fMaxCent) {
840 if (fGeneralHistograms) fHistEventRejection->Fill("Cent",1);
845 if (fUseAliAnaUtils) {
846 if (!fAliAnalysisUtils)
847 fAliAnalysisUtils = new AliAnalysisUtils();
848 fAliAnalysisUtils->SetMinVtxContr(2);
849 fAliAnalysisUtils->SetMaxVtxZ(999);
850 if(fMinVz<-10.) fMinVz = -10.;
851 if(fMinVz>10.) fMaxVz = 10.;
853 if (!fAliAnalysisUtils->IsVertexSelected2013pA(InputEvent())) {
854 if (fGeneralHistograms) fHistEventRejection->Fill("VtxSel2013pA",1);
858 if (fAliAnalysisUtils->IsPileUpEvent(InputEvent())) {
859 if (fGeneralHistograms) fHistEventRejection->Fill("PileUp",1);
864 if ((fMinVz != -999) && (fMaxVz != -999)) {
865 if (fNVertCont == 0 ) {
866 if (fGeneralHistograms) fHistEventRejection->Fill("vertex contr.",1);
869 Double_t vz = fVertex[2];
870 if (vz<fMinVz || vz>fMaxVz) {
871 if (fGeneralHistograms) fHistEventRejection->Fill("Vz",1);
876 if (fMinPtTrackInEmcal > 0 && fGeom) {
877 Bool_t trackInEmcalOk = kFALSE;
878 Int_t ntracks = GetNParticles(0);
879 for (Int_t i = 0; i < ntracks; i++) {
880 AliVParticle *track = GetAcceptParticleFromArray(i,0);
884 Double_t phiMin = fGeom->GetArm1PhiMin() * TMath::DegToRad();
885 Double_t phiMax = fGeom->GetArm1PhiMax() * TMath::DegToRad();
886 Int_t runNumber = InputEvent()->GetRunNumber();
887 if (runNumber>=177295 && runNumber<=197470) { //small SM masked in 2012 and 2013
889 phiMax = TMath::Pi();
892 if (track->Eta() < fGeom->GetArm1EtaMin() || track->Eta() > fGeom->GetArm1EtaMax() || track->Phi() < phiMin || track->Phi() > phiMax)
894 if (track->Pt() > fMinPtTrackInEmcal) {
895 trackInEmcalOk = kTRUE;
899 if (!trackInEmcalOk) {
900 if (fGeneralHistograms) fHistEventRejection->Fill("trackInEmcal",1);
905 if (fMinNTrack > 0) {
906 Int_t nTracksAcc = 0;
907 Int_t ntracks = GetNParticles(0);
908 for (Int_t i = 0; i < ntracks; i++) {
909 AliVParticle *track = GetAcceptParticleFromArray(i,0);
912 if (track->Pt() > fTrackPtCut) {
914 if (nTracksAcc>=fMinNTrack)
918 if (nTracksAcc<fMinNTrack) {
919 if (fGeneralHistograms) fHistEventRejection->Fill("minNTrack",1);
924 if (!(fEPV0 > fMinEventPlane && fEPV0 <= fMaxEventPlane) &&
925 !(fEPV0 + TMath::Pi() > fMinEventPlane && fEPV0 + TMath::Pi() <= fMaxEventPlane) &&
926 !(fEPV0 - TMath::Pi() > fMinEventPlane && fEPV0 - TMath::Pi() <= fMaxEventPlane))
928 if (fGeneralHistograms) fHistEventRejection->Fill("EvtPlane",1);
932 if (fSelectPtHardBin != -999 && fSelectPtHardBin != fPtHardBin) {
933 if (fGeneralHistograms) fHistEventRejection->Fill("SelPtHardBin",1);
940 //________________________________________________________________________
941 TClonesArray *AliAnalysisTaskEmcal::GetArrayFromEvent(const char *name, const char *clname)
943 // Get array from event.
945 TClonesArray *arr = 0;
947 if (!sname.IsNull()) {
948 arr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(sname));
950 AliWarning(Form("%s: Could not retrieve array with name %s!", GetName(), name));
960 TString objname(arr->GetClass()->GetName());
962 if (!cls.InheritsFrom(clname)) {
963 AliWarning(Form("%s: Objects of type %s in %s are not inherited from %s!",
964 GetName(), cls.GetName(), name, clname));
970 //________________________________________________________________________
971 Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
973 // Retrieve objects from event.
980 const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
982 vert->GetXYZ(fVertex);
983 fNVertCont = vert->GetNContributors();
986 fBeamType = GetBeamType();
988 if (fBeamType == kAA || fBeamType == kpA ) {
989 AliCentrality *aliCent = InputEvent()->GetCentrality();
991 fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
993 if (fCent >= 0 && fCent < 10) fCentBin = 0;
994 else if (fCent >= 10 && fCent < 30) fCentBin = 1;
995 else if (fCent >= 30 && fCent < 50) fCentBin = 2;
996 else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
998 AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
999 fCentBin = fNcentBins-1;
1002 Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1004 fCentBin = TMath::FloorNint(fCent/centWidth);
1007 if (fCentBin>=fNcentBins) {
1008 AliWarning(Form("%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),fCent,fCentBin));
1009 fCentBin = fNcentBins-1;
1013 AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
1014 fCentBin = fNcentBins-1;
1016 AliEventplane *aliEP = InputEvent()->GetEventplane();
1018 fEPV0 = aliEP->GetEventplane("V0" ,InputEvent());
1019 fEPV0A = aliEP->GetEventplane("V0A",InputEvent());
1020 fEPV0C = aliEP->GetEventplane("V0C",InputEvent());
1022 AliWarning(Form("%s: Could not retrieve event plane information!", GetName()));
1032 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent()->GenEventHeader());
1033 if (!fPythiaHeader) {
1035 AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
1038 for (UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
1039 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
1040 if (fPythiaHeader) break;
1046 if (fPythiaHeader) {
1047 fPtHard = fPythiaHeader->GetPtHard();
1049 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
1050 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
1051 for (fPtHardBin = 0; fPtHardBin < 11; fPtHardBin++) {
1052 if (fPtHard >= ptHardLo[fPtHardBin] && fPtHard < ptHardHi[fPtHardBin])
1056 fXsection = fPythiaHeader->GetXsection();
1057 fNTrials = fPythiaHeader->Trials();
1061 fTriggers = GetTriggerList();
1066 //________________________________________________________________________
1067 AliParticleContainer* AliAnalysisTaskEmcal::AddParticleContainer(const char *n)
1069 // Add particle container
1070 // will be called in AddTask macro
1072 TString tmp = TString(n);
1073 if (tmp.IsNull()) return 0;
1075 AliParticleContainer *cont = 0x0;
1076 cont = new AliParticleContainer();
1077 cont->SetArrayName(n);
1078 TString contName = cont->GetArrayName();
1080 fParticleCollArray.Add(cont);
1085 //________________________________________________________________________
1086 AliClusterContainer* AliAnalysisTaskEmcal::AddClusterContainer(const char *n)
1088 // Add cluster container
1089 // will be called in AddTask macro
1091 TString tmp = TString(n);
1092 if (tmp.IsNull()) return 0;
1094 AliClusterContainer *cont = 0x0;
1095 cont = new AliClusterContainer();
1096 cont->SetArrayName(n);
1098 fClusterCollArray.Add(cont);
1103 //________________________________________________________________________
1104 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(Int_t i) const
1106 // Get i^th particle container
1108 if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1109 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1113 //________________________________________________________________________
1114 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(Int_t i) const
1116 // Get i^th cluster container
1118 if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1119 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1123 //________________________________________________________________________
1124 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(const char *name) const
1126 // Get particle container with name
1128 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1132 //________________________________________________________________________
1133 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(const char *name) const
1135 // Get cluster container with name
1137 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1141 //________________________________________________________________________
1142 TClonesArray* AliAnalysisTaskEmcal::GetParticleArray(Int_t i) const
1144 // Get i^th TClonesArray with AliVParticle
1146 AliParticleContainer *cont = GetParticleContainer(i);
1148 AliError(Form("%s: Particle container %d not found",GetName(),i));
1151 TString contName = cont->GetArrayName();
1152 return cont->GetArray();
1155 //________________________________________________________________________
1156 TClonesArray* AliAnalysisTaskEmcal::GetClusterArray(Int_t i) const
1158 // Get i^th TClonesArray with AliVCluster
1160 AliClusterContainer *cont = GetClusterContainer(i);
1162 AliError(Form("%s:Cluster container %d not found",GetName(),i));
1165 return cont->GetArray();
1168 //________________________________________________________________________
1169 AliVParticle* AliAnalysisTaskEmcal::GetAcceptParticleFromArray(Int_t p, Int_t c) const
1171 // Get particle p if accepted from container c
1172 // If particle not accepted return 0
1174 AliParticleContainer *cont = GetParticleContainer(c);
1176 AliError(Form("%s: Particle container %d not found",GetName(),c));
1179 AliVParticle *vp = cont->GetAcceptParticle(p);
1184 //________________________________________________________________________
1185 AliVCluster* AliAnalysisTaskEmcal::GetAcceptClusterFromArray(Int_t cl, Int_t c) const
1187 // Get particle p if accepted from container c
1188 // If particle not accepted return 0
1190 AliClusterContainer *cont = GetClusterContainer(c);
1192 AliError(Form("%s: Cluster container %d not found",GetName(),c));
1195 AliVCluster *vc = cont->GetAcceptCluster(cl);
1200 //________________________________________________________________________
1201 Int_t AliAnalysisTaskEmcal::GetNParticles(Int_t i) const
1203 // Get number of entries in particle array i
1205 AliParticleContainer *cont = GetParticleContainer(i);
1207 AliError(Form("%s: Particle container %d not found",GetName(),i));
1210 return cont->GetNEntries();
1213 //________________________________________________________________________
1214 Int_t AliAnalysisTaskEmcal::GetNClusters(Int_t i) const
1216 // Get number of entries in cluster array i
1218 AliClusterContainer *cont = GetClusterContainer(i);
1220 AliError(Form("%s: Cluster container %d not found",GetName(),i));
1223 return cont->GetNEntries();
1226 //________________________________________________________________________
1227 AliEmcalTriggerPatchInfo* AliAnalysisTaskEmcal::GetMainTriggerPatch()
1229 //get main trigger match; if not known yet, look for it and cache
1231 if (fMainTriggerPatch)
1232 return fMainTriggerPatch;
1234 if (!fTriggerPatchInfo) {
1235 AliError(Form("%s: fTriggerPatchInfo not available",GetName()));
1239 //number of patches in event
1240 Int_t nPatch = fTriggerPatchInfo->GetEntries();
1242 //extract main trigger patch
1243 AliEmcalTriggerPatchInfo *patch;
1244 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
1246 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
1247 if (patch->IsMainTrigger()) {
1248 fMainTriggerPatch = patch;
1253 return fMainTriggerPatch;
1256 //________________________________________________________________________
1257 void AliAnalysisTaskEmcal::AddObjectToEvent(TObject *obj)
1259 // Add object to event
1261 if (!(InputEvent()->FindListObject(obj->GetName()))) {
1262 InputEvent()->AddObject(obj);
1264 AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), obj->GetName()));
1268 //________________________________________________________________________
1269 void AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max, Double_t* array) const
1271 Double_t binWidth = (max-min)/n;
1273 for (Int_t i = 1; i <= n; i++) {
1274 array[i] = array[i-1]+binWidth;
1278 //________________________________________________________________________
1279 Double_t* AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max) const
1281 Double_t *array = new Double_t[n+1];
1283 GenerateFixedBinArray(n, min, max, array);
1288 //________________________________________________________________________
1289 void AliAnalysisTaskEmcal::SetRejectionReasonLabels(TAxis* axis)
1291 axis->SetBinLabel(1, "NullObject");
1292 axis->SetBinLabel(2, "Pt");
1293 axis->SetBinLabel(3, "Acceptance");
1294 axis->SetBinLabel(4, "BitMap");
1295 axis->SetBinLabel(5, "Bit4");
1296 axis->SetBinLabel(6, "Bit5");
1297 axis->SetBinLabel(7, "Bit6");
1298 axis->SetBinLabel(8, "Bit7");
1299 axis->SetBinLabel(9, "MCFlag");
1300 axis->SetBinLabel(10, "MCGenerator");
1301 axis->SetBinLabel(11, "ChargeCut");
1302 axis->SetBinLabel(12, "Bit11");
1303 axis->SetBinLabel(13, "Bit12");
1304 axis->SetBinLabel(14, "IsEMCal");
1305 axis->SetBinLabel(15, "Time");
1306 axis->SetBinLabel(16, "Energy");
1307 axis->SetBinLabel(17, "Bit16");
1308 axis->SetBinLabel(18, "Bit17");
1309 axis->SetBinLabel(19, "Area");
1310 axis->SetBinLabel(20, "AreaEmc");
1311 axis->SetBinLabel(21, "ZLeadingCh");
1312 axis->SetBinLabel(22, "ZLeadingEmc");
1313 axis->SetBinLabel(23, "NEF");
1314 axis->SetBinLabel(24, "MinLeadPt");
1315 axis->SetBinLabel(25, "MaxTrackPt");
1316 axis->SetBinLabel(26, "MaxClusterPt");
1317 axis->SetBinLabel(27, "Flavour");
1318 axis->SetBinLabel(28, "TagStatus");
1319 axis->SetBinLabel(29, "Bit28");
1320 axis->SetBinLabel(30, "Bit29");
1321 axis->SetBinLabel(31, "Bit30");
1322 axis->SetBinLabel(32, "Bit31");