Event Mixing for Triggered BF analysis
[u/mrichter/AliRoot.git] / PWGCF / EBYE / macros / AddTaskBalanceTriggered.C
1 // now in options\r
2 \r
3 //PID config\r
4 Bool_t kUseNSigmaPID = kFALSE;\r
5 Double_t nSigmaMax = 3.0;\r
6 Bool_t kUseBayesianPID = kTRUE;\r
7 Double_t gMinAcceptedProbability = 0.7;\r
8 \r
9 //_________________________________________________________//\r
10 AliAnalysisTaskTriggeredBF *AddTaskBalanceTriggered(Double_t centrMin=0.,\r
11                                                  Double_t centrMax=80.,\r
12                                                  Bool_t gRunShuffling=kFALSE,\r
13                                                  Bool_t gRunMixing=kFALSE,\r
14                                                  TString centralityEstimator="V0M",\r
15                                                  Double_t vertexZ=10.,\r
16                                                  Double_t DCAxy=-1,\r
17                                                  Double_t DCAz=-1,\r
18                                                  Double_t ptMin=0.15,\r
19                                                  Double_t ptMax=20,\r
20                                                  Double_t etaMin=-0.8,\r
21                                                  Double_t etaMax=0.8,\r
22                                                  Double_t maxTPCchi2 = -1, \r
23                                                  Int_t minNClustersTPC = -1,\r
24                                                  Bool_t kUsePID = kFALSE,\r
25                                                  Int_t AODfilterBit = 128,\r
26                                                  Bool_t bCentralTrigger = kFALSE,\r
27                                                  TString fileNameBase="AnalysisResults") {\r
28 \r
29   // Creates a balance function analysis task and adds it to the analysis manager.\r
30   // Get the pointer to the existing analysis manager via the static access method.\r
31   TString centralityName("");\r
32   centralityName+=Form("%.0f",centrMin);\r
33   centralityName+="-";\r
34   centralityName+=Form("%.0f",centrMax);\r
35   centralityName+="_";\r
36   centralityName+=Form("%s",centralityEstimator.Data());\r
37   centralityName+="_";\r
38   centralityName+=Form("vZ%.1f",vertexZ);\r
39   centralityName+="_";\r
40   centralityName+=Form("DCAxy%.1f",DCAxy);\r
41   centralityName+="_";\r
42   centralityName+=Form("DCAz%.1f",DCAz);\r
43   centralityName+="_Pt";\r
44   centralityName+=Form("%.1f",ptMin);\r
45   centralityName+="-";\r
46   centralityName+=Form("%.1f",ptMax);\r
47   centralityName+="_Eta";\r
48   centralityName+=Form("%.1f",etaMin);\r
49   centralityName+="-";\r
50   centralityName+=Form("%.1f",etaMax);\r
51   centralityName+="_Chi";\r
52   centralityName+=Form("%.1f",maxTPCchi2);\r
53   centralityName+="_nClus";\r
54   centralityName+=Form("%d",minNClustersTPC);\r
55   centralityName+="_Bit";\r
56   centralityName+=Form("%d",AODfilterBit);\r
57   if(bCentralTrigger)   centralityName+="_withCentralTrigger";\r
58 \r
59 \r
60 \r
61   TString outputFileName(fileNameBase);\r
62   outputFileName.Append(".root");\r
63 \r
64   //===========================================================================\r
65   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();\r
66   if (!mgr) {\r
67     ::Error("AddTaskTriggeredBF", "No analysis manager to connect to.");\r
68     return NULL;\r
69   }\r
70 \r
71   // Check the analysis type using the event handlers connected to the analysis manager.\r
72   //===========================================================================\r
73   if (!mgr->GetInputEventHandler()) {\r
74     ::Error("AddTaskTriggeredBF", "This task requires an input event handler");\r
75     return NULL;\r
76   }\r
77   TString analysisType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"\r
78   if(dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler())) analysisType = "MC";\r
79 \r
80   // setup the balance function objects\r
81   AliBalanceTriggered *bf  = 0;  // Balance Function object\r
82   AliBalanceTriggered *bfs = 0;  // shuffled Balance function object\r
83   AliBalanceTriggered *bfm = 0;  // mixing Balance function object\r
84   \r
85   if (analysisType=="AOD"){\r
86     \r
87     bf = new AliBalanceTriggered();\r
88     bf->SetAnalysisLevel(analysisType);\r
89     bf->InitHistograms();\r
90     \r
91     if(gRunShuffling){\r
92       bfs = new AliBalanceTriggered();\r
93       bfs->SetAnalysisLevel(analysisType);\r
94       bfs->InitHistograms();\r
95     }\r
96     if(gRunMixing){\r
97       bfm = new AliBalanceTriggered();\r
98       bfm->SetAnalysisLevel(analysisType);\r
99       bfm->InitHistograms();\r
100     }\r
101   }\r
102   else{\r
103     ::Error("AddTaskTriggeredBF", "analysis type NOT supported.");\r
104     return NULL;\r
105   }\r
106 \r
107   // Create the task, add it to manager and configure it.\r
108   //===========================================================================\r
109   AliAnalysisTaskTriggeredBF *taskTriggeredBF = new AliAnalysisTaskTriggeredBF("TaskTriggeredBF");\r
110   taskTriggeredBF->SetAnalysisObject(bf);\r
111   if(gRunShuffling) taskTriggeredBF->SetShufflingObject(bfs);\r
112   if(gRunMixing){\r
113     taskTriggeredBF->SetMixingObject(bfm);\r
114     taskTriggeredBF->SetMixingTracks(50000);\r
115   }\r
116 \r
117   taskTriggeredBF->SetCentralityPercentileRange(centrMin,centrMax);\r
118   if(analysisType == "AOD") {\r
119     // pt and eta cut (pt_min, pt_max, eta_min, eta_max)\r
120     taskTriggeredBF->SetAODtrackCutBit(AODfilterBit);\r
121     taskTriggeredBF->SetKinematicsCutsAOD(ptMin,ptMax,etaMin,etaMax);\r
122     \r
123     // set extra DCA cuts (-1 no extra cut)\r
124     taskTriggeredBF->SetExtraDCACutsAOD(DCAxy,DCAz);\r
125     \r
126     // set extra TPC chi2 / nr of clusters cut\r
127     taskTriggeredBF->SetExtraTPCCutsAOD(maxTPCchi2, minNClustersTPC);\r
128     \r
129   }\r
130 \r
131   // offline trigger selection (AliVEvent.h)\r
132   // taskTriggeredBF->UseOfflineTrigger(); // NOT used (selection is done with the AliAnalysisTaskSE::SelectCollisionCandidates()) \r
133   // with this only selected events are analyzed (first 2 bins in event QA histogram are the same))\r
134   // documentation in https://twiki.cern.ch/twiki/bin/viewauth/ALICE/PWG1EvSelDocumentation\r
135   if(bCentralTrigger) taskTriggeredBF->SelectCollisionCandidates(AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral);\r
136   else                taskTriggeredBF->SelectCollisionCandidates(AliVEvent::kMB);\r
137 \r
138   // centrality estimator (default = V0M)\r
139   taskTriggeredBF->SetCentralityEstimator(centralityEstimator);\r
140   \r
141   // vertex cut (x,y,z)\r
142   taskTriggeredBF->SetVertexDiamond(.3,.3,vertexZ);\r
143   \r
144   //bf->PrintAnalysisSettings();\r
145   mgr->AddTask(taskTriggeredBF);\r
146   \r
147   // Create ONLY the output containers for the data produced by the task.\r
148   // Get and connect other common input/output containers via the manager as below\r
149   //==============================================================================\r
150   TString outputFileName = AliAnalysisManager::GetCommonFileName();\r
151   outputFileName += ":PWGCFEbyE.outputBalanceFunctionTriggeredAnalysis";\r
152   AliAnalysisDataContainer *coutQA = mgr->CreateContainer(Form("listQA_%s",centralityName.Data()), TList::Class(),AliAnalysisManager::kOutputContainer,outputFileName.Data());\r
153   AliAnalysisDataContainer *coutTriggeredBF = mgr->CreateContainer(Form("listTriggeredBF_%s",centralityName.Data()), TList::Class(),AliAnalysisManager::kOutputContainer,outputFileName.Data());\r
154   if(gRunShuffling) AliAnalysisDataContainer *coutTriggeredBFS = mgr->CreateContainer(Form("listTriggeredBFShuffled_%s",centralityName.Data()), TList::Class(),AliAnalysisManager::kOutputContainer,outputFileName.Data());\r
155   if(gRunMixing) AliAnalysisDataContainer *coutTriggeredBFM = mgr->CreateContainer(Form("listTriggeredBFMixed_%s",centralityName.Data()), TList::Class(),AliAnalysisManager::kOutputContainer,outputFileName.Data());\r
156 \r
157   mgr->ConnectInput(taskTriggeredBF, 0, mgr->GetCommonInputContainer());\r
158   mgr->ConnectOutput(taskTriggeredBF, 1, coutQA);\r
159   mgr->ConnectOutput(taskTriggeredBF, 2, coutTriggeredBF);\r
160   if(gRunShuffling) mgr->ConnectOutput(taskTriggeredBF, 3, coutTriggeredBFS);\r
161   if(gRunMixing) mgr->ConnectOutput(taskTriggeredBF, 4, coutTriggeredBFM);\r
162 \r
163   return taskTriggeredBF;\r
164 }\r