fix minor bug: add task argument was not passed to tak
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / macros / AddTask_GammaConvCalo_PbPb.C
1 void AddTask_GammaConvCalo_PbPb(        Int_t trainConfig = 1,  //change different set of cuts
2                                                                         Bool_t isMC   = kFALSE, //run MC 
3                                                                         Int_t enableQAMesonTask = 0, //enable QA in AliAnalysisTaskGammaConvV1
4                                                                         Int_t enableQAPhotonTask = 0, // enable additional QA task
5                                                                         TString fileNameInputForWeighting = "MCSpectraInput.root", // path to file for weigting input
6                                                                         Int_t headerSelectionInt = 0,  // 1 pi0 header, 2 eta header, 3 both (only for "named" boxes)
7                                                                         TString cutnumberAODBranch = "1000000060084000001500000",
8                                                                         TString periodName = "LHC13d2",  //name of the period for added signals and weighting
9                                                                         Bool_t doWeighting = kFALSE  //enable Weighting
10                                                                 ) {
11
12         // ================= Load Librariers =================================
13         gSystem->Load("libCore.so");  
14         gSystem->Load("libTree.so");
15         gSystem->Load("libGeom.so");
16         gSystem->Load("libVMC.so");
17         gSystem->Load("libPhysics.so");
18         gSystem->Load("libMinuit");
19         gSystem->Load("libSTEERBase");
20         gSystem->Load("libESD");
21         gSystem->Load("libAOD");
22         gSystem->Load("libANALYSIS");
23         gSystem->Load("libANALYSISalice");  
24         gSystem->Load("libPWGGAGammaConv.so");
25         gSystem->Load("libCDB.so");
26         gSystem->Load("libSTEER.so");
27         gSystem->Load("libSTEERBase.so");
28         gSystem->Load("libTENDER.so");
29         gSystem->Load("libTENDERSupplies.so");
30         
31         Int_t isHeavyIon = 1;
32         
33         // ================== GetAnalysisManager ===============================
34         AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
35         if (!mgr) {
36                 Error(Form("AddTask_GammaConvV1_%i",trainConfig), "No analysis manager found.");
37                 return ;
38         }
39
40         // ================== GetInputEventHandler =============================
41         AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
42         
43         //========= Add PID Reponse to ANALYSIS manager ====
44         if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
45                 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
46                 AddTaskPIDResponse(isMC);
47         }
48         
49         //=========  Set Cutnumber for V0Reader ================================
50         TString cutnumberPhoton = "000084001001500000000";
51         TString cutnumberEvent = "1000000";
52         AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
53
54         //========= Add V0 Reader to  ANALYSIS manager if not yet existent =====
55         if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
56                 AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
57                 
58                 fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
59                 fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
60                 fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
61
62                 if (!mgr) {
63                         Error("AddTask_V0ReaderV1", "No analysis manager found.");
64                         return;
65                 }
66
67                 AliConvEventCuts *fEventCuts=NULL;
68                 if(cutnumberEvent!=""){
69                         fEventCuts= new AliConvEventCuts(cutnumberEvent.Data(),cutnumberEvent.Data());
70                         fEventCuts->SetPreSelectionCutFlag(kTRUE);
71                         if(fEventCuts->InitializeCutsFromCutString(cutnumberEvent.Data())){
72                                 fV0ReaderV1->SetEventCuts(fEventCuts);
73                                 fEventCuts->SetFillCutHistograms("",kTRUE);
74                         }
75                 }
76
77                 
78                 // Set AnalysisCut Number
79                 AliConversionPhotonCuts *fCuts=NULL;
80                 if(cutnumberPhoton!=""){
81                         fCuts= new AliConversionPhotonCuts(cutnumberPhoton.Data(),cutnumberPhoton.Data());
82                         fCuts->SetPreSelectionCutFlag(kTRUE);
83                         fCuts->SetIsHeavyIon(isHeavyIon);
84                         if(fCuts->InitializeCutsFromCutString(cutnumberPhoton.Data())){
85                                 fV0ReaderV1->SetConversionCuts(fCuts);
86                                 fCuts->SetFillCutHistograms("",kTRUE);
87                         }
88                 }
89
90                 if(inputHandler->IsA()==AliAODInputHandler::Class()){
91                 // AOD mode
92                         fV0ReaderV1->SetDeltaAODBranchName(Form("GammaConv_%s_gamma",cutnumberAODBranch.Data()));
93                 }
94                 fV0ReaderV1->Init();
95
96                 AliLog::SetGlobalLogLevel(AliLog::kFatal);
97
98                 //connect input V0Reader
99                 mgr->AddTask(fV0ReaderV1);
100                 mgr->ConnectInput(fV0ReaderV1,0,cinput);
101
102         }
103
104         //================================================
105         //========= Add task to the ANALYSIS manager =====
106         //================================================
107         AliAnalysisTaskGammaConvCalo *task=NULL;
108         task= new AliAnalysisTaskGammaConvCalo(Form("GammaConvCalo_%i",trainConfig));
109         task->SetIsHeavyIon(isHeavyIon);
110         task->SetIsMC(isMC);
111         // Cut Numbers to use in Analysis
112         Int_t numberOfCuts = 5;
113
114         TString *eventCutArray = new TString[numberOfCuts];
115         TString *photonCutArray = new TString[numberOfCuts];
116         TString *clusterCutArray = new TString[numberOfCuts];
117         TString *mesonCutArray = new TString[numberOfCuts];
118
119         // meson cuts
120         // meson type (Dalitz or not), BG scheme, pool depth, rotation degrees, rapidity cut, radius cut, alpha, chi2, shared electrons, reject to close v0, MC smearing, dca, dca, dca
121   
122         if (trainConfig == 1){ // EMCAL clusters
123                 eventCutArray[ 0] = "6010001"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "10000040022030000"; mesonCutArray[ 0] = "01525065000000"; // 0-5%
124                 eventCutArray[ 1] = "6120001"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "10000040022030000"; mesonCutArray[ 1] = "01525065000000"; // 5-10%
125                 eventCutArray[ 2] = "5010001"; photonCutArray[ 2] = "002092970028250400000"; clusterCutArray[2] = "10000040022030000"; mesonCutArray[ 2] = "01525065000000"; // 0-10%
126                 eventCutArray[ 3] = "5240001"; photonCutArray[ 3] = "002092970028250400000"; clusterCutArray[3] = "10000040022030000"; mesonCutArray[ 3] = "01525065000000"; // 20-40%
127                 eventCutArray[ 4] = "5250001"; photonCutArray[ 4] = "002092970028250400000"; clusterCutArray[4] = "10000040022030000"; mesonCutArray[ 4] = "01525065000000"; // 20-50%
128         } else if (trainConfig == 2){ // PHOS clusters
129                 eventCutArray[ 0] = "6010001"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "20000030022000000"; mesonCutArray[ 0] = "01525065000000"; // 0-5%
130                 eventCutArray[ 1] = "6120001"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "20000030022000000"; mesonCutArray[ 1] = "01525065000000"; // 5-10%
131                 eventCutArray[ 2] = "5010001"; photonCutArray[ 2] = "002092970028250400000"; clusterCutArray[2] = "20000030022000000"; mesonCutArray[ 2] = "01525065000000"; // 0-10%
132                 eventCutArray[ 3] = "5240001"; photonCutArray[ 3] = "002092970028250400000"; clusterCutArray[3] = "20000030022000000"; mesonCutArray[ 3] = "01525065000000"; // 20-40%
133                 eventCutArray[ 4] = "5250001"; photonCutArray[ 4] = "002092970028250400000"; clusterCutArray[4] = "20000030022000000"; mesonCutArray[ 4] = "01525065000000"; // 20-50%
134
135                 
136         } else {
137                 Error(Form("GammaConvCalo_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
138                 return;
139         }
140
141         TList *EventCutList = new TList();
142         TList *ConvCutList = new TList();
143         TList *ClusterCutList = new TList();
144         TList *MesonCutList = new TList();
145
146         TList *HeaderList = new TList();
147         if (periodName.CompareTo("LHC13d2")==0){
148                 TObjString *Header1 = new TObjString("pi0_1");
149                 HeaderList->Add(Header1);
150         //    TObjString *Header3 = new TObjString("eta_2");
151         //    HeaderList->Add(Header3);
152
153         } else if (periodName.CompareTo("LHC12a17x_fix")==0){
154                 TObjString *Header1 = new TObjString("PARAM");
155                 HeaderList->Add(Header1);
156         } else if (periodName.CompareTo("LHC14a1a")==0){
157                 if (headerSelectionInt == 1){ 
158                         TObjString *Header1 = new TObjString("pi0_1");
159                         HeaderList->Add(Header1);
160                 } else if (headerSelectionInt == 2){
161                         TObjString *Header1 = new TObjString("eta_2");
162                         HeaderList->Add(Header1);
163                 } else {
164                         TObjString *Header1 = new TObjString("pi0_1");
165                         HeaderList->Add(Header1);
166                         TObjString *Header2 = new TObjString("eta_2");
167                         HeaderList->Add(Header2);
168                 }  
169         } else if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0){
170                 TObjString *Header1 = new TObjString("BOX");
171                 HeaderList->Add(Header1);
172         }       
173
174         EventCutList->SetOwner(kTRUE);
175         AliConvEventCuts **analysisEventCuts = new AliConvEventCuts*[numberOfCuts];
176         ConvCutList->SetOwner(kTRUE);
177         AliConversionPhotonCuts **analysisCuts = new AliConversionPhotonCuts*[numberOfCuts];
178         ClusterCutList->SetOwner(kTRUE);
179         AliCaloPhotonCuts **analysisClusterCuts = new AliCaloPhotonCuts*[numberOfCuts];
180         MesonCutList->SetOwner(kTRUE);
181         AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
182
183         for(Int_t i = 0; i<numberOfCuts; i++){
184                 
185                 analysisEventCuts[i] = new AliConvEventCuts();
186                 if ( trainConfig == 1){
187                         if (periodName.CompareTo("LHC14a1a") ==0 || periodName.CompareTo("LHC14a1b") ==0 || periodName.CompareTo("LHC14a1c") ==0 ){
188                                 if ( i == 0 && doWeighting)  analysisEventCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kTRUE, kFALSE,fileNameInputForWeighting, Form("Pi0_Hijing_%s_PbPb_2760GeV_0005TPC",periodName.Data()), Form("Eta_Hijing_%s_PbPb_2760GeV_0005TPC",periodName.Data()), "","Pi0_Fit_Data_PbPb_2760GeV_0005V0M","Eta_Fit_Data_PbPb_2760GeV_0005V0M");
189                                 if ( i == 1 && doWeighting)  analysisEventCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kTRUE, kFALSE,fileNameInputForWeighting, Form("Pi0_Hijing_%s_PbPb_2760GeV_0510TPC",periodName.Data()), Form("Eta_Hijing_%s_PbPb_2760GeV_0510TPC",periodName.Data()), "","Pi0_Fit_Data_PbPb_2760GeV_0510V0M","Eta_Fit_Data_PbPb_2760GeV_0510V0M");
190                                 if ( i == 2 && doWeighting)  analysisEventCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kTRUE, kFALSE,fileNameInputForWeighting, Form("Pi0_Hijing_%s_PbPb_2760GeV_0010TPC",periodName.Data()), Form("Eta_Hijing_%s_PbPb_2760GeV_0010TPC",periodName.Data()), "","Pi0_Fit_Data_PbPb_2760GeV_0010V0M","Eta_Fit_Data_PbPb_2760GeV_0010V0M");
191                                 if ( i == 3 && doWeighting)  analysisEventCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kTRUE, kFALSE,fileNameInputForWeighting, Form("Pi0_Hijing_%s_PbPb_2760GeV_2040TPC",periodName.Data()), Form("Eta_Hijing_%s_PbPb_2760GeV_2040TPC",periodName.Data()), "","Pi0_Fit_Data_PbPb_2760GeV_2040V0M","Eta_Fit_Data_PbPb_2760GeV_2040V0M");
192                                 if ( i == 4 && doWeighting)  analysisEventCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kTRUE, kFALSE,fileNameInputForWeighting, Form("Pi0_Hijing_%s_PbPb_2760GeV_2050TPC",periodName.Data()), Form("Eta_Hijing_%s_PbPb_2760GeV_2050TPC",periodName.Data()), "","Pi0_Fit_Data_PbPb_2760GeV_2050V0M","Eta_Fit_Data_PbPb_2760GeV_2050V0M");
193                         }       
194                 } 
195                 analysisEventCuts[i]->InitializeCutsFromCutString(eventCutArray[i].Data());
196                 if (periodName.CompareTo("LHC14a1b") ==0 || periodName.CompareTo("LHC14a1c") ==0 ){
197                         if (headerSelectionInt == 1) analysisEventCuts[i]->SetAddedSignalPDGCode(111);
198                         if (headerSelectionInt == 2) analysisEventCuts[i]->SetAddedSignalPDGCode(221);
199                 }
200                 EventCutList->Add(analysisEventCuts[i]);
201                 analysisEventCuts[i]->SetFillCutHistograms("",kFALSE);
202
203                 analysisCuts[i] = new AliConversionPhotonCuts();
204                 analysisCuts[i]->InitializeCutsFromCutString(photonCutArray[i].Data());
205                 ConvCutList->Add(analysisCuts[i]);
206                 analysisCuts[i]->SetFillCutHistograms("",kFALSE);
207                                 
208                 analysisClusterCuts[i] = new AliCaloPhotonCuts();
209                 analysisClusterCuts[i]->InitializeCutsFromCutString(clusterCutArray[i].Data());
210                 ClusterCutList->Add(analysisClusterCuts[i]);
211                 analysisClusterCuts[i]->SetFillCutHistograms("");
212
213                 analysisMesonCuts[i] = new AliConversionMesonCuts();
214                 analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
215                 MesonCutList->Add(analysisMesonCuts[i]);
216                 analysisMesonCuts[i]->SetFillCutHistograms("");
217                 analysisEventCuts[i]->SetAcceptedHeader(HeaderList);
218         
219         }
220
221         task->SetEventCutList(numberOfCuts,EventCutList);
222         task->SetConversionCutList(numberOfCuts,ConvCutList);
223         task->SetCaloCutList(numberOfCuts,ClusterCutList);
224         task->SetMesonCutList(numberOfCuts,MesonCutList);
225         task->SetMoveParticleAccordingToVertex(kTRUE);
226         task->SetDoMesonAnalysis(kTRUE);
227         task->SetDoMesonQA(enableQAMesonTask); //Attention new switch for Pi0 QA
228         task->SetDoPhotonQA(enableQAPhotonTask);  //Attention new switch small for Photon QA
229
230         //connect containers
231         AliAnalysisDataContainer *coutput =
232                 mgr->CreateContainer(Form("GammaConvCalo_%i",trainConfig), TList::Class(),
233                                                         AliAnalysisManager::kOutputContainer,Form("GammaConvCalo_%i.root",trainConfig));
234
235         mgr->AddTask(task);
236         mgr->ConnectInput(task,0,cinput);
237         mgr->ConnectOutput(task,1,coutput);
238
239         return;
240
241 }