updated GammaConv software to estimate pileup
[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 = "100000000008400100150000000"; 
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] = "301000104209297002322000000"; mesonCutArray[ 0] = "01522045009000"; // 0-5%
101       cutarray[ 1] = "312000104209297002322000000"; mesonCutArray[ 1] = "01522045009000"; // 5-10%
102       cutarray[ 2] = "101000104209297002322000000"; mesonCutArray[ 2] = "01522045009000"; // 0-10%
103       cutarray[ 3] = "112000104209297002322000000"; mesonCutArray[ 3] = "01522045009000"; // 10-20%
104    } else if (trainConfig == 2) { // Standard neutral pion cuts
105       cutarray[ 0] = "124000104209297002322000000"; mesonCutArray[ 0] = "01522045009000"; // 20-40%
106       cutarray[ 1] = "146000104209297002322000000"; mesonCutArray[ 1] = "01522065009000"; // 40-60%
107       cutarray[ 2] = "168000104209297002322000000"; mesonCutArray[ 2] = "01522065009000"; // 60-80%
108       cutarray[ 3] = "108000104209297002322000000"; mesonCutArray[ 3] = "01522065009000"; // 0-80%
109    } else if (trainConfig == 3) { // Standard direct photon cuts
110       cutarray[ 0] = "102000104209237002370000000"; mesonCutArray[ 0] = "01522045009000"; // 0-20%
111       cutarray[ 1] = "104000104209237002370000000"; mesonCutArray[ 1] = "01522045009000"; // 0-40%
112       cutarray[ 2] = "148000104209237002370000000"; mesonCutArray[ 2] = "01522065009000"; // 40-80%
113       cutarray[ 3] = "108000104209237002370000000"; mesonCutArray[ 3] = "01522045009000"; // 0-80%
114    } else if (trainConfig == 4) { // Standard direct photon cuts
115       cutarray[ 0] = "101000104209237002370000000"; mesonCutArray[ 0] = "01522045009000"; // 0-10%
116       cutarray[ 1] = "112000104209237002370000000"; mesonCutArray[ 1] = "01522045009000"; // 10-20%
117       cutarray[ 2] = "124000104209237002370000000"; mesonCutArray[ 2] = "01522045009000"; // 20-40%
118       cutarray[ 3] = "109000104209237002370000000"; mesonCutArray[ 3] = "01522045009000"; // 0-90%
119    } else if (trainConfig == 5) { // Standard neutral pion cuts only added signals
120       cutarray[ 0] = "301000204209297002322000000"; mesonCutArray[ 0] = "01522045009000"; // 0-5%
121       cutarray[ 1] = "312000204209297002322000000"; mesonCutArray[ 1] = "01522045009000"; // 5-10%
122       cutarray[ 2] = "101000204209297002322000000"; mesonCutArray[ 2] = "01522045009000"; // 0-10%
123       cutarray[ 3] = "112000204209297002322000000"; mesonCutArray[ 3] = "01522045009000"; // 10-20%
124    } else if (trainConfig == 6) { // Standard neutral pion cuts only added signals
125       cutarray[ 0] = "124000204209297002322000000"; mesonCutArray[ 0] = "01522045009000"; // 20-40%
126       cutarray[ 1] = "146000204209297002322000000"; mesonCutArray[ 1] = "01522065009000"; // 40-60%
127       cutarray[ 2] = "168000204209297002322000000"; mesonCutArray[ 2] = "01522065009000"; // 60-80%
128       cutarray[ 3] = "108000204209297002322000000"; mesonCutArray[ 3] = "01522065009000"; // 0-80%
129    } else if (trainConfig == 7) { // Standard direct photon cuts
130       cutarray[ 0] = "102000304209237002370000000"; mesonCutArray[ 0] = "01522045009000"; // 0-20%
131       cutarray[ 1] = "104000304209237002370000000"; mesonCutArray[ 1] = "01522045009000"; // 0-40%
132       cutarray[ 2] = "148000304209237002370000000"; mesonCutArray[ 2] = "01522065009000"; // 40-80%
133       cutarray[ 3] = "108000304209237002370000000"; mesonCutArray[ 3] = "01522045009000"; // 0-80%
134    } else if (trainConfig == 8) { // Standard direct photon cuts
135       cutarray[ 0] = "101000304209237002370000000"; mesonCutArray[ 0] = "01522045009000"; // 0-10%
136       cutarray[ 1] = "112000304209237002370000000"; mesonCutArray[ 1] = "01522045009000"; // 10-20%
137       cutarray[ 2] = "124000304209237002370000000"; mesonCutArray[ 2] = "01522045009000"; // 20-40%
138       cutarray[ 3] = "109000304209237002370000000"; mesonCutArray[ 3] = "01522045009000"; // 0-90%
139    } else if(trainConfig == 9){ // Different trigger conditions
140       cutarray[ 0] = "301000104209297002322000000"; mesonCutArray[ 0] = "01522045009000"; // 0-5%
141       cutarray[ 1] = "301400104209297002322000000"; mesonCutArray[ 1] = "01522045009000"; // 0-5% kMB
142       cutarray[ 2] = "301500104209297002322000000"; mesonCutArray[ 2] = "01522045009000"; // 0-5% kSemiCentral
143       cutarray[ 3] = "301600104209297002322000000"; mesonCutArray[ 3] = "01522045009000"; // 0-5% kCentral
144    } else if (trainConfig == 10) { // Standard direct photon cuts
145       cutarray[ 0] = "102000204209237002370000000"; mesonCutArray[ 0] = "01522045009000"; // 0-20%
146       cutarray[ 1] = "104000204209237002370000000"; mesonCutArray[ 1] = "01522045009000"; // 0-40%
147       cutarray[ 2] = "148000204209237002370000000"; mesonCutArray[ 2] = "01522065009000"; // 40-80%
148       cutarray[ 3] = "108000204209237002370000000"; mesonCutArray[ 3] = "01522045009000"; // 0-80%
149    } else if (trainConfig == 11) { // Standard direct photon cuts
150       cutarray[ 0] = "101000204209237002370000000"; mesonCutArray[ 0] = "01522045009000"; // 0-10%
151       cutarray[ 1] = "112000204209237002370000000"; mesonCutArray[ 1] = "01522045009000"; // 10-20%
152       cutarray[ 2] = "124000204209237002370000000"; mesonCutArray[ 2] = "01522045009000"; // 20-40%
153       cutarray[ 3] = "109000204209237002370000000"; mesonCutArray[ 3] = "01522045009000"; // 0-90%   
154    } else {
155       Error(Form("GammaConvV1_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
156       return;
157    }
158
159    TList *ConvCutList = new TList();
160    TList *MesonCutList = new TList();
161
162    TList *HeaderList = new TList();
163    TObjString *Header1 = new TObjString("pi0_1");
164    HeaderList->Add(Header1);
165    TObjString *Header3 = new TObjString("eta_2");
166    HeaderList->Add(Header3);
167    
168    ConvCutList->SetOwner(kTRUE);
169    AliConversionCuts **analysisCuts = new AliConversionCuts*[numberOfCuts];
170    MesonCutList->SetOwner(kTRUE);
171    AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
172
173
174    for(Int_t i = 0; i<numberOfCuts; i++){
175       if (trainConfig == 1 ){
176          if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0005", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0005");
177          if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0510", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0510"); 
178          if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0010", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0010");
179          if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE,fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_1020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_1020");
180       } else if (trainConfig == 2){ 
181         if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_2040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_2040");
182         if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_4060", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_4060");
183         if (i==2  && doWeighting) analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_6080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_6080");
184         if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0080");
185       } else if (trainConfig == 3){
186         if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0020");
187         if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0040");
188         if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_4080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_4080");
189         if (i == 3 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0080", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0080");
190       } else if (trainConfig == 4){
191          if (i == 0 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0010", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0010");
192          if (i == 1 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE,fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_1020", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_1020");
193          if (i == 2 && doWeighting)  analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_2040", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_2040");
194       } else if (trainConfig == 9){
195          if (doWeighting) analysisCuts[i]->SetUseReweightingWithHistogramFromFile(kTRUE, kFALSE, kTRUE, fileNameInputForWeighting, "Pi0_Hijing_PbPb_2760GeV_0005", "", "K0s_RatioDataToMC_Hijing_PbPb_2760GeV_0005");
196          if (i == 1) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kMB, "AliVEvent::kMB" );
197          if (i == 2) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kSemiCentral,"AliVEvent::kSemiCentral" );
198          if (i == 3) analysisCuts[i]->SelectSpecialTrigger(AliVEvent::kCentral,"AliVEvent::kCentral" );
199          
200       } 
201       analysisCuts[i] = new AliConversionCuts();
202       analysisCuts[i]->InitializeCutsFromCutString(cutarray[i].Data());
203       ConvCutList->Add(analysisCuts[i]);
204
205       analysisCuts[i]->SetFillCutHistograms("",kFALSE);
206       analysisMesonCuts[i] = new AliConversionMesonCuts();
207       analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
208       MesonCutList->Add(analysisMesonCuts[i]);
209       analysisMesonCuts[i]->SetFillCutHistograms("");
210       analysisCuts[i]->SetAcceptedHeader(HeaderList);
211    }
212
213    task->SetConversionCutList(numberOfCuts,ConvCutList);
214    task->SetMesonCutList(numberOfCuts,MesonCutList);
215    task->SetMoveParticleAccordingToVertex(kTRUE);
216    task->SetDoMesonAnalysis(kTRUE);
217    if (enableQAMesonTask) task->SetDoMesonQA(kTRUE); //Attention new switch for Pi0 QA
218    if (enableQAMesonTask) task->SetDoPhotonQA(kTRUE);  //Attention new switch small for Photon QA
219
220    //connect containers
221    AliAnalysisDataContainer *coutput =
222       mgr->CreateContainer(Form("GammaConvV1_%i",trainConfig), TList::Class(),
223                            AliAnalysisManager::kOutputContainer,Form("GammaConvV1_%i.root",trainConfig));
224
225    mgr->AddTask(task);
226    mgr->ConnectInput(task,0,cinput);
227    mgr->ConnectOutput(task,1,coutput);
228
229    return;
230
231 }