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 fAliAnalysisUtils(0x0),
62 fOffTrigger(AliVEvent::kAny),
68 fMinPtTrackInEmcal(0),
69 fEventPlaneVsEmcal(-1),
75 fSelectPtHardBin(-999),
79 fNeedEmcalGeom(kTRUE),
101 fMainTriggerPatch(0x0),
105 fHistTrialsAfterSel(0),
106 fHistEventsAfterSel(0),
107 fHistXsectionAfterSel(0),
115 fHistEventRejection(0)
117 // Default constructor.
123 fParticleCollArray.SetOwner(kTRUE);
124 fClusterCollArray.SetOwner(kTRUE);
127 //________________________________________________________________________
128 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
129 AliAnalysisTaskSE(name),
131 fGeneralHistograms(kFALSE),
132 fInitialized(kFALSE),
136 fCaloTriggerPatchInfoName(),
143 fUseAliAnaUtils(kFALSE),
144 fRejectPileup(kFALSE),
145 fAliAnalysisUtils(0x0),
146 fOffTrigger(AliVEvent::kAny),
148 fTriggerTypeSel(kND),
152 fMinPtTrackInEmcal(0),
153 fEventPlaneVsEmcal(-1),
154 fMinEventPlane(-1e6),
159 fSelectPtHardBin(-999),
163 fNeedEmcalGeom(kTRUE),
170 fTriggerPatchInfo(0),
183 fParticleCollArray(),
185 fMainTriggerPatch(0x0),
189 fHistTrialsAfterSel(0),
190 fHistEventsAfterSel(0),
191 fHistXsectionAfterSel(0),
199 fHistEventRejection(0)
201 // Standard constructor.
207 fParticleCollArray.SetOwner(kTRUE);
208 fClusterCollArray.SetOwner(kTRUE);
211 DefineOutput(1, TList::Class());
215 //________________________________________________________________________
216 AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
221 //________________________________________________________________________
222 void AliAnalysisTaskEmcal::SetClusPtCut(Double_t cut, Int_t c)
224 AliClusterContainer *cont = GetClusterContainer(c);
225 if (cont) cont->SetClusPtCut(cut);
226 else AliError(Form("%s in SetClusPtCut(...): container %d not found",GetName(),c));
229 //________________________________________________________________________
230 void AliAnalysisTaskEmcal::SetClusTimeCut(Double_t min, Double_t max, Int_t c)
232 AliClusterContainer *cont = GetClusterContainer(c);
233 if (cont) cont->SetClusTimeCut(min,max);
234 else AliError(Form("%s in SetClusTimeCut(...): container %d not found",GetName(),c));
237 //________________________________________________________________________
238 void AliAnalysisTaskEmcal::SetTrackPtCut(Double_t cut, Int_t c)
240 AliParticleContainer *cont = GetParticleContainer(c);
241 if (cont) cont->SetParticlePtCut(cut);
242 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
247 //________________________________________________________________________
248 void AliAnalysisTaskEmcal::SetTrackEtaLimits(Double_t min, Double_t max, Int_t c)
250 AliParticleContainer *cont = GetParticleContainer(c);
251 if (cont) cont->SetParticleEtaLimits(min,max);
252 else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
255 //________________________________________________________________________
256 void AliAnalysisTaskEmcal::SetTrackPhiLimits(Double_t min, Double_t max, Int_t c)
258 AliParticleContainer *cont = GetParticleContainer(c);
259 if (cont) cont->SetParticlePhiLimits(min,max);
260 else AliError(Form("%s in SetTrackPhiLimits(...): container %d not found",GetName(),c));
263 //________________________________________________________________________
264 void AliAnalysisTaskEmcal::UserCreateOutputObjects()
266 // Create user output.
268 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
270 AliVEventHandler *evhand = mgr->GetInputEventHandler();
272 if (evhand->InheritsFrom("AliESDInputHandler")) {
280 AliError("Event handler not found!");
284 AliError("Analysis manager not found!");
291 fOutput = new TList();
294 if (fForceBeamType == kpp)
297 if (!fGeneralHistograms)
301 fHistTrialsAfterSel = new TH1F("fHistTrialsAfterSel", "fHistTrialsAfterSel", 11, 0, 11);
302 fHistTrialsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
303 fHistTrialsAfterSel->GetYaxis()->SetTitle("trials");
304 fOutput->Add(fHistTrialsAfterSel);
306 fHistEventsAfterSel = new TH1F("fHistEventsAfterSel", "fHistEventsAfterSel", 11, 0, 11);
307 fHistEventsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
308 fHistEventsAfterSel->GetYaxis()->SetTitle("total events");
309 fOutput->Add(fHistEventsAfterSel);
311 fHistXsectionAfterSel = new TProfile("fHistXsectionAfterSel", "fHistXsectionAfterSel", 11, 0, 11);
312 fHistXsectionAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
313 fHistXsectionAfterSel->GetYaxis()->SetTitle("xsection");
314 fOutput->Add(fHistXsectionAfterSel);
316 fHistTrials = new TH1F("fHistTrials", "fHistTrials", 11, 0, 11);
317 fHistTrials->GetXaxis()->SetTitle("p_{T} hard bin");
318 fHistTrials->GetYaxis()->SetTitle("trials");
319 fOutput->Add(fHistTrials);
321 fHistEvents = new TH1F("fHistEvents", "fHistEvents", 11, 0, 11);
322 fHistEvents->GetXaxis()->SetTitle("p_{T} hard bin");
323 fHistEvents->GetYaxis()->SetTitle("total events");
324 fOutput->Add(fHistEvents);
326 fHistXsection = new TProfile("fHistXsection", "fHistXsection", 11, 0, 11);
327 fHistXsection->GetXaxis()->SetTitle("p_{T} hard bin");
328 fHistXsection->GetYaxis()->SetTitle("xsection");
329 fOutput->Add(fHistXsection);
331 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
332 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
334 for (Int_t i = 1; i < 12; i++) {
335 fHistTrialsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
336 fHistEventsAfterSel->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
338 fHistTrials->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
339 fHistXsection->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
340 fHistEvents->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
343 fHistPtHard = new TH1F("fHistPtHard", "fHistPtHard", fNbins*2, fMinBinPt, fMaxBinPt*4);
344 fHistPtHard->GetXaxis()->SetTitle("p_{T,hard} (GeV/c)");
345 fHistPtHard->GetYaxis()->SetTitle("counts");
346 fOutput->Add(fHistPtHard);
349 fHistCentrality = new TH1F("fHistCentrality","Event centrality distribution", 200, 0, 100);
350 fHistCentrality->GetXaxis()->SetTitle("Centrality (%)");
351 fHistCentrality->GetYaxis()->SetTitle("counts");
352 fOutput->Add(fHistCentrality);
354 fHistZVertex = new TH1F("fHistZVertex","Z vertex position", 60, -30, 30);
355 fHistZVertex->GetXaxis()->SetTitle("z");
356 fHistZVertex->GetYaxis()->SetTitle("counts");
357 fOutput->Add(fHistZVertex);
359 fHistEventPlane = new TH1F("fHistEventPlane","Event plane", 120, -TMath::Pi(), TMath::Pi());
360 fHistEventPlane->GetXaxis()->SetTitle("event plane");
361 fHistEventPlane->GetYaxis()->SetTitle("counts");
362 fOutput->Add(fHistEventPlane);
364 fHistEventRejection = new TH1F("fHistEventRejection","Reasons to reject event",20,0,20);
365 fHistEventRejection->GetXaxis()->SetBinLabel(1,"PhysSel");
366 fHistEventRejection->GetXaxis()->SetBinLabel(2,"trigger");
367 fHistEventRejection->GetXaxis()->SetBinLabel(3,"trigTypeSel");
368 fHistEventRejection->GetXaxis()->SetBinLabel(4,"Cent");
369 fHistEventRejection->GetXaxis()->SetBinLabel(5,"vertex contr.");
370 fHistEventRejection->GetXaxis()->SetBinLabel(6,"Vz");
371 fHistEventRejection->GetXaxis()->SetBinLabel(7,"trackInEmcal");
372 fHistEventRejection->GetXaxis()->SetBinLabel(8,"minNTrack");
373 fHistEventRejection->GetXaxis()->SetBinLabel(9,"VtxSel2013pA");
374 fHistEventRejection->GetXaxis()->SetBinLabel(10,"PileUp");
375 fHistEventRejection->GetXaxis()->SetBinLabel(11,"EvtPlane");
376 fHistEventRejection->GetXaxis()->SetBinLabel(12,"SelPtHardBin");
377 fHistEventRejection->GetYaxis()->SetTitle("counts");
378 fOutput->Add(fHistEventRejection);
380 fHistEventCount = new TH1F("fHistEventCount","fHistEventCount",2,0,2);
381 fHistEventCount->GetXaxis()->SetBinLabel(1,"Accepted");
382 fHistEventCount->GetXaxis()->SetBinLabel(2,"Rejected");
383 fHistEventCount->GetYaxis()->SetTitle("counts");
384 fOutput->Add(fHistEventCount);
386 PostData(1, fOutput);
389 //________________________________________________________________________
390 Bool_t AliAnalysisTaskEmcal::FillGeneralHistograms()
393 fHistEventsAfterSel->Fill(fPtHardBin, 1);
394 fHistTrialsAfterSel->Fill(fPtHardBin, fNTrials);
395 fHistXsectionAfterSel->Fill(fPtHardBin, fXsection);
396 fHistPtHard->Fill(fPtHard);
399 fHistCentrality->Fill(fCent);
400 fHistZVertex->Fill(fVertex[2]);
401 fHistEventPlane->Fill(fEPV0);
406 //________________________________________________________________________
407 void AliAnalysisTaskEmcal::UserExec(Option_t *)
409 // Main loop, called for each event.
411 fMainTriggerPatch = NULL;
419 if (!RetrieveEventObjects())
422 if (IsEventSelected()) {
423 if (fGeneralHistograms) fHistEventCount->Fill("Accepted",1);
426 if (fGeneralHistograms) fHistEventCount->Fill("Rejected",1);
430 if (fGeneralHistograms && fCreateHisto) {
431 if (!FillGeneralHistograms())
439 if (!FillHistograms())
443 if (fCreateHisto && fOutput) {
444 // information for this iteration of the UserExec in the container
445 PostData(1, fOutput);
449 //________________________________________________________________________
450 Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Int_t c) const
452 // Return true if cluster is accepted.
457 AliClusterContainer *cont = GetClusterContainer(c);
459 AliError(Form("%s:Container %d not found",GetName(),c));
463 return cont->AcceptCluster(clus);
466 //________________________________________________________________________
467 Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVParticle *track, Int_t c) const
469 // Return true if track is accepted.
474 AliParticleContainer *cont = GetParticleContainer(c);
476 AliError(Form("%s:Container %d not found",GetName(),c));
480 return cont->AcceptParticle(track);
483 //________________________________________________________________________
484 Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &fXsec, Float_t &fTrials, Int_t &pthard)
487 // Get the cross section and the trails either from pyxsec.root or from pysec_hists.root
488 // Get the pt hard bin from the file path
489 // This is to called in Notify and should provide the path to the AOD/ESD file
490 // (Partially copied from AliAnalysisHelperJetTasks)
492 TString file(currFile);
496 if (file.Contains(".zip#")) {
497 Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
498 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
499 Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
500 file.Replace(pos+1,pos2-pos1,"");
502 // not an archive take the basename....
503 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
505 AliDebug(1,Form("File name: %s",file.Data()));
507 // Get the pt hard bin
508 TString strPthard(file);
510 strPthard.Remove(strPthard.Last('/'));
511 strPthard.Remove(strPthard.Last('/'));
512 if (strPthard.Contains("AOD")) strPthard.Remove(strPthard.Last('/'));
513 strPthard.Remove(0,strPthard.Last('/')+1);
514 if (strPthard.IsDec())
515 pthard = strPthard.Atoi();
517 AliWarning(Form("Could not extract file number from path %s", strPthard.Data()));
519 // 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
520 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root"));
523 // next trial fetch the histgram file
524 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
526 // not a severe condition but inciate that we have no information
529 // find the tlist we want to be independtent of the name so use the Tkey
530 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
535 TList *list = dynamic_cast<TList*>(key->ReadObj());
540 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
541 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
544 } else { // no tree pyxsec.root
545 TTree *xtree = (TTree*)fxsec->Get("Xsection");
551 Double_t xsection = 0;
552 xtree->SetBranchAddress("xsection",&xsection);
553 xtree->SetBranchAddress("ntrials",&ntrials);
562 //________________________________________________________________________
563 Bool_t AliAnalysisTaskEmcal::UserNotify()
565 // Called when file changes.
567 if (!fIsPythia || !fGeneralHistograms || !fCreateHisto)
570 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
572 AliError(Form("%s - UserNotify: No current tree!",GetName()));
576 Float_t xsection = 0;
580 TFile *curfile = tree->GetCurrentFile();
582 AliError(Form("%s - UserNotify: No current file!",GetName()));
586 TChain *chain = dynamic_cast<TChain*>(tree);
587 if (chain) tree = chain->GetTree();
589 Int_t nevents = tree->GetEntriesFast();
591 PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthardbin);
594 if ((pthardbin < 0) || (pthardbin > 10)) pthardbin = 0;
596 fHistTrials->Fill(pthardbin, trials);
597 fHistXsection->Fill(pthardbin, xsection);
598 fHistEvents->Fill(pthardbin, nevents);
603 //________________________________________________________________________
604 void AliAnalysisTaskEmcal::ExecOnce()
606 // Init the analysis.
609 AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
613 if (fNeedEmcalGeom) {
614 fGeom = AliEMCALGeometry::GetInstance();
616 AliError(Form("%s: Can not create geometry", GetName()));
622 if (fEventPlaneVsEmcal >= 0) {
624 Double_t ep = (fGeom->GetArm1PhiMax() + fGeom->GetArm1PhiMin()) / 2 * TMath::DegToRad() + fEventPlaneVsEmcal - TMath::Pi();
625 fMinEventPlane = ep - TMath::Pi() / 4;
626 fMaxEventPlane = ep + TMath::Pi() / 4;
629 AliWarning("Could not set event plane limits because EMCal geometry was not loaded!");
633 //Load all requested track branches - each container knows name already
634 for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
635 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
636 cont->SetArray(InputEvent());
639 if (fParticleCollArray.GetEntriesFast()>0) {
640 fTracks = GetParticleArray(0);
642 AliError(Form("%s: Could not retrieve first track branch!", GetName()));
647 //Load all requested cluster branches - each container knows name already
648 for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
649 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
650 cont->SetArray(InputEvent());
653 if (fClusterCollArray.GetEntriesFast()>0) {
654 fCaloClusters = GetClusterArray(0);
655 if (!fCaloClusters) {
656 AliError(Form("%s: Could not retrieve first cluster branch!", GetName()));
661 if (!fCaloCellsName.IsNull() && !fCaloCells) {
662 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
664 AliError(Form("%s: Could not retrieve cells %s!", GetName(), fCaloCellsName.Data()));
669 if (!fCaloTriggersName.IsNull() && !fCaloTriggers) {
670 fCaloTriggers = dynamic_cast<AliVCaloTrigger*>(InputEvent()->FindListObject(fCaloTriggersName));
671 if (!fCaloTriggers) {
672 AliError(Form("%s: Could not retrieve calo triggers %s!", GetName(), fCaloTriggersName.Data()));
677 if (!fCaloTriggerPatchInfoName.IsNull() && !fTriggerPatchInfo) {
678 fTriggerPatchInfo = GetArrayFromEvent(fCaloTriggerPatchInfoName.Data(),"AliEmcalTriggerPatchInfo");
679 if (!fTriggerPatchInfo) {
680 AliError(Form("%s: Could not retrieve calo trigger patch info %s!", GetName(), fCaloTriggerPatchInfoName.Data()));
686 fInitialized = kTRUE;
689 //_____________________________________________________
690 AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
692 // Get beam type : pp-AA-pA
693 // ESDs have it directly, AODs get it from hardcoded run number ranges
695 if (fForceBeamType != kNA)
696 return fForceBeamType;
698 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
700 const AliESDRun *run = esd->GetESDRun();
701 TString beamType = run->GetBeamType();
702 if (beamType == "p-p")
704 else if (beamType == "A-A")
706 else if (beamType == "p-A")
711 Int_t runNumber = InputEvent()->GetRunNumber();
712 if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
713 (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
715 } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
716 (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
724 //________________________________________________________________________
725 ULong_t AliAnalysisTaskEmcal::GetTriggerList()
727 if (!fTriggerPatchInfo)
730 //number of patches in event
731 Int_t nPatch = fTriggerPatchInfo->GetEntries();
733 //loop over patches to define trigger type of event
738 AliEmcalTriggerPatchInfo *patch;
739 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
740 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
741 if (patch->IsGammaHigh()) nG1++;
742 if (patch->IsGammaLow()) nG2++;
743 if (patch->IsJetHigh()) nJ1++;
744 if (patch->IsJetLow()) nJ2++;
747 AliDebug(2, "Patch summary: ");
748 AliDebug(2, Form("Number of patches: %d", nPatch));
749 AliDebug(2, Form("Jet: low[%d], high[%d]" ,nJ2, nJ1));
750 AliDebug(2, Form("Gamma: low[%d], high[%d]" ,nG2, nG1));
754 SETBIT(triggers, kG1);
756 SETBIT(triggers, kG2);
758 SETBIT(triggers, kJ1);
760 SETBIT(triggers, kJ2);
764 //________________________________________________________________________
765 Bool_t AliAnalysisTaskEmcal::HasTriggerType(TriggerType t)
767 // Check if event has a given trigger type
769 return fTriggers == 0;
771 return TESTBIT(fTriggers, int(t));
774 //________________________________________________________________________
775 Bool_t AliAnalysisTaskEmcal::IsEventSelected()
777 // Check if event is selected
779 if (fOffTrigger != AliVEvent::kAny) {
781 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
783 res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
785 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
787 res = ((AliVAODHeader*)aev->GetHeader())->GetOfflineTrigger();
790 if ((res & fOffTrigger) == 0) {
791 if (fGeneralHistograms) fHistEventRejection->Fill("PhysSel",1);
796 if (!fTrigClass.IsNull()) {
798 const AliESDEvent *eev = dynamic_cast<const AliESDEvent*>(InputEvent());
800 fired = eev->GetFiredTriggerClasses();
802 const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
804 fired = aev->GetFiredTriggerClasses();
807 if (!fired.Contains("-B-")) {
808 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
811 TObjArray *arr = fTrigClass.Tokenize("|");
813 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
817 for (Int_t i=0;i<arr->GetEntriesFast();++i) {
818 TObject *obj = arr->At(i);
821 if (fired.Contains(obj->GetName())) {
828 if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
833 if (fTriggerTypeSel != kND) {
834 if (!HasTriggerType(fTriggerTypeSel)) {
835 if (fGeneralHistograms) fHistEventRejection->Fill("trigTypeSel",1);
840 if ((fMinCent != -999) && (fMaxCent != -999)) {
841 if (fCent<fMinCent || fCent>fMaxCent) {
842 if (fGeneralHistograms) fHistEventRejection->Fill("Cent",1);
847 if (fUseAliAnaUtils) {
848 if (!fAliAnalysisUtils)
849 fAliAnalysisUtils = new AliAnalysisUtils();
850 fAliAnalysisUtils->SetMinVtxContr(2);
851 fAliAnalysisUtils->SetMaxVtxZ(999);
852 if(fMinVz<-10.) fMinVz = -10.;
853 if(fMinVz>10.) fMaxVz = 10.;
855 if (!fAliAnalysisUtils->IsVertexSelected2013pA(InputEvent())) {
856 if (fGeneralHistograms) fHistEventRejection->Fill("VtxSel2013pA",1);
860 if (fRejectPileup &&fAliAnalysisUtils->IsPileUpEvent(InputEvent())) {
861 if (fGeneralHistograms) fHistEventRejection->Fill("PileUp",1);
866 if ((fMinVz != -999) && (fMaxVz != -999)) {
867 if (fNVertCont == 0 ) {
868 if (fGeneralHistograms) fHistEventRejection->Fill("vertex contr.",1);
871 Double_t vz = fVertex[2];
872 if (vz<fMinVz || vz>fMaxVz) {
873 if (fGeneralHistograms) fHistEventRejection->Fill("Vz",1);
878 if (fMinPtTrackInEmcal > 0 && fGeom) {
879 Bool_t trackInEmcalOk = kFALSE;
880 Int_t ntracks = GetNParticles(0);
881 for (Int_t i = 0; i < ntracks; i++) {
882 AliVParticle *track = GetAcceptParticleFromArray(i,0);
886 Double_t phiMin = fGeom->GetArm1PhiMin() * TMath::DegToRad();
887 Double_t phiMax = fGeom->GetArm1PhiMax() * TMath::DegToRad();
888 Int_t runNumber = InputEvent()->GetRunNumber();
889 if (runNumber>=177295 && runNumber<=197470) { //small SM masked in 2012 and 2013
891 phiMax = TMath::Pi();
894 if (track->Eta() < fGeom->GetArm1EtaMin() || track->Eta() > fGeom->GetArm1EtaMax() || track->Phi() < phiMin || track->Phi() > phiMax)
896 if (track->Pt() > fMinPtTrackInEmcal) {
897 trackInEmcalOk = kTRUE;
901 if (!trackInEmcalOk) {
902 if (fGeneralHistograms) fHistEventRejection->Fill("trackInEmcal",1);
907 if (fMinNTrack > 0) {
908 Int_t nTracksAcc = 0;
909 Int_t ntracks = GetNParticles(0);
910 for (Int_t i = 0; i < ntracks; i++) {
911 AliVParticle *track = GetAcceptParticleFromArray(i,0);
914 if (track->Pt() > fTrackPtCut) {
916 if (nTracksAcc>=fMinNTrack)
920 if (nTracksAcc<fMinNTrack) {
921 if (fGeneralHistograms) fHistEventRejection->Fill("minNTrack",1);
926 if (!(fEPV0 > fMinEventPlane && fEPV0 <= fMaxEventPlane) &&
927 !(fEPV0 + TMath::Pi() > fMinEventPlane && fEPV0 + TMath::Pi() <= fMaxEventPlane) &&
928 !(fEPV0 - TMath::Pi() > fMinEventPlane && fEPV0 - TMath::Pi() <= fMaxEventPlane))
930 if (fGeneralHistograms) fHistEventRejection->Fill("EvtPlane",1);
934 if (fSelectPtHardBin != -999 && fSelectPtHardBin != fPtHardBin) {
935 if (fGeneralHistograms) fHistEventRejection->Fill("SelPtHardBin",1);
942 //________________________________________________________________________
943 TClonesArray *AliAnalysisTaskEmcal::GetArrayFromEvent(const char *name, const char *clname)
945 // Get array from event.
947 TClonesArray *arr = 0;
949 if (!sname.IsNull()) {
950 arr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(sname));
952 AliWarning(Form("%s: Could not retrieve array with name %s!", GetName(), name));
962 TString objname(arr->GetClass()->GetName());
964 if (!cls.InheritsFrom(clname)) {
965 AliWarning(Form("%s: Objects of type %s in %s are not inherited from %s!",
966 GetName(), cls.GetName(), name, clname));
972 //________________________________________________________________________
973 Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
975 // Retrieve objects from event.
982 const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
984 vert->GetXYZ(fVertex);
985 fNVertCont = vert->GetNContributors();
988 fBeamType = GetBeamType();
990 if (fBeamType == kAA || fBeamType == kpA ) {
991 AliCentrality *aliCent = InputEvent()->GetCentrality();
993 fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
995 if (fCent >= 0 && fCent < 10) fCentBin = 0;
996 else if (fCent >= 10 && fCent < 30) fCentBin = 1;
997 else if (fCent >= 30 && fCent < 50) fCentBin = 2;
998 else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
1000 AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
1001 fCentBin = fNcentBins-1;
1004 Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1006 fCentBin = TMath::FloorNint(fCent/centWidth);
1009 if (fCentBin>=fNcentBins) {
1010 AliWarning(Form("%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),fCent,fCentBin));
1011 fCentBin = fNcentBins-1;
1015 AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
1016 fCentBin = fNcentBins-1;
1018 AliEventplane *aliEP = InputEvent()->GetEventplane();
1020 fEPV0 = aliEP->GetEventplane("V0" ,InputEvent());
1021 fEPV0A = aliEP->GetEventplane("V0A",InputEvent());
1022 fEPV0C = aliEP->GetEventplane("V0C",InputEvent());
1024 AliWarning(Form("%s: Could not retrieve event plane information!", GetName()));
1034 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent()->GenEventHeader());
1035 if (!fPythiaHeader) {
1037 AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
1040 for (UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
1041 fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
1042 if (fPythiaHeader) break;
1048 if (fPythiaHeader) {
1049 fPtHard = fPythiaHeader->GetPtHard();
1051 const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
1052 const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
1053 for (fPtHardBin = 0; fPtHardBin < 11; fPtHardBin++) {
1054 if (fPtHard >= ptHardLo[fPtHardBin] && fPtHard < ptHardHi[fPtHardBin])
1058 fXsection = fPythiaHeader->GetXsection();
1059 fNTrials = fPythiaHeader->Trials();
1063 fTriggers = GetTriggerList();
1068 //________________________________________________________________________
1069 AliParticleContainer* AliAnalysisTaskEmcal::AddParticleContainer(const char *n)
1071 // Add particle container
1072 // will be called in AddTask macro
1074 TString tmp = TString(n);
1075 if (tmp.IsNull()) return 0;
1077 AliParticleContainer *cont = 0x0;
1078 cont = new AliParticleContainer();
1079 cont->SetArrayName(n);
1080 TString contName = cont->GetArrayName();
1082 fParticleCollArray.Add(cont);
1087 //________________________________________________________________________
1088 AliClusterContainer* AliAnalysisTaskEmcal::AddClusterContainer(const char *n)
1090 // Add cluster container
1091 // will be called in AddTask macro
1093 TString tmp = TString(n);
1094 if (tmp.IsNull()) return 0;
1096 AliClusterContainer *cont = 0x0;
1097 cont = new AliClusterContainer();
1098 cont->SetArrayName(n);
1100 fClusterCollArray.Add(cont);
1105 //________________________________________________________________________
1106 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(Int_t i) const
1108 // Get i^th particle container
1110 if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1111 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1115 //________________________________________________________________________
1116 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(Int_t i) const
1118 // Get i^th cluster container
1120 if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1121 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1125 //________________________________________________________________________
1126 AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(const char *name) const
1128 // Get particle container with name
1130 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1134 //________________________________________________________________________
1135 AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(const char *name) const
1137 // Get cluster container with name
1139 AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1143 //________________________________________________________________________
1144 TClonesArray* AliAnalysisTaskEmcal::GetParticleArray(Int_t i) const
1146 // Get i^th TClonesArray with AliVParticle
1148 AliParticleContainer *cont = GetParticleContainer(i);
1150 AliError(Form("%s: Particle container %d not found",GetName(),i));
1153 TString contName = cont->GetArrayName();
1154 return cont->GetArray();
1157 //________________________________________________________________________
1158 TClonesArray* AliAnalysisTaskEmcal::GetClusterArray(Int_t i) const
1160 // Get i^th TClonesArray with AliVCluster
1162 AliClusterContainer *cont = GetClusterContainer(i);
1164 AliError(Form("%s:Cluster container %d not found",GetName(),i));
1167 return cont->GetArray();
1170 //________________________________________________________________________
1171 AliVParticle* AliAnalysisTaskEmcal::GetAcceptParticleFromArray(Int_t p, Int_t c) const
1173 // Get particle p if accepted from container c
1174 // If particle not accepted return 0
1176 AliParticleContainer *cont = GetParticleContainer(c);
1178 AliError(Form("%s: Particle container %d not found",GetName(),c));
1181 AliVParticle *vp = cont->GetAcceptParticle(p);
1186 //________________________________________________________________________
1187 AliVCluster* AliAnalysisTaskEmcal::GetAcceptClusterFromArray(Int_t cl, Int_t c) const
1189 // Get particle p if accepted from container c
1190 // If particle not accepted return 0
1192 AliClusterContainer *cont = GetClusterContainer(c);
1194 AliError(Form("%s: Cluster container %d not found",GetName(),c));
1197 AliVCluster *vc = cont->GetAcceptCluster(cl);
1202 //________________________________________________________________________
1203 Int_t AliAnalysisTaskEmcal::GetNParticles(Int_t i) const
1205 // Get number of entries in particle array i
1207 AliParticleContainer *cont = GetParticleContainer(i);
1209 AliError(Form("%s: Particle container %d not found",GetName(),i));
1212 return cont->GetNEntries();
1215 //________________________________________________________________________
1216 Int_t AliAnalysisTaskEmcal::GetNClusters(Int_t i) const
1218 // Get number of entries in cluster array i
1220 AliClusterContainer *cont = GetClusterContainer(i);
1222 AliError(Form("%s: Cluster container %d not found",GetName(),i));
1225 return cont->GetNEntries();
1228 //________________________________________________________________________
1229 AliEmcalTriggerPatchInfo* AliAnalysisTaskEmcal::GetMainTriggerPatch()
1231 //get main trigger match; if not known yet, look for it and cache
1233 if (fMainTriggerPatch)
1234 return fMainTriggerPatch;
1236 if (!fTriggerPatchInfo) {
1237 AliError(Form("%s: fTriggerPatchInfo not available",GetName()));
1241 //number of patches in event
1242 Int_t nPatch = fTriggerPatchInfo->GetEntries();
1244 //extract main trigger patch
1245 AliEmcalTriggerPatchInfo *patch;
1246 for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
1248 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
1249 if (patch->IsMainTrigger()) {
1250 fMainTriggerPatch = patch;
1255 return fMainTriggerPatch;
1258 //________________________________________________________________________
1259 void AliAnalysisTaskEmcal::AddObjectToEvent(TObject *obj)
1261 // Add object to event
1263 if (!(InputEvent()->FindListObject(obj->GetName()))) {
1264 InputEvent()->AddObject(obj);
1266 AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), obj->GetName()));
1270 //________________________________________________________________________
1271 void AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max, Double_t* array) const
1273 Double_t binWidth = (max-min)/n;
1275 for (Int_t i = 1; i <= n; i++) {
1276 array[i] = array[i-1]+binWidth;
1280 //________________________________________________________________________
1281 Double_t* AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max) const
1283 Double_t *array = new Double_t[n+1];
1285 GenerateFixedBinArray(n, min, max, array);
1290 //________________________________________________________________________
1291 void AliAnalysisTaskEmcal::SetRejectionReasonLabels(TAxis* axis)
1293 axis->SetBinLabel(1, "NullObject");
1294 axis->SetBinLabel(2, "Pt");
1295 axis->SetBinLabel(3, "Acceptance");
1296 axis->SetBinLabel(4, "BitMap");
1297 axis->SetBinLabel(5, "Bit4");
1298 axis->SetBinLabel(6, "Bit5");
1299 axis->SetBinLabel(7, "Bit6");
1300 axis->SetBinLabel(8, "Bit7");
1301 axis->SetBinLabel(9, "MCFlag");
1302 axis->SetBinLabel(10, "MCGenerator");
1303 axis->SetBinLabel(11, "ChargeCut");
1304 axis->SetBinLabel(12, "Bit11");
1305 axis->SetBinLabel(13, "Bit12");
1306 axis->SetBinLabel(14, "IsEMCal");
1307 axis->SetBinLabel(15, "Time");
1308 axis->SetBinLabel(16, "Energy");
1309 axis->SetBinLabel(17, "Bit16");
1310 axis->SetBinLabel(18, "Bit17");
1311 axis->SetBinLabel(19, "Area");
1312 axis->SetBinLabel(20, "AreaEmc");
1313 axis->SetBinLabel(21, "ZLeadingCh");
1314 axis->SetBinLabel(22, "ZLeadingEmc");
1315 axis->SetBinLabel(23, "NEF");
1316 axis->SetBinLabel(24, "MinLeadPt");
1317 axis->SetBinLabel(25, "MaxTrackPt");
1318 axis->SetBinLabel(26, "MaxClusterPt");
1319 axis->SetBinLabel(27, "Flavour");
1320 axis->SetBinLabel(28, "TagStatus");
1321 axis->SetBinLabel(29, "Bit28");
1322 axis->SetBinLabel(30, "Bit29");
1323 axis->SetBinLabel(31, "Bit30");
1324 axis->SetBinLabel(32, "Bit31");