changes in AddTasks
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / macros / AddTask_GammaConvV1_PbPb.C
1 void AddTask_GammaConvV1_PbPb(  Int_t trainConfig = 1,  //change different set of cuts
2                               Bool_t isMC   = kFALSE, //run MC 
3                               Bool_t enableQAMesonTask = kFALSE, //enable QA in AliAnalysisTaskGammaConvV1
4                               Bool_t enableQAPhotonTask = kFALSE, // 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 = "1000000000084001001500000"; 
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 = 4;
95
96    TString *cutarray = new TString[numberOfCuts];
97    TString *mesonCutArray = new TString[numberOfCuts];
98
99    if(trainConfig == 1){ // Standard neutral pion cuts
100       cutarray[ 0] = "3010001042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 0-5%
101       cutarray[ 1] = "3120001042092970023220000"; mesonCutArray[ 1] = "01522045009"; // 5-10%
102       cutarray[ 2] = "1010001042092970023220000"; mesonCutArray[ 2] = "01522045009"; // 0-10%
103       cutarray[ 3] = "1120001042092970023220000"; mesonCutArray[ 3] = "01522045009"; // 10-20%
104    } else if (trainConfig == 2) { // Standard neutral pion cuts
105       cutarray[ 0] = "1240001042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 20-40%
106       cutarray[ 1] = "1460001042092970023220000"; mesonCutArray[ 1] = "01522065009"; // 40-60%
107       cutarray[ 2] = "1680001042092970023220000"; mesonCutArray[ 2] = "01522065009"; // 60-80%
108       cutarray[ 3] = "1080001042092970023220000"; mesonCutArray[ 3] = "01522065009"; // 0-80%
109    } else if (trainConfig == 3) { // Standard direct photon cuts
110       cutarray[ 0] = "1020001042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-20%
111       cutarray[ 1] = "1040001042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 0-40%
112       cutarray[ 2] = "1480001042092370023700000"; mesonCutArray[ 2] = "01522065009"; // 40-80%
113       cutarray[ 3] = "1080001042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-80%
114    } else if (trainConfig == 4) { // Standard direct photon cuts
115       cutarray[ 0] = "1010001042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-10%
116       cutarray[ 1] = "1120001042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 10-20%
117       cutarray[ 2] = "1240001042092370023700000"; mesonCutArray[ 2] = "01522045009"; // 20-40%
118       cutarray[ 3] = "1090001042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-90%
119    } else if (trainConfig == 5) { // Standard neutral pion cuts only added signals
120       cutarray[ 0] = "3010002042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 0-5%
121       cutarray[ 1] = "3120002042092970023220000"; mesonCutArray[ 1] = "01522045009"; // 5-10%
122       cutarray[ 2] = "1010002042092970023220000"; mesonCutArray[ 2] = "01522045009"; // 0-10%
123       cutarray[ 3] = "1120002042092970023220000"; mesonCutArray[ 3] = "01522045009"; // 10-20%
124    } else if (trainConfig == 6) { // Standard neutral pion cuts only added signals
125       cutarray[ 0] = "1240002042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 20-40%
126       cutarray[ 1] = "1460002042092970023220000"; mesonCutArray[ 1] = "01522065009"; // 40-60%
127       cutarray[ 2] = "1680002042092970023220000"; mesonCutArray[ 2] = "01522065009"; // 60-80%
128       cutarray[ 3] = "1080002042092970023220000"; mesonCutArray[ 3] = "01522065009"; // 0-80%
129    } else if (trainConfig == 7) { // Standard direct photon cuts
130       cutarray[ 0] = "1020003042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-20%
131       cutarray[ 1] = "1040003042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 0-40%
132       cutarray[ 2] = "1480003042092370023700000"; mesonCutArray[ 2] = "01522065009"; // 40-80%
133       cutarray[ 3] = "1080003042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-80%
134    } else if (trainConfig == 8) { // Standard direct photon cuts
135       cutarray[ 0] = "1010003042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-10%
136       cutarray[ 1] = "1120003042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 10-20%
137       cutarray[ 2] = "1240003042092370023700000"; mesonCutArray[ 2] = "01522045009"; // 20-40%
138       cutarray[ 3] = "1090003042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-90%
139    } else if(trainConfig == 9){ // Different trigger conditions
140       cutarray[ 0] = "3010001042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 0-5%
141       cutarray[ 1] = "3014001042092970023220000"; mesonCutArray[ 1] = "01522045009"; // 0-5% kMB
142       cutarray[ 2] = "3015001042092970023220000"; mesonCutArray[ 2] = "01522045009"; // 0-5% kSemiCentral
143       cutarray[ 3] = "3016001042092970023220000"; mesonCutArray[ 3] = "01522045009"; // 0-5% kCentral
144       
145    } else {
146       Error(Form("GammaConvV1_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
147       return;
148    }
149
150    TList *ConvCutList = new TList();
151    TList *MesonCutList = new TList();
152
153    TList *HeaderList = new TList();
154    TObjString *Header1 = new TObjString("pi0_1");
155    HeaderList->Add(Header1);
156    TObjString *Header3 = new TObjString("eta_2");
157    HeaderList->Add(Header3);
158    
159    ConvCutList->SetOwner(kTRUE);
160    AliConversionCuts **analysisCuts = new AliConversionCuts*[numberOfCuts];
161    MesonCutList->SetOwner(kTRUE);
162    AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
163
164
165    for(Int_t i = 0; i<numberOfCuts; i++){
166       if (trainConfig == 1 ){
167          if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0005", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0005");
168          if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0510", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0510"); 
169          if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0010", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0010");
170          if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE,fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_1020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_1020");
171       } else if (trainConfig == 2){ 
172         if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_2040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_2040");
173         if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_4060", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_4060");
174         if (i==2  && doWeighting) analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_6080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_6080");
175         if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0080");
176       } else if (trainConfig == 3){
177         if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0020");
178         if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0040");
179         if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_4080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_4080");
180         if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0080");
181       } else if (trainConfig == 4){
182          if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0010", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0010");
183          if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE,fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_1020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_1020");
184          if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_2040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_2040");
185       } else if (trainConfig == 9){
186          if (doWeighting) analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0005", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0005");
187          if (i == 1) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kMB, "AliVEvent::kMB" );
188          if (i == 2) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kSemiCentral,"AliVEvent::kSemiCentral" );
189          if (i == 3) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kCentral,"AliVEvent::kCentral" );
190          
191       } 
192       analysisCuts[i] = new AliConversionCuts();
193       analysisCuts[i]->InitializeCutsFromCutString(cutarray[i].Data());
194       ConvCutList->Add(analysisCuts[i]);
195
196       analysisCuts[i]->SetFillCutHistograms("",kFALSE);
197       analysisMesonCuts[i] = new AliConversionMesonCuts();
198       analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
199       MesonCutList->Add(analysisMesonCuts[i]);
200       analysisMesonCuts[i]->SetFillCutHistograms("");
201       analysisCuts[i]->SetAcceptedHeader(HeaderList);
202    }
203
204    task->SetConversionCutList(numberOfCuts,ConvCutList);
205    task->SetMesonCutList(numberOfCuts,MesonCutList);
206    task->SetMoveParticleAccordingToVertex(kTRUE);
207    task->SetDoMesonAnalysis(kTRUE);
208    if (enableQAMesonTask) task->SetDoMesonQA(kTRUE); //Attention new switch for Pi0 QA
209    if (enableQAMesonTask) task->SetDoPhotonQA(kTRUE);  //Attention new switch small for Photon QA
210
211    //connect containers
212    AliAnalysisDataContainer *coutput =
213       mgr->CreateContainer(Form("GammaConvV1_%i",trainConfig), TList::Class(),
214                            AliAnalysisManager::kOutputContainer,Form("GammaConvV1_%i.root",trainConfig));
215
216    mgr->AddTask(task);
217    mgr->ConnectInput(task,0,cinput);
218    mgr->ConnectOutput(task,1,coutput);
219
220    return;
221
222 }