MAYOR commit to separate Event and Conversion Cuts, all tasks working except dPhi...
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / macros / AddTask_GammaConvV1_PbPb2.C
1 void AddTask_GammaConvV1_PbPb2(  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                               Bool_t doWeighting = kFALSE,  //enable Weighting
7                               TString cutnumberAODBranch = "1000000060084000001500000" 
8                            ) {
9
10         // ================= Load Librariers =================================
11         gSystem->Load("libCore.so");  
12         gSystem->Load("libTree.so");
13         gSystem->Load("libGeom.so");
14         gSystem->Load("libVMC.so");
15         gSystem->Load("libPhysics.so");
16         gSystem->Load("libMinuit");
17         gSystem->Load("libSTEERBase");
18         gSystem->Load("libESD");
19         gSystem->Load("libAOD");
20         gSystem->Load("libANALYSIS");
21         gSystem->Load("libANALYSISalice");  
22         gSystem->Load("libPWGGAGammaConv.so");
23         gSystem->Load("libCDB.so");
24         gSystem->Load("libSTEER.so");
25         gSystem->Load("libSTEERBase.so");
26         gSystem->Load("libTENDER.so");
27         gSystem->Load("libTENDERSupplies.so");
28                 
29         Int_t isHeavyIon = 1;
30         
31         // ================== GetAnalysisManager ===============================
32         AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
33         if (!mgr) {
34                 Error(Form("AddTask_GammaConvV1_%i",trainConfig), "No analysis manager found.");
35                 return ;
36         }
37
38         // ================== GetInputEventHandler =============================
39         AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
40         
41         //========= Add PID Reponse to ANALYSIS manager ====
42         if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
43                 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
44                 AddTaskPIDResponse(isMC);
45         }
46         
47         //=========  Set Cutnumber for V0Reader ================================
48         TString cutnumberPhoton = "000084001001500000000";
49         TString cutnumberEvent = "1000000";
50         AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
51         //========= Add V0 Reader to  ANALYSIS manager if not yet existent =====
52         if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
53                 AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
54                 
55                 fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
56                 fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
57                 fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
58
59                 if (!mgr) {
60                         Error("AddTask_V0ReaderV1", "No analysis manager found.");
61                         return;
62                 }
63
64                 AliConvEventCuts *fEventCuts=NULL;
65                 if(cutnumberEvent!=""){
66                         fEventCuts= new AliConvEventCuts(cutnumberEvent.Data(),cutnumberEvent.Data());
67                         fEventCuts->SetPreSelectionCutFlag(kTRUE);
68                         if(fEventCuts->InitializeCutsFromCutString(cutnumberEvent.Data())){
69                                 fV0ReaderV1->SetEventCuts(fEventCuts);
70                                 fEventCuts->SetFillCutHistograms("",kTRUE);
71                         }
72                 }
73
74                 // Set AnalysisCut Number
75                 AliConversionPhotonCuts *fCuts=NULL;
76                 if(cutnumberPhoton!=""){
77                         fCuts= new AliConversionPhotonCuts(cutnumberPhoton.Data(),cutnumberPhoton.Data());
78                         fCuts->SetPreSelectionCutFlag(kTRUE);
79                         fCuts->SetIsHeavyIon(isHeavyIon);
80                         if(fCuts->InitializeCutsFromCutString(cutnumberPhoton.Data())){
81                                 fV0ReaderV1->SetConversionCuts(fCuts);
82                                 fCuts->SetFillCutHistograms("",kTRUE);
83                         }
84                 }
85                 
86                 if(inputHandler->IsA()==AliAODInputHandler::Class()){
87                 // AOD mode
88                         fV0ReaderV1->SetDeltaAODBranchName(Form("GammaConv_%s_gamma",cutnumberAODBranch.Data()));
89                 }
90                 fV0ReaderV1->Init();
91
92                 AliLog::SetGlobalLogLevel(AliLog::kInfo);
93
94                 //connect input V0Reader
95                 mgr->AddTask(fV0ReaderV1);
96                 mgr->ConnectInput(fV0ReaderV1,0,cinput);
97
98         }
99
100         //================================================
101         //========= Add task to the ANALYSIS manager =====
102         //================================================
103         AliAnalysisTaskGammaConvV1 *task=NULL;
104         task= new AliAnalysisTaskGammaConvV1(Form("GammaConvV1_%i",trainConfig));
105         task->SetIsHeavyIon(isHeavyIon);
106         task->SetIsMC(isMC);
107         // Cut Numbers to use in Analysis
108         Int_t numberOfCuts = 1;
109
110         TString *eventCutArray = new TString[numberOfCuts];
111         TString *photonCutArray = new TString[numberOfCuts];
112         TString *mesonCutArray = new TString[numberOfCuts];
113
114         if (trainConfig == 1){ 
115                 eventCutArray[ 0] = "6010001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522045009000"; 
116         } else if (trainConfig == 2) { 
117                 eventCutArray[ 0] = "6120001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522045009000"; 
118         } else if (trainConfig == 3) { 
119                 eventCutArray[ 0] = "5010001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522045009000"; 
120         } else if (trainConfig == 4) { 
121                 eventCutArray[ 0] = "5020001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522045009000";    
122         } else if (trainConfig == 5) { 
123                 eventCutArray[ 0] = "5120001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522045009000";    
124         } else if (trainConfig == 6) { 
125                 eventCutArray[ 0] = "5240001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522045009000";       
126         } else if (trainConfig == 7) {    
127                 eventCutArray[ 0] = "5460001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
128         } else if (trainConfig == 8) {    
129                 eventCutArray[ 0] = "5480001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000";    
130         } else if (trainConfig == 9) {    
131                 eventCutArray[ 0] = "5450001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
132         } else if (trainConfig == 10) { 
133                 eventCutArray[ 0] = "5560001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000";
134         } else if (trainConfig == 11) { 
135                 eventCutArray[ 0] = "5680001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000";    
136         } else if (trainConfig == 12) { 
137                 eventCutArray[ 0] = "5670001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
138         } else if (trainConfig == 13) { 
139                 eventCutArray[ 0] = "5780001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
140         } else if (trainConfig == 14) { 
141                 eventCutArray[ 0] = "4690001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000";
142         } else if (trainConfig == 15) { 
143                 eventCutArray[ 0] = "5890001"; photonCutArray[ 0] = "042092970023220000000"; mesonCutArray[ 0] = "01522065009000";    
144         } else  if (trainConfig == 16){ 
145                 eventCutArray[ 0] = "6010001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000"; 
146         } else if (trainConfig == 17) { 
147                 eventCutArray[ 0] = "6120001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000"; 
148         } else if (trainConfig == 18) { 
149                 eventCutArray[ 0] = "5010001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000"; 
150         } else if (trainConfig == 19) { 
151                 eventCutArray[ 0] = "5020001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";    
152         } else if (trainConfig == 20) { 
153                 eventCutArray[ 0] = "5120001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";    
154         } else if (trainConfig == 21) { 
155                 eventCutArray[ 0] = "5240001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";       
156         } else if (trainConfig == 22) {    
157                 eventCutArray[ 0] = "5460001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000"; 
158         } else if (trainConfig == 23) {    
159                 eventCutArray[ 0] = "5480001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";    
160         } else if (trainConfig == 24) {    
161                 eventCutArray[ 0] = "5450001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000"; 
162         } else if (trainConfig == 25) { 
163                 eventCutArray[ 0] = "5560001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";
164         } else if (trainConfig == 26) { 
165                 eventCutArray[ 0] = "5680001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";    
166         } else if (trainConfig == 27) { 
167                 eventCutArray[ 0] = "5670001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000"; 
168         } else if (trainConfig == 28) { 
169                 eventCutArray[ 0] = "5780001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000"; 
170         } else if (trainConfig == 29) { 
171                 eventCutArray[ 0] = "4690001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";
172         } else if (trainConfig == 30) { 
173                 eventCutArray[ 0] = "5890001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";    
174         } else if (trainConfig == 31) { 
175                 eventCutArray[ 0] = "5080001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";    
176         } else if (trainConfig == 32) { 
177                 eventCutArray[ 0] = "5250001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";       
178         } else if (trainConfig == 33) { 
179                 eventCutArray[ 0] = "5350001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";       
180         } else if (trainConfig == 34) { 
181                 eventCutArray[ 0] = "5450001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";       
182         } else if (trainConfig == 35) { 
183                 eventCutArray[ 0] = "5340001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";       
184         } else if (trainConfig == 36) { 
185                 eventCutArray[ 0] = "5230001"; photonCutArray[ 0] = "002092970028250400000"; mesonCutArray[ 0] = "01525065000000";       
186         } else {
187                 Error(Form("GammaConvV1_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
188                 return;
189         }
190
191         TList *EventCutList = new TList();
192         TList *ConvCutList = new TList();
193         TList *MesonCutList = new TList();
194
195         TList *HeaderList = new TList();
196         TObjString *Header1 = new TObjString("BOX");
197         HeaderList->Add(Header1);
198         //    TObjString *Header3 = new TObjString("eta_2");
199         //    HeaderList->Add(Header3);
200         
201         EventCutList->SetOwner(kTRUE);
202         AliConvEventCuts **analysisEventCuts = new AliConvEventCuts*[numberOfCuts];
203         ConvCutList->SetOwner(kTRUE);
204         AliConversionPhotonCuts **analysisCuts = new AliConversionPhotonCuts*[numberOfCuts];
205         MesonCutList->SetOwner(kTRUE);
206         AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
207
208         for(Int_t i = 0; i<numberOfCuts; i++){
209                 analysisEventCuts[i] = new AliConvEventCuts();
210                 analysisEventCuts[i]->InitializeCutsFromCutString(eventCutArray[i].Data());
211                 EventCutList->Add(analysisEventCuts[i]);
212                 analysisEventCuts[i]->SetFillCutHistograms("",kFALSE);
213                 
214                 analysisCuts[i] = new AliConversionPhotonCuts();
215                 analysisCuts[i]->InitializeCutsFromCutString(photonCutArray[i].Data());
216                 ConvCutList->Add(analysisCuts[i]);
217                 analysisCuts[i]->SetFillCutHistograms("",kFALSE);
218
219                 analysisMesonCuts[i] = new AliConversionMesonCuts();
220                 analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
221                 MesonCutList->Add(analysisMesonCuts[i]);
222                 analysisMesonCuts[i]->SetFillCutHistograms("");
223                 
224                 analysisEventCuts[i]->SetAcceptedHeader(HeaderList);
225         }
226
227         task->SetEventCutList(numberOfCuts,EventCutList);
228         task->SetConversionCutList(numberOfCuts,ConvCutList);
229         task->SetMesonCutList(numberOfCuts,MesonCutList);
230         task->SetMoveParticleAccordingToVertex(kTRUE);
231         task->SetDoMesonAnalysis(kTRUE);
232         task->SetDoMesonQA(enableQAMesonTask); //Attention new switch for Pi0 QA
233         task->SetDoPhotonQA(enableQAPhotonTask);  //Attention new switch small for Photon QA
234
235         //connect containers
236         AliAnalysisDataContainer *coutput =
237                 mgr->CreateContainer(Form("GammaConvV1_%i",trainConfig), TList::Class(),
238                                                         AliAnalysisManager::kOutputContainer,Form("GammaConvV1_%i.root",trainConfig));
239
240         mgr->AddTask(task);
241         mgr->ConnectInput(task,0,cinput);
242         mgr->ConnectOutput(task,1,coutput);
243
244         return;
245
246 }