]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/vertexingHF/AliAnalysisTaskSESignificance.cxx
Fix (Chiara )
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAnalysisTaskSESignificance.cxx
CommitLineData
cbedddce 1/**************************************************************************
2 * Copyright(c) 1998-2008, 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
27de2dfb 16/* $Id$ */
17
cbedddce 18/////////////////////////////////////////////////////////////
19//
20// AliAnalysisTaskSESignificane to calculate effects on
21// significance of D mesons cut
22// Authors: G. Ortona, ortona@to.infn.it
23// F. Prino, prino@to.infn.it
24// Renu Bala, bala@to.infn.it
25// Chiara Bianchin, cbianchi@pd.infn.it
26/////////////////////////////////////////////////////////////
27
28#include <Riostream.h>
29#include <TClonesArray.h>
30#include <TCanvas.h>
31#include <TList.h>
32#include <TFile.h>
33#include <TString.h>
34#include <TH1F.h>
35#include <TDatabasePDG.h>
36
83e7d8d8 37#include <AliLog.h>
cbedddce 38#include "AliAnalysisManager.h"
39#include "AliAODHandler.h"
40#include "AliAODEvent.h"
41#include "AliAODVertex.h"
42#include "AliAODTrack.h"
43#include "AliAODMCHeader.h"
44#include "AliAODMCParticle.h"
45#include "AliAODRecoDecayHF3Prong.h"
46#include "AliAODRecoDecayHF.h"
47#include "AliAODRecoDecayHF2Prong.h"
48#include "AliAODRecoDecayHF4Prong.h"
49#include "AliAODRecoCascadeHF.h"
50
51#include "AliAnalysisTaskSE.h"
52#include "AliRDHFCutsDplustoKpipi.h"
83e7d8d8 53#include "AliRDHFCutsD0toKpipipi.h"
54#include "AliRDHFCutsDstoKKpi.h"
55#include "AliRDHFCutsDStartoKpipi.h"
cbedddce 56#include "AliRDHFCutsD0toKpi.h"
83e7d8d8 57#include "AliRDHFCutsLctopKpi.h"
cbedddce 58#include "AliMultiDimVector.h"
59
60#include "AliAnalysisTaskSESignificance.h"
61
62ClassImp(AliAnalysisTaskSESignificance)
63
64
65//________________________________________________________________________
66AliAnalysisTaskSESignificance::AliAnalysisTaskSESignificance():
67 AliAnalysisTaskSE(),
68 fOutput(0),
69 fCutList(0),
70 fHistNEvents(0),
71 fUpmasslimit(1.965),
72 fLowmasslimit(1.765),
73 fRDCuts(0),
74 fNPtBins(0),
75 fReadMC(kFALSE),
33c5731e 76 fBFeedDown(kBoth),
cbedddce 77 fDecChannel(0),
196a3266 78 fPDGmother(0),
79 fNProngs(0),
80 fBranchName(""),
f80a6da9 81 fSelectionlevel(0),
196a3266 82 fNVars(0),
f80a6da9 83 fNBins(100),
c135594e 84 fPartOrAndAntiPart(0),
85 fDsChannel(0)
cbedddce 86{
87 // Default constructor
196a3266 88 SetPDGCodes();
c135594e 89 SetDsChannel(kPhi);
cbedddce 90}
91
92//________________________________________________________________________
93AliAnalysisTaskSESignificance::AliAnalysisTaskSESignificance(const char *name, TList* listMDV,AliRDHFCuts *rdCuts,Int_t decaychannel,Int_t selectionlevel):
94 AliAnalysisTaskSE(name),
95 fOutput(0),
96 fCutList(listMDV),
97 fHistNEvents(0),
98 fUpmasslimit(0),
99 fLowmasslimit(0),
100 fRDCuts(rdCuts),
101 fNPtBins(0),
102 fReadMC(kFALSE),
33c5731e 103 fBFeedDown(kBoth),
cbedddce 104 fDecChannel(decaychannel),
196a3266 105 fPDGmother(0),
106 fNProngs(0),
107 fBranchName(""),
f80a6da9 108 fSelectionlevel(selectionlevel),
196a3266 109 fNVars(0),
f80a6da9 110 fNBins(100),
c135594e 111 fPartOrAndAntiPart(0),
112 fDsChannel(0)
cbedddce 113{
114
196a3266 115 SetPDGCodes();
c135594e 116 SetDsChannel(kPhi);
196a3266 117 SetMassLimits(0.15,fPDGmother); //check range
cbedddce 118 fNPtBins=fRDCuts->GetNPtBins();
83e7d8d8 119
196a3266 120 fNVars=fRDCuts->GetNVarsForOpt();
121 if(fNVars>kMaxCutVar) AliFatal(Form("Too large number of cut variables, maximum is %d",kMaxCutVar))
122
cbedddce 123 if(fDebug>1)fRDCuts->PrintAll();
124 // Output slot #1 writes into a TList container
125 DefineOutput(1,TList::Class()); //My private output
126 DefineOutput(2,TList::Class());
795316ee 127 DefineOutput(3,AliRDHFCuts::Class()); //class of the cuts
3aa6ce53 128 CheckConsistency();
cbedddce 129}
130
131 //________________________________________________________________________
132AliAnalysisTaskSESignificance::~AliAnalysisTaskSESignificance()
133{
134 // Destructor
135 if (fOutput) {
136 delete fOutput;
137 fOutput = 0;
138 }
139 if (fCutList) {
140 delete fCutList;
141 fCutList = 0;
142 }
143 if(fHistNEvents){
144 delete fHistNEvents;
145 fHistNEvents=0;
146 }
cbedddce 147/*
148 if(fRDCuts) {
149 delete fRDCuts;
150 fRDCuts= 0;
151 }
152*/
153
3aa6ce53 154}
196a3266 155//_________________________________________________________________
156void AliAnalysisTaskSESignificance::SetPDGCodes(){
157 // sets channel dependent quantities
158
159 switch(fDecChannel){
160 case 0:
161 //D+
162 fPDGmother=411;
163 fNProngs=3;
164 fPDGdaughters[0]=211;//pi
165 fPDGdaughters[1]=321;//K
166 fPDGdaughters[2]=211;//pi
167 fPDGdaughters[3]=0; //empty
168 fBranchName="Charm3Prong";
169 break;
170 case 1:
171 //D0
172 fPDGmother=421;
173 fNProngs=2;
174 fPDGdaughters[0]=211;//pi
175 fPDGdaughters[1]=321;//K
176 fPDGdaughters[2]=0; //empty
177 fPDGdaughters[3]=0; //empty
178 fBranchName="D0toKpi";
179 break;
180 case 2:
181 //D*
182 fPDGmother=413;
183 fNProngs=3;
184 fPDGdaughters[1]=211;//pi
185 fPDGdaughters[0]=321;//K
186 fPDGdaughters[2]=211;//pi (soft?)
187 fPDGdaughters[3]=0; //empty
188 fBranchName="Dstar";
189 break;
190 case 3:
191 //Ds
192 fPDGmother=431;
193 fNProngs=3;
194 fPDGdaughters[0]=321;//K
195 fPDGdaughters[1]=321;//K
196 fPDGdaughters[2]=211;//pi
197 fPDGdaughters[3]=0; //empty
198 fBranchName="Charm3Prong";
199 break;
200 case 4:
201 //D0 in 4 prongs
202 fPDGmother=421;
203 fNProngs=4;
204 fPDGdaughters[0]=321;
205 fPDGdaughters[1]=211;
206 fPDGdaughters[2]=211;
207 fPDGdaughters[3]=211;
208 fBranchName="Charm4Prong";
209 break;
210 case 5:
211 //Lambda_c
212 fPDGmother=4122;
213 fNProngs=3;
214 fPDGdaughters[0]=2212;//p
215 fPDGdaughters[1]=321;//K
216 fPDGdaughters[2]=211;//pi
217 fPDGdaughters[3]=0; //empty
218 fBranchName="Charm3Prong";
219 break;
220 }
221}
222
3aa6ce53 223//_________________________________________________________________
224Bool_t AliAnalysisTaskSESignificance::CheckConsistency(){
225
226 Bool_t result = kTRUE;
227
228 const Int_t nvars=fRDCuts->GetNVars();//ForOpt();
229 //Float_t *vars = new Float_t[nvars];
230 Bool_t *varsforopt = fRDCuts->GetVarsForOpt();
231 Bool_t *uppervars = fRDCuts->GetIsUpperCut();
232 TString *names = fRDCuts->GetVarNames();
233
234 for(Int_t i=0;i<fNPtBins;i++){
235 TString mdvname=Form("multiDimVectorPtBin%d",i);
236 Int_t ic=0;
237
238 for(Int_t ivar=0;ivar<nvars;ivar++){
239 if(varsforopt[ivar]){
240 Float_t min = ((AliMultiDimVector*)fCutList->FindObject(mdvname.Data()))->GetMinLimit(ic);
241 Float_t max = ((AliMultiDimVector*)fCutList->FindObject(mdvname.Data()))->GetMaxLimit(ic);
242 if(min==max){
e4c00a7b 243 AliFatal(Form("tight and loose cut for optimization variable number %d are the same in ptbin %d\n",ic,i));
244 return kFALSE;
3aa6ce53 245 }
246 Bool_t lowermdv = ((AliMultiDimVector*)fCutList->FindObject(mdvname.Data()))->GetGreaterThan(ic);
247 if(uppervars[ivar]&&lowermdv){
e4c00a7b 248 AliFatal(Form("%s is declared as uppercut, but as been given tighter cut larger then loose cut in ptbin %d \n ---please check your cuts \n ",names[ivar].Data(),i));
249 return kFALSE;
3aa6ce53 250 }
251 if(!uppervars[ivar]&&!lowermdv){
e4c00a7b 252 AliFatal(Form("%s is declared as lower cut, but as been given tighter cut smaller then loose cut in ptbin %d \n ---please check your cuts \n",names[ivar].Data(),i));
253 return kFALSE;
3aa6ce53 254 }
255 ic++;
256 }
257 }
258 }
259 return result;
260}
cbedddce 261//_________________________________________________________________
33c5731e 262void AliAnalysisTaskSESignificance::SetBFeedDown(FeedDownEnum flagB){
263 if(fReadMC)fBFeedDown=flagB;
264 else {
795316ee 265 AliInfo("B feed down not allowed without MC info\n");
266 fBFeedDown=kBoth;
33c5731e 267 }
268}
269//_________________________________________________________________
cbedddce 270void AliAnalysisTaskSESignificance::SetMassLimits(Float_t range, Int_t pdg){
271 Float_t mass=0;
272 Int_t abspdg=TMath::Abs(pdg);
5ecc6e9b 273 mass=TDatabasePDG::Instance()->GetParticle(abspdg)->Mass();
cbedddce 274 fUpmasslimit = mass+range;
275 fLowmasslimit = mass-range;
276}
277//_________________________________________________________________
278void AliAnalysisTaskSESignificance::SetMassLimits(Float_t lowlimit, Float_t uplimit){
279 if(uplimit>lowlimit)
280 {
f80a6da9 281 fUpmasslimit = uplimit;
282 fLowmasslimit = lowlimit;
cbedddce 283 }
284}
285
286
287
288//________________________________________________________________________
289void AliAnalysisTaskSESignificance::LocalInit()
290{
291 // Initialization
292
293 if(fDebug > 1) printf("AnalysisTaskSESignificance::Init() \n");
294
795316ee 295 switch(fDecChannel){
296 case 0:
297 {
298 AliRDHFCutsDplustoKpipi* copycut=new AliRDHFCutsDplustoKpipi(*(static_cast<AliRDHFCutsDplustoKpipi*>(fRDCuts)));
299 // Post the data
300 PostData(3,copycut);
301 }
302 break;
303 case 1:
304 {
305 AliRDHFCutsD0toKpi* copycut=new AliRDHFCutsD0toKpi(*(static_cast<AliRDHFCutsD0toKpi*>(fRDCuts)));
306 // Post the data
307 PostData(3,copycut);
308 }
309 break;
310 case 2:
311 {
312 AliRDHFCutsDStartoKpipi* copycut=new AliRDHFCutsDStartoKpipi(*(static_cast<AliRDHFCutsDStartoKpipi*>(fRDCuts)));
313 // Post the data
314 PostData(3,copycut);
315 }
316 break;
317 case 3:
318 {
319 AliRDHFCutsDstoKKpi* copycut=new AliRDHFCutsDstoKKpi(*(static_cast<AliRDHFCutsDstoKKpi*>(fRDCuts)));
320 // Post the data
321 PostData(3,copycut);
322 }
323 break;
324 case 4:
325 {
326 AliRDHFCutsD0toKpipipi* copycut=new AliRDHFCutsD0toKpipipi(*(static_cast<AliRDHFCutsD0toKpipipi*>(fRDCuts)));
327 // Post the data
328 PostData(3,copycut);
329 }
330 break;
331 case 5:
332 {
333 AliRDHFCutsLctopKpi* copycut=new AliRDHFCutsLctopKpi(*(static_cast<AliRDHFCutsLctopKpi*>(fRDCuts)));
334 // Post the data
335 PostData(3,copycut);
336 }
337 break;
338
339 default:
340 return;
341 }
342
cbedddce 343 TList *mdvList = new TList();
344 mdvList->SetOwner();
345 mdvList = fCutList;
795316ee 346
cbedddce 347 PostData(2,mdvList);
348
795316ee 349
cbedddce 350}
351//________________________________________________________________________
352void AliAnalysisTaskSESignificance::UserCreateOutputObjects()
353{
354 // Create the output container
355
356 if(fDebug > 1) printf("AnalysisTaskSESignificance::UserCreateOutputObjects() \n");
357
358 // Several histograms are more conveniently managed in a TList
359 fOutput = new TList();
360 fOutput->SetOwner();
361 fOutput->SetName("OutputHistos");
362
363 //same number of steps in each multiDimVectorPtBin%d !
364 Int_t nHist=((AliMultiDimVector*)fCutList->FindObject("multiDimVectorPtBin0"))->GetNTotCells();
83e7d8d8 365 cout<<"ncells = "<<nHist<<" n ptbins = "<<fNPtBins<<endl;
cbedddce 366 nHist=nHist*fNPtBins;
83e7d8d8 367 cout<<"Total = "<<nHist<<endl;
cbedddce 368 for(Int_t i=0;i<nHist;i++){
369
370 TString hisname;
371 TString signame;
372 TString bkgname;
373 TString rflname;
374 TString title;
375
376 hisname.Form("hMass_%d",i);
377 signame.Form("hSig_%d",i);
378 bkgname.Form("hBkg_%d",i);
379 rflname.Form("hRfl_%d",i);
380
381 title.Form("Invariant mass;M[GeV/c^{2}];Entries");
382
f80a6da9 383 fMassHist[i]=new TH1F(hisname.Data(),title.Data(),fNBins,fLowmasslimit,fUpmasslimit);
cbedddce 384 fMassHist[i]->Sumw2();
385 fOutput->Add(fMassHist[i]);
386
387 if(fReadMC){
f80a6da9 388 fSigHist[i]=new TH1F(signame.Data(),title.Data(),fNBins,fLowmasslimit,fUpmasslimit);
cbedddce 389 fSigHist[i]->Sumw2();
390 fOutput->Add(fSigHist[i]);
391
f80a6da9 392 fBkgHist[i]=new TH1F(bkgname.Data(),title.Data(),fNBins,fLowmasslimit,fUpmasslimit);
cbedddce 393 fBkgHist[i]->Sumw2();
394 fOutput->Add(fBkgHist[i]);
395
f80a6da9 396 if(fDecChannel != AliAnalysisTaskSESignificance::kDplustoKpipi){
397 fRflHist[i]=new TH1F(rflname.Data(),title.Data(),fNBins,fLowmasslimit,fUpmasslimit);
398 fRflHist[i]->Sumw2();
399 fOutput->Add(fRflHist[i]);
400 }
cbedddce 401 }
402 }
403
795316ee 404 fHistNEvents=new TH1F("fHistNEvents","Number of AODs scanned",8,-0.5,7.5);
cbedddce 405 fHistNEvents->GetXaxis()->SetBinLabel(1,"nEventsAnal");
dc850ba8 406 fHistNEvents->GetXaxis()->SetBinLabel(2,"nEvSelected (vtx)");
5ecc6e9b 407 fHistNEvents->GetXaxis()->SetBinLabel(3,"nCandidatesSelected");
408 fHistNEvents->GetXaxis()->SetBinLabel(4,"nTotEntries Mass hists");
d52f7b50 409 fHistNEvents->GetXaxis()->SetBinLabel(5,"Pile-up Rej");
dc850ba8 410 fHistNEvents->GetXaxis()->SetBinLabel(6,"N. of 0SMH");
95af3e50 411 if(fReadMC){
412 fHistNEvents->GetXaxis()->SetBinLabel(7,"MC Cand from c");
413 fHistNEvents->GetXaxis()->SetBinLabel(8,"MC Cand from b");
414 } else{
415 fHistNEvents->GetXaxis()->SetBinLabel(7,"N candidates");
416 }
cbedddce 417 fHistNEvents->GetXaxis()->SetNdivisions(1,kFALSE);
418 fOutput->Add(fHistNEvents);
419
420
421 return;
422}
423
424//________________________________________________________________________
425void AliAnalysisTaskSESignificance::UserExec(Option_t */*option*/)
426{
427 // Execute analysis for current event:
428 // heavy flavor candidates association to MC truth
429
430 AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
83e7d8d8 431 if(fDebug>2) printf("Analysing decay %d\n",fDecChannel);
cbedddce 432 // Post the data already here
433 PostData(1,fOutput);
434 TClonesArray *arrayProng =0;
435
436 if(!aod && AODEvent() && IsStandardAOD()) {
437 // In case there is an AOD handler writing a standard AOD, use the AOD
438 // event in memory rather than the input (ESD) event.
439 aod = dynamic_cast<AliAODEvent*> (AODEvent());
440 // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
441 // have to taken from the AOD event hold by the AliAODExtension
442 AliAODHandler* aodHandler = (AliAODHandler*)
443 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
444 if(aodHandler->GetExtensions()) {
445
446 AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
447 AliAODEvent *aodFromExt = ext->GetAOD();
196a3266 448 arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject(fBranchName.Data());
cbedddce 449
196a3266 450 }
dc222f77 451 } else if(aod) {
196a3266 452 arrayProng=(TClonesArray*)aod->GetList()->FindObject(fBranchName.Data());
cbedddce 453 }
dc222f77 454 if(!aod || !arrayProng) {
f80a6da9 455 AliError("AliAnalysisTaskSESignificance::UserExec:Branch not found!\n");
cbedddce 456 return;
457 }
458
7c23877d 459 // fix for temporary bug in ESDfilter
460 // the AODs with null vertex pointer didn't pass the PhysSel
196a3266 461 if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) return;
cbedddce 462 TClonesArray *arrayMC=0;
463 AliAODMCHeader *mcHeader=0;
464
465 // load MC particles
466 if(fReadMC){
467
468 arrayMC = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
469 if(!arrayMC) {
dc222f77 470 AliError("AliAnalysisTaskSESignificance::UserExec:MC particles branch not found!\n");
471 return;
cbedddce 472 }
473
474 // load MC header
475 mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
476 if(!mcHeader) {
f80a6da9 477 AliError("AliAnalysisTaskSESignificance::UserExec:MC header branch not found!\n");
cbedddce 478 return;
479 }
480 }
481
482 fHistNEvents->Fill(0); // count event
483
484 AliAODRecoDecayHF *d=0;
cbedddce 485
486
cbedddce 487
488 Int_t nHistpermv=((AliMultiDimVector*)fCutList->FindObject("multiDimVectorPtBin0"))->GetNTotCells();
489 Int_t nProng = arrayProng->GetEntriesFast();
490 if(fDebug>1) printf("Number of D2H: %d\n",nProng);
491
dc850ba8 492 // trigger class for PbPb C0SMH-B-NOPF-ALLNOTRD, C0SMH-B-NOPF-ALL
493 TString trigclass=aod->GetFiredTriggerClasses();
494 if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD") || trigclass.Contains("C0SMH-B-NOPF-ALL")) fHistNEvents->Fill(5);
495
fb9311e8 496 if(fRDCuts->IsEventSelected(aod)) {
497 fHistNEvents->Fill(1);
498 }else{
d52f7b50 499 if(fRDCuts->GetWhyRejection()==1) // rejected for pileup
500 fHistNEvents->Fill(4);
5ecc6e9b 501 return;
502 }
dc850ba8 503
cbedddce 504 for (Int_t iProng = 0; iProng < nProng; iProng++) {
95af3e50 505 fHistNEvents->Fill(6);
cbedddce 506 d=(AliAODRecoDecayHF*)arrayProng->UncheckedAt(iProng);
cbedddce 507
196a3266 508 Bool_t isFidAcc = fRDCuts->IsInFiducialAcceptance(d->Pt(),d->Y(fPDGmother));
a4bb4427 509 Int_t isSelected=fRDCuts->IsSelected(d,fSelectionlevel,aod);
33c5731e 510
795316ee 511 if(fReadMC && fBFeedDown!=kBoth && isSelected){
196a3266 512 Int_t labD = d->MatchToMC(fPDGmother,arrayMC,fNProngs,fPDGdaughters);
33c5731e 513 if(labD>=0){
514 AliAODMCParticle *partD = (AliAODMCParticle*)arrayMC->At(labD);
515 Int_t label=partD->GetMother();
516 AliAODMCParticle *mot = (AliAODMCParticle*)arrayMC->At(label);
517 while(label>=0){//get first mother
518 mot = (AliAODMCParticle*)arrayMC->At(label);
519 label=mot->GetMother();
520 }
521 Int_t pdgMotCode = mot->GetPdgCode();
795316ee 522
33c5731e 523 if(TMath::Abs(pdgMotCode)<=4){
795316ee 524 fHistNEvents->Fill(6);
33c5731e 525 if(fBFeedDown==kBeautyOnly)isSelected=kFALSE; //from primary charm
526 }else{
795316ee 527 fHistNEvents->Fill(7);
528 if(fBFeedDown==kCharmOnly) isSelected=kFALSE; //from beauty
33c5731e 529 }
795316ee 530
33c5731e 531 }
532 }
cbedddce 533
33c5731e 534
f80a6da9 535 if(isSelected&&isFidAcc) {
5ecc6e9b 536 fHistNEvents->Fill(2); // count selected with loosest cuts
83e7d8d8 537 if(fDebug>1) printf("+++++++Is Selected\n");
cbedddce 538
cbedddce 539 Int_t nVals=0;
c135594e 540 if(fDecChannel==3) SetPDGdaughterDstoKKpi();
196a3266 541 fRDCuts->GetCutVarsForOpt(d,fVars,fNVars,fPDGdaughters);
cbedddce 542 Int_t ptbin=fRDCuts->PtBin(d->Pt());
543 if(ptbin==-1) continue;
544 TString mdvname=Form("multiDimVectorPtBin%d",ptbin);
196a3266 545 AliMultiDimVector* muvec=(AliMultiDimVector*)fCutList->FindObject(mdvname.Data());
c135594e 546
196a3266 547 ULong64_t *addresses = muvec->GetGlobalAddressesAboveCuts(fVars,(Float_t)d->Pt(),nVals);
cbedddce 548 if(fDebug>1)printf("nvals = %d\n",nVals);
cbedddce 549 for(Int_t ivals=0;ivals<nVals;ivals++){
196a3266 550 if(addresses[ivals]>=muvec->GetNTotCells()){
cbedddce 551 if (fDebug>1) printf("Overflow!!\n");
dc222f77 552 delete [] addresses;
cbedddce 553 return;
554 }
c135594e 555
f80a6da9 556 fHistNEvents->Fill(3);
c135594e 557
f80a6da9 558 //fill the histograms with the appropriate method
559 switch (fDecChannel){
560 case 0:
196a3266 561 FillDplus(d,arrayMC,(Int_t)(ptbin*nHistpermv+addresses[ivals]),isSelected);
f80a6da9 562 break;
563 case 1:
196a3266 564 FillD02p(d,arrayMC,(Int_t)(ptbin*nHistpermv+addresses[ivals]),isSelected);
f80a6da9 565 break;
566 case 2:
196a3266 567 FillDstar(d,arrayMC,(Int_t)(ptbin*nHistpermv+addresses[ivals]),isSelected);
f80a6da9 568 break;
569 case 3:
c135594e 570 if(isSelected&1){
571 FillDs(d,arrayMC,(Int_t)(ptbin*nHistpermv+addresses[ivals]),isSelected,1);
572 }
f80a6da9 573 break;
574 case 4:
196a3266 575 FillD04p(d,arrayMC,(Int_t)(ptbin*nHistpermv+addresses[ivals]),isSelected);
f80a6da9 576 break;
577 case 5:
196a3266 578 FillLambdac(d,arrayMC,(Int_t)(ptbin*nHistpermv+addresses[ivals]),isSelected);
f80a6da9 579 break;
580 default:
581 break;
cbedddce 582 }
f80a6da9 583
cbedddce 584 }
c135594e 585
586 if (fDecChannel==3 && isSelected&2){
587 SetPDGdaughterDstopiKK();
588 nVals=0;
589 fRDCuts->GetCutVarsForOpt(d,fVars,fNVars,fPDGdaughters);
590 addresses = muvec->GetGlobalAddressesAboveCuts(fVars,(Float_t)d->Pt(),nVals);
591 if(fDebug>1)printf("nvals = %d\n",nVals);
592 for(Int_t ivals=0;ivals<nVals;ivals++){
593 if(addresses[ivals]>=muvec->GetNTotCells()){
594 if (fDebug>1) printf("Overflow!!\n");
595 delete [] addresses;
596 return;
597 }
598 FillDs(d,arrayMC,(Int_t)(ptbin*nHistpermv+addresses[ivals]),isSelected,0);
599
600 }
601
602 }
603
dc222f77 604 delete [] addresses;
cbedddce 605 }// end if selected
cbedddce 606
607 }
f80a6da9 608
e11ae259 609
cbedddce 610 PostData(1,fOutput);
611 return;
612}
613
f80a6da9 614//***************************************************************************
615
616// Methods used in the UserExec
617
f80a6da9 618
619//********************************************************************************************
620
621//Methods to fill the istograms with MC information, one for each candidate
622//NB: the implementation for each candidate is responsibility of the corresponding developer
623
196a3266 624void AliAnalysisTaskSESignificance::FillDplus(AliAODRecoDecayHF* d,TClonesArray *arrayMC,Int_t index,Int_t isSel){
f80a6da9 625 //D+ channel
626 if(!isSel){
627 AliError("Candidate not selected\n");
628 return;
629 }
630
631 if(fPartOrAndAntiPart*d->GetCharge()<0)return;
196a3266 632 Int_t pdgdaughters[3] = {211,321,211};
633 Double_t mass=d->InvMass(3,(UInt_t*)pdgdaughters);
f80a6da9 634
196a3266 635 fMassHist[index]->Fill(mass);
f80a6da9 636
f80a6da9 637
638 if(fReadMC){
639 Int_t lab=-1;
640 lab = d->MatchToMC(411,arrayMC,3,pdgdaughters);
641 if(lab>=0){ //signal
196a3266 642 fSigHist[index]->Fill(mass);
f80a6da9 643 } else{ //background
196a3266 644 fBkgHist[index]->Fill(mass);
f80a6da9 645 }
646 }
647}
648
649
196a3266 650void AliAnalysisTaskSESignificance::FillD02p(AliAODRecoDecayHF* d,TClonesArray *arrayMC,Int_t index,Int_t isSel){
f80a6da9 651
652 //D0->Kpi channel
653
654 //mass histograms
196a3266 655 Int_t pdgdaughtersD0[2]={211,321};//pi,K
656 Int_t pdgdaughtersD0bar[2]={321,211};//K,pi
657 Double_t masses[2];
658 masses[0]=d->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0); //D0
659 masses[1]=d->InvMass(fNProngs,(UInt_t*)pdgdaughtersD0bar); //D0bar
660
f80a6da9 661 if((isSel==1 || isSel==3) && fPartOrAndAntiPart>=0) fMassHist[index]->Fill(masses[0]);
662 if(isSel>=2 && fPartOrAndAntiPart<=0) fMassHist[index]->Fill(masses[1]);
663
664
4d829de7 665
f80a6da9 666 //MC histograms
667 if(fReadMC){
668
669 Int_t matchtoMC=-1;
670
671 //D0
672 Int_t pdgdaughters[2];
673 pdgdaughters[0]=211;//pi
674 pdgdaughters[1]=321;//K
f80a6da9 675
196a3266 676 matchtoMC = d->MatchToMC(fPDGmother,arrayMC,fNProngs,pdgdaughters);
f80a6da9 677
678 Int_t prongPdgPlus=421,prongPdgMinus=(-1)*421;
679 if((isSel==1 || isSel==3) && fPartOrAndAntiPart>=0){ //D0
680 if(matchtoMC>=0){
681 AliAODMCParticle *dMC = (AliAODMCParticle*)arrayMC->At(matchtoMC);
682 Int_t pdgMC = dMC->GetPdgCode();
683
684 if(pdgMC==prongPdgPlus) fSigHist[index]->Fill(masses[0]);
685 else fRflHist[index]->Fill(masses[0]);
686
687 } else fBkgHist[index]->Fill(masses[0]);
688
689 }
690 if(isSel>=2 && fPartOrAndAntiPart<=0){ //D0bar
691 if(matchtoMC>=0){
692 AliAODMCParticle *dMC = (AliAODMCParticle*)arrayMC->At(matchtoMC);
693 Int_t pdgMC = dMC->GetPdgCode();
694
695 if(pdgMC==prongPdgMinus) fSigHist[index]->Fill(masses[1]);
696 else fRflHist[index]->Fill(masses[1]);
697 } else fBkgHist[index]->Fill(masses[1]);
698 }
699 }
700}
701
196a3266 702void AliAnalysisTaskSESignificance::FillDstar(AliAODRecoDecayHF* /*d*/,TClonesArray */*arrayMC*/,Int_t /*index*/,Int_t /*matchtoMC*/){
f80a6da9 703 //D* channel
704
705 AliInfo("Dstar channel not implemented\n");
706
707}
708
709
c135594e 710void AliAnalysisTaskSESignificance::FillDs(AliAODRecoDecayHF* d,TClonesArray *arrayMC,Int_t index,Int_t isSel,Int_t optDecay){
4d829de7 711
c135594e 712 // Fill Ds histos
4d829de7 713
714
196a3266 715 Int_t pdgDsKKpi[3]={321,321,211};//K,K,pi
716 Int_t pdgDspiKK[3]={211,321,321};//pi,K,K
717 Double_t masses[2];
718 masses[0]=d->InvMass(fNProngs,(UInt_t*)pdgDsKKpi); //Ds
719 masses[1]=d->InvMass(fNProngs,(UInt_t*)pdgDspiKK); //Dsbar
720
4d829de7 721 Int_t labDs=-1;
722 if(fReadMC){
196a3266 723 labDs = d->MatchToMC(431,arrayMC,3,pdgDsKKpi);
4d829de7 724 }
f80a6da9 725
c135594e 726 Int_t isKKpi=isSel&1;
727 Int_t ispiKK=isSel&2;
728 Int_t isPhiKKpi=isSel&4;
729 Int_t isPhipiKK=isSel&8;
730 Int_t isK0starKKpi=isSel&16;
731 Int_t isK0starpiKK=isSel&32;
732
733
734 if(fDsChannel==kPhi && (isPhiKKpi==0 && isPhipiKK==0)) return;
735 if(fDsChannel==kK0star && (isK0starKKpi==0 && isK0starpiKK==0)) return;
736
737 if (optDecay==1){
738 if(isKKpi && fPartOrAndAntiPart*d->GetCharge()>=0) {
739 if(fDsChannel==kPhi && isPhiKKpi==0) return;
740 if(fDsChannel==kK0star && isK0starKKpi==0) return;
741
742 fMassHist[index]->Fill(masses[0]);
743
744 if(fReadMC){
745 if(labDs>=0){
746 Int_t labDau0=((AliAODTrack*)d->GetDaughter(0))->GetLabel();
747 AliAODMCParticle* p=(AliAODMCParticle*)arrayMC->UncheckedAt(labDau0);
748 Int_t pdgCode0=TMath::Abs(p->GetPdgCode());
749 if(pdgCode0==321) {
750 fSigHist[index]->Fill(masses[0]); //signal
751 }else{
752 fRflHist[index]->Fill(masses[0]); //Reflected signal
753 }
4d829de7 754 }else{
c135594e 755 fBkgHist[index]->Fill(masses[0]); // Background
4d829de7 756 }
4d829de7 757 }
758 }
759 }
760
c135594e 761 if (optDecay==0){
762 if(ispiKK && fPartOrAndAntiPart*d->GetCharge()>=0){
763 if(fDsChannel==kPhi && isPhipiKK==0) return;
764 if(fDsChannel==kK0star && isK0starpiKK==0) return;
765
766 fMassHist[index]->Fill(masses[1]);
767
768 if(fReadMC){
769 if(labDs>=0){
770 Int_t labDau0=((AliAODTrack*)d->GetDaughter(0))->GetLabel();
771 AliAODMCParticle* p=(AliAODMCParticle*)arrayMC->UncheckedAt(labDau0);
772 Int_t pdgCode0=TMath::Abs(p->GetPdgCode());
773 if(pdgCode0==211) {
774 fSigHist[index]->Fill(masses[1]);
775 }else{
776 fRflHist[index]->Fill(masses[1]);
777 }
4d829de7 778 }else{
c135594e 779 fBkgHist[index]->Fill(masses[1]);
4d829de7 780 }
4d829de7 781 }
782 }
783 }
f80a6da9 784}
785
196a3266 786void AliAnalysisTaskSESignificance::FillD04p(AliAODRecoDecayHF* /*d*/,TClonesArray */*arrayMC*/,Int_t /*index*/,Int_t /*matchtoMC*/){
f80a6da9 787 //D0->Kpipipi channel
788 AliInfo("D0 in 4 prongs channel not implemented\n");
789
790}
791
038a276c 792void AliAnalysisTaskSESignificance::FillLambdac(AliAODRecoDecayHF* d,TClonesArray* arrayMC,Int_t index,Int_t isSel){
793
794 // Mass hypothesis
795 Double_t masses[2];
796 Int_t pdgdaughtersLc[3]={2212,321,211}; //p,K,pi
797 masses[0]=d->InvMass(fNProngs,(UInt_t*)pdgdaughtersLc);
798 Int_t pdgdaughtersLc2[3]={211,321,2212}; //pi,K,p
799 masses[1]=d->InvMass(fNProngs,(UInt_t*)pdgdaughtersLc2);
800
801
802 if(fPartOrAndAntiPart==0 || fPartOrAndAntiPart==d->GetCharge()) {
803
804 // isSel=1 : p K pi ; isSel=2 : pi K p ;
805 if(isSel==1 || isSel==3) fMassHist[index]->Fill(masses[0]);
806 if(isSel>=2) fMassHist[index]->Fill(masses[1]);
807
808 // Check the MC truth
809 if(fReadMC){
810
811 Int_t ispKpi = 0;
812 Int_t ispiKp = 0;
813 ispKpi = isSel&1;
814 ispiKp = isSel&2;
815 Int_t matchtoMC = -1;
816 //
817 Int_t pPDG = 2212; // p
818 Int_t kPDG = 321; // K
819 Int_t piPDG = 211; // pi
820 Int_t absPdgMom = 4122;
821 matchtoMC = d->MatchToMC(absPdgMom,arrayMC,fNProngs,pdgdaughtersLc);
822
823 if(matchtoMC>=0){
824
825 AliAODMCParticle *dMC = (AliAODMCParticle*)arrayMC->At(matchtoMC);
826 Int_t pdgMC = dMC->GetPdgCode();
827 if (TMath::Abs(pdgMC)!=absPdgMom) AliInfo("What's up, isn't it a lambdac ?!");
828 Int_t labDau0 = ((AliAODTrack*)d->GetDaughter(0))->GetLabel();
829 AliAODMCParticle* p0 = (AliAODMCParticle*)arrayMC->UncheckedAt(labDau0);
830 Int_t pdgCode0 = TMath::Abs(p0->GetPdgCode());
831 Int_t labDau1 = ((AliAODTrack*)d->GetDaughter(1))->GetLabel();
832 AliAODMCParticle* p1 = (AliAODMCParticle*)arrayMC->UncheckedAt(labDau1);
833 Int_t pdgCode1 = TMath::Abs(p1->GetPdgCode());
834 Int_t labDau2 = ((AliAODTrack*)d->GetDaughter(2))->GetLabel();
835 AliAODMCParticle* p2 = (AliAODMCParticle*)arrayMC->UncheckedAt(labDau2);
836 Int_t pdgCode2 = TMath::Abs(p2->GetPdgCode());
837
838 // Fill in the histograms in case of p K pi decays
839 if(ispKpi==1){
840 if(pdgCode0==pPDG && pdgCode1==kPDG && pdgCode2==piPDG){
841 fSigHist[index]->Fill(masses[0]);
842 } else {
843 fRflHist[index]->Fill(masses[0]);
844 }
845 }
846 // Fill in the histograms in case of pi K p decays
847 if(ispiKp==2){
848 if(pdgCode0==piPDG && pdgCode1==kPDG && pdgCode2==pPDG){
849 fSigHist[index]->Fill(masses[1]);
850 } else {
851 fRflHist[index]->Fill(masses[1]);
852 }
853 }
854 } else {
855 if(ispKpi==1) fBkgHist[index]->Fill(masses[0]);
856 if(ispiKp==2) fBkgHist[index]->Fill(masses[1]);
857 }
858 }
859 }
f80a6da9 860
f80a6da9 861
862}
863
cbedddce 864
865//________________________________________________________________________
866void AliAnalysisTaskSESignificance::Terminate(Option_t */*option*/)
867{
868 // Terminate analysis
869 //
870 if(fDebug > 1) printf("AnalysisTaskSESignificance: Terminate() \n");
871
872
873 fOutput = dynamic_cast<TList*> (GetOutputData(1));
874 if (!fOutput) {
875 printf("ERROR: fOutput not available\n");
876 return;
877 }
878
879 fCutList = dynamic_cast<TList*> (GetOutputData(2));
880 if (!fCutList) {
881 printf("ERROR: fCutList not available\n");
882 return;
883 }
884
885 AliMultiDimVector* mdvtmp=(AliMultiDimVector*)fCutList->FindObject("multiDimVectorPtBin0");
886 if (!mdvtmp){
887 cout<<"multidimvec not found in TList"<<endl;
888 fCutList->ls();
889 return;
890 }
891 Int_t nHist=mdvtmp->GetNTotCells();
892 TCanvas *c1=new TCanvas("c1","Invariant mass distribution - loose cuts",500,500);
893 Bool_t drawn=kFALSE;
894 for(Int_t i=0;i<nHist;i++){
895
896 TString hisname;
897 TString signame;
898 TString bkgname;
899 TString rflname;
900
901 hisname.Form("hMass_%d",i);
902 signame.Form("hSig_%d",i);
903 bkgname.Form("hBkg_%d",i);
904 rflname.Form("hRfl_%d",i);
905
906 fMassHist[i]=dynamic_cast<TH1F*>(fOutput->FindObject(hisname.Data()));
907
908 if (!drawn && fMassHist[i]->GetEntries() > 0){
909 c1->cd();
910 fMassHist[i]->Draw();
911 drawn=kTRUE;
912 }
913
914 if(fReadMC){
915 fSigHist[i]=dynamic_cast<TH1F*>(fOutput->FindObject(signame.Data()));
916 fBkgHist[i]=dynamic_cast<TH1F*>(fOutput->FindObject(bkgname.Data()));
f80a6da9 917 if(fDecChannel != AliAnalysisTaskSESignificance::kDplustoKpipi) fRflHist[i]=dynamic_cast<TH1F*>(fOutput->FindObject(rflname.Data()));
cbedddce 918 }
919
920 }
921
922
923
924
925 return;
926}
ab3e5f67 927//-------------------------------------------
cbedddce 928