90abf9e211ebe8d59f3d5ac71d6ff640e65490ae
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / macros / AddTask_GammaConvV1_pPb2.C
1 void AddTask_GammaConvV1_pPb2(  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 generatorName = "DPMJET",
8                               TString cutnumberAODBranch = "8000000060084000001500000" // cutnumber for AOD branch
9                            ) {
10  
11         // ================= Load Librariers =================================
12         gSystem->Load("libCore.so");  
13         gSystem->Load("libTree.so");
14         gSystem->Load("libGeom.so");
15         gSystem->Load("libVMC.so");
16         gSystem->Load("libPhysics.so");
17         gSystem->Load("libMinuit");
18         gSystem->Load("libSTEERBase");
19         gSystem->Load("libESD");
20         gSystem->Load("libAOD");
21         gSystem->Load("libANALYSIS");
22         gSystem->Load("libANALYSISalice");  
23         gSystem->Load("libPWGGAGammaConv.so");
24         gSystem->Load("libCDB.so");
25         gSystem->Load("libSTEER.so");
26         gSystem->Load("libSTEERBase.so");
27         gSystem->Load("libTENDER.so");
28         gSystem->Load("libTENDERSupplies.so");
29      
30         Int_t isHeavyIon = 2;
31                 
32         // ================== GetAnalysisManager ===============================
33         AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
34         if (!mgr) {
35                 Error(Form("AddTask_GammaConvV1_%i",trainConfig), "No analysis manager found.");
36                 return ;
37         }
38         
39         // ================== GetInputEventHandler =============================
40         AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
41         
42         //========= Add PID Reponse to ANALYSIS manager ====
43         if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
44                 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
45                 AddTaskPIDResponse(isMC);
46         }
47         
48         //=========  Set Cutnumber for V0Reader ================================
49         TString cutnumberPhoton = "060084001001500000000";
50         TString cutnumberEvent = "8000000";
51         Bool_t doEtaShift = kFALSE;
52         AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
53         //========= Add V0 Reader to  ANALYSIS manager if not yet existent =====
54         if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
55                 AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
56                 
57                 fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
58                 fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
59                 fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
60                 
61                 if (!mgr) {
62                         Error("AddTask_V0ReaderV1", "No analysis manager found.");
63                         return;
64                 }
65         
66                 AliConvEventCuts *fEventCuts=NULL;
67                 if(cutnumberEvent!=""){
68                         fEventCuts= new AliConvEventCuts(cutnumberEvent.Data(),cutnumberEvent.Data());
69                         fEventCuts->SetPreSelectionCutFlag(kTRUE);
70                         if(fEventCuts->InitializeCutsFromCutString(cutnumberEvent.Data())){
71                                 fEventCuts->DoEtaShift(doEtaShift);
72                                 fV0ReaderV1->SetEventCuts(fEventCuts);
73                                 fEventCuts->SetFillCutHistograms("",kTRUE);
74                         }
75                 }
76
77                 // Set AnalysisCut Number
78                 AliConversionPhotonCuts *fCuts=NULL;
79                 if(cutnumberPhoton!=""){
80                         fCuts= new AliConversionPhotonCuts(cutnumberPhoton.Data(),cutnumberPhoton.Data());
81                         fCuts->SetPreSelectionCutFlag(kTRUE);
82                         fCuts->SetIsHeavyIon(isHeavyIon);
83                         if(fCuts->InitializeCutsFromCutString(cutnumberPhoton.Data())){
84                                 fV0ReaderV1->SetConversionCuts(fCuts);
85                                 fCuts->SetFillCutHistograms("",kTRUE);
86                         }
87                 }
88                 if(inputHandler->IsA()==AliAODInputHandler::Class()){
89                 // AOD mode
90                         cout << "AOD handler: adding " << cutnumberAODBranch.Data() << " as conversion branch" << endl;
91                         fV0ReaderV1->SetDeltaAODBranchName(Form("GammaConv_%s_gamma",cutnumberAODBranch.Data()));
92                 }
93                 fV0ReaderV1->Init();
94         
95                 AliLog::SetGlobalLogLevel(AliLog::kInfo);
96         
97                 //connect input V0Reader
98                 mgr->AddTask(fV0ReaderV1);
99                 mgr->ConnectInput(fV0ReaderV1,0,cinput);
100         
101         }
102         
103         //================================================
104         //========= Add task to the ANALYSIS manager =====
105         //================================================
106         //            find input container
107         AliAnalysisTaskGammaConvV1 *task=NULL;
108         task= new AliAnalysisTaskGammaConvV1(Form("GammaConvV1_%i",trainConfig));
109         task->SetIsHeavyIon(isHeavyIon);
110         task->SetIsMC(isMC);
111         // Cut Numbers to use in Analysis
112         Int_t numberOfCuts = 1;
113         
114         TString *eventCutArray = new TString[numberOfCuts];
115         TString *photonCutArray = new TString[numberOfCuts];
116         TString *mesonCutArray = new TString[numberOfCuts];
117         Bool_t doEtaShiftIndCuts = kFALSE;
118         TString stringShift = "";
119         
120         if(trainConfig == 1){
121                 eventCutArray[ 0] = "8000011"; photonCutArray[ 0] = "002093172003290000000"; mesonCutArray[ 0] = "01621035009000"; 
122         } else if (trainConfig == 2) {
123                 eventCutArray[ 0] = "8000011"; photonCutArray[ 0] = "002092170008260400000"; mesonCutArray[ 0] = "01621035009000";
124         } else if (trainConfig == 3) {   
125                 eventCutArray[ 0] = "8020011"; photonCutArray[ 0] = "002092170008260400000"; mesonCutArray[ 0] = "01621035009000";      
126         } else if (trainConfig == 4) {   
127                 eventCutArray[ 0] = "8240011"; photonCutArray[ 0] = "002092170008260400000"; mesonCutArray[ 0] = "01621035009000";         
128         } else if (trainConfig == 5) {   
129                 eventCutArray[ 0] = "8460011"; photonCutArray[ 0] = "002092170008260400000"; mesonCutArray[ 0] = "01621035009000";         
130         } else if (trainConfig == 6) {   
131                 eventCutArray[ 0] = "8680011"; photonCutArray[ 0] = "002092170008260400000"; mesonCutArray[ 0] = "01621035009000";      
132         } else if (trainConfig == 7) {   
133                 eventCutArray[ 0] = "8600011"; photonCutArray[ 0] = "002092170008260400000"; mesonCutArray[ 0] = "01621035009000";         
134         } else if (trainConfig == 8) {   
135                 eventCutArray[ 0] = "8000011"; photonCutArray[ 0] = "009092170008260400000"; mesonCutArray[ 0] = "01621035009000";    //RCut 7.5cm   
136         } else if (trainConfig == 9) {   
137                 eventCutArray[ 0] = "8000011"; photonCutArray[ 0] = "005092170008260400000"; mesonCutArray[ 0] = "01621035009000";    //RCut 10cm     
138         } else if (trainConfig == 10) {   
139                 eventCutArray[ 0] = "8000011"; photonCutArray[ 0] = "008092170008260400000"; mesonCutArray[ 0] = "01621035009000";    //RCut 12.5cm    
140         } else if (trainConfig == 11) {   
141                 eventCutArray[ 0] = "8000011"; photonCutArray[ 0] = "006092170008260400000"; mesonCutArray[ 0] = "01621035009000";    //RCut 20cm    
142         } else if (trainConfig == 12) {   
143                 eventCutArray[ 0] = "8000011"; photonCutArray[ 0] = "007092170008260400000"; mesonCutArray[ 0] = "01621035009000";    //RCut 35cm    
144         } else {
145                 Error(Form("GammaConvV1_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
146                 return;
147         }
148         
149         TList *EventCutList = new TList();
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         EventCutList->SetOwner(kTRUE);
160         AliConvEventCuts **analysisEventCuts = new AliConvEventCuts*[numberOfCuts];
161         ConvCutList->SetOwner(kTRUE);
162         AliConversionPhotonCuts **analysisCuts = new AliConversionPhotonCuts*[numberOfCuts];
163         MesonCutList->SetOwner(kTRUE);
164         AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
165         
166         
167         for(Int_t i = 0; i<numberOfCuts; i++){  
168                 analysisEventCuts[i] = new AliConvEventCuts();   
169                 analysisEventCuts[i]->InitializeCutsFromCutString(eventCutArray[i].Data());
170                 if (doEtaShiftIndCuts) {
171                         analysisEventCuts[i]->DoEtaShift(doEtaShiftIndCuts);
172                         analysisEventCuts[i]->SetEtaShift(stringShift);
173                 }
174                 EventCutList->Add(analysisEventCuts[i]);
175                 analysisEventCuts[i]->SetFillCutHistograms("",kFALSE);
176                 
177                 analysisCuts[i] = new AliConversionPhotonCuts();
178                 analysisCuts[i]->InitializeCutsFromCutString(photonCutArray[i].Data());
179                 analysisCuts[i]->SetIsHeavyIon(isHeavyIon);
180                 ConvCutList->Add(analysisCuts[i]);
181                 analysisCuts[i]->SetFillCutHistograms("",kFALSE);
182
183                 analysisMesonCuts[i] = new AliConversionMesonCuts();
184                 analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
185                 MesonCutList->Add(analysisMesonCuts[i]);
186                 analysisMesonCuts[i]->SetFillCutHistograms("");
187                 analysisEventCuts[i]->SetAcceptedHeader(HeaderList);
188         }
189         
190         task->SetEventCutList(numberOfCuts,EventCutList);
191         task->SetConversionCutList(numberOfCuts,ConvCutList);
192         task->SetMesonCutList(numberOfCuts,MesonCutList);
193         task->SetMoveParticleAccordingToVertex(kTRUE);
194         task->SetDoMesonAnalysis(kTRUE);
195         task->SetDoMesonQA(enableQAMesonTask); //Attention new switch for Pi0 QA
196         task->SetDoPhotonQA(enableQAPhotonTask);  //Attention new switch small for Photon QA
197         
198         //connect containers
199         AliAnalysisDataContainer *coutput =
200                 mgr->CreateContainer(Form("GammaConvV1_%i",trainConfig), TList::Class(),
201                                                         AliAnalysisManager::kOutputContainer,Form("GammaConvV1_%i.root",trainConfig));
202         
203         mgr->AddTask(task);
204         mgr->ConnectInput(task,0,cinput);
205         mgr->ConnectOutput(task,1,coutput);
206         
207         return;
208  
209 }