bugfixes + extended track matching histograms
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / macros / AddTask_GammaConvCalo_pPb.C
1 void AddTask_GammaConvCalo_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 enableQAPhotonTask = 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                               Bool_t enableExtendedMatching = kFALSE //enable or disable extended matching histograms for conversion electrons <-> cluster
10                                                         ) {
11
12         // ================= Load Librariers =================================
13         gSystem->Load("libCore.so");  
14         gSystem->Load("libTree.so");
15         gSystem->Load("libGeom.so");
16         gSystem->Load("libVMC.so");
17         gSystem->Load("libPhysics.so");
18         gSystem->Load("libMinuit");
19         gSystem->Load("libSTEERBase");
20         gSystem->Load("libESD");
21         gSystem->Load("libAOD");
22         gSystem->Load("libANALYSIS");
23         gSystem->Load("libANALYSISalice");  
24         gSystem->Load("libPWGGAGammaConv.so");
25         gSystem->Load("libCDB.so");
26         gSystem->Load("libSTEER.so");
27         gSystem->Load("libSTEERBase.so");
28         gSystem->Load("libTENDER.so");
29         gSystem->Load("libTENDERSupplies.so");
30                 
31         Int_t isHeavyIon = 2;
32         
33         // ================== GetAnalysisManager ===============================
34         AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
35         if (!mgr) {
36                 Error(Form("AddTask_GammaConvV1_%i",trainConfig), "No analysis manager found.");
37                 return ;
38         }
39
40         // ================== GetInputEventHandler =============================
41         AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
42         
43         //========= Add PID Reponse to ANALYSIS manager ====
44         if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
45                 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
46                 AddTaskPIDResponse(isMC);
47         }
48         
49         Printf("here \n");
50         
51         //=========  Set Cutnumber for V0Reader ================================
52         TString cutnumberPhoton = "060084001001500000000";
53         TString cutnumberEvent = "8000000";
54         Bool_t doEtaShift = kFALSE;
55         AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
56
57         //========= Add V0 Reader to  ANALYSIS manager if not yet existent =====
58         if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
59                 AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
60                 
61                 fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
62                 fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
63                 fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
64
65                 if (!mgr) {
66                         Error("AddTask_V0ReaderV1", "No analysis manager found.");
67                         return;
68                 }
69
70                 AliConvEventCuts *fEventCuts=NULL;
71                 if(cutnumberEvent!=""){
72                         fEventCuts= new AliConvEventCuts(cutnumberEvent.Data(),cutnumberEvent.Data());
73                         fEventCuts->SetPreSelectionCutFlag(kTRUE);
74                         if(fEventCuts->InitializeCutsFromCutString(cutnumberEvent.Data())){
75                                 fEventCuts->DoEtaShift(doEtaShift);
76                                 fV0ReaderV1->SetEventCuts(fEventCuts);
77                                 fEventCuts->SetFillCutHistograms("",kTRUE);
78                         }
79                 }
80
81                 // Set AnalysisCut Number
82                 AliConversionPhotonCuts *fCuts=NULL;
83                 if(cutnumberPhoton!=""){
84                         fCuts= new AliConversionPhotonCuts(cutnumberPhoton.Data(),cutnumberPhoton.Data());
85                         fCuts->SetPreSelectionCutFlag(kTRUE);
86                         fCuts->SetIsHeavyIon(isHeavyIon);
87                         if(fCuts->InitializeCutsFromCutString(cutnumberPhoton.Data())){
88                                 fV0ReaderV1->SetConversionCuts(fCuts);
89                                 fCuts->SetFillCutHistograms("",kTRUE);
90                         }
91                 }
92                 if(inputHandler->IsA()==AliAODInputHandler::Class()){
93                 // AOD mode
94                         fV0ReaderV1->SetDeltaAODBranchName(Form("GammaConv_%s_gamma",cutnumberAODBranch.Data()));
95                 }
96                 fV0ReaderV1->Init();
97
98                 AliLog::SetGlobalLogLevel(AliLog::kFatal);
99
100                 //connect input V0Reader
101                 mgr->AddTask(fV0ReaderV1);
102                 mgr->ConnectInput(fV0ReaderV1,0,cinput);
103
104         }
105
106         //================================================
107         //========= Add task to the ANALYSIS manager =====
108         //================================================
109         AliAnalysisTaskGammaConvCalo *task=NULL;
110         task= new AliAnalysisTaskGammaConvCalo(Form("GammaConvCalo_%i",trainConfig));
111         task->SetIsHeavyIon(isHeavyIon);
112         task->SetIsMC(isMC);
113         // Cut Numbers to use in Analysis
114         Int_t numberOfCuts = 2;
115         if (trainConfig==3 || trainConfig==5  ){ numberOfCuts =6;}
116         if (trainConfig==6 || trainConfig==7  ){ numberOfCuts =5;}
117         
118         TString *eventCutArray = new TString[numberOfCuts];
119         TString *photonCutArray = new TString[numberOfCuts];
120         TString *clusterCutArray = new TString[numberOfCuts];
121         TString *mesonCutArray = new TString[numberOfCuts];
122
123         // cluster cuts
124         // 0 "ClusterType",  1 "EtaMin", 2 "EtaMax", 3 "PhiMin", 4 "PhiMax", 5 "DistanceToBadChannel", 6 "Timing", 7 "TrackMatching", 8 "ExoticCell",
125         // 9 "MinEnergy", 10 "MinNCells", 11 "MinM02", 12 "MaxM02", 13 "MinM20", 14 "MaxM20", 15 "MaximumDispersion", 16 "NLM"
126         
127         if (trainConfig == 1){ 
128                 eventCutArray[ 0] = "8000001"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "10000040022030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kINT7 // EMCAL clusters
129                 eventCutArray[ 1] = "8005201"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "10000040022030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters
130         } else if (trainConfig == 2) {  
131                 eventCutArray[ 0] = "8000001"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "20000030022000000"; mesonCutArray[0] = "01525065000000"; //standart cut, kINT7 // PHOS clusters
132                 eventCutArray[ 1] = "8006201"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "20000030022000000"; mesonCutArray[1] = "01525065000000"; //standard cut, kPHI7       // PHOS clusters        
133         } else if (trainConfig == 3){ 
134                 eventCutArray[ 0] = "8008101"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "10000040022030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kEMCEGA based on INT7 // EMCAL clusters
135                 eventCutArray[ 1] = "8008301"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "10000040022030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMCEG1 based on INT7 // EMCAL clusters
136                 eventCutArray[ 2] = "8008501"; photonCutArray[ 2] = "002092970028250400000"; clusterCutArray[2] = "10000040022030000"; mesonCutArray[2] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters
137                 eventCutArray[ 3] = "8009101"; photonCutArray[ 3] = "002092970028250400000"; clusterCutArray[3] = "10000040022030000"; mesonCutArray[3] = "01525065000000"; //standard cut, kEMCEJE based on INT7 // EMCAL clusters
138                 eventCutArray[ 4] = "8009301"; photonCutArray[ 4] = "002092970028250400000"; clusterCutArray[4] = "10000040022030000"; mesonCutArray[4] = "01525065000000"; //standard cut, kEMCEJ1 based on INT7 // EMCAL clusters
139                 eventCutArray[ 5] = "8009501"; photonCutArray[ 5] = "002092970028250400000"; clusterCutArray[5] = "10000040022030000"; mesonCutArray[5] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters
140         } else if (trainConfig == 4){ 
141                 eventCutArray[ 0] = "8000001"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "10000040052030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kINT7 // EMCAL clusters
142                 eventCutArray[ 1] = "8005201"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "10000040052030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMC7 // EMCAL clusters     
143         } else if (trainConfig == 5){ 
144                 eventCutArray[ 0] = "8008101"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "10000040052030000"; mesonCutArray[0] = "01525065000000"; //standart cut, kEMCEGA based on INT7 // EMCAL clusters
145                 eventCutArray[ 1] = "8008301"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "10000040052030000"; mesonCutArray[1] = "01525065000000"; //standard cut, kEMCEG1 based on INT7 // EMCAL clusters
146                 eventCutArray[ 2] = "8008501"; photonCutArray[ 2] = "002092970028250400000"; clusterCutArray[2] = "10000040052030000"; mesonCutArray[2] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters
147                 eventCutArray[ 3] = "8009101"; photonCutArray[ 3] = "002092970028250400000"; clusterCutArray[3] = "10000040052030000"; mesonCutArray[3] = "01525065000000"; //standard cut, kEMCEJE based on INT7 // EMCAL clusters
148                 eventCutArray[ 4] = "8009301"; photonCutArray[ 4] = "002092970028250400000"; clusterCutArray[4] = "10000040052030000"; mesonCutArray[4] = "01525065000000"; //standard cut, kEMCEJ1 based on INT7 // EMCAL clusters
149                 eventCutArray[ 5] = "8009501"; photonCutArray[ 5] = "002092970028250400000"; clusterCutArray[5] = "10000040052030000"; mesonCutArray[5] = "01525065000000"; //standard cut, kEMCEG2 based on INT7 // EMCAL clusters             
150         } else if (trainConfig == 6){ //EMCAL
151                 eventCutArray[ 0] = "8000001"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "10000041052030000"; mesonCutArray[0] = "01525065000000"; 
152                 eventCutArray[ 1] = "8000001"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "10000042052030000"; mesonCutArray[1] = "01525065000000"; 
153                 eventCutArray[ 2] = "8000001"; photonCutArray[ 2] = "002092970028250400000"; clusterCutArray[2] = "10000043052030000"; mesonCutArray[2] = "01525065000000"; 
154                 eventCutArray[ 3] = "8000001"; photonCutArray[ 3] = "002092970028250400000"; clusterCutArray[3] = "10000044052030000"; mesonCutArray[3] = "01525065000000"; 
155                 eventCutArray[ 4] = "8000001"; photonCutArray[ 4] = "002092970028250400000"; clusterCutArray[4] = "10000045052030000"; mesonCutArray[4] = "01525065000000"; 
156         } else if (trainConfig == 7) { //PHOS
157                 eventCutArray[ 0] = "8000001"; photonCutArray[ 0] = "002092970028250400000"; clusterCutArray[0] = "20000031022000000"; mesonCutArray[0] = "01525065000000"; 
158                 eventCutArray[ 1] = "8000001"; photonCutArray[ 1] = "002092970028250400000"; clusterCutArray[1] = "20000032022000000"; mesonCutArray[1] = "01525065000000"; 
159                 eventCutArray[ 2] = "8000001"; photonCutArray[ 2] = "002092970028250400000"; clusterCutArray[2] = "20000033022000000"; mesonCutArray[2] = "01525065000000"; 
160                 eventCutArray[ 3] = "8000001"; photonCutArray[ 3] = "002092970028250400000"; clusterCutArray[3] = "20000034022000000"; mesonCutArray[3] = "01525065000000"; 
161                 eventCutArray[ 4] = "8000001"; photonCutArray[ 4] = "002092970028250400000"; clusterCutArray[4] = "20000035022000000"; mesonCutArray[4] = "01525065000000"; 
162         } else {
163                 Error(Form("GammaConvCalo_%i",trainConfig), "wrong trainConfig variable no cuts have been specified for the configuration");
164                 return;
165         }
166
167         TList *EventCutList = new TList();
168         TList *ConvCutList = new TList();
169         TList *ClusterCutList = new TList();
170         TList *MesonCutList = new TList();
171
172         TList *HeaderList = new TList();
173         if (doWeightingPart==1) {
174                 TObjString *Header1 = new TObjString("pi0_1");
175                 HeaderList->Add(Header1);
176         }
177         if (doWeightingPart==2){
178                 TObjString *Header3 = new TObjString("eta_2");
179                 HeaderList->Add(Header3);
180         }
181         if (doWeightingPart==3) {
182                 TObjString *Header1 = new TObjString("pi0_1");
183                 HeaderList->Add(Header1);
184                 TObjString *Header3 = new TObjString("eta_2");
185                 HeaderList->Add(Header3);
186         }
187
188         EventCutList->SetOwner(kTRUE);
189         AliConvEventCuts **analysisEventCuts = new AliConvEventCuts*[numberOfCuts];
190         ConvCutList->SetOwner(kTRUE);
191         AliConversionPhotonCuts **analysisCuts = new AliConversionPhotonCuts*[numberOfCuts];
192         ClusterCutList->SetOwner(kTRUE);
193         AliCaloPhotonCuts **analysisClusterCuts = new AliCaloPhotonCuts*[numberOfCuts];
194         MesonCutList->SetOwner(kTRUE);
195         AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];
196
197         for(Int_t i = 0; i<numberOfCuts; i++){
198                 analysisEventCuts[i] = new AliConvEventCuts();   
199                 analysisEventCuts[i]->InitializeCutsFromCutString(eventCutArray[i].Data());
200                 EventCutList->Add(analysisEventCuts[i]);
201                 analysisEventCuts[i]->SetFillCutHistograms("",kFALSE);
202                 
203                 analysisCuts[i] = new AliConversionPhotonCuts();
204                 analysisCuts[i]->InitializeCutsFromCutString(photonCutArray[i].Data());
205                 analysisCuts[i]->SetIsHeavyIon(isHeavyIon);
206                 ConvCutList->Add(analysisCuts[i]);
207                 analysisCuts[i]->SetFillCutHistograms("",kFALSE);
208         
209                 analysisClusterCuts[i] = new AliCaloPhotonCuts();
210                 analysisClusterCuts[i]->InitializeCutsFromCutString(clusterCutArray[i].Data());
211                 ClusterCutList->Add(analysisClusterCuts[i]);
212         analysisClusterCuts[i]->SetExtendedMatching(enableExtendedMatching);
213                 analysisClusterCuts[i]->SetFillCutHistograms("");
214                 
215                 analysisMesonCuts[i] = new AliConversionMesonCuts();
216                 analysisMesonCuts[i]->InitializeCutsFromCutString(mesonCutArray[i].Data());
217                 MesonCutList->Add(analysisMesonCuts[i]);
218                 analysisMesonCuts[i]->SetFillCutHistograms("");
219                 analysisEventCuts[i]->SetAcceptedHeader(HeaderList);
220         }
221
222         task->SetEventCutList(numberOfCuts,EventCutList);
223         task->SetConversionCutList(numberOfCuts,ConvCutList);
224         task->SetCaloCutList(numberOfCuts,ClusterCutList);
225         task->SetMesonCutList(numberOfCuts,MesonCutList);
226         task->SetMoveParticleAccordingToVertex(kTRUE);
227         task->SetDoMesonAnalysis(kTRUE);
228         task->SetDoMesonQA(enableQAMesonTask); //Attention new switch for Pi0 QA
229         task->SetDoPhotonQA(enableQAPhotonTask);  //Attention new switch small for Photon QA
230         task->SetDoClusterQA(1);  //Attention new switch small for Cluster QA
231
232         //connect containers
233         AliAnalysisDataContainer *coutput =
234                 mgr->CreateContainer(Form("GammaConvCalo_%i",trainConfig), TList::Class(),
235                                                         AliAnalysisManager::kOutputContainer,Form("GammaConvCalo_%i.root",trainConfig));
236
237         mgr->AddTask(task);
238         mgr->ConnectInput(task,0,cinput);
239         mgr->ConnectOutput(task,1,coutput);
240
241         return;
242
243 }