Changed AddTasks
[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    // ================== GetAnalysisManager ===============================
30    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
31    if (!mgr) {
32       Error(Form("AddTask_GammaConvV1_%i",trainConfig), "No analysis manager found.");
33       return ;
34    }
35
36    // ================== GetInputEventHandler =============================
37    AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
38    
39    //========= Add PID Reponse to ANALYSIS manager ====
40    if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
41       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
42       AddTaskPIDResponse(isMC);
43    }
44    
45    //=========  Set Cutnumber for V0Reader ================================
46    TString cutnumber = "1000000000084001001500000000"; 
47    AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
48    //========= Add V0 Reader to  ANALYSIS manager if not yet existent =====
49    if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
50       AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
51       
52       fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
53       fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
54       fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
55
56       if (!mgr) {
57          Error("AddTask_V0ReaderV1", "No analysis manager found.");
58          return;
59       }
60
61       // Set AnalysisCut Number
62       AliConversionCuts *fCuts=NULL;
63       if(cutnumber!=""){
64          fCuts= new AliConversionCuts(cutnumber.Data(),cutnumber.Data());
65          fCuts->SetPreSelectionCutFlag(kTRUE);
66          if(fCuts->InitializeCutsFromCutString(cutnumber.Data())){
67             fV0ReaderV1->SetConversionCuts(fCuts);
68             fCuts->SetFillCutHistograms("",kTRUE);
69          }
70       }
71       
72       if(inputHandler->IsA()==AliAODInputHandler::Class()){
73       // AOD mode
74          fV0ReaderV1->SetDeltaAODBranchName(Form("GammaConv_%s_gamma",cutnumberAODBranch.Data()));
75       }
76       fV0ReaderV1->Init();
77
78       AliLog::SetGlobalLogLevel(AliLog::kInfo);
79
80       //connect input V0Reader
81       mgr->AddTask(fV0ReaderV1);
82       mgr->ConnectInput(fV0ReaderV1,0,cinput);
83
84    }
85
86    //================================================
87    //========= Add task to the ANALYSIS manager =====
88    //================================================
89    AliAnalysisTaskGammaConvV1 *task=NULL;
90    task= new AliAnalysisTaskGammaConvV1(Form("GammaConvV1_%i",trainConfig));
91    task->SetIsHeavyIon(1);
92    task->SetIsMC(isMC);
93    // Cut Numbers to use in Analysis
94    Int_t numberOfCuts = 1;
95
96    TString *cutarray = new TString[numberOfCuts];
97    TString *mesonCutArray = new TString[numberOfCuts];
98
99    if (trainConfig == 1){ 
100       cutarray[ 0] = "6010001042092970023220000000"; mesonCutArray[ 0] = "01522045009000"; 
101    } else if (trainConfig == 2) { 
102       cutarray[ 0] = "6120001042092970023220000000"; mesonCutArray[ 0] = "01522045009000"; 
103    } else if (trainConfig == 3) { 
104       cutarray[ 0] = "5010001042092970023220000000"; mesonCutArray[ 0] = "01522045009000"; 
105    } else if (trainConfig == 4) { 
106       cutarray[ 0] = "5020001042092970023220000000"; mesonCutArray[ 0] = "01522045009000";    
107    } else if (trainConfig == 5) { 
108       cutarray[ 0] = "5120001042092970023220000000"; mesonCutArray[ 0] = "01522045009000";    
109    } else if (trainConfig == 6) { 
110       cutarray[ 0] = "5240001042092970023220000000"; mesonCutArray[ 0] = "01522045009000";       
111    } else if (trainConfig == 7) {    
112       cutarray[ 0] = "5460001042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
113    } else if (trainConfig == 8) {    
114       cutarray[ 0] = "5480001042092970023220000000"; mesonCutArray[ 0] = "01522065009000";    
115    } else if (trainConfig == 9) {    
116       cutarray[ 0] = "5450001042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
117    } else if (trainConfig == 10) { 
118       cutarray[ 0] = "5560001042092970023220000000"; mesonCutArray[ 0] = "01522065009000";
119    } else if (trainConfig == 11) { 
120       cutarray[ 0] = "5680001042092970023220000000"; mesonCutArray[ 0] = "01522065009000";    
121    } else if (trainConfig == 12) { 
122       cutarray[ 0] = "5670001042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
123    } else if (trainConfig == 13) { 
124       cutarray[ 0] = "5780001042092970023220000000"; mesonCutArray[ 0] = "01522065009000"; 
125    } else if (trainConfig == 14) { 
126       cutarray[ 0] = "4690001042092970023220000000"; mesonCutArray[ 0] = "01522065009000";
127    } else if (trainConfig == 15) { 
128       cutarray[ 0] = "5890001042092970023220000000"; mesonCutArray[ 0] = "01522065009000";    
129    } else  if (trainConfig == 16){ 
130       cutarray[ 0] = "6010002032092970023220000000"; mesonCutArray[ 0] = "01523045009000"; 
131    } else if (trainConfig == 17) { 
132       cutarray[ 0] = "6120001032092970023220000000"; mesonCutArray[ 0] = "01523045009000"; 
133    } else if (trainConfig == 18) { 
134       cutarray[ 0] = "5010001032092970023220000000"; mesonCutArray[ 0] = "01523045009000"; 
135    } else if (trainConfig == 19) { 
136       cutarray[ 0] = "5020001032092970023220000000"; mesonCutArray[ 0] = "01523045009000";    
137    } else if (trainConfig == 20) { 
138       cutarray[ 0] = "5120001032092970023220000000"; mesonCutArray[ 0] = "01523045009000";    
139    } else if (trainConfig == 21) { 
140       cutarray[ 0] = "5240001032092970023220000000"; mesonCutArray[ 0] = "01523045009000";       
141    } else if (trainConfig == 22) {    
142       cutarray[ 0] = "5460001032092970023220000000"; mesonCutArray[ 0] = "01523065009000"; 
143    } else if (trainConfig == 23) {    
144       cutarray[ 0] = "5480001032092970023220000000"; mesonCutArray[ 0] = "01523065009000";    
145    } else if (trainConfig == 24) {    
146       cutarray[ 0] = "5450001032092970023220000000"; mesonCutArray[ 0] = "01523065009000"; 
147    } else if (trainConfig == 25) { 
148       cutarray[ 0] = "5560001032092970023220000000"; mesonCutArray[ 0] = "01523065009000";
149    } else if (trainConfig == 26) { 
150       cutarray[ 0] = "5680001032092970023220000000"; mesonCutArray[ 0] = "01523065009000";    
151    } else if (trainConfig == 27) { 
152       cutarray[ 0] = "5670001032092970023220000000"; mesonCutArray[ 0] = "01523065009000"; 
153    } else if (trainConfig == 28) { 
154       cutarray[ 0] = "5780001032092970023220000000"; mesonCutArray[ 0] = "01523065009000"; 
155    } else if (trainConfig == 29) { 
156       cutarray[ 0] = "4690001032092970023220000000"; mesonCutArray[ 0] = "01523065009000";
157    } else if (trainConfig == 30) { 
158       cutarray[ 0] = "5890001032092970023220000000"; mesonCutArray[ 0] = "01523065009000";    
159    } else if (trainConfig == 31) { 
160       cutarray[ 0] = "5080001002092970023220000000"; mesonCutArray[ 0] = "01525065009000";    
161    } else if (trainConfig == 32) { 
162       cutarray[ 0] = "5080002002092970023220000000"; mesonCutArray[ 0] = "01525065009000";    
163    } else {
164       Error(Form("GammaConvV1_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
165       return;
166    }
167
168    TList *ConvCutList = new TList();
169    TList *MesonCutList = new TList();
170
171    TList *HeaderList = new TList();
172    TObjString *Header1 = new TObjString("BOX");
173    HeaderList->Add(Header1);
174 //    TObjString *Header3 = new TObjString("eta_2");
175 //    HeaderList->Add(Header3);
176    
177    ConvCutList->SetOwner(kTRUE);
178    AliConversionCuts **analysisCuts = new AliConversionCuts*[numberOfCuts];
179    MesonCutList->SetOwner(kTRUE);
180    AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
181
182    for(Int_t i = 0; i<numberOfCuts; i++){
183       analysisCuts[i] = new AliConversionCuts();
184       analysisCuts[i]->InitializeCutsFromCutString(cutarray[i].Data());
185       ConvCutList->Add(analysisCuts[i]);
186
187       analysisCuts[i]->SetFillCutHistograms("",kFALSE);
188       analysisMesonCuts[i] = new AliConversionMesonCuts();
189       analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
190       MesonCutList->Add(analysisMesonCuts[i]);
191       analysisMesonCuts[i]->SetFillCutHistograms("");
192       analysisCuts[i]->SetAcceptedHeader(HeaderList);
193    }
194
195    task->SetConversionCutList(numberOfCuts,ConvCutList);
196    task->SetMesonCutList(numberOfCuts,MesonCutList);
197    task->SetMoveParticleAccordingToVertex(kTRUE);
198    task->SetDoMesonAnalysis(kTRUE);
199    task->SetDoMesonQA(enableQAMesonTask); //Attention new switch for Pi0 QA
200    task->SetDoPhotonQA(enableQAPhotonTask);  //Attention new switch small for Photon QA
201
202    //connect containers
203    AliAnalysisDataContainer *coutput =
204       mgr->CreateContainer(Form("GammaConvV1_%i",trainConfig), TList::Class(),
205                            AliAnalysisManager::kOutputContainer,Form("GammaConvV1_%i.root",trainConfig));
206
207    mgr->AddTask(task);
208    mgr->ConnectInput(task,0,cinput);
209    mgr->ConnectOutput(task,1,coutput);
210
211    return;
212
213 }