11e598b3f1eb08c3233a602ccf9fdc19a1973392
[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                            ) {
8
9    // ================= Load Librariers =================================
10    gSystem->Load("libCore.so");  
11    gSystem->Load("libTree.so");
12    gSystem->Load("libGeom.so");
13    gSystem->Load("libVMC.so");
14    gSystem->Load("libPhysics.so");
15    gSystem->Load("libMinuit");
16    gSystem->Load("libSTEERBase");
17    gSystem->Load("libESD");
18    gSystem->Load("libAOD");
19    gSystem->Load("libANALYSIS");
20    gSystem->Load("libANALYSISalice");  
21    gSystem->Load("libPWGGAGammaConv.so");
22    gSystem->Load("libCDB.so");
23    gSystem->Load("libSTEER.so");
24    gSystem->Load("libSTEERBase.so");
25    gSystem->Load("libTENDER.so");
26    gSystem->Load("libTENDERSupplies.so");
27       
28    // ================== GetAnalysisManager ===============================
29    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
30    if (!mgr) {
31       Error(Form("AddTask_GammaConvV1_%i",trainConfig), "No analysis manager found.");
32       return ;
33    }
34
35    // ================== GetInputEventHandler =============================
36    AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
37    
38    //========= Add PID Reponse to ANALYSIS manager ====
39    if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
40       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
41       AddTaskPIDResponse(isMC);
42    }
43    
44    //=========  Set Cutnumber for V0Reader ================================
45    TString cutnumber = "1000000000084001001500000"; 
46    AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
47    //========= Add V0 Reader to  ANALYSIS manager if not yet existent =====
48    if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
49       AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
50       
51       fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
52       fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
53       fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
54
55       if (!mgr) {
56          Error("AddTask_V0ReaderV1", "No analysis manager found.");
57          return;
58       }
59
60       // Set AnalysisCut Number
61       AliConversionCuts *fCuts=NULL;
62       if(cutnumber!=""){
63          fCuts= new AliConversionCuts(cutnumber.Data(),cutnumber.Data());
64          fCuts->SetPreSelectionCutFlag(kTRUE);
65          if(fCuts->InitializeCutsFromCutString(cutnumber.Data())){
66             fV0ReaderV1->SetConversionCuts(fCuts);
67             fCuts->SetFillCutHistograms("",kTRUE);
68          }
69       }
70       fV0ReaderV1->Init();
71
72       AliLog::SetGlobalLogLevel(AliLog::kInfo);
73
74       //connect input V0Reader
75       mgr->AddTask(fV0ReaderV1);
76       mgr->ConnectInput(fV0ReaderV1,0,cinput);
77
78    }
79
80    //================================================
81    //========= Add task to the ANALYSIS manager =====
82    //================================================
83    AliAnalysisTaskGammaConvV1 *task=NULL;
84    task= new AliAnalysisTaskGammaConvV1(Form("GammaConvV1_%i",trainConfig));
85    task->SetIsHeavyIon(1);
86    task->SetIsMC(isMC);
87    // Cut Numbers to use in Analysis
88    Int_t numberOfCuts = 4;
89
90    TString *cutarray = new TString[numberOfCuts];
91    TString *mesonCutArray = new TString[numberOfCuts];
92
93    if(trainConfig == 1){ // Standard neutral pion cuts
94       cutarray[ 0] = "3010001042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 0-5%
95       cutarray[ 1] = "3120001042092970023220000"; mesonCutArray[ 1] = "01522045009"; // 5-10%
96       cutarray[ 2] = "1010001042092970023220000"; mesonCutArray[ 2] = "01522045009"; // 0-10%
97       cutarray[ 3] = "1120001042092970023220000"; mesonCutArray[ 3] = "01522045009"; // 10-20%
98    } else if (trainConfig == 2) { // Standard neutral pion cuts
99       cutarray[ 0] = "1240001042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 20-40%
100       cutarray[ 1] = "1460001042092970023220000"; mesonCutArray[ 1] = "01522065009"; // 40-60%
101       cutarray[ 2] = "1680001042092970023220000"; mesonCutArray[ 2] = "01522065009"; // 60-80%
102       cutarray[ 3] = "1080001042092970023220000"; mesonCutArray[ 3] = "01522065009"; // 0-80%
103    } else if (trainConfig == 3) { // Standard direct photon cuts
104       cutarray[ 0] = "1020001042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-20%
105       cutarray[ 1] = "1040001042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 0-40%
106       cutarray[ 2] = "1480001042092370023700000"; mesonCutArray[ 2] = "01522065009"; // 40-80%
107       cutarray[ 3] = "1080001042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-80%
108    } else if (trainConfig == 4) { // Standard direct photon cuts
109       cutarray[ 0] = "1010001042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-10%
110       cutarray[ 1] = "1120001042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 10-20%
111       cutarray[ 2] = "1240001042092370023700000"; mesonCutArray[ 2] = "01522045009"; // 20-40%
112       cutarray[ 3] = "1090001042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-90%
113    } else if (trainConfig == 5) { // Standard neutral pion cuts only added signals
114       cutarray[ 0] = "3010002042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 0-5%
115       cutarray[ 1] = "3120002042092970023220000"; mesonCutArray[ 1] = "01522045009"; // 5-10%
116       cutarray[ 2] = "1010002042092970023220000"; mesonCutArray[ 2] = "01522045009"; // 0-10%
117       cutarray[ 3] = "1120002042092970023220000"; mesonCutArray[ 3] = "01522045009"; // 10-20%
118    } else if (trainConfig == 6) { // Standard neutral pion cuts only added signals
119       cutarray[ 0] = "1240002042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 20-40%
120       cutarray[ 1] = "1460002042092970023220000"; mesonCutArray[ 1] = "01522065009"; // 40-60%
121       cutarray[ 2] = "1680002042092970023220000"; mesonCutArray[ 2] = "01522065009"; // 60-80%
122       cutarray[ 3] = "1080002042092970023220000"; mesonCutArray[ 3] = "01522065009"; // 0-80%
123    } else if (trainConfig == 7) { // Standard direct photon cuts
124       cutarray[ 0] = "1020003042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-20%
125       cutarray[ 1] = "1040003042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 0-40%
126       cutarray[ 2] = "1480003042092370023700000"; mesonCutArray[ 2] = "01522065009"; // 40-80%
127       cutarray[ 3] = "1080003042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-80%
128    } else if (trainConfig == 8) { // Standard direct photon cuts
129       cutarray[ 0] = "1010003042092370023700000"; mesonCutArray[ 0] = "01522045009"; // 0-10%
130       cutarray[ 1] = "1120003042092370023700000"; mesonCutArray[ 1] = "01522045009"; // 10-20%
131       cutarray[ 2] = "1240003042092370023700000"; mesonCutArray[ 2] = "01522045009"; // 20-40%
132       cutarray[ 3] = "1090003042092370023700000"; mesonCutArray[ 3] = "01522045009"; // 0-90%
133    } else if(trainConfig == 9){ // Different trigger conditions
134       cutarray[ 0] = "3010001042092970023220000"; mesonCutArray[ 0] = "01522045009"; // 0-5%
135       cutarray[ 1] = "3014001042092970023220000"; mesonCutArray[ 1] = "01522045009"; // 0-5% kMB
136       cutarray[ 2] = "3015001042092970023220000"; mesonCutArray[ 2] = "01522045009"; // 0-5% kSemiCentral
137       cutarray[ 3] = "3016001042092970023220000"; mesonCutArray[ 3] = "01522045009"; // 0-5% kCentral
138       
139    } else {
140       Error(Form("GammaConvV1_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
141       return;
142    }
143
144    TList *ConvCutList = new TList();
145    TList *MesonCutList = new TList();
146
147    TList *HeaderList = new TList();
148    TObjString *Header1 = new TObjString("pi0_1");
149    HeaderList->Add(Header1);
150    TObjString *Header3 = new TObjString("eta_2");
151    HeaderList->Add(Header3);
152    
153    ConvCutList->SetOwner(kTRUE);
154    AliConversionCuts **analysisCuts = new AliConversionCuts*[numberOfCuts];
155    MesonCutList->SetOwner(kTRUE);
156    AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
157
158
159    for(Int_t i = 0; i<numberOfCuts; i++){
160       if (trainConfig == 1 ){
161          if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0005", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0005");
162          if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0510", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0510"); 
163          if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0010", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0010");
164          if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE,fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_1020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_1020");
165       } else if (trainConfig == 2){ 
166         if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_2040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_2040");
167         if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_4060", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_4060");
168         if (i==2  && doWeighting) analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_6080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_6080");
169         if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0080");
170       } else if (trainConfig == 3){
171         if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0020");
172         if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0040");
173         if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_4080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_4080");
174         if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0080");
175       } else if (trainConfig == 4){
176          if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0010", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0010");
177          if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE,fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_1020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_1020");
178          if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_2040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_2040");
179       } else if (trainConfig == 9){
180          if (doWeighting) analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0005", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0005");
181          if (i == 1) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kMB, "AliVEvent::kMB" );
182          if (i == 2) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kSemiCentral,"AliVEvent::kSemiCentral" );
183          if (i == 3) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kCentral,"AliVEvent::kCentral" );
184          
185       } 
186       analysisCuts[i] = new AliConversionCuts();
187       analysisCuts[i]->InitializeCutsFromCutString(cutarray[i].Data());
188       ConvCutList->Add(analysisCuts[i]);
189
190       analysisCuts[i]->SetFillCutHistograms("",kFALSE);
191       analysisMesonCuts[i] = new AliConversionMesonCuts();
192       analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
193       MesonCutList->Add(analysisMesonCuts[i]);
194       analysisMesonCuts[i]->SetFillCutHistograms("");
195       analysisCuts[i]->SetAcceptedHeader(HeaderList);
196    }
197
198    task->SetConversionCutList(numberOfCuts,ConvCutList);
199    task->SetMesonCutList(numberOfCuts,MesonCutList);
200    task->SetMoveParticleAccordingToVertex(kTRUE);
201    task->SetDoMesonAnalysis(kTRUE);
202    if (enableQAMesonTask) task->SetDoMesonQA(kTRUE); //Attention new switch for Pi0 QA
203    if (enableQAMesonTask) task->SetDoPhotonQA(kTRUE);  //Attention new switch small for Photon QA
204
205    //connect containers
206    AliAnalysisDataContainer *coutput =
207       mgr->CreateContainer(Form("GammaConvV1_%i",trainConfig), TList::Class(),
208                            AliAnalysisManager::kOutputContainer,Form("GammaConvV1_%i.root",trainConfig));
209
210    mgr->AddTask(task);
211    mgr->ConnectInput(task,0,cinput);
212    mgr->ConnectOutput(task,1,coutput);
213
214    return;
215
216 }