]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/vertexingHF/AliAnalysisTaskSED0Mass.cxx
Adding chi2 of the fit.
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAnalysisTaskSED0Mass.cxx
CommitLineData
49061176 1/**************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/////////////////////////////////////////////////////////////
17//
18// AliAnalysisTaskSE for D0 candidates invariant mass histogram
a41f6fad 19// and comparison with the MC truth and cut variables distributions.
49061176 20//
21// Authors: A.Dainese, andrea.dainese@lnl.infn.it
feb73eca 22// Chiara Bianchin, chiara.bianchin@pd.infn.it (invariant mass)
23// Carmelo Di Giglio, carmelo.digiglio@ba.infn.it (like sign)
49061176 24/////////////////////////////////////////////////////////////
25
26#include <Riostream.h>
27#include <TClonesArray.h>
527f330b 28#include <TCanvas.h>
49061176 29#include <TNtuple.h>
30#include <TList.h>
31#include <TH1F.h>
a41f6fad 32#include <TH2F.h>
33#include <TDatabasePDG.h>
49061176 34
b557eb43 35#include "AliAnalysisManager.h"
34137226 36#include "AliESDtrack.h"
b557eb43 37#include "AliAODHandler.h"
49061176 38#include "AliAODEvent.h"
39#include "AliAODVertex.h"
40#include "AliAODTrack.h"
41#include "AliAODMCHeader.h"
42#include "AliAODMCParticle.h"
43#include "AliAODRecoDecayHF2Prong.h"
44#include "AliAODRecoCascadeHF.h"
45#include "AliAnalysisVertexingHF.h"
46#include "AliAnalysisTaskSE.h"
47#include "AliAnalysisTaskSED0Mass.h"
48
b557eb43 49
49061176 50ClassImp(AliAnalysisTaskSED0Mass)
51
52
53//________________________________________________________________________
54AliAnalysisTaskSED0Mass::AliAnalysisTaskSED0Mass():
55AliAnalysisTaskSE(),
ea0d8716 56fOutputMass(0),
57fDistr(0),
58fNentries(0),
34137226 59fChecks(0),
ea0d8716 60fCutList(0),
61fCuts(0),
feb73eca 62fArray(0),
ce39f0ac 63fReadMC(0),
40445ada 64fCutOnDistr(0),
feb73eca 65fLsNormalization(1.)
66
ea0d8716 67
49061176 68{
69 // Default constructor
9de8c723 70 for(Int_t i=0;i<5;i++) {fTotPosPairs[i]=0; fTotNegPairs[i]=0;}
49061176 71}
72
73//________________________________________________________________________
ea0d8716 74AliAnalysisTaskSED0Mass::AliAnalysisTaskSED0Mass(const char *name,AliRDHFCutsD0toKpi* cuts):
49061176 75AliAnalysisTaskSE(name),
ea0d8716 76fOutputMass(0),
34137226 77fDistr(0),
ea0d8716 78fNentries(0),
34137226 79fChecks(0),
ea0d8716 80fCutList(0),
81fCuts(0),
feb73eca 82fArray(0),
ce39f0ac 83fReadMC(0),
40445ada 84fCutOnDistr(0),
feb73eca 85fLsNormalization(1.)
6321ee46 86
ea0d8716 87
49061176 88{
89 // Default constructor
9de8c723 90 for(Int_t i=0;i<5;i++) {fTotPosPairs[i]=0; fTotNegPairs[i]=0;}
49061176 91
ea0d8716 92 //fCuts=new AliRDHFCutsD0toKpi(*cuts);
93 fCuts=cuts;
94
95 // Output slot #1 writes into a TList container (mass with cuts)
49061176 96 DefineOutput(1,TList::Class()); //My private output
ea0d8716 97 // Output slot #2 writes into a TList container (distributions)
a4ae02cd 98 DefineOutput(2,TList::Class()); //My private output
ea0d8716 99 // Output slot #3 writes into a TH1F container (number of events)
a4ae02cd 100 DefineOutput(3,TH1F::Class()); //My private output
ea0d8716 101 // Output slot #4 writes into a TList container (quality check)
a41f6fad 102 DefineOutput(4,TList::Class()); //My private output
ea0d8716 103 // Output slot #5 writes into a TList container (cuts)
104 DefineOutput(5,AliRDHFCutsD0toKpi::Class()); //My private output
105 //DefineOutput(5,TList::Class()); //My private output
106
49061176 107}
108
109//________________________________________________________________________
110AliAnalysisTaskSED0Mass::~AliAnalysisTaskSED0Mass()
111{
ea0d8716 112 if (fOutputMass) {
113 delete fOutputMass;
114 fOutputMass = 0;
a4ae02cd 115 }
a41f6fad 116 if (fDistr) {
117 delete fDistr;
118 fDistr = 0;
119 }
34137226 120 if (fChecks) {
121 delete fChecks;
122 fChecks = 0;
123 }
ea0d8716 124 if (fCuts) {
125 delete fCuts;
126 fCuts = 0;
49061176 127 }
46c96ce5 128 if (fNentries){
129 delete fNentries;
130 fNentries = 0;
131 }
ea0d8716 132
133 if(fCutList){
134 delete fCutList;
135 fCutList=0;
136 }
137
49061176 138}
139
140//________________________________________________________________________
141void AliAnalysisTaskSED0Mass::Init()
142{
143 // Initialization
144
145 if(fDebug > 1) printf("AnalysisTaskSED0Mass::Init() \n");
146
ea0d8716 147
148 fCutList=new TList();
149 fCutList->SetOwner();
150 fCutList->SetName("listofCutsObj");
151 fCutList->Add(fCuts);
152
153 AliRDHFCutsD0toKpi* copyfCuts=new AliRDHFCutsD0toKpi(*fCuts);
154 // Post the data
155 PostData(5,copyfCuts);
156 //PostData(5,fCutList);
49061176 157
49061176 158 return;
159}
160
161//________________________________________________________________________
162void AliAnalysisTaskSED0Mass::UserCreateOutputObjects()
163{
164
165 // Create the output container
166 //
167 if(fDebug > 1) printf("AnalysisTaskSED0Mass::UserCreateOutputObjects() \n");
168
169 // Several histograms are more conveniently managed in a TList
ea0d8716 170 fOutputMass = new TList();
171 fOutputMass->SetOwner();
172 fOutputMass->SetName("listMass");
49061176 173
a41f6fad 174 fDistr = new TList();
175 fDistr->SetOwner();
176 fDistr->SetName("distributionslist");
177
34137226 178 fChecks = new TList();
179 fChecks->SetOwner();
180 fChecks->SetName("checkHistograms");
181
0108fa62 182 TString nameMass=" ",nameSgn27=" ",nameSgn=" ", nameBkg=" ", nameRfl=" ",nameMassNocutsS =" ",nameMassNocutsB =" ", namedistr=" ";
49061176 183
ea0d8716 184 for(Int_t i=0;i<fCuts->GetNPtBins();i++){
b272aebf 185
7646d6da 186 nameMass="histMass_";
ea0d8716 187 nameMass+=i;
9de8c723 188 nameSgn27="histSgn27_";
ea0d8716 189 nameSgn27+=i;
7646d6da 190 nameSgn="histSgn_";
ea0d8716 191 nameSgn+=i;
7646d6da 192 nameBkg="histBkg_";
ea0d8716 193 nameBkg+=i;
a4ae02cd 194 nameRfl="histRfl_";
ea0d8716 195 nameRfl+=i;
0108fa62 196 nameMassNocutsS="hMassS_";
ea0d8716 197 nameMassNocutsS+=i;
0108fa62 198 nameMassNocutsB="hMassB_";
ea0d8716 199 nameMassNocutsB+=i;
7646d6da 200
b272aebf 201 //histograms of cut variable distributions
202
203 // pT
204 namedistr="hptpiS_";
ea0d8716 205 namedistr+=i;
b272aebf 206 TH1F *hptpiS = new TH1F(namedistr.Data(), "P_{T} distribution (pions);p_{T} [GeV/c]",200,0.,8.);
207
208 namedistr="hptKS_";
ea0d8716 209 namedistr+=i;
b272aebf 210 TH1F *hptKS = new TH1F(namedistr.Data(), "P_{T} distribution (kaons);p_{T} [GeV/c]",200,0.,8.);
211
212 namedistr="hptB_";
ea0d8716 213 namedistr+=i;
b272aebf 214 TH1F *hptB = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
215
216 // pT no mass cut
217 namedistr="hptpiSnoMcut_";
ea0d8716 218 namedistr+=i;
b272aebf 219 TH1F *hptpiSnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution (pions);p_{T} [GeV/c]",200,0.,8.);
220
221 namedistr="hptKSnoMcut_";
ea0d8716 222 namedistr+=i;
b272aebf 223 TH1F *hptKSnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution (kaons);p_{T} [GeV/c]",200,0.,8.);
224
225 namedistr="hptB1prongnoMcut_";
ea0d8716 226 namedistr+=i;
b272aebf 227 TH1F *hptB1pnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
228
229 namedistr="hptB2prongsnoMcut_";
ea0d8716 230 namedistr+=i;
b272aebf 231 TH1F *hptB2pnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
232
233
234 // dca
235 namedistr="hdcaS_";
ea0d8716 236 namedistr+=i;
b272aebf 237 TH1F *hdcaS = new TH1F(namedistr.Data(), "DCA distribution;dca [cm]",200,0.,0.1);
238 namedistr="hdcaB_";
ea0d8716 239 namedistr+=i;
b272aebf 240 TH1F *hdcaB = new TH1F(namedistr.Data(), "DCA distribution;dca [cm]",200,0.,0.1);
241
242 // costhetastar
243 namedistr="hcosthetastarS_";
ea0d8716 244 namedistr+=i;
b272aebf 245 TH1F *hcosthetastarS = new TH1F(namedistr.Data(), "cos#theta* distribution;cos#theta*",200,-1.,1.);
246 namedistr="hcosthetastarB_";
ea0d8716 247 namedistr+=i;
b272aebf 248 TH1F *hcosthetastarB = new TH1F(namedistr.Data(), "cos#theta* distribution;cos#theta*",200,-1.,1.);
249
250 // impact parameter
251 namedistr="hd0piS_";
ea0d8716 252 namedistr+=i;
b272aebf 253 TH1F *hd0piS = new TH1F(namedistr.Data(), "Impact parameter distribution (pions);d0(#pi) [cm]",200,-0.1,0.1);
254
255 namedistr="hd0KS_";
ea0d8716 256 namedistr+=i;
b272aebf 257 TH1F *hd0KS = new TH1F(namedistr.Data(), "Impact parameter distribution (kaons);d0(K) [cm]",200,-0.1,0.1);
258 namedistr="hd0B_";
ea0d8716 259 namedistr+=i;
b272aebf 260 TH1F *hd0B = new TH1F(namedistr.Data(), "Impact parameter distribution;d0 [cm]",200,-0.1,0.1);
261
262 namedistr="hd0d0S_";
ea0d8716 263 namedistr+=i;
b272aebf 264 TH1F *hd0d0S = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution;d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
265 namedistr="hd0d0B_";
ea0d8716 266 namedistr+=i;
b272aebf 267 TH1F *hd0d0B = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution;d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
268
269 // costhetapoint
270 namedistr="hcosthetapointS_";
ea0d8716 271 namedistr+=i;
b272aebf 272 TH1F *hcosthetapointS = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
273 namedistr="hcosthetapointB_";
ea0d8716 274 namedistr+=i;
b272aebf 275 TH1F *hcosthetapointB = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
276
277 namedistr="hcosthpointd0d0S_";
ea0d8716 278 namedistr+=i;
b272aebf 279 TH2F *hcosthpointd0d0S= new TH2F(namedistr.Data(),"Correlation cos#theta_{Point}-d_{0}#timesd_{0};cos#theta_{Point};d_{0}#timesd_{0} [cm^{2}]",200,0,1.,200,-0.001,0.001);
280 namedistr="hcosthpointd0d0B_";
ea0d8716 281 namedistr+=i;
b272aebf 282 TH2F *hcosthpointd0d0B= new TH2F(namedistr.Data(),"Correlation cos#theta_{Point}-d_{0}#timesd_{0};cos#theta_{Point};d_{0}#timesd_{0} [cm^{2}]",200,0,1.,200,-0.001,0.001);
283
284 fDistr->Add(hptpiS);
285 fDistr->Add(hptKS);
286 fDistr->Add(hptB);
287
288 fDistr->Add(hptpiSnoMcut);
289 fDistr->Add(hptKSnoMcut);
290 fDistr->Add(hptB1pnoMcut);
291 fDistr->Add(hptB2pnoMcut);
292
293 fDistr->Add(hdcaS);
294 fDistr->Add(hdcaB);
295
296 fDistr->Add(hd0piS);
297 fDistr->Add(hd0KS);
298 fDistr->Add(hd0B);
299
300 fDistr->Add(hd0d0S);
301 fDistr->Add(hd0d0B);
302
303 fDistr->Add(hcosthetastarS);
304 fDistr->Add(hcosthetastarB);
305
306 fDistr->Add(hcosthetapointS);
307 fDistr->Add(hcosthetapointB);
308
309 fDistr->Add(hcosthpointd0d0S);
310 fDistr->Add(hcosthpointd0d0B);
311
312
a41f6fad 313 //histograms of invariant mass distributions
314
46c96ce5 315 TH1F* tmpMt = new TH1F(nameMass.Data(),"D^{0} invariant mass; M [GeV]; Entries",200,1.765,1.965);
316 TH1F *tmpMl=(TH1F*)tmpMt->Clone();
317 tmpMt->Sumw2();
318 tmpMl->Sumw2();
a4ae02cd 319
9de8c723 320 //to compare with AliAnalysisTaskCharmFraction
321 TH1F* tmpS27t = new TH1F(nameSgn27.Data(),"D^{0} invariant mass in M(D^{0}) +/- 27 MeV - MC; M [GeV]; Entries",200,1.765,1.965);
322 TH1F *tmpS27l=(TH1F*)tmpS27t->Clone();
323 tmpS27t->Sumw2();
324 tmpS27l->Sumw2();
0108fa62 325
326 //distribution w/o cuts
6321ee46 327 // TH1F* tmpMS = new TH1F(nameMassNocutsS.Data(),"D^{0} invariant mass; M [GeV]; Entries",300,0.7,3.);
328 TH1F* tmpMS = new TH1F(nameMassNocutsS.Data(),"D^{0} invariant mass; M [GeV]; Entries",300,1.56484,2.16484); //range (MD0-300MeV, mD0 + 300MeV)
329 TH1F *tmpMB=(TH1F*)tmpMS->Clone();
0108fa62 330 tmpMB->SetName(nameMassNocutsB.Data());
331 tmpMS->Sumw2();
332 tmpMB->Sumw2();
333
334 //MC signal and background
46c96ce5 335 TH1F* tmpSt = new TH1F(nameSgn.Data(), "D^{0} invariant mass - MC; M [GeV]; Entries",200,1.765,1.965);
336 TH1F *tmpSl=(TH1F*)tmpSt->Clone();
337 tmpSt->Sumw2();
338 tmpSl->Sumw2();
a4ae02cd 339
46c96ce5 340 TH1F* tmpBt = new TH1F(nameBkg.Data(), "Background invariant mass - MC; M [GeV]; Entries",200,1.765,1.965);
341 TH1F *tmpBl=(TH1F*)tmpBt->Clone();
342 tmpBt->Sumw2();
343 tmpBl->Sumw2();
a4ae02cd 344
feb73eca 345 //Reflection: histo filled with D0Mass which pass the cut (also) as D0bar and with D0bar which pass (also) the cut as D0
46c96ce5 346 TH1F* tmpRt = new TH1F(nameRfl.Data(), "Reflected signal invariant mass - MC; M [GeV]; Entries",200,1.765,1.965);
347 TH1F *tmpRl=(TH1F*)tmpRt->Clone();
348 tmpRt->Sumw2();
349 tmpRl->Sumw2();
a4ae02cd 350 // printf("Created histograms %s\t%s\t%s\t%s\n",tmpM->GetName(),tmpS->GetName(),tmpB->GetName(),tmpR->GetName());
351
ea0d8716 352 fOutputMass->Add(tmpMt);
353 fOutputMass->Add(tmpSt);
354 fOutputMass->Add(tmpS27t);
355 fOutputMass->Add(tmpBt);
356 fOutputMass->Add(tmpRt);
357
0108fa62 358 fDistr->Add(tmpMS);
359 fDistr->Add(tmpMB);
360
34137226 361
7646d6da 362 }
a4ae02cd 363
34137226 364 //histograms for vertex checking
365 TString checkname="hptGoodTr";
366
367 TH1F* hptGoodTr=new TH1F(checkname.Data(),"Pt distribution of 'good' tracks;p_{t}[GeV];Number",200,0.,8.);
368 hptGoodTr->SetTitleOffset(1.3,"Y");
369 checkname="hdistrGoodTr";
a41f6fad 370
34137226 371 TH1F* hdistrGoodTr=new TH1F(checkname.Data(),"Distribution of number of good tracks per event;no.good-tracks/ev;Entries",31,0,31);
372 hdistrGoodTr->SetTitleOffset(1.3,"Y");
373
374 //conta gli eventi con vertice buoni e almeno due tracce utilizzabili
375 fChecks->Add(hptGoodTr);
376 fChecks->Add(hdistrGoodTr);
377
378 fNentries=new TH1F("nentriesD0", "nentriesD0->Integral(1,2) = number of AODs *** nentriesD0->Integral(3,4) = number of candidates selected with cuts *** nentriesD0->Integral(5,6) = number of D0 selected with cuts *** nentriesD0->Integral(7,8) = events with good vertex", 5,0.,5.);
379
380 fNentries->GetXaxis()->SetBinLabel(1,"nEventsAnal");
381 fNentries->GetXaxis()->SetBinLabel(2,"nCandidatesSelected");
382 fNentries->GetXaxis()->SetBinLabel(3,"nD0Selected");
383 fNentries->GetXaxis()->SetBinLabel(4,"nEventsGoodVtx");
384 fNentries->GetXaxis()->SetBinLabel(5,"nEventsGoodVtx+>2tracks");
385 fNentries->GetXaxis()->SetNdivisions(1,kFALSE);
a4ae02cd 386
ea0d8716 387
40445ada 388 // Post the data
ea0d8716 389 PostData(1,fOutputMass);
390 PostData(2,fChecks);
40445ada 391 PostData(3,fNentries);
392 PostData(4,fDistr);
ea0d8716 393
49061176 394 return;
395}
396
397//________________________________________________________________________
398void AliAnalysisTaskSED0Mass::UserExec(Option_t */*option*/)
399{
400 // Execute analysis for current event:
401 // heavy flavor candidates association to MC truth
a4ae02cd 402 //cout<<"I'm in UserExec"<<endl;
ea0d8716 403
404
405 //cuts order
406 // printf(" |M-MD0| [GeV] < %f\n",fD0toKpiCuts[0]);
407 // printf(" dca [cm] < %f\n",fD0toKpiCuts[1]);
408 // printf(" cosThetaStar < %f\n",fD0toKpiCuts[2]);
409 // printf(" pTK [GeV/c] > %f\n",fD0toKpiCuts[3]);
410 // printf(" pTpi [GeV/c] > %f\n",fD0toKpiCuts[4]);
411 // printf(" |d0K| [cm] < %f\n",fD0toKpiCuts[5]);
412 // printf(" |d0pi| [cm] < %f\n",fD0toKpiCuts[6]);
413 // printf(" d0d0 [cm^2] < %f\n",fD0toKpiCuts[7]);
414 // printf(" cosThetaPoint > %f\n",fD0toKpiCuts[8]);
415
416
49061176 417 AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
feb73eca 418
b557eb43 419 TString bname;
feb73eca 420 if(fArray==0){ //D0 candidates
b557eb43 421 // load D0->Kpi candidates
feb73eca 422 //cout<<"D0 candidates"<<endl;
b557eb43 423 bname="D0toKpi";
feb73eca 424 } else { //LikeSign candidates
feb73eca 425 // load like sign candidates
b557eb43 426 //cout<<"LS candidates"<<endl;
427 bname="LikeSign2Prong";
428 }
429
430 TClonesArray *inputArray=0;
34137226 431
b557eb43 432 if(!aod && AODEvent() && IsStandardAOD()) {
433 // In case there is an AOD handler writing a standard AOD, use the AOD
434 // event in memory rather than the input (ESD) event.
435 aod = dynamic_cast<AliAODEvent*> (AODEvent());
436 // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
437 // have to taken from the AOD event hold by the AliAODExtension
438 AliAODHandler* aodHandler = (AliAODHandler*)
439 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
34137226 440
b557eb43 441 if(aodHandler->GetExtensions()) {
442 AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
34137226 443 AliAODEvent* aodFromExt = ext->GetAOD();
b557eb43 444 inputArray=(TClonesArray*)aodFromExt->GetList()->FindObject(bname.Data());
feb73eca 445 }
b557eb43 446 } else {
447 inputArray=(TClonesArray*)aod->GetList()->FindObject(bname.Data());
448 }
feb73eca 449
b557eb43 450
451 if(!inputArray) {
452 printf("AliAnalysisTaskSED0Mass::UserExec: input branch not found!\n");
453 return;
49061176 454 }
455
34137226 456
ce39f0ac 457 TClonesArray *mcArray = 0;
458 AliAODMCHeader *mcHeader = 0;
459
460 if(fReadMC) {
461 // load MC particles
462 mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
463 if(!mcArray) {
464 printf("AliAnalysisTaskSED0Mass::UserExec: MC particles branch not found!\n");
465 return;
466 }
40445ada 467
ce39f0ac 468 // load MC header
469 mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
470 if(!mcHeader) {
471 printf("AliAnalysisTaskSED0Mass::UserExec: MC header branch not found!\n");
472 return;
473 }
49061176 474 }
475
b557eb43 476 //printf("VERTEX Z %f %f\n",vtx1->GetZ(),mcHeader->GetVtxZ());
40445ada 477
a4ae02cd 478 //histogram filled with 1 for every AOD
34137226 479 fNentries->Fill(0);
49061176 480
0108fa62 481
40445ada 482
483 // AOD primary vertex
484 AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
b272aebf 485
40445ada 486 Bool_t isGoodVtx=kFALSE;
b272aebf 487
40445ada 488 //vtx1->Print();
489 TString primTitle = vtx1->GetTitle();
490 if(primTitle.Contains("VertexerTracks") && vtx1->GetNContributors()>0) {
491 isGoodVtx=kTRUE;
492 fNentries->Fill(3);
493 }
494
495 //cout<<"Start checks"<<endl;
496 Int_t ntracks=0,isGoodTrack=0;
497
498 if(aod) ntracks=aod->GetNTracks();
499
75638da0 500 //cout<<"ntracks = "<<ntracks<<endl;
ea0d8716 501
75638da0 502 //loop on tracks in the event
503 for (Int_t k=0;k<ntracks;k++){
504 AliAODTrack* track=aod->GetTrack(k);
505 //cout<<"in loop"<<endl;
506 //check clusters of the tracks
507 Int_t nclsTot=0,nclsSPD=0;
40445ada 508
75638da0 509 for(Int_t l=0;l<6;l++) {
510 if(TESTBIT(track->GetITSClusterMap(),l)) {
511 nclsTot++; if(l<2) nclsSPD++;
b272aebf 512 }
75638da0 513 }
40445ada 514
75638da0 515 if (track->Pt()>0.3 &&
516 track->GetStatus()&AliESDtrack::kTPCrefit &&
517 track->GetStatus()&AliESDtrack::kITSrefit &&
518 nclsTot>3 &&
519 nclsSPD>0) {//fill hist good tracks
520 //cout<<"in if"<<endl;
521 ((TH1F*)fChecks->FindObject("hptGoodTr"))->Fill(track->Pt());
522 isGoodTrack++;
40445ada 523 }
75638da0 524 //cout<<"isGoodTrack = "<<isGoodTrack<<endl;
525 ((TH1F*)fChecks->FindObject("hdistrGoodTr"))->Fill(isGoodTrack);
526 }
527 //number of events with good vertex and at least 2 good tracks
528 if (isGoodTrack>=2 && isGoodVtx) fNentries->Fill(4);
ea0d8716 529
530
75638da0 531 // loop over candidates
532 Int_t nInD0toKpi = inputArray->GetEntriesFast();
533 if(fDebug>1) printf("Number of D0->Kpi: %d\n",nInD0toKpi);
534
75638da0 535 for (Int_t iD0toKpi = 0; iD0toKpi < nInD0toKpi; iD0toKpi++) {
536 //Int_t nPosPairs=0, nNegPairs=0;
537 //cout<<"inside the loop"<<endl;
538 AliAODRecoDecayHF2Prong *d = (AliAODRecoDecayHF2Prong*)inputArray->UncheckedAt(iD0toKpi);
539 Bool_t unsetvtx=kFALSE;
540 if(!d->GetOwnPrimaryVtx()) {
541 d->SetOwnPrimaryVtx(vtx1); // needed to compute all variables
542 unsetvtx=kTRUE;
543 }
ea0d8716 544
75638da0 545 //check reco daughter in acceptance
546 Double_t eta0=d->EtaProng(0);
547 Double_t eta1=d->EtaProng(1);
ea0d8716 548
549 if (TMath::Abs(eta0) < 0.9 && TMath::Abs(eta1) < 0.9) {
550 FillVarHists(d,mcArray,fCuts,fDistr);
551 FillMassHists(d,mcArray,fCuts,fOutputMass);
75638da0 552 }
ea0d8716 553
75638da0 554 if(unsetvtx) d->UnsetOwnPrimaryVtx();
555 } //end for prongs
556
ea0d8716 557
40445ada 558 // Post the data
ea0d8716 559 PostData(1,fOutputMass);
560 PostData(2,fDistr);
40445ada 561 PostData(3,fNentries);
ea0d8716 562 PostData(4,fChecks);
563
40445ada 564 cout<<"Other PostData"<<endl;
565 return;
566}
b272aebf 567
40445ada 568//____________________________________________________________________________
ea0d8716 569void AliAnalysisTaskSED0Mass::FillVarHists(AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliRDHFCutsD0toKpi *cuts, TList *listout){
40445ada 570 //
571 // function used in UserExec to fill variable histograms:
572 //
b272aebf 573
40445ada 574 //add distr here
575 UInt_t pdgs[2];
576
577 Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
578 pdgs[0]=211;
579 pdgs[1]=321;
580 Double_t minvD0 = part->InvMassD0();
581 pdgs[1]=211;
582 pdgs[0]=321;
583 Double_t minvD0bar = part->InvMassD0bar();
584 //cout<<"inside mass cut"<<endl;
b272aebf 585
40445ada 586 Int_t pdgDgD0toKpi[2]={321,211};
587 Int_t lab=-9999;
588 if(fReadMC) lab=part->MatchToMC(421,arrMC,2,pdgDgD0toKpi); //return MC particle label if the array corresponds to a D0, -1 if not (cf. AliAODRecoDecay.cxx)
589 //Double_t pt = d->Pt(); //mother pt
590 Bool_t isSelected=kFALSE;
b272aebf 591
ea0d8716 592 if(fCutOnDistr){
593 isSelected = cuts->IsSelected(part,AliRDHFCuts::kAll);
594 if (!isSelected){
595 //cout<<"Not Selected"<<endl;
596 return;
597 }
598 }
0108fa62 599
40445ada 600 TString fillthispi="",fillthisK="",fillthis="";
b272aebf 601
ea0d8716 602 Int_t ptbin=cuts->PtBin(part->Pt());
40445ada 603 if(!fCutOnDistr || (fCutOnDistr && isSelected)){ //if no cuts or cuts passed
ea0d8716 604 //printf("\nif no cuts or cuts passed\n");
40445ada 605 if(lab>=0 && fReadMC){ //signal
0108fa62 606
40445ada 607 //check pdg of the prongs
608 AliAODTrack *prong0=(AliAODTrack*)part->GetDaughter(0);
609 AliAODTrack *prong1=(AliAODTrack*)part->GetDaughter(1);
610 Int_t labprong[2];
611 labprong[0]=prong0->GetLabel();
612 labprong[1]=prong1->GetLabel();
613 AliAODMCParticle *mcprong=0;
614 Int_t pdgProng[2]={0,0};
615 for (Int_t iprong=0;iprong<2;iprong++){
616 if(labprong[iprong]>=0) mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
617 pdgProng[iprong]=mcprong->GetPdgCode();
0108fa62 618 }
619
40445ada 620 //no mass cut ditributions: ptbis
621
622 fillthispi="hptpiSnoMcut_";
623 fillthispi+=ptbin;
624
625 fillthisK="hptKSnoMcut_";
626 fillthisK+=ptbin;
627
628 if (TMath::Abs(pdgProng[0]) == 211 && TMath::Abs(pdgProng[1]) == 321){
629 ((TH1F*)listout->FindObject(fillthispi))->Fill(part->PtProng(0));
630 ((TH1F*)listout->FindObject(fillthisK))->Fill(part->PtProng(1));
631 }else {
632 if (TMath::Abs(pdgProng[0]) == 321 && TMath::Abs(pdgProng[1]) == 211){
633 ((TH1F*)listout->FindObject(fillthisK))->Fill(part->PtProng(0));
634 ((TH1F*)listout->FindObject(fillthispi))->Fill(part->PtProng(1));
635 }
636 }
637
638 //no mass cut ditributions: mass
639 fillthis="hMassS_";
640 fillthis+=ptbin;
641
642 if (((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421){//D0
643 ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
644 }
645 else { //D0bar
646 ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
647 }
648
0108fa62 649 //apply cut on invariant mass on the pair
650 if(TMath::Abs(minvD0-mPDG)<0.03 || TMath::Abs(minvD0bar-mPDG)<0.03){
40445ada 651
0108fa62 652 if(fArray==1) cout<<"LS signal: ERROR"<<endl;
653 for (Int_t iprong=0; iprong<2; iprong++){
40445ada 654 AliAODTrack *prong=(AliAODTrack*)part->GetDaughter(iprong);
04e09ffc 655 labprong[iprong]=prong->GetLabel();
40445ada 656
0108fa62 657 //cout<<"prong name = "<<prong->GetName()<<" label = "<<prong->GetLabel()<<endl;
40445ada 658 if(labprong[iprong]>=0) mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
0108fa62 659 Int_t pdgprong=mcprong->GetPdgCode();
40445ada 660
0108fa62 661 if(TMath::Abs(pdgprong)==211) {
662 //cout<<"pi"<<endl;
40445ada 663
664 fillthispi="hptpiS_";
665 fillthispi+=ptbin;
666 ((TH1F*)listout->FindObject(fillthispi))->Fill(part->PtProng(iprong));
667
668 fillthisK="hd0KS_";
669 fillthisK+=ptbin;
670 ((TH1F*)listout->FindObject(fillthisK))->Fill(part->Getd0Prong(iprong));
b272aebf 671 }
40445ada 672
673 if(TMath::Abs(pdgprong)==321) {
674 //cout<<"kappa"<<endl;
675
676 fillthisK="hptKS_";
677 fillthisK+=ptbin;
678 ((TH1F*)listout->FindObject(fillthisK))->Fill(part->PtProng(iprong));
679
680 fillthisK="hd0KS_";
681 fillthisK+=ptbin;
682 ((TH1F*)listout->FindObject(fillthisK))->Fill(part->Getd0Prong(iprong));
b272aebf 683 }
b272aebf 684
40445ada 685 fillthis="hdcaS_";
686 fillthis+=ptbin;
687 ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
b272aebf 688
40445ada 689 fillthis="hcosthetapointS_";
690 fillthis+=ptbin;
691 ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngle());
b272aebf 692
40445ada 693 fillthis="hcosthpointd0d0S_";
694 fillthis+=ptbin;
695 ((TH2F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngle(),part->Prodd0d0());
b272aebf 696
40445ada 697 fillthis="hcosthetastarS_";
698 fillthis+=ptbin;
699 if (((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)((TH1F*)listout->FindObject(fillthis))->Fill(part->CosThetaStarD0());
700 else ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosThetaStarD0bar());
0108fa62 701
40445ada 702 fillthis="hd0d0S_";
703 fillthis+=ptbin;
704 ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0());
705
b272aebf 706 }
40445ada 707 }
0108fa62 708 } else{ //Background or LS
709 //cout<<"is background"<<endl;
40445ada 710
b272aebf 711 //no mass cut distributions: mass, ptbis
40445ada 712 fillthis="hMassB_";
713 fillthis+=ptbin;
ea0d8716 714
715 if (!fCutOnDistr || (fCutOnDistr && (isSelected==1 || isSelected==3))) ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
716 if (!fCutOnDistr || (fCutOnDistr && isSelected>1)) ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
b272aebf 717
40445ada 718 fillthis="hptB1prongnoMcut_";
719 fillthis+=ptbin;
720
721 ((TH1F*)listout->FindObject(fillthis))->Fill(part->PtProng(0));
722
723 fillthis="hptB2prongsnoMcut_";
724 fillthis+=ptbin;
725 ((TH1F*)listout->FindObject(fillthis))->Fill(part->PtProng(0));
726 ((TH1F*)listout->FindObject(fillthis))->Fill(part->PtProng(1));
0108fa62 727
728 //apply cut on invariant mass on the pair
729 if(TMath::Abs(minvD0-mPDG)<0.03 || TMath::Abs(minvD0bar-mPDG)<0.03){
730
731
40445ada 732 AliAODTrack *prong=(AliAODTrack*)part->GetDaughter(0);
0108fa62 733 if(!prong) cout<<"No daughter found";
734 else{
735 if(prong->Charge()==1) {fTotPosPairs[4]++;} else {fTotNegPairs[4]++;}
736 }
40445ada 737
738 //normalise pt distr to half afterwards
739 fillthis="hptB_";
740 fillthis+=ptbin;
0108fa62 741
40445ada 742 ((TH1F*)listout->FindObject(fillthis))->Fill(part->PtProng(0));((TH1F*)listout->FindObject("hptB_1"))->Fill(part->PtProng(1));
0108fa62 743
40445ada 744 fillthis="hd0B_";
745 fillthis+=ptbin;
746 ((TH1F*)listout->FindObject(fillthis))->Fill(part->Getd0Prong(0));
ce39f0ac 747
40445ada 748 fillthis="hdcaB_";
749 fillthis+=ptbin;
750 ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
34137226 751
40445ada 752 fillthis="hcosthetastarB_";
753 fillthis+=ptbin;
ea0d8716 754 if (!fCutOnDistr || (fCutOnDistr && (isSelected==1 || isSelected==3)))((TH1F*)listout->FindObject(fillthis))->Fill(part->CosThetaStarD0());
755 if (!fCutOnDistr || (fCutOnDistr && isSelected>1))((TH1F*)listout->FindObject(fillthis))->Fill(part->CosThetaStarD0bar());
40445ada 756
757 fillthis="hd0d0B_";
758 fillthis+=ptbin;
759 ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0());
760
761 fillthis="hcosthetapointB_";
762 fillthis+=ptbin;
763 ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngle());
764
765 fillthis="hcosthpointd0d0B_";
766 fillthis+=ptbin;
767 ((TH2F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngle(),part->Prodd0d0());
768
769 }
770 }
771 }
49061176 772 return;
773}
ea0d8716 774//____________________________________________________________________________
775
776void AliAnalysisTaskSED0Mass::FillMassHists(AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliRDHFCutsD0toKpi* cuts, TList *listout){
49061176 777 //
40445ada 778 // function used in UserExec to fill mass histograms:
49061176 779 //
9de8c723 780
781
782 Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
783
ea0d8716 784 Int_t isSelected=cuts->IsSelected(part,AliRDHFCuts::kAll); //selected
785 //cout<<"is selected = "<<isSelected<<endl;
feb73eca 786
ea0d8716 787 //cout<<"check cuts = "<<endl;
788 //cuts->PrintAll();
789 if (!isSelected){
790 //cout<<"Not Selected"<<endl;
791 return;
792 }
9de8c723 793
ea0d8716 794 cout<<"Candidate selected"<<endl;
a41f6fad 795
ea0d8716 796 Double_t invmassD0 = part->InvMassD0(), invmassD0bar = part->InvMassD0bar();
797 //printf("SELECTED\n");
798 Int_t ptbin=cuts->PtBin(part->Pt());
9de8c723 799
ea0d8716 800 AliAODTrack *prong=(AliAODTrack*)part->GetDaughter(0);
801 if(!prong) cout<<"No daughter found";
802 else{
803 if(prong->Charge()==1) {fTotPosPairs[ptbin-1]++;} else {fTotNegPairs[ptbin-1]++;}
804 }
7646d6da 805
ea0d8716 806 TString fillthis="";
807 Int_t pdgDgD0toKpi[2]={321,211};
808 Int_t labD0=-1;
809 if (fReadMC) labD0 = part->MatchToMC(421,arrMC,2,pdgDgD0toKpi); //return MC particle label if the array corresponds to a D0, -1 if not (cf. AliAODRecoDecay.cxx)
810
811 //count candidates selected by cuts
812 fNentries->Fill(1);
813 //count true D0 selected by cuts
814 if (fReadMC && labD0>=0) fNentries->Fill(2);
815 //PostData(3,fNentries);
816
817 if (isSelected==1 || isSelected==3) { //D0
818 fillthis="histMass_";
819 fillthis+=ptbin;
820 //cout<<"Filling "<<fillthis<<endl;
821
822 //printf("Fill mass with D0");
823 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
feb73eca 824
ea0d8716 825 if(labD0>=0) {
826 if(fArray==1) cout<<"LS signal ERROR"<<endl;
827
828 AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
829 Int_t pdgD0 = partD0->GetPdgCode();
830 //cout<<"pdg = "<<pdgD0<<endl;
831 if (pdgD0==421){ //D0
832 //cout<<"Fill S with D0"<<endl;
833 fillthis="histSgn_";
834 fillthis+=ptbin;
835 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
836 if(TMath::Abs(invmassD0 - mPDG) < 0.027){
837 fillthis="histSgn27_";
46c96ce5 838 fillthis+=ptbin;
839 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
a4ae02cd 840 }
ea0d8716 841 } else{ //it was a D0bar
842 fillthis="histRfl_";
a4ae02cd 843 fillthis+=ptbin;
844 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
845 }
ea0d8716 846 } else {//background
847 fillthis="histBkg_";
a4ae02cd 848 fillthis+=ptbin;
ea0d8716 849 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
850 }
851
852 }
853 if (isSelected>1) { //D0bar
854 fillthis="histMass_";
855 fillthis+=ptbin;
856 //printf("Fill mass with D0bar");
857 ((TH1F*)listout->FindObject(fillthis))->Fill(invmassD0bar);
feb73eca 858
ea0d8716 859 if(labD0>=0) {
860 if(fArray==1) cout<<"LS signal ERROR"<<endl;
861 AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
862 Int_t pdgD0 = partD0->GetPdgCode();
863 //cout<<" pdg = "<<pdgD0<<endl;
864 if (pdgD0==-421){ //D0bar
865 fillthis="histSgn_";
866 fillthis+=ptbin;
867 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
868 if (TMath::Abs(invmassD0bar - mPDG) < 0.027){
869 fillthis="histSgn27_";
a4ae02cd 870 fillthis+=ptbin;
871 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
ea0d8716 872 }
9de8c723 873
a4ae02cd 874
ea0d8716 875 } else{
876 fillthis="histRfl_";
a4ae02cd 877 fillthis+=ptbin;
878 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
879 }
ea0d8716 880 } else {//background or LS
881 fillthis="histBkg_";
882 fillthis+=ptbin;
883 ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
a4ae02cd 884 }
ea0d8716 885 }
a4ae02cd 886
40445ada 887 return;
49061176 888}
889//________________________________________________________________________
890void AliAnalysisTaskSED0Mass::Terminate(Option_t */*option*/)
891{
892 // Terminate analysis
893 //
894 if(fDebug > 1) printf("AnalysisTaskSED0Mass: Terminate() \n");
895
6321ee46 896
ea0d8716 897 fOutputMass = dynamic_cast<TList*> (GetOutputData(1));
898 if (!fOutputMass) {
899 printf("ERROR: fOutputMass not available\n");
a4ae02cd 900 return;
901 }
ea0d8716 902 fDistr = dynamic_cast<TList*> (GetOutputData(2));
903 if (!fDistr) {
904 printf("ERROR: fDistr not available\n");
a41f6fad 905 return;
906 }
40445ada 907 fNentries = dynamic_cast<TH1F*>(GetOutputData(3));
908 if(!fNentries){
909 printf("ERROR: fNEntries not available\n");
910 return;
911 }
ea0d8716 912 fChecks = dynamic_cast<TList*> (GetOutputData(4));
34137226 913 if (!fChecks) {
914 printf("ERROR: fChecks not available\n");
915 return;
916 }
ea0d8716 917
feb73eca 918 if(fArray==1){
40445ada 919 for(Int_t ipt=0;ipt<5;ipt++){
feb73eca 920 fLsNormalization = 2.*TMath::Sqrt(fTotPosPairs[ipt]*fTotNegPairs[ipt]);
921
922
ea0d8716 923 if(fLsNormalization>1e-6) {
9de8c723 924
feb73eca 925 TString massName="histMass_";
ea0d8716 926 massName+=ipt;
927 ((TH1F*)fOutputMass->FindObject(massName))->Scale((1/fLsNormalization)*((TH1F*)fOutputMass->FindObject(massName))->GetEntries());
928
feb73eca 929 }
40445ada 930
feb73eca 931
40445ada 932 fLsNormalization = 2.*TMath::Sqrt(fTotPosPairs[4]*fTotNegPairs[4]);
933
ea0d8716 934 if(fLsNormalization>1e-6) {
40445ada 935
936 TString nameDistr="hptB_";
ea0d8716 937 nameDistr+=ipt;
40445ada 938 ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
939 nameDistr="hdcaB_";
ea0d8716 940 nameDistr+=ipt;
40445ada 941 ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
942 nameDistr="hcosthetastarB_";
ea0d8716 943 nameDistr+=ipt;
40445ada 944 ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
945 nameDistr="hd0B_";
ea0d8716 946 nameDistr+=ipt;
40445ada 947 ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
948 nameDistr="hd0d0B_";
ea0d8716 949 nameDistr+=ipt;
40445ada 950 ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
951 nameDistr="hcosthetapointB_";
ea0d8716 952 nameDistr+=ipt;
40445ada 953 ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
954 nameDistr="hcosthpointd0d0B_";
ea0d8716 955 nameDistr+=ipt;
40445ada 956 ((TH2F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH2F*)fDistr->FindObject(nameDistr))->GetEntries());
feb73eca 957
40445ada 958 }
feb73eca 959 }
960 }
527f330b 961 TString cvname;
962
963 if (fArray==0){
964 cvname="D0invmass";
965 } else cvname="LSinvmass";
966
34137226 967 TCanvas *cMass=new TCanvas(cvname,cvname);
968 cMass->cd();
ea0d8716 969 ((TH1F*)fOutputMass->FindObject("histMass_3"))->Draw();
527f330b 970
34137226 971 TCanvas* cStat=new TCanvas("cstat","Stat");
972 cStat->cd();
973 cStat->SetGridy();
ea0d8716 974 //((TH1F*)fDistr->FindObject("nEntriesD0"))->Draw("htext0");
34137226 975 fNentries->Draw("htext0");
527f330b 976
49061176 977 return;
978}
979