- added new task for pi0 reconstruction using purely calorimeter clusters
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / macros / AddTask_GammaCalo_pPb.C
1 void AddTask_GammaCalo_pPb(  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 enableQAClusterTask = 0, // enable additional QA task
5                               TString fileNameInputForWeighting = "MCSpectraInput.root", // path to file for weigting input
6                               Int_t doWeightingPart = 0,  //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         Printf("here \n");
49         
50         //=========  Set Cutnumber for V0Reader ================================
51         TString cutnumberPhoton = "060084001001500000000";
52         TString cutnumberEvent = "8000000";
53         Bool_t doEtaShift = kFALSE;
54         AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
55
56         //========= Add V0 Reader to  ANALYSIS manager if not yet existent =====
57         if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
58                 AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
59                 
60                 fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
61                 fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
62                 fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
63
64                 if (!mgr) {
65                         Error("AddTask_V0ReaderV1", "No analysis manager found.");
66                         return;
67                 }
68                 AliConvEventCuts *fEventCuts=NULL;
69                 if(cutnumberEvent!=""){
70                         fEventCuts= new AliConvEventCuts(cutnumberEvent.Data(),cutnumberEvent.Data());
71                         fEventCuts->SetPreSelectionCutFlag(kTRUE);
72                         if(fEventCuts->InitializeCutsFromCutString(cutnumberEvent.Data())){
73                                 fEventCuts->DoEtaShift(doEtaShift);
74                                 fV0ReaderV1->SetEventCuts(fEventCuts);
75                                 fEventCuts->SetFillCutHistograms("",kTRUE);
76                         }
77                 }
78                 // Set AnalysisCut Number
79                 AliConversionPhotonCuts *fCuts=NULL;
80                 if(cutnumberPhoton!=""){
81                         fCuts= new AliConversionPhotonCuts(cutnumberPhoton.Data(),cutnumberPhoton.Data());
82                         fCuts->SetPreSelectionCutFlag(kTRUE);
83                         fCuts->SetIsHeavyIon(isHeavyIon);
84                         if(fCuts->InitializeCutsFromCutString(cutnumberPhoton.Data())){
85                                 fV0ReaderV1->SetConversionCuts(fCuts);
86                                 fCuts->SetFillCutHistograms("",kTRUE);
87                         }
88                 }
89                 if(inputHandler->IsA()==AliAODInputHandler::Class()){
90                 // AOD mode
91                         fV0ReaderV1->SetDeltaAODBranchName(Form("GammaConv_%s_gamma",cutnumberAODBranch.Data()));
92                 }
93                 fV0ReaderV1->Init();
94
95                 AliLog::SetGlobalLogLevel(AliLog::kFatal);
96
97                 //connect input V0Reader
98                 mgr->AddTask(fV0ReaderV1);
99                 mgr->ConnectInput(fV0ReaderV1,0,cinput);
100         }
101
102         //================================================
103         //========= Add task to the ANALYSIS manager =====
104         //================================================
105         AliAnalysisTaskGammaCalo *task=NULL;
106         task= new AliAnalysisTaskGammaCalo(Form("GammaCalo_%i",trainConfig));
107         task->SetIsHeavyIon(isHeavyIon);
108         task->SetIsMC(isMC);
109         // Cut Numbers to use in Analysis
110         Int_t numberOfCuts = 2;
111         if (trainConfig==3 || trainConfig==5  ){ numberOfCuts =6;}
112         if (trainConfig==6   ){ numberOfCuts =5;}
113         
114         TString *eventCutArray = new TString[numberOfCuts];
115         TString *clusterCutArray = new TString[numberOfCuts];
116         TString *mesonCutArray = new TString[numberOfCuts];
117
118         // cluster cuts
119         // 0 "ClusterType",  1 "EtaMin", 2 "EtaMax", 3 "PhiMin", 4 "PhiMax", 5 "DistanceToBadChannel", 6 "Timing", 7 "TrackMatching", 8 "ExoticCell",
120         // 9 "MinEnergy", 10 "MinNCells", 11 "MinM02", 12 "MaxM02", 13 "MinM20", 14 "MaxM20", 15 "MaximumDispersion", 16 "NLM"
121         
122         if (trainConfig == 1){ 
123                 eventCutArray[ 0] = "8000001"; clusterCutArray[0] = "10000040022030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kINT7 // EMCAL clusters
124                 eventCutArray[ 1] = "8005201"; clusterCutArray[1] = "10000040022030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters
125         } else if (trainConfig == 2) {  
126                 eventCutArray[ 0] = "8000001"; clusterCutArray[0] = "20000030022000000"; mesonCutArray[0] = "01525065000000"; //standart cut, kINT7 // PHOS clusters
127                 eventCutArray[ 1] = "8006201"; clusterCutArray[1] = "20000030022000000"; mesonCutArray[1] = "01525065000000"; //standard cut, kPHI7     // PHOS clusters        
128         } else if (trainConfig == 3){ 
129                 eventCutArray[ 0] = "8008101"; clusterCutArray[0] = "10000040022030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kEMCEGA based on INT7 // EMCAL clusters
130                 eventCutArray[ 1] = "8008301"; clusterCutArray[1] = "10000040022030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMCEG1 based on INT7 // EMCAL clusters
131                 eventCutArray[ 2] = "8008501"; clusterCutArray[2] = "10000040022030000"; mesonCutArray[2] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters
132                 eventCutArray[ 3] = "8009101"; clusterCutArray[3] = "10000040022030000"; mesonCutArray[3] = "01525065000000"; //standard cut, kEMCEJE based on INT7 // EMCAL clusters
133                 eventCutArray[ 4] = "8009301"; clusterCutArray[4] = "10000040022030000"; mesonCutArray[4] = "01525065000000"; //standard cut, kEMCEJ1 based on INT7 // EMCAL clusters
134                 eventCutArray[ 5] = "8009501"; clusterCutArray[5] = "10000040022030000"; mesonCutArray[5] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters
135         } else if (trainConfig == 4){ 
136                 eventCutArray[ 0] = "8000001"; clusterCutArray[0] = "10000040052030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kINT7 // EMCAL clusters
137                 eventCutArray[ 1] = "8005201"; clusterCutArray[1] = "10000040052030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters   
138         } else if (trainConfig == 5){ 
139                 eventCutArray[ 0] = "8008101"; clusterCutArray[0] = "10000040052030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kEMCEGA based on INT7 // EMCAL clusters
140                 eventCutArray[ 1] = "8008301"; clusterCutArray[1] = "10000040052030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMCEG1 based on INT7 // EMCAL clusters
141                 eventCutArray[ 2] = "8008501"; clusterCutArray[2] = "10000040052030000"; mesonCutArray[2] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters
142                 eventCutArray[ 3] = "8009101"; clusterCutArray[3] = "10000040052030000"; mesonCutArray[3] = "01525065000000"; //standard cut, kEMCEJE based on INT7 // EMCAL clusters
143                 eventCutArray[ 4] = "8009301"; clusterCutArray[4] = "10000040052030000"; mesonCutArray[4] = "01525065000000"; //standard cut, kEMCEJ1 based on INT7 // EMCAL clusters
144                 eventCutArray[ 5] = "8009501"; clusterCutArray[5] = "10000040052030000"; mesonCutArray[5] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters           
145         } else if (trainConfig == 6){ 
146                 eventCutArray[ 0] = "8000001"; clusterCutArray[0] = "10000043052030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kINT7 // EMCAL clusters
147                 eventCutArray[ 1] = "8000001"; clusterCutArray[1] = "10000044052030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters   
148                 eventCutArray[ 2] = "8000001"; clusterCutArray[2] = "10000045052030000"; mesonCutArray[2] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters   
149                 eventCutArray[ 3] = "8000001"; clusterCutArray[3] = "10000046052030000"; mesonCutArray[3] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters   
150                 eventCutArray[ 4] = "8000001"; clusterCutArray[4] = "10000047052030000"; mesonCutArray[4] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters   
151         } else {
152                 Error(Form("GammaCalo_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
153                 return;
154         }
155
156         TList *EventCutList = new TList();
157         TList *ClusterCutList = new TList();
158         TList *MesonCutList = new TList();
159
160         TList *HeaderList = new TList();
161         if (doWeightingPart==1) {
162                 TObjString *Header1 = new TObjString("pi0_1");
163                 HeaderList->Add(Header1);
164         }
165         if (doWeightingPart==2){
166                 TObjString *Header3 = new TObjString("eta_2");
167                 HeaderList->Add(Header3);
168         }
169         if (doWeightingPart==3) {
170                 TObjString *Header1 = new TObjString("pi0_1");
171                 HeaderList->Add(Header1);
172                 TObjString *Header3 = new TObjString("eta_2");
173                 HeaderList->Add(Header3);
174         }
175
176         EventCutList->SetOwner(kTRUE);
177         AliConvEventCuts **analysisEventCuts = new AliConvEventCuts*[numberOfCuts];
178         ClusterCutList->SetOwner(kTRUE);
179         AliCaloPhotonCuts **analysisClusterCuts = new AliCaloPhotonCuts*[numberOfCuts];
180         MesonCutList->SetOwner(kTRUE);
181         AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
182
183         for(Int_t i = 0; i<numberOfCuts; i++){
184                 analysisEventCuts[i] = new AliConvEventCuts();   
185                 analysisEventCuts[i]->InitializeCutsFromCutString(eventCutArray[i].Data());
186                 EventCutList->Add(analysisEventCuts[i]);
187                 analysisEventCuts[i]->SetFillCutHistograms("",kFALSE);
188                         
189                 analysisClusterCuts[i] = new AliCaloPhotonCuts();
190                 analysisClusterCuts[i]->InitializeCutsFromCutString(clusterCutArray[i].Data());
191                 ClusterCutList->Add(analysisClusterCuts[i]);
192                 analysisClusterCuts[i]->SetFillCutHistograms("");
193                 
194                 analysisMesonCuts[i] = new AliConversionMesonCuts();
195                 analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
196                 MesonCutList->Add(analysisMesonCuts[i]);
197                 analysisMesonCuts[i]->SetFillCutHistograms("");
198                 analysisEventCuts[i]->SetAcceptedHeader(HeaderList);
199         }
200         task->SetEventCutList(numberOfCuts,EventCutList);
201         task->SetCaloCutList(numberOfCuts,ClusterCutList);
202         task->SetMesonCutList(numberOfCuts,MesonCutList);
203         task->SetDoMesonAnalysis(kTRUE);
204         task->SetDoMesonQA(enableQAMesonTask); //Attention new switch for Pi0 QA
205         task->SetDoClusterQA(enableQAClusterTask);  //Attention new switch small for Cluster QA
206
207         //connect containers
208         AliAnalysisDataContainer *coutput =
209                 mgr->CreateContainer(Form("GammaCalo_%i",trainConfig), TList::Class(),
210                                                         AliAnalysisManager::kOutputContainer,Form("GammaCalo_%i.root",trainConfig));
211
212         mgr->AddTask(task);
213         mgr->ConnectInput(task,0,cinput);
214         mgr->ConnectOutput(task,1,coutput);
215
216         return;
217
218 }