Improve use of JetContainers, fix cluster name in AddTasks
[u/mrichter/AliRoot.git] / PWGJE / FlavourJetTasks / macros / AddTaskDFilterAndCorrelations.C
CommitLineData
bbb94467 1void *AddTaskDFilterAndCorrelations(
2 AliAnalysisTaskSEDmesonsFilterCJ::ECandidateType cand = AliAnalysisTaskSEDmesonsFilterCJ::kDstartoKpipi,
3 TString filename = "DStartoKpipiCuts.root",
4 Bool_t theMCon = kFALSE,
5 Bool_t reco = kTRUE /*must be true if theMCon is false*/,
6 TString suffix = "",
7 TString jetArrname = "",
cc5dbb3b 8 TString trackArrname = "PicoTracks",
bbb94467 9 Bool_t triggerOnLeadingJet = kFALSE,
10 Int_t leadingHadType = 0 /*0 = charged, 1 = neutral, 2 = both*/,
11 Float_t R = 0.4,
12 Float_t jptcut = 10.,
13 const char *cutType = "TPC",
ad6abcae 14 Int_t thnsparse=1, /*-1 = no thnsparse, 0 = heavy, 1 = light*/
76bf81f2 15 Double_t percjetareacut = 1.,
b2705b43 16 AliAnalysisTaskEmcal::TriggerType trType=AliAnalysisTaskEmcal::kND,
17 Int_t typeDjet=2
76bf81f2 18)
bbb94467 19{
20 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
21 if (!mgr) {
22 ::Error("AddTaskSEDmesonsFilterCJ", "No analysis manager to connect to.");
23 return NULL;
24 }
25
26 Bool_t useStdC = kFALSE;
27 TFile* filecuts=TFile::Open(filename);
28 if(!filecuts || (filecuts && !filecuts->IsOpen())) {
29 cout<<"Input file not found: use std cuts"<<endl;
30 useStdC = kTRUE;
31 }
32
33 AliRDHFCuts *analysiscuts=0x0;
34 switch (cand) {
35 case 0 :
36 if(useStdC) {
37 analysiscuts = new AliRDHFCutsD0toKpi();
38 analysiscuts->SetStandardCutsPP2010();
39 } else
40 analysiscuts = (AliRDHFCutsD0toKpi*)filecuts->Get("D0toKpiCuts");
41 break;
42 case 1 :
43 if(useStdC) {
44 analysiscuts = new AliRDHFCutsDStartoKpipi();
45 analysiscuts->SetStandardCutsPP2010();
46 } else
47 analysiscuts = (AliRDHFCutsDStartoKpipi*)filecuts->Get("DStartoKpipiCuts");
48 analysiscuts->SetName("DStartoKpipiCuts");
49 break;
50 }
51
52 if (!analysiscuts) { // mm let's see if everything is ok
53 AliFatal("Specific AliRDHFCuts not found");
54 return;
55 }
56
57 printf("CREATE TASK\n"); //CREATE THE TASK
58
ce11164d 59 TString candname="DStar";
60 if(cand==0) candname="D0";
5b64c502 61 TString sR = Form("R%.1f",R);
62
ce11164d 63 TString taskFiltername="DmesonsFilterCJ";
64 taskFiltername+=candname;
65 taskFiltername+=suffix;
66 if(theMCon) taskFiltername+="MC";
67 if(!reco) taskFiltername+="gen";
68
69 AliAnalysisTaskSEDmesonsFilterCJ* taskFilter = mgr->GetTask(taskFiltername.Data());
5b64c502 70 Bool_t bTaskFilter=kTRUE;
ce11164d 71 if (!taskFilter){
5b64c502 72 bTaskFilter=kFALSE;
ce11164d 73 taskFilter = new AliAnalysisTaskSEDmesonsFilterCJ(taskFiltername.Data(),analysiscuts,cand);
74 if(!theMCon) reco=kTRUE;
75 taskFilter->SetMC(theMCon); //D meson settings
76 taskFilter->SetUseReco(reco);
77 mgr->AddTask(taskFilter);
5b64c502 78 } else Printf("Task %s already exist, continue",taskFiltername.Data());
ce11164d 79
bbb94467 80 // create the task
ce11164d 81 TString taskCorrName="TaskFlavourJetCorrelations";
82 taskCorrName+=candname;
83 taskCorrName+=suffix;
84 if(theMCon) taskCorrName+="MC";
85 if(!reco) taskCorrName+="gen";
86 taskCorrName+=cutType;
87 taskCorrName+=Form("PTj%.0f",jptcut);
5b64c502 88 taskCorrName+=sR;
bbb94467 89
ce11164d 90 AliAnalysisTaskFlavourJetCorrelations *taskCorr = new AliAnalysisTaskFlavourJetCorrelations(taskCorrName.Data(),
bbb94467 91 analysiscuts, cand);
ce11164d 92
cc5dbb3b 93 taskCorr->SetJetArrayName(jetArrname);
94 taskCorr->SetTrackArrayName(trackArrname);
95 //taskCorr->SetRadius(R);
96 AliParticleContainer *trackCont = taskCorr->AddParticleContainer(trackArrname);
97 trackCont->SetClassName("AliVTrack");
98
99 AliJetContainer *jetCont = taskCorr->AddJetContainer(jetArrname,cutType,R);
100 if(jetCont) {
101 jetCont->ConnectParticleContainer(trackCont);
102 //jetCont->SetJetAcceptanceType(cutType);
103 jetCont->SetJetPtCut(jptcut);
104 jetCont->SetPercAreaCut(percjetareacut);
105 }
bbb94467 106 taskCorr->SetMC(theMCon);
107 taskCorr->SetUseReco(reco);
108 taskCorr->SetTriggerOnLeadingJet(triggerOnLeadingJet);
b2705b43 109 taskCorr->SetTypeDJetSelection(typeDjet);
76bf81f2 110 if(theMCon && trType!=AliAnalysisTaskEmcal::kND){
111 taskCorr->SetCaloTriggerPatchInfoName("EmcalTriggers");
112 taskCorr->SetTriggerTypeSel(trType);
113 }
ad6abcae 114 if(thnsparse==-1)taskCorr->TurnOffTHnSparse();
115 if(thnsparse==0) taskCorr->HeavyTHnSparse();
116 if(thnsparse==1) taskCorr->LightTHnSparse();
117
bbb94467 118 mgr->AddTask(taskCorr);
119
120 if(theMCon) {
121 suffix+="MC";
122 if(reco) suffix+="rec";
123 }
124
bbb94467 125
126 // Create and connect containers for input/output
127 TString outputfile = AliAnalysisManager::GetCommonFileName();
128 TString outputfileF = outputfile, outputfileC = outputfile;
129 outputfileF += ":PWG3_D2H_DmesonsForJetCorrelations";
130 outputfileC += ":PWG3_D2H_DEmcalJet";
131
132 outputfileF += suffix;
133 outputfileC += suffix;
134
135 TString nameContainerF0="histograms";
136 TString nameContainerF1="cuts";
137
138 TString nameContainerC0="hCor";
139 TString nameContainerC1="cutsJ";
140
141 TString nameContainerFC2="Dcandidates";
142 TString nameContainerFC3="DSBcandidates";
143
144 nameContainerF0 += candname;
145 nameContainerF1 += candname;
146 nameContainerC0 += candname;
147 nameContainerC1 += candname;
148 nameContainerFC2 += candname;
149 nameContainerFC3 += candname;
150
151 nameContainerF0 += suffix;
152 nameContainerF1 += suffix;
153 nameContainerC0 += suffix;
154 nameContainerC1 += suffix;
155 nameContainerFC2 += suffix;
156 nameContainerFC3 += suffix;
157
5b64c502 158 nameContainerC0+=sR;
159 nameContainerC1+=sR;
160
bbb94467 161 // ------ input data ------
162 AliAnalysisDataContainer *cinput0 = mgr->GetCommonInputContainer();
8577f7bc 163 cinput0->SetName(Form("in%s%s",candname.Data(),suffix.Data()));
bbb94467 164
165 // ----- output data -----
5b64c502 166 AliAnalysisDataContainer *coutputF0;
167 AliAnalysisDataContainer *coutputF1;
168 AliAnalysisDataContainer *coutputFC2;
169 AliAnalysisDataContainer *coutputFC3;
170
171 if(!bTaskFilter){
172 coutputF0 = mgr->CreateContainer(nameContainerF0, TList::Class(),AliAnalysisManager::kOutputContainer,outputfileF.Data());
bbb94467 173
5b64c502 174 coutputF1 = mgr->CreateContainer(nameContainerF1, AliRDHFCuts::Class(),AliAnalysisManager::kOutputContainer, outputfileF.Data());
bbb94467 175
5b64c502 176 coutputFC2 = mgr->CreateContainer(nameContainerFC2, TClonesArray::Class(),AliAnalysisManager::kExchangeContainer, outputfileF.Data()); // exchange
177
178 coutputFC3 = mgr->CreateContainer(nameContainerFC3, TClonesArray::Class(),AliAnalysisManager::kExchangeContainer, outputfileF.Data()); // exchange
179
180 } else {
181 TObjArray * cnt = mgr->GetContainers();
182 coutputF0 = (AliAnalysisDataContainer*)cnt->FindObject(nameContainerF0);
183 coutputF1 = (AliAnalysisDataContainer*)cnt->FindObject(nameContainerF1);
184 coutputFC2= (AliAnalysisDataContainer*)cnt->FindObject(nameContainerFC2);
185 coutputFC3= (AliAnalysisDataContainer*)cnt->FindObject(nameContainerFC3);
186 }
bbb94467 187
188 AliAnalysisDataContainer *coutputC0 = mgr->CreateContainer(nameContainerC0, TList::Class(),AliAnalysisManager::kOutputContainer,outputfileC.Data());
189
190 AliAnalysisDataContainer *coutputC1 = mgr->CreateContainer(nameContainerC1, AliRDHFCuts::Class(),AliAnalysisManager::kOutputContainer, outputfileC.Data());
191
5b64c502 192
8577f7bc 193 mgr->ConnectInput(taskFilter,0,cinput0);
194 mgr->ConnectInput(taskCorr,0,cinput0);
bbb94467 195
196 mgr->ConnectOutput(taskFilter,1,coutputF0);
197 mgr->ConnectOutput(taskFilter,2,coutputF1);
198 mgr->ConnectOutput(taskFilter,3,coutputFC2);
199 mgr->ConnectOutput(taskFilter,4,coutputFC3);
200
201
202 mgr->ConnectInput(taskCorr,1,coutputFC2);
203 mgr->ConnectInput(taskCorr,2,coutputFC3);
204 mgr->ConnectOutput(taskCorr,1,coutputC0);
205 mgr->ConnectOutput(taskCorr,2,coutputC1);
206 //if(cand==1) mgr->ConnectOutput(task,4,coutput4);
207
208 Printf("Input and Output connected to the manager");
209 return;
210}
211